ucResAdditiveProcess.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Windows.Forms;
  8. using Core.Mes.Client.Comm.Server;
  9. using Core.Mes.Client.Comm.Tool;
  10. using Core.StlMes.Client.LgClassModel;
  11. using CoreFS.CA06;
  12. using Infragistics.Win;
  13. using Infragistics.Win.UltraWinGrid;
  14. namespace Core.StlMes.Client.LgCommon
  15. {
  16. public partial class ucResAdditiveProcess : UserControl
  17. {
  18. public ucResAdditiveProcess()
  19. {
  20. InitializeComponent();
  21. ClsControlPack.RefreshAndAutoSize(ugData);
  22. }
  23. private OpeBase _ob;
  24. private DataTable columns;
  25. private string _stove = "";
  26. private string _station = "";
  27. private string _disposalTime = "";
  28. private LG_PROCESS _process;
  29. private bool flag = false;
  30. private bool _changed = false;
  31. public void SetOb(OpeBase ob)
  32. {
  33. _ob = ob;
  34. }
  35. public bool Changed
  36. {
  37. get
  38. {
  39. return _changed ? _changed : ugData.Rows.Count >= 0 && ugData.Rows.Any(p => (bool)p.Cells["NewRow"].Value);
  40. }
  41. }
  42. public bool CanSave
  43. {
  44. get
  45. {
  46. try
  47. {
  48. ugData.UpdateData();
  49. }
  50. catch (Exception)
  51. {
  52. return false;
  53. }
  54. return ugData.Rows.Count<=0 || ugData.Rows.All(p => (bool)p.Cells["Valid"].Value);
  55. }
  56. }
  57. public bool SaveDate()
  58. {
  59. if (_ob == null) return false;
  60. if (!Changed || dataTable1.Rows.Count<=0) return true;
  61. if (!CanSave)
  62. {
  63. MessageBox.Show(@"添加料过程数据不正确,无法保存添加料过程数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  64. return true;
  65. }
  66. var data = dataTable1.AsEnumerable().Select(p =>
  67. {
  68. List<Dictionary<string, object>> datas = new List<Dictionary<string, object>>();
  69. for (int i = 3; i < p.ItemArray.Length; i++)
  70. {
  71. if (p[i] == DBNull.Value || p[i] == null || p[i].ToString().Trim()=="") continue;
  72. datas.Add(new Dictionary<string, object>()
  73. {
  74. { "Code", dataTable1.Columns[i].ColumnName },
  75. { "Value" , p[i] }
  76. });
  77. }
  78. return new Dictionary<string, object>()
  79. {
  80. { dataTable1.Columns[0].ColumnName, p[0] },
  81. { dataTable1.Columns[1].ColumnName, (p[1]==null|| string.IsNullOrEmpty(p[1].ToString()))?" ":p[1] },
  82. { dataTable1.Columns[2].ColumnName, p[2] },
  83. { "Data",datas }
  84. };
  85. }
  86. ).ToList();
  87. try
  88. {
  89. ServerHelper.SetData("Core.LgMes.Server.LgDeviceManager.StlAdditive.SaveAdditivesProcess", new object[] { data,_process.ToString(), _stove,
  90. _station,_disposalTime }, _ob);
  91. return true;
  92. }
  93. catch (Exception ex)
  94. {
  95. return false;
  96. }
  97. }
  98. public void SetData(LG_PROCESS PROCESS,string Stove, string station, string disposalTime)
  99. {
  100. _stove = Stove;
  101. _station = station;
  102. _disposalTime = disposalTime;
  103. _process = PROCESS;
  104. Refresh();
  105. }
  106. private void Refresh()
  107. {
  108. if (_ob == null) return;
  109. dataTable1.Rows.Clear();
  110. DataTable datas =
  111. ServerHelper.GetData(
  112. "Core.LgMes.Server.LgDeviceManager.StlAdditive.GetAdditivesProcess",
  113. new object[]
  114. {
  115. _process.ToString(),
  116. _stove,
  117. _station,
  118. _disposalTime
  119. }, _ob);
  120. if (datas==null ||datas.Rows.Count <= 0) return;
  121. foreach (DataRow row in datas.Rows)
  122. {
  123. var newRow = dataTable1.NewRow();
  124. newRow["JMDATE"] = row["JMDATE"];
  125. newRow["HOPPERNUMID"] = row["HOPPERNUMID"];
  126. newRow["MATERIELTYPE"] = row["MATERIELTYPE"];
  127. string code = row["MATERIELCODE"].ToString();
  128. string value = row["JMWGT"].ToString();
  129. if(!dataTable1.Columns.Contains(code)) continue;
  130. newRow[code] = value;
  131. if (CheckRowValid(newRow))
  132. {
  133. dataTable1.Rows.Add(newRow);
  134. var tempRow = ugData.Rows[ugData.Rows.Count - 1];
  135. tempRow.Cells["Valid"].Value = true;
  136. }
  137. }
  138. if (dataTable1.Rows.Count >= 0)
  139. {
  140. ClsControlPack.RefreshAndAutoSize(ugData);
  141. }
  142. _changed = false;
  143. }
  144. public void RefeshColumns(string strStationCode)
  145. {
  146. ugData.BeginUpdate();
  147. bool bSuccess;
  148. string strMsg;
  149. DataSet ds = ClsDataAccessPack.GetData("AddColumns.Select", new ArrayList { strStationCode, strStationCode }, out bSuccess, out strMsg, _ob);
  150. if (!bSuccess || ds.Tables.Count <= 0) return;
  151. columns = ds.Tables[0];
  152. ValueList vlist = new ValueList();
  153. foreach (DataRow row in columns.Rows)
  154. {
  155. string TypeCode = row["ITEM_TYPE"].ToString();
  156. string TypeName = row["ITEM_TYPE_NAME"].ToString();
  157. if (vlist.FindByDataValue(TypeCode) == null)
  158. {
  159. vlist.ValueListItems.Add(TypeCode, TypeName);
  160. }
  161. }
  162. ClsControlPack.SetGridValuelist(ref ugData, "MATERIELTYPE", ref vlist);
  163. while (this.dataTable1.Columns.Count > 3)
  164. {
  165. this.dataTable1.Columns.RemoveAt(3);
  166. }
  167. try
  168. {
  169. string strCode = "", strName = "";
  170. for (int i = 0; i < columns.Rows.Count; i++)
  171. {
  172. strCode = columns.Rows[i]["ITEM_CODE"].ToString();
  173. strName = columns.Rows[i]["ITEM_NAME"].ToString();
  174. if (string.IsNullOrEmpty(strName)) continue;
  175. if (!dataTable1.Columns.Contains(strCode))
  176. {
  177. DataColumn column = new DataColumn(strCode, typeof(string)) { Caption = strName };
  178. this.dataTable1.Columns.Add(column);
  179. ugData.DisplayLayout.Bands[0].Columns[strCode].CellAppearance.TextVAlign = VAlign.Middle;
  180. ugData.DisplayLayout.Bands[0].Columns[strCode].CellAppearance.TextHAlign = HAlign.Right;
  181. }
  182. }
  183. for (int i = 3; i < dataTable1.Columns.Count; i++)
  184. {
  185. List<string> codes = columns.AsEnumerable().Select(p => p["ITEM_CODE"].ToString()).Distinct().ToList();
  186. if (!codes.Contains(dataTable1.Columns[i].ColumnName))
  187. {
  188. dataTable1.Columns.RemoveAt(i--);
  189. }
  190. }
  191. }
  192. catch { }
  193. finally
  194. {
  195. try
  196. {
  197. SetAdditiveDataSummary();
  198. ugData.EndUpdate();
  199. _changed = false;
  200. }
  201. catch { }
  202. }
  203. }
  204. //物料
  205. public void SetAdditiveProcess(string strStationCode,string strDisposalTime)
  206. {
  207. bool bSuccess;
  208. string strMsg;
  209. DataSet ds = ClsDataAccessPack.GetData("AddColumns.Select", new ArrayList { strStationCode, strStationCode }, out bSuccess, out strMsg, _ob);
  210. if (!bSuccess || ds.Tables.Count<=0) return;
  211. ugData.BeginUpdate();
  212. columns = ds.Tables[0];
  213. ValueList vlist = new ValueList();
  214. foreach (DataRow row in columns.Rows)
  215. {
  216. string TypeCode = row["ITEM_TYPE"].ToString();
  217. string TypeName = row["ITEM_TYPE_NAME"].ToString();
  218. if (vlist.FindByDataValue(TypeCode)==null)
  219. {
  220. vlist.ValueListItems.Add(TypeCode, TypeName);
  221. }
  222. }
  223. ClsControlPack.SetGridValuelist(ref ugData, "MATERIELTYPE", ref vlist);
  224. this.dataTable1.Rows.Clear();
  225. while (this.dataTable1.Columns.Count>3)
  226. {
  227. this.dataTable1.Columns.RemoveAt(3);
  228. }
  229. try
  230. {
  231. string strCode = "", strName = "";
  232. for (int i = 0; i < columns.Rows.Count; i++)
  233. {
  234. strCode = columns.Rows[i]["ITEM_CODE"].ToString();
  235. strName = columns.Rows[i]["ITEM_NAME"].ToString();
  236. if(string.IsNullOrEmpty(strName)) continue;
  237. if (!dataTable1.Columns.Contains(strCode))
  238. {
  239. DataColumn column = new DataColumn(strCode, typeof(string)) {Caption = strName};
  240. this.dataTable1.Columns.Add(column);
  241. ugData.DisplayLayout.Bands[0].Columns[strCode].CellAppearance.TextVAlign = VAlign.Middle;
  242. ugData.DisplayLayout.Bands[0].Columns[strCode].CellAppearance.TextHAlign = HAlign.Right;
  243. }
  244. }
  245. }
  246. catch { }
  247. finally
  248. {
  249. try
  250. {
  251. // UltraGridRow row = ultraGrid1.DisplayLayout.Bands[0].AddNew();
  252. //DataRow drFL= dataTable1.NewRow();
  253. // drFL[0] = "配料方案";
  254. // row.Cells[0].Value = "配料方案";
  255. //this.dataTable1.Rows.Add(drFL);
  256. SetAdditiveDataSummary();
  257. ugData.EndUpdate();
  258. _changed = false;
  259. }
  260. catch { }
  261. }
  262. }
  263. private void SetAdditiveDataSummary()
  264. {
  265. try
  266. {
  267. UltraGridBand band = this.ugData.DisplayLayout.Bands[0];
  268. band.Summaries.Clear();
  269. SummarySettings summary = band.Summaries.Add(SummaryType.Count, band.Columns[0]);
  270. summary.SummaryDisplayArea = SummaryDisplayAreas.TopFixed;
  271. summary.SummaryPosition = SummaryPosition.UseSummaryPositionColumn;
  272. summary.Appearance.ForeColor = Color.DarkBlue;
  273. summary.Appearance.BackColor = Color.White;
  274. summary.Appearance.TextVAlign = VAlign.Middle;
  275. summary.Appearance.TextHAlign = HAlign.Center;
  276. summary.Appearance.FontData.Bold = DefaultableBoolean.True;
  277. summary.DisplayFormat = "投料合计:";
  278. if (columns != null && columns.Rows.Count > 0)
  279. {
  280. List<string> codes = columns.AsEnumerable().Select(p => p["ITEM_CODE"].ToString()).Distinct().ToList();
  281. for (int idx = 0; idx < codes.Count; idx++)
  282. {
  283. try
  284. {
  285. summary = band.Summaries.Add(SummaryType.Sum, band.Columns[codes[idx]]);
  286. summary.SummaryDisplayArea = SummaryDisplayAreas.TopFixed;
  287. summary.SummaryPosition = SummaryPosition.UseSummaryPositionColumn;
  288. summary.Appearance.FontData.Bold = DefaultableBoolean.True;
  289. summary.DisplayFormat = " {0:#####.###}";
  290. summary.Appearance.TextVAlign = VAlign.Middle;
  291. summary.Appearance.TextHAlign = HAlign.Right;
  292. summary.Appearance.ForeColor = Color.DarkBlue;
  293. summary.Appearance.BackColor = Color.White;
  294. }
  295. catch { }
  296. }
  297. }
  298. band.Override.SummaryFooterCaptionVisible = DefaultableBoolean.False;
  299. }
  300. catch { }
  301. }
  302. private void tsmAdd_Click(object sender, EventArgs e)
  303. {
  304. if (dataTable1.Columns.Count <= 3)
  305. {
  306. MessageBox.Show("请先配置添加料");
  307. return;
  308. }
  309. var dr1 = dataTable1.NewRow();
  310. dr1["JMDATE"] = DateTime.Now;
  311. dataTable1.Rows.Add(dr1);
  312. var tempRow = ugData.Rows[ugData.Rows.Count - 1];
  313. tempRow.Appearance.BackColor = Color.Orange;
  314. tempRow.Cells["Valid"].Value = false;
  315. if (dataTable1.Rows.Count <= 1)
  316. {
  317. ClsControlPack.RefreshAndAutoSize(ugData);
  318. }
  319. }
  320. private void tsmDelete_Click(object sender, EventArgs e)
  321. {
  322. if (ugData.ActiveRow == null)
  323. {
  324. MessageBox.Show("请选中一行再进行删除");
  325. return;
  326. }
  327. if (!(bool)ugData.ActiveRow.Cells["NewRow"].Value)
  328. {
  329. _changed = true;
  330. }
  331. dataTable1.Rows.RemoveAt(ugData.ActiveRow.Index);
  332. }
  333. private void ugTem_KeyPress(object sender, KeyPressEventArgs e)
  334. {
  335. if (ugData.ActiveRow != null)
  336. {
  337. try
  338. {
  339. ugData.UpdateData();
  340. }
  341. catch (Exception)
  342. {
  343. }
  344. }
  345. }
  346. private void ugTem_BeforeRowsDeleted(object sender, Infragistics.Win.UltraWinGrid.BeforeRowsDeletedEventArgs e)
  347. {
  348. if (e.Rows != null)
  349. {
  350. StlTempsamplingEntity StlTempsamplingEntity = e.Rows[0].ListObject as StlTempsamplingEntity;
  351. if (StlTempsamplingEntity != null && !StlTempsamplingEntity.NewRow)
  352. {
  353. _changed = true;
  354. }
  355. }
  356. }
  357. private void ugTem_ClickCellButton(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e)
  358. {
  359. e.Cell.Value = DateTime.Now;
  360. }
  361. private void ugTem_AfterCellUpdate(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e)
  362. {
  363. var row = ugData.ActiveRow;
  364. if (row != null)
  365. {
  366. if (!CheckRowValid(row)
  367. )
  368. {
  369. row.Appearance.BackColor = Color.Orange;
  370. row.Cells["Valid"].Value = false;
  371. }
  372. else
  373. {
  374. row.Appearance.BackColor = Color.LightGreen;
  375. row.Cells["Valid"].Value = true;
  376. }
  377. if (!(bool)row.Cells["NewRow"].Value)
  378. {
  379. _changed = true;
  380. }
  381. }
  382. //StlTempsamplingEntity StlTempsamplingEntity = ugData.ActiveRow.ListObject as StlTempsamplingEntity;
  383. //if (StlTempsamplingEntity != null && StlTempsamplingEntity.NewRow)
  384. //{
  385. // if (StlTempsamplingEntity.Startdate == null || StlTempsamplingEntity.Enddate == null ||
  386. // StlTempsamplingEntity.Startdate > StlTempsamplingEntity.Enddate
  387. // || StlTempsamplingEntity.Samplingname == ""
  388. // || StlTempsamplingEntity.Samplingvalue == null
  389. // )
  390. // {
  391. // ugTem.Rows[ugTem.ActiveRow.Index].Appearance.BackColor = Color.Orange;
  392. // }
  393. // else
  394. // {
  395. // ugTem.Rows[ugTem.ActiveRow.Index].Appearance.BackColor = Color.LightGreen;
  396. // }
  397. //}
  398. }
  399. private bool CheckRowValid(UltraGridRow row)
  400. {
  401. if (row.Cells["JMDATE"].Value == null
  402. || row.Cells["MATERIELTYPE"].Value == null || row.Cells["MATERIELTYPE"].Value == DBNull.Value) return false;
  403. /* row.Cells["JMDATE"].Value == null
  404. || row.Cells["MATERIELTYPE"].Value == null*/
  405. if (row.Cells.Count <= 5) return false;
  406. for (int i = 3; i < row.Cells.Count-2; i++)
  407. {
  408. double data;
  409. if (row.Cells[i].Value != null && double.TryParse(row.Cells[i].Value.ToString(), out data))
  410. {
  411. return true;
  412. }
  413. }
  414. return false;
  415. }
  416. private bool CheckRowValid(DataRow row)
  417. {
  418. if (row["JMDATE"] == null
  419. || row["MATERIELTYPE"] == null) return false;
  420. if (row.ItemArray.Length <= 3) return false;
  421. for (int i = 3; i < row.ItemArray.Length; i++)
  422. {
  423. if( row[i]!=null && !string.IsNullOrEmpty(row[i].ToString()))
  424. {
  425. return true;
  426. }
  427. }
  428. return false;
  429. }
  430. private void ugTem_MouseDown(object sender, MouseEventArgs e)
  431. {
  432. if (e.Button == MouseButtons.Right)
  433. {
  434. UIElement uieOver = ugData.DisplayLayout.UIElement.ElementFromPoint(new Point(e.X, e.Y));
  435. if (uieOver != null)
  436. {
  437. UltraGridRow ugrOver = uieOver.GetContext(typeof(UltraGridRow), true) as UltraGridRow;
  438. ugData.ActiveRow = ugrOver;
  439. }
  440. }
  441. }
  442. private void ugData_CellChange(object sender, CellEventArgs e)
  443. {
  444. if (ugData.ActiveRow != null)
  445. {
  446. try
  447. {
  448. ugData.UpdateData();
  449. }
  450. catch (Exception)
  451. {
  452. }
  453. }
  454. if (e.Cell.Column.Key.Equals("MATERIELTYPE", StringComparison.CurrentCultureIgnoreCase))
  455. {
  456. for (int i = 3; i < e.Cell.Row.Cells.Count; i++)
  457. {
  458. var cell = e.Cell.Row.Cells[i];
  459. cell.IgnoreRowColActivation = true;
  460. if (cell.Activation == Activation.ActivateOnly)
  461. {
  462. cell.Value = null;
  463. }
  464. }
  465. }
  466. }
  467. private void ugData_InitializeRow(object sender, InitializeRowEventArgs e)
  468. {
  469. string type = e.Row.Cells["MATERIELTYPE"].Value.ToString();
  470. if (type == "") return;
  471. List<string> data =
  472. columns.AsEnumerable()
  473. .Where(p => p["ITEM_TYPE"].ToString() == type)
  474. .Select(p => p["ITEM_CODE"].ToString())
  475. .ToList();
  476. for (int i =3; i < e.Row.Cells.Count; i++)
  477. {
  478. var cell = e.Row.Cells[i];
  479. cell.IgnoreRowColActivation = true;
  480. if (data.Contains(cell.Column.Key))
  481. {
  482. cell.Activation = Activation.AllowEdit;
  483. cell.Appearance.ResetBackColor();
  484. cell.IgnoreRowColActivation = false;
  485. }
  486. else
  487. {
  488. cell.Activation = Activation.ActivateOnly;
  489. cell.Appearance.BackColor = Color.LightGray;
  490. cell.IgnoreRowColActivation = true;
  491. }
  492. }
  493. }
  494. }
  495. }