Browse Source

异步加载数据,分页临界数据对比

章政 6 years ago
parent
commit
c4364231c5
1 changed files with 53 additions and 39 deletions
  1. 53 39
      UAS-出货标签管理(吉利通)/UAS_出货标签管理.cs

+ 53 - 39
UAS-出货标签管理(吉利通)/UAS_出货标签管理.cs

@@ -244,7 +244,7 @@ namespace UAS_LabelMachine
                     case "FrontendCheck":
                         //比对当前箱数量和容量
                         FrontCollect.Text = msg;
-                        if (!FrontCheckFunction(pib_id, msg, out ErrorMsg))
+                        if (!FrontCheckFunction( msg, out ErrorMsg))
                         {
                             LogicHandler.SendDataToPLC(PLC1, PLCInstruct.FrontDataDelete);
                             MessageLog.AppendText(">>" + ErrorMsg + "\n", Color.Red);
@@ -276,8 +276,6 @@ namespace UAS_LabelMachine
                         BackCheck.Text = msg;
                         if (BackendCheckFunction(msg, pib_id, out ErrorMsg))
                         {
-                            //设置变量为已勾选
-                            ShowDt.Select("pib_id=" + pib_id)[0]["pib_ifpick"] = -1;
                             LogicHandler.SendDataToPLC(PLC1, PLCInstruct.BackDataPass);
                         }
                         else
@@ -297,7 +295,7 @@ namespace UAS_LabelMachine
             }
         }
 
-        private bool FrontCheckFunction(string pib_id, string msg, out string ErrorMsg)
+        private bool FrontCheckFunction(string msg, out string ErrorMsg)
         {
             int GroupCount = 0;
             ErrorMsg = "";
@@ -354,23 +352,23 @@ namespace UAS_LabelMachine
                             case "PN":
                                 PN = arr[ItemIndex[j]];
                                 //自动匹配客户PN
-                                DataTable pndt = BaseUtil.filterDataTable(ShowDt, "pr_orispeccode='" + PN + "' and pib_ifpick=0 ");
+                                DataTable pndt = (DataTable)adh.ExecuteSql("select min(rownum) as rn from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and pr_orispeccode='" + PN + "' and pib_ifpick=0", "select");
                                 int rownum = 0;
                                 if (pndt.Rows.Count > 0)
                                 {
-                                    rownum = int.Parse(pndt.Rows[0]["rownum"].ToString());
+                                    rownum = int.Parse(pndt.Rows[0]["rn"].ToString());
                                     //如果需要翻页的话
                                     if (!(rownum >= (PageSize * (CurrentPage - 1) + 1) && rownum <= PageSize * CurrentPage))
                                     {
                                         CurrentPage = rownum / PageSize + 1;
                                         LoadGridData();
-                                        CurrentRowIndex = rownum % PageSize - 1;
+                                        CurrentRowIndex = rownum % PageSize == 0 ? PageSize - 1 : rownum % PageSize - 1;
                                         if (CurrentRowIndex - 10 > 0)
                                             LabelInf.FirstDisplayedScrollingRowIndex = CurrentRowIndex - 5;
                                     }
                                     else
                                     {
-                                        CurrentRowIndex = rownum - 1;
+                                        CurrentRowIndex = rownum % PageSize == 0 ? PageSize - 1 : rownum % PageSize - 1;
                                         if (CurrentRowIndex - 10 > 0)
                                             LabelInf.FirstDisplayedScrollingRowIndex = CurrentRowIndex - 5;
                                     }
@@ -438,6 +436,7 @@ namespace UAS_LabelMachine
                 //获取当前最大的箱号
                 LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value = DateCode;
                 LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value = LotNo;
+                LabelInf.Rows[CurrentRowIndex].Cells["pib_ifmodify"].Value = true;
                 string boxcode = adh.getFieldDataByCondition("prodiobarcode", "max(pib_outboxcode1)", "pib_inoutno='" + pi_inoutno.Text + "'").ToString();
                 int outboxcode1 = int.Parse(boxcode == "" ? "1" : boxcode);
                 boxcode = adh.getFieldDataByCondition("prodiobarcode", "max(pib_outboxcode2)", "pib_inoutno='" + pi_inoutno.Text + "'").ToString();
@@ -449,12 +448,17 @@ namespace UAS_LabelMachine
                     outboxcode1 = outboxcode1 + 1;
                     LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
                 }
-                if (CurrentRowIndex - 1 >= 0)
+                //获取当前的行号
+                int CurrentRowNum = int.Parse(LabelInf.Rows[CurrentRowIndex].Cells["rownum"].Value.ToString());
+                //获取上一行的数据
+                DataTable LastRowData = null;
+                if (CurrentRowNum - 1 > 0)
                 {
+                    LastRowData = (DataTable)adh.ExecuteSql("select pib_lotno,pib_custmidboxcode,pib_custoutboxcode,pd_pocode,pd_custprodcode,pd_custprodspec,pib_datecode from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and rownum=" + (CurrentRowNum - 1), "select");
                     //或者不符合合并条件中盒号+1
                     if (cu_print_midlotno.Checked)
                     {
-                        if (LabelInf.Rows[CurrentRowIndex - 1].Cells["pib_lotno"].Value.ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value.ToString())
+                        if (LastRowData.Rows[0]["pib_lotno"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value.ToString())
                         {
                             LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
                             LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = MidBoxBarCode;
@@ -463,7 +467,7 @@ namespace UAS_LabelMachine
                     }
                     else if (cu_print_midpo.Checked)
                     {
-                        if (LabelInf.Rows[CurrentRowIndex - 1].Cells["pd_pocode"].Value.ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pd_pocode"].Value.ToString())
+                        if (LastRowData.Rows[0]["pd_pocode"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pd_pocode"].Value.ToString())
                         {
                             LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
                             LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = MidBoxBarCode;
@@ -472,7 +476,7 @@ namespace UAS_LabelMachine
                     }
                     else if (cu_print_midprod.Checked)
                     {
-                        if (LabelInf.Rows[CurrentRowIndex - 1].Cells["pr_orispeccode"].Value.ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pd_custprodcode"].Value.ToString())
+                        if (LastRowData.Rows[0]["pd_custprodcode"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pd_custprodcode"].Value.ToString())
                         {
                             LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
                             LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = MidBoxBarCode;
@@ -481,7 +485,7 @@ namespace UAS_LabelMachine
                     }
                     else if (cu_print_midspec.Checked)
                     {
-                        if (LabelInf.Rows[CurrentRowIndex - 1].Cells["pd_custprodspec"].Value.ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pd_custprodspec"].Value.ToString())
+                        if (LastRowData.Rows[0]["pd_custprodspec"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pd_custprodspec"].Value.ToString())
                         {
                             LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
                             LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = MidBoxBarCode;
@@ -490,18 +494,17 @@ namespace UAS_LabelMachine
                     }
                     else if (cu_print_middc.Checked)
                     {
-                        if (LabelInf.Rows[CurrentRowIndex - 1].Cells["pib_datecode"].Value.ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value.ToString())
+                        if (LastRowData.Rows[0]["pib_datecode"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value.ToString())
                         {
                             LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
                             LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = MidBoxBarCode;
                             outboxcode1 = outboxcode1 + 1;
                         }
                     }
-                    if (MidBoxBarCode == "")
-                    {
-                        LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
-                    }
-                    LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = MidBoxBarCode;
+                    if (LastRowData.Rows[0]["pib_custmidboxcode"].ToString() == MidBoxBarCode)
+                        LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = LastRowData.Rows[0]["pib_custmidboxcode"].ToString();
+                    else
+                        LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = MidBoxBarCode;
                 }
                 else
                 {
@@ -514,12 +517,12 @@ namespace UAS_LabelMachine
                     LogicHandler.GetBarCode(PI_ID, pd_id, 1, out OutBoxBarCode);
                     LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
                 }
-                else if (CurrentRowIndex - 1 >= 0)
+                else if (CurrentRowNum - 1 > 0)
                 {
                     //或者不符合合并条件中盒号+1
                     if (cu_print_outlotno.Checked)
                     {
-                        if (LabelInf.Rows[CurrentRowIndex - 1].Cells["pib_lotno"].Value.ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value.ToString())
+                        if (LastRowData.Rows[0]["pib_lotno"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value.ToString())
                         {
                             LogicHandler.GetBarCode(PI_ID, pd_id, 1, out OutBoxBarCode);
                             LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
@@ -527,7 +530,7 @@ namespace UAS_LabelMachine
                     }
                     else if (cu_print_outpo.Checked)
                     {
-                        if (LabelInf.Rows[CurrentRowIndex - 1].Cells["pd_pocode"].Value.ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pd_pocode"].Value.ToString())
+                        if (LastRowData.Rows[0]["pd_pocode"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pd_pocode"].Value.ToString())
                         {
                             LogicHandler.GetBarCode(PI_ID, pd_id, 1, out OutBoxBarCode);
                             LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
@@ -535,7 +538,7 @@ namespace UAS_LabelMachine
                     }
                     else if (cu_print_outprod.Checked)
                     {
-                        if (LabelInf.Rows[CurrentRowIndex - 1].Cells["pr_orispeccode"].Value.ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pd_custprodcode"].Value.ToString())
+                        if (LastRowData.Rows[0]["pd_custprodcode"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pd_custprodcode"].Value.ToString())
                         {
                             LogicHandler.GetBarCode(PI_ID, pd_id, 1, out OutBoxBarCode);
                             LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
@@ -543,7 +546,7 @@ namespace UAS_LabelMachine
                     }
                     else if (cu_print_outspec.Checked)
                     {
-                        if (LabelInf.Rows[CurrentRowIndex - 1].Cells["pd_custprodspec"].Value.ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pd_custprodspec"].Value.ToString())
+                        if (LastRowData.Rows[0]["pd_custprodspec"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pd_custprodspec"].Value.ToString())
                         {
                             LogicHandler.GetBarCode(PI_ID, pd_id, 1, out OutBoxBarCode);
                             LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
@@ -551,17 +554,16 @@ namespace UAS_LabelMachine
                     }
                     else if (cu_print_outdc.Checked)
                     {
-                        if (LabelInf.Rows[CurrentRowIndex - 1].Cells["pib_datecode"].Value.ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value.ToString())
+                        if (LastRowData.Rows[0]["pib_datecode"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value.ToString())
                         {
                             LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
                             LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
                         }
                     }
-                    if (OutBoxBarCode == "")
-                    {
-                        LogicHandler.GetBarCode(PI_ID, pd_id, 1, out OutBoxBarCode);
-                    }
-                    LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
+                    if (OutBoxBarCode == LastRowData.Rows[0]["pib_custoutboxcode"].ToString())
+                        LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = LastRowData.Rows[0]["pib_custoutboxcode"].ToString();
+                    else
+                        LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
                 }
                 else
                 {
@@ -570,7 +572,8 @@ namespace UAS_LabelMachine
                 }
                 LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value = outboxcode1;
                 LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = outboxcode2;
-                adh.ExecuteSql("update prodiobarcode set pib_outboxcode2=" + outboxcode2 + ",pib_outboxcode1=" + outboxcode1 + ",pib_custoutboxcode='" + OutBoxBarCode + "',pib_custmidboxcode='" + MidBoxBarCode + "',pib_lotno='" + LotNo + "',pib_datecode='" + DateCode + "',pib_ifpick=-1 where pib_id=" + pib_id, "update");
+                string pib_id = LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString();
+                adh.ExecuteSql("update prodiobarcode set pib_outboxcode2=" + outboxcode2 + ",pib_outboxcode1=" + outboxcode1 + ",pib_custoutboxcode='" + OutBoxBarCode + "',pib_custmidboxcode='" + MidBoxBarCode + "',pib_lotno='" + LotNo + "',pib_datecode='" + DateCode + "',pib_ifpick=-1,pib_ifmodify=-1 where pib_id=" + pib_id, "update");
                 LabelInf.Refresh();
                 return true;
             }
@@ -1414,10 +1417,9 @@ namespace UAS_LabelMachine
             LoadGridData(new object(), new EventArgs());
         }
         int CurrentPage = 1;
-        int PageSize = 500;
+        int PageSize = 4;
         int DataSize = 0;
         int MaxPageSize = 0;
-        DataTable ShowDt;
         /// <summary>
         /// 自定义函数  加载明细行的数据,多处使用添加进函数
         /// </summary>
@@ -1434,7 +1436,6 @@ namespace UAS_LabelMachine
             }
             sql.Append(" order by rownum");
             DataTable LabelInfDataTable = (DataTable)adh.ExecuteSql(sql.ToString(), "select");
-            ShowDt = (DataTable)adh.ExecuteSql("select * from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' order by rownum", "select");
             if (LabelInfDataTable.Rows.Count == 0)
             {
                 //嵌套查询重置RowNum
@@ -1445,7 +1446,6 @@ namespace UAS_LabelMachine
                 sql.Append("pib_outboxcode2,nvl(pib_ifpick,0)pib_ifpick,nvl(pib_ifprint,0)pib_ifprint from prodiobarcode left join prodinout on pib_piid=pi_id left join prodiodetail on pib_piid=pd_piid and  ");
                 sql.Append("pd_pdno=pib_pdno and pd_prodcode=pib_prodcode left join product on pr_code=pib_prodcode left join sale on sa_code=pib_ordercode where pib_piid='" + PI_ID + "' order by to_number(pib_id))t");
                 LabelInfDataTable = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
-                ShowDt = LabelInfDataTable;
                 //检验查询的字段和本地数据库字段是否匹配
                 adh.AddColumFromDataTable(LabelInfDataTable, "prodiobarcode");
                 //将数据保存在本地数据库
@@ -1459,9 +1459,9 @@ namespace UAS_LabelMachine
                     LabelInfDataTable = BaseUtil.filterDataTable(LabelInfDataTable, "rownum <=" + PageSize + " and pib_pdno >= " + DetailRange1.Value + " and pib_pdno<=" + DetailRange2.Value);
                 }
             }
-            LabelInf.DataSource = null;
+            bindingsource(LabelInf, LabelInfDataTable);
+            //LabelInf.DataSource = null;
             BaseUtil.FillDgvWithDataTable(LabelInf, LabelInfDataTable);
-
             //获取数据总条数
             if (!DetailRange.Checked)
             {
@@ -1498,6 +1498,21 @@ namespace UAS_LabelMachine
             }
         }
 
+
+        delegate void BindDataSource(DataGridView dgv, DataTable dt);//定义委托
+
+        void bindingsource(DataGridView dgv, DataTable dt)
+        {
+            if (dgv.InvokeRequired)
+            {
+                dgv.Invoke(new BindDataSource(bindingsource), new object[] { dgv, dt });
+            }
+            else
+            {
+                dgv.AutoGenerateColumns = false;
+                dgv.DataSource = dt;
+            }
+        }
         /// <summary>
         /// 重绘Cell的颜色
         /// </summary>
@@ -1693,7 +1708,6 @@ namespace UAS_LabelMachine
             if (result == DialogResult.OK)
             {
                 ExcelHandler eh = new ExcelHandler();
-                DataTable dt = ShowDt;
                 for (int i = dt.Columns.Count - 1; i >= 0; i--)
                 {
                     for (int j = 0; j < LabelInf.Columns.Count; j++)
@@ -1881,7 +1895,7 @@ namespace UAS_LabelMachine
             string pib_id = LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString();
             int pib_pdno = int.Parse(LabelInf.Rows[CurrentRowIndex].Cells["pib_pdno"].Value.ToString());
             string ErrorMsg = "";
-            FrontCheckFunction(pib_id, "", out ErrorMsg);
+            FrontCheckFunction( "", out ErrorMsg);
         }
 
         private void ButtonRecheckPass_Click(object sender, EventArgs e)