protected void btn_Download_Click(object sender, EventArgs e) { // Clear all content output from the buffer stream Response.ClearContent(); // Specify the default file name using "content-disposition" RESPONSE header Response.AppendHeader("content-disposition", "attachment; filename=PbDowntimeReport " + DateTime.Now.ToString("ddMMyy_HHmm") + ".xls"); // Set excel as the HTTP MIME type Response.ContentType = "application/excel"; // Create an instance of stringWriter for writing information to a string StringWriter stringWriter = new StringWriter(); // Create an instance of HtmlTextWriter class for writing markup // characters and text to an ASP.NET server control output stream HtmlTextWriter htw = new HtmlTextWriter(stringWriter); int ColTot = GV_DownTime_Details.Rows[0].Cells.Count; HttpContext.Current.Response.Write("<Table border='1' bgColor='#ffffff' " + "borderColor='#000000' Text-align='Center' cellSpacing='0' cellPadding='0' " + "style='font-size:10.0pt; font-family:Calibri; background:white'> " + "<TR><TD COLSPAN='" + ColTot.ToString() + "' style='background:yellow; font-size:14.0pt; vertical-align:middle; Text-align:Center; height:35px;'><B>" + globle.BankName + " PASSBOOK PRINTING KIOSKS - DOWNTIME CALCULATION REPORT GENERATED ON " + DateTime.Now.ToString("dd MMM yyyy, hh:mm tt") + "</B></TD></TR>"); GV_DownTime_Details.HeaderStyle.ForeColor = Color.White; GV_DownTime_Details.HeaderStyle.BackColor = Color.Blue; GV_DownTime_Details.HeaderStyle.Font.Bold = true; GV_DownTime_Details.Font.Name = "Calibri"; GV_DownTime_Details.RenderControl(htw); Response.Write(stringWriter.ToString()); HttpContext.Current.Response.Flush(); HttpContext.Current.Response.End(); Response.End(); }
protected void btn_Search_by_serial_no_Click(object sender, EventArgs e) { try { Reply objRes = new Reply(); // send request using (WebClient client = new WebClient()) { if (Session["Role"].ToString().ToLower().Contains("admin")) { parameter = "all# #" + DDL_Duration.SelectedItem.Text + "#serial#" + txt_SerialNo_searching.Text; } else { parameter = Session["Role"].ToString() + "#" + Session["Location"].ToString() + "#" + DDL_Duration.SelectedItem.Text + "#serial#" + txt_SerialNo_searching.Text; } client.Headers[HttpRequestHeader.ContentType] = "text/json"; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; string JsonString = JsonConvert.SerializeObject(parameter); EncRequest objEncRequest = new EncRequest(); objEncRequest.RequestData = AesGcm256.Encrypt(JsonString); string dataEncrypted = JsonConvert.SerializeObject(objEncRequest); string result = client.UploadString(URL + "/GetDownTimeReport", "POST", dataEncrypted); EncResponse objResponse = JsonConvert.DeserializeObject <EncResponse>(result); objResponse.ResponseData = AesGcm256.Decrypt(objResponse.ResponseData); //objRes = JsonConvert.DeserializeObject<Reply>(objResponse.ResponseData); //DataContractJsonSerializer objDCS = new DataContractJsonSerializer(typeof(Reply)); //MemoryStream objMS = new MemoryStream(Encoding.UTF8.GetBytes(objResponse.ResponseData)); //objRes = (Reply)objDCS.ReadObject(objMS); Newtonsoft.Json.JsonSerializer json = new Newtonsoft.Json.JsonSerializer(); json.NullValueHandling = NullValueHandling.Ignore; StringReader sr = new StringReader(objResponse.ResponseData); Newtonsoft.Json.JsonTextReader reader = new JsonTextReader(sr); objRes = json.Deserialize <Reply>(reader); if (objRes.res == true) { for (int i = 0; i < objRes.DS.Tables[0].Rows.Count; i++) { Decimal T = Convert.ToDecimal(objRes.DS.Tables[0].Rows[i]["Down Time%"]); // total minte Decimal rem = T / 100; //string dd = span.Days + "." + span.Hours; //Decimal A = Convert.ToDecimal(T) * 8; //Decimal B = ; //int TempHours = 0; //if (span.Days > 0) //{ // TempHours = span.Days * 8; //} //if (span.Hours > 0) // TempHours + = span.Hours; string B = (100 - rem).ToString(); // total (8) hours in a day, In 30 days = 240 hours = 14400 mint objRes.DS.Tables[0].Rows[i]["Down Time%"] = Convert.ToString(rem); //objRes.DS.Tables[0].Rows[i]["Passbook Printer"] = rem.ToString(); objRes.DS.Tables[0].Rows[i]["Avalability%"] = B; objRes.DS.AcceptChanges(); } lbl_tot.Text = "Total Records are : " + objRes.DS.Tables[0].Rows.Count.ToString(); GV_DownTime_Details.DataSource = objRes.DS.Tables[0]; GV_DownTime_Details.DataBind(); ExportBTN.Visible = true; } else { PageUtility.MessageBox(this, "Data Not Exist. "); // Response.Write("<script type='text/javascript'>alert( 'Data Not Exist.' )</script>"); GV_DownTime_Details.DataSource = null; GV_DownTime_Details.DataBind(); ExportBTN.Visible = false; lbl_tot.Text = ""; } } } catch (Exception ex) { PageUtility.MessageBox(this, "catch error : " + ex.Message); } }