Пример #1
0
        public ActionResult ShortList(GridCommand command, ItemSearchModel searchModel)
        {
            SearchCacheModel searchCacheModel = this.ProcessSearchModel(command, searchModel);

            ViewBag.PageSize = base.ProcessPageSize(command.PageSize);
            return(View());
        }
        public ActionResult Index(int?page, ItemSearchModel Model)
        {
            List <ItemViewModel> list = new List <ItemViewModel>();

            list = _itemBL.Search(Model, page);
            if (page.HasValue && Session[ScreenController] != null)
            {
                Model = (ItemSearchModel)Session[ScreenController];
            }
            else
            {
                Session[ScreenController] = Model;
            }

            int Count = _itemBL.Count(Model);

            TempData["SearchCount"] = Count + " row(s)";
            var pageNumber = (page ?? 1);

            ViewBag.No = (pageNumber - 1) * 200;
            Model.searchResultModel = new StaticPagedList <ItemViewModel>(list, pageNumber, 200, Count);
            ViewBag.Parent          = new SelectList(_itemBL.GetListCategory(true), "id", "name");
            ViewBag.CurrentFilter   = Model;
            return(PartialView("ListItem", Model.searchResultModel));
        }
Пример #3
0
        public void ExportItemXLS(ItemSearchModel searchModel)
        {
            string hql = " select i from Item as i ";

            if (!string.IsNullOrWhiteSpace(searchModel.ReferenceCode))
            {
                hql += string.Format(" and i.ReferenceCode like '{0}%' ", searchModel.ReferenceCode);
            }
            if (!string.IsNullOrWhiteSpace(searchModel.Code))
            {
                hql += string.Format(" and i.Code = '{0}' ", searchModel.Code);
            }
            if (!string.IsNullOrWhiteSpace(searchModel.Description))
            {
                hql += string.Format(" and i.Description like '{0}%' ", searchModel.Description);
            }
            if (searchModel.IsActive)
            {
                hql += string.Format(" and i.IsActive = 1 ");
            }
            else
            {
                hql += string.Format(" and i.IsActive = 0 ");
            }
            hql += " order by i.CreateDate asc ";
            IList <Item> exportItemList = this.genericMgr.FindAll <Item>(hql);

            ExportToXLS <Item>("ExportItemXLS", "xls", exportItemList);
        }
Пример #4
0
        public IActionResult Results(ItemSearchModel searchModel)
        {
            searchModel.ItemsPerPage = searchModel.ResultsPerPage;

            var queryObject = new ItemSearchQueryEntity()
            {
                ItemId               = searchModel.Code,
                Description          = searchModel.Description,
                DateCreatedStart     = searchModel.DateCreatedStart,
                DateCreatedEnd       = searchModel.DateCreatedEnd,
                Category             = searchModel.Category,
                StorageLocation      = searchModel.StorageLocation,
                CustomerPurchasedFor = searchModel.CustomerPurchasedFor,
                CustomerReservedFor  = searchModel.CustomerReservedFor,
                StockLevel           = searchModel.StockLevel,
                ResultsPerPage       = searchModel.ResultsPerPage
            };

            var results = _itemService.FindItemSearchResults(queryObject);

            var filterResults = results.Skip((searchModel.CurrentPage - 1) * searchModel.ItemsPerPage).Take(searchModel.ItemsPerPage).ToList();

            var presentation = new ItemSearchResultsModel
            {
                CurrentPage  = searchModel.CurrentPage,
                Items        = filterResults,
                ItemsPerPage = searchModel.ResultsPerPage,
                TotalItems   = (results.Count() > 0 ? results.Count() : 1)
            };

            return(View(presentation));
        }
Пример #5
0
        public ActionResult List(GridCommand command, ItemSearchModel searchModel)
        {
            ViewBag.HaveEditPermission = CurrentUser.Permissions.Where(p => p.PermissionCode == "Url_Item_Edit").Count() > 0;
            SearchCacheModel searchCacheModel = this.ProcessSearchModel(command, searchModel);

            ViewBag.PageSize = base.ProcessPageSize(command.PageSize);
            return(View());
        }
Пример #6
0
        public IActionResult Search()
        {
            ViewBag.ResultsPerPage   = _selectListService.ResultsPerPage();
            ViewBag.Categories       = _selectListService.CategoriesAll();
            ViewBag.StorageLocations = _selectListService.StorageLocationsAll();

            var presentation = new ItemSearchModel();

            return(View(presentation));
        }
Пример #7
0
        public ActionResult Index(int?page, ItemSearchModel Model)
        {
            Model.searchResultModel   = new List <ItemViewModel>();
            Model.searchResultModel   = _categoryBL.Search(Model);
            Session[ScreenController] = Model;
            var pageNumber = (page ?? 1);
            var list       = Model.searchResultModel.ToPagedList(pageNumber, 100);

            ViewBag.Parent = new SelectList(_categoryBL.GetListCategory(true), "id", "name");
            return(PartialView("ListItem", list));
        }
Пример #8
0
        public int Count(ItemSearchModel model)
        {
            int    result;
            string strQuery = "SELECT COUNT(item.id) ";

            strQuery += " FROM `product_item` item LEFT JOIN (SELECT c.`id`, cpp.`name` AS category_parent_name, c.`name` FROM product_category c Left JOIN (SELECT cp.`name`, cp.`id` FROM product_category cp ) cpp on cpp.`id` = c.`parent_id`) cate ON item.`category_id` = cate.`id` WHERE 1 ";
            strQuery += ((model.category_id) != null) ? " AND (item.`category_id` = @category OR item.`category_id` IN (SELECT cate.`id` FROM product_category cate WHERE cate.`parent_id` = @category ))" : "";
            strQuery += (!string.IsNullOrEmpty(model.code)) ? " AND item.`code` LIKE @code" : "";
            strQuery += (!string.IsNullOrEmpty(model.name)) ? " AND item.`name` LIKE @name" : "";
            result    = (_db.ExecuteScalar <int>(strQuery, new { code = '%' + model.code + '%', name = '%' + model.name + '%', category = model.category_id }));
            return(result);
        }
        public List <ItemViewModel> Search(ItemSearchModel model)
        {
            string strQuery = "SELECT item.`id`, item.`code`, item.`name`, cate.`name` category_name, item.`specification`, item.`description`  ";

            strQuery += " FROM `product_item` item JOIN (SELECT `id`, `name` FROM `product_category` ";
            strQuery += ((model.category_id) != null) ? " WHERE `id` IN ( @category ) OR `parent_id` IN ( @category ))" : ")";
            strQuery += " cate ON item.`category_id` = cate.`id` WHERE 1";
            strQuery += (!string.IsNullOrEmpty(model.code)) ? " AND item.`code` LIKE @code" : "";
            strQuery += (!string.IsNullOrEmpty(model.name)) ? " AND item.`name` LIKE @name" : "";
            var result = _db.Query <ItemViewModel>(strQuery, new { code = '%' + model.code + '%', name = '%' + model.name + '%', category = model.category_id }).ToList();

            return(result);
        }
Пример #10
0
        public ActionResult Index()
        {
            ItemSearchModel Model = new ItemSearchModel();

            if (Session[ScreenController] != null)
            {
                Model = (ItemSearchModel)Session[ScreenController];
                Model.searchResultModel = new List <ItemViewModel>();
                Model.searchResultModel = _categoryBL.Search(Model).ToPagedList(1, 100);
            }
            else
            {
                Model.searchResultModel = new List <ItemViewModel>().ToPagedList(1, 100);
            }
            ViewBag.Parent = new SelectList(_categoryBL.GetListCategory(true), "id", "name");
            return(View(Model));
        }
Пример #11
0
        public IActionResult Results(ItemSearchModel searchModel)
        {
            searchModel.ItemsPerPage = searchModel.ResultsPerPage;
            var results = _itemService.FindItemSearchResults(searchModel);

            var filterResults = results.Skip((searchModel.CurrentPage - 1) * searchModel.ItemsPerPage).Take(searchModel.ItemsPerPage).ToList();

            var presentation = new ItemSearchResultsModel
            {
                CurrentPage  = searchModel.CurrentPage,
                Items        = filterResults,
                ItemsPerPage = searchModel.ResultsPerPage,
                TotalItems   = (results.Count() > 0 ? results.Count() : 1)
            };

            return(View(presentation));
        }
Пример #12
0
        public async Task <JsonResult> FetchItemsPartialAsync(ItemSearchModel itemSearchModel)
        {
            ResponseModel searchResponseModel = new ResponseModel()
            {
                Success = false,
                Data    = null,
            };

            try
            {
                if (itemSearchModel.TypeList == null)
                {
                    itemSearchModel.TypeList = new List <int>();
                }
                ItemsResponseModel itemsResponseModel = await GetItemsAsync(itemSearchModel);

                if (itemsResponseModel != null)
                {
                    if (itemsResponseModel.TotalItems == 0)
                    {
                        return(Json(new { Success = true, Status = HttpStatusCode.NotFound, Message = "No item(s) found" }, JsonRequestBehavior.AllowGet));
                    }
                    else if (itemsResponseModel.TotalItems <= (itemsResponseModel.CurrentPage * itemsResponseModel.ItemsPerPage))
                    {
                        var html = RenderRazorViewToString("~/Views/List/_ListItemPartial.cshtml", itemsResponseModel.Items);
                        return(Json(new { Success = true, Status = HttpStatusCode.ResetContent, Html = html, Message = "Change filters to search for more items" }, JsonRequestBehavior.AllowGet));
                    }
                    else if (itemsResponseModel.Items != null)
                    {
                        var html = RenderRazorViewToString("~/Views/List/_ListItemPartial.cshtml", itemsResponseModel.Items);
                        return(Json(new { Success = true, Status = HttpStatusCode.OK, Message = "", Object = itemsResponseModel.Items, Html = html }, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        return(Json(new { Success = false, Status = HttpStatusCode.InternalServerError, Message = "Something went wrong while fetching items" }, JsonRequestBehavior.AllowGet));
                    }
                }
                return(Json(new { Success = false, Status = HttpStatusCode.InternalServerError, Message = "Something went wrong while fetching items" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { Success = false, Status = HttpStatusCode.InternalServerError, Message = "Something went wrong while fetching items" }, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult Index()
        {
            ItemSearchModel Model = new ItemSearchModel();

            if (Session[ScreenController] != null)
            {
                Model = (ItemSearchModel)Session[ScreenController];
                int Count = _itemBL.Count(Model);
                Model.searchResultModel = new List <ItemViewModel>();
                Model.searchResultModel = _itemBL.Search(Model);
                Model.searchResultModel = new StaticPagedList <ItemViewModel>(Model.searchResultModel, 1, 200, Count);
            }
            else
            {
                Model.searchResultModel = new List <ItemViewModel>();
                Model.searchResultModel = new StaticPagedList <ItemViewModel>(Model.searchResultModel, 1, 200, 0);
            }
            ViewBag.Parent = new SelectList(_itemBL.GetListCategory(true), "id", "name");
            ViewBag.No     = 0;
            return(View(Model));
        }
Пример #14
0
        public void ExportShortCodeXLS(ItemSearchModel searchModel)
        {
            var            user  = SecurityContextHolder.Get();
            string         hql   = " select i from Item as i where 1=1 ";
            IList <object> param = new List <object>();

            if (!string.IsNullOrWhiteSpace(searchModel.Code))
            {
                hql += " and i.Code=? ";
                param.Add(searchModel.Code);
            }
            if (!string.IsNullOrWhiteSpace(searchModel.Flow))
            {
//                hql += @" and exists( select 1 from FlowDetail as f where f.Item=i.Code and f.Flow=?  and  exists
//                    (select 1 from UserPermissionView as p where p.UserId =" + user.Id + " and  p.PermissionCategoryType in (" + (int)com.Sconit.CodeMaster.PermissionCategoryType.Supplier + "," + (int)com.Sconit.CodeMaster.PermissionCategoryType.Customer + "," + (int)com.Sconit.CodeMaster.PermissionCategoryType.Region +
//                    ") and  exists ( select 1 from FlowMaster as fm where fm.Flow=? and  p.PermissionCode = fm.PartyFrom or p.PermissionCode = fm.PartyTo ))  ) ";
                hql += @" and exists( select 1 from FlowDetail as f where f.Item=i.Code and f.Flow=?  and exists
                ( select 1 from FlowMaster as fm where fm.Code=f.Flow and fm.Code=? and exists
                (select 1 from UserPermissionView as p where p.UserId =" + user.Id +
                       " and (((fm.PartyFrom=p.PermissionCode or fm.PartyTo=p.PermissionCode ) and p.PermissionCategoryType in (3,4)) or  (fm.PartyTo=p.PermissionCode and p.PermissionCategoryType=2 )))))";
                param.Add(searchModel.Flow);
                param.Add(searchModel.Flow);
            }
            else
            {
                //hql += " and exists( select f from FlowDetail as f where f.Item=i.Code  and  exists (select 1 from UserPermissionView as p where p.UserId =" + user.Id + "and  p.PermissionCategoryType in (" + (int)com.Sconit.CodeMaster.PermissionCategoryType.Supplier + "," + (int)com.Sconit.CodeMaster.PermissionCategoryType.Customer + "," + (int)com.Sconit.CodeMaster.PermissionCategoryType.Region + ") and (p.PermissionCode = f.PartyFrom or p.PermissionCode = f.PartyTo ))  ) ";
                hql += @" and exists( select 1 from FlowDetail as f where f.Item=i.Code   and exists
                ( select 1 from FlowMaster as fm where fm.Code=f.Flow and exists
                (select 1 from UserPermissionView as p where p.UserId =" + user.Id +
                       " and (((fm.PartyFrom=p.PermissionCode or fm.PartyTo=p.PermissionCode ) and p.PermissionCategoryType in (3,4)) or  (fm.PartyTo=p.PermissionCode and p.PermissionCategoryType=2 )))))";
            }
            if (!string.IsNullOrWhiteSpace(searchModel.ReferenceCode))
            {
                hql += " and i.ReferenceCode like ? ";
                param.Add(searchModel.ReferenceCode + "%");
            }
            IList <Item> exportList = this.genericMgr.FindAll <Item>(hql, param.ToArray());

            ExportToXLS <Item>("ExportShorCode", "XLS", exportList);
        }
Пример #15
0
        public ItemSearchResponseModel AdvancedSearchItems(ItemSearchModel item)
        {
            ItemSearchResponseModel result = new ItemSearchResponseModel();

            using (OrmocIMSEntities context = new OrmocIMSEntities())
            {
                result.RecordCount = context.ItemAdvancedSearch_SP(item.ModuleName, item.Id.HasValue ? item.Id.Value.ToString() : null,
                                                                   null, string.IsNullOrEmpty(item.ItemName) ? null : item.ItemName,
                                                                   string.IsNullOrEmpty(item.Brand) ? null : item.Brand,
                                                                   item.CategoryId.HasValue ? item.CategoryId.Value.ToString() : null,
                                                                   item.SubCategoryId.HasValue ? item.SubCategoryId.Value.ToString() : null,
                                                                   item.Location.HasValue ? item.Location.Value.ToString() : null,
                                                                   string.IsNullOrEmpty(item.Tag) ? null : item.Tag,
                                                                   string.IsNullOrEmpty(item.Sku) ? null : item.Sku,
                                                                   item.StatusCd.HasValue ? item.StatusCd.Value.ToString() : null
                                                                   ).Count();

                result.SearchResult = context.ItemAdvancedSearch_SP(item.ModuleName, item.Id.HasValue ? item.Id.Value.ToString() : null,
                                                                    null, string.IsNullOrEmpty(item.ItemName) ? null : item.ItemName,
                                                                    string.IsNullOrEmpty(item.Brand) ? null : item.Brand,
                                                                    item.CategoryId.HasValue ? item.CategoryId.Value.ToString() : null,
                                                                    item.SubCategoryId.HasValue ? item.SubCategoryId.Value.ToString() : null,
                                                                    item.Location.HasValue ? item.Location.Value.ToString() : null,
                                                                    string.IsNullOrEmpty(item.Tag) ? null : item.Tag,
                                                                    string.IsNullOrEmpty(item.Sku) ? null : item.Sku,
                                                                    item.StatusCd.HasValue ? item.StatusCd.Value.ToString() : null
                                                                    ).Skip(item.NextBatch).Take(10)
                                      .Select(x => new ItemSearchResult
                {
                    Id         = x.Id,
                    ItemName   = x.ItemName,
                    Brand      = x.BrandName,
                    Status     = x.StatusCd,
                    CreateDttm = x.CreateDttm
                }).ToList();

                return(result);
            }
        }
Пример #16
0
        public ItemSearchGeneralResponseModel ItemAdvancedSearch(ItemSearchQueryModel item)
        {
            ItemSearchResultModel          singleItem = new ItemSearchResultModel();
            ItemSearchGeneralResponseModel result     = new ItemSearchGeneralResponseModel();

            result.SearchResult = new List <ItemSearchResultModel>();
            ItemSearchModel searchTerm = new ItemSearchModel();

            searchTerm.ModuleName    = "items";
            searchTerm.Id            = item.Id;
            searchTerm.ItemName      = item.ItemName;
            searchTerm.Brand         = item.Brand;
            searchTerm.CategoryId    = item.CategoryId;
            searchTerm.SubCategoryId = item.SubCategoryId;
            searchTerm.Location      = item.Location;
            searchTerm.Tag           = item.Tag;
            searchTerm.Sku           = item.Sku;
            searchTerm.StatusCd      = item.StatusCd;
            searchTerm.NextBatch     = (item.NextBatch - 1) * 10;

            var query      = _itemDataAccess.AdvancedSearchItems(searchTerm);
            var codeDetail = _itemDataAccess.GetAllItemStatus();

            result.RecordCount = query.RecordCount;

            for (int i = 0; i < query.SearchResult.Count; i++)
            {
                singleItem.Id         = query.SearchResult[i].Id;
                singleItem.ItemName   = query.SearchResult[i].ItemName;
                singleItem.Brand      = query.SearchResult[i].Brand;
                singleItem.Status     = codeDetail.Where(x => x.Id == query.SearchResult[i].Status).Select(x => x.CodeValue).FirstOrDefault();
                singleItem.CreateDttm = query.SearchResult[i].CreateDttm;

                result.SearchResult.Add(singleItem);
                singleItem = new ItemSearchResultModel();
            }

            return(result);
        }
Пример #17
0
        /// <summary>
        /// Search Statement
        /// </summary>
        /// <param name="command">Telerik GridCommand</param>
        /// <param name="searchModel">Item Search Model</param>
        /// <returns>return Search Statement</returns>
        private SearchStatementModel PrepareSearchStatement(GridCommand command, ItemSearchModel searchModel)
        {
            string whereStatement = string.Empty;

            IList <object> param = new List <object>();

            HqlStatementHelper.AddLikeStatement("ReferenceCode", searchModel.ReferenceCode, HqlStatementHelper.LikeMatchMode.Start, "i", ref whereStatement, param);
            HqlStatementHelper.AddLikeStatement("Code", searchModel.Code, HqlStatementHelper.LikeMatchMode.Start, "i", ref whereStatement, param);
            HqlStatementHelper.AddLikeStatement("Description", searchModel.Description, HqlStatementHelper.LikeMatchMode.Start, "i", ref whereStatement, param);
            HqlStatementHelper.AddEqStatement("IsActive", searchModel.IsActive, "i", ref whereStatement, param);
            string sortingStatement = HqlStatementHelper.GetSortingStatement(command.SortDescriptors);

            SearchStatementModel searchStatementModel = new SearchStatementModel();

            searchStatementModel.SelectCountStatement = selectCountStatement;
            searchStatementModel.SelectStatement      = selectStatement;
            searchStatementModel.WhereStatement       = whereStatement;
            searchStatementModel.SortingStatement     = sortingStatement;
            searchStatementModel.Parameters           = param.ToArray <object>();

            return(searchStatementModel);
        }
Пример #18
0
        public List <ItemViewModel> Search(int?page, ItemSearchModel model)
        {
            int?start;

            if (page != null)
            {
                start = (page - 1) * 200;
            }
            else
            {
                start = 0;
            }
            string strQuery = "SELECT item.`id`, item.`code`, item.`name`, cate.`name` category_name, item.`specification`, item.`description`  ";

            strQuery += " FROM `product_item` item LEFT JOIN (SELECT c.`id`, cpp.`name` AS category_parent_name, c.`name` FROM product_category c Left JOIN (SELECT cp.`name`, cp.`id` FROM product_category cp ) cpp on cpp.`id` = c.`parent_id`) cate ON item.`category_id` = cate.`id` WHERE 1 ";
            strQuery += ((model.category_id) != null) ? " AND (item.`category_id` = @category OR item.`category_id` IN (SELECT cate.`id` FROM product_category cate WHERE cate.`parent_id` = @category ))" : "";
            strQuery += (!string.IsNullOrEmpty(model.code)) ? " AND item.`code` LIKE @code" : "";
            strQuery += (!string.IsNullOrEmpty(model.name)) ? " AND item.`name` LIKE @name" : "";
            strQuery += " LIMIT @start,200 ";
            var result = _db.Query <ItemViewModel>(strQuery, new { code = '%' + model.code + '%', name = '%' + model.name + '%', category = model.category_id, start = start }).ToList();

            return(result);
        }
Пример #19
0
        private async Task <List <ItemViewModel> > GetItemsAsync(ItemSearchModel itemSearchModel)
        {
            string        actionPath      = "Listing/GetItems";
            ResponseModel responseContent = null;

            using (HttpClient client = new HttpClient())
            {
                client.BaseAddress = new Uri(CommonFunction.GetWebAPIBaseURL());
                client.DefaultRequestHeaders.Authorization = AuthHandler.AuthenticationHeader();

                //client.BaseAddress = new Uri(path);
                HttpResponseMessage response = await client.PostAsJsonAsync(actionPath, itemSearchModel);

                if (response.IsSuccessStatusCode)
                {
                    responseContent = await response.Content.ReadAsAsync <ResponseModel>();
                }
            }
            var json = JsonConvert.SerializeObject(responseContent.Data);
            var itemsResponseModel = JsonConvert.DeserializeObject <ItemsResponseModel>(json);

            return(itemsResponseModel.Items);
        }
Пример #20
0
        private async Task <ItemsResponseModel> GetItemsAsync(ItemSearchModel itemSearchModel)
        {
            try
            {
                if (itemSearchModel.TypeList == null)
                {
                    itemSearchModel.TypeList = new List <int>();
                }
                string        actionPath      = "Listing/GetItems";
                ResponseModel responseContent = null;
                using (HttpClient client = new HttpClient())
                {
                    client.BaseAddress = new Uri(CommonFunction.GetWebAPIBaseURL());
                    client.DefaultRequestHeaders.Authorization = AuthHandler.AuthenticationHeader();
                    HttpResponseMessage response = await client.PostAsJsonAsync(actionPath, itemSearchModel);

                    if (response.IsSuccessStatusCode)
                    {
                        responseContent = await response.Content.ReadAsAsync <ResponseModel>();
                    }
                }
                if (responseContent != null && responseContent.Success)
                {
                    var json = JsonConvert.SerializeObject(responseContent.Data);
                    var itemsResponseModel = JsonConvert.DeserializeObject <ItemsResponseModel>(json);
                    return(itemsResponseModel);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Пример #21
0
 public List <ItemViewModel> Search(ItemSearchModel model, int?page = null)
 {
     return(_itemDAO.Search(page, model));
 }
Пример #22
0
        public ActionResult _AjaxShortList(GridCommand command, ItemSearchModel searchModel)
        {
            SearchStatementModel searchStatementModel = this.PrepareShortSearchStatement(command, searchModel);

            return(PartialView(GetAjaxPageData <Item>(searchStatementModel, command)));
        }
Пример #23
0
 public int Count(ItemSearchModel model)
 {
     return(_itemDAO.Count(model));
 }
 public List <ItemViewModel> Search(ItemSearchModel model)
 {
     return(_itemDAO.Search(model));
 }
Пример #25
0
        public async Task <PartialViewResult> FetchItemsPartialAsync(ItemSearchModel itemSearchModel)
        {
            List <ItemViewModel> items = await GetItemsAsync(itemSearchModel);

            return(PartialView("~/Views/Delivery/_PopularItemsPartial.cshtml", items));
        }
Пример #26
0
        /// <summary>
        /// Return all Inventory Items matching the specified criteria.
        /// All results are returned if no criteria are specified
        /// </summary>
        /// <param name="searchModel"></param>
        /// <returns></returns>
        public List <InventoryItem> FindItemSearchResults(ItemSearchModel searchModel)
        {
            Context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;

            var results = Context.InventoryItems
                          .Include(x => x.ConsumptionEventsNavigation)
                          .Include(x => x.CategoryNavigation)
                          .Include(x => x.UnitNavigation)
                          .Include(x => x.StorageLocationNavigation)
                          .AsQueryable()
                          .AsNoTracking();

            // Code
            if (!String.IsNullOrEmpty(searchModel.Code))
            {
                results = results.Where(x => x.InventoryItemId.Contains(searchModel.Code));
            }

            // Description
            if (!String.IsNullOrEmpty(searchModel.Description))
            {
                results = results.Where(x => x.Description.Contains(searchModel.Description, StringComparison.InvariantCultureIgnoreCase));
            }

            // Date Added
            if (searchModel.DateCreatedStart != null && searchModel.DateCreatedEnd != null)
            {
                results = results.Where(x => x.DateAdded.Value.Date >= searchModel.DateCreatedStart.Value.Date && x.DateAdded.Value.Date <= searchModel.DateCreatedEnd.Value.Date);
            }
            else if (searchModel.DateCreatedStart != null && searchModel.DateCreatedEnd == null)
            {
                results = results.Where(x => x.DateAdded.Value.Date >= searchModel.DateCreatedStart.Value.Date);
            }
            else if (searchModel.DateCreatedStart == null && searchModel.DateCreatedEnd != null)
            {
                results = results.Where(x => x.DateAdded.Value.Date <= searchModel.DateCreatedEnd.Value.Date);
            }

            // Category
            if (searchModel.Category != null)
            {
                results = results.Where(x => x.InventoryCategoryId == searchModel.Category);
            }

            // Storage Location
            if (searchModel.StorageLocation != null)
            {
                results = results.Where(x => x.StorageLocationId == searchModel.StorageLocation);
            }

            // Customer Purchased For
            if (!String.IsNullOrEmpty(searchModel.CustomerPurchasedFor))
            {
                results = results.Where(x => x.CustomerPurchasedFor.Contains(searchModel.CustomerPurchasedFor, StringComparison.InvariantCultureIgnoreCase));
            }

            // Customer Reserved For
            if (!String.IsNullOrEmpty(searchModel.CustomerReservedFor))
            {
                results = results.Where(x => x.CustomerReservedFor.Contains(searchModel.CustomerReservedFor, StringComparison.InvariantCultureIgnoreCase));
            }

            // In Stock
            if (searchModel.InStock == "Yes")
            {
                results = results.Where(x => x.StockLevel == "In Stock");
            }
            else if (searchModel.InStock == "No")
            {
                results = results.Where(x => x.StockLevel != "In Stock");
            }

            var realResults = results.OrderBy(x => x.InventoryItemId).ToList();

            return(realResults);
        }
Пример #27
0
        private SearchStatementModel PrepareShortSearchStatement(GridCommand command, ItemSearchModel searchModel)
        {
            var    user           = SecurityContextHolder.Get();
            string whereStatement = " where 1=1 ";
            //whereStatement += @" and  exists (select 1 from UserPermissionView as p where p.UserId =" + user.Id + "and  p.PermissionCategoryType in (" + (int)com.Sconit.CodeMaster.PermissionCategoryType.Supplier + "," + (int)com.Sconit.CodeMaster.PermissionCategoryType.Customer + "," + (int)com.Sconit.CodeMaster.PermissionCategoryType.Region + ") and (p.PermissionCode = f.PartyFrom or p.PermissionCode = f.PartyTo ))";
            IList <object> param = new List <object>();

            if (!string.IsNullOrWhiteSpace(searchModel.Flow))
            {
                whereStatement += @" and exists( select 1 from FlowDetail as f where f.Item=i.Code and f.Flow=?  and exists
                ( select 1 from FlowMaster as fm where fm.Code=f.Flow and fm.Code=? and exists
                (select 1 from UserPermissionView as p where p.UserId =" + user.Id +
                                  " and (((fm.PartyFrom=p.PermissionCode or fm.PartyTo=p.PermissionCode ) and p.PermissionCategoryType in (3,4)) or  (fm.PartyTo=p.PermissionCode and p.PermissionCategoryType=2 )))))";
                param.Add(searchModel.Flow);
                param.Add(searchModel.Flow);
            }
            else
            {
                whereStatement += @" and exists( select 1 from FlowDetail as f where f.Item=i.Code   and exists
                ( select 1 from FlowMaster as fm where fm.Code=f.Flow and exists
                (select 1 from UserPermissionView as p where p.UserId =" + user.Id +
                                  " and (((fm.PartyFrom=p.PermissionCode or fm.PartyTo=p.PermissionCode ) and p.PermissionCategoryType in (3,4)) or  (fm.PartyTo=p.PermissionCode and p.PermissionCategoryType=2 )))))";
            }

            HqlStatementHelper.AddLikeStatement("ReferenceCode", searchModel.ReferenceCode, HqlStatementHelper.LikeMatchMode.Start, "i", ref whereStatement, param);
            HqlStatementHelper.AddEqStatement("Code", searchModel.Code, "i", ref whereStatement, param);
            HqlStatementHelper.AddEqStatement("IsActive", true, "i", ref whereStatement, param);
            string sortingStatement = HqlStatementHelper.GetSortingStatement(command.SortDescriptors);

            SearchStatementModel searchStatementModel = new SearchStatementModel();

            searchStatementModel.SelectCountStatement = selectCountStatement;
            searchStatementModel.SelectStatement      = selectStatement;
            searchStatementModel.WhereStatement       = whereStatement;
            searchStatementModel.SortingStatement     = sortingStatement;
            searchStatementModel.Parameters           = param.ToArray <object>();

            return(searchStatementModel);
        }