FormEditDataManage.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 DevExpress.XtraLayout;
  12. using ProjectBase.Data.Logs;
  13. using SIMDP.Model;
  14. using ProjectBase.Data.BaseDAL;
  15. using SIMDP.BLL;
  16. namespace SIMDP
  17. {
  18. public partial class FormEditDataManage : DevExpress.XtraEditors.XtraForm
  19. {
  20. //
  21. /// <summary>
  22. /// 修改的数据
  23. /// </summary>
  24. public DataRow row { get; set; }
  25. /// <summary>
  26. /// 规则列表
  27. /// </summary>
  28. public DataTable dtRule { get; set; }
  29. public string ruleId { get; set; }
  30. private List<TextEdit> txtList = new List<TextEdit>(); //动态生成的textEdit
  31. public FormEditDataManage()
  32. {
  33. InitializeComponent();
  34. }
  35. private void FormEditDataManage_Load(object sender, EventArgs e)
  36. {
  37. InitControls();
  38. }
  39. private void InitControls()
  40. {
  41. this.layoutControl1.BeginUpdate();
  42. this.layoutControlItem2.Text = dtRule.Rows[0].Field<string>("Name") + ":";
  43. this.textEditName.Text = row[3].ToString();
  44. this.layoutControl1.EndUpdate();
  45. for (int i = 1; i < dtRule.Rows.Count; i++)
  46. {
  47. DrawControls( i);
  48. }
  49. }
  50. private void btn_Cancel_Click(object sender, EventArgs e)
  51. {
  52. this.Close();
  53. }
  54. /// <summary>
  55. /// 动态创建控件
  56. /// </summary>
  57. /// <param name="i"></param>
  58. private void DrawControls(int i)
  59. {
  60. try
  61. {
  62. int y = 26 + 24 * i;
  63. this.layoutControl1.BeginUpdate();
  64. DevExpress.XtraEditors.TextEdit textName = new TextEdit();
  65. textName.Location = new System.Drawing.Point(84, 38);
  66. textName.Name = "txtRulesName" + i.ToString();
  67. textName.Size = new System.Drawing.Size(186, 20);
  68. textName.StyleController = this.layoutControl1;
  69. textName.Text = row[3 + i].ToString();
  70. this.layoutControl1.Controls.Add(textName);
  71. txtList.Add(textName);
  72. DevExpress.XtraLayout.LayoutControlItem layout1 = new DevExpress.XtraLayout.LayoutControlItem();
  73. layout1.Control = textName;
  74. layout1.Location = new System.Drawing.Point(0, y);
  75. //layout1.MaxSize = new System.Drawing.Size(150, 24);
  76. //layout1.MinSize = new System.Drawing.Size(80, 24);
  77. layout1.Name = "layout" + (i + 3).ToString();
  78. layout1.Size = new System.Drawing.Size(262, 24);
  79. //layout1.SizeConstraintsType = DevExpress.XtraLayout.SizeConstraintsType.Custom;
  80. layout1.Text = dtRule.Rows[i].Field<string>("Name") + ":";
  81. //layout1.TextAlignMode = TextAlignModeItem.AutoSize;
  82. layout1.TextSize = new System.Drawing.Size(69, 14);
  83. this.layoutControlGroup1.Items.AddRange(new DevExpress.XtraLayout.BaseLayoutItem[] { layout1 });
  84. this.layoutControl1.EndUpdate();
  85. }
  86. catch (Exception ex)
  87. {
  88. LogHelper.log.Error(string.Format("动态创建控件出现错误:{0}", ex));
  89. }
  90. }
  91. private void btn_Save_Click(object sender, EventArgs e)
  92. {
  93. try
  94. {
  95. FormUserVerification form = new FormUserVerification();
  96. form.ShowDialog();
  97. if (form.DialogResult != DialogResult.OK)
  98. {
  99. DevExpress.XtraEditors.XtraMessageBox.Show("用户验证失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  100. return;
  101. }
  102. MoProductData mo = new MoProductData();
  103. mo.DataId = Convert.ToInt64(row[0]);
  104. mo.RuleId = Convert.ToInt64(ruleId) ;
  105. mo.RuleTime = Convert.ToDateTime(row[1]);
  106. mo.Batchid = row[2].ToString();
  107. string str = this.textEditName.Text;
  108. for (int i = 0; i < txtList.Count; i++)
  109. {
  110. str += "," + txtList[i].Text;
  111. }
  112. mo.DataValue = str;
  113. bool flag = BLLFactory<BlProductData>.Instance.Update(mo,mo.DataId);
  114. if (flag)
  115. {
  116. DevExpress.XtraEditors.XtraMessageBox.Show("保存成功。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  117. this.Close();
  118. }
  119. else
  120. {
  121. DevExpress.XtraEditors.XtraMessageBox.Show("保存失败。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  122. return;
  123. }
  124. }
  125. catch (Exception ex)
  126. {
  127. DevExpress.XtraEditors.XtraMessageBox.Show("保存失败。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  128. LogHelper.log.Error(string.Format("修改数据库product_data出现错误:{0}", ex));
  129. }
  130. }
  131. }
  132. }