123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404 |
- 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;
- using System.Collections.Generic;
- namespace UAS_MES.Make
- {
- public partial class Make_ColorBoxLoadPrint : Form
- {
- DataHelper dh;
- DataTable dt;
- LogStringBuilder sql = new LogStringBuilder();
- AutoSizeFormClass asc = new AutoSizeFormClass();
- //保存StepProduct查询出来的数据
- DataTable ListA = new DataTable();
- //制造单号
- string macode;
- //当前工单的序列号
- //string sn_code;
- //当前提示的索引
- int RemainIndex = 0;
- Dictionary<string, string> CheckBarcode = new Dictionary<string, string>();
- List<string> TSN = new List<string>();
- string ErrorMessage = "";
- System.DateTime[] indate;
- string ms_firstsn = "";
- ApplicationClass lbl;
- Document doc;
- Thread InitPrint;
- List<string> CollectData = new List<string>();
- List<string> CollectDataSonCode = new List<string>();
- List<string> SPID = new List<string>();
- public Make_ColorBoxLoadPrint()
- {
- InitializeComponent();
- load.Checked = true;
- }
- private void Make_ColorBoxLoadPrint_Load(object sender, EventArgs e)
- {
- asc.controllInitializeSize(this);
- InitPrint = new Thread(InPrint);
- SetLoadingWindow stw = new SetLoadingWindow(InitPrint, "初始化打印程序");
- BaseUtil.SetFormCenter(stw);
- stw.ShowDialog();
- //工单号放大镜配置
- ma_code.TableName = "make left join product on ma_prodcode=pr_code";
- ma_code.SelectField = "ma_code # 工单号,pr_code # 产品编号,ma_qty # 工单数量,ma_craftcode # 途程编号,pr_detail # 产品名称,ma_bomversion # Bom版本";
- ma_code.FormName = Name;
- ma_code.DBTitle = "工单查询";
- ma_code.SetValueField = new string[] { "ma_code", "pr_code", "ma_qty", "pr_detail", "ma_craftcode", "ma_bomversion" };
- ma_code.Condition = "ma_statuscode='STARTED' order by ma_updatedate desc";
- ma_code.DbChange += Ms_makecode_DbChange;
- Lock.GetMakeCodeCtl(ma_code);
- ma_code.SetLockCheckBox(Lock);
- code.Focus();
- dh = SystemInf.dh;
- StepCount.StepCode = User.CurrentStepCode;
- StepCount.Source = User.UserSourceCode;
- StepCount.LineCode = User.UserLineCode;
- StepCount.Dh = dh;
- StepCount.Start();
- }
- private void Ms_makecode_DbChange(object sender, EventArgs e)
- {
- dt = ma_code.ReturnData;
- 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 (code.Text == "")
- {
- OperateResult.AppendText(">>输入内容不能为空\n", Color.Red);
- return;
- }
- if (SystemInf.UpperCollection)
- {
- code.Text = code.Text.ToUpper();
- }
- if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
- {
- string Msid;
- if (ListA.Rows.Count == 0 && load.Checked)
- {
- if (SystemInf.GetRelation)
- {
- string sn = dh.getFieldDataByCondition("SNRELATION_VIEW", "sr_sn", "content like '%" + code.Text + "%'").ToString();
- int count = int.Parse(dh.getFieldDataByCondition("SNRELATION_VIEW", "count(1) cn", "content like '%" + code.Text + "%'").ToString());
- if (sn == ""|| count > 1)
- {
- MessageBox.Show("SN:" + code.Text + "未找到关联信息");
- return;
- }
- else
- {
- if (SystemInf.UpperCollection)
- code.Text = sn.ToUpper();
- else
- code.Text = sn;
- }
- }
- if (LogicHandler.CheckStepSNAndMacode(ma_code.Text, User.UserSourceCode, code.Text, User.UserCode, out macode, out Msid, out ErrorMessage) || ListA.Rows.Count > 0)
- {
- sql.Clear();
- sql.Append("select ma_code,ms_craftcode,ms_sncode,ma_qty,pr_detail,pr_code,nvl(ms_bomversion,ma_bomversion) ms_bomversion,ms_firstsn from makeserial left join make on ");
- sql.Append("ms_makecode=ma_code left join product on ms_prodcode=pr_code where ms_id='" + Msid + "'");
- DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- if (dt.Rows.Count > 0)
- {
- BaseUtil.SetFormValue(this.Controls, dt);
- ms_firstsn = dt.Rows[0]["ms_firstsn"].ToString();
- Lock.Checked = true;
- LoadCollectNum();
- OperateResult.AppendText(">>获取序列号" + code.Text + "成功\n", Color.Green);
- if (PrintLabel.SelectedValue == null)
- {
- OperateResult.AppendText(">>产品编号:" + pr_code.Text + "未维护彩盒标签\n", Color.Red, code);
- return;
- }
- ms_sncode.Text = code.Text;
- code.Text = "";
- }
- sql.Clear();
- sql.Append("select max(sp_id)sp_id,max(sp_detno)sp_detno,min(sp_ifrepeat)sp_ifrepeat,max(sp_checkbarcode)sp_checkbarcode,min(sp_checksalecode)sp_checksalecode,sp_fsoncode,max(sp_barcoderule)");
- sql.Append("sp_barcoderule,wm_concat(sp_soncode) sp_soncode,max(sp_ifuseregex)sp_ifuseregex,max(sp_ifforsn)");
- sql.Append("sp_ifforsn,max(sp_length)sp_length,max(sp_type)sp_type,replace(wm_concat(sp_prefix),',','|')sp_prefix,max(sp_regex)sp_regex,max(sp_instr)sp_instr");
- sql.Append(",max(pr_detail)pr_detail from stepproduct left join product on pr_code=sp_fsoncode where ");
- sql.Append("sp_bomversion='" + ms_bomversion.Text + "' and sp_craftcode='" + ms_craftcode.Text + "' and sp_stepcode='" + User.CurrentStepCode + "' ");
- sql.Append("And sp_mothercode ='" + pr_code.Text + "' and sp_tracekind=1 and not exists(select 1 from craftmaterial where ");
- sql.Append("cm_sncode in (select '" + ms_firstsn + "' from dual union select sn from makesnrelation where firstsn='" + ms_firstsn + "') and cm_makecode='" + ma_code.Text + "' and cm_soncode=");
- sql.Append("sp_soncode and cm_status=0) group by sp_fsoncode order by SP_DETNO asc");
- ListA = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- //获取对应 产品的机身标的打印模板
- if (ListA.Rows.Count > 0)
- {
- string soncode = ListA.Rows[RemainIndex]["sp_soncode"].ToString();
- string prdetail = ListA.Rows[RemainIndex]["pr_detail"].ToString();
- OperateResult.AppendText("<<请采集" + soncode + "(" + prdetail + ")的物料数据\n", Color.Black);
- code.Clear();
- }
- else
- {
- OperateResult.AppendText(">>当前序列号" + ms_sncode.Text + "不在本道工序,请采集其它序列号\n", Color.Black);
- if (!LogicHandler.SetStepResult(ma_code.Text, User.UserSourceCode, ms_sncode.Text, "上料采集", "上料成功", User.UserCode, out ErrorMessage))
- OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
- else
- {
- //提示正确返回时传递的信息
- if (ErrorMessage.Contains("AFTERSUCCESS"))
- OperateResult.AppendText(">>" + ErrorMessage + "\n");
- OperateResult.AppendText(">>序列号" + ms_sncode.Text + "上料采集完成!\n", Color.Green);
- }
- return;
- }
- }
- else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
- }
- else if (unload.Checked == true)
- {
- if (LogicHandler.CheckStepSNAndMacode(ma_code.Text, User.UserSourceCode, code.Text, User.UserCode, out macode, out Msid, out ErrorMessage))
- {
- dt = (DataTable)dh.ExecuteSql("select ms_firstsn,cm_id,cm_stepcode,ms_makecode,cm_mccode,cm_makecode,cm_craftcode from craftmaterial left join makeserial on cm_makecode=ms_makecode and cm_sncode=ms_sncode where cm_sncode='" + code.Text + "' and cm_makecode='" + macode + "' and cm_materialtype=1", "select");
- if (dt.Rows.Count > 0)
- {
- string ms_macode = dt.Rows[0]["ms_makecode"].ToString();
- ms_firstsn = dt.Rows[0]["ms_firstsn"].ToString();
- string cm_stepcode = dt.Rows[0]["cm_stepcode"].ToString();
- string cm_mccode = dt.Rows[0]["cm_mccode"].ToString();
- string cm_makecode = dt.Rows[0]["cm_makecode"].ToString();
- string cm_craftcode = dt.Rows[0]["cm_craftcode"].ToString();
- sql.Clear();
- sql.Append("update makeserial set ms_nextmacode='' where ms_sncode in(select cm_barcode from craftmaterial where ");
- sql.Append("cm_makecode='" + cm_makecode + "' and cm_sncode='" + code.Text + "' and cm_stepcode='" + cm_stepcode + "' and cm_craftcode='" + cm_craftcode + "' ");
- sql.Append("and cm_materialtype=1 and nvl(cm_status,0) =0) and ms_nextmacode='" + macode + "'");
- dh.ExecuteSql(sql.GetString(), "update");
- //进行下料
- sql.Clear();
- sql.Append("delete from craftmaterial where (cm_sncode in (select sn from makesnrelation where firstsn");
- sql.Append("='" + ms_firstsn + "') or cm_sncode = '" + ms_firstsn + "') and cm_makecode = '" + macode + "' ");
- sql.Append("and cm_status = 0 and cm_stepcode='" + User.CurrentStepCode + "' and cm_materialtype=1");
- dh.ExecuteSql(sql.GetString(), "delete");
- LogicHandler.InsertMakeProcess(macode, code.Text, User.UserSourceCode, "上料采集操作", "下料成功", User.UserCode);
- LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "上料采集", "下料成功", code.Text, "");
- OperateResult.AppendText(">>序列号" + code.Text + "下料成功\n", Color.Green, code);
- }
- else OperateResult.AppendText(">>该序列号未上料,无需下料\n", Color.Red, code);
- }
- else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
- }
- else
- {
- //获取上料需要传递的参数,sp_soncode,sp_id
- string sp_soncode = ListA.Rows[RemainIndex]["sp_soncode"].ToString();
- string sp_fsoncode = ListA.Rows[RemainIndex]["sp_fsoncode"].ToString();
- string sp_prefix = ListA.Rows[RemainIndex]["sp_prefix"].ToString();
- string sp_regex = ListA.Rows[RemainIndex]["sp_regex"].ToString();
- string length = ListA.Rows[RemainIndex]["sp_length"].ToString();
- string sp_id = ListA.Rows[RemainIndex]["sp_id"].ToString();
- string sp_ifrepeat = ListA.Rows[RemainIndex]["sp_ifrepeat"].ToString();
- string sp_ifforsn = ListA.Rows[RemainIndex]["sp_ifforsn"].ToString();
- string sp_barcoderule = ListA.Rows[RemainIndex]["sp_barcoderule"].ToString();
- string sp_checkbarcode = ListA.Rows[RemainIndex]["sp_checkbarcode"].ToString();
- string sp_checksalecode = ListA.Rows[RemainIndex]["sp_checksalecode"].ToString();
- string sp_instr = ListA.Rows[RemainIndex]["sp_instr"].ToString();
- if (LogicHandler.CheckSNBeforeLoad(ma_code.Text, code.Text, sp_fsoncode, sp_soncode, sp_barcoderule, sp_prefix, length, sp_ifrepeat, sp_instr, sp_checksalecode, out ErrorMessage))
- {
- //判断采集的条码和本次采集的也不能重复
- if (CollectData.Contains(code.Text) && sp_ifrepeat != "-1")
- {
- OperateResult.AppendText(">>条码" + code.Text + "已经上料\n", Color.Red, code);
- return;
- }
- TSN.Add(code.Text.Substring(0, code.Text.Length > 40 ? 40 : code.Text.Length));
- if (sp_checkbarcode != "")
- {
- if (CheckBarcode.ContainsKey(sp_checkbarcode))
- {
- if (CheckBarcode[sp_checkbarcode] != code.Text)
- {
- OperateResult.AppendText(">>条码" + code.Text + "需要检查物料,未匹配到之前上料数据\n", Color.Red, code);
- return;
- }
- }
- else
- {
- OperateResult.AppendText(">>条码" + code.Text + "需要检查物料,未匹配到之前上料数据\n", Color.Red, code);
- return;
- }
- }
- if (sp_barcoderule == "BARCODE")
- {
- sp_soncode = ErrorMessage;
- }
- CollectData.Add(code.Text.Substring(0, code.Text.Length > 40 ? 40 : code.Text.Length));
- SPID.Add(sp_id);
- CollectDataSonCode.Add(sp_soncode);
- if (!CheckBarcode.ContainsKey(sp_fsoncode))
- {
- CheckBarcode.Add(sp_fsoncode, code.Text.Substring(0, code.Text.Length > 40 ? 40 : code.Text.Length));
- }
- OperateResult.AppendText(">>物料" + code.Text + "采集成功,条码号" + code.Text + "\n", Color.Green, code);
- RemainIndex = RemainIndex + 1;
- }
- else
- {
- OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
- return;
- }
- code.Clear();
- if (RemainIndex <= ListA.Rows.Count - 1)
- {
- string soncode = ListA.Rows[RemainIndex]["sp_soncode"].ToString();
- string prdetail = ListA.Rows[RemainIndex]["pr_detail"].ToString();
- OperateResult.AppendText("<<请采集" + soncode + "(" + prdetail + ")的物料数据\n", Color.Black);
- }
- if (RemainIndex == ListA.Rows.Count)
- {
- sql.Clear();
- sql.Append("insert into Craftmaterial (cm_id ,cm_makecode,cm_maid,cm_maprodcode, cm_soncode, cm_mscode, cm_sncode, cm_stepcode, cm_stepname,cm_fsoncode,");
- sql.Append("cm_craftcode,cm_craftname,cm_barcode,cm_inqty,cm_indate,cm_inman,cm_linecode,cm_wccode,cm_sourcecode,cm_spid,cm_status,cm_materialtype,cm_firstsn)");
- sql.Append("select Craftmaterial_seq.nextval, ma_code, ma_id, ma_prodcode,:soncode,ms_code,ms_sncode,mcd_stepcode,");
- sql.Append("mcd_stepname,sp_fsoncode,ms_craftcode,ms_craftname,:barcode,1,sysdate,'" + User.UserCode + "','" + User.UserLineCode + "',ma_wccode,");
- sql.Append("'" + User.UserSourceCode + "',:sp_id,0,1,ms_firstsn from make left join makecraftdetail on mcd_macode=ma_code left join stepproduct on sp_stepcode=mcd_stepcode ");
- sql.Append("and sp_craftcode=ma_craftcode and sp_mothercode = ma_prodcode left join makeserial on ms_makecode=ma_code ");
- sql.Append("where ma_code='" + ma_code.Text + "'and sp_id=:sp_id1 and mcd_stepcode = '" + User.CurrentStepCode + "' and ms_sncode='" + ms_sncode.Text + "'");
- dh.BatchInsert(sql.GetString(), new string[] { "soncode", "barcode", "sp_id", "sp_id1" }, CollectDataSonCode.ToArray(), CollectData.ToArray(), SPID.ToArray(), SPID.ToArray());
- //更新半成品SN已被工单使用
- dh.BatchInsert("update makeserial set ms_nextmacode='" + ma_code.Text + "' where ms_id=(select max(ms_id) from makeserial where ms_sncode=:sncode and ms_nextmacode is null and ms_makecode<>'" + ma_code.Text + "')", new string[] { "sncode" }, TSN.ToArray());
- try
- {
- string Log = "";
- for (int i = 0; i < CollectDataSonCode.Count; i++)
- {
- Log += CollectDataSonCode.ToArray()[i] + " " + CollectData.ToArray()[i] + " " + SPID.ToArray()[i];
- }
- LogManager.DoLog(Log);
- }
- catch (Exception)
- {
- }
- OperateResult.AppendText(">>序列号" + ms_sncode.Text + "对应的物料已经采集完成\n", Color.Green);
- LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "上料采集", "上料成功", ms_sncode.Text, "");
- RemainIndex = 0;
- TSN.Clear();
- SPID.Clear();
- CollectData.Clear();
- CheckBarcode.Clear();
- CollectDataSonCode.Clear();
- BaseUtil.CleanDataTable(ListA);
- if (LogicHandler.SetTestResult(ma_code.Text, User.UserSourceCode, ms_sncode.Text, "彩盒上料打印", "彩盒上料成功", User.UserCode, out ErrorMessage))
- {
- //提示正确返回时传递的信息
- if (ErrorMessage.Contains("AFTERSUCCESS"))
- OperateResult.AppendText(">>" + ErrorMessage + "\n");
- mcd_okqty.Text = int.Parse(mcd_okqty.Text) + 1 + "";
- code.Clear();
- LoadCollectNum();
- BaseUtil.CleanDataTableData(ListA);
- }
- else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
- // doc = lbl.Documents.Open(PrintLabel.Text);
- if (!Print.CodeSoft(Tag.ToString(), ref lbl, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), Printer.Text, ms_sncode.Text, int.Parse(PrintNum.Text), ma_code.Text, pr_code.Text, "彩盒标", "0", out ErrorMessage))
- {
- OperateResult.AppendText(ErrorMessage + "\n", Color.Red);
- }
- return;
- }
- }
- }
- else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
- }
- }
- private void Make_ColorBoxLoadPrint_SizeChanged(object sender, EventArgs e)
- {
- asc.controlAutoSize(this);
- }
- 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";
- }
- private void LoadCollectNum()
- {
- dt = (DataTable)dh.ExecuteSql("select ma_qty-mcd_inqty mcd_remainqty 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);
- }
- private void Make_ColorBoxLoadPrint_FormClosing(object sender, FormClosingEventArgs e)
- {
- BaseUtil.ClosePrint(lbl);
- }
- private void ClearSn_code_Click(object sender, EventArgs e)
- {
- if (ListA != null)
- BaseUtil.CleanDataTableData(ListA);
- TSN.Clear();
- SPID.Clear();
- CheckBarcode.Clear();
- CollectDataSonCode.Clear();
- CollectData.Clear();
- RemainIndex = 0;
- code.Clear();
- OperateResult.AppendText(">>请重新采集序列号\n");
- }
- 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);
- }
- }
- private void code_KeyDown(object sender, KeyEventArgs e)
- {
- }
- }
- }
|