示例#1
0
 private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.RowIndex >= 0)
     {
         DataGridViewRow row  = dataGridView1.Rows[e.RowIndex];
         Controller      ctrl = (Controller)row.Tag;
         if (this.dataGridView1.ColumnCount == e.ColumnIndex + 2)//修改IP
         {
             if (MessageBox.Show("确定修改设备地址?", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
             {
                 ctrl.ip      = row.Cells[2].Value.ToString();
                 ctrl.mask    = row.Cells[3].Value.ToString();
                 ctrl.gateway = row.Cells[4].Value.ToString();
                 IAccessCore access = new WGAccess();
                 access.SetControllerIP(ctrl);
             }
         }
         else if (this.dataGridView1.ColumnCount == e.ColumnIndex + 1)//获取控制器状态
         {
             IAccessCore     access = new WGAccess();
             ControllerState state  = access.GetControllerState(ctrl);
             MessageBox.Show(state.lastRecordIndex + " " + state.reasonNo.ToString());
         }
     }
 }
示例#2
0
        private void DoSearch(int waitminisecond = 0)
        {
            CtrlWaiting ctrlWaiting = new CtrlWaiting("搜索控制器中...", new Action(() =>
            {
                if (waitminisecond > 0)
                {
                    Thread.Sleep(waitminisecond);//需要等待控制器修改IP后重启
                }
                IAccessCore access       = new WGAccess();
                List <Controller> ctrlrs = access.SearchController();
                var dataCtrls            = ControllerHelper.GetList("1=1", false);
                if (ctrlrs == null || ctrlrs.Count == 0)
                {
                    WinInfoHelper.ShowInfoWindow(this, "没有查询到控制器!", 5);
                }
                else
                {
                    this.Invoke(new Action(() =>
                    {
                        AddControllerToGrid(ctrlrs, dataCtrls);
                    }));
                }
            }));

            ctrlWaiting.Show(this);
        }
示例#3
0
        private void tsmiResetRecord_Click(object sender, EventArgs e)
        {
            DataGridViewRow row = GetSelectRow();

            if (row == null)
            {
                WinInfoHelper.ShowInfoWindow(this, "未有选择控制器!");
                return;
            }
            Maticsoft.Model.SMT_CONTROLLER_INFO ctrlInfo = (Maticsoft.Model.SMT_CONTROLLER_INFO)row.Tag;
            if (MessageBox.Show("确定恢复该控制器" + ctrlInfo.NAME + "记录读取?", "确定", MessageBoxButtons.OKCancel) != DialogResult.OK)
            {
                return;
            }

            CtrlWaiting waiting = new CtrlWaiting(() =>
            {
                try
                {
                    IAccessCore acc = new WGAccess();
                    var c           = ControllerHelper.ToController(ctrlInfo);
                    bool ret        = acc.SetControllerReadedIndex(c, 0);
                    WinInfoHelper.ShowInfoWindow(this, "恢复控制器" + ctrlInfo.NAME + "记录" + (ret ? "成功!" : "失败!"));
                }
                catch (Exception ex)
                {
                    log.Error("恢复控制器记录异常:", ex);
                    WinInfoHelper.ShowInfoWindow(this, "恢复控制器" + ctrlInfo.NAME + "记录异常:" + ex.Message);
                }
            });

            waiting.Show(this);
        }
示例#4
0
 private void Read()
 {
     try
     {
         while (_isRun)
         {
             try
             {
                 IAccessCore     ac    = new WGAccess();
                 ControllerState state = ac.GetControllerState(_controler);
                 //var s=  ac.GetControllerRecord(_controler, -1);
                 DoCallBack(state != null, state);
             }
             catch (ThreadAbortException)
             {
                 throw;
             }
             catch (Exception)
             {
                 if (!_isRun)
                 {
                     return;
                 }
                 DoCallBack(false, null);
             }
             Thread.Sleep(_scanInterval);
         }
     }
     catch (Exception)
     {
         return;
     }
 }
示例#5
0
        public void StartReadRecord()
        {
            log.Info("开始读取记录:" + _controller.sn);
            using (IAccessCore acc = new WGAccess())
            {
                try
                {
                    if (acc.BeginReadRecord(Controller))
                    {
                        try
                        {
                            while (true)
                            {
                                ControllerState record = acc.ReadNextRecord();
                                if (record == null || record.recordType == RecordType.NoRecord)
                                {
                                    log.Info("记录读取完毕:" + _controller.sn);
                                    break;
                                }
                                try
                                {
                                    RecordTaskService.Instance.SaveRecord(_controller.id, record);
                                }
                                catch (Exception ex)
                                {
                                    if (record.lastRecordIndex <= 0)
                                    {
                                        record.lastRecordIndex = 0xffffffff;
                                    }
                                    else
                                    {
                                        record.lastRecordIndex--;
                                    }
                                    acc.SetControllerReadedIndex(Controller, record.lastRecordIndex);
                                    return;
                                }
                            }
                        }
                        finally
                        {
                            acc.EndReadRecord();
                        }
                    }

                    ControllerState state = acc.GetControllerState(Controller);
                    if (state != null)
                    {
                        RecordTaskService.Instance.SaveState(_controller.id, state);
                    }
                }
                catch (Exception ex)
                {
                    RecordTaskService.Instance.SaveState(_controller.id, null);
                    throw ex;
                }
            }
        }
示例#6
0
        private void btnResetRecord_Click(object sender, EventArgs e)
        {
            IAccessCore access = new WGAccess();
            Controller  ctrl   = GetSelectedController();

            if (ctrl == null)
            {
                return;
            }
            access.SetControllerReadedIndex(ctrl, 0);
        }
示例#7
0
        private void tsmiResetIP_Click(object sender, EventArgs e)
        {
            var rows = GetSelectedRows();

            if (rows.Count == 0)
            {
                WinInfoHelper.ShowInfoWindow(this, "请选择控制器!");
            }
            else
            {
                if (MessageBox.Show("确定恢复选择控制器IP?", "提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                {
                    return;
                }
                CtrlWaiting waiting = new CtrlWaiting(() =>
                {
                    List <ManualResetEvent> evts = new List <ManualResetEvent>();
                    foreach (var item in rows)
                    {
                        Controller c         = (Controller)item.Tag;
                        ManualResetEvent evt = new ManualResetEvent(false);
                        evts.Add(evt);
                        ThreadPool.QueueUserWorkItem(new WaitCallback((o) =>
                        {
                            try
                            {
                                using (IAccessCore ac = new WGAccess())
                                {
                                    c.ip      = "192.168.0.0";
                                    c.mask    = "255.255.255.0";
                                    c.gateway = "192.168.0.254";
                                    ac.SetControllerIP(c);
                                }
                            }
                            catch (Exception ex)
                            {
                                WinInfoHelper.ShowInfoWindow(this, c.sn + "重置IP异常:" + ex.Message);
                            }
                            finally
                            {
                                evt.Set();
                            }
                        }));
                    }
                    foreach (var item in evts)
                    {
                        item.WaitOne(30000);
                    }
                });
                waiting.Show(this);
            }
        }
示例#8
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            _ctrller.ip      = ipAdd.Value;
            _ctrller.mask    = ipMask.Value;
            _ctrller.gateway = ipGateway.Value;


            IAccessCore access = new WGAccess();

            access.SetControllerIP(_ctrller);
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
示例#9
0
        private void btnSetTime_Click(object sender, EventArgs e)
        {
            Controller ctrl = GetSelectedController();

            if (ctrl == null)
            {
                return;
            }
            IAccessCore access = new WGAccess();
            bool        ret    = access.SetControllerTime(ctrl, dateTimePicker1.Value);

            MessageBox.Show("设置" + (ret ? "成功!" : "失败"));
        }
示例#10
0
        private void btnOpenRemoteDoor_Click(object sender, EventArgs e)
        {
            Controller ctrl = GetSelectedController();

            if (ctrl == null)
            {
                return;
            }
            IAccessCore access = new WGAccess();
            bool        ret    = access.OpenRemoteControllerDoor(ctrl, (int)iintValue.Value);

            MessageBox.Show("远程开门" + (ret ? "成功" : "失败"));
        }
示例#11
0
        private void btnGetReadedIndex_Click(object sender, EventArgs e)
        {
            Controller ctrl = GetSelectedController();

            if (ctrl == null)
            {
                return;
            }
            IAccessCore access = new WGAccess();
            long        index  = access.GetControllerReadedIndex(ctrl);

            MessageBox.Show("已读记录:index=" + index);
        }
示例#12
0
        private void btnReadRecord_Click(object sender, EventArgs e)
        {
            Controller ctrl = GetSelectedController();

            if (ctrl == null)
            {
                return;
            }
            IAccessCore     access = new WGAccess();
            ControllerState state  = access.GetControllerRecord(ctrl, 0);

            MessageBox.Show("记录:index=" + state.lastRecordIndex + " reasonNo=" + state.reasonNo + " time=" + state.recordTime);
        }
示例#13
0
        private void btnGetTime_Click(object sender, EventArgs e)
        {
            Controller ctrl = GetSelectedController();

            if (ctrl == null)
            {
                return;
            }
            IAccessCore access = new WGAccess();
            DateTime    dt     = access.GetControllerTime(ctrl);

            dateTimePicker1.Value = dt;
        }
示例#14
0
        private void btnRevIP_Click(object sender, EventArgs e)
        {
            IAccessCore access = new WGAccess();
            Controller  ctrl   = GetSelectedController();

            if (ctrl == null)
            {
                return;
            }
            string ip   = "";
            int    port = 0;

            if (access.GetReceiveServer(ctrl, ref ip, ref port))
            {
                MessageBox.Show("Server IP:" + ip + ",Port:" + port);
            }
        }
示例#15
0
        private void btnSetTime_Click(object sender, EventArgs e)
        {
            Controller ctrl = GetSelectedController();

            if (ctrl == null)
            {
                return;
            }
            if (dtpTime.ValueObject == null)
            {
                WinInfoHelper.ShowInfoWindow(this, "请选择时间!");
                return;
            }
            using (IAccessCore access = new WGAccess())
            {
                bool ret = access.SetControllerTime(ctrl, dtpTime.Value);
                WinInfoHelper.ShowInfoWindow(this, "设置时间" + (ret ? "成功!" : "失败"));
            }
        }
示例#16
0
        private void btnAddAuth_Click(object sender, EventArgs e)
        {
            Controller ctrl = GetSelectedController();

            if (ctrl == null)
            {
                return;
            }
            IAccessCore            access = new WGAccess();
            Dictionary <int, bool> dic    = new Dictionary <int, bool>();

            dic.Add(1, true);
            dic.Add(2, true);

//             bool ret = access.AddOrModifyAuthority(ctrl, (long)iintValue.Value,
//                 DateTime.Now, DateTime.Now.AddDays(10), dic
//                 );
//             MessageBox.Show("设置权限" + (ret ? "成功" : "失败"));
        }
示例#17
0
        private void button1_Click(object sender, EventArgs e)
        {
            IAccessCore       access = new WGAccess();
            List <Controller> ctrls  = access.SearchController();

            dataGridView1.Rows.Clear();
            foreach (var item in ctrls)
            {
                string door = "";
                switch (item.doorType)
                {
                case ControllerDoorType.OneDoorTwoDirections:
                    door = "单门双向";
                    break;

                case ControllerDoorType.TwoDoorsTwoDirections:
                    door = "双门双向";
                    break;

                case ControllerDoorType.FourDoorsOneDirection:
                    door = "四门单向";
                    break;

                default:
                    break;
                }
                DataGridViewRow row = new DataGridViewRow();
                row.CreateCells(dataGridView1,
                                item.sn,
                                door,
                                item.ip,
                                item.mask,
                                item.gateway,
                                item.mac,
                                item.driverVersion,
                                item.driverReleaseTime,
                                "确定修改",
                                "获取状态"
                                );
                row.Tag = item;
                dataGridView1.Rows.Add(row);
            }
        }
示例#18
0
        private void tsmiRecordButton_Click(object sender, EventArgs e)
        {
            DataGridViewRow row = GetSelectRow();

            if (row == null)
            {
                WinInfoHelper.ShowInfoWindow(this, "未有选择控制器!");
                return;
            }
            Maticsoft.Model.SMT_CONTROLLER_INFO ctrlInfo = (Maticsoft.Model.SMT_CONTROLLER_INFO)row.Tag;
            CtrlWaiting waiting = new CtrlWaiting(() =>
            {
                try
                {
                    IAccessCore access = new WGAccess();
                    var c    = ControllerHelper.ToController(ctrlInfo);
                    bool ret = access.SetRecordButtonRecords(c, !ctrlInfo.ENABLE_BUTTON_RECORD);
                    if (!ret)
                    {
                        WinInfoHelper.ShowInfoWindow(this, "设置按钮记录状态失败!");
                    }
                    else
                    {
                        Maticsoft.BLL.SMT_CONTROLLER_INFO ctrlBll = new Maticsoft.BLL.SMT_CONTROLLER_INFO();
                        ctrlInfo.ENABLE_BUTTON_RECORD             = !ctrlInfo.ENABLE_BUTTON_RECORD;
                        ctrlBll.Update(ctrlInfo);
                    }
                }
                catch (System.Exception ex)
                {
                    log.Error("设置按钮记录状态异常:", ex);
                    WinInfoHelper.ShowInfoWindow(this, "设置按钮记录状态异常:" + ex.Message);
                }
            });

            waiting.Show(this);
        }
示例#19
0
 private void DoDelete(DataGridViewRow row)
 {
     if (MessageBox.Show("确定删除该控制器?", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
     {
         CtrlWaiting ctrlWaiting = new CtrlWaiting("正在删除中...", () =>
         {
             try
             {
                 Maticsoft.Model.SMT_CONTROLLER_INFO ctrlr = (Maticsoft.Model.SMT_CONTROLLER_INFO)row.Tag;
                 DialogResult dr = DialogResult.No;
                 this.Invoke(new Action(() =>
                 {
                     dr = MessageBox.Show("是否清除该控制器权限?", "提示", MessageBoxButtons.YesNo);
                 }));
                 if (dr == DialogResult.Yes)
                 {
                     Controller c = ControllerHelper.ToController(ctrlr);
                     using (IAccessCore ac = new WGAccess())
                     {
                         try
                         {
                             bool ret = ac.ClearAuthority(c);
                             if (!ret)
                             {
                                 this.Invoke(new Action(() =>
                                 {
                                     dr = MessageBox.Show("清除控制器权限失败(控制器可能离线),是否继续删除控制器?", "提示", MessageBoxButtons.YesNo);
                                 }));
                                 if (dr == DialogResult.No)
                                 {
                                     return;
                                 }
                             }
                         }
                         catch (Exception ex)
                         {
                             log.Error("清除控制器权限失败(控制器可能离线)(删除控制器):", ex);
                             this.Invoke(new Action(() =>
                             {
                                 dr = MessageBox.Show("清除控制器权限失败(控制器可能离线),是否继续删除控制器?", "提示", MessageBoxButtons.YesNo);
                             }));
                             if (dr == DialogResult.No)
                             {
                                 return;
                             }
                         }
                     }
                 }
                 Maticsoft.BLL.SMT_CONTROLLER_INFO ctrlBll = new Maticsoft.BLL.SMT_CONTROLLER_INFO();
                 ctrlBll.Delete(ctrlr.ID);
                 //置门关联控制器为空
                 Maticsoft.DBUtility.DbHelperSQL.ExecuteSql("update SMT_DOOR_INFO set CTRL_ID=-1,CTRL_DOOR_INDEX=0 where CTRL_ID=" + ctrlr.ID);
                 SmtLog.Info("设备", "控制器删除:" + ctrlr.IP + "," + ctrlr.NAME);
                 this.Invoke(new Action(() =>
                 {
                     dgvCtrlr.Rows.Remove(row);
                 }));
             }
             catch (System.Exception ex)
             {
                 log.Error("删除控制器异常:", ex);
                 WinInfoHelper.ShowInfoWindow(this, "删除失败:" + ex.Message);
             }
         });
         ctrlWaiting.Show(this);
     }
 }
示例#20
0
        private void DoUpload()
        {
            CtrlWaiting waiting = new CtrlWaiting(() =>
            {
                var ctrls = ControllerHelper.GetList("1=1");
                if (ctrls.Count == 0)
                {
                    WinInfoHelper.ShowInfoWindow(this, "没有控制器!");
                    return;
                }
                Maticsoft.BLL.SMT_TIMESCALE_INFO tsBll = new Maticsoft.BLL.SMT_TIMESCALE_INFO();
                var models = tsBll.GetModelList("");
                models     = models.OrderBy(m => m.TIME_NO).ToList();//时段升序
                Maticsoft.BLL.SMT_WEEKEX_INFO wbll = new Maticsoft.BLL.SMT_WEEKEX_INFO();
                var weekexs = wbll.GetModelList("");

                SmtLog.Info("设置", "上传时间段设置");
                FrmDetailInfo.Show(false);
                FrmDetailInfo.AddOneMsg(string.Format("开始上传控制器时段:控制器数={0},时段数={1} ...", ctrls.Count, models.Count));
                List <ManualResetEvent> eventList = new List <ManualResetEvent>();
                foreach (var item in ctrls)
                {
                    ManualResetEvent evt = new ManualResetEvent(false);
                    eventList.Add(evt);
                    ThreadPool.QueueUserWorkItem(new WaitCallback((o) =>
                    {
                        try
                        {
                            var ctrl = ControllerHelper.ToController(item);
                            using (IAccessCore acc = new WGAccess())
                            {
                                if (acc.ClearTimeScales(ctrl))
                                {
                                    FrmDetailInfo.AddOneMsg(string.Format("清除控制器时间段成功:SN={0},IP={1},开始上传控制器时间段...", ctrl.sn, ctrl.ip));
                                    foreach (var model in models)
                                    {
                                        var m    = TimeScaleHelper.ToTimeScale(model);
                                        bool ret = acc.SetTimeScales(ctrl, m);
                                        if (!ret)
                                        {
                                            FrmDetailInfo.AddOneMsg(string.Format("上传控制器时间段失败:时段号={0},控制器IP={1}", model.TIME_NO, ctrl.ip), isRed: true);
                                        }
                                        else
                                        {
                                            FrmDetailInfo.AddOneMsg(string.Format("上传控制器时间段成功:时段号={0},控制器IP={1}", model.TIME_NO, ctrl.ip));
                                        }
                                    }
                                }
                                else
                                {
                                    FrmDetailInfo.AddOneMsg(string.Format("清除控制器时间段失败:SN={0},IP={1},结束该控制器上传...", ctrl.sn, ctrl.ip), isRed: true);
                                }

                                if (acc.SetHoliday(ctrl, new HolidayPrm()
                                {
                                    IsClear = true,
                                    startDate = DateTime.Now,
                                    endDate = DateTime.Now.AddDays(1)
                                }))
                                {
                                    FrmDetailInfo.AddOneMsg(string.Format("清除控制器假期约束成功:SN={0},IP={1},开始上传假期约束...", ctrl.sn, ctrl.ip));
                                    foreach (var w in weekexs)
                                    {
                                        bool ret = acc.SetHoliday(ctrl, new HolidayPrm()
                                        {
                                            IsClear   = false,
                                            IsOnDuty  = w.WEEKEX_ON_DUTY,
                                            startDate = w.WEEKEX_START_DATE,
                                            endDate   = w.WEEKEX_END_DATE
                                        });
                                        if (!ret)
                                        {
                                            FrmDetailInfo.AddOneMsg(string.Format("上传控制器假期约束失败:约束={0},起止时间={1}~{2},控制器IP={3}", w.WEEKEX_ON_DUTY ? "上班" : "假期", w.WEEKEX_START_DATE, w.WEEKEX_END_DATE, ctrl.ip), isRed: true);
                                        }
                                        else
                                        {
                                            FrmDetailInfo.AddOneMsg(string.Format("上传控制器假期约束成功:约束={0},起止时间={1}~{2},控制器IP={3}", w.WEEKEX_ON_DUTY ? "上班" : "假期", w.WEEKEX_START_DATE, w.WEEKEX_END_DATE, ctrl.ip));
                                        }
                                    }
                                }
                                else
                                {
                                    FrmDetailInfo.AddOneMsg(string.Format("清除控制器假期约束失败:SN={0},IP={1}", ctrl.sn, ctrl.ip), isRed: true);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            FrmDetailInfo.AddOneMsg(string.Format("上传控制器时间段失败:SN={0},IP={1},异常信息:{2},结束该控制器上传...", item.SN_NO, item.IP, ex.Message), isRed: true);
                            log.Error("上传控制器时间段失败,", ex);
                            SmtLog.ErrorFormat("设置", "上传控制器时间段失败:SN={0},IP={1},异常信息:{2},结束该控制器上传...", item.SN_NO, item.IP, ex.Message);
                        }
                        finally
                        {
                            evt.Set();
                        }
                    }));
                }
                foreach (var item in eventList)
                {
                    item.WaitOne(60000);
                }
                FrmDetailInfo.AddOneMsg("结束控制器时段上传!");
            });

            waiting.Show(this);
        }
示例#21
0
        private void DoSave(bool upload)
        {
            try
            {
                if (!CheckInput())
                {
                    return;
                }
                Maticsoft.Model.SMT_CONTROLLER_INFO ctrlInfo = new Maticsoft.Model.SMT_CONTROLLER_INFO();
                if (_ctrlr != null)
                {
                    ctrlInfo.MAC            = _ctrlr.MAC;
                    ctrlInfo.ID             = _ctrlr.ID;
                    ctrlInfo.MASK           = _ctrlr.MASK;
                    ctrlInfo.ORG_ID         = _ctrlr.ORG_ID;
                    ctrlInfo.ORDER_VALUE    = _ctrlr.ORDER_VALUE;
                    ctrlInfo.CTRLR_MODEL    = _ctrlr.CTRLR_MODEL;
                    ctrlInfo.DRIVER_DATE    = _ctrlr.DRIVER_DATE;
                    ctrlInfo.DRIVER_VERSION = _ctrlr.DRIVER_VERSION;
                    ctrlInfo.GATEWAY        = _ctrlr.GATEWAY;
                }
                else
                {
                    ctrlInfo.ID = -1;
                }
                ctrlInfo.SN_NO     = tbCtrlrSn.Text.Trim();
                ctrlInfo.IS_ENABLE = cbCtrlrEnable.Checked;
                string name = tbCtrlName.Text.Trim();
                if (name == "")
                {
                    name = ctrlInfo.SN_NO;
                }
                ctrlInfo.NAME       = name;
                ctrlInfo.IP         = ipCtrlr.Value;
                ctrlInfo.PORT       = iiPort.Value;
                ctrlInfo.CTRLR_DESC = tbDesc.Text.Trim();
                ctrlInfo.CTRLR_TYPE = (int)_lastType;
                ctrlInfo.AREA_ID    = -1;
                if (cboTreeArea.SelectedNode != null && cboTreeArea.SelectedNode.Tag is Maticsoft.Model.SMT_CONTROLLER_ZONE)
                {
                    var area = cboTreeArea.SelectedNode.Tag as Maticsoft.Model.SMT_CONTROLLER_ZONE;
                    ctrlInfo.AREA_ID   = area.ID;
                    ctrlInfo.AREA_NAME = area.ZONE_NAME;
                }

                List <DoorNameAttriData>             doorNameDatas   = doorNameAttriGroup.GetDatas();
                List <DoorReaderAttriData>           doorReaderDatas = doorReaderAttriGroup.GetDatas();
                List <Maticsoft.Model.SMT_DOOR_INFO> doors           = new List <Maticsoft.Model.SMT_DOOR_INFO>();
                foreach (var item in doorNameDatas)
                {
                    Maticsoft.Model.SMT_DOOR_INFO door = new Maticsoft.Model.SMT_DOOR_INFO();
                    door.CTRL_ID          = ctrlInfo.ID;
                    door.CTRL_DELAY_TIME  = item.doorSecond;
                    door.CTRL_DOOR_INDEX  = item.doorNo;
                    door.CTRL_STYLE       = item.doorCtrlType;
                    door.IS_ALLOW_VISITOR = item.visitor;
                    if (_ctrlr != null)
                    {
                        var old = _ctrlr.DOOR_INFOS.Find(m => m.CTRL_DOOR_INDEX == item.doorNo);
                        if (old != null)
                        {
                            door.ID        = old.ID;
                            door.DOOR_DESC = old.DOOR_DESC;
                        }
                    }
                    else
                    {
                        door.ID        = -1;
                        door.DOOR_DESC = "";
                    }
                    door.DOOR_NAME = item.doorName;
                    DoorReaderAttriData reader1 = doorReaderDatas.Find(m => m.doorNo == item.doorNo && m.isEnter1);
                    DoorReaderAttriData reader2 = doorReaderDatas.Find(m => m.doorNo == item.doorNo && !m.isEnter1);
                    door.IS_ATTENDANCE1 = reader1 == null ? false : reader1.isAttend;
                    door.IS_ATTENDANCE2 = reader2 == null ? false : reader2.isAttend;
                    door.IS_ENABLE      = item.doorEnable;
                    door.IS_ENTER1      = reader1 == null ? false : reader1.isEnter;
                    door.IS_ENTER2      = reader2 == null ? false : reader2.isEnter;
                    doors.Add(door);
                }
                CtrlWaiting ctrlWaiting = new CtrlWaiting(() =>
                {
                    try
                    {
                        Maticsoft.BLL.SMT_CONTROLLER_INFO ctrlBll = new Maticsoft.BLL.SMT_CONTROLLER_INFO();
                        var exists = ctrlBll.GetModelList("SN_NO='" + ctrlInfo.SN_NO + "'");

                        if (ctrlInfo.ID != -1)
                        {
                            if (exists.Count > 0)
                            {
                                if (exists[0].ID != ctrlInfo.ID)
                                {
                                    WinInfoHelper.ShowInfoWindow(this, "已存在控制器序列号:" + ctrlInfo.SN_NO);
                                    return;
                                }
                            }
                            ctrlBll.Update(ctrlInfo);
                            ctrlInfo.DOOR_INFOS = _ctrlr.DOOR_INFOS;
                            _ctrlr = ctrlInfo;
                        }
                        else
                        {
                            if (exists.Count > 0)
                            {
                                WinInfoHelper.ShowInfoWindow(this, "已存在控制器序列号:" + ctrlInfo.SN_NO);
                                return;
                            }
                            ctrlInfo.ID = ctrlBll.Add(ctrlInfo);
                            _ctrlr      = ctrlInfo;
                        }

                        if (_lastType != ControllerDoorType.Elevator)//非电梯控制器
                        {
                            Maticsoft.BLL.SMT_DOOR_INFO doorBll = new Maticsoft.BLL.SMT_DOOR_INFO();

                            foreach (var item in doors)
                            {
                                var edoors = doorBll.GetModelList("CTRL_ID=" + ctrlInfo.ID + " and " + " CTRL_DOOR_INDEX=" + item.CTRL_DOOR_INDEX);
                                if (edoors.Count > 0)
                                {
                                    item.ID = edoors[0].ID;
                                    doorBll.Update(item);
                                }
                                else
                                {
                                    item.CTRL_ID = ctrlInfo.ID;
                                    item.ID      = doorBll.Add(item);
                                }
                            }
                            _ctrlr.DOOR_INFOS = doors;

                            if (upload)
                            {
                                string errMsg = null;
                                if (UploadPrivate.UploadByCtrlr(_ctrlr, out errMsg, doors, true))
                                {
                                    if (errMsg != "")
                                    {
                                        WinInfoHelper.ShowInfoWindow(this, "设置控制器" + (_ctrlr.IS_ENABLE ? "启用" : "禁用") + "异常:" + errMsg);
                                        return;
                                    }
                                }
                                else
                                {
                                    WinInfoHelper.ShowInfoWindow(this, "设置控制器" + (_ctrlr.IS_ENABLE ? "启用" : "禁用") + "异常:" + errMsg);
                                    return;
                                }
                                Controller c = ControllerHelper.ToController(_ctrlr);
                                //设置门控制方式
                                foreach (var item in doors)
                                {
                                    using (IAccessCore access = new WGAccess())
                                    {
                                        bool ret = access.SetDoorControlStyle(c, (int)item.CTRL_DOOR_INDEX, (DoorControlStyle)item.CTRL_STYLE, item.CTRL_DELAY_TIME);
                                        if (!ret)
                                        {
                                            WinInfoHelper.ShowInfoWindow(this, "上传门控制方式失败!");
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                        this.Invoke(new Action(() =>
                        {
                            this.DialogResult = DialogResult.OK;
                            this.Close();
                        }));
                    }
                    catch (Exception ex)
                    {
                        log.Error("保存异常:" + ex.Message, ex);
                        WinInfoHelper.ShowInfoWindow(this, "保存异常:" + ex.Message);
                    }
                });
                ctrlWaiting.Show(this);
            }
            catch (Exception ex)
            {
                WinInfoHelper.ShowInfoWindow(this, "保存异常:" + ex.Message);
                log.Error("保存异常:" + ex.Message, ex);
            }
        }
示例#22
0
        private void btnApplyState_Click(object sender, EventArgs e)
        {
            List <decimal> ids            = GetCtrlIds();
            bool           isAllowVisitor = cbIsAllowVisitor.Checked;
            CtrlWaiting    waiting        = new CtrlWaiting(() =>
            {
                try
                {
                    List <decimal> visitorIds = new List <decimal>();
                    foreach (var item in _doors)
                    {
                        if (item.IS_ALLOW_VISITOR != isAllowVisitor)
                        {
                            visitorIds.Add(item.ID);
                        }
                    }
                    if (visitorIds.Count > 0)
                    {
                        Maticsoft.DBUtility.DbHelperSQL.Query("update SMT_DOOR_INFO set IS_ALLOW_VISITOR=" + (isAllowVisitor ? 1 : 0) + " where ID in (" + string.Join(",", visitorIds.ToArray()) + ")");
                        WinInfoHelper.ShowInfoWindow(this.Parent, "更新访客状态正常!");
                        foreach (var item in _doors)
                        {
                            item.IS_ALLOW_VISITOR = isAllowVisitor;
                        }
                    }

                    Maticsoft.BLL.SMT_CONTROLLER_INFO ctrlBLL = new Maticsoft.BLL.SMT_CONTROLLER_INFO();
                    var ctrls = ctrlBLL.GetModelList("ID in (" + string.Join(",", ids) + ")");
                    DoorControlStyle style = DoorControlStyle.Online;
                    if (rbOnline.Checked)
                    {
                        style = DoorControlStyle.Online;
                    }
                    else if (rbAlwaysOpen.Checked)
                    {
                        style = DoorControlStyle.AlwaysOpen;
                    }
                    else if (rbAlwaysClose.Checked)
                    {
                        style = DoorControlStyle.AlwaysClose;
                    }
                    List <ManualResetEvent> resetEvents = new List <ManualResetEvent>();
                    foreach (var item in ctrls)
                    {
                        var doors = _doors.FindAll(m => m.CTRL_ID == item.ID);
                        if (doors.Count == 0)
                        {
                            continue;
                        }
                        ManualResetEvent evt = new ManualResetEvent(false);
                        resetEvents.Add(evt);
                        ThreadPool.QueueUserWorkItem(new WaitCallback((o) =>
                        {
                            try
                            {
                                var c           = ControllerHelper.ToController(item);
                                IAccessCore acc = new WGAccess();
                                foreach (var d in doors)
                                {
                                    if (d.CTRL_DOOR_INDEX == null)
                                    {
                                        continue;
                                    }
                                    string temp = "在线";
                                    switch (style)
                                    {
                                    case DoorControlStyle.Online:
                                        temp = "在线";
                                        break;

                                    case DoorControlStyle.AlwaysOpen:
                                        temp = "常开";
                                        break;

                                    case DoorControlStyle.AlwaysClose:
                                        temp = "常关";
                                        break;

                                    default:
                                        break;
                                    }
                                    bool ret = acc.SetDoorControlStyle(c, (int)d.CTRL_DOOR_INDEX, style, iDelayTime.Value);
                                    if (!ret)
                                    {
                                        this.Invoke(new Action(() =>
                                        {
                                            if (_dgvX != null)
                                            {
                                                DataGridViewRow row = new DataGridViewRow();
                                                row.CreateCells(_dgvX, DateTime.Now, d.DOOR_NAME, "设置门禁失败!控制器IP=" + item.IP + ",SN=" + item.SN_NO + ",门禁:" + d.DOOR_NAME);
                                                _dgvX.Rows.Insert(0, row);
                                                row.Selected = true;
                                            }
                                        }));
                                        WinInfoHelper.ShowInfoWindow(this.Parent, "设置门禁失败!控制器IP=" + item.IP + ",SN=" + item.SN_NO + ",门禁:" + d.DOOR_NAME);
                                        continue;
                                    }
                                    else
                                    {
                                        Maticsoft.BLL.SMT_DOOR_INFO doorBll = new Maticsoft.BLL.SMT_DOOR_INFO();
                                        d.CTRL_DELAY_TIME = iDelayTime.Value;
                                        d.CTRL_STYLE      = (int)style;
                                        doorBll.Update(d);
                                        IsChanged = true;
                                        this.Invoke(new Action(() =>
                                        {
                                            if (_dgvX != null)
                                            {
                                                DataGridViewRow row = new DataGridViewRow();
                                                row.CreateCells(_dgvX, DateTime.Now, d.DOOR_NAME, "设置门禁:" + d.DOOR_NAME + " " + temp + "状态,时间" + iDelayTime.Value + "秒成功!");
                                                _dgvX.Rows.Insert(0, row);
                                                row.Selected = true;
                                            }
                                        }));
                                        WinInfoHelper.ShowInfoWindow(this.Parent, "设置门禁:" + d.DOOR_NAME + " " + temp + "状态,时间" + iDelayTime.Value + "秒成功!");
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                log.Error("设置门禁发生异常:", ex);
                                this.Invoke(new Action(() =>
                                {
                                    if (_dgvX != null)
                                    {
                                        DataGridViewRow row = new DataGridViewRow();
                                        row.CreateCells(_dgvX, DateTime.Now, "", "设置门禁发生异常!控制器IP=" + item.IP + ",SN=" + item.SN_NO + ",异常信息:" + ex.Message);
                                        _dgvX.Rows.Insert(0, row);
                                        row.Selected = true;
                                    }
                                }));
                                WinInfoHelper.ShowInfoWindow(this.Parent, "设置门禁发生异常!控制器IP=" + item.IP + ",SN=" + item.SN_NO + ",异常信息:" + ex.Message);
                            }
                            finally
                            {
                                evt.Set();
                            }
                        }));
                    }
                    foreach (var item in resetEvents)
                    {
                        item.WaitOne(15000);
                    }
                }
                catch (Exception ex)
                {
                    log.Error("设置门禁发生异常1:", ex);
                    WinInfoHelper.ShowInfoWindow(this.Parent, "设置门禁发生异常!");
                }
                finally
                {
                    this.Invoke(new Action(() =>
                    {
                        this.Close();
                    }));
                }
            });

            waiting.Show(this);
        }