public static string CreateZPL(ShippingObject externalDocument, TypePrint typePrint) { string fileZpl = typePrint switch { TypePrint.DPI200 => File.ReadAllText(PathLabel("SmartLabel_200.prn")), TypePrint.DPI300 => File.ReadAllText(PathLabel("SmartLabel_300.prn")), TypePrint.DPI600 => File.ReadAllText(PathLabel("SmartLabel_600.prn")), _ => throw new Exception("Printer type not found."), }; fileZpl = Regex .Replace(fileZpl, @"\s+", ""); // Remetente fileZpl = fileZpl.Replace("[REMNOME]", externalDocument.SenderData.Name?.ToUpper()); fileZpl = fileZpl.Replace("[REMENDERECO]", externalDocument.SenderData.Street?.ToUpper()); fileZpl = fileZpl.Replace("[REMNUMERO]", externalDocument.SenderData.Number?.ToUpper()); fileZpl = fileZpl.Replace("[REMBAIRRO]", externalDocument.SenderData.Neighborhood?.ToUpper()); fileZpl = fileZpl.Replace("[REMCEP]", externalDocument.SenderData.ZipCode); fileZpl = fileZpl.Replace("[REMCIDADE]", externalDocument.SenderData.City?.ToUpper()); fileZpl = fileZpl.Replace("[REMUF]", externalDocument.SenderData.State?.ToUpper()); // Destinatário fileZpl = fileZpl.Replace("[DESTNOME]", externalDocument.RecipientData.Name); fileZpl = fileZpl.Replace("[DESTENDERECO]", externalDocument.RecipientData.Street); fileZpl = fileZpl.Replace("[DESTENDERECONUMERO]", externalDocument.RecipientData.Number); fileZpl = fileZpl.Replace("[DESTBAIRRO]", externalDocument.RecipientData.Neighborhood); fileZpl = fileZpl.Replace("[DESTCOMPLEMENTO]", externalDocument.RecipientData.Complement); fileZpl = fileZpl.Replace("[DESTCEP]", externalDocument.RecipientData.ZipCode); fileZpl = fileZpl.Replace("[DESTCIDADE]", externalDocument.RecipientData.City); fileZpl = fileZpl.Replace("[DESTUF]", externalDocument.RecipientData.Street); //Transportadora fileZpl = fileZpl.Replace("[ENCTIPO]", externalDocument.ShippingData.TypeService.ToUpper()); fileZpl = fileZpl.Replace("[VOLCODBARRA]", externalDocument.ShippingData.Barcode.ToUpper()); fileZpl = fileZpl.Replace("[ENCPEDIDO]", externalDocument.ShippingData.Order.ToUpper()); fileZpl = fileZpl.Replace("[VOLROTA]", externalDocument.ShippingData.Route.ToUpper()); //Outros fileZpl = fileZpl.Replace("[DATA]", DateTime.Now.ToString("dd/MM")); fileZpl = fileZpl.Replace("[HORAINI]", DateTime.Now.ToString("HH:mm")); fileZpl = fileZpl.Replace("[HORAFIM]", DateTime.Now.ToString("HH:mm")); return(fileZpl); }
public static void Main() { ShippingObject _dadosRemessa = new ShippingObject(); _dadosRemessa.RecipientData.Name = "Eliana Xavier"; _dadosRemessa.RecipientData.Street = "Praça Conego Ulisses"; _dadosRemessa.RecipientData.Number = "308"; _dadosRemessa.RecipientData.Neighborhood = "Centro"; _dadosRemessa.RecipientData.Complement = "Apartamento 101"; _dadosRemessa.RecipientData.ZipCode = "37270-000"; _dadosRemessa.RecipientData.City = "Campo Belo"; _dadosRemessa.RecipientData.State = "MG"; _dadosRemessa.SenderData.Name = "Sophie e Andreia Contábil Ltda"; _dadosRemessa.SenderData.Street = "Rua Jairo de Aquino Martins"; _dadosRemessa.SenderData.Number = "890"; _dadosRemessa.SenderData.Neighborhood = "Parque das Rodovias"; _dadosRemessa.SenderData.ZipCode = "12605-615"; _dadosRemessa.SenderData.City = "Lorena"; _dadosRemessa.SenderData.State = "SP"; _dadosRemessa.ShippingData.TypeService = "STD"; _dadosRemessa.ShippingData.Route = "DIQ-MG-INT [001]"; _dadosRemessa.ShippingData.Barcode = "diqi00090000000001"; _dadosRemessa.ShippingData.Order = "SDfhsHCD94_001_v"; string path = Directory.GetCurrentDirectory(); var typePrint = TypePrint.DPI300; var typeFile = TypeFile.PDF; Console.WriteLine(String.Format("-----------------------Label {0}-----------------------", typeFile.ToString())); string fileZpl = Zpl.CreateZPL(_dadosRemessa, typePrint); Util.SaveZPLToFile.ZplToFile(fileZpl, typePrint, typeFile); Console.WriteLine(String.Format("------------------Generated {0} File-------------------", typeFile.ToString())); Console.WriteLine("-------------------------Label-------------------------"); Console.WriteLine(fileZpl); }