230 lines
14 KiB
C#
230 lines
14 KiB
C#
using gregn6Lib;
|
||
using Newtonsoft.Json;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using DM_Weight.Models;
|
||
using System.Configuration;
|
||
using DM_Weight.util;
|
||
|
||
namespace DM_Weight.Report
|
||
{
|
||
public class GridReportUtil
|
||
{
|
||
|
||
// 定义Grid++Report报表主对象
|
||
public static GridppReport Report = new GridppReport();
|
||
public static string gridConnectionString = ConfigurationManager.AppSettings["gridConnectionString"];
|
||
/**
|
||
* 打印预览
|
||
* tempname: 模板文件名称
|
||
* data: 模板数据
|
||
*/
|
||
public static void PrintReport(string tempname, object data)
|
||
{
|
||
// 定义Grid++Report报表主对象
|
||
GridppReport Report = new GridppReport();
|
||
// 加载模板文件
|
||
Report.LoadFromFile(new FileInfo(AppDomain.CurrentDomain.BaseDirectory) + "ReportTemp//" + tempname);
|
||
string s = JsonConvert.SerializeObject(data);
|
||
// 加载数据
|
||
Report.LoadDataFromXML(JsonConvert.SerializeObject(data));
|
||
Report.PrintPreview(true);
|
||
}
|
||
|
||
public static void PrintReportStock()
|
||
{
|
||
// 定义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,
|
||
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`";
|
||
// 加载模板文件
|
||
Report.LoadFromFile(new FileInfo(AppDomain.CurrentDomain.BaseDirectory) + "ReportTemp//" + "stock_template.grf");
|
||
Report.DetailGrid.Recordset.ConnectionString = gridConnectionString;
|
||
Report.DetailGrid.Recordset.QuerySQL = SQL;
|
||
Report.PrintPreview(true);
|
||
}
|
||
public static void PrintReportAccountBook(DateTime? startDate, DateTime? endDate)
|
||
{
|
||
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");
|
||
// 定义Grid++Report报表主对象
|
||
GridppReport Report = new GridppReport();
|
||
// 加载模板文件
|
||
Report.LoadFromFile(new FileInfo(AppDomain.CurrentDomain.BaseDirectory) + "ReportTemp//" + "account_book_temp.grf");
|
||
string SQL = string.Empty;
|
||
Report.DetailGrid.Recordset.ConnectionString = gridConnectionString;
|
||
//Report.Initialize += new _IGridppReportEvents_InitializeEventHandler(() =>
|
||
//{
|
||
// Report.ParameterByName("machine_id").Value = (ConfigurationManager.AppSettings["machineId"] ?? "DM1");
|
||
// Report.ParameterByName("startDate").Value = startDate ?? Convert.ToDateTime("2010-1-1");
|
||
// Report.ParameterByName("endDate").Value = endDate ?? DateTime.Now.AddDays(1);
|
||
//});
|
||
//Report.DetailGrid.Recordset.QuerySQL = SQL;
|
||
SQL = $@"SELECT 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`, mr.`invoice_id` 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`, mr.`eff_date` AS `effDate`, u1.`user_name` AS `operatorName`, u2.`user_name` AS `reviewerName` 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}' ORDER BY mr.`drug_id`, mr.`operation_time`, mr.`id`";
|
||
Report.DetailGrid.Recordset.QuerySQL = SQL;
|
||
Report.PrintPreview(true);
|
||
}
|
||
|
||
public static void PrintReportMechineRecord(int type, DateTime? startDate, DateTime? endDate)
|
||
{
|
||
// 定义Grid++Report报表主对象
|
||
GridppReport Report = new GridppReport();
|
||
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 SQL = string.Empty;
|
||
//Report.Initialize += new _IGridppReportEvents_InitializeEventHandler(() =>
|
||
//{
|
||
// Report.ParameterByName("machine_id").Value = (ConfigurationManager.AppSettings["machineId"] ?? "DM1");
|
||
// Report.ParameterByName("startDate").Value = startDate??DateTime.Now.AddYears(-10);
|
||
// Report.ParameterByName("endDate").Value = endDate??DateTime.Now.AddDays(1);
|
||
//});
|
||
// 加载模板文件
|
||
if (type == 1)
|
||
{
|
||
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,
|
||
di.`drug_name` AS drugName,di.`drug_spec` AS drugSpec,di.`pack_unit` AS packUnit,
|
||
di.`manufactory` AS manuFactory,di.`max_stock` AS baseQuantity,dmr.`drug_id` AS drugId,
|
||
ul.`user_name` AS nickname FROM dm_machine_record dmr LEFT JOIN drug_info di ON di.`drug_id` = dmr.`drug_id`
|
||
LEFT JOIN user_list ul ON ul.`id` = dmr.`Operator` WHERE dmr.`type` = 1 AND dmr.`machine_id` = '{p_machine_id}'
|
||
AND dmr.`operation_time` > '{p_startDate}' AND dmr.`operation_time` < '{p_endDate}'";
|
||
}
|
||
else if (type == 2)
|
||
{
|
||
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,
|
||
di.`drug_name` AS drugName,di.`drug_spec` AS drugSpec,di.`pack_unit` AS packUnit,
|
||
di.`manufactory` AS manuFactory,di.`max_stock` AS baseQuantity,dmr.`drug_id` AS drugId,
|
||
ul.`user_name` AS nickname FROM dm_machine_record dmr LEFT JOIN drug_info di ON di.`drug_id` = dmr.`drug_id`
|
||
LEFT JOIN user_list ul ON ul.`id` = dmr.`Operator` WHERE dmr.`type` = 2
|
||
AND dmr.`machine_id` ='{p_machine_id}' AND dmr.`operation_time` > '{p_startDate}'
|
||
AND dmr.`operation_time` < '{p_endDate}'";
|
||
}
|
||
else if (type == 3)
|
||
{
|
||
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,
|
||
dmr.`eff_date` AS effDate,dmr.`operation_time` AS operationTime,di.`drug_name` AS drugName,
|
||
di.`drug_spec` AS drugSpec,di.`pack_unit` AS packUnit,
|
||
di.`manufactory` AS manuFactory,di.`max_stock` AS baseQuantity,
|
||
dmr.`drug_id` AS drugId,ul.`user_name` AS nickname FROM dm_machine_record dmr
|
||
LEFT JOIN drug_info di ON di.`drug_id` = dmr.`drug_id` LEFT JOIN user_list ul ON ul.`id` = dmr.`Operator`
|
||
WHERE dmr.`type` in (31, 32) AND dmr.`machine_id` = '{p_machine_id}' AND dmr.`operation_time` > '{p_startDate}'
|
||
AND dmr.`operation_time` < '{p_endDate}'";
|
||
}
|
||
else
|
||
{
|
||
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.`quantity` AS quantity,
|
||
dmr.`manu_no` AS manuNo,dmr.`eff_date` AS effDate,dmr.`operation_time` AS operationTime,
|
||
di.`drug_name` AS drugName,di.`drug_spec` AS drugSpec,di.`pack_unit` AS packUnit,
|
||
di.`manufactory` AS manuFactory,di.`max_stock` AS baseQuantity,dmr.`drug_id` AS drugId,
|
||
ul.`user_name` AS nickname FROM dm_machine_record dmr LEFT JOIN drug_info di ON di.`drug_id` = dmr.`drug_id`
|
||
LEFT JOIN user_list ul ON ul.`id` = dmr.`Operator` WHERE dmr.`type` = 4
|
||
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);
|
||
}
|
||
/// <summary>
|
||
/// 麻醉科精一、精二药品领取登记表
|
||
/// </summary>
|
||
/// <remarks>
|
||
/// <para>
|
||
/// 麻醉科药品领取登记表按取药时间查询 <br/> 精一固定5种药;精二固定4种药
|
||
/// </para>
|
||
/// </remarks>
|
||
/// <param name="startDate"></param>
|
||
/// <param name="endDate"></param>
|
||
/// <param name="type">1->精1;2->精2</param>
|
||
public static void PrintReportDrugTakeCheckIn(DateTime? startDate, DateTime? endDate,int type)
|
||
{
|
||
// 定义Grid++Report报表主对象
|
||
GridppReport Report = new GridppReport();
|
||
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 SQL = string.Empty;
|
||
Report.Initialize += new _IGridppReportEvents_InitializeEventHandler(() =>
|
||
{
|
||
Report.ParameterByName("machine_id").Value = (ConfigurationManager.AppSettings["machineId"] ?? "DM1");
|
||
Report.ParameterByName("startDate").Value = startDate ?? DateTime.Now.AddYears(-10);
|
||
Report.ParameterByName("endDate").Value = endDate ?? DateTime.Now.AddDays(1);
|
||
});
|
||
|
||
SQL = $@"SELECT operation_time,d.drug_name,manu_no,eff_date,quantity,u.User_name,ur.user_name reviewer,returnOptTime,u2.User_name returnUser,u2r.user_name returnReviewer,return_quantity1,return_quantity2
|
||
from dm_machine_record AS mr
|
||
LEFT JOIN (SELECT operation_time returnOptTime,operator returnOperator,reviewer returnReviewer,drug_id returnDrug_id,get_id
|
||
FROM dm_machine_record) AS returnMr
|
||
ON mr.drug_id=returnMr.returnDrug_id AND returnMr.get_id=mr.id LEFT JOIN drug_info d on mr.drug_id=d.drug_id
|
||
LEFT JOIN user_list u on mr.operator=u.id
|
||
LEFT JOIN user_list ur on mr.reviewer=ur.id
|
||
LEFT JOIN user_list u2 on returnMr.returnOperator=u2.id
|
||
LEFT JOIN user_list u2r on returnMr.returnReviewer=u2r.id
|
||
WHERE mr.type=2 AND mr.`machine_id` = '{p_machine_id}' AND mr.`operation_time` > '{p_startDate}' AND mr.`operation_time` < '{p_endDate}' ";
|
||
if (type == 1)
|
||
{
|
||
// 加载模板文件
|
||
Report.LoadFromFile(new FileInfo(AppDomain.CurrentDomain.BaseDirectory) + "ReportTemp//" + "drug_take_check_in.grf");
|
||
SQL += @" and mr.DRUG_ID IN('9131487','10826545','9112595','9132487','9087821')";
|
||
}
|
||
else
|
||
{
|
||
// 加载模板文件
|
||
Report.LoadFromFile(new FileInfo(AppDomain.CurrentDomain.BaseDirectory) + "ReportTemp//" + "drug_take_check_in2.grf");
|
||
SQL += @" and mr.DRUG_ID IN('95892862','1053979','9644264','12663789')";
|
||
}
|
||
SQL+=" GROUP BY mr.operation_time, mr.drug_id, mr.operator, mr.machine_id";
|
||
|
||
Report.DetailGrid.Recordset.ConnectionString = gridConnectionString;
|
||
Report.DetailGrid.Recordset.QuerySQL = SQL;
|
||
|
||
Report.PrintPreview(true);
|
||
}
|
||
|
||
|
||
/**
|
||
* 打印预览
|
||
* tempname: 模板文件名称
|
||
* data: 模板数据
|
||
*/
|
||
public static void PrintMachineRecordReport(List<MachineRecord> data)
|
||
{
|
||
// 定义Grid++Report报表主对象
|
||
GridppReport Report = new GridppReport();
|
||
// 加载模板文件
|
||
Report.LoadFromFile(new FileInfo(AppDomain.CurrentDomain.BaseDirectory) + "ReportTemp//machine_log.grf");
|
||
|
||
// 加载数据
|
||
Report.ParameterByName("type").AsInteger = 1;
|
||
Report.PrintPreview(true);
|
||
}
|
||
}
|
||
}
|