Ejemplo n.º 1
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();
            }
        }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
0
 private void closeingWindow(object sender, FormClosingEventArgs e)
 {
     if (this.bt_connectServer.Text == "断开")
     {
         try
         {
             socketClient.Close();
             threadTCP.Abort();
         }
         catch
         {
             Console.Write("socket close failed!!!!");
         }
         this.bt_connectServer.Text = "连接";
     }
     if (appClass != null)
     {
         try
         {
             if (appClass.Documents.Count > 0)
             {
                 appClass.Documents.CloseAll(true);
             }
             appClass.Quit();
             appClass = null;
         }
         catch (Exception err)
         {
             throw;
         }
     }
     Environment.Exit(0);
 }
Ejemplo n.º 4
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
                });
            }
        }
Ejemplo n.º 5
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();
        }
Ejemplo n.º 6
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);
            }
        }
Ejemplo n.º 7
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);
            }
        }
Ejemplo n.º 8
0
        private void FrmPallet_Load(object sender, EventArgs e)
        {
            try
            {
                #region 添加应用程序
                if (this.sMain.gUserInfo.rolecaption == "系统开发员")
                {
                    IList <IDictionary <string, object> > lsfunls = new List <IDictionary <string, object> >();
                    FrmBLL.publicfuntion.GetFromCtls(this, ref lsfunls);
                    Dictionary <string, object> dic = new Dictionary <string, object>();
                    dic.Add("PROGID", this.Name);
                    dic.Add("PROGNAME", this.Text);
                    dic.Add("PROGDESC", this.Text);
                    FrmBLL.publicfuntion.AddProgInfo(dic, lsfunls);
                }
                #endregion
            }
            catch (Exception ex)
            {
                this.sMain.ShowPrgMsg(ex.Message, MainParent.MsgType.Error);
            }

            labemployee.Text = sMain.gUserInfo.username;


            #region 调节控件位置

            panelEx3.Width = PalConfig.Width / 2;
            panelEx6.Left  = panelEx5.Width / 3;
            panelEx7.Left  = panelEx5.Width / 3;
            panelEx8.Left  = panelEx5.Width / 3;
            panelEx9.Left  = panelEx5.Width / 3;
            panelEx11.Left = panelEx5.Width / 3;
            label4.Left    = panelEx5.Width / 3 - 100;
            label5.Left    = panelEx5.Width / 3 - 100;
            label8.Left    = panelEx5.Width / 3 - 100;
            label6.Left    = label4.Left - label4.Width + 22;
            label7.Left    = label4.Left - label4.Width + 22;

            //panelEx10.Location = new Point(label7.Location.X,panelEx9.Location.Y + 50);
            //panelEx10.Size = new Size(PalConfig.Width / 2 - 100, panelEx5.Height - panelEx9.Location.Y - 60);

            #endregion

            //XmlDocument doc = new XmlDocument();
            //string XmlName = "DllConfig.xml";
            //doc.Load(XmlName);
            //LineName=((XmlElement)doc.SelectSingleNode("AutoCreate").SelectSingleNode("PALLET").SelectSingleNode("LINE")).GetAttribute("Name").ToString();
            //LineCode = ((XmlElement)doc.SelectSingleNode("AutoCreate").SelectSingleNode("PALLET").SelectSingleNode("LINECODE")).GetAttribute("Name").ToString();
            //CraftName = ((XmlElement)doc.SelectSingleNode("AutoCreate").SelectSingleNode("PALLET").SelectSingleNode("CRFTNAME")).GetAttribute("Name").ToString();
            //CraftId = ((XmlElement)doc.SelectSingleNode("AutoCreate").SelectSingleNode("PALLET").SelectSingleNode("CRFTID")).GetAttribute("Name").ToString();

            MyLine  = FrmBLL.ReadIniFile.IniReadValue("PACK_PALLET", "LINE", IniFilePatch);
            MYGROUP = FrmBLL.ReadIniFile.IniReadValue("PACK_PALLET", "CRFTNAME", IniFilePatch);
            //  LineCode = FrmBLL.ReadIniFile.IniReadValue("PACK_PALLET", "LINECODE", IniFilePatch);

            facid = sMain.gUserInfo.facId;

            if (string.IsNullOrEmpty(facid))
            {
                MessageBox.Show("厂区代码为空");
            }
            SetStation();
            labTotalCount.Text = "0";
            labcount.Text      = "0";
            labver.Text        = "";
            labpallet.Text     = "";
            LabCustPallet.Text = "";
            lbl = new LabelManager2.ApplicationClass();
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Codesoft模板打印。
        /// </summary>
        /// <param name="name">打印机名称/IP地址。</param>
        /// <param name="port">打印机端口。</param>
        /// <param name="directAccess">直接访问打印机。</param>
        /// <param name="templatePath">codesoft模板绝对路径。</param>
        /// <param name="obj">替换模版文件中的变量。</param>
        /// <returns></returns>
        public bool Print(string name, string port, bool directAccess, string templatePath, ExpandoObject obj)
        {
            LabelManager2.IApplication lbl = null;
            LabelManager2.IDocument    doc = null;
            try
            {
                lbl = new LabelManager2.ApplicationClass();
                string path = templatePath.Replace("codesoft://", string.Empty);
                if (doc == null)
                {
                    if (Path.IsPathRooted(path) == false)
                    {
                        string directoryName = System.AppDomain.CurrentDomain.BaseDirectory;
                        path = Path.GetFullPath(Path.Combine(directoryName, path));
                    }
                    lbl.Documents.Open(path);
                    if (lbl == null)
                    {
                        throw new Exception(string.Format("打开模板文件({0})失败。", path));
                    }
                    doc = lbl.ActiveDocument;
                }

                if (doc == null)
                {
                    throw new Exception(string.Format("打开模板文件({0})失败。", path));
                }

                var printQty = 1;
                if (obj != null)
                {
                    for (int i = 1; i <= doc.Variables.FormVariables.Count; i++)
                    {
                        var variableItem = doc.Variables.FormVariables.Item(i);
                        KeyValuePair <string, object> pair = obj.FirstOrDefault(item => item.Key.ToUpper() == variableItem.Name.ToUpper());
                        if (pair.Value != null)
                        {
                            variableItem.Value = Convert.ToString(pair.Value);
                        }
                    }
                    KeyValuePair <string, object> printQtyPair = obj.FirstOrDefault(item => item.Key.ToUpper() == "PrintQty".ToUpper());

                    if (printQtyPair.Value != null)
                    {
                        int.TryParse(Convert.ToString(printQtyPair.Value), out printQty);
                    }
                }

                string defaultPrinterName = doc.Printer.Name;

                if (defaultPrinterName != name && doc.Printer.SwitchTo(name, port, directAccess) == false)
                {
                    LabelManager2.Strings vars = lbl.PrinterSystem().Printers(LabelManager2.enumKindOfPrinters.lppxAllPrinters);
                    string printerNames        = string.Empty;
                    for (int i = 1; i <= vars.Count; i++)
                    {
                        printerNames += vars.Item(i) + ";";
                    }
                    throw new Exception(string.Format("打印机({0})不存在。系统中存在的打印机列表 {1}。", name, printerNames));
                }

                doc.PrintDocument(printQty);
            }
            finally
            {
                //释放非托管资源
                if (doc != null)
                {
                    doc.FormFeed();
                    doc.Close();
                    doc = null;
                }

                if (lbl != null)
                {
                    lbl.Quit();
                    lbl = null;
                }
            }
            return(true);
        }
Ejemplo n.º 10
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);

            }
        }
Ejemplo n.º 11
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);
                }
            }
        }