123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- 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_MES_NEW.DataOperate;
- using UAS_MES_NEW.Entity;
- using UAS_MES_NEW.PublicForm;
- using UAS_MES_NEW.PublicMethod;
- namespace UAS_MES_NEW.Query
- {
- public partial class Query_OnlineTraceBack : Form
- {
- DataHelper dh;
- LogStringBuilder sql = new LogStringBuilder();
- AutoSizeFormClass asc = new AutoSizeFormClass();
- DataTable ComBoxData = new DataTable();
- BarTender.Application engine;
- Thread InitPrint;
- DataTable Dbfind;
- public Query_OnlineTraceBack()
- {
- InitializeComponent();
- }
- private void Query_OnlineTraceBack_Load(object sender, EventArgs e)
- {
- asc.controllInitializeSize(this);
- dh = SystemInf.dh;
- DataColumn status = new DataColumn("status");
- DataColumn statuscode = new DataColumn("statuscode");
- ComBoxData.Columns.Add(status);
- ComBoxData.Columns.Add(statuscode);
- DataRow dr = ComBoxData.NewRow();
- dr[0] = "全部"; dr[1] = "ALL"; ComBoxData.Rows.Add(dr);
- dr = ComBoxData.NewRow();
- dr[0] = "未生产"; dr[1] = "null"; ComBoxData.Rows.Add(dr);
- dr = ComBoxData.NewRow();
- dr[0] = "已归属"; dr[1] = "0"; ComBoxData.Rows.Add(dr);
- dr = ComBoxData.NewRow();
- dr[0] = "在线"; dr[1] = "1"; ComBoxData.Rows.Add(dr);
- dr = ComBoxData.NewRow();
- dr[0] = "已完工"; dr[1] = "2"; ComBoxData.Rows.Add(dr);
- dr = ComBoxData.NewRow();
- dr[0] = "不良待维修"; dr[1] = "3"; ComBoxData.Rows.Add(dr);
- dr = ComBoxData.NewRow();
- dr[0] = "已报废"; dr[1] = "4"; ComBoxData.Rows.Add(dr);
- ms_status.DataSource = ComBoxData;
- ms_status.DisplayMember = "status";
- ms_status.ValueMember = "statuscode";
- //工单号放大镜配置
- ma_code.TableName = "make left join product on ma_prodcode=pr_code";
- ma_code.SelectField = "ma_code # 工单号,ma_prodcode # 产品编号,ma_qty # 工单数量,pr_detail # 产品名称,ma_softversion # 软件版本";
- ma_code.FormName = Name;
- ma_code.SetValueField = new string[] { "ma_code" };
- ma_code.Condition = "ma_statuscode='STARTED'";
- ma_code.DbChange += Ma_code_DbChange;
- InitPrint = new Thread(InPrint);
- SetLoadingWindow stw = new SetLoadingWindow(InitPrint, "初始化打印程序");
- InitPrint.Start();
- }
- private void InPrint()
- {
- try
- {
- engine = new BarTender.Application();
- //lbl = new ApplicationClass();
- //BaseUtil.WriteLbl();
- }
- catch (Exception ex)
- {
- // OperateResult.AppendText("未正确安装打印软件\n", Color.Red);
- }
- }
- private void Ma_code_DbChange(object sender, EventArgs e)
- {
- Dbfind = ma_code.ReturnData;
- BaseUtil.SetFormValue(this.Controls, Dbfind);
- Query.PerformClick();
- }
- private void Query_OnlineTraceBack_SizeChanged(object sender, EventArgs e)
- {
- asc.controlAutoSize(this);
- }
- private void Query_Click(object sender, EventArgs e)
- {
- if (dh.CheckExist("make", "ma_code='" + ma_code.Text + "'"))
- {
- string condition = BaseUtil.GetScreenSqlCondition(ma_code, ms_stepcode, ms_nextstepcode);
- string statuscode = ms_status.SelectedValue.ToString();
- sql.Clear();
- sql.Append("select distinct sncode SN,ms_linecode 线别,ms_stepcode 当前工序,ms_nextstepcode 下一工序,ms_craftcode 当前途程,makecode ms_makecode, ");
- sql.Append("case when ms_status is null then '未生产' when ms_status=0 then '已归属' when ms_status=1 then '在线' when ms_status=2 ");
- sql.Append(" then '已完工' when ms_status=3 then '不良待维修' when ms_status=4 then '已报废' ");
- sql.Append("else 'null' end 状态 from((select msd_sncode sncode,msd_makecode makecode,msd_type type ");
- sql.Append("from makesnruledetail where msd_makecode='" + ma_code.Text + "') union (select msl_sncode sncode,msl_makecode ");
- sql.Append("makecode,msl_type type from makesnlist where msl_makecode='" + ma_code.Text + "') union (");
- sql.Append("select ms_sncode,ms_makecode,'' type from makeserial where ms_makecode='" + ma_code.Text + "'))");
- sql.Append("A left join makeserial on ms_sncode=sncode and ms_makecode=makecode ");
- sql.Append(condition);
- if (statuscode == "null")
- {
- sql.Append("and ms_status is null");
- }
- else if (statuscode == "ALL")
- {
- }
- else
- {
- sql.Append("and ms_status ='" + statuscode + "'");
- }
- sql.Append(" order by SN ");
- DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- BaseUtil.FillDgvWithDataTable(SnInf, dt);
- Count.Text = SnInf.Rows.Count.ToString();
- ma_qty.Text = dh.getFieldDataByCondition("make", "ma_qty", "ma_code='" + ma_code.Text + "'").ToString();
- }
- else
- {
- MessageBox.Show("工单号" + ma_code.Text + "不存在");
- BaseUtil.CleanDataGridView(SnInf);
- ma_code.Text = "";
- }
- }
- private void ms_status_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (ma_code.Text != "")
- Query.PerformClick();
- }
- 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)SnInf.DataSource;
- //导出Excel的时候返回一个文件名,用户选择是否打开
- string filePath = eh.ExportExcel(dt, FolderPath);
- //用户选择导出之后是否立即打开
- MessageBoxButtons messButton = MessageBoxButtons.YesNo;
- string openFile = MessageBox.Show(this.ParentForm, "是否打开文件"+ filePath, "提示", messButton).ToString();
- if (openFile == "Yes")
- {
- System.Diagnostics.Process.Start(filePath);
- }
- }
-
- }
- private void Query_OnlineTraceBack_FormClosing(object sender, FormClosingEventArgs e)
- {
- if (engine != null)
- engine.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
- dh.Dispose();
- }
- private void checkBox1_CheckedChanged(object sender, EventArgs e)
- {
- int count = SnInf.Rows.Count;
- for (int i = 0; i < count; i++)
- {
- DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)SnInf.Rows[i].Cells["choose1"];
- Boolean flag = Convert.ToBoolean(checkCell.Value);
- if (flag != checkBox1.Checked)
- {
- checkCell.Value = checkBox1.Checked;
- }
- else
- {
- continue;
- }
- }
- }
- private void normalButton2_Click(object sender, EventArgs e)
- {
- BarTender.Format doc2 = engine.Formats.Open(System.AppDomain.CurrentDomain.BaseDirectory + "20X10打印标签.btw");
- if (doc2 == null)
- {
- MessageBox.Show("标签文件打开失败");
- return;
- }
- int count = SnInf.Rows.Count;
- for (int i = 0; i < count; i++)
- {
- DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)SnInf.Rows[i].Cells["choose1"];
- Boolean flag = Convert.ToBoolean(checkCell.Value);
- if (flag == true)
- {
- doc2.SetNamedSubStringValue("SN", SnInf.Rows[i].Cells["SN"].Value.ToString());
- // 同样标签的份数
- doc2.PrintSetup.IdenticalCopiesOfLabel = 1;
- // 序列标签数
- doc2.PrintSetup.NumberSerializedLabels = 1;
- doc2.PrintSetup.Printer = Printer.Text;
- doc2.PrintOut(false, false);
- }
- }
- doc2.Close(BarTender.BtSaveOptions.btDoNotSaveChanges);
- //打印完毕
- engine.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
- }
- private void Setting_Click(object sender, EventArgs e)
- {
- PrintDialog printd = new PrintDialog();
- printd.PrinterSettings.PrinterName = Printer.Text;
- printd.ShowDialog();
- }
- private void ma_code_UserControlTextChanged(object sender, EventArgs e)
- {
- DataTable dt = (DataTable)dh.ExecuteSql(" select mcd_stepcode,mcd_stepname from MAKECRAFTDETAIL where mcd_macode = '" + ma_code.Text+"' order by mcd_detno asc ", "select");
- DataTable dt2 = (DataTable)dh.ExecuteSql(" select mcd_stepcode,mcd_stepname from MAKECRAFTDETAIL where mcd_macode = '" + ma_code.Text + "' order by mcd_detno asc ", "select");
- ms_stepcode.DisplayMember = "mcd_stepname";
- ms_stepcode.ValueMember = "mcd_stepcode";
- ms_stepcode.DataSource = dt;
- ms_stepcode.Text = "";
- ms_nextstepcode.DisplayMember = "mcd_stepname";
- ms_nextstepcode.ValueMember = "mcd_stepcode";
- ms_nextstepcode.DataSource = dt2;
- ms_nextstepcode.Text = "";
- }
- }
- }
|