using System;
using System.Data;
using System.Globalization;
using System.IO;
using System.Resources;
using System.Threading;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using DevExpress.Web;
/****************************************************************************************************************************
* Project Name    : TimeCheck                                        Started Date  : 12-Aug-2007
* Module          : Terminal Master                                  Last Modified : 14-Aug-2007
* Programmer      : Arun vinoth.T
* Current Storage : \\Angler56\Projects\Inprogress\SCREEN1206\code\Time_AttendanceApp
* BackUp          :
****************************************************************************************************************************/
public partial class Masters_TA_UI_Master_Terminal : Base.BasePage
{
    #region "Variable Declaration"
    LeaveEventData objLeave = new LeaveEventData();
    ResourceManager rm;
    CultureInfo ci;
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    cls_Common objcommon = new cls_Common();
    TerminalEventData objTerminalEventData = new TerminalEventData();
    TerminalDatatypeEventData objTerminalDatatype = new TerminalDatatypeEventData();
    int EmployeeID = 0;
    string gstrUserGroupName = string.Empty, strScript = string.Empty, source_Language;
    #endregion
    #region PageLoad
    protected override void Page_Load(object sender, EventArgs e)
    {
        base.Page_Load(sender, e);
        gv_Terminal.Styles.CssFilePath = Convert.ToString(Session["GridCSS"]);
        source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
        rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        ci = Thread.CurrentThread.CurrentCulture;
        site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);
        LoadStrings(ci);
        EmployeeID = Convert.ToInt32(Session["EmpAutoID"]);
        string strSetAlert = "";
        strSetAlert = strSetAlert + "<script language='javascript'>";
        strSetAlert = strSetAlert + "RestoreAlert('" + rm.GetString("Alert_Norecordsfound", ci) + "','" + rm.GetString("Alert_Areyousuretorestore", ci) + "','" + rm.GetString("Alert_Selecteddataisnotindeletedstatus", ci) + "','" + rm.GetString("Alert_Selectdatatorestore", ci) + "','" + rm.GetString("Alert_Nodeletedrecordsavailable", ci) + "');";
        strSetAlert = strSetAlert + "</script>";
        Page.RegisterStartupScript("RestoreAlert", strSetAlert);
        UserRights();
        if (Session["UserGroupName"] != null)
        {
            gstrUserGroupName = Convert.ToString(Session["UserGroupName"]);
        }
        if (gstrUserGroupName != "SuperAdmin")
        {
            btn_Restore.Visible = false;
            btn_PermanentDelete.Visible = false;
        }
        if (!IsPostBack)
        {
            base.CheckPages(224);
            objcommon.menu("Terminal", "224");
        }
        DataSet ds = new DataSet();
        ds = objTerminalDatatype.Select_TerminalDatatype(Convert.ToString(Session["UserGroupName"]));
        foreach (DataRow dr in ds.Tables[0].Rows)
        {
            if (Convert.ToString(dr["FileType"]) == "RDBMS")
            {
                btnsync.Enabled = true;
                break;
            }
        }
        BindGridView();
        btn_add.Focus();
    }
    #endregion
    #region ButtonEvents
    protected void btnsync_Click(object sender, EventArgs e)
    {
        string constr = string.Empty;
        DataSet ds = new DataSet();
        ds = objTerminalDatatype.Select_TerminalDatatype(Convert.ToString(Session["UserGroupName"]));
        DataSet dsDeviceList = new DataSet();
        int LicTerminalCount = TerminalCount();
        int TermialCount = objTerminalDatatype.intTerminalCreationCount();
        LicTerminalCount = LicTerminalCount - TermialCount;
        divNoOfTer.Style.Add("color", "Green");
        lblNoOfTerminal.Text = rm.GetString("lbl_NoofTerminalscanbeadd", ci) + LicTerminalCount;
        DataTable dt = new DataTable();
        dt.Columns.AddRange(new DataColumn[3] { new DataColumn("nReaderIdn"), new DataColumn("sName"), new DataColumn("DataType") });
        foreach (DataRow dr in ds.Tables[0].Rows)
        {
            if (Convert.ToString(dr["FileType"]) == "RDBMS" && Convert.ToInt32(dr["BrandId"]) == 3 && Convert.ToString(dr["IsDeleted"]) == "False")
            {
                constr = Encryption.Decrypt(Convert.ToString(dr["ConnectionString"]), "");
                dsDeviceList = objTerminalDatatype.Select_DeviceFromBiostar(constr);
                if (dsDeviceList.Tables.Count > 0)
                {
                    foreach (DataRow drDevice in dsDeviceList.Tables[0].Rows)
                    {
                        dt.Rows.Add(Convert.ToString(drDevice["nReaderIdn"]), Convert.ToString(drDevice["sName"]), Convert.ToString(drDevice["DataType"]));
                    }
                }
            }
        }
        gvDeviceList.DataSource = dt;
        gvDeviceList.DataBind();
        Session["DataDeviceTerminal"] = dt;
        string strScript1 = "";
        strScript1 = strScript1 + "<script language='javascript'>";
        strScript1 = strScript1 + "ShowPopup();";
        strScript1 = strScript1 + "</script>";
        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strScript1, false);
    }
    private void fillPunchtype()
    {
        DataTable dt = new DataTable();
        dt = (DataTable)Session["DataDeviceTerminal"];
        if (dt != null && dt.Rows.Count > 0)
        {
            gvDeviceList.DataSource = dt;
            gvDeviceList.DataBind();
        }
        else
        {
            gvDeviceList.DataSource = dt;
            gvDeviceList.DataBind();
        }
        string strScript1 = string.Empty;
        strScript1 = strScript1 + "<script language='javascript'>";
        strScript1 = strScript1 + "ShowPopup();";
        strScript1 = strScript1 + "</script>";
        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strScript1, false);
    }
    protected void GetSelectedRecords(object sender, EventArgs e)
    {
        EmployeeID = Convert.ToInt32(Session["EmpAutoID"]);
        DataTable dt = new DataTable();
        dt.Columns.AddRange(new DataColumn[3] { new DataColumn("nReaderIdn"), new DataColumn("sName"), new DataColumn("DataType") });
        Label lblReaderID = new Label();
        Label lblReaderName = new Label();
        Label lblDataType = new Label();
        int intCount = 0;
        int LicTerminalCount = TerminalCount();
        foreach (GridViewRow row in gvDeviceList.Rows)
        {
            if (row.RowType == DataControlRowType.DataRow)
            {
                CheckBox chkRow = (CheckBox)row.FindControl("chkSelected");
                if (chkRow.Checked)
                {
                    lblReaderID = (Label)row.FindControl("lblReaderId");
                    lblReaderName = (Label)row.FindControl("lblName");
                    lblDataType = (Label)row.FindControl("lblDataType");
                    dt.Rows.Add(lblReaderID.Text, lblReaderName.Text, lblDataType.Text);
                    intCount = intCount + 1;
                }
            }
        }
        int TermialCount = objTerminalDatatype.intTerminalCreationCount();
        LicTerminalCount = LicTerminalCount - TermialCount;
        if (LicTerminalCount < intCount)
        {
            divNoOfTer.Style.Add("color", "Red");
            string strScript = "<script language='javascript' type='text/javascript'>";
            strScript += "alert('" + rm.GetString("Aleart_TerminalSyncexceeds", ci) + "');ShowPopup();";
            strScript += " </script>";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strScript, false);
            DataTable dtAllData = new DataTable();
            dtAllData = (DataTable)Session["DataDeviceTerminal"];
            gvDeviceList.DataSource = dtAllData;
            gvDeviceList.DataBind();
        }
        else
        {
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    objTerminalEventData.InsertTerminalDetails(Convert.ToString(dr["nReaderIdn"]), Convert.ToString(dr["nReaderIdn"]), Convert.ToString(dr["sName"]), Convert.ToInt32(dr["DataType"]), EmployeeID);
                }
                divNoOfTer.Style.Add("color", "Green");
                string strScript = "";
                strScript = strScript + "<script language='javascript'>";
                strScript = strScript + "alert('" + rm.GetString("Aleart_TerminalSyncComplete", ci) + "');";
                strScript = strScript + "location.replace('TA_UI_Master_Terminal.aspx');";
                strScript = strScript + "</script>";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strScript, false);
            }
        }
    }
    protected void btn_add_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_Master_TerminalAdd.aspx");
    }
    protected void btn_Cancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_Master_TerminalList.aspx");
    }
    protected void btn_Delete_Click(object sender, EventArgs e)
    {
        string[] ChkBoxIDs;
        if (hdnSelectRow.Value != string.Empty && hdnSelectRow.Value != null)
        {
            ChkBoxIDs = objLeave.commaStringToArray(hdnSelectRow.Value);
            for (int i = 0; i < ChkBoxIDs.Length; i++)
            {
                int Count = objTerminalEventData.GetTerminalMappingCount(Convert.ToInt32(ChkBoxIDs[i]));
                if (Count > 0)
                {
                    base.Message(rm.GetString("Master_Terminal_Reader_Delete", ci));
                    hdnSelectRow.Value = "";
                    return;
                }
            }
            objTerminalEventData.DeleteTerminals(hdnSelectRow.Value, EmployeeID);
            base.MessageWithRedirect(rm.GetString("Alert_Terminaldeletedsuccessfully", ci), "TA_UI_Master_Terminal.aspx");
        }
        else
        {
            strScript = strScript + "<script language='javascript'>";
            strScript = strScript + "alert('" + rm.GetString("DeletionRecordAlert", ci) + "')";
            strScript = strScript + "</script>";
            Page.RegisterStartupScript("DelAlert1", strScript);
            return;
        }
    }
    protected void btn_Restore_Click(object sender, EventArgs e)
    {
        string[] ChkBoxIDs;
        if (hdnSelectRow.Value != string.Empty && hdnSelectRow.Value != null)
        {
            ChkBoxIDs = objLeave.commaStringToArray(hdnSelectRow.Value);
            for (int i = 0; i < ChkBoxIDs.Length; i++)
            {
                int Count = objTerminalEventData.CheckRestoreTerminal(Convert.ToInt32(ChkBoxIDs[i]));
                if (Count > 0)
                {
                    base.Message(rm.GetString("Message_Cannot_Restore", ci));
                    gv_Terminal.DataBind();
                    hdnSelectRow.Value = "";
                    return;
                }
                bool isAllowTerminalAdd = CheckNoOfTerminalForLicense();
                if (isAllowTerminalAdd)
                {
                    objTerminalEventData.RestoreTerminals(ChkBoxIDs[i], EmployeeID);
                }
                else
                {
                    return;
                }
            }
            base.MessageWithRedirect(rm.GetString("Alert_Terminalrestoredsuccessfully", ci), "TA_UI_Master_Terminal.aspx");
        }
        else
        {
            strScript = strScript + "<script language='javascript'>";
            strScript = strScript + "alert('" + rm.GetString("DeletionRecordAlert", ci) + "')";
            strScript = strScript + "</script>";
            Page.RegisterStartupScript("DelAlert1", strScript);
            return;
        }
    }
    protected void btn_PermanentDelete_Click(object sender, EventArgs e)
    {
        string[] ChkBoxIDs;
        if (hdnSelectRow.Value != string.Empty && hdnSelectRow.Value != null)
        {
            ChkBoxIDs = objLeave.commaStringToArray(hdnSelectRow.Value);
            for (int i = 0; i < ChkBoxIDs.Length; i++)
            {
                objTerminalEventData.PermanentDeleteTerminals(ChkBoxIDs[i], EmployeeID);
            }
            base.MessageWithRedirect(rm.GetString("Alert_Terminaldeletedsuccessfully", ci), "TA_UI_Master_Terminal.aspx");
        }
        else
        {
            strScript = strScript + "<script language='javascript'>";
            strScript = strScript + "alert('" + rm.GetString("DeletionRecordAlert", ci) + "')";
            strScript = strScript + "</script>";
            Page.RegisterStartupScript("DelAlert1", strScript);
            return;
        }
    }
    #endregion
    #region UserDefinedFunction
    private int TerminalCount()
    {
        DemoVersion objDemoVersion = new DemoVersion();
        int GetCount = 0;
        string[] fileArr = Directory.GetFiles(Server.MapPath("../LicenseFile"), "*.lic");
        int arrCount = fileArr.Length;
        if (arrCount > 0)
        {
            string licenseFileName = Convert.ToString(fileArr[arrCount - 1]);
            FileStream licenseFileStream = new FileStream(licenseFileName, FileMode.Open);
            StreamReader licenseFileStreamReader = new StreamReader(licenseFileStream);
            string encryptedLicFileInfo = licenseFileStreamReader.ReadToEnd();
            licenseFileStreamReader.Close();
            licenseFileStream.Close();
            string decryptedLicFileInfo = string.Empty;
            try
            {
                decryptedLicFileInfo = Encryption.Decrypt(encryptedLicFileInfo, "");
            }
            catch
            {
                string strScript = "<script language='javascript' type='text/javascript'>";
                strScript += "alert('" + rm.GetString("Alert_Licenseinformationarenotcorrect", ci) + "');";
                strScript += "location.href='../Index.aspx';";
                strScript += " </script>";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strScript, false);
                return 1;
            }
            string[] decryptedLicFileInfoArr = decryptedLicFileInfo.Split('#');
            string basicLicInfo = Convert.ToString(decryptedLicFileInfoArr[0]);
            string[] basicLicInfoArr = basicLicInfo.Split(',');
            int noOfEmployeeLicFile = Convert.ToInt32(basicLicInfoArr[8]);
            GetCount = noOfEmployeeLicFile;
            return GetCount;
        }
        else
        {
            return 5;
        }
        return GetCount;
    }
    public void BindGridView()
    {
        DataSet ds = new DataSet();
        ds = objTerminalEventData.SelectTerminalDetails(Convert.ToString(Session["UserGroupName"]));
        gv_Terminal.DataSource = ds;
        gv_Terminal.DataBind();
        string strChkIds = string.Empty;
        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            strChkIds = strChkIds + Convert.ToString(ds.Tables[0].Rows[i][0]) + ",";
        }
        if (strChkIds != string.Empty && strChkIds != null)
        {
            strChkIds = strChkIds.Substring(0, strChkIds.Length - 1);
            hdnGetAllid.Value = Convert.ToString(strChkIds);
        }
    }
    private string CheckDelete()
    {
        string ChkBoxIDs = string.Empty;
        return (ChkBoxIDs);
    }
    private void LoadStrings(CultureInfo ci)
    {
        lbl_TerminalMaster.Text = rm.GetString("Masters_Terminal_TerminalMaster", ci);
        btn_add.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Add", ci);
        btn_Delete.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Delete", ci);
        btn_Cancel.Text = rm.GetString("btn_Back", ci);
        btn_Restore.Text = rm.GetString("btn_Restore", ci);
        btn_PermanentDelete.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Delete", ci);
        gv_Terminal.Columns[2].Caption = rm.GetString("TerminalMaster_Terminal_Id", ci);
        gv_Terminal.Columns[3].Caption = rm.GetString("TerminalMaster_Terminal_Name", ci);
        gv_Terminal.Columns[4].Caption = rm.GetString("TerminalMaster_Terminal_Desc", ci);
        gv_Terminal.Columns[5].Caption = rm.GetString("TerminalDataType_RawDataFormat", ci);
        lblDataView.Text = rm.GetString("lblDataView", ci);
        btnsync.Text = "&nbsp;&nbsp;" + rm.GetString("lbl_DeviceDataSync", ci);
        lblDeviceList.Text = rm.GetString("lbl_DeviceDataSync", ci);
        gvDeviceList.Columns[1].HeaderText= rm.GetString("TerminalMaster_Terminal_Name", ci);
        gvDeviceList.Columns[2].HeaderText = rm.GetString("TerminalMaster_Terminal_Desc", ci);
        //gv_Terminal.Columns[6].Caption = rm.GetString("DeleteStatus", ci);
    }
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(10, Convert.ToInt32(Session["userGroup_Id"]), "");
        if (ds_Checkuser.Tables[0].Rows.Count > 0)
        {
            if (ds_Checkuser.Tables[0].Rows[0]["addPrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["addPrv"]) == 1)
            {
                this.btn_add.Visible = true;
            }
            else
            {
                this.btn_add.Visible = false;
            }
            if (ds_Checkuser.Tables[0].Rows[0]["deletePrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["deletePrv"]) == 1)
            {
                gv_Terminal.Columns[1].Visible = true;
                this.btn_Delete.Visible = false;
                this.btn_PermanentDelete.Visible = true;
                this.btn_Restore.Visible = false;
                gv_Terminal.Columns[1].Visible = true;
                gv_Terminal.Columns[8].Visible = true;
            }
            else
            {
                this.btn_Delete.Visible = false;
                gv_Terminal.Columns[1].Visible = false;
                gv_Terminal.Columns[8].Visible = false;
                this.btn_PermanentDelete.Visible = false;
                this.btn_Restore.Visible = false;
            }
            if (ds_Checkuser.Tables[0].Rows[0]["modifyPrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["modifyPrv"]) == 1)
            {
                this.gv_Terminal.Columns[7].Visible = true;
            }
            else
            {
                this.gv_Terminal.Columns[7].Visible = false;
            }
            if (ds_Checkuser.Tables[0].Rows[0]["viewPrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["viewPrv"]) == 1)
            {
                this.gv_Terminal.Columns[6].Visible = true;
            }
            else
            {
                this.gv_Terminal.Columns[6].Visible = false;
            }
        }
        else
        {
            Response.Redirect("MasterLandingPage.aspx");
        }
    }
    protected void EditLinkButton_Click(object sender, EventArgs e)
    {
        LinkButton btn = sender as LinkButton;
        int intTerminal_ID = Convert.ToInt32(btn.CommandName);
        Response.Redirect("TA_UI_Master_TerminalModify.aspx?Terminal_Id=" + intTerminal_ID);
    }
    protected void btn_delete_Click_1(object sender, EventArgs e)
    {
        LinkButton btn = sender as LinkButton;
        int TerminalId = Convert.ToInt32(btn.CommandName);
        int Count = objTerminalEventData.GetTerminalMappingCount(TerminalId);
        if (Count > 0)
        {
            base.Message(rm.GetString("Master_Terminal_Reader_Delete", ci));
            return;
        }
        objTerminalEventData.PermanentDeleteTerminals(Convert.ToString(TerminalId), EmployeeID);
        base.MessageWithRedirect(rm.GetString("Alert_Terminaldeletedsuccessfully", ci), "TA_UI_Master_Terminal.aspx");
    }
    private bool CheckNoOfTerminalForLicense()
    {
        DemoVersion objDemoVersion = new DemoVersion();
        bool allowEmployeeAdd = false;
        string[] fileArr = Directory.GetFiles(Server.MapPath("../LicenseFile"), "*.lic");
        int arrCount = fileArr.Length;
        if (arrCount > 0)
        {
            string licenseFileName = Convert.ToString(fileArr[arrCount - 1]);
            FileStream licenseFileStream = new FileStream(licenseFileName, FileMode.Open);
            StreamReader licenseFileStreamReader = new StreamReader(licenseFileStream);
            string encryptedLicFileInfo = licenseFileStreamReader.ReadToEnd();
            licenseFileStreamReader.Close();
            licenseFileStream.Close();
            string decryptedLicFileInfo = string.Empty;
            try
            {
                decryptedLicFileInfo = Encryption.Decrypt(encryptedLicFileInfo, "");
            }
            catch
            {
                string strScript = "<script language='javascript' type='text/javascript'>";
                strScript += "alert('" + rm.GetString("Alert_Licenseinformationarenotcorrect", ci) + "');";
                strScript += "location.href='../Index.aspx';";
                strScript += " </script>";
                this.RegisterStartupScript("AlertLicInfoNotCorrect", strScript);
                return false;
            }
            string[] decryptedLicFileInfoArr = decryptedLicFileInfo.Split('#');
            string basicLicInfo = Convert.ToString(decryptedLicFileInfoArr[0]);
            string[] basicLicInfoArr = basicLicInfo.Split(',');
            int noOfEmployeeLicFile = Convert.ToInt32(basicLicInfoArr[8]);
            allowEmployeeAdd = objDemoVersion.RestoreCheckTerminalCreation("License", noOfEmployeeLicFile);
            if (allowEmployeeAdd)
            {
                return true;
            }
            else
            {
                string strScript = "<script language='javascript' type='text/javascript'>";
                strScript += "alert('" + rm.GetString("Alert_LicensenotallowtoRestoreTerminal", ci) + "');";
                strScript += " </script>";
                this.RegisterStartupScript("setScript", strScript);
                return false;
            }
        }
        else
        {
            return true;
        }
    }
    #endregion
    #region GridviewEvents
    protected void gv_Terminal_HtmlRowCreated(object sender, DevExpress.Web.ASPxGridViewTableRowEventArgs e)
    {
        if (e.RowType == GridViewRowType.Data)
        {
            source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
            rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
            ci = Thread.CurrentThread.CurrentCulture;
            Label DeletedRecord = (Label)gv_Terminal.FindRowCellTemplateControl(e.VisibleIndex, null, "lblIsDeleted");
            if (DeletedRecord != null)
            {
                if (DeletedRecord.Text == "True" || DeletedRecord.Text == rm.GetString("Grid_True", ci))
                {
                    DeletedRecord.ForeColor = System.Drawing.Color.Red;
                }
            }
            HtmlInputCheckBox deleteChkBxItem = (HtmlInputCheckBox)gv_Terminal.FindRowCellTemplateControl(e.VisibleIndex, null, "chkSelect");
            LinkButton LnkbtnDelete = (LinkButton)gv_Terminal.FindRowCellTemplateControl(e.VisibleIndex, null, "btnDelete");
            if (deleteChkBxItem != null)
            {
                int Count = objTerminalEventData.GetTerminalMappingCount(Convert.ToInt32(e.GetValue("Terminal_Id")));
                if (Count > 0)
                {
                    deleteChkBxItem.Disabled = true;
                    LnkbtnDelete.Enabled = false;
                    LnkbtnDelete.OnClientClick = null;
                }
                else
                {
                    deleteChkBxItem.Disabled = false;
                    LnkbtnDelete.Enabled = true;
                }
            }
            if (DeletedRecord != null)
            {
                if (DeletedRecord.Text == "True")
                {
                    DeletedRecord.Text = rm.GetString("Grid_True", ci);
                    if (hdnDeletedData.Value == string.Empty)
                    {
                        hdnDeletedData.Value = Convert.ToString(e.GetValue("Terminal_Id"));
                    }
                    else
                    {
                        if (hdnDeletedData.Value.Contains(Convert.ToString(e.GetValue("Terminal_Id"))) == false)
                        {
                            hdnDeletedData.Value = hdnDeletedData.Value + "," + Convert.ToString(e.GetValue("Terminal_Id"));
                        }
                    }
                }
                else if (DeletedRecord.Text == "False")
                {
                    DeletedRecord.Text = rm.GetString("Grid_False", ci);
                }
            }
        }
    }
    #endregion
    protected void gvDeviceList_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvDeviceList.PageIndex = e.NewPageIndex;
        fillPunchtype();
    }
}