664 lines
46 KiB
C#
664 lines
46 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;
|
|
using System.Data;
|
|
using MySqlConnector;
|
|
using System.Windows.Markup;
|
|
|
|
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.small_unit as smallUnit,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 ";
|
|
if(App.SingleModel)
|
|
{
|
|
SQL += " and cl.row_no<=8";
|
|
}
|
|
else
|
|
{
|
|
SQL += " and cl.row_no>8";
|
|
}
|
|
SQL += " 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);
|
|
}
|
|
/// <summary>
|
|
/// 导出盘点后库存信息
|
|
/// </summary>
|
|
/// <param name="startDate"></param>
|
|
/// <param name="endDate"></param>
|
|
public static void PrintReportStockNew(DateTime? startDate, DateTime? endDate)
|
|
{
|
|
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);
|
|
}
|
|
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");
|
|
// 定义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 TYPE, stockQuantity,inQuantity,outQuantity,operationTime,invoiceId,drugName,drugId,drugSpec,packUnit,dosage,manufactory,manuNo,effDate,
|
|
operatorName,reviewerName,supplierDept,receiveDept,bigUnit,smallUnit 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`,
|
|
di.`drug_spec` AS `drugSpec`, di.`pack_unit` AS `packUnit`,di.big_unit as bigUnit,di.small_unit as smallUnit, 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))
|
|
{
|
|
SQL += " AND mr.drug_id='" + drug_id + "' ";
|
|
}
|
|
SQL += " ORDER BY mr.`drug_id`, mr.`operation_time`, mr.`id`) AS T";
|
|
if (type > 0)
|
|
{
|
|
if (type == 1)
|
|
{
|
|
SQL += " WHERE inQuantity>0 ";
|
|
}
|
|
if (type == 2)
|
|
{
|
|
SQL += " WHERE outQuantity>0 ";
|
|
}
|
|
if (type == 5)
|
|
{
|
|
SQL += " WHERE type=5 ";
|
|
}
|
|
}
|
|
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.small_unit as smallUnit,
|
|
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.small_unit as smallUnit,
|
|
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.small_unit as smallUnit,
|
|
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.`check_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.small_unit as smallUnit,
|
|
di.`manufactory` AS manuFactory,di.`max_stock` AS baseQuantity,dmr.`drug_id` AS drugId,
|
|
ul.`user_name` AS nickname,u2.`user_name` as reviewer 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`
|
|
LEFT JOIN user_list u2 ON dmr.`reviewer` = u2.`id` 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);
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* 打印预览
|
|
* 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);
|
|
}
|
|
//交接班记录报表
|
|
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);
|
|
string p_machine_id = (ConfigurationManager.AppSettings["machineId"] ?? "DM1");
|
|
// 定义Grid++Report报表主对象
|
|
GridppReport Report = new GridppReport();
|
|
// 加载模板文件
|
|
//Report.LoadFromFile(new FileInfo(AppDomain.CurrentDomain.BaseDirectory) + "ReportTemp//" + "changeShifts_temp.grf");
|
|
Report.LoadFromFile(new FileInfo(AppDomain.CurrentDomain.BaseDirectory) + "ReportTemp//" + "changeShifts_temp_new.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);
|
|
});
|
|
SQL = $@"SELECT opt_date,drug_name,drug_spec,beforenum,getnum,usenum,manu_no,surplus,CONCAT(fromoperator,' ',fromreviewer) as fromoperator,
|
|
CONCAT(tooperator,' ',toreviewer) as tooperator,pack_unit,stockQuantity,emptyQuantity
|
|
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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 盘点页面导出记录,按选中行进行导出
|
|
/// </summary>
|
|
/// <param name="type"></param>
|
|
/// <param name="startDate"></param>
|
|
/// <param name="endDate"></param>
|
|
public static void PrintReportMechineRecordForSelect(List<MachineRecord> data)
|
|
{
|
|
// 定义Grid++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>>();
|
|
records.Add("table", data);
|
|
string str = JsonConvert.SerializeObject(records);
|
|
Report.LoadDataFromXML(str);
|
|
// 加载数据
|
|
Report.PrintPreview(true);
|
|
}
|
|
/// <summary>
|
|
/// 导出处方登记专册
|
|
/// </summary>
|
|
/// <param name="orderNo"></param>
|
|
/// <param name="startDate"></param>
|
|
/// <param name="endDate"></param>
|
|
public static void PrintReportOrderAccount(string orderNo, 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);
|
|
});
|
|
Report.LoadFromFile(new FileInfo(AppDomain.CurrentDomain.BaseDirectory) + "ReportTemp//account_book_order.grf");
|
|
|
|
SQL = $@"SELECT DISTINCT oi.recv_date,oi.p_name,oi.sex,oi.age,oi.id_number,oi.patient_no,oi.disease,dm.manu_no,dm.Quantity,oi.doctor_name,oi.order_no,dm.reviewer,dm.operator,ul.user_name operatorName,ul2.user_name reviewerName
|
|
,di.Drug_name,di.Drug_spec,di.big_unit,di.small_unit as smallUnit,di.drug_id,dm.receivePerson,di.manuFactory,patient_card,dm.ordinalNum as ordinalNum,CONCAT(DATE_FORMAT(operation_time,'%Y%m%d'),ordinalnum) as OrderOrdinal
|
|
from order_info oi inner join order_detail od on oi.order_no=od.Order_No
|
|
LEFT JOIN dm_machine_record dm on oi.order_no=dm.invoice_id AND od.`drug_id`=dm.`drug_id`
|
|
inner JOIN drug_info di on od.drug_id=di.drug_id left join user_list ul on dm.operator=ul.id left join user_list ul2 on dm.reviewer=ul2.id
|
|
WHERE dm.machine_id = '{p_machine_id}' and oi.recv_date>'{p_startDate}' and oi.recv_date<'{p_endDate}' and dm.type=2 ";
|
|
if (!string.IsNullOrEmpty(orderNo))
|
|
{
|
|
SQL += $" and oi.order_no='{orderNo}'";
|
|
}
|
|
SQL += " order by di.drug_id,oi.recv_date,dm.ordinalNum";
|
|
|
|
Report.DetailGrid.Recordset.ConnectionString = gridConnectionString;
|
|
Report.DetailGrid.Recordset.QuerySQL = SQL;
|
|
|
|
Report.PrintPreview(true);
|
|
}
|
|
/// <summary>
|
|
/// 导出回收登记记录
|
|
/// </summary>
|
|
/// <param name="orderNo"></param>
|
|
/// <param name="startDate"></param>
|
|
/// <param name="endDate"></param>
|
|
public static void PrintReportReturnEmpty(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);
|
|
});
|
|
Report.LoadFromFile(new FileInfo(AppDomain.CurrentDomain.BaseDirectory) + "ReportTemp//return_empty.grf");
|
|
|
|
SQL = $@"SELECT di.drug_id, YEAR(dm.operation_time) as dmYear,oi.P_name,oi.dept_name,dm.operation_time,dm.Quantity,dm.manu_no,dm.returnPerson,dm.receivePerson,di.drug_name,di.Drug_spec,di.big_unit,di.small_unit as smallUnit,di.manufactory from order_info oi
|
|
inner join dm_machine_record dm on oi.order_no=dm.invoice_id
|
|
inner join drug_info di on dm.drug_id=di.drug_id
|
|
where dm.type=32 and dm.machine_id = '{p_machine_id}' and dm.operation_time>'{p_startDate}' and dm.operation_time<'{p_endDate}'";
|
|
|
|
SQL += " order by di.drug_iddm.operation_time,";
|
|
|
|
Report.DetailGrid.Recordset.ConnectionString = gridConnectionString;
|
|
Report.DetailGrid.Recordset.QuerySQL = SQL;
|
|
|
|
Report.PrintPreview(true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 逐日消耗专用账册
|
|
/// </summary>
|
|
/// <param name="startDate"></param>
|
|
/// <param name="endDate"></param>
|
|
/// <param name="drug_id"></param>
|
|
public static void PrintReportSpecialAccount(DateTime endDate, string drug_id)
|
|
{
|
|
//DateTime? p_startDate = startDate ?? Convert.ToDateTime("2010-1-1");
|
|
//DateTime? p_endDate = endDate ?? DateTime.Now.AddDays(1);
|
|
string strDate = endDate.ToString("yyyy-MM");
|
|
string p_machine_id = (ConfigurationManager.AppSettings["machineId"] ?? "DM1");
|
|
// 定义Grid++Report报表主对象
|
|
GridppReport Report = new GridppReport();
|
|
string SQL = string.Empty;
|
|
string machine_id = (ConfigurationManager.AppSettings["machineId"] ?? "DM1");
|
|
|
|
// SQL = $@"SELECT mr.drug_id as drugId,'test' InTotal,YEAR(mr.`operation_time`) as DMYear,MONTH(mr.`operation_time`) as DMMonth,
|
|
// DAY(mr.`operation_time`) as DMDay,manu_no as manuNo,operation_time as operationTime,return_quantity1 as inQuantity,return_quantity2 as outQuantity,
|
|
// manunoQuantity as stockQuantity,u1.user_name as operatorName,u2.user_name as reviewerName,di.`drug_name` AS `drugName`,
|
|
// di.`drug_spec` AS `drugSpec`, di.`pack_unit` AS `packUnit`,di.big_unit as bigUnit, di.`dosage` AS `dosage`, di.`manufactory` AS `manufactory`
|
|
//FROM dm_machine_record mr INNER 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` = '{machine_id}' and type=5 and DATE_FORMAT(operation_time,'%Y-%m')='{strDate}' ORDER BY mr.drug_id,operation_time";
|
|
|
|
SQL = $@"SELECT t.drugId,t.DMYear,t.DMMonth,t.DMDay,t.manuNo,t.operationTime,t.inQuantity as inQuantity,t.outQuantity AS outQuantity,dmr.manunoQuantity AS stockQuantity,t.operatorName,t.reviewerName,
|
|
t.drugName,t.drugSpec,t.packUnit,t.bigUnit,t.smallUnit,t.dosage,t.manufactory from dm_machine_record dmr inner join
|
|
(SELECT max(mr.id) id, mr.drug_id as drugId,'test' InTotal,YEAR(mr.`operation_time`) as DMYear,MONTH(mr.`operation_time`) as DMMonth,
|
|
DAY(mr.`operation_time`) as DMDay,manu_no as manuNo,operation_time as operationTime,
|
|
SUM(IF(mr.`type` IN (1, 31), mr.`quantity`, IF(mr.`type` = 4 AND mr.`quantity` > 0, mr.`quantity`, 0)) ) AS `inQuantity`,
|
|
SUM(IF(mr.`type` = 2, mr.`quantity`, IF(mr.`type` = 4 AND mr.`quantity` < 0, (0 - mr.`quantity`), 0))) AS `outQuantity`,
|
|
manunoQuantity as stockQuantity,u1.user_name as operatorName,u2.user_name as reviewerName,di.`drug_name` AS `drugName`,
|
|
di.`drug_spec` AS `drugSpec`, di.`pack_unit` AS `packUnit`,di.big_unit as bigUnit,di.small_unit as smallUnit, di.`dosage` AS `dosage`, di.`manufactory` AS `manufactory`
|
|
FROM dm_machine_record mr INNER 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` = '{machine_id}' and type in(1,2,31,4,5) and mr.manu_no is not NULL and DATE_FORMAT(operation_time,'%Y-%m')='{strDate}'and IF(mr.`type` = 4 AND mr.`quantity` = 0, 99999, mr.`quantity`) <>99999
|
|
GROUP BY drugId,DMYear,DMMonth,DMDay,manuNo ORDER BY mr.drug_id,operation_time) t on dmr.id=t.id";
|
|
List<Dictionary<string, object>> tableList = SqlSugarHelper.Db.SqlQueryable<dynamic>(SQL).ToDictionaryList();
|
|
for (int i = 0; i < tableList.Count; i++)
|
|
{
|
|
LastMonthModel InTotalModel = new LastMonthModel();
|
|
LastMonthModel OutTotalModel = new LastMonthModel();
|
|
LastMonthModel StackTotalModel = new LastMonthModel();
|
|
foreach (KeyValuePair<string, object> kvp in tableList[i])
|
|
{
|
|
if (kvp.Key == "drugId")
|
|
{
|
|
//查询药品id对应的上月结存数量及批号
|
|
string strValue = kvp.Value.ToString();
|
|
string inQuantitySQL = $@"SELECT GROUP_CONCAT(SumInQuantity) as StrTotalQuantity,GROUP_CONCAT(manu_no) as StrTotalManuNo from
|
|
(SELECT sum(IF(mr.`type` IN (1, 31), mr.`quantity`, IF(mr.`type` = 4 AND mr.`quantity` > 0, mr.`quantity`, 0))) as SumInQuantity,manu_no
|
|
from dm_machine_record mr where drug_id='{strValue}' and machine_id='{machine_id}' and type in(1,2,31,4,5) and mr.manu_no is not NULL
|
|
and DATE_FORMAT(operation_time,'%Y-%m')='{strDate}'and IF(mr.`type` = 4 AND mr.`quantity` = 0, 99999, mr.`quantity`) <>99999 GROUP BY drug_id,manu_no ORDER BY drug_id,operation_time) as t";
|
|
InTotalModel = SqlSugarHelper.Db.SqlQueryable<LastMonthModel>(inQuantitySQL).First();
|
|
|
|
string outQuantitySQL = $@"SELECT GROUP_CONCAT(SumInQuantity) as StrTotalQuantity,GROUP_CONCAT(manu_no) as StrTotalManuNo from
|
|
(SELECT sum(IF(mr.`type` = 2, mr.`quantity`, IF(mr.`type` = 4 AND mr.`quantity` < 0, (0 - mr.`quantity`), 0))) as SumInQuantity ,manu_no
|
|
from dm_machine_record mr where drug_id='{strValue}' and machine_id='{machine_id}' and type in(1,2,31,4,5) and mr.manu_no is not NULL
|
|
and DATE_FORMAT(operation_time,'%Y-%m')='{strDate}' and IF(mr.`type` = 4 AND mr.`quantity` = 0, 99999, mr.`quantity`) <>99999 GROUP BY drug_id,manu_no ORDER BY drug_id,operation_time) as t";
|
|
OutTotalModel = SqlSugarHelper.Db.SqlQueryable<LastMonthModel>(outQuantitySQL).First();
|
|
|
|
string stockQuantitySQL = $@"SELECT GROUP_CONCAT(a.Manu_No) as StrTotalManuNo,GROUP_CONCAT(a.manunoQuantity) as StrTotalQuantity from dm_machine_record a inner join
|
|
(select drug_id,manu_no,max(operation_time) as latest_date,stock_quantity from dm_machine_record
|
|
WHERE DATE_FORMAT(operation_time,'%Y-%m')='{strDate}' and machine_id='{machine_id}' and Type<>32 and manu_no is not NULL GROUP BY drug_id,manu_no ) b on a.drug_id=b.drug_id and a.manu_no=b.manu_no
|
|
and a.operation_time=b.latest_date and machine_id='{machine_id}' WHERE a.drug_id='{strValue}' and Type<>32 and DATE_FORMAT(operation_time,'%Y-%m')='{strDate}'";
|
|
StackTotalModel = SqlSugarHelper.Db.SqlQueryable<LastMonthModel>(stockQuantitySQL).First();
|
|
}
|
|
}
|
|
tableList[i].Add("inTotal", InTotalModel.StrTotalQuantity);
|
|
tableList[i].Add("inTotalManuNo", InTotalModel.StrTotalManuNo);
|
|
tableList[i].Add("outTotal", OutTotalModel.StrTotalQuantity);
|
|
tableList[i].Add("outTotalManuNo", OutTotalModel.StrTotalManuNo);
|
|
tableList[i].Add("stockTotal", StackTotalModel.StrTotalQuantity);
|
|
tableList[i].Add("stockTotalManuNO", StackTotalModel.StrTotalManuNo);
|
|
}
|
|
Dictionary<string, List<Dictionary<string, object>>> records = new Dictionary<string, List<Dictionary<string, object>>>();
|
|
records.Add("table", tableList);
|
|
string str = JsonConvert.SerializeObject(records);
|
|
// 加载模板文件
|
|
Report.LoadFromFile(new FileInfo(AppDomain.CurrentDomain.BaseDirectory) + "ReportTemp//" + "account_book_temp-01.grf");
|
|
Report.LoadDataFromXML(str);
|
|
Report.PrintPreview(true);
|
|
}
|
|
static GridppReport rptMain = new GridppReport();
|
|
static GridppReport rptCustomerList = new GridppReport();
|
|
/// <summary>
|
|
/// 逐日消耗专用账册2
|
|
/// </summary>
|
|
/// <param name="startDate"></param>
|
|
/// <param name="endDate"></param>
|
|
/// <param name="drug_id"></param>
|
|
public static void PrintReportSpecialAccount2(DateTime endDate, string drug_id)
|
|
{
|
|
//InsertSubReport("ReportTemp//account_book_temp-022.grf", "2d");
|
|
|
|
//用推模式给子报表提供数据:为子报表定义一个外部的报表对象,以便处理其报表事件
|
|
//用推模式给子报表提供数据:
|
|
//rptMain.ControlByName("2d").AsSubReport.Report = rptCustomerList; //子报表部件框的报表对象关联一个外部报表对象,以便响应报表事件
|
|
////rptCustomerList.DetailGrid.Recordset.ConnectionString = gridConnectionString; //让子报表 rptProductList 用推模式填入报表数据,将程序中取得的数据填入到报表中
|
|
//rptCustomerList.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(CustomerListFetchRecord); //连接报表事件
|
|
//rptMain.PrintPreview(true);
|
|
|
|
GridppReport Report = new GridppReport();
|
|
string machine_id = (ConfigurationManager.AppSettings["machineId"] ?? "DM1");
|
|
string strDate = endDate.ToString("yyyy-MM");
|
|
|
|
string masterSql = $@" SELECT DISTINCT di.`drug_id` AS `drugId`, YEAR(mr.`operation_time`) as DMYear,MONTH(mr.`operation_time`) as DMMonth, di.`drug_name` AS `drugName`, di.`drug_spec` AS `drugSpec`,
|
|
di.big_unit as bigUnit,di.small_unit as smallUnit, di.`dosage` AS `dosage`, di.`manufactory` AS `manufactory`, '' lastMonthStock,'' lastMonthMauno,
|
|
mr.`manu_no` AS `manuNo`from dm_machine_record mr inner join drug_info di on mr.drug_id=di.drug_id where machine_id='{machine_id}' and type in(1,2,31,4) and DATE_FORMAT(mr.operation_time,'%Y-%m')='{strDate}'
|
|
ORDER BY mr.drug_id";
|
|
List<Dictionary<string, object>> masterList = SqlSugarHelper.Db.SqlQueryable<dynamic>(masterSql).ToDictionaryList();
|
|
|
|
string detail1Sql = $@" SELECT di.drug_id as drugId,DAY(mr.operation_time) AS DMDAY,mr.TYPE,
|
|
IF(mr.`type` IN (1, 31), mr.`quantity`, IF(mr.`type` = 4 AND mr.`quantity` > 0, mr.`quantity`, 0)) AS `inQuantity`,
|
|
mr.manu_no as manuNo,ul.user_name as operatorname,u2.user_name as reviewername from dm_machine_record mr
|
|
inner join drug_info di on mr.drug_id=di.drug_id left join user_list ul on mr.operator=ul.id left join user_list u2 on mr.reviewer=u2.id
|
|
where mr.machine_id='{machine_id}' and type in (1,31,4) and DATE_FORMAT(mr.operation_time,'%Y-%m')='{strDate}'
|
|
and if(mr.Type=4 and mr.Quantity=0,99999, mr.`quantity`) <>99999 ORDER BY mr.drug_id";
|
|
List<Dictionary<string, object>> detail1List = SqlSugarHelper.Db.SqlQueryable<dynamic>(detail1Sql).ToDictionaryList();
|
|
|
|
string detail2Sql = $@"SELECT
|
|
di.`drug_id` AS `drugId`,DAY(mr.`operation_time`) as DMDay,
|
|
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`,
|
|
mr.`manu_no` AS `manuNo`,-- mr.`eff_date` AS `effDate`,
|
|
u1.`user_name` AS `operatorName`, u2.`user_name` AS `reviewerName` -- ,mr.supplierDept,mr.receiveDept
|
|
-- sum(InQuantity) as TotalInQuantity
|
|
FROM
|
|
dm_machine_record mr INNER 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` = '{machine_id}' AND type in(2,4)
|
|
AND DATE_FORMAT(mr.operation_time,'%Y-%m')= '{strDate}' and IF(mr.`type` = 4 AND mr.`quantity` = 0, 99999, mr.`quantity`) <>99999 ORDER BY mr.drug_id ";
|
|
|
|
List<Dictionary<string, object>> detail2List = SqlSugarHelper.Db.SqlQueryable<dynamic>(detail2Sql).ToDictionaryList();
|
|
|
|
Dictionary<string, List<Dictionary<string, object>>> records = new Dictionary<string, List<Dictionary<string, object>>>();
|
|
records.Add("Master", masterList);
|
|
records.Add("Detail1", detail1List);
|
|
records.Add("Detail2", detail2List);
|
|
|
|
string str = JsonConvert.SerializeObject(records);
|
|
Report.LoadFromFile(new FileInfo(AppDomain.CurrentDomain.BaseDirectory) + "ReportTemp//" + "account_book_temp-022.grf");
|
|
Report.LoadDataFromXML(str);
|
|
// 加载数据
|
|
Report.PrintPreview(true);
|
|
}
|
|
|
|
public static void PrintReportSpecialAccount2New(DateTime MonthDate, string drug_id)
|
|
{
|
|
GridppReport Report = new GridppReport();
|
|
string machine_id = (ConfigurationManager.AppSettings["machineId"] ?? "DM1");
|
|
string strDate = MonthDate.ToString("yyyy-MM");
|
|
int DMYear = MonthDate.Year;
|
|
int DMMonth = MonthDate.Month;
|
|
string masterSql = $@"SELECT distinct di.drug_id as drugId,di.drug_name as drugName,di.drug_spec as drugSpec,di.big_unit as bigUnit,di.small_unit as smallUnit,di.manufactory as manufactory,{DMYear} DMYear,{DMMonth} DMMonth from channel_stock cs
|
|
inner join drug_info di on cs.drug_id=di.drug_id where machine_id='{machine_id}' ORDER BY di.drug_id ";
|
|
List<Dictionary<string, object>> masterList = SqlSugarHelper.Db.SqlQueryable<dynamic>(masterSql).ToDictionaryList();
|
|
|
|
|
|
for (int i = 0; i < masterList.Count; i++)
|
|
{
|
|
LastMonthModel lastMonth = new LastMonthModel();
|
|
foreach (KeyValuePair<string, object> kvp in masterList[i])
|
|
{
|
|
if (kvp.Key == "drugId")
|
|
{
|
|
//查询药品id对应的上月结存数量及批号
|
|
string strValue = kvp.Value.ToString();
|
|
string lastMonthSql = $@"SELECT GROUP_CONCAT(manu_no) as StrTotalManuNo,GROUP_CONCAT(manunoQuantity) as StrTotalQuantity
|
|
from dm_machine_record where drug_id='{strValue}' and machine_id='{machine_id}' and DATE_FORMAT(operation_time,'%Y-%m-%d')=LAST_DAY(DATE_SUB('{MonthDate}', INTERVAL 1 MONTH)) and type=5";
|
|
lastMonth = SqlSugarHelper.Db.SqlQueryable<LastMonthModel>(lastMonthSql).First();
|
|
}
|
|
}
|
|
masterList[i].Add("lastMonthStock", lastMonth.StrTotalManuNo);
|
|
masterList[i].Add("lastMonthMauno", lastMonth.StrTotalQuantity);
|
|
}
|
|
|
|
|
|
|
|
string detailSql = $@"SELECT drug_id as drugId,DAY(mr.`operation_time`) as DMDay,manu_no as manuNo,operation_time as operationTime,return_quantity1 as inQuantity,return_quantity2 as outQuantity,
|
|
manunoQuantity as stockQuantity,u1.user_name as operatorName,u2.user_name as reviewerName
|
|
FROM dm_machine_record mr LEFT JOIN user_list u1 ON mr.`operator` = u1.`id`LEFT JOIN user_list u2 ON mr.`reviewer` = u2.`id`
|
|
WHERE mr.`machine_id` = '{machine_id}' and type=5 and DATE_FORMAT(operation_time,'%Y-%m')='{strDate}' ORDER BY drug_id,operation_time";
|
|
|
|
List<Dictionary<string, object>> detailMaster0List = SqlSugarHelper.Db.SqlQueryable<dynamic>(detailSql).ToDictionaryList();
|
|
List<Dictionary<string, object>> detailMaster1List = SqlSugarHelper.Db.SqlQueryable<dynamic>(detailSql).ToDictionaryList();
|
|
|
|
//List<Dictionary<string, object>> detail1List = detailList.Where(it => Convert.ToInt32(it.GetValueOrDefault("inQuantity")) > 0 && Convert.ToInt32(it.GetValueOrDefault("outQuantity")) <= 0)
|
|
List<Dictionary<string, object>> detail1List = detailMaster0List.Where(it => Convert.ToInt32(it.GetValueOrDefault("inQuantity")) > 0)
|
|
.Select(it =>
|
|
{
|
|
it.Remove("outQuantity");
|
|
it.Remove("stockQuantity");
|
|
return it;
|
|
})
|
|
.ToList();
|
|
//List<Dictionary<string, object>> detail2List = detailList.Where(it => Convert.ToInt32(it.GetValueOrDefault("outQuantity")) >0||!(Convert.ToInt32(it.GetValueOrDefault("inQuantity")) >0 && Convert.ToInt32(it.GetValueOrDefault("outQuantity")) == 0))
|
|
List<Dictionary<string, object>> detail2List = detailMaster1List
|
|
.Select(it =>
|
|
{
|
|
it.Remove("inQuantity");
|
|
return it;
|
|
}).ToList();
|
|
Dictionary<string, List<Dictionary<string, object>>> records = new Dictionary<string, List<Dictionary<string, object>>>();
|
|
records.Add("Master", masterList);
|
|
records.Add("Detail1", detail1List);
|
|
records.Add("Detail2", detail2List);
|
|
string str = JsonConvert.SerializeObject(records);
|
|
Report.LoadFromFile(new FileInfo(AppDomain.CurrentDomain.BaseDirectory) + "ReportTemp//" + "account_book_temp-022.grf");
|
|
Report.LoadDataFromXML(str);
|
|
// 加载数据
|
|
Report.PrintPreview(true);
|
|
|
|
}
|
|
public static void test(DateTime endDate, string drug_id)
|
|
{
|
|
//DateTime? p_startDate = startDate ?? Convert.ToDateTime("2010-1-1");
|
|
//DateTime? p_endDate = endDate ?? DateTime.Now.AddDays(1);
|
|
string strDate = endDate.ToString("yyyy-MM");
|
|
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-02.grf");
|
|
string SQL = string.Empty;
|
|
string machine_id = (ConfigurationManager.AppSettings["machineId"] ?? "DM1");
|
|
string strINSql = $@"SELECT GROUP_CONCAT(Manu_No) AS StrTotalManuNo,GROUP_CONCAT(totalInQuantity) AS StrTotalQuantity FROM
|
|
(
|
|
SELECT
|
|
DISTINCT Manu_No ,sum(IF(mr.`type` IN (1, 31), mr.`quantity`, IF(mr.`type` = 4 AND mr.`quantity` > 0, mr.`quantity`, 0))) as totalInQuantity
|
|
from dm_machine_record mr
|
|
INNER JOIN drug_info di ON mr.`drug_id` = di.`drug_id` where mr.machine_id='{machine_id}'
|
|
and IF(mr.`type` IN (1, 31), mr.`quantity`, IF(mr.`type` = 4 AND mr.`quantity` > 0, mr.`quantity`, 0)) >0
|
|
and DATE_FORMAT(operation_time,'%Y-%m')= '{strDate}' and type in('1,31,4')
|
|
GROUP BY mr.drug_id,mr.manu_no
|
|
) as t";
|
|
AccountTotalQuantity InQuantityList = SqlSugarHelper.Db.SqlQueryable<dynamic>(strINSql)
|
|
.Select(it => new AccountTotalQuantity()).First();
|
|
|
|
string strOutSql = $@"SELECT GROUP_CONCAT(Manu_No) AS StrTotalManuNo,GROUP_CONCAT(TotalOutQuantity) AS StrTotalQuantity FROM
|
|
(
|
|
SELECT
|
|
DISTINCT Manu_No ,SUM(IF(mr.`type` = 2, mr.`quantity`, IF(mr.`type` = 4 AND mr.`quantity` < 0, (0 - mr.`quantity`), 0))) AS TotalOutQuantity
|
|
from dm_machine_record mr
|
|
INNER JOIN drug_info di ON mr.`drug_id` = di.`drug_id` where mr.machine_id='{machine_id}'
|
|
and IF(mr.`type` = 2, mr.`quantity`, IF(mr.`type` = 4 AND mr.`quantity` < 0, (0 - mr.`quantity`), 0)) >0
|
|
and DATE_FORMAT(operation_time,'%Y-%m')= '{strDate}' and type in('2,4')
|
|
GROUP BY mr.drug_id,mr.manu_no
|
|
) as t";
|
|
AccountTotalQuantity OutQuantityList = SqlSugarHelper.Db.SqlQueryable<dynamic>(strOutSql)
|
|
.Select(it => new AccountTotalQuantity()).First();
|
|
|
|
string strStockSql = $@"SELECT GROUP_CONCAT(Manu_No) AS StrTotalManuNo,GROUP_CONCAT(stock_quantity) AS StrTotalQuantity FROM
|
|
(SELECT a.Manu_No,a.stock_quantity from dm_machine_record a inner join
|
|
(select drug_id,manu_no,max(operation_time) as latest_date,stock_quantity from dm_machine_record
|
|
WHERE DATE_FORMAT(operation_time,'%Y-%m')='{strDate}' and machine_id='{machine_id}' GROUP BY drug_id,manu_no ) b on a.drug_id=b.drug_id and a.manu_no=b.manu_no
|
|
and a.operation_time=b.latest_date and machine_id='{machine_id}' WHERE DATE_FORMAT(operation_time,'%Y-%m')='{strDate}') as t ";
|
|
AccountTotalQuantity StockQuantityList = SqlSugarHelper.Db.SqlQueryable<dynamic>(strStockSql)
|
|
.Select(it => new AccountTotalQuantity()).First();
|
|
string str1 = "本月领药数量" + ":" + InQuantityList.StrTotalQuantity + " 批号:" + InQuantityList.StrTotalManuNo;
|
|
string str2 = "本月发药数量" + ":" + OutQuantityList.StrTotalQuantity + " 批号:" + OutQuantityList.StrTotalManuNo;
|
|
string str3 = "本月结存数量" + ":" + StockQuantityList.StrTotalQuantity + " 批号:" + StockQuantityList.StrTotalManuNo;
|
|
//Report.ControlByName("StaticBox24").AsStaticBox.Text = str1;
|
|
//Report.ControlByName("StaticBox26").AsStaticBox.Text = str2;
|
|
//Report.ControlByName("StaticBox28").AsStaticBox.Text = str3;
|
|
|
|
|
|
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
|
|
YEAR(mr.`operation_time`) as DMYear,MONTH(mr.`operation_time`) as DMMonth,DAY(mr.`operation_time`) as DMDay,
|
|
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`,
|
|
di.`drug_spec` AS `drugSpec`, di.`pack_unit` AS `packUnit`,di.big_unit as bigUnit,di.small_unit as smallUnit, 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
|
|
-- sum(InQuantity) as TotalInQuantity
|
|
FROM
|
|
dm_machine_record mr INNER 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` = '{machine_id}' AND type in(2,4)
|
|
AND DATE_FORMAT(mr.operation_time,'%Y-%m')= '{strDate}' and IF(mr.`type` = 4 AND mr.`quantity` = 0, 99999, mr.`quantity`) <>99999 ";
|
|
if (!string.IsNullOrEmpty(drug_id))
|
|
{
|
|
SQL += " AND mr.drug_id='" + drug_id + "' ";
|
|
}
|
|
SQL += "ORDER BY YEAR(mr.`operation_time`),MONTH(mr.`operation_time`),DAY(mr.`operation_time`),mr.`drug_id`,mr.manu_no"; //" GROUP BY mr.drug_id,mr.manu_no,mr.operation_time " +
|
|
|
|
Report.DetailGrid.Recordset.QuerySQL = SQL;
|
|
|
|
Report.PrintPreview(true);
|
|
}
|
|
|
|
}
|
|
public class LastMonthModel
|
|
{
|
|
public string StrTotalManuNo { get; set; } = "0";
|
|
public string StrTotalQuantity { get; set; } = "0";
|
|
}
|
|
}
|