20190626_ secondary development BarTender printer _C # Code _ _ print side while reading TID_ printer POSTEK

 

demo code is as follows:

void btnPrint_Click Private (SENDER Object, EventArgs E) 
        { 
            IF (this.btnPrint.Text == "stop printing") 
            { 
                SetBtnPrintUIEnable (); 
                return; 
            } 
       // disable the associated button on the interface 
            SetBtnPrintUIDisable (); 
            var dt = new new the DataTable ();   
            new new the Task ( 
                () => 
                { 
                    /// start printing 
                    @ 1 acquires the selected dgv source. 
                    dt = GetDgvDataSourceChecked (); 

                    IF (dt.Rows.Count <= 0) 
                    {
                        SetTxtMessageInfo (this.txtMessageError, "nothing selected data can not be printed"); 
                        Common.Contactor.ShowErrorMessage ($ "nothing selected data can not be printed"); 
                        SetBtnPrintUIEnable (); 
                        return; 
                    } 
                    the Thread.Sleep (500); 
                    SetTxtMessageInfo (this.txtMessageInfo, "the data check in..."); 

                    // start printing 
                    string tempPath = ConfigHelper.GetConfigString ( "templateName" ); // template name 
                    Thread.Sleep (500); 
                    SetTxtMessageInfo (this.txtMessageInfo, $ "template name currently in use temppath} {"); 

                    IF (String.IsNullOrEmpty (temppath.Trim()))
                    {  
                         SetTxtMessageInfo (this.txtMessageError, $ "template file {tempPath} may not exist, please adjust"); 
                       the Common .Contactor.ShowErrorMessage ($ "template file {tempPath} may not exist, please adjust");
                        SetBtnPrintUIEnable (); 
                        return; 
                    } 
                    IF (Path.GetExtension (temppath) .Equals ( "BTW")) 
                    { 
                        SetTxtMessageInfo (this.txtMessageError, $ "file format does not support temppath} {"); 
                        Common.Contactor.ShowErrorMessage ( $ "file format does not support temppath} {"); 
                        SetBtnPrintUIEnable (); 
                        return; 
                    } 

                    String FileName = Path.GetFileName (temppath); 
                    String primkey = ConfigHelper.GetConfigString ( "primkey"); 
                    the Thread.Sleep (500);
                    SetTxtMessageInfo (this.txtMessageInfo, "parity data is completed, to start printing..."); 
                        the format = engine.Documents.Open (temppath); // open btw template files on the path 
                        // set default printer 
                        format.PrintSetup.PrinterName = new System.Drawing.Printing.PrintDocument () PrinterSettings. .PrinterName;
                    the using (Engine Engine Engine new new = (to true)) 
                    { 
                        engine.Start (); 
                        IF (the format = null!) 
                        { 
                            format.Close (SaveOptions.DoNotSaveChanges); 
                        } 
                        format.PrintSetup.IdenticalCopiesOfLabel = PrintCount; // Convert.ToInt32 ( GetControlText (this.cboPrintCount)); // 
                        format.PrintSetup.NumberOfSerializedLabels =. 1; 
                        var DCS = dt.Columns.Cast <the DataColumn> (.) the Select ((DC) => dc.Caption {return;}.) Skip ( 1); // the first one to jump out; in fact, the first to jump, do not jump all right 
                        var templateStrs = format.SubStrings.Select ((s) => { s.Name return;.}) the ToArray (); 

                        String diffStr String.Join = ( ",", templateStrs.Except (DCS)); 

                        . IF (diffStr.Trim () the Length> 0) 
                        {
                            SetTxtMessageInfo (this.txtMessageError, $ "in your template file {FileName}, there are these \ r {diffStr} \ r n content identification fields are not about to print \ n \, \ r \ n You must adjust or modify the template data acquisition statement to continue "); 
                            Common.Contactor.ShowErrorRestart ($" in your template file {FileName}, there are these \ r {diffStr} \ r n content identification fields are not about to print \ n \, \ r \ n You must adjust the template or modify data acquisition statements before you can continue "); 
                            SetBtnPrintUIEnable (); 
                            format = null; 
                            return; 
                        } 
                        //" templateStr "value =" bundle number, pattern, length, weight, machine, cloth inspection station, rack number, even clip flag, records the time, the state of bundle number, the date of the electronic tag, the electronic tag number " 
                        lock (engine) must be locked print engine // 
                        { 
                            for (int I = 0; I <dt.Rows .Count; i++) 
                            { 
                                Object oPrimKey = dt.Rows [i] [primKey] ; // get the value corresponding to the primary key column 
                                IF (oPrimKey == oPrimKey.ToString DBNull.Value || () the Length <= 0.) 
                                { 
                                    SetTxtMessageInfo (this.txtMessageError, $ "primary key {primKey} data error, it can not be NULL or empty string "); 
                                    Common.Contactor.ShowErrorMessage ($" {primKey} primary key data error, it can not be NULL or empty string "); 
                                    SetBtnPrintUIEnable (); 
                                    the format = null;
                                    return;
                                } 
                                String currentPrimkey oPrimKey.ToString = (); 
                                String operatorRFIDLabel.GetRFID_TID TID = (); // read tag TID

                                (! RegValidate.WordOrNumber (TID)) IF 
                                { 
                                    SetTxtMessageInfo (this.txtMessageError, $ "TID label content acquisition error {tid}, printing will stop"); 
                                    Common.Contactor.ShowErrorMessage ($ "Get Tag Content Error {tid}, printing will stop "); 
                                    SetBtnPrintUIEnable (); 
                                    the format = null; 
                                    return; 
                                } 

                                for (int J = 0; J <templateStrs.Length; J ++) 
                                {
                                    . format.SubStrings [templateStrs [j]] Value = dt.Rows [i] [templateStrs [j]] ToString ();. // Print templates corresponding to the parameter assignment SN 
                                } 
                                the Messages messages; 
                                int = 10000 waitForCompletionTimeout; / / 10 seconds The 
                                System.Diagnostics.Trace.WriteLine ( "→→→→→→→→→ the TID is" TID +); 
                                the Result = R & lt format.Print ( "", waitForCompletionTimeout, OUT messages); 
                                // String = messageString " \ n-\ nMessages: "; 
                                // the Thread.Sleep (500); 
                                SetTxtMessageInfo (this.txtMessageInfo, $" is the printing of the parts {i + 1},Its primary key code is {oPrimKey} ");
                                Thread.Sleep (2000); // printer according to Booz was measured, it is necessary to stop 2s, otherwise TID will repeat 
                                //// write database, can not block library to write, affect the printer reads the TID timeout 
                                queuePrint.Enqueue (string.Format (ConfigHelper.GetConfigString ( "updateTid"), TID, currentPrimkey.Trim ())); 

                                String = ConfigHelper.GetConfigString COM ( "insertMysql"); 
                                String HN_NO dt.Rows = [I] [ "pattern"] == DBNull ? .Value string.Empty: dt.Rows [i] [ " pattern"] .ToString (); 
                                String GH_NO = dt.Rows [i] [ "bundle No."] == DBNull.Value string.Empty: dt? .Rows [i] [ "bundle number"] .ToString (); 
                                String QTY_XD dt.Rows = [I] [ "length"] == DBNull.Value string?.Empty : dt.Rows[i]["长度"].ToString();
                                string QTY_GJ = dt.Rows[i]["重量"] == DBNull.Value ? string.Empty : dt.Rows[i]["重量"].ToString();
                                string JT_NO = dt.Rows[i]["机台"] == DBNull.Value ? string.Empty : dt.Rows[i]["机台"].ToString();
                                string YB_NO = dt.Rows[i]["验布工"] == DBNull.Value ? string.Empty : dt.Rows[i]["验布工"].ToString();
                                string FJ_NO = dt.Rows[i]["货架号"] == DBNull.Value ? string.Empty : dt.Rows[i]["货架号"].ToString();
                                string LF_ID = dt.Rows[i]["连幅标记"] == DBNull.Value ? string.Empty : dt.Rows[i]["连幅标记"].ToString();
                                DateTime USR_DD = dt.? Rows [i] [ "record time"] == DBNull.Value DateTime.Now: Convert.ToDateTime (dt.Rows [i] [ "record time"]);
                                string GH_STA = dt.Rows [i] [ " bundle number state"] == DBNull.Value string.Empty: dt.Rows [ i] [ " bundle number state"] .ToString ();? 

                                String = strSQL string.Format (ConfigHelper.GetConfigString ( "insertMysql"), TID, HN_NO, GH_NO, QTY_XD, QTY_GJ, JT_NO, YB_NO, FJ_NO, LF_ID, USR_DD, GH_STA); 
                                queuePrint.Enqueue (strSQL); 
                            } 
                        } 
                        format.Close (SaveOptions.DoNotSaveChanges) ; 
                        format = null; 
                        engine.Stop (); 

                        // start the buttons 
                        SetBtnPrintUIEnable ();
                    } 
                }
                ) .Start (); 

          / * 1) Print method: This is the most commonly used printing method, which can be set to print the name of the task, whether to wait for the completion of the printing, wait timeout, the output of the printing process information. 
            2) PrintOut method: If you need to print settings dialog box appears and states at the time of print, you can choose to implement this method. 
            3) Save method: Save Changes to the Format. 
            4) SetNamedSubStringValue Method: setting a specific value of SubString herein can be used as a method for dynamically changing the content of the print. 
            5) SetPromt method: with SetNamedSubStringValue similar method, but he set the value of print prompt, certain labels can pop-up dialog during printing by setting the input value of certain variables to change the print content, this method is the dynamic setting these variables. But it is rarely used in the integration. 
            6) IdenticalCopiesOfLabel property: This is to set the same tag number of copies to be printed when printing the default settings for the label. 
            7) NumberSerializedLabels properties: This is the sequence of the time used for printing, when you start a series of labels, this property represents the number of copies is printed, for example, you are the initial data sequence of 1, increment of 1, NumberSerializedLabels is set to 5, it will print out 1,2,3,4,5, five tabs out. 
            8) Printer Properties: The printer you want to use the default specified for the system default printer
            9) PrintToFile property: is immediately marked with a printer to print out, or was it generates a print file. 
            * / 
        }

  

 

Guess you like

Origin www.cnblogs.com/wxylog/p/11093361.html