using iTextSharp.text.html.simpleparser; using iTextSharp.text.pdf; using iTextSharp.text; using System; using System.Collections.Generic; using System.Configuration; using System.Data.SqlClient; using System.Data; using System.Globalization; using System.IO; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace Newdelhibarassocia.dhadmin { public partial class Summaryac : System.Web.UI.Page { Class1 obj = new Class1(); string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; SqlCommand cmd; decimal grandTotal = 0; int totalReceipts = 0; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { } } // ✅ EXPORT TO EXCEL DateTime dtss; protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { // Data rows if (e.Row.RowType == DataControlRowType.DataRow) { decimal amount = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "TotalAmount")); int receipt = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "TotalReceipts")); grandTotal += amount; totalReceipts += receipt; } // Footer row if (e.Row.RowType == DataControlRowType.Footer) { e.Row.Cells[0].Text = "TOTAL"; e.Row.Cells[0].Font.Bold = true; e.Row.Cells[2].Text = grandTotal.ToString("N2"); e.Row.Cells[2].Font.Bold = true; e.Row.Cells[3].Text = totalReceipts.ToString(); e.Row.Cells[3].Font.Bold = true; } } // ✅ REQUIRED public override void VerifyRenderingInServerForm(Control control) { } private void BindGrid() { string fromDate = TextBox1.Text; string toDate = TextBox2.Text; string condition = ""; if (!string.IsNullOrEmpty(fromDate) && !string.IsNullOrEmpty(toDate)) { condition = " AND Daten BETWEEN '" + fromDate + "' AND '" + toDate + "'"; } string query = @" SELECT CONVERT(date, Daten) AS BillDate, btype, SUM(CAST(ISNULL(totalamount,0) AS DECIMAL(18,2))) AS TotalAmount, COUNT(*) AS TotalReceipts FROM newdelhibar_bill WHERE Status != 'Cancel' AND id != '0' " + condition + @" GROUP BY CONVERT(date, Daten), btype ORDER BY BillDate DESC"; DataSet ds = obj.ReturnDataSet(query); if (ds != null && ds.Tables[0].Rows.Count > 0) { GridView1.DataSource = ds; GridView1.DataBind(); } } protected void Button1_Click(object sender, EventArgs e) { BindGrid(); } protected void btnExcel_Click1(object sender, EventArgs e) { // Refresh data BindGrid(); Response.Clear(); Response.Buffer = true; Response.AddHeader("content-disposition", "attachment;filename=BillReport.xls"); Response.Charset = ""; Response.ContentType = "application/vnd.ms-excel"; // Style (optional but useful) GridView1.HeaderStyle.BackColor = System.Drawing.Color.LightGray; GridView1.HeaderStyle.Font.Bold = true; GridView1.FooterStyle.BackColor = System.Drawing.Color.LightYellow; GridView1.FooterStyle.Font.Bold = true; GridView1.GridLines = GridLines.Both; using (StringWriter sw = new StringWriter()) { HtmlTextWriter hw = new HtmlTextWriter(sw); GridView1.AllowPaging = false; GridView1.DataBind(); GridView1.RenderControl(hw); string style = @""; Response.Write(style); Response.Output.Write(sw.ToString()); Response.Flush(); Response.End(); } } } }