You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.9 KiB
C#

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<string> SendPrintInfo(PrintModel model)
{
var client = new EasyClient<DataPackage>(new DataFilter()).AsClient();
// var client = new EasyClient<DataPackage>.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<byte> buffer = new List<byte>();
byte[] tmp = JsonSerializer.SerializeToUtf8Bytes(data);
buffer.Add(0xAC);
buffer.Add(0x02);
buffer.AddRange(BitConverter.GetBytes(tmp.Length).Take(2));
buffer.AddRange(tmp);
ArraySegment<byte> segment = new ArraySegment<byte>(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;
}
/// <summary>
///
/// </summary>
/// <param name="model"></param>
public static string CreateReportPDF(PrintModel model)
{
// var env = DSIocManage.Instance.GetService<IHostingEnvironment>();
// var env = context.ServiceProvider.GetService<IHostingEnvironment>();
// 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()
// {
// }
}
}