123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398 |
- using System;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using UAS_MES.DataOperate;
- using UAS_MES.PublicMethod;
- using UAS_MES.Entity;
- using LabelManager2;
- using System.Threading;
- using UAS_MES.PublicForm;
- namespace UAS_MES.Make
- {
- public partial class Make_ColorBoxLabelPrint : Form
- {
- DataHelper dh;
- DataTable dt;
- Document doc;
- LogStringBuilder sql = new LogStringBuilder();
- AutoSizeFormClass asc = new AutoSizeFormClass();
- System.DateTime[] indate;
- //保存StepProduct查询出来的数据
- DataTable ListA = new DataTable();
- //保存make left join makecraftdetail left join product的数据
- // DataTable ListB;
- //保存ProductLabel数据
- DataTable ListC;
- //工序编号
- string stepcode;
- //下一工序编号
- string nextstepcode;
- //工艺路线编号
- string craftcode;
- //制造单号
- string macode;
- //当前提示的索引
- int RemainIndex = 0;
- //保存TSN编号
- string ms_id = null;
- string PR_CHECKCARTONW = "0";
- bool pr_change = false;
- Thread InitPrint;
- ApplicationClass lbl;
- DataTable Dbfind;
- public Make_ColorBoxLabelPrint()
- {
- InitializeComponent();
- }
- private void Make_ColorBoxLabelPrint_Load(object sender, EventArgs e)
- {
- sncode.Focus();
- asc.controllInitializeSize(this);
- InitPrint = new Thread(InPrint);
- SetLoadingWindow stw = new SetLoadingWindow(InitPrint, "初始化打印程序");
- BaseUtil.SetFormCenter(stw);
- stw.ShowDialog();
- //设置锁定工单
- LockMakeCode.GetMakeCodeCtl(ma_code);
- ma_code.SetLockCheckBox(LockMakeCode);
- //工单号放大镜配置
- ma_code.TableName = "make left join product on ma_prodcode=pr_code";
- ma_code.SelectField = "ma_code # 工单号,pr_code # 产品编号,pr_detail # 产品名称";
- ma_code.FormName = Name;
- ma_code.SetValueField = new string[] { "ma_code", "pr_code", "pr_detail" };
- ma_code.Condition = "ma_statuscode='STARTED'";
- ma_code.DbChange += Ma_code_DbChange;
- OperateResult.AppendText(">>请输入TSN\n", Color.Black);
- dh = SystemInf.dh;
- StepCount.StepCode = User.CurrentStepCode;
- StepCount.Source = User.UserSourceCode;
- StepCount.LineCode = User.UserLineCode;
- StepCount.Dh = dh;
- StepCount.Start();
- }
- private void Ma_code_DbChange(object sender, EventArgs e)
- {
- Dbfind = ma_code.ReturnData;
- BaseUtil.SetFormValue(this.Controls, Dbfind);
- //获取工单的其他信息
- sql.Clear();
- sql.Append("select ma_code,nvl(mcd_okqty,0) mcd_okqty,ma_prodcode as pr_code ,pr_detail,");
- sql.Append("pr_spec,ma_qty - nvl(mcd_inqty, 0) mcd_remainqty from make left join makecraftdetail on ");
- sql.Append("mcd_maid=ma_id left join product on pr_code=ma_prodcode where ma_code='" + ma_code.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
- dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- if (dt.Rows.Count > 0)
- {
- BaseUtil.SetFormValue(this.Controls, dt);
- }
- }
- private void InPrint()
- {
- try
- {
- lbl = new ApplicationClass();
- BaseUtil.WriteLbl();
- }
- catch (Exception ex)
- {
- OperateResult.AppendText("未正确安装CodeSoft软件\n", Color.Red);
- }
- }
- private void sn_code_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- if (CheckTSN.Checked == true && ms_id == null)
- {
- if (sncode.Text == "")
- {
- OperateResult.AppendText(">>TSN不能为空\n", Color.Red);
- OperateResult.AppendText(">>请输入TSN\n", Color.Black);
- return;
- }
- OperateResult.AppendText(">>" + sncode.Text + "\n", Color.Black);
- sql.Clear();
- sql.Append("select max(ms_id) ms_id from makeserial where ms_code = '" + sncode.Text + "'");
- dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- if (dt.Rows[0][0].ToString() != "")
- {
- ms_id = dt.Rows[0][0].ToString();
- sncode.Focus();
- OperateResult.AppendText(">>请输入SN\n", Color.Black, sncode);
- return;
- }
- else
- {
- OperateResult.AppendText(">>TSN" + sncode.Text + "错误,不存在\n", Color.Red, sncode);
- OperateResult.AppendText(">>请输入TSN\n", Color.Black);
- return;
- }
- }
- if (sncode.Text == "")
- {
- OperateResult.AppendText(">>序列号不能为空\n", Color.Red);
- return;
- }
- OperateResult.AppendText(">>" + sncode.Text + "\n", Color.Black);
- if (CheckTSN.Checked == true && ms_id != null)
- {
- sql.Clear();
- sql.Append("select ms_id from makeserial where ms_id='" + ms_id + "' and ms_sncode = '"+sncode.Text+"'");
- dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- if (dt.Rows.Count > 0)
- {
- OperateResult.AppendText(">>TSN和SN一致\n", Color.Green);
- }
- else
- {
- OperateResult.AppendText(">>TSN和SN不一致\n", Color.Red, sncode);
- OperateResult.AppendText(">>请输入TSN\n", Color.Black);
- ms_id = null;
- return;
- }
- }
- string oMsID;
- string ErrorMessage;
- string oMakeCode;
- if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
- {
- //判断界面工单是否为空时的序列号是否自动归属工单
- string oStatus = "";
- //是否提示过工单切换框,检测前执行
- bool NoteAlready = LogicHandler.CheckDiffMakeCodeBeforeStepCheck(sncode.Text, ma_code.Text, NoteForChange.Checked, out oMakeCode, out ErrorMessage);
- if (!NoteAlready)
- {
- OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sncode);
- return;
- }
- if (ma_code.Text != oMakeCode && oMakeCode != null)
- {
- dt = (DataTable)dh.ExecuteSql("select ma_code,ma_prodcode,ma_softversion,ma_salecode,pr_detail,nvl(pr_sendchecktype,'LineCode')pr_sendchecktype,ma_qty from make left join product on ma_prodcode=pr_code where ma_code='" + oMakeCode + "'", "select");
- if (dt.Rows.Count > 0)
- {
- BaseUtil.SetFormValue(this.Controls, dt);
- LockMakeCode.Checked = true;
- }
- }
- // 获取工单归属工单下一工序是否正确
- if (LogicHandler.CheckStepSNAndMacode(ma_code.Text, User.UserSourceCode, sncode.Text, User.UserCode, out oMakeCode, out oMsID, out ErrorMessage))
- {
- //获取工单的其他信息
- sql.Clear();
- sql.Append("select ma_code,nvl(ma_unlimitin,0)ma_unlimitin,pr_code,pr_detail,pr_spec from ");
- sql.Append("make left join product on pr_code=ma_prodcode where ma_code='" + oMakeCode + "'");
- dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- if (dt.Rows.Count > 0)
- {
- PR_CHECKCARTONW = dh.getFieldDataByCondition("craftdetail left join craft on cr_id=cd_crid left join makeserial on ms_craftcode =cr_code and cr_prodcode = ms_prodcode", "nvl(cd_ifweigh,'0') cd_ifweigh", "ms_sncode='" + sncode.Text + "' and ms_makecode='" + oMakeCode + "' and cd_stepcode = '" + User.CurrentStepCode + "'").ToString();
- if (PR_CHECKCARTONW != "0")
- {
- OperateResult.AppendText(">>彩盒" + sncode.Text + "当前处于称重工序,无法在此界面采集,需去彩盒称重界面进行采集\n", Color.Black, sncode);
- return;
- }
- BaseUtil.SetFormValue(this.Controls, dt);
- LockMakeCode.Checked = true;
- //提示用户“<<工单号:取ma_makecode”
- OperateResult.AppendText("<<工单号:" + ma_code.Text + "\n", Color.Black);
- //提示用户“<< 序列号:XXXX”
- OperateResult.AppendText("<<序列号:" + sncode.Text + "\n", Color.Black);
- if (pr_change)
- {
- String dialog = MessageBox.Show("是否使用当前标签模板", "提示", MessageBoxButtons.OKCancel).ToString();
- if (dialog != "OK")
- {
- OperateResult.AppendText(">>请重新选择标签模板\n", Color.Green);
- return;
- }
- else pr_change = false;
- }
- }
- else
- {
- OperateResult.AppendText(">>无序列号" + sncode.Text + "对应工单信息\n", Color.Red, sncode);
- sncode.Focus();
- return;
- }
- string result = "";
- if (int.Parse(mcd_remainqty.Text) <= 0 && dt.Rows[0]["ma_unlimitin"].ToString() == "0")
- {
- macode = ma_code.Text;
- ErrorMessage = "工单" + macode + "打印结束\n>请输入SN";
- OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Green);
- sncode.Focus();
- }
- else
- {
- //所选标签不为空
- if (PrintLabel.SelectedValue != null)
- {
- //如果打印张数为空,返回
- if (PrintNum.Text == "" || int.Parse(PrintNum.Text) == 0)
- {
- OperateResult.AppendText(">>打印张数不可空或者为0\n", Color.Red, sncode);
- //清空输入框的值,聚焦
- sncode.Focus();
- //提示用户“>>请输入SN”
- OperateResult.AppendText(">>请输入SN\n", Color.Black);
- return;
- }
- //更新至下一步工序
- if (LogicHandler.SetStepResult(oMakeCode, User.UserSourceCode, sncode.Text, "彩盒打印", "彩盒打印成功", User.UserCode, out ErrorMessage))
- {
- //提示正确返回时传递的信息
- if (ErrorMessage.Contains("AFTERSUCCESS"))
- OperateResult.AppendText(">>" + ErrorMessage + "\n");
- // doc = lbl.Documents.Open(PrintLabel.Text);
- if (Print.CodeSoft(Tag.ToString(), ref lbl, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), Printer.Text, sncode.Text, int.Parse(PrintNum.Text), oMakeCode, pr_code.Text, "彩盒标", "0", out ErrorMessage))
- {
- //提示用户打印成功
- OperateResult.AppendText(">>序列号:" + sncode.Text + "打印结束\n", Color.Green);
- }
- else
- {
- OperateResult.AppendText(ErrorMessage + "\n", Color.Red);
- }
- if (CollectRemark.Checked && Remark.Text != "")
- {
- LogicHandler.CollectRemarkInf(sncode.Text, "", "", oMakeCode, pr_code.Text, Remark.Text);
- }
- LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "彩盒打印", "彩盒打印成功", sncode.Text, "");
- //刷新打印数量和剩余数量
- dt = (DataTable)dh.ExecuteSql("select ma_qty - nvl(mcd_inqty, 0) mcd_remainqty,mcd_okqty from make left join makecraftdetail on mcd_macode=ma_code where ma_code='" + ma_code.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'", "select");
- BaseUtil.SetFormValue(Controls, dt);
- sncode.Text = "";
- ms_id = null;
- sncode.Focus();
- }
- else
- {
- OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sncode);
- ms_id = null;
- sncode.Focus();
- }
- }
- else
- {
- OperateResult.AppendText(">>产品编号:" + pr_code.Text + "未维护彩盒标签\n", Color.Red, sncode);
- return;
- }
- if (CheckTSN.Checked == true)
- {
- OperateResult.AppendText(">>请输入TSN\n", Color.Black);
- ms_id = null;
- }
- else
- OperateResult.AppendText(">>请输入SN\n", Color.Black);
- }
- }
- else
- {
- OperateResult.AppendText(ErrorMessage + "\n", Color.Red, sncode);
- if (CheckTSN.Checked == true)
- {
- OperateResult.AppendText(">>请输入TSN\n", Color.Black);
- ms_id = null;
- }
- else
- OperateResult.AppendText(">>请输入SN\n", Color.Black);
- }
- }
- else
- {
- OperateResult.AppendText(ErrorMessage + "\n", Color.Red, sncode);
- if (CheckTSN.Checked == true)
- {
- OperateResult.AppendText(">>请输入TSN\n", Color.Black);
- ms_id = null;
- }
- else
- OperateResult.AppendText(">>请输入SN\n", Color.Black);
- }
- }
- }
- //根据产品编号获取打印模板
- private void pr_code_TextChanged(object sender, EventArgs e)
- {
- DataTable _dt = (DataTable)dh.ExecuteSql("select la_id,la_url,la_isdefault from label where la_prodcode='" + pr_code.Text + "' and la_templatetype='彩盒标' and la_statuscode='AUDITED' order by la_isdefault", "select");
- PrintLabel.DataSource = _dt;
- PrintLabel.DisplayMember = "la_url";
- PrintLabel.ValueMember = "la_id";
- pr_change = true;
- }
- private void Make_ColorBoxLabelPrint_Activated(object sender, EventArgs e)
- {
- sncode.Focus();
- }
- private void Make_ColorBoxLabelPrint_FormClosing(object sender, FormClosingEventArgs e)
- {
- BaseUtil.ClosePrint(lbl);
- }
- private void Make_ColorBoxLabelPrint_SizeChanged(object sender, EventArgs e)
- {
- asc.controlAutoSize(this);
- }
- private void ma_code_UserControlTextChanged(object sender, EventArgs e)
- {
- if (ma_code.Text.Length > 4)
- {
- //获取工单的其他信息
- sql.Clear();
- sql.Append("select ma_code,nvl(mcd_okqty,0) mcd_okqty,ma_prodcode as pr_code ,pr_detail,");
- sql.Append("pr_spec,ma_qty - nvl(mcd_inqty, 0) mcd_remainqty from make left join makecraftdetail on ");
- sql.Append("mcd_maid=ma_id left join product on pr_code=ma_prodcode where ma_code='" + ma_code.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
- DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- if (dt.Rows.Count > 0)
- {
- BaseUtil.SetFormValue(this.Controls, dt);
- }
- else
- {
- sncode.Text = "";
- }
- }
- }
- private void CheckTSN_CheckedChanged(object sender, EventArgs e)
- {
- if (CheckTSN.Checked == true)
- {
- ms_id = null;
- OperateResult.AppendText(">>切换至检查TSN\n", Color.Green);
- OperateResult.AppendText(">>请输入TSN\n", Color.Black, sncode);
- sncode.Focus();
- }
- else
- {
- ms_id = null;
- OperateResult.AppendText(">>切换至不检查TSN\n", Color.Green);
- OperateResult.AppendText(">>请输入SN\n", Color.Black, sncode);
- sncode.Focus();
- }
- }
- private void PrintLabel_SelectedValueChanged(object sender, EventArgs e)
- {
- if (PrintLabel.SelectedValue != null && PrintLabel.SelectedValue.ToString() != "System.Data.DataRowView")
- {
- string PrintNums = dh.getFieldDataByCondition("label", "la_printnos", "la_id='" + PrintLabel.SelectedValue.ToString() + "'").ToString();
- PrintNum.Text = (PrintNums == "" ? "1" : PrintNums);
- }
- }
- }
- }
|