Exemple #1
0
 public static void UpdateDoorSync(Maticsoft.Model.SMT_DOOR_INFO door)
 {
     if (door != null)
     {
         ThreadPool.QueueUserWorkItem(new WaitCallback((o) =>
         {
             try
             {
                 Maticsoft.BLL.SMT_DOOR_INFO doorBll = new Maticsoft.BLL.SMT_DOOR_INFO();
                 doorBll.Update(door);
             }
             catch (Exception ex)
             {
                 log.Error("更新门禁异常:", ex);
             }
         }));
     }
 }
        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);
        }
Exemple #3
0
        private void biAdd_Click(object sender, EventArgs e)
        {
            if (cbCtrler.SelectedItem == null)
            {
                WinInfoHelper.ShowInfoWindow(this, "请选择电梯控制器!");
                return;
            }
            if (cbDoorIndex.SelectedItem == null)
            {
                WinInfoHelper.ShowInfoWindow(this, "请选择继电器序号!");
                return;
            }
            if (tbDoorName.Text.Trim() == "")
            {
                WinInfoHelper.ShowInfoWindow(this, "梯门名称不能为空!");
                return;
            }
            var info  = (Maticsoft.Model.SMT_CONTROLLER_INFO)((ComboBoxItem)cbCtrler.SelectedItem).Tag;
            int index = (int)cbDoorIndex.SelectedItem;

            Maticsoft.Model.SMT_DOOR_INFO door = new Maticsoft.Model.SMT_DOOR_INFO();
            door.CTRL_ID         = info.ID;
            door.CTRL_DOOR_INDEX = index;
            door.DOOR_NAME       = tbDoorName.Text.Trim();
            door.ID        = -1;
            door.IS_ENABLE = true;
            CtrlWaiting waiting = new CtrlWaiting(() =>
            {
                try
                {
                    Maticsoft.BLL.SMT_DOOR_INFO doorBll = new Maticsoft.BLL.SMT_DOOR_INFO();
                    var doors = doorBll.GetModelList("CTRL_ID=" + info.ID + " and CTRL_DOOR_INDEX=" + index);
                    if (doors.Count > 0)
                    {
                        doors[0].DOOR_NAME = door.DOOR_NAME;
                        doorBll.Update(doors[0]);
                        door.ID = doors[0].ID;
                    }
                    else
                    {
                        door.ID = doorBll.Add(door);
                    }
                    this.Invoke(new Action(() =>
                    {
                        DataGridViewRow row = null;
                        foreach (DataGridViewRow item in dgvData.Rows)
                        {
                            if ((decimal)item.Cells[0].Value == info.ID &&
                                (int)item.Cells[2].Value == index
                                )
                            {
                                row = item;

                                break;
                            }
                        }
                        if (row != null)
                        {
                            row.Cells[3].Value = door.DOOR_NAME;
                            row.Tag            = door;
                        }
                        else
                        {
                            row = new DataGridViewRow();
                            row.CreateCells(dgvData,
                                            info.ID,
                                            info.NAME,
                                            index,
                                            door.DOOR_NAME,
                                            "删除"
                                            );
                            row.Tag = door;
                            dgvData.Rows.Add(row);
                        }
                        if (cbDoorIndex.SelectedIndex < cbDoorIndex.Items.Count - 1)
                        {
                            cbDoorIndex.SelectedIndex += 1;
                        }
                    }));
                }
                catch (Exception ex)
                {
                    log.Error("添加梯控门失败:", ex);
                    WinInfoHelper.ShowInfoWindow(this, "添加梯控门失败:" + ex.Message);
                    return;
                }
            });

            waiting.Show(this);
        }
        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);
            }
        }