Ejemplo n.º 1
0
        public HttpResponseBase GetCatagory(string id = "true")
        {
            List<ProductCategory> categoryList = new List<ProductCategory>();
            List<ProductCategoryCustom> cateList = new List<ProductCategoryCustom>();
            string resultStr = "";
            BLL.gigade.Model.Vendor vendorModel = (BLL.gigade.Model.Vendor)Session["vendor"];
            try
            {
                _procateMgr = new ProductCategoryMgr(connectionString);
                categoryList = _procateMgr.QueryAll(new ProductCategory { });
                cateList = getCate(categoryList, "5");
                List<ProductCategorySetTemp> TempresultList = new List<ProductCategorySetTemp>();
                List<ProductCategorySet> resultList = new List<ProductCategorySet>();
                ProductCategorySetTemp query = new ProductCategorySetTemp();
                if (!string.IsNullOrEmpty(Request.Params["ProductId"]))
                {
                    uint product_id = 0;
                    if (uint.TryParse(Request.Params["ProductId"], out product_id)) //正式表數據
                    {
                        _categorySetMgr = new ProductCategorySetMgr(connectionString);
                        resultList = _categorySetMgr.Query(new ProductCategorySet { Product_Id = uint.Parse(Request.Params["ProductId"]) });
                        TempresultList = null;
                    }
                    else
                    {
                        resultList = null;
                        query.Product_Id = Request.Params["ProductId"];
                        _productTempMgr = new ProductTempMgr(connectionString);
                        ProductTemp productT = _productTempMgr.GetProTempByVendor(new ProductTemp { Product_Id = Request.Params["ProductId"] }).FirstOrDefault();
                        if (productT != null)
                        {
                            query.Combo_Type = productT.Combo_Type;
                        }
                        else
                        {
                            query.Combo_Type = COMBO_TYPE;
                        }
                        query.Writer_Id = (int)vendorModel.vendor_id;

                        _categoryTempSetMgr = new ProductCategorySetTempMgr(connectionString);
                        TempresultList = (from c in _categoryTempSetMgr.QueryByVendor(query)
                                          select new
                                          {
                                              Id = c.Id,
                                              Product_Id = c.Product_Id,
                                              Category_Id = c.Category_Id,
                                              Brand_Id = c.Brand_Id
                                          }).ToList().ConvertAll<ProductCategorySetTemp>(m => new ProductCategorySetTemp
                                          {
                                              Id = m.Id,

                                              Product_Id = m.Product_Id,
                                              Category_Id = m.Category_Id,
                                              Brand_Id = m.Brand_Id
                                          });
                    }
                }

                //調試resultlist是否為空
                GetCategoryList(categoryList, ref cateList, TempresultList, resultList);

                List<ProductCategoryCustom> cateListResult = new List<ProductCategoryCustom>();
                cateListResult = getCate(categoryList, "0");
                cateListResult[0].children = getCate(categoryList, cateListResult[0].id.ToString());
                int cateLen = cateListResult[0].children.Count;
                int i = 0;
                while (cateLen > 0)
                {
                    if (cateListResult[0].children[i].id == "5")
                    {
                        i++;
                    }
                    else
                    {
                        cateListResult[0].children.Remove(cateListResult[0].children[i]);
                    }
                    cateLen--;
                }
                cateListResult[0].children[0].children = cateList;
                resultStr = JsonConvert.SerializeObject(cateListResult);
                resultStr = resultStr.Replace("Checked", "checked");
            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
            }
            this.Response.Clear();
            this.Response.Write(resultStr);
            this.Response.End();
            return this.Response;
        }
        public HttpResponseBase GetCatagory()
        {
            List<ProductCategory> categoryList = new List<ProductCategory>();
            List<ProductCategoryCustom> cateList = new List<ProductCategoryCustom>();
            string resultStr = "";
            try
            {
                _procateMgr = new ProductCategoryMgr(connectionString);

                categoryList = _procateMgr.QueryAll(new ProductCategory { });

                cateList = getCate(categoryList, "5");
                List<ProductCategorySetTemp> TempresultList = new List<ProductCategorySetTemp>();
                List<ProductCategorySet> resultList = new List<ProductCategorySet>();
                string Ven_product_id = string.Empty;
                if (!string.IsNullOrEmpty(Request.Params["ProductId"]))
                {
                    Ven_product_id = Request.Params["ProductId"];
                }
                //if (!string.IsNullOrEmpty(Request.Form["OldProductId"]))
                //{
                //    Ven_product_id = Request.Form["OldProductId"];
                //}
                BLL.gigade.Model.Vendor vendorModel = (BLL.gigade.Model.Vendor)Session["vendor"];
                int writd_Id = Convert.ToInt32(vendorModel.vendor_id);

                ProductCategorySetTemp query = new ProductCategorySetTemp { Writer_Id = writd_Id, Combo_Type = COMBO_TYPE, Product_Id = Ven_product_id };
                _categoryTempSetMgr = new ProductCategorySetTempMgr(connectionString);

                TempresultList = (from c in _categoryTempSetMgr.QueryByVendor(query)
                                  select new
                                  {
                                      Id = c.Id,
                                      Product_Id = c.Product_Id,
                                      Category_Id = c.Category_Id,
                                      Brand_Id = c.Brand_Id
                                  }).ToList().ConvertAll<ProductCategorySetTemp>(m => new ProductCategorySetTemp()
                              {
                                  Id = m.Id,
                                  Product_Id = m.Product_Id,
                                  Category_Id = m.Category_Id,
                                  Brand_Id = m.Brand_Id
                              });


                GetCategoryList(categoryList, ref cateList, TempresultList, resultList);
                List<ProductCategoryCustom> cateListResult = new List<ProductCategoryCustom>();
                cateListResult = getCate(categoryList, "0");
                cateListResult[0].children = getCate(categoryList, cateListResult[0].id.ToString());
                int cateLen = cateListResult[0].children.Count;
                int i = 0;
                while (cateLen > 0)
                {
                    if (cateListResult[0].children[i].id.ToString() == "5")
                    {
                        i++;
                    }
                    else
                    {
                        cateListResult[0].children.Remove(cateListResult[0].children[i]);
                    }
                    cateLen--;
                }
                cateListResult[0].children[0].children = cateList;
                resultStr = JsonConvert.SerializeObject(cateListResult);
                resultStr = resultStr.Replace("Checked", "checked");
            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
            }

            this.Response.Clear();
            this.Response.Write(resultStr);
            this.Response.End();
            return this.Response;
        }