FrmRunTimeRptZgNew.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. using Core.Mes.Client.Comm.Control;
  2. using Core.Mes.Client.Comm.Server;
  3. using Core.Mes.Client.Comm.Tool;
  4. using Core.StlMes.Client.YdmPipeManage;
  5. using Core.StlMes.Client.YdmPipeManage.Tool;
  6. using CoreFS.CA06;
  7. using Infragistics.Win.UltraWinGrid;
  8. using System;
  9. using System.Collections;
  10. using System.Collections.Generic;
  11. using System.ComponentModel;
  12. using System.Data;
  13. using System.Drawing;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Windows.Forms;
  17. namespace Core.StlMes.Client.YdmPipeReport
  18. {
  19. public partial class FrmRunTimeRptZgNew : FrmBase
  20. {
  21. public FrmRunTimeRptZgNew()
  22. {
  23. InitializeComponent();
  24. }
  25. private string beglongCode = "";//部门ID
  26. private Hashtable ShapeRelation = null;
  27. private void FrmRunTimeRptZgNew_Load(object sender, EventArgs e)
  28. {
  29. dtBathYear.Value = DateTime.Parse(DateTime.Now.ToString("yyyy-MM"));
  30. }
  31. public override void ToolBar_Click(object sender, string ToolbarKey)
  32. {
  33. switch (ToolbarKey)
  34. {
  35. case "Query":
  36. queryData();
  37. break;
  38. case "Export":
  39. exportData();
  40. break;
  41. case "insertTal":
  42. insertTal();
  43. break;
  44. case "cancelInsertTal":
  45. cancelInsertTal();
  46. break;
  47. case "Close":
  48. this.Close();
  49. break;
  50. }
  51. }
  52. /// <summary>
  53. /// 查询
  54. /// </summary>
  55. private void queryData()
  56. {
  57. string yearMothTim = this.dtBathYear.Value.ToString("yyyyMM");
  58. DataTable table1 = null;
  59. DataTable table2 = null;
  60. DataTable table3 = null;
  61. string[] arr = BaseMethod.getPlineValid(this.ValidDataPurviewIds,this.ob);
  62. //beglongCode = ClsBaseInfo.GetDepartIdBySectionId(this.UserInfo.GetDeptid(), this.ob);
  63. try
  64. {
  65. this.Cursor = Cursors.WaitCursor; //控制鼠标的样式为等待
  66. if (Constant.WaitingForm == null)
  67. {
  68. Constant.WaitingForm = new WaitingForm();
  69. }
  70. Constant.WaitingForm.ShowToUser = true;
  71. Constant.WaitingForm.Show();
  72. Constant.WaitingForm.Update();
  73. //上期期初
  74. if (!this.GetOriginalLastB(yearMothTim, out table1, arr))
  75. {
  76. }
  77. //本期入库量
  78. if (!this.GetThisInB(yearMothTim, out table2, arr))
  79. {
  80. //return;
  81. }
  82. //本期出库量
  83. if (!this.GetThisOutB(yearMothTim, out table3, arr))
  84. {
  85. //return;
  86. }
  87. DataTable table = new DataTable();
  88. string[] strMergeColumns = new string[] { "JUDGE_STOVE_NO","PLINE_NAME" };
  89. if (table1 != null)
  90. {
  91. table = table1.DefaultView.ToTable(true, strMergeColumns);
  92. if (table2 != null)
  93. {
  94. table.Merge(table2.DefaultView.ToTable(true, strMergeColumns));
  95. }
  96. if (table3 != null)
  97. {
  98. table.Merge(table3.DefaultView.ToTable(true, strMergeColumns));
  99. }
  100. }
  101. else
  102. {
  103. if (table2 != null)
  104. {
  105. table = table2.DefaultView.ToTable(true, strMergeColumns);
  106. if (table3 != null)
  107. {
  108. table.Merge(table3.DefaultView.ToTable(true, strMergeColumns));
  109. }
  110. }
  111. else
  112. {
  113. if (table3 != null)
  114. {
  115. table = table3.DefaultView.ToTable(true, strMergeColumns);
  116. }
  117. }
  118. }
  119. if (table != null)
  120. {
  121. table.DefaultView.Sort = "JUDGE_STOVE_NO,PLINE_NAME";
  122. table = table.DefaultView.ToTable(true, strMergeColumns);
  123. }
  124. else
  125. {
  126. return;
  127. }
  128. string strSort = "", strHeatNo = "",strPlineName = "";
  129. DataRow newrow;
  130. DataRow[] rows;
  131. this.dataTable1.Rows.Clear();
  132. decimal dWgt = 0.0M, dAjust = 0.0M;
  133. int dCount = 0;
  134. decimal dThisIn_Month = 0.0M, dThisOut_Month = 0.00M;
  135. int dThisIn_MonthCount = 0, dThisOut_MonthCount = 0;
  136. string strRowFilters = "";
  137. for (int i = 0; i < table.Rows.Count; i++)
  138. {
  139. newrow = this.dataTable1.NewRow();
  140. try
  141. {
  142. strHeatNo = Convert.ToString(table.Rows[i]["JUDGE_STOVE_NO"]);//炉号
  143. strPlineName = Convert.ToString(table.Rows[i]["PLINE_NAME"]);//产线
  144. strRowFilters = string.IsNullOrEmpty(strHeatNo) ? " JUDGE_STOVE_NO is null " : " JUDGE_STOVE_NO = '" + strHeatNo + "' ";
  145. strRowFilters += string.IsNullOrEmpty(strPlineName) ? " and PLINE_NAME is null " : " and PLINE_NAME = '" + strPlineName + "' ";
  146. try
  147. {
  148. table1.CaseSensitive = true;
  149. rows = table1.Select(strRowFilters);
  150. if (rows.Length > 0)
  151. {
  152. try
  153. {
  154. dWgt = decimal.Parse(Convert.ToString(rows[0]["WEIGHT"]));
  155. dCount = int.Parse(Convert.ToString(rows[0]["COUNT"]));
  156. }
  157. catch
  158. {
  159. dWgt = 0.0M;
  160. dCount = 0;
  161. }
  162. }
  163. else
  164. {
  165. dWgt = 0.0M;
  166. dCount = 0;
  167. }
  168. }
  169. catch
  170. {
  171. dWgt = 0.0M;
  172. dCount = 0;
  173. }
  174. try
  175. {
  176. table2.CaseSensitive = true;
  177. rows = table2.Select(strRowFilters);
  178. if (rows.Length > 0)
  179. {
  180. try
  181. {
  182. dThisIn_Month = decimal.Parse(Convert.ToString(rows[0]["WEIGHT_MONTH"]));
  183. dThisIn_MonthCount = int.Parse(Convert.ToString(rows[0]["WEIGHT_MONTHCOUNT"]));
  184. }
  185. catch
  186. {
  187. dThisIn_Month = 0.0M;
  188. dThisIn_MonthCount = 0;
  189. }
  190. }
  191. else
  192. {
  193. dThisIn_Month = 0.0M;
  194. dThisIn_MonthCount = 0;
  195. }
  196. }
  197. catch
  198. {
  199. dThisIn_Month = 0.0M;
  200. dThisIn_MonthCount = 0;
  201. }
  202. try
  203. {
  204. table3.CaseSensitive = true;
  205. rows = table3.Select(strRowFilters);
  206. if (rows.Length > 0)
  207. {
  208. try
  209. {
  210. dThisOut_Month = decimal.Parse(Convert.ToString(rows[0]["WEIGHT_MONTH"]));
  211. dThisOut_MonthCount = int.Parse(Convert.ToString(rows[0]["weight_monthcount"]));
  212. }
  213. catch
  214. {
  215. dThisOut_Month = 0.0M;
  216. dThisOut_MonthCount = 0;
  217. }
  218. }
  219. else
  220. {
  221. dThisOut_Month = 0.0M;
  222. dThisOut_MonthCount = 0;
  223. }
  224. }
  225. catch
  226. {
  227. dThisOut_Month = 0.0M;
  228. dThisOut_MonthCount = 0;
  229. }
  230. try
  231. {
  232. newrow["JUDGE_STOVE_NO"] = strHeatNo;
  233. newrow["PLINE_NAME"] = strPlineName;
  234. newrow["ORIGINAL_AMOUNT"] = Convert.ToString(dWgt).Trim();
  235. newrow["ORIGINAL_COUNT"] = Convert.ToString(dCount).Trim();
  236. newrow["MONTH_1"] = dThisIn_Month.ToString().Trim();
  237. newrow["MONTH_1COUNT"] = dThisIn_MonthCount.ToString().Trim();
  238. newrow["MONTH_2"] = dThisOut_Month.ToString().Trim();
  239. newrow["MONTH_2COUNT"] = dThisOut_MonthCount.ToString().Trim();
  240. newrow["END_AMOUNT"] = Convert.ToString(dWgt + dThisIn_Month - dThisOut_Month + dAjust).Trim();
  241. newrow["END_COUNT"] = Convert.ToString(dCount + dThisIn_MonthCount - dThisOut_MonthCount).Trim();
  242. newrow["AWEIGHT"] = Convert.ToString(dAjust).Trim();
  243. try
  244. {
  245. if (ShapeRelation!=null&&ShapeRelation.Contains(strHeatNo))
  246. {
  247. strSort = ShapeRelation[strHeatNo].ToString();
  248. }
  249. else
  250. {
  251. strSort = "";
  252. }
  253. }
  254. catch
  255. {
  256. strSort = "";
  257. }
  258. this.dataSet1.Tables[0].Rows.Add(newrow);
  259. }
  260. catch { }
  261. }
  262. catch { }
  263. }
  264. this.SetStaticsInfo();
  265. CommonMethod.SetGridSumArea(this.ultraGrid1);
  266. this.Cursor = Cursors.Default;
  267. Constant.WaitingForm.ShowToUser = false;
  268. Constant.WaitingForm.Close();
  269. Constant.WaitingForm = null;
  270. }
  271. catch (Exception e)
  272. {
  273. this.Cursor = Cursors.Default;
  274. Constant.WaitingForm.ShowToUser = false;
  275. Constant.WaitingForm.Close();
  276. Constant.WaitingForm = null;
  277. }
  278. }
  279. /// <summary>
  280. /// 结转期初数据
  281. /// </summary>
  282. private void insertTal()
  283. {
  284. string dtYear = this.dtBathYear.Value.ToString("yyyyMM");
  285. string dtNowTim = DateTime.Now.AddMonths(1).ToString("yyyyMM");
  286. //if (!this.dtBathYear.Value.AddMonths(1).ToString("yyyyMM").Equals(dtNowTim))
  287. //{
  288. // MessageUtil.ShowTips("所选结转年月与当前所在月往后推一月不一致,请重新选择结转年月!");
  289. // return;
  290. //}
  291. UltraGridRow row = this.ultraGrid1.ActiveRow;
  292. if (row == null || row.Index < 0)
  293. {
  294. MessageUtil.ShowWarning("无库存信息,无法结转!");
  295. return;
  296. }
  297. string departId = ClsBaseInfo.GetDepartIdBySectionId(this.UserInfo.GetDeptid(), this.ob);
  298. DataTable ds = ServerHelper.GetData("com.steering.pss.ydm.Report.FrmRunTimeRptZg.getIntalJZB", new object[] { dtNowTim, departId }, ob);
  299. if (int.Parse(ds.Rows[0][0].ToString()) > 0)
  300. {
  301. MessageUtil.ShowTips("已存在结转数据,不允许重复结转!");
  302. return;
  303. }
  304. ArrayList parm = new ArrayList();
  305. if (MessageUtil.ShowYesNoAndQuestion("是否结转期初数据?") == DialogResult.No) return;
  306. try
  307. {
  308. this.Cursor = Cursors.WaitCursor; //控制鼠标的样式为等待
  309. if (Constant.WaitingForm == null)
  310. {
  311. Constant.WaitingForm = new WaitingForm();
  312. }
  313. Constant.WaitingForm.ShowToUser = true;
  314. Constant.WaitingForm.Show();
  315. Constant.WaitingForm.Update();
  316. foreach (UltraGridRow uRow in ultraGrid1.Rows)
  317. {
  318. if (int.Parse(uRow.Cells["END_COUNT"].Value.ToString()) > 0)
  319. {
  320. ArrayList list = new ArrayList();
  321. list.Add(uRow.Cells["JUDGE_STOVE_NO"].Value.ToString());
  322. list.Add(uRow.Cells["END_COUNT"].Value.ToString());
  323. list.Add(uRow.Cells["END_AMOUNT"].Value.ToString());
  324. list.Add(this.dtBathYear.Value.AddMonths(1).ToString("yyyyMM"));
  325. list.Add(this.UserInfo.GetUserName());
  326. parm.Add(list);
  327. }
  328. }
  329. CoreClientParam ccp = new CoreClientParam();
  330. ccp.ServerName = "com.steering.pss.ydm.Report.FrmRunTimeRptZgNew";
  331. ccp.MethodName = "insertInitalBelog";
  332. ccp.ServerParams = new object[] { parm, departId, dtYear };
  333. ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  334. if (ccp.ReturnCode != -1)
  335. {
  336. if (ccp.ReturnInfo.Equals("期初数据结转成功!"))
  337. {
  338. MessageUtil.ShowTips(ccp.ReturnInfo);
  339. }
  340. else
  341. {
  342. MessageUtil.ShowTips(ccp.ReturnInfo);
  343. }
  344. }
  345. this.Cursor = Cursors.Default;
  346. Constant.WaitingForm.ShowToUser = false;
  347. Constant.WaitingForm.Close();
  348. Constant.WaitingForm = null;
  349. }
  350. catch (Exception e)
  351. {
  352. this.Cursor = Cursors.Default;
  353. Constant.WaitingForm.ShowToUser = false;
  354. Constant.WaitingForm.Close();
  355. Constant.WaitingForm = null;
  356. }
  357. }
  358. /// <summary>
  359. /// 取消结转
  360. /// </summary>
  361. private void cancelInsertTal()
  362. {
  363. string dtYear = this.dtBathYear.Value.ToString("yyyyMM");
  364. string dtYear2 = this.dtBathYear.Value.AddMonths(1).ToString("yyyyMM");
  365. string dtNowTim = DateTime.Now.ToString("yyyyMM");
  366. if (!this.dtBathYear.Value.AddMonths(1).ToString("yyyyMM").Equals(dtNowTim))
  367. {
  368. MessageUtil.ShowTips("所选结转年月与当前所在月往后推一月不一致,请重新选择结转年月!");
  369. return;
  370. }
  371. ArrayList parm = new ArrayList();
  372. if (MessageUtil.ShowYesNoAndQuestion("是否撤销结转期初数据?") == DialogResult.No) return;
  373. try
  374. {
  375. this.Cursor = Cursors.WaitCursor; //控制鼠标的样式为等待
  376. if (Constant.WaitingForm == null)
  377. {
  378. Constant.WaitingForm = new WaitingForm();
  379. }
  380. Constant.WaitingForm.ShowToUser = true;
  381. Constant.WaitingForm.Show();
  382. Constant.WaitingForm.Update();
  383. CoreClientParam ccp = new CoreClientParam();
  384. ccp.ServerName = "com.steering.pss.ydm.Report.FrmRunTimeRptZgNew";
  385. ccp.MethodName = "cancelInsertTal";
  386. ccp.ServerParams = new object[] { dtYear, dtYear2 };
  387. ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  388. if (ccp.ReturnCode != -1)
  389. {
  390. if (ccp.ReturnInfo.Equals("撤销成功!"))
  391. {
  392. MessageUtil.ShowTips(ccp.ReturnInfo);
  393. }
  394. else
  395. {
  396. MessageUtil.ShowTips(ccp.ReturnInfo);
  397. }
  398. }
  399. this.Cursor = Cursors.Default;
  400. Constant.WaitingForm.ShowToUser = false;
  401. Constant.WaitingForm.Close();
  402. Constant.WaitingForm = null;
  403. }
  404. catch (Exception e)
  405. {
  406. this.Cursor = Cursors.Default;
  407. Constant.WaitingForm.ShowToUser = false;
  408. Constant.WaitingForm.Close();
  409. Constant.WaitingForm = null;
  410. }
  411. }
  412. //期初(所属权)
  413. private bool GetOriginalLastB(string yearMothTim, out DataTable table, string[] belogCode)
  414. {
  415. table = null;
  416. DataSet set = new DataSet();
  417. DataTable ds = ServerHelper.GetData("com.steering.pss.ydm.Report.FrmRunTimeRptZgNew.getOriginalLastB", new object[] { yearMothTim, belogCode }, this.ob);
  418. if (ds != null && ds.Rows.Count > 0)
  419. {
  420. set.Tables.Add(ds);
  421. table = set.Tables[0];
  422. return true;
  423. }
  424. return false;
  425. }
  426. //入库量
  427. private bool GetThisInB(string yearMothTim, out DataTable table, string[] belogCode)
  428. {
  429. table = null;
  430. DataSet set = new DataSet();
  431. DataTable ds = ServerHelper.GetData("com.steering.pss.ydm.Report.FrmRunTimeRptZgNew.getThisInB", new object[] { yearMothTim, belogCode }, this.ob);
  432. if (ds != null && ds.Rows.Count > 0)
  433. {
  434. set.Tables.Add(ds);
  435. table = set.Tables[0];
  436. return true;
  437. }
  438. return false;
  439. }
  440. //本期出库量
  441. private bool GetThisOutB(string yearMothTim, out DataTable table, string[] belogCode)
  442. {
  443. table = null;
  444. DataSet set = new DataSet();
  445. DataTable ds = ServerHelper.GetData("com.steering.pss.ydm.Report.FrmRunTimeRptZgNew.getThisOutB", new object[] { yearMothTim, belogCode }, this.ob);
  446. if (ds != null && ds.Rows.Count > 0)
  447. {
  448. set.Tables.Add(ds);
  449. table = set.Tables[0];
  450. return true;
  451. }
  452. return false;
  453. }
  454. /// <summary>
  455. /// 导出
  456. /// </summary>
  457. private void exportData()
  458. {
  459. GridHelper.ulGridToExcel(ultraGrid1, "炉批运行年月收发存汇总");
  460. }
  461. private void SetStaticsInfo()
  462. {
  463. try
  464. {
  465. if (this.ultraGrid1.Rows.Count == 0)
  466. {
  467. this.ultraGrid1.DisplayLayout.Bands[0].Summaries.Clear();
  468. }
  469. else
  470. {
  471. ArrayList alist = new ArrayList();
  472. alist.Add("ORIGINAL_AMOUNT");
  473. alist.Add("ORIGINAL_COUNT");
  474. alist.Add("MONTH_1");
  475. alist.Add("MONTH_1COUNT");
  476. alist.Add("MONTH_2");
  477. alist.Add("MONTH_2COUNT");
  478. alist.Add("END_AMOUNT");
  479. alist.Add("END_COUNT");
  480. alist.Add("AWEIGHT");
  481. CommonMethod.SetStaticsInfoSum(ref this.ultraGrid1, alist, true);
  482. }
  483. }
  484. catch { }
  485. }
  486. }
  487. }