FormEditRuleValue.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using ProjectBase.Data.BaseDAL;
  2. using ProjectBase.Data.Logs;
  3. using SIMDP.BLL;
  4. using SIMDP.Model;
  5. using ProjectBase.Util;
  6. using System;
  7. using System.Data;
  8. using System.Windows.Forms;
  9. namespace SIMDP.View
  10. {
  11. public partial class FormEditRuleValue : DevExpress.XtraEditors.XtraForm
  12. {
  13. /// <summary>
  14. /// 执行添加修改操作的rule_Value
  15. /// </summary>
  16. private DataTable dt;
  17. /// <summary>
  18. /// 需要修改的变量
  19. /// </summary>
  20. private DataRow dtRow;
  21. /// <summary>
  22. /// 构造函数
  23. /// </summary>
  24. /// <param name="dt">执行添加修改操作的rule_Value</param>
  25. /// <param name="selectRow">要修改的变量/param>
  26. public FormEditRuleValue(DataTable dtRule, DataRow selectRow)
  27. {
  28. InitializeComponent();
  29. dt = dtRule;
  30. InitControls(selectRow);
  31. }
  32. /// <summary>
  33. /// 初始化控件
  34. /// </summary>
  35. /// <param name="selectRow">要修改的变量</param>
  36. private void InitControls(DataRow selectRow)
  37. {
  38. //下拉框--类型
  39. BindingSource bsType = new BindingSource();
  40. bsType.DataSource = SysEnvironment.dirType;
  41. this.lookUp_RuleType.Properties.DataSource = bsType;
  42. this.lookUp_RuleType.Properties.ValueMember = "Key";
  43. this.lookUp_RuleType.Properties.DisplayMember = "Value";
  44. this.lookUp_RuleType.Properties.NullText = "请您选择";
  45. //下拉框--查询条件
  46. BindingSource bsQuery = new BindingSource();
  47. bsQuery.DataSource = SysEnvironment.dirRuleValueQuery;
  48. this.lookUp_RuleQuery.Properties.DataSource = bsQuery;
  49. this.lookUp_RuleQuery.Properties.ValueMember = "Key";
  50. this.lookUp_RuleQuery.Properties.DisplayMember = "Value";
  51. this.lookUp_RuleQuery.Properties.NullText = "请您选择";
  52. //下拉框--名称
  53. this.textEditRuleName.Text = selectRow["Name"].ToString();
  54. this.lookUp_RuleType.EditValue = Convert.ToInt32(selectRow["Type"]);
  55. this.lookUp_RuleQuery.Properties.NullText = selectRow["Query"].ToString();
  56. this.txt_RuleOrder.Text = selectRow["OrderNum"].ToString();
  57. if (selectRow != null)
  58. {
  59. dtRow = selectRow;
  60. }
  61. }
  62. private void btn_Cancel_Click(object sender, EventArgs e)
  63. {
  64. this.Close();
  65. }
  66. private void btn_Save_Click(object sender, EventArgs e)
  67. {
  68. try
  69. {
  70. if (lookUp_RuleType.Text == "请您选择" || lookUp_RuleQuery.Text == "请您选择" || string.IsNullOrEmpty(txt_RuleOrder.Text))
  71. {
  72. DevExpress.XtraEditors.XtraMessageBox.Show("请将信息填写完整。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  73. return;
  74. }
  75. DataRow[] drArr = dt.Select(string.Format("OrderNum = '{0}'", txt_RuleOrder.Text));
  76. if (drArr.Length > 0)
  77. {
  78. if (dtRow["OrderNum"].ToString() != txt_RuleOrder.Text)
  79. {
  80. DevExpress.XtraEditors.XtraMessageBox.Show("此序号已存在,请重新输入。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  81. return;
  82. }
  83. }
  84. FormUserVerification form = new FormUserVerification();
  85. form.ShowDialog();
  86. if (form.DialogResult != DialogResult.OK)
  87. {
  88. DevExpress.XtraEditors.XtraMessageBox.Show("用户验证失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  89. return;
  90. }
  91. string ruleId = dtRow["RuleId"].ToString();
  92. //string id = lookUp_RuleID.Text;
  93. string name = this.textEditRuleName.Text;
  94. string type = lookUp_RuleType.EditValue.ToString();
  95. string orderNum = txt_RuleOrder.Text;
  96. string query = lookUp_RuleQuery.Text;
  97. dt.Rows.Remove(dtRow);
  98. dt.Rows.Add(ruleId, name, type, orderNum, query);
  99. //将dataTable中的数据按照规则组合成数据表rules中的rule_value字段值
  100. //BlRule blRule = new BlRule();
  101. string ruleValue = BLLFactory<BlRule>.Instance.FormRuleValue(dt);
  102. MoRule rule = BLLFactory<BlRule>.Instance.FindByID(ruleId);
  103. rule.RuleValue = ruleValue;
  104. //修改数据库中的rule_value
  105. bool flag = BLLFactory<BlRule>.Instance.Update(rule, ruleId);
  106. if (flag)
  107. {
  108. DevExpress.XtraEditors.XtraMessageBox.Show("修改成功。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  109. this.Close();
  110. }
  111. }
  112. catch (Exception ex)
  113. {
  114. DevExpress.XtraEditors.XtraMessageBox.Show("修改失败。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  115. LogHelper.log.Error(string.Format("修改数据库rules出现错误:{0}", ex));
  116. }
  117. }
  118. }
  119. }