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.Packing { public partial class Packing_CartonSplit : Form { //拼接sql的 LogStringBuilder sql = new LogStringBuilder(); DataHelper dh; DataTable dt;//存放箱号查询信息 DataTable checknoInfo; string error = "";//记录错误信息 string ms_id = ""; string outboxcode = ""; string pd_id = ""; AutoSizeFormClass asc = new AutoSizeFormClass(); public Packing_CartonSplit() { InitializeComponent(); } private void Packing_CartonSplit_Load(object sender, EventArgs e) { asc.controllInitializeSize(this); OperateResult.AppendText(">>请输入箱号\n", Color.Black); pa_outboxcode.Focus(); dh = SystemInf.dh; } private void pa_outboxcode_KeyDown(object sender, KeyEventArgs e) { //按下回车 if (e.KeyCode == Keys.Enter) { lKeyDown(false); } } private void sncode_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (sncode.Text == "") { OperateResult.AppendText("<<输入不能为空\n", Color.Red); return; } //根据序列号带出箱号 //if (pa_outboxcode.Text == "") //{ // OperateResult.AppendText("<<请先选择箱号\n", Color.Red, sncode); // return; //} OperateResult.AppendText(">>" + sncode.Text + "\n", Color.Black); if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out error)) { //验证序列号是否存在,是否装箱,箱号等于页面输入的箱号 //select max(ms_id) from makeserial where ms_sncode=? ms_id = dh.getFieldDataByCondition("makeserial", "max(ms_id)", "ms_sncode='" + sncode.Text + "'").ToString(); if (ms_id == "") { OperateResult.AppendText("<<序列号" + sncode.Text + "不存在\n", Color.Red, sncode); return; } outboxcode = dh.getFieldDataByCondition("makeserial", "ms_outboxcode", "ms_id='" + ms_id + "' and nvl(ms_outboxcode,' ')<>' '").ToString(); if (outboxcode == "") { OperateResult.AppendText("<<序列号" + sncode.Text + "未装箱\n", Color.Red, sncode); return; } //没填箱号,就赋值箱号 if (pa_outboxcode.Text == "") { pa_outboxcode.Text = outboxcode; //勾上 lock_outbox.Checked = true; } if (pa_outboxcode.Text != outboxcode) { OperateResult.AppendText("<<序列号" + sncode.Text + "箱号为:" + outboxcode + ",不在箱号:" + pa_outboxcode.Text + "中,无法拆箱\n", Color.Red, sncode); return; } //验证箱号 if (!checkOutboxcode(false)) { return; } //验证是否在箱内 pd_id = dh.getFieldDataByCondition("packagedetail", "pd_id", "pd_outboxcode='" + pa_outboxcode.Text + "' and pd_barcode='" + sncode.Text + "'").ToString(); if (pd_id == "") { OperateResult.AppendText("<<序列号" + sncode.Text + "不在箱号:" + pa_outboxcode.Text + "内,不允许拆箱\n", Color.Red, sncode); return; } //进行拆箱处理 //删除明细 dh.ExecuteSql("delete from packagedetail where pd_id='" + pd_id + "'", "select"); //更新序列号 dh.ExecuteSql("update makeserial set ms_outboxcode='' , ms_nextstepcode=ms_stepcode where ms_id='" + ms_id + "'", "update"); //更新箱内当前数量 dh.ExecuteSql("update package set pa_currentqty=pa_currentqty-1,pa_status=0 where pa_outboxcode='" + pa_outboxcode.Text + "'", "update"); //记录拆箱操作日志 LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, packtype.Text, User.UserLineCode, User.UserSourceCode, "卡通箱拆箱", "卡通箱拆箱成功,序列号:" + sncode.Text + ",箱号:" + pa_outboxcode.Text, sncode.Text, ""); //提示拆箱成功 OperateResult.AppendText("<<拆箱成功,序列号:" + sncode.Text + ",已从箱号:" + pa_outboxcode.Text + "内移除\n", Color.Green); //刷新箱内数量 pa_currentqty.Text = int.Parse(pa_currentqty.Text) - 1 + ""; //计数加1 count.Text = int.Parse(count.Text) + 1 + ""; sncode.Text = ""; } else { OperateResult.AppendText("<<" + error + "\n", Color.Red, sncode); } } } private bool checkOutboxcode(bool flag) { //校验箱号 sql.Clear(); sql.Append("select pa_prodcode,pr_detail,pr_spec,pa_standardqty,nvl(pa_currentqty,0) pa_currentqty,pa_salecode,pa_makecode,"); sql.Append("pa_packtype,nvl(pa_downstatus,0) pa_downstatus,pa_checkno from package left join product on "); sql.Append("pr_code=pa_prodcode where pa_outboxcode='" + pa_outboxcode.Text + "' and PA_TYPE=1"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); //查询无值,提示用户 “箱号不存在”,清空输入框中的值 if (dt.Rows.Count == 0) { if (flag) { MessageBox.Show("箱号" + pa_outboxcode.Text + "不存在"); pa_outboxcode.Focus(); return false; } OperateResult.AppendText("<<箱号" + pa_outboxcode.Text + "不存在\n", Color.Red, pa_outboxcode); return false; } //判断是否下地 if (dt.Rows[0]["pa_downstatus"].ToString() != "0") { if (flag) { MessageBox.Show("箱号" + pa_outboxcode.Text + "处于下地状态不允许操作"); pa_outboxcode.Focus(); return false; } OperateResult.AppendText("<<箱号" + pa_outboxcode.Text + "处于下地状态不允许操作\n", Color.Red, pa_outboxcode); return false; } //判断是否有抽检批次号,并且未判定 if (dt.Rows[0]["pa_checkno"].ToString() != "") { checknoInfo = (DataTable)dh.ExecuteSql("select count(1) cn from oqcbatch where ob_checkno='" + dt.Rows[0]["pa_checkno"].ToString() + "' and ob_status not in('OK','NG')", "select"); //cn>0 ,则返回提示用户“箱号处于送检状态,不允许拆箱” if (int.Parse(checknoInfo.Rows[0]["cn"].ToString()) > 0) { if (flag) { MessageBox.Show("箱号" + pa_outboxcode.Text + "处于送检状态,不允许拆箱"); pa_outboxcode.Focus(); return false; } OperateResult.AppendText("<<箱号" + pa_outboxcode.Text + "处于送检状态,不允许拆箱\n", Color.Red, pa_outboxcode); return false; } } //验证mothercode是否为空,有没有装大箱 if (dh.getFieldDataByCondition("package", "pa_mothercode", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() != "") { if (flag) { MessageBox.Show("<<卡通箱:" + pa_outboxcode.Text + "已装箱,不允许拆箱\n"); pa_outboxcode.Focus(); return false; } OperateResult.AppendText("<<卡通箱:" + pa_outboxcode.Text + "已装箱,不允许拆箱\n", Color.Red, sncode); return false; } return true; } private void lock_outbox_CheckedChanged(object sender, EventArgs e) { if (!lock_outbox.Checked) { if (!pa_outboxcode.Enabled) { //取消勾选,箱号不可编辑时设置可编辑 pa_outboxcode.Enabled = true; } pa_outboxcode.Focus(); } else { //勾选 if (!lKeyDown(true)) { lock_outbox.Checked = false; } } } private void Packing_CartonSplit_SizeChanged(object sender, EventArgs e) { asc.controlAutoSize(this); } private bool lKeyDown(bool flag) { //输入不能为空 if (pa_outboxcode.Text == "") { if (flag) { MessageBox.Show("输入不能为空"); pa_outboxcode.Focus(); return false; ; } OperateResult.AppendText("<<输入不能为空\n", Color.Red); return false; } if (pa_outboxcode.Enabled) { OperateResult.AppendText(">>" + pa_outboxcode.Text + "\n", Color.Black); } //验证箱号 if (!checkOutboxcode(flag)) { return false; } //判定通过,则自动勾选,显示箱号相关信息 BaseUtil.SetFormValue(this.Controls, dt); //特殊赋值 if (dt.Rows[0]["pa_packtype"].ToString() == "SALE") { packtype.Text = dt.Rows[0]["pa_salecode"].ToString(); } else if (dt.Rows[0]["pa_packtype"].ToString() == "MAKE") { packtype.Text = dt.Rows[0]["pa_makecode"].ToString(); } else if (dt.Rows[0]["pa_packtype"].ToString() == "MIX" || dt.Rows[0]["pa_packtype"].ToString() == "SPEC") { pa_prodcode.Text = "混包"; } pa_outboxcode.Enabled = false; lock_outbox.Checked = true; sncode.Focus(); return true; } private void pa_outboxcode_Leave(object sender, EventArgs e) { if (pa_outboxcode.Text != "") { lKeyDown(true); } } } }