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 Core.Mes.Client.Common; using Infragistics.Win.UltraWinGrid; using System.Collections; using Infragistics.Win; using System.Diagnostics; using System.IO; using CoreFS.CA06; using Core.LgMes.Client.Comm; namespace Core.LgMes.Client.lgIntegrationQuery { public partial class FrmCcmWeightReport : frmStyleBase { public FrmCcmWeightReport() { InitializeComponent(); } private UltraGridRow currRow = null; public override void ToolBar_Click(object sender, string ToolbarKey) { switch (ToolbarKey) { case "Query": { proc_Query(); break; } case "Save": { proc_Add("Edit"); proc_Query(); break; } case "Export": { try { if (ultraGrid1.Rows.Count == 0) return; string strFileName = "合金验收记录" + DateTime.Now.ToString("yyyyMMdd"); SaveFileDialog dlg = new SaveFileDialog(); dlg.Title = "保存"; dlg.OverwritePrompt = true; dlg.Filter = "Excel文件(*.xls)|*.xls"; dlg.AddExtension = true; dlg.FileName = strFileName; if (dlg.ShowDialog() == DialogResult.OK) { strFileName = dlg.FileName; ultraGridExcelExporter1.Export(ultraGrid1, strFileName); if (MessageBox.Show("数据导出成功!\r\n需要打开所导出文件吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { ultraGridExcelExporter1.Export(ultraGrid1, strFileName); ProcessStartInfo p = new ProcessStartInfo(strFileName); p.WorkingDirectory = Path.GetDirectoryName(strFileName); Process.Start(p); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } break; } case "Close": { this.Close(); break; } } } public void proc_Query() { if (ultraDateTimeEditor2.DateTime.Date.Subtract(ultraDateTimeEditor1.DateTime.Date).Days > 60) { MessageBox.Show("查询时间不可超过2个月。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (ultraDateTimeEditor1.DateTime.Date > ultraDateTimeEditor2.DateTime.Date) { MessageBox.Show("查询开始日期不能大于结束日期!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } Cursor oldCursor = this.Cursor; this.Cursor = Cursors.WaitCursor; try { this.dataTable1.Clear(); string sqlStr = @"SELECT TO_CHAR(T.OPTDATE, 'YYYY-MM-DD HH24:MI:SS') OPTDATE, DECODE(SUBSTR(T.SHIFTCODE, 1, 1), '1', '早', '2', '中', '3', '晚') SHIFTGROUP, DECODE(SUBSTR(T.SHIFTCODE, 1, 1), '1', '甲', '2', '乙', '3', '丙', '丁') SHIFTCLASS, DECODE(T.STATIONCODE,'01','6#','02','5#','7#') STATIONCODE, T.HEATNO, T.PLANSTEEL, T1.PLAN_LINES FACT_ROUTE, T.BILLETSECTION, T.BILLETSECTION2, NVL(T.PFBALEWGT, 0) - NVL(T.BALELEAVEWGT, 0) JGWGT, T2.WEIGHT, SENDSMPOPTOR1, SENDSMPOPTOR2, SENDSMPOPTOR3, CONFIRMOPTOR FROM (SELECT * FROM STL_CCM_OPTINFO UNION SELECT * FROM J#STL_CCM_OPTINFO) T LEFT JOIN PPC_STEEL_HEAT T1 ON T.HEATNO = T1.HEATNO LEFT JOIN (SELECT SUBSTR(SLAB_NO, 1, 9) || 'A' HEATNO, SUM(NVL(WEIGHT_WGT, SLAB_WGT / 1000)) WEIGHT FROM STL_INCISION_VIEW GROUP BY SUBSTR(SLAB_NO, 1, 9) || 'A') T2 ON T.HEATNO = T2.HEATNO WHERE NVL(T.BALESTARTTIME, T.OPTDATE) BETWEEN TO_DATE('{0}','YYYY-MM-DD HH24:MI:SS') AND TO_DATE('{1}','YYYY-MM-DD HH24:MI:SS') AND DISPOSALTIME = '01' ORDER BY T.STATIONCODE,NVL(T.BALESTARTTIME, T.OPTDATE)"; if (ultraDateTimeEditor1.DateTime.Date > ultraDateTimeEditor2.DateTime.Date) { MessageBox.Show("查询开始日期不能大于结束日期!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string strFrom = ultraDateTimeEditor1.DateTime.ToString("yyyy-MM-dd") + " 00:00:00"; string strTo = ultraDateTimeEditor2.DateTime.ToString("yyyy-MM-dd") + " 23:59:59"; sqlStr = string.Format(sqlStr, strFrom, strTo); //调用服务端方法 CoreClientParam CCP_LgEts = new CoreClientParam(); DataTable dt = new DataTable(); CCP_LgEts.ServerName = "Core.LgMes.Server.Common.ComDBExecute"; CCP_LgEts.MethodName = "doSimpleQuery"; CCP_LgEts.ServerParams = new object[] { sqlStr }; CCP_LgEts.SourceDataTable = dt; this.ExecuteQueryToDataTable(CCP_LgEts, CoreInvokeType.Internal); DataSet ds = new DataSet(); if (dt != null && dt.Rows.Count > 0) { this.dataTable1.Rows.Clear(); DataRow dr; for (int iRow = 0; iRow < dt.Rows.Count; iRow++) { dr = this.dataTable1.NewRow(); for (int jCol = 0; jCol < dt.Columns.Count; jCol++) { if (dt.Columns[jCol].ColumnName == "FACT_ROUTE") { dr[dt.Columns[jCol].ColumnName] = CStaticMethod.analysPlan_Lines(dt.Rows[iRow][jCol].ToString()); } else { dr[dt.Columns[jCol].ColumnName] = dt.Rows[iRow][jCol]; } } this.dataTable1.Rows.Add(dr); } } ultraGrid1.UpdateData(); if (ultraGrid1.Rows.Count > 0) { ultraGrid1.ActiveCell = ultraGrid1.Rows[0].Cells["STATIONCODE"]; ultraGrid1.Rows[0].Cells["STATIONCODE"].Selected = false; } //this.proc_SetUltraGridReadOnly(ultraGrid1); ArrayList alistColumns = new ArrayList(); alistColumns.Add("JGWGT"); alistColumns.Add("WEIGHT"); alistColumns.Add("SENDSMPOPTOR1"); alistColumns.Add("SENDSMPOPTOR2"); alistColumns.Add("SENDSMPOPTOR3"); proc_Statics(ref ultraGrid1, alistColumns, true, " {0:############0.0}"); } catch { } finally { this.Cursor = oldCursor; } } public void proc_Add(string flag) { try { this.ultraGrid1.UpdateData(); if (dataTable1.Rows.Count > 0) { string strErr = ""; string strMess = ""; if (flag == "Add") { ArrayList arry = new ArrayList(); arry.Add("frmAlloy.Insert"); string str1 = ultraGrid1.ActiveRow.Cells["STATIONCODE"].Text; string str2 = ultraGrid1.ActiveRow.Cells["LK"].Text; string str3 = ultraGrid1.ActiveRow.Cells["GGM"].Text; string str4 = ultraGrid1.ActiveRow.Cells["GT"].Text; string str5 = ultraGrid1.ActiveRow.Cells["GM"].Text; string str6 = ultraGrid1.ActiveRow.Cells["ZTJ"].Text; string str7 = ultraGrid1.ActiveRow.Cells["ZTMT"].Text; string str8 = ultraGrid1.ActiveRow.Cells["TT"].Text; string str9 = ultraGrid1.ActiveRow.Cells["JSMK"].Text; string str10 = ultraGrid1.ActiveRow.Cells["ZTGT"].Text; string str11 = ultraGrid1.ActiveRow.Cells["MT"].Text; string str12 = ultraGrid1.ActiveRow.Cells["GTGT"].Text; string str13 = ultraGrid1.ActiveRow.Cells["JLZ"].Text; string str14 = ultraGrid1.ActiveRow.Cells["RHGZJ"].Text; string str15 = ultraGrid1.ActiveRow.Cells["DGYSQ"].Text; string str16 = ultraGrid1.ActiveRow.Cells["HZYSH"].Text; string str17 = this.UserInfo.GetUserName(); arry.Add(str1); arry.Add(str2); arry.Add(str3); arry.Add(str4); arry.Add(str5); arry.Add(str6); arry.Add(str7); arry.Add(str8); arry.Add(str9); arry.Add(str10); arry.Add(str11); arry.Add(str12); arry.Add(str13); arry.Add(str14); arry.Add(str15); arry.Add(str16); arry.Add(str17); CommonClientToServer cctos = new CommonClientToServer(); cctos.ob = this.ob; cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBSave", "doSimpleSave", arry, out strErr); this.proc_setCellReadOnly(currRow, true); currRow = null; } else if (flag == "Edit") { ArrayList arry = new ArrayList(); arry.Add("frmCcmWeight1.Update"); string str1 = ultraGrid1.ActiveRow.Cells["SENDSMPOPTOR1"].Text; string str2 = ultraGrid1.ActiveRow.Cells["SENDSMPOPTOR2"].Text; string str3 = ultraGrid1.ActiveRow.Cells["SENDSMPOPTOR3"].Text; string str4 = ultraGrid1.ActiveRow.Cells["CONFIRMOPTOR"].Text; string str5 = ultraGrid1.ActiveRow.Cells["HEATNO"].Text; arry.Add(str1); arry.Add(str2); arry.Add(str3); arry.Add(str4); arry.Add(str5); CommonClientToServer cctos = new CommonClientToServer(); cctos.ob = this.ob; cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBSave", "doSimpleSave", arry, out strErr); arry.Clear(); arry.Add("frmCcmWeight2.Update"); arry.Add(str1); arry.Add(str2); arry.Add(str3); arry.Add(str4); arry.Add(str5); cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBSave", "doSimpleSave", arry, out strErr); this.proc_setCellReadOnly(currRow, true); currRow = null; } if (strErr == "") { dataTable1.AcceptChanges(); //JJBStaticFunction.SetRowEdit(ultraGrid1); if (!string.IsNullOrEmpty(strMess)) MessageBox.Show(strMess, "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { MessageBox.Show("保存失败!输入信息已经存在或数据无效。", "错误"); } if (ultraGrid1.ActiveCell != null) ultraGrid1.ActiveCell.Activated = false; } } catch (System.Exception ex) { Console.WriteLine(ex.ToString()); } } private void proc_setCellReadOnly(UltraGridRow row, bool bReadOnly) { try { if (row == null) return; if (bReadOnly) { row.Activation = Activation.ActivateOnly; row.CellAppearance.BackColor = Color.White; foreach (Infragistics.Win.UltraWinGrid.UltraGridCell cell in row.Cells) { cell.CancelUpdate(); } } else { row.Activation = Activation.AllowEdit; row.CellAppearance.BackColor = Color.Khaki; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void proc_SetUltraGridReadOnly(Infragistics.Win.UltraWinGrid.UltraGridBase ultGrid) { foreach (UltraGridRow row in ultGrid.Rows) { row.Activation = Activation.ActivateOnly; } } public void proc_Statics(ref UltraGrid ultraGrid, ArrayList alistColumns, bool clearExists, string strFormat) { try { if (alistColumns == null) { return; } UltraGridBand band = ultraGrid.DisplayLayout.Bands[0]; if (clearExists) band.Summaries.Clear(); SummarySettings summary = null; UltraGridColumn cl = null; foreach (UltraGridColumn column in ultraGrid.DisplayLayout.Bands[0].Columns) { if (column.RowLayoutColumnInfo.OriginX == 0) { cl = column; break; } } summary = band.Summaries.Add(SummaryType.Count, cl); summary.SummaryDisplayArea = SummaryDisplayAreas.BottomFixed; summary.SummaryPosition = SummaryPosition.UseSummaryPositionColumn; summary.DisplayFormat = "合计:"; summary.Appearance.TextHAlign = Infragistics.Win.HAlign.Center; summary.Appearance.TextVAlign = Infragistics.Win.VAlign.Middle; summary.Appearance.FontData.Bold = DefaultableBoolean.True; if (string.IsNullOrEmpty(strFormat.Trim())) { strFormat = " {0:############0.00}"; } for (int i = 0; i < alistColumns.Count; i++) { try { summary = band.Summaries.Add(SummaryType.Sum, band.Columns[alistColumns[i].ToString()]); summary.SummaryDisplayArea = SummaryDisplayAreas.BottomFixed; summary.SummaryPosition = SummaryPosition.UseSummaryPositionColumn; summary.DisplayFormat = strFormat; summary.Appearance.TextHAlign = Infragistics.Win.HAlign.Right; summary.Appearance.TextVAlign = Infragistics.Win.VAlign.Middle; summary.Appearance.FontData.Bold = DefaultableBoolean.True; summary.Appearance.ForeColor = Color.DarkBlue; summary.Appearance.BackColor = Color.White; } catch { } } band.Override.SummaryFooterCaptionVisible = Infragistics.Win.DefaultableBoolean.False; } catch { } } private void FrmCcmWeightReport_Load(object sender, EventArgs e) { ultraDateTimeEditor1.DateTime = DateTime.Today; ultraDateTimeEditor2.DateTime = DateTime.Today; } } }