using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using TTCom.Common;
namespace Rpt
{
public partial class RptSalePrint : PrintBase
{
const string strRptCode = "RptSale";
DateTime qBaseDate;// => Request.QueryString["basedate"].ToDateTime();
protected void Page_Init(object sender, EventArgs e)
{
qBaseDate = new DateTime(2020, 12, 11);
UF_Preinit(strRptCode);
//UF_GetQueryString();
//lblMsg.Text = ReportPath;
try
{
DS_Report = new DataSet();
DS_Report.ReadXmlSchema(xsdPath);
if (!IsPostBack)
{
Cache.Clear(DSTableTB);
UF_SetMainData();
UF_Rpt();
}
else
{
DS_Report = GetListI(DSTableTB);
}
//預覽報表
rd.Load(Server.MapPath(ReportPath));
rd.SetDataSource(DS_Report);
//CRV1.DisplayGroupTree = false;
CRV1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;
CRV1.ReportSource = rd;
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
private void Page_Unload(object sender, System.EventArgs E)
{
rd.Dispose();
CRV1.Dispose();
}
/// <summary>
/// 將查詢資料存放至HttpContext.Current
/// </summary>
/// <param name="ItemName"></param>
/// <returns></returns>
public DataSet GetListI(string ItemName)
{
DataSet dsData = new DataSet();
HttpContext context = HttpContext.Current;
//當查詢的區塊編號的編號cache不存在
if (context.Cache[ItemName.ToString()] == null)
{
//與資料庫相連取資料的程式
UF_Rpt();
dsData = (DataSet)context.Cache[ItemName.ToString()];
}
else
{
//將目前已經查詢過的區塊號碼 Cache 轉為 DataTable
dsData = (DataSet)context.Cache[ItemName.ToString()];
}
return dsData;
}
protected void UF_GetQueryString()
{
}
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);
}
Cache.CreateCache(DSTableTB, DS_Report, 5);
}
protected void btnPrint_Click(object sender, EventArgs e)
{
ReportDocument cry = new ReportDocument();
try
{
cry.Load(Server.MapPath(ReportPath));
cry.SetDataSource(DS_Report);
cry.PrintToPrinter(1, false, 0, 0);
}
catch (Exception ex)
{
}
}
}
}