2017-07-07 2 views
0

Ich entwickle eine App in Xamarin PCL Typ ... manage nach Druckern suchen, verbinde den Drucker, aber wenn ich meine Variablen drucken möchte, werden diese nicht gedruckt .... (Aber wenn Sie die Gutschein, der standardmäßig bringt) Ich besitze das SDK Zebra LinkOS_XamarinSDK, ich habe meinen Code angehängt .... irgendwelche Hilfe für mich?Drucken Bluetooth Xamarin

Mein SelectPrinterView.cs

public SelectPrinterView(UsuariosMovil usuarioMovil) 
    { 

     Title = "Seleccione una Impresora";   

     printerList = new ObservableCollection<IDiscoveredPrinter>(); 

     printerLv = new ListView 
     { 
      ItemsSource = printerList, 
      ItemTemplate = new DataTemplate(() => 
      { 
       printerLbl = new Label { Text = "No hay Impresoras Seleccionadas" }; 

       Label addressLbl = new Label(); 
      addressLbl.SetBinding(Label.TextProperty, "Address"); 

      Label friendlyLbl = new Label(); 
      friendlyLbl.SetBinding(Label.TextProperty, "FriendlyName"); 

      return new ViewCell 
      { 
       View = new StackLayout 
       { 
        Orientation = StackOrientation.Horizontal, 
        Children = { addressLbl, friendlyLbl } 
       } 
      }; 
     }) 
    }; 
    printerLv.ItemSelected += PrinterLv_ItemSelected; 

My Printing Funktion:

private void sendZplReceipt(IConnection printerConnection) 
     { 
      String tmpHeader = 
        /* 
        Some basics of ZPL. Find more information here : http://www.zebra.com 

        ^XA indicates the beginning of a label 
        ^PW sets the width of the label (in dots) 
        ^MNN sets the printer in continuous mode (variable length receipts only make sense with variably sized labels) 
        ^LL sets the length of the label (we calculate this value at the end of the routine) 
        ^LH sets the reference axis for printing. 
         You will notice we change this positioning of the 'Y' axis (length) as we build up the label. Once the positioning is changed, all new fields drawn on the label are rendered as if '0' is the new home position 
        ^FO sets the origin of the field relative to Label Home ^LH 
        ^A sets font information 
        ^FD is a field description 
        ^GB is graphic boxes (or lines) 
        ^B sets barcode information 
        ^XZ indicates the end of a label 
        */ 

        "^XA" + 

        "^POI^PW400^MNN^LL325^LH0,0" + "\r\n" + 

        "^FO50,50" + "\r\n" + "^A0,N,70,70" + "\r\n" + "^FD Infraccion^FS" + "\r\n" + 

        "^FO50,130" + "\r\n" + "^A0,N,35,35" + "\r\n" + "^FDMunicipal^FS" + "\r\n" + 

        "^FO50,180" + "\r\n" + "^A0,N,25,25" + "\r\n" + "^FDUsuario Movil:^FS" + "\r\n" + 

        "^FO225,180" + "\r\n" + "^A0,N,25,25" + "\r\n" + "^FD" + "" +"^FS" + "\r\n" + 

        "^FO50,220" + "\r\n" + "^A0,N,25,25" + "\r\n" + "^FDFecha:^FS" + "\r\n" + 

        "^FO225,220" + "\r\n" + "^A0,N,25,25" + "\r\n" + "^FD"+ DateTime.Now +"^FS" + "\r\n" + 

        "^FO50,273" + "\r\n" + "^A0,N,30,30" + "\r\n" + "^FDDatos de la Infraccion^FS" + "\r\n" + 

        "^FO280,273" + "\r\n" + "^A0,N,25,25" + "\r\n" + "^FD^FS" + "\r\n" + 

        "^FO50,300" + "\r\n" + "^GB350,5,5,B,0^FS" + "^XZ"; 

      int headerHeight = 325; 

      DateTime date = new DateTime(); 
      string sdf = "yyyy/MM/dd"; 
      string dateString = date.ToString(sdf); 

      string header = string.Format(tmpHeader, dateString); 

      printerConnection.Write(GetBytes(header)); 

      int heightOfOneLine = 40; 

      Double totalPrice = 0; 

      Dictionary<string, string> itemsToPrint = createListOfItems(); 

      foreach (string productName in itemsToPrint.Keys) 
      { 
       string price; 
       itemsToPrint.TryGetValue(productName, out price); 

       String lineItem = "^XA^POI^LL40" + "^FO50,10" + "\r\n" + "^A0,N,28,28" + "\r\n" + "^FD{0}^FS" + "\r\n" + "^FO280,10" + "\r\n" + "^A0,N,28,28" + "\r\n" + "^FD${1}^FS" + "^XZ"; 
       Double tempPrice; 
       Double.TryParse(price, out tempPrice); 
       totalPrice += tempPrice; 
       String oneLineLabel = String.Format(lineItem, productName, price); 

       printerConnection.Write(GetBytes(oneLineLabel)); 

      } 

      long totalBodyHeight = (itemsToPrint.Count + 1) * heightOfOneLine; 

      long footerStartPosition = headerHeight + totalBodyHeight; 

      string tPrice = Convert.ToString(Math.Round((totalPrice), 2)); 

      String footer = String.Format("^XA^POI^LL600" + "\r\n" + 

      "^FO50,1" + "\r\n" + "^GB350,5,5,B,0^FS" + "\r\n" + 

      "^FO50,15" + "\r\n" + "^A0,N,40,40" + "\r\n" + "^FD^FS" + "\r\n" + 

      "^FO175,15" + "\r\n" + "^A0,N,40,40" + "\r\n" + "^FD$^FS" + "\r\n" + 

      "^FO50,130" + "\r\n" + "^A0,N,45,45" + "\r\n" + "^FDFirma Inspector^FS" + "\r\n" + 

      "^FO50,190" + "\r\n" + "^GB350,200,2,B^FS" + "\r\n" + 

      "^FO50,400" + "\r\n" + "^GB350,5,5,B,0^FS" + "\r\n" + 

      "^FO50,420" + "\r\n" + "^A0,N,30,30" + "\r\n" + "^FDwww.AHSEGROUP.com^FS" + "\r\n" + 

      "^FO50,470" + "\r\n" + "^B3N,N,45,Y,N" + "\r\n" + "^FD^FS" + "\r\n" + "^XZ", tPrice); 

      printerConnection.Write(GetBytes(footer)); 

     } 

     private Dictionary<string, string> createListOfItems() 
     { 
      String[] names = { "Motivo: ", "Lugar: ", "RUT: ", "Automovil: ", "Modelo: ", "Color: " }; 
      String[] prices = { "", "", "", "", "", "" }; 
      Dictionary<string, string> retVal = new Dictionary<string, string>(); 

      for (int ix = 0; ix < names.Length; ix++) 
      { 
       retVal.Add(names[ix], prices[ix]); 
      } 
      return retVal;    
     } 

Jede Idee, wie die Parameter aufrufen drucken? .... Ich habe 2 Modelle UsuariosMovil und Verletzungen zugeordnet ... kann mir jemand helfen?

+0

Können Sie ein Bild hinzufügen, was gedruckt wird? – banno

+0

Ein Bild von meinem Gutschein? Oder ein Bild von meinem Bildschirm? @banno –

Antwort

1

Ich kopiert und eingefügt Ihre sendZplReceipt(IConnection printerConnection) und createListOfItems() Methoden und getestet, um zu sehen, was tatsächlich druckt. Wenn Sie Werte für Ihr Array String[] prices eingeben, werden die Werte im Beleg korrekt ausgefüllt. Der Gesamtpreis wird dem Beleg jedoch nicht hinzugefügt. Um dies zu beheben, habe ich {0} in

"^FO175,15" + "\r\n" + "^A0,N,40,40" + "\r\n" + "^FD$^FS" + "\r\n" 

, die die Linie

geändert
"^FO175,15" + "\r\n" + "^A0,N,40,40" + "\r\n" + "^FD${0}^FS" + "\r\n" 

dies das Problem des Gesamtpreises nicht fest auf dem Kassenbon ausgedruckt werden.

String footer = String.Format("^XA^POI^LL600" + "\r\n" + 

     "^FO50,1" + "\r\n" + "^GB350,5,5,B,0^FS" + "\r\n" + 

     "^FO50,15" + "\r\n" + "^A0,N,40,40" + "\r\n" + "^FD^FS" + "\r\n" + 

     "^FO175,15" + "\r\n" + "^A0,N,40,40" + "\r\n" + "^FD${0}^FS" + "\r\n" + 

     "^FO50,130" + "\r\n" + "^A0,N,45,45" + "\r\n" + "^FDFirma Inspector^FS" + "\r\n" + 

     "^FO50,190" + "\r\n" + "^GB350,200,2,B^FS" + "\r\n" + 

     "^FO50,400" + "\r\n" + "^GB350,5,5,B,0^FS" + "\r\n" + 

     "^FO50,420" + "\r\n" + "^A0,N,30,30" + "\r\n" + "^FDwww.AHSEGROUP.com^FS" + "\r\n" + 

     "^FO50,470" + "\r\n" + "^B3N,N,45,Y,N" + "\r\n" + "^FD^FS" + "\r\n" + "^XZ", tPrice);