FrmTqnqD02.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Collections;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Reflection;
  10. using System.Text;
  11. using System.Windows.Forms;
  12. using Core.Mes.Client.Comm.Control;
  13. using Core.Mes.Client.Comm.Format;
  14. using Core.Mes.Client.Comm.Tool;
  15. using CoreFS.CA06;
  16. using Infragistics.Win;
  17. using Infragistics.Win.UltraWinGrid;
  18. using NPOI.SS.UserModel;
  19. using Core.StlMes.Client.PnCost.Models;
  20. using Core.StlMes.Client.PnCost.NewCost.弹窗;
  21. using Core.Mes.Client.Comm.Server;
  22. namespace Core.StlMes.Client.PnCost
  23. {
  24. public partial class FrmTqnqD02 : FrmBase
  25. {
  26. #region 定义变量
  27. public FrmTqnqD02()
  28. {
  29. InitializeComponent();
  30. }
  31. private DataTable dtgang;
  32. #endregion
  33. private void doQueryBaseinfo()
  34. {
  35. DataTable dt = ClsBaseInfo.GetComBaseInfo("4049", ob);
  36. cfp.DataSource = dt;
  37. cfp.ValueMember = "BASECODE";
  38. cfp.DisplayMember = "BASENAME";
  39. ClsBaseInfo.SetComboItemHeight(cfp);
  40. List<String> ls = new List<String>();
  41. ls.Add("不锈钢");
  42. ls.Add("模具钢");
  43. List<String> ls2 = new List<String>();
  44. ls2.Add("高温回火");
  45. ls2.Add("热轧");
  46. hslb.DataSource = ls;
  47. jhzt.DataSource = ls2;
  48. //DataTable dt2 = ClsBaseInfo.GetComBaseInfo("4049", ob);
  49. //hslb.DataSource = dt;
  50. //hslb.ValueMember = "BASECODE";
  51. //hslb.DisplayMember = "BASENAME";
  52. //ClsBaseInfo.SetComboItemHeight(hslb);
  53. //DataTable dt3 = ClsBaseInfo.GetComBaseInfo("4049", ob);
  54. //jhzt.DataSource = dt;
  55. //jhzt.ValueMember = "BASECODE";
  56. //jhzt.DisplayMember = "BASENAME";
  57. //ClsBaseInfo.SetComboItemHeight(jhzt);
  58. }
  59. #region 方法
  60. public override void ToolBar_Click(object sender, string ToolbarKey)
  61. {
  62. base.ToolBar_Click(sender, ToolbarKey);
  63. switch (ToolbarKey)
  64. {
  65. case "doQuery":
  66. Query();
  67. break;
  68. case "doSave":
  69. doSave();
  70. break;
  71. case "doAdd":
  72. doAdd();
  73. break;
  74. case "doBbsc":
  75. doBbsc();
  76. break;
  77. case "doSeeBb":
  78. doSeeBb();
  79. break;
  80. //case "doDelete":
  81. // this.doDelete();
  82. // break;
  83. case "Close":
  84. this.doDelete();
  85. break;
  86. }
  87. }
  88. private void doSeeBb()
  89. {
  90. this.ultraGrid1.UpdateData();
  91. IQueryable<UltraGridRow> checkMagRows = this.ultraGrid1.Rows.AsQueryable().Where(" XUANZE = 'True'");
  92. if (checkMagRows.Count() > 1)
  93. {
  94. MessageUtil.ShowTips("选择的条数有误!");
  95. return;
  96. }
  97. string strurl = "";
  98. foreach (UltraGridRow uRow in checkMagRows)
  99. {
  100. Tqnqd02Entity tqnqd02Entity = (Tqnqd02Entity)uRow.ListObject;
  101. strurl = "http://172.16.2.137:8081/webroot/decision/view/report?viewlet=tqnqd06.cpt" + "&processCode="+tqnqd02Entity.ProcessCode; //+ "&BILL_NO=" + BillNo + "&NAME=" + this.UserInfo.GetUserName();
  102. FrmRepExcel fBug = new FrmRepExcel(ob, strurl);
  103. fBug.AutoSize = true;
  104. fBug.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  105. fBug.WindowState = FormWindowState.Maximized;
  106. fBug.Text = "成本测算";
  107. fBug.Show();
  108. }
  109. }
  110. private void doBbsc()
  111. {
  112. this.ultraGrid1.UpdateData();
  113. IQueryable<UltraGridRow> checkMagRows = this.ultraGrid1.Rows.AsQueryable().Where(" XUANZE = 'True'");
  114. if (checkMagRows.Count() == 0)
  115. {
  116. MessageUtil.ShowTips("请选择要生成的数据!");
  117. return;
  118. }
  119. ArrayList parm = new ArrayList();
  120. foreach (UltraGridRow uRow in checkMagRows)
  121. {
  122. Tqnqd02Entity tqnqd02Entity = (Tqnqd02Entity)uRow.ListObject;
  123. string tqnqd02EntityResult = JSONFormat.Format(tqnqd02Entity);
  124. parm.Add(tqnqd02EntityResult);
  125. }
  126. CoreClientParam ccp = new CoreClientParam();
  127. ccp.ServerName = "com.steering.mes.cost.FrmTqnqd02";
  128. ccp.MethodName = "doBbsc";
  129. ccp.ServerParams = new object[] { parm };
  130. ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  131. if (ccp.ReturnCode != -1)
  132. {
  133. if (ccp.ReturnInfo.Equals("操作成功"))
  134. {
  135. // DoQueryInList();
  136. Query();
  137. MessageUtil.ShowTips(ccp.ReturnInfo);
  138. }
  139. else
  140. {
  141. MessageUtil.ShowTips(ccp.ReturnInfo);
  142. }
  143. }
  144. }
  145. protected override void OnLoad(EventArgs e)
  146. {
  147. base.OnLoad(e);
  148. EntityHelper.ShowGridCaption<Tqnqd02Entity>(ultraGrid1.DisplayLayout.Bands[0]);
  149. ultraGrid1.ClickCellButton += new CellEventHandler(ugData_ClickCellButton);
  150. doQueryBaseinfo();
  151. Query();
  152. }
  153. protected virtual void ugData_ClickCellButton(object sender, CellEventArgs e)
  154. {
  155. UltraGridCell cell = ultraGrid1.ActiveCell;
  156. UltraGridRow row = e.Cell.Row;
  157. string strKey = this.ultraGrid1.ActiveCell.Column.ToString();
  158. IQueryable<UltraGridRow> checkMagRows = this.ultraGrid1.Rows.AsQueryable().Where(" XUANZE = 'True'");
  159. if (checkMagRows.Count() == 0)
  160. {
  161. MessageUtil.ShowTips("请选择数据!");
  162. return;
  163. }
  164. if(strKey.Equals("OutSgSign"))
  165. {
  166. FrmTqnqD01T frm = new FrmTqnqD01T(this.ob);
  167. frm.ShowDialog();
  168. if (frm.DialogResult == System.Windows.Forms.DialogResult.OK)
  169. {
  170. row.Cells["OutSgSign"].Value = frm.steelname;
  171. row.Cells["OutSgStd"].Value = frm.stdname;
  172. row.Cells["OutSteelTypeCode"].Value = frm.steeltype;
  173. row.Cells["OutSmeltCode"].Value = frm.cx;
  174. }
  175. }
  176. if(strKey.Equals("SgSign"))
  177. {
  178. FrmProductManage frm = new FrmProductManage(this.ob);
  179. frm.ShowDialog();
  180. if (frm.DialogResult == System.Windows.Forms.DialogResult.OK)
  181. {
  182. row.Cells["SgSign"].Value = frm.steelname_;
  183. row.Cells["SgStd"].Value = frm.stdname_;
  184. }
  185. }
  186. if (strKey.Equals("RpCode"))
  187. {
  188. FrmTqnqc13T frm = new FrmTqnqc13T(this.ob);
  189. frm.ShowDialog();
  190. if (frm.DialogResult == System.Windows.Forms.DialogResult.OK)
  191. {
  192. row.Cells["RpCode"].Value = frm.rpcede_;
  193. row.Cells["WholeBacklogName"].Value = frm.cx_;
  194. }
  195. }
  196. }
  197. private void doDelete()
  198. {
  199. this.ultraGrid1.UpdateData();
  200. IQueryable<UltraGridRow> checkMagRows = this.ultraGrid1.Rows.AsQueryable().Where(" XUANZE = 'True'");
  201. if (checkMagRows.Count() == 0)
  202. {
  203. MessageUtil.ShowTips("请选择需要删除的数据!");
  204. return;
  205. }
  206. ArrayList parm = new ArrayList();
  207. foreach (UltraGridRow uRow in checkMagRows)
  208. {
  209. SingnhjxhEntity SingnhjxhEntity = (SingnhjxhEntity)uRow.ListObject;
  210. string OfflineResultTity = JSONFormat.Format(SingnhjxhEntity);
  211. parm.Add(OfflineResultTity);
  212. }
  213. CoreClientParam ccp = new CoreClientParam();
  214. ccp.ServerName = "com.steering.mes.cost.Frmsinghjxh";
  215. ccp.MethodName = "doDelete";
  216. ccp.ServerParams = new object[] { parm };
  217. ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  218. if (ccp.ReturnCode != -1)
  219. {
  220. if (ccp.ReturnInfo.Equals("操作成功"))
  221. {
  222. // DoQueryInList();
  223. Query();
  224. MessageUtil.ShowTips(ccp.ReturnInfo);
  225. }
  226. else
  227. {
  228. MessageUtil.ShowTips(ccp.ReturnInfo);
  229. }
  230. }
  231. }
  232. ///
  233. private void doAdd()
  234. {
  235. this.ultraGrid1.UpdateData();
  236. IQueryable<UltraGridRow> checkMagRows = this.ultraGrid1.Rows.AsQueryable().Where(" XUANZE = 'True'");
  237. if (checkMagRows.Count() == 0)
  238. {
  239. MessageUtil.ShowTips("请选择需要新增的数据");
  240. return;
  241. }
  242. ArrayList parm = new ArrayList();
  243. foreach (UltraGridRow uRow in checkMagRows)
  244. {
  245. Tqnqd02Entity entity = (Tqnqd02Entity)uRow.ListObject;
  246. entity.RecCreator = this.UserInfo.GetUserName();
  247. string Tqnqd02Entity = JSONFormat.Format(entity);
  248. parm.Add(Tqnqd02Entity);
  249. }
  250. CoreClientParam ccp = new CoreClientParam();
  251. ccp.ServerName = "com.steering.mes.cost.FrmTqnqd02";
  252. ccp.MethodName = "doAdd";
  253. ccp.ServerParams = new object[] { parm };
  254. ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  255. if (ccp.ReturnCode != -1)
  256. {
  257. if (ccp.ReturnInfo.Equals("操作成功"))
  258. {
  259. // DoQueryInList();
  260. Query();
  261. MessageUtil.ShowTips(ccp.ReturnInfo);
  262. }
  263. else
  264. {
  265. MessageUtil.ShowTips(ccp.ReturnInfo);
  266. }
  267. }
  268. }
  269. public List<SingnhjxhEntity> ReadExcelToSingnhjxhEntity(string fileName)
  270. {
  271. //定义要返回的datatable对象
  272. List<SingnhjxhEntity> SingnhjxhEntitys = new List<SingnhjxhEntity>();
  273. try
  274. {
  275. if (!File.Exists(fileName))
  276. {
  277. return null;
  278. }
  279. //根据指定路径读取文件
  280. using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
  281. {
  282. //根据文件流创建excel数据结构
  283. NPOI.SS.UserModel.IWorkbook workbook = NPOI.SS.UserModel.WorkbookFactory.Create(fs);
  284. //IWorkbook workbook = new HSSFWorkbook(fs);
  285. for (int k = 0; k < workbook.NumberOfSheets; k++)
  286. {
  287. NPOI.SS.UserModel.ISheet sheet = workbook.GetSheetAt(k);
  288. if (sheet != null)
  289. {
  290. //最后一列的标号
  291. int rowCount = sheet.LastRowNum;
  292. for (int i = 1; i <= rowCount; ++i)
  293. {
  294. SingnhjxhEntity entity = new SingnhjxhEntity();
  295. NPOI.SS.UserModel.IRow row = sheet.GetRow(i);
  296. if (row == null) continue; //没有数据的行默认是null       
  297. if (row.Cells.Count < 4)
  298. {
  299. throw new Exception("无足够列");
  300. }
  301. string SgSign = GetCellValue(row.Cells[0]);
  302. string cic = GetCellValue(row.Cells[1]);
  303. if (SgSign == "" || SgSign == null)
  304. {
  305. throw new Exception("牌号为空");
  306. }
  307. if (cic == "" || cic == null)
  308. {
  309. throw new Exception("索引号为空");
  310. }
  311. decimal outsife;
  312. decimal outhcmnfe;
  313. decimal outmcmnfe;
  314. decimal outlcmnfe;
  315. decimal outhccrfe;
  316. decimal outmccrfe;
  317. decimal outlccrfe;
  318. decimal outwccrfe;
  319. decimal outmofe;
  320. decimal outvfe;
  321. decimal outnbfe;
  322. decimal outenl;
  323. decimal outcathodecopper;
  324. decimal outwcu;
  325. decimal outlfrb;
  326. decimal outsicaba;
  327. decimal outal;
  328. decimal outalwire;
  329. decimal outtifecorewire;
  330. decimal outbfecorewire;
  331. decimal outswire;
  332. decimal outcawire;
  333. decimal outalpowder;
  334. decimal outnicalon;
  335. decimal outferrosiliconpowder;
  336. decimal outblowgraphitepowder;
  337. decimal outslagcarburizingball;
  338. decimal.TryParse(GetCellValue(row.Cells[2]), out outsife);
  339. decimal.TryParse(GetCellValue(row.Cells[3]), out outhcmnfe);
  340. decimal.TryParse(GetCellValue(row.Cells[4]), out outmcmnfe);
  341. decimal.TryParse(GetCellValue(row.Cells[5]), out outlcmnfe);
  342. decimal.TryParse(GetCellValue(row.Cells[6]), out outhccrfe);
  343. decimal.TryParse(GetCellValue(row.Cells[7]), out outmccrfe);
  344. decimal.TryParse(GetCellValue(row.Cells[8]), out outlccrfe);
  345. decimal.TryParse(GetCellValue(row.Cells[9]), out outwccrfe);
  346. decimal.TryParse(GetCellValue(row.Cells[10]), out outmofe);
  347. decimal.TryParse(GetCellValue(row.Cells[11]), out outvfe);
  348. decimal.TryParse(GetCellValue(row.Cells[12]), out outnbfe);
  349. decimal.TryParse(GetCellValue(row.Cells[13]), out outenl);
  350. decimal.TryParse(GetCellValue(row.Cells[14]), out outcathodecopper);
  351. decimal.TryParse(GetCellValue(row.Cells[15]), out outwcu);
  352. decimal.TryParse(GetCellValue(row.Cells[16]), out outlfrb);
  353. decimal.TryParse(GetCellValue(row.Cells[17]), out outsicaba);
  354. decimal.TryParse(GetCellValue(row.Cells[18]), out outal);
  355. decimal.TryParse(GetCellValue(row.Cells[19]), out outalwire);
  356. decimal.TryParse(GetCellValue(row.Cells[20]), out outtifecorewire);
  357. decimal.TryParse(GetCellValue(row.Cells[21]), out outbfecorewire);
  358. decimal.TryParse(GetCellValue(row.Cells[22]), out outswire);
  359. decimal.TryParse(GetCellValue(row.Cells[23]), out outcawire);
  360. decimal.TryParse(GetCellValue(row.Cells[24]), out outalpowder);
  361. decimal.TryParse(GetCellValue(row.Cells[25]), out outnicalon);
  362. decimal.TryParse(GetCellValue(row.Cells[26]), out outferrosiliconpowder);
  363. decimal.TryParse(GetCellValue(row.Cells[27]), out outblowgraphitepowder);
  364. decimal.TryParse(GetCellValue(row.Cells[28]), out outslagcarburizingball);
  365. entity.OutSife = outsife;
  366. entity.OutHcMnfe = outhcmnfe;
  367. entity.OutMcMnfe = outmcmnfe;
  368. entity.OutLcMnfe = outlcmnfe;
  369. entity.OutHcCrfe = outhccrfe;
  370. entity.OutMcCrfe = outmccrfe;
  371. entity.OutLcCrfe = outlccrfe;
  372. entity.OutWcCrfe = outwccrfe;
  373. entity.OutMofe = outmofe;
  374. entity.OutVfe = outvfe;
  375. entity.OutNbfe = outnbfe;
  376. entity.OutEni = outenl;
  377. entity.OutCathodeCopper = outcathodecopper;
  378. entity.OutWcu = outwcu;
  379. entity.OutLfrb = outlfrb;
  380. entity.OutSicaba = outsicaba;
  381. entity.OutAl = outal;
  382. entity.OutAlWire = outalwire;
  383. entity.OutTifeCoreWire = outtifecorewire;
  384. entity.OutBfeCoreWire = outbfecorewire;
  385. entity.OutSWire = outswire;
  386. entity.OutCaWire = outcawire;
  387. entity.OutAlPowder = outalpowder;
  388. entity.OutNicalon = outnicalon;
  389. entity.OutFerrosiliconPowder = outferrosiliconpowder;
  390. entity.OutBlowGraphitePowder = outblowgraphitepowder;
  391. entity.OutSlagCarburizingBall = outslagcarburizingball;
  392. entity.Cic = cic;
  393. entity.SgSign = SgSign;
  394. SingnhjxhEntitys.Add(entity);
  395. }
  396. }
  397. }
  398. }
  399. return SingnhjxhEntitys;
  400. }
  401. catch (Exception ex)
  402. {
  403. MessageBox.Show("EXCEL格式错误:" + ex.Message);
  404. return null;
  405. }
  406. }
  407. private string GetCellValue(ICell cell)
  408. {
  409. string value = "";
  410. switch (cell.CellType)
  411. {
  412. case CellType.Blank:
  413. value = "";
  414. break;
  415. case CellType.Numeric:
  416. short format = cell.CellStyle.DataFormat;
  417. value = cell.NumericCellValue.ToString2();
  418. break;
  419. case CellType.String:
  420. value = cell.StringCellValue;
  421. break;
  422. }
  423. return value;
  424. }
  425. /// <summary>
  426. /// 保存
  427. /// </summary>
  428. private void doSave()
  429. {
  430. try
  431. {
  432. this.ultraGrid1.UpdateData();
  433. IQueryable<UltraGridRow> checkMagRows = this.ultraGrid1.Rows.AsQueryable().Where(" XUANZE = 'True'");
  434. if (checkMagRows.Count() == 0)
  435. {
  436. MessageUtil.ShowTips("请选择需要修改的数据!");
  437. return;
  438. }
  439. ArrayList parm = new ArrayList();
  440. foreach (UltraGridRow uRow in checkMagRows)
  441. {
  442. Tqnqd02Entity entity = (Tqnqd02Entity)uRow.ListObject;
  443. entity.DuMaker = UserInfo.GetUserName();
  444. string SingnhjxhEntity = JSONFormat.Format(entity);
  445. parm.Add(SingnhjxhEntity);
  446. }
  447. CoreClientParam ccp = new CoreClientParam();
  448. ccp.ServerName = "com.steering.mes.cost.FrmTqnqd02";
  449. ccp.MethodName = "doSave";
  450. ccp.ServerParams = new object[] { parm };
  451. ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  452. if (ccp.ReturnCode != -1)
  453. {
  454. if (ccp.ReturnInfo.Equals("操作成功"))
  455. {
  456. // DoQueryInList();
  457. Query();
  458. MessageUtil.ShowTips(ccp.ReturnInfo);
  459. }
  460. else
  461. {
  462. MessageUtil.ShowTips(ccp.ReturnInfo);
  463. }
  464. }
  465. }
  466. catch
  467. {
  468. return;
  469. }
  470. }
  471. /// 查询方法
  472. /// <summary>
  473. /// 查询方法
  474. /// </summary>
  475. private void Query()
  476. {
  477. List<Tqnqd02Entity> listSource = EntityHelper.GetData<Tqnqd02Entity>(
  478. "com.steering.mes.cost.FrmTqnqd02.doQuery", new object[] { lgcxText.Text, bhcxText.Text, gzlbText.Text, gpphText.Text,gpbzText.Text }, this.ob);
  479. singnhjxhEntityBindingSource.DataSource = listSource;
  480. GridHelper.RefreshAndAutoSize(ultraGrid1);
  481. }
  482. /// 保存方法
  483. /// <summary>
  484. /// 保存方法
  485. /// </summary>
  486. private void Save()
  487. {
  488. }
  489. #endregion
  490. #region
  491. #endregion
  492. }
  493. }