//[HttpPost] //public ActionResult TransactionQuery(string searchkey,DateTime startdate,DateTime enddate) //{ // if (HttpContext.Session["UID"] == null) // { // return RedirectToAction("Index", "Portal", null); // } // List<mTransaction> Transactions = new List<mTransaction>(); // using (Models.MerchantService db = new Models.MerchantService()) // { // List<v_Transactions> trans = db.v_Transactions.Where(x => (x.MPU_Merchant_ID.Contains(searchkey) || x.Merchant_Name.Contains(searchkey)) && (x.TrxDate >= startdate && x.TrxDate <= enddate)).ToList(); // Transactions = trans.Select(x => new mTransaction { MPU_Merchant_ID = x.MPU_Merchant_ID, Merchant_Name = x.Merchant_Name, CardNo = x.CardNo, CardType = x.CardType, TrxDate = x.TrxDate, TrxAmount = x.TrxAmount, SettAmount = x.SettAmount }).ToList(); // } // //mTransaction tran = new mTransaction(); // //Transactions = tran.transaction_query(searchkey, startdate, enddate); // return View(Transactions); //} public PartialViewResult TransactionQueryResult(string searchkey, string startdate, string enddate) { List <mTransaction> Transactions = new List <mTransaction>(); if (HttpContext.Session["UID"] == null) { TempData["ErrorMessage"] = "Session Error"; TempData.Keep(); return(PartialView(Transactions)); } try { DateTime sDate = Convert.ToDateTime(startdate); DateTime eDate = Convert.ToDateTime(enddate); mTransaction T = new mTransaction(); Transactions = T.transaction_query(searchkey, sDate, eDate); return(PartialView(Transactions)); } catch (Exception ex) { TempData["ErrorMessage"] = ex.Message; TempData.Keep(); return(PartialView(Transactions)); } //mTransaction tran = new mTransaction(); //Transactions = tran.transaction_query(searchkey, startdate, enddate); }
internal FileResult TransactionExportToExcel(string searchkey, string startdate, string enddate) { if (HttpContext.Session["UID"] != null && startdate != null && enddate != null) { List <mTransaction> srl = new List <mTransaction>(); mTransaction sr = new mTransaction(); DateTime sdate = Convert.ToDateTime(startdate); DateTime edate = Convert.ToDateTime(enddate); srl = sr.transaction_query(searchkey, sdate, edate); ExcelPackage.LicenseContext = LicenseContext.NonCommercial; ExcelPackage Ep = new ExcelPackage(); ExcelWorksheet Sheet = Ep.Workbook.Worksheets.Add("TransactionQuery"); Sheet.Cells["A1"].Value = "TrxDate"; Sheet.Cells["B1"].Value = "MID"; Sheet.Cells["C1"].Value = "Merchant Name"; Sheet.Cells["D1"].Value = "Card No"; Sheet.Cells["E1"].Value = "Card Type"; Sheet.Cells["F1"].Value = "MDR Rate"; Sheet.Cells["G1"].Value = "Tran Amount"; Sheet.Cells["H1"].Value = "MDR Value"; Sheet.Cells["I1"].Value = "Settlement Amount"; int row = 2; foreach (mTransaction item in srl) { Sheet.Cells[string.Format("A{0}", row)].Value = item.TrxDate.Value.Date.ToString("MM/dd/yyyy"); Sheet.Cells[string.Format("B{0}", row)].Value = item.MPU_Merchant_ID; Sheet.Cells[string.Format("C{0}", row)].Value = item.Merchant_Name; Sheet.Cells[string.Format("D{0}", row)].Value = item.CardNo; Sheet.Cells[string.Format("E{0}", row)].Value = item.CardType; Sheet.Cells[string.Format("F{0}", row)].Value = item.TRXMDRRate; Sheet.Cells[string.Format("G{0}", row)].Value = item.TrxAmount; Sheet.Cells[string.Format("H{0}", row)].Value = item.MDRValue; Sheet.Cells[string.Format("I{0}", row)].Value = item.SettAmount; row++; } using (ExcelRange rng = Sheet.Cells[string.Format("F{0}:H{1}", 2, row + 1)]) { rng.Style.Numberformat.Format = "###,###,##0.00"; } Sheet.Cells[string.Format("A{0}:F{1}", row, row)].Merge = true; Sheet.Cells[string.Format("A{0}", row)].Value = "Total"; Sheet.Cells[string.Format("G{0}", row)].Value = srl.Sum(i => i.TrxAmount); Sheet.Cells[string.Format("H{0}", row)].Value = srl.Sum(i => i.MDRValue); Sheet.Cells[string.Format("I{0}", row)].Value = srl.Sum(i => i.SettAmount); Sheet.Cells["A:AZ"].AutoFitColumns(); Response.Clear(); var FileByteArray = Ep.GetAsByteArray(); return(File(FileByteArray, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", sdate.ToString("MM/dd/yyyy") + "-" + edate.ToString("MM/dd/yyyy") + "_TransactionQuery.xlsx")); //Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; //Response.AddHeader("content-disposition", "attachment: filename=" +trxdate.ToString("MM/dd/yyyy")+chkType+ "_SettlementReport.xlsx"); //Response.BinaryWrite(Ep.GetAsByteArray()); //Response.End(); } else { return(File(new byte[0], "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")); } }