浏览代码

优化执行速度,减少执行SQL

章政 8 年之前
父节点
当前提交
259c004fb7

+ 70 - 72
UAS-MES/FunctionCode/Make/Make_BigBoxCollection.cs

@@ -151,7 +151,7 @@ namespace UAS_MES.Make
                         if (pa_nextstep == "")
                         {
                             //判断线外,必须已完工并且未入库
-                            dt = (DataTable)dh.ExecuteSql("select wm_concat(ms_sncode) from mes_package_view  left join makeserial on v_barcode=ms_sncode and ms_sncode=v_barcode where  v_outboxcode='" + outboxcode.Text + "' and ms_status<>2", "select");
+                            dt = (DataTable)dh.ExecuteSql("select wm_concat(ms_sncode) from mes_package_view  left join makeserial on v_makecode=ms_makecode and ms_sncode=v_barcode where v_outboxcode='" + outboxcode.Text + "' and ms_status<>2", "select");
                             if (dt.Rows[0][0].ToString() == "")
                             {
                                 //判断箱未入库
@@ -202,7 +202,7 @@ namespace UAS_MES.Make
                             return;
                         }
                         //箱号不存在进行插入
-                        dt = (DataTable)dh.ExecuteSql("select pa_id from  package where pa_outboxcode='" + pa_outboxcode.Text + "'", "select");
+                        DataTable dt = (DataTable)dh.ExecuteSql("select pa_id from  package where pa_outboxcode='" + pa_outboxcode.Text + "'", "select");
                         if (dt.Rows.Count == 0)
                         {
                             pa_id = dh.GetSEQ("package_seq");
@@ -223,7 +223,73 @@ namespace UAS_MES.Make
                             return;
                         }
                         //如果未装满的话
-                        CollectBox();
+                        sql.Clear();
+                        sql.Append("select count(0) cn from packagedetail left join package on pa_id=pd_paid where ");
+                        sql.Append("pa_outboxcode='" + pa_outboxcode.Text + "'");
+                        int packageqty = int.Parse((dh.ExecuteSql(sql.GetString(), "select") as DataTable).Rows[0][0].ToString());
+                        dt = (DataTable)dh.ExecuteSql("select nvl(pa_status,0) pa_status,pa_mothercode from package where pa_outboxcode='" + outboxcode.Text + "' and pa_type=1", "select");
+                        //采集的卡通箱号存在
+                        if (dt.Rows.Count > 0)
+                        {
+                            if (dt.Rows[0]["pa_status"].ToString() == "1")
+                            {
+                                //判断是否已经装箱
+                                if (dt.Rows[0]["pa_mothercode"].ToString() == "")
+                                {
+                                    //插入大箱明细
+                                    List<string> SQLS = new List<string>();
+                                    sql.Clear();
+                                    sql.Append("insert into packagedetail(pd_id, pd_paid, pd_outboxcode,pd_innerboxcode, pd_innerqty,pd_makecode,pd_prodcode,pd_builddate)");
+                                    sql.Append("select packagedetail_seq.nextval,'" + pa_id + "','" + pa_outboxcode.Text + "','" + outboxcode.Text + "'");
+                                    sql.Append(",pa_packageqty,pa_makecode,'" + pd_prodcode.Text + "',sysdate from package where pa_outboxcode='" + outboxcode.Text + "'");
+                                    SQLS.Add(sql.GetString());
+                                    //箱内计数+1
+                                    SQLS.Add("update package set PA_CURRENTQTY=PA_CURRENTQTY+1,PA_PACKAGEQTY=PA_PACKAGEQTY+1,PA_TOTALQTY=(select sum(pd_innerqty) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode='" + pa_outboxcode.Text + "') where pa_outboxcode='" + pa_outboxcode.Text + "' and pa_type=2");
+                                    //更新采集的子箱记录母箱号
+                                    SQLS.Add("update package set pa_mothercode='" + pa_outboxcode.Text + "' where pa_outboxcode='" + outboxcode.Text + "'");
+                                    dh.ExecuteSQLTran(SQLS.ToArray());
+                                    if (dh.getFieldDataByCondition("package", "pa_makecode", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() == "")
+                                    {
+                                        string carton_macode = dh.getFieldDataByCondition("package", "pa_makecode", "pa_outboxcode='" + outboxcode.Text + "'").ToString();
+                                        pa_makecode.Text = carton_macode;
+                                        dh.ExecuteSql("update package set pa_makecode='" + carton_macode + "' where pa_outboxcode='" + pa_outboxcode.Text + "'", "update");
+                                    }
+                                    LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "大箱采集", "大箱" + pa_outboxcode.Text + "采集卡通箱" + outboxcode.Text + "采集成功", outboxcode.Text, "");
+                                    //记录卡通箱所有序列号操作日志
+                                    if (pa_nextstep != "")
+                                    {
+                                        LogicHandler.OutBoxStepPass(outboxcode.Text, pa_makecode.Text, User.UserSourceCode, User.UserCode, "大箱采集成功,大箱号:" + pa_outboxcode.Text, "大箱采集");
+                                    }
+                                    LoadGridData();
+                                    LoadCollectNum();
+                                    //更新箱号的NextStepCode
+                                    if (pa_currentqty.Text == "1")
+                                    {
+                                        string nextstepcode = dh.getFieldDataByCondition("mes_package_view left join makeserial on ms_sncode=v_barcode", "ms_nextstepcode", "v_outboxcode='" + outboxcode.Text + "'").ToString();
+                                        dh.UpdateByCondition("package", "pa_nextstep='" + nextstepcode + "'", "pa_outboxcode='" + pa_outboxcode.Text + "'");
+                                    }
+                                    OperateResult.AppendText(">>卡通箱号" + outboxcode.Text + "采集成功!\n", Color.Green, outboxcode);
+                                    if (packageqty + 1 == pa_stanqty)
+                                    {
+                                        dh.ExecuteSql("update package set pa_status=1 where pa_outboxcode='" + pa_outboxcode.Text + "'", "update");
+                                        if (AutoPrint.Checked)
+                                        {
+                                            OperateResult.AppendText(">>箱已装满,自动打印!\n", Color.Green);
+                                            Printlab.PerformClick();
+                                        }
+                                    }
+                                }
+                                else
+                                {
+                                    if (dt.Rows[0]["pa_mothercode"].ToString() == pa_outboxcode.Text)
+                                        OperateResult.AppendText(">>卡通箱号" + outboxcode.Text + "已在本大箱内\n", Color.Red, outboxcode);
+                                    else
+                                        OperateResult.AppendText(">>卡通箱号" + outboxcode.Text + "已采集至大箱" + dt.Rows[0]["pa_mothercode"].ToString() + "\n", Color.Red, outboxcode);
+                                }
+                            }
+                            else OperateResult.AppendText(">>卡通箱号" + outboxcode.Text + "尚未封箱\n", Color.Red, outboxcode);
+                        }
+                        else OperateResult.AppendText(">>卡通箱号" + outboxcode.Text + "不存在\n", Color.Red, outboxcode);
                     }
                     else
                     {
@@ -234,6 +300,7 @@ namespace UAS_MES.Make
                         SQLS.Add("update package set pa_packageqty=pa_packageqty-1,pa_totalqty=pa_totalqty-(select pa_totalqty from package where pa_outboxcode='" + outboxcode.Text + "'),pa_currentqty=0,pa_status=0 where pa_outboxcode='" + pa_outboxcode.Text + "'");
                         SQLS.Add("update package set pa_mothercode='' where pa_outboxcode='" + outboxcode.Text + "'");
                         dh.ExecuteSQLTran(SQLS.ToArray());
+                        OperateResult.AppendText(">>箱号" + outboxcode.Text + "取消采集成功\n", Color.Green);
                         LoadCollectNum();
                         LoadGridData();
                         outboxcode.Clear();
@@ -254,75 +321,6 @@ namespace UAS_MES.Make
             BaseUtil.FillDgvWithDataTable(PackageInf, dt);
         }
 
-        private void CollectBox()
-        {
-            sql.Clear();
-            sql.Append("select count(0) cn from packagedetail left join package on pa_id=pd_paid where ");
-            sql.Append("pa_outboxcode='" + pa_outboxcode.Text + "'");
-            int packageqty = int.Parse((dh.ExecuteSql(sql.GetString(), "select") as DataTable).Rows[0][0].ToString());
-            DataTable dt = (DataTable)dh.ExecuteSql("select nvl(pa_status,0) pa_status,pa_mothercode from package where pa_outboxcode='" + outboxcode.Text + "' and pa_type=1", "select");
-            //采集的卡通箱号存在
-            if (dt.Rows.Count > 0)
-            {
-                if (dt.Rows[0]["pa_status"].ToString() == "1")
-                {
-                    //判断是否已经装箱
-                    if (dt.Rows[0]["pa_mothercode"].ToString() == "")
-                    {
-                        //插入大箱明细
-                        sql.Clear();
-                        sql.Append("insert into packagedetail(pd_id, pd_paid, pd_outboxcode,pd_innerboxcode, pd_innerqty,pd_makecode,pd_prodcode,pd_builddate)");
-                        sql.Append("select packagedetail_seq.nextval,'" + pa_id + "','" + pa_outboxcode.Text + "','" + outboxcode.Text + "'");
-                        sql.Append(",pa_packageqty,pa_makecode,'" + pd_prodcode.Text + "',sysdate from package where pa_outboxcode='" + outboxcode.Text + "'");
-                        dh.ExecuteSql(sql.GetString(), "insert");
-                        //箱内计数+1
-                        dh.UpdateByCondition("package", "PA_CURRENTQTY=PA_CURRENTQTY+1,PA_PACKAGEQTY=PA_PACKAGEQTY+1,PA_TOTALQTY=(select sum(pd_innerqty) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode='" + pa_outboxcode.Text + "')", "pa_outboxcode='" + pa_outboxcode.Text + "' and pa_type=2");
-                        //更新采集的子箱记录母箱号
-                        dh.UpdateByCondition("package", "pa_mothercode='" + pa_outboxcode.Text + "'", "pa_outboxcode='" + outboxcode.Text + "'");
-                        if (dh.getFieldDataByCondition("package", "pa_makecode", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() == "")
-                        {
-                            string carton_macode = dh.getFieldDataByCondition("package", "pa_makecode", "pa_outboxcode='" + outboxcode.Text + "'").ToString();
-                            pa_makecode.Text = carton_macode;
-                            dh.ExecuteSql("update package set pa_makecode='" + carton_macode + "' where pa_outboxcode='" + pa_outboxcode.Text + "'", "update");
-                        }
-                        LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "大箱采集", "大箱" + pa_outboxcode.Text + "采集卡通箱" + outboxcode.Text + "采集成功", outboxcode.Text, "");
-                        //记录卡通箱所有序列号操作日志
-                        if (pa_nextstep != "")
-                        {
-                            LogicHandler.OutBoxStepPass(outboxcode.Text, pa_makecode.Text, User.UserSourceCode, User.UserCode, "大箱采集成功,大箱号:" + pa_outboxcode.Text, "大箱采集");
-                        }
-                        LoadGridData();
-                        LoadCollectNum();
-                        //更新箱号的NextStepCode
-                        if (pa_currentqty.Text == "1")
-                        {
-                            string nextstepcode = dh.getFieldDataByCondition("mes_package_view left join makeserial on ms_sncode=v_barcode", "ms_nextstepcode", "v_outboxcode='" + outboxcode.Text + "'").ToString();
-                            dh.UpdateByCondition("package", "pa_nextstep='" + nextstepcode + "'", "pa_outboxcode='" + pa_outboxcode.Text + "'");
-                        }
-                        OperateResult.AppendText(">>卡通箱号" + outboxcode.Text + "采集成功!\n", Color.Green, outboxcode);
-                        if (packageqty + 1 == pa_stanqty)
-                        {
-                            dh.ExecuteSql("update package set pa_status=1 where pa_outboxcode='" + pa_outboxcode.Text + "'", "update");
-                            if (AutoPrint.Checked)
-                            {
-                                OperateResult.AppendText(">>箱已装满,自动打印!\n", Color.Green);
-                                Printlab.PerformClick();
-                            }
-                        }
-                    }
-                    else
-                    {
-                        if (dt.Rows[0]["pa_mothercode"].ToString() == pa_outboxcode.Text)
-                            OperateResult.AppendText(">>卡通箱号" + outboxcode.Text + "已在本大箱内\n", Color.Red, outboxcode);
-                        else
-                            OperateResult.AppendText(">>卡通箱号" + outboxcode.Text + "已采集至大箱" + dt.Rows[0]["pa_mothercode"].ToString() + "\n", Color.Red, outboxcode);
-                    }
-                }
-                else OperateResult.AppendText(">>卡通箱号" + outboxcode.Text + "尚未封箱\n", Color.Red, outboxcode);
-            }
-            else OperateResult.AppendText(">>卡通箱号" + outboxcode.Text + "不存在\n", Color.Red, outboxcode);
-        }
-
         private void FillPrintLabel()
         {
             DataTable _dt = (DataTable)dh.ExecuteSql("select la_id,la_printnos,substr(la_url,instr(la_url,'\\',-1)+1)la_name,la_url,la_isdefault from label where la_prodcode='" + pa_prodcode.Text + "' and la_templatetype='大箱标' and la_statuscode='AUDITED' order by la_isdefault", "select");

+ 16 - 7
UAS-MES/FunctionCode/Make/Make_PackageCollection.cs

@@ -95,7 +95,11 @@ namespace UAS_MES.Make
                     pr_outboxinnerqty.Text = pa_standardqty.Text;
                 }
             }
-            else sn_code.Focus();
+            else
+            {
+                pa_makecode.Text = "";
+                sn_code.Focus();
+            }
             LoadCheckQTY();
         }
 
@@ -156,13 +160,17 @@ namespace UAS_MES.Make
                         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='" + sn_code.Text + "' and ms_makecode='" + oMakeCode + "' and cd_stepcode = '" + User.CurrentStepCode + "'").ToString();
                         //获取序列号信息
                         sql.Clear();
-                        sql.Append("select ms_makecode,nvl(pa_downstatus,0) pa_downstatus,pa_sccode,pa_checkno,pr_packrule,");
+                        sql.Append("select ms_makecode,ms_prodcode,nvl(pa_downstatus,0) pa_downstatus,pa_sccode,pa_checkno,pr_packrule,");
                         sql.Append("nvl(pr_outboxinnerqty,0)pr_outboxinnerqty,nvl(PR_CHECKCARTONW,'0') PR_CHECKCARTONW from makeserial left join product on ms_prodcode=pr_code left join packagedetail ");
                         sql.Append("on pd_barcode=ms_sncode left join package on pa_id =pd_paid where ms_id='" + oMsID + "'");
                         dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
+                        string ms_makecode = "";
+                        string ms_prodcode = "";
                         if (dt.Rows.Count > 0)
                         {
                             StandardQTY = decimal.Parse(dt.Rows[0]["pr_outboxinnerqty"].ToString());
+                            ms_makecode = dt.Rows[0]["ms_makecode"].ToString();
+                            ms_prodcode = dt.Rows[0]["ms_prodcode"].ToString();
                             BaseUtil.SetFormValue(this.Controls, dt);
                         }
                         //保证箱内容量不会被重置
@@ -177,12 +185,13 @@ namespace UAS_MES.Make
                             if (boxcode != "")
                             {
                                 pa_outboxcode.Text = boxcode;
+                                pa_makecode.Text = "";
                                 LoadGridData();
                             }
                             else
                             {
                                 //如果勾选了自动生成箱号,在封箱或者首次
-                                if (AutoGenBoxCode.Checked && (pa_status.Text == "1" || pa_status.Text == ""))
+                                if (AutoGenBoxCode.Checked && (pa_status.Text == "1" || pa_status.Text == "" || pa_status.Text == "0"))
                                     pa_outboxcode.Text = LogicHandler.GetOutBoxCode("PACKAGE", "", pr_code.Text, User.UserCode);
                             }
                         }
@@ -197,7 +206,7 @@ namespace UAS_MES.Make
                             switch (pr_packrule.Text.ToUpper())
                             {
                                 case "MAKE":
-                                    if (dh.getFieldDataByCondition("makeserial", "ms_makecode", "ms_id='" + oMsID + "'").ToString() != pa_makecode.Text && pa_makecode.Text != "")
+                                    if (ms_makecode != pa_makecode.Text && pa_makecode.Text != "")
                                     {
                                         OperateResult.AppendText(">>序列号" + sn_code.Text + "所属工单和当前箱号工单不相等\n", Color.Red, sn_code);
                                         return;
@@ -218,9 +227,9 @@ namespace UAS_MES.Make
                                     }
                                     break;
                                 case "PROD":
-                                    if (dh.getFieldDataByCondition("makeserial", "ms_prodcode", "ms_id='" + oMsID + "'").ToString() != pr_code.Text)
+                                    if (ms_prodcode != pr_code.Text)
                                     {
-                                        OperateResult.AppendText(">>序列号" + sn_code.Text + "对应物料和该箱所装物料不同\n", Color.Red, sn_code);
+                                        OperateResult.AppendText(">>序列号" + sn_code.Text + "对应产品和该箱所装产品不同\n", Color.Red, sn_code);
                                         return;
                                     }
                                     break;
@@ -298,7 +307,7 @@ namespace UAS_MES.Make
                                     }
                                     sn_code.Clear();
                                 }
-                                else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red,sn_code);
+                                else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sn_code);
                             }
                         }
                         //勾选了取消箱号先验证箱号存不存在,存在的话移除掉,重新加载一次数据

+ 1 - 0
UAS-MES/FunctionCode/Make/Make_PalletCollection.cs

@@ -282,6 +282,7 @@ namespace UAS_MES.Make
                         SQLS.Add("update package set pa_packageqty=pa_packageqty-1,pa_totalqty=pa_totalqty-(select pa_totalqty from package where pa_outboxcode='" + outboxcode.Text + "'),pa_currentqty=0,pa_status=0 where pa_outboxcode='" + pa_outboxcode.Text + "'");
                         SQLS.Add("update package set pa_mothercode='' where pa_outboxcode='" + outboxcode.Text + "'");
                         dh.ExecuteSQLTran(SQLS.ToArray());
+                        OperateResult.AppendText(">>箱号" + outboxcode.Text + "取消采集成功\n", Color.Green);
                         LoadCollectNum();
                         LoadGridData();
                         outboxcode.Clear();