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 UAS_MES_NEW.DataOperate; using UAS_MES_NEW.Entity; using UAS_MES_NEW.PublicMethod; namespace UAS_MES_NEW.Special { public partial class Special_SmtLocation : Form { DataHelper dh; LogStringBuilder sql = new LogStringBuilder(); DataTable dt = new DataTable(); DataTable dbfind; ExcelHandler eh; DataTable dbbom; public Special_SmtLocation() { InitializeComponent(); } private void Special_BoxSplit_Load(object sender, EventArgs e) { eh = new ExcelHandler(); dh = SystemInf.dh; pr_code.FormName = Name; pr_code.SetValueField = new string[] { "pr_code" }; pr_code.TableName = "product"; pr_code.SelectField = "pr_code # 物料编号,pr_detail # 物料名称,pr_kind # 物料种类,pr_spec # 物料规格"; pr_code.DbChange += Pr_code_DbChange; } private void Pr_code_DbChange(object sender, EventArgs e) { dbfind = pr_code.ReturnData; BaseUtil.SetFormValue(this.Controls, dbfind); } private void normalButton2_Click(object sender, EventArgs e) { DialogResult result = openFileDialog1.ShowDialog(); if (result == DialogResult.OK) { textBox1.Text = openFileDialog1.FileName; } } private void normalButton3_Click(object sender, EventArgs e) { if (pr_code.Text == "" || textBox1.Text == "") { MessageBox.Show("产品编号与座标图地址不可为空"); return; } dt = eh.ImportExcel(textBox1.Text, "test"); DataTable dta = new DataTable(); DataTable dtb = new DataTable(); dta.Columns.Add("序号", typeof(string)); dta.Columns.Add("线别", typeof(string)); dta.Columns.Add("产品编号", typeof(string)); dta.Columns.Add("设备编号", typeof(string)); dta.Columns.Add("站位", typeof(string)); dta.Columns.Add("板面", typeof(string)); dta.Columns.Add("首选料号", typeof(string)); dta.Columns.Add("替代料号", typeof(string)); dta.Columns.Add("单位用量", typeof(int)); dtb.Columns.Add("序号", typeof(string)); dtb.Columns.Add("线别", typeof(string)); dtb.Columns.Add("产品编号", typeof(string)); dtb.Columns.Add("设备编号", typeof(string)); dtb.Columns.Add("站位", typeof(string)); dtb.Columns.Add("板面", typeof(string)); dtb.Columns.Add("首选料号", typeof(string)); dtb.Columns.Add("替代料号", typeof(string)); dtb.Columns.Add("单位用量", typeof(int)); //for (int i = 0; i < dt.Rows.Count; i++) //{ // MessageBox.Show(dt.Rows[i]["RefDes"].ToString()+":"+ dt.Rows[i]["Layer"].ToString()); //} BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt); dbbom = (DataTable)dh.ExecuteSql("select BD_SONCODE, case when SUBSTR(BD_LOCATION,length(BD_LOCATION)) = ',' then SUBSTR(BD_LOCATION,1,LENGTH(BD_LOCATION)-1) else BD_LOCATION end BD_LOCATION from bomdetail@WP where bd_mothercode = '"+pr_code.Text+"' and bd_location is not null and nvl(bd_usestatus,' ') <>'DISABLE'", "select"); for (int i = 0; i < dbbom.Rows.Count; i++) { String[] locationsum = dbbom.Rows[i]["BD_LOCATION"].ToString().Split(','); int A = 0; int B = 0; for (int j = 0; j < locationsum.Length; j++) { String location = locationsum[j]; DataRow[] dra = dt.Select("RefDes = '"+location+ "' and Layer = 'Top'"); DataRow[] drb = dt.Select("RefDes = '" + location + "' and Layer = 'Bottom'"); if (dra.Length > 0) { A++; } if (drb.Length > 0) { B++; } } if (A > 0) { DataRow dr = dta.NewRow(); dr[2] = pr_code.Text; dr[5] = "A"; dr[6] = dbbom.Rows[i]["BD_SONCODE"].ToString(); dr[7] = dbbom.Rows[i]["BD_SONCODE"].ToString(); dr[8] = A; dta.Rows.Add(dr); } if (B > 0) { DataRow dr = dtb.NewRow(); dr[2] = pr_code.Text; dr[5] = "B"; dr[6] = dbbom.Rows[i]["BD_SONCODE"].ToString(); dr[7] = dbbom.Rows[i]["BD_SONCODE"].ToString(); dr[8] = B; dtb.Rows.Add(dr); } } String filepath; DialogResult result = folderBrowserDialog1.ShowDialog(); if (result == DialogResult.OK) { filepath = folderBrowserDialog1.SelectedPath; eh.ExportExcel(dta, filepath,"A"); eh.ExportExcel(dtb, filepath,"B"); MessageBox.Show("OK"); } } } }