1)日结存中保存dm_machine_record为总库存数,非批次库存数

2)生成日结存 按钮 点击时 先删除 已生成的日结存,再查询是否有操作记录,如果没有则生成一条记录,生成的“凭证号” 字段列显示为“日结存”字样,“借入数量”与“发出数量”为该药品下所有批次数总和,“总结存”为该药品总库存,显示当时登录的“发药人”、“复核人”字段列,其他不显示,如果有出、入库数则生成一条当日总出、入库数及总结存数的数据。

3)生成日结存 按钮 生成的记录为 药品对应的记录,而非批次对应的记录
4)库存盘点中,盘点时不记录盘点库存为0且盘点后库存仍为0的记录(该批次可能不再用了)

5)修改报表,由原来的显示打印预览改为保存pdf并打开已保存的PDF
This commit is contained in:
maqiao 2024-03-13 16:25:55 +08:00
parent c36cbf4a1f
commit 35695d2094
14 changed files with 480 additions and 115 deletions

View File

@ -252,7 +252,7 @@ namespace DM_Weight
//交接班记录
containerRegistry.RegisterForNavigation<ChangeShiftsListWindow, ChangeShiftsListWindowViewModel>();
containerRegistry.RegisterForNavigation<PrintPdfView, PrintPdfViewModel>();
//交接班
containerRegistry.RegisterForNavigation<ChangeShiftsDialog, ChangeShiftsDialogViewModel>();

View File

@ -69,6 +69,7 @@
<PackageReference Include="log4net" Version="2.0.15" />
<PackageReference Include="MaterialDesignThemes" Version="4.8.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2365.46" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.39" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="Prism.Unity" Version="8.1.97" />

View File

@ -72,7 +72,7 @@ namespace DM_Weight.Models
[SugarColumn(ColumnName = "eff_date")]
public DateTime? EffDate { get; set; }
/// <summary>
/// 出库入库类型(1入库2出库31还药32还空瓶)
/// 出库入库类型(1入库2出库31还药32还空瓶4盘点5日结存)
///</summary>
[SugarColumn(ColumnName = "type")]
public int Type { get; set; }
@ -106,13 +106,15 @@ namespace DM_Weight.Models
/// 退药量
/// 默认值: 0
///</summary>
[SugarColumn(ColumnName = "return_quantity1", IsOnlyIgnoreInsert = true)]
//[SugarColumn(ColumnName = "return_quantity1", IsOnlyIgnoreInsert = true)]
[SugarColumn(ColumnName = "return_quantity1")]
public int ReturnQuantity1 { get; set; }
/// <summary>
/// 退空瓶量
/// 默认值: 0
///</summary>
[SugarColumn(ColumnName = "return_quantity2", IsOnlyIgnoreInsert = true)]
//[SugarColumn(ColumnName = "return_quantity2", IsOnlyIgnoreInsert = true
[SugarColumn(ColumnName = "return_quantity2")]
public int ReturnQuantity2 { get; set; }
/// <summary>
/// 取药记录id

View File

@ -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);
}
/// <summary>
/// 导出盘点后库存信息
@ -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<string> 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);
}
/// <summary>
@ -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<string,List<MachineRecord>> records = new Dictionary<string,List<MachineRecord>>();
Dictionary<string, List<MachineRecord>> records = new Dictionary<string, List<MachineRecord>>();
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);
}
}
}

View File

@ -166,7 +166,9 @@
"ColumnContentCell":[
{
"Column":"日期",
"WordWrap":true,
"TextAlign":"MiddleCenter",
"ShrinkFontToFit":true,
"DataField":"日期"
},
{

View File

@ -91,6 +91,7 @@
"ColumnContentCell":[
{
"Column":"盘点日期",
"WordWrap":true,
"DataField":"盘点日期"
},
{

View File

@ -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<ChannelStockCount> accountList = SqlSugarHelper.Db.SqlQueryable<ChannelStockCount>(SQL).ToList();
//List<ChannelStock> accountList = SqlSugarHelper.Db.Queryable<ChannelStock>().Includes<DrugInfo>(cs=>cs.DrugInfo)

View File

@ -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`

View File

@ -237,8 +237,13 @@ namespace DM_Weight.ViewModels
{
try
{
//查询账册中所有记录,与库存中的记录做比校,如果账册中没有,则添加一条
string machineId = ConfigurationManager.AppSettings["machineId"] ?? "DM1";
//根据已生成的日结存记录
int deleteNum = SqlSugarHelper.Db.Deleteable<MachineRecord>()
.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<AccountModel> accountList = _machineRecordService.ReportAccountBook(nowDate, null, 0);
//库存中的记录
List<ChannelStockCount> 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<ChannelStock>()
.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<ChannelStock>()
.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();
}
}

View File

@ -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(() =>
{

View File

@ -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<int, ChannelStock> grouping = enumerator.Current;
//int DrawerNo =Convert.ToInt32(grouping.Key.Substring(0,grouping.Key.IndexOf('-')));
int DrawerNo = grouping.Key;
List<ChannelStock> channelStocks = grouping.ToList();
channelStocks.ForEach(it => it.process = 1);
List<ChannelStock> Stocks = grouping.ToList();
List<ChannelStock> copyStocks = new List<ChannelStock>();
foreach (var item in Stocks)
{
copyStocks.Add(item);
}
Stocks.ForEach(it => it.process = 1);
_portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉");
List<ChannelStock> singleChannels = channelStocks.GroupBy(it => new
List<ChannelStock> 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)
{

View File

@ -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;
/// <summary>
/// PDF 的 html 模板
/// </summary>
public string Template
{
get => _template;
set => SetProperty(ref _template, value);
}
private ExpandoObject _data;
public event Action<IDialogResult> RequestClose;
/// <summary>
/// 传递给 pdf 的数据
/// </summary>
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";
}
}

View File

@ -0,0 +1,19 @@
<UserControl x:Class="DM_Weight.Views.Dialog.PrintPdfView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:DM_Weight.Views.Dialog"
xmlns:wpf="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
mc:Ignorable="d" MinHeight="750" MinWidth="1000"
d:DesignHeight="450" d:DesignWidth="800">
<Grid Margin="24">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid>
<wpf:WebView2 x:Name="webView2" Source="{Binding pdfFilePath}" />
</Grid>
</Grid>
</UserControl>

View File

@ -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
{
/// <summary>
/// PrintPdfView.xaml 的交互逻辑
/// </summary>
public partial class PrintPdfView : UserControl
{
public PrintPdfView()
{
InitializeComponent();
}
///// <summary>
///// 配置 WebView2加载 vuejs加载 pdf 模板,传递数据到 html 中
///// </summary>
///// <returns></returns>
//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 中
// };
//}
}
}