using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using CoreFS.CA06; using Core.Mes.Client.Comm; using Core.Mes.Client.Comm.Server; using System.Collections; using Core.Mes.Client.Comm.Control; using System.Diagnostics; using System.IO; using Infragistics.Win.UltraWinGrid; using Core.Mes.Client.Comm.Tool; using com.steering.pss.plnsaleord.order.model; namespace Core.StlMes.Client.PlnSaleOrd { public partial class FrmReqApplyInfo : FrmBase { public FrmReqApplyInfo() { this.IsLoadUserView = true; InitializeComponent(); } public FrmReqApplyInfo(OpeBase openBase) { this.ob = ob; InitializeComponent(); } public override void ToolBar_Click(object sender, string ToolbarKey) { base.ToolBar_Click(sender, ToolbarKey); switch (ToolbarKey) { case "Query": DoQuery(); break; case "Confirm": DoConfirm(); break; case "CancelConfirm": CancelConFirm(); break; case "Export": DoExport(); break; case "Close": this.Close(); break; } } private void FrmReqApplyInfo_Load(object sender, EventArgs e) { this.ultraDateTimeApplyDateFrom.Value = DateTime.Now; this.ultraDateTimeApplyDateTo.Value = DateTime.Now; PlanComm.setGridActivation(this.ultraGridReqOrd.DisplayLayout.Bands[0], "CHC", "CONFIRM_WT"); PlanComm.setGridDigitalCol(ultraGridReqOrd.DisplayLayout.Bands[0], 7, 3, "REP_QTY", "REQWEIGHT", "CONFIRM_WT"); DoQuery(); } /// /// 查询 /// private void DoQuery() { try { ArrayList param = new ArrayList(); string strOrderNo = ""; //合同号 string strDateForm = "1000/01/01"; //交货结束日期从,默认最小日期 string strDateTo = "9999/12/31"; //交货结束日期到,默认最大日期 string strChecked = ""; if (this.checkBoxOrderNo.Checked) { //合同号 strOrderNo = this.ultraTextOrderNo.Text.Trim(); } if (this.checkBoxApplyDate.Checked) { //申请日期 strDateForm = this.ultraDateTimeApplyDateFrom.DateTime.ToString("yyyy/MM/dd"); strDateTo = this.ultraDateTimeApplyDateTo.DateTime.ToString("yyyy/MM/dd"); } if (checkBoxInCuldeAll.Checked) { strChecked = "1"; } param.Add(strOrderNo); param.Add(strDateForm); param.Add(strDateTo); param.Add(strChecked); DataTable dt = ServerHelper.GetData("com.steering.pss.plnsaleord.order.CoreReqRequest.getReqOrder", new object[] { param }, this.ob); GridHelper.CopyDataToDatatable(dt, dataTable1, true); } catch (Exception ex) { if (ex is MESException) { } else { MessageBox.Show(ex.Message); } } } /// /// 确认补量申请 /// private void DoConfirm() { try { ArrayList list = new ArrayList(); ultraGridReqOrd.UpdateData(); IQueryable checkRows = ultraGridReqOrd.Rows.AsQueryable().Where("CHC = 'True'"); if (checkRows.Count() == 0) { MessageUtil.ShowTips("未勾选任何行!"); return; } foreach (UltraGridRow uRow in checkRows) { double confirmWt = 0; PlnSaleorderRNumEntity rNumEntity = new PlnSaleorderRNumEntity(); rNumEntity.PlanDealName = UserInfo.GetUserName(); rNumEntity.RepQty = uRow.Cells["REP_QTY"].Value.ToString(); rNumEntity.RNumId = uRow.Cells["R_NUM_ID"].Value.ToString(); rNumEntity.Reqweight = uRow.Cells["REQWEIGHT"].Value.ToString(); double.TryParse(uRow.Cells["CONFIRM_WT"].Value.ToString(), out confirmWt); rNumEntity.ConfirmWt = confirmWt.ToString(); list.Add(rNumEntity); } CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "com.steering.pss.plnsaleord.order.CoreReqRequest"; ccp.MethodName = "setConfirm"; ccp.ServerParams = new object[] { list }; ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnCode != -1) { MessageUtil.ShowTips("确认成功!"); } else { MessageUtil.ShowError("确认失败!" + ccp.ReturnInfo); } } catch (Exception ex) { MessageBox.Show(ex.Message); } DoQuery(); } /// /// 取消确认 /// private void CancelConFirm() { ArrayList list = new ArrayList(); ultraGridReqOrd.UpdateData(); IQueryable checkRows = ultraGridReqOrd.Rows.AsQueryable().Where("CHC = 'True'"); if (checkRows.Count() == 0) { MessageUtil.ShowTips("未勾选任何行!"); return; } foreach (UltraGridRow uRow in checkRows) { list.Add(uRow.Cells["R_NUM_ID"].Value.ToString()); } CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "com.steering.pss.plnsaleord.order.CoreReqRequest"; ccp.MethodName = "canCelConfirm"; ccp.ServerParams = new object[] { list }; ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp == null) { MessageUtil.ShowError("服务端处理失败!"); return; } if (ccp.ReturnCode < 0) { MessageUtil.ShowError("操作失败!\n" + ccp.ReturnInfo); return; } if (ccp.ReturnObject != null) { MessageUtil.ShowTips(ccp.ReturnObject.ToString()); DoQuery(); } } /// /// 导出 /// private void DoExport() { try { int rowCount = this.ultraGridReqOrd.Rows.Count; int colCount = this.ultraGridReqOrd.DisplayLayout.Bands[0].Columns.Count - 10; object[,] arr = new object[rowCount, colCount]; for (int j = 0; j < rowCount; j++) { for (int i = 0; i < colCount; i++) { string output = ultraGridReqOrd.Rows[j].Cells[i].Value.ToString(); if (ultraGridReqOrd.DisplayLayout.Bands[0].Columns[i].Key.Equals("GROUP_ROLL")) { //产线 int plineCode = 0; output = output.Replace("机组", ""); if (int.TryParse(output, out plineCode)) { output = "'" + plineCode.ToString(); } } if (ultraGridReqOrd.DisplayLayout.Bands[0].Columns[i].Key.Equals("STEELNAME")) { //钢级 double grade = 0; if (double.TryParse(output, out grade)) { output = "'" + output; } } if (ultraGridReqOrd.DisplayLayout.Bands[0].Columns[i].Key.Equals("ROLL_MONTH")) { //轧制月份 DateTime dt = new DateTime(); if (DateTime.TryParse(output, out dt)) { output = "'" + dt.ToString("yyyyMM"); } } arr[j, i] = output; } } string path = System.Windows.Forms.Application.StartupPath + "\\model"; string tempExcel = path + "\\FrmSaleOrdmodel.xls"; string outPutExcl = "补量合同" + DateTime.Now.ToString("yyyyMMdd"); if (!System.IO.File.Exists(tempExcel))//检察模板是否存在 { MessageBox.Show(this, "未找到报表模板!"); return; } if (ultraGridReqOrd.Rows.Count == 0) return; if (outPutExcl.Length == 0) outPutExcl = "未命名"; SaveFileDialog dlg = new SaveFileDialog(); dlg.Title = "保存"; dlg.OverwritePrompt = true; dlg.Filter = "Excel文件(*.xls)|*.xls"; dlg.AddExtension = true; dlg.FileName = outPutExcl; if (dlg.ShowDialog() == DialogResult.OK) { outPutExcl = dlg.FileName; WaitFromOpen(); ExcelHelper excelport = new ExcelHelper(tempExcel, outPutExcl); if (excelport.ArrayToExcel(arr, 2, 1, "Sheet")) { WaitFromColse(); if (MessageBox.Show("数据导出成功!\n需要打开所导出文件吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { ProcessStartInfo p = new ProcessStartInfo(outPutExcl); p.WorkingDirectory = Path.GetDirectoryName(outPutExcl); Process.Start(p); } } else { WaitFromColse(); MessageBox.Show("数据导出失败!"); return; } } } catch (Exception ex) { WaitFromColse(); MessageBox.Show(ex.Message); } } /// /// 等待窗口 /// private void WaitFromOpen() { this.Cursor = Cursors.WaitCursor; //控制鼠标的样式为等待 if (Constant.WaitingForm == null) { Constant.WaitingForm = new WaitingForm(); } Constant.WaitingForm.ShowToUser = true; Constant.WaitingForm.Show(); Constant.WaitingForm.Update(); } /// /// 关闭等待 /// private void WaitFromColse() { this.Cursor = Cursors.Default; Constant.WaitingForm.ShowToUser = false; Constant.WaitingForm.Close(); Constant.WaitingForm = null; } private void checkBoxApplyDate_CheckedChanged(object sender, EventArgs e) { if (checkBoxApplyDate.Checked) { this.ultraDateTimeApplyDateFrom.Enabled = true; this.ultraDateTimeApplyDateTo.Enabled = true; } else { this.ultraDateTimeApplyDateFrom.Enabled = false; this.ultraDateTimeApplyDateTo.Enabled = false; } } private void checkBoxOrderNo_CheckedChanged(object sender, EventArgs e) { if (checkBoxOrderNo.Checked) { this.ultraTextOrderNo.Enabled = true; } else { this.ultraTextOrderNo.Enabled = false; } } private void ultraDateTimeApplyDateFrom_ValueChanged(object sender, EventArgs e) { ultraDateTimeApplyDateTo.MinDate = ultraDateTimeApplyDateFrom.DateTime.Date; } private void ultraDateTimeApplyDateTo_ValueChanged(object sender, EventArgs e) { ultraDateTimeApplyDateFrom.MaxDate = ultraDateTimeApplyDateTo.DateTime.AddDays(1).Date.AddSeconds(-1); } private void ultraGridReqOrd_AfterSelectChange(object sender, AfterSelectChangeEventArgs e) { foreach (UltraGridRow uRow in ultraGridReqOrd.Selected.Rows) { if (uRow.GetType() != typeof(Infragistics.Win.UltraWinGrid.UltraGridGroupByRow)) { uRow.Cells["CHC"].Value = true; } } } } }