using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http.Json; using System.Text; using System.Text.Json.Serialization; using System.Threading.Tasks; using Newtonsoft.Json; using SuperSocket.Client; using JsonSerializer = System.Text.Json.JsonSerializer; namespace DS.Module.FastReport { public static class PrintUtil { public static async Task SendPrintInfo(PrintModel model) { var client = new EasyClient(new DataFilter()).AsClient(); // var client = new EasyClient.AsClient(); if (!await client.ConnectAsync(new IPEndPoint(IPAddress.Loopback,3000))) { return "连接打印服务器失败!"; } var data = new DataPackage(); data.Key = "PRINT"; data.Body = JsonConvert.SerializeObject(model) ; // client.SendAsync(JsonSerializer.SerializeToUtf8Bytes(data)); List buffer = new List(); byte[] tmp = JsonSerializer.SerializeToUtf8Bytes(data); buffer.Add(0xAC); buffer.Add(0x02); buffer.AddRange(BitConverter.GetBytes(tmp.Length).Take(2)); buffer.AddRange(tmp); ArraySegment segment = new ArraySegment(buffer.ToArray()); client.SendAsync(segment); // var result = new DataPackage(); var temp = await client.ReceiveAsync(); var str = Encoding.UTF8.GetString(temp.Data); // client.CloseAsync(); return str; } /// /// /// /// public static string CreateReportPDF(PrintModel model) { // var env = DSIocManage.Instance.GetService(); // var env = context.ServiceProvider.GetService(); // var basePath = env.WebRootPath; string pdfpath = string.Empty; // Report report = new Report(); // report.Load(model.PrintPath); // // // var main = ModelConvertHelper.ToDataTable(model.MainData); // // var detail = ModelConvertHelper.ToDataTable(model.DetailData); // // report.RegisterData(main, "Main"); // report.RegisterData(detail, "Detail"); // // //运行报表 // report.Prepare(); // // // report.Report.(); var fileName = "wwwroot/PDFUpload/" + DateTime.Now +".PDF"; //导出PDF报表 // PDFExport export = new PDFExport(); // report.Export(export, fileName); // report.Dispose(); return fileName; } // private string CreateReportPDF() // { // } } }