|
|
using System;using System.Collections.Generic;using System.Data;using System.Linq;using System.IO;using System.Text;using System.Threading.Tasks;using Report.Entity;using System.Windows.Forms;using System.Reflection;using System.Threading;using System.Net.Cache;
namespace ReportLibrary{ public class ReportClient {
private async Task<DataSet> getBusinessDataSet(RequestReportBase req,bool isSave=false) { DataSet ds = new DataSet(); /* Dictionary<string,string> dict=new Dictionary<string,string>(); foreach(var item in req.Parameters) { dict.Add(item.Name,item.Value); } switch (req.ReportCode) { case "0001": case "0008": ds = await ConvertHelper.PatientGuideToDataSetAsync(req.DataJsonPath, dict, req.WebsiteUrl, req.ApiUrl, isSave); break; case "0002": case "0003": ds = await ConvertHelper.TestRequestToDataSetAsync(req.DataJsonPath, dict, req.WebsiteUrl, req.ApiUrl, isSave); break; case "0004": ds = await ConvertHelper.ExamRequestToDataSetAsync(req.DataJsonPath, dict, req.WebsiteUrl, req.ApiUrl, isSave); break; case "0005": ds = await ConvertHelper.ReportHealthToDataSetAsync(req.DataJsonPath, dict, req.WebsiteUrl, req.ApiUrl,req.ImageUrl, isSave); break; case "0006": ds = await ConvertHelper.OccupationalDiseaseToDataSetAsync(req.DataJsonPath, dict, req.WebsiteUrl, req.ApiUrl,req.ImageUrl, isSave); break; case "0007": ds = await ConvertHelper.PayBillToDataSetAsync(req.DataJsonPath, dict, req.WebsiteUrl, req.ApiUrl, isSave); break; case "0009": ds = await ConvertHelper.OccuptionDiseaseFinalToDataSetAsync(req.DataJsonPath, dict, req.WebsiteUrl, req.ApiUrl, isSave); break; case "0010": ds = await ConvertHelper.OccuptionDiseaseDetailToDataSetAsync(req.DataJsonPath, dict, req.WebsiteUrl, req.ApiUrl, isSave); break; } */ return ds; } public async Task<string> ReportExport(string reqStr) { string resStr = string.Empty; string dataJson = string.Empty; ResponseReport res = new ResponseReport(); try { ReportHelper report = new ReportHelper(); RequestExport req = ClientConfig.DeserializeObject<RequestExport>(reqStr);
if (string.IsNullOrEmpty(req.TemplatePath)) { res.code = -103; res.message = "未找到对应的报表模板文件,无法导出"; return await Task.Run(() => { resStr = ClientConfig.SerializeObject(res);
return resStr; }); } Dictionary<string, string> dict = new Dictionary<string, string>(); foreach (var item in req.Parameters) { dict.Add(item.Name, item.Value); } var list = ReportHelper.ToPicTable(dict, req.WebsiteUrl); DataTable dt=list.ToDataTable(); dt.TableName = "pic"; string json = FileHelper.ReadAllText(req.DataJsonPath); DataSet ds = ClientConfig.ConvertJsonToDataSet(json, req.ImageUrl,req.ApiUrl); ds.Tables.Add(dt); await report.ReportExport(req, ds); res.code = 1; res.message = "Success"; } catch (BusinessException bEx) { res.code = -101; res.message = bEx.Message;
} catch (Exception ex) { res.code = -100; res.message = ex.Message; } resStr = ClientConfig.SerializeObject(res); return resStr; } public async Task<string> ReportPrint(string reqStr) { ResponseReport res = new ResponseReport(); string resStr = string.Empty; string dataJson = string.Empty; try { ReportHelper report = new ReportHelper(); RequestPrint req = ClientConfig.DeserializeObject<RequestPrint>(reqStr); if (string.IsNullOrEmpty(req.TemplatePath)) { res.code = -103; res.message = "未找到对应的报表模板文件,无法打印"; return await Task.Run(() => { resStr = ClientConfig.SerializeObject(res);
return resStr; }); }
Dictionary<string, string> dict = new Dictionary<string, string>(); foreach (var item in req.Parameters) { dict.Add(item.Name, item.Value); } var list = ReportHelper.ToPicTable(dict, req.WebsiteUrl); DataTable dt = list.ToDataTable(); dt.TableName = "pic"; string json = FileHelper.ReadAllText(req.DataJsonPath); DataSet ds = ClientConfig.ConvertJsonToDataSet(json, req.ImageUrl, req.ApiUrl); ds.Tables.Add(dt); string result= await report.ReportPrint(req, ds); if (result.Equals("Success")) { res.code = 1; res.message = "Success"; } else { res.code = -1; res.message = result; }
} catch (BusinessException bEx) { res.code = -101; res.message = bEx.Message;
} catch (Exception ex) { res.code = -100; res.message = ex.Message; } resStr = ClientConfig.SerializeObject(res); return resStr; }
public async Task<string> ReportPrintPre(string reqStr) { ResponseReport res = new ResponseReport(); string resStr = string.Empty; string dataJson = string.Empty; try { ReportHelper report = new ReportHelper(); RequestPrintPre req = ClientConfig.DeserializeObject<RequestPrintPre>(reqStr);
if (string.IsNullOrEmpty(req.TemplatePath)) { res.code = -103; res.message = "未找到对应的报表模板文件,无法预览"; return await Task.Run(() => { resStr = ClientConfig.SerializeObject(res);
return resStr; }); }
Dictionary<string, string> dict = new Dictionary<string, string>(); foreach (var item in req.Parameters) { dict.Add(item.Name, item.Value); } var list = ReportHelper.ToPicTable(dict, req.WebsiteUrl); DataTable dt = list.ToDataTable(); dt.TableName = "pic"; string json = FileHelper.ReadAllText(req.DataJsonPath); string paramJson = ClientConfig.SerializeObject(list); string DataJsonPath = ClientConfig.UpdateJson(json, paramJson); FileHelper.WriteAllText(req.DataJsonPath, DataJsonPath); DataSet ds = ClientConfig.ConvertJsonToDataSet(json, req.ImageUrl, req.ApiUrl); ds.Tables.Add(dt); string fileName= await report.ReportPrintPre(req, ds); res.code = 1; res.data = fileName; res.message = "Success"; } catch (BusinessException bEx) { res.code = -101; res.message = bEx.Message; } catch (Exception ex) { res.code = -100; res.message = ex.Message; } resStr = ClientConfig.SerializeObject(res); return resStr; } public async Task<string> ReportDesign(string reqStr) { ResponseDesign res = new ResponseDesign(); string resStr = string.Empty; try { RequestDesign req = ClientConfig.DeserializeObject<RequestDesign>(reqStr); if (req.DataSetJson == null) { res.code = -102; res.message = "需打印数据为空值,无法打开模板"; return await Task.Run(() => { resStr = ClientConfig.SerializeObject(res);
return resStr; }); } if (string.IsNullOrEmpty(req.TemplatePath)) { res.code = -103; res.message = "未找到对应的报表模板文件,无法打开模板"; return await Task.Run(() => { resStr = ClientConfig.SerializeObject(res);
return resStr; }); } ReportHelper.ReportDesign(req); res.code = 1; res.message = "Success";
} catch (BusinessException bEx) { res.code = -101; res.message = bEx.Message;
} catch (Exception ex) { res.code = -100; res.message = ex.Message; } return await Task.Run(() => { resStr= ClientConfig.SerializeObject(res); return resStr; }); /* Task<String> task = Task.Factory.StartNew<string>(() => { Request req = ClientConfig.DeserializeObject<Request>(reqStr); ResponseEle res = new ResponseEle(); try { ReportHelper.ReportDesign(req); res.Code = 1; res.Message = "Success";
} catch (Exception ex) { res.Code = -1; res.Message = ex.Message; } string resStr = ClientConfig.SerializeObject(res); return resStr; });
String taskResult = await task; return taskResult; */ } }}
|