LayoutMstQuery.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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.Diagnostics;
  11. using System.Drawing;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading;
  15. using System.Windows.Forms;
  16. namespace DllXqManager
  17. {
  18. public partial class LayoutMstQuery : Form
  19. {
  20. private List<LayoutMst> CurrDs = null;
  21. public delegate void SelRow(List<LayoutMst> 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 LayoutMstQuery()
  27. {
  28. InitializeComponent();
  29. }
  30. public LayoutMstQuery(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<LayoutMst>(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<LayoutMst>(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. private void ShowBase(LayoutMst id)
  118. {
  119. //if(CurrForm != null)
  120. //{
  121. // (CurrForm as TLcdBase).SetCurrID(id);
  122. //}
  123. //else
  124. //{
  125. // CurrForm = new TLcdBase(id);
  126. // (CurrForm as TLcdBase).eventaddrow += AddRow;
  127. // (CurrForm as TLcdBase).eventcloseform += CloseCurrForm;
  128. // CurrForm.Owner = this;
  129. // CurrForm.Show();
  130. //}
  131. LayoutMstBase temp = new LayoutMstBase(id);
  132. temp.ShowDialog();
  133. }
  134. private void ShowBaseFor(LayoutMst id)
  135. {
  136. //if(CurrForm != null)
  137. //{
  138. // (CurrForm as TLcdBase).SetCurrID(id);
  139. //}
  140. //else
  141. //{
  142. // CurrForm = new TLcdBase(id);
  143. // (CurrForm as TLcdBase).eventaddrow += AddRow;
  144. // (CurrForm as TLcdBase).eventcloseform += CloseCurrForm;
  145. // CurrForm.Owner = this;
  146. // CurrForm.Show();
  147. //}
  148. LayoutMstBaseFor temp = new LayoutMstBaseFor(id);
  149. temp.Show();
  150. }
  151. private void button4_Click(object sender, EventArgs e)
  152. {
  153. ShowBase(null);
  154. }
  155. private void mmaquery_Load(object sender, EventArgs e)
  156. {
  157. Filldgvmain(GetCondition());
  158. }
  159. private void dgvmain_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  160. {
  161. if (dgvmain.CurrentRow == null)
  162. return;
  163. ShowBaseFor(dgvmain.CurrentRow.DataBoundItem as LayoutMst);
  164. }
  165. private void dgvmain_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
  166. {
  167. if (e.Button == MouseButtons.Right)
  168. {
  169. if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
  170. {
  171. dgvmain.CurrentCell = dgvmain.Rows[e.RowIndex].Cells[e.ColumnIndex];
  172. System.Drawing.Point pointglobal = System.Windows.Forms.Control.MousePosition;
  173. cms.Show(pointglobal);
  174. }
  175. }
  176. }
  177. private void toolStripMenuItem3_Click(object sender, EventArgs e)
  178. {
  179. foreach(var temprow in CurrDs)
  180. {
  181. temprow.IsSelected = 1;
  182. }
  183. dgvmain.Refresh();
  184. }
  185. private void toolStripMenuItem4_Click(object sender, EventArgs e)
  186. {
  187. foreach (var temprow in CurrDs)
  188. {
  189. temprow.IsSelected = 0;
  190. }
  191. dgvmain.Refresh();
  192. }
  193. private void button2_Click(object sender, EventArgs e)
  194. {
  195. }
  196. private void button3_Click(object sender, EventArgs e)
  197. {
  198. dgvmain.EndEdit();
  199. edit代码.Focus();
  200. List<LayoutMst> rows = CurrDs.Where(t => t.IsSelected == 1).ToList();//.Tables[0].Select("选择=1");
  201. if(rows.Count<=0)
  202. {
  203. MessageBox.Show("您没有选择数据,请选择!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  204. return;
  205. }
  206. eventSelRow?.Invoke(rows,CurrSelType);
  207. this.Close();
  208. }
  209. private LayoutMst DelLayoutMst(List<LayoutMst> entitys)
  210. {
  211. try
  212. {
  213. Hashtable tempds = new Hashtable();
  214. string str = JsonConvert.SerializeObject(entitys);
  215. tempds.Add(nameof(LayoutMst), str);
  216. Hashtable reds = PubInfo.CallFunction("DllStatusShowBll.StatusShowBll", "DelLayoutMst", tempds);
  217. if (reds == null)
  218. return null;
  219. LayoutMst reentity = JsonConvert.DeserializeObject<LayoutMst>(reds[nameof(LayoutMst)].ToString());
  220. return reentity;
  221. }
  222. catch (Exception e)
  223. {
  224. MessageBox.Show("操作发生错误,错误信息为:" + e.Message.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  225. return null;
  226. }
  227. }
  228. private void toolStripMenuItem2_Click(object sender, EventArgs e)
  229. {
  230. List<LayoutMst> rows = CurrDs.Where(t => t.IsSelected == 1).ToList();//.Tables[CurrTableName].Select("选择=1");
  231. if (rows.Count <= 0)
  232. {
  233. MessageBox.Show("您没有选择数据,请选择。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  234. return;
  235. }
  236. if (MessageBox.Show("您确定要执行此操作吗?", "询问", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk) == DialogResult.Cancel)
  237. return;
  238. LayoutMst result = DelLayoutMst(rows);
  239. if (result != null)
  240. {
  241. MessageBox.Show("操作成功。");
  242. foreach (var temprow in rows)
  243. CurrDs.Remove(temprow);
  244. Binddgvmain();
  245. }
  246. }
  247. private void mcaquery_FormClosed(object sender, FormClosedEventArgs e)
  248. {
  249. }
  250. private void cms_Opening(object sender, CancelEventArgs e)
  251. {
  252. dgvmain.EndEdit();
  253. edit代码.Focus();
  254. }
  255. private void 编辑位置ToolStripMenuItem_Click(object sender, EventArgs e)
  256. {
  257. if (dgvmain.CurrentRow == null)
  258. return;
  259. LayoutMst mst = dgvmain.CurrentRow.DataBoundItem as LayoutMst;
  260. LayoutMstBase temp = new LayoutMstBase(mst);
  261. temp.Show();
  262. }
  263. }
  264. }