TLcdQuery.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. 
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Diagnostics;
  8. using System.Drawing;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading;
  12. using System.Windows.Forms;
  13. using DllEapEntity;
  14. using DllPubInfo;
  15. using Newtonsoft.Json;
  16. namespace DllXqManager
  17. {
  18. public partial class TLcdQuery : Form
  19. {
  20. private List<TLcd> CurrDs = null;
  21. public delegate void SelRow(List<TLcd> rows,int seltype);
  22. public event SelRow eventSelRow = null;
  23. private int CurrType = 1;//1为维护机台,2为选择机台
  24. private int CurrSelType = 1;//选择模式,1为启动模式,2为标准模式
  25. private string CurrCondition = "";
  26. public TLcdQuery()
  27. {
  28. InitializeComponent();
  29. }
  30. public TLcdQuery(string condition)
  31. {
  32. InitializeComponent();
  33. CurrSelType = 1;
  34. CurrCondition = condition;
  35. SetForm(2);
  36. }
  37. private void SetForm(int ftype)
  38. {
  39. CurrType = ftype;
  40. if (ftype == 2)
  41. {
  42. button3.Visible = true;
  43. button4.Visible = false;
  44. }
  45. }
  46. private string GetCondition()
  47. {
  48. StringBuilder sqlstr = new StringBuilder(100);
  49. if(edit代码.Text.Trim()!="")
  50. {
  51. sqlstr.AppendFormat(" and a.fcode like '%{0}%'", edit代码.Text.Trim());
  52. }
  53. if (edit名称.Text.Trim() != "")
  54. {
  55. sqlstr.AppendFormat(" and a.fname like '%{0}%'", edit名称.Text.Trim());
  56. }
  57. sqlstr.AppendFormat(CurrCondition);
  58. return sqlstr.ToString();
  59. }
  60. private void Filldgvmain(string condition)
  61. {
  62. try
  63. {
  64. Cursor = Cursors.WaitCursor;
  65. string errorinfo = "";
  66. CurrDs = PubInfo.SelectForCondition<TLcd>(condition, ref errorinfo).ToList();
  67. if (CurrDs == null)
  68. {
  69. MessageBox.Show(errorinfo);
  70. return;
  71. }
  72. Binddgvmain();
  73. foreach (DataGridViewColumn dgvc in dgvmain.Columns)
  74. {
  75. dgvc.ReadOnly = true;
  76. }
  77. dgvmain.Columns["选择"].ReadOnly = false;
  78. if (CurrType == 1)
  79. {
  80. //dgvmain.Columns[nameof(OrderMst.MacFCode)].Visible = false;
  81. //dgvmain.Columns[nameof(OrderMst.MacFName)].Visible = false;
  82. //dgvmain.Columns["机台指令类别"].Visible = false;
  83. //dgvmain.Columns["机台指令类别ID"].Visible = false;
  84. }
  85. }
  86. catch (Exception ex)
  87. {
  88. MessageBox.Show("操作发生错误,错误信息为:" + ex.Message.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  89. }
  90. finally
  91. {
  92. Cursor = Cursors.Default;
  93. }
  94. //dgvmain.Columns["选择"].ReadOnly = false;
  95. }
  96. private BindingSource currbs = null;
  97. private void Binddgvmain()
  98. {
  99. currbs = new BindingSource();
  100. var cols = CurrDs.Where(t => t.EntityStatusID >= 0).ToList();
  101. currbs.DataSource = cols;
  102. bindingNavigator2.BindingSource = currbs;
  103. dgvmain.DataSource = currbs;
  104. PubInfo.InitDataGridView<TLcd>(dgvmain);
  105. //dgvmain.Columns[nameof(BaseEntity.IsSelected)].Visible = false;
  106. //dgvColDetail.Rows[0].Visible = false;
  107. }
  108. private void button1_Click(object sender, EventArgs e)
  109. {
  110. Filldgvmain(GetCondition());
  111. }
  112. private Form CurrForm = null;
  113. public void CloseCurrForm()
  114. {
  115. CurrForm =null;
  116. }
  117. public void AddRow(TLcd id)
  118. {
  119. //查询是否存在,不存在则添加
  120. List<TLcd> rows = CurrDs.Where(t => t.ID == id.ID).ToList();
  121. if(rows.Count<=0)
  122. {
  123. CurrDs.Add(id);
  124. }
  125. else
  126. {
  127. rows[0] = id;
  128. }
  129. //dgvmain.Refresh();
  130. Binddgvmain();
  131. }
  132. private void ShowBase(TLcd id)
  133. {
  134. if(CurrForm != null)
  135. {
  136. (CurrForm as TLcdBase).SetCurrID(id);
  137. }
  138. else
  139. {
  140. CurrForm = new TLcdBase(id);
  141. (CurrForm as TLcdBase).eventaddrow += AddRow;
  142. (CurrForm as TLcdBase).eventcloseform += CloseCurrForm;
  143. CurrForm.Owner = this;
  144. CurrForm.Show();
  145. }
  146. }
  147. private void button4_Click(object sender, EventArgs e)
  148. {
  149. ShowBase(null);
  150. }
  151. private void mmaquery_Load(object sender, EventArgs e)
  152. {
  153. Filldgvmain(GetCondition());
  154. }
  155. private void dgvmain_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  156. {
  157. if (dgvmain.CurrentRow == null)
  158. return;
  159. ShowBase(dgvmain.CurrentRow.DataBoundItem as TLcd);
  160. }
  161. private void dgvmain_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
  162. {
  163. if (e.Button == MouseButtons.Right)
  164. {
  165. if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
  166. {
  167. dgvmain.CurrentCell = dgvmain.Rows[e.RowIndex].Cells[e.ColumnIndex];
  168. System.Drawing.Point pointglobal = System.Windows.Forms.Control.MousePosition;
  169. cms.Show(pointglobal);
  170. }
  171. }
  172. }
  173. private void toolStripMenuItem3_Click(object sender, EventArgs e)
  174. {
  175. foreach(var temprow in CurrDs)
  176. {
  177. temprow.IsSelected = 1;
  178. }
  179. dgvmain.Refresh();
  180. }
  181. private void toolStripMenuItem4_Click(object sender, EventArgs e)
  182. {
  183. foreach (var temprow in CurrDs)
  184. {
  185. temprow.IsSelected = 0;
  186. }
  187. dgvmain.Refresh();
  188. }
  189. private void button2_Click(object sender, EventArgs e)
  190. {
  191. }
  192. private void button3_Click(object sender, EventArgs e)
  193. {
  194. dgvmain.EndEdit();
  195. edit代码.Focus();
  196. List<TLcd> rows = CurrDs.Where(t => t.IsSelected == 1).ToList();
  197. if(rows.Count<=0)
  198. {
  199. MessageBox.Show("您没有选择数据,请选择!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  200. return;
  201. }
  202. eventSelRow?.Invoke(rows,CurrSelType);
  203. this.Close();
  204. }
  205. private TLcd CallIUBase(List<TLcd> entitys)
  206. {
  207. try
  208. {
  209. Hashtable tempds = new Hashtable();
  210. string str = JsonConvert.SerializeObject(entitys);
  211. tempds.Add(nameof(TLcd), str);
  212. Hashtable reds = PubInfo.CallFunction("DllStatusShowBll.StatusShowBll", "DelTLcd", tempds);
  213. if (reds == null)
  214. return null;
  215. TLcd reentity = JsonConvert.DeserializeObject<TLcd>(reds[nameof(TLcd)].ToString());
  216. return reentity;
  217. }
  218. catch (Exception e)
  219. {
  220. MessageBox.Show("操作发生错误,错误信息为:" + e.Message.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  221. return null;
  222. }
  223. }
  224. private void toolStripMenuItem2_Click(object sender, EventArgs e)
  225. {
  226. dgvmain.EndEdit();
  227. edit代码.Focus();
  228. List<TLcd> rows = CurrDs.Where(t => t.IsSelected == 1).ToList();
  229. if (rows.Count <= 0)
  230. {
  231. MessageBox.Show("您没有选择数据,请选择。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  232. return;
  233. }
  234. if (MessageBox.Show("您确定要执行此操作吗?", "询问", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk) == DialogResult.Cancel)
  235. return;
  236. TLcd result = CallIUBase(rows);
  237. if (result !=null)
  238. {
  239. MessageBox.Show("操作成功。");
  240. foreach (var temprow in rows)
  241. CurrDs.Remove(temprow);
  242. Binddgvmain();
  243. }
  244. }
  245. private void mcaquery_FormClosed(object sender, FormClosedEventArgs e)
  246. {
  247. }
  248. private void cms_Opening(object sender, CancelEventArgs e)
  249. {
  250. dgvmain.EndEdit();
  251. edit代码.Focus();
  252. }
  253. }
  254. }