public void ExportXLS(ItemSearchModel searchModel)
 {
     int value = System.Convert.ToInt32(base.systemMgr.GetEntityPreferenceValue(EntityPreference.CodeEnum.MaxRowSizeOnPage));
     GridCommand command = new GridCommand();
     command.Page = 1;
     command.PageSize = value;
     SearchStatementModel searchStatementModel = this.PrepareSearchStatement(command, searchModel);
     GridModel<Item> gridModel = GetAjaxPageData<Item>(searchStatementModel, command);
     var itemCategoryList = this.genericMgr.FindAll<ItemCategory>();
     foreach (var listdata in gridModel.Data)
     {
         listdata.ItemCategoryDesc = GetItemCategory(listdata.ItemCategory, Sconit.CodeMaster.SubCategory.ItemCategory, itemCategoryList).Description;
         listdata.MaterialsGroupDesc = GetItemCategory(listdata.MaterialsGroup, Sconit.CodeMaster.SubCategory.MaterialsGroup, itemCategoryList).Description;
     }
     var fileName = string.Format("Item.xls");
     ExportToXLS<Item>(fileName, gridModel.Data.ToList());
 }
        /// <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.Anywhere, "i", ref whereStatement, param);
            HqlStatementHelper.AddEqStatement("IsActive", searchModel.IsActive, "i", ref whereStatement, param);
            HqlStatementHelper.AddEqStatement("IsVirtual", searchModel.IsVirtual, "i", ref whereStatement, param);
            if (!string.IsNullOrWhiteSpace(searchModel.ItemCategory))
                HqlStatementHelper.AddEqStatement("ItemCategory", searchModel.ItemCategory, "i", ref whereStatement, param);
            if (!string.IsNullOrWhiteSpace(searchModel.MaterialsGroup))
                HqlStatementHelper.AddEqStatement("MaterialsGroup", searchModel.MaterialsGroup, "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;
        }
 public ActionResult List(GridCommand command, ItemSearchModel searchModel)
 {
     SearchCacheModel searchCacheModel = this.ProcessSearchModel(command, searchModel);
     if (searchCacheModel.isBack == true)
     {
         ViewBag.Page = searchCacheModel.Command.Page==0 ? 1 : searchCacheModel.Command.Page;
     }
     ViewBag.PageSize = base.ProcessPageSize(command.PageSize);
     return View();
 }
 public ActionResult _AjaxList(GridCommand command, ItemSearchModel searchModel)
 {
     this.GetCommand(ref command, searchModel);
     SearchStatementModel searchStatementModel = this.PrepareSearchStatement(command, searchModel);
     GridModel<Item> gridModel = GetAjaxPageData<Item>(searchStatementModel, command);
     var itemCategoryList = this.genericMgr.FindAll<ItemCategory>();
     foreach (var listdata in gridModel.Data)
     {
         listdata.ItemCategoryDesc = GetItemCategory(listdata.ItemCategory,Sconit.CodeMaster.SubCategory.ItemCategory,itemCategoryList).Description;
         listdata.MaterialsGroupDesc = GetItemCategory(listdata.MaterialsGroup, Sconit.CodeMaster.SubCategory.MaterialsGroup, itemCategoryList).Description;
     }
     return PartialView(gridModel);
 }
        /// <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.AddLikeStatement("ShortCode", searchModel.ShortCode, 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;
        }
        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("ShortCode", searchModel.ShortCode, "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;
        }
        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.ShortCode))
            {
                hql += " and i.ShortCode=? ";
                param.Add(searchModel.ShortCode);
            }
            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);
        }
 public ActionResult _AjaxShortList(GridCommand command, ItemSearchModel searchModel)
 {
     SearchStatementModel searchStatementModel = this.PrepareShortSearchStatement(command, searchModel);
     return PartialView(GetAjaxPageData<Item>(searchStatementModel, command));
 }
 public ActionResult ShortList(GridCommand command, ItemSearchModel searchModel)
 {
     SearchCacheModel searchCacheModel = this.ProcessSearchModel(command, searchModel);
     ViewBag.PageSize = base.ProcessPageSize(command.PageSize);
     return View();
 }
Exemple #10
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.ShortCode))
     {
         hql += string.Format(" and i.ShortCode like '{0}%' ", searchModel.ShortCode);
     }
     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);
 }
Exemple #11
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();
 }