FormEditLogOperationSetting.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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.BLL;
  12. using SIMDP.Model;
  13. using ProjectBase.Data.BaseDAL;
  14. using ProjectBase.Util;
  15. using ProjectBase.Data.Logs;
  16. namespace SIMDP.View
  17. {
  18. public partial class FormEditLogOperationSetting : DevExpress.XtraEditors.XtraForm
  19. {
  20. /// <summary>
  21. /// 需要修改的日志操作配置对象
  22. /// </summary>
  23. public MoLogOperationSetting operationSetting { get; set; }
  24. public FormEditLogOperationSetting()
  25. {
  26. InitializeComponent();
  27. }
  28. private void FormEditLogOperationSetting_Load(object sender, EventArgs e)
  29. {
  30. InitControls();
  31. }
  32. /// <summary>
  33. /// 初始化控件
  34. /// </summary>
  35. private void InitControls()
  36. {
  37. //下拉框--数据库表名
  38. List<string> tableList = BLLFactory<BlLogOperationSetting>.Instance.GetTableNames();
  39. this.lookUp_TableName.Properties.DataSource = tableList;
  40. this.lookUp_TableName.Properties.NullText = null;
  41. if (operationSetting == null)
  42. {
  43. this.btn_Save.Enabled = false;
  44. this.lookUp_TableName.Properties.NullText = "请您选择";
  45. this.txt_Creator.Text = SysEnvironment.CurrentLoginName;
  46. this.txt_Editor.Text = SysEnvironment.CurrentLoginName;
  47. return;
  48. }
  49. this.btn_Add.Enabled = false;
  50. this.lookUp_TableName.EditValue = operationSetting.TableName;
  51. this.lookUp_TableName.Enabled = false;
  52. this.check_Insert.Checked = operationSetting.InsertLog;
  53. this.check_Delete.Checked = operationSetting.DeleteLog;
  54. this.check_Update.Checked = operationSetting.UpdateLog;
  55. this.txt_Creator.Text = operationSetting.CreatorName;
  56. this.txt_Editor.Text = SysEnvironment.CurrentLoginName;
  57. this.check_Forbid.Checked = operationSetting.Forbid;
  58. }
  59. private void btn_Cancel_Click(object sender, EventArgs e)
  60. {
  61. this.Close();
  62. }
  63. private void btn_Add_Click(object sender, EventArgs e)
  64. {
  65. try
  66. {
  67. if (lookUp_TableName.Text == "请您选择")
  68. {
  69. DevExpress.XtraEditors.XtraMessageBox.Show("请输入数据库表", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  70. return;
  71. }
  72. //检查是否还有其他相同关键字的记录
  73. bool exist = BLLFactory<BlLogOperationSetting>.Instance.IsExistKey("setting_tableName", this.lookUp_TableName.Text);
  74. if (exist)
  75. {
  76. DevExpress.XtraEditors.XtraMessageBox.Show("指定的【数据库表】已经存在,不能重复添加,请修改", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  77. return;
  78. }
  79. MoLogOperationSetting mo = new MoLogOperationSetting();
  80. mo.Forbid = this.check_Forbid.Checked;
  81. mo.TableName = this.lookUp_TableName.Text;
  82. mo.InsertLog = this.check_Insert.Checked;
  83. mo.DeleteLog = this.check_Delete.Checked;
  84. mo.UpdateLog = this.check_Update.Checked;
  85. mo.CreatorAccount = SysEnvironment.CurrentLoginID;
  86. mo.CreatorName = SysEnvironment.CurrentLoginName;
  87. mo.CreateTime = DateTime.Now;
  88. mo.EditorAccount = SysEnvironment.CurrentLoginID;
  89. mo.EditorName = SysEnvironment.CurrentLoginName;
  90. mo.EditTime = DateTime.Now;
  91. bool flag = BLLFactory<BlLogOperationSetting>.Instance.Insert(mo);
  92. if (flag)
  93. {
  94. DevExpress.XtraEditors.XtraMessageBox.Show("添加成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  95. this.DialogResult = DialogResult.OK;
  96. this.Close();
  97. }
  98. else
  99. {
  100. DevExpress.XtraEditors.XtraMessageBox.Show("添加失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  101. }
  102. }
  103. catch (Exception ex)
  104. {
  105. DevExpress.XtraEditors.XtraMessageBox.Show("添加失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  106. LogHelper.log.Error(string.Format("插入数据库log_operationSetting出现错误:{0}", ex.ToString()));
  107. }
  108. }
  109. private void btn_Save_Click(object sender, EventArgs e)
  110. {
  111. try
  112. {
  113. MoLogOperationSetting mo = new MoLogOperationSetting();
  114. mo.ID = operationSetting.ID;
  115. mo.Forbid = this.check_Forbid.Checked;
  116. mo.TableName = this.lookUp_TableName.Text;
  117. mo.InsertLog = this.check_Insert.Checked;
  118. mo.DeleteLog = this.check_Delete.Checked;
  119. mo.UpdateLog = this.check_Update.Checked;
  120. mo.CreatorAccount = operationSetting.CreatorAccount;
  121. mo.CreatorName = operationSetting.CreatorName;
  122. mo.CreateTime = operationSetting.CreateTime;
  123. mo.EditorAccount = SysEnvironment.CurrentLoginID;
  124. mo.EditorName = SysEnvironment.CurrentLoginName;
  125. mo.EditTime = DateTime.Now;
  126. bool flag = BLLFactory<BlLogOperationSetting>.Instance.Update(mo,mo.ID);
  127. if (flag)
  128. {
  129. DevExpress.XtraEditors.XtraMessageBox.Show("修改成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  130. this.DialogResult = DialogResult.OK;
  131. this.Close();
  132. }
  133. else
  134. {
  135. DevExpress.XtraEditors.XtraMessageBox.Show("修改失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  136. }
  137. }
  138. catch (Exception ex)
  139. {
  140. DevExpress.XtraEditors.XtraMessageBox.Show("修改失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  141. LogHelper.log.Error(string.Format("修改数据库log_operationSetting出现错误:{0}", ex.ToString()));
  142. }
  143. }
  144. }
  145. }