FormEditBlack.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Linq;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using DevExpress.XtraEditors;
  11. using SIMDP.Model;
  12. using SIMDP.BLL;
  13. using ProjectBase.Data.BaseDAL;
  14. using ProjectBase.Util;
  15. using ProjectBase.Data.Logs;
  16. namespace SIMDP.View
  17. {
  18. public partial class FormEditBlack : DevExpress.XtraEditors.XtraForm
  19. {
  20. /// <summary>
  21. /// 需要修改的黑白名单对象
  22. /// </summary>
  23. public MoWhite white { get; set; }
  24. /// <summary>
  25. /// 授权类型的字典表
  26. /// </summary>
  27. private Dictionary<string, string> Dic_Type
  28. {
  29. get
  30. {
  31. Dictionary<string, string> type = new Dictionary<string, string>();
  32. type.Add("1", "白名单");
  33. type.Add("0", "黑名单");
  34. return type;
  35. }
  36. }
  37. public FormEditBlack()
  38. {
  39. InitializeComponent();
  40. }
  41. private void FormEditBlack_Load(object sender, EventArgs e)
  42. {
  43. InitControls();
  44. }
  45. private void InitControls()
  46. {
  47. //下拉框--类型
  48. this.lookUp_Type.Properties.DataSource = Dic_Type;
  49. this.lookUp_Type.Properties.ValueMember = "Key";
  50. this.lookUp_Type.Properties.DisplayMember = "Value";
  51. this.lookUp_Type.Properties.NullText = "请您选择";
  52. //下拉框--所属用户
  53. List<MoAuthoryUser> userList = BLLFactory<BlAuthoryUser>.Instance.GetAll();
  54. Dictionary<string, string> dic = new Dictionary<string, string>();
  55. foreach (MoAuthoryUser item in userList)
  56. {
  57. dic.Add(item.LoginAccount, item.UserName);
  58. }
  59. this.lookUp_UserName.Properties.DataSource = dic;
  60. this.lookUp_UserName.Properties.ValueMember = "Key";
  61. this.lookUp_UserName.Properties.DisplayMember = "Value";
  62. this.lookUp_UserName.Properties.NullText = "请您选择";
  63. this.txt_Creator.Enabled = false;
  64. this.txt_Editor.Enabled = false;
  65. if (white == null)
  66. {
  67. this.btn_Save.Enabled = false;
  68. this.txt_Creator.Text = SysEnvironment.CurrentLoginName;
  69. this.txt_Editor.Text = SysEnvironment.CurrentLoginName;
  70. return;
  71. }
  72. this.btn_Add.Enabled = false;
  73. this.txt_Name.Text = white.Name;
  74. this.lookUp_UserName.EditValue = white.UserAccount;
  75. this.lookUp_Type.EditValue = white.Type.ToString();
  76. this.txt_IpStart.Text = white.IPStart;
  77. this.txt_IpEnd.Text = white.IPEnd;
  78. this.txt_Note.Text = white.Note;
  79. this.txt_Creator.Text = white.CreatorName;
  80. this.txt_Editor.Text = white.EditorName;
  81. this.check_Forbid.Checked = white.Forbid;
  82. }
  83. private void btn_Cancel_Click(object sender, EventArgs e)
  84. {
  85. this.Close();
  86. }
  87. private void btn_Add_Click(object sender, EventArgs e)
  88. {
  89. if (string.IsNullOrEmpty(txt_Name.Text))
  90. {
  91. DevExpress.XtraEditors.XtraMessageBox.Show("请输入显示名称", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  92. return;
  93. }
  94. if (lookUp_UserName.Text == "请您选择")
  95. {
  96. DevExpress.XtraEditors.XtraMessageBox.Show("请输入所属用户", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  97. return;
  98. }
  99. if (lookUp_Type.Text == "请您选择")
  100. {
  101. DevExpress.XtraEditors.XtraMessageBox.Show("请输入授权类型", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  102. return;
  103. }
  104. if (string.IsNullOrEmpty(txt_IpStart.Text))
  105. {
  106. DevExpress.XtraEditors.XtraMessageBox.Show("请输入IP起始地址", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  107. return;
  108. }
  109. if (string.IsNullOrEmpty(txt_IpEnd.Text))
  110. {
  111. DevExpress.XtraEditors.XtraMessageBox.Show("请输入IP结束地址", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  112. return;
  113. }
  114. try
  115. {
  116. MoWhite mo = new MoWhite();
  117. mo.Name = txt_Name.Text;
  118. mo.UserAccount = lookUp_UserName.EditValue.ToString();
  119. mo.UserName = lookUp_UserName.Text;
  120. mo.Type = Convert.ToInt32(lookUp_Type.EditValue);
  121. mo.Forbid = check_Forbid.Checked;
  122. mo.IPStart = txt_IpStart.Text;
  123. mo.IPEnd = txt_IpEnd.Text;
  124. mo.Note = txt_Note.Text;
  125. mo.CreatorAccount = SysEnvironment.CurrentLoginID;
  126. mo.CreatorName = SysEnvironment.CurrentLoginName;
  127. mo.CreateTime = DateTime.Now;
  128. mo.EditorAccount = SysEnvironment.CurrentLoginID;
  129. mo.EditorName = SysEnvironment.CurrentLoginName;
  130. mo.EditTime = DateTime.Now;
  131. bool flag = BLLFactory<BlWhite>.Instance.Insert(mo);
  132. if (flag)
  133. {
  134. DevExpress.XtraEditors.XtraMessageBox.Show("添加成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  135. this.DialogResult = DialogResult.OK;
  136. this.Close();
  137. }
  138. else
  139. {
  140. DevExpress.XtraEditors.XtraMessageBox.Show("添加失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  141. }
  142. }
  143. catch (Exception ex)
  144. {
  145. DevExpress.XtraEditors.XtraMessageBox.Show("添加失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  146. LogHelper.log.Error(string.Format("插入数据库black出现错误:{0}", ex.ToString()));
  147. }
  148. }
  149. private void btn_Save_Click(object sender, EventArgs e)
  150. {
  151. if (string.IsNullOrEmpty(txt_Name.Text))
  152. {
  153. DevExpress.XtraEditors.XtraMessageBox.Show("请输入显示名称", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  154. return;
  155. }
  156. if (lookUp_UserName.Text == "请您选择")
  157. {
  158. DevExpress.XtraEditors.XtraMessageBox.Show("请输入所属用户", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  159. return;
  160. }
  161. if (lookUp_Type.Text == "请您选择")
  162. {
  163. DevExpress.XtraEditors.XtraMessageBox.Show("请输入授权类型", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  164. return;
  165. }
  166. if (string.IsNullOrEmpty(txt_IpStart.Text))
  167. {
  168. DevExpress.XtraEditors.XtraMessageBox.Show("请输入IP起始地址", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  169. return;
  170. }
  171. if (string.IsNullOrEmpty(txt_IpEnd.Text))
  172. {
  173. DevExpress.XtraEditors.XtraMessageBox.Show("请输入IP结束地址", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  174. return;
  175. }
  176. try
  177. {
  178. MoWhite mo = new MoWhite();
  179. mo.ID = white.ID;
  180. mo.Name = txt_Name.Text;
  181. mo.UserAccount = lookUp_UserName.EditValue.ToString();
  182. mo.UserName = lookUp_UserName.Text;
  183. mo.Type = Convert.ToInt32(lookUp_Type.EditValue);
  184. mo.Forbid = check_Forbid.Checked;
  185. mo.IPStart = txt_IpStart.Text;
  186. mo.IPEnd = txt_IpEnd.Text;
  187. mo.Note = txt_Note.Text;
  188. mo.CreatorAccount = white.CreatorAccount;
  189. mo.CreatorName = white.CreatorName;
  190. mo.CreateTime = white.CreateTime;
  191. mo.EditorAccount = SysEnvironment.CurrentLoginID;
  192. mo.EditorName = SysEnvironment.CurrentLoginName;
  193. mo.EditTime = DateTime.Now;
  194. bool flag = BLLFactory<BlWhite>.Instance.Update(mo,mo.ID);
  195. if (flag)
  196. {
  197. DevExpress.XtraEditors.XtraMessageBox.Show("修改成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  198. this.DialogResult = DialogResult.OK;
  199. this.Close();
  200. }
  201. else
  202. {
  203. DevExpress.XtraEditors.XtraMessageBox.Show("修改失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  204. }
  205. }
  206. catch (Exception ex)
  207. {
  208. DevExpress.XtraEditors.XtraMessageBox.Show("修改失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  209. LogHelper.log.Error(string.Format("修改数据库black出现错误:{0}", ex.ToString()));
  210. }
  211. }
  212. }
  213. }