123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Linq;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using DevExpress.XtraEditors;
- using SIMDP.Model;
- using SIMDP.BLL;
- using ProjectBase.Data.BaseDAL;
- using ProjectBase.Util;
- using ProjectBase.Data.Logs;
- namespace SIMDP.View
- {
- public partial class FormEditBlack : DevExpress.XtraEditors.XtraForm
- {
- /// <summary>
- /// 需要修改的黑白名单对象
- /// </summary>
- public MoWhite white { get; set; }
- /// <summary>
- /// 授权类型的字典表
- /// </summary>
- private Dictionary<string, string> Dic_Type
- {
- get
- {
- Dictionary<string, string> type = new Dictionary<string, string>();
- type.Add("1", "白名单");
- type.Add("0", "黑名单");
- return type;
- }
- }
- public FormEditBlack()
- {
- InitializeComponent();
- }
- private void FormEditBlack_Load(object sender, EventArgs e)
- {
- InitControls();
- }
- private void InitControls()
- {
- //下拉框--类型
- this.lookUp_Type.Properties.DataSource = Dic_Type;
- this.lookUp_Type.Properties.ValueMember = "Key";
- this.lookUp_Type.Properties.DisplayMember = "Value";
- this.lookUp_Type.Properties.NullText = "请您选择";
- //下拉框--所属用户
- List<MoAuthoryUser> userList = BLLFactory<BlAuthoryUser>.Instance.GetAll();
- Dictionary<string, string> dic = new Dictionary<string, string>();
- foreach (MoAuthoryUser item in userList)
- {
- dic.Add(item.LoginAccount, item.UserName);
- }
- this.lookUp_UserName.Properties.DataSource = dic;
- this.lookUp_UserName.Properties.ValueMember = "Key";
- this.lookUp_UserName.Properties.DisplayMember = "Value";
- this.lookUp_UserName.Properties.NullText = "请您选择";
- this.txt_Creator.Enabled = false;
- this.txt_Editor.Enabled = false;
- if (white == null)
- {
- this.btn_Save.Enabled = false;
- this.txt_Creator.Text = SysEnvironment.CurrentLoginName;
- this.txt_Editor.Text = SysEnvironment.CurrentLoginName;
- return;
- }
- this.btn_Add.Enabled = false;
- this.txt_Name.Text = white.Name;
- this.lookUp_UserName.EditValue = white.UserAccount;
- this.lookUp_Type.EditValue = white.Type.ToString();
- this.txt_IpStart.Text = white.IPStart;
- this.txt_IpEnd.Text = white.IPEnd;
- this.txt_Note.Text = white.Note;
- this.txt_Creator.Text = white.CreatorName;
- this.txt_Editor.Text = white.EditorName;
- this.check_Forbid.Checked = white.Forbid;
- }
- private void btn_Cancel_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- private void btn_Add_Click(object sender, EventArgs e)
- {
- if (string.IsNullOrEmpty(txt_Name.Text))
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("请输入显示名称", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (lookUp_UserName.Text == "请您选择")
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("请输入所属用户", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (lookUp_Type.Text == "请您选择")
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("请输入授权类型", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (string.IsNullOrEmpty(txt_IpStart.Text))
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("请输入IP起始地址", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (string.IsNullOrEmpty(txt_IpEnd.Text))
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("请输入IP结束地址", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- try
- {
- MoWhite mo = new MoWhite();
- mo.Name = txt_Name.Text;
- mo.UserAccount = lookUp_UserName.EditValue.ToString();
- mo.UserName = lookUp_UserName.Text;
- mo.Type = Convert.ToInt32(lookUp_Type.EditValue);
- mo.Forbid = check_Forbid.Checked;
- mo.IPStart = txt_IpStart.Text;
- mo.IPEnd = txt_IpEnd.Text;
- mo.Note = txt_Note.Text;
- mo.CreatorAccount = SysEnvironment.CurrentLoginID;
- mo.CreatorName = SysEnvironment.CurrentLoginName;
- mo.CreateTime = DateTime.Now;
- mo.EditorAccount = SysEnvironment.CurrentLoginID;
- mo.EditorName = SysEnvironment.CurrentLoginName;
- mo.EditTime = DateTime.Now;
- bool flag = BLLFactory<BlWhite>.Instance.Insert(mo);
- if (flag)
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("添加成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- this.DialogResult = DialogResult.OK;
- this.Close();
- }
- else
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("添加失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- catch (Exception ex)
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("添加失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- LogHelper.log.Error(string.Format("插入数据库black出现错误:{0}", ex.ToString()));
- }
- }
- private void btn_Save_Click(object sender, EventArgs e)
- {
- if (string.IsNullOrEmpty(txt_Name.Text))
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("请输入显示名称", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (lookUp_UserName.Text == "请您选择")
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("请输入所属用户", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (lookUp_Type.Text == "请您选择")
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("请输入授权类型", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (string.IsNullOrEmpty(txt_IpStart.Text))
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("请输入IP起始地址", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (string.IsNullOrEmpty(txt_IpEnd.Text))
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("请输入IP结束地址", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- try
- {
- MoWhite mo = new MoWhite();
- mo.ID = white.ID;
- mo.Name = txt_Name.Text;
- mo.UserAccount = lookUp_UserName.EditValue.ToString();
- mo.UserName = lookUp_UserName.Text;
- mo.Type = Convert.ToInt32(lookUp_Type.EditValue);
- mo.Forbid = check_Forbid.Checked;
- mo.IPStart = txt_IpStart.Text;
- mo.IPEnd = txt_IpEnd.Text;
- mo.Note = txt_Note.Text;
- mo.CreatorAccount = white.CreatorAccount;
- mo.CreatorName = white.CreatorName;
- mo.CreateTime = white.CreateTime;
- mo.EditorAccount = SysEnvironment.CurrentLoginID;
- mo.EditorName = SysEnvironment.CurrentLoginName;
- mo.EditTime = DateTime.Now;
- bool flag = BLLFactory<BlWhite>.Instance.Update(mo,mo.ID);
- if (flag)
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("修改成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- this.DialogResult = DialogResult.OK;
- this.Close();
- }
- else
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("修改失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- catch (Exception ex)
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("修改失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- LogHelper.log.Error(string.Format("修改数据库black出现错误:{0}", ex.ToString()));
- }
- }
- }
- }
|