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