FrmReqApplyInfo.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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.plan.order.model;
  19. namespace Core.StlMes.Client.Plan.Order
  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 "Export":
  45. DoExport();
  46. break;
  47. case "Close":
  48. this.Close();
  49. break;
  50. }
  51. }
  52. private void FrmReqApplyInfo_Load(object sender, EventArgs e)
  53. {
  54. this.ultraDateTimeApplyDateFrom.Value = DateTime.Now;
  55. this.ultraDateTimeApplyDateTo.Value = DateTime.Now;
  56. DoQuery();
  57. }
  58. /// <summary>
  59. /// 查询
  60. /// </summary>
  61. private void DoQuery()
  62. {
  63. try
  64. {
  65. ArrayList param = new ArrayList();
  66. string strOrderNo = ""; //合同号
  67. string strDateForm = "1000/01/01"; //交货结束日期从,默认最小日期
  68. string strDateTo = "9999/12/31"; //交货结束日期到,默认最大日期
  69. string strChecked = "";
  70. if (this.checkBoxOrderNo.Checked)
  71. {
  72. //合同号
  73. strOrderNo = this.ultraTextOrderNo.Text.Trim();
  74. }
  75. if (this.checkBoxApplyDate.Checked)
  76. {
  77. //接收日期
  78. strDateForm = this.ultraDateTimeApplyDateFrom.DateTime.ToString("yyyy/MM/dd");
  79. strDateTo = this.ultraDateTimeApplyDateTo.DateTime.ToString("yyyy/MM/dd");
  80. }
  81. if (checkBoxInCuldeAll.Checked)
  82. {
  83. strChecked = "1";
  84. }
  85. param.Add(strOrderNo);
  86. param.Add(strDateForm);
  87. param.Add(strDateTo);
  88. param.Add(strChecked);
  89. DataTable dt = ServerHelper.GetData("com.steering.pss.plan.order.CoreReqRequest.getReqOrder",
  90. new object[] { param }, this.ob);
  91. GridHelper.CopyDataToDatatable(dt, dataTable1, true);
  92. PlanComm.setGridActivation(this.ultraGridReqOrd.DisplayLayout.Bands[0], "CHC", "CONFIRM_WT");
  93. PlanComm.setGridDigitalColMaxInput(ultraGridReqOrd.DisplayLayout.Bands[0], 7, 3, "REP_QTY", "REQWEIGHT", "CONFIRM_WT");
  94. }
  95. catch (Exception ex)
  96. {
  97. if (ex is MESException)
  98. {
  99. }
  100. else
  101. {
  102. MessageBox.Show(ex.Message);
  103. }
  104. }
  105. }
  106. /// <summary>
  107. /// 确认补量申请
  108. /// </summary>
  109. private void DoConfirm()
  110. {
  111. try
  112. {
  113. ArrayList list = new ArrayList();
  114. ultraGridReqOrd.UpdateData();
  115. IQueryable<UltraGridRow> checkRows = ultraGridReqOrd.Rows.AsQueryable().Where("CHC = 'True'");
  116. if (checkRows.Count() == 0)
  117. {
  118. MessageUtil.ShowTips("未勾选任何行!");
  119. return;
  120. }
  121. foreach (UltraGridRow uRow in checkRows)
  122. {
  123. double confirmWt = 0;
  124. PlnSaleorderRNumEntity rNumEntity = new PlnSaleorderRNumEntity();
  125. rNumEntity.PlanDealName = UserInfo.GetUserName();
  126. rNumEntity.RepQty = uRow.Cells["REP_QTY"].Value.ToString();
  127. rNumEntity.RNumId = uRow.Cells["R_NUM_ID"].Value.ToString();
  128. double.TryParse(uRow.Cells["CONFIRM_WT"].Value.ToString(), out confirmWt);
  129. rNumEntity.ConfirmWt = confirmWt.ToString();
  130. list.Add(rNumEntity);
  131. }
  132. CoreClientParam ccp = new CoreClientParam();
  133. ccp.ServerName = "com.steering.pss.plan.order.CoreReqRequest";
  134. ccp.MethodName = "setConfirm";
  135. ccp.ServerParams = new object[] { list };
  136. ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  137. if (ccp.ReturnCode != -1)
  138. {
  139. MessageUtil.ShowTips(ccp.ReturnInfo);
  140. }
  141. else
  142. {
  143. MessageUtil.ShowError("确认失败!" + ccp.ReturnInfo);
  144. }
  145. }
  146. catch (Exception ex)
  147. {
  148. MessageBox.Show(ex.Message);
  149. }
  150. DoQuery();
  151. }
  152. /// <summary>
  153. /// 导出
  154. /// </summary>
  155. private void DoExport()
  156. {
  157. try
  158. {
  159. int rowCount = this.ultraGridReqOrd.Rows.Count;
  160. int colCount = this.ultraGridReqOrd.DisplayLayout.Bands[0].Columns.Count - 9;
  161. object[,] arr = new object[rowCount, colCount];
  162. for (int j = 0; j < rowCount; j++)
  163. {
  164. for (int i = 0; i < colCount; i++)
  165. {
  166. string output = ultraGridReqOrd.Rows[j].Cells[i].Value.ToString();
  167. if (ultraGridReqOrd.DisplayLayout.Bands[0].Columns[i].Key.Equals("GROUP_ROLL"))
  168. {
  169. //产线
  170. int plineCode = 0;
  171. output = output.Replace("机组", "");
  172. if (int.TryParse(output, out plineCode))
  173. {
  174. output = "'" + plineCode.ToString();
  175. }
  176. }
  177. if (ultraGridReqOrd.DisplayLayout.Bands[0].Columns[i].Key.Equals("STEELNAME"))
  178. {
  179. //钢级
  180. double grade = 0;
  181. if (double.TryParse(output, out grade))
  182. {
  183. output = "'" + output;
  184. }
  185. }
  186. if (ultraGridReqOrd.DisplayLayout.Bands[0].Columns[i].Key.Equals("ROLL_MONTH"))
  187. {
  188. //轧制月份
  189. DateTime dt = new DateTime();
  190. if (DateTime.TryParse(output, out dt))
  191. {
  192. output = "'" + dt.ToString("yyyyMM");
  193. }
  194. }
  195. arr[j, i] = output;
  196. }
  197. }
  198. string path = System.Windows.Forms.Application.StartupPath + "\\model";
  199. string tempExcel = path + "\\FrmSaleOrdermodel.xls";
  200. string outPutExcl = "补量合同" + DateTime.Now.ToString("yyyyMMdd");
  201. if (!System.IO.File.Exists(tempExcel))//检察模板是否存在
  202. {
  203. MessageBox.Show(this, "未找到报表模板!");
  204. return;
  205. }
  206. if (ultraGridReqOrd.Rows.Count == 0) return;
  207. if (outPutExcl.Length == 0) outPutExcl = "未命名";
  208. SaveFileDialog dlg = new SaveFileDialog();
  209. dlg.Title = "保存";
  210. dlg.OverwritePrompt = true;
  211. dlg.Filter = "Excel文件(*.xls)|*.xls";
  212. dlg.AddExtension = true;
  213. dlg.FileName = outPutExcl;
  214. if (dlg.ShowDialog() == DialogResult.OK)
  215. {
  216. outPutExcl = dlg.FileName;
  217. WaitFromOpen();
  218. ExcelHelper excelport = new ExcelHelper(tempExcel, outPutExcl);
  219. if (excelport.ArrayToExcel(arr, 2, 1, "Sheet"))
  220. {
  221. WaitFromColse();
  222. if (MessageBox.Show("数据导出成功!\n需要打开所导出文件吗?", "提示",
  223. MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  224. {
  225. ProcessStartInfo p = new ProcessStartInfo(outPutExcl);
  226. p.WorkingDirectory = Path.GetDirectoryName(outPutExcl);
  227. Process.Start(p);
  228. }
  229. }
  230. else
  231. {
  232. WaitFromColse();
  233. MessageBox.Show("数据导出失败!");
  234. return;
  235. }
  236. }
  237. }
  238. catch (Exception ex)
  239. {
  240. WaitFromColse();
  241. MessageBox.Show(ex.Message);
  242. }
  243. }
  244. /// <summary>
  245. /// 等待窗口
  246. /// </summary>
  247. private void WaitFromOpen()
  248. {
  249. this.Cursor = Cursors.WaitCursor; //控制鼠标的样式为等待
  250. if (Constant.WaitingForm == null)
  251. {
  252. Constant.WaitingForm = new WaitingForm();
  253. }
  254. Constant.WaitingForm.ShowToUser = true;
  255. Constant.WaitingForm.Show();
  256. Constant.WaitingForm.Update();
  257. }
  258. /// <summary>
  259. /// 关闭等待
  260. /// </summary>
  261. private void WaitFromColse()
  262. {
  263. this.Cursor = Cursors.Default;
  264. Constant.WaitingForm.ShowToUser = false;
  265. Constant.WaitingForm.Close();
  266. Constant.WaitingForm = null;
  267. }
  268. private void checkBoxApplyDate_CheckedChanged(object sender, EventArgs e)
  269. {
  270. if (checkBoxApplyDate.Checked)
  271. {
  272. this.ultraDateTimeApplyDateFrom.Enabled = true;
  273. this.ultraDateTimeApplyDateTo.Enabled = true;
  274. }
  275. else
  276. {
  277. this.ultraDateTimeApplyDateFrom.Enabled = false;
  278. this.ultraDateTimeApplyDateTo.Enabled = false;
  279. }
  280. }
  281. private void checkBoxOrderNo_CheckedChanged(object sender, EventArgs e)
  282. {
  283. if (checkBoxOrderNo.Checked)
  284. {
  285. this.ultraTextOrderNo.Enabled = true;
  286. }
  287. else
  288. {
  289. this.ultraTextOrderNo.Enabled = false;
  290. }
  291. }
  292. private void ultraDateTimeApplyDateFrom_ValueChanged(object sender, EventArgs e)
  293. {
  294. ultraDateTimeApplyDateTo.MinDate = ultraDateTimeApplyDateFrom.DateTime.Date;
  295. }
  296. private void ultraDateTimeApplyDateTo_ValueChanged(object sender, EventArgs e)
  297. {
  298. ultraDateTimeApplyDateFrom.MaxDate = ultraDateTimeApplyDateTo.DateTime.AddDays(1).Date.AddSeconds(-1);
  299. }
  300. }
  301. }