示例#1
0
        public async Task <IActionResult> Print(int ruloId)
        {
            if (!User.IsInRole("Rulo", AuthType.Update))
            {
                return(Unauthorized());
            }

            var rulo = await factory.Rulos.GetRuloFromRuloID(ruloId);

            string ZPLString = string.Empty;

            ZPLString = System.IO.File.ReadAllText(System.IO.Path.Combine(webHostEnvironment.WebRootPath, "..\\Reports\\RuloLabel.prn"));
            ZPLString = ZPLString.Replace("ReplaceRuloID", rulo.RuloID.ToString());
            ZPLString = ZPLString.Replace("ReplaceStyle", rulo.Style);
            ZPLString = ZPLString.Replace("ReplaceLote", rulo.Lote);
            ZPLString = ZPLString.Replace("ReplaceBeam", rulo.Beam.ToString());
            ZPLString = ZPLString.Replace("ReplaceLoom", rulo.Loom.ToString());
            ZPLString = ZPLString.Replace("ReplaceMeters", rulo.ExitLength.ToString("#,##0.00"));
            ZPLString = ZPLString.Replace("ReplaceDate", DateTime.Now.ToString("yyyy-MM-dd HH:mm"));

            var result = await RawPrinterHelper.PrintToZPLByIP(appSettings.PrinterIP, ZPLString);

            if (!result)
            {
                return(new JsonResult(new { errorMessage = "Error to the print label!" }));
            }

            return(Ok());
        }