using OfficeOpenXml; using OfficeOpenXml.Style; using OfficeOpenXml.Table; using Swift.API.GoogleAuthenticator; using Swift.DAL.BL.System.UserManagement; using Swift.DAL.SwiftDAL; using Swift.web.Library; using Swift.web.SwiftSystem.UserManagement.ApplicationUserPool; using System; using System.Data; using System.Globalization; using System.IO; using System.Text; using System.Web; using System.Web.UI.WebControls; namespace Swift.web.SendMoney { public partial class Default : System.Web.UI.Page { private ApplicationUserDao user = new ApplicationUserDao(); private UserPool userPool = UserPool.GetInstance(); protected GoogleAuthenticatorAPI _auth = new GoogleAuthenticatorAPI(); private readonly StaticDataDdl _sdd = new StaticDataDdl(); protected string use2FA = "Y"; protected void Page_Load(object sender, EventArgs e) { //var usr = Server.HtmlEncode(User.Identity.Name); //Response.Write(usr); //username.Attributes.Add("onkeypress", "ClearMessage()"); //pwd.Attributes.Add("onkeypress", "isCapslock((event?event:evt))"); //employeeId.Attributes.Add("onkeypress", "ClearMessage()"); //ExportToExcel(); if (!IsPostBack) { if (GetStatic.ReadWebConfig("UseGoogle2FAuthAgent", "") != "Y") { use2FA = "N"; DisableGoogle2FAuth(); } else { EnableGoogle2FAuth(); } var userPool = UserPool.GetInstance(); userPool.RemoveUser(GetStatic.GetUser()); Session.Clear(); Session.Abandon(); PopulateDDL(); //ValidateDc(); //ValidateIPAddress(); } } private void ExportToExcel() { ExcelPackage.LicenseContext = LicenseContext.NonCommercial; ExcelPackage ExcelPkg = new ExcelPackage(); ExcelWorksheet wsSheet1 = ExcelPkg.Workbook.Worksheets.Add("Sheet1"); using (ExcelRange Rng = wsSheet1.Cells["B2:I2"]) { Rng.Value = "Everyday Be Coding - Format Table using EPPlus .Net Library - Part 15(B)"; Rng.Merge = true; Rng.Style.Font.Size = 16; Rng.Style.Font.Bold = true; Rng.Style.Font.Italic = true; } using (ExcelRange Rng = wsSheet1.Cells["B4:G12"]) { ExcelTableCollection tblcollection = wsSheet1.Tables; ExcelTable table = tblcollection.Add(Rng, "tblSalesman"); //Set Columns position & name table.Columns[0].Name = "Id"; table.Columns[1].Name = "Salesman Name"; table.Columns[2].Name = "Sales Amount"; table.Columns[3].Name = "Profits"; table.Columns[4].Name = "Country"; table.Columns[5].Name = "Date"; //table.ShowHeader = false; table.ShowFilter = true; table.ShowTotal = true; //Add TotalsRowFormula into Excel table Columns table.Columns[0].TotalsRowLabel = "Total Rows"; table.Columns[1].TotalsRowFormula = "SUBTOTAL(102,[Id])"; //102 = Count table.Columns[2].TotalsRowFormula = "SUBTOTAL(109,[Sales Amount])"; //109 = Sum table.Columns[3].TotalsRowFormula = "SUBTOTAL(101,[Profits])"; //101 = Average //Add TotalsRowFunction into Excel table Columns //table.Columns[0].TotalsRowLabel = "Total Rows"; //able.Columns[1].TotalsRowFunction = RowFunctions.Count; //table.Columns[2].TotalsRowFunction = RowFunctions.Sum; //table.Columns[3].TotalsRowFunction = RowFunctions.Average; table.TableStyle = TableStyles.Dark9; } //Insert data into the Excel Table Cells //"ID" Column string IntCellFormat = "###0;"; using (ExcelRange Rng = wsSheet1.Cells["B5"]) { Rng.Style.Numberformat.Format = IntCellFormat; Rng.Value = Convert.ToInt32("1001"); } using (ExcelRange Rng = wsSheet1.Cells["B6"]) { Rng.Style.Numberformat.Format = IntCellFormat; Rng.Value = Convert.ToInt32("1002"); } using (ExcelRange Rng = wsSheet1.Cells["B7"]) { Rng.Style.Numberformat.Format = IntCellFormat; Rng.Value = Convert.ToInt32("1003"); } using (ExcelRange Rng = wsSheet1.Cells["B8"]) { Rng.Style.Numberformat.Format = IntCellFormat; Rng.Value = Convert.ToInt32("1004"); } using (ExcelRange Rng = wsSheet1.Cells["B9"]) { Rng.Style.Numberformat.Format = IntCellFormat; Rng.Value = Convert.ToInt32("1005"); } using (ExcelRange Rng = wsSheet1.Cells["B10"]) { Rng.Style.Numberformat.Format = IntCellFormat; Rng.Value = Convert.ToInt32("1006"); } using (ExcelRange Rng = wsSheet1.Cells["B11"]) { Rng.Style.Numberformat.Format = IntCellFormat; Rng.Value = Convert.ToInt32("1007"); } using (ExcelRange Rng = wsSheet1.Cells["B12"]) { Rng.Style.Numberformat.Format = IntCellFormat; Rng.Value = Convert.ToInt32("1008"); } //"Salesman Name" Column using (ExcelRange Rng = wsSheet1.Cells["C5"]) { Rng.Value = "John"; } using (ExcelRange Rng = wsSheet1.Cells["C6"]) { Rng.Value = "Sunil"; } using (ExcelRange Rng = wsSheet1.Cells["C7"]) { Rng.Value = "Smith"; } using (ExcelRange Rng = wsSheet1.Cells["C8"]) { Rng.Value = "Rohit"; } using (ExcelRange Rng = wsSheet1.Cells["C9"]) { Rng.Value = "Matt"; } using (ExcelRange Rng = wsSheet1.Cells["C10"]) { Rng.Value = "Jack"; } using (ExcelRange Rng = wsSheet1.Cells["C11"]) { Rng.Value = "johnson"; } using (ExcelRange Rng = wsSheet1.Cells["C12"]) { Rng.Value = "Brown"; } using (ExcelRange Rng = wsSheet1.Cells["C12"]) { Rng.Value = "Brown"; } using (ExcelRange Rng = wsSheet1.Cells["C13"]) { Rng.Style.HorizontalAlignment = ExcelHorizontalAlignment.Left; } //"Sales Amount" Column string CurrencyCellFormat = "$###,###,##0.00"; using (ExcelRange Rng = wsSheet1.Cells["D5"])//3 { Rng.Style.Numberformat.Format = CurrencyCellFormat; Rng.Value = Convert.ToDecimal("700.00"); } using (ExcelRange Rng = wsSheet1.Cells["D6"]) { Rng.Style.Numberformat.Format = CurrencyCellFormat; Rng.Value = Convert.ToDecimal("800.00"); } using (ExcelRange Rng = wsSheet1.Cells["D7"]) { Rng.Style.Numberformat.Format = CurrencyCellFormat; Rng.Value = Convert.ToDecimal("1000.00"); } using (ExcelRange Rng = wsSheet1.Cells["D8"]) { Rng.Style.Numberformat.Format = CurrencyCellFormat; Rng.Value = Convert.ToDecimal("1100.00"); } using (ExcelRange Rng = wsSheet1.Cells["D9"]) { Rng.Style.Numberformat.Format = CurrencyCellFormat; Rng.Value = Convert.ToDecimal("5000.00"); } using (ExcelRange Rng = wsSheet1.Cells["D10"]) { Rng.Style.Numberformat.Format = CurrencyCellFormat; Rng.Value = Convert.ToDecimal("200.00"); } using (ExcelRange Rng = wsSheet1.Cells["D11"]) { Rng.Style.Numberformat.Format = CurrencyCellFormat; Rng.Value = Convert.ToDecimal("100.00"); } using (ExcelRange Rng = wsSheet1.Cells["D12"]) { Rng.Style.Numberformat.Format = CurrencyCellFormat; Rng.Value = Convert.ToDecimal("200.00"); } using (ExcelRange Rng = wsSheet1.Cells["D13"]) { Rng.Style.Numberformat.Format = CurrencyCellFormat; Rng.Style.HorizontalAlignment = ExcelHorizontalAlignment.Right; } //"Profits" Column string PersentageCellFormat = "#0\\.00%"; using (ExcelRange Rng = wsSheet1.Cells["E5"]) { Rng.Style.Numberformat.Format = PersentageCellFormat; Rng.Value = Convert.ToDecimal(50.01); } using (ExcelRange Rng = wsSheet1.Cells["E6"]) { Rng.Style.Numberformat.Format = PersentageCellFormat; Rng.Value = Convert.ToDecimal(20.02); } using (ExcelRange Rng = wsSheet1.Cells["E7"]) { Rng.Style.Numberformat.Format = PersentageCellFormat; Rng.Value = Convert.ToInt32(56.30); } using (ExcelRange Rng = wsSheet1.Cells["E8"]) { Rng.Style.Numberformat.Format = PersentageCellFormat; Rng.Value = Convert.ToDecimal(45.90); } using (ExcelRange Rng = wsSheet1.Cells["E9"]) { Rng.Style.Numberformat.Format = PersentageCellFormat; Rng.Value = Convert.ToDecimal(90.92); } using (ExcelRange Rng = wsSheet1.Cells["E10"]) { Rng.Style.Numberformat.Format = PersentageCellFormat; Rng.Value = Convert.ToDecimal(80.88); } using (ExcelRange Rng = wsSheet1.Cells["E11"]) { Rng.Style.Numberformat.Format = PersentageCellFormat; Rng.Value = Convert.ToDecimal(76.90); } using (ExcelRange Rng = wsSheet1.Cells["E12"]) { Rng.Style.Numberformat.Format = PersentageCellFormat; Rng.Value = Convert.ToDecimal(39.9); } using (ExcelRange Rng = wsSheet1.Cells["E13"]) { Rng.Style.Numberformat.Format = PersentageCellFormat; Rng.Style.HorizontalAlignment = ExcelHorizontalAlignment.Right; } //"Country" Column using (ExcelRange Rng = wsSheet1.Cells["F5"]) { Rng.Value = "UK"; } using (ExcelRange Rng = wsSheet1.Cells["F6"]) { Rng.Value = "IND"; } using (ExcelRange Rng = wsSheet1.Cells["F7"]) { Rng.Value = "USA"; } using (ExcelRange Rng = wsSheet1.Cells["F8"]) { Rng.Value = "IND"; } using (ExcelRange Rng = wsSheet1.Cells["F9"]) { Rng.Value = "USA"; } using (ExcelRange Rng = wsSheet1.Cells["F10"]) { Rng.Value = "IND"; } using (ExcelRange Rng = wsSheet1.Cells["F11"]) { Rng.Value = "UK"; } using (ExcelRange Rng = wsSheet1.Cells["F12"]) { Rng.Value = "UK"; } //"Date" Column string DateCellFormat = "mm/dd/yyyy"; using (ExcelRange Rng = wsSheet1.Cells["G5"]) { Rng.Style.Numberformat.Format = DateCellFormat; Rng.Value = Convert.ToDateTime("10/30/2016"); } using (ExcelRange Rng = wsSheet1.Cells["G6"]) { Rng.Style.Numberformat.Format = DateCellFormat; Rng.Value = Convert.ToDateTime("06/23/2017"); } using (ExcelRange Rng = wsSheet1.Cells["G7"]) { Rng.Style.Numberformat.Format = DateCellFormat; Rng.Value = Convert.ToDateTime("05/13/2017"); } using (ExcelRange Rng = wsSheet1.Cells["G8"]) { Rng.Style.Numberformat.Format = DateCellFormat; Rng.Value = Convert.ToDateTime("09/10/2017"); } using (ExcelRange Rng = wsSheet1.Cells["G9"]) { Rng.Style.Numberformat.Format = DateCellFormat; Rng.Value = Convert.ToDateTime("07/26/2017"); } using (ExcelRange Rng = wsSheet1.Cells["G10"]) { Rng.Style.Numberformat.Format = DateCellFormat; Rng.Value = Convert.ToDateTime("08/26/2017"); } using (ExcelRange Rng = wsSheet1.Cells["G11"]) { Rng.Style.Numberformat.Format = DateCellFormat; Rng.Value = Convert.ToDateTime("09/10/2017"); } using (ExcelRange Rng = wsSheet1.Cells["G12"]) //1 { Rng.Style.Numberformat.Format = DateTimeFormatInfo.CurrentInfo.ShortDatePattern; Rng.Value = Convert.ToDateTime("09/10/2017"); } using (ExcelRange Rng = wsSheet1.Cells["I12"]) { Rng.Style.Numberformat.Format = DateTimeFormatInfo.CurrentInfo.ShortDatePattern; Rng.Value = Convert.ToDateTime("09/10/2017"); } using (ExcelRange Rng = wsSheet1.Cells["J12"]) //2 { Rng.Style.Numberformat.Format = "yyyy-mm-dd hh:mm:ss"; Rng.Value = Convert.ToDateTime("09/10/2017"); } using (ExcelRange Rng = wsSheet1.Cells["K12"]) { Rng.Style.Numberformat.Format = "#,##0.00"; Rng.Value = Convert.ToDouble("500000.06"); } wsSheet1.Cells[wsSheet1.Dimension.Address].AutoFitColumns(); //ExcelPkg.SaveAs(new FileInfo(@"E:\FormatExcelTable.xlsx")); ExcelPkg.Workbook.Properties.Title = "DetailTransactionReport"; this.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; this.Response.AddHeader( "content-disposition", string.Format("attachment; filename={0}", "test.xlsx")); this.Response.BinaryWrite(ExcelPkg.GetAsByteArray()); } private void EnableGoogle2FAuth() { Google2FAuthDiv.Visible = true; verificationCode.Enabled = true; Google2FAuthDivCode.Visible = false; employeeId.Enabled = false; } private void PopulateDDL() { _sdd.SetDDL(ref ddlBranch, "EXEC proc_sendPageLoadData @flag='LOGIN-BRANCH'", "agentId", "agentName", "", "Select Login Branch"); } private void DisableGoogle2FAuth() { Google2FAuthDiv.Visible = false; verificationCode.Enabled = false; Google2FAuthDivCode.Visible = true; employeeId.Enabled = true; } private void ValidateDc() { var ipAddress = Request.ServerVariables["REMOTE_ADDR"]; var dcIdNo = Request.ClientCertificate["SERIALNUMBER"]; var dcUserName = Request.ClientCertificate["SUBJECTCN"]; var res = user.ValidateDcId(dcIdNo, dcUserName, ipAddress); if (res.ErrorCode != "0") { Response.Redirect(GetStatic.GetUrlRoot() + "/SiteDown/"); } } private void ValidateIPAddress() { var ipAddress = Request.ServerVariables["REMOTE_ADDR"]; System.Web.HttpBrowserCapabilities browser = Request.Browser; var result = user.GetIpStatus(ipAddress, browser.Platform); if (result.ErrorCode == "1") { //LoginBox.Visible = false; //sslRow.Visible = false; errMsg.InnerHtml = result.Msg; var mailBody = "