public PartialViewResult IndexPtv(int?kind, string reciever, int?userId, string userName, float?totalFrom, float?totalTo, DateTime?fromDate, DateTime?toDate, int?currentPageIndex) { if (string.IsNullOrEmpty(userName)) { userName = string.Empty; userId = 0; } var ctx = new SmsContext(); var expenses = ctx.SP_GET_EXPENSES(Convert.ToInt32(kind), reciever, userId, userName, totalFrom, totalTo, fromDate, toDate).Take(SystemConstant.MAX_ROWS).ToList <SP_GET_EXPENSES_Result>(); ExpenesModel model = new ExpenesModel(); model.Count = expenses.Count; int pageSize = SystemConstant.ROWS; int pageIndex = currentPageIndex == null ? 1 : (int)currentPageIndex; model.ResultList = expenses.ToPagedList(pageIndex, pageSize); ViewBag.Kind = kind; ViewBag.Reciever = reciever; ViewBag.UserId = userId; ViewBag.UserName = userName; ViewBag.TotalFrom = totalFrom; ViewBag.ToTalTo = totalTo; ViewBag.FromDate = fromDate; ViewBag.ToDate = toDate; ctx.Dispose(); return(PartialView("IndexPtv", model)); }
public FileContentResult downloadExpenses(int?kind, string reciever, int?userId, string userName, float?totalFrom, float?totalTo, DateTime?fromDate, DateTime?toDate) { if (string.IsNullOrEmpty(userName)) { userName = string.Empty; userId = 0; } string fileName = DateTime.Now.ToString("ddMMyyyyHHmmss") + DateTime.Now.Millisecond.ToString(); System.Text.StringBuilder fileStringBuilder = new System.Text.StringBuilder(); fileStringBuilder.Append("\"STT\","); fileStringBuilder.Append("\"Ngày\","); fileStringBuilder.Append("\"Tên người chi\","); fileStringBuilder.Append("\"Tên người nhận\","); fileStringBuilder.Append("\"Mục đích chi tiền\","); fileStringBuilder.Append("\"Tổng tiền\""); var ctx = new SmsContext(); var expenses = ctx.SP_GET_EXPENSES(Convert.ToInt32(kind), reciever, userId, userName, totalFrom, totalTo, fromDate, toDate).Take(SystemConstant.MAX_ROWS).ToList <SP_GET_EXPENSES_Result>(); int i = 0; string str = ""; foreach (var detail in expenses) { fileStringBuilder.Append("\n"); i += 1; fileStringBuilder.Append("\"" + i + "\","); fileStringBuilder.Append("\"" + ((DateTime)detail.NGAY_CHI).ToString("dd/MM/yyyy") + "\","); fileStringBuilder.Append("\"" + detail.TEN_NGUOI_DUNG + "\","); fileStringBuilder.Append("\"" + detail.TEN_NGUOI_NHAN + "\","); switch (detail.LOAI_CHI) { case 1: str = "Chi mua hàng"; break; case 2: str = "Chi cho vận chuyển"; break; case 3: str = "Chi cho tiền lương nhân viên"; break; case 4: str = "Chi vào mục đích khác"; break; } fileStringBuilder.Append("\"" + str + "\","); fileStringBuilder.Append("\"" + detail.TONG_CHI.ToString("#,###,##") + "\","); } ctx.Dispose(); return(File(new System.Text.UTF8Encoding().GetBytes(fileStringBuilder.ToString()), "text/csv", fileName + ".csv")); }