using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading; using System.Windows.Forms; using UAS_LabelMachine.Entity; using UAS_LabelMachine.PublicForm; using UAS_LabelMachine.PublicMethod; namespace UAS_LabelMachine { public partial class ExportExcel : Form { ExcelHandler eh = new ExcelHandler(); DataHelper dh = SystemInf.dh; string inoutno; SetLoadingWindow stw; public ExportExcel(string pi_inoutno) { InitializeComponent(); inoutno = pi_inoutno; } private void Export_Click(object sender, EventArgs e) { ExportFileDialog.Description = "选择导出的路径"; DialogResult result = ExportFileDialog.ShowDialog(); if (result == DialogResult.OK) { Thread thread = new Thread(ExportMethod); stw = new SetLoadingWindow(thread, "正在导出数据"); BaseUtil.SetFormCenter(stw); stw.ShowDialog(); } } private void ExportMethod() { string custcode = dh.getFieldDataByCondition("prodinout", "pi_cardcode", "pi_inoutno='" + inoutno + "'").ToString(); { StringBuilder sql = new StringBuilder(); List conditionbox = new List(); if (!CH_PBCODE.Checked && BoxCode.Checked) { MessageBox.Show("勾选盒号分页,打印内容请勾选盒号"); return; } //if (!CH_SPLITBATCH.Checked && BatchCode.Checked) //{ // MessageBox.Show("勾选扩撒批分页,打印内容请勾选扩撒批号"); // return; //} if ((!CH_SPLITBATCH.Checked || !CH_PBCODE.Checked) && BoxSplit.Checked) { MessageBox.Show("勾选盒号拆批,打印内容请勾选扩撒批号和盒号"); return; } conditionbox.Add(CH_BLUEFILM); conditionbox.Add(CH_PBCODE); conditionbox.Add(CH_REMARK); conditionbox.Add(CH_SPLITBATCH); conditionbox.Add(CH_WATERID); conditionbox.Add(ch_code); conditionbox.Add(CH_YIELD); conditionbox.Add(M_Param1); conditionbox.Add(H_Param1); conditionbox.Add(H_Param2); conditionbox.Add(FirstPage_WID); conditionbox.Add(FirstPage_YIELD); conditionbox.Add(FirstPage_REMARK); string SplitType = ""; if (FixRow.Checked) { SplitType = FixRow.Name; } else if (BatchCode.Checked) { SplitType = BatchCode.Name; } else if (BoxCode.Checked) { SplitType = BoxCode.Name; } else if (BoxSplit.Checked) { SplitType = BoxSplit.Name; } string caption = ""; if (Chinese.Checked) { caption = "es_caption"; dh.ExecuteSql("update prodinout set pi_exporttype='Chinese' where pi_inoutno='" + inoutno + "'", "update"); } else { caption = "es_engcaption es_caption"; dh.ExecuteSql("update prodinout set pi_exporttype='English' where pi_inoutno='" + inoutno + "'", "update"); } if (Mount.Checked) { dh.ExecuteSql("update prodinout set pi_exporttype1='QTY' where pi_inoutno='" + inoutno + "'", "update"); } else { dh.ExecuteSql("update prodinout set pi_exporttype1='Rate' where pi_inoutno='" + inoutno + "'", "update"); } DataTable SQL1_ = (DataTable)dh.ExecuteSql("select es_filed,es_datatype," + caption + ",es_filed1 from CS_EXPORTSETTING where es_type='DataPage' and es_enable=-1 and es_custcode='" + custcode + "' order by es_detno", "select"); //没有置顶客户的取空的 if (SQL1_.Rows.Count == 0) { SQL1_ = (DataTable)dh.ExecuteSql("select es_filed,es_datatype," + caption + ",es_filed1 from CS_EXPORTSETTING where es_type='DataPage' and es_enable=-1 and es_custcode is null order by es_detno", "select"); } string es_field1 = ""; for (int i = 0; i < SQL1_.Rows.Count; i++) { //不是参数的直接拼接 if (SQL1_.Rows[i]["es_datatype"].ToString() != "Param") es_field1 += SQL1_.Rows[i]["es_filed"].ToString() + ","; //是参数的则先判断是否含有内容 else if ( (SQL1_.Rows[i]["es_filed"].ToString().Contains(M_Param1.Text) && M_Param1.Visible == true && M_Param1.Checked) || (SQL1_.Rows[i]["es_filed"].ToString().Contains(M_Param2.Text) && M_Param2.Visible == true && M_Param2.Checked) || (SQL1_.Rows[i]["es_filed"].ToString().Contains(M_Param3.Text) && M_Param3.Visible == true && M_Param3.Checked) || (SQL1_.Rows[i]["es_filed"].ToString().Contains(M_Param4.Text) && M_Param4.Visible == true && M_Param4.Checked) || (SQL1_.Rows[i]["es_filed"].ToString().Contains(H_Param1.Text) && H_Param1.Visible == true && H_Param1.Checked) || (SQL1_.Rows[i]["es_filed"].ToString().Contains(H_Param2.Text) && H_Param2.Visible == true && H_Param2.Checked) || (SQL1_.Rows[i]["es_filed"].ToString().Contains(H_Param3.Text) && H_Param3.Visible == true && H_Param3.Checked) || (SQL1_.Rows[i]["es_filed"].ToString().Contains(H_Param4.Text) && H_Param4.Visible == true && H_Param4.Checked)) { es_field1 += SQL1_.Rows[i]["es_filed"].ToString() + ","; } } //生成导出数据 LogicHandler.GenHFEData(inoutno); //分页信息的DataTable string datasql = ""; LogicHandler.GetDataSQL(inoutno, es_field1.Substring(0, es_field1.Length - 1), Mount.Checked ? "QTY" : "Rate", out datasql); DataTable dt = (DataTable)dh.ExecuteSql(datasql, "select"); for (int i = 0; i < dt.Columns.Count; i++) { for (int j = 0; j < SQL1_.Rows.Count; j++) { if (dt.Columns[i].ColumnName == SQL1_.Rows[j]["es_filed1"].ToString().ToUpper()) { dt.Columns[i].ColumnName = SQL1_.Rows[j]["es_filed1"].ToString(); dt.Columns[i].Caption = SQL1_.Rows[j]["es_caption"].ToString(); } } } //获取首页需要展示的字段 DataTable SQL_ = (DataTable)dh.ExecuteSql("select es_filed," + caption + ",es_filed1 from CS_EXPORTSETTING where es_type='First' and es_enable=-1 and es_custcode='" + custcode + "' order by es_detno", "select"); if (SQL_.Rows.Count == 0) { SQL_ = (DataTable)dh.ExecuteSql("select es_filed," + caption + ",es_filed1 from CS_EXPORTSETTING where es_type='First' and es_enable=-1 and es_custcode is null order by es_detno", "select"); } string es_field = ""; for (int i = 0; i < SQL_.Rows.Count; i++) { es_field += SQL_.Rows[i]["es_filed"].ToString() + ","; } sql.Clear(); //首页信息的DataTable if (BoxCode.Checked) { sql.Append("select " + es_field.Substring(0, es_field.Length - 1) + " from FIRSTPAGE_Box_VIEW where pi_inoutno='" + inoutno + "'"); } else { sql.Append("select " + es_field.Substring(0, es_field.Length - 1) + " from FIRSTPAGE_BATCH_VIEW where pi_inoutno='" + inoutno + "'"); } DataTable dt1 = (DataTable)dh.ExecuteSql(sql.ToString(), "select"); for (int i = 0; i < dt1.Columns.Count; i++) { if (dt1.Columns[i].ColumnName == SQL_.Rows[i]["es_filed1"].ToString().ToUpper()) { dt1.Columns[i].ColumnName = SQL_.Rows[i]["es_filed1"].ToString(); dt1.Columns[i].Caption = SQL_.Rows[i]["es_caption"].ToString(); } } string FilePath = ""; string pi_cardcode = dh.getFieldDataByCondition("prodinout", "pi_cardcode", "pi_inoutno='" + inoutno + "'").ToString(); //晶源客户 if (pi_cardcode == dh.GetConfig("JINGYUAN", "ExportProdExcel").ToString()) { FilePath = eh.JINYUAN(dt1, dt, ExportFileDialog.SelectedPath, inoutno, SplitType, int.Parse(RowNum.Text), conditionbox); } else if (pi_cardcode == dh.GetConfig("LIPUXIN", "ExportProdExcel").ToString()) { FilePath = eh.LIPIUXIN(dt1, dt, ExportFileDialog.SelectedPath, inoutno, SplitType, int.Parse(RowNum.Text), conditionbox); } else { FilePath = eh.ExportExcel_Normal(dt1, dt, ExportFileDialog.SelectedPath, inoutno, SplitType, int.Parse(RowNum.Text), conditionbox); } string close = MessageBox.Show(this.ParentForm, "导出成功,是否打开文件", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString(); if (close.ToString() == "Yes") System.Diagnostics.Process.Start(FilePath); Close(); } } private void ExportExcel_Load(object sender, EventArgs e) { Activate(); LogicHandler.CustInit("0"); StringBuilder sql = new StringBuilder(); sql.Clear(); sql.Append("select distinct replace(cep_name,'(ON)','ON')cep_name,CEP_COLLECTIONTYPE from ProdIODetail left join Product on pd_prodcode = pr_code "); sql.Append("left join CHIP_EDCPARAMS_SPEC on pr_orispeccode=ced_model left join CHIP_EDCPARAMS_SPECDETAIL on ced_id=cesd_cedid "); sql.Append("left join CHIP_EDCPARAMS on CESD_CEPID = CEP_ID where pd_inoutno='" + inoutno + "' and ced_status='-1' and CEP_COLLECTIONTYPE='机测'"); DataTable dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select"); for (int i = 0; i < dt.Rows.Count; i++) { if (i <= 4) { Controls["M_Param" + (i + 1)].Visible = true; ((CheckBox)Controls["M_Param" + (i + 1)]).Checked = true; Controls["M_Param" + (i + 1)].Text = dt.Rows[i]["cep_name"].ToString(); } } sql.Clear(); sql.Append("select distinct replace(cep_name,'(ON)','ON')cep_name,CEP_COLLECTIONTYPE from ProdIODetail left join Product on pd_prodcode = pr_code "); sql.Append("left join CHIP_EDCPARAMS_SPEC on pr_orispeccode=ced_model left join CHIP_EDCPARAMS_SPECDETAIL on ced_id=cesd_cedid "); sql.Append("left join CHIP_EDCPARAMS on CESD_CEPID = CEP_ID where pd_inoutno='" + inoutno + "' and ced_status='-1' and CEP_COLLECTIONTYPE='手测'"); dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select"); for (int i = 0; i < dt.Rows.Count; i++) { if (i <= 4) { Controls["H_Param" + (i + 1)].Visible = true; ((CheckBox)Controls["H_Param" + (i + 1)]).Checked = true; Controls["H_Param" + (i + 1)].Text = dt.Rows[i]["cep_name"].ToString(); } } } private void ExportSetting_Click(object sender, EventArgs e) { ExportColumns ex = new ExportColumns(inoutno); ex.WindowState = FormWindowState.Maximized; ex.ShowDialog(); } private void groupBox1_Paint(object sender, PaintEventArgs e) { e.Graphics.Clear(this.BackColor); } private void BatchCode_CheckedChanged(object sender, EventArgs e) { RadioButton box = (RadioButton)sender; if (box.Checked) { switch (box.Name) { case "BatchCode": CH_SPLITBATCH.Checked = true; break; case "BoxCode": CH_PBCODE.Checked = true; break; case "FixRow": break; case "BoxSplit": CH_SPLITBATCH.Checked = true; CH_PBCODE.Checked = true; break; default: break; } } } } }