FormEditAE2Stock.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using System;
  2. using System.Windows.Forms;
  3. using SIMDP.Model;
  4. using SIMDP.BLL;
  5. using ProjectBase.Data.Logs;
  6. using ProjectBase.Data.BaseDAL;
  7. using ProjectBase.Util;
  8. namespace SIMDP.Project
  9. {
  10. public partial class FormEditAE2Stock : DevExpress.XtraEditors.XtraForm
  11. {
  12. /// <summary>
  13. /// 定义AE2Stock对象
  14. /// </summary>
  15. public MoAE2Stock item;
  16. /// <summary>
  17. /// 定义委托
  18. /// </summary>
  19. public delegate void save();
  20. /// <summary>
  21. /// 定义事件,保存数据成功后刷新FormAE2Stock中的数据
  22. /// </summary>
  23. public event save saveData;
  24. public FormEditAE2Stock(MoAE2Stock stock)
  25. {
  26. InitializeComponent();
  27. BindingSource bs = new BindingSource();
  28. this.btn_Save.Enabled = false;
  29. if (stock != null) //修改功能
  30. {
  31. item = stock;
  32. txtValue1.Text = stock.StockId.ToString();
  33. txtValue2.Text = stock.PlcCode.ToString();
  34. txtValue3.Text = stock.State.ToString();
  35. this.btn_Save.Enabled = true;
  36. this.btn_Add.Enabled = false;
  37. }
  38. }
  39. private void btn_Cancel_Click(object sender, EventArgs e)
  40. {
  41. this.Close();
  42. }
  43. private void btn_Save_Click(object sender, EventArgs e)
  44. {
  45. try
  46. {
  47. int stockId = Convert.ToInt32(txtValue1.Text);
  48. item.PlcCode = Convert.ToInt32(txtValue2.Text);
  49. item.State = Convert.ToInt32(txtValue3.Text);
  50. bool flag;
  51. if (stockId != item.StockId)
  52. {
  53. flag = BLLFactory<BlAE2Stock>.Instance.Delete(item.StockId, SysEnvironment.CurrentLoginID);
  54. if (flag)
  55. {
  56. item.StockId = stockId;
  57. flag = BLLFactory<BlAE2Stock>.Instance.Insert(item);
  58. }
  59. }
  60. else
  61. {
  62. flag = BLLFactory<BlAE2Stock>.Instance.Update(item, item.StockId);
  63. }
  64. if (flag)
  65. {
  66. DevExpress.XtraEditors.XtraMessageBox.Show("修改成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  67. saveData();
  68. this.Close();
  69. }
  70. }
  71. catch (Exception ex)
  72. {
  73. DevExpress.XtraEditors.XtraMessageBox.Show("修改失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  74. LogHelper.log.Error(string.Format("修改数据表ae2stock出现错误:{0}", ex));
  75. }
  76. }
  77. private void btn_Add_Click(object sender, EventArgs e)
  78. {
  79. try
  80. {
  81. MoAE2Stock item = new MoAE2Stock();
  82. item.StockId = Convert.ToInt32(txtValue1.Text);
  83. item.PlcCode = Convert.ToInt32(txtValue2.Text);
  84. item.State = Convert.ToInt32(txtValue3.Text);
  85. bool flag = BLLFactory<BlAE2Stock>.Instance.Insert(item);
  86. if (flag)
  87. {
  88. DevExpress.XtraEditors.XtraMessageBox.Show("添加成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  89. saveData();
  90. this.Close();
  91. }
  92. }
  93. catch (Exception ex)
  94. {
  95. DevExpress.XtraEditors.XtraMessageBox.Show("添加失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  96. LogHelper.log.Error(string.Format("插入数据表ae2stock出现错误:{0}", ex));
  97. }
  98. }
  99. }
  100. }