FrmTubTechnological.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using CoreFS.CA06;
  10. using Core.Mes.Client.Comm.Tool;
  11. using Core.StlMes.Client.ZGMil.Entity;
  12. using Core.Mes.Client.Comm.Server;
  13. using System.Windows.Documents;
  14. using Infragistics.Win.UltraWinEditors;
  15. using Infragistics.Win.UltraWinGrid;
  16. using Infragistics.Win;
  17. using System.Text.RegularExpressions;
  18. using System.Collections;
  19. using Core.Mes.Client.Comm.Format;
  20. namespace Core.StlMes.Client.ZGMil.Signature
  21. {
  22. public partial class FrmTubTechnological : FrmBase
  23. {
  24. public FrmTubTechnological()
  25. {
  26. InitializeComponent();
  27. }
  28. private void FrmTubTechnological_Load(object sender, EventArgs e)
  29. {
  30. EntityHelper.ShowGridCaption<MilCraftworkSetEntity>(ultraGrid1.DisplayLayout.Bands[0]);
  31. EntityHelper.ShowGridCaption<MilCraftworkSetEntity>(ultraGrid2.DisplayLayout.Bands[0]);
  32. InitBase();
  33. }
  34. UltraComboEditor plineCode = new UltraComboEditor();
  35. UltraComboEditor station = new UltraComboEditor();
  36. UltraComboEditor factoryId = new UltraComboEditor();
  37. UltraNumericEditor numEditor = new UltraNumericEditor();
  38. UltraDateTimeEditor dateEditor = new UltraDateTimeEditor();
  39. /// <summary>
  40. /// 加载基础信息
  41. /// </summary>
  42. private void InitBase()
  43. {
  44. string[] arr = null;
  45. NativeMethodNew na = new NativeMethodNew(this.ob);
  46. arr = na.GetPCodePline(this.ValidDataPurviewIds);
  47. InitComboEditor1(plineCode, "com.steering.mes.signature.FrmTubTechnological.doQueryPline", "PLINE_CODE", this.ob, false,arr);
  48. BindColumn(plineCode, "PlineName", this.Controls, this.ultraGrid1, 0);
  49. InitComboEditor(station, "com.steering.mes.signature.FrmTubTechnological.doQueryStation", "STATION_CODE",this.ob, false);
  50. BindColumn(station, "StationDesc", this.Controls, this.ultraGrid1, 0);
  51. }
  52. /// <summary>
  53. /// 初始化下拉框
  54. /// </summary>
  55. /// <param name="uce">下拉框</param>
  56. /// <param name="methodId">请求的服务</param>
  57. /// <param name="valueMember">值成员</param>
  58. /// <param name="ob">ob对象</param>
  59. /// <param name="isEmpty">是否有空行</param>
  60. public static void InitComboEditor(UltraComboEditor uce, string methodId, string valueMember, OpeBase ob, bool isEmpty)
  61. {
  62. DataTable dt = ServerHelper.GetData(methodId, null, ob);
  63. if (dt != null && dt.Rows.Count > 0)
  64. {
  65. if (isEmpty)
  66. {
  67. Object[] obj = new Object[] { "", "" };
  68. DataRow dr = dt.NewRow();
  69. dr.ItemArray = obj;
  70. dt.Rows.InsertAt(dr, 0);
  71. }
  72. uce.ValueMember = valueMember;
  73. uce.DataSource = dt;
  74. SetComboItemHeight(uce);
  75. }
  76. }
  77. public static void InitComboEditor2(UltraComboEditor uce, string methodId, string valueMember, OpeBase ob, string value,bool isEmpty)
  78. {
  79. DataTable dt = ServerHelper.GetData(methodId, new object[] { value }, ob);
  80. if (dt != null && dt.Rows.Count > 0)
  81. {
  82. if (isEmpty)
  83. {
  84. Object[] obj = new Object[] { "", "" };
  85. DataRow dr = dt.NewRow();
  86. dr.ItemArray = obj;
  87. dt.Rows.InsertAt(dr, 0);
  88. }
  89. uce.ValueMember = valueMember;
  90. uce.DataSource = dt;
  91. SetComboItemHeight(uce);
  92. }
  93. }
  94. public static void InitComboEditor1(UltraComboEditor uce, string methodId, string valueMember, OpeBase ob, bool isEmpty,string[] arr)
  95. {
  96. DataTable dt = ServerHelper.GetData(methodId, new object[]{arr}, ob);
  97. if (dt != null && dt.Rows.Count > 0)
  98. {
  99. if (isEmpty)
  100. {
  101. Object[] obj = new Object[] { "", "" };
  102. DataRow dr = dt.NewRow();
  103. dr.ItemArray = obj;
  104. dt.Rows.InsertAt(dr, 0);
  105. }
  106. uce.ValueMember = valueMember;
  107. uce.DataSource = dt;
  108. SetComboItemHeight(uce);
  109. }
  110. }
  111. /// <summary>
  112. /// 将下拉框绑定到GRID列
  113. /// </summary>
  114. /// <param name="uce">下拉框(已经初始化完成)</param>
  115. /// <param name="ColumnName">列名</param>
  116. /// <param name="con">空间集合(每次只需填入this.Controls)</param>
  117. /// <param name="ug">GRID</param>
  118. /// <param name="i">GRID的第几层结构</param>
  119. public static void BindColumn(UltraComboEditor uce, string ColumnName, System.Windows.Forms.Control.ControlCollection con, UltraGrid ug, int i)
  120. {
  121. con.Add(uce);
  122. uce.Visible = false;
  123. ug.DisplayLayout.Bands[i].Columns[ColumnName].EditorComponent = uce;
  124. ug.DisplayLayout.Bands[i].Columns[ColumnName].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
  125. SetComboItemHeight(uce);
  126. }
  127. /// <summary>
  128. /// 设置UltraComboEditor中的中文和非中文统一高度。
  129. /// </summary>
  130. /// <param name="cmb"></param>
  131. public static void SetComboItemHeight(UltraComboEditor cmb)
  132. {
  133. foreach (ValueListItem item in cmb.Items)
  134. {
  135. if (Regex.IsMatch(item.DisplayText, @"[\u4e00-\u9fa5]+"))
  136. {
  137. item.Appearance.FontData.SizeInPoints = 9.0F;
  138. }
  139. else
  140. {
  141. item.Appearance.FontData.SizeInPoints = 10.5F;
  142. }
  143. }
  144. }
  145. /// <summary>
  146. /// 重写基类方法
  147. /// </summary>
  148. /// <param name="sender"></param>
  149. /// <param name="ToolbarKey"></param>
  150. public override void ToolBar_Click(object sender, string ToolbarKey)
  151. {
  152. switch (ToolbarKey)
  153. {
  154. case "Query":
  155. doQueryData();
  156. break;
  157. case "Add":
  158. doAdd();
  159. break;
  160. case"Update":
  161. doUpdate();
  162. break;
  163. case"Delete":
  164. doDelete();
  165. break;
  166. case "Close":
  167. this.Close();
  168. break;
  169. }
  170. }
  171. /// <summary>
  172. /// 删除工艺项
  173. /// </summary>
  174. private void doDelete()
  175. {
  176. UltraGridRow urg = ultraGrid2.ActiveRow;
  177. if (urg == null) { MessageUtil.ShowTips("无数据!"); return; }
  178. this.ultraGrid2.UpdateData();
  179. IQueryable<UltraGridRow> checkMagRows = this.ultraGrid2.Rows.AsQueryable().Where(" CHK = 'True'");
  180. if (checkMagRows.Count() == 0)
  181. {
  182. if (MessageUtil.ShowYesNoAndQuestion("是否作废该项所有工艺项?") == DialogResult.No)
  183. {
  184. MessageUtil.ShowTips("请选择需要作废的的工艺项!");
  185. return;
  186. }
  187. else
  188. {
  189. foreach (UltraGridRow row1 in ultraGrid2.Rows)
  190. {
  191. row1.Cells["CHK"].Value = true;
  192. }
  193. }
  194. }
  195. IQueryable<UltraGridRow> checkMagRows1 = this.ultraGrid2.Rows.AsQueryable().Where(" CHK = 'True'");
  196. ArrayList parm = new ArrayList();
  197. foreach (UltraGridRow row in checkMagRows1)
  198. {
  199. MilCraftworkSetEntity _milCraftEntity = EntityHelper.CopyEntity<MilCraftworkSetEntity>(row.ListObject);
  200. string _milCraftTity = JSONFormat.Format(_milCraftEntity);
  201. parm.Add(_milCraftTity);
  202. }
  203. if (MessageUtil.ShowYesNoAndQuestion("是否确认作废工艺项?") == DialogResult.No)
  204. {
  205. return;
  206. }
  207. CoreClientParam ccp = new CoreClientParam();
  208. ccp.ServerName = "com.steering.mes.signature.FrmTubTechnological";
  209. ccp.MethodName = "doDeleteData";
  210. ccp.ServerParams = new object[] { parm };
  211. ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  212. if (ccp.ReturnCode != -1)
  213. {
  214. if (ccp.ReturnInfo.Equals("作废成功!"))
  215. {
  216. doQueryData();
  217. MessageUtil.ShowTips(ccp.ReturnInfo);
  218. }
  219. }
  220. else
  221. {
  222. MessageUtil.ShowTips(ccp.ReturnInfo);
  223. }
  224. }
  225. /// <summary>
  226. /// 修改工艺项
  227. /// </summary>
  228. private void doUpdate()
  229. {
  230. this.ultraGrid2.UpdateData();
  231. IQueryable<UltraGridRow> checkMagRows = this.ultraGrid2.Rows.AsQueryable().Where(" CHK = 'True'");
  232. if (checkMagRows.Count() == 0)
  233. {
  234. MessageUtil.ShowTips("请选择需要修改的的工艺项!");
  235. return;
  236. }
  237. ArrayList parm = new ArrayList();
  238. foreach (UltraGridRow row in checkMagRows)
  239. {
  240. if (row.Cells["FactorName"].Text.ToString() == "" || row.Cells["FactorVal"].Text.ToString() == "")
  241. {
  242. MessageUtil.ShowTips("工艺项/工艺参数都不能为空!");
  243. return;
  244. }
  245. MilCraftworkSetEntity _milCraftEntity = EntityHelper.CopyEntity<MilCraftworkSetEntity>(row.ListObject);
  246. _milCraftEntity.FactorId = row.Cells["FactorName"].Value.ToString();
  247. _milCraftEntity.FactorName = row.Cells["FactorName"].Text.Trim();
  248. _milCraftEntity.UpdateName = this.UserInfo.GetUserName();
  249. string _milCraftTity = JSONFormat.Format(_milCraftEntity);
  250. parm.Add(_milCraftTity);
  251. }
  252. if (MessageUtil.ShowYesNoAndQuestion("是否修改工艺项?") == DialogResult.No)
  253. {
  254. return;
  255. }
  256. CoreClientParam ccp = new CoreClientParam();
  257. ccp.ServerName = "com.steering.mes.signature.FrmTubTechnological";
  258. ccp.MethodName = "doUpdateData";
  259. ccp.ServerParams = new object[] {parm};
  260. ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  261. if (ccp.ReturnCode != -1)
  262. {
  263. if (ccp.ReturnInfo.Equals("修改成功!"))
  264. {
  265. doQueryData();
  266. MessageUtil.ShowTips(ccp.ReturnInfo);
  267. }
  268. }
  269. else
  270. {
  271. MessageUtil.ShowTips(ccp.ReturnInfo);
  272. }
  273. }
  274. /// <summary>
  275. /// 查询已维护的工艺参数
  276. /// </summary>
  277. private void doQueryData()
  278. {
  279. string[] arr = null;
  280. NativeMethodNew na = new NativeMethodNew(this.ob);
  281. arr = na.GetPCodePline(this.ValidDataPurviewIds);
  282. List<MilCraftworkSetEntity> listSource = EntityHelper.GetData<MilCraftworkSetEntity>("com.steering.mes.signature.FrmTubTechnological.doQueryData", new object[] { arr }, ob);
  283. MilCraftworkSetEntitybindingSource.DataSource = listSource;
  284. }
  285. /// <summary>
  286. /// 维护工艺参数
  287. /// </summary>
  288. private void doAdd()
  289. {
  290. this.ultraGrid1.UpdateData();
  291. this.ultraGrid2.UpdateData();
  292. UltraGridRow uRow = this.ultraGrid1.ActiveRow;
  293. if (!(uRow.Cells["PlineName"].Text.ToString() != "" && uRow.Cells["StationDesc"].Text.ToString() != "" && uRow.Cells["ClassName"].Text.Trim() != ""))
  294. {
  295. MessageUtil.ShowTips("机组/工序点/版本号都不允许为空!");
  296. return;
  297. }
  298. List<string> ss = new List<string>();
  299. ArrayList list = new ArrayList();
  300. MilCraftworkSetEntity milCraftEntity = EntityHelper.CopyEntity<MilCraftworkSetEntity>(uRow.ListObject);
  301. if (milCraftEntity.PlineCode.Equals(""))
  302. {
  303. milCraftEntity.PlineCode = uRow.Cells["PlineName"].Value.ToString();
  304. milCraftEntity.PlineName = uRow.Cells["PlineName"].Text.Trim();
  305. milCraftEntity.StationCode = uRow.Cells["StationDesc"].Value.ToString();
  306. milCraftEntity.StationDesc = uRow.Cells["StationDesc"].Text.Trim();
  307. milCraftEntity.CreateName = this.UserInfo.GetUserName();
  308. }
  309. else
  310. {
  311. milCraftEntity.CreateName = this.UserInfo.GetUserName();
  312. }
  313. string milCraftTity = JSONFormat.Format(milCraftEntity);
  314. list.Add(milCraftTity);
  315. IQueryable<UltraGridRow> checkMagRows = this.ultraGrid2.Rows.AsQueryable().Where(" CHK = 'True'");
  316. if (checkMagRows.Count() == 0)
  317. {
  318. MessageUtil.ShowTips("请选择需要维护的工艺项!");
  319. return;
  320. }
  321. ArrayList parm = new ArrayList();
  322. foreach(UltraGridRow row in checkMagRows)
  323. {
  324. if (row.Cells["FactorName"].Text.ToString() == "" || row.Cells["FactorVal"].Text.ToString() == "")
  325. {
  326. MessageUtil.ShowTips("工艺项/工艺参数都不能为空!");
  327. return;
  328. }
  329. MilCraftworkSetEntity _milCraftEntity = EntityHelper.CopyEntity <MilCraftworkSetEntity>(row.ListObject);
  330. _milCraftEntity.FactorId = row.Cells["FactorName"].Value.ToString();
  331. _milCraftEntity.FactorName = row.Cells["FactorName"].Text.Trim();
  332. string _milCraftTity = JSONFormat.Format(_milCraftEntity);
  333. parm.Add(_milCraftTity);
  334. if (ss.Contains(_milCraftEntity.FactorName.ToString()))
  335. {
  336. MessageUtil.ShowTips("已选择相同工艺项,不允许重复!");
  337. return;
  338. }
  339. else
  340. {
  341. ss.Add(_milCraftEntity.FactorName.ToString());
  342. }
  343. }
  344. if (!getCraftSet(uRow.Cells["PlineName"].Value.ToString2(), uRow.Cells["StationDesc"].Value.ToString2(), uRow.Cells["ClassName"].Text.Trim()))
  345. {
  346. MessageUtil.ShowTips("已存在该版本名称,不允许重复!");
  347. return;
  348. }
  349. if (MessageUtil.ShowYesNoAndQuestion("是否维护工艺参数?") == DialogResult.No)
  350. {
  351. return;
  352. }
  353. CoreClientParam ccp = new CoreClientParam();
  354. ccp.ServerName = "com.steering.mes.signature.FrmTubTechnological";
  355. ccp.MethodName = "doAdd";
  356. ccp.ServerParams = new object[] {list,parm };
  357. ccp = ob.ExecuteNonQuery(ccp,CoreInvokeType.Internal);
  358. if (ccp.ReturnCode != -1)
  359. {
  360. if (ccp.ReturnInfo.Equals("维护成功!"))
  361. {
  362. doQueryData();
  363. MessageUtil.ShowTips(ccp.ReturnInfo);
  364. }
  365. }
  366. else
  367. {
  368. MessageUtil.ShowTips(ccp.ReturnInfo);
  369. }
  370. }
  371. /// <summary>
  372. /// 判断是否已有相同产线版本
  373. /// </summary>
  374. /// <returns></returns>
  375. private bool getCraftSet(string plineCode,string stationId,string className)
  376. {
  377. DataTable ds = ServerHelper.GetData("com.steering.mes.signature.FrmTubTechnological.getCraftSet", new object[] { plineCode, stationId, className }, ob);
  378. if (ds.Rows.Count > 0)
  379. {
  380. return false;
  381. }
  382. else
  383. {
  384. return true;
  385. }
  386. }
  387. private void doQueryData(string className,string stationCode,string plineCode)
  388. {
  389. List<MilCraftworkSetEntity> listSource = EntityHelper.GetData<MilCraftworkSetEntity>("com.steering.mes.signature.FrmTubTechnological.doQuery", new object[] { className, stationCode, plineCode }, ob);
  390. MilCraftworkSetEntity1bindingSource.DataSource = listSource;
  391. }
  392. private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
  393. {
  394. doQueryData(this.ultraGrid1.ActiveRow.Cells["ClassName"].Value.ToString(), this.ultraGrid1.ActiveRow.Cells["stationCode"].Value.ToString(), this.ultraGrid1.ActiveRow.Cells["PlineCode"].Value.ToString());
  395. }
  396. private void ultraGrid2_CellChange(object sender, CellEventArgs e)
  397. {
  398. ultraGrid2.UpdateData();
  399. UltraGridRow ugr = this.ultraGrid2.ActiveRow;
  400. string factorId = "";
  401. if (e.Cell.Column.Key.Equals("FactorName"))
  402. {
  403. factorId = this.ultraGrid2.ActiveRow.Cells["FactorName"].Value.ToString();
  404. DataTable ds = ServerHelper.GetData("com.steering.mes.signature.FrmTubTechnological.doQueryType", new object[] { factorId }, ob);
  405. if (ds.Rows.Count > 0)
  406. {
  407. if (ds.Rows[0]["COLUMN_TYPE"].ToString() == "D")
  408. {
  409. this.ultraGrid2.ActiveRow.Cells["FactorVal"].Value = "";
  410. ugr.Cells["FactorVal"].EditorComponent = numEditor;
  411. numEditor.NumericType = NumericType.Decimal;
  412. numEditor.MaskInput = "nnnnn.nnn";
  413. }
  414. else if (ds.Rows[0]["COLUMN_TYPE"].ToString() == "T")
  415. {
  416. this.ultraGrid2.ActiveRow.Cells["FactorVal"].Value = "";
  417. ugr.Cells["FactorVal"].EditorComponent = dateEditor;
  418. dateEditor.FormatString = "yyyy-MM-dd HH:mm:ss";
  419. }
  420. else
  421. {
  422. this.ultraGrid2.ActiveRow.Cells["FactorVal"].Value = "";
  423. ugr.Cells["FactorVal"].EditorComponent = null;
  424. }
  425. }
  426. }
  427. }
  428. private void ultraGrid1_CellChange(object sender, CellEventArgs e)
  429. {
  430. this.ultraGrid1.UpdateData();
  431. if (e.Cell.Column.Key == "StationDesc")
  432. {
  433. InitComboEditor2(factoryId, "com.steering.mes.signature.FrmTubTechnological.doQueryFactor", "FACTOR_ID",this.ob, this.ultraGrid1.ActiveRow.Cells["StationDesc"].Value.ToString2(), false);
  434. BindColumn(factoryId, "FactorName", this.Controls, this.ultraGrid2, 0);
  435. }
  436. }
  437. }
  438. }