123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- using ProjectBase.Data.BaseDAL;
- using ProjectBase.Data.Logs;
- using SIMDP.BLL;
- using SIMDP.Model;
- using ProjectBase.Util;
- using System;
- using System.Data;
- using System.Windows.Forms;
- namespace SIMDP.View
- {
- public partial class FormEditRuleValue : DevExpress.XtraEditors.XtraForm
- {
- /// <summary>
- /// 执行添加修改操作的rule_Value
- /// </summary>
- private DataTable dt;
- /// <summary>
- /// 需要修改的变量
- /// </summary>
- private DataRow dtRow;
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="dt">执行添加修改操作的rule_Value</param>
- /// <param name="selectRow">要修改的变量/param>
- public FormEditRuleValue(DataTable dtRule, DataRow selectRow)
- {
- InitializeComponent();
- dt = dtRule;
- InitControls(selectRow);
- }
- /// <summary>
- /// 初始化控件
- /// </summary>
- /// <param name="selectRow">要修改的变量</param>
- private void InitControls(DataRow selectRow)
- {
- //下拉框--类型
- BindingSource bsType = new BindingSource();
- bsType.DataSource = SysEnvironment.dirType;
- this.lookUp_RuleType.Properties.DataSource = bsType;
- this.lookUp_RuleType.Properties.ValueMember = "Key";
- this.lookUp_RuleType.Properties.DisplayMember = "Value";
- this.lookUp_RuleType.Properties.NullText = "请您选择";
- //下拉框--查询条件
- BindingSource bsQuery = new BindingSource();
- bsQuery.DataSource = SysEnvironment.dirRuleValueQuery;
- this.lookUp_RuleQuery.Properties.DataSource = bsQuery;
- this.lookUp_RuleQuery.Properties.ValueMember = "Key";
- this.lookUp_RuleQuery.Properties.DisplayMember = "Value";
- this.lookUp_RuleQuery.Properties.NullText = "请您选择";
- //下拉框--名称
- this.textEditRuleName.Text = selectRow["Name"].ToString();
- this.lookUp_RuleType.EditValue = Convert.ToInt32(selectRow["Type"]);
- this.lookUp_RuleQuery.Properties.NullText = selectRow["Query"].ToString();
- this.txt_RuleOrder.Text = selectRow["OrderNum"].ToString();
- if (selectRow != null)
- {
- dtRow = selectRow;
- }
- }
- private void btn_Cancel_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- private void btn_Save_Click(object sender, EventArgs e)
- {
- try
- {
- if (lookUp_RuleType.Text == "请您选择" || lookUp_RuleQuery.Text == "请您选择" || string.IsNullOrEmpty(txt_RuleOrder.Text))
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("请将信息填写完整。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- DataRow[] drArr = dt.Select(string.Format("OrderNum = '{0}'", txt_RuleOrder.Text));
- if (drArr.Length > 0)
- {
- if (dtRow["OrderNum"].ToString() != txt_RuleOrder.Text)
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("此序号已存在,请重新输入。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- }
- FormUserVerification form = new FormUserVerification();
- form.ShowDialog();
- if (form.DialogResult != DialogResult.OK)
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("用户验证失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- string ruleId = dtRow["RuleId"].ToString();
- //string id = lookUp_RuleID.Text;
- string name = this.textEditRuleName.Text;
- string type = lookUp_RuleType.EditValue.ToString();
- string orderNum = txt_RuleOrder.Text;
- string query = lookUp_RuleQuery.Text;
- dt.Rows.Remove(dtRow);
- dt.Rows.Add(ruleId, name, type, orderNum, query);
- //将dataTable中的数据按照规则组合成数据表rules中的rule_value字段值
- //BlRule blRule = new BlRule();
- string ruleValue = BLLFactory<BlRule>.Instance.FormRuleValue(dt);
- MoRule rule = BLLFactory<BlRule>.Instance.FindByID(ruleId);
- rule.RuleValue = ruleValue;
- //修改数据库中的rule_value
- bool flag = BLLFactory<BlRule>.Instance.Update(rule, ruleId);
- if (flag)
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("修改成功。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
- this.Close();
- }
- }
- catch (Exception ex)
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("修改失败。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
- LogHelper.log.Error(string.Format("修改数据库rules出现错误:{0}", ex));
- }
- }
- }
- }
|