private void btnPrint_Click(object sender, EventArgs e)
        {
            int count = 0;

            if (finshingLabels != null && finshingLabels.Count > 0)
            {
                try
                {

                    foreach (FinshingLabel flb in finshingLabels)
                    {

                        // string path = Application.StartupPath + @"Finishing_Assy_Label\TXFKY5Z0026(TH-P42GT30).btw";
                        string path = "C:\\Finishing Assy Label\\TXFKY5Z0026(TH-P42GT30).btw";

                        btApp.Visible = false;
                        btformat = btApp.Formats.Open(path, true, "");

                        // barcode
                        btformat.SetNamedSubStringValue("completelno", flb.CompleteNo); // 1.complete_numbers.completelno
                        btformat.SetNamedSubStringValue("rev", flb.Rev);// 2.finishing_labels.rev
                        btformat.SetNamedSubStringValue("place_name1", flb.PlaceName);// 3.placeNtext
                        btformat.SetNamedSubStringValue("product_barcode_date", flb.ProductBarCodeDate);// 4.finishing_labels.product_text_date
                        btformat.SetNamedSubStringValue("line", flb.Line); // 5.line
                        btformat.SetNamedSubStringValue("ship", flb.Shift);// 6.finishing_labels.ship
                        btformat.SetNamedSubStringValue("serial", Convert.ToDouble(flb.Serial).ToString("00000"));// 7.finishing_labels.serial

                        // text
                        btformat.SetNamedSubStringValue("completelno", flb.CompleteNo); // 1.complete_numbers.completelno
                        btformat.SetNamedSubStringValue("product_text_date", flb.ProductTextDate); // 2.finishing_labels.product_text_date
                        btformat.SetNamedSubStringValue("serial", Convert.ToDouble(flb.Serial).ToString("00000"));  // 3.finishing_labels.serial
                        btformat.SetNamedSubStringValue("rev", flb.Rev); // 4.finishing_labels.rev
                        btformat.SetNamedSubStringValue("place_name", flb.PlaceName); // 5.place_name
                        btformat.SetNamedSubStringValue("ship", flb.Shift);  // 6.finishing_labels.ship

                        btformat.PrintOut(false, false);

                        //// insert to database
                        FinshingLabel fbl = finishService.GetByBarCode(flb.Barcode);
                        if (fbl == null)
                        {
                            int result = finishService.CreateFinishingLabel(flb);
                            if (result > -1)
                            {
                                Console.WriteLine("Insert Complete");
                                count++;
                            }
                            else
                            {
                                Console.WriteLine("Insert Not Complete");
                            }
                        }

                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
                finally
                {
                    btformat.Close(BarTender.BtSaveOptions.btDoNotSaveChanges);
                }

                lblresult.Visible = true;
                lblresult.Text = " บันทึกเรียบร้อยจำนวน  : " + count + "   รายการ";

            }
        }
Example #2
0
        protected void Khoitao()
        {
            //*** Can set up Interop.bartender properties : Embed interop type =false => TRUE se bao loi
            //KillBTprocess();

            btApp         = new BarTender.ApplicationClass();
            btFormat      = new BarTender.FormatClass();
            ListSharename = new List <string>();
            ListSharename = null;
        }
Example #3
0
        private void button5_Click(object sender, EventArgs e)
        {
            try
            {
                label45.Text = "";
                string idnumber = this.textBox3.Text;
                if (idnumber != null && idnumber.Length == 18)
                {
                    DisplayPersonTeShuInfo(idnumber);

                    string nameCodenew = textBox1.Text + " " + Regex.Replace(textBox3.Text, "(\\d{6})\\d{10}(\\d{2})", "$1**********$2");
                    if (nameCodenew.IndexOf('*') < 0)
                    {
                        nameCodenew = textBox1.Text + " " + textBox3.Text.Substring(0, 6) + "**********" + textBox3.Text.Substring(16, 2);
                    }
                    string    codenew = "";
                    int       fnum    = Int32.Parse(this.numericUpDown1.Value.ToString());
                    DataTable dttjjk  = grjddao.selectTjjk(idnumber);
                    if (dttjjk != null && dttjjk.Rows.Count > 0)
                    {
                        codenew = dttjjk.Rows[0]["bar_code"].ToString();

                        //调用Bartender
                        btApp = new BarTender.Application();
                        //获取打印模板,指定打印机
                        btFormat = btApp.Formats.Open(@str + "\\cs1.btw", false, "");
                        // 同样标签的份数
                        btFormat.PrintSetup.IdenticalCopiesOfLabel = fnum;
                        // 序列标签数
                        btFormat.PrintSetup.NumberSerializedLabels = 1;
                        //设置参数 code
                        btFormat.SetNamedSubStringValue("code", codenew);
                        btFormat.SetNamedSubStringValue("nameCode", nameCodenew);
                        //打印开始 第2个参数是 是否显示打印机属性的。可以设置打印机路径
                        btFormat.PrintOut(false, false);
                        //关闭摸板文件,并且关闭文件流
                        btFormat.Close(BarTender.BtSaveOptions.btDoNotSaveChanges);
                        //打印完毕
                        btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
                    }
                    else
                    {
                        MessageBox.Show("此身份证号没有登记过,请检查!");
                    }
                }
                else
                {
                    MessageBox.Show("身份证号不正确,请检查!");
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message + "---" + ee.StackTrace);
            }
        }
Example #4
0
        private void btnprint_Click(object sender, EventArgs e)
        {
            if (boxLabel != null)
            {

                try
                {

                    string path = "C:\\box_label\\Production_box_label.bt.btw";

                    btApp.Visible = false;
                    btformat = btApp.Formats.Open(path, true, "");

                    // barcode
                    btformat.SetNamedSubStringValue("name", boxLabel.CompleteNo); // 1.completeno
                    btformat.SetNamedSubStringValue("model", boxLabel.ModelNo); // 2.model_no
                    btformat.SetNamedSubStringValue("Date", boxLabel.ProductDate); // 3.production_date
                    btformat.SetNamedSubStringValue("qty", boxLabel.Quantity); // 4.qty
                    btformat.SetNamedSubStringValue("box", Convert.ToDouble(boxLabel.Serial).ToString()); // 5.box_no
                    btformat.SetNamedSubStringValue("mold", boxLabel.MoldNo); // 6.mold_no

                    // text
                    List<CompleteNumber> cnums = new List<CompleteNumber>();
                    cnums = service.getCompleteByComplete(boxLabel.CompleteNo);

                    if (cnums != null && cnums.Count > 0)
                    {
                        btformat.SetNamedSubStringValue("customer", cnums[0].Customer);   // 1.complete_number.customer
                        btformat.SetNamedSubStringValue("part_name", cnums[0].PartName); // // 3.complete_number.part_name
                        btformat.SetNamedSubStringValue("model_no", cnums[0].ModelNo);  //  // 4.complete_number.model_no
                    }
                    btformat.SetNamedSubStringValue("part_name", cnums[0].PartName); // // 3.complete_number.part_name
                    btformat.SetNamedSubStringValue("customer", cnums[0].Customer); // // 3.complete_number.part_name
                    btformat.SetNamedSubStringValue("model_no", cnums[0].ModelNo);  //  // 4.complete_number.model_no
                    btformat.SetNamedSubStringValue("complete_no", boxLabel.CompleteNo);  // 2.complete_number.complete_no
                    btformat.SetNamedSubStringValue("mold_no", boxLabel.MoldNo); // 5.box_label.mold_no
                    btformat.SetNamedSubStringValue("product_date", boxLabel.ProductDate); // 6.box_label.product_date
                    btformat.SetNamedSubStringValue("quantity", boxLabel.Quantity); // 7.box_label.quantity
                    btformat.SetNamedSubStringValue("serial", Convert.ToDouble(boxLabel.Serial).ToString());  //8.box_label.serial
                    btformat.SetNamedSubStringValue("supplier", boxLabel.Suplier);

                    btformat.PrintOut(false, false);

                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
                finally
                {
                    btformat.Close(BarTender.BtSaveOptions.btDoNotSaveChanges);
                }

            }
        }
Example #5
0
        //打印条码
        public void OnPrintSampleBarcode(string barcode, int pageCount, string nameCode)
        {
            bool addjkbool = false;

            if (grjdxx != null)
            {
                DataTable dt = grjddao.judgeRepeat(textBox3.Text);
                if (dt.Rows.Count < 1)
                {
                    grjdxx.archive_no = basicInfoSettings.xcuncode + grjdxx.Cardcode.Substring(14);
                    grjdxx.photo_code = grjdxx.Cardcode + ".jpg";
                    bool istrue = grjddao.addgrjdInfo(grjdxx);
                }
                jkBean jk = new jkBean();
                jk.aichive_no = grjdxx.archive_no;
                jk.id_number  = grjdxx.Cardcode;
                jk.bar_code   = barcode;
                jk.Pic1       = grjdxx.CardPic;
                jk.Pic2       = grjdxx.Cardcode + ".jpg";
                addjkbool     = grjddao.addJkInfo(jk);

                textBox5.Text = jk.aichive_no;
                textBox6.Text = barcode;
            }
            try
            {
                if (addjkbool)
                {
                    //调用Bartender
                    btApp = new BarTender.Application();
                    //获取打印模板,指定打印机
                    btFormat = btApp.Formats.Open(@str + "\\cs1.btw", false, "");
                    // 同样标签的份数
                    btFormat.PrintSetup.IdenticalCopiesOfLabel = pageCount;
                    // 序列标签数
                    btFormat.PrintSetup.NumberSerializedLabels = 1;
                    //设置参数 code
                    btFormat.SetNamedSubStringValue("code", barcode);
                    btFormat.SetNamedSubStringValue("nameCode", nameCode);
                    //打印开始 第2个参数是 是否显示打印机属性的。可以设置打印机路径
                    btFormat.PrintOut(false, false);
                    //关闭摸板文件,并且关闭文件流
                    btFormat.Close(BarTender.BtSaveOptions.btDoNotSaveChanges);
                    //打印完毕
                    btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("打印机设备连接不正确,请重新连接或重启!");
                //throw e;
            }
        }
Example #6
0
        public void Printbarcode()
        {
            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();
                        BarTender.Format btFormat = btapp.Formats.Open(strPath, false, "");

                        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)
                        {
                            for (int j = 0; j < reader2.Rows.Count; j++)
                            {
                                itemstr = "var_" + reader2.Rows[j][1].ToString();
                                btFormat.SetNamedSubStringValue(itemstr, reader2.Rows[j][0].ToString());
                            }

                            textBox_log.Text += "文档开始打印:标签" + (i + 1).ToString() + "\r\n";
                            //labeldoc.PrintDocument(); //打印一次
                            btFormat.PrintOut(true, false);
                            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);
                        btFormat.Close(BarTender.BtSaveOptions.btDoNotSaveChanges); //退出时是否保存标签
                    }
                }
            }
            catch (Exception exceptions)
            {
                MessageBox.Show("标签打印出错!请联系设备技术员处理。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            finally
            {
                // labelapp.Documents.CloseAll();
            }
        }
Example #7
0
        private void SetTemplateNamedSubStringValueToPartN <T>(BarTender.Format btFormat, List <string> list, T entry, int partId)
        {
            var t = entry.GetType();

            foreach (PropertyInfo item in t.GetProperties())
            {
                var name = item.Name + (partId + 1).ToString(); // 属性名称
                if (list.Contains(name))
                {
                    btFormat.SetNamedSubStringValue(name, Convert.ToString(item.GetValue(entry, null)));
                }
                // var value = item.GetValue(entry, null); // 属性值
                // var type = value?.GetType() ?? typeof(object);//获得属性的类型
            }
        }
        private void btnprint_Click(object sender, EventArgs e)
        {
            if (injectionPanalLabels != null)
            {

                try
                {

                    // string path = Application.StartupPath + @"Injection_Label\1.btw";
                    string path = "C:\\Injection_Label\\TKY5ZA02501(46SCabinetMC16002).btw";

                    btApp.Visible = false;
                    btformat = btApp.Formats.Open(path, true, "");

                    // barcode
                    btformat.SetNamedSubStringValue("part_no", injectionPanalLabels.Part); // 1.part_no
                    btformat.SetNamedSubStringValue("production_date", injectionPanalLabels.date); // 2.production_date
                    btformat.SetNamedSubStringValue("serialno", Convert.ToDouble(injectionPanalLabels.Serial).ToString("00000")); // 3.serialno
                    btformat.SetNamedSubStringValue("shift", injectionPanalLabels.Shift); // 4.shift
                    btformat.SetNamedSubStringValue("rev", injectionPanalLabels.Rev); // 5.rev
                    btformat.SetNamedSubStringValue("meterialno", injectionPanalLabels.MatterialNo); // 6.meterialno
                    btformat.SetNamedSubStringValue("lotno", injectionPanalLabels.LotNo); // 7.lotno
                    btformat.SetNamedSubStringValue("colorno", injectionPanalLabels.ColorNo); // 8.colorno
                    btformat.SetNamedSubStringValue("machine_no", injectionPanalLabels.MachineNo); // 9.machine_no
                    btformat.SetNamedSubStringValue("mold_no", injectionPanalLabels.MoldNo); //10. mold_no

                    // text
                    btformat.SetNamedSubStringValue("part", injectionPanalLabels.Part); // 1.injection_panal_labels.part
                    btformat.SetNamedSubStringValue("product_date", injectionPanalLabels.date); // 2.injection_panal_labels.product_date
                    btformat.SetNamedSubStringValue("serial", Convert.ToDouble(injectionPanalLabels.Serial).ToString("00000"));  // 3.injection_panal_labels.serial
                    btformat.SetNamedSubStringValue("ship", injectionPanalLabels.Shift); // 4.injection_panal_labelsship
                    btformat.SetNamedSubStringValue("rev", injectionPanalLabels.Rev); // 5.injection_panal_labels.rev
                    btformat.SetNamedSubStringValue("machine_no", injectionPanalLabels.MachineNo);  // 6.injection_panal_labels.machine_no

                    btformat.PrintOut(false, false);

                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
                finally
                {
                    btformat.Close(BarTender.BtSaveOptions.btDoNotSaveChanges);
                }

            }
        }
Example #9
0
        public string BarTenderPrintLS <T>(IEnumerable <T> lists, BarTenderPrintConfigModelXX config)
        {
            string printerName  = config.PrinterName;                           // 打印机名称
            string templateName = config.TemplateSelectedItem.TemplateFullName; //通用模板名称

            BarTender.Application btApp = new BarTender.Application();
            try
            {
                // StringBuilder stringBuilder = new StringBuilder();
                BarTender.Format btFormat = btApp.Formats.Open(templateName, false, "");
                btFormat.PrintSetup.Printer = printerName;
                btFormat.PrintSetup.NumberSerializedLabels = 1;
                btFormat.PrintSetup.IdenticalCopiesOfLabel = 1;
                string nameValues = "," + btFormat.NamedSubStrings.GetAll("|", ",");
                Regex  rg         = new Regex(@",([^|]*)", RegexOptions.IgnoreCase);
                var    fieldLists = GetTendarFieldName(nameValues.Replace(Environment.NewLine, ""), rg);


                foreach (var entry in lists)
                {
                    SetTemplateNamedSubStringValueToPart(btFormat, fieldLists, entry);
                    var s1 = btFormat.PrintOut(false, false);
                    if (s1 != 0)
                    {
                        btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
                        return("打印结果不正常,打开模板手动打印取消警告窗口");
                    }
                    else
                    {
                        WriteRowHashValueLog(entry);
                    }
                }
                return("打印成功");
            }
            catch (Exception ex)
            {
                btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
                throw new Exception(ex.Message);
            }
            finally
            {
                if (btApp != null)
                {
                    btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
                }
            }
        }
Example #10
0
 private void 打印小标签ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         btFormat = btAPP.Formats.Open(System.Windows.Forms.Application.StartupPath + @"\Test.btw", false, "");
         btFormat.PrintSetup.IdenticalCopiesOfLabel = 1; //打印份数
         btFormat.PrintSetup.NumberSerializedLabels = 1; //序列标签数
         btFormat.SetNamedSubStringValue("打印文本", listView1.SelectedItems[0].SubItems[20].Text.Trim());
         //btFormat.SetNamedSubStringValue("打印条码", txtBarcode.Text.Trim());
         btFormat.PrintOut(true, false);                        //第二个false设置打印时是否跳出打印属性
         btFormat.Close(BarTender.BtSaveOptions.btSaveChanges); //退出时是否保存标签
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
        private void btnprint_Click(object sender, EventArgs e)
        {
            if (printingLabels != null)
            {

                try
                {

                    // string path = Application.StartupPath + @"Finishing_Assy_Label\TXFKY5Z0026(TH-P42GT30).btw";
                    string path = "C:\\Finishing_Print\\TKP5ZA01901 Print.btw";

                    btApp.Visible = false;
                    btformat = btApp.Formats.Open(path, true, "");

                    // barcode
                    btformat.SetNamedSubStringValue("part", printingLabels.Part); // 1.part
                    btformat.SetNamedSubStringValue("product_date", printingLabels.ProductDate); // 2.product_date
                    btformat.SetNamedSubStringValue("serial", Convert.ToDouble(printingLabels.Serial).ToString("00000"));// 3.serial
                    btformat.SetNamedSubStringValue("ship", printingLabels.Shift); // 4.ship
                    btformat.SetNamedSubStringValue("rev", printingLabels.Rev); // 5.rev
                    btformat.SetNamedSubStringValue("color_no", printingLabels.ColorNo); // 4.color_no
                    btformat.SetNamedSubStringValue("proecess", "Print," + printingLabels.Process); // 5.proecess

                    // text
                    btformat.SetNamedSubStringValue("part", printingLabels.Part); // 1.printing_labels.part
                    btformat.SetNamedSubStringValue("product_date", printingLabels.ProductDate); // 2.printing_labels.product_date
                    btformat.SetNamedSubStringValue("serial", Convert.ToDouble(printingLabels.Serial).ToString("00000")); // 3.printing_labels.serial
                    btformat.SetNamedSubStringValue("ship", printingLabels.Shift);// 4.printing_labels.ship
                    btformat.SetNamedSubStringValue("process", "Print," + printingLabels.Process);// 5.printing_labels.process

                    btformat.SetNamedSubStringValue("moldno", "#" + printingLabels.Mold); // 6.mold_no

                    btformat.PrintOut(false, false);

                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
                finally
                {
                    btformat.Close(BarTender.BtSaveOptions.btDoNotSaveChanges);
                }

            }
        }
Example #12
0
        public List <string> GetListFieldNameFromBTlabel()
        {
            List <string> DsShareName = new List <string>();

            try
            {
                string strlistSharename = "";
                // lblLinkBT.Text = Labelpath2print;
                //listShareName.Items.Clear();
                //loadField of bartender to data
                btFormat = btApp.Formats.Open(strpath, false, "");

                btFormat = btApp.Formats.Open(strpath, true, "");//reload
                //MessageBox.Show(btFormat.NamedSubStrings.GetAll(",", ":"));
                foreach (BarTender.SubString btSubString in btFormat.NamedSubStrings)
                {
                    //MessageBox.Show("Name is: " + btSubString.Name + "\n\r Full is: " + btFormat.NamedSubStrings.GetAll(",", ":"));
                    strlistSharename += btSubString.Name + " ";
                }
                strlistSharename = strlistSharename.Trim();//clear end blank=problem at get sharename from list

                //string a = PhanMem.listation4setuplabel;
                string[] words = strlistSharename.Split(' ');
                DsShareName.Clear();
                foreach (string i in words)
                {
                    //MessageBox.Show(i);
                    //DsShareName.Add("ok ne");
                    DsShareName.Add(i);
                    //DsShareName.Add(i.ToString());
                }

                DsShareName.Sort();
                return(DsShareName);
                //loadField of bartender to data

                //load copied setup
                //txtCopied.Value = Convert.ToDecimal(btFormat.IdenticalCopiesOfLabel);
                //load copied setup
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(DsShareName);
            }
        }
        private void btnprint_Click(object sender, EventArgs e)
        {
            if (finshingLabel != null) {

                try
                {

                    // string path = Application.StartupPath + @"Finishing_Assy_Label\TXFKY5Z0026(TH-P42GT30).btw";
                    string path = "C:\\Finishing Assy Label\\TXFKY5Z0026(TH-P42GT30).btw";

                    btApp.Visible = false;
                    btformat = btApp.Formats.Open(path, true, "");

                    // barcode
                    btformat.SetNamedSubStringValue("completelno", finshingLabel.CompleteNo); // 1.complete_numbers.completelno
                    btformat.SetNamedSubStringValue("rev", finshingLabel.Rev);// 2.finishing_labels.rev
                    btformat.SetNamedSubStringValue("place_name1", finshingLabel.PlaceName);// 3.placeNtext
                    btformat.SetNamedSubStringValue("product_text_date", finshingLabel.ProductBarCodeDate);// 4.finishing_labels.product_text_date
                    btformat.SetNamedSubStringValue("line", finshingLabel.Line); // 5.line
                    btformat.SetNamedSubStringValue("ship", finshingLabel.Shift);// 6.finishing_labels.ship
                    btformat.SetNamedSubStringValue("serial", Convert.ToDouble(finshingLabel.Serial).ToString("00000"));// 7.finishing_labels.serial

                    // text
                    btformat.SetNamedSubStringValue("completelno", finshingLabel.CompleteNo); // 1.complete_numbers.completelno
                    btformat.SetNamedSubStringValue("product_text_date", finshingLabel.ProductTextDate); // 2.finishing_labels.product_text_date
                    btformat.SetNamedSubStringValue("serial", Convert.ToDouble(finshingLabel.Serial).ToString("00000"));  // 3.finishing_labels.serial
                    btformat.SetNamedSubStringValue("rev", finshingLabel.Rev); // 4.finishing_labels.rev
                    btformat.SetNamedSubStringValue("place_name", finshingLabel.PlaceName); // 5.place_name
                    btformat.SetNamedSubStringValue("ship", finshingLabel.Shift);  // 6.finishing_labels.ship

                    btformat.PrintOut(false, false);

                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
                finally
                {
                    btformat.Close(BarTender.BtSaveOptions.btDoNotSaveChanges);
                }

            }
        }
Example #14
0
        private bool SetTemplateNamedSubStringValueToPart4(BarTender.Format btFormat, List <string> list, OilSampleEntryModel data)
        {
            if (list.Contains("ProductionDate4"))
            {
                btFormat.SetNamedSubStringValue("ProductionDate4", data.ProductionDate.ToString("yyyy-MM-dd"));
            }
            if (list.Contains("ProductionModel4"))
            {
                btFormat.SetNamedSubStringValue("ProductionModel4", data.ProductionModel);
            }
            if (list.Contains("ProductionName4"))
            {
                btFormat.SetNamedSubStringValue("ProductionName4", data.ProductionName);
            }
            if (list.Contains("ExpirationMonth4"))
            {
                btFormat.SetNamedSubStringValue("ExpirationMonth4", data.ExpirationMonth);
            }
            if (list.Contains("BatchNo4"))
            {
                btFormat.SetNamedSubStringValue("BatchNo4", data.BatchNo);
            }
            if (list.Contains("CheckNo4"))
            {
                btFormat.SetNamedSubStringValue("CheckNo4", data.CheckNo);
            }
            if (list.Contains("RoughWeight4"))
            {
                btFormat.SetNamedSubStringValue("RoughWeight4", data.RoughWeight);
            }
            if (list.Contains("WeightPerBucket4"))
            {
                btFormat.SetNamedSubStringValue("WeightPerBucket4", data.WeightPerBucket.ToString());
            }

            return(true);
        }
Example #15
0
        public string BarTenderOilSamplePrint(BarTenderPrintConfigModel config, OilSampleEntryModel data)
        {
            string weightPerBucket     = string.Empty;
            string weightPerBucketLast = string.Empty;
            string printerName         = config.PrinterName;
            string templateName        = config.TemplateFullName;

            BarTender.Application btApp = new BarTender.Application();
            try
            {
                // 获取批次号(先获取打印记录的,如果没有就获取新的)
                string batchNo = new OilSampleService().GetOilSampleEntryBatchNo(data.Id);
                if (string.IsNullOrEmpty(batchNo))
                {
                    var seq = new CommonService().GetCurrentDateNextSerialNumber(data.ProductionDate, "OilSamplePrintBatchNo");
                    batchNo = data.ProductionDate.ToString("yyMMdd") + seq.ToString().PadLeft(3, '0');
                }

                //int printCount = data.CurrencyPrintCount % config.TemplatePerPage == 0 ? data.CurrencyPrintCount / config.TemplatePerPage : data.CurrencyPrintCount / config.TemplatePerPage + 1;

                BarTender.Format btFormat = btApp.Formats.Open(templateName, false, "");
                btFormat.PrintSetup.Printer = printerName;

                string nameValues = "," + btFormat.NamedSubStrings.GetAll("|", ",");
                Regex  rg         = new Regex(@",([^|]*)", RegexOptions.IgnoreCase);
                var    list       = GetTendarFieldName(nameValues.Replace(Environment.NewLine, ""), rg);
                btFormat.PrintSetup.NumberSerializedLabels = 1;
                btFormat.PrintSetup.IdenticalCopiesOfLabel = 1;
                weightPerBucket     = data.WeightPerBucket.ToString();
                weightPerBucketLast = data.WeightPerBucket.ToString();

                //for (int i = 0; i < printCount; i++)
                //{
                // 最后一张(已打张数+本次打印数量 >=总张数  的最后一页)
                if (data.TotalWeight % data.WeightPerBucket != 0 && data.PrintedCount + data.CurrencyPrintCount >= data.PrintTotalCount)
                {
                    weightPerBucketLast = (Math.Round(data.TotalWeight % data.WeightPerBucket, 2)).ToString();
                }
                if (list.Contains("ProductionDate"))
                {
                    btFormat.SetNamedSubStringValue("ProductionDate", data.ProductionDate.ToString("yyyy-MM-dd"));
                }
                if (list.Contains("ProductionModel"))
                {
                    btFormat.SetNamedSubStringValue("ProductionModel", data.ProductionModel);
                }
                if (list.Contains("ProductionName"))
                {
                    btFormat.SetNamedSubStringValue("ProductionName", data.ProductionName);
                }
                if (list.Contains("ExpirationMonth"))
                {
                    btFormat.SetNamedSubStringValue("ExpirationMonth", data.ExpirationMonth);
                }
                if (list.Contains("BatchNo"))
                {
                    btFormat.SetNamedSubStringValue("BatchNo", batchNo);
                }
                if (list.Contains("CheckNo"))
                {
                    btFormat.SetNamedSubStringValue("CheckNo", data.CheckNo);
                }
                if (list.Contains("RoughWeight"))
                {
                    btFormat.SetNamedSubStringValue("RoughWeight", data.RoughWeight);
                }

                if (list.Contains("WeightPerBucket"))
                {
                    btFormat.SetNamedSubStringValue("WeightPerBucket", weightPerBucket);
                }

                if (list.Contains("WeightPerBucketLast"))
                {
                    btFormat.SetNamedSubStringValue("WeightPerBucketLast", weightPerBucketLast);
                }

                var s = btFormat.PrintOut(false, false);
                //}

                btFormat.Close(BarTender.BtSaveOptions.btDoNotSaveChanges);
                btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
                return(batchNo);
            }
            catch (Exception ex)
            {
                btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
                throw new Exception(ex.Message);
            }
            finally
            {
                if (btApp != null)
                {
                    btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
                }
            }
        }
Example #16
0
        public string BarTenderPrintA4 <T>(IEnumerable <T> lists, BarTenderPrintConfigModelXX config, int totalPages)
        {
            string printerName       = config.PrinterName;                                                                                                   // 打印机名称
            int    templateTotalPage = config.TemplateSelectedItem.TemplateTotalPage;                                                                        //一张A4纸里面的小张数
            int    pages             = (int)Math.Ceiling(totalPages / (double)templateTotalPage);                                                            // 应该打印A4纸张数
            int    initPages         = pages;                                                                                                                //原始打印张数
            int    remainCount       = totalPages % templateTotalPage;                                                                                       // 最后一个模板张数

            string templateName    = config.TemplateSelectedItem.TemplateFullName;                                                                           //通用模板名称
            string newtemplateName = remainCount == 0 ? Path.Combine(config.TemplateSelectedItem.TemplateFolderPath, $"1{config.TemplateSelectedItem.TemplateFileName.Substring(1)}")
                : Path.Combine(config.TemplateSelectedItem.TemplateFolderPath, $"{remainCount}{config.TemplateSelectedItem.TemplateFileName.Substring(1)}"); // 最后一个模板名称

            BarTender.Application btApp = new BarTender.Application();
            try
            {
                #region  整数张数数据打印

                // 最多纸张模板
                BarTender.Format btFormat = btApp.Formats.Open(templateName, false, "");
                btFormat.PrintSetup.Printer = printerName;
                btFormat.PrintSetup.NumberSerializedLabels = 1;
                btFormat.PrintSetup.IdenticalCopiesOfLabel = 1;
                string nameValues = "," + btFormat.NamedSubStrings.GetAll("|", ",");
                Regex  rg         = new Regex(@",([^|]*)", RegexOptions.IgnoreCase);
                var    fieldLists = GetTendarFieldName(nameValues.Replace(Environment.NewLine, ""), rg);

                // 剩余部分模板
                BarTender.Format btFormat1   = null;
                List <string>    fieldLists1 = new List <string>();
                if (remainCount > 0)
                {
                    btFormat1 = btApp.Formats.Open(newtemplateName, false, "");
                    btFormat1.PrintSetup.Printer = printerName;
                    btFormat1.PrintSetup.NumberSerializedLabels = 1;
                    btFormat1.PrintSetup.IdenticalCopiesOfLabel = 1;
                    string nameValues1 = "," + btFormat1.NamedSubStrings.GetAll("|", ",");
                    Regex  rg1         = new Regex(@",([^|]*)", RegexOptions.IgnoreCase);
                    fieldLists1 = GetTendarFieldName(nameValues1.Replace(Environment.NewLine, ""), rg1);
                }


                //对各个部分赋值
                int beginPartId = 0;

                //StringBuilder logStrings = new StringBuilder();
                foreach (var entry in lists)
                {
                    //某行记录的打印张数,直接写日志
                    int printCount = GetPrintCountAndWriteLog(entry);

                    // 如果本次打印张数超过一张A4纸上
                    while (printCount + beginPartId >= templateTotalPage)
                    {
                        for (int z = beginPartId; z < templateTotalPage; z++)
                        {
                            SetTemplateNamedSubStringValueToPartN(btFormat, fieldLists, entry, z);
                        }

                        printCount  = printCount + beginPartId - templateTotalPage;
                        beginPartId = 0;
                        pages--;
                        var s1 = btFormat.PrintOut(false, false);
                        if (s1 != 0)
                        {
                            btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
                            return("打印结果不正常,打开模板手动打印取消警告窗口");
                        }
                    }

                    //单条记录完全打印最后新开一张A4打印的数据(先部分赋值,和剩下行记录数据一起打印)
                    if (printCount > 0)
                    {
                        for (int z = beginPartId; z < printCount + beginPartId; z++)
                        {
                            if (pages == 1 && remainCount > 0) //最后一页把值赋到第二个模板上
                            {
                                SetTemplateNamedSubStringValueToPartN(btFormat1, fieldLists1, entry, z);
                            }
                            else
                            {
                                SetTemplateNamedSubStringValueToPartN(btFormat, fieldLists, entry, z);
                            }
                        }
                        beginPartId += printCount;
                    }
                }

                // 如果是最后一张A4的打印情况下, 新开模板赋值打印
                if (pages == 1)
                {
                    if (remainCount == 0)
                    {
                        var s111 = btFormat.PrintOut(false, false);
                        btFormat.Close(BarTender.BtSaveOptions.btDoNotSaveChanges);
                        if (s111 != 0)
                        {
                            btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
                            return("打印结果不正常,打开模板手动打印取消警告窗口");
                        }
                    }
                    else
                    {
                        var s222 = btFormat1.PrintOut(false, false);
                        btFormat1.Close(BarTender.BtSaveOptions.btDoNotSaveChanges);
                        btFormat.Close(BarTender.BtSaveOptions.btDoNotSaveChanges);
                        if (s222 != 0)
                        {
                            btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
                            return("打印结果不正常,打开模板手动打印取消警告窗口");
                        }
                    }
                }
                #endregion
                // 写日志
                //new CommonService().ExecuteSqlAsyncReturns(logStrings.ToString());
                return("打印成功");
            }
            catch (Exception ex)
            {
                btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
                throw new Exception(ex.Message);
            }
            finally
            {
                if (btApp != null)
                {
                    btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
                }
            }
        }
Example #17
0
        public bool BarTenderOilSampleEntryMergePrint(BarTenderPrintConfigModel config, ObservableCollection <OilSampleEntryModel> data, int printTotalNum, List <BarTenderTemplateModel> barTenderTemplates)
        {
            string printerName = config.PrinterName;

            string templateName = barTenderTemplates.FirstOrDefault(m => m.TemplatePerPage == printTotalNum && m.TemplateTotalPage == 4).TemplateFullName;
            List <OilSampleFlowPrintLogModel> logs = new List <OilSampleFlowPrintLogModel>();

            BarTender.Application btApp = new BarTender.Application();
            try
            {
                BarTender.Format btFormat = btApp.Formats.Open(templateName, false, "");
                btFormat.PrintSetup.Printer = printerName;
                string nameValues = "," + btFormat.NamedSubStrings.GetAll("|", ",");
                Regex  rg         = new Regex(@",([^|]*)", RegexOptions.IgnoreCase);
                var    list       = GetTendarFieldName(nameValues.Replace(Environment.NewLine, ""), rg);
                btFormat.PrintSetup.NumberSerializedLabels = 1;
                btFormat.PrintSetup.IdenticalCopiesOfLabel = 1;
                int z = 0;
                for (int i = 0; i < data.Count; i++)
                {
                    var    entry   = data[i];
                    string batchNo = new OilSampleService().GetOilSampleEntryBatchNo(entry.Id);
                    if (string.IsNullOrEmpty(batchNo))
                    {
                        var seq = new CommonService().GetCurrentDateNextSerialNumber(entry.ProductionDate, "OilSamplePrintBatchNo");
                        batchNo = entry.ProductionDate.ToString("yyMMdd") + seq.ToString().PadLeft(3, '0');
                    }
                    entry.BatchNo = batchNo;
                    logs.Add(new OilSampleFlowPrintLogModel
                    {
                        FormsonId    = entry.Id,
                        FormmainId   = entry.FormmainId,
                        EntryId      = entry.EntryId,
                        PrintCount   = entry.CurrencyPrintCount,
                        PrintedCount = entry.PrintedCount + entry.CurrencyPrintCount,
                        BatchNo      = entry.BatchNo,
                        TypeId       = config.TemplateTypeId,
                        TypeDesc     = config.TemplateTypeName
                    });

                    for (int j = 0; j < entry.CurrencyPrintCount; j++)
                    {
                        z++;
                        if (entry.PrintedCount + entry.CurrencyPrintCount >= entry.PrintTotalCount && j == entry.CurrencyPrintCount - 1 && entry.TotalWeight % entry.WeightPerBucket != 0)
                        {
                            entry.WeightPerBucket = (float)Math.Round(entry.TotalWeight % entry.WeightPerBucket, 2);
                        }
                        switch (z)
                        {
                        case 1: SetTemplateNamedSubStringValueToPart1(btFormat, list, entry); break;

                        case 2: SetTemplateNamedSubStringValueToPart2(btFormat, list, entry); break;

                        case 3: SetTemplateNamedSubStringValueToPart3(btFormat, list, entry); break;

                        case 4: SetTemplateNamedSubStringValueToPart4(btFormat, list, entry); break;

                        default: break;
                        }
                    }
                }

                var s = btFormat.PrintOut(false, false);

                // 写日志
                foreach (var item in logs)
                {
                    var result = new OilSampleService().InsertOilSampleFlowLog2(item);
                    if (!result)
                    {
                        return(false);
                    }
                }


                btFormat.Close(BarTender.BtSaveOptions.btDoNotSaveChanges);
                btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
                return(true);
            }
            catch (Exception ex)
            {
                btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
                throw new Exception(ex.Message);
            }
            finally
            {
                if (btApp != null)
                {
                    btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
                }
            }
        }
Example #18
0
        private void btnPrint_Click(object sender, EventArgs e)
        {
            int count = 0;

            if (boxLabels != null && boxLabels.Count > 0)
            {

                try
                {
                    foreach (BoxLabel flb in boxLabels)
                    {

                        string path = "C:\\box_label\\Production_box_label.bt.btw";

                        btApp.Visible = false;
                        btformat = btApp.Formats.Open(path, true, "");

                        // barcode
                        btformat.SetNamedSubStringValue("name", flb.CompleteNo); // 1.completeno
                        btformat.SetNamedSubStringValue("model", flb.ModelNo); // 2.model_no
                        btformat.SetNamedSubStringValue("Date", flb.ProductDate); // 3.production_date
                        btformat.SetNamedSubStringValue("qty", flb.Quantity); // 4.qty
                        btformat.SetNamedSubStringValue("box", Convert.ToDouble(flb.Serial).ToString()); // 5.box_no
                        btformat.SetNamedSubStringValue("mold", flb.MoldNo); // 6.mold_no

                        // text
                        List<CompleteNumber> cnums = new List<CompleteNumber>();
                        cnums = service.getCompleteByComplete(flb.CompleteNo);

                        if (cnums != null && cnums.Count > 0) {
                            btformat.SetNamedSubStringValue("customer", cnums[0].Customer);   // 1.complete_number.customer
                            btformat.SetNamedSubStringValue("part_name", cnums[0].PartName); // // 3.complete_number.part_name
                            btformat.SetNamedSubStringValue("model_no", model.Name);  //  // 4.complete_number.model_no
                        }
                        btformat.SetNamedSubStringValue("part_name", completeNumbers[0].PartName); // // 3.complete_number.part_name
                        btformat.SetNamedSubStringValue("customer", model.Customer); // // 3.complete_number.part_name
                        btformat.SetNamedSubStringValue("model_no", model.Name);  //  // 4.complete_number.model_no
                        btformat.SetNamedSubStringValue("complete_no", flb.CompleteNo);  // 2.complete_number.complete_no
                        btformat.SetNamedSubStringValue("mold_no", flb.MoldNo); // 5.box_label.mold_no
                        btformat.SetNamedSubStringValue("product_date", flb.ProductDate); // 6.box_label.product_date
                        btformat.SetNamedSubStringValue("quantity", flb.Quantity); // 7.box_label.quantity
                        btformat.SetNamedSubStringValue("serial", Convert.ToDouble(flb.Serial).ToString());  //8.box_label.serial
                        btformat.SetNamedSubStringValue("supplier", boxNumbers[0].Suplier);

                        btformat.PrintOut(false, false);

                        // insert to database
                        BoxLabel fbl = boxLabelService.GetByBarCode(flb.BarCodeNo);
                        if (fbl == null)
                        {
                            int result = boxLabelService.CreateInjectionBoxLabel(flb);
                            if (result > -1)
                            {
                                Console.WriteLine("Insert Complete");
                                count++;
                            }
                            else
                            {
                                Console.WriteLine("Insert Not Complete");
                            }
                        }

                    }

                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
                finally
                {
                    btformat.Close(BarTender.BtSaveOptions.btDoNotSaveChanges);
                }

                lblresult.Visible = true;
                lblresult.Text = " บันทึกเรียบร้อยจำนวน  : " + count + "   รายการ";

            }
        }
        private void btnPrint_Click(object sender, EventArgs e)
        {
            int count = 0;

            if (paintingLabels != null && paintingLabels.Count > 0) {

                foreach (PaintingLabels flb in paintingLabels)
                {
                    // string path = Application.StartupPath + @"Finishing_Assy_Label\TXFKY5Z0026(TH-P42GT30).btw";
                    string path = "C:\\Finishing_Paint\\TKP5ZA01901 paint.btw";

                    btApp.Visible = false;
                    btformat = btApp.Formats.Open(path, true, "");

                    // barcode
                    btformat.SetNamedSubStringValue("part", flb.Part); // 1.part
                    btformat.SetNamedSubStringValue("production_date", flb.ProductDate); // 2.production_date
                    btformat.SetNamedSubStringValue("serail", Convert.ToDouble(flb.Serial).ToString("00000")); // 3.serail
                    btformat.SetNamedSubStringValue("shift", flb.Shift); // 4.shift
                    btformat.SetNamedSubStringValue("rev", flb.Rev); // 5.rev
                    btformat.SetNamedSubStringValue("color_nob", paintingColors[0].Name); // 6.color_no
                    btformat.SetNamedSubStringValue("process", "Paint," + flb.ProCess); // 7.process

                    // text
                    btformat.SetNamedSubStringValue("part", flb.Part);  // 1.painting_labels.part
                    btformat.SetNamedSubStringValue("product_date", flb.ProductDate); // 2.painting_labels.product_date
                    btformat.SetNamedSubStringValue("serail", Convert.ToDouble(flb.Serial).ToString("00000")); // 3.painting_labels.serail
                    btformat.SetNamedSubStringValue("ship", flb.Shift); // 4.painting_labels.ship
                    btformat.SetNamedSubStringValue("color_no", "Paint," + flb.ProCess); // 5.painting_labels.color_no
                    btformat.SetNamedSubStringValue("mold_no", "#" + flb.Mold); // 6.mold_no

                    btformat.PrintOut(false, false);

                    // insert to database
                    PaintingLabels fbl = paintingService.GetByBarCode(flb.BarCode);
                    if (fbl == null)
                    {
                        int result = paintingService.CreatePaintingLabel(flb);
                        if (result > -1)
                        {
                            Console.WriteLine("Insert Complete");
                            count++;
                        }
                        else
                        {
                            Console.WriteLine("Insert Not Complete");
                        }
                    }

                }

                lblresult.Visible = true;
                lblresult.Text = " บันทึกเรียบร้อยจำนวน  : " + count + "   รายการ";

            }
        }
Example #20
0
        public bool BarTenderExpressPrint(BarTenderPrintConfigModelXX config, decimal formmainId)
        {
            string printerName  = config.PrinterName;
            string templateName = config.TemplateSelectedItem.TemplateFullName;

            BarTender.Application btApp = new BarTender.Application();
            try
            {
                var data = new OilSampleService().GetExpressPrintData(formmainId);
                BarTender.Format btFormat = btApp.Formats.Open(templateName, false, "");
                btFormat.PrintSetup.Printer = printerName;

                string nameValues = "," + btFormat.NamedSubStrings.GetAll("|", ",");
                Regex  rg         = new Regex(@",([^|]*)", RegexOptions.IgnoreCase);
                var    list       = GetTendarFieldName(nameValues.Replace(Environment.NewLine, ""), rg);
                btFormat.PrintSetup.IdenticalCopiesOfLabel = 1;
                btFormat.PrintSetup.NumberSerializedLabels = 1;

                //btFormat.SetNamedSubStringValue("AA", data.SendName);

                if (list.Contains("SendName"))
                {
                    btFormat.SetNamedSubStringValue("SendName", data.SendName);
                }
                if (list.Contains("SendPhone"))
                {
                    btFormat.SetNamedSubStringValue("SendPhone", data.SendPhone);
                }
                if (list.Contains("SendCompanyName"))
                {
                    btFormat.SetNamedSubStringValue("SendCompanyName", data.SendCompanyName);
                }
                if (list.Contains("SendAddress"))
                {
                    btFormat.SetNamedSubStringValue("SendAddress", data.SendAddress);
                }
                if (list.Contains("ContractMan"))
                {
                    btFormat.SetNamedSubStringValue("ContractMan", data.ContractMan);
                }
                if (list.Contains("ContractPhone"))
                {
                    btFormat.SetNamedSubStringValue("ContractPhone", data.ContractPhone);
                }
                if (list.Contains("ContractCompanyName"))
                {
                    btFormat.SetNamedSubStringValue("ContractCompanyName", data.ContractCompanyName);
                }
                if (list.Contains("ContractAddress"))
                {
                    btFormat.SetNamedSubStringValue("ContractAddress", data.ContractAddress);
                }

                /* var s= 结果是0 可能是成功的意思 */
                var s = btFormat.PrintOut(false, false);
                btFormat.Close(BarTender.BtSaveOptions.btDoNotSaveChanges);
                btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
                return(true);
            }
            catch (Exception ex)
            {
                btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
                throw new Exception(ex.Message);
            }
            finally
            {
                if (btApp != null)
                {
                    btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
                }
            }
        }
Example #21
0
        //打印条码
        public void OnPrintSampleBarcode(string barcode, int pageCount, string nameCode)
        {
            bool      addjkbool = false;
            DataTable dt        = null;

            if (grjdxx != null)
            {
                string cardcode = grjdxx.Cardcode;
                if (!"".Equals(cardcode))
                {
                    dt = grjddao.judgeRepeat(textBox3.Text);
                }
                else
                {
                    dt = grjddao.judgeRepeatBync(textBox1.Text, textBox8.Text);
                }
                if (dt.Rows.Count < 1)
                {
                    if (!"".Equals(cardcode))
                    {
                        grjdxx.archive_no = cardcode;
                    }
                    grjdxx.doctor_id = basicInfoSettings.zeren_doctorId;
                    grjddao.addgrjdInfo(grjdxx); //添加个人信息档案
                    registrationRecordCheck();   //右侧统计
                }
                else
                {
                    grjdxx.archive_no = dt.Rows[0]["archive_no"].ToString();
                    grjddao.updategejdInfonew(grjdxx, 0);
                    //grjdxx.archive_no = dt.Rows[0]["archive_no"].ToString();
                    //grjdxx.doctor_id= dt.Rows[0]["doctor_id"].ToString();
                    //grjddao.updateGrjdInfo(grjdxx.archive_no, grjdxx.photo_code);
                    //grjddao.updategejdInfo(grjdxx);
                }
                grjddao.addPhysicalExaminationInfo(grjdxx, barcode);//添加健康体检表信息
                jkBean jk = new jkBean();
                jk.aichive_no   = grjdxx.archive_no;
                jk.id_number    = grjdxx.Cardcode;
                jk.bar_code     = barcode;
                jk.Pic1         = grjdxx.CardPic;
                jk.Pic2         = grjdxx.Cardcode + ".jpg";
                jk.village_code = basicInfoSettings.xcuncode;
                jk.address      = grjdxx.Zhuzhi;
                jk.name         = grjdxx.name;
                jk.sex          = grjdxx.Sex;
                jk.age          = grjdxx.age;
                jk.JddwName     = basicInfoSettings.organ_name;
                jk.JdrName      = basicInfoSettings.input_name;
                jk.ZrysName     = basicInfoSettings.zeren_doctor;
                jk.XzjdName     = basicInfoSettings.xzName;
                jk.CjwhName     = basicInfoSettings.xcName;
                addjkbool       = grjddao.addJkInfo(jk);
                textBox5.Text   = jk.aichive_no;
                textBox6.Text   = barcode;
                if (addjkbool)
                {   //体检信息统计表
                    grjddao.addBgdcInfo(grjdxx, barcode, basicInfoSettings.xcuncode);
                }
            }
            try
            {
                if (addjkbool)
                {
                    //调用Bartender
                    btApp = new BarTender.Application();
                    //获取打印模板,指定打印机
                    btFormat = btApp.Formats.Open(@str + "\\cs1.btw", false, "");
                    // 同样标签的份数
                    btFormat.PrintSetup.IdenticalCopiesOfLabel = pageCount;
                    // 序列标签数
                    btFormat.PrintSetup.NumberSerializedLabels = 1;
                    //设置参数 code
                    btFormat.SetNamedSubStringValue("code", barcode);
                    btFormat.SetNamedSubStringValue("nameCode", nameCode);
                    //打印开始 第2个参数是 是否显示打印机属性的。可以设置打印机路径
                    btFormat.PrintOut(false, false);
                    //关闭摸板文件,并且关闭文件流
                    btFormat.Close(BarTender.BtSaveOptions.btDoNotSaveChanges);
                    //打印完毕
                    btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
                    jkjcheckdao.updateShDevice(-1, -1, 1, -1, -1, -1, -1, -1, -1, -1);
                }
            }
            catch (Exception e)
            {
                loginLogBean lb = new loginLogBean();
                lb.name       = frmLogin.name;
                lb.createTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                lb.eventInfo  = "打印机设备连接不正确!";
                lb.type       = "3";
                logservice.addCheckLog(lb);
                MessageBox.Show(e.Message + "---" + e.StackTrace);
                MessageBox.Show("打印机设备连接不正确,请重新连接或重启!");
                jkjcheckdao.updateShDevice(-1, -1, 0, -1, -1, -1, -1, -1, -1, -1);
            }
            Common.SetComboBoxInfo(comboBox7, ltdorganizationDao.GetShengInfo());//默认区域
            DataTable dtbasic = bsdao.checkBasicsettingInfo();

            if (dtbasic.Rows.Count > 0)
            {
                xcuncode  = dtbasic.Rows[0]["cun_code"].ToString();
                shengcode = dtbasic.Rows[0]["sheng_code"].ToString();
                Common.SetComboBoxInfo(comboBox6, ltdorganizationDao.GetCityInfo(shengcode));
                shicode = dtbasic.Rows[0]["shi_code"].ToString();
                Common.SetComboBoxInfo(comboBox3, ltdorganizationDao.GetCountyInfo(shicode));
                qxcode = dtbasic.Rows[0]["qx_code"].ToString();
                Common.SetComboBoxInfo(comboBox4, areadao.zhenInfo(qxcode));
                xzcode = dtbasic.Rows[0]["xz_code"].ToString();
                Common.SetComboBoxInfo(comboBox5, areadao.cunInfo(xzcode));
                //因为名称有可能对应不上那么就用code对应
                Common.SetComboBoxSelectIndex(comboBox7, shengcode);
                Common.SetComboBoxSelectIndex(comboBox6, shicode);
                Common.SetComboBoxSelectIndex(comboBox3, qxcode);
                Common.SetComboBoxSelectIndex(comboBox4, xzcode);
                Common.SetComboBoxSelectIndex(comboBox5, xcuncode);
            }
        }
        private void btnPrint_Click(object sender, EventArgs e)
        {
            int count = 0;

            if (injectionCabinetLabels != null && injectionCabinetLabels.Count > 0)
            {

                foreach (InjectionCabinetLabel inj in injectionCabinetLabels)
                {
                    try
                    {

                        // string path = Application.StartupPath + @"Injection_Label\1.btw";
                        string path = "C:\\Injection_Label\\TKY5ZA02501(46SCabinetMC16002).btw";

                        btApp.Visible = false;
                        btformat = btApp.Formats.Open(path, true, "");

                        // barcode
                        btformat.SetNamedSubStringValue("part_no", inj.Part); // 1.part_no
                        btformat.SetNamedSubStringValue("production_date", inj.date); // 2.production_date
                        btformat.SetNamedSubStringValue("serialno", Convert.ToDouble(inj.Serial).ToString("00000")); // 3.serialno
                        btformat.SetNamedSubStringValue("shift", inj.Shift); // 4.shift
                        btformat.SetNamedSubStringValue("rev", inj.Rev); // 5.rev
                        btformat.SetNamedSubStringValue("meterialno", injectionMaterial.Name); // 6.meterialno
                        btformat.SetNamedSubStringValue("lotno", inj.LotNo); // 7.lotno
                        btformat.SetNamedSubStringValue("colorno", injectionColors.Name); // 8.colorno
                        btformat.SetNamedSubStringValue("machine_no", injectionMachine.Name); // 9.machine_no
                        btformat.SetNamedSubStringValue("mold_no", inj.MoldNo); //10. mold_no

                        // text
                        btformat.SetNamedSubStringValue("part", inj.Part); // 1.injection_cabinet_labels.part
                        btformat.SetNamedSubStringValue("product_date", inj.date); // 2.injection_cabinet.labels.product_date
                        btformat.SetNamedSubStringValue("serial", Convert.ToDouble(inj.Serial).ToString("00000"));  // 3.injection_cabinet.labels.serial
                        btformat.SetNamedSubStringValue("ship", inj.Shift); // 4.injection_cabinet.labels.ship
                        btformat.SetNamedSubStringValue("rev", inj.Rev); // 5.injection_cabinet.labels.rev
                        btformat.SetNamedSubStringValue("machine_no", injectionMachine.Name);  // 6.injection_cabinet.labels.machine_no

                        btformat.PrintOut(false, false);

                        // insert to database
                        InjectionCabinetLabel injold = injectionService.GetByCode(inj.BarCode);
                        if (injold == null)
                        {

                            int result = injectionService.CreateInjectionCabinetLabel(inj);
                            if (result > -1)
                            {
                                Console.WriteLine("Insert Complete");
                                count++;
                            }
                            else
                            {
                                Console.WriteLine("Insert Not Complete");
                            }
                        }

                    }

                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }
                    finally
                    {
                        btformat.Close(BarTender.BtSaveOptions.btDoNotSaveChanges);
                    }

                    lblresult.Visible = true;
                    lblresult.Text = " บันทึกเรียบร้อยจำนวน  : " + count + "   รายการ";

                }

            }
        }
Example #23
0
 public void GanDuongDanBTlabel(string path)
 {
     strpath  = path;
     btFormat = btApp.Formats.Open(strpath, true, "");//reload
 }
Example #24
0
        private void cmdprint_Click(object sender, EventArgs e)
        {
            if (txtmodel.Text=="")
            {
                XtraMessageBox.Show("กรุณาเลือก Part ก่อน  !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                txtmodel.Focus();
                return;
            }

            string _dtDate = dateTimePicker2.Value.ToShortDateString();

            string[] _days = Regex.Split(_dtDate, "/");
            int year = Convert.ToInt32(_days[2]) - 543;
            int mount = Convert.ToInt32(_days[0]);

            int mm = Convert.ToInt32(_days[1]);

            plabel2.Entities.Label newLabel = new plabel2.Entities.Label();
            newLabel.PartName = part.Ckt;
            newLabel.SerialNo = txtlastserial.Text.Trim();
            newLabel.PrintTime = dateTimePicker2.Value;
            newLabel.Line = "A";
            newLabel.Ckt = part.Ckt;
            newLabel.Model = txtmodel.Text.Trim();
            newLabel.OilType = part.OilType;
            newLabel.OilWeight = part.OilWeight;
            newLabel.Status = "3";
            newLabel.Run = Convert.ToInt32(run.ToString());
            newLabel.MM = mm.ToString();
            //print

               int count =Convert.ToInt32(txtqty.Text.Trim());
               for (int i=0;i< count;i++){

                string path = Application.StartupPath + @"\TEST.btw";

                btApp.Visible = false;
                btformat = btApp.Formats.Open(path, true, "");
                btformat.SetNamedSubStringValue("customerpart", newLabel.PartName);
                btformat.SetNamedSubStringValue("ckt", newLabel.Ckt);
                btformat.SetNamedSubStringValue("serial", newLabel.SerialNo);
                btformat.SetNamedSubStringValue("oilweight", newLabel.OilWeight);
                btformat.SetNamedSubStringValue("oiltype", newLabel.OilType);
                btformat.SetNamedSubStringValue("model", newLabel.Model);

                btformat.PrintOut(false, false);
               }

            using (ITransaction tx = Session.BeginTransaction())
            {
                Session.Save(newLabel);
                Session.Flush();
                tx.Commit();
            }

            XtraMessageBox.Show("บันทึกเรียบร้อยแล้ว ");
        }
Example #25
0
        public static void print(String dataPath, BarTender.Format btFormat)
        {
            StreamReader sr              = new StreamReader(dataPath, Encoding.Default);
            String       breedName       = "";
            String       gradeName       = "";
            String       proLotNum       = "";
            String       productPirntNum = "";
            String       line;

            String[] lines;
            while ((line = sr.ReadLine()) != null)
            {
                lines = line.Split('|');
                for (int i = 0; i < lines.Length; i++)
                {
                    //Console.WriteLine(lines[i]);
                    if (i == 0)
                    {
                        breedName = lines[i];
                    }
                    else if (i == 1)
                    {
                        gradeName = lines[i];
                    }
                    else if (i == 2)
                    {
                        proLotNum = lines[i];
                    }
                    else if (i == 3)
                    {
                        if (lines[i].Contains(","))
                        {                      //一页一页的打印,如2,3
                            String[] numArray = lines[i].Split(',');
                            for (int k = 0; k < numArray.Length; k++)
                            {
                                //Console.WriteLine(getPrintNum(numArray[k]));
                                productPirntNum = getPrintNum(numArray[k]);
                                btFormat.SetNamedSubStringValue("联合品牌名", breedName);
                                btFormat.SetNamedSubStringValue("产品等级", gradeName);
                                btFormat.SetNamedSubStringValue("条码", proLotNum + productPirntNum);
                                btFormat.PrintOut(false, false);
                                Thread.Sleep(1000);
                            }
                        }
                        else if (lines[i].Contains("-"))
                        {                                             //批量打印,如1-20
                            String[] twoNumArray = lines[i].Split('-');
                            for (int k = int.Parse(twoNumArray[0]); k <= int.Parse(twoNumArray[1]); k++)
                            {
                                String numString = System.Convert.ToString(k);
                                //Console.WriteLine(getPrintNum(numString));
                                productPirntNum = getPrintNum(numString);
                                btFormat.SetNamedSubStringValue("联合品牌名", breedName);
                                btFormat.SetNamedSubStringValue("产品等级", gradeName);
                                btFormat.SetNamedSubStringValue("条码", proLotNum + productPirntNum);
                                btFormat.PrintOut(false, false);
                                Thread.Sleep(1000);
                            }
                        }
                        else
                        {
                            String numString = System.Convert.ToString(lines[i]);
                            //Console.WriteLine(getPrintNum(numString));
                            productPirntNum = getPrintNum(numString);
                            btFormat.SetNamedSubStringValue("联合品牌名", breedName);
                            btFormat.SetNamedSubStringValue("产品等级", gradeName);
                            btFormat.SetNamedSubStringValue("条码", proLotNum + productPirntNum);
                            btFormat.PrintOut(false, false);
                            Thread.Sleep(1000);
                        }
                    }
                }
            }
            sr.Close();
        }