protected void Page_Load(object sender, EventArgs e)
        {
            IsConfirmNeeded = true;
            ConfirmMessage  = "Place User Card on reader";

            // Insure that the __doPostBack() JavaScript is added to the page...
            ClientScript.GetPostBackEventReference(this, string.Empty);

            if (IsPostBack)
            {
                string eventTarget   = Request["__EVENTTARGET"] ?? string.Empty;
                string eventArgument = Request["__EVENTARGUMENT"] ?? string.Empty;


                switch (eventTarget)
                {
                case "UserConfirmationPostBack":
                    if (Convert.ToBoolean(eventArgument))
                    {
                        // User said yes do it...
                        WriteOnCard();
                        btnWrite.Enabled = false;
                    }
                    else
                    {
                        // User said NOT to do it...
                        //this.lblMsg.Text = "No";
                    }
                    break;
                }
            }

            if (!Page.IsPostBack)
            {
                //  RootPath.Value = this.Server.MapPath("~//Enrollment//NativeTemplate.exe");
                RootPath.Value = @"C:\Program Files\CMS\Enrollment\NativeTemplate.exe";
                clsCardRW objcard = new clsCardRW();
                objcard.CardSettings();
                FillData();
            }
        }
        private void WriteOnCard()
        {
            string strsql = "";

            try
            {
                if (ddlFormat.Text == "Native")
                {
                    strsql = "select " + clsCardRW.finger_val1 + "," + clsCardRW.finger_val2 + ",FingerQuality1,FingerQuality2 from Finger_Template " +
                             "where Format_Type = 'Native' and EmployeeCD = '" + txtEmpCd.Text + "' and Isdeleted = 'false'";

                    SqlDataAdapter da = new SqlDataAdapter(strsql, AccessController.m_connecton);
                    DataTable      dt = new DataTable();
                    da.Fill(dt);

                    if (dt.Rows.Count != 0)
                    {
                        byte[] NativeTemplate1 = (byte[])dt.Rows[0][clsCardRW.finger_val1];
                        byte[] NativeTemplate2 = (byte[])dt.Rows[0][clsCardRW.finger_val2];
                        int    FingerQty1      = Convert.ToInt32(dt.Rows[0]["FingerQuality1"]);
                        int    FingerQty2      = Convert.ToInt32(dt.Rows[0]["FingerQuality2"]);

                        clsCardRW objclsCardRW = new clsCardRW();
                        string    strCardWrite = objclsCardRW.WriteCard(NativeTemplate1, NativeTemplate2, FingerQty1, FingerQty2);
                        string    Message      = "";
                        if (strCardWrite != "")
                        {
                            Message = "Failed to write native template on card. " + strCardWrite;
                            string someScript2 = "";
                            someScript2 = "<script language='javascript'>alert('" + Message + "');</script>";
                            Page.ClientScript.RegisterStartupScript(this.GetType(), "onload", someScript2);
                            return;
                        }
                        else
                        {
                            Message = "Successfully written native template on card";
                            string someScript2 = "";
                            someScript2 = "<script language='javascript'>alert('" + Message + "');</script>";
                            Page.ClientScript.RegisterStartupScript(this.GetType(), "onload", someScript2);

                            clsCardRW.Execute = false;
                            SqlConnection conn = new SqlConnection(AccessController.m_connecton);
                            conn.Open();
                            SqlCommand cmd = new SqlCommand();
                            cmd.Connection  = conn;
                            cmd.CommandText = "Update Finger_Template set CardIssue = 'true' where EmployeeCD = '" + txtEmpCd.Text + "' and IsDeleted = 'false'";
                            cmd.ExecuteNonQuery();
                        }
                    }
                }
                else if (ddlFormat.Text == "ISO")
                {
                    strsql = "select " + clsCardRW.ISOfinger_val1 + "," + clsCardRW.ISOfinger_val2 + ",ISOFingerQuality1,ISOFingerQuality2 from Finger_Template " +
                             "where Format_Type = 'ISO' and EmployeeCD = '" + txtEmpCd.Text + "' and Isdeleted = 'false'";

                    SqlDataAdapter da = new SqlDataAdapter(strsql, AccessController.m_connecton);
                    DataTable      dt = new DataTable();
                    da.Fill(dt);

                    if (dt.Rows.Count != 0)
                    {
                        byte[] ISOTemplate1  = (byte[])dt.Rows[0][clsCardRW.ISOfinger_val1];
                        byte[] ISOTemplate2  = (byte[])dt.Rows[0][clsCardRW.ISOfinger_val2];
                        int    ISOFingerQty1 = Convert.ToInt32(dt.Rows[0]["ISOFingerQuality1"]);
                        int    ISOFingerQty2 = Convert.ToInt32(dt.Rows[0]["ISOFingerQuality2"]);

                        clsCardRW objclsCardRW = new clsCardRW();
                        string    strCardWrite = objclsCardRW.ISOWriteCard(ISOTemplate1, ISOTemplate2, ISOFingerQty1, ISOFingerQty2);
                        string    Message      = "";
                        if (strCardWrite != "")
                        {
                            Message = "Failed to write ISO template on card. " + strCardWrite;
                            string someScript2 = "";
                            someScript2 = "<script language='javascript'>alert('" + Message + "');</script>";
                            Page.ClientScript.RegisterStartupScript(this.GetType(), "onload", someScript2);
                            return;
                        }
                        else
                        {
                            Message = "Successfully written ISO template on card";
                            string someScript2 = "";
                            someScript2 = "<script language='javascript'>alert('" + Message + "');</script>";
                            Page.ClientScript.RegisterStartupScript(this.GetType(), "onload", someScript2);

                            clsCardRW.Execute = false;
                            SqlConnection conn = new SqlConnection(AccessController.m_connecton);
                            conn.Open();
                            SqlCommand cmd = new SqlCommand();
                            cmd.Connection  = conn;
                            cmd.CommandText = "Update Finger_Template set CardIssue = 'true' where EmployeeCD = '" + txtEmpCd.Text + "' and IsDeleted = 'false'";
                            cmd.ExecuteNonQuery();
                        }
                    }
                }
                else if (ddlFormat.Text == "Both")
                {
                    strsql = "select " + clsCardRW.finger_val1 + "," + clsCardRW.finger_val2 + "," + clsCardRW.ISOfinger_val1 + "," + clsCardRW.ISOfinger_val2 + ", " +
                             "FingerQuality1,FingerQuality2,ISOFingerQuality1,ISOFingerQuality2 from Finger_Template " +
                             "where Format_Type = 'Both' and EmployeeCD = '" + txtEmpCd.Text + "' and Isdeleted = 'false'";

                    SqlDataAdapter da = new SqlDataAdapter(strsql, AccessController.m_connecton);
                    DataTable      dt = new DataTable();
                    da.Fill(dt);

                    if (dt.Rows.Count != 0)
                    {
                        byte[] NativeTemplate1 = (byte[])dt.Rows[0][clsCardRW.finger_val1];
                        byte[] NativeTemplate2 = (byte[])dt.Rows[0][clsCardRW.finger_val2];
                        int    FingerQty1      = Convert.ToInt32(dt.Rows[0]["FingerQuality1"]);
                        int    FingerQty2      = Convert.ToInt32(dt.Rows[0]["FingerQuality2"]);

                        byte[] ISOTemplate1  = (byte[])dt.Rows[0][clsCardRW.ISOfinger_val1];
                        byte[] ISOTemplate2  = (byte[])dt.Rows[0][clsCardRW.ISOfinger_val2];
                        int    ISOFingerQty1 = Convert.ToInt32(dt.Rows[0]["ISOFingerQuality1"]);
                        int    ISOFingerQty2 = Convert.ToInt32(dt.Rows[0]["ISOFingerQuality2"]);

                        clsCardRW     objclsCardRW = new clsCardRW();
                        string        strCardWrite = objclsCardRW.WriteCard(NativeTemplate1, NativeTemplate2, FingerQty1, FingerQty2);
                        string        Message      = "";
                        SqlConnection conn         = new SqlConnection(AccessController.m_connecton);
                        conn.Open();
                        SqlCommand cmd = new SqlCommand();
                        cmd.Connection = conn;
                        if (strCardWrite != "")
                        {
                            Message = "Failed to write native template on card. " + strCardWrite;
                            string someScript2 = "";
                            someScript2 = "<script language='javascript'>alert('" + Message + "');</script>";
                            Page.ClientScript.RegisterStartupScript(this.GetType(), "onload", someScript2);
                            cmd.CommandText = "Update Finger_Template set CardIssue = 'false' where EmployeeCD = '" + txtEmpCd.Text + "' and IsDeleted = 'false'";
                            cmd.ExecuteNonQuery();
                            return;
                        }
                        else
                        {
                            Message = "Successfully written native template on card";
                            string someScript2 = "";
                            someScript2 = "<script language='javascript'>alert('" + Message + "');</script>";
                            Page.ClientScript.RegisterStartupScript(this.GetType(), "onload", someScript2);

                            clsCardRW.Execute = false;
                            cmd.CommandText   = "Update Finger_Template set CardIssue = 'true' where EmployeeCD = '" + txtEmpCd.Text + "' and IsDeleted = 'false'";
                            cmd.ExecuteNonQuery();
                        }

                        string strCardWrite1 = objclsCardRW.ISOWriteCard(ISOTemplate1, ISOTemplate2, ISOFingerQty1, ISOFingerQty2);
                        string Message1      = "";
                        if (strCardWrite != "")
                        {
                            Message1 = "Failed to write ISO template on card. " + strCardWrite;
                            string someScript2 = "";
                            someScript2 = "<script language='javascript'>alert('" + Message + "');</script>";
                            Page.ClientScript.RegisterStartupScript(this.GetType(), "onload", someScript2);
                            cmd.CommandText = "Update Finger_Template set CardIssue = 'false' where EmployeeCD = '" + txtEmpCd.Text + "' and IsDeleted = 'false'";
                            cmd.ExecuteNonQuery();
                            return;
                        }
                        else
                        {
                            Message1 = "Successfully written ISO template on card";
                            string someScript2 = "";
                            someScript2 = "<script language='javascript'>alert('" + Message + "');</script>";
                            Page.ClientScript.RegisterStartupScript(this.GetType(), "onload", someScript2);

                            clsCardRW.Execute = false;
                            cmd.CommandText   = "Update Finger_Template set CardIssue = 'true' where EmployeeCD = '" + txtEmpCd.Text + "' and IsDeleted = 'false'";
                            cmd.ExecuteNonQuery();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }