From 35695d20941686d828b443369c3c6878ccae2336 Mon Sep 17 00:00:00 2001 From: maqiao <625215135@qq.com> Date: Wed, 13 Mar 2024 16:25:55 +0800 Subject: [PATCH] =?UTF-8?q?1=EF=BC=89=E6=97=A5=E7=BB=93=E5=AD=98=E4=B8=AD?= =?UTF-8?q?=E4=BF=9D=E5=AD=98dm=5Fmachine=5Frecord=E4=B8=BA=E6=80=BB?= =?UTF-8?q?=E5=BA=93=E5=AD=98=E6=95=B0=EF=BC=8C=E9=9D=9E=E6=89=B9=E6=AC=A1?= =?UTF-8?q?=E5=BA=93=E5=AD=98=E6=95=B0=202=EF=BC=89=E7=94=9F=E6=88=90?= =?UTF-8?q?=E6=97=A5=E7=BB=93=E5=AD=98=20=E6=8C=89=E9=92=AE=20=E7=82=B9?= =?UTF-8?q?=E5=87=BB=E6=97=B6=20=E5=85=88=E5=88=A0=E9=99=A4=20=E5=B7=B2?= =?UTF-8?q?=E7=94=9F=E6=88=90=E7=9A=84=E6=97=A5=E7=BB=93=E5=AD=98=EF=BC=8C?= =?UTF-8?q?=E5=86=8D=E6=9F=A5=E8=AF=A2=E6=98=AF=E5=90=A6=E6=9C=89=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E8=AE=B0=E5=BD=95=EF=BC=8C=E5=A6=82=E6=9E=9C=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E5=88=99=E7=94=9F=E6=88=90=E4=B8=80=E6=9D=A1=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=EF=BC=8C=E7=94=9F=E6=88=90=E7=9A=84=E2=80=9C=E5=87=AD?= =?UTF-8?q?=E8=AF=81=E5=8F=B7=E2=80=9D=20=E5=AD=97=E6=AE=B5=E5=88=97?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E4=B8=BA=E2=80=9C=E6=97=A5=E7=BB=93=E5=AD=98?= =?UTF-8?q?=E2=80=9D=E5=AD=97=E6=A0=B7=EF=BC=8C=E2=80=9C=E5=80=9F=E5=85=A5?= =?UTF-8?q?=E6=95=B0=E9=87=8F=E2=80=9D=E4=B8=8E=E2=80=9C=E5=8F=91=E5=87=BA?= =?UTF-8?q?=E6=95=B0=E9=87=8F=E2=80=9D=E4=B8=BA=E8=AF=A5=E8=8D=AF=E5=93=81?= =?UTF-8?q?=E4=B8=8B=E6=89=80=E6=9C=89=E6=89=B9=E6=AC=A1=E6=95=B0=E6=80=BB?= =?UTF-8?q?=E5=92=8C=EF=BC=8C=E2=80=9C=E6=80=BB=E7=BB=93=E5=AD=98=E2=80=9D?= =?UTF-8?q?=E4=B8=BA=E8=AF=A5=E8=8D=AF=E5=93=81=E6=80=BB=E5=BA=93=E5=AD=98?= =?UTF-8?q?=EF=BC=8C=E6=98=BE=E7=A4=BA=E5=BD=93=E6=97=B6=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E7=9A=84=E2=80=9C=E5=8F=91=E8=8D=AF=E4=BA=BA=E2=80=9D=E3=80=81?= =?UTF-8?q?=E2=80=9C=E5=A4=8D=E6=A0=B8=E4=BA=BA=E2=80=9D=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E5=88=97=EF=BC=8C=E5=85=B6=E4=BB=96=E4=B8=8D=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=EF=BC=8C=E5=A6=82=E6=9E=9C=E6=9C=89=E5=87=BA=E3=80=81=E5=85=A5?= =?UTF-8?q?=E5=BA=93=E6=95=B0=E5=88=99=E7=94=9F=E6=88=90=E4=B8=80=E6=9D=A1?= =?UTF-8?q?=E5=BD=93=E6=97=A5=E6=80=BB=E5=87=BA=E3=80=81=E5=85=A5=E5=BA=93?= =?UTF-8?q?=E6=95=B0=E5=8F=8A=E6=80=BB=E7=BB=93=E5=AD=98=E6=95=B0=E7=9A=84?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 3)生成日结存 按钮 生成的记录为 药品对应的记录,而非批次对应的记录 4)库存盘点中,盘点时不记录盘点库存为0且盘点后库存仍为0的记录(该批次可能不再用了) 5)修改报表,由原来的显示打印预览改为保存pdf并打开已保存的PDF --- DM_Weight/App.xaml.cs | 2 +- DM_Weight/DM_Weight.csproj | 1 + DM_Weight/Models/MachineRecord.cs | 8 +- DM_Weight/Report/GridReportUtil.cs | 217 +++++++++++++++--- DM_Weight/ReportTemp/account_book_temp.grf | 2 + .../ReportTemp/machine_log_check_new2.grf | 1 + DM_Weight/Services/ChannelStockService.cs | 2 +- DM_Weight/Services/MachineRecordService.cs | 6 +- .../ViewModels/AccountWindowViewModel.cs | 90 +++++--- .../CheckRecordNewWindowViewModel.cs | 10 +- .../CheckStockNewWindowViewModel.cs | 108 +++++---- DM_Weight/ViewModels/PrintPdfViewModel.cs | 68 ++++++ DM_Weight/Views/Dialog/PrintPdfView.xaml | 19 ++ DM_Weight/Views/Dialog/PrintPdfView.xaml.cs | 61 +++++ 14 files changed, 480 insertions(+), 115 deletions(-) create mode 100644 DM_Weight/ViewModels/PrintPdfViewModel.cs create mode 100644 DM_Weight/Views/Dialog/PrintPdfView.xaml create mode 100644 DM_Weight/Views/Dialog/PrintPdfView.xaml.cs diff --git a/DM_Weight/App.xaml.cs b/DM_Weight/App.xaml.cs index 7ac68ee..34a4f40 100644 --- a/DM_Weight/App.xaml.cs +++ b/DM_Weight/App.xaml.cs @@ -252,7 +252,7 @@ namespace DM_Weight //交接班记录 containerRegistry.RegisterForNavigation(); - + containerRegistry.RegisterForNavigation(); //交接班 containerRegistry.RegisterForNavigation(); diff --git a/DM_Weight/DM_Weight.csproj b/DM_Weight/DM_Weight.csproj index 962e012..79dd253 100644 --- a/DM_Weight/DM_Weight.csproj +++ b/DM_Weight/DM_Weight.csproj @@ -69,6 +69,7 @@ + diff --git a/DM_Weight/Models/MachineRecord.cs b/DM_Weight/Models/MachineRecord.cs index f9cb957..64b5687 100644 --- a/DM_Weight/Models/MachineRecord.cs +++ b/DM_Weight/Models/MachineRecord.cs @@ -72,7 +72,7 @@ namespace DM_Weight.Models [SugarColumn(ColumnName = "eff_date")] public DateTime? EffDate { get; set; } /// - /// 出库入库类型(1入库2出库31还药32还空瓶) + /// 出库入库类型(1入库2出库31还药32还空瓶4盘点5日结存) /// [SugarColumn(ColumnName = "type")] public int Type { get; set; } @@ -106,13 +106,15 @@ namespace DM_Weight.Models /// 退药量 /// 默认值: 0 /// - [SugarColumn(ColumnName = "return_quantity1", IsOnlyIgnoreInsert = true)] + //[SugarColumn(ColumnName = "return_quantity1", IsOnlyIgnoreInsert = true)] + [SugarColumn(ColumnName = "return_quantity1")] public int ReturnQuantity1 { get; set; } /// /// 退空瓶量 /// 默认值: 0 /// - [SugarColumn(ColumnName = "return_quantity2", IsOnlyIgnoreInsert = true)] + //[SugarColumn(ColumnName = "return_quantity2", IsOnlyIgnoreInsert = true + [SugarColumn(ColumnName = "return_quantity2")] public int ReturnQuantity2 { get; set; } /// /// 取药记录id diff --git a/DM_Weight/Report/GridReportUtil.cs b/DM_Weight/Report/GridReportUtil.cs index ed7148b..54a2bb6 100644 --- a/DM_Weight/Report/GridReportUtil.cs +++ b/DM_Weight/Report/GridReportUtil.cs @@ -9,6 +9,11 @@ using System.Threading.Tasks; using DM_Weight.Models; using System.Configuration; using DM_Weight.util; +using DM_Weight.Views; +using System.Diagnostics; +using log4net; +using log4net.Repository.Hierarchy; +using DM_Weight.ViewModels; namespace DM_Weight.Report { @@ -17,7 +22,7 @@ namespace DM_Weight.Report // 定义Grid++Report报表主对象 public static GridppReport Report = new GridppReport(); - public static string gridConnectionString = ConfigurationManager.AppSettings["gridConnectionString"]; + public static string gridConnectionString = ConfigurationManager.AppSettings["gridConnectionString"]; /** * 打印预览 * tempname: 模板文件名称 @@ -43,7 +48,7 @@ namespace DM_Weight.Report { Report.ParameterByName("machine_id").Value = (ConfigurationManager.AppSettings["machineId"] ?? "DM1"); }); - string machine_id=(ConfigurationManager.AppSettings["machineId"] ?? "DM1"); + string machine_id = (ConfigurationManager.AppSettings["machineId"] ?? "DM1"); string SQL = $@"SELECT cl.`row_no` AS drawerNo,cl.`col_no` AS colNo,cl.`quantity` AS quantity,cl.`manu_no` AS manuNo,cl.`eff_date` AS effDate, di.`drug_name` AS drugName,di.`drug_spec` AS drugSpec,di.`pack_unit` AS packUnit,di.`manufactory` AS manuFactory,di.`max_stock` AS baseQuantity, cl.`drug_id` AS drugId FROM channel_stock cl INNER JOIN drug_info di ON di.`drug_id` = cl.`drug_id` WHERE cl.`machine_id` = '{machine_id}' AND cl.`drawer_type` = 1 ORDER BY cl.`drug_id`"; @@ -51,7 +56,22 @@ namespace DM_Weight.Report Report.LoadFromFile(new FileInfo(AppDomain.CurrentDomain.BaseDirectory) + "ReportTemp//" + "stock_template.grf"); Report.DetailGrid.Recordset.ConnectionString = gridConnectionString; Report.DetailGrid.Recordset.QuerySQL = SQL; - Report.PrintPreview(true); + //Report.PrintPreview(true); + string filePath = AppDomain.CurrentDomain.BaseDirectory + "ReportTemp//" + "stock_template.pdf"; + if (File.Exists(filePath)) + { + try + { + + File.Delete(filePath); + } + catch (Exception ex) + { + FindAndKillProcess(); + + } + } + Report.ExportDirect(GRExportType.gretPDF, filePath, false, true); } /// /// 导出盘点后库存信息 @@ -76,15 +96,64 @@ namespace DM_Weight.Report Report.LoadFromFile(new FileInfo(AppDomain.CurrentDomain.BaseDirectory) + "ReportTemp//" + "machine_log_check_new2.grf"); Report.DetailGrid.Recordset.ConnectionString = gridConnectionString; Report.DetailGrid.Recordset.QuerySQL = SQL; - Report.PrintPreview(true); + // Report.PrintPreview(true); + + string filePath = AppDomain.CurrentDomain.BaseDirectory + "ReportTemp//" + "machine_log_check_new2.pdf"; + if (File.Exists(filePath)) + { + try + { + + File.Delete(filePath); + } + catch (Exception ex) + { + FindAndKillProcess(); + + } + } + + Report.ExportDirect(GRExportType.gretPDF, filePath, false, true); } - public static void PrintReportAccountBook(DateTime? startDate, DateTime? endDate,int type,string drug_id) + public static Task PrintReportStockNewTest(DateTime? startDate, DateTime? endDate) + { + return Task.Run(() => + { + string filePath = string.Empty; + DateTime? p_startDate = startDate ?? Convert.ToDateTime("2010-1-1"); + DateTime? p_endDate = endDate ?? DateTime.Now.AddDays(1); + // 定义Grid++Report报表主对象 + GridppReport Report = new GridppReport(); + //Report.Initialize += new _IGridppReportEvents_InitializeEventHandler(() => + //{ + // Report.ParameterByName("machine_id").Value = (ConfigurationManager.AppSettings["machineId"] ?? "DM1"); + //}); + string machine_id = (ConfigurationManager.AppSettings["machineId"] ?? "DM1"); + string SQL = $@"SELECT cl.`row_no` AS drawerNo,cl.`col_no` AS colNo,cl.`quantity` AS quantity,cl.`manu_no` AS manuNo,cl.`eff_date` AS effDate, + `drug_name` AS drugName,`drug_spec` AS drugSpec,`pack_unit` AS packUnit,`manufactory` AS manuFactory,`max_stock` AS baseQuantity, + cl.`drug_id` AS drugId,cl.manuquantity, cl.`optdate` FROM check_stock cl WHERE cl.`machine_id` = '{machine_id}' AND cl.`optdate` > '{p_startDate}' AND cl.`optdate` < '{p_endDate}' ORDER BY cl.`optdate` desc, cl.`drug_id`"; + // 加载模板文件 + Report.LoadFromFile(new FileInfo(AppDomain.CurrentDomain.BaseDirectory) + "ReportTemp//" + "machine_log_check_new2.grf"); + Report.DetailGrid.Recordset.ConnectionString = gridConnectionString; + Report.DetailGrid.Recordset.QuerySQL = SQL; + // Report.PrintPreview(true); + //Report.SaveToFile(new FileInfo(AppDomain.CurrentDomain.BaseDirectory) + "ReportTemp//" + "Test.pdf"); + bool isSave = Report.ExportDirect(GRExportType.gretPDF, new FileInfo(AppDomain.CurrentDomain.BaseDirectory) + "ReportTemp//" + "machine_log_check_new2.pdf", false, false); + + if (isSave) + { + filePath = AppDomain.CurrentDomain.BaseDirectory + "ReportTemp\\" + "machine_log_check_new2.pdf"; + } + return filePath; + }); + } + public static void PrintReportAccountBook(DateTime? startDate, DateTime? endDate, int type, string drug_id) { DateTime? p_startDate = startDate ?? Convert.ToDateTime("2010-1-1"); DateTime? p_endDate = endDate ?? DateTime.Now.AddDays(1); - string p_machine_id= (ConfigurationManager.AppSettings["machineId"] ?? "DM1"); + string p_machine_id = (ConfigurationManager.AppSettings["machineId"] ?? "DM1"); // 定义Grid++Report报表主对象 - GridppReport Report = new GridppReport(); + GridppReport Report = new GridppReport(); // 加载模板文件 Report.LoadFromFile(new FileInfo(AppDomain.CurrentDomain.BaseDirectory) + "ReportTemp//" + "account_book_temp.grf"); string SQL = string.Empty; @@ -98,19 +167,20 @@ namespace DM_Weight.Report //Report.DetailGrid.Recordset.QuerySQL = SQL; SQL = $@"SELECT TYPE, stockQuantity,inQuantity,outQuantity,operationTime,invoiceId,drugName,drugId,drugSpec,packUnit,dosage,manufactory,manuNo,effDate, operatorName,reviewerName,supplierDept,receiveDept,bigUnit FROM - (SELECT mr.type, mr.`stock_quantity` AS `stockQuantity`, IF(mr.`type` IN (1, 31), mr.`quantity`, IF(mr.`type` = 4 AND mr.`quantity` > 0, mr.`quantity`, 0)) - AS `inQuantity`, IF(mr.`type` = 2, mr.`quantity`, IF(mr.`type` = 4 AND mr.`quantity` < 0, (0 - mr.`quantity`), 0)) AS `outQuantity`, - mr.`operation_time` AS `operationTime`,IF(mr.`type`=1,mr.`invoice_id`,NULL) AS `invoiceId`, di.`drug_name` AS `drugName`, di.`drug_id` AS `drugId`, + (SELECT mr.type, mr.`stock_quantity` AS `stockQuantity`, + IF(mr.`type` IN (1, 31), mr.`quantity`, IF(mr.`type` = 4 AND mr.`quantity` > 0, mr.`quantity`, IF(mr.`type` = 5,mr.return_quantity1,0))) AS `inQuantity`, + IF(mr.`type` = 2, mr.`quantity`, IF(mr.`type` = 4 AND mr.`quantity` < 0, (0 - mr.`quantity`), IF(mr.`type` = 5,mr.return_quantity2,0))) AS `outQuantity`, + mr.`operation_time` AS `operationTime`,IF(mr.`type`=1||mr.type=5,mr.`invoice_id`,NULL) AS `invoiceId`, di.`drug_name` AS `drugName`, di.`drug_id` AS `drugId`, di.`drug_spec` AS `drugSpec`, di.`pack_unit` AS `packUnit`,di.big_unit as bigUnit, di.`dosage` AS `dosage`, di.`manufactory` AS `manufactory`, mr.`manu_no` AS `manuNo`, mr.`eff_date` AS `effDate`, u1.`user_name` AS `operatorName`, u2.`user_name` AS `reviewerName`,mr.supplierDept,mr.receiveDept FROM dm_machine_record mr LEFT JOIN drug_info di ON mr.`drug_id` = di.`drug_id` LEFT JOIN user_list u1 ON mr.`operator` = u1.`id` LEFT JOIN user_list u2 ON mr.`reviewer` = u2.`id` WHERE mr.`machine_id` = '{p_machine_id}' AND mr.`operation_time` > '{p_startDate}' AND mr.`operation_time` < '{p_endDate}' and IF(mr.`type` = 4 AND mr.`quantity` = 0, 99999, mr.`quantity`) <>99999 "; - if(!string.IsNullOrEmpty(drug_id)) + if (!string.IsNullOrEmpty(drug_id)) { - SQL+= " AND mr.drug_id='"+ drug_id+"' "; + SQL += " AND mr.drug_id='" + drug_id + "' "; } - SQL+= " ORDER BY mr.`drug_id`, mr.`operation_time`, mr.`id`) AS T"; + SQL += " ORDER BY mr.`drug_id`, mr.`operation_time`, mr.`id`) AS T"; if (type > 0) { if (type == 1) @@ -127,11 +197,27 @@ namespace DM_Weight.Report } } Report.DetailGrid.Recordset.QuerySQL = SQL; - Report.PrintPreview(true); + //Report.PrintPreview(true); + string filePath = AppDomain.CurrentDomain.BaseDirectory + "ReportTemp//" + "account_book_temp.pdf"; + if (File.Exists(filePath)) + { + try + { + + File.Delete(filePath); + } + catch (Exception ex) + { + FindAndKillProcess(); + + } + } + Report.ExportDirect(GRExportType.gretPDF, filePath, false, true); } public static void PrintReportMechineRecord(int type, DateTime? startDate, DateTime? endDate) { + string saveFileName = string.Empty; // 定义Grid++Report报表主对象 GridppReport Report = new GridppReport(); DateTime? p_startDate = startDate ?? Convert.ToDateTime("2010-1-1"); @@ -147,6 +233,7 @@ namespace DM_Weight.Report // 加载模板文件 if (type == 1) { + saveFileName = "machine_log_add.pdf"; Report.LoadFromFile(new FileInfo(AppDomain.CurrentDomain.BaseDirectory) + "ReportTemp//" + "machine_log_add.grf"); SQL = $@"SELECT dmr.`drawer_no` AS drawerNo,dmr.`col_no` AS colNo,dmr.`type` AS `type`,dmr.`quantity` AS quantity, dmr.`manu_no` AS manuNo,dmr.`eff_date` AS effDate,dmr.`operation_time` AS operationTime, @@ -158,6 +245,8 @@ namespace DM_Weight.Report } else if (type == 2) { + + saveFileName = "machine_log_take.pdf"; Report.LoadFromFile(new FileInfo(AppDomain.CurrentDomain.BaseDirectory) + "ReportTemp//" + "machine_log_take.grf"); SQL = $@" SELECT dmr.`drawer_no` AS drawerNo,dmr.`col_no` AS colNo,dmr.`type` AS `type`,dmr.`quantity` AS quantity, dmr.`manu_no` AS manuNo,dmr.`eff_date` AS effDate,dmr.`operation_time` AS operationTime, @@ -170,6 +259,8 @@ namespace DM_Weight.Report } else if (type == 3) { + + saveFileName = "machine_log_return.pdf"; Report.LoadFromFile(new FileInfo(AppDomain.CurrentDomain.BaseDirectory) + "ReportTemp//" + "machine_log_return.grf"); SQL = $@" SELECT dmr.`drawer_no` AS drawerNo,dmr.`col_no` AS colNo,dmr.`type` AS `type`, CONCAT(dmr.`quantity`,IF(dmr.`type`=32,""(空瓶)"","""")) AS quantity,dmr.`manu_no` AS manuNo, @@ -183,6 +274,7 @@ namespace DM_Weight.Report } else { + saveFileName = "machine_log_check.pdf"; Report.LoadFromFile(new FileInfo(AppDomain.CurrentDomain.BaseDirectory) + "ReportTemp//" + "machine_log_check.grf"); SQL = $@" SELECT dmr.`drawer_no` AS drawerNo,dmr.`col_no` AS colNo,dmr.`type` AS `type`,dmr.`check_quantity` AS quantity, dmr.`manu_no` AS manuNo,dmr.`eff_date` AS effDate,dmr.`operation_time` AS operationTime, @@ -195,14 +287,41 @@ namespace DM_Weight.Report AND dmr.`machine_id` = '{p_machine_id}' AND dmr.`operation_time` > '{p_startDate}' AND dmr.`operation_time` < '{p_endDate}'"; } - - Report.DetailGrid.Recordset.ConnectionString = gridConnectionString; - Report.DetailGrid.Recordset.QuerySQL= SQL; - Report.PrintPreview(true); + Report.DetailGrid.Recordset.ConnectionString = gridConnectionString; + Report.DetailGrid.Recordset.QuerySQL = SQL; + + //Report.PrintPreview(true); + string filePath = AppDomain.CurrentDomain.BaseDirectory + "ReportTemp//" + saveFileName; + if (File.Exists(filePath)) + { + try + { + + File.Delete(filePath); + } + catch (Exception ex) + { + FindAndKillProcess(); + + } + } + Report.ExportDirect(GRExportType.gretPDF, filePath, false, true); } - + public static bool FindAndKillProcess() + { + foreach (Process clsProcess in Process.GetProcesses()) + { + if (clsProcess.ProcessName.Contains("wps")||clsProcess.ProcessName.Contains("msedge")) + { + clsProcess.Kill(); + //return true; + } + } + //process not found, return false + return false; + } /** * 打印预览 @@ -215,13 +334,28 @@ namespace DM_Weight.Report GridppReport Report = new GridppReport(); // 加载模板文件 Report.LoadFromFile(new FileInfo(AppDomain.CurrentDomain.BaseDirectory) + "ReportTemp//machine_log.grf"); - + // 加载数据 Report.ParameterByName("type").AsInteger = 1; - Report.PrintPreview(true); + //Report.PrintPreview(true); + string filePath = AppDomain.CurrentDomain.BaseDirectory + "ReportTemp//" + "machine_log.pdf"; + if (File.Exists(filePath)) + { + try + { + + File.Delete(filePath); + } + catch (Exception ex) + { + FindAndKillProcess(); + + } + } + Report.ExportDirect(GRExportType.gretPDF, filePath, false, true); } //交接班记录报表 - public static void PrintChangeShiftsReport(DateTime? startDate,DateTime? endDate) + public static void PrintChangeShiftsReport(DateTime? startDate, DateTime? endDate) { DateTime? p_startDate = startDate ?? Convert.ToDateTime("2010-1-1"); DateTime? p_endDate = endDate ?? DateTime.Now.AddDays(1); @@ -243,7 +377,23 @@ namespace DM_Weight.Report from `hkc_shiftsreport` WHERE `machineid` = '{p_machine_id}' AND `opt_date` > '{p_startDate}' AND opt_date < '{p_endDate}' ORDER BY opt_date"; Report.DetailGrid.Recordset.QuerySQL = SQL; - Report.PrintPreview(true); + //Report.PrintPreview(true); + string filePath = AppDomain.CurrentDomain.BaseDirectory + "ReportTemp//" + "changeShifts_temp.pdf"; + if (File.Exists(filePath)) + { + try + { + + File.Delete(filePath); + } + catch (Exception ex) + { + FindAndKillProcess(); + + } + } + Report.ExportDirect(GRExportType.gretPDF, filePath, false, true); + } /// @@ -258,12 +408,27 @@ namespace DM_Weight.Report GridppReport Report = new GridppReport(); // 加载模板文件 Report.LoadFromFile(new FileInfo(AppDomain.CurrentDomain.BaseDirectory) + "ReportTemp//machine_log_check.grf"); - Dictionary> records = new Dictionary>(); + Dictionary> records = new Dictionary>(); records.Add("table", data); - string str= JsonConvert.SerializeObject(records); + string str = JsonConvert.SerializeObject(records); Report.LoadDataFromXML(str); // 加载数据 - Report.PrintPreview(true); + //Report.PrintPreview(true); + string filePath = AppDomain.CurrentDomain.BaseDirectory + "ReportTemp//" + "machine_log_check.pdf"; + if (File.Exists(filePath)) + { + try + { + + File.Delete(filePath); + } + catch (Exception ex) + { + FindAndKillProcess(); + + } + } + Report.ExportDirect(GRExportType.gretPDF, filePath, false, true); } } } diff --git a/DM_Weight/ReportTemp/account_book_temp.grf b/DM_Weight/ReportTemp/account_book_temp.grf index d509b10..1af7efd 100644 --- a/DM_Weight/ReportTemp/account_book_temp.grf +++ b/DM_Weight/ReportTemp/account_book_temp.grf @@ -166,7 +166,9 @@ "ColumnContentCell":[ { "Column":"日期", + "WordWrap":true, "TextAlign":"MiddleCenter", + "ShrinkFontToFit":true, "DataField":"日期" }, { diff --git a/DM_Weight/ReportTemp/machine_log_check_new2.grf b/DM_Weight/ReportTemp/machine_log_check_new2.grf index 4de9e86..80d1d41 100644 --- a/DM_Weight/ReportTemp/machine_log_check_new2.grf +++ b/DM_Weight/ReportTemp/machine_log_check_new2.grf @@ -91,6 +91,7 @@ "ColumnContentCell":[ { "Column":"盘点日期", + "WordWrap":true, "DataField":"盘点日期" }, { diff --git a/DM_Weight/Services/ChannelStockService.cs b/DM_Weight/Services/ChannelStockService.cs index a871464..3c31d9b 100644 --- a/DM_Weight/Services/ChannelStockService.cs +++ b/DM_Weight/Services/ChannelStockService.cs @@ -23,7 +23,7 @@ namespace DM_Weight.Services string SQL = $@"SELECT CS.drug_id as DrugId,CS.manu_no as ManuNo,sum(quantity) as Quantity,CS.eff_date as EffDate,DI.drug_name as DrugName, DI.drug_spec as DrugSpec,DI.dosage as Dosage,DI.manufactory as ManuFactory,DI.small_unit as SmallUnit,DI.pack_unit as PackUnit, CS.machine_id as MachineId FROM channel_stock CS - INNER JOIN drug_info DI ON CS.drug_id=DI.drug_id where CS.machine_id='{p_machine_id}' AND quantity>0 GROUP BY CS.drug_id,CS.manu_no "; + INNER JOIN drug_info DI ON CS.drug_id=DI.drug_id where CS.machine_id='{p_machine_id}' AND quantity>0 GROUP BY CS.drug_id";//,CS.manu_no "; List accountList = SqlSugarHelper.Db.SqlQueryable(SQL).ToList(); //List accountList = SqlSugarHelper.Db.Queryable().Includes(cs=>cs.DrugInfo) diff --git a/DM_Weight/Services/MachineRecordService.cs b/DM_Weight/Services/MachineRecordService.cs index 2809a39..15bd2fc 100644 --- a/DM_Weight/Services/MachineRecordService.cs +++ b/DM_Weight/Services/MachineRecordService.cs @@ -30,9 +30,9 @@ namespace DM_Weight.Services string p_machine_id = (ConfigurationManager.AppSettings["machineId"] ?? "DM1"); string SQL = $@"SELECT TYPE, stockQuantity,inQuantity,outQuantity,operationTime,invoiceId,drugName,drugId,drugSpec,packUnit,dosage,manufactory,manuNo,effDate, operatorName,reviewerName,supplierDept,receiveDept FROM - (SELECT mr.type,mr.`stock_quantity` AS `stockQuantity`, IF(mr.`type` IN (1, 31), mr.`quantity`, IF(mr.`type` = 4 AND mr.`quantity` > 0, mr.`quantity`, 0)) - AS `inQuantity`, IF(mr.`type` = 2, mr.`quantity`, IF(mr.`type` = 4 AND mr.`quantity` < 0, (0 - mr.`quantity`), 0)) AS `outQuantity`, - DATE_FORMAT(mr.`operation_time`,'%m/%d') AS `operationTime`,IF(mr.`type`=1,mr.`invoice_id`,NULL) AS `invoiceId`, di.`drug_name` AS `drugName`, di.`drug_id` AS `drugId`, + (SELECT mr.type,mr.`stock_quantity` AS `stockQuantity`, IF(mr.`type` IN (1, 31), mr.`quantity`, IF(mr.`type` = 4 AND mr.`quantity` > 0, mr.`quantity`, IF(mr.`type` = 5,mr.return_quantity1,0))) + AS `inQuantity`, IF(mr.`type` = 2, mr.`quantity`, IF(mr.`type` = 4 AND mr.`quantity` < 0, (0 - mr.`quantity`), IF(mr.`type` = 5,mr.return_quantity2,0))) AS `outQuantity`, + DATE_FORMAT(mr.`operation_time`,'%m/%d') AS `operationTime`,IF(mr.`type`=1||mr.type=5,mr.`invoice_id`,NULL) AS `invoiceId`, di.`drug_name` AS `drugName`, di.`drug_id` AS `drugId`, di.`drug_spec` AS `drugSpec`, di.`pack_unit` AS `packUnit`, di.`dosage` AS `dosage`, di.`manufactory` AS `manufactory`, mr.`manu_no` AS `manuNo`, DATE_FORMAT(mr.`eff_date`,'%y/%m/%d') AS `effDate`, u1.`user_name` AS `operatorName`, u2.`user_name` AS `reviewerName`,mr.supplierDept,mr.receiveDept FROM dm_machine_record mr LEFT JOIN drug_info di ON mr.`drug_id` = di.`drug_id` LEFT JOIN user_list u1 ON mr.`operator` = u1.`id` diff --git a/DM_Weight/ViewModels/AccountWindowViewModel.cs b/DM_Weight/ViewModels/AccountWindowViewModel.cs index 848db2f..a70c5f7 100644 --- a/DM_Weight/ViewModels/AccountWindowViewModel.cs +++ b/DM_Weight/ViewModels/AccountWindowViewModel.cs @@ -237,8 +237,13 @@ namespace DM_Weight.ViewModels { try { - - //查询账册中所有记录,与库存中的记录做比校,如果账册中没有,则添加一条 + string machineId = ConfigurationManager.AppSettings["machineId"] ?? "DM1"; + //根据已生成的日结存记录 + int deleteNum = SqlSugarHelper.Db.Deleteable() + .Where(cs => cs.Type.Equals(5) && cs.OperationTime.ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd") && cs.MachineId.Equals(machineId)).ExecuteCommand(); + int inQuantity = 0; //当日入库量 + int outQuantity = 0; //当日出库量 + //查询账册中所有记录,与库存中的记录做比校,如果账册中没有,则添加一条,有则添加一条总日结存 List accountList = _machineRecordService.ReportAccountBook(nowDate, null, 0); //库存中的记录 List channelStockList = _channelStockService.GetAll(); @@ -249,33 +254,47 @@ namespace DM_Weight.ViewModels for (int i = 0; i < channelStockList.Count; i++) { - int Count = accountList.Where(cs => cs.DrugId == channelStockList[i].DrugId && cs.ManuNo == channelStockList[i].ManuNo).Count(); + int Count = accountList.Where(cs => cs.DrugId == channelStockList[i].DrugId).Count(); + if (Count <= 0) { - //没有直接插入 - // 保存数据 出/入库记录 - string InvoiceId = "Account_" + CurrentTimeMillis(); - SqlSugarHelper.Db.Insertable(new MachineRecord() - { - MachineId = channelStockList[i].MachineId, - DrawerNo = 0,//channelStockList[i].DrawerNo, - ColNo = 0,// channelStockList[i].ColNo,FV - DrugId = channelStockList[i].DrugId, - ManuNo = channelStockList[i].ManuNo, - EffDate = !String.IsNullOrEmpty(channelStockList[i].EffDate) ? DateTime.ParseExact(channelStockList[i].EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) : null, - Operator = HomeWindowViewModel.Operator?.Id, - Reviewer = HomeWindowViewModel.Reviewer?.Id, - OperationTime = DateTime.Now, - Quantity = 0, - Type = 5, - InvoiceId = string.Empty,//InvoiceId, - StockQuantity = channelStockList[i].Quantity, - ManunoQuantity = 0, - SupplierDept = ConfigurationManager.AppSettings["supplierDept"].ToString(), - ReceiveDept = ConfigurationManager.AppSettings["receiveDept"].ToString() - }).ExecuteCommand(); - + inQuantity = 0; + outQuantity = 0; } + else + { + inQuantity = accountList.Where(cs => cs.DrugId == channelStockList[i].DrugId).Sum(cs => cs.InQuantity); + outQuantity= accountList.Where(cs => cs.DrugId == channelStockList[i].DrugId).Sum(cs => cs.OutQuantity); + } + // 获取药品总库存 + int channelStockQuantity = SqlSugarHelper.Db.Queryable() + .Where(cs => cs.DrugId.Equals(channelStockList[i].DrugId)).Sum(it => it.Quantity); + //没有直接插入 + // 保存数据 出/入库记录 + string InvoiceId = "Account_" + CurrentTimeMillis(); + SqlSugarHelper.Db.Insertable(new MachineRecord() + { + MachineId = channelStockList[i].MachineId, + DrawerNo = 0,//channelStockList[i].DrawerNo, + ColNo = 0,// channelStockList[i].ColNo,FV + DrugId = channelStockList[i].DrugId, + ManuNo = "",//channelStockList[i].ManuNo, + EffDate = null,// !String.IsNullOrEmpty(channelStockList[i].EffDate) ? DateTime.ParseExact(channelStockList[i].EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) : null, + Operator = HomeWindowViewModel.Operator?.Id, + Reviewer = HomeWindowViewModel.Reviewer?.Id, + OperationTime = DateTime.Now, + Quantity = 0, + Type = 5, + InvoiceId = "日结存",//InvoiceId, + ReturnQuantity1 = inQuantity, //当日入库量总数 + ReturnQuantity2 = outQuantity, //当日出库量总数 + StockQuantity = channelStockQuantity, + ManunoQuantity = 0, + SupplierDept =string.Empty,// ConfigurationManager.AppSettings["supplierDept"].ToString(), + ReceiveDept = string.Empty,//ConfigurationManager.AppSettings["receiveDept"].ToString() + }).ExecuteCommand(); + + } } else @@ -284,6 +303,11 @@ namespace DM_Weight.ViewModels { //账册中没有记录则把库存中的所有数据都要生成一条账册记录 // 保存数据 出/入库记录 + // 获取药品总库存 + int channelStockQuantity = SqlSugarHelper.Db.Queryable() + .Where(cs => cs.DrugId.Equals(channelStockList[i].DrugId)).Sum(it => it.Quantity); + + string InvoiceId = "Account_" + CurrentTimeMillis(); SqlSugarHelper.Db.Insertable(new MachineRecord() { @@ -291,18 +315,20 @@ namespace DM_Weight.ViewModels DrawerNo = 0,//channelStockList[i].DrawerNo, ColNo = 0,//channelStockList[i].ColNo, DrugId = channelStockList[i].DrugId, - ManuNo = channelStockList[i].ManuNo, - EffDate = !String.IsNullOrEmpty(channelStockList[i].EffDate) ? DateTime.ParseExact(channelStockList[i].EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) : null, + ManuNo = "",// channelStockList[i].ManuNo, + EffDate = null,// !String.IsNullOrEmpty(channelStockList[i].EffDate) ? DateTime.ParseExact(channelStockList[i].EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) : null, Operator = HomeWindowViewModel.Operator?.Id, Reviewer = HomeWindowViewModel.Reviewer?.Id, OperationTime = DateTime.Now, Quantity = 0, Type = 5, - InvoiceId = string.Empty,//InvoiceId, - StockQuantity = channelStockList[i].Quantity, + InvoiceId = "日结存",// string.Empty,//InvoiceId, + ReturnQuantity1 = inQuantity, //当日入库量总数 + ReturnQuantity2 = outQuantity, //当日出库量总数 + StockQuantity = channelStockQuantity, ManunoQuantity = 0, - SupplierDept = ConfigurationManager.AppSettings["supplierDept"].ToString(), - ReceiveDept = ConfigurationManager.AppSettings["receiveDept"].ToString() + SupplierDept = string.Empty,//ConfigurationManager.AppSettings["supplierDept"].ToString(), + ReceiveDept = string.Empty,//ConfigurationManager.AppSettings["receiveDept"].ToString() }).ExecuteCommand(); } } diff --git a/DM_Weight/ViewModels/CheckRecordNewWindowViewModel.cs b/DM_Weight/ViewModels/CheckRecordNewWindowViewModel.cs index 39d60fc..2ca9778 100644 --- a/DM_Weight/ViewModels/CheckRecordNewWindowViewModel.cs +++ b/DM_Weight/ViewModels/CheckRecordNewWindowViewModel.cs @@ -132,8 +132,16 @@ namespace DM_Weight.ViewModels { GridReportUtil.PrintReportStockNew(StartDate, EndDate); }); + + //get => new DelegateCommand(() => + //{ + // //DialogParameters dialogParameters = new DialogParameters(); + // //dialogParameters.Add("orderInfo", SelectedOrder); + // DialogServiceExtensions.ShowDialogHost(_dialogService, "PrintPdfView", null, DoDialogResult, "RootDialog"); + //}); + } - public DelegateCommand Query + public DelegateCommand Query { get => new DelegateCommand(() => { diff --git a/DM_Weight/ViewModels/CheckStockNewWindowViewModel.cs b/DM_Weight/ViewModels/CheckStockNewWindowViewModel.cs index fb16be6..4406add 100644 --- a/DM_Weight/ViewModels/CheckStockNewWindowViewModel.cs +++ b/DM_Weight/ViewModels/CheckStockNewWindowViewModel.cs @@ -210,11 +210,11 @@ namespace DM_Weight.ViewModels //} logger.Info($"抽屉号DrawerNoBefore【{DrawerNoBefore}】抽屉号DrawerNoAfter【{DrawerNoAfter}】"); - if (DrawerNoAfter == 17|| DrawerNoBefore == 17) + if (DrawerNoAfter == 17 || DrawerNoBefore == 17) { //if (DrawerNoBefore == 17) { - int sleepMilliseconds = Convert.ToInt32(ConfigurationManager.AppSettings["CheckSleepMilliseconds"]??"500"); + int sleepMilliseconds = Convert.ToInt32(ConfigurationManager.AppSettings["CheckSleepMilliseconds"] ?? "500"); Thread.Sleep(sleepMilliseconds); } //else @@ -317,18 +317,23 @@ namespace DM_Weight.ViewModels IGrouping grouping = enumerator.Current; //int DrawerNo =Convert.ToInt32(grouping.Key.Substring(0,grouping.Key.IndexOf('-'))); int DrawerNo = grouping.Key; - List channelStocks = grouping.ToList(); - channelStocks.ForEach(it => it.process = 1); + List Stocks = grouping.ToList(); + List copyStocks = new List(); + foreach (var item in Stocks) + { + copyStocks.Add(item); + } + Stocks.ForEach(it => it.process = 1); _portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉"); - List singleChannels = channelStocks.GroupBy(it => new + List singleChannels = Stocks.GroupBy(it => new { it.DrawerNo, it.ColNo }).Select(it => { var ret = it.First(); - ret.Quantity = it.Sum(itx => itx.Quantity); + //ret.Quantity = it.Sum(itx => itx.Quantity); ret.AddQuantity = it.Sum(itx => itx.AddQuantity); return ret; }).ToList().FindAll(it => it.BoardType != 1); @@ -395,30 +400,34 @@ namespace DM_Weight.ViewModels .Where(cs => cs.DrawerType == 1) .ToList(); - // 保存数据 盘点记录 - SqlSugarHelper.Db.Insertable(new MachineRecord() + //盘点时不记录盘点库存为0且盘点后库存仍为0的记录(该批次可能不再用了) + if (!it.Quantity.Equals(0) || !it.CheckQuantity.Equals(0)) { - MachineId = it.MachineId, - DrawerNo = it.DrawerNo, - ColNo = it.ColNo, - DrugId = it.DrugId, - ManuNo = it.ManuNo, - EffDate = !String.IsNullOrEmpty(it.EffDate) ? DateTime.ParseExact(it.EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) : null, - Operator = HomeWindowViewModel.Operator?.Id, - Reviewer = HomeWindowViewModel.Reviewer?.Id, - OperationTime = DateTime.Now, - Quantity = it.CheckQuantity - it.Quantity, - Type = 4, - InvoiceId = InvoiceId, - StockQuantity = nowChannels.Sum(it => it.Quantity), - CheckQuantity = it.CheckQuantity, - ManunoQuantity = nowChannels.FindAll(it2 => it2.ManuNo == it.ManuNo).Sum(it => it.Quantity) - }).ExecuteCommand(); + // 保存数据 盘点记录 + SqlSugarHelper.Db.Insertable(new MachineRecord() + { + MachineId = it.MachineId, + DrawerNo = it.DrawerNo, + ColNo = it.ColNo, + DrugId = it.DrugId, + ManuNo = it.ManuNo, + EffDate = !String.IsNullOrEmpty(it.EffDate) ? DateTime.ParseExact(it.EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) : null, + Operator = HomeWindowViewModel.Operator?.Id, + Reviewer = HomeWindowViewModel.Reviewer?.Id, + OperationTime = DateTime.Now, + Quantity = it.CheckQuantity - it.Quantity, + Type = 4, + InvoiceId = InvoiceId, + StockQuantity = nowChannels.Sum(it => it.Quantity), + CheckQuantity = it.CheckQuantity, + ManunoQuantity = nowChannels.FindAll(it2 => it2.ManuNo == it.ManuNo).Sum(it => it.Quantity) + }).ExecuteCommand(); + logger.Info($"库存盘点->库位【{it.DrawerNo}-{it.ColNo}】药品【{it.DrugInfo.DrugName}】盘点前库存【{it.Quantity}】,更改后【{it.CheckQuantity}】"); - logger.Info($"库存盘点->库位【{it.DrawerNo}-{it.ColNo}】药品【{it.DrugInfo.DrugName}】盘点前库存【{it.Quantity}】,更改后【{it.CheckQuantity}】"); + } } - + //Task.Factory.StartNew(()=> SaveCheckRecord()); string machine_id = (ConfigurationManager.AppSettings["machineId"] ?? "DM1"); string strSql = $@"SELECT cl.`row_no` AS rowNo,cl.`col_no` AS colNo,cl.`quantity` AS quantity,cl.`manu_no` AS manuNo,cl.`eff_date` AS effDate, @@ -448,28 +457,31 @@ namespace DM_Weight.ViewModels for (int j = 0; j < insertList.Count; j++) { - - CheckRecordStock cStock = insertList[j]; - // 保存数据 盘点后药品总库存及批次库存数 - SqlSugarHelper.Db.Insertable(new CheckRecordStock() + //盘点时不记录盘点库存为0且盘点后库存仍为0的记录(该批次可能不再用了) + if (!insertList[j].quantity.Equals(0)) { - rowNo = cStock.rowNo, - colNo = cStock.colNo, - ManuQuantity = checkRecordStockList.Where(it => it.drugId == cStock.drugId && it.manuNo == cStock.manuNo).Sum(it => it.quantity), - manuNo = cStock.manuNo, - effDate = cStock.effDate, - drugName = cStock.drugName, - manufactory = cStock.manufactory, - drugSpec = cStock.drugSpec, - packUnit = cStock.packUnit, - maxStock = cStock.maxStock, - drugId = cStock.drugId, - MachineId = cStock.MachineId, - quantity = checkRecordStockList.Where(it => it.drugId == cStock.drugId).Sum(it => it.quantity), - optdate = DateTime.Now.ToString(), - operatorUser = HomeWindowViewModel.Operator?.Id.ToString(), - reviewerUser = HomeWindowViewModel.Reviewer?.Id.ToString() - }).ExecuteCommand(); + CheckRecordStock cStock = insertList[j]; + // 保存数据 盘点后药品总库存及批次库存数 + SqlSugarHelper.Db.Insertable(new CheckRecordStock() + { + rowNo = cStock.rowNo, + colNo = cStock.colNo, + ManuQuantity = checkRecordStockList.Where(it => it.drugId == cStock.drugId && it.manuNo == cStock.manuNo).Sum(it => it.quantity), + manuNo = cStock.manuNo, + effDate = cStock.effDate, + drugName = cStock.drugName, + manufactory = cStock.manufactory, + drugSpec = cStock.drugSpec, + packUnit = cStock.packUnit, + maxStock = cStock.maxStock, + drugId = cStock.drugId, + MachineId = cStock.MachineId, + quantity = checkRecordStockList.Where(it => it.drugId == cStock.drugId).Sum(it => it.quantity), + optdate = DateTime.Now.ToString(), + operatorUser = HomeWindowViewModel.Operator?.Id.ToString(), + reviewerUser = HomeWindowViewModel.Reviewer?.Id.ToString() + }).ExecuteCommand(); + } } } logger.Info("已完成-保存数据 盘点后药品总库存及批次库存数"); @@ -606,7 +618,7 @@ namespace DM_Weight.ViewModels }); } - public bool KeepAlive => true; + public bool KeepAlive => false; private void DoDialogResult(IDialogResult dialogResult) { diff --git a/DM_Weight/ViewModels/PrintPdfViewModel.cs b/DM_Weight/ViewModels/PrintPdfViewModel.cs new file mode 100644 index 0000000..8a461eb --- /dev/null +++ b/DM_Weight/ViewModels/PrintPdfViewModel.cs @@ -0,0 +1,68 @@ +using DM_Weight.Report; +using Prism.Mvvm; +using Prism.Services.Dialogs; +using System; +using System.Collections.Generic; +using System.Dynamic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DM_Weight.ViewModels +{ + internal class PrintPdfViewModel: BindableBase , IDialogAware + { + private string _pdfFilePath; + public string pdfFilePath + { + get=>_pdfFilePath; + set =>SetProperty(ref _pdfFilePath, value); + } + public PrintPdfViewModel() + { + pdfFilePath = GridReportUtil.PrintReportStockNewTest(DateTime.Now.AddDays(-1),DateTime.Now).Result; + } + + private string _template; + /// + /// PDF 的 html 模板 + /// + public string Template + { + get => _template; + set => SetProperty(ref _template, value); + } + + private ExpandoObject _data; + + public event Action RequestClose; + + /// + /// 传递给 pdf 的数据 + /// + public ExpandoObject Data + { + get => _data; + set => SetProperty(ref _data, value); + } + + public void OnDialogOpened(IDialogParameters parameters) + { + // 弹窗接收 template 和 data 两个参数 + //parameters.TryGetValue("template", out _template); + //parameters.TryGetValue("data", out _data); + } + + public bool CanCloseDialog() + { + return true; + } + + public void OnDialogClosed() + { + //throw new NotImplementedException(); + } + + public string Title => "预览 PDF"; + } +} diff --git a/DM_Weight/Views/Dialog/PrintPdfView.xaml b/DM_Weight/Views/Dialog/PrintPdfView.xaml new file mode 100644 index 0000000..44e1976 --- /dev/null +++ b/DM_Weight/Views/Dialog/PrintPdfView.xaml @@ -0,0 +1,19 @@ + + + + + + + + + + + diff --git a/DM_Weight/Views/Dialog/PrintPdfView.xaml.cs b/DM_Weight/Views/Dialog/PrintPdfView.xaml.cs new file mode 100644 index 0000000..50464c8 --- /dev/null +++ b/DM_Weight/Views/Dialog/PrintPdfView.xaml.cs @@ -0,0 +1,61 @@ +using DM_Weight.ViewModels; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace DM_Weight.Views.Dialog +{ + /// + /// PrintPdfView.xaml 的交互逻辑 + /// + public partial class PrintPdfView : UserControl + { + public PrintPdfView() + { + InitializeComponent(); + } + ///// + ///// 配置 WebView2,加载 vuejs,加载 pdf 模板,传递数据到 html 中 + ///// + ///// + //private async Task Load() + //{ + // await webView2.EnsureCoreWebView2Async(); + // webView2.CoreWebView2.Settings.AreDefaultContextMenusEnabled = false; // 禁止右键菜单 + + // var assembly = Assembly.GetExecutingAssembly(); + // var resourceName = "PrintPdf.Views.vue.global.js"; + + // using var stream = assembly.GetManifestResourceStream(resourceName); + // if (stream != null) + // { + // using var reader = new StreamReader(stream); + // var vue = await reader.ReadToEndAsync(); + // await webView2.CoreWebView2.AddScriptToExecuteOnDocumentCreatedAsync(vue); // 加载 vuejs + // } + + // var vm = (PrintPdfViewModel)DataContext; + + // webView2.CoreWebView2.NavigateToString(vm.Template); // 加载 pdf 模板 + + // webView2.CoreWebView2.NavigationCompleted += (sender, args) => + // { + // var json = JsonSerializer.Serialize(vm.Data); + // webView2.CoreWebView2.PostWebMessageAsJson(json); // 将数据传递到 html 中 + // }; + //} + } +}