Exemplo n.º 1
0
        public PQGridData SearchProducts()
        {
            PQGridData data = new PQGridData();
            int page = 0;
            int pageSize = 30;
            int total = 0;
            int? category_id = null;
            string keyword = "";
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request = context.Request;
            string user_id = User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            ProductManager pdtManager = new ProductManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
            int.TryParse(request["page"],out page);
            int.TryParse(request["pageSize"],out pageSize);

            if (page <= 0)
            {
                page = 1;
            }

            if (pageSize <= 0)
            {
                pageSize = 30;
            }

            if (request["cid"] != null && request["cid"].ToString() != "" && request["cid"].ToString()!="0")
            {
                int cid = 0;
                int.TryParse(request["cid"],out cid);
                if (cid > 0) {
                    category_id = cid;
                }
            }
            keyword = request["keyword"];
            int[] sids = null;
            string suppliers = request["suppliers"];
            if (!string.IsNullOrEmpty(suppliers))
            {
                string[] ss = suppliers.Split(',');
                sids = new int[ss.Length];
                for (int i = 0; i < ss.Length; i++)
                {
                    sids[i] = int.Parse(ss[i]);
                }
            }
            bool includeProps = false;
            if (!string.IsNullOrEmpty(request["include_prop"]) && request["include_prop"] == "1")
            {
                includeProps = true;
            }
            else
            {
                includeProps = false;
            }

            int[] product_ids = null;
            if (!string.IsNullOrEmpty(request["product_ids"]))
            {
                product_ids = base.ConvertToIntArrar(request["product_ids"]);
            }

            bool paging = true;

            if (!string.IsNullOrEmpty(request["paging"]) && request["paging"]=="0")
            {
                paging=false;
            }

            bool includeSupplier = false;
            if (!string.IsNullOrEmpty(request["include_supplier"]) && request["include_supplier"] == "1")
            {
                includeSupplier = true;
            }
            else
            {
                includeSupplier = false;
            }
            data.data = pdtManager.SearchProducts(product_ids, sids, keyword, "", 0, 0, category_id, page, pageSize, out total, includeProps, paging, includeSupplier);
            data.totalRecords = total;
            data.curPage = page;
            data.pageSize = pageSize;
            return data;
        }