예제 #1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            string pwd = this.tbPassword.Text.Trim();

            if (pwd == "")
            {
                WinInfoHelper.ShowInfoWindow(this, "密码为空!");
                return;
            }
            var doors = doorTree.Tree.GetNodeList(true, typeof(Maticsoft.Model.SMT_DOOR_INFO));

            if (doors.Count == 0)
            {
                WinInfoHelper.ShowInfoWindow(this, "未选择任何门禁!");
                return;
            }
            List <decimal> doorIds = new List <decimal>();

            foreach (var item in doors)
            {
                doorIds.Add(((Maticsoft.Model.SMT_DOOR_INFO)item.Tag).ID);
            }
            CtrlWaiting ctrlWaiting = new CtrlWaiting(() =>
            {
                try
                {
                    Maticsoft.BLL.SMT_SUPER_PWD pwdBll             = new Maticsoft.BLL.SMT_SUPER_PWD();
                    List <Maticsoft.Model.SMT_SUPER_PWD> models    = pwdBll.GetModelList("SUPER_PWD='" + pwd + "'");
                    List <Maticsoft.Model.SMT_SUPER_PWD> addmodels = new List <Maticsoft.Model.SMT_SUPER_PWD>();
                    foreach (var item in doorIds)
                    {
                        if (!models.Exists(m => m.DOOR_ID == item))
                        {
                            Maticsoft.Model.SMT_SUPER_PWD model = new Maticsoft.Model.SMT_SUPER_PWD()
                            {
                                DOOR_ID   = item,
                                SUPER_PWD = pwd
                            };
                            model.ID = pwdBll.Add(model);
                            addmodels.Add(model);
                            SmtLog.InfoFormat("配置", "添加超级通行密码:门禁Id={0}", item);
                        }
                    }
                    if (addmodels.Count > 0)
                    {
                        RefreshDatas();
                    }
                }
                catch (Exception ex)
                {
                    WinInfoHelper.ShowInfoWindow(this, "添加超级通行密码异常!" + ex.Message);
                    log.Error("添加超级通行密码异常:", ex);
                }
            });

            ctrlWaiting.Show(this);
        }
예제 #2
0
        private void DeleteRows(List <DataGridViewRow> rows)
        {
            if (rows.Count == 0)
            {
                return;
            }
            if (MessageBox.Show("确定删除超级密码?", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                List <Maticsoft.Model.SMT_SUPER_PWD> pwds = new List <Maticsoft.Model.SMT_SUPER_PWD>();
                foreach (var item in rows)
                {
                    List <Maticsoft.Model.SMT_SUPER_PWD> models = (List <Maticsoft.Model.SMT_SUPER_PWD>)item.Tag;
                    pwds.AddRange(models);
                }
                CtrlWaiting waiting = new CtrlWaiting(() =>
                {
                    try
                    {
                        Maticsoft.BLL.SMT_SUPER_PWD pwdbll = new Maticsoft.BLL.SMT_SUPER_PWD();
                        foreach (var item in pwds)
                        {
                            pwdbll.Delete(item.ID);
                        }

                        Maticsoft.BLL.SMT_SUPER_PWD pwdBll = new Maticsoft.BLL.SMT_SUPER_PWD();
                        var models = pwdbll.GetModelList("");
                        try
                        {
                            UploadPrivate.UploadPwds(models);
                        }
                        catch (Exception ex)
                        {
                            WinInfoHelper.ShowInfoWindow(this, "上传密码发生异常:" + ex.Message);
                            log.Error("上传密码发生异常:", ex);
                        }


                        this.Invoke(new Action(() =>
                        {
                            foreach (var item in rows)
                            {
                                dgvData.Rows.Remove(item);
                            }
                        }));
                    }
                    catch (Exception ex)
                    {
                        WinInfoHelper.ShowInfoWindow(this, "删除超级密码异常:" + ex.Message);
                        log.Error("删除超级密码异常:", ex);
                    }
                });
                waiting.Show(this);
            }
        }