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.Query { public partial class Query_DateRate : Form { AutoSizeFormClass asc = new AutoSizeFormClass(); string querysql = ""; string condition; DataHelper dh = SystemInf.dh; DataTable Dbfind; LogStringBuilder sql = new LogStringBuilder(); public Query_DateRate() { InitializeComponent(); } private void Query_SpecialReport_Load(object sender, EventArgs e) { asc.controllInitializeSize(this); //工单号放大镜配置 pr_code.TableName = " product "; pr_code.SelectField = "pr_code # 产品编号,pr_detail # 产品名称,pr_orispeccode # 型号"; pr_code.FormName = Name; pr_code.SetValueField = new string[] { "pr_code" }; pr_code.Condition = "pr_statuscode='AUDITED'"; pr_code.DbChange += pr_code_DbChange; wc_code.TableName = " workcenter "; wc_code.SelectField = "wc_code # 车间编号,wc_name # 车间名称"; wc_code.FormName = Name; wc_code.SetValueField = new string[] { "wc_code" }; wc_code.Condition = "wc_statuscode='AUDITED'"; wc_code.DbChange += pr_code_DbChange; li_code.TableName = " line "; li_code.SelectField = "li_code # 车间编号,li_name # 车间名称"; li_code.FormName = Name; li_code.SetValueField = new string[] { "li_code" }; li_code.Condition = "li_statuscode='AUDITED'"; li_code.DbChange += pr_code_DbChange; ma_code.TableName = " make left join product on ma_prodcode=pr_code left join workcenter on ma_wccode = wc_code"; ma_code.SelectField = "ma_code # 工单编号,ma_prodcode # 产品编号,pr_orispeccode # 型号,wc_code # 工作中心"; ma_code.FormName = Name; ma_code.SetValueField = new string[] { "ma_code" }; ma_code.Condition = ""; ma_code.DbChange += pr_code_DbChange; ma_kind.TableName = " MAKIND_VIEW "; ma_kind.SelectField = "ma_kind # 工单类型"; ma_kind.FormName = Name; ma_kind.SetValueField = new string[] { "ma_kind" }; ma_kind.Condition = ""; ma_kind.DbChange += pr_code_DbChange; //BeginDate.Value = new DateTime(now.year, Now.Month, now.day); } private void Export_Click(object sender, EventArgs e) { if (wc_code.Text == "") { MessageBox.Show("请输入车间"); return; } if (EndDate.Value < BeginDate.Value) { MessageBox.Show("结束日期不能小于起始日期"); } condition = ""; condition = " sp_date between to_date('" + BeginDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + "', 'yyyy-mm-dd hh24:mi:ss') and to_date('" + EndDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + "', 'yyyy-mm-dd hh24:mi:ss') "; if (wc_code.Text != "") { condition += " and sp_wccode = '" + wc_code.Text + "'"; } if (pr_code.Text != "") { // condition += " and sp_prodcode = '" + pr_code.Text + "'"; condition += " and sp_prodcode in ('" + pr_code.Text.Replace("|", "','") + "')"; } if (ma_code.Text != "") { // condition += " and sp_makecode = '" + ma_code.Text + "'"; condition += " and sp_makecode in ('" + ma_code.Text.Replace("|", "','") + "')"; } if (li_code.Text != "") { // condition += " and sp_linecode = '" + li_code.Text + "'"; condition += " and sp_linecode in ('" + li_code.Text.Replace("|", "','") + "')"; } if (ma_kind.Text != "") { condition += " and ma_kind in ('" + ma_kind.Text.Replace("|", "','") + "')"; } string v_sql = ""; //string v_sql1 = ""; LogicHandler.GetQuerySQL(condition, "直通率", out v_sql); DataTable dt = (DataTable)dh.ExecuteSql(v_sql, "select"); double agsum = 0; double bdsum = 0; double fisum = 0; double rate = 1; for (int i = 0; i < dt.Rows.Count; i++) { agsum = agsum + double.Parse(dt.Rows[i]["AGOKQTY"].ToString()); bdsum = bdsum + double.Parse(dt.Rows[i]["NGQTY"].ToString()); fisum = fisum + double.Parse(dt.Rows[i]["FIQTY"].ToString()); if (dt.Rows[i]["ST_IFCALC"].ToString() == "-1") { rate = rate * (double.Parse(dt.Rows[i]["OKRATE"].ToString()) / 100); } } rate = rate * 100; DataRow dr = dt.NewRow(); dr[3] = "ALL"; dr[7] = agsum; dr[8] = bdsum; dr[9] = fisum; dr[10] = String.Format("{0:F}", rate); dt.Rows.InsertAt(dr, dt.Rows.Count); BaseUtil.FillDgvWithDataTable(Data, dt); } private void pr_code_DbChange(object sender, EventArgs e) { //Dbfind = pr_code.ReturnData; //BaseUtil.SetFormValue(this.Controls, Dbfind); } private void Data_CellContentClick(object sender, DataGridViewCellEventArgs e) { try { if (Data.Columns[e.ColumnIndex].Name == "SNQTY") { Form baditem = new BadItem(ma_code.Text,li_code.Text, pr_code.Text, wc_code.Text, BeginDate.Value.ToString("yyyy-MM-dd HH:mm:ss"), EndDate.Value.ToString("yyyy-MM-dd HH:mm:ss"), Data.Rows[e.RowIndex].Cells["sp_stepcode"].Value.ToString(),ma_kind.Text); baditem.Show(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void Query_DateRate_SizeChanged(object sender, EventArgs e) { asc.controlAutoSize(this); } private void normalButton1_Click(object sender, EventArgs e) { //Data表示导出数据 //Templet表示导出模板 folderBrowserDialog1.Description = "选择导出的路径"; DialogResult result = folderBrowserDialog1.ShowDialog(); if (result == DialogResult.OK) { string FolderPath = folderBrowserDialog1.SelectedPath; ExcelHandler eh = new ExcelHandler(); //DataTable dt = (DataTable)Data.DataSource; //导出Excel的时候返回一个文件名,用户选择是否打开 string filePath = eh.ExportExcel(Data, FolderPath); //用户选择导出之后是否立即打开 MessageBoxButtons messButton = MessageBoxButtons.YesNo; string openFile = MessageBox.Show(this.ParentForm, "是否打开文件" + filePath, "提示", messButton).ToString(); if (openFile == "Yes") { System.Diagnostics.Process.Start(filePath); } } } } }