VrpMesureData.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Reflection;
  9. using System.Text;
  10. using System.Windows.Forms;
  11. using com.steering.mes.mcp.entity;
  12. using Core.Mes.Client.Comm.Control;
  13. using Core.Mes.Client.Comm.Format;
  14. using Core.Mes.Client.Comm.Tool;
  15. using Core.StlMes.Client.Mcp.Control.Entity;
  16. //using Core.StlMes.Client.Mcp.Mch.Entity;
  17. using CoreFS.CA06;
  18. using Infragistics.Win;
  19. using Infragistics.Win.UltraWinGrid;
  20. using NPOI.SS.UserModel;
  21. namespace Core.StlMes.Client.Mcp.VRP.Vrp
  22. {
  23. public partial class VrpMesureData : FrmBase
  24. {
  25. private string _judgeStove;
  26. private string _batchNo;
  27. private string _plineCode;
  28. private string _heatPlanId;
  29. private string _userName;
  30. private PlnZyJgxCEntity _jgxPlan = null;
  31. public List<RtdMeasurePosdataEntity> list = new List<RtdMeasurePosdataEntity>();
  32. public VrpMesureData(string heatPlanId, string judgeStove, string batchNo,string PlineCode,OpeBase _ob, string userName,bool ShowAdd)
  33. {
  34. _judgeStove = judgeStove;
  35. _batchNo = batchNo;
  36. _heatPlanId = heatPlanId;
  37. _plineCode = PlineCode;
  38. _userName = userName;
  39. this.ob = _ob;
  40. InitializeComponent();
  41. if (!ShowAdd)
  42. {
  43. uegAdd.Visible = false;
  44. }
  45. Query();
  46. }
  47. public VrpMesureData(PlnZyJgxCEntity JgxPlan, OpeBase _ob, string userName, bool ShowAdd)
  48. {
  49. _jgxPlan = JgxPlan;
  50. _judgeStove = JgxPlan.JudgeStoveNo;
  51. _batchNo = JgxPlan.BatchNo;
  52. _heatPlanId = JgxPlan.HeatPlanNo;
  53. _plineCode = JgxPlan.PlineCode;
  54. _userName = userName;
  55. this.ob = _ob;
  56. InitializeComponent();
  57. if (!ShowAdd)
  58. {
  59. uegAdd.Visible = false;
  60. }
  61. Query();
  62. }
  63. protected override void OnLoad(EventArgs e)
  64. {
  65. base.OnLoad(e);
  66. EntityHelper.ShowGridCaption<RtdMeasurePosdataEntity>(ugData.DisplayLayout.Bands[0]);
  67. ugData.DisplayLayout.Override.AllowRowFiltering = DefaultableBoolean.False;
  68. ugData.DisplayLayout.Override.HeaderClickAction = HeaderClickAction.Default;
  69. EntityHelper.ShowGridCaption<RtdMeasurePosdataEntity>(ultraGrid1.DisplayLayout.Bands[0]);
  70. bindingSource1.DataSource = new List<RtdMeasurePosdataEntity>()
  71. {
  72. new RtdMeasurePosdataEntity()
  73. {
  74. MatNo = "1",
  75. ActLen = (decimal)13313,
  76. ActWeight = 529,
  77. ProBz = "甲",
  78. ProBc = "早"
  79. }
  80. };
  81. }
  82. private void ugData_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
  83. {
  84. RtdMeasurePosdataEntity entity = e.Row.ListObject as RtdMeasurePosdataEntity;
  85. if(entity==null) return;
  86. if(entity.Flag== "10") e.Row.Appearance.BackColor = Color.Gray;
  87. else if (entity.Rk != "1") e.Row.Appearance.BackColor = Color.Yellow;
  88. e.Row.Cells["MatNo"].EditorComponent = entity.Flag == "10" ? uteRecover : uteRemove;
  89. entity.WtType = entity.OraActWeight == null ? "实重" : "理重";
  90. }
  91. private void ultraToolbarsManager1_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
  92. {
  93. switch (e.Tool.Key)
  94. {
  95. case "Save": // ButtonTool
  96. Query();
  97. // Place code here
  98. break;
  99. case "Show": // ButtonTool
  100. ShowData();
  101. // Place code here
  102. break;
  103. case "Close": // ButtonTool
  104. this.DialogResult = DialogResult.Cancel;
  105. break;
  106. case "Turn": // ButtonTool
  107. Turn();
  108. // Place code here
  109. break;
  110. case "Revert": // ButtonTool
  111. Revert();
  112. // Place code here
  113. break;
  114. }
  115. }
  116. private void Query()
  117. {
  118. list = EntityHelper.GetData<RtdMeasurePosdataEntity>(
  119. "com.steering.mes.mcp.Mch.FrmMeasureResult.geRtdMeasurePosdataAll",
  120. new object[] { _judgeStove,_batchNo,_plineCode, "0" },
  121. ob);
  122. rtdMeasurePosdataEntityBindingSource.DataSource = chkFlag.Checked ?list: list.Where(p => p.Flag == "00").ToList() ;
  123. var WasteList = list.Where(p => p.Flag == "10").ToList();
  124. string message = "共" + list.Where(p=>p.Flag=="00").Select(p=>p.MatNo).Distinct().Count() + "支";
  125. string messageW=" ";
  126. if(WasteList.Any())
  127. messageW = " 已剔除" + WasteList.Count+ "条";
  128. ugData.DisplayLayout.Bands[0].Summaries[0].DisplayFormat = message;
  129. ugData.DisplayLayout.Bands[0].Summaries[1].DisplayFormat =
  130. list.Where(p => p.Flag == "00" && p.Rk == "1").Sum(p => p.ActLen).ToString3();
  131. ugData.DisplayLayout.Bands[0].Summaries[2].DisplayFormat =
  132. list.Where(p => p.Flag == "00" && p.Rk == "1").Sum(p => p.ActWeight).ToString3();
  133. ugData.DisplayLayout.Bands[0].Summaries["Waste"].DisplayFormat = messageW;
  134. GridHelper.RefreshAndAutoSizeExceptColumns(ugData, "MatInfo" );
  135. }
  136. private void Turn()
  137. {
  138. if(_jgxPlan==null) return;
  139. using (VrpMesureDataPerWt mesureData = new VrpMesureDataPerWt(ob,_jgxPlan))
  140. {
  141. mesureData.ShowDialog();
  142. if (mesureData.DialogResult == DialogResult.OK)
  143. {
  144. Query();
  145. }
  146. }
  147. }
  148. private void Revert()
  149. {
  150. if (_jgxPlan == null) return;
  151. var ccp = new CoreClientParam();
  152. ccp.ServerName = "com.steering.mes.mcp.Mch.FrmMeasureResult";
  153. ccp.MethodName = "Revert";
  154. ccp.ServerParams = new object[]
  155. {
  156. _jgxPlan.JudgeStoveNo,
  157. _jgxPlan.BatchNo,
  158. _jgxPlan.PlineCode
  159. };
  160. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  161. if (ccp.ReturnCode != -1)
  162. {
  163. if (ccp.ReturnInfo.Equals("操作成功"))
  164. {
  165. Query();
  166. }
  167. else
  168. {
  169. MessageUtil.ShowTips(ccp.ReturnInfo);
  170. }
  171. }
  172. }
  173. private void chkFlag_CheckedChanged(object sender, EventArgs e)
  174. {
  175. rtdMeasurePosdataEntityBindingSource.DataSource = chkFlag.Checked ?list: list.Where(p => p.Flag == "00").ToList() ;
  176. 按钮显示区域.Tools["Show"].SharedPropsInternal.Caption = chkFlag.Checked ? "隐藏已剔除" : "显示已剔除";
  177. }
  178. private void ShowData()
  179. {
  180. chkFlag.Checked = !chkFlag.Checked;
  181. rtdMeasurePosdataEntityBindingSource.DataSource = chkFlag.Checked ? list : list.Where(p => p.Flag == "00").ToList();
  182. 按钮显示区域.Tools["Show"].SharedPropsInternal.Caption = chkFlag.Checked ? "隐藏已剔除" : "显示已剔除";
  183. }
  184. private void uteRemove_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
  185. {
  186. RtdMeasurePosdataEntity entity = ugData.ActiveRow.ListObject as RtdMeasurePosdataEntity;
  187. if (entity == null) return;
  188. var ccp = new CoreClientParam();
  189. ccp.ServerName = "com.steering.mes.mcp.Mch.FrmMeasureResult";
  190. ccp.MethodName = "DoRemoveDbk";
  191. ccp.ServerParams = new object[]
  192. {
  193. _heatPlanId,
  194. entity.KeyId
  195. };
  196. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  197. if (ccp.ReturnCode != -1)
  198. {
  199. if (ccp.ReturnInfo.Equals("成功"))
  200. {
  201. Query();
  202. }
  203. else
  204. {
  205. MessageUtil.ShowTips(ccp.ReturnInfo);
  206. }
  207. }
  208. }
  209. private void uteRecover_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
  210. {
  211. RtdMeasurePosdataEntity entity = ugData.ActiveRow.ListObject as RtdMeasurePosdataEntity;
  212. if (entity == null) return;
  213. var ccp = new CoreClientParam();
  214. ccp.ServerName = "com.steering.mes.mcp.Mch.FrmMeasureResult";
  215. ccp.MethodName = "DoRecover";
  216. ccp.ServerParams = new object[]
  217. {
  218. _heatPlanId,
  219. entity.KeyId
  220. };
  221. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  222. if (ccp.ReturnCode != -1)
  223. {
  224. if (ccp.ReturnInfo.Equals("成功"))
  225. {
  226. Query();
  227. }
  228. else
  229. {
  230. MessageUtil.ShowTips(ccp.ReturnInfo);
  231. }
  232. }
  233. }
  234. private void ultraButton1_Click(object sender, EventArgs e)
  235. {
  236. if (string.IsNullOrWhiteSpace(utMatNo.Text))
  237. {
  238. MessageBox.Show("请输入管号!");
  239. return;
  240. }
  241. double len = 0;
  242. if (string.IsNullOrWhiteSpace(uteLen.Text) || !double.TryParse(uteLen.Text.Trim(),out len))
  243. {
  244. MessageBox.Show("请输入正确的长度!");
  245. return;
  246. }
  247. if (string.IsNullOrWhiteSpace(uteWt.Text) || !double.TryParse(uteWt.Text.Trim(), out len))
  248. {
  249. MessageBox.Show("请输入正确的重量!");
  250. return;
  251. }
  252. RtdMeasurePosdataEntity entity = new RtdMeasurePosdataEntity()
  253. {
  254. MatNo = utMatNo.Text,
  255. ActLen = decimal.Parse(uteLen.Text.Trim()),
  256. ActWeight = decimal.Parse(uteWt.Text.Trim()),
  257. MatInfo = uteMatInfo.Text,
  258. Flag = "00",
  259. JudgeStoveNo = _judgeStove,
  260. BatchNo = _batchNo,
  261. CreateUser = _userName,
  262. ProBc = uceBc.SelectedIndex<0?"":uceBc.SelectedItem.DataValue.ToString2(),
  263. ProBz = uceBz.SelectedIndex<0?"":uceBz.SelectedItem.DataValue.ToString2()
  264. };
  265. var ccp = new CoreClientParam();
  266. ccp.ServerName = "com.steering.mes.mcp.Mch.FrmMeasureResult";
  267. ccp.MethodName = "DoAddMeasureDataDbk";
  268. ccp.ServerParams = new object[]
  269. {
  270. JSONFormat.Format(entity),
  271. _heatPlanId
  272. };
  273. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  274. if (ccp.ReturnCode != -1)
  275. {
  276. MessageUtil.ShowTips(ccp.ReturnInfo);
  277. if (ccp.ReturnInfo.Equals("新增成功"))
  278. {
  279. Query();
  280. }
  281. }
  282. }
  283. private void ubt_Click(object sender, EventArgs e)
  284. {
  285. GridHelper.ulGridToExcel( ultraGrid1 , "导入模板");
  286. }
  287. private void btnExport_Click(object sender, EventArgs e)
  288. {
  289. List<RtdMeasurePosdataEntity> list = null;
  290. var openFileDialog = new OpenFileDialog
  291. {
  292. Filter = "测量点数据|*.xls;*.xlsx"
  293. };
  294. if (openFileDialog.ShowDialog() == DialogResult.OK)
  295. {
  296. list = ReadExcelToRtdMeasurePosdataEntity(openFileDialog.FileName);
  297. }
  298. if (list == null) return;
  299. if (list.Count <= 0)
  300. {
  301. MessageBox.Show("Excel无数据");
  302. return;
  303. }
  304. var ccp = new CoreClientParam();
  305. ccp.ServerName = "com.steering.mes.mcp.Mch.FrmMeasureResult";
  306. ccp.MethodName = "DoAddMeasureData";
  307. ccp.ServerParams = new object[]
  308. {
  309. list.Select(JSONFormat.Format).ToList(),
  310. _heatPlanId
  311. };
  312. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  313. if (ccp.ReturnCode != -1)
  314. {
  315. MessageUtil.ShowTips(ccp.ReturnInfo);
  316. if (ccp.ReturnInfo.Equals("新增成功"))
  317. {
  318. Query();
  319. }
  320. }
  321. }
  322. public List<RtdMeasurePosdataEntity> ReadExcelToRtdMeasurePosdataEntity(string fileName)
  323. {
  324. //定义要返回的datatable对象
  325. List<RtdMeasurePosdataEntity> RtdMeasurePosdataEntitys = new List<RtdMeasurePosdataEntity>();
  326. try
  327. {
  328. if (!File.Exists(fileName))
  329. {
  330. return null;
  331. }
  332. //根据指定路径读取文件
  333. using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
  334. {
  335. //根据文件流创建excel数据结构
  336. NPOI.SS.UserModel.IWorkbook workbook = NPOI.SS.UserModel.WorkbookFactory.Create(fs);
  337. //IWorkbook workbook = new HSSFWorkbook(fs);
  338. for (int k = 0; k < workbook.NumberOfSheets; k++)
  339. {
  340. NPOI.SS.UserModel.ISheet sheet = workbook.GetSheetAt(k);
  341. if (sheet != null)
  342. {
  343. //最后一列的标号
  344. int rowCount = sheet.LastRowNum;
  345. for (int i = 1; i <= rowCount; ++i)
  346. {
  347. NPOI.SS.UserModel.IRow row = sheet.GetRow(i);
  348. if (row == null) continue; //没有数据的行默认是null       
  349. if (row.Cells.Count < 3)
  350. {
  351. throw new Exception("无足够列");
  352. }
  353. string bc ="", bz = "";
  354. if (row.Cells.Count > 5)
  355. {
  356. bc = GetCellValue(row.Cells[4]);
  357. if (bc == "早") bc = "1";
  358. if (bc == "中") bc = "2";
  359. if (bc == "晚") bc = "3";
  360. if (bc == "白") bc = "0";
  361. if (bc != "" && bc != "1" && bc != "0" && bc != "2" && bc != "3")
  362. {
  363. throw new Exception("无法识别班次");
  364. }
  365. bz = GetCellValue(row.Cells[5]);
  366. if (bz == "甲") bz = "1";
  367. if (bz == "乙") bz = "2";
  368. if (bz == "丙") bz = "3";
  369. if (bz == "丁") bz = "4";
  370. if (bz != "" && bz != "1" && bz != "4" && bz != "2" && bz != "3")
  371. {
  372. throw new Exception("无法识别班组");
  373. }
  374. }
  375. RtdMeasurePosdataEntity entity = new RtdMeasurePosdataEntity()
  376. {
  377. MatNo = GetCellValue(row.Cells[0]),
  378. MatInfo= row.Cells.Count <4?"": GetCellValue(row.Cells[3]),
  379. Flag = "00",
  380. JudgeStoveNo = _judgeStove,
  381. BatchNo = _batchNo,
  382. CreateUser = _userName,
  383. ProBz = bz,
  384. ProBc = bc
  385. };
  386. decimal actLen;
  387. decimal actWt;
  388. decimal.TryParse(GetCellValue(row.Cells[1]), out actLen);
  389. decimal.TryParse(GetCellValue(row.Cells[2]), out actWt);
  390. if (actLen == null || actLen <= 0)
  391. {
  392. throw new Exception("长度异常");
  393. }
  394. if (actWt == null || actWt <= 0)
  395. {
  396. throw new Exception("重量异常");
  397. }
  398. entity.ActLen = actLen;
  399. entity.ActWeight = actWt;
  400. RtdMeasurePosdataEntitys.Add(entity);
  401. }
  402. }
  403. }
  404. }
  405. return RtdMeasurePosdataEntitys;
  406. }
  407. catch (Exception ex)
  408. {
  409. MessageBox.Show("EXCEL格式错误:" + ex.Message);
  410. return null;
  411. }
  412. }
  413. private string GetCellValue(ICell cell)
  414. {
  415. string value="";
  416. switch (cell.CellType)
  417. {
  418. case CellType.Blank:
  419. value = "";
  420. break;
  421. case CellType.Numeric:
  422. short format = cell.CellStyle.DataFormat;
  423. value = cell.NumericCellValue.ToString2();
  424. break;
  425. case CellType.String:
  426. value = cell.StringCellValue;
  427. break;
  428. }
  429. return value;
  430. }
  431. }
  432. }