using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using TTCom.Common;
namespace Process
{
/// <summary>
/// 輸入: https://localhost:44397/ITTest/TestCR2PDF.aspx?basedate=2020/12/11
/// 輸出: D:\RptSale20201211.pdf
/// </summary>
public partial class TestCR2PDF : PrintBase
{
const string strRptCode = "RptSale";
DateTime qBaseDate => Request.QueryString["basedate"].ToDateTime();
private void ToPDF()
{
DS_Report = new DataSet();
DS_Report.ReadXmlSchema(xsdPath);
UF_SetMainData(0);
UF_Rpt();
ReportDocument rptDoc = new ReportDocument();
rptDoc.Load(Server.MapPath(@"..\RptCR/RptSale.rpt"), OpenReportMethod.OpenReportByTempCopy);
rptDoc.SetDataSource(DS_Report);
//產生PDF檔
ExportOptions crExportOptions = new ExportOptions();
DiskFileDestinationOptions crDiskFileDestinationOptions = new DiskFileDestinationOptions();
string fname = @"D:\"+ strRptCode + qBaseDate.ToString("yyyyMMdd") + ".pdf";
crDiskFileDestinationOptions.DiskFileName = fname;
crExportOptions = rptDoc.ExportOptions;
{
crExportOptions.DestinationOptions = crDiskFileDestinationOptions;
crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
crExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
}
rptDoc.Export();
rptDoc.Close();
rptDoc.Dispose();
}
protected void Page_Init(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
UF_Preinit(strRptCode);
ToPDF();
}
}
private void UF_Rpt()
{
//SetCompany();
//SetPartner(qPartnerSn);
ReportProvider reportProvider = new ReportProvider();
//var m = reportProvider.GetRptSal01M(qEnumSysClosingItem, qClosingDate);
DataRow drM = DS_Report.Tables[DSTableM].NewRow();
drM["BaseDate"] = qBaseDate.ToString("yyyy/MM/dd");
DS_Report.Tables[DSTableM].Rows.Add(drM);
List<DTORptSaleTB> listTB = reportProvider.GetRptSaleTB(qBaseDate);
foreach (var item in listTB)
{
DataRow dr = DS_Report.Tables[DSTableTB].NewRow();
dr["BaseDate"] = item.BaseDate.ToString("yyyy/MM/dd");
dr["PartnerNameS"] = EnumHelper.GetEnumString<EnumPartner>(item.PartnerSn);
dr["CaseNumAll"] = item.CaseNumAll;
dr["PayAmtAll"] = item.PayAmtAll;
dr["LoanBalance"] = item.LoanBalance;
dr["CaseNumD"] = item.CaseNumD;
dr["PayAmtD"] = item.PayAmtD;
dr["CaseNumM"] = item.CaseNumM;
dr["PayAmtM"] = item.PayAmtM;
dr["RPayAmtM"] = item.RPayAmtM;
dr["RatePayAmtM"] = item.PayAmtM == 0 ? 0 : item.RPayAmtM / item.PayAmtM * 100;
dr["CaseNumMP"] = item.CaseNumMP;
dr["PayAmtMP"] = item.PayAmtMP;
dr["RPayAmtMP"] = item.RPayAmtMP;
dr["RatePayAmtMP"] = item.PayAmtMP == 0 ? 0 : item.RPayAmtMP / item.PayAmtMP * 100;
dr["CaseNumY"] = item.CaseNumY;
dr["PayAmtY"] = item.PayAmtY;
dr["RPayAmtY"] = item.RPayAmtY;
dr["RatePayAmtY"] = item.PayAmtY == 0 ? 0 : item.RPayAmtY / item.PayAmtY * 100;
dr["CaseNumYP"] = item.CaseNumYP;
dr["PayAmtYP"] = item.PayAmtYP;
dr["LoanBalance30"] = item.LoanBalance30;
dr["LoanBalance60"] = item.LoanBalance60;
dr["LoanBalanceRate30"] = item.DelayRate30 * 100;
dr["LoanBalanceRate60"] = item.DelayRate60 * 100;
DS_Report.Tables[DSTableTB].Rows.Add(dr);
}
}
}
}