protected void BtnExportReport_Click(object sender, EventArgs e)
{
TransactionStatus = false;
SpecialPermissionNoFormAccess = 109;
SpecialPermissionAccessValidity();
if (TransactionStatus == false)
{
//MessageTitle = "Select Proforma" + "<br/>" + "GENERATE NEW REPAIR ORDER";
MessageTitle = "Permission Not Granted !!!!";
MessageSwalTitle = "Oops !!!";
MessageSwalDisplay = MessageTitle;
MessageSwalType = "warning"; // info , success , warning , error
ScriptManager.RegisterStartupScript(this, this.GetType(), "Script", "FunctionAlertMessage('" + MessageSwalTitle + "', '" + MessageSwalDisplay + "', '" + MessageSwalType + "');", true);
return;
}
ExportReport();
}
// End Export Btn
protected void ExportReport()
{
string NewEntry = "Entry By : " +
TxtUserId.Text.Trim() + "-" +
TxtUserName.Text.Trim() + " " + DateTime.Now.Date.ToString("dd-MM-yyyy") + " " + TransactionTime;
UserIdandName = TxtUserId.Text.Trim().ToUpper() + "-" + TxtUserName.Text.Trim().ToUpper();
int MainCompanyCodeTmp = int.Parse(TxtUserCompanyCode.Text);
int MainBranchCodeTmp = int.Parse(TxtUserBranchCode.Text);
int UserIdTmp=int.Parse(TxtUserId.Text);
string UserNameTmp=TxtUserName.Text.Trim().ToUpper();
// SET DATABASE CONNECTION.
ConnectionStringFunction();
SqlCn = new SqlConnection(ConPath);
SqlCn.Open();
SqlDt = new DataTable();
SqlCm = new SqlCommand("ModelList", SqlCn);
SqlCm.CommandType = CommandType.StoredProcedure;
SqlCm.Parameters.AddWithValue("ModelName", "NA");
SqlCm.Parameters.AddWithValue("MainCompanyCode", MainCompanyCodeTmp);
SqlCm.Parameters.AddWithValue("SearchType", "EXPORTLIST");
SqlDa = new SqlDataAdapter(SqlCm);
SqlDa.Fill(SqlDt);
//// CALCULATE RUNNING TOTAL (WILL DISPLAY AT THE FOOTER OF EXCEL WORKBOOK.)
//Decimal dTotalPrice = 0;
//for (int i = 0; i <= SqlDt.Rows.Count - 1; i++)
//{
// //dTotalPrice += SqlDt.Rows[i].Field<Decimal>(1); // 1 is cell no
//}
// NOW ASSIGN DATA TO A DATAGRID.
//DataGrid dg = new DataGrid();
//GridView dg = new GridView();
dg.DataSource = SqlDt;
dg.DataBind();
if (dg.Rows.Count == 0)
{
MessageTitle = "No Record Found";
MessageSwalTitle = "Oops !!!";
MessageSwalDisplay = MessageTitle;
MessageSwalType = "warning"; // info , success , warning , error
ScriptManager.RegisterStartupScript(this, this.GetType(), "Script", "FunctionAlertMessage('" + MessageSwalTitle + "', '" + MessageSwalDisplay + "', '" + MessageSwalType + "');", true);
return;
}
////=========== Add Serial No in DataTable But adding at Last===================
//DataColumn newCol = new DataColumn("RowNumber", typeof(string));
//SqlDt.Columns.Add(newCol);
//int i = 0;
//foreach (DataRow row in SqlDt.Rows)
//{
// i++;
// row["RowNumber"] = i.ToString();
//}
////=========== End Add Serial No in DataTable But adding at Last===================
//string sFileName =TxtPiDetail.Text+ "_PiCallList_" + System.DateTime.Now + ".xls";
string sFileName = "ModalList_" + System.DateTime.Now + ".xls";
sFileName = sFileName.Replace("/", "");
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment; filename=" + sFileName);
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
using (StringWriter sw = new StringWriter())
{
HtmlTextWriter hw = new HtmlTextWriter(sw);
//To Export all pages
dg.AllowPaging = false;
dg.HeaderRow.BackColor = Color.White;
foreach (TableCell cell in dg.HeaderRow.Cells)
{
cell.ForeColor = Color.Black;
cell.Font.Bold = true;
cell.Font.Size = 10;
cell.BackColor = Color.LightCyan;
}
foreach (GridViewRow row in dg.Rows)
{
row.BackColor = Color.White;
foreach (TableCell cell in row.Cells)
{
if (row.RowIndex % 2 == 0)
{
cell.BackColor = dg.AlternatingRowStyle.BackColor;
}
else
{
cell.BackColor = dg.RowStyle.BackColor;
}
//int CellNo = 0;
//if (cell is DataControlFieldCell)
//{
// CellNo = row.Cells.GetCellIndex(cell);
//}
//if (CellNo == 3 || CellNo == 4)
//{
// string CellValue = row.Cells[CellNo].Text;
// DateTime DateTimeNextFollowuDate = DateTime.ParseExact(CellValue, "MM/dd/yyyy", null); // textbox show be read only =false
// DateTimeNextFollowuDate = Convert.ToDateTime(DateTimeNextFollowuDate, System.Globalization.CultureInfo.GetCultureInfo("hi-IN").DateTimeFormat);
// //"hi-IN" is culture information about India. You can change as per culture like French, German, etc.
// string NextFollowupDateTmp = DateTimeNextFollowuDate.ToString("dd-MMM-yyyy");
// cell.Text = NextFollowupDateTmp;
//}
//if (CellNo ==5)
//{
// cell.ForeColor = Color.Red; ;
//}
////cell.CssClass = "textmode";
}
}
//int ColNo= (dg.DataSource as DataTable).Columns.Count;
//string Colspan ="'"+(ColNo - 2).ToString()+"'";
string ReportTitle = "<table> " +
"<tr>" +
" <td colspan='12' style='background-color:lightyellow ; border:solid;text-align:center;font-size:50px;color:darkblue '><b>" + "Model List".ToUpper() + "</b></td>" +
"</tr>" +
"<tr>" +
" <td style='background-color:lightyellow; border:solid '><b>" + "Report Date" + "</b></td>" +
" <td colspan='11' style='background-color:lightyellow;text-align:left; border:solid '><b>" + System.DateTime.Now.ToString("dd-MM-yyyy hh:mm:ss") + "</b></td>" +
"</tr>" +
"<tr>" +
" <td style='background-color:lightyellow; border:solid '><b>" + "Company Name" + "</b></td>" +
" <td colspan='11' style='background-color:lightyellow; border:solid '><b>" + TxtUserCompanyName.Text + "</b></td>" +
"</tr>" +
"</table>";
// ADD A ROW AT THE END OF THE SHEET SHOWING A RUNNING TOTAL OF PRICE.
Response.Write(ReportTitle);
//Response.Write(ReportCompany);
//Response.Write(ReportDateRange);
//Response.Write(ReportDate);
dg.RenderControl(hw);
//Convert to number
//Response.Write("<style> TD { mso-number-format:\@; } </style>");
//style to format numbers to string
string style = @"<style> .textmode { mso-number-format:\@; } </style>";
Response.Write(style);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
}
}
// End Export Report
public override void VerifyRenderingInServerForm(Control control)
{
/* Verifies that the control is rendered */
}
// End override