FormEditModel.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. using System;
  2. using System.Collections.Generic;
  3. using ProjectBase.Controls;
  4. using SIMDP.BLL;
  5. using ProjectBase.Data.Pager;
  6. using SIMDP.Model;
  7. using ProjectBase.Util;
  8. using ProjectBase.Data.BaseDAL;
  9. using ProjectBase.Data.Logs;
  10. using ProjectBase.Data.Redis;
  11. using StackExchange.Redis;
  12. using System.Windows.Forms;
  13. using System.Drawing;
  14. using System.Data;
  15. using System.Data.Common;
  16. using System.Text.RegularExpressions;
  17. namespace SIMDP.Project
  18. {
  19. public partial class FormEditModel : DevExpress.XtraEditors.XtraForm
  20. {
  21. public delegate void delegateSaveFinished();
  22. public event delegateSaveFinished saveFinshed;
  23. private MoModelContrast mcmodel;
  24. public FormEditModel()
  25. {
  26. InitializeComponent();
  27. btn_Save.Enabled = false;
  28. btn_Add.Enabled = true;
  29. }
  30. /// <summary>
  31. /// 通过修改按钮进入的构造函数
  32. /// </summary>
  33. /// <param name="model"></param>
  34. public FormEditModel(MoModelContrast model)
  35. {
  36. InitializeComponent();
  37. txt_plccode.Text = model.PLC_Code.ToString();
  38. txt_model.Text = model.Model_Code.ToString();
  39. txt_engname.Text = model.English_Name;
  40. txt_chiname.Text = model.Chinese_Name;
  41. btn_Save.Enabled = true;
  42. btn_Add.Enabled = false;
  43. mcmodel = model;
  44. }
  45. private bool CheckCriticalField()
  46. {
  47. if (string.IsNullOrEmpty(txt_plccode.Text) || string.IsNullOrEmpty(txt_model.Text))
  48. return false;
  49. return true;
  50. }
  51. private void btn_Add_Click(object sender, EventArgs e)
  52. {
  53. if(!CheckCriticalField())
  54. {
  55. DevExpress.XtraEditors.XtraMessageBox.Show("请将关键字段填写完整。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  56. return;
  57. }
  58. try
  59. {
  60. MoModelContrast model = new MoModelContrast()
  61. {
  62. PLC_Code = Convert.ToInt32(txt_plccode.Text),
  63. Model_Code = txt_model.Text,
  64. English_Name = txt_engname.Text,
  65. Chinese_Name = txt_chiname.Text,
  66. };
  67. bool bflag = BLLFactory<BlModelContrast>.Instance.Insert(model);
  68. if (bflag)
  69. {
  70. LogHelper.log.Info($"【车型解析界面--添加按钮】用户修改条目:{model.PLC_Code} {model.Model_Code}");
  71. DevExpress.XtraEditors.XtraMessageBox.Show("添加成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  72. saveFinshed();
  73. this.Close();
  74. }
  75. }
  76. catch (Exception ex )
  77. {
  78. DevExpress.XtraEditors.XtraMessageBox.Show($"添加失败。\n{ex.Message}", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  79. LogHelper.log.Error($"异常:{ex.Message}");
  80. }
  81. }
  82. private void btn_Save_Click(object sender, EventArgs e)
  83. {
  84. if (!CheckCriticalField())
  85. {
  86. DevExpress.XtraEditors.XtraMessageBox.Show("请将关键字段填写完整。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  87. return;
  88. }
  89. try
  90. {
  91. mcmodel.PLC_Code = Convert.ToInt32(txt_plccode.Text);
  92. mcmodel.Model_Code = txt_model.Text;
  93. mcmodel.English_Name = txt_engname.Text;
  94. mcmodel.Chinese_Name = txt_chiname.Text;
  95. bool bflag = BLLFactory<BlModelContrast>.Instance.Update(mcmodel,mcmodel.Id);
  96. if (bflag)
  97. {
  98. LogHelper.log.Info($"【车型解析界面--修改按钮】用户修改条目:{mcmodel.PLC_Code} {mcmodel.Model_Code}");
  99. DevExpress.XtraEditors.XtraMessageBox.Show("修改成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  100. saveFinshed();
  101. this.Close();
  102. }
  103. }
  104. catch (Exception ex )
  105. {
  106. DevExpress.XtraEditors.XtraMessageBox.Show($"修改失败。\n{ex.Message}", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  107. LogHelper.log.Error($"异常:{ex.Message}");
  108. }
  109. }
  110. private void btn_Cancel_Click(object sender, EventArgs e)
  111. {
  112. this.Close();
  113. }
  114. protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
  115. {
  116. int WM_KEYDOWN = 256;
  117. int WM_SYSKEYDOWN = 260;
  118. if (msg.Msg == WM_KEYDOWN | msg.Msg == WM_SYSKEYDOWN)
  119. {
  120. switch (keyData)
  121. {
  122. case Keys.Escape:
  123. //Application.Exit();
  124. this.Close();
  125. break;
  126. }
  127. }
  128. return false;
  129. }
  130. private void txt_plccode_KeyPress(object sender, KeyPressEventArgs e)
  131. {
  132. if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar))
  133. {
  134. e.Handled = true;
  135. }
  136. }
  137. }
  138. }