201 lines
		
	
	
		
			12 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			201 lines
		
	
	
		
			12 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`,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.`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);
 | 
						|
        }
 | 
						|
 | 
						|
 | 
						|
 | 
						|
        /**
 | 
						|
         * 打印预览
 | 
						|
         * 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");
 | 
						|
            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
 | 
						|
                    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);
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 |