Exemplo n.º 1
0
        /// <summary>
        /// 通过Bt打印机进行打印
        /// </summary>
        protected virtual void onBtPrint()
        {
            try
            {
                //1.获取默认打印机 填充数据 2.开始打印  3.计数清零 4.Exfo待打印数据列表清零
                //获取默认打印机
                PrintDocument fPrintDocument = new PrintDocument();

                Messages messages = null;
                //设置打印模板
                LabelFormatDocument btFormat = btEngine.Documents.Open(LabPatch + LabName);

                //设置打印机
                btFormat.PrintSetup.PrinterName = fPrintDocument.PrinterSettings.PrinterName;
                btFormat.Activate();

                if (_WTT_LabSetInfo != null)
                {
                    //填充打印数据源
                    foreach (DataRow dr in _WTT_LabSetInfo.Tables[0].Rows)
                    {
                        string drName = dr["Name"].ToString();
                        btFormat.SubStrings[drName].Value = dr["Value"].ToString();
                    }


                    //BT打印临时添加代码变更时间 2015-5-26 变更原因 海信标签需要进行1315打印 而其它的则都不需要1315
                    if (LabName == "海信_RD-A-ELA32983.btw")
                    {
                        Pack_Exfo _M_Pack_Exfo = new Pack_Exfo();
                        //添加打印数据
                        DataSet temds = _M_Pack_Exfo.GetList("ClientSN='" + SN + "'");
                        if (temds.Tables[0].Rows.Count < 4)
                        {
                            My_MessageBox.My_MessageBox_Message("打印数据不足(1310或1550数据不够)请检测标签和数据!请重新上传测试数据");
                        }
                        //填充打印数据源
                        foreach (DataRow dr in temds.Tables[0].Rows)
                        {
                            if (dr["PartNumber"].ToString() == "1" && dr["Wave"].ToString() == "1310nm")
                            {
                                btFormat.SubStrings["IL_One_13"].Value = dr["IL_A"].ToString();
                                btFormat.SubStrings["RL_One_13"].Value = dr["Refl_A"].ToString();
                            }
                            if (dr["PartNumber"].ToString() == "1" && dr["Wave"].ToString() == "1550nm")
                            {
                                btFormat.SubStrings["IL_One_15"].Value = dr["IL_A"].ToString();
                                btFormat.SubStrings["RL_One_15"].Value = dr["Refl_A"].ToString();
                            }
                            if (dr["PartNumber"].ToString() == "2" && dr["Wave"].ToString() == "1310nm")
                            {
                                btFormat.SubStrings["IL_Two_13"].Value = dr["IL_A"].ToString();
                                btFormat.SubStrings["RL_Two_13"].Value = dr["Refl_A"].ToString();
                            }
                            if (dr["PartNumber"].ToString() == "2" && dr["Wave"].ToString() == "1550nm")
                            {
                                btFormat.SubStrings["IL_Two_15"].Value = dr["IL_A"].ToString();
                                btFormat.SubStrings["RL_Two_15"].Value = dr["Refl_A"].ToString();
                            }
                        }
                    }
                }

                btFormat.SubStrings["SN"].Value = SN;

                // Result result = btFormat.Print("PrintJob1", out messages);
                btFormat.Print();
                btFormat.Close(SaveOptions.SaveChanges);
                _LabCount = 0;
                _WTT_NotPrintList.Clear();
                SN = "";
            }
            catch (System.Exception ex)
            { My_MessageBox.My_MessageBox_Message(ex.Message); }
        }