FrmReqApplyInfo.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using CoreFS.CA06;
  10. using Core.Mes.Client.Comm;
  11. using Core.Mes.Client.Comm.Server;
  12. using System.Collections;
  13. using Core.Mes.Client.Comm.Control;
  14. using System.Diagnostics;
  15. using System.IO;
  16. using Infragistics.Win.UltraWinGrid;
  17. using Core.Mes.Client.Comm.Tool;
  18. using com.steering.pss.plnsaleord.order.model;
  19. namespace Core.StlMes.Client.PlnSaleOrd
  20. {
  21. public partial class FrmReqApplyInfo : FrmBase
  22. {
  23. public FrmReqApplyInfo()
  24. {
  25. this.IsLoadUserView = true;
  26. InitializeComponent();
  27. }
  28. public FrmReqApplyInfo(OpeBase openBase)
  29. {
  30. this.ob = ob;
  31. InitializeComponent();
  32. }
  33. public override void ToolBar_Click(object sender, string ToolbarKey)
  34. {
  35. base.ToolBar_Click(sender, ToolbarKey);
  36. switch (ToolbarKey)
  37. {
  38. case "Query":
  39. DoQuery();
  40. break;
  41. case "Confirm":
  42. DoConfirm();
  43. break;
  44. case "CancelConfirm":
  45. CancelConFirm();
  46. break;
  47. case "Export":
  48. DoExport();
  49. break;
  50. case "Close":
  51. this.Close();
  52. break;
  53. }
  54. }
  55. private void FrmReqApplyInfo_Load(object sender, EventArgs e)
  56. {
  57. this.ultraDateTimeApplyDateFrom.Value = DateTime.Now;
  58. this.ultraDateTimeApplyDateTo.Value = DateTime.Now;
  59. PlanComm.setGridActivation(this.ultraGridReqOrd.DisplayLayout.Bands[0], "CHC", "CONFIRM_WT");
  60. PlanComm.setGridDigitalCol(ultraGridReqOrd.DisplayLayout.Bands[0], 7, 3, "REP_QTY", "REQWEIGHT", "CONFIRM_WT");
  61. DoQuery();
  62. }
  63. /// <summary>
  64. /// 查询
  65. /// </summary>
  66. private void DoQuery()
  67. {
  68. try
  69. {
  70. ArrayList param = new ArrayList();
  71. string strOrderNo = ""; //合同号
  72. string strDateForm = "1000/01/01"; //交货结束日期从,默认最小日期
  73. string strDateTo = "9999/12/31"; //交货结束日期到,默认最大日期
  74. string strChecked = "";
  75. if (this.checkBoxOrderNo.Checked)
  76. {
  77. //合同号
  78. strOrderNo = this.ultraTextOrderNo.Text.Trim();
  79. }
  80. if (this.checkBoxApplyDate.Checked)
  81. {
  82. //申请日期
  83. strDateForm = this.ultraDateTimeApplyDateFrom.DateTime.ToString("yyyy/MM/dd");
  84. strDateTo = this.ultraDateTimeApplyDateTo.DateTime.ToString("yyyy/MM/dd");
  85. }
  86. if (checkBoxInCuldeAll.Checked)
  87. {
  88. strChecked = "1";
  89. }
  90. param.Add(strOrderNo);
  91. param.Add(strDateForm);
  92. param.Add(strDateTo);
  93. param.Add(strChecked);
  94. DataTable dt = ServerHelper.GetData("com.steering.pss.plnsaleord.order.CoreReqRequest.getReqOrder",
  95. new object[] { param }, this.ob);
  96. GridHelper.CopyDataToDatatable(dt, dataTable1, true);
  97. }
  98. catch (Exception ex)
  99. {
  100. if (ex is MESException)
  101. {
  102. }
  103. else
  104. {
  105. MessageBox.Show(ex.Message);
  106. }
  107. }
  108. }
  109. /// <summary>
  110. /// 确认补量申请
  111. /// </summary>
  112. private void DoConfirm()
  113. {
  114. try
  115. {
  116. ArrayList list = new ArrayList();
  117. ultraGridReqOrd.UpdateData();
  118. IQueryable<UltraGridRow> checkRows = ultraGridReqOrd.Rows.AsQueryable().Where("CHC = 'True'");
  119. if (checkRows.Count() == 0)
  120. {
  121. MessageUtil.ShowTips("未勾选任何行!");
  122. return;
  123. }
  124. foreach (UltraGridRow uRow in checkRows)
  125. {
  126. double confirmWt = 0;
  127. PlnSaleorderRNumEntity rNumEntity = new PlnSaleorderRNumEntity();
  128. rNumEntity.PlanDealName = UserInfo.GetUserName();
  129. rNumEntity.RepQty = uRow.Cells["REP_QTY"].Value.ToString();
  130. rNumEntity.RNumId = uRow.Cells["R_NUM_ID"].Value.ToString();
  131. rNumEntity.Reqweight = uRow.Cells["REQWEIGHT"].Value.ToString();
  132. double.TryParse(uRow.Cells["CONFIRM_WT"].Value.ToString(), out confirmWt);
  133. rNumEntity.ConfirmWt = confirmWt.ToString();
  134. list.Add(rNumEntity);
  135. }
  136. CoreClientParam ccp = new CoreClientParam();
  137. ccp.ServerName = "com.steering.pss.plnsaleord.order.CoreReqRequest";
  138. ccp.MethodName = "setConfirm";
  139. ccp.ServerParams = new object[] { list };
  140. ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  141. if (ccp.ReturnCode != -1)
  142. {
  143. MessageUtil.ShowTips("确认成功!");
  144. }
  145. else
  146. {
  147. MessageUtil.ShowError("确认失败!" + ccp.ReturnInfo);
  148. }
  149. }
  150. catch (Exception ex)
  151. {
  152. MessageBox.Show(ex.Message);
  153. }
  154. DoQuery();
  155. }
  156. /// <summary>
  157. /// 取消确认
  158. /// </summary>
  159. private void CancelConFirm()
  160. {
  161. ArrayList list = new ArrayList();
  162. ultraGridReqOrd.UpdateData();
  163. IQueryable<UltraGridRow> checkRows = ultraGridReqOrd.Rows.AsQueryable().Where("CHC = 'True'");
  164. if (checkRows.Count() == 0)
  165. {
  166. MessageUtil.ShowTips("未勾选任何行!");
  167. return;
  168. }
  169. foreach (UltraGridRow uRow in checkRows)
  170. {
  171. list.Add(uRow.Cells["R_NUM_ID"].Value.ToString());
  172. }
  173. CoreClientParam ccp = new CoreClientParam();
  174. ccp.ServerName = "com.steering.pss.plnsaleord.order.CoreReqRequest";
  175. ccp.MethodName = "canCelConfirm";
  176. ccp.ServerParams = new object[] { list };
  177. ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  178. if (ccp == null)
  179. {
  180. MessageUtil.ShowError("服务端处理失败!");
  181. return;
  182. }
  183. if (ccp.ReturnCode < 0)
  184. {
  185. MessageUtil.ShowError("操作失败!\n" + ccp.ReturnInfo);
  186. return;
  187. }
  188. if (ccp.ReturnObject != null)
  189. {
  190. MessageUtil.ShowTips(ccp.ReturnObject.ToString());
  191. DoQuery();
  192. }
  193. }
  194. /// <summary>
  195. /// 导出
  196. /// </summary>
  197. private void DoExport()
  198. {
  199. try
  200. {
  201. int rowCount = this.ultraGridReqOrd.Rows.Count;
  202. int colCount = this.ultraGridReqOrd.DisplayLayout.Bands[0].Columns.Count - 10;
  203. object[,] arr = new object[rowCount, colCount];
  204. for (int j = 0; j < rowCount; j++)
  205. {
  206. for (int i = 0; i < colCount; i++)
  207. {
  208. string output = ultraGridReqOrd.Rows[j].Cells[i].Value.ToString();
  209. if (ultraGridReqOrd.DisplayLayout.Bands[0].Columns[i].Key.Equals("GROUP_ROLL"))
  210. {
  211. //产线
  212. int plineCode = 0;
  213. output = output.Replace("机组", "");
  214. if (int.TryParse(output, out plineCode))
  215. {
  216. output = "'" + plineCode.ToString();
  217. }
  218. }
  219. if (ultraGridReqOrd.DisplayLayout.Bands[0].Columns[i].Key.Equals("STEELNAME"))
  220. {
  221. //钢级
  222. double grade = 0;
  223. if (double.TryParse(output, out grade))
  224. {
  225. output = "'" + output;
  226. }
  227. }
  228. if (ultraGridReqOrd.DisplayLayout.Bands[0].Columns[i].Key.Equals("ROLL_MONTH"))
  229. {
  230. //轧制月份
  231. DateTime dt = new DateTime();
  232. if (DateTime.TryParse(output, out dt))
  233. {
  234. output = "'" + dt.ToString("yyyyMM");
  235. }
  236. }
  237. arr[j, i] = output;
  238. }
  239. }
  240. string path = System.Windows.Forms.Application.StartupPath + "\\model";
  241. string tempExcel = path + "\\FrmSaleOrdmodel.xls";
  242. string outPutExcl = "补量合同" + DateTime.Now.ToString("yyyyMMdd");
  243. if (!System.IO.File.Exists(tempExcel))//检察模板是否存在
  244. {
  245. MessageBox.Show(this, "未找到报表模板!");
  246. return;
  247. }
  248. if (ultraGridReqOrd.Rows.Count == 0) return;
  249. if (outPutExcl.Length == 0) outPutExcl = "未命名";
  250. SaveFileDialog dlg = new SaveFileDialog();
  251. dlg.Title = "保存";
  252. dlg.OverwritePrompt = true;
  253. dlg.Filter = "Excel文件(*.xls)|*.xls";
  254. dlg.AddExtension = true;
  255. dlg.FileName = outPutExcl;
  256. if (dlg.ShowDialog() == DialogResult.OK)
  257. {
  258. outPutExcl = dlg.FileName;
  259. WaitFromOpen();
  260. ExcelHelper excelport = new ExcelHelper(tempExcel, outPutExcl);
  261. if (excelport.ArrayToExcel(arr, 2, 1, "Sheet"))
  262. {
  263. WaitFromColse();
  264. if (MessageBox.Show("数据导出成功!\n需要打开所导出文件吗?", "提示",
  265. MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  266. {
  267. ProcessStartInfo p = new ProcessStartInfo(outPutExcl);
  268. p.WorkingDirectory = Path.GetDirectoryName(outPutExcl);
  269. Process.Start(p);
  270. }
  271. }
  272. else
  273. {
  274. WaitFromColse();
  275. MessageBox.Show("数据导出失败!");
  276. return;
  277. }
  278. }
  279. }
  280. catch (Exception ex)
  281. {
  282. WaitFromColse();
  283. MessageBox.Show(ex.Message);
  284. }
  285. }
  286. /// <summary>
  287. /// 等待窗口
  288. /// </summary>
  289. private void WaitFromOpen()
  290. {
  291. this.Cursor = Cursors.WaitCursor; //控制鼠标的样式为等待
  292. if (Constant.WaitingForm == null)
  293. {
  294. Constant.WaitingForm = new WaitingForm();
  295. }
  296. Constant.WaitingForm.ShowToUser = true;
  297. Constant.WaitingForm.Show();
  298. Constant.WaitingForm.Update();
  299. }
  300. /// <summary>
  301. /// 关闭等待
  302. /// </summary>
  303. private void WaitFromColse()
  304. {
  305. this.Cursor = Cursors.Default;
  306. Constant.WaitingForm.ShowToUser = false;
  307. Constant.WaitingForm.Close();
  308. Constant.WaitingForm = null;
  309. }
  310. private void checkBoxApplyDate_CheckedChanged(object sender, EventArgs e)
  311. {
  312. if (checkBoxApplyDate.Checked)
  313. {
  314. this.ultraDateTimeApplyDateFrom.Enabled = true;
  315. this.ultraDateTimeApplyDateTo.Enabled = true;
  316. }
  317. else
  318. {
  319. this.ultraDateTimeApplyDateFrom.Enabled = false;
  320. this.ultraDateTimeApplyDateTo.Enabled = false;
  321. }
  322. }
  323. private void checkBoxOrderNo_CheckedChanged(object sender, EventArgs e)
  324. {
  325. if (checkBoxOrderNo.Checked)
  326. {
  327. this.ultraTextOrderNo.Enabled = true;
  328. }
  329. else
  330. {
  331. this.ultraTextOrderNo.Enabled = false;
  332. }
  333. }
  334. private void ultraDateTimeApplyDateFrom_ValueChanged(object sender, EventArgs e)
  335. {
  336. ultraDateTimeApplyDateTo.MinDate = ultraDateTimeApplyDateFrom.DateTime.Date;
  337. }
  338. private void ultraDateTimeApplyDateTo_ValueChanged(object sender, EventArgs e)
  339. {
  340. ultraDateTimeApplyDateFrom.MaxDate = ultraDateTimeApplyDateTo.DateTime.AddDays(1).Date.AddSeconds(-1);
  341. }
  342. private void ultraGridReqOrd_AfterSelectChange(object sender, AfterSelectChangeEventArgs e)
  343. {
  344. foreach (UltraGridRow uRow in ultraGridReqOrd.Selected.Rows)
  345. {
  346. if (uRow.GetType() != typeof(Infragistics.Win.UltraWinGrid.UltraGridGroupByRow))
  347. {
  348. uRow.Cells["CHC"].Value = true;
  349. }
  350. }
  351. }
  352. }
  353. }