/// <summary>
        /// Save Button Click Event.
        /// </summary>
        private void SaveBtn_Click(object sender, EventArgs e)
        {
            try {
                var target = new CardAuthInfo();
                target.BeginTime = BeginTimeDTP.Value;
                target.EndTime   = EndTimeDTP.Value;
                target.Password  = PwdCB.Text.Trim();
                target.Enabled   = EnabledCB.Checked;
                var limitId = (Int32)LimitTypeCB.SelectedValue;
                switch ((EnmLimitID)limitId)
                {
                case EnmLimitID.TQ:
                    target.LimitId    = EnmLimitID.TQ;
                    target.LimitIndex = ComUtility.DefaultInt32;
                    break;

                case EnmLimitID.WTMG:
                    target.LimitId    = EnmLimitID.WTMG;
                    target.LimitIndex = Convert.ToInt32(LimitIndexCB.SelectedValue);
                    break;

                case EnmLimitID.DTM:
                    target.LimitId    = EnmLimitID.DTM;
                    target.LimitIndex = Convert.ToInt32(LimitIndexCB.SelectedValue);
                    break;
                }

                var SaveCardAuth = new List <CardAuthInfo>();
                if (CurBehavior == EnmSaveBehavior.Add)
                {
                    var Devices = new List <Int32>();
                    CheckDevTreeView(DeviceTreeView.Nodes, Devices);
                    if (Devices.Count == 0)
                    {
                        MessageBox.Show("请勾选需要授权的设备", "系统警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    var Cards = new List <String>();
                    CheckCardsTreeView(CardsTreeView.Nodes, Cards);
                    if (Cards.Count == 0)
                    {
                        MessageBox.Show("请勾选需要授权的卡片", "系统警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    foreach (var dev in Devices)
                    {
                        foreach (var card in Cards)
                        {
                            var ca = new CardAuthInfo();
                            ca.CardSn     = card;
                            ca.DevId      = dev;
                            ca.LimitId    = target.LimitId;
                            ca.LimitIndex = target.LimitIndex;
                            ca.BeginTime  = target.BeginTime;
                            ca.EndTime    = target.EndTime;
                            ca.Password   = target.Password;
                            ca.Enabled    = target.Enabled;
                            SaveCardAuth.Add(ca);
                        }
                    }
                }
                else
                {
                    foreach (var ca in CurCardAuth)
                    {
                        ca.LimitId    = target.LimitId;
                        ca.LimitIndex = target.LimitIndex;
                        ca.BeginTime  = target.BeginTime;
                        ca.EndTime    = target.EndTime;
                        ca.Password   = target.Password;
                        ca.Enabled    = target.Enabled;
                    }
                    SaveCardAuth.AddRange(CurCardAuth);
                }

                var IsSync = SyncCB.Checked;
                var result = Common.ShowWait(() => {
                    CardAuthEntity.SaveCardAuth(SaveCardAuth, IsSync);
                }, default(String), "正在保存,请稍后...", default(Int32), default(Int32));

                if (result == DialogResult.OK)
                {
                    foreach (var ca in SaveCardAuth)
                    {
                        Common.WriteLog(DateTime.Now, CurBehavior == EnmSaveBehavior.Add ? EnmMsgType.Authin : EnmMsgType.Info, Common.CurUser.UserName, "Delta.MPS.AccessSystem.SaveCardDevAuthForm.SaveBtn.Click", String.Format("{0}卡片授权[设备:{1} 卡号:{2}]", CurBehavior == EnmSaveBehavior.Add ? "新增" : "更新", ca.DevId, ca.CardSn), null);
                    }

                    if (CurBehavior == EnmSaveBehavior.Edit)
                    {
                        foreach (var cc in CurCardAuth)
                        {
                            var OriCA = OriCardAuth.Find(oc => oc.CardSn.Equals(cc.CardSn) && oc.DevId == cc.DevId);
                            if (OriCA != null)
                            {
                                Common.CopyObjectValues(cc, OriCA);
                            }
                        }
                    }
                    MessageBox.Show("数据保存完成", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    DialogResult = System.Windows.Forms.DialogResult.OK;
                }
                else
                {
                    MessageBox.Show("数据保存失败", "系统警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            } catch (Exception err) {
                Common.WriteLog(DateTime.Now, EnmMsgType.Error, "System", "Delta.MPS.AccessSystem.SaveCardDevAuthForm.SaveBtn.Click", err.Message, err.StackTrace);
                MessageBox.Show(err.Message, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #2
0
        /// <summary>
        /// Save CardAuth Click Event.
        /// </summary>
        private void SaveBtn_Click(object sender, EventArgs e)
        {
            try {
                var target = new CardAuthInfo();
                target.BeginTime = BeginTimeDTP.Value;
                target.EndTime   = EndTimeDTP.Value;
                target.Password  = PwdCB.Text.Trim();
                target.Enabled   = EnabledCB.Checked;
                var limitId = (Int32)LimitTypeCB.SelectedValue;
                switch ((EnmLimitID)limitId)
                {
                case EnmLimitID.TQ:
                    target.LimitId    = EnmLimitID.TQ;
                    target.LimitIndex = ComUtility.DefaultInt32;
                    break;

                case EnmLimitID.WTMG:
                    target.LimitId    = EnmLimitID.WTMG;
                    target.LimitIndex = Convert.ToInt32(LimitIndexCB.SelectedValue);
                    break;

                case EnmLimitID.DTM:
                    target.LimitId    = EnmLimitID.DTM;
                    target.LimitIndex = Convert.ToInt32(LimitIndexCB.SelectedValue);
                    break;
                }

                var Devices = new List <Int32>();
                CheckDevTreeView(DevTreeView.Nodes, Devices);
                if (Devices.Count == 0)
                {
                    MessageBox.Show("请勾选需要授权的设备", "系统警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                var Cards = new List <String>();
                CheckCardsTreeView(CardTreeView.Nodes, Cards);
                if (Cards.Count == 0)
                {
                    MessageBox.Show("请勾选需要授权的卡片", "系统警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (MessageBox.Show("您确定要执行批量授权操作吗?", "确认对话框", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.OK)
                {
                    var SaveCardAuth = new List <CardAuthInfo>();
                    foreach (var dev in Devices)
                    {
                        foreach (var card in Cards)
                        {
                            var ca = new CardAuthInfo();
                            ca.CardSn     = card;
                            ca.DevId      = dev;
                            ca.LimitId    = target.LimitId;
                            ca.LimitIndex = target.LimitIndex;
                            ca.BeginTime  = target.BeginTime;
                            ca.EndTime    = target.EndTime;
                            ca.Password   = target.Password;
                            ca.Enabled    = target.Enabled;
                            SaveCardAuth.Add(ca);
                        }
                    }

                    var IsSync = SyncCB.Checked;
                    var result = Common.ShowWait(() => {
                        CardAuthEntity.SaveCardAuth(SaveCardAuth, IsSync);
                    }, default(String), "正在保存,请稍后...", default(Int32), default(Int32), 1800);

                    if (result == DialogResult.OK)
                    {
                        foreach (var ca in SaveCardAuth)
                        {
                            Common.WriteLog(DateTime.Now, EnmMsgType.Authin, Common.CurUser.UserName, "Delta.MPS.AccessSystem.BatchCardAuthForm.SaveBtn.Click", String.Format("新增卡片授权[设备:{0} 卡号:{1}]", ca.DevId, ca.CardSn), null);
                        }

                        MessageBox.Show("数据保存完成", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        DialogResult = System.Windows.Forms.DialogResult.OK;
                    }
                    else
                    {
                        MessageBox.Show("数据保存失败", "系统警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            } catch (Exception err) {
                Common.WriteLog(DateTime.Now, EnmMsgType.Error, "System", "Delta.MPS.AccessSystem.BatchCardAuthForm.SaveBtn.Click", err.Message, err.StackTrace);
                MessageBox.Show(err.Message, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }