MesureData.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  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.Mch.Entity;
  16. using CoreFS.CA06;
  17. using Infragistics.Win;
  18. using Infragistics.Win.UltraWinGrid;
  19. using Core.StlMes.Client.ZGMil.Entity;
  20. using NPOI.SS.UserModel;
  21. namespace Core.StlMes.Client.ZGMil.Result
  22. {
  23. public partial class MesureData : 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 MesureData(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 MesureData(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. }
  78. };
  79. }
  80. private void ugData_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
  81. {
  82. RtdMeasurePosdataEntity entity = e.Row.ListObject as RtdMeasurePosdataEntity;
  83. if(entity==null) return;
  84. if(entity.Flag== "10") e.Row.Appearance.BackColor = Color.Gray;
  85. else if (entity.Rk != "1") e.Row.Appearance.BackColor = Color.Yellow;
  86. e.Row.Cells["MatNo"].EditorComponent = entity.Flag == "10" ? uteRecover : uteRemove;
  87. entity.WtType = entity.OraActWeight == null ? "实重" : "理重";
  88. }
  89. private void ultraToolbarsManager1_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
  90. {
  91. switch (e.Tool.Key)
  92. {
  93. case "Save": // ButtonTool
  94. Query();
  95. // Place code here
  96. break;
  97. case "Show": // ButtonTool
  98. ShowData();
  99. // Place code here
  100. break;
  101. case "update": // ButtonTool
  102. update();
  103. break;
  104. case "Close": // ButtonTool
  105. this.DialogResult = DialogResult.Cancel;
  106. break;
  107. //case "Turn": // ButtonTool
  108. // Turn();
  109. // // Place code here
  110. // break;
  111. //case "Revert": // ButtonTool
  112. // Revert();
  113. // // Place code here
  114. // break;
  115. }
  116. }
  117. /// <summary>
  118. /// 清除异常数据
  119. /// </summary>
  120. private void update()
  121. {
  122. RtdMeasurePosdataEntity entity = ugData.ActiveRow.ListObject as RtdMeasurePosdataEntity;
  123. if (entity == null) return;
  124. var ccp = new CoreClientParam();
  125. ccp.ServerName = "com.steering.mes.zgmil.coup.FrmMeasureResultZG";
  126. ccp.MethodName = "Doupdate";
  127. ccp.ServerParams = new object[]
  128. {
  129. JSONFormat.Format(entity),
  130. _heatPlanId
  131. };
  132. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  133. if (ccp.ReturnCode != -1)
  134. {
  135. if (ccp.ReturnInfo.Equals("成功"))
  136. {
  137. Query();
  138. }
  139. else
  140. {
  141. MessageUtil.ShowTips(ccp.ReturnInfo);
  142. }
  143. }
  144. }
  145. private void Query()
  146. {
  147. list = EntityHelper.GetData<RtdMeasurePosdataEntity>(
  148. "com.steering.mes.zgmil.coup.FrmMeasureResultZG.geRtdMeasurePosdataAll",
  149. new object[] { _judgeStove,_batchNo,_plineCode, "0" },
  150. ob);
  151. rtdMeasurePosdataEntityBindingSource1.DataSource = chkFlag.Checked ?list: list.Where(p => p.Flag == "00").ToList() ;
  152. var WasteList = list.Where(p => p.Flag == "10").ToList();
  153. string message = "共" + list.Where(p=>p.Flag=="00").Select(p=>p.MatNo).Distinct().Count() + "支";
  154. string messageW=" ";
  155. if(WasteList.Any())
  156. messageW = " 已剔除" + WasteList.Count+ "条";
  157. ugData.DisplayLayout.Bands[0].Summaries[0].DisplayFormat = message;
  158. ugData.DisplayLayout.Bands[0].Summaries[1].DisplayFormat =
  159. list.Where(p => p.Flag == "00" && p.Rk == "1").Sum(p => p.ActLen).ToString3();
  160. ugData.DisplayLayout.Bands[0].Summaries[2].DisplayFormat =
  161. list.Where(p => p.Flag == "00" && p.Rk == "1").Sum(p => p.ActWeight).ToString3();
  162. ugData.DisplayLayout.Bands[0].Summaries["Waste"].DisplayFormat = messageW;
  163. GridHelper.RefreshAndAutoSizeExceptColumns(ugData, "MatInfo" );
  164. }
  165. //private void Turn()
  166. //{
  167. // if(_jgxPlan==null) return;
  168. // double PerWt =
  169. // Math.Round(
  170. // (double.Parse(_jgxPlan.Outdiameter.ToString3()) - double.Parse(_jgxPlan.Wallthick.ToString3()))*
  171. // double.Parse(_jgxPlan.Wallthick.ToString3())*0.0246615d, 2)/1000d;
  172. // var ccp = new CoreClientParam();
  173. // ccp.ServerName = "com.steering.mes.mcp.Mch.FrmMeasureResult";
  174. // ccp.MethodName = "Turn";
  175. // ccp.ServerParams = new object[]
  176. // {
  177. // PerWt,
  178. // _jgxPlan.JudgeStoveNo,
  179. // _jgxPlan.BatchNo,
  180. // _jgxPlan.PlineCode
  181. // };
  182. // ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  183. // if (ccp.ReturnCode != -1)
  184. // {
  185. // if (ccp.ReturnInfo.Equals("操作成功"))
  186. // {
  187. // Query();
  188. // }
  189. // else
  190. // {
  191. // MessageUtil.ShowTips(ccp.ReturnInfo);
  192. // }
  193. // }
  194. //}
  195. //private void Revert()
  196. //{
  197. // if (_jgxPlan == null) return;
  198. // var ccp = new CoreClientParam();
  199. // ccp.ServerName = "com.steering.mes.mcp.Mch.FrmMeasureResult";
  200. // ccp.MethodName = "Revert";
  201. // ccp.ServerParams = new object[]
  202. // {
  203. // _jgxPlan.JudgeStoveNo,
  204. // _jgxPlan.BatchNo,
  205. // _jgxPlan.PlineCode
  206. // };
  207. // ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  208. // if (ccp.ReturnCode != -1)
  209. // {
  210. // if (ccp.ReturnInfo.Equals("操作成功"))
  211. // {
  212. // Query();
  213. // }
  214. // else
  215. // {
  216. // MessageUtil.ShowTips(ccp.ReturnInfo);
  217. // }
  218. // }
  219. //}
  220. private void chkFlag_CheckedChanged(object sender, EventArgs e)
  221. {
  222. rtdMeasurePosdataEntityBindingSource1.DataSource = chkFlag.Checked ?list: list.Where(p => p.Flag == "00").ToList() ;
  223. 按钮显示区域.Tools["Show"].SharedPropsInternal.Caption = chkFlag.Checked ? "隐藏已剔除" : "显示已剔除";
  224. }
  225. private void ShowData()
  226. {
  227. chkFlag.Checked = !chkFlag.Checked;
  228. rtdMeasurePosdataEntityBindingSource1.DataSource = chkFlag.Checked ? list : list.Where(p => p.Flag == "00").ToList();
  229. 按钮显示区域.Tools["Show"].SharedPropsInternal.Caption = chkFlag.Checked ? "隐藏已剔除" : "显示已剔除";
  230. }
  231. private void ShowButton()
  232. {
  233. if (toolMenu.Toolbars[0].Tools.Exists("CancelFurnace"))
  234. {
  235. toolMenu.Toolbars[0].Tools["CancelFurnace"].InstanceProps.Visible = DefaultableBoolean.False;
  236. }
  237. }
  238. private void uteRemove_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
  239. {
  240. RtdMeasurePosdataEntity entity = ugData.ActiveRow.ListObject as RtdMeasurePosdataEntity;
  241. if (entity == null) return;
  242. var ccp = new CoreClientParam();
  243. ccp.ServerName = "com.steering.mes.zgmil.coup.FrmMeasureResultZG";
  244. ccp.MethodName = "DoRemove";
  245. ccp.ServerParams = new object[]
  246. {
  247. _heatPlanId,
  248. entity.KeyId
  249. };
  250. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  251. if (ccp.ReturnCode != -1)
  252. {
  253. if (ccp.ReturnInfo.Equals("成功"))
  254. {
  255. Query();
  256. }
  257. else
  258. {
  259. MessageUtil.ShowTips(ccp.ReturnInfo);
  260. }
  261. }
  262. }
  263. private void uteRecover_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
  264. {
  265. RtdMeasurePosdataEntity entity = ugData.ActiveRow.ListObject as RtdMeasurePosdataEntity;
  266. if (entity == null) return;
  267. var ccp = new CoreClientParam();
  268. ccp.ServerName = "com.steering.mes.zgmil.coup.FrmMeasureResultZG";
  269. ccp.MethodName = "DoRecover";
  270. ccp.ServerParams = new object[]
  271. {
  272. _heatPlanId,
  273. entity.KeyId
  274. };
  275. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  276. if (ccp.ReturnCode != -1)
  277. {
  278. if (ccp.ReturnInfo.Equals("成功"))
  279. {
  280. Query();
  281. }
  282. else
  283. {
  284. MessageUtil.ShowTips(ccp.ReturnInfo);
  285. }
  286. }
  287. }
  288. private void ultraButton1_Click(object sender, EventArgs e)
  289. {
  290. if (string.IsNullOrWhiteSpace(utMatNo.Text))
  291. {
  292. MessageBox.Show("请输入管号!");
  293. return;
  294. }
  295. double len = 0;
  296. //if (string.IsNullOrWhiteSpace(uteLen.Text) || !double.TryParse(uteLen.Text.Trim(),out len))
  297. //{
  298. // MessageBox.Show("请输入正确的长度!");
  299. // return;
  300. //}
  301. if (string.IsNullOrWhiteSpace(uteWt.Text) || !double.TryParse(uteWt.Text.Trim(), out len))
  302. {
  303. MessageBox.Show("请输入正确的重量!");
  304. return;
  305. }
  306. RtdMeasurePosdataEntity entity = new RtdMeasurePosdataEntity()
  307. {
  308. MatNo = utMatNo.Text,
  309. //ActLen = decimal.Parse(uteLen.Text.Trim()),
  310. ActWeight = decimal.Parse(uteWt.Text.Trim()),
  311. MatInfo = uteMatInfo.Text,
  312. Flag = "00",
  313. JudgeStoveNo = _judgeStove,
  314. BatchNo = _batchNo,
  315. CreateUser = _userName,
  316. };
  317. var ccp = new CoreClientParam();
  318. ccp.ServerName = "com.steering.mes.zgmil.coup.FrmMeasureResultZG";
  319. ccp.MethodName = "DoAddMeasureData";
  320. ccp.ServerParams = new object[]
  321. {
  322. JSONFormat.Format(entity),
  323. _heatPlanId
  324. };
  325. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  326. if (ccp.ReturnCode != -1)
  327. {
  328. MessageUtil.ShowTips(ccp.ReturnInfo);
  329. if (ccp.ReturnInfo.Equals("新增成功"))
  330. {
  331. Query();
  332. }
  333. }
  334. }
  335. private void ubt_Click(object sender, EventArgs e)
  336. {
  337. GridHelper.ulGridToExcel( ultraGrid1 , "导入模板");
  338. }
  339. private void btnExport_Click(object sender, EventArgs e)
  340. {
  341. List<RtdMeasurePosdataEntity> list = null;
  342. var openFileDialog = new OpenFileDialog
  343. {
  344. Filter = "测量点数据|*.xls;*.xlsx"
  345. };
  346. if (openFileDialog.ShowDialog() == DialogResult.OK)
  347. {
  348. list = ReadExcelToRtdMeasurePosdataEntity(openFileDialog.FileName);
  349. }
  350. if (list == null) return;
  351. if (list.Count <= 0)
  352. {
  353. MessageBox.Show("Excel无数据");
  354. return;
  355. }
  356. var ccp = new CoreClientParam();
  357. ccp.ServerName = "com.steering.mes.zgmil.coup.FrmMeasureResultZG";
  358. ccp.MethodName = "DoAddMeasureData";
  359. ccp.ServerParams = new object[]
  360. {
  361. list.Select(JSONFormat.Format).ToList(),
  362. _heatPlanId
  363. };
  364. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  365. if (ccp.ReturnCode != -1)
  366. {
  367. MessageUtil.ShowTips(ccp.ReturnInfo);
  368. if (ccp.ReturnInfo.Equals("新增成功"))
  369. {
  370. Query();
  371. }
  372. }
  373. }
  374. public List<RtdMeasurePosdataEntity> ReadExcelToRtdMeasurePosdataEntity(string fileName)
  375. {
  376. //定义要返回的datatable对象
  377. List<RtdMeasurePosdataEntity> RtdMeasurePosdataEntitys = new List<RtdMeasurePosdataEntity>();
  378. try
  379. {
  380. if (!File.Exists(fileName))
  381. {
  382. return null;
  383. }
  384. //根据指定路径读取文件
  385. using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
  386. {
  387. //根据文件流创建excel数据结构
  388. NPOI.SS.UserModel.IWorkbook workbook = NPOI.SS.UserModel.WorkbookFactory.Create(fs);
  389. //IWorkbook workbook = new HSSFWorkbook(fs);
  390. for (int k = 0; k < workbook.NumberOfSheets; k++)
  391. {
  392. NPOI.SS.UserModel.ISheet sheet = workbook.GetSheetAt(k);
  393. if (sheet != null)
  394. {
  395. //最后一列的标号
  396. int rowCount = sheet.LastRowNum;
  397. for (int i = 1; i <= rowCount; ++i)
  398. {
  399. NPOI.SS.UserModel.IRow row = sheet.GetRow(i);
  400. if (row == null) continue; //没有数据的行默认是null       
  401. if (row.Cells.Count < 4)
  402. {
  403. throw new Exception("无足够列");
  404. }
  405. RtdMeasurePosdataEntity entity = new RtdMeasurePosdataEntity()
  406. {
  407. MatNo = GetCellValue(row.Cells[0]),
  408. MatInfo = GetCellValue(row.Cells[3]),
  409. Flag = "00",
  410. JudgeStoveNo = _judgeStove,
  411. BatchNo = _batchNo,
  412. CreateUser = _userName,
  413. };
  414. decimal actLen;
  415. decimal actWt;
  416. decimal.TryParse(GetCellValue(row.Cells[1]), out actLen);
  417. decimal.TryParse(GetCellValue(row.Cells[2]), out actWt);
  418. if (actLen == null || actLen <= 0)
  419. {
  420. throw new Exception("长度异常");
  421. }
  422. if (actWt == null || actWt <= 0)
  423. {
  424. throw new Exception("重量异常");
  425. }
  426. entity.ActLen = actLen;
  427. entity.ActWeight = actWt;
  428. RtdMeasurePosdataEntitys.Add(entity);
  429. }
  430. }
  431. }
  432. }
  433. return RtdMeasurePosdataEntitys;
  434. }
  435. catch (Exception ex)
  436. {
  437. MessageBox.Show("EXCEL格式错误:" + ex.Message);
  438. return null;
  439. }
  440. }
  441. private string GetCellValue(ICell cell)
  442. {
  443. string value="";
  444. switch (cell.CellType)
  445. {
  446. case CellType.Blank:
  447. value = "";
  448. break;
  449. case CellType.Numeric:
  450. short format = cell.CellStyle.DataFormat;
  451. value = cell.NumericCellValue.ToString2();
  452. break;
  453. case CellType.String:
  454. value = cell.StringCellValue;
  455. break;
  456. }
  457. return value;
  458. }
  459. }
  460. }