protected void btnStatusGenerateReport_Click(object sender, EventArgs e) { pieChartPanel.Visible = false; claimStatusPanel.Visible = true; GridClaimData.Visible = true; SqlConnection con1 = new SqlConnection(cs); using (con1) { using (cmd = new SqlCommand("select ERSClaimID,ERSApproverName,EmployeeName,ERSClaimType,(Currency+'.' + ' '+CAST(ERSBillAmount as varchar(30))) as ERSBillAmount,ERSClaimStatus from ERSClaim left join Employee on Employee.EmployeeID = ERSClaim.ERSEmployeeID left join ERSApprover on ERSClaim.ERSApproverID=ERSApprover.ERSApproverID Where ERSClaimStatus='" + ClaimStatusDropDown.SelectedValue + "'")) { SqlDataAdapter dt = new SqlDataAdapter(); try { cmd.Connection = con1; con1.Open(); dt.SelectCommand = cmd; DataTable dTable = new DataTable(); dt.Fill(dTable); SqlDataReader sdr = cmd.ExecuteReader(); GridClaimData.DataSource = dTable; GridClaimData.DataBind(); } catch (Exception ex) { // Error msg display here Response.Write(ex.Message); } } } }
private void ClaimDataGrid() { SqlConnection con = new SqlConnection(cs); using (con) { using (SqlCommand cmd = new SqlCommand("select ERSClaimID,ERSApproverID,ERSEmployeeID,ERSClaimType,(Currency+'.' + ' '+CAST(ERSBillAmount as varchar(30))) as ERSBillAmount,ERSClaimStatus,ERSClaimProcessDate from ERSClaim Where (ERSClaimDate>='" + TextBox1.Text + "'and ERSClaimDate<='" + TextBox2.Text + "') and ERSApproverID='" + Session["SessionEmployeeID"].ToString() + "' ")) { SqlDataAdapter dt = new SqlDataAdapter(); try { cmd.Connection = con; con.Open(); dt.SelectCommand = cmd; DataTable dTable = new DataTable(); dt.Fill(dTable); SqlDataReader sdr = cmd.ExecuteReader(); GridClaimData.DataSource = dTable; GridClaimData.DataBind(); //if (GridClaimData.Columns.Count > 0) //{ // GridClaimData.Columns[0].Visible = false; // GridClaimData.Columns[6].Visible = false; //} //else //{ // GridClaimData.HeaderRow.Cells[0].Visible = false; // GridClaimData.HeaderRow.Cells[6].Visible = false; // foreach (GridViewRow gvr in GridClaimData.Rows) // { // gvr.Cells[0].Visible = false; // } //} } catch (Exception ex) { // Error msg display here Response.Write(ex.Message); } } } }
private void ExportGridToExcel() { //GridClaimData.AllowPaging = true; //this.ClaimDataGrid(); //GridClaimData.ForeColor = System.Drawing.Color.Black; GridClaimData.RowStyle.ForeColor = System.Drawing.Color.Black; GridClaimData.HeaderStyle.ForeColor = System.Drawing.Color.Black; Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=ExportGridData.xls"); Response.ContentType = "File/Data.xls"; StringWriter StringWriter = new System.IO.StringWriter(); HtmlTextWriter HtmlTextWriter = new HtmlTextWriter(StringWriter); GridClaimData.RenderControl(HtmlTextWriter); Response.Write(StringWriter.ToString()); Response.End(); }
protected void btnEmployeeGenerateReports_Click(object sender, EventArgs e) { pieChartPanel.Visible = false; employeePanel.Visible = true; GridClaimData.Visible = true; SqlConnection con = new SqlConnection(cs); SqlCommand cmd; using (con) { using (cmd = new SqlCommand("select ERSClaimID,ERSApproverName,EmployeeName,ERSClaimType,(Currency+'.' + ' '+CAST(ERSBillAmount as varchar(30))) as ERSBillAmount,ERSClaimStatus from ERSClaim left join Employee on Employee.EmployeeID = ERSClaim.ERSEmployeeID left join ERSApprover on ERSClaim.ERSApproverID=ERSApprover.ERSApproverID where EmployeeName='" + DropDownList2.SelectedValue + "'", con)) { SqlDataAdapter dt = new SqlDataAdapter(); try { cmd.Connection = con; con.Open(); dt.SelectCommand = cmd; DataTable dTable = new DataTable(); dt.Fill(dTable); SqlDataReader sdr = cmd.ExecuteReader(); GridClaimData.DataSource = dTable; GridClaimData.DataBind(); } catch (Exception ex) { Response.Write(ex.Message); } } if (GridClaimData.Rows.Count > 0) { GridClaimData.CssClass = "table table-bordered table-striped table-inverse nomargin"; GridClaimData.UseAccessibleHeader = true; GridClaimData.HeaderRow.TableSection = TableRowSection.TableHeader; GridClaimData.FooterRow.TableSection = TableRowSection.TableFooter; } } }
private void ClaimDataGrid2() { if (DropDownList1.SelectedIndex == 2) { SqlConnection con = new SqlConnection(cs); using (con) { using (cmd = new SqlCommand("select ERSClaimID,ERSApproverName,EmployeeName,ERSClaimType,(Currency+'.' + ' '+CAST(ERSBillAmount as varchar(30))) as ERSBillAmount,ERSClaimStatus from ERSClaim left join Employee on Employee.EmployeeID = ERSClaim.ERSEmployeeID left join ERSApprover on ERSClaim.ERSApproverID=ERSApprover.ERSApproverID Where ERSClaimDate>='" + TextBox1.Text + "'and ERSClaimDate<='" + TextBox3.Text + "'", con)) { SqlDataAdapter dt = new SqlDataAdapter(); try { cmd.Connection = con; con.Open(); dt.SelectCommand = cmd; DataTable dTable = new DataTable(); dt.Fill(dTable); SqlDataReader sdr = cmd.ExecuteReader(); GridClaimData.DataSource = dTable; GridClaimData.DataBind(); } catch (Exception ex) { // Error msg display here Response.Write(ex.Message); } } } if (GridClaimData.Rows.Count > 0) { GridClaimData.CssClass = "table table-bordered table-striped table-inverse nomargin"; GridClaimData.UseAccessibleHeader = true; GridClaimData.HeaderRow.TableSection = TableRowSection.TableHeader; GridClaimData.FooterRow.TableSection = TableRowSection.TableFooter; } } }
protected void btnExportExcel_Click(object sender, EventArgs e) { try { if (GridClaimData.Rows.Count > 0) { //btnExportExcel.Visible = true; Response.Clear(); Response.Buffer = true; Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.xls"); Response.Charset = ""; Response.ContentType = "application/vnd.ms-excel"; using (StringWriter sw = new StringWriter()) { HtmlTextWriter hw = new HtmlTextWriter(sw); GridClaimData.RowStyle.ForeColor = System.Drawing.Color.Black; GridClaimData.HeaderStyle.ForeColor = System.Drawing.Color.Black; //To Export all pages GridClaimData.AllowPaging = false; //this.BindGrid(); if (DropDownList1.SelectedIndex == 1) { btnEmployeeGenerateReports_Click(sender, e); } else if (DropDownList1.SelectedIndex == 2) { btnclaimDateGenerateReports_Click(sender, e); } else if (DropDownList1.SelectedIndex == 3) { btnStatusGenerateReport_Click(sender, e); } foreach (TableCell cell in GridClaimData.HeaderRow.Cells) { cell.BackColor = GridClaimData.HeaderStyle.BackColor; } foreach (GridViewRow row in GridClaimData.Rows) { row.BackColor = Color.White; foreach (TableCell cell in row.Cells) { if (row.RowIndex % 2 == 0) { cell.BackColor = GridClaimData.AlternatingRowStyle.BackColor; } else { cell.BackColor = GridClaimData.RowStyle.BackColor; } cell.CssClass = "textmode"; } } GridClaimData.RenderControl(hw); //style to format numbers to string string style = @"<style> .textmode { } </style>"; Response.Write(style); Response.Output.Write(sw.ToString()); Response.Flush(); Response.End(); } } else { if (DropDownList1.SelectedIndex == 1) { pieChartPanel.Visible = false; employeePanel.Visible = true; claimDatePanel.Visible = false; claimStatusPanel.Visible = false; } else if (DropDownList1.SelectedIndex == 2) { pieChartPanel.Visible = false; employeePanel.Visible = false; claimDatePanel.Visible = true; claimStatusPanel.Visible = false; } else if (DropDownList1.SelectedIndex == 3) { pieChartPanel.Visible = false; employeePanel.Visible = false; claimDatePanel.Visible = false; claimStatusPanel.Visible = true; } alertmod.Style.Add("background-color", "#ffc2b3"); alert.Style.Add("background-color", "#ffc2b3"); Label5.ForeColor = System.Drawing.ColorTranslator.FromHtml("black"); Label5.Text = "No records to export"; alert.Visible = true; TextBox1.Text = string.Empty; TextBox3.Text = string.Empty; } } catch (Exception ex) { alertmod.Style.Add("background-color", "#ffc2b3"); alert.Style.Add("background-color", "#ffc2b3"); //Label2.ForeColor = System.Drawing.ColorTranslator.FromHtml("Red"); Label5.ForeColor = System.Drawing.ColorTranslator.FromHtml("black"); //Label2.Text = "Failure!"; Label5.Text = "Employee has no claims"; alert.Visible = true; } }