TEntityBase.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. using Cksoft.Unity;
  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 TEntityBase : Form
  18. {
  19. private int CurrID = 0;
  20. private TEntity CurrEntity = null;
  21. public delegate void closeForm();
  22. public delegate void AddRow(TEntity id);
  23. public event closeForm eventcloseform = null;
  24. public event AddRow eventaddrow = null;
  25. private string CurrTableName = "TEntity";
  26. public TEntityBase(TEntity id)
  27. {
  28. InitializeComponent();
  29. InitTypeItem();
  30. SetCurrID(id);
  31. }
  32. public void SetCurrID(TEntity id)
  33. {
  34. InitForm(id);
  35. }
  36. private void InitTypeItem()
  37. {
  38. StringBuilder sqlstr = new StringBuilder(100);
  39. string errorinfo = "";
  40. sqlstr.AppendFormat("select a.subid ID,a.preid 主项ID,a.fname 名称,a.fnum clevel from constitem a where a.preid in(8,9)");
  41. DataSet tempds = PubInfo.Select(sqlstr.ToString(), "constitem", ref errorinfo);
  42. if (tempds == null)
  43. {
  44. MessageBox.Show(errorinfo, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  45. return;
  46. }
  47. List<ConstItem> items = PubInfo.DataSetToItem(tempds);
  48. PubInfo.InitComboBox(editFTypeFName, items, 8);
  49. PubInfo.InitComboBox(editIfStart, items, 9);
  50. }
  51. private void InitForm(TEntity id)
  52. {
  53. CurrEntity = id;
  54. if (CurrEntity == null)
  55. {
  56. CurrEntity = new TEntity();
  57. }
  58. //用实体的值去赋值界面控件显示的值
  59. string errorinfo = "";
  60. int result = DllPubInfo.PubInfo.InitFormControl<TEntity>(panel1, CurrEntity, null, ref errorinfo);
  61. if (result < 0)
  62. MessageBox.Show(errorinfo);
  63. }
  64. private void button1_Click(object sender, EventArgs e)
  65. {
  66. InitForm(null);
  67. }
  68. private TEntity CallIUBase(TEntity entity)
  69. {
  70. try
  71. {
  72. string errorinfo = "";
  73. int result = PubInfo.UpdateRowFormControl(panel1, entity, ref errorinfo);
  74. if (result < 0)
  75. {
  76. MessageBox.Show("更新数据发生错误:" + errorinfo);
  77. return null;
  78. }
  79. Hashtable tempds = new Hashtable();
  80. string str = JsonConvert.SerializeObject(entity);
  81. tempds.Add(nameof(TEntity), str);
  82. Hashtable reds = PubInfo.CallFunction("DllStatusShowBll.StatusShowBll", "IUTEntity", tempds);
  83. if (reds == null)
  84. return null;
  85. TEntity reentity = JsonConvert.DeserializeObject<TEntity>(reds[nameof(TEntity)].ToString());
  86. return reentity;
  87. }
  88. catch (Exception e)
  89. {
  90. MessageBox.Show("操作发生错误,错误信息为:" + e.Message.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  91. return null;
  92. }
  93. }
  94. private void button2_Click(object sender, EventArgs e)
  95. {
  96. //if(edit代码.Text.Trim()=="")
  97. //{
  98. // MessageBox.Show("代码不能为空,请填写!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  99. // edit代码.Focus();
  100. // return;
  101. //}
  102. if (editFName.Text.Trim() == "")
  103. {
  104. MessageBox.Show("名称不能为空,请填写!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  105. editFName.Focus();
  106. return;
  107. }
  108. TEntity result = CallIUBase(CurrEntity);
  109. if(result!=null)
  110. {
  111. MessageBox.Show("操作成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  112. InitForm(result);
  113. eventaddrow?.Invoke(result);
  114. }
  115. }
  116. private void mmabase_FormClosing(object sender, FormClosingEventArgs e)
  117. {
  118. eventcloseform?.Invoke();
  119. }
  120. public void Selmma(DataRow row)
  121. {
  122. //if(row==null)
  123. //{
  124. // edit机型代码.Text = "";
  125. // return;
  126. //}
  127. //edit机型代码.Text = row["代码"].ToString();
  128. }
  129. private void btEmail_Click(object sender, EventArgs e)
  130. {
  131. //mmaquery temp = new mmaquery();
  132. //temp.eventselrow += Selmma;
  133. //temp.ShowDialog();
  134. }
  135. private void button3_Click(object sender, EventArgs e)
  136. {
  137. CurrEntity = new TEntity();
  138. editFCode.Text = "";
  139. }
  140. private void btEmail_Click_1(object sender, EventArgs e)
  141. {
  142. TLcdQuery temp = new TLcdQuery("");
  143. temp.eventSelRow += Temp_eventSelRow;
  144. temp.ShowDialog();
  145. }
  146. private void Temp_eventSelRow(List<TLcd> rows, int seltype)
  147. {
  148. editTLcdFCode.Text = rows[0].FCode;
  149. editTLcdFCode.Tag = rows[0].ID;
  150. editTLcdFName.Text = rows[0].FName;
  151. }
  152. }
  153. }