public ActionResult Index(UserSearchModel search) { try { var users = _userService.GetUsers(1, _webHelper.ExcelSheetMaxRows, search.WarehouseId, (search.UserId == null) ? 0 : search.UserId.Value); var table = new DataTable(); table.Columns.Add(_resourceManager.GetString("User.Name")); table.Columns.Add(_resourceManager.GetString("User.FullName")); table.Columns.Add(_resourceManager.GetString("User.Warehouse")); table.Columns.Add(_resourceManager.GetString("User.Role")); foreach (var user in users) { table.Rows.Add(new object[] { user.UserName, user.FullName, user.Warehouse.WarehouseName, user.Role.Name, }); } var excelData = _exportManager.ExportExcelFromDataTable(table, "Users", null); return(File(excelData, FileContentType.EXCEL, "Users.xlsx")); } catch (Exception ex) { ErrorNotification(_resourceManager.GetString("Error" + ex.Message)); return(Redirect(Request.RawUrl)); } }
public ActionResult Index(ProfileBoxSearchModel search) { try { var profileBoxes = _profileBoxService.Search(1, _webHelper.ExcelSheetMaxRows, search.ToCriteria <ProfileBoxSearchModel, ProfileBoxSearchCriteria>()); var table = new DataTable(); table.Columns.Add(_resourceManager.GetString("ProfileBox.Name")); table.Columns.Add(_resourceManager.GetString("ProfileBox.CreatedDate")); table.Columns.Add(_resourceManager.GetString("ProfileBox.UserID")); table.Columns.Add(_resourceManager.GetString("ProfileBox.WareHouse")); table.Columns.Add(_resourceManager.GetString("ProfileBox.BoxStatus2")); table.Columns.Add(_resourceManager.GetString("ProfileBox.AdaCount")); foreach (var box in profileBoxes) { table.Rows.Add(new object[] { box.Name, box.CreatedDate.ToString("dd/MM/yyyy"), box.User.UserName, box.Warehouse.WarehouseName, box.Status.Name, box.ADACount, }); } var excelData = _exportManager.ExportExcelFromDataTable(table, "ProfileBoxes", null); return(File(excelData, FileContentType.EXCEL, "ProfileBoxes.xlsx")); } catch (Exception ex) { ErrorNotification(_resourceManager.GetString("Error" + ex.Message)); return(Redirect(Request.RawUrl)); } }
public ActionResult ExportLetterToExcel(DistributorLetterSearchModel search) { try { var letters = _distributorService.SearchDistributorLetter(search.DistributorNumber, search.StartDate, search.EndDate, search.WarehouseID, 1, _webHelper.ExcelSheetMaxRows, null, null); var data = letters.Select(x => x.ToModel <DistributorGridModel>()).ToList(); var table = new System.Data.DataTable(); table.Columns.Add(_resourceManager.GetString("NewLetter.Distributor")); table.Columns.Add(_resourceManager.GetString("NewLetter.DistributorName")); table.Columns.Add(_resourceManager.GetString("NewLetter.Address")); table.Columns.Add(_resourceManager.GetString("NewLetter.Telephone")); table.Columns.Add(_resourceManager.GetString("NewLetter.OldDistributor")); table.Columns.Add(_resourceManager.GetString("NewLetter.OldDistributorName")); table.Columns.Add(_resourceManager.GetString("NewLetter.Telephone") + " "); table.Columns.Add(_resourceManager.GetString("NewLetter.Sponsor")); table.Columns.Add(_resourceManager.GetString("NewLetter.SponsorName")); table.Columns.Add(_resourceManager.GetString("NewLetter.Address") + " "); table.Columns.Add(_resourceManager.GetString("NewLetter.Telephone") + " "); table.Columns.Add(_resourceManager.GetString("NewLettter.Platium")); table.Columns.Add(_resourceManager.GetString("NewLettter.PlatiumName")); table.Columns.Add(_resourceManager.GetString("NewLetter.Address") + " "); table.Columns.Add(_resourceManager.GetString("NewLetter.Telephone") + " "); table.Columns.Add(_resourceManager.GetString("DistributorLetter.LetterDate")); table.Columns.Add(_resourceManager.GetString("NewLetter.Creator")); table.Columns.Add(_resourceManager.GetString("NewLetter.Warehouse")); foreach (var letter in data) { table.Rows.Add(new object[] { letter.DistNumber, letter.DistName, letter.DistAddress, letter.DistTelephone, letter.OldDistNumber, letter.OldDistName, letter.OldDistTelephone, letter.SponsorNum, letter.SponsorName, letter.SponsorAddress, letter.SponsorTelephone, letter.PlatiumNumber, letter.PlatiumName, letter.PlatiumAddress, letter.PlatiumTelephone, letter.LetterDate.ToString("dd/MM/yyyy"), letter.Creator, letter.Warehouse }); } var excelData = _exportManager.ExportExcelFromDataTable(table, "Letter", null); return(File(excelData, FileContentType.EXCEL, "Letter_" + search.DistributorNumber + ".xlsx")); } catch (Exception ex) { ErrorNotification(_resourceManager.GetString("Error" + ex.Message)); return(Redirect(Request.RawUrl)); } }