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 System.Collections; using Infragistics.Win.UltraWinGrid; using Core.Mes.Client.Common; using System.Diagnostics; using System.IO; namespace Core.LgMes.Client.lgIntegrationQuery { public partial class FrmWeightCheck : FrmBase { public FrmWeightCheck() { InitializeComponent(); } private void FrmWeightCheck_Load(object sender, EventArgs e) { } public override void ToolBar_Click(object sender, string ToolbarKey) { switch (ToolbarKey) { case "Query": { proc_Query(); break; } case "CheckIn": { CheckIn("审核通过"); break; } case " ": { CheckIn("审核不通过"); break; } case "CheckCancel": { CheckCancel(); break; } case "Export": { ExportExcel(); break; } case "Close": { this.Close(); break; } } } public void proc_Query() { this.dataSet1.Tables[0].Clear(); if (uldtEndTime.DateTime.Date.Subtract(uldtBeginTime.DateTime.Date).Days > 180) { MessageBox.Show("查询时间不可超过6个月。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (uldtBeginTime.DateTime > uldtEndTime.DateTime) { MessageBox.Show("查询起始时间不能大于结束时间!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } try { string strErr = ""; this.dataSet1.Tables[0].Clear(); string DelToDateFrom = Convert.ToString(this.uldtBeginTime.DateTime.ToString("yyyyMMdd")); string DelToDateTo = Convert.ToString(this.uldtEndTime.DateTime.ToString("yyyyMMdd")); DateTime t1 = DateTime.ParseExact(DelToDateFrom, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture); DateTime t2 = DateTime.ParseExact(DelToDateTo, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture); System.TimeSpan t3 = t2 - t1; //两个时间相减 。默认得到的是 两个时间之间的天数 得到:365.00:00:00 double getDay = t3.TotalDays; //将这个天数转换成天数, 返回值是double类型的(其实不必转换,因为t3默认就是天数) 得到: if (getDay > 30) { MessageBox.Show("查询周期过长,是否继续查询?"); } string sqlCondition = "1=1 AND (T1.MATRL_END_CAUSE_CD IS NULL OR T1.MATRL_END_CAUSE_CD != '4')"; sqlCondition += " AND T1.SLAB_CUT_DTIME BETWEEN '" + DelToDateFrom + "000000" + "' AND '" + DelToDateTo + "235959" + "'"; if (this.chk_CCMID.Checked) { sqlCondition += " AND T1.PROC_CD LIKE 'J" + this.cmb_CCMID.Text.Trim() + "%'"; } sqlCondition += " ORDER BY T1.SLAB_CUT_DTIME "; ArrayList arry1 = new ArrayList(); ArrayList sqlList = new ArrayList(); arry1.Add("FrmWeightCheckInfo.Select");//此ID为XML文件ID sqlList.Add(sqlCondition); //调用服务端方法 CoreClientParam CCP_JJBQuery = new CoreClientParam(); DataTable dt = new DataTable(); CCP_JJBQuery.ServerName = "Core.LgMes.Server.Common.ComDBQuery"; CCP_JJBQuery.MethodName = "doQuery"; CCP_JJBQuery.ServerParams = new object[] { arry1, sqlList }; CCP_JJBQuery.SourceDataTable = dt;//dataSet1.Tables[0]; this.ExecuteQueryToDataTable(CCP_JJBQuery, CoreInvokeType.Internal); if (string.IsNullOrEmpty(strErr)) { 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 (this.dataTable1.Columns.Contains(dt.Columns[jCol].ColumnName)) { dr[dt.Columns[jCol].ColumnName] = dt.Rows[iRow][jCol]; } } this.dataTable1.Rows.Add(dr); } } } //this.dataSet1.data = dt; //System.Diagnostics.Debug.WriteLine(this.dataSet1.Tables[0].ToString()); foreach (UltraGridRow ugr in this.ultraGrid1.Rows) { if (ugr.Cells["CHECK_STATE"].Text.Trim() == "审核不通过") ugr.CellAppearance.BackColor = Color.OrangeRed; else if (ugr.Cells["CHECK_STATE"].Text.Trim() == "审核通过") ugr.CellAppearance.BackColor = Color.Lime; } this.ultraGrid1.DisplayLayout.Bands[0].Columns["Choose"].CellActivation = Activation.AllowEdit; this.ultraGrid1.DisplayLayout.Bands[0].Columns["BILLETNO"].CellActivation = Activation.ActivateOnly; this.ultraGrid1.DisplayLayout.Bands[0].Columns["BilletType"].CellActivation = Activation.ActivateOnly; this.ultraGrid1.DisplayLayout.Bands[0].Columns["THICK"].CellActivation = Activation.ActivateOnly; this.ultraGrid1.DisplayLayout.Bands[0].Columns["WIDTH"].CellActivation = Activation.ActivateOnly; this.ultraGrid1.DisplayLayout.Bands[0].Columns["LENGTH"].CellActivation = Activation.ActivateOnly; this.ultraGrid1.DisplayLayout.Bands[0].Columns["QUANTITY"].CellActivation = Activation.ActivateOnly; this.ultraGrid1.DisplayLayout.Bands[0].Columns["WEIGHT"].CellActivation = Activation.ActivateOnly; this.ultraGrid1.DisplayLayout.Bands[0].Columns["THEORYWEIGHT"].CellActivation = Activation.ActivateOnly; this.ultraGrid1.DisplayLayout.Bands[0].Columns["GOWHERE"].CellActivation = Activation.ActivateOnly; this.ultraGrid1.DisplayLayout.Bands[0].Columns["Check_State"].CellActivation = Activation.ActivateOnly; } catch (Exception EX) { MessageBox.Show(EX.ToString()); } } private void CheckIn(string state) { string strErr = "", sqlNew = ""; int i = 0; if (this.ultraGrid1.Rows.Count == 0) { MessageBox.Show("请查询数据后再进行审核"); return; } foreach (UltraGridRow ugr in this.ultraGrid1.Rows) { if (ugr.Cells["Choose"].Text.Trim().ToUpper() != "TRUE") continue; string billetno = ugr.Cells["BILLETNO"].Text.Trim();//坯号 string billettype = ugr.Cells["BilletType"].Text.Trim();//坯料类型 string MeterWeight = ugr.Cells["WeightPerMeter"].Text.Trim();//米单重 string thick = ugr.Cells["THICK"].Text.Trim();//厚度 string width = ugr.Cells["WIDTH"].Text.Trim();//宽度 string length = ugr.Cells["LENGTH"].Text.Trim();//长度 string quantity = ugr.Cells["QUANTITY"].Text.Trim();//支数 string weight = ugr.Cells["WEIGHT"].Text.Trim();//磅重 string theoryweight = ugr.Cells["THEORYWEIGHT"].Text.Trim();//理重 string optman = this.UserInfo.GetUserName(); string gowhere = ugr.Cells["GOWHERE"].Text.Trim();//去向 string ccmid = ugr.Cells["CCMID"].Text.Trim();//铸机号 if (!string.IsNullOrEmpty(ugr.Cells["Check_State"].Text.Trim()) && ugr.Cells["Check_State"].Text.Trim() != "未审核") { MessageBox.Show(billetno + "已审核,如需重新审核,请先撤销审核"); return; } else { sqlNew = "select * from CXUSER.JOB_WEIGHTCHECK_INFO@XGCX where billetno = '" + billetno + "'"; CoreClientParam CCP_Query = new CoreClientParam(); DataTable dt = new DataTable(); CCP_Query.ServerName = "Core.LgMes.Server.Common.ComDBExecute"; // 考虑原来返回数据形式性能太低,修改为前端传sql,服务端直接执行模式 2013.11.18 CCP_Query.MethodName = "doSimpleQuery"; CCP_Query.ServerParams = new object[] { sqlNew }; CCP_Query.SourceDataTable = dt; ExecuteQueryToDataTable(CCP_Query, CoreInvokeType.Internal); if (dt != null && dt.Rows.Count > 0) { MessageBox.Show(billetno + "已审核,如需重新审核,请先撤销审核"); proc_Query(); return; } } string sql = "insert into CXUSER.JOB_WEIGHTCHECK_INFO@XGCX(BILLETNO,THICK,WIDTH,LENGTH,THEORYWEIGHT,WEIGHT,CHECK_STATE,CHECK_TIME,CHECK_MAN," + "QUANTITY,METER_WEIGHT,BILLETTYPE,SLAB_SOURCE,GOWHERE,CCMID) " + " values('" + billetno + "','" + thick + "','" + width + "','" + length + "','" + theoryweight + "','" + weight + "','" + state + "',sysdate,'" + optman + "','" + quantity + "','" + MeterWeight + "','" + billettype + "' , '" + "第二炼钢厂" + "','" + gowhere + "','" + ccmid + "')"; CommonClientToServer cctos = new CommonClientToServer(); cctos.ob = this.ob; cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBExecute", "ExcuteNoParameter", sql, out strErr); if (!string.IsNullOrEmpty(strErr)) { MessageBox.Show("坯料:" + billetno + "审核失败。" + strErr); proc_Query(); return; } i++; } MessageBox.Show(i + "条坯料全部审核成功。"); proc_Query(); } private void CheckCancel() { string strErr = "", sqlNew = ""; int i = 0; if (this.ultraGrid1.Rows.Count == 0) { MessageBox.Show("请查询数据后再进行撤销审核"); return; } foreach (UltraGridRow ugr in this.ultraGrid1.Rows) { if (ugr.Cells["Choose"].Text.Trim().ToUpper() != "TRUE") continue; string billetno = ugr.Cells["BILLETNO"].Text.Trim();//坯号 string billettype = ugr.Cells["BilletType"].Text.Trim();//坯料类型 if (string.IsNullOrEmpty(ugr.Cells["Check_State"].Text.Trim())) { MessageBox.Show(billetno + "已撤销,无需再次撤销"); return; } /*if (ugr.Cells["STORAGESTATUS"].Text.Trim() == "已出库") { MessageBox.Show(billetno + "已出库,不允许撤销审核,请联系一钢质检"); return; } else { if (billettype == "板坯") { sqlNew = "select STORAGESTATUS from cxuser.kcg_stufflist@xgcx where billetno = '" + billetno + "'"; } else { sqlNew = "select MAX(STORAGESTATUS) from cxuser.kcg_stufflist@xgcx where heatno = '" + billetno + "' group by heatno"; } CallingMessage par1 = new CallingMessage(); par1.ServerName = "lgIntegrationQuery"; par1.AssemblyName = "Core.LgMes.Server.lgIntegrationQuery"; par1.ClassName = "Core.LgMes.Server.lgIntegrationQuery.LgGeneralInfo"; par1.MethodName = "ExecuteCommand_Return"; par1.args = new object[] { sqlNew }; DataSet ds1 = (DataSet)ClientCommon._RemotingHelp.ExecuteMethod(par1, out strErr); String flag = ds1.Tables[0].Rows[0][0].ToString(); if (flag == "2") { MessageBox.Show(billetno + "已出库,不允许撤销审核,请联系一钢质检"); return; } }*/ string sql = "DELETE FROM CXUSER.JOB_WEIGHTCHECK_INFO@XGCX WHERE BILLETNO = '" + billetno + "'"; CommonClientToServer cctos = new CommonClientToServer(); cctos.ob = this.ob; cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBExecute", "ExcuteNoParameter", sql, out strErr); if (!string.IsNullOrEmpty(strErr)) { MessageBox.Show("坯料:" + billetno + "撤销失败。" + strErr); proc_Query(); return; } i++; } MessageBox.Show(i + "条坯料全部撤销成功。"); proc_Query(); } private void ExportExcel() { try { if (this.ultraGrid1.Rows.Count == 0) { MessageBox.Show("请先检索数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string StrfileName = System.Windows.Forms.Application.StartupPath + "\\Report\\过磅数据审核.xls"; this.GridExcelExporter.Export(this.ultraGrid1, StrfileName); ProcessStartInfo p = new ProcessStartInfo(StrfileName); p.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized; p.WorkingDirectory = Path.GetDirectoryName(StrfileName); Process.Start(p); } catch (Exception ex) { MessageBox.Show(ex.Message + "\n处理方法:查看(" + System.Windows.Forms.Application.StartupPath + ")目录下是否有[ Report文件夹 ],如果没有请手动创建!"); } } private void uCkEditorForFilter_CheckedChanged(object sender, EventArgs e) { try { if (uCkEditorForFilter.Checked) { this.ultraGrid1.DisplayLayout.Override.AllowRowFiltering = Infragistics.Win.DefaultableBoolean.True; } else { this.ultraGrid1.DisplayLayout.Bands[0].ColumnFilters.ClearAllFilters(); this.ultraGrid1.DisplayLayout.Override.AllowRowFiltering = Infragistics.Win.DefaultableBoolean.False; } } catch { } } private void chk_CCMID_CheckedChanged(object sender, EventArgs e) { if (chk_CCMID.Checked) cmb_CCMID.Enabled = true; else cmb_CCMID.Enabled = false; } } }