瀏覽代碼

自定义打标打印按钮,补打界面调整

shim 8 年之前
父節點
當前提交
69eb0f4d88
共有 2 個文件被更改,包括 56 次插入6 次删除
  1. 54 6
      UAS-MES/FunctionCode/Make/Make_CustomLabelPrint.cs
  2. 2 0
      UAS-MES/FunctionCode/Make/Make_RePrintLabel.cs

+ 54 - 6
UAS-MES/FunctionCode/Make/Make_CustomLabelPrint.cs

@@ -47,6 +47,8 @@ namespace UAS_MES.Make
         StringBuilder sb = new StringBuilder();
 
         bool canPrint = false;
+
+        string[] inputValues;//存放用户输入的参数值
         public Make_CustomLabelPrint()
         {
             InitializeComponent();
@@ -138,9 +140,11 @@ namespace UAS_MES.Make
                 }
                 else
                 {
-                    if (doc==null) {
-                        OperateResult.AppendText(">>无可用标签\n", Color.Red,inputText);
-                        return;
+                    //下标为1的时候实例化存值的数组
+                    if (currentIndex==1) {
+                        inputValues = new string[paramsInfo.Rows.Count];
+                        sb = new StringBuilder();
+                        doc = lbl.Documents.Open(ftpOperater.DownLoadTo + listA.Rows[PrintLabel.SelectedIndex]["pl_labelname"].ToString());
                     }
                     //将值赋到doc对应的变量
                     for (int i = 0; i < doc.Variables.FormVariables.Count; i++)
@@ -161,6 +165,7 @@ namespace UAS_MES.Make
                                 doc.Variables.FormVariables.Item(i + 1).Value = dh.GetLabelParam(sql).ToString();
                                 sb.AppendLine("打印参数【" + doc.Variables.FormVariables.Item(i + 1).Name + "】赋值," + "取值SQL:" + sql + ",取到值" + doc.Variables.FormVariables.Item(i + 1).Value);
                             }
+                            inputValues[currentIndex - 1] = inputText.Text;
                         }
                     }
                     if (currentIndex == paramsInfo.Rows.Count)
@@ -182,7 +187,6 @@ namespace UAS_MES.Make
                         //重置currenIndex为1
                         currentIndex = 1;
                         OperateResult.AppendText(">>请输入自定义模板的" + paramsInfo.Rows[0]["lp_name"].ToString() + "\n", Color.Black);
-                        doc=lbl.Documents.Open(ftpOperater.DownLoadTo + listA.Rows[PrintLabel.SelectedIndex]["pl_labelname"].ToString());
                     }
                     else
                     {
@@ -223,7 +227,7 @@ namespace UAS_MES.Make
                 {
                     doc.Close();
                 }
-                doc = lbl.Documents.Open(ftpOperater.DownLoadTo + listA.Rows[PrintLabel.SelectedIndex]["pl_labelname"].ToString());
+                //doc = lbl.Documents.Open(ftpOperater.DownLoadTo + listA.Rows[PrintLabel.SelectedIndex]["pl_labelname"].ToString());
                 currentIndex = 1;
                 //聚焦输入框
                 inputText.Focus();
@@ -259,7 +263,51 @@ namespace UAS_MES.Make
 
         private void printButton_Click(object sender, EventArgs e)
         {
-
+            if (canPrint)
+            {
+                doc = lbl.Documents.Open(ftpOperater.DownLoadTo + listA.Rows[PrintLabel.SelectedIndex]["pl_labelname"].ToString());
+                sb = new StringBuilder();
+                //将值赋到doc对应的变量
+                for (int i = 0; i < doc.Variables.FormVariables.Count; i++)
+                {
+                    for (int j = 0; j < paramsInfo.Rows.Count; j++)
+                    {
+                        //找到对应的变量名
+                        if (doc.Variables.FormVariables.Item(i + 1).Name == paramsInfo.Rows[j]["lp_name"].ToString())
+                        {
+                            //如果当时采集行的 lp_valuetype=’INPUT’,并且lp_sql 为空,则直接将采集的值赋给标签打印
+                            if (paramsInfo.Rows[j]["lp_valuetype"].ToString() == "INPUT" && paramsInfo.Rows[j]["lp_sql"].ToString() == "")
+                            {
+                                doc.Variables.FormVariables.Item(i + 1).Value = inputValues[j];
+                            }
+                            else
+                            {
+                                //取sql拿值赋给变量
+                                string sql = paramsInfo.Rows[j]["lp_sql"].ToString();
+                                sql = sql.Substring(0, sql.IndexOf("{")) + "'" + inputValues[j] + "'";
+                                doc.Variables.FormVariables.Item(i + 1).Value = dh.GetLabelParam(sql).ToString();
+                                sb.AppendLine("打印参数【" + doc.Variables.FormVariables.Item(i + 1).Name + "】赋值," + "取值SQL:" + sql + ",取到值" + doc.Variables.FormVariables.Item(i + 1).Value);
+                            }
+                        }
+                    }
+                }
+                //打印
+                LogManager.DoLog(sb.ToString());
+                //保存本次赋值进行打印
+                doc.Save();
+                doc.Printer.SwitchTo(Printer.Text);
+                doc.PrintDocument(int.Parse(printNum.Text));
+                doc.Close();
+                //讲文件最后写入时间改成数据库中拿到的时间
+                info = new FileInfo(ftpOperater.DownLoadTo + PrintLabel.Text.Split(':')[1]);
+                info.LastWriteTime = indate[PrintLabel.SelectedIndex];
+                //打印成功
+                OperateResult.AppendText("<<打印成功\n", Color.Green);
+            }
+            else
+            {
+                OperateResult.AppendText("<<标签参数未全部输入完成\n", Color.Red);
+            }
         }
     }
 }

+ 2 - 0
UAS-MES/FunctionCode/Make/Make_RePrintLabel.cs

@@ -226,6 +226,7 @@ namespace UAS_MES.Make
                 }
                 //判定通过进行打印
                 //按照打印张数打印
+                OperateResult.AppendText("<<打印成功\n", Color.Green);
                 Print.CodeSoft(lbl, PrintLabel.Text.Split(':')[1], PrintLabel.SelectedValue.ToString(), Printer.Text, inputValue.Text, int.Parse(printNum.Text), indate[PrintLabel.SelectedIndex]);
                 //打印成功,记录日志commandlog , cl_operate彩盒或者机身标补打印,cl_result补打印成功
                 LogicHandler.DoCommandLog(User.UserCode, "", User.UserLineCode, User.UserSourceCode, giftBox.Checked?"彩盒标补打印":"机身标补打印", "补打印成功", inputValue.Text, "");
@@ -248,6 +249,7 @@ namespace UAS_MES.Make
                     return;
                 }
                 //判断通过,打印
+                OperateResult.AppendText("<<打印成功\n", Color.Green);
                 Print.CodeSoft(lbl, PrintLabel.Text.Split(':')[1], PrintLabel.SelectedValue.ToString(), Printer.Text, inputValue.Text, int.Parse(printNum.Text), indate[PrintLabel.SelectedIndex]);
                 //打印成功,记录日志commandlog , cl_operate彩盒或者机身标补打印,cl_result补打印成功
                 LogicHandler.DoCommandLog(User.UserCode, "", User.UserLineCode, User.UserSourceCode, "卡通箱标签补打印,箱号:"+ inputValue.Text, "补打印成功","", "");