You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

1168 lines
46 KiB

using Swift.DAL.AccountReport;
using Swift.DAL.BL.Remit.Transaction;
using Swift.DAL.SwiftDAL;
using Swift.web.Library;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Swift.web.Responsive.AgentPanelReports
{
public partial class Reports : Page
{
private Boolean AllowDrillDown;
private string cssClass = "TBLReport table table-bordered table-condensed table-striped";
private string fieldAlignment = "";
private string fieldFormat = "";
private string fieldWrap = "";
private string tblCaption = "";
private Boolean mergeColumnHead;
private ReportResult reportResult = new ReportResult();
private string excludeColumns = "";
private bool includeSerialNo = false;
private bool useDBRowColorCode = false;
private int subTotalBy = -1;
private int totalTextCol = -1;
private int subTotalTextCol = -1;
private string subTotalFields = "";
private string subTotalText = "";
private string totalFields = "";
private string totalText = "";
private int totalPage = 0;
private int pageNo = 0;
private double grandTotal = 0.00;
private double grandTotalUsd = 0.00;
private double grandTotal_1 = 0.00;
private string reportName = "";
private int extraCol = 0;
private string flag = "";
protected string Url = GetStatic.GetUrlRoot();
private string isExportFull = "";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (GetStatic.GetUser() == "")
Response.Redirect(GetStatic.GetDefaultPage());
}
PrintReport();
}
private void PrintHead()
{
Page.Title = reportResult.ReportHead;
head.InnerHtml = reportResult.ReportHead;
}
private void PrintFilters()
{
var user = GetStatic.GetUser();
var now = GetStatic.GetUserDateTime();
filters.InnerHtml = "Filters Applied : <br />" + reportResult.Filters +
"<br /><br />Generated On=" + now +
" || Generated By=" + user;
}
private void PrintError()
{
rptDiv.InnerHtml = "<div class = \"reportError\">" + reportResult.Msg + "</div>";
}
protected string GetURL()
{
return Request.Url.AbsoluteUri.Replace("&pageNumber=" + GetPageNumber(), "");
}
private void PrintReport()
{
string reportName = GetStatic.ReadQueryString("reportName", "").ToLower();
string mode = GetStatic.ReadQueryString("mode", "").ToLower();
isExportFull = mode.ToLower() == "download" ? "Y" : "N";
reportResult = PrepareReport(reportName);
if (mode == "download")
{
string format = GetStatic.ReadQueryString("format", "xls");
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment; filename=" + reportName + "." + format);
exportDiv.Visible = false;
}
PrintHead();
PrintFilters();
if (reportResult.ErrorCode != "0")
{
PrintError();
return;
}
if (reportName == "usermatrix")
{
PrintUserMatrixReport();
return;
}
if (reportName == "rsptxnsummaryrpt")
{
TxnRSPSummaryReport();
return;
}
DataTable dt;
int tableCount = reportResult.Result.Tables.Count;
if (tableCount > 4)
{
if (mode != "download")
ShowPaging(reportResult.Result.Tables[0]);
dt = reportResult.Result.Tables[1];
}
else
{
dt = reportResult.ResultSet;
}
string reportText = GenerateReport(ref dt);
rptDiv.InnerHtml = reportText;
}
private void ShowPaging(DataTable dt)
{
DataTable dtPaging = dt;
int totalRecords = Convert.ToInt32(dtPaging.Rows[0]["TXNCOUNT"].ToString());
int PageSizes = Convert.ToInt32(dtPaging.Rows[0]["PAGESIZE"].ToString());
int PageNumber = Convert.ToInt32(dtPaging.Rows[0]["PAGENUMBER"].ToString());
if (dtPaging.Columns.Count > 3)
grandTotal = Convert.ToDouble(dtPaging.Rows[0]["GRANDTOTAL"].ToString());
if (dtPaging.Columns.Count > 4)
grandTotalUsd = Convert.ToDouble(dtPaging.Rows[0]["GRANDTOTAL_USD"].ToString());
string cssLink = "pagingLink";
totalPage = totalRecords / PageSizes;
if ((totalPage * PageSizes) < totalRecords)
totalPage++;
var sbPaging = new StringBuilder("<table class='table table-bordered table-striped table-responsive '><tr><td nowrap='nowrap'>");
sbPaging.AppendLine("<div class='reportFilters' width='100%'>");
sbPaging.AppendLine("<span style='width:auto; margin-top:5px;'>Results:&nbsp; " + totalRecords + " records &nbsp; </span>");
paging.Visible = true;
int currPage = GetPageNumber();
int startPage = (currPage - 5 <= 0 ? 1 : currPage - 5);
int offSet = (startPage == 1 ? ((currPage - 5) * -1 + 1) : 0);
int endPage = currPage + 4 + offSet;
endPage = currPage == 0 ? 10 : endPage;
endPage = (endPage > totalPage ? totalPage : endPage);
if (currPage > 10 && (endPage - startPage) + 1 != 10)
{
startPage = startPage - (10 - (endPage - startPage + 1));
}
if (totalRecords > PageSizes)// Convert.ToInt32(GetStatic.GetReportPagesize()))
{
string url = GetURL();
sbPaging.AppendLine("<img onclick='GotoPage(1);' src='../../Images/paging_Icons/first_page.png' alt='First Page' style='margin-top:5px;float:left;border:none;cursor:pointer' />");
sbPaging.AppendLine("<img " + (GetPageNumber() != 1 ? " onclick='GotoPage(" + (GetPageNumber() - 1) + ");'" : "") + " src='../../Images/paging_Icons/" + (GetPageNumber() == 1 ? "previous_page_dis" : "previous_page") + ".png' style='margin-top:5px;float:left;border:none;cursor:pointer' alt='Previous Page' /></a>");
for (int i = startPage; i < endPage + 1; i++)
{
cssLink = PageNumber == i ? "pagingLinkSelected" : "pagingLink";
sbPaging.AppendLine("<span onclick ='GotoPage(" + i + ");' class='" + cssLink + "'>" + i + "</span>");
}
sbPaging.AppendLine("<img " + (GetPageNumber() != totalPage ? "onclick=GotoPage(" + (GetPageNumber() + 1) + ");" : "") + " src='../../Images/paging_Icons/" + (GetPageNumber() == totalPage ? "next_page_dis" : "next_page") + ".png' style='margin-top:5px;border:none;cursor:pointer' alt='Next Page' /></a>");
sbPaging.AppendLine("<img onclick=GotoPage(" + totalPage + "); src='../../Images/paging_Icons/last_page.png' style='margin-top:5px;border:none;cursor:pointer' />");
}
sbPaging.AppendLine("</div></td><td nowrap='nowrap' width='135' align=\"right\">");
if (totalRecords > PageSizes) //Convert.ToInt32(GetStatic.GetReportPagesize()))
sbPaging.AppendLine("Goto Page: " + GotoList(totalPage));
sbPaging.AppendLine("</td></tr></table>");
paging.InnerHtml = sbPaging.ToString();
}
private string GotoList(int totalPage)
{
StringBuilder sb = new StringBuilder("");
sb.AppendLine("<select id='gotoLabel' onchange=GotoPage(this.value); style='min-width:50px'>");
for (int i = 0; i < totalPage; i++)
{
sb.AppendLine("<option value='" + (i + 1) + "' " + (GetPageNumber() == (i + 1) ? "Selected=Selected" : "") + " >" + (i + 1) + "</option>");
}
sb.AppendLine("</select>");
return sb.ToString();
}
private ReportResult PrepareReport(string reportName)
{
if (reportName == "domestictxn")
{
reportResult = PrepareReport_domestictxn();
}
else if (reportName == "userwiserpt")
{
reportResult = PrepareUserWiseReport();
}
else if (reportName == "40111600")
{
reportResult = PrepareReport_40111600();
}
else if (reportName == "cancelreport")
{
reportResult = PrepareCancelReport();
}
else if (reportName == "rsptxnsummaryrpt")
reportResult = PrepareRSPTxnSummaryReport();
return reportResult;
}
#region Report part
private ReportResult PrepareRSPTxnSummaryReport()
{
string pCountry = GetStatic.ReadQueryString("beneficiary", "");
string agentName = GetStatic.ReadQueryString("agentName", "");
string branch = GetStatic.ReadQueryString("branch", "");
string sAgent = GetStatic.ReadQueryString("sAgent", "");
string status = GetStatic.ReadQueryString("status", "");
string dateType = GetStatic.ReadQueryString("date", "");
string fromDate = GetStatic.ReadQueryString("from", "");
string toDate = GetStatic.ReadQueryString("to", "");
string reportType = GetStatic.ReadQueryString("rType", "");
string countryBankId = GetStatic.ReadQueryString("countryBankId", "");
string pageNumber = GetStatic.ReadQueryString("pageNumber", "1");
return (new TranAgentReportDao().GetTxnSummaryReport(GetStatic.GetUser(), branch, sAgent, pCountry, agentName, status, dateType, fromDate, toDate,
reportType, countryBankId, pageNumber, GetStatic.GetReportPagesize()));
}
private void TxnRSPSummaryReport()
{
string reportType = GetStatic.ReadQueryString("rType", "");
switch (reportType)
{
case "Detail":
GetRSPTxnDetailReport();
break;
case "BranchWise":
GetTxnBranchwiseReport();
break;
case "ReceivingAgentWise":
//GetTxnRecAgentwiseReport();
GetRSPTxnSummaryReport("ReceivingAgentWise");
break;
case "ReceivingAgentDetail":
GetTxnRecAgentDetailReport();
break;
case "ReceivingDateWise":
//GetTxnRecAgentDatewiseReport();
GetRSPTxnSummaryReport("ReceivingDateWise");
break;
case "SettlementReport":
//GetTxnRecAgentDatewiseReport();
GetRSPSettlmentReport();
break;
case "SettlementReport_Send":
//GetTxnRecAgentDatewiseReport();
GetRSPSettlmentReport_Drill();
break;
case "SettlementReport_Cancel":
GetRSPSettlmentReport_Drill();
break;
case "SettlementReport_Paid":
GetRSPSettlmentReport_Drill();
break;
case "ReceivingAgentCountryWise":
// GetTxnCollDetailReport();
GetRSPTxnSummaryReport("ReceivingAgentCountryWise");
break;
}
}
private void GetTxnRecAgentDetailReport()
{
var rptName = GetStatic.ReadQueryString("reportName", "").ToLower();
var html = new StringBuilder();
DataTable rpt;
string rptTest = "";
if (rptName == "oldtxnsummaryrpt")
{
fieldFormat = "|||N|N|N||N";
fieldAlignment = "||R|R|R|R|R|R|R|R|R|R|L|R";
totalText = "<b>Total</b>";
totalFields = "2|3|4|5|7";
}
else
{
fieldFormat = "|||N|N|N|N|N||N";
fieldAlignment = "||R|R|R|R|R|R|R|R|R|R|L|R";
totalText = "<b>Total</b>";
totalFields = "|2|3|4|5|7|9";
}
for (int i = 0; i < reportResult.Result.Tables.Count - 3; i++)
{
if (i == 1)
tblCaption = "Cancel Transaction Detail";
rpt = reportResult.Result.Tables[i];
rptTest = GenerateReport(ref rpt).Replace("<td", "<td nowrap = \"nowrap\"");
html.AppendLine(rptTest);
}
rptDiv.InnerHtml = html.ToString();
}
private void GetRSPSettlmentReport_Drill()
{
var html = new StringBuilder();
DataTable rpt;
string rptTest = "";
fieldFormat = "|||N|N|N|N|N|N";
fieldAlignment = "|||R|R|R|R|R|R";
totalText = "<b>Total</b>";
totalFields = "3|4|5|6|7|8|9";
rpt = reportResult.Result.Tables[0];
rptTest = GenerateReport(ref rpt).Replace("<td", "<td nowrap = \"nowrap\"");
html.AppendLine(rptTest);
rptDiv.InnerHtml = html.ToString();
}
private void GetRSPSettlmentReport()
{
var html = new StringBuilder();
DataTable rpt;
string rptTest = "";
for (int i = 0; i < reportResult.Result.Tables.Count - 3; i++)
{
if (i == 0)
{
tblCaption = "Summary Report";
fieldFormat = "|||N|N|N|N|N||N";
fieldAlignment = "|||R|R|R|R|R|R";
totalText = "<b>Total</b>";
totalFields = "3|4|5|6|7|8|9";
}
if (i == 1)
{
tblCaption = "Settlment Summary Report";
fieldFormat = "||N";
fieldAlignment = "|R|R";
totalText = "<b>Net Settlement</b>";
totalFields = "1|2";
}
rpt = reportResult.Result.Tables[i];
rptTest = GenerateReport(ref rpt).Replace("<td", "<td nowrap = \"nowrap\"");
html.AppendLine(rptTest);
}
rptDiv.InnerHtml = html.ToString();
}
private void GetRSPTxnSummaryReport(string reportType)
{
var html = new StringBuilder();
DataTable rpt;
string rptTest = "";
if (reportType == "BankWise")
{
fieldFormat = "||||N|N";
fieldAlignment = "|R|R|R|R|R";
subTotalBy = 0;
subTotalFields = "2|3|4|5";
subTotalText = "<b >Total</b>";
totalText = "<b>Grand Total</b>";
totalFields = "2|3|4|5";
}
else if (reportType == "ReceivingAgentWise")
{
fieldFormat = "||N|N|N||N";
fieldAlignment = "|R|R|R|R|R|R|R";
totalText = "<b>Total</b>";
totalFields = "1|2|3|4|6";
}
else if (reportType == "ReceivingAgentCountryWise")
{
fieldFormat = "||N|N|N||N|";
fieldAlignment = "|R|R|R|R|R|R|R";
totalText = "<b>Total</b>";
totalFields = "1|2|3|4|6";
}
else if (reportType == "ReceivingDateWise")
{
fieldFormat = "|||||N|N|N|N|N";
fieldAlignment = "|||||R|R|R|R|R|R|R|";
totalText = "<b>Total</b>";
totalFields = "6|7|8|9";
}
else if (reportType == "CashCollectionDetails")
{
fieldFormat = "||||||N|";
fieldAlignment = "||||C|C|R|";
totalText = "<b>Total</b>";
totalFields = "6";
}
else if (reportType == "bankCollectionDetail")
{
fieldFormat = "||||||N|";
fieldAlignment = "||||C|C|R|";
totalText = "<b>Total</b>";
totalFields = "6";
}
rpt = reportResult.Result.Tables[0];
rptTest = GenerateReport(ref rpt).Replace("<td", "<td nowrap = \"nowrap\"");
html.AppendLine(rptTest);
rptDiv.InnerHtml = html.ToString();
}
private void GetTxnBranchwiseReport()
{
var html = new StringBuilder();
DataTable rpt;
string rptTest = "";
fieldFormat = "||||||||||";
fieldAlignment = "||R|R|R|R|R|R|R|R";
totalText = "<b>Total</b>";
totalFields = "2|3|4|5|6|7|8|9";
for (int i = 0; i < reportResult.Result.Tables.Count - 3; i++)
{
if (i == 1)
tblCaption = "Cancel Transaction Detail";
rpt = reportResult.Result.Tables[i];
rptTest = GenerateReport(ref rpt).Replace("<td", "<td nowrap = \"nowrap\"");
html.AppendLine(rptTest);
}
rptDiv.InnerHtml = html.ToString();
}
private void GetRSPTxnDetailReport()
{
var html = new StringBuilder();
DataTable rpt;
string rptTest = "";
for (int i = 0; i < reportResult.Result.Tables.Count - 3; i++)
{
if (i == 0)
{
tblCaption = "Transaction Summary Report";
fieldFormat = "||";
fieldAlignment = "|R|R";
}
if (i == 1)
{
tblCaption = "Summary Report";
fieldFormat = "||||N|";
fieldAlignment = "|||R|R|R";
totalText = "<b>Total</b>";
totalFields = "3|4";
}
rpt = reportResult.Result.Tables[i];
rptTest = GenerateReport(ref rpt).Replace("<td", "<td nowrap = \"nowrap\"");
html.AppendLine(rptTest);
}
rptDiv.InnerHtml = html.ToString();
}
private ReportResult PrepareCancelReport()
{
fieldFormat = "|||||||N|N";
fieldAlignment = "|||||||R|R|";
totalText = "<b>Total</b>";
totalFields = "7";
string fromDate = GetStatic.ReadQueryString("fromDate", "");
string toDate = GetStatic.ReadQueryString("toDate", "");
string sBranch = GetStatic.ReadQueryString("branchId", "");
string pcountry = GetStatic.ReadQueryString("pcountry", "");
string cancelType = GetStatic.ReadQueryString("cancelType", "");
string pageNumber = GetStatic.ReadQueryString("pageNumber", "1");
string user = GetStatic.GetUser();
return (new TranAgentReportDao().GetCancelReport(user, pcountry, sBranch, fromDate, toDate, cancelType, pageNumber, GetStatic.GetReportPagesize()));
}
private ReportResult PrepareReport_40111600()
{
string pageNumber = GetStatic.ReadQueryString("pageNumber", "1");
string rptType = GetStatic.ReadQueryString("rptType", "");
string pCountry = GetStatic.ReadQueryString("pCountry", "");
string pAgent = GetStatic.ReadQueryString("pAgent", "");
string sBranch = GetStatic.ReadQueryString("sbranch", "");
string depositType = GetStatic.ReadQueryString("depositType", "");
string searchBy = GetStatic.ReadQueryString("searchBy", "");
string searchByValue = GetStatic.ReadQueryString("searchByValue", "");
string orderBy = GetStatic.ReadQueryString("orderBy", "");
string status = GetStatic.ReadQueryString("status", "");
string paymentType = GetStatic.ReadQueryString("paymentType", "");
string dateField = GetStatic.ReadQueryString("dateField", "");
string from = GetStatic.ReadQueryString("from", "");
string to = GetStatic.ReadQueryString("to", "");
string transType = GetStatic.ReadQueryString("transType", "");
string displayTranNo = GetStatic.ReadQueryString("displayTranNo", "");
useDBRowColorCode = true;
mergeColumnHead = true;
includeSerialNo = true;
subTotalText = "<b><i>Sub Total</i></b>";
totalTextCol = 3;
subTotalTextCol = 3;
subTotalFields = "8|10|12|14";
fieldFormat = "|||||||N||N||N||N|";
fieldAlignment = "|||||||R||R||R||R|";
totalFields = "7|9|11|13";
totalText = "<b>Grand Total</b>";
return (new TranAgentReportDao().Get_40111600_Report(GetStatic.GetUser(), pCountry, pAgent, sBranch, depositType, orderBy, status, paymentType, dateField, from, to, transType, displayTranNo, searchBy, searchByValue, pageNumber, GetStatic.GetReportPagesize(), rptType));
}
private ReportResult PrepareUserWiseReport()
{
mergeColumnHead = true;
fieldFormat = "|||||||||||N||N";
fieldAlignment = "|||||||R||R||R||R";
totalFields = "7|9|11";
totalText = "<b>Total</b>";
string branch = GetStatic.ReadQueryString("branch", "");
string userName = GetStatic.ReadQueryString("userName", "");
string fromDate = GetStatic.ReadQueryString("fromDate", "");
string toDate = GetStatic.ReadQueryString("toDate", "");
string reportType = GetStatic.ReadQueryString("type", "");
string rCountry = GetStatic.ReadQueryString("rCountry", "");
string pageNumber = GetStatic.ReadQueryString("pageNumber", "1");
return (new TranAgentReportDao().GetUserwiseReport(GetStatic.GetUser(), GetStatic.GetAgent(), branch, userName, fromDate, toDate,
reportType, rCountry, pageNumber, GetStatic.GetReportPagesize()));
}
private ReportResult PrepareReport_domestictxn()
{
string fromDate = GetStatic.ReadQueryString("fromDate", "");
string todate = GetStatic.ReadQueryString("todate", "");
string agentId = GetStatic.ReadQueryString("agentId", "");
string DateType = GetStatic.ReadQueryString("DateType", "");
string payment_status = GetStatic.ReadQueryString("payment_status", "");
string type = GetStatic.ReadQueryString("type", "");
string user = GetStatic.GetUser();
includeSerialNo = true;
fieldFormat = "||||N|N||||";
fieldAlignment = "||||R|R||||";
return (new AccountReportDao().GetDomesticTxnReport(user, agentId, fromDate, todate, DateType, payment_status, type));
}
private int GetPageNumber()
{
return
Convert.ToInt32(GetStatic.ReadNumericDataFromQueryString("pageNumber") == 0
? 1
: GetStatic.ReadNumericDataFromQueryString("pageNumber"));
}
#endregion
#region Generate Report
public String GenerateReport(ref DataTable dt)
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-us");
var ExcludeFieldList = new ArrayList();
foreach (var col in excludeColumns.Split('|'))
{
ExcludeFieldList.Add(col.ToLower());
}
ExcludeFieldList.Add("rowcolor");
var html = new StringBuilder("");
html.AppendLine("<div style = \"clear:both;margin-top:20px;\">");
html.AppendLine("<table class=\"table table-responsive table-bordered table-striped\" ");
if (tblCaption != "")
html.AppendLine("<tr><td style='td' colspan=\"" + (dt.Columns.Count + extraCol).ToString() +
"\">" + tblCaption + "</td></tr>");
html.AppendLine(CreateReportHead(ref dt, mergeColumnHead, ref ExcludeFieldList));
html.AppendLine(CreateReportBody(ref dt, subTotalFields, totalFields, ref ExcludeFieldList, totalTextCol,
subTotalTextCol));
html.AppendLine("<tr><td style='td' colspan=\"" + (dt.Columns.Count + extraCol) + "\" align=\"center\">");
if (totalPage == 0)
totalPage = 1;
html.AppendLine("Page " + (GetPageNumber() == 0 ? 1 : GetPageNumber()) + " of " + totalPage +
"");
html.AppendLine("</td></tr>");
html.AppendLine("</table>");
html.AppendLine("</div>");
return html.ToString();
}
private int SerialNo = 0;
private String CreateReportBody(ref DataTable dt, string subTotalFieldList, string totalFieldList,
ref ArrayList ExcludeFieldList, int totalTextCol, int subTotalTextCol)
{
int cnt = 0;
var body = new StringBuilder("");
var SerialNoColumnValue = "";
bool doSubTotal = subTotalBy > -1 ? true : false;
bool doTotal = totalFieldList != "" ? true : false;
string[] totalFieldsArray = totalFieldList.Replace(" ", "").Split('|');
var totalValues = new double[totalFieldsArray.Length];
string[] subTotalFieldsArray = subTotalFieldList.Replace(" ", "").Split('|');
var subTotalValues = new double[subTotalFieldsArray.Length];
string[] fieldFormatList = fieldFormat.Replace(" ", "").Split('|');
string tmpSubTotalText = "||";
var hasRowColorCol = dt.Columns.Contains("rowColor");
foreach (DataRow row in dt.Rows)
{
if (includeSerialNo)
{
SerialNo++;
SerialNoColumnValue = "<td style='td' align=\"right\">" + SerialNo.ToString() + "</td>";
}
else
{
SerialNoColumnValue = "";
}
if (doSubTotal)
{
if (tmpSubTotalText == "||")
tmpSubTotalText = row[subTotalBy].ToString();
if (tmpSubTotalText != row[subTotalBy].ToString())
{
body.AppendLine(CreateTotalRow(ref dt, subTotalText, subTotalBy, subTotalFieldsArray,
subTotalValues, fieldFormatList, fieldAlignment, fieldWrap,
ref ExcludeFieldList, subTotalTextCol, includeSerialNo));
tmpSubTotalText = row[subTotalBy].ToString();
for (int i = 0; i < subTotalValues.Length; i++)
{
subTotalValues[i] = 0;
}
}
}
if (useDBRowColorCode && hasRowColorCol)
{
body.AppendLine("<tr style=\"background:" + row["rowColor"].ToString() + ";\">");
}
else
{
body.AppendLine(++cnt % 2 == 1 ? "<tr>" : "<tr style=\"background: #F0F0F0;\">");
}
body.AppendLine(SerialNoColumnValue);
for (int i = 0; i < dt.Columns.Count; i++)
{
if (ExcludeFieldList.IndexOf(dt.Columns[i].ColumnName.ToLower()) > -1)
{
continue;
}
string format = GetFormat(fieldFormatList, i);
string data = row[i].ToString();
if (format != "")
{
double dataParse;
double.TryParse(row[i].ToString(), out dataParse);
data = dataParse < 0 ? GetStatic.ParseMinusValue(dataParse) : dataParse.ToString(format);
//Parse Minus Value
}
if (AllowDrillDown)
{
data = CreateLink(data);
}
string alignment = GetAlignment(fieldAlignment, i);
string noWrapProperty = GetNoWrapping(fieldWrap, i);
body.AppendLine("<td style='td' " + alignment + noWrapProperty + ">" + data + "</td>");
var data2 = row[i].ToString();
if (doTotal)
{
int pos = Array.IndexOf(totalFieldsArray, i.ToString());
if (pos >= 0)
{
if (data2.IndexOf('<') > -1)
{
data2 = GetStatic.RemoveAllTags(data2);
}
double value;
double.TryParse(data2, out value);
totalValues[pos] = totalValues[pos] + value;
}
}
if (doSubTotal)
{
int pos = Array.IndexOf(subTotalFieldsArray, i.ToString());
if (pos >= 0)
{
if (data2.IndexOf('<') > -1)
{
data2 = GetStatic.RemoveAllTags(data2);
}
double value;
double.TryParse(data2, out value);
subTotalValues[pos] = subTotalValues[pos] + value;
}
}
}
body.AppendLine("</tr>");
}
if (doSubTotal)
{
body.AppendLine(CreateTotalRow(ref dt, subTotalText, subTotalBy, subTotalFieldsArray, subTotalValues,
fieldFormatList, fieldAlignment, fieldWrap, ref ExcludeFieldList,
totalTextCol, includeSerialNo));
}
if (doTotal)
{
if (grandTotal != 0.00)
{
if (totalPage == GetPageNumber())
body.AppendLine(CreatGrandTotalRow(ref dt, totalText, 0, totalFieldsArray, grandTotal,
fieldFormatList,
fieldAlignment, fieldWrap, grandTotal, grandTotalUsd,
grandTotal_1, ref ExcludeFieldList, includeSerialNo));
}
else
{
body.AppendLine(CreateTotalRow(ref dt, totalText, 0, totalFieldsArray, totalValues, fieldFormatList,
fieldAlignment, fieldWrap, ref ExcludeFieldList, totalTextCol, includeSerialNo));
}
}
return body.ToString();
}
private static String CreateTotalRow(ref DataTable dt, string totalText, int totalFieldIndex,
string[] totalFields, Double[] totalValues, string[] fieldFormatList,
string fieldAlignmentList, string fieldWrapList,
ref ArrayList ExcludeFieldList, int totalTextCol, bool includeSerialNo)
{
var rowText = new StringBuilder("");
rowText.AppendLine("<tr>");
if (includeSerialNo)
{
if (totalText.IndexOf("<td>") == -1)
rowText.AppendLine("<td></td>");
}
for (int i = 0; i < dt.Columns.Count; i++)
{
if (ExcludeFieldList.IndexOf(dt.Columns[i].ColumnName.ToLower()) > -1)
{
continue;
}
int pos = Array.IndexOf(totalFields, i.ToString());
string data = "";
string alignment = "";
string nowrapProperty = "";
if (pos >= 0)
{
string format = GetFormat(fieldFormatList, i);
data = totalValues[pos] < 0
? GetStatic.ParseMinusValue(totalValues[pos])
: totalValues[pos].ToString(format.ToUpper());
alignment = GetAlignment(fieldAlignmentList, i);
nowrapProperty = GetNoWrapping(fieldWrapList, i);
}
if (totalTextCol > -1)
{
totalFieldIndex = totalTextCol;
}
if (i == totalFieldIndex) data = totalText;
rowText.AppendLine("<td style='td' " + alignment + nowrapProperty + ">" + data + "</td>");
}
rowText.AppendLine("</tr>");
return rowText.ToString();
}
private static String CreatGrandTotalRow(ref DataTable dt, string totalText, int totalFieldIndex,
string[] totalFields, Double totalValues, string[] fieldFormatList,
string fieldAlignmentList, string fieldWrapList, Double grandTotal,
Double grandTotalUsd, Double grandTotal_1,
ref ArrayList ExcludeFieldList, bool includeSerialNo)
{
var rowText = new StringBuilder("");
rowText.AppendLine("<tr>");
if (includeSerialNo)
{
if (totalText.IndexOf("<td>") == -1)
rowText.AppendLine("<td></td>");
}
for (int i = 0; i < dt.Columns.Count; i++)
{
if (ExcludeFieldList.IndexOf(dt.Columns[i].ColumnName.ToLower()) > -1)
{
continue;
}
int pos = Array.IndexOf(totalFields, i.ToString());
string data = "";
string alignment = "";
string nowrapProperty = "";
if (pos >= 0)
{
data = GetStatic.ParseMinusValue(grandTotal.ToString());
alignment = GetAlignment(fieldAlignmentList, i);
nowrapProperty = GetNoWrapping(fieldWrapList, i);
}
if (i == totalFieldIndex)
data = totalText;
if (i == 9 && grandTotal != 0.00)
{
rowText.AppendLine("<td style='td' align=\"right\">" + GetStatic.ParseMinusValue(grandTotal) +
"</td>");
}
else if (i == 11 && grandTotalUsd != 0.00)
{
rowText.AppendLine("<td style='td' align=\"right\">" + GetStatic.ParseMinusValue(grandTotalUsd) +
"</td>");
}
else if (i == 13 && grandTotal_1 != 0.00)
{
rowText.AppendLine("<td style='td' align=\"right\">" + GetStatic.ParseMinusValue(grandTotal_1) +
"</td>");
}
else
{
rowText.AppendLine("<td style='td' " + alignment + nowrapProperty + ">" + data + "</td>");
}
}
rowText.AppendLine("</tr>");
return rowText.ToString();
}
private static string GetFormat(string[] fieldFormatList, int currFieldIndex)
{
return fieldFormatList.Length > currFieldIndex ? fieldFormatList[currFieldIndex] : "";
//return ( pos == -1 ? "": fieldFormatList[pos]);
}
private static string GetNoWrapping(string fieldWrapList, int currFieldIndex)
{
if (fieldWrapList == "")
return "";
string[] wrapListArray = fieldWrapList.Split('|');
string isWrap = wrapListArray.Length > currFieldIndex ? wrapListArray[currFieldIndex] : "";
string noWrapValue = "";
if (isWrap == "Y")
noWrapValue = " nowrap = \"nowrap\"";
return noWrapValue;
}
private static string GetAlignment(string fieldAlignmentList, int currFieldIndex)
{
if (fieldAlignmentList == "")
return "";
string[] alignListArray = fieldAlignmentList.Split('|');
string alignName = alignListArray.Length > currFieldIndex ? alignListArray[currFieldIndex] : "";
string align = "";
switch (alignName.ToUpper())
{
case "R":
align = " align=\"right\"";
break;
case "L":
align = " align=\"left\"";
break;
case "C":
align = " align=\"center\"";
break;
default:
break;
}
return align;
}
private static string CreateLink(string data)
{
return "";
}
private String CreateReportHead(ref DataTable dt, Boolean merge, ref ArrayList ExcludeFieldList)
{
var head = new StringBuilder("");
var SerialNoColumnHead = "";
if (includeSerialNo)
{
SerialNoColumnHead = "<th style='th'>SN.</th>";
extraCol = 1;
}
if (!merge)
{
head.AppendLine("<tr>");
head.AppendLine(SerialNoColumnHead);
foreach (DataColumn col in dt.Columns)
{
if (ExcludeFieldList.IndexOf(col.ColumnName.ToLower()) > -1)
{
extraCol--;
continue;
}
head.AppendLine("<th style='th'>" + col.ColumnName + "</th>");
}
head.AppendLine("</tr>");
}
else
{
var columns = new Dictionary<string, string>();
foreach (DataColumn col in dt.Columns)
{
if (ExcludeFieldList.IndexOf(col.ColumnName.ToLower()) > -1)
{
extraCol--;
continue;
}
var splitPos = col.ColumnName.IndexOf('_');
if (splitPos == -1)
{
columns.Add(col.ColumnName, col.ColumnName);
}
else
{
var key = col.ColumnName.Substring(0, splitPos);
var value = col.ColumnName.Substring(splitPos + 1, col.ColumnName.Length - splitPos - 1);
if (!columns.ContainsKey(key))
{
columns.Add(key, value);
}
else
{
columns[key] = columns[key] + "|" + value;
}
}
}
var row1 = "";
var row2 = "";
foreach (var kvp in columns)
{
string[] values = kvp.Value.Split('|');
if (values.Length == 1)
{
row1 = row1 + "<th style='th' rowspan=\"2\">" + kvp.Key + "</th>";
}
else
{
row1 = row1 + "<th style='th' align=\"center\" colspan=\"" + values.Length + "\">" + kvp.Key +
"</th>";
foreach (string value in values)
{
row2 = row2 + "<th style='th'>" + value + "</th>";
}
}
}
if (includeSerialNo)
{
SerialNoColumnHead = "<th style='th' rowspan=\"2\">SN.</th>";
}
head.AppendLine("<tr>" + SerialNoColumnHead + row1 + "</tr>");
head.AppendLine("<tr>" + row2 + "</tr>");
}
return head.ToString();
}
#endregion
private void PrintUserMatrixReport()
{
const string pStart = "<p style=\"page-break-after: always\">";
const string pEnd = "</p>";
var html = new StringBuilder();
cssClass = "TBLReportMatrix table table-bordered table-condensed table-striped";
int employeeTable = 0;
foreach (DataRow dr in reportResult.Result.Tables[0].Rows)
{
string name = dr["Name"].ToString();
string department = dr["department"].ToString();
string branch = dr["branch"].ToString();
string supervisor = dr["supervisor"].ToString();
DataTable rptDt = reportResult.Result.Tables[++employeeTable];
string reportText = GenerateReport(ref rptDt).Replace("<td", "<td nowrap = \"nowrap\"");
html.AppendLine(pStart);
html.AppendLine("<div class = \"welcome-div\">");
html.AppendLine("User Name: " + name + "");
html.AppendLine("<br />");
//html.AppendLine("Department: " + department + "");
//html.AppendLine("<br />");
html.AppendLine("Agent/Branch Name: " + branch + "");
//html.AppendLine("<br />");
//html.AppendLine("Supervisor: " + supervisor + "");
html.AppendLine("</div>");
html.AppendLine(reportText);
html.AppendLine(pEnd);
}
rptDiv.InnerHtml = html.ToString();
head.Visible = false;
filters.Visible = false;
//hr1.Visible = false;
//hr2.Visible = false;
export.Visible = false;
}
private ColDefinatoin GetColumnNameToIndex(DataTable dt, string totalFieldNameList, string subTotalFieldNameList)
{
var r = new ColDefinatoin();
var fList = new ArrayList();
r.Alignment = "";
r.Format = " ";
r.SubTotalFields = " ";
r.TotalFields = " ";
for (var i = 0; i < dt.Columns.Count; i++)
{
var cp = new ColProperties(i);
fList.Add(cp);
}
var cList = totalFieldNameList.Split('|');
foreach (var colName in cList)
{
var pos = dt.Columns.IndexOf(colName);
if (pos >= 0)
{
var cp = (ColProperties)fList[pos];
cp.IsTotal = true;
fList[pos] = cp;
}
}
foreach (var colName in cList)
{
var pos = dt.Columns.IndexOf(colName);
pos = pos - 1;
if (pos >= 0)
{
var cp = (ColProperties)fList[pos];
cp.IsNumeric = true;
fList[pos] = cp;
}
}
cList = subTotalFieldNameList.Split('|');
foreach (var colName in cList)
{
var pos = dt.Columns.IndexOf(colName);
if (pos >= 0)
{
var cp = (ColProperties)fList[pos];
cp.IsSubTotal = true;
fList[pos] = cp;
}
}
foreach (ColProperties itm in fList)
{
r.Alignment = r.Alignment + (r.Alignment.Length > 0 ? "|" : "") +
((itm.IsSubTotal || itm.IsTotal) ? "R" : "L");
r.Format = r.Format + (r.Format.Length > 0 ? "|" : "") + ((itm.IsNumeric) ? "N" : "");
r.SubTotalFields = r.SubTotalFields + (r.SubTotalFields.Length > 0 ? "|" : "") +
(itm.IsSubTotal ? itm.Index.ToString() : "");
r.TotalFields = r.TotalFields + (r.TotalFields.Length > 0 ? "|" : "") +
(itm.IsTotal ? itm.Index.ToString() : "");
}
return r;
}
public class ColDefinatoin
{
public string TotalFields { get; set; }
public string SubTotalFields { get; set; }
public string Alignment { get; set; }
public string Format { get; set; }
}
public class ColProperties
{
public int Index { get; set; }
public bool IsTotal { get; set; }
public bool IsNumeric { get; set; }
public bool IsSubTotal { get; set; }
public ColProperties()
{
}
public ColProperties(int index)
{
Index = index;
IsTotal = false;
IsSubTotal = false;
IsNumeric = false;
}
}
}
}