Browse Source

调整版本使用FastReport

章政 7 years ago
parent
commit
7682d660ef
1 changed files with 106 additions and 337 deletions
  1. 106 337
      UAS-出货标签管理(泽天)/UAS_出货标签管理.cs

+ 106 - 337
UAS-出货标签管理(泽天)/UAS_出货标签管理.cs

@@ -34,21 +34,15 @@ namespace UAS_LabelMachine
         /// <summary>
         /// 单盘打印文件
         /// </summary>
-        Document SingleDoc;
+        Report SingleReport = new Report();
         /// <summary>
         /// 中盒打印文件
         /// </summary>
-        Document MidDoc;
+        Report MidReport = new Report();
         /// <summary>
         /// 外箱打印文件
         /// </summary>
-        Document OutBoxDoc;
-
-        string OutLabelType = "";
-
         Report OutReport = new Report();
-
-        DataTable Attach;
         /// <summary>
         /// 唛头文件
         /// </summary>
@@ -68,10 +62,6 @@ namespace UAS_LabelMachine
 
         bool logout = false;
 
-        DataTable SingleLabelParam;
-        DataTable MidLabelParam;
-        DataTable OutLabelParam;
-
         //主表数据源
         DataTable LabelInfDataTable;
         /// <summary>
@@ -79,14 +69,6 @@ namespace UAS_LabelMachine
         /// </summary>
         List<string> SingleID = new List<string>();
         /// <summary>
-        /// 单盘的打印参数
-        /// </summary>
-        List<string> SingleBoxArgument = new List<string>();
-        /// <summary>
-        /// 中盒的打印参数
-        /// </summary>
-        List<string> MidBoxArgument = new List<string>();
-        /// <summary>
         /// 是否全选
         /// </summary>
         bool AllChecked = false;
@@ -95,12 +77,6 @@ namespace UAS_LabelMachine
         /// 是否通过选择Combox来改变打开的文件
         /// </summary>
         bool ComBoxClickChangeLabelDoc = false;
-
-        List<string> SingleParam = new List<string>();
-
-        List<string> MidParam = new List<string>();
-
-        List<string> OutParam = new List<string>();
         //当前采集的物料编号
         string CurrentPrCode = "";
         //当前采集的最小包装
@@ -120,16 +96,12 @@ namespace UAS_LabelMachine
         int NumLength = 0;
         int Radix = 0;
 
-        string SingleSQL = "";
-
-        string MidSQL = "";
-
-        string OutSQL = "";
-
         private bool EnablePrint = true;
 
         string[] PIBID;
 
+        DataTable Attach;
+
         public UAS_出货标签打印(string Master)
         {
             InitializeComponent();
@@ -207,12 +179,6 @@ namespace UAS_LabelMachine
         {
             客户标签维护 form = new 客户标签维护();
             BaseUtil.SetFormCenter(form);
-            if (SingleDoc != null)
-                SingleDoc.Close();
-            if (MidDoc != null)
-                MidDoc.Close();
-            if (OutBoxDoc != null)
-                OutBoxDoc.Close();
             if (FootDoc != null)
                 FootDoc.Close();
             form.FormClosed += LabelFormClose;
@@ -384,11 +350,11 @@ namespace UAS_LabelMachine
             sql.Append("insert into prodiobarcode(PIB_ID,PIB_PRODCODE,PIB_INDATE,PIB_INOUTNO,PIB_PIID,PIB_PDNO, PIB_PDID,PIB_PICLASS,");
             sql.Append("PIB_BARCODE,PIB_CUSTBARCODE,PIB_QTY,pib_brand,pib_datecode,pib_lotno,PIB_OUTBOXCODE2,pib_inman,PIB_IFPRINT,PIB_ORDERCODE,PIB_CUSTPO) ");
             sql.Append("select :PIB_ID,pd_prodcode,sysdate,pi_inoutno,pi_id,pd_pdno,pd_id,pi_class,");
-            sql.Append("'" + pib_barcode + "',:PIB_CUSTBARCODE,'" + CurrentZXBZ + "',pjd_brand,'" + Data["DATECODE"] + "','" + Data["LOTNO"] + "','" + pib_outboxcode2 + "','" + User.UserCode + "','" + (EnablePrint ? 1 : 0).ToString() + "',pd_ordercode,pd_pocode ");
+            sql.Append("'" + pib_barcode + "',:PIB_CUSTBARCODE,'" + CurrentZXBZ + "',pjd_brand,'" + Data["DATECODE"] + "','" + Data["LOTNO"] + "','" + pib_outboxcode2 + "','" + User.UserCode + "','" + (EnablePrint && SingleLabelAutoPrint.Checked ? 1 : 0).ToString() + "',pd_ordercode,pd_pocode ");
             sql.Append("from prodinout left join prodiodetail on pi_id=pd_piid left join PRODJOINVENDDETAIL on pjd_brand =pd_brand and pjd_prodcode=pd_prodcode where pi_id='" + PI_ID + "' and pd_prodcode='" + CurrentPrCode + "' and pd_pdno='" + CurrentPDNO + "'");
             dh.BatchInsert(sql.ToString(), new string[] { "PIB_ID", "PIB_CUSTBARCODE" }, PIBID, CustBarCode.ToArray());
             //更新流水号
-            dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum) + "'", "rmn_nrcode='" + pi_cardcode.Text + "' and rmn_prefix='" + Prefix + "'");
+            dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum + CodeCount) + "'", "rmn_nrcode='" + pi_cardcode.Text + "' and rmn_prefix='" + Prefix + "'");
             LoadGridData(new object(), new EventArgs());
             //加载完数据之后进行容量的判断
             int BoxNum = LabelInfDataTable.Select("pib_outboxcode2='" + OutBoxNum.Text + "'").Length;
@@ -440,37 +406,26 @@ namespace UAS_LabelMachine
         {
             if (EnablePrint)
             {
-                try
-                {
-                    if (SingleDoc.Variables.FreeVariables.Count == 0)
-                    {
-                        MessageBox.Show("单盘标签未维护参数", "提示");
-                        return;
-                    }
-                }
-                catch (Exception)
-                {
-                    MessageBox.Show("单盘标签未维护参数", "提示");
-                    return;
-                }
                 //用标签本身的变量作为最外层的循环条件去匹配;
-                string[] arg = SingleBoxArgument.ToArray();
                 StringBuilder ParamLog = new StringBuilder();
                 for (int i = 0; i < PIBID.Length; i++)
                 {
-                    //将维护的模板参数和模板本身的参数名称进行比对
-                    DataTable dt = (DataTable)dh.ExecuteSql(SingleSQL.ToLower().Replace("{pib_id}", "'" + PIBID[i] + "'"), "select");
-                    for (int k = 0; k < SingleLabelParam.Rows.Count; k++)
+                    for (int k = 0; k < Attach.Rows.Count; k++)
                     {
-                        string ParamName = SingleLabelParam.Rows[k]["lp_name"].ToString();
-                        SingleDoc.Variables.FreeVariables.Item(ParamName).Value = dt.Rows[0][k].ToString();
-                        ParamLog.AppendLine("pib_id:" + PIBID[i] + ",SingleDoc打印参数【" + SingleDoc.Variables.FreeVariables.Item(ParamName).Name + "】赋值," + "取到值" + SingleDoc.Variables.FreeVariables.Item(ParamName).Value);
+                        for (int j = 0; j < SingleReport.Parameters.Count; j++)
+                        {
+                            if (Attach.Rows[k][0].ToString() == SingleReport.Parameters[j].Name)
+                            {
+                                SingleReport.SetParameterValue(SingleReport.Parameters[j].Name, Attach.Rows[k][1].ToString());
+                            }
+                        }
                     }
-                    LogManager.DoLog(ParamLog.ToString());
-                    //保存参数打印
-                    Console.WriteLine(SingleDoc.Database.GetType());
-                    SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text);
-                    SingleDoc.PrintDocument();
+                    DataTable dt = (DataTable)dh.ExecuteSql("select * from prodiosingleinfo_view where 主键ID=" + PIBID[i], "select");
+                    SingleReport.RegisterData(dt, "prodiosingleinfo_view");
+                    SingleReport.GetDataSource("prodiosingleinfo_view").Enabled = true;
+                    SingleReport.PrintSettings.ShowDialog = false;
+                    SingleReport.PrintSettings.Printer = SingleLabelPrinter.Text;
+                    SingleReport.Print();
                     Properties.Settings.Default.SPrinter = SingleLabelPrinter.Text;
                     Properties.Settings.Default.Save();
                 }
@@ -509,8 +464,6 @@ namespace UAS_LabelMachine
             SingleLabelCombox.DisplayMember = "cl_labelname";
             SingleLabelCombox.ValueMember = "la_id";
             SingleLabelCombox.DataSource = dt;
-            if (SingleDoc != null)
-                SingleDoc.Close();
             if (!GetGridOnly.Checked)
                 for (int i = 0; i < dt.Rows.Count; i++)
                 {
@@ -523,37 +476,7 @@ namespace UAS_LabelMachine
                 }
             if (SingleLabelCombox.Text != "")
             {
-                SingleDoc = lbl.Documents.Open(ftpOperater.DownLoadTo + SingleLabelCombox.Text);
-                string ParamCondition = "";
-                for (int i = 0; i < SingleDoc.Variables.FreeVariables.Count; i++)
-                {
-                    if (i != SingleDoc.Variables.FreeVariables.Count - 1)
-                    {
-                        ParamCondition += "'" + SingleDoc.Variables.FreeVariables.Item(i + 1).Name + "',";
-                    }
-                    else
-                    {
-                        ParamCondition += "'" + SingleDoc.Variables.FreeVariables.Item(i + 1).Name + "'";
-                    }
-                }
-                SingleLabelParam = (DataTable)dh.ExecuteSql("select lp_name,lp_sql from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + SingleLabelCombox.SelectedValue.ToString().Split('#')[0] + " and lp_name in(" + ParamCondition + ") order by lp_detno", "select");
-                DataTable Attach = (DataTable)dh.ExecuteSql("select lap_param lp_name,lap_value lp_sql from LABELATTACHPARAMETER where lap_custcode='" + pi_cardcode.Text + "' and lap_param in(" + ParamCondition + ")", "select");
-                SingleSQL = "select * from ";
-                for (int i = 0; i < SingleLabelParam.Rows.Count; i++)
-                {
-                    if (i != SingleLabelParam.Rows.Count - 1 || Attach.Rows.Count > 0)
-                        SingleSQL += "(" + SingleLabelParam.Rows[i]["lp_sql"].ToString() + "),";
-                    else
-                        SingleSQL += "(" + SingleLabelParam.Rows[i]["lp_sql"].ToString() + ")";
-                }
-                for (int i = 0; i < Attach.Rows.Count; i++)
-                {
-                    if (i != Attach.Rows.Count - 1)
-                        SingleSQL += "(select '" + Attach.Rows[i]["lp_sql"].ToString() + "' from dual),";
-                    else
-                        SingleSQL += "(select '" + Attach.Rows[i]["lp_sql"].ToString() + "' from dual)";
-                }
-                SingleLabelParam.Merge(Attach);
+                SingleReport.Load(@"F:/Simple List.frx");
             }
             sql.Clear();
             sql.Append("select to_char(nvl(cl_date,sysdate),'YYYY-MM-DD HH24:Mi:SS') cl_date,cl_labelname,cl_isdefault,la_id||'#'||cl_labelurl||'#'||to_char(cl_date,'YYYY-MM-DD HH24:Mi:SS')  la_id,cl_custcode from customerlabel left join prodinout on pi_cardcode=cl_custcode ");
@@ -563,8 +486,6 @@ namespace UAS_LabelMachine
             MidLabelCombox.DisplayMember = "cl_labelname";
             MidLabelCombox.ValueMember = "la_id";
             MidLabelCombox.DataSource = dt;
-            if (MidDoc != null)
-                MidDoc.Close();
             if (!GetGridOnly.Checked)
                 for (int i = 0; i < dt.Rows.Count; i++)
                 {
@@ -577,37 +498,7 @@ namespace UAS_LabelMachine
                 }
             if (MidLabelCombox.Text != "")
             {
-                MidDoc = lbl.Documents.Open(ftpOperater.DownLoadTo + MidLabelCombox.Text);
-                string ParamCondition = "";
-                for (int i = 0; i < MidDoc.Variables.FreeVariables.Count; i++)
-                {
-                    if (i != MidDoc.Variables.FreeVariables.Count - 1)
-                    {
-                        ParamCondition += "'" + MidDoc.Variables.FreeVariables.Item(i + 1).Name + "',";
-                    }
-                    else
-                    {
-                        ParamCondition += "'" + MidDoc.Variables.FreeVariables.Item(i + 1).Name + "'";
-                    }
-                }
-                MidLabelParam = (DataTable)dh.ExecuteSql("select lp_name,lp_sql from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + MidLabelCombox.SelectedValue.ToString().Split('#')[0] + " and lp_name in(" + ParamCondition + ")  order by lp_detno", "select");
-                DataTable Attach = (DataTable)dh.ExecuteSql("select lap_param lp_name,lap_value lp_sql from LABELATTACHPARAMETER where lap_custcode='" + pi_cardcode.Text + "' and lap_param in(" + ParamCondition + ")", "select");
-                MidSQL = "select * from ";
-                for (int i = 0; i < MidLabelParam.Rows.Count; i++)
-                {
-                    if (i != MidLabelParam.Rows.Count - 1 || Attach.Rows.Count > 0)
-                        MidSQL += "(" + MidLabelParam.Rows[i]["lp_sql"].ToString() + "),";
-                    else
-                        MidSQL += "(" + MidLabelParam.Rows[i]["lp_sql"].ToString() + ")";
-                }
-                for (int i = 0; i < Attach.Rows.Count; i++)
-                {
-                    if (i != Attach.Rows.Count - 1)
-                        MidSQL += "(select '" + Attach.Rows[i]["lp_sql"].ToString() + "' from dual),";
-                    else
-                        MidSQL += "(select '" + Attach.Rows[i]["lp_sql"].ToString() + "' from dual)";
-                }
-                MidLabelParam.Merge(Attach);
+                MidReport.Load(@"F:/Simple List.frx");
             }
             //缓存中盒参数
             sql.Clear();
@@ -618,8 +509,6 @@ namespace UAS_LabelMachine
             OutBoxCombox.DisplayMember = "cl_labelname";
             OutBoxCombox.ValueMember = "la_id";
             OutBoxCombox.DataSource = dt;
-            if (OutBoxDoc != null)
-                OutBoxDoc.Close();
             if (!GetGridOnly.Checked)
                 for (int i = 0; i < dt.Rows.Count; i++)
                 {
@@ -632,46 +521,7 @@ namespace UAS_LabelMachine
                 }
             if (OutBoxCombox.Text != "")
             {
-                if (OutBoxCombox.Text.Substring(OutBoxCombox.Text.LastIndexOf(".") + 1).ToLower() == "frx")
-                {
-                    OutLabelType = "FastReport";
-                    OutReport.Load(ftpOperater.DownLoadTo + OutBoxCombox.Text);
-                }
-                else
-                {
-                    OutLabelType = "CodeSoft";
-                    OutBoxDoc = lbl.Documents.Open(ftpOperater.DownLoadTo + OutBoxCombox.Text);
-                    string ParamCondition = "";
-                    for (int i = 0; i < OutBoxDoc.Variables.FreeVariables.Count; i++)
-                    {
-                        if (i != OutBoxDoc.Variables.FreeVariables.Count - 1)
-                        {
-                            ParamCondition += "'" + OutBoxDoc.Variables.FreeVariables.Item(i + 1).Name + "',";
-                        }
-                        else
-                        {
-                            ParamCondition += "'" + OutBoxDoc.Variables.FreeVariables.Item(i + 1).Name + "'";
-                        }
-                    }
-                    OutLabelParam = (DataTable)dh.ExecuteSql("select lp_name,lp_sql from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + OutBoxCombox.SelectedValue.ToString().Split('#')[0] + " and lp_name in(" + ParamCondition + ")  order by lp_detno", "select");
-                    DataTable Attach = (DataTable)dh.ExecuteSql("select lap_param lp_name,lap_value lp_sql from LABELATTACHPARAMETER where lap_custcode='" + pi_cardcode.Text + "' and lap_param in(" + ParamCondition + ")", "select");
-                    OutSQL = "select * from ";
-                    for (int i = 0; i < OutLabelParam.Rows.Count; i++)
-                    {
-                        if (i != OutLabelParam.Rows.Count - 1 || Attach.Rows.Count > 0)
-                            OutSQL += "(" + OutLabelParam.Rows[i]["lp_sql"].ToString() + "),";
-                        else
-                            OutSQL += "(" + OutLabelParam.Rows[i]["lp_sql"].ToString() + ")";
-                    }
-                    for (int i = 0; i < Attach.Rows.Count; i++)
-                    {
-                        if (i != Attach.Rows.Count - 1)
-                            OutSQL += "(select '" + Attach.Rows[i]["lp_sql"].ToString() + "' from dual),";
-                        else
-                            OutSQL += "(select '" + Attach.Rows[i]["lp_sql"].ToString() + "' from dual)";
-                    }
-                    OutLabelParam.Merge(Attach);
-                }
+                OutReport.Load(@"F:/Simple List.frx");
             }
             if (!File.Exists(ftpOperater.DownLoadTo + "唛头.lab"))
             {
@@ -711,9 +561,6 @@ namespace UAS_LabelMachine
                     LoadGridData(sender, e);
                     //获取条码规则
                     GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix);
-                    //重新输入单号后清除缓存
-                    MidBoxArgument.Clear();
-                    SingleBoxArgument.Clear();
                     SingleID.Clear();
                     Input.Focus();
                     //从后往前找未采集的行
@@ -742,20 +589,7 @@ namespace UAS_LabelMachine
         {
             if (EnablePrint)
             {
-                try
-                {
-                    if (SingleDoc.Variables.FreeVariables.Count == 0)
-                    {
-                        MessageBox.Show("单盘标签未维护参数", "提示");
-                        return;
-                    }
-                }
-                catch (Exception)
-                {
-                    MessageBox.Show("单盘标签未维护参数", "提示");
-                    return;
-                }
-                if (SingleLabelParam.Rows.Count > 0 && LabelInf.Rows.Count > 0)
+                if (LabelInf.Rows.Count > 0)
                 {
                     //每次打印清除之前缓存的行号和ID,后面会判断需要打印的数据重新加载
                     SingleID.Clear();
@@ -787,34 +621,33 @@ namespace UAS_LabelMachine
                     }
                     //用于判断用户是否勾选了行
                     int CheckedRowCount = 0;
-                    string[] arg = SingleBoxArgument.ToArray();
                     for (int i = 0; i < LabelInf.RowCount; i++)
                     {
                         //勾选了并且未打印
                         if (LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString().ToLower() == "true" && LabelInf.Rows[i].Cells["pib_ifprint"].FormattedValue.ToString().ToLower() != "true")
                         {
-                            CheckedRowCount = CheckedRowCount + 1;
-                            //以标签模板的参数为基准,循环取数
-                            try
+                            for (int k = 0; k < Attach.Rows.Count; k++)
                             {
-                                string pib_id = LabelInf.Rows[i].Cells["pib_id1"].Value.ToString();
-                                DataTable dt = (DataTable)dh.ExecuteSql(SingleSQL.ToLower().Replace("{pib_id}", "'" + pib_id + "'"), "select");
-                                StringBuilder ParamLog = new StringBuilder();
-                                for (int k = 0; k < SingleLabelParam.Rows.Count; k++)
+                                for (int j = 0; j < SingleReport.Parameters.Count; j++)
                                 {
-                                    string ParamName = SingleLabelParam.Rows[k]["lp_name"].ToString();
-                                    SingleDoc.Variables.FreeVariables.Item(ParamName).Value = dt.Rows[0][k].ToString();
-                                    ParamLog.AppendLine("pib_id:" + pib_id + ",SingleDoc打印参数【" + SingleDoc.Variables.FreeVariables.Item(ParamName).Name + "】赋值," + "取到值" + SingleDoc.Variables.FreeVariables.Item(ParamName).Value);
+                                    if (Attach.Rows[k][0].ToString() == SingleReport.Parameters[j].Name)
+                                    {
+                                        SingleReport.SetParameterValue(SingleReport.Parameters[j].Name, Attach.Rows[k][1].ToString());
+                                    }
                                 }
-                                LogManager.DoLog(ParamLog.ToString());
-                                //保存参数打印
-                                SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text);
-                                SingleDoc.PrintDocument();
-                                Properties.Settings.Default.SPrinter = SingleLabelPrinter.Text;
-                                Properties.Settings.Default.Save();
-                                LabelInf.Rows[i].Cells["pib_ifprint"].Value = true;
                             }
-                            catch (Exception ex) { LogManager.DoLog(ex.StackTrace); }
+                            CheckedRowCount = CheckedRowCount + 1;
+                            string pib_id = LabelInf.Rows[i].Cells["pib_id1"].Value.ToString();
+                            DataTable dt = (DataTable)dh.ExecuteSql("select * from prodiosingleinfo_view where 主键ID=" + pib_id, "select");
+                            SingleReport.RegisterData(dt, "prodiosingleinfo_view");
+                            SingleReport.GetDataSource("prodiosingleinfo_view").Enabled = true;
+                            //保存参数打印
+                            SingleReport.PrintSettings.ShowDialog = false;
+                            SingleReport.PrintSettings.Printer = SingleLabelPrinter.Text;
+                            SingleReport.Print();
+                            Properties.Settings.Default.SPrinter = SingleLabelPrinter.Text;
+                            Properties.Settings.Default.Save();
+                            LabelInf.Rows[i].Cells["pib_ifprint"].Value = true;
                         }
                     }
                     LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "手动打印箱标", "打印成功");
@@ -916,23 +749,29 @@ namespace UAS_LabelMachine
                         return;
                     }
                 }
-                MidBoxArgument.Clear();
                 List<int> MidOutBoxCode = new List<int>();
                 List<int> MidOutBoxCodeIndex = new List<int>();
                 string la_id = MidLabelCombox.SelectedValue.ToString().Split('#')[0];
                 for (int i = (begin == 0 ? 0 : begin); i <= (end == 0 ? LabelInf.Rows.Count - 1 : end); i++)
                 {
-                    if (!MidOutBoxCode.Contains(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())))
+                    try
+                    {
+                        if (!MidOutBoxCode.Contains(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())))
+                        {
+                            MidOutBoxCode.Add(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()));
+                            MidOutBoxCodeIndex.Add(i);
+                        }
+                    }
+                    catch (Exception)
                     {
-                        MidOutBoxCode.Add(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()));
-                        MidOutBoxCodeIndex.Add(i);
+                        MessageBox.Show("请先封箱!");
+                        return;
                     }
                 }
                 for (int i = 0; i < MidOutBoxCodeIndex.Count; i++)
                 {
                     MidBoxCodePrint(la_id, MidOutBoxCodeIndex[i]);
                 }
-                MidBoxArgument.Clear();
                 return;
             }
             bool FindMidLabel = false;
@@ -943,8 +782,6 @@ namespace UAS_LabelMachine
                 string LabelUrl = dh.getFieldDataByCondition("label left join customerlabel on la_code=cl_labelcode", "cl_labelurl", "la_id='" + la_id + "' and cl_labelname='" + cl_labelname + "'").ToString();
                 //中盒号所在的行
                 int MidLabelRowIndex = 0;
-                //查找是否存在该中盒号
-                List<int> MidRowIndex = new List<int>();
                 //缓存中盒数据
                 for (int i = 0; i < LabelInf.RowCount; i++)
                 {
@@ -953,12 +790,11 @@ namespace UAS_LabelMachine
                         //找到了输入的中盒号停止循环
                         FindMidLabel = true;
                         MidLabelRowIndex = i;
-                        MidRowIndex.Add(i);
                     }
                 }
                 //找到了指定的盒号
                 if (FindMidLabel)
-                    MidBoxCodePrint(la_id, MidLabelRowIndex, MidRowIndex.ToArray());
+                    MidBoxCodePrint(la_id, MidLabelRowIndex);
                 else
                     MessageBox.Show("该出入库单未找到该中盒号!", "提示");
             }
@@ -990,11 +826,14 @@ namespace UAS_LabelMachine
             {
                 for (int i = 0; i < LabelInf.RowCount; i++)
                 {
-                    string outboxcode2 = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString();
-                    //富为使用包装单的逻辑
-                    //如果不包含该箱号则进行添加
-                    if (!Outboxcode.Contains(outboxcode2))
-                        Outboxcode.Add(outboxcode2);
+                    if (LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString().ToLower() == "true")
+                    {
+                        string outboxcode2 = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString();
+                        //富为使用包装单的逻辑
+                        //如果不包含该箱号则进行添加
+                        if (!Outboxcode.Contains(outboxcode2))
+                            Outboxcode.Add(outboxcode2);
+                    }
                 }
                 //按获取到的箱号列表进行打印
                 if (Outboxcode.ToArray().Length > 0)
@@ -1053,47 +892,24 @@ namespace UAS_LabelMachine
         {
             if (EnablePrint)
             {
-                string[] arg = MidBoxArgument.ToArray();
-                //将维护的模板参数和模板本身的参数名称进行比对
-                for (int k = 0; k < MidLabelParam.Rows.Count; k++)
-                {
-                    //名称相等的时候,取SQL进行值的查询
-                    string ParamName = MidLabelParam.Rows[k]["lp_name"].ToString();
-                    string pib_id = LabelInf.Rows[rowindex].Cells["pib_id1"].Value.ToString();
-                    string pib_outboxcode1 = LabelInf.Rows[rowindex].Cells["pib_outboxcode1"].Value.ToString();
-                    DataTable dt = (DataTable)dh.ExecuteSql(MidSQL.ToLower().Replace("{pib_id}", pib_id).Replace("{pib_outboxcode1}", pib_outboxcode1), "select");
-                    //获取打印执行的SQL
-                    MidDoc.Variables.FreeVariables.Item(ParamName).Value = dt.Rows[0][k].ToString();
-                    LogManager.DoLog("打印参数【" + MidDoc.Variables.FreeVariables.Item(ParamName).Name + "】赋值," + ",取到值" + MidDoc.Variables.FreeVariables.Item(ParamName).Value);
-                }
-                //保存参数打印
-                MidDoc.Printer.SwitchTo(MidLabelPrinter.Text);
-                MidDoc.PrintDocument();
-                Properties.Settings.Default.MPrinter = MidLabelPrinter.Text;
-                Properties.Settings.Default.Save();
-            }
-        }
-
-        private void MidBoxCodePrint(string la_id, int rowindex, int[] midindex)
-        {
-            if (EnablePrint)
-            {
-                //将维护的模板参数和模板本身的参数名称进行比对
-                for (int k = 0; k < MidLabelParam.Rows.Count; k++)
+                for (int i = 0; i < Attach.Rows.Count; i++)
                 {
-                    //名称相等的时候,取SQL进行值的查询
-                    string ParamName = MidLabelParam.Rows[k]["lp_name"].ToString();
-                    string pib_id = LabelInf.Rows[rowindex].Cells["pib_id1"].Value.ToString();
-                    string pib_outboxcode1 = LabelInf.Rows[rowindex].Cells["pib_outboxcode1"].Value.ToString();
-                    DataTable dt = (DataTable)dh.ExecuteSql(MidSQL.ToLower().Replace("{pib_id}", pib_id).Replace("{pib_outboxcode1}", pib_outboxcode1), "select");
-                    //获取打印执行的SQL
-                    MidDoc.Variables.FreeVariables.Item(ParamName).Value = dt.Rows[0][k].ToString();
-                    LogManager.DoLog("打印参数【" + MidDoc.Variables.FreeVariables.Item(ParamName).Name + "】赋值" + ",取到值" + MidDoc.Variables.FreeVariables.Item(ParamName).Value);
+                    for (int j = 0; j < MidReport.Parameters.Count; j++)
+                    {
+                        if (Attach.Rows[i][0].ToString() == MidReport.Parameters[j].Name)
+                        {
+                            MidReport.SetParameterValue(MidReport.Parameters[j].Name, Attach.Rows[i][1].ToString());
+                        }
+                    }
                 }
-                //保存参数打印
-
-                MidDoc.Printer.SwitchTo(MidLabelPrinter.Text);
-                MidDoc.PrintDocument();
+                //名称相等的时候,取SQL进行值的查询
+                string pib_id = LabelInf.Rows[rowindex].Cells["pib_id1"].Value.ToString();
+                string pib_outboxcode1 = LabelInf.Rows[rowindex].Cells["pib_outboxcode1"].Value.ToString();
+                DataTable dt = (DataTable)dh.ExecuteSql("select * from prodiobarcode where pib_id=" + pib_id, "select");
+                MidReport.RegisterData(dt, "Prodiobarcode");
+                MidReport.GetDataSource("Prodiobarcode").Enabled = true;
+                MidReport.PrintSettings.Printer = MidLabelPrinter.Text;
+                MidReport.Print();
                 Properties.Settings.Default.MPrinter = MidLabelPrinter.Text;
                 Properties.Settings.Default.Save();
             }
@@ -1106,64 +922,36 @@ namespace UAS_LabelMachine
         {
             if (EnablePrint)
             {
-                try
+                for (int i = 0; i < Attach.Rows.Count; i++)
                 {
-                    string pib_id = LabelInf.Rows[rowindex].Cells["pib_id1"].Value.ToString();
-                    string pib_outboxcode2 = LabelInf.Rows[rowindex].Cells["pib_outboxcode2"].Value.ToString();
-                    if (OutLabelType == "CodeSoft")
+                    for (int j = 0; j < OutReport.Parameters.Count; j++)
                     {
-                        //将维护的模板参数和模板本身的参数名称进行比对
-                        DataTable dt = (DataTable)dh.ExecuteSql(OutSQL.ToLower().Replace("{pib_id}", "'" + pib_id + "'").Replace("{pib_outboxcode2}", "'" + pib_outboxcode2 + "'"), "select");
-                        for (int k = 0; k < OutLabelParam.Rows.Count; k++)
+                        if (Attach.Rows[i][0].ToString() == OutReport.Parameters[j].Name)
                         {
-                            //获取对应行的pib_id
-                            string ParamName = OutLabelParam.Rows[k]["lp_name"].ToString();
-                            OutBoxDoc.Variables.FreeVariables.Item(ParamName).Value = dt.Rows[0][k].ToString();
-                            LogManager.DoLog("打印参数【" + OutBoxDoc.Variables.FreeVariables.Item(ParamName).Name + "】赋值" + ",取到值" + OutBoxDoc.Variables.FreeVariables.Item(ParamName).Value);
+                            OutReport.SetParameterValue(OutReport.Parameters[j].Name, Attach.Rows[i][1].ToString());
                         }
-                        //保存参数打印
-                        OutBoxDoc.Printer.SwitchTo(OutBoxPrinter.Text);
-                        OutBoxDoc.PrintDocument();
-                        Properties.Settings.Default.OPrinter = OutBoxPrinter.Text;
-                        Properties.Settings.Default.Save();
-                        LogManager.DoLog("执行打印外箱,pib_id:" + LabelInf.Rows[rowindex].Cells["pib_id1"].Value.ToString());
-                        LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "手动打印外箱箱标", "打印成功");
                     }
-                    else if (OutLabelType == "FastReport")
+                }
+                DataTable dt = (DataTable)dh.ExecuteSql("select * from prodiooutinfo_view where 出货单号='" + pi_inoutno.Text + "' and 外箱号='" + pib_outboxcode2 + "'", "select");
+                DataTable dt1 = dt.Clone();
+                for (int i = 0; i < dt.Rows.Count; i++)
+                {
+                    DataRow dr = dt1.NewRow();
+                    for (int j = 0; j < dt.Columns.Count; j++)
                     {
-                        for (int i = 0; i < Attach.Rows.Count; i++)
-                        {
-                            for (int j = 0; j < OutReport.Parameters.Count; j++)
-                            {
-                                if (Attach.Rows[i][0].ToString() == OutReport.Parameters[j].Name)
-                                {
-                                    OutReport.SetParameterValue(OutReport.Parameters[j].Name, Attach.Rows[i][1].ToString());
-                                }
-                            }
-                        }
-                        DataTable dt = (DataTable)dh.ExecuteSql("select * from prodioinfo_view where 出货单号='" + pi_inoutno.Text + "' and 外箱号='" + pib_outboxcode2 + "'", "select");
-                        DataTable dt1 = dt.Clone();
-                        for (int i = 0; i < dt.Rows.Count; i++)
-                        {
-                            DataRow dr = dt1.NewRow();
-                            for (int j = 0; j < dt.Columns.Count; j++)
-                            {
-                                dr[j] = dt.Rows[i][j].ToString();
-                            }
-                            dt1.Rows.Add(dr);
-                            if ((i + 1) % 5 == 0 || (i + 1) == dt.Rows.Count)
-                            {
-                                OutReport.RegisterData(dt1, "prodioinfo_view");
-                                OutReport.GetDataSource("prodioinfo_view").Enabled = true;
-                                OutReport.PrintSettings.ShowDialog = false;
-                                OutReport.PrintSettings.Printer = OutBoxPrinter.Text;
-                                OutReport.Print();
-                                BaseUtil.CleanDataTableData(dt1);
-                            }
-                        }
+                        dr[j] = dt.Rows[i][j].ToString();
+                    }
+                    dt1.Rows.Add(dr);
+                    if ((i + 1) % 5 == 0 || (i + 1) == dt.Rows.Count)
+                    {
+                        OutReport.RegisterData(dt1, "prodiooutinfo_view");
+                        OutReport.GetDataSource("prodiooutinfo_view").Enabled = true;
+                        OutReport.PrintSettings.ShowDialog = false;
+                        OutReport.PrintSettings.Printer = OutBoxPrinter.Text;
+                        OutReport.Print();
+                        BaseUtil.CleanDataTableData(dt1);
                     }
                 }
-                catch (Exception ex) { MessageBox.Show(ex.Message, "提示"); }
             }
         }
 
@@ -1307,13 +1095,7 @@ namespace UAS_LabelMachine
             {
                 if (ComBoxClickChangeLabelDoc)
                 {
-                    if (SingleDoc != null)
-                        SingleDoc.Close();
-                    if (SingleLabelCombox.Text != "" && SingleLabelCombox.SelectedValue != null && !GetGridOnly.Checked)
-                    {
-                        System.DateTime time = Convert.ToDateTime(SingleLabelCombox.SelectedValue.ToString().Split('#')[2]);
-                        SingleDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(SingleLabelCombox.SelectedValue.ToString().Split('#')[1], SingleLabelCombox.Text, time));
-                    }
+
                 }
             }
             catch (Exception) { }
@@ -1330,13 +1112,7 @@ namespace UAS_LabelMachine
             {
                 if (ComBoxClickChangeLabelDoc)
                 {
-                    if (MidDoc != null)
-                        MidDoc.Close();
-                    if (MidLabelCombox.Text != "" && MidLabelCombox.SelectedValue != null && !GetGridOnly.Checked)
-                    {
-                        System.DateTime time = Convert.ToDateTime(MidLabelCombox.SelectedValue.ToString().Split('#')[2]);
-                        MidDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(MidLabelCombox.SelectedValue.ToString().Split('#')[1], MidLabelCombox.Text, time));
-                    }
+
                 }
             }
             catch (Exception) { }
@@ -1353,13 +1129,7 @@ namespace UAS_LabelMachine
             {
                 if (ComBoxClickChangeLabelDoc)
                 {
-                    if (OutBoxDoc != null)
-                        OutBoxDoc.Close();
-                    if (OutBoxCombox.Text != "" && OutBoxCombox.SelectedValue != null && !GetGridOnly.Checked)
-                    {
-                        System.DateTime time = Convert.ToDateTime(OutBoxCombox.SelectedValue.ToString().Split('#')[2]);
-                        OutBoxDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(OutBoxCombox.SelectedValue.ToString().Split('#')[1], OutBoxCombox.Text, time));
-                    }
+
                 }
             }
             catch (Exception) { }
@@ -1736,7 +1506,6 @@ namespace UAS_LabelMachine
             {
                 //生成中盒条码
                 int pib_outboxcode1 = 0;
-                CurrentMaxNum = CurrentMaxNum - 1;
                 for (int i = 0; i < dt.Rows.Count; i++)
                 {
                     List<string> MidBoxCode = new List<string>();
@@ -1746,7 +1515,7 @@ namespace UAS_LabelMachine
                     //如果不是10的整数倍则为尾盒
                     for (int j = 0; j < dt1.Rows.Count; j++)
                     {
-                        if (j % 10 == 0)
+                        if (j % 10 == 0 && j != 0)
                         {
                             pib_outboxcode1 = pib_outboxcode1 + 1;
                             CurrentMaxNum = CurrentMaxNum + 1;
@@ -1768,14 +1537,14 @@ namespace UAS_LabelMachine
                 {
                     List<string> OutBoxCode = new List<string>();
                     List<string> PIBOUTBOXCODE2 = new List<string>();
-                    string serialcode = BaseUtil.DToAny(CurrentMaxNum, Radix);
+                    string serialcode = BaseUtil.DToAny(MaxNum, Radix);
                     for (int k = serialcode.ToString().Length; k < NumLength; k++)
                     {
                         serialcode = "0" + serialcode;
                     }
                     OutBoxCode.Add(Prefix + serialcode + Suffix);
                     PIBOUTBOXCODE2.Add(dt.Rows[i]["pib_outboxcode2"].ToString());
-                    CurrentMaxNum = CurrentMaxNum + 1;
+                    MaxNum = MaxNum + 1;
                     dh.BatchInsert("update prodiobarcode set pib_custoutboxcode=:pib_custoutboxcode where pib_outboxcode2=:pib_outboxcode2 and pib_custoutboxcode is null", new string[] { "pib_custoutboxcode", "pib_outboxcode2" }, OutBoxCode.ToArray(), PIBOUTBOXCODE2.ToArray());
                 }
                 dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + CurrentMaxNum + "'", "rmn_nrcode='" + pi_cardcode.Text + "' and rmn_prefix='" + Prefix + "'");