Esempio n. 1
0
    protected void btnDeleteSelected_Click(object sender, EventArgs e)
    {
        string    optype = "1";
        DataTable dtUser = new DataTable();

        dtUser.Columns.Add("sdwEnrollNumber");
        dtUser.Columns.Add("sName");
        dtUser.Columns.Add("sPassWord");
        dtUser.Columns.Add("iPrivilege");
        dtUser.Columns.Add("sTmpData");
        dtUser.Columns.Add("sCardNumber");
        dtUser.Columns.Add("Emp_Id");
        dtUser.Columns.Add("IP");
        dtUser.Columns.Add("Port");
        dtUser.Columns.Add("Device_Id");
        dtUser.Columns.Add("sEnabled");

        if (chkUser.Checked && chkFinger.Checked && chkFace.Checked)
        {
            optype = "5";
        }

        else if (chkUser.Checked && chkFinger.Checked && !chkFace.Checked)
        {
            optype = "6";
        }
        else if (chkUser.Checked && !chkFinger.Checked && chkFace.Checked)
        {
            optype = "7";
        }
        else if (chkFinger.Checked && chkFace.Checked)
        {
            optype = "4";
        }

        else if (chkFace.Checked)
        {
            optype = "3";
        }
        else if (chkFinger.Checked)
        {
            optype = "2";
        }
        else if (chkUser.Checked)
        {
            optype = "1";
        }

        for (int rowcount = 0; rowcount < gvUser.Rows.Count; rowcount++)
        {
            if (((CheckBox)gvUser.Rows[rowcount].FindControl("chkSel")).Checked)
            {
                string EnrollNo = gvUser.DataKeys[rowcount]["sdwEnrollNumber"].ToString();

                string Password       = gvUser.DataKeys[rowcount]["sPassword"].ToString();
                string EmpId          = gvUser.DataKeys[rowcount]["Emp_Id"].ToString();
                string empname        = gvUser.DataKeys[rowcount]["sName"].ToString();
                string Privilege      = gvUser.DataKeys[rowcount]["iPrivilege"].ToString();
                string FingerTemplate = string.Empty;
                string DeviceId       = gvUser.DataKeys[rowcount]["Device_Id"].ToString();
                string ip             = gvUser.DataKeys[rowcount]["IP"].ToString();
                string Port           = gvUser.DataKeys[rowcount]["Port"].ToString();

                string iflag    = string.Empty;
                string senabled = gvUser.DataKeys[rowcount]["bEnabled"].ToString();
                string CardNo   = gvUser.DataKeys[rowcount]["sCardNumber"].ToString();

                DataRow dr = dtUser.NewRow();
                dr["sdwEnrollNumber"] = EnrollNo;
                dr["sName"]           = empname;
                dr["sPassword"]       = Password;
                dr["iPrivilege"]      = Privilege;
                dr["sEnabled"]        = senabled;
                dr["sCardNumber"]     = CardNo;
                dr["Emp_Id"]          = EmpId;
                dr["Device_Id"]       = DeviceId;
                dr["IP"]       = ip;
                dr["Port"]     = Port;
                dr["sEnabled"] = senabled;
                dtUser.Rows.Add(dr);
            }
        }



        DataTable dtFinger = new DataTable();
        DataTable dtFace   = new DataTable();

        DataTable dtDistinctDevice = dtUser.DefaultView.ToTable(true, "Device_Id");

        for (int devicecounter = 0; devicecounter < dtDistinctDevice.Rows.Count; devicecounter++)
        {
            DataTable dtUserByDevice = new DataView(dtUser, "Device_Id='" + dtDistinctDevice.Rows[devicecounter][0].ToString() + "'", "", DataViewRowState.CurrentRows).ToTable();
            if (dtUserByDevice.Rows.Count > 0)
            {
                string ip   = dtUserByDevice.Rows[0]["IP"].ToString();
                string Port = dtUserByDevice.Rows[0]["Port"].ToString();
                bool   IsDeviceConnected = false;
                if (objDeviceOp.Device_Connection(ip, Convert.ToInt32(Port), 0))
                {
                    IsDeviceConnected = true;
                }
                for (int rowcount = 0; rowcount < dtUserByDevice.Rows.Count; rowcount++)
                {
                    objEmp = new EmployeeMaster();
                    if (rowcount % 50 == 0)
                    {
                        ;
                    }

                    string EnrollNo      = dtUserByDevice.Rows[rowcount]["sdwEnrollNumber"].ToString();
                    string DeviceEmpName = dtUserByDevice.Rows[rowcount]["sName"].ToString();
                    string Password      = dtUserByDevice.Rows[rowcount]["sPassword"].ToString();
                    string EmpId         = dtUserByDevice.Rows[rowcount]["Emp_Id"].ToString();

                    string Privilege      = dtUserByDevice.Rows[rowcount]["iPrivilege"].ToString();
                    string DeviceId       = dtUserByDevice.Rows[rowcount]["Device_Id"].ToString();
                    string senabled       = dtUserByDevice.Rows[rowcount]["sEnabled"].ToString();
                    string CardNo         = dtUserByDevice.Rows[rowcount]["sCardNumber"].ToString();
                    string FingerTemplate = string.Empty;
                    string iflag          = string.Empty;
                    string faceindex      = string.Empty;
                    string facedata       = string.Empty;
                    string facelength     = string.Empty;
                    string fingerindex    = string.Empty;

                    bool b = false;
                    if (IsDeviceConnected)
                    {
                        if (optype == "1")
                        {
                            try
                            {
                                b = objDeviceOp.DelSingleUser(ip, Convert.ToInt32(Port), Convert.ToInt32(EmpId));
                            }
                            catch
                            {
                            }
                        }

                        else if (optype == "2")
                        {
                            try
                            {
                                b = objDeviceOp.DelSingleUserFinger(ip, Convert.ToInt32(Port), Convert.ToInt32(EmpId));
                            }
                            catch
                            {
                            }
                        }
                        else if (optype == "3")
                        {
                            try
                            {
                                b = objDeviceOp.DelSingleUserFace(ip, Convert.ToInt32(Port), (EmpId));
                            }
                            catch
                            {
                            }
                        }
                        else if (optype == "4")
                        {
                            try
                            {
                                b = objDeviceOp.DelSingleUserFinger(ip, Convert.ToInt32(Port), Convert.ToInt32(EmpId));

                                b = objDeviceOp.DelSingleUserFace(ip, Convert.ToInt32(Port), (EmpId));
                            }
                            catch
                            {
                            }
                        }


                        else if (optype == "5")
                        {
                            try
                            {
                                b = objDeviceOp.DelSingleUserFinger(ip, Convert.ToInt32(Port), Convert.ToInt32(EmpId));

                                b = objDeviceOp.DelSingleUserFace(ip, Convert.ToInt32(Port), (EmpId));

                                b = objDeviceOp.DelSingleUser(ip, Convert.ToInt32(Port), Convert.ToInt32(EmpId));
                            }
                            catch
                            {
                            }
                        }

                        else if (optype == "6")
                        {
                            try
                            {
                                b = objDeviceOp.DelSingleUser(ip, Convert.ToInt32(Port), Convert.ToInt32(EmpId));
                                b = objDeviceOp.DelSingleUserFinger(ip, Convert.ToInt32(Port), Convert.ToInt32(EmpId));
                            }
                            catch
                            {
                            }
                        }

                        else if (optype == "7")
                        {
                            try
                            {
                                b = objDeviceOp.DelSingleUser(ip, Convert.ToInt32(Port), Convert.ToInt32(EmpId));
                                b = objDeviceOp.DelSingleUserFace(ip, Convert.ToInt32(Port), (EmpId));
                            }
                            catch
                            {
                            }
                        }
                    }
                }
            }
        }

        gvUser.DataSource = null;
        gvUser.DataBind();
        pnlList.Visible     = true;
        pnlDeviceOp.Visible = false;

        DisplayMessage("Users Deleted");
    }