Beispiel #1
0
        private void ExecDeviceCommand(int AutoType, string AutoName)
        {
            DateTime dt = new DateTime();

            if (!db.GetServerDate(ref dt))
            {
                return;
            }
            DataTable dtBlack = null;
            DataTable dtPower = null;
            byte      devType = 0;
            string    devName = "";

            QHKS.TConnInfo   connInfo;
            QHKS.TMJConnInfo mjConn;
            TConnInfoNewMJ   mjNewConn;
            TConnInfoFinger  connFinger;
            string           msg    = "";
            bool             state  = false;
            string           MacVer = "";
            int    RecordCount      = 0;
            int    RecordIndex      = 0;
            string dataMsg          = "";

            progBar.Style = ProgressBarStyle.Marquee;
            progBar.Value = 50;
            if ((AutoType == 2) || (AutoType == 4))
            {
                progBar.Style = ProgressBarStyle.Blocks;
                progBar.Value = 0;
            }
            if (AutoType == 3)
            {
                try
                {
                    dtBlack = db.GetDataTable(Pub.GetSQL(DBCode.DB_001003, new string[] { "501" }));
                }
                catch (Exception E)
                {
                    Pub.ShowErrorMsg(E);
                    return;
                }
            }
            for (int i = 0; i < tvMac.Nodes.Count; i++)
            {
                Application.DoEvents();
                if (!isRealing)
                {
                    break;
                }
                if (tvMac.StateImageList == null)
                {
                    if (!tvMac.Nodes[i].Checked)
                    {
                        continue;
                    }
                }
                else
                {
                    if (tvMac.Nodes[i].StateImageIndex == 0)
                    {
                        continue;
                    }
                }
                devType = Convert.ToByte(tvMac.Nodes[i].Tag);
                devName = tvMac.Nodes[i].Text;
                for (int j = 0; j < tvMac.Nodes[i].Nodes.Count; j++)
                {
                    Application.DoEvents();
                    if (!isRealing)
                    {
                        break;
                    }
                    if (tvMac.StateImageList == null)
                    {
                        if (!tvMac.Nodes[i].Nodes[j].Checked)
                        {
                            continue;
                        }
                    }
                    else
                    {
                        if (tvMac.Nodes[i].Nodes[j].StateImageIndex != 1)
                        {
                            continue;
                        }
                    }
                    switch (devType)
                    {
                    case 0:
                        connInfo = (QHKS.TConnInfo)tvMac.Nodes[i].Nodes[j].Tag;
                        switch (AutoType)
                        {
                        case 1://同步时间
                            msg = string.Format(Pub.GetResText(formCode, "MsgSyncTime", ""), devName, connInfo.MacSN);
                            break;

                        case 2://回收数据
                            msg = string.Format(Pub.GetResText(formCode, "MsgGetData", ""), devName, connInfo.MacSN);
                            break;

                        case 3://下载黑名单
                            msg = string.Format(Pub.GetResText(formCode, "MsgBlackKQ", ""), connInfo.MacSN);
                            break;

                        case 4://下载权限
                            msg = string.Format(Pub.GetResText(formCode, "MsgDownPower", ""), devName, connInfo.MacSN);
                            break;
                        }
                        MsgString = msg;
                        ShowMsg(msg);
                        DeviceObject.objKS.Init(ref connInfo);
                        state = DeviceObject.objKS.SysDeviceInfoGet(ref MacVer);
                        if (state)
                        {
                            DeviceObject.objKS.InitMacVer(MacVer);
                        }
                        switch (AutoType)
                        {
                        case 1://同步时间
                            if (state)
                            {
                                state = DeviceObject.objKS.PubTimeSet(dt);
                            }
                            UpdateMsg(state);
                            break;

                        case 2://回收数据
                            DeviceObject.objKS.SysSetState(false);
                            KQReadData readData = new KQReadData(this.Text + "[" + AutoName + "]", true);
                            if (state)
                            {
                                state = readData.ReadData(db, textFormat, connInfo.MacSN, ref RecordCount, ref RecordIndex,
                                                          false, ShowReadDataProcess);
                            }
                            DeviceObject.objKS.SysSetState(true);
                            UpdateMsg(state, string.Format("{0}/{1}", RecordIndex, RecordCount));
                            break;

                        case 3://下载黑名单
                            if (state)
                            {
                                KQDownBlack kqBlack = new KQDownBlack(dtBlack, connInfo);
                                if (state)
                                {
                                    state = kqBlack.Down();
                                }
                            }
                            UpdateMsg(state);
                            break;

                        case 4://下载权限
                            break;
                        }
                        break;

                    case 1:
                        if (SystemInfo.IsNewMJ)
                        {
                            mjNewConn = (TConnInfoNewMJ)tvMac.Nodes[i].Nodes[j].Tag;
                            switch (AutoType)
                            {
                            case 1://同步时间
                                msg = string.Format(Pub.GetResText(formCode, "MsgSyncTime", ""), devName, mjNewConn.MacSN);
                                break;

                            case 2://回收数据
                                msg = string.Format(Pub.GetResText(formCode, "MsgGetData", ""), devName, mjNewConn.MacSN);
                                break;

                            case 3://下载黑名单
                                msg = string.Format(Pub.GetResText(formCode, "MsgBlackMJ", ""), mjNewConn.MacSN);
                                break;

                            case 4://下载权限
                                msg = string.Format(Pub.GetResText(formCode, "MsgDownPower", ""), devName, mjNewConn.MacSN);
                                break;
                            }
                            MsgString = msg;
                            ShowMsg(msg);
                            DeviceObject.objMJNew.NewDevice(mjNewConn);
                            switch (AutoType)
                            {
                            case 1://同步时间
                                AccessV2API.TYPE_Setting setting = new AccessV2API.TYPE_Setting();
                                state = DeviceObject.objMJNew.ReadSetting(out setting);
                                if (state)
                                {
                                    DeviceObject.objMJNew.DateTimeToMJDateTime(dt, ref setting.DateTime);
                                    state = DeviceObject.objMJNew.SetSetting(setting);
                                }
                                UpdateMsg(state);
                                break;

                            case 2://回收数据
                                MJReadData readData = new MJReadData(this.Text + "[" + AutoName + "]");
                                state = readData.ReadDataNew(db, mjNewConn.MacSN.ToString(), ref RecordCount, ref RecordIndex, ShowReadDataProcess);
                                UpdateMsg(state, string.Format("{0}/{1}", RecordIndex, RecordCount));
                                break;

                            case 3://下载黑名单
                                MJDownBlack mjBlack = new MJDownBlack(dtBlack, mjNewConn);
                                state = mjBlack.DownNew();
                                UpdateMsg(state);
                                break;

                            case 4://下载权限
                                RecordIndex = 0;
                                RecordCount = 0;
                                try
                                {
                                    dtPower = db.GetDataTable(Pub.GetSQL(DBCode.DB_003004, new string[] { "0", "" }));
                                    state   = DeviceObject.objMJNew.ClearRegister();
                                    if (state)
                                    {
                                        bool   IsE         = false;
                                        byte   DoorID      = 0;
                                        UInt32 cardNo      = 0;
                                        UInt32 OtherCardNo = 0;
                                        string EmpNo       = "";
                                        string EmpName     = "";
                                        string EmpPass     = "";
                                        AccessV2API.TYPE_Register Register;
                                        RecordCount = dtPower.Rows.Count;
                                        for (int k = 0; k < RecordCount; k++)
                                        {
                                            ShowReadDataProcess(RecordCount, k + 1);
                                            IsE    = dtPower.Rows[k]["IsEnable"].ToString().ToUpper() == "Y";
                                            DoorID = Convert.ToByte(dtPower.Rows[k]["MacDoorID"].ToString());
                                            UInt32.TryParse(dtPower.Rows[k]["CardPhysicsNo10"].ToString(), out cardNo);
                                            UInt32.TryParse(dtPower.Rows[k]["OtherCardNo"].ToString(), out OtherCardNo);
                                            EmpNo   = DeviceObject.objMJNew.GetLengthText(dtPower.Rows[k]["EmpNo"].ToString(), 16);
                                            EmpName = DeviceObject.objMJNew.GetLengthText(dtPower.Rows[k]["EmpName"].ToString(), 16);
                                            EmpPass = DeviceObject.objMJNew.GetLengthText(dtPower.Rows[k]["CardPWD"].ToString(), 8);
                                            if (EmpPass == null)
                                            {
                                                EmpPass = "";
                                            }
                                            EmpPass = EmpPass.Length > 8 ? EmpPass.Substring(0, 8) : EmpPass;
                                            if (IsE)
                                            {
                                                if (cardNo > 0)
                                                {
                                                    Register          = new AccessV2API.TYPE_Register();
                                                    Register.CardNo   = cardNo;
                                                    Register.Door     = DoorID;
                                                    Register.Password = EmpPass;
                                                    UInt32.TryParse(dtPower.Rows[k]["MacTimeNo"].ToString(), out Register.TimeGroup);
                                                    DeviceObject.objMJNew.DateTimeToMJDateTime(Convert.ToDateTime(dtPower.Rows[k]["CardStartDate"].ToString()), ref Register.DateBegin);
                                                    DeviceObject.objMJNew.DateTimeToMJDateTime(Convert.ToDateTime(dtPower.Rows[k]["CardEndDate"].ToString()), ref Register.DateEnd);
                                                    Register.UserID   = EmpNo;
                                                    Register.UserName = EmpName;
                                                    state             = DeviceObject.objMJNew.AddRegister(Register);
                                                }
                                                if (state && OtherCardNo > 0)
                                                {
                                                    Register          = new AccessV2API.TYPE_Register();
                                                    Register.CardNo   = OtherCardNo;
                                                    Register.Door     = DoorID;
                                                    Register.Password = EmpPass;
                                                    UInt32.TryParse(dtPower.Rows[k]["MacTimeNo"].ToString(), out Register.TimeGroup);
                                                    DeviceObject.objMJNew.DateTimeToMJDateTime(Convert.ToDateTime(dtPower.Rows[k]["CardStartDate"].ToString()), ref Register.DateBegin);
                                                    DeviceObject.objMJNew.DateTimeToMJDateTime(Convert.ToDateTime(dtPower.Rows[k]["CardEndDate"].ToString()), ref Register.DateEnd);
                                                    Register.UserID   = EmpNo;
                                                    Register.UserName = EmpName;
                                                    state             = DeviceObject.objMJNew.AddRegister(Register);
                                                }
                                            }
                                            else
                                            {
                                                state = true;
                                            }
                                            if (!state)
                                            {
                                                break;
                                            }
                                            RecordIndex++;
                                        }
                                    }
                                }
                                catch (Exception E)
                                {
                                    state = false;
                                    Pub.ShowErrorMsg(E);
                                }
                                UpdateMsg(state, string.Format("{0}/{1}", RecordIndex, RecordCount));
                                break;
                            }
                        }
                        else
                        {
                            mjConn = (QHKS.TMJConnInfo)tvMac.Nodes[i].Nodes[j].Tag;
                            switch (AutoType)
                            {
                            case 1://同步时间
                                msg = string.Format(Pub.GetResText(formCode, "MsgSyncTime", ""), devName, mjConn.MacSN);
                                break;

                            case 2://回收数据
                                msg = string.Format(Pub.GetResText(formCode, "MsgGetData", ""), devName, mjConn.MacSN);
                                break;

                            case 3://下载黑名单
                                msg = string.Format(Pub.GetResText(formCode, "MsgBlackMJ", ""), mjConn.MacSN);
                                break;

                            case 4://下载权限
                                msg = string.Format(Pub.GetResText(formCode, "MsgDownPower", ""), devName, mjConn.MacSN);
                                break;
                            }
                            MsgString = msg;
                            ShowMsg(msg);
                            DeviceObject.objMJ.Init(ref mjConn);
                            switch (AutoType)
                            {
                            case 1://同步时间
                                state = DeviceObject.objMJ.SetMacTime(dt);
                                UpdateMsg(state);
                                break;

                            case 2://回收数据
                                MJReadData readData = new MJReadData(this.Text + "[" + AutoName + "]");
                                state = readData.ReadData(db, mjConn.MacSN, ref RecordCount, ref RecordIndex, ShowReadDataProcess);
                                UpdateMsg(state, string.Format("{0}/{1}", RecordIndex, RecordCount));
                                break;

                            case 3://下载黑名单
                                MJDownBlack mjBlack = new MJDownBlack(dtBlack, mjConn);
                                state = mjBlack.Down();
                                UpdateMsg(state);
                                break;

                            case 4://下载权限
                                RecordIndex = 0;
                                RecordCount = 0;
                                try
                                {
                                    dtPower = db.GetDataTable(Pub.GetSQL(DBCode.DB_003004, new string[] { "0", "" }));
                                    state   = DeviceObject.objMJ.ClearMacPower();
                                    if (state)
                                    {
                                        bool   IsE         = false;
                                        byte   DoorID      = 0;
                                        string cardNo      = "";
                                        string OtherCardNo = "";
                                        QHKS.TMJUpPowerInfo power;
                                        RecordCount = dtPower.Rows.Count;
                                        for (int k = 0; k < RecordCount; k++)
                                        {
                                            ShowReadDataProcess(RecordCount, k + 1);
                                            IsE         = dtPower.Rows[k]["IsEnable"].ToString().ToUpper() == "Y";
                                            DoorID      = Convert.ToByte(dtPower.Rows[k]["MacDoorID"].ToString());
                                            cardNo      = dtPower.Rows[k]["CardPhysicsNo10"].ToString();
                                            OtherCardNo = dtPower.Rows[k]["OtherCardNo"].ToString();
                                            if (IsE)
                                            {
                                                power             = new QHKS.TMJUpPowerInfo();
                                                power.CardNo      = cardNo;
                                                power.OtherCardNo = OtherCardNo;
                                                power.StartDate   = Convert.ToDateTime(dtPower.Rows[k]["CardStartDate"].ToString());
                                                power.EndDate     = Convert.ToDateTime(dtPower.Rows[k]["CardEndDate"].ToString());
                                                power.Password    = dtPower.Rows[k]["CardPWD"].ToString();
                                                power.EmpNo       = dtPower.Rows[k]["EmpNo"].ToString();
                                                power.EmpName     = dtPower.Rows[k]["EmpName"].ToString();
                                                power.DoorID      = DoorID;
                                                byte.TryParse(dtPower.Rows[k]["MacTimeNo"].ToString(), out power.TimeID);
                                                state = DeviceObject.objMJ.SetMacUpPowerInfo(ref power);
                                            }
                                            else
                                            {
                                                state = true;
                                            }
                                            if (!state)
                                            {
                                                break;
                                            }
                                            RecordIndex++;
                                        }
                                    }
                                }
                                catch (Exception E)
                                {
                                    state = false;
                                    Pub.ShowErrorMsg(E);
                                }
                                UpdateMsg(state, string.Format("{0}/{1}", RecordIndex, RecordCount));
                                break;
                            }
                        }
                        break;

                    case 2:
                        connInfo = (QHKS.TConnInfo)tvMac.Nodes[i].Nodes[j].Tag;
                        switch (AutoType)
                        {
                        case 1://同步时间
                            msg = string.Format(Pub.GetResText(formCode, "MsgSyncTime", ""), devName, connInfo.MacSN);
                            break;

                        case 2://回收数据
                            msg = string.Format(Pub.GetResText(formCode, "MsgGetData", ""), devName, connInfo.MacSN);
                            break;

                        case 3://下载黑名单
                            msg = string.Format(Pub.GetResText(formCode, "MsgBlackSF", ""), connInfo.MacSN);
                            break;

                        case 4://下载权限
                            msg = string.Format(Pub.GetResText(formCode, "MsgDownPower", ""), devName, connInfo.MacSN);
                            break;
                        }
                        MsgString = msg;
                        ShowMsg(msg);
                        DeviceObject.objKS.Init(ref connInfo);
                        state = DeviceObject.objKS.SysDeviceInfoGet(ref MacVer);
                        if (state)
                        {
                            DeviceObject.objKS.InitMacVer(MacVer);
                        }
                        switch (AutoType)
                        {
                        case 1://同步时间
                            if (state)
                            {
                                state = DeviceObject.objKS.PubTimeSet(dt);
                            }
                            UpdateMsg(state);
                            break;

                        case 2://回收数据
                            DeviceObject.objKS.SysSetState(false);
                            SFReadData readData = new SFReadData(this.Text + "[" + AutoName + "]", true);
                            if (state)
                            {
                                state = readData.ReadData(db, connInfo.MacSN, connInfo.MacType, ref dataMsg, false,
                                                          ShowSFReadDataProcess);
                            }
                            DeviceObject.objKS.SysSetState(true);
                            UpdateMsg(state, dataMsg);
                            break;

                        case 3://下载黑名单
                            if (state)
                            {
                                SFDownBlack sfBlack = new SFDownBlack(dtBlack, connInfo);
                                if (state)
                                {
                                    state = sfBlack.Down();
                                }
                            }
                            UpdateMsg(state);
                            break;

                        case 4://下载权限
                            break;
                        }
                        break;

                    case 3:
                        connFinger = (TConnInfoFinger)tvMac.Nodes[i].Nodes[j].Tag;
                        switch (AutoType)
                        {
                        case 1://同步时间
                            msg = string.Format(Pub.GetResText(formCode, "MsgSyncTime", ""), devName, connFinger.MacSN);
                            break;

                        case 2://回收数据
                            msg = string.Format(Pub.GetResText(formCode, "MsgGetData", ""), devName, connFinger.MacSN);
                            break;

                        case 3://下载黑名单
                            break;

                        case 4://下载权限
                            break;
                        }
                        MsgString = msg;
                        ShowMsg(msg);
                        DeviceObject.objFK623.InitConn(connFinger);
                        switch (AutoType)
                        {
                        case 1://同步时间
                            DeviceObject.objFK623.Open();
                            state = DeviceObject.objFK623.IsOpen;
                            if (state)
                            {
                                state = DeviceObject.objFK623.SetDeviceTime(dt);
                            }
                            DeviceObject.objFK623.Close();
                            UpdateMsg(state);
                            break;

                        case 2://回收数据
                            FingerReadData readData = new FingerReadData(this.Text + "[" + AutoName + "]", 1);
                            state = readData.FK623ReadData(db, textFormat, connFinger.MacSN, ref RecordCount,
                                                           ref RecordIndex, ShowReadDataProcess);
                            UpdateMsg(state, string.Format("{0}/{1}", RecordIndex, RecordCount));
                            break;

                        case 3://下载黑名单
                            break;

                        case 4://下载权限
                            break;
                        }
                        break;
                    }
                }
            }
            if (dtBlack != null)
            {
                dtBlack.Reset();
            }
            if (dtPower != null)
            {
                dtPower.Reset();
            }
            db.WriteSYLog(this.Text, AutoName, lblMsg.Text);
        }
Beispiel #2
0
        protected override bool ExecMacCommand(byte flag, int MacSN, ref string MacMsg)
        {
            bool ret     = base.ExecMacCommand(flag, MacSN, ref MacMsg);
            byte MacType = 0;

            if ((flag == 0) || (flag == 1))
            {
                MacType = Convert.ToByte(GetMacType(MacSN.ToString()));
            }
            bool IsNew = false;

            if (flag == 0)
            {
                IsNew = true;
            }
            if (readData == null)
            {
                readData = new SFReadData(this.Text + "[" + CurrentTool + "]", IsNew);
            }
            currflag = flag;
            string dataMsg = "";

            switch (flag)
            {
            case 0:
            case 1:
                DeviceObject.objKS.SysSetState(false);
                MsgString     = lblMsg.Text;
                progBar.Style = ProgressBarStyle.Blocks;
                progBar.Value = 0;
                ret           = readData.ReadData(db, MacSN, MacType, ref dataMsg, false, ShowReadDataProcess);
                MacMsg        = dataMsg;
                break;

            case 2:
                RefreshMsg(CurrentTool + "[" + usbFile + "]......");
                MsgString     = lblMsg.Text;
                progBar.Style = ProgressBarStyle.Blocks;
                progBar.Value = 0;
                ret           = readData.ReadDataUSB(usbFile, db, ref dataMsg, ShowReadDataProcess);
                MacMsg        = dataMsg;
                lblMsg.Text   = MsgString + MacMsg;

                break;

            case 3:
                RefreshMsg(CurrentTool + "[" + usbFile + "]......");
                MsgString     = lblMsg.Text;
                progBar.Style = ProgressBarStyle.Blocks;
                progBar.Value = 0;
                ret           = readData.ReadDataText(usbFile, db, ref dataMsg, ShowReadDataProcess);
                MacMsg        = dataMsg;
                lblMsg.Text   = MsgString + MacMsg;
                progBar.Style = ProgressBarStyle.Blocks;
                progBar.Value = 0;
                break;
            }
            if (flag == 0 || flag == 1)
            {
                DeviceObject.objKS.SysSetState(true);
            }
            readData = null;

            return(ret);
        }