Hi friends ,here i am showing the entire my page code,so please see bold code for displaying nested grids.
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="AllReports.ascx.cs" Inherits="UCs_AllReports" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<%@ Register Src="~/UCs/NewCustomMessage.ascx" TagName="NewCustomMessage" TagPrefix="uc1" %>
<link href="../App_Themes/Blue/blue_site.css" rel="stylesheet" type="text/css" />
<link href="../App_Themes/Blue/StyleSheet.css" rel="stylesheet" type="text/css" />
<label id="Lable1" runat="server" style="font-family: Tahoma; font-size: 11px; font-weight: 900;">
From Date <span style="color: Red; font-weight: lighter">*</span></label>
<asp:DropDownList ID="ddlMonth1" runat="server" ValidationGroup="report" AppendDataBoundItems="True"
CausesValidation="True" Style="width: auto;">
<asp:RequiredFieldValidator ID="rfvMon1" runat="server" ControlToValidate="ddlMonth1"
Display="None" ErrorMessage="Please Select Month" ValidationGroup="report" InitialValue="Month"></asp:RequiredFieldValidator>
<cc1:ValidatorCalloutExtender ID="rfvMon1_ValidatorCalloutExtender" runat="server"
Enabled="True" HighlightCssClass="validatorCalloutHighlight" TargetControlID="rfvMon1">
<asp:DropDownList ID="ddlYear1" runat="server" ValidationGroup="report" AppendDataBoundItems="True"
CausesValidation="True" Style="width: auto;">
<asp:ListItem>Year</asp:ListItem>
<asp:RequiredFieldValidator ID="rfvddlYear1" runat="server" ControlToValidate="ddlYear1"
Display="None" ErrorMessage="Please Select Year" ValidationGroup="report" InitialValue="Year"></asp:RequiredFieldValidator>
<cc1:ValidatorCalloutExtender ID="rfvddlYear1_ValidatorCalloutExtender1" runat="server"
Enabled="True" HighlightCssClass="validatorCalloutHighlight" TargetControlID="rfvddlYear1">
<label id="LAble2" runat="server" style="font-family: Tahoma; font-size: 11px; font-weight: 900;">
To Date <span style="color: Red; font-weight: lighter">*</span></label>
<asp:DropDownList ID="ddlMonth2" runat="server" ValidationGroup="report" Style="width: auto;"
AppendDataBoundItems="True" CausesValidation="True">
<asp:RequiredFieldValidator ID="rfvddlMonth2" runat="server" ControlToValidate="ddlMonth2"
Display="None" ErrorMessage="Please Select Month" ValidationGroup="report" InitialValue="Month"></asp:RequiredFieldValidator>
<cc1:ValidatorCalloutExtender ID="rfvddlMonth2_ValidatorCalloutExtender1" runat="server"
Enabled="True" HighlightCssClass="validatorCalloutHighlight" TargetControlID="rfvddlMonth2">
<asp:DropDownList ID="ddlYear2" runat="server" ValidationGroup="report" Width="73px"
Height="16px" AppendDataBoundItems="True" CausesValidation="True" Style="width: auto;">
<asp:ListItem>Year</asp:ListItem>
<asp:RequiredFieldValidator ID="rfvddlYear2" runat="server" ControlToValidate="ddlYear2"
Display="None" ErrorMessage="Please Select Year" ValidationGroup="report" InitialValue="Year"></asp:RequiredFieldValidator>
<cc1:ValidatorCalloutExtender ID="rfvddlYear2_ValidatorCalloutExtender2" runat="server"
Enabled="True" HighlightCssClass="validatorCalloutHighlight" TargetControlID="rfvddlYear2">
<asp:Button ID="btnShowReport" runat="server" OnClick="btnShowReport_Click" Text="Show Report"
ValidationGroup="report" Style="text-align: center" />
<%-- <table align="center" cellspacing="40px" width="800px">
<asp:Menu ID="Menu1" runat="server" Orientation="Horizontal" OnMenuItemClick="Menu1_MenuItemClick"
Visible="false" Font-Size="Medium" BackColor="#5C75A9">
<asp:MenuItem Text="District Wise" Value="0"></asp:MenuItem>
<%-- <asp:MenuItem Text="Graph" Value="1"></asp:MenuItem>
<td style="font-size: 15px; text-align: center">
<asp:Label ID="lblHeaderText" runat="server" />
<%-- <asp:MultiView ID="MultiView1" runat="server" Visible="false" ActiveViewIndex="0">--%>
<%-- <asp:View ID="Tab1" runat="server">--%>
<asp:UpdatePanel runat="server" UpdateMode="Conditional" ID="UpdatePanel11">
<%-- <asp:Panel ID="pnl1" runat="server">--%>
<%-- </asp:Panel>--%>
<%-- <asp:View ID="Tab2" runat="server">--%>
<%--<asp:UpdatePanel runat="server" UpdateMode="Conditional" ID="ParentPanel">
<ContentTemplate>
<asp:Panel ID="pnl2" runat="server">
<asp:GridView ID="grdServiceWiseReport" runat="server" DataKeyNames="Service Id"
AutoGenerateColumns="false" BorderColor="WhiteSmoke" BorderStyle="Groove" BorderWidth="2px"
Width="800px" GridLines="None" AllowPaging="true" PageSize="10" OnRowCommand="grdServiceWiseReport_RowCommand"
OnRowDataBound="grdServiceWiseReport_RowDataBound">
<Columns>
<asp:TemplateField ItemStyle-Width="9">
<ItemTemplate>
<asp:ImageButton ID="ImgBtn1" ImageUrl="~/Images/viewIcon1.png" CommandName="Expand1"
ToolTip="View Service Details" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Service Name" HeaderText="Service" />
<asp:BoundField DataField="Total Transactions" HeaderText="Total Transactions" />
<asp:BoundField DataField="Total Amount" HeaderText="Total Amount" />
<asp:TemplateField>
<ItemTemplate>
<asp:PlaceHolder ID="phServiceDetails" runat="server" Visible="false">
<tr>
<td width="9">
</td>
<td colspan="6">
<asp:UpdatePanel runat="server" ID="ChildControl" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="grdServiceDetails" GridLines="None" AutoGenerateColumns="false"
runat="server" AllowPaging="true" PageSize="5" Width="775px" BorderWidth="1"
DataKeyNames="Service Id" OnRowCommand="grdServiceDetails_RowCommand" OnPageIndexChanging="grdServiceDetails_PageIndexChanging"
ShowFooter="true" BorderColor="#27415C">
<Columns>
<asp:BoundField DataField="Center Name" HeaderText="Center Name" />
<asp:BoundField DataField="No Of Transactions" HeaderText="Transactions" />
<asp:BoundField DataField="Amount" HeaderText="Amount" />
<asp:BoundField DataField="Last Update" HeaderText="Last Update" />
<asp:BoundField DataField="Updated By" HeaderText="Updated By" />
<asp:TemplateField>
<FooterTemplate>
<asp:ImageButton ID="imgExportPDF1" ImageUrl="~/Images/File_Pdf_11.png" runat="server"
CommandName="PDFCreation1" Width="30px" />
<asp:ImageButton ID="imgExportExcel1" ImageUrl="~/Images/Excel-icon.png" Width="20px"
runat="server" CommandName="ExcelCreation1" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
<PagerSettings Position="TopAndBottom" />
<PagerStyle CssClass="ob_paging" />
<HeaderStyle CssClass="ob_gH" />
<SelectedRowStyle CssClass="ob_gRS" />
<RowStyle CssClass="ob_gR" />
<AlternatingRowStyle CssClass="ob_gRA" />
<FooterStyle CssClass="ob_footer" />
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="grdServiceDetails" />
</Triggers>
</asp:UpdatePanel>
</asp:PlaceHolder>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerSettings Position="TopAndBottom" />
<PagerStyle CssClass="ob_paging" />
<HeaderStyle CssClass="ob_gH" />
<SelectedRowStyle CssClass="ob_gRS" />
<RowStyle CssClass="ob_gR" />
<AlternatingRowStyle CssClass="ob_gRA" />
<FooterStyle CssClass="ob_footer" />
</asp:GridView>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>--%>
<%--<asp:Panel ID="pnlReports" runat="server" Visible="false">--%>
<uc3:PDFExport ID="PDFExport1" runat="server" EnableViewState="false" />
<uc1:ExcelExport ID="ExcelExport1" runat="server" EnableViewState="false" />
<%-- <input id="PrintReport" type="image" src="../Images/printer.png" onclick="return PrintReport_onclick()" />--%>
-------------------------------------------------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Globalization;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.Configuration;
using System.Drawing;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
using System.IO;
using System.Net;
public partial class UCs_AllReports : System.Web.UI.UserControl
{
DataAccess da = new DataAccess();
DataSet ds;
DataSet dsServiceWise;
string TitleText = "";
DateTimeFormatInfo format = new DateTimeFormatInfo();
MonthYear my = new MonthYear();
public void Export(string fileName, DataTable ds)
{
string FileName = fileName + ".pdf";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("content-disposition", string.Format("attachment;filename=\"" + FileName + "\""));
HttpContext.Current.Response.ContentType = "application/octet-stream";
// step 1: creation of a document-object
Document document = new Document();
PdfWriter writer = PdfWriter.GetInstance(document, Response.OutputStream);
document.Open();
TitleText = fileName + " From " + ddlMonth1.SelectedItem + "-" + ddlYear1.Text + " To " + ddlMonth2.SelectedItem + "-" + ddlYear2.Text + "";
if (ds.Rows.Count != 0)
{
//For the Header
PdfPTable pdfTable1 = new PdfPTable(2);
pdfTable1.WidthPercentage = 100; // percentage
pdfTable1.DefaultCell.BorderColor = (new iTextSharp.text.Color(System.Drawing.Color.White));
pdfTable1.DefaultCell.BorderWidth = 0;
pdfTable1.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
PdfPCell header = new PdfPCell(new Phrase(DateTime.Now.ToLongDateString(), FontFactory.GetFont("Arial", 7, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.GRAY)));
header.Border = 0;
header.Colspan = 2;
header.HorizontalAlignment = Element.ALIGN_RIGHT;
PdfPCell header1 = new PdfPCell(new Phrase(TitleText, FontFactory.GetFont("Arial", 10, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.WHITE)));
header1.BackgroundColor = iTextSharp.text.Color.DARK_GRAY;
header1.Padding = 5;
header1.Colspan = 2;
header1.HorizontalAlignment = Element.ALIGN_LEFT;
pdfTable1.AddCell(header);
pdfTable1.AddCell(header1);
//For the data of consumption
PdfPTable pdfTable = new PdfPTable(ds.Columns.Count);
pdfTable.DefaultCell.Padding = 1;
pdfTable.WidthPercentage = 100; // percentage
pdfTable.DefaultCell.BorderWidth = 0.5f;
pdfTable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
pdfTable.DefaultCell.VerticalAlignment = Element.ALIGN_MIDDLE;
for (int i = 0; i < ds.Columns.Count; i++)
{
PdfPCell comcol = new PdfPCell(new Phrase(ds.Columns[i].ColumnName, FontFactory.GetFont("Arial", 6, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK)));
comcol.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY;
comcol.HorizontalAlignment = Element.ALIGN_CENTER;
pdfTable.AddCell(comcol);
// pdfTable.AddCell(new Phrase(ds1.Tables[table].Columns[i].ColumnName, FontFactory.GetFont("Arial", 6, iTextSharp.text.Font.BOLD)));
}
for (int row = 0; row < ds.Rows.Count; row++)
{
for (int column = 0; column < ds.Columns.Count; column++)
{
pdfTable.AddCell(new Phrase(ds.Rows[row][column].ToString(), FontFactory.GetFont("Arial", 6, iTextSharp.text.Font.NORMAL)));
}
}
document.Add(pdfTable1);
document.Add(pdfTable);
}
document.Close();
}
private void Export1(string fileName, DataTable dt)
{
string FileName = fileName + ".xls";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("content-disposition", string.Format("attachment;filename=\"" + FileName + "\""));
HttpContext.Current.Response.ContentType = "application/vnd.xls";
TitleText = fileName + " From " + ddlMonth1.SelectedItem + "-" + ddlYear1.Text + " To " + ddlMonth2.SelectedItem + "-" + ddlYear2.Text + "";
using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter htw = new HtmlTextWriter(sw))
{
// Create a table to contain the grid
System.Web.UI.WebControls.Table table = new System.Web.UI.WebControls.Table();
TableRow trHeading = new TableRow();
TableCell tdCaption = new TableCell();
tdCaption.RowSpan = 2;
tdCaption.ColumnSpan = 2 * dt.Columns.Count;
tdCaption.Font.Bold = true;
tdCaption.Font.Size = 16;
tdCaption.HorizontalAlign = HorizontalAlign.Center;
tdCaption.VerticalAlign = VerticalAlign.Middle;
Label lblText = new Label();
lblText.Text = "<h3>" + TitleText + "</h3>";
tdCaption.Controls.Add(lblText);
tdCaption.Attributes.Add("style", "color:blue");
// tdCaption.BackColor = System.Drawing.Color.Gray;
// tdCaption.ForeColor = System.Drawing.Color.White;
trHeading.Cells.Add(tdCaption);
trHeading.BorderWidth = 0;
table.Rows.Add(trHeading);
TableRow trspace = new TableRow();
TableCell tdspace = new TableCell();
tdspace.HorizontalAlign = HorizontalAlign.Center;
tdspace.VerticalAlign = VerticalAlign.Middle;
table.Rows.Add(trspace);
// include the gridline settings
table.GridLines = GridLines.Both;
// add the header row to the table
TableRow headerRow = new TableRow();
for (int i = 0; i < dt.Columns.Count; i++)
{
TableHeaderCell headerCell = new TableHeaderCell();
headerCell.ColumnSpan = 2;
headerCell.Font.Bold = true;
headerCell.Font.Size = 12;
headerCell.HorizontalAlign = HorizontalAlign.Center;
headerCell.VerticalAlign = VerticalAlign.Middle;
headerCell.Text = dt.Columns[i].ColumnName;
headerRow.Cells.Add(headerCell);
}
table.Rows.Add(headerRow);
// add each of the data rows to the table
foreach (DataRow dr in dt.Rows)
{
TableRow tr = new TableRow();
for (int i = 0; i < dt.Columns.Count; i++)
{
TableCell td = new TableCell();
td.HorizontalAlign = HorizontalAlign.Center;
td.VerticalAlign = VerticalAlign.Middle;
td.ColumnSpan = 2;
td.Text = Convert.ToString(dr[i]);
tr.Cells.Add(td);
}
table.Rows.Add(tr);
}
// render the table into the htmlwriter
table.RenderControl(htw);
// render the htmlwriter into the response
HttpContext.Current.Response.Write(sw.ToString());
HttpContext.Current.Response.End();
}
}
}
private static void PrepareControlForExport(Control control)
{
for (int i = 0; i < control.Controls.Count; i++)
{
Control current = control.Controls[i];
if (current is LinkButton)
{
control.Controls.Remove(current);
control.Controls.AddAt(i, new LiteralControl((current as LinkButton).Text));
}
else if (current is ImageButton)
{
control.Controls.Remove(current);
control.Controls.AddAt(i, new LiteralControl((current as ImageButton).AlternateText));
}
else if (current is HyperLink)
{
control.Controls.Remove(current);
control.Controls.AddAt(i, new LiteralControl((current as HyperLink).Text));
}
else if (current is DropDownList)
{
control.Controls.Remove(current);
control.Controls.AddAt(i, new LiteralControl((current as DropDownList).SelectedItem.Text));
}
else if (current is CheckBox)
{
control.Controls.Remove(current);
control.Controls.AddAt(i, new LiteralControl((current as CheckBox).Checked ? "True" : "False"));
}
if (current.HasControls())
{
PrepareControlForExport(current);
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadMonthYear();
}
//else
//{
// ddlMonth1.SelectedIndex = -1;
// ddlYear1.SelectedIndex = -1;
// ddlMonth2.SelectedIndex = -1;
// ddlYear2.SelectedIndex = -1;
//}
}
protected void LoadMonthYear()
{
ds = my.GetMonthYears();
ddlMonth1.Items.Clear();
ddlMonth1.Items.Add("Month");
string months = ConfigurationManager.AppSettings["Month"];
string[] month = months.Split(',');
int i = 1;
foreach (var item in month)
{
System.Web.UI.WebControls.ListItem lt = new System.Web.UI.WebControls.ListItem(item, Convert.ToString(i));
ddlMonth1.Items.Add(lt);
i++;
}
ddlYear1.DataSource = ds;
ddlYear1.DataTextField = "year";
ddlYear1.SelectedIndex = -1;
ddlYear1.DataBind();
ddlMonth2.Items.Clear();
ddlMonth2.Items.Add("Month");
string months2 = ConfigurationManager.AppSettings["Month"];
string[] month2 = months2.Split(',');
int j = 1;
foreach (var item1 in month2)
{
System.Web.UI.WebControls.ListItem lt1 = new System.Web.UI.WebControls.ListItem(item1, Convert.ToString(j));
ddlMonth2.Items.Add(lt1);
j++;
}
ddlYear2.DataSource = ds;
ddlYear2.DataTextField = "year";
ddlYear2.SelectedIndex = -1;
ddlYear2.DataBind();
}
protected void btnShowReport_Click(object sender, EventArgs e)
{
ViewState["flag"] = null;
try
{
if (Convert.ToInt32(ddlYear1.Text) > Convert.ToInt32(ddlYear2.Text))
{
ViewState["flag"] = 1;
CustomMessage1.Alert("From Year should not grater than the to year");
pnlmain.Visible = false;
//MultiView1.Visible = false;
//Menu1.Visible = false;
//pnlReports.Visible = false;
}
else if ((Convert.ToInt32(ddlYear1.Text) == Convert.ToInt32(ddlYear2.Text)) && (Convert.ToInt32(ddlMonth1.Text) > Convert.ToInt32(ddlMonth2.Text)))
{
ViewState["flag"] = 2;
CustomMessage1.Alert("From month should not grater than the to month");
pnlmain.Visible = false;
//MultiView1.Visible = false;
//Menu1.Visible = false;
//pnlReports.Visible = false;
}
else if (ViewState["flag"] == null)
{
ds = da.GetDistrictWiseReports(Convert.ToInt32(ddlMonth1.Text), Convert.ToInt32(ddlYear1.Text), Convert.ToInt32(ddlMonth2.Text), Convert.ToInt32(ddlYear2.Text));
DataTable dt = new DataTable();
dt.Columns.Add("District Name");
dt.Columns.Add("Total Transactions");
dt.Columns.Add("Income");
dt.Columns.Add("Amount Collected");
dt.Columns.Add("Expenditure");
dt.Columns.Add("Revenue");
dt.Columns.Add("District No");
ds.Tables.Add(dt);
DataRow dr = null;
if (ds.Tables[0].Rows.Count == ds.Tables[1].Rows.Count)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
int distno1 = Convert.ToInt32(ds.Tables[0].Rows[i]["District No1"].ToString());
string distName1 = ds.Tables[0].Rows[i]["District Name1"].ToString();
int TotalTransactions1 = Convert.ToInt32(ds.Tables[0].Rows[i]["Total Transactions1"].ToString());
double Income1 = Convert.ToDouble(ds.Tables[0].Rows[i]["Income1"].ToString());
double totalAmount1 = Convert.ToDouble(ds.Tables[0].Rows[i]["Amount Collected1"].ToString());
double expenditure1 = Convert.ToDouble(ds.Tables[1].Rows[i]["Expenditure1"].ToString());
double revenue1 = Income1 - expenditure1;
dr = dt.NewRow();
dr["District Name"] = distName1;
dr["Total Transactions"] = TotalTransactions1;
dr["Income"] = string.Format("{0:0.####}", Income1);
dr["Amount Collected"] = string.Format("{0:0.####}", totalAmount1);
dr["Expenditure"] = string.Format("{0:0.####}", expenditure1);
dr["Revenue"] = string.Format("{0:0.####}", revenue1);
dr["District No"] = distno1;
dt.Rows.Add(dr);
}
/*dsServiceWise = da.GetServiceWiseReports(Convert.ToInt32(ddlMonth1.Text), Convert.ToInt32(ddlYear1.Text), Convert.ToInt32(ddlMonth2.Text), Convert.ToInt32(ddlYear2.Text));*/
if (ds.Tables[2].Rows.Count != 0)/*&& dsServiceWise.Tables[0].Rows.Count != 0)*/
{
pnlmain.Visible = true;
//Menu1.Visible = true;
//MultiView1.Visible = true;
//pnlReports.Visible = true;
lblHeaderText.Text = "District Wise Report From " + ddlMonth1.SelectedItem + "-" + ddlYear1.Text + " To " + ddlMonth2.SelectedItem + "-" + ddlYear2.Text;
ViewState["DistrictWiseReports"] = ds.Tables[2];
grdDistrictReports.DataSource = ds.Tables[2];
grdDistrictReports.DataBind();
GenerateDistrictWiseReport();
/*ViewState["ServiceWiseReports"] = dsServiceWise;
grdServiceWiseReport.DataSource = dsServiceWise;
grdServiceWiseReport.DataBind();
GenerateServiceWiseReport();*/
}
/* else if (ds.Tables[0].Rows.Count != 0 && dsServiceWise.Tables[0].Rows.Count == 0)
{
pnlmain.Visible = true;
Menu1.Visible = true;
MultiView1.Visible = true;
pnlReports.Visible = true;
ViewState["DistrictWiseReports"] = ds;
grdDistrictReports.DataSource = ds;
grdDistrictReports.DataBind();
GenerateDistrictWiseReport();
/*ViewState["ServiceWiseReports"] = null;
grdServiceWiseReport.DataSource = "";
grdServiceWiseReport.EmptyDataText = "<b><center>No Data Available</center></b>";*/
//}
//else if (ds.Tables[0].Rows.Count == 0)/* && dsServiceWise.Tables[0].Rows.Count != 0)*/
//{
// pnlmain.Visible = true;
// //Menu1.Visible = true;
// MultiView1.Visible = true;
// pnlReports.Visible = true;
// /*ViewState["ServiceWiseReports"] = dsServiceWise;
// grdServiceWiseReport.DataSource = dsServiceWise;
// grdServiceWiseReport.DataBind();
// GenerateServiceWiseReport();*/
// grdDistrictReports.DataSource = "";
// grdDistrictReports.EmptyDataText = "<b><center>No Data Available</center></b>";
//}
else
{
pnlmain.Visible = false;
//Menu1.Visible = false;
//MultiView1.Visible = false;
//pnlReports.Visible = false;
ViewState["DistrictWiseReports"] = null;
ViewState["ServiceWiseReports"] = null;
grdDistrictReports.DataSource = "";
grdDistrictReports.EmptyDataText = "<b><center>No Data Available</center></b>";
//CustomMessage1.Alert("No DistrictWise and ServiceWise Data Available");
CustomMessage1.Alert("No District Wise Data Available");
}
}
else
{
pnlmain.Visible = false;
//Menu1.Visible = false;
//MultiView1.Visible = false;
//pnlReports.Visible = false;
CustomMessage1.Alert("Invalid Data");
}
}
}
catch (Exception ex)
{
Logging.Logflatfile_Ex(ex);
}
}
protected void GenerateDistrictWiseReport()
{
//DataTable ds1 = (DataTable)ViewState["DistrictWiseReports"];
DataTable dt1 = new DataTable();
dt1.Columns.Add("District Name");
dt1.Columns.Add("Total Transactions");
dt1.Columns.Add("Income");
dt1.Columns.Add("Amount Collected");
dt1.Columns.Add("Expenditure");
dt1.Columns.Add("Revenue");
ds.Tables.Add(dt1);
DataRow dr = null;
for (int i = 0; i < ds.Tables[2].Rows.Count; i++)
{
string distName1 = ds.Tables[2].Rows[i]["District Name"].ToString();
int TotalTransactions1 = Convert.ToInt32(ds.Tables[2].Rows[i]["Total Transactions"].ToString());
double Income1 = Convert.ToDouble(ds.Tables[2].Rows[i]["Income"].ToString());
double totalAmount1 = Convert.ToDouble(ds.Tables[2].Rows[i]["Amount Collected"].ToString());
double expenditure1 = Convert.ToDouble(ds.Tables[2].Rows[i]["Expenditure"].ToString());
double revenue1 = Convert.ToDouble(ds.Tables[2].Rows[i]["Revenue"].ToString());
dr = dt1.NewRow();
dr["District Name"] = distName1;
dr["Total Transactions"] = TotalTransactions1;
dr["Income"] = Income1;
dr["Amount Collected"] = totalAmount1;
dr["Expenditure"] = expenditure1;
dr["Revenue"] = revenue1;
dt1.Rows.Add(dr);
}
if (Convert.ToInt32(ViewState["MenuStatus"]) == 0 && dt1.Rows.Count != 0)
{
lblHeaderText.Text = "District Wise Report From " + ddlMonth1.SelectedItem + "-" + ddlYear1.Text + " To " + ddlMonth2.SelectedItem + "-" + ddlYear2.Text;
ExcelExport1.DataTableToExport = PDFExport1.DataTableToExport = dt1;
PDFExport1.TitleText = "District Wise Report From " + ddlMonth1.SelectedItem + "-" + ddlYear1.Text + " To " + ddlMonth2.SelectedItem + "-" + ddlYear2.Text + "";
ExcelExport1.TitleText = "District Wise Report From " + ddlMonth1.SelectedItem + "-" + ddlYear1.Text + " To " + ddlMonth2.SelectedItem + "-" + ddlYear2.Text + "";
ExcelExport1.FileName = PDFExport1.FileName = "District Wise Report";
}
}
/* protected void GenerateServiceWiseReport()
{
DataSet ds3 = (DataSet)ViewState["ServiceWiseReports"];
if (Convert.ToInt32(ViewState["MenuStatus"]) == 1 && ds3 != null)
{
lblHeaderText.Text = "Service Wise Report From " + ddlMonth1.SelectedItem + "-" + ddlYear1.Text + " To " + ddlMonth2.SelectedItem + "-" + ddlYear2.Text;
ExcelExport1.DataTableToExport = PDFExport1.DataTableToExport = ds3.Tables[0];
PDFExport1.TitleText = "Service Wise Report From " + ddlMonth1.SelectedItem + "-" + ddlYear1.Text + " To " + ddlMonth2.SelectedItem + "-" + ddlYear2.Text + "";
ExcelExport1.TitleText = "Service Wise Report From " + ddlMonth1.SelectedItem + "-" + ddlYear1.Text + " To " + ddlMonth2.SelectedItem + "-" + ddlYear2.Text + "";
ExcelExport1.FileName = PDFExport1.FileName = "ServiceWiseReport" + DateTime.Now.ToString();
}
}*/
public DataSet GetDistrictWiseCenterDetails()
{
DataSet dsGetDistrictWiseCenterDetails = da.GetCenterWiseReports(Convert.ToInt32(ddlMonth1.Text), Convert.ToInt32(ddlYear1.Text), Convert.ToInt32(ddlMonth2.Text), Convert.ToInt32(ddlYear2.Text), Convert.ToInt32(Session["District_No"]));
DataTable dt2 = new DataTable();
dt2.Columns.Add("Center Name");
dt2.Columns.Add("Service Name");
dt2.Columns.Add("Transactons");
dt2.Columns.Add("Income");
dt2.Columns.Add("Amount Collected");
dsGetDistrictWiseCenterDetails.Tables.Add(dt2);
DataRow dr = null;
for (int i = 0; i < dsGetDistrictWiseCenterDetails.Tables[0].Rows.Count; i++)
{
string CenterName1 = dsGetDistrictWiseCenterDetails.Tables[0].Rows[i]["Center Name"].ToString();
string ServiceName1 = dsGetDistrictWiseCenterDetails.Tables[0].Rows[i]["Service Name"].ToString();
int Transactions1 = Convert.ToInt32(dsGetDistrictWiseCenterDetails.Tables[0].Rows[i]["No Of Transactions"].ToString());
double Income1 = Convert.ToDouble(dsGetDistrictWiseCenterDetails.Tables[0].Rows[i]["Income"].ToString());
double AmountCollected1 = Convert.ToDouble(dsGetDistrictWiseCenterDetails.Tables[0].Rows[i]["Amount Collected"].ToString());
dr = dt2.NewRow();
dr["Center Name"] = CenterName1;
dr["Service Name"] = ServiceName1;
dr["Transactons"] = Transactions1;
dr["Income"] = Income1;
dr["Amount Collected"] = AmountCollected1;
dt2.Rows.Add(dr);
}
return dsGetDistrictWiseCenterDetails;
}
protected void grdCenterDetails_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView gvwChild = (GridView)sender;
GridViewRow gvRowParent = (GridViewRow)gvwChild.Parent.Parent.Parent.Parent.Parent;
gvwChild.PageIndex = e.NewPageIndex;
Session["District_No"] = (grdDistrictReports.DataKeys[gvRowParent.RowIndex].Value.ToString());
DataSet ds1 = GetDistrictWiseCenterDetails();
gvwChild.DataSource = ds1;
gvwChild.DataBind();
}
protected void grdCenterDetails_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "PDFCreation")
{
GridView gvwChild = (GridView)sender;
GridViewRow gvRowParent = (GridViewRow)gvwChild.Parent.Parent.Parent.Parent.Parent;
ImageButton imgpdfcreation = (ImageButton)gvwChild.FooterRow.FindControl("imgExportPDF");
if (imgpdfcreation.ImageUrl == @"~/Images/File_Pdf_11.png")
{
DataTable ds1 = (DataTable)ViewState["DistrictWiseReports"];
Session["District_No"] = (grdDistrictReports.DataKeys[gvRowParent.RowIndex].Value.ToString());
Session["District_Name"] = Convert.ToString(ds1.Rows[gvRowParent.RowIndex]["District Name"]);
DataSet dsGetDistrictWiseCenterDetails1 = GetDistrictWiseCenterDetails();
Export(Session["District_Name"] + " District Center Wise Report", dsGetDistrictWiseCenterDetails1.Tables[1]);
}
}
if (e.CommandName == "ExcelCreation")
{
GridView gvwChild = (GridView)sender;
GridViewRow gvRowParent = (GridViewRow)gvwChild.Parent.Parent.Parent.Parent.Parent;
ImageButton imgpdfexcelcreation = (ImageButton)gvwChild.FooterRow.FindControl("imgExportExcel");
if (imgpdfexcelcreation.ImageUrl == @"~/Images/Excel-icon.png")
{
DataTable ds1 = (DataTable)ViewState["DistrictWiseReports"];
Session["District_No"] = (grdDistrictReports.DataKeys[gvRowParent.RowIndex].Value.ToString());
Session["District_Name"] = Convert.ToString(ds1.Rows[gvRowParent.RowIndex]["District Name"]);
DataSet dsGetDistrictWiseCenterDetails1 = GetDistrictWiseCenterDetails();
Export1(Session["District_Name"] + " District Center Wise Report", dsGetDistrictWiseCenterDetails1.Tables[1]);
}
}
}
protected void grdDistrictReports_RowCommand(object sender, GridViewCommandEventArgs e)
{
//ViewState["DistrictWiseCenterDetails"] = null;
if (e.CommandName == "Expand")
{
ImageButton imgbtn;
GridView gv = (GridView)(sender);
Int32 rowIndex = Convert.ToInt32(e.CommandArgument.ToString());
PlaceHolder objPH = (PlaceHolder)(gv.Rows[rowIndex].FindControl("phCenterDetails"));
// ObjectDataSource objDS = (ObjectDataSource)(gv.Rows[rowIndex].FindControl("objOrderDetails"));
GridView objChildGrid = (GridView)(gv.Rows[rowIndex].FindControl("grdCenterDetails"));
imgbtn = (ImageButton)(gv.Rows[rowIndex].FindControl("ImgBtn"));
if (imgbtn.ImageUrl == @"~/Images/gridplus.gif")
{
Session["District_No"] = gv.DataKeys[rowIndex][0].ToString();
DataSet dsGetDistrictWiseCenterDetails1 = GetDistrictWiseCenterDetails();
//ViewState["CenterDetails1"] = dsGetDistrictWiseCenterDetails1;
imgbtn.ImageUrl = @"~/Images/gridminus.gif";
if (objChildGrid != null)
{
if (objPH != null)
objPH.Visible = true;
objChildGrid.Visible = true;
if (dsGetDistrictWiseCenterDetails1.Tables[0].Rows.Count != 0)
{
//ViewState["DistrictWiseCenterDetails"] = dsGetDistrictWiseCenterDetails1;
objChildGrid.DataSource = dsGetDistrictWiseCenterDetails1;
objChildGrid.DataBind();
// GenerateDistrictWiseCenterReport();
}
else
{
objChildGrid.EmptyDataText = "<b><center>No Transactions</center></b>";
}
}
}
else
{
if (objChildGrid != null)
{
imgbtn.ImageUrl = @"~/Images/gridplus.gif";
if (objPH != null)
objPH.Visible = false;
objChildGrid.Visible = false;
}
}
}
}
protected void grdDistrictReports_RowDataBound(object sender, GridViewRowEventArgs e)
{
ImageButton imgBtn;
if (e.Row.RowType == DataControlRowType.DataRow)
{
imgBtn = (ImageButton)(e.Row.FindControl("ImgBtn"));
imgBtn.CommandArgument = e.Row.RowIndex.ToString();
if (e.Row.Cells[0].Text == Session["District_No"])
{
PlaceHolder objPH;
objPH = (PlaceHolder)(e.Row.FindControl("phCenterDetails"));
if (objPH != null)
objPH.Visible = true;
if (imgBtn.ImageUrl == @"~/Images/gridplus.gif")
imgBtn.ImageUrl = @"~/Images/gridminus.gif";
else
imgBtn.ImageUrl = @"~/Images/gridplus.gif";
}
}
}
/* protected void grdServiceDetails_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView gvwChild = (GridView)sender;
GridViewRow gvRowParent = (GridViewRow)gvwChild.Parent.Parent.Parent.Parent.Parent;
gvwChild.PageIndex = e.NewPageIndex;
Session["Service_Id"] = (grdServiceWiseReport.DataKeys[gvRowParent.RowIndex].Value.ToString());
DataSet ds1 = GetServiceWiseCenterDetails();
gvwChild.DataSource = ds1;
gvwChild.DataBind();
}*/
/* protected void grdServiceDetails_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "PDFCreation1")
{
GridView gvwChild = (GridView)sender;
GridViewRow gvRowParent = (GridViewRow)gvwChild.Parent.Parent.Parent.Parent.Parent;
ImageButton imgpdfcreation = (ImageButton)gvwChild.FooterRow.FindControl("imgExportPDF1");
if (imgpdfcreation.ImageUrl == @"~/Images/File_Pdf_11.png")
{
Session["Service_Id"] = (grdServiceWiseReport.DataKeys[gvRowParent.RowIndex].Value.ToString());
DataSet dsGetServiceWiseCenterDetails1 = GetServiceWiseCenterDetails();
Export("ServiceWiseCenterReport", dsGetServiceWiseCenterDetails1.Tables[0]);
}
}
if (e.CommandName == "ExcelCreation1")
{
GridView gvwChild = (GridView)sender;
GridViewRow gvRowParent = (GridViewRow)gvwChild.Parent.Parent.Parent.Parent.Parent;
ImageButton imgpdfexcelcreation = (ImageButton)gvwChild.FooterRow.FindControl("imgExportExcel1");
if (imgpdfexcelcreation.ImageUrl == @"~/Images/Excel-icon.png")
{
Session["Service_Id"] = (grdServiceWiseReport.DataKeys[gvRowParent.RowIndex].Value.ToString());
DataSet dsGetServiceWiseCenterDetails1 = GetServiceWiseCenterDetails();
Export1("ServiceWiseCenterReport", dsGetServiceWiseCenterDetails1.Tables[0]);
}
}
}*/
/* public DataSet GetServiceWiseCenterDetails()
{
DataSet dsGetServiceWiseCenterDetails = da.GetService_Center_Reports(Convert.ToInt32(ddlMonth1.Text), Convert.ToInt32(ddlYear1.Text), Convert.ToInt32(ddlMonth2.Text), Convert.ToInt32(ddlYear2.Text), Convert.ToInt32(Session["Service_Id"]));
return dsGetServiceWiseCenterDetails;
}*/
/* protected void grdServiceWiseReport_RowCommand(object sender, GridViewCommandEventArgs e)
{
//ViewState["ServiceWiseCenterReports"] = null;
if (e.CommandName == "Expand1")
{
ImageButton imgbtn1;
GridView gv1 = (GridView)(sender);
Int32 rowIndex1 = Convert.ToInt32(e.CommandArgument.ToString());
PlaceHolder objPH1 = (PlaceHolder)(gv1.Rows[rowIndex1].FindControl("phServiceDetails"));
// ObjectDataSource objDS = (ObjectDataSource)(gv.Rows[rowIndex].FindControl("objOrderDetails"));
GridView objChildGrid1 = (GridView)(gv1.Rows[rowIndex1].FindControl("grdServiceDetails"));
imgbtn1 = (ImageButton)(gv1.Rows[rowIndex1].FindControl("ImgBtn1"));
if (imgbtn1.ImageUrl == "~/Images/viewIcon1.png")
{
Session["Service_Id"] = gv1.DataKeys[rowIndex1][0].ToString();
DataSet dsGetServiceWiseCenterDetails1 = GetServiceWiseCenterDetails();
imgbtn1.ImageUrl = @"~/Images/gridminus1.gif";
if (objChildGrid1 != null)
{
if (objPH1 != null)
objPH1.Visible = true;
objChildGrid1.Visible = true;
if (dsGetServiceWiseCenterDetails1.Tables[0].Rows.Count != 0)
{
//ViewState["ServiceWiseCenterReports"] = dsGetServiceWiseCenterDetails1;
objChildGrid1.DataSource = dsGetServiceWiseCenterDetails1;
objChildGrid1.DataBind();
}
else
{
objChildGrid1.EmptyDataText = "<b><center>No Transactions</center></b>";
}
}
}
else
{
if (objChildGrid1 != null)
{
imgbtn1.ImageUrl = @"~/Images/viewIcon1.png";
if (objPH1 != null)
objPH1.Visible = false;
objChildGrid1.Visible = false;
objChildGrid1.DataSource = "";
}
}
}
}*/
/* protected void grdServiceWiseReport_RowDataBound(object sender, GridViewRowEventArgs e)
{
ImageButton imgBtn;
if (e.Row.RowType == DataControlRowType.DataRow)
{
imgBtn = (ImageButton)(e.Row.FindControl("ImgBtn1"));
imgBtn.CommandArgument = e.Row.RowIndex.ToString();
if (e.Row.Cells[0].Text == Session["Service_Id"])
{
PlaceHolder objPH;
objPH = (PlaceHolder)(e.Row.FindControl("phServiceDetails"));
if (objPH != null)
objPH.Visible = true;
if (imgBtn.ImageUrl == "~/Images/viewIcon1.png")
imgBtn.ImageUrl = @"~/Images/gridminus1.gif";
else
imgBtn.ImageUrl = @"~/Images/viewIcon1.png";
}
}
}*/
//protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
//{
// MultiView1.ActiveViewIndex = Int32.Parse(Menu1.SelectedValue);
// ViewState["MenuStatus"] = Int32.Parse(MultiView1.ActiveViewIndex.ToString());
// GenerateDistrictWiseReport();
// //GenerateDistrictWiseCenterReport();
// /* GenerateServiceWiseReport();*/
//}
protected void PrintReport_Click(object sender, ImageClickEventArgs e)
{
}
public void Reset()
{
ddlMonth1.SelectedIndex = ddlMonth2.SelectedIndex = ddlYear1.SelectedIndex = ddlYear2.SelectedIndex = -1;
pnlmain.Visible = false;
}
}
-------------------------------------------------------------------------------------------------------------