MacStatusQuery.cs 10.0 KB

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