TLcdBase.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. 
  2. using DllEapEntity;
  3. using DllPubInfo;
  4. using Newtonsoft.Json;
  5. using System;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. using System.ComponentModel;
  9. using System.Data;
  10. using System.Drawing;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Windows.Forms;
  15. namespace DllXqManager
  16. {
  17. public partial class TLcdBase : Form
  18. {
  19. private TLcd CurrEntity = null;
  20. public delegate void closeForm();
  21. public delegate void AddRow(TLcd id);
  22. public event closeForm eventcloseform = null;
  23. public event AddRow eventaddrow = null;
  24. public TLcdBase(TLcd id)
  25. {
  26. InitializeComponent();
  27. SetCurrID(id);
  28. }
  29. public void SetCurrID(TLcd id)
  30. {
  31. InitForm(id);
  32. }
  33. private void InitForm(TLcd id)
  34. {
  35. CurrEntity = id;
  36. if (CurrEntity == null)
  37. {
  38. CurrEntity = new TLcd();
  39. }
  40. //用实体的值去赋值界面控件显示的值
  41. string errorinfo = "";
  42. int result = DllPubInfo.PubInfo.InitFormControl<TLcd>(panel1, CurrEntity, null, ref errorinfo);
  43. if (result < 0)
  44. MessageBox.Show(errorinfo);
  45. }
  46. private void button1_Click(object sender, EventArgs e)
  47. {
  48. InitForm(null);
  49. }
  50. private TLcd CallIUBase(TLcd entity)
  51. {
  52. try
  53. {
  54. string errorinfo = "";
  55. int result = PubInfo.UpdateRowFormControl(panel1, entity, ref errorinfo);
  56. if (result < 0)
  57. {
  58. MessageBox.Show("更新数据发生错误:" + errorinfo);
  59. return null;
  60. }
  61. Hashtable tempds = new Hashtable();
  62. string str = JsonConvert.SerializeObject(entity);
  63. tempds.Add(nameof(TLcd), str);
  64. Hashtable reds = PubInfo.CallFunction("DllStatusShowBll.StatusShowBll", "IUTLcd", tempds);
  65. if (reds == null)
  66. return null;
  67. TLcd reentity = JsonConvert.DeserializeObject<TLcd>(reds[nameof(TLcd)].ToString());
  68. return reentity;
  69. }
  70. catch (Exception e)
  71. {
  72. MessageBox.Show("操作发生错误,错误信息为:" + e.Message.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  73. return null;
  74. }
  75. }
  76. private void button2_Click(object sender, EventArgs e)
  77. {
  78. //if(edit代码.Text.Trim()=="")
  79. //{
  80. // MessageBox.Show("代码不能为空,请填写!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  81. // edit代码.Focus();
  82. // return;
  83. //}
  84. if (editFName.Text.Trim() == "")
  85. {
  86. MessageBox.Show("名称不能为空,请填写!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  87. editFName.Focus();
  88. return;
  89. }
  90. TLcd result = CallIUBase(CurrEntity);
  91. if(result!=null)
  92. {
  93. MessageBox.Show("操作成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  94. InitForm(result);
  95. eventaddrow?.Invoke(result);
  96. }
  97. }
  98. private void mmabase_FormClosing(object sender, FormClosingEventArgs e)
  99. {
  100. eventcloseform?.Invoke();
  101. }
  102. public void Selmma(DataRow row)
  103. {
  104. //if(row==null)
  105. //{
  106. // edit机型代码.Text = "";
  107. // return;
  108. //}
  109. //edit机型代码.Text = row["代码"].ToString();
  110. }
  111. private void btEmail_Click(object sender, EventArgs e)
  112. {
  113. //mmaquery temp = new mmaquery();
  114. //temp.eventselrow += Selmma;
  115. //temp.ShowDialog();
  116. }
  117. private void button3_Click(object sender, EventArgs e)
  118. {
  119. //if (CurrDs == null)
  120. //{
  121. // InitForm(0);
  122. // return;
  123. //}
  124. //CurrID = 0;
  125. //CurrDs.Tables[0].Rows[0]["id"] = 0;
  126. CurrEntity = new TLcd();
  127. editFCode.Text = "";
  128. }
  129. }
  130. }