Exemplo n.º 1
0
 public ActionResult ExportNotScannedListToExcel(NotScannedModel.DistributorUpdateSearchModel search)
 {
     if (ModelState.IsValid)
     {
         try
         {
             var distUpdates = _distributorService.SearchDistributorUpdates(
                 new DistributorUpdateSearchCriteria
             {
                 StartDate   = CommonHelper.GetStartOfDate(search.StartDate),
                 EndDate     = CommonHelper.GetEndOfDate(search.EndDate),
                 Statuses    = new[] { (short)DistributorUpdateStatus.NotCompleted },
                 WarehouseId = search.WarehouseId,
                 UpdateType  = search.UpdateType
             },
                 1,
                 _webHelper.ExcelSheetMaxRows,
                 null,
                 null);
             var fileName  = string.Format(_webHelper.ExcelFileNameFormat, ExcelExportType.DISTRIBUTOR_UPDATES, DateTime.Now, FileExtension.EXCEL);
             var excelData = _exportManager.GenerateDistributorUpdateExcel(distUpdates, search.StartDate, search.EndDate);
             return(File(excelData, FileContentType.EXCEL, fileName));
         }
         catch (Exception ex)
         {
             ErrorNotification(_resourceManager.GetString("Distributor.NotScanned.FailedToExportExcel"));
             _logger.WriteLog("Failed to export not scanned distributors to excel.", ex);
         }
     }
     return(Redirect(Request.RawUrl));
 }
Exemplo n.º 2
0
        public ActionResult NotScanned(NotScannedModel.DistributorUpdateSearchModel search, int page = 1, int pageSize = 10, GridSortOptions sort = null)
        {
            var model = new NotScannedModel();

            if (search.StartDate == DateTime.MinValue)
            {
                search.StartDate = DateTime.Now.AddDays(-7);
            }
            if (search.EndDate == DateTime.MinValue)
            {
                search.EndDate = DateTime.Now;
            }

            // Search criteria
            model.AllDistributorUpdateTypes = _distributorService.GetAllDistributorUpdateTypeNames().Select(x => new SelectListItem()
            {
                Text = x, Value = x
            }).ToList().InsertEmptyValue();
            model.AllWarehouses = WebUtility.ConvertDictionaryToSelectList(_warehouseService.GetAllWarehouses(), true);
            model.Search        = search;

            if (Request.QueryString.HasKeys())
            {
                // Set profile box data
                if (sort == null || string.IsNullOrEmpty(sort.Column))
                {
                    sort = new GridSortOptions()
                    {
                        Column = "DistNumber", Direction = SortDirection.Ascending
                    }
                }
                ;
                ViewBag.Sort = sort;

                var boxes = _distributorService.SearchDistributorUpdates(
                    new DistributorUpdateSearchCriteria
                {
                    StartDate   = CommonHelper.GetStartOfDate(search.StartDate),
                    EndDate     = CommonHelper.GetEndOfDate(search.EndDate),
                    Statuses    = new[] { (short)DistributorUpdateStatus.NotCompleted },
                    WarehouseId = search.WarehouseId,
                    UpdateType  = search.UpdateType
                },
                    page,
                    pageSize,
                    sort.Column,
                    WebUtility.GetSortDir(sort));
                model.DistributorUpdates = boxes.Select(x => x.ToModel <NotScannedModel.DistributorUpdateModel>()).ToList();
                model.Pager = boxes.ToMvcPaging(model.DistributorUpdates);

                // If current page > total pages, redirect to last page
                if (model.Pager.TotalPages > 0 && model.Pager.PageNumber > model.Pager.TotalPages)
                {
                    return(Redirect(Url.Paging(model.Pager.TotalPages, model.Pager.PageSize).ToString()));
                }
            }
            return(View(model));
        }