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 System.IO; using System.Diagnostics; using Infragistics.Win.UltraWinGrid; using System.Reflection; //using System.Drawing; //using System.Collections.Generic; //using System.ComponentModel; namespace Core.LZMes.Client.UIB { public partial class UIB030320 : FrmBase { public UIB030320() { InitializeComponent(); } private void UIB030320_Load(object sender, EventArgs e) { this.textProdLn.SelectedIndex = 1;//产线 this.comboShen.SelectedIndex = 0;//审核状态 this.comboSend.SelectedIndex = 1;//发送状态 this.comboBoxLanguage.SelectedIndex = 0;//语种 this.comboBox1.SelectedIndex = 0;//发送异常 this.textInvNO.Text = OperateConditionRecode.ReadCondition("UIB030320_INVNO"); this.textOrd.Text = OperateConditionRecode.ReadCondition("UIB030320_ORD"); this.ultraDateTimeEditor1.Value = DateTime.Now.AddDays(-3); string directoryPath = "C:\\Temp\\ZBS\\"; if (!Directory.Exists(directoryPath))//若不存在,则创建临时文件夹 { Directory.CreateDirectory(directoryPath); } if (Directory.Exists(directoryPath)) { foreach (string f in Directory.GetFileSystemEntries(directoryPath)) { try { if (File.Exists(f)) File.Delete(f); //直接删除其中的文件 } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); continue;//文件正在使用,则跳过该文件 } } } } public override void ToolBar_Click(object sender, string ToolbarKey) { switch (ToolbarKey) { case "Query": this.DoQuery(); break; case "DownLoad": this.DownLoad(); break; case "SendWWW": this.SendWWW(); break; case "DoCheck": this.DoCheck(); break; case "UnDoCheck": this.UnDoCheck(); break; case "DoSave": this.DoSave(); break; case "DoPrint": this.print(); break; } } private void DoQuery() { try { ArrayList al = new ArrayList(); if (this.textProdLn.Text == "热轧") { al.Add("UIB030320_HOST_01.SELECT"); } else if (this.textProdLn.Text == "开平") { al.Add("UIB030320_BANJIA_01.SELECT"); } else if (this.textProdLn.Text == "酸轧") { al.Add("UIB030320_SUAN_01.SELECT"); } else if (this.textProdLn.Text == "连退") { al.Add("UIB030320_LIAN_01.SELECT"); } else if (this.textProdLn.Text == "板加(非)") { al.Add("UIB030320_HOTBJ_01.SELECT"); } else { return; } OperateConditionRecode.WriteCondition("UIB030320_INVNO" , this.textInvNO.Text); OperateConditionRecode.WriteCondition("UIB030320_ORD", this.textOrd.Text); al.Add(this.textOrd.Text); al.Add(this.comboShen.Text); al.Add(this.ultraDateTimeEditor1.DateTime.ToString("yyyyMMdd")); al.Add(this.ultraDateTimeEditor2.DateTime.ToString("yyyyMMdd")); al.Add(this.textCar.Text); al.Add("");//运送指示号 al.Add(this.textInvNO.Text);//明细号 al.Add(this.textStlGrd.Text);//牌号 al.Add(this.comboSend.Text);//是否已发送 al.Add(this.comboSend.Text);//是否已发送 al.Add(this.comboBox1.Text);//是否发送异常 this.dataSet1.Tables[0].Clear(); CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "UIB.COM.ComDBQuery"; ccp.MethodName = "doSimpleQuery"; ccp.ServerParams = new object[] { al }; ccp.SourceDataTable = this.dataSet1.Tables[0]; this.ExecuteQueryToDataTable(ccp, CoreInvokeType.Internal); foreach (UltraGridRow ugr in this.ultraGrid1.Rows) { if (ugr.Cells["CRET_PRINT_TP"].Text == "") { ugr.Appearance.ForeColor = Color.Blue;//字体颜色 } else if (ugr.Cells["SEND_TP"].Text != "Y") { ugr.Appearance.ForeColor = Color.Blue;//字体颜色 } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } } public void DoCheck()//审核 { if (MessageBox.Show("确定审核?", "提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel) return; try { ArrayList al = new ArrayList(); foreach (UltraGridRow ugr in this.ultraGrid1.Rows) { if (Convert.ToBoolean(ugr.Cells["CHK"].Text)) { al.Add(ugr.Cells["CRET_NO"].Text); } } CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "UIB.UIB03.UIB030320"; ccp.MethodName = "ZBSCheckTP"; ccp.ServerParams = new object[] { this.ultraGrid1.Rows[0].Cells["PROD_LINE"].Text//以首行的生产线为当前操作生产线 , al , "Y"//区分审核与取消审核 , this.UserInfo.GetUserName() }; this.ExecuteNonQuery(ccp, CoreInvokeType.Internal); this.DoQuery(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } } public void DoSave()//订单备注 { try { //if (MessageBox.Show("确定修改?", "提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel) // return; //ArrayList al = new ArrayList(); //if (this.ultraGrid1.ActiveRow.Cells["PROD_LINE"].Text.Trim() == "热轧" // || this.ultraGrid1.ActiveRow.Cells["PROD_LINE"].Text.Trim() == "酸轧") //{ // al.Add("UIB030320_01.UPDATE"); //} //else if (this.ultraGrid1.ActiveRow.Cells["PROD_LINE"].Text.Trim() == "板加") //{ // al.Add("UIB030320_02.UPDATE"); //} //al.Add(this.textBoxRMK.Text);//订单备注 //al.Add(this.ultraGrid1.ActiveRow.Cells["ORD_NO"].Text);//合同号 //al.Add(this.ultraGrid1.ActiveRow.Cells["ORD_SEQ"].Text);//订单号 //CoreClientParam ccp = new CoreClientParam(); //ccp.ServerName = "UIB.COM.ComDBSave"; //ccp.MethodName = "doXmlSave"; //ccp.ServerParams = new object[] { al }; //this.ExecuteNonQuery(ccp, CoreInvokeType.Internal); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } } public void UnDoCheck()//取消审核,一次只取消一条记录 { if (MessageBox.Show("确定取消审核?", "提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel) return; try { ArrayList al = new ArrayList(); foreach (UltraGridRow ugr in this.ultraGrid1.Rows) { if (Convert.ToBoolean(ugr.Cells["CHK"].Text)) { al.Add(ugr.Cells["CRET_NO"].Text); } } CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "UIB.UIB03.UIB030320"; ccp.MethodName = "ZBSCheckTP"; ccp.ServerParams = new object[] { this.ultraGrid1.Rows[0].Cells["PROD_LINE"].Text//以首行的生产线为当前操作生产线 , al , "N"//区分审核与取消审核 , this.UserInfo.GetUserName() }; this.ExecuteNonQuery(ccp, CoreInvokeType.Internal); this.DoQuery(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } //try //{ // if (MessageBox.Show("确定取消审核?", "提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel) // return; // if (this.ultraGrid1.ActiveRow == null) return; // if (this.ultraGrid1.ActiveRow.Cells["CRET_PRINT_TP"].Text == "") return; // ArrayList al = new ArrayList(); // al.Add("UIB030320_01.UPDATE"); // al.Add("N"); // al.Add(this.UserInfo.GetUserName()); // al.Add(this.ultraGrid1.ActiveRow.Cells["CRET_NO"].Text); // CoreClientParam ccp = new CoreClientParam(); // ccp.ServerName = "UIB.COM.ComDBSave"; // ccp.MethodName = "doXmlSave"; // ccp.ServerParams = new object[] { al }; // this.ExecuteNonQuery(ccp, CoreInvokeType.Internal); //} //catch (Exception ex) //{ // System.Diagnostics.Debug.WriteLine(ex.ToString()); //} } public void DownLoad()//下载或预览 { try { if (this.ultraGrid1.ActiveRow == null) return; if (this.ultraGrid1.ActiveRow.Cells["CRET_PRINT_TP"].Text.Trim() == "") { MessageBox.Show("未审核的对象" ,"提示"); return; } CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "UIB.UIB03.UIB030320"; ccp.MethodName = "downLoad"; ccp.ServerParams = new object[] { this.ultraGrid1.ActiveRow.Cells["TMPL_NO"].Text.Trim() //模板 ,this.ultraGrid1.ActiveRow.Cells["CRET_NO"].Text.Trim()//质保书号 ,this.ultraGrid1.ActiveRow.Cells["PROD_LINE"].Text.Trim()//产线 ,this.ultraGrid1.ActiveRow.Cells["INV_NO"].Text.Trim()//明细号 // ,this.comboBoxLanguage.Text//语种区分 ,""};//发送时该参数才有值 CoreClientParam cx = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnObject != null && ccp.ReturnCode == 5) { MessageBox.Show(ccp.ReturnObject.ToString(), "提示"); return; } if (ccp.ReturnInfo != null && ccp.ReturnInfo != "") { MessageBox.Show(ccp.ReturnInfo, "提示"); return; } byte[] byData = (byte[])cx.ReturnObject; System.DateTime dt = System.DateTime.Now; string TimeNow = string.Format("{0:yyyyMMddHHmmssffff}", dt); string directoryPath = "C:\\Temp\\ZBS\\"; string sFile = directoryPath + this.ultraGrid1.ActiveRow.Cells["CRET_NO"].Text + "_" + TimeNow + ".xls"; FileStream fs = new FileStream(sFile, FileMode.OpenOrCreate, FileAccess.Write); fs.Write(byData, 0, byData.Length); fs.Close(); ProcessStartInfo p = new ProcessStartInfo(sFile); p.WorkingDirectory = Path.GetDirectoryName(sFile); Process.Start(p); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } //发送到外网 public void SendWWW() { if (MessageBox.Show("确定发送?", "提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel) return; try { foreach (UltraGridRow ugr in this.ultraGrid1.Rows) { if (Convert.ToBoolean(ugr.Cells["CHK"].Text) && ugr.Cells["CRET_PRINT_TP"].Text == "Y") { CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "UIB.UIB03.UIB030320"; ccp.MethodName = "downLoad"; ccp.ServerParams = new object[] {ugr.Cells["TMPL_NO"].Text.Trim() //模板号 ,ugr.Cells["CRET_NO"].Text.Trim()//质保书编号 ,ugr.Cells["PROD_LINE"].Text.Trim()//产线 ,ugr.Cells["INV_NO"].Text.Trim()//明细号 // ,this.comboBoxLanguage.Text ,"SEND"};//表示发送 this.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnObject != null && ccp.ReturnCode == 5) { MessageBox.Show(ccp.ReturnObject.ToString(), "提示"); ArrayList al = new ArrayList(); al.Add("UIB030320_MS_02.UPDATE"); al.Add(ugr.Cells["CRET_NO"].Text.Trim());//质保书编号 ccp.ServerName = "UIB.COM.ComDBSave"; ccp.MethodName = "doXmlSave"; ccp.ServerParams = new object[] { al }; this.ExecuteNonQuery(ccp, CoreInvokeType.Internal); al.Clear(); al.Add("UIB030320_MS_03.UPDATE"); al.Add(ugr.Cells["CRET_NO"].Text.Trim());//质保书编号 ccp.ServerName = "UIB.COM.ComDBSave"; ccp.MethodName = "doXmlSave"; ccp.ServerParams = new object[] { al }; this.ExecuteNonQuery(ccp, CoreInvokeType.Internal); return; } if(ccp.ReturnInfo != null && ccp.ReturnInfo != "") { MessageBox.Show(ccp.ReturnInfo, "提示"); return; } else ugr.Cells["SEND_TP"].Value = "Y"; } } this.DoQuery(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } } public void print()//打印 { try { string directoryPath = "C:\\Temp\\ZBS\\"; int indexFlag = 0; foreach (UltraGridRow ugr in this.ultraGrid1.Rows) { if (Convert.ToBoolean(ugr.Cells["CHK"].Text) && ugr.Cells["CRET_PRINT_TP"].Text == "Y" ) { if ((this.textProdLn.Text == "酸轧" || this.textProdLn.Text == "连退") && ugr.Cells["PRINT_CNT"].Text != "0") { if (MessageBox.Show(ugr.Cells["CRET_NO"].Text + "已经打印过确定打印?", "提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel) return; } indexFlag++; CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "UIB.UIB03.UIB030320"; ccp.MethodName = "downLoad"; ccp.ServerParams = new object[] { ugr.Cells["TMPL_NO"].Text.Trim() //模板 ,ugr.Cells["CRET_NO"].Text.Trim()//质保书号 ,ugr.Cells["PROD_LINE"].Text.Trim()//产线 // ,this.comboBoxLanguage.Text.Trim()//语种区分 ,""};//发送时该参数才有值 CoreClientParam cx = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal); byte[] byData = (byte[])cx.ReturnObject; System.DateTime dt = System.DateTime.Now; string TimeNow = string.Format("{0:yyyyMMddHHmmssffff}", dt); string sFile = directoryPath + ugr.Cells["CRET_NO"].Text + "_" + TimeNow + Convert.ToString(indexFlag) + ".xls"; FileStream fs = new FileStream(sFile, FileMode.OpenOrCreate, FileAccess.Write); fs.Write(byData, 0, byData.Length); fs.Close(); Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application(); Microsoft.Office.Interop.Excel.Workbook workbook = app.Application.Workbooks.Add(sFile); Microsoft.Office.Interop.Excel._Worksheet ws = (Microsoft.Office.Interop.Excel._Worksheet)workbook.Worksheets[1]; ws.PrintOut(1, 1, 1, false, Missing.Value, false, false, Missing.Value);//"HP LaserJet P1505" workbook.Saved = true; workbook.Close(Missing.Value, Missing.Value, Missing.Value); app.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(ws); System.Runtime.InteropServices.Marshal.ReleaseComObject(app); app = null; GC.Collect(); CoreClientParam ccp2 = new CoreClientParam(); ccp2.ServerName = "UIB.UIB03.UIB030320"; ccp2.MethodName = "PrintCnt"; ccp2.ServerParams = new object[] { this.UserInfo.GetUserName().ToString(), ugr.Cells["CRET_NO"].Text.Trim() }; cx = this.ExecuteNonQuery(ccp2, CoreInvokeType.Internal); } }this.DoQuery(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } } private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)//订单备注 { } private object missing = Missing.Value; //private Microsoft.Office.Interop.Excel.Application ExcelRS; //private Microsoft.Office.Interop.Excel.Workbook RSbook; //private Microsoft.Office.Interop.Excel.Worksheet RSsheet; private void button1_Click(object sender, EventArgs e) { } //this.sTREETTableAdapter.Fill(this.dataSet1.she); //string OutFilePath = System.Windows.Forms.Application.StartupPath + @" emp.xls"; //string TemplateFilePath = System.Windows.Forms.Application.StartupPath + @"模版.xls"; //PrintInit(TemplateFilePath, OutFilePath); //public bool PrintInit(string templetFile, string outputFile) //{ // try // { // if (templetFile == null) { MessageBox.Show("Excel模板文件路径不能为空!"); return false;} // if (outputFile == null) // { // MessageBox.Show("输出Excel文件路径不能为空!"); // return false; // } // //把模版文件templetFile拷贝到目输出文件outputFile中,并且目标文件可以改写 // System.IO.File.Copy(templetFile, outputFile, true); // if (this.ExcelRS != null) ExcelRS = null; // //实例化ExcelRS对象 // ExcelRS = new Microsoft.Office.Interop.Excel.ApplicationClass();//打开目标文件 // //outputFile // RSbook = ExcelRS.Workbooks.Open(outputFile, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing); //设置第一个工作溥 // RSsheet = (Microsoft.Office.Interop.Excel.Worksheet)RSbook.Sheets.get_Item(1); //激活当前工作溥 // RSsheet.Activate(); //在当前工作溥写入内容 // for (int i = 0; i < this.dataGridView1.RowCount; i++) // { // RSsheet.Cells[3 + i, 1] = this.dataGridView1[0, i].Value.ToString(); // RSsheet.Cells[3 + i, 2] = this.dataGridView1[1, i].Value.ToString(); // RSsheet.Cells[3 + i, 3] = this.dataGridView1[2, i].Value.ToString(); } //保存目标文件 // RSbook.Save(); //设置DisplayAlerts // ExcelRS.DisplayAlerts = false; // ExcelRS.Visible = true; //ExcelRS.DisplayAlerts = true; //释放对象 // RSsheet = null; // RSbook = null; // ExcelRS = null; //释放内存 // } // catch (Exception ex) // { // MessageBox.Show(ex.ToString()); // return false; // } // return true; //} public void cCollect() { GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); GC.WaitForPendingFinalizers(); } //private void checkBox1_CheckedChanged(object sender, EventArgs e) //{ // foreach (UltraGridRow ugr in this.ultraGrid1.Rows) // { // ugr.Cells["CHK"].Value = this.checkBox1.Checked; // ugr.Update(); // } //} private System.Collections.Hashtable tmphsb = new Hashtable(); string tmpflag = "True"; private void ultraGrid1_AfterHeaderCheckStateChanged(object sender, AfterHeaderCheckStateChangedEventArgs e) { if (e.Column.Key == "CHK") { foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in e.Rows) { if (row.IsFilteredOut) { if (tmpflag == "True" && tmphsb[row.Cells["CRET_NO"].Value.ToString()].ToString() == "False") { row.Cells["CHK"].Value = "False"; } if (tmpflag == "False" && tmphsb[row.Cells["CRET_NO"].Value.ToString()].ToString() == "True") { row.Cells["CHK"].Value = "True"; } } } } } private void ultraGrid1_BeforeHeaderCheckStateChanged(object sender, BeforeHeaderCheckStateChangedEventArgs e) { if (e.Column.Key == "CHK") { if (e.NewCheckState == CheckState.Checked) { tmpflag = "True"; } else { tmpflag = "False"; } tmphsb.Clear(); foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in this.ultraGrid1.Rows) { if(!tmphsb.ContainsKey(row.Cells["CRET_NO"].Value.ToString())) tmphsb.Add(row.Cells["CRET_NO"].Value.ToString(), row.Cells["CHK"].Value.ToString()); } } } } }