| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505 |
- using LabelManager2;
- using System;
- using System.Data;
- using System.Text;
- using System.Windows.Forms;
- using UAS_MES.DataOperate;
- using UAS_MES.Entity;
- using UAS_MES.PublicMethod;
- using System.Drawing;
- using System.Threading;
- using UAS_MES.PublicForm;
- using System.IO.Ports;
- using System.IO;
- using System.Text.RegularExpressions;
- namespace UAS_MES.Make
- {
- public partial class Make_PackageCollectionWeigh : Form
- {
- DataHelper dh;
- DataTable dt;
- LogStringBuilder sql = new LogStringBuilder();
- AutoSizeFormClass asc = new AutoSizeFormClass();
- ApplicationClass lbl;
- Thread thread;
- DataTable Dbfind;
- string ErrorMessage = "";
- string oMakeCode = "";
- string oMsID = "";
- //称量的标准重量
- int Weight;
- //最大重量
- int MaxWeight;
- //最小重量
- int MinWeight;
- //创建串口实例
- SerialPort serialPort1 = new SerialPort();
- //true的时候表示从串口读取数据
- bool GetData = true;
- System.DateTime[] indate;
- public Make_PackageCollectionWeigh()
- {
- InitializeComponent();
- }
- //创建打印进程
- private void NewPrint()
- {
- try
- {
- lbl = new ApplicationClass();
- BaseUtil.WriteLbl(lbl);
- }
- catch (Exception ex)
- {
- OperateResult.AppendText("未正确安装CodeSoft软件\n", Color.Red);
- }
- }
- private void 包装采集_Load(object sender, EventArgs e)
- {
- pa_outboxcode.ShowClickIcon = false;
- ComList.Text = BaseUtil.GetCacheData("PortName").ToString();
- Baurate.Text = BaseUtil.GetCacheData("BaudRate").ToString();
- //设置DbFind的必须的数据
- PrintNum.Value = 1;
- asc.controllInitializeSize(this);
- thread = new Thread(NewPrint);
- SetLoadingWindow stw = new SetLoadingWindow(thread, "初始化打印程序");
- BaseUtil.SetFormCenter(stw);
- stw.ShowDialog();
- dh = new DataHelper();
- thread = new Thread(getSerialData);
- try
- {
- GetData = true;
- serialPort1.PortName = ComList.Text;
- serialPort1.BaudRate = int.Parse(Baurate.Text);
- serialPort1.Open();
- thread.Start();
- }
- catch (Exception mes)
- {
- if (Baurate.Text == "" || ComList.Text == "")
- OperateResult.AppendText(">>请先在电子秤调试界面维护波特率和串口\n", Color.Red);
- else
- OperateResult.AppendText(">>" + mes.Message + "\n", Color.Red);
- }
- }
- private void getSerialData()
- {
- if (serialPort1.IsOpen)
- {
- if (!SystemInf.OpenPort.Contains(serialPort1.PortName))
- {
- SystemInf.OpenPort.Add(serialPort1.PortName);
- try
- {
- while (GetData)
- {
- try
- {
- weight.Text = Regex.Replace(serialPort1.ReadLine(), "\\D+", "");
- if (pr_cartonunit.Text == "kg")
- weight.Text = (float.Parse(weight.Text) / 1000).ToString();
- }
- catch (Exception)
- {
- GetData = false;
- }
- }
- }
- catch (IOException ex) { MessageBox.Show(ex.Message); }
- }
- else
- MessageBox.Show("端口已被占用,请关闭其他窗口");
- }
- }
- private void 包装采集_SizeChanged(object sender, EventArgs e)
- {
- asc.controlAutoSize(this);
- }
- private void 包装采集_Activated(object sender, EventArgs e)
- {
- pa_outboxcode.Focus();
- }
- //刷新表单的数据的数据
- private void LoadData()
- {
- //加载表单数据
- string Err = "";
- if (pa_outboxcode.Text != "")
- {
- sql.Clear();
- sql.Append("select pa_outboxcode,pr_code,pa_status,pr_packrule,pr_detail,pa_packageqty,pr_outboxinnerqty,pa_standardqty,pa_currentqty,pr_cartonminw, ");
- sql.Append("pr_cartonmaxw,pr_cartonunit,pr_cartongw from package left join product on pa_prodcode=pr_code where pa_outboxcode='" + pa_outboxcode.Text + "'");
- Err = "箱号";
- }
- else
- {
- sql.Clear();
- sql.Append("select ms_makecode,pr_cartonunit,pa_status,pr_packrule,pr_code,pr_detail,pr_outboxinnerqty,pa_standardqty,pa_packageqty,pa_currentqty,");
- sql.Append("pa_outboxcode,pr_cartonminw,pr_cartonmaxw,pr_cartongw from makeserial left join product on ms_prodcode=pr_code left ");
- sql.Append("join packagedetail on pd_barcode=ms_sncode left join package on pa_id =pd_paid where ms_sncode='" + sn_code.Text + "'");
- Err = "序列号";
- }
- dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- if (dt.Rows.Count > 0)
- {
- if (pr_code.Text != "")
- {
- dt.Columns.Remove(dt.Columns["pa_standardqty"]);
- }
- //重量的临时变量
- string _weight = dt.Rows[0]["pr_cartongw"].ToString();
- string _maxweight = dt.Rows[0]["pr_cartonmaxw"].ToString();
- string _minweight = dt.Rows[0]["pr_cartonminw"].ToString();
- //赋值重量单位
- Weight = int.Parse(_weight == "" ? "0" : _weight);
- MaxWeight = int.Parse(_maxweight == "" ? "0" : _maxweight);
- MinWeight = int.Parse(_minweight == "" ? "0" : _minweight);
- BaseUtil.SetFormValue(this.Controls, dt);
- if (Weight - MinWeight == MaxWeight - Weight)
- pr_cartonboxgw.Text = Weight + "±" + (MaxWeight - Weight);
- else
- pr_cartonboxgw.Text = MinWeight + "-" + MaxWeight;
- }
- else OperateResult.AppendText(">>" + Err + "不存在\n", Color.Red);
- }
- private void LoadGridData()
- {
- //加载Grid数据
- dt = (DataTable)dh.ExecuteSql("select pa_outboxcode,pd_barcode,pd_innerqty,pa_indate from packageDetail left join package on pa_id=pd_paid where pa_outboxcode='" + pa_outboxcode.Text + "'", "select");
- BaseUtil.FillDgvWithDataTable(PackageDetail, dt);
- //更新界面的采集数量
- pa_currentqty.Text = dh.getFieldDataByCondition("package", "pa_currentqty", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString();
- }
- private void InsertDetail()
- {
- if (int.Parse(pa_currentqty.Text == "" ? "0" : pa_currentqty.Text) < int.Parse(pr_outboxinnerqty.Text))
- {
- sql.Clear();
- sql.Append("insert into packagedetail(pd_id,pd_paid,pd_outboxcode,pd_innerqty,pd_barcode) ");
- sql.Append("select packagedetail_seq.nextval,pa_id,pa_outboxcode,pa_totalqty,'" + sn_code.Text + "' from package where pa_outboxcode='" + pa_outboxcode.Text + "'");
- dh.ExecuteSql(sql.GetString(), "insert");
- dh.UpdateByCondition("Package", "pa_packageqty=pa_packageqty+1,pa_currentqty=pa_currentqty+1", "pa_outboxcode='" + pa_outboxcode.Text + "'");
- dh.UpdateByCondition("makeserial", "ms_outboxcode='" + pa_outboxcode.Text + "'", "ms_id='" + oMsID + "'");
- LoadCheckQTY();
- if (LogicHandler.SetStepResult(ms_makecode.Text, User.UserSourceCode, sn_code.Text, "包装采集", "装箱成功", User.UserCode, out ErrorMessage))
- {
- OperateResult.AppendText(">>序列号" + sn_code.Text + "采集成功!\n", Color.Green);
- //满箱更新状态为1
- if (int.Parse(pa_currentqty.Text == "" ? "0" : pa_currentqty.Text) + 1 == int.Parse(pr_outboxinnerqty.Text))
- {
- //检查重量合格
- if (float.Parse(weight.Text) > MinWeight && float.Parse(weight.Text) < MaxWeight)
- {
- dh.UpdateByCondition("package", "pa_status=1", "pa_outboxcode='" + pa_outboxcode.Text + "'");
- if (AutoPrint.Checked)
- Print_Click(new object(), new EventArgs());
- }
- else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "重量不符合标准重量\n", Color.Red);
- }
- LoadGridData();
- sn_code.Clear();
- }
- }
- else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "已采集满\n", Color.Red);
- }
- private void Print_Click(object sender, EventArgs e)
- {
- if (PrintLabel.Items.Count != 0)
- {
- if (dh.getFieldDataByCondition("package", "pa_status", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() == "1")
- {
- dh.ExecuteSql("update package set pa_printcount=pa_printcount+1 where pa_outboxcode='" + pa_outboxcode.Text + "'", "update");
- OperateResult.AppendText(">>开始打印箱号" + pa_outboxcode.Text + "\n", Color.Green);
- Print.CodeSoft(lbl, PrintLabel.Text.Split(':')[1], PrintLabel.SelectedValue.ToString(), PrintList.Text, pa_outboxcode.Text, int.Parse(PrintNum.Text), indate[PrintLabel.SelectedIndex]);
- }
- else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "尚未封箱,请封箱后执行打印\n", Color.Red);
- }
- else OperateResult.AppendText(">>产品" + pr_code.Text + "未维护打印标签\n", Color.Red);
- }
- //加载工单信息和装箱明细信息
- private void pa_code_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- LoadData();
- LoadGridData();
- }
- }
- //输入序列号的回车事件
- private void barcode_KeyDown(object sender, KeyEventArgs e)
- {
- //当用户输入回车键的时候
- if (e.KeyCode == Keys.Enter)
- {
- if (LogicHandler.CheckStepSNAndMacode("", User.UserSourceCode, sn_code.Text, User.UserCode, out oMakeCode, out oMsID, out ErrorMessage))
- {
- if (pa_outboxcode.Text == "")
- {
- if (dh.getFieldDataByCondition("makeserial", "ms_outboxcode", "ms_id='" + oMsID + "'").ToString() != "")
- {
- LoadData();
- LoadGridData();
- }
- else
- {
- LoadData();
- pa_outboxcode.GeneratePaCode_Click(new object(), new EventArgs());
- }
- }
- //按工单核对装箱
- switch (pr_packrule.Text)
- {
- case "M":
- if (dh.getFieldDataByCondition("makeserial", "ms_makecode", "ms_id='" + oMsID + "'").ToString() != ms_makecode.Text)
- {
- OperateResult.AppendText(">>序列号" + sn_code.Text + "所属工单和当前箱号工单不相等\n", Color.Red, sn_code);
- return;
- }
- break;
- case "S":
- if (dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode.Text + "'"))
- {
- sql.Clear();
- sql.Append("select 1 from package left join make on pa_salecode=ma_salecode left join makeserial ");
- sql.Append("on ma_code=ms_makecode where pa_outboxcode='" + pa_outboxcode.Text + "' and ms_id='" + oMsID + "'");
- DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- if (dt.Rows.Count == 0)
- {
- OperateResult.AppendText(">>序列号" + sn_code.Text + "所属订单号和当前箱号订单不相等\n", Color.Red, sn_code);
- return;
- }
- }
- break;
- case "":
- if (dh.getFieldDataByCondition("makeserial", "ms_prodcode", "ms_id='" + oMsID + "'").ToString() != pr_code.Text)
- {
- OperateResult.AppendText(">>序列号" + sn_code.Text + "对应物料和该箱所装物料不同\n", Color.Red, sn_code);
- return;
- }
- break;
- default:
- break;
- }
- //判断箱内总数必须大于0
- if (pr_outboxinnerqty.Text == "" || pr_outboxinnerqty.Text == "0")
- {
- OperateResult.AppendText(">>箱内容量必须大于0\n", Color.Red);
- return;
- }
- //如果未勾选了取消录入
- if (!Cancel.Checked)
- {
- //判断序列号是否已经装箱
- if (dh.getFieldDataByCondition("makeserial", "ms_outboxcode", "ms_id='" + oMsID + "'").ToString() != "")
- {
- OperateResult.AppendText(">>序列号" + sn_code.Text + "已经装箱!\n", Color.Red, sn_code);
- }
- else
- {
- //满箱之后采集下一个之前自动清除内容,生成新的箱号
- if ((AutoGenBoxCode.Checked && pa_currentqty.Text != "" && pr_outboxinnerqty.Text == pa_currentqty.Text) || pa_status.Text == "1")
- {
- pa_currentqty.Text = "";
- pa_outboxcode.Text = "";
- pa_status.Text = "0";
- BaseUtil.CleanDGVData(PackageDetail);
- pa_outboxcode.GeneratePaCode_Click(new object(), new EventArgs());
- }
- //箱号不存在的情况
- if (!dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode.Text + "'"))
- {
- //插入Package主表箱号信息
- sql.Clear();
- sql.Append("insert into package (pa_id,pa_outboxcode,pa_packageqty,pa_totalqty,pa_status,pa_indate,pa_makecode,pa_prodcode,pa_salecode,");
- sql.Append("pa_custcode,pa_type,pa_packtype) select package_seq.nextval,'" + pa_outboxcode.Text + "',0," + pr_outboxinnerqty.Text + ",0,");
- sql.Append("sysdate,'" + ms_makecode.Text + "', ma_prodcode,ma_salecode,ma_custcode,1,'" + pr_packrule.Text + "' from make where ma_code = '" + ms_makecode.Text + "'");
- dh.ExecuteSql(sql.GetString(), "insert");
- OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "采集成功!\n", Color.Green);
- InsertDetail();
- }
- else
- {
- if (dh.getRowCount("makeserial", "ms_sncode='" + sn_code.Text + "'") > 0)
- InsertDetail();
- else
- OperateResult.AppendText(">>序列号" + sn_code.Text + "不存在\n", Color.Red, sn_code);
- }
- }
- }
- //勾选了取消箱号先验证箱号存不存在,存在的话移除掉,重新加载一次数据
- else
- {
- if (dh.getFieldDataByCondition("package", "pa_status", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() != "1")
- {
- string outboxcode = dh.getFieldDataByCondition("makeserial", "ms_outboxcode", "ms_id='" + oMsID + "'").ToString();
- if (outboxcode != "")
- {
- if (outboxcode == pa_outboxcode.Text)
- {
- //删除明细行的数据
- dh.ExecuteSql("delete from packagedetail where pd_barcode='" + sn_code.Text + "' and pd_paid=(select pa_id from package where pa_outboxcode='" + pa_outboxcode.Text + "')", "delete");
- //更新已装数
- dh.UpdateByCondition("Package", "pa_packageqty=pa_packageqty-1,pa_currentqty=pa_currentqty-1", "pa_outboxcode='" + pa_outboxcode.Text + "'");
- //清除序列号箱号
- dh.UpdateByCondition("makeserial", "ms_outboxcode=''", "ms_id='" + oMsID + "'");
- OperateResult.AppendText(">>已从该箱中移除序列号" + sn_code.Text + "\n", Color.Green, sn_code);
- LoadGridData();
- }
- else OperateResult.AppendText(">>序列号" + sn_code.Text + "不在箱" + pa_outboxcode.Text + "内\n", Color.Red);
- }
- else OperateResult.AppendText(">>序列号" + sn_code.Text + "尚未装箱\n", Color.Red);
- }
- else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "已经封箱,不允许取消采集\n", Color.Red);
- }
- }
- else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
- }
- }
- private void Clean_Click(object sender, EventArgs e)
- {
- OperateResult.Clear();
- }
- private void pr_code_TextChanged(object sender, EventArgs e)
- {
- pa_outboxcode.MakeCode = ms_makecode.Text;
- pa_outboxcode.ProdCode = pr_code.Text;
- pa_outboxcode.Caller = "PACKAGE";
- dt = (DataTable)dh.ExecuteSql("select pl_labelcode||':'||pl_labelname pl_laname,pl_labelname,pl_labelcode,pl_labelurl,pl_indate from productlabel where pl_prodcode='" + pr_code.Text + "' order by pl_isdefault desc ", "select");
- PrintLabel.DataSource = dt;
- PrintLabel.DisplayMember = "pl_laname";
- PrintLabel.ValueMember = "pl_labelcode";
- ftpOperater ftp = new ftpOperater();
- indate = new System.DateTime[dt.Rows.Count];
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- BaseUtil.GetPrintLabel(dt.Rows[i]["pl_labelname"].ToString(), dt.Rows[i]["pl_labelurl"].ToString(), dt.Rows[i]["pl_indate"].ToString());
- indate[i] = Convert.ToDateTime(dt.Rows[i]["pl_indate"].ToString());
- }
- }
- private void 包装采集_FormClosing(object sender, FormClosingEventArgs e)
- {
- BaseUtil.ClosePrint(lbl);
- if (serialPort1.IsOpen)
- {
- GetData = false;
- serialPort1.Close();
- SystemInf.OpenPort.Remove(serialPort1.PortName);
- thread.Interrupt();
- }
- dh.Dispose();
- }
- private void Packing_Click(object sender, EventArgs e)
- {
- if (dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode.Text + "' and pa_status<>1"))
- {
- dh.UpdateByCondition("package", "pa_status=1,pa_totalqty=pa_currentqty,pa_packageqty=pa_currentqty", "pa_outboxcode='" + pa_outboxcode.Text + "'");
- pa_status.Text = "1";
- OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "封箱成功\n", Color.Green);
- }
- else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "错误或者已封箱\n", Color.Red);
- }
- private void SendCheck_Click(object sender, EventArgs e)
- {
- sql.Clear();
- sql.Append("update oqcbatch set ob_status='UNCHECK' where ob_checkno ='" + ob_checkno.Text + "'");
- dh.ExecuteSql(sql.GetString(), "select");
- ob_nowcheckqty.Text = "";
- ob_batchqty.Text = "";
- ob_nowcheckqty.ForeColor = Color.Black;
- SendCheck.Enabled = false;
- OperateResult.AppendText(">>批次" + ob_checkno.Text + "送检成功\n", Color.Green);
- LogicHandler.InsertMakeProcess(sn_code.Text, oMakeCode, User.UserSourceCode, "手动送检", "手动送检成功", User.UserCode);
- //记录操作日志
- LogicHandler.DoCommandLog(User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "手动送检", "手动送检成功", "", ob_checkno.Text);
- ob_checkno.Text = "";
- }
- bool AutoCut;
- private void LoadCheckQTY()
- {
- sql.Clear();
- string condition = "";
- int nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
- int batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
- if (nowcheckqty + 1 == batchqty && AutoCut)
- {
- condition = "and ob_status='UNCHECK' and ob_checkno='" + ob_checkno.Text + "'";
- }
- else
- {
- condition = "and ob_status='ENTERING' ";
- }
- sql.Append("select ob_batchqty,ob_nowcheckqty,ob_checkno from oqcbatch where ");
- sql.Append("ob_linecode='" + User.UserLineCode + "' and ob_prodcode='" + pr_code.Text + "' and ");
- sql.Append("ob_stepcode='" + User.CurrentStepCode + "' " + condition);
- DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- if (dt.Rows.Count > 0)
- {
- ob_batchqty.Text = dt.Rows[0]["ob_batchqty"].ToString();
- ob_nowcheckqty.Text = dt.Rows[0]["ob_nowcheckqty"].ToString();
- ob_checkno.Text = dt.Rows[0]["ob_checkno"].ToString();
- nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
- batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
- if (nowcheckqty == batchqty)
- {
- ob_nowcheckqty.ForeColor = Color.Red;
- OperateResult.AppendText(">>当前采集数量已达到送检数量\n", Color.Red);
- }
- }
- else
- {
- ob_batchqty.Text = "";
- ob_nowcheckqty.Text = "";
- ob_checkno.Text = "";
- SendCheck.Enabled = false;
- }
- if (ob_batchqty.Text != "")
- {
- SendCheck.Enabled = true;
- }
- else
- {
- SendCheck.Enabled = false;
- }
- }
- private void ob_checkno_TextChanged(object sender, EventArgs e)
- {
- if (ob_checkno.Text != "")
- {
- string Cut = dh.getFieldDataByCondition("product left join oqcbatch on ob_prodcode=pr_code", "pr_ifautocutcheckno", "ob_checkno='" + ob_checkno.Text + "'").ToString();
- if (Cut == "" || Cut == "0")
- AutoCut = false;
- else
- AutoCut = true;
- SendCheck.Enabled = true;
- }
- }
- }
- }
|