Пример #1
0
        public static void printCustomMaterial(string filename, string customMaterial)
        {
            if (labApp == null)
            {
                initCodeSoft();
            }

            try
            {
                string labFileName = @"D:\printLab\" + filename;
                if (!File.Exists(labFileName))
                {
                    MessageBox.Show("沒有找到標簽模板文件:" + labFileName + ",請聯系系統管理員", "溫馨提示");
                    return;
                }
                labApp.Documents.Open(labFileName, false);// 调用设计好的label文件
                if (doc != null)
                {
                    doc.Close();
                    doc = null;
                }
                doc = labApp.ActiveDocument;
                doc.Printer.SwitchTo("codesoft");//打印机名字,自定义,可以修改

                doc.Variables.FormVariables.Item("BAR").Value = customMaterial;
                doc.PrintDocument(); //打印一次
                doc.FormFeed();      //结束打印
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Пример #2
0
        private static void Print(PrintTask task)
        {
            LabelManager2.ApplicationClass lbl = new LabelManager2.ApplicationClass();

            lbl.Documents.Open(XmlTool.Read("Root/Printaddress") + @"\" + XmlTool.Read("Root/PrintLabName"), true);//调用设计好的label文件

            try
            {
                LabelManager2.Document doc = lbl.ActiveDocument;

                doc.Variables.FormVariables.Item("code").Value = task.Code;

                doc.Variables.FormVariables.Item("name").Value = task.Name;

                doc.Variables.FormVariables.Item("boxId").Value = task.Boxid;

                doc.Variables.FormVariables.Item("sum").Value = task.Sum;

                doc.PrintDocument(2);                                              //打印
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                lbl.Documents.CloseAll(true);
                lbl.Quit();
            }
        }
Пример #3
0
        private bool LoadLabel()
        {
            try
            {
                _loadedDocument?.Close();


                _loadedDocument = CsApp.Documents.Open(_fileLabelTemplatePath);
                switch (_labelType)
                {
                case LabelType.Individual:
                    LoadIndividualVariables();
                    break;

                case LabelType.Group:
                    LoadGroupLable();
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                if (CsApp.Documents.Count > 0)
                {
                    NoDocOpened = false;
                    return(true);
                }

                return(false);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #4
0
 public void Close()
 {
     server.Documents.CloseAll();
     server.Quit();
     doc    = null;
     server = null;
 }
Пример #5
0
        public static LabelManager2.Application labApp = null;//new LabelManager2.Application();


        public static void initCodesoftModel(string codesoftmodelname)
        {
            if (labApp == null)
            {
                labApp = new LabelManager2.Application();
            }

            if (POD != null)
            {
                POD.Close();
            }

            string labFileName = CodeSoftPath + codesoftmodelname.Replace("Model", "") + ".Lab";

            try
            {
                if (!File.Exists(labFileName))
                {
                    MessageBox.Show("沒有找到標簽模板文件:" + codesoftmodelname.Replace("Model", "") + ".Lab     請聯系系統管理員", "溫馨提示");
                    return;
                }
                labApp.Documents.Open(labFileName, false);// 调用设计好的label文件
                POD = labApp.ActiveDocument;
            }
            catch
            {
            }
            finally
            {
            }
        }
Пример #6
0
        /// <summary>
        /// 加载标签文档
        /// </summary>
        private void LoadLppx(string strHead, string startSn, string Productname, int printNum)
        {
            string mdl = string.Empty;

            if (this.rb_printmodel1.Checked)
            {
                mdl = "SFCSN1.lab";
            }
            else
            {
                mdl = "SFCSN.lab";
            }
            string labpath = string.Format(@"{0}\{1}\{2}", System.IO.Directory.GetCurrentDirectory(), "Print", mdl);

            if (!File.Exists(labpath))
            {
                mFrm.ShowPrgMsg("条码档没有找找到,正在从Ftp下载..", MainParent.MsgType.Warning);
                FrmBLL.Ftp_MyFtp ftp = new FrmBLL.Ftp_MyFtp();
                ftp.DownloadFile(mdl, System.AppDomain.CurrentDomain.BaseDirectory + "Print", mdl);
                mFrm.ShowPrgMsg("标签文档下载完成", MainParent.MsgType.Outgoing);
            }
            lppx         = new LabelManager2.ApplicationClass();
            doc          = lppx.Documents.Open(labpath, true);
            doc.ViewMode = LabelManager2.enumViewMode.lppxViewModeSize;
        }
Пример #7
0
        public void PrintPalletLabel(DataTable dtPrint, int PrintQTY, string FilePatch)
        {
            if (!File.Exists(FilePatch))  //判断条码文件是否存在
            {
                sMain.ShowPrgMsg("条码档没有找到,请确认当前目录是否存在 PALLET.lab", MainParent.MsgType.Error);
                return;
            }

            try
            {
                lbl.Documents.Open(FilePatch, false);// 调用设计好的label文件
                LabelManager2.Document doc = lbl.ActiveDocument;
                foreach (DataRow dr in dtPrint.Rows)
                {
                    try
                    {
                        doc.Variables.FormVariables.Item(dr[0].ToString()).Value = dr[1].ToString();
                    }
                    catch
                    {
                    }
                }
                int Num = Convert.ToInt32(PrintQTY);        //打印数量
                doc.PrintDocument(Num);                     //打印
            }
            catch (Exception ex)
            {
                sMain.ShowPrgMsg(ex.Message, MainParent.MsgType.Error);
            }
            finally
            {
                //退出
            }
        }
Пример #8
0
        public void Printbarcode(LabelManager2.Application labelapp)
        {
            try
            {
                //db.SSHConnectMySql();
                String selstr = "select distinct tag_index from list_barcodeprint where print_status=0 and processpoint = '" + comboBox1.Text + "'";

                DataTable reader  = this.db2.Select(selstr);
                String    itemstr = "";

                if (reader != null)
                {
                    for (int i = 0; i < reader.Rows.Count; i++)
                    {
                        string strPath = textBox_path.Text.Trim();
                        this.labelapp.Documents.Open(strPath, false);
                        LabelManager2.Document labeldoc = labelapp.ActiveDocument;
                        int vcount = labeldoc.Variables.FormVariables.Count;

                        textBox_log.Text += "新建打印文档对象\r\n";
                        String    selsql1 = "select barcode,varible_index from list_barcodeprint where print_status=0 and tag_index=" + reader.Rows[i][0] + "  and processpoint = '" + comboBox1.Text + "' order by varible_index";
                        DataTable reader2 = this.db2.Select(selsql1);
                        if (reader2 != null && (reader2.Rows.Count == vcount))
                        {
                            for (int j = 0; j < reader2.Rows.Count; j++)
                            {
                                itemstr = "var_" + reader2.Rows[j][1].ToString();
                                labeldoc.Variables.FormVariables.Item(itemstr).Value = reader2.Rows[j][0].ToString();
                            }

                            textBox_log.Text += "文档开始打印:标签" + (i + 1).ToString() + "\r\n";
                            labeldoc.PrintDocument(); //打印一次
                            textBox_log.Text += "文档结束打印:标签" + (i + 1).ToString() + "\r\n";
                            labeldoc.FormFeed();      //结束打印

                            String updatesql1 = "update list_barcodeprint set print_status=1 where print_status=0 and tag_index=" + reader.Rows[i][0] + "  and processpoint = '" + comboBox1.Text + "'";
                            this.db2.Update(updatesql1);
                        }
                        textBox_log.Text += "文档关闭\r\n";
                        labeldoc.Close(true);
                    }
                }
            }
            catch (Exception exceptions)
            {
                MessageBox.Show("标签打印出错!请联系设备技术员处理。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            finally
            {
                labelapp.Documents.CloseAll();
            }
        }
Пример #9
0
        /// <summary>
        /// 初始化环境
        /// </summary>
        /// <param name="breadonly">模板文件是否只读</param>
        public void InitLppxApp(bool breadonly)
        {
            this.mlppx = new LabelManager2.ApplicationClass();
            mDoc       = mlppx.Documents.Open(labfile, breadonly);

            mDoc.Activate();
            mDoc.ViewMode = LabelManager2.enumViewMode.lppxViewModeSize;

            lsFormulasInfo      = new List <varinfo>();
            lsFormVariablesInfo = new List <varinfo>();
            lsFreeVariablesInfo = new List <varinfo>();

            for (int x = 1; x <= this.mDoc.Variables.Formulas.Count; x++)
            {
                lsFormulasInfo.Add(new varinfo()
                {
                    varoutputmask = this.mDoc.Variables.Formulas.Item(x).OutputMask,
                    varprefix     = this.mDoc.Variables.Formulas.Item(x).Prefix,
                    varsuffix     = this.mDoc.Variables.Formulas.Item(x).Suffix,
                    varlen        = this.mDoc.Variables.Formulas.Item(x).Length,
                    varname       = this.mDoc.Variables.Formulas.Item(x).Name,
                    varval        = this.mDoc.Variables.Formulas.Item(x).Value
                });
            }

            for (int x = 1; x <= this.mDoc.Variables.FormVariables.Count; x++)
            {
                lsFormVariablesInfo.Add(new varinfo()
                {
                    varoutputmask = this.mDoc.Variables.FormVariables.Item(x).OutputMask,
                    varprefix     = this.mDoc.Variables.FormVariables.Item(x).Prefix,
                    varsuffix     = this.mDoc.Variables.FormVariables.Item(x).Suffix,
                    varlen        = this.mDoc.Variables.FormVariables.Item(x).Length,
                    varname       = this.mDoc.Variables.FormVariables.Item(x).Name,
                    varval        = this.mDoc.Variables.FormVariables.Item(x).Value
                });
            }

            for (int x = 1; x <= this.mDoc.Variables.FreeVariables.Count; x++)
            {
                lsFreeVariablesInfo.Add(new varinfo()
                {
                    varoutputmask = this.mDoc.Variables.FreeVariables.Item(x).OutputMask,
                    varprefix     = this.mDoc.Variables.FreeVariables.Item(x).Prefix,
                    varsuffix     = this.mDoc.Variables.FreeVariables.Item(x).Suffix,
                    varlen        = this.mDoc.Variables.FreeVariables.Item(x).Length,
                    varname       = this.mDoc.Variables.FreeVariables.Item(x).Name,
                    varval        = this.mDoc.Variables.FreeVariables.Item(x).Value
                });
            }
        }
Пример #10
0
 public static void disposePrinter()
 {
     if (doc != null)
     {
         doc.Close();
         doc = null;
         // labApp.Quit();
     }
     if (labApp != null)
     {
         labApp.Quit();
         labApp = null;
     }
 }
Пример #11
0
        public void OpenTemplateMaterialLot(string printername, string fileName, string varName)
        {
            if (NoCodeSoft != "1")
            {
                string path = string.Empty;
                path = System.Environment.CurrentDirectory + "\\" + fileName;

                if (this._templatePath != path)
                {
                    this._printerName  = printername;
                    this._templatePath = path;

                    if (string.IsNullOrEmpty(varName))
                    {
                        throw new Exception("$Print_VarName_ISempty");
                    }

                    if (this._templatePath == null || this._templatePath == string.Empty)
                    {
                        throw new Exception("$ERROR_Label_template_empty");
                    }

                    if (_app == null)
                    {
                        throw new Exception("$ERROR_Open_CodeSoft !");
                    }

                    /// 设定标签模板文件路径
                    _doc = _app.Documents.Open(_templatePath, true);

                    if (_doc == null)
                    {
                        throw new Exception("$ERROR_Label_Open: " + fileName);
                    }

                    /// 设定标签打印时用的打印机
                    if (this._printerName != null && this._printerName != string.Empty)
                    {
                        if (_doc.Printer == null)
                        {
                            throw new Exception("$ERROR_Set_Printer_ERROR !");
                        }

                        _doc.Printer.SwitchTo(this._printerName, string.Empty, false);
                    }
                }
            }
        }
Пример #12
0
Файл: Form1.cs Проект: 88886/-
        private void Print(string pSN)
        {//print
            // string SN = pSN;
            lbl = new LabelManager2.Application();
            lbl.Documents.Open(docPath, true);
            LabelManager2.Document document = lbl.ActiveDocument;

            document.Variables.FreeVariables.Item("SN").Value = pSN;

            document.PrintDocument(1);
            document.FormFeed();
            lbl.Documents.CloseAll();
            document = null;
            lbl.Quit();
            //createLog("BOX_LABEL", CN, pSN, DateTime.Now.ToString("yyyy-MM-dd"), "Trinity");
            stopProcess("lppa");
        }
Пример #13
0
        public bool Print(LabelType typ, List <String> detail)
        {
            core c    = new core();
            bool temp = false;

            server = new LabelManager2.Application();
            doc    = new LabelManager2.Document();
            string defaultprinter = getdefaultprinter();

            try
            {
                switch (typ)
                {
                //PRINT LABEL
                case LabelType.PRINTLABEL:
                    server.Documents.Open(Application.StartupPath + @"\PRINTLABEL.lab");
                    server.PrinterSystem();
                    doc = server.ActiveDocument;

                    //Nama printer harus sesuai dg Hardware yang dipasang
                    doc.Printer.SwitchTo(defaultprinter);
                    //doc.Printer.SwitchTo("HP DJ 2130 series");
                    //doc.Printer.SwitchTo("HP LaserJet Professional P1102");

                    doc.Variables.FormVariables.Item("olshopname").Value   = detail[0].ToString();
                    doc.Variables.FormVariables.Item("nama").Value         = detail[1].ToString();
                    doc.Variables.FormVariables.Item("alamat").Value       = detail[2].ToString();
                    doc.Variables.FormVariables.Item("email").Value        = detail[3].ToString();
                    doc.Variables.FormVariables.Item("hp").Value           = detail[4].ToString();
                    doc.Variables.FormVariables.Item("tanggalpesan").Value = detail[5].ToString();
                    doc.Variables.FormVariables.Item("qty").Value          = detail[6].ToString();

                    doc.PrintLabel(1);
                    doc.FormFeed();
                    temp = true;
                    c.killLppa();
                    break;
                }
            }
            catch (Exception ex) { }
            return(temp);
        }
Пример #14
0
 private bool LoadLabel(Dictionary <string, string> variables)
 {
     try
     {
         _loadedDocument?.Close();
         _loadedDocument          = CsApp.Documents.Open(_labelType.TemplateFile);
         _loadedDocument.ViewMode = LabelManager2.enumViewMode.lppxViewModeValue;
         AssignVariables(variables);
         if (CsApp.Documents.Count > 0)
         {
             NoDocOpened = false;
             return(true);
         }
     }
     catch (Exception ex)
     {
         // ignored
     }
     return(false);
 }
Пример #15
0
        public void SwitchPrinter(string PrinterName)
        {
            ConnectToLppx2();

            LabelManager2.Document ActiveDoc = GetActiveDocument();
            if (ActiveDoc != null)
            {
                LabelManager2.PrinterSystem PrnSystem    = _mCsApp.PrinterSystem();
                LabelManager2.Strings       PrintersName = PrnSystem.Printers(LabelManager2.enumKindOfPrinters.lppxAllPrinters);

                string CurrentPrinter = ActiveDoc.Printer.Name;
                if (CurrentPrinter != PrinterName)
                {
                    short  NbPrinters      = PrintersName.Count;
                    string FullPrinterName = "";
                    for (short i = 1; i <= NbPrinters; i++)
                    {
                        FullPrinterName = PrintersName.Item(i);
                        int pos = FullPrinterName.LastIndexOf(',');
                        if (pos != -1)
                        {
                            string CurrentPrinterName = FullPrinterName.Substring(0, pos);
                            if (CurrentPrinterName == PrinterName)
                            {
                                bool   bDirectAccess = false;
                                string PortName      = FullPrinterName.Substring(pos + 1);
                                if (PortName.StartsWith("->"))
                                {
                                    PortName      = PortName.Substring(2);
                                    bDirectAccess = true;
                                }
                                ActiveDoc.Printer.SwitchTo(PrinterName, PortName, bDirectAccess);
                            }
                        }
                    }
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(PrintersName);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(PrnSystem);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(ActiveDoc);
                }
            }
        }
Пример #16
0
        public void OpenTemplate(string printername, string path)
        {
            if (NoCodeSoft != "1")
            {
                if (this._templatePath != path)
                {
                    this._printerName  = printername;
                    this._templatePath = path;

                    if (this._templatePath == null || this._templatePath == string.Empty)
                    {
                        throw new Exception("$ERROR_Label_template_empty");
                    }

                    if (_app == null)
                    {
                        throw new Exception("$ERROR_Open_CodeSoft !");
                    }

                    /// 设定标签模板文件路径
                    _doc = _app.Documents.Open(_templatePath, true);

                    if (_doc == null)
                    {
                        throw new Exception("$ERROR_Label_Open");
                    }

                    /// 设定标签打印时用的打印机
                    if (this._printerName != null && this._printerName != string.Empty)
                    {
                        if (_doc.Printer == null)
                        {
                            throw new Exception("$ERROR_Set_Printer_ERROR !");
                        }

                        _doc.Printer.SwitchTo(this._printerName, string.Empty, false);
                    }
                }
            }
        }
Пример #17
0
        private void button2_Click(object sender, EventArgs e)
        {
            string    fileName = System.AppDomain.CurrentDomain.BaseDirectory + @"\newTest1.Lab";
            DataTable dt       = GetDgvToTable(dataGridView1);
            int       number   = 0;


            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if ((dt.Rows[i][0]).ToString() == "True")
                {
                    LabelManager2.ApplicationClass lbl = new LabelManager2.ApplicationClass();

                    lbl.Documents.Open(fileName, false);//比较费时间
                    LabelManager2.Document labeldoc = lbl.ActiveDocument;

                    labeldoc.Variables.FormVariables.Item("变量2").Value = dt.Rows[i][2].ToString();
                    labeldoc.Variables.FormVariables.Item("变量3").Value = dt.Rows[i][3].ToString();
                    labeldoc.Variables.FormVariables.Item("变量4").Value = dt.Rows[i][4].ToString();
                    labeldoc.Variables.FormVariables.Item("变量5").Value = dt.Rows[i][5].ToString();
                    labeldoc.Variables.FormVariables.Item("变量6").Value = dt.Rows[i][6].ToString();
                    labeldoc.Variables.FormVariables.Item("变量9").Value = dt.Rows[i][7].ToString();;
                    labeldoc.PrintDocument(); //打印一次

                    //labeldoc.formfeed();
                    number++;

                    string    sql1 = "select Print_Times from ShippingInfoConfirmBody2 where Itm2 = '" + dt.Rows[i][9] + "'";
                    DataTable dt1  = SqlHelper.ExecuteDataTable(sql1);
                    int       bar  = Convert.ToInt32(dt1.Rows[0][0]) + 1;
                    string    sql2 = "update ShippingInfoConfirmBody2 set Print_Times = '" + bar + "' where Itm2 = '" + dt.Rows[i][9] + "'";
                    int       rst  = SqlHelper.ExecuteQuery(sql2);
                }
            }
            MessageBox.Show("共打印" + number + "条记录");
            load();
        }
Пример #18
0
        public static void InitCodesoftForReturn()
        {
            try
            {
                labApp = new LabelManager2.Application();
                string labFileName = @"D:\printLab\test.Lab";
                if (!File.Exists(labFileName))
                {
                    MessageBox.Show("沒有找到標簽模板文件:" + labFileName + ",請聯系系統管理員", "溫馨提示");
                    return;
                }

                labApp.Documents.Open(labFileName, false); // 调用设计好的label文件
                doc = labApp.ActiveDocument;
                doc.Printer.SwitchTo("codesoft");          //打印机名字,自定义,可以修改
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
            }
        }
Пример #19
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (cmbPrinterList.Text == "")
            {
                { MessageBox.Show("未選擇打印機!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); cmbPrinterList.Focus(); return; }
            }
            if (cb_SN.Text.Trim() == "")
            {
                MessageBox.Show("廠商簡稱未選擇", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); cb_SN.Focus(); return;
            }

            if (cb_S_PN.Text.Trim() == "")
            {
                MessageBox.Show("廠商料號未選擇", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); cb_S_PN.Focus(); return;
            }
            if (tb_C_PN.Text.Trim() == "")
            {
                MessageBox.Show("立德料號未選擇", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); tb_C_PN.Focus(); return;
            }
            if (tb_ep.Text.Trim() == "")
            {
                MessageBox.Show("環保特性未選擇", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); tb_ep.Focus(); return;
            }
            if (tb_cs_Rev.Text.Trim() == "")
            {
                MessageBox.Show("廠商版本版本不能爲空", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); tb_cs_Rev.Focus(); return;
            }
            if (tb_Lide_Rev.Text.Trim() == "")
            {
                MessageBox.Show("立德版本版本不能爲空", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); tb_Lide_Rev.Focus(); return;
            }
            if (tb_LOT_NO.Text.Trim() == "")
            {
                MessageBox.Show("LOT_NO不能爲空", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); tb_LOT_NO.Focus(); return;
            }
            if (tb_NW.Text.Trim() == "" || tb_NW.Value == 0)
            {
                MessageBox.Show("净重不能爲0", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); tb_NW.Focus(); return;
            }
            if (tb_GW.Text.Trim() == "" || tb_GW.Value == 0)
            {
                MessageBox.Show("毛重不能爲0", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); tb_GW.Focus(); return;
            }
            if (tb_QTY.Text.Trim() == "" || tb_QTY.Value == 0)
            {
                MessageBox.Show("數量不能爲0", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); tb_QTY.Focus(); return;
            }


            string startupPath  = System.Windows.Forms.Application.StartupPath;
            string labFileName  = startupPath + "\\lideSPA.Lab";
            string CodeSoftName = startupPath + "\\Interop.LabelManager2.dll";

            try
            {
                if (!File.Exists(CodeSoftName))
                {
                    MessageBox.Show("沒有找到dll:" + startupPath + "\\Interop.LabelManager2.dll,請聯系系統管理員", "溫馨提示");
                    return;
                }
                if (!File.Exists(labFileName))
                {
                    MessageBox.Show("沒有找到標簽模板文件:" + startupPath + "\\lideSPA.Lab,請聯系系統管理員", "溫馨提示");
                    return;
                }
                btnOK.Enabled = false;

                for (int i = 0; i < Convert.ToInt32(tb_printNum.Value); i++)
                {
                    labApp = new LabelManager2.ApplicationClass();
                    labApp.Documents.Open(startupPath + @"\lideSPA.Lab", false);// 调用设计好的label文件
                    doc = labApp.ActiveDocument;
                    doc.Printer.SwitchTo(OldActPrn);

                    if (tb_ep.Text.Trim() == "HF")
                    {
                        doc.Variables.FormVariables.Item("HF").Value   = tb_ep.Text.Trim();
                        doc.Variables.FormVariables.Item("ROHS").Value = "";
                    }
                    else
                    {
                        doc.Variables.FormVariables.Item("ROHS").Value = tb_ep.Text.Trim();
                        doc.Variables.FormVariables.Item("HF").Value   = "";
                    }
                    doc.Variables.FormVariables.Item("S_N").Value    = cb_SN.Text.Trim(); //给参数传值
                    doc.Variables.FormVariables.Item("S_PN").Value   = cb_S_PN.Text.Trim();
                    doc.Variables.FormVariables.Item("C_PN").Value   = tb_C_PN.Text.Trim();
                    doc.Variables.FormVariables.Item("R_FK").Value   = tb_cs_Rev.Text.Trim();
                    doc.Variables.FormVariables.Item("R_LIDE").Value = tb_Lide_Rev.Text.Trim();
                    doc.Variables.FormVariables.Item("L_N").Value    = tb_LOT_NO.Text.Trim();
                    doc.Variables.FormVariables.Item("DT").Value     = dateTimePicker_del.Value.ToString("yy'/'MM'/'dd");
                    doc.Variables.FormVariables.Item("DT2").Value    = dateTimePicker_del.Value.ToString("yyMMdd");
                    doc.Variables.FormVariables.Item("NW").Value     = tb_NW.Text.Trim();
                    doc.Variables.FormVariables.Item("GW").Value     = tb_GW.Text.Trim();
                    doc.Variables.FormVariables.Item("QTY").Value    = tb_QTY.Text.Trim();
                    doc.Variables.FormVariables.Item("QTY2").Value   = Convert.ToInt32(tb_QTY.Text.Trim()).ToString("0000000");
                    doc.Variables.FormVariables.Item("UNIT").Value   = tb_unit.Text.Trim();
                    doc.Variables.FormVariables.Item("S_ID").Value   = ConfigurationManager.AppSettings[this.cb_SN.Text]; //二维码上的供應商a
                    //int strWidth = doc.DocObjects.Barcodes.Item("Barcode1(2)").
                    //Console.WriteLine(strWidth);

                    // doc.Variables.
                    // doc.Variables.FreeVariables.Item("Text25").Value = "1";


                    doc.PrintDocument(1);                              //打印
                    if (labApp != null)
                    {
                        labApp.Documents.CloseAll(true);
                        labApp.Quit();//退出
                        labApp = null;
                        doc    = null;
                    }
                }
                btnOK.Enabled = true;
                //inival();
            }
            catch (Exception ex)
            {
                MessageBox.Show("出錯啦,原因如下:\n\r" + ex.Message, "出錯啦");
                btnOK.Enabled = true;
            }
            finally
            {
                if (labApp != null)
                {
                    labApp.Documents.CloseAll(true);
                    labApp.Quit();//退出
                    labApp = null;
                    doc    = null;
                }
                btnOK.Enabled = true;
                GC.Collect(0);
            }
        }
Пример #20
0
        /// <summary>
        /// Prints the label.
        /// </summary>
        /// <param name="vendor">The vendor.</param>
        /// <param name="date">The date.</param>
        /// <param name="pn">The pn.</param>
        /// <param name="descrition">The descrition.</param>
        /// <param name="po">The po.</param>
        /// <param name="qty">The qty.</param>
        /// <param name="sn">The sn.</param>
        /// <param name="k1">The k1.</param>
        /// <param name="k2">The k2.</param>
        /// <param name="end">The end.</param>
        /// <remarks>Created At Time: [ 2017-10-30 22:36 ], By User:lishuai, On Machine:Brian-NB</remarks>
        private void PrintLabel()
        {
            string vendor     = string.Empty;
            string date       = string.Empty;
            string pn         = string.Empty;
            string descrition = string.Empty;
            string po         = string.Empty;
            string qty        = string.Empty;
            string sn         = string.Empty;
            string k1         = string.Empty;
            string k2         = string.Empty;
            string end        = string.Empty;
            string ph         = string.Empty;//生产批号;


            try
            {
                if (dataGridView1.Rows.Count > 0)
                {
                    vendor = dataGridView1.CurrentRow.Cells[0].Value.ToString();
                    DateTime dt  = DateTime.Now;
                    string   sdt = dt.GetDateTimeFormats('g')[0].ToString();         //供应商
                    date       = sdt;
                    pn         = dataGridView1.CurrentRow.Cells[5].Value.ToString(); //料号
                    ph         = dataGridView1.CurrentRow.Cells[2].Value.ToString(); //批号
                    descrition = dataGridView1.CurrentRow.Cells[6].Value.ToString(); //描述
                    po         = dataGridView1.CurrentRow.Cells[1].Value.ToString(); //订单

                    qty = dataGridView1.CurrentRow.Cells[9].Value.ToString();        //总托数

                    sn = dataGridView1.CurrentRow.Cells[4].Value.ToString();         //托号
                    k1 = dataGridView1.CurrentRow.Cells[7].Value.ToString();         //原始重量
                    k2 = lbl_weight.Text;                                            //实际重量



                    // double cy = Convert.ToDouble(dataGridView1.CurrentRow.Cells[7].Value) - Convert.ToDouble(lbl_weight.Text);
                    double cy = Convert.ToDouble(lbl_weight.Text) - Convert.ToDouble(dataGridView1.CurrentRow.Cells[7].Value);

                    cy = System.Math.Abs(cy);

                    if (cy <= 1)
                    {
                        end = "OK";
                    }
                    else
                    {
                        end = "NG";
                    }


                    #region print
                    LabelManager2.Application labelapp = new LabelManager2.Application(); //创建lppa.exe进程
                    string strPath = System.Windows.Forms.Application.StartupPath + "\\102X152.Lab";


                    labelapp.Documents.Open(strPath, false);
                    LabelManager2.Document labeldoc = labelapp.ActiveDocument;

                    labeldoc.Variables.FormVariables.Item("VENDOR").Value = vendor;
                    labeldoc.Variables.FormVariables.Item("DATE").Value   = date;
                    labeldoc.Variables.FormVariables.Item("PN").Value     = pn;
                    labeldoc.Variables.FormVariables.Item("PH").Value     = ph;//批号
                    labeldoc.Variables.FormVariables.Item("DSP").Value    = descrition;
                    labeldoc.Variables.FormVariables.Item("PO").Value     = po;
                    labeldoc.Variables.FormVariables.Item("QTY").Value    = qty;
                    labeldoc.Variables.FormVariables.Item("SN").Value     = sn;
                    labeldoc.Variables.FormVariables.Item("K1").Value     = k1;
                    labeldoc.Variables.FormVariables.Item("K2").Value     = k2;
                    labeldoc.Variables.FormVariables.Item("END").Value    = end;



                    labeldoc.PrintDocument(); //打印一次
                    labeldoc.FormFeed();      //结束打印

                    labeldoc.Close(true);
                    labelapp.Application.Quit();

                    #endregion
                }
                else
                {
                    MessageBox.Show("请先选中要称重的托盘数据!!");
                    return;
                }
            }
            catch (IOException ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
        }
Пример #21
0
        //BarTender.Application btApp;
        // BarTender.Format btFormat;
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (cmbPrinterList.Text == "")
            {
                { MessageBox.Show("未選擇打印機!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); cmbPrinterList.Focus(); return; }
            }
            if (tb_PartNO.Text.Trim() == "")
            {
                MessageBox.Show("料件編號未選擇", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); tb_PartNO.Focus(); return;
            }
            if (tb_ver.Text.Trim() == "")
            {
                MessageBox.Show("版本不能爲空", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); tb_ver.Focus(); return;
            }
            if (tb_wo.Text.Trim() == "")
            {
                MessageBox.Show("訂單號不能爲空", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); tb_wo.Focus(); return;
            }
            if (datePickFrom.Text.Trim() == "")
            {
                MessageBox.Show("生產時間不能爲空", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); datePickFrom.Focus(); return;
            }
            if (tb_item.Text.Trim() == "")
            {
                MessageBox.Show("項次不能爲空", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); tb_item.Focus(); return;
            }
            if (tb_no.Text.Trim() == "" || tb_no.Value == 0)
            {
                MessageBox.Show("數量不能為0", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); tb_no.Focus(); return;
            }
            if (tb_weight.Text.Trim() == "" || tb_weight.Value == 0)
            {
                MessageBox.Show("重量不能爲0", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); tb_weight.Focus(); return;
            }
            if (dateTimePicker_del.Text.Trim() == "")
            {
                MessageBox.Show("交貨日期不能爲空", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); dateTimePicker_del.Focus(); return;
            }


            //btApp = getBarTender();
            ////檢查是否有安裝BarTend
            //if (btApp == null)
            //{
            //    MessageBox.Show("列印前請先安裝BarTender!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); //列印前請先安裝BarTender!
            //    return;
            //}
            //檢查bartender是否與LincenseServer連線
            //else if (!btApp.LicenseServer.IsConnected)
            //{
            //    MessageBox.Show("請確認Bartender版本與License Server是否連線!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); //請確認Bartender版本與License Server是否連線!
            //    return;
            //}



            string startupPath  = System.Windows.Forms.Application.StartupPath;
            string labFileName  = startupPath + "\\lide.Lab";
            string CodeSoftName = startupPath + "\\Interop.LabelManager2.dll";

            try
            {
                if (!File.Exists(CodeSoftName))
                {
                    MessageBox.Show("沒有找到dll:" + startupPath + "\\Interop.LabelManager2.dll,請聯系系統管理員", "溫馨提示");
                    return;
                }
                if (!File.Exists(labFileName))
                {
                    MessageBox.Show("沒有找到標簽模板文件:" + startupPath + "\\lide.Lab,請聯系系統管理員", "溫馨提示");
                    return;
                }
                btnOK.Enabled = false;
                //btFormat = btApp.Formats.Open(startupPath + @"\lide", false, OldActPrn);
                //btFormat.PrintSetup.IdenticalCopiesOfLabel = Convert.ToInt32(tb_printNum.Value);  //设置同序列打印的份数
                //btFormat.PrintSetup.NumberSerializedLabels =1 ;  //设置需要打印的序列数
                //btFormat.SetNamedSubStringValue("tb_PartNO", this.tb_PartNO.Text); //向bartender模板传递变量
                //btFormat.SetNamedSubStringValue("tb_ver", this.tb_ver.Text);//版本
                //btFormat.SetNamedSubStringValue("tb_env", this.tb_ep.Text);//環保
                //btFormat.SetNamedSubStringValue("tb_spec", this.tb_spec.Text);//規格
                //btFormat.SetNamedSubStringValue("tb_wo", this.tb_wo.Text);//工單
                //btFormat.SetNamedSubStringValue("tb_dev", this.tb_dev.Text);//幾臺
                //btFormat.SetNamedSubStringValue("tb_data", this.datePickFrom.Value.ToString("yyyy/MM/dd"));//生產日期
                //btFormat.SetNamedSubStringValue("tb_item", this.tb_item.Text);//項次
                //btFormat.SetNamedSubStringValue("tb_no", this.tb_no.Text);//數量
                //btFormat.SetNamedSubStringValue("tb_unit", this.tb_unit.Text);//單位
                //btFormat.SetNamedSubStringValue("tb_ven", this.tb_ven.Text);//供应商
                //btFormat.SetNamedSubStringValue("tb_ven2", ConfigurationManager.AppSettings[this.tb_ven.Text]);//二维码上的供應商
                //btFormat.SetNamedSubStringValue("tb_weight", this.tb_weight.Text);//毛重
                //btFormat.SetNamedSubStringValue("tb_del_data", this.dateTimePicker_del.Value.ToString("yyyy/MM/dd"));//交貨日期
                //btFormat.SetNamedSubStringValue("tb_org", this.tb_org.Text);//生產地方
                //btFormat.SetNamedSubStringValue("tb_bak", this.tb_bak.Text);//備注
                //btFormat.SetNamedSubStringValue("tb_mon", this.tb_mon.Text);//月份

                //btFormat.PrintOut(false, false); //第二个false设置打印时是否跳出打印属性
                //btFormat.Close(BarTender.BtSaveOptions.btSaveChanges); //退出时是否保存标签

                for (int i = 0; i < Convert.ToInt32(tb_printNum.Value); i++)
                {
                    labApp = new LabelManager2.ApplicationClass();
                    labApp.Documents.Open(startupPath + @"\lide.Lab", false);// 调用设计好的label文件
                    doc = labApp.ActiveDocument;
                    doc.Printer.SwitchTo(OldActPrn);

                    string strMon = "";
                    if (int.Parse(tb_mon.Value.ToString()) < 10)
                    {
                        strMon = "0" + int.Parse(tb_mon.Value.ToString());
                    }
                    else
                    {
                        strMon = tb_mon.Value.ToString();
                    }


                    doc.Variables.FormVariables.Item("tb_PartNO").Value   = tb_PartNO.Text.Trim(); //给参数传值
                    doc.Variables.FormVariables.Item("tb_ver").Value      = tb_ver.Text.Trim();
                    doc.Variables.FormVariables.Item("tb_env").Value      = tb_ep.Text.Trim();
                    doc.Variables.FormVariables.Item("tb_spec").Value     = tb_spec.Text.Trim();
                    doc.Variables.FormVariables.Item("tb_wo").Value       = tb_wo.Text.Trim();
                    doc.Variables.FormVariables.Item("tb_dev").Value      = tb_dev.Text.Trim();
                    doc.Variables.FormVariables.Item("tb_data").Value     = datePickFrom.Value.ToString("yyyy'/'MM'/'dd");
                    doc.Variables.FormVariables.Item("tb_item").Value     = tb_item.Text.Trim();
                    doc.Variables.FormVariables.Item("tb_no").Value       = tb_no.Text.Trim();
                    doc.Variables.FormVariables.Item("tb_unit").Value     = tb_unit.Text.Trim();
                    doc.Variables.FormVariables.Item("tb_ven").Value      = tb_ven.Text.Trim();
                    doc.Variables.FormVariables.Item("tb_ven2").Value     = ConfigurationManager.AppSettings[this.tb_ven.Text]; //二维码上的供應商A
                    doc.Variables.FormVariables.Item("tb_weight").Value   = tb_weight.Text.Trim();
                    doc.Variables.FormVariables.Item("tb_del_data").Value = dateTimePicker_del.Value.ToString("yyyy'/'MM'/'dd");
                    doc.Variables.FormVariables.Item("tb_org").Value      = tb_org.Text.Trim();
                    doc.Variables.FormVariables.Item("tb_bak").Value      = tb_bak.Text.Trim();
                    doc.Variables.FormVariables.Item("tb_mon").Value      = strMon;

                    doc.PrintDocument(1);                             //打印a
                    if (labApp != null)
                    {
                        labApp.Documents.CloseAll(true);
                        labApp.Quit();//退出
                        labApp = null;
                        doc    = null;
                    }
                }
                btnOK.Enabled = true;
                //inival();
            }
            catch (Exception ex)
            {
                MessageBox.Show("出錯啦,原因如下:\n\r" + ex.Message, "出錯啦");
                btnOK.Enabled = true;
            }
            finally
            {
                if (labApp != null)
                {
                    labApp.Documents.CloseAll(true);
                    labApp.Quit();//退出
                    labApp = null;
                    doc    = null;
                }
                btnOK.Enabled = true;
                GC.Collect(0);
            }
        }
Пример #22
0
        private void button1_Click(object sender, EventArgs e)
        {
            string StrSupplier = cb_Supplier.Text;
            string StrPart_NO = cb_PartNO.Text;
            string StrPart_Name = tb_Part_Name.Text;
            string StrSpec = tb_Spec.Text;
            string strBand = tb_Band.Text;
            string StrMaterial = tb_Material.Text;
            string StrProd_Data = datePickFrom.Value.ToString("yyyy'-'MM'-'dd");
            Console.WriteLine(StrProd_Data);
            string StrBuy_NO = tb_buy_no.Text.Trim();
            string StrBuy_Item = tb_buy_item.Text.Trim();
            string StrLot_NO = tb_lot_no.Text.Trim();
            string StrEP_NO = tb_ep_no.Text.Trim();
            string StrVerifier = tb_Verifier.Text.Trim();
            string StrWO_NO = tb_wo.Text.Trim();
            string StrSum = tb_sum.Text;
            string StrBak = tb_bak.Text.Trim();
            string StrUnit = tb_Unit.Text.Trim();

            if (cmbPrinterList.Text == "") { { MessageBox.Show("未選擇打印機!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); cmbPrinterList.Focus(); return; } }
            if (StrSupplier == "") { MessageBox.Show("供應商未選擇", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); cb_Supplier.Focus(); return; }
            if (StrPart_NO == "") { MessageBox.Show("料號不能爲空", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); cb_PartNO.Focus(); return; }
            if (StrBuy_NO == "") { MessageBox.Show("采購單號不能爲空", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); tb_buy_no.Focus(); return; }
            if (StrBuy_Item == "") { MessageBox.Show("采購項次不能爲空", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); tb_buy_item.Focus(); return; }
            if (StrLot_NO == "") { MessageBox.Show("製造批號不能爲空", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); tb_lot_no.Focus(); return; }
            if (StrEP_NO == "") { MessageBox.Show("電鍍批號不能爲空", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); tb_ep_no.Focus(); return; }
            if (StrWO_NO == "") { MessageBox.Show("工單不能爲空", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); tb_wo.Focus(); return; }
            if (StrSum == "" || tb_sum.Value == 0) { MessageBox.Show("數量不能爲空", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); tb_sum.Focus(); return; }
            if (StrVerifier == "") { MessageBox.Show("檢驗員不能爲空", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); tb_Verifier.Focus(); return; }




            // btApp = getBarTender();
            //檢查是否有安裝BarTend
            //if (btApp == null)
            //{
            //    MessageBox.Show("列印前請先安裝BarTender!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); //列印前請先安裝BarTender!
            //    return;
            //}          
            //檢查btw文件是否存在
            string startupPath = System.Windows.Forms.Application.StartupPath;
            string labFileName = startupPath + "\\deyi.Lab";
            string OracleName = startupPath + "\\Oracle.ManagedDataAccess.dll";
            string CodeSoftName = startupPath + "\\Interop.LabelManager2.dll";

            try
            {
                if (!File.Exists(OracleName))
                {
                    MessageBox.Show("沒有找到dll文件:" + startupPath + "\\Oracle.ManagedDataAccess.dll ,請聯系系統管理員", "溫馨提示");
                    return;
                }
                if (!File.Exists(CodeSoftName))
                {
                    MessageBox.Show("沒有找到dll:" + startupPath + "\\Interop.LabelManager2.dll,請聯系系統管理員", "溫馨提示");
                    return;
                }
                if (!File.Exists(labFileName))
                {
                    MessageBox.Show("沒有找到標簽模板文件:" + startupPath + "\\deyi.Lab,請聯系系統管理員", "溫馨提示");
                    return;
                }

                if (!Regex.IsMatch(StrEP_NO, strRegex))
                {
                    MessageBox.Show("電鍍批號格式不正確!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                int itempEP = Convert.ToInt32(StrEP_NO.Substring(11));
                if (itempEP == 0) { return; };
                if ((Convert.ToInt32(tb_printNum.Value) + itempEP) >= 1000)
                {
                    MessageBox.Show("電鍍批號流水碼加打印數量不可超過999", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                string strConnResult = dao.ConnTo();//連接mysql數據庫。
                if (strConnResult == "success")
                {
                    string strGet_ep_sum = dao.get_ep_sum(StrEP_NO);
                    if (strGet_ep_sum == "NO")
                    {
                        MessageBox.Show("電鍍批號已存在,請重新輸入。", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else if (strGet_ep_sum.Contains("NG"))
                    {
                        MessageBox.Show(strGet_ep_sum, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    
                    List<SnDataVO> list = new List<SnDataVO>();
                    for (int i = 0; i < Convert.ToInt32(tb_printNum.Value); i++)
                    {
                        if (i != 0) 
                        {
                            if((itempEP + i) < 1000)
                            {
                                StrEP_NO = StrEP_NO.Substring(0, 11) + (itempEP + i).ToString("000");
                            }
                            else
                            {
                                //MessageBox.Show("电镀批号流水码已达999,已用尽!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                break;
                            }
                            
                        }                      
                        strGet_ep_sum = dao.get_ep_sum(StrEP_NO);
                        if (strGet_ep_sum == "NO")
                        {
                            continue;
                        }
                        else if (strGet_ep_sum.Contains("NG"))
                        {
                            MessageBox.Show(strGet_ep_sum, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        string strSERIAL_NO = "";
                        string strGet_serial_noResult = dao.get_serial_no(StrProd_Data);
                        string strStrProd_Data2 = datePickFrom.Value.ToString("yyMMdd");
                        if (strGet_serial_noResult == "")
                        {
                            strSERIAL_NO = "A-" + strSUPPLIES_ID + "-" + strStrProd_Data2 + "-" + "00001";//如果SN_DATA中是空的。
                        }
                        else if (strGet_serial_noResult.Substring(0, 2) == "NG")
                        {
                            MessageBox.Show(strGet_serial_noResult, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        else
                        {
                            //如果SN_DATA中不是空的。
                            int iLenght = strGet_serial_noResult.Length;
                            strSERIAL_NO = "A-" + strSUPPLIES_ID + "-" + strStrProd_Data2 + "-" + (Convert.ToInt32(strGet_serial_noResult.Substring(iLenght-5)) + 1).ToString("00000");
                        }

                        string strResurt = dao.Insert_sn_data(strSERIAL_NO, StrEP_NO, strSUPPLIES_ID, StrLot_NO, StrProd_Data, StrWO_NO, StrSum, StrUnit, StrSupplier, StrPart_NO, StrPart_Name, strBand, StrSpec, StrMaterial, StrBuy_NO, StrBuy_Item, StrVerifier, StrBak);
                        if (strResurt == "Duplicate")
                        {
                            continue;
                        }
                        else if (strResurt.Contains("NG"))
                        {
                            MessageBox.Show(strResurt, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }

                        SnDataVO sndatavo = new SnDataVO();
                        sndatavo.SERIAL_NO = strSERIAL_NO;
                        sndatavo.EP_NO = StrEP_NO;
                        sndatavo.SUPPLYER_ID = strSUPPLIES_ID;
                        sndatavo.LOT_NO = StrLot_NO;
                        sndatavo.PROD_DATE = StrProd_Data;
                        sndatavo.WO_NO = StrWO_NO;
                        sndatavo.QTY = StrSum;
                        sndatavo.UNIT = StrUnit;
                        sndatavo.SUPPLYER = StrSupplier;
                        sndatavo.PART_NO = StrPart_NO;
                        sndatavo.PART_NAME = StrPart_Name;
                        sndatavo.BAND = strBand;
                        sndatavo.SPEC = StrSpec;
                        sndatavo.MATERIAL = StrMaterial;
                        sndatavo.BUY_NO = StrBuy_NO;
                        sndatavo.BUY_ENTRY = StrBuy_Item;
                        sndatavo.VERIFIER = StrVerifier;
                        sndatavo.REMARK = StrBak;
                        list.Add(sndatavo);
                    }

                   // btFormat = btApp.Formats.Open(startupPath + @"\deyi", false, OldActPrn);
                    DateTime dateTime = DateTime.Parse(StrProd_Data);
                    string strYY = dateTime.Year.ToString();
                    int intMonth = dateTime.Month;
                    double doubleM = (double)intMonth / 3.0;
                    string strQuarter = Math.Ceiling(doubleM).ToString();

                    button1.Enabled = false;
                    foreach (SnDataVO vo in list)
                    {
                        labApp = new LabelManager2.ApplicationClass();
                        labApp.Documents.Open(startupPath+@"\deyi.Lab", false);// 调用设计好的label文件
                        doc = labApp.ActiveDocument;
                        doc.Printer.SwitchTo(OldActPrn);

                        doc.Variables.FormVariables.Item("StrSerial_NO").Value = vo.SERIAL_NO; //序号
                        doc.Variables.FormVariables.Item("StrEP_NO").Value = vo.EP_NO; //供应商
                        doc.Variables.FormVariables.Item("StrSupplier").Value = vo.SUPPLYER; //供应商
                        doc.Variables.FormVariables.Item("StrPart_NO").Value = vo.PART_NO;//料号
                        doc.Variables.FormVariables.Item("StrPart_Name").Value = vo.PART_NAME;//品名
                        doc.Variables.FormVariables.Item("StrSpec").Value = vo.SPEC;//規格
                        doc.Variables.FormVariables.Item("strBand").Value = vo.BAND;//带别
                        doc.Variables.FormVariables.Item("StrMaterial").Value = vo.MATERIAL;//材质
                        doc.Variables.FormVariables.Item("StrProd_Data").Value = vo.PROD_DATE;//制造日期
                        doc.Variables.FormVariables.Item("StrProd_Data2").Value = datePickFrom.Value.ToString("yyMMdd");//二维码上的制造日期
                        doc.Variables.FormVariables.Item("StrBuy_NO").Value = vo.BUY_NO;//采购单号
                        doc.Variables.FormVariables.Item("StrBuy_Item").Value = vo.BUY_ENTRY;//采购项次
                        doc.Variables.FormVariables.Item("StrLot_NO").Value = vo.LOT_NO;//制造批号
                        doc.Variables.FormVariables.Item("StrEP_NO").Value = vo.EP_NO;//电镀批号
                        doc.Variables.FormVariables.Item("StrVerifier").Value = vo.VERIFIER;//检验员
                        doc.Variables.FormVariables.Item("StrWO_NO").Value = vo.WO_NO;//工单
                        doc.Variables.FormVariables.Item("StrSum").Value = vo.QTY;//数量
                        doc.Variables.FormVariables.Item("StrUnit").Value = vo.UNIT;//单位
                        doc.Variables.FormVariables.Item("StrBak").Value = StrBak;//备注
                        doc.Variables.FormVariables.Item("StrYY").Value = strYY;//年strQuarter
                        doc.Variables.FormVariables.Item("strQuarter").Value = strQuarter;

                        doc.PrintDocument(1);                             //打印
                        if (labApp != null)
                        {
                            labApp.Documents.CloseAll(true);
                            labApp.Quit();//退出
                            labApp = null;
                            doc = null;
                        }
                        //btFormat.PrintSetup.IdenticalCopiesOfLabel = 1;  //设置同序列打印的份数
                        //btFormat.PrintSetup.NumberSerializedLabels = 1;  //设置需要打印的序列数
                        //btFormat.SetNamedSubStringValue("StrSerial_NO", vo.SERIAL_NO); //序号
                        //btFormat.SetNamedSubStringValue("StrEP_NO", vo.EP_NO); //供应商
                        //btFormat.SetNamedSubStringValue("StrSupplier", vo.SUPPLYER); //供应商
                        //btFormat.SetNamedSubStringValue("StrPart_NO", vo.PART_NO);//料号
                        //btFormat.SetNamedSubStringValue("StrPart_Name", vo.PART_NAME);//品名
                        //btFormat.SetNamedSubStringValue("StrSpec", vo.SPEC);//規格
                        //btFormat.SetNamedSubStringValue("strBand", vo.BAND);//带别
                        //btFormat.SetNamedSubStringValue("StrMaterial", vo.MATERIAL);//材质
                        //btFormat.SetNamedSubStringValue("StrProd_Data", vo.PROD_DATE);//制造日期
                        //btFormat.SetNamedSubStringValue("StrBuy_NO", vo.BUY_NO);//采购单号
                        //btFormat.SetNamedSubStringValue("StrBuy_Item", vo.BUY_ENTRY);//采购项次
                        //btFormat.SetNamedSubStringValue("StrLot_NO", vo.LOT_NO);//制造批号
                        //btFormat.SetNamedSubStringValue("StrEP_NO", vo.EP_NO);//电镀批号
                        //btFormat.SetNamedSubStringValue("StrVerifier", vo.VERIFIER);//检验员
                        //btFormat.SetNamedSubStringValue("StrWO_NO", vo.WO_NO);//工单
                        //btFormat.SetNamedSubStringValue("StrSum", vo.QTY);//数量
                        //btFormat.SetNamedSubStringValue("StrUnit", vo.UNIT);//单位
                        //btFormat.SetNamedSubStringValue("StrBak", StrBak);//备注
                        //btFormat.SetNamedSubStringValue("StrYY", strYY);//年strQuarter
                        //btFormat.SetNamedSubStringValue("strQuarter", strQuarter);
                        //btFormat.PrintOut(false, false); //第二个false设置打印时是否跳出打印属性
                    }
                    //btFormat.Close(BarTender.BtSaveOptions.btDoNotSaveChanges); //退出时是否保存标签
                }
                else
                {
                    MessageBox.Show("数据库连接错误!" + strConnResult, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                getLastEPNO();
                button1.Enabled = true;
                //inival();
            }
            catch (Exception ex)
            {
                MessageBox.Show("出錯啦,原因如下:\n\r" + ex.Message, "出錯啦");
                button1.Enabled = true;
            }
            finally
            {
                if (labApp != null)
                {
                    labApp.Documents.CloseAll(true);
                    labApp.Quit();//退出
                    labApp = null;
                    doc = null;
                }
                button1.Enabled = true;
                dao.Close();
                GC.Collect(0);

            }
        }
Пример #23
0
        private void btn_print_Click(object sender, EventArgs e)
        {
            try
            {
                this.label4.Text = "";
                if (!string.IsNullOrEmpty(this.cmb_ph.Text))
                {
                    if (!string.IsNullOrEmpty(this.txt_fh.Text))
                    {
                        #region 简单根据第一码是否是%判断条码扫描是否正确
                        if (!txt_fh.Text.StartsWith("%"))
                        {
                            // MessageBox.Show("条码错误,请确认第一码是否是%");

                            #region 弹窗
                            //Form_Message f = new Form_Message();

                            //f.Show();
                            this.label4.Text = "条码第一码不为%";
                            #endregion

                            txt_fh.SelectAll();
                            return;
                        }

                        #endregion


                        #region  判断条码长度是否不为12码,如果是提示;

                        if (this.txt_fh.Text.Trim().Length != 10)
                        {
                            // MessageBox.Show("条码长度不正确!");
                            this.label4.Text = "条码长度不正确!";
                            // this.btn_print.Enabled = false;
                            FormLogin f = new FormLogin();
                            f.StartPosition = FormStartPosition.CenterScreen;
                            if (f.ShowDialog() != DialogResult.OK)
                            {
                                return;
                            }
                        }

                        #region 比对是否已经打过,已经存在于wps文件中。
                        if (heckisexit(this.txt_fh.Text.Trim().Substring(1).ToString(), this.cmb_ph.Text))
                        {
                            this.label4.Text = "条码重复,已经打印,请联系主管确认!!";

                            FormLogin f = new FormLogin();
                            f.StartPosition = FormStartPosition.CenterScreen;

                            if (f.ShowDialog() != DialogResult.OK)
                            {
                                return;
                            }
                        }
                        #endregion

                        #endregion
                        this.label4.Text = "";
                        #region print
                        LabelManager2.Application labelapp = new LabelManager2.Application(); //创建lppa.exe进程
                        string strPath = System.Windows.Forms.Application.StartupPath + "\\PrinteModel1.lab";


                        labelapp.Documents.Open(strPath, false);
                        LabelManager2.Document labeldoc = labelapp.ActiveDocument;

                        labeldoc.Variables.FormVariables.Item("p1").Value = cmb_ph.Text.Trim();
                        string fh = txt_fh.Text.Trim().Substring(1);
                        labeldoc.Variables.FormVariables.Item("p2").Value = fh;
                        //MessageBox.Show(fh);

                        labeldoc.PrintDocument(); //打印一次
                        labeldoc.FormFeed();      //结束打印

                        labeldoc.Close(true);
                        labelapp.Application.Quit();

                        #endregion

                        #region SaveToCsv
                        SaveDataToCsv();
                        #endregion

                        #region bindgrid

                        //BindGrid();
                        //改为一次只绑定一笔
                        BindDataManu();
                        #endregion

                        #region clear
                        // btn_clear_Click(null, null);
                        #endregion
                        this.txt_fh.Text = "";
                        this.txt_fh.Focus();
                    }
                    else
                    {
                        MessageBox.Show("请扫描番号条码");
                    }
                }
                else
                {
                    MessageBox.Show("请先选择品号!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #24
0
        /// <summary>
        /// 调用打印机方法。在多线程中调用,故而加上同步锁‘lock’,确保同一时间只有一个线程调用打印机
        /// </summary>
        /// <param name="array"></param>
        /// <param name="localLabName"></param>
        private void PrintBarcode(JArray array, string localLabName)
        {
            lock (this){
                labName = localLabName;
                string strRptFile = confPath + "\\" + localLabName;
                try
                {
                    if (appClass == null)
                    {
                        appClass = new LabelManager2.ApplicationClass();
                    }
                    //LabelManager2.Document docRpt =
                    appClass.Documents.Open(strRptFile, false);

                    doc = appClass.ActiveDocument;

                    if (doc == null)
                    {
                        MessageBox.Show(string.Format("{0}\r\n模板文件不存在!", strRptFile));
                        return;
                    }

                    foreach (JObject jobj in array)
                    {
                        foreach (var item in jobj)
                        {
                            if (doc.Variables.Item(item.Key) == null)
                            {
                                continue;
                            }

                            doc.Variables.Item(item.Key).Value = item.Value.ToString();
                        }
                        doc.Printer.SwitchTo(printerName);//条码信息发送至打印机

                        //调用博斯特打印机使用printLable函数打印:‘一行单列’的标签会出现左右偏移的现象,故而用printDocument函数打印‘一行单列’的标签
                        //而使用printDocument函数打印:‘一行多列’的标签时,只会打印一行中指定数量的标签,不会自动填充剩余的空白标签,故而使用printLable函数打印‘一行多列’的标签
                        //if (this.cbSingle.Checked == true)
                        //{
                        //    doc.PrintDocument(copies);
                        //}
                        //if (this.cbMany.Checked == true)
                        //{
                        doc.PrintLabel(copies);
                        //}

                        unFinishLabCnt--;
                        finishLabCnt++;
                        updateUI();
                    }
                    doc.FormFeed();//打印完自动结束
                }
                catch (Exception err)
                {
                    addListItemText("打印条码出错:" + err.ToString());
                }
                finally
                {
                    appClass.Documents.CloseAll(true);
                    appClass.Quit();//退出
                    appClass = null;
                    doc      = null;
                    GC.Collect(0);
                }
            }
        }