Ejemplo n.º 1
0
        private void GetUserIDListFromMac()
        {
            bool   state;
            bool   ret               = false;
            int    vnResultCode      = -1;
            UInt32 vEnrollNumber     = 0;
            int    vBackupNumber     = 0;
            int    vPrivilege        = 0;
            int    vnEnableFlag      = 0;
            string UserName          = "";
            int    EnrollNumberCount = 0;
            int    PersonNum         = 0;

            lblMsg.ForeColor = Color.FromName("Black");
            TDIConnInfo conn;

            progBar1.ProgressType = DevComponents.DotNetBar.eProgressItemType.Marquee;
            progBar1.Visible      = true;
            lblMsg1.Visible       = true;
            btnStop.Visible       = true;
            btnStop.Focus();
            if (connList.Count > 0)
            {
                for (int i = 0; i < connList.Count; i++)
                {
                    conn = connList[i];

                    switch (conn.MacSeriesTypeId)
                    {
                    case 2:
                        if (SystemInfo.ShowSEA != 1)
                        {
                            Pub.MessageBoxShow(string.Format(Pub.GetResText(formCode, "MsgUnModuleInfo", ""), Pub.GetResText(formCode, "SeaDev", "")));
                            break;
                        }
                        if (RegisterInfo.IsValid || RegisterInfo.IsTest)
                        {
                            if (RegisterInfo.EndDate < DateTime.Now)
                            {
                                Pub.MessageBoxShow(RegisterInfo.StateText);
                                break;
                            }
                        }
                        SystemInfo.MacSeriesTypeId = 2;
                        string url = "http://" + conn.NetHost + "/";
                        //查询人员总数
                        string                       searchTotlePersonUrl      = url + "action/SearchPersonNum";
                        SearchTotlePerson            searchTotlePerson         = new SearchTotlePerson(Convert.ToInt32(conn.MacSN), 0, "", "", 2, "0-100", 0, "");
                        jsonBody <SearchTotlePerson> jsonBodySearchTotlePerson = new jsonBody <SearchTotlePerson>("SearchPersonNum", searchTotlePerson);
                        string                       jsonString = JsonConvert.SerializeObject(jsonBodySearchTotlePerson);
                        ret = DeviceObject.objFK623.POST_GetResponse(searchTotlePersonUrl, conn.MacSeriesUserName, conn.SeaSeries_Pwd, ref jsonString);
                        if (!ret)
                        {
                            lblMsg.ForeColor = Color.FromName("red");
                            lblMsg.Text      = DeviceObject.objFK623.SeaBodyStr();
                            continue;
                        }
                        jsonBody <SearchTotlePersonInfo> searchTotlePersonInfo = JsonConvert.DeserializeObject <jsonBody <SearchTotlePersonInfo> >(jsonString);
                        {
                            PersonNum = searchTotlePersonInfo.info.PersonNum;
                        }
                        if (PersonNum == 0)
                        {
                            lblMsg.ForeColor = Color.FromName("red");
                            lblMsg.Text      = (Pub.GetResText(formCode, "ErrorUnUserID", ""));
                            continue;
                        }
                        int count = 0;
                        while (true)
                        {
                            if (Stop || StopGet)
                            {
                                break;
                            }
                            //查询人员
                            string searchMultipleUrl            = url + "action/SearchPersonList";
                            SearchMultiplePerson searchMultiple = new SearchMultiplePerson(Convert.ToInt32(conn.MacSN), 0, "", "", 2, "0-100", 0, "", count * 10, 10, 0);
                            count++;
                            jsonBody <SearchMultiplePerson> jsonBodySearchMultiplePerson = new jsonBody <SearchMultiplePerson>("SearchPersonList", searchMultiple);
                            jsonString = JsonConvert.SerializeObject(jsonBodySearchMultiplePerson);
                            ret        = DeviceObject.objFK623.POST_GetResponse(searchMultipleUrl, conn.MacSeriesUserName, conn.SeaSeries_Pwd, ref jsonString);
                            if (!ret)
                            {
                                break;
                            }
                            jsonBody <SearchMultiplePersonInfo <SearchPersonInfo> > searchMultiplePersonInfo = JsonConvert.DeserializeObject <jsonBody <SearchMultiplePersonInfo <SearchPersonInfo> > >(jsonString);
                            {
                                for (int j = 0; j < searchMultiplePersonInfo.info.Listnum; j++)
                                {
                                    if (Stop || StopGet)
                                    {
                                        break;
                                    }
                                    vEnrollNumber = searchMultiplePersonInfo.info.List[j].CustomizeID;
                                    UserName      = searchMultiplePersonInfo.info.List[j].Name;
                                    if (!selStringList.Contains(vEnrollNumber.ToString()) && vEnrollNumber != 0)
                                    {
                                        //int index = this.cardGrid.Rows.Add();
                                        cardGrid.Rows.Add(new object[] { false, vEnrollNumber.ToString(), UserName });
                                        //// ((DataGridViewCheckBoxCell)cardGrid.Rows[index].Cells[0]).Value = true;
                                        //this.cardGrid.Rows[index].Cells[1].Value = vEnrollNumber.ToString();
                                        //this.cardGrid.Rows[index].Cells[2].Value = UserName;

                                        selStringList.Add(vEnrollNumber.ToString());

                                        lblMsg.Text = string.Format("{0}", cardGrid.Rows.Count);
                                    }
                                    //EnrollNumberCount++;

                                    lblMsg1.Text = Pub.GetResText(formCode, "btnGetListFromMac", "") + string.Format("-{0} /{1} ", cardGrid.Rows.Count, cardGrid.Rows.Count);
                                }
                            }
                            Application.DoEvents();
                        }
                        break;

                    case 3:
                        if (SystemInfo.ShowSTAR != 1)
                        {
                            Pub.MessageBoxShow(string.Format(Pub.GetResText(formCode, "MsgUnModuleInfo", ""), Pub.GetResText(formCode, "StarDev", "")));
                            break;
                        }
                        if (RegisterInfo.IsValid || RegisterInfo.IsTest)
                        {
                            if (RegisterInfo.EndDate < DateTime.Now)
                            {
                                Pub.MessageBoxShow(RegisterInfo.StateText);
                                break;
                            }
                        }
                        try
                        {
                            if (DeviceObject.socKetClient.Open(conn.NetHost, conn.NetPort, conn.NetPassword))
                            {
                                string        cmd               = "GetDeviceInfo";
                                DeviceCmd     getDeviceCmd      = new DeviceCmd(cmd);
                                StringBuilder jsonStringBuilder = new StringBuilder(JsonConvert.SerializeObject(getDeviceCmd));
                                if (DeviceObject.socKetClient.SendData(ref jsonStringBuilder))
                                {
                                    cmd = "GetUserIdList";
                                    GetUserIdListCmd getUserIdListCmd = new GetUserIdListCmd(0);
                                    _DeviceCmd <GetUserIdListCmd> devGetUserIdListCmd = new _DeviceCmd <GetUserIdListCmd>(cmd, getUserIdListCmd);
RE:
                                    if (Stop || StopGet)
                                    {
                                        break;
                                    }
                                    jsonStringBuilder = new StringBuilder(JsonConvert.SerializeObject(devGetUserIdListCmd));
                                    if (DeviceObject.socKetClient.SendData(ref jsonStringBuilder))
                                    {
                                        int back = DeviceObject.socKetClient.JsonRecive(jsonStringBuilder);
                                        if (back == 0)
                                        {
                                            _ResultInfo <UserListInfo <UserIdName> > personIDList = JsonConvert.DeserializeObject <_ResultInfo <UserListInfo <UserIdName> > >(jsonStringBuilder.ToString());
                                            if (personIDList.result_data.users != null)
                                            {
                                                for (int x = 0; x < personIDList.result_data.users.Count; x++)
                                                {
                                                    int index = this.cardGrid.Rows.Add();
                                                    this.cardGrid.Rows[index].Cells[1].Value = personIDList.result_data.users[x].userId;
                                                    this.cardGrid.Rows[index].Cells[2].Value = personIDList.result_data.users[x].name;

                                                    selStringList.Add(personIDList.result_data.users[x].userId);
                                                    EnrollNumberCount = index;
                                                    lblMsg.Text       = string.Format("{0}", index);
                                                }
                                            }
                                            else
                                            {
                                                lblMsg.ForeColor = Color.FromName("red");
                                                lblMsg.Text      = (Pub.GetResText(formCode, "ErrorUnUserID", ""));
                                                ret = false;
                                                continue;
                                            }

                                            if (personIDList.result_data.packageId != 0)
                                            {
                                                devGetUserIdListCmd.data.packageId++;
                                                goto RE;
                                            }

                                            lblMsg1.Text = Pub.GetResText(formCode, "btnGetListFromMac", "") + string.Format("-{0} /{1} ", EnrollNumberCount, EnrollNumberCount);
                                            Application.DoEvents();
                                            ret = true;
                                        }
                                        else
                                        {
                                            ret = false;
                                        }
                                    }
                                    else
                                    {
                                        ret = false;
                                    }
                                }
                            }
                            else
                            {
                                lblMsg.ForeColor = Color.FromName("red");
                                lblMsg.Text      = DeviceObject.objFK623.GetRunMsg((int)enumErrorCode.RUNERR_NO_OPEN_COMM);
                                continue;
                            }
                            DeviceObject.socKetClient.Close();
                        }
                        catch (Exception E)
                        {
                            MessageBox.Show(E.Message);
                        }
                        break;

                    default:
                        SystemInfo.MacSeriesTypeId = 1;
                        DeviceObject.objFK623.InitConn(conn);
                        if (!DeviceObject.objFK623.IsOpen)
                        {
                            DeviceObject.objFK623.Open();
                        }
                        vnResultCode = DeviceObject.objFK623.EnableDevice(0);
                        state        = DeviceObject.objFK623.IsOpen;
                        if (state)
                        {
                            vnResultCode = DeviceObject.objFK623.ReadAllUserID();
                        }
                        else
                        {
                            lblMsg.ForeColor = Color.FromName("red");
                            lblMsg.Text      = DeviceObject.objFK623.GetRunMsg((int)enumErrorCode.RUNERR_NO_OPEN_COMM);
                        }

                        if (vnResultCode != (int)enumErrorCode.RUN_SUCCESS)
                        {
                            if (state)
                            {
                                lblMsg.ForeColor = Color.FromName("red");
                                lblMsg.Text      = (Pub.GetResText(formCode, "ErrorUnUserID", ""));
                            }
                            DeviceObject.objFK623.EnableDevice(1);
                            DeviceObject.objFK623.Close();
                            continue;
                        }

                        do
                        {
                            vnResultCode = DeviceObject.objFK623.GetAllUserID(
                                ref vEnrollNumber,
                                ref vBackupNumber,
                                ref vPrivilege,
                                ref vnEnableFlag);

                            if (vnResultCode != (int)enumErrorCode.RUN_SUCCESS)
                            {
                                DeviceObject.objFK623.EnableDevice(1);
                                DeviceObject.objFK623.Close();
                                break;
                            }
                            DeviceObject.objFK623.GetUserName(vEnrollNumber, ref UserName);
                            if (!selStringList.Contains(vEnrollNumber.ToString()) && vEnrollNumber != 0)
                            {
                                int index = this.cardGrid.Rows.Add();
                                // ((DataGridViewCheckBoxCell)cardGrid.Rows[index].Cells[0]).Value = true;
                                this.cardGrid.Rows[index].Cells[1].Value = vEnrollNumber.ToString();
                                this.cardGrid.Rows[index].Cells[2].Value = UserName;

                                selStringList.Add(vEnrollNumber.ToString());
                                EnrollNumberCount = index;
                                lblMsg.Text       = string.Format("{0}", index);
                            }
                            //EnrollNumberCount++;

                            lblMsg1.Text = Pub.GetResText(formCode, "btnGetListFromMac", "") + string.Format("-{0} /{1} ", EnrollNumberCount, EnrollNumberCount);
                            Application.DoEvents();
                            if (StopGet)
                            {
                                DeviceObject.objFK623.EnableDevice(1);
                                DeviceObject.objFK623.Close();
                                break;
                            }
                            if (Stop)
                            {
                                DeviceObject.objFK623.EnableDevice(1);
                                DeviceObject.objFK623.Close();
                                this.Close();
                            }
                        }while (true);
                        break;
                    }

                    cardGrid.Sort(this.cardGrid.Columns[1], ListSortDirection.Ascending);//排序
                    lblMsg.ForeColor      = Color.FromName("Black");
                    lblMsg.Text           = cardGrid.Rows.Count.ToString();
                    lblMsg1.Text          = Pub.GetResText(formCode, "MsgReadEndData", "");
                    progBar1.ProgressType = DevComponents.DotNetBar.eProgressItemType.Standard;
                    progBar1.Value        = 0;
                    StopGet          = false;
                    progBar1.Visible = false;
                    lblMsg1.Visible  = false;
                    btnStop.Visible  = false;
                }
            }
        }
Ejemplo n.º 2
0
        private bool GetValidity(int MacSN, string url, string name, string pwd, ref string MacMsg)
        {
            bool ret = false;

            byte[] Photo    = new byte[0];
            int    EmpCount = 0;

            DataRow[] rows    = null;
            DataRow[] empRows = null;
            string    EmpNo   = "";

            int PersonNum = 0;

            string jsonString = "";
            string StatusMsg  = lblMsg.Text;

            string StartDate = "NULL";
            string EndDate   = "NULL";

            byte[] CardData = new byte[0];
            string guid     = "";

            progBar.ProgressType = eProgressItemType.Standard;

            DataTable dtInsert    = new DataTable();
            DataTable dtUpdate    = new DataTable();
            DataTable dtSelect    = new DataTable();
            DataTable dtEmpSelect = new DataTable();

            try
            {
                dtInsert    = SystemInfo.db.GetDataTable(Pub.GetSQL(DBCode.DB_000300, new string[] { "519" }));
                dtUpdate    = SystemInfo.db.GetDataTable(Pub.GetSQL(DBCode.DB_000300, new string[] { "519" }));
                dtSelect    = SystemInfo.db.GetDataTable(Pub.GetSQL(DBCode.DB_000300, new string[] { "518", MacSN.ToString() }));
                dtEmpSelect = SystemInfo.db.GetDataTable(Pub.GetSQL(DBCode.DB_000101, new string[] { "27" }));

                //查询人员总数
                string                       searchTotlePersonUrl      = url + "action/SearchPersonNum";
                SearchTotlePerson            searchTotlePerson         = new SearchTotlePerson(Convert.ToInt32(MacSN), 0, "", "", 2, "0-100", 0, "");
                jsonBody <SearchTotlePerson> jsonBodySearchTotlePerson = new jsonBody <SearchTotlePerson>("SearchPersonNum", searchTotlePerson);
                jsonString = JsonConvert.SerializeObject(jsonBodySearchTotlePerson);
                ret        = DeviceObject.objFK623.POST_GetResponse(searchTotlePersonUrl, name, pwd, ref jsonString);
                if (!ret)
                {
                    return(false);
                }
                jsonBody <SearchTotlePersonInfo> searchTotlePersonInfo = JsonConvert.DeserializeObject <jsonBody <SearchTotlePersonInfo> >(jsonString);
                {
                    PersonNum = searchTotlePersonInfo.info.PersonNum;
                }
                if (PersonNum == 0)
                {
                    return(false);
                }

                int i = 0;
                while (true)
                {
                    //查询人员
                    string searchMultipleUrl            = url + "action/SearchPersonList";
                    SearchMultiplePerson searchMultiple = new SearchMultiplePerson(Convert.ToInt32(MacSN), 0, "", "", 2, "0-100", 0, "", i * 10, 10, 1);
                    i++;
                    jsonBody <SearchMultiplePerson> jsonBodySearchMultiplePerson = new jsonBody <SearchMultiplePerson>("SearchPersonList", searchMultiple);
ES:
                    jsonString = JsonConvert.SerializeObject(jsonBodySearchMultiplePerson);
                    ret        = DeviceObject.objFK623.POST_GetResponse(searchMultipleUrl, name, pwd, ref jsonString);
                    if (!ret)
                    {
                        if (DeviceObject.objFK623.SeaBodyStr().Equals(Pub.GetResText("", "FK_RUNERR_NO_OPEN_COMM", "")))
                        {
                            DialogResult MessRet = Pub.MessageBoxQuestion(DeviceObject.objFK623.SeaBodyStr() + "\r\n\r\n" +
                                                                          Pub.GetResText(formCode, "MsgContinue", ""), MessageBoxButtons.OKCancel);
                            if (MessRet == DialogResult.OK)
                            {
                                goto ES;
                            }
                            else
                            {
                                ret = false;
                                break;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                    jsonBody <SearchMultiplePersonInfo <SearchPersonInfo> > searchMultiplePersonInfo = JsonConvert.DeserializeObject <jsonBody <SearchMultiplePersonInfo <SearchPersonInfo> > >(jsonString);
                    {
                        for (int j = 0; j < searchMultiplePersonInfo.info.Listnum; j++)
                        {
                            EmpCount++;

                            if (searchMultiplePersonInfo.info.List[j].Tempvalid != 0)
                            {
                                StartDate = searchMultiplePersonInfo.info.List[j].ValidBegin;
                                EndDate   = searchMultiplePersonInfo.info.List[j].ValidEnd;
                            }
                            else
                            {
                                StartDate = null;
                                EndDate   = null;
                            }

                            empRows = dtEmpSelect.Select("FingerNo=" + searchMultiplePersonInfo.info.List[j].CustomizeID + "");
                            if (empRows.Length > 0)
                            {
                                EmpNo = empRows[0]["EmpNo"].ToString();
                                rows  = dtSelect.Select("EmpNo='" + EmpNo + "'");
                                if (rows.Length > 0)
                                {
                                    guid = rows[0]["GUID"].ToString();
                                    dtUpdate.Rows.Add(new object[] { guid, MacSN, EmpNo, OprtInfo.OprtNo, DateTime.Now.ToString(SystemInfo.SQLDateTimeFMT), StartDate, EndDate });
                                }
                                else
                                {
                                    dtInsert.Rows.Add(new object[] { GetGUID(), MacSN, EmpNo, OprtInfo.OprtNo, DateTime.Now.ToString(SystemInfo.SQLDateTimeFMT), StartDate, EndDate });
                                    dtSelect.Rows.Add(new object[] { GetGUID(), MacSN, EmpNo, OprtInfo.OprtNo, DateTime.Now.ToString(SystemInfo.SQLDateTimeFMT), StartDate, EndDate });
                                }
                            }

                            lblMsg.Text = StatusMsg + Pub.GetResText(formCode, "MsgFingerInfo", "") +
                                          string.Format(" - {2}/{3}  [{0}: {1}]", searchMultiplePersonInfo.info.List[j].CustomizeID, searchMultiplePersonInfo.info.List[j].Name, EmpCount, PersonNum);
                            if (EmpCount > 0)
                            {
                                progBar.Value = EmpCount * 100 / PersonNum;
                            }
                            Application.DoEvents();
                        }
                        if (dtInsert.Rows.Count > 0)
                        {
                            SystemInfo.db.batchEmpInSertData(dtInsert, "DI_SeaPower");
                            dtInsert.Clear();
                        }
                        if (dtUpdate.Rows.Count > 0)
                        {
                            SystemInfo.db.batchEmpUpdateData(dtUpdate, "DI_SeaPower", "GUID");
                            dtUpdate.Clear();
                        }
                    }
                }
            }
            catch (Exception E)
            {
                Pub.ShowErrorMsg(E);
            }
            finally
            {
                string tmp = Pub.GetResText(formCode, "MsgUpInfo", "");
                MacMsg = string.Format(tmp, PersonNum, EmpCount, EmpCount);
            }

            if (EmpCount > 0)
            {
                FK623Attend.SeaBody = Pub.GetResText("", "FK_RUN_SUCCESS", "");
                ret = true;
            }
            return(ret);
        }