public HttpResponseBase GetCatagory(string id = "true")
        {
            List<ProductCategory> categoryList = new List<ProductCategory>();
            List<ProductCategoryCustom> cateList = new List<ProductCategoryCustom>();
            List<ProductCategorySet> resultList = new List<ProductCategorySet>();

            _procateMgr = new ProductCategoryMgr(connectionString);
            ParameterMgr parameterMgr = new ParameterMgr(connectionString);

            string resultStr = "";
            try
            {
                uint rootId = 0;
                categoryList = _procateMgr.QueryAll(new ProductCategory { });
                List<Parametersrc> fatherIdResult = parameterMgr.QueryUsed(new Parametersrc { ParameterType = "event_type", Used = 1, ParameterCode = "CXXM" });
                rootId = Convert.ToUInt32(fatherIdResult[0].ParameterProperty);
                cateList = getCate(categoryList, rootId);
                GetCategoryList(categoryList, ref cateList, resultList);
                resultStr = JsonConvert.SerializeObject(cateList);
            }
            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;
        }
예제 #2
0
        /// <summary>
        /// 獲取商品數據
        /// </summary>
        /// <returns></returns>
        public HttpResponseBase GetTrialProdCateList()
        {
            List<TrialProdCateQuery> store = new List<TrialProdCateQuery>();
            string json = string.Empty;
            try
            {
                TrialProdCateQuery query = new TrialProdCateQuery();
                #region 獲取query對象數據
                query.Start = Convert.ToInt32(Request.Params["start"] ?? "0");

                if (!string.IsNullOrEmpty(Request.Form["limit"]))
                {
                    query.Limit = Convert.ToInt32(Request.Params["limit"]);
                }
                #endregion
                _trialProdMgr = new TrialProdCateMgr(mySqlConnectionString);
                _prodMgr = new ProductMgr(mySqlConnectionString);
                prodCateMgr = new ProductCategoryMgr(mySqlConnectionString);//實例化對象mgr
                _giftMgr = new PromotionsAmountGiftMgr(mySqlConnectionString);
                _trialMgr = new PromotionsAmountTrialMgr(mySqlConnectionString);
                int totalCount = 0;
                store = _trialProdMgr.Query(query, out totalCount);

                foreach (var item in store)
                {
                    item.product_name = _prodMgr.QueryClassify(Convert.ToUInt32(item.product_id)).Product_Name;
                    item.category_name = prodCateMgr.QueryAll(new ProductCategory { category_id = item.category_id }).FirstOrDefault().category_name;
                    if (item.event_id.StartsWith("T1") || item.event_id.StartsWith("T2"))
                    {
                        int id = Convert.ToInt16(item.event_id.Substring(2).ToString());
                        item.event_name = _trialMgr.GetModel(id).name;
                    }
                    if (item.event_id.StartsWith("G3"))
                    {
                        int id = Convert.ToInt16(item.event_id.Substring(2).ToString());
                        item.event_name = _giftMgr.GetModel(id).name;
                    }
                }
                IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
                //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式     
                timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
                json = "{success:true,totalCount:" + totalCount + ",data:" + JsonConvert.SerializeObject(store, Formatting.Indented, timeConverter) + "}";//返回json數據
            }

            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);
                json = "{success:false}";
            }


            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
예제 #3
0
        public HttpResponseBase GetCatagory()
        {
            List<ProductCategory> categoryList = new List<ProductCategory>();
            List<ProductCategoryCustom> cateList = new List<ProductCategoryCustom>();
            int categoryType = 2; //用來區別查詢所有節點還是查詢新館的節點 //edit by wwei0216w 2014/12/25
            //從後臺獲取查詢所有節點還是查詢新館的節點
            categoryType = Request["categoryType"] == null ? 2 : Convert.ToInt32(Request["categoryType"]);

            string resultStr = "";
            try
            {
                _procateMgr = new ProductCategoryMgr(connectionString);
                categoryList = _procateMgr.QueryAll(new ProductCategory { });
                cateList = getCate(categoryList, 0);
                List<ProductCategorySet> resultList = new List<ProductCategorySet>();
                if (!string.IsNullOrEmpty(Request.Params["ProductId"]))
                {
                    _categorySetMgr = new ProductCategorySetMgr(connectionString);
                    resultList = _categorySetMgr.Query(new ProductCategorySet { Product_Id = uint.Parse(Request.Params["ProductId"]) });

                }
                else
                {
                    Caller _caller = (Session["caller"] as Caller);
                    ProductCategorySetTemp query = new ProductCategorySetTemp { Writer_Id = _caller.user_id, Combo_Type = COMBO_TYPE };
                    _categoryTempSetMgr = new ProductCategorySetTempMgr(connectionString);
                    if (!string.IsNullOrEmpty(Request.Params["OldProductId"]))//edit by xiaohui 2014/09/24
                    {
                        query.Product_Id = Request.Params["OldProductId"];
                    }
                    resultList = (from c in _categoryTempSetMgr.Query(query)
                                  select new
                                  {
                                      Id = c.Id,
                                      Product_Id = c.Product_Id,
                                      Category_Id = c.Category_Id,
                                      Brand_Id = c.Brand_Id
                                  }).ToList().ConvertAll<ProductCategorySet>(m => new ProductCategorySet()
                                  {
                                      Id = m.Id,
                                      Product_Id = uint.Parse(m.Product_Id),
                                      Category_Id = m.Category_Id,
                                      Brand_Id = m.Brand_Id
                                  });
                }


                GetCategoryList(categoryList, ref cateList, resultList);

                switch (categoryType)
                {
                    case 0:
                        resultStr = JsonConvert.SerializeObject(cateList);
                        break;
                    case 1: //等於754      
                        cateList.FindAll(m => m.id == "2")[0].children.RemoveAll(m => m.id != "754");//移除新館節點
                        resultStr = JsonConvert.SerializeObject(cateList);
                        break;
                    case 2:
                        cateList.FindAll(m => m.id == "2")[0].children.RemoveAll(m => m.id == "754");//移除新館節點
                        resultStr = JsonConvert.SerializeObject(cateList);
                        break;
                }
                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;
        }
예제 #4
0
        /// <summary>
        /// 獲取商品數據
        /// </summary>
        /// <returns></returns>
        public HttpResponseBase UpdateTrialProdCate()
        {
            List<TrialProdCateQuery> storeLi = new List<TrialProdCateQuery>();
            string json = string.Empty;
            try
            {
                _pcsMgr = new ProductCategorySetMgr(mySqlConnectionString);
                _trialProdMgr = new TrialProdCateMgr(mySqlConnectionString);
                //獲取新館類別

                prodCateMgr = new ProductCategoryMgr(mySqlConnectionString);//實例化對象mgr
                List<ProductCategory> category = prodCateMgr.QueryAll(new ProductCategory { category_display = 0 });//獲取所有的類別 顯示的隱藏的

                ProductCategory useCate = prodCateMgr.QueryAll(new ProductCategory { category_father_id = 754, category_name = "用品館" }).FirstOrDefault();
                string cateUseStr = string.Empty;//設定對象獲取用品館所有子類別
                GetAllCategory_id(category, useCate.category_id, ref cateUseStr);//設定對象獲取用品館所有子類別 顯示的

                ProductCategory eatCate = prodCateMgr.QueryAll(new ProductCategory { category_father_id = 754, category_name = "食品館" }).FirstOrDefault();
                string cateEatStr = string.Empty;//設定對象獲取食品館所有子類別
                GetAllCategory_id(category, eatCate.category_id, ref cateEatStr);//設定對象獲取食品館所有子類別 顯示的
                _prodMgr = new ProductMgr(mySqlConnectionString);

                //找到商品
                List<TrialProdCateQuery> store = _trialProdMgr.UadateTrialProd();

                Product prodModel = new Product();

                //找到商品新館所有類別
                foreach (var item in store)
                {

                    if (item.product_id != 0)
                    {
                        prodModel = _prodMgr.QueryClassify(Convert.ToUInt32(item.product_id));

                        DataTable dt = new DataTable();
                        if (prodModel != null)
                        {
                            if (prodModel.Prod_Classify == 10)
                            {
                                item.type = 1;
                                dt = _pcsMgr.GetCateByProds(item.product_id.ToString(), cateEatStr);

                                //找到大類類別
                                bool isTrue = false;
                                if (dt.Rows.Count != 0)
                                {
                                    foreach (DataRow row in dt.Rows)
                                    {
                                        ProductCategory pcModel = new ProductCategory();
                                        GetFatherCategory_id(category, ref isTrue, eatCate.category_id, Convert.ToUInt32(row["category_id"]), ref  pcModel);
                                        if (isTrue && pcModel != null)
                                        {
                                            if (item.category_id == 0)
                                            {
                                                item.category_id = pcModel.category_id;
                                                storeLi.Add(item);
                                            }
                                            else
                                            {
                                                if (pcModel.category_id != item.category_id)
                                                {
                                                    TrialProdCateQuery queryItem = new TrialProdCateQuery();
                                                    queryItem.product_id = item.product_id;
                                                    queryItem.event_id = item.event_id;
                                                    queryItem.type = item.type;
                                                    queryItem.start_date = item.start_date;
                                                    queryItem.end_date = item.end_date;
                                                    queryItem.category_id = pcModel.category_id;
                                                    List<TrialProdCateQuery> CFLi = storeLi.FindAll(p => p.category_id == queryItem.category_id && p.product_id == queryItem.product_id && p.type == queryItem.type && p.event_id == queryItem.event_id).ToList();
                                                    if (CFLi.Count == 0)
                                                    {
                                                        storeLi.Add(queryItem);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            else if (prodModel.Prod_Classify == 20)
                            {
                                item.type = 2;
                                dt = _pcsMgr.GetCateByProds(item.product_id.ToString(), cateUseStr);
                                //找到大類類別
                                bool isTrue = false;
                                if (dt.Rows.Count != 0)
                                {
                                    foreach (DataRow row in dt.Rows)
                                    {
                                        ProductCategory pcModel = new ProductCategory();
                                        GetFatherCategory_id(category, ref isTrue, useCate.category_id, Convert.ToUInt32(row["category_id"]), ref  pcModel);
                                        if (isTrue && pcModel != null)
                                        {
                                            if (item.category_id == 0)
                                            {
                                                item.category_id = pcModel.category_id;
                                                storeLi.Add(item);
                                            }
                                            else
                                            {
                                                if (pcModel.category_id != item.category_id)
                                                {
                                                    TrialProdCateQuery queryItem = new TrialProdCateQuery();
                                                    queryItem.product_id = item.product_id;
                                                    queryItem.event_id = item.event_id;
                                                    queryItem.type = item.type;
                                                    queryItem.start_date = item.start_date;
                                                    queryItem.end_date = item.end_date;
                                                    queryItem.category_id = pcModel.category_id;
                                                    List<TrialProdCateQuery> CFLi = storeLi.FindAll(p => p.category_id == queryItem.category_id && p.product_id == queryItem.product_id && p.type == queryItem.type && p.event_id == queryItem.event_id).ToList();
                                                    if (CFLi.Count == 0)
                                                    {
                                                        storeLi.Add(queryItem);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                        }
                    }
                }


                //插入數據到主表trial_prod_cate
                if (_trialProdMgr.InsertTrialProd(storeLi))
                {
                    json = "{success:true}";
                }
                else
                {
                    json = "{success:false}";
                }
            }
            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);
                json = "{success:false}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
        public HttpResponseBase GetProductByCategorySet()
        {
            string resultStr = "{success:false,msg:0,item:[]}";
            try
            {
                _productCategoryBannerImplMgr = new ProductCategoryBannerMgr(mySqlConnectionString);
                if (!string.IsNullOrEmpty(Request.Params["banner_cateid"].ToString()))
                {
                    uint isTryUint = 0;
                    if (uint.TryParse(Request.Params["banner_cateid"].ToString(), out isTryUint))
                    {
                        uint banner_cateid = Convert.ToUInt32(Request.Params["banner_cateid"].ToString());

                        //獲取新館類別
                        uint fatherid = _productCategoryBannerImplMgr.GetXGCate().FirstOrDefault().category_id;//獲取754
                        prodCateMgr = new ProductCategoryMgr(mySqlConnectionString);//實例化對象mgr
                        List<ProductCategory> category = prodCateMgr.QueryAll(new ProductCategory { category_display = 0 });//獲取所有的類別 包括隱藏和顯示的
                        string cateStr = string.Empty;//設定對象保存新館所有類別
                        GetAllCategory_id(category, fatherid, ref cateStr);//獲取所有新館類別

                        if (!string.IsNullOrEmpty(cateStr))//專區類別處理數據
                        {
                            DataTable dt = new DataTable();
                            List<ProductCategory> query = category.FindAll(p => p.category_id == banner_cateid).ToList();//判斷是否是類別專區 
                            if (query.Count != 0) //新館專區類別設定
                            {
                                dt = _productCategoryBannerImplMgr.isSaleProd(cateStr, banner_cateid);//獲取所有類別
                            }
                            else//不是專區的類別數據  優惠專區999998  優惠專區頁999997 優惠專區頁999996 產地直送999995
                            {
                                dt = _productCategoryBannerImplMgr.GetXGCateByBanner(cateStr, banner_cateid);
                            }

                            string cateStrs = string.Empty;//存儲所有新館類別樹狀結構數據

                            //根據新館子元素找父級元素 新館樹狀結構
                            if (dt.Rows.Count != 0)
                            {
                                bool isTrue = false;
                                string cateStrTree = string.Empty;

                                foreach (DataRow row in dt.Rows)
                                {
                                    if (Convert.ToUInt32(Convert.ToUInt32(row["category_id"])) != banner_cateid)
                                    {
                                        GetFatherCategory_id(category, ref isTrue, fatherid, Convert.ToUInt32(row["category_id"]), ref cateStrTree);
                                        if (isTrue && cateStrTree != null)
                                        {
                                            cateStrs += Convert.ToUInt32(row["category_id"]);
                                            cateStrs += ",";
                                        }
                                    }
                                }
                                cateStrs += cateStrTree;

                                if (!string.IsNullOrEmpty(cateStrs))
                                {
                                    cateStrs = cateStrs.Substring(0, cateStrs.Length - 1);
                                    List<ProductCategory> li = _productCategoryBannerImplMgr.GetProductCategoryInfo(cateStrs);
                                    IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
                                    //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式     
                                    timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
                                    resultStr = "{success:true,item:" + JsonConvert.SerializeObject(li, Formatting.Indented, timeConverter) + "}";//返回json數據

                                }
                            }
                            else
                            {
                                resultStr = "{success:true,totalCount:0,item:[]}";
                            }
                        }
                    }
                }


            }
            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);
                resultStr = "{success:false,msg:0,item:[]}";
            }


            this.Response.Clear();
            this.Response.Write(resultStr);
            this.Response.End();
            return this.Response;
        }
        public HttpResponseBase GetBannerCateBrand()
        {
            string json = "{success:true}";
            _cateBrandMgr = new ProductCategoryBrandMgr(mySqlConnectionString);
            _productCategoryBannerImplMgr = new ProductCategoryBannerMgr(mySqlConnectionString);
            _parameterMgr = new ParameterMgr(mySqlConnectionString);
            try
            {
                if (!string.IsNullOrEmpty(Request.Params["banner_cateid"].ToString()))
                {
                    uint isTryUint = 0;
                    if (uint.TryParse(Request.Params["banner_cateid"].ToString(), out isTryUint))
                    {
                        int banner_cateid = Convert.ToInt32(Request.Params["banner_cateid"].ToString());

                        //獲取新館類別
                        uint XGCateId = _productCategoryBannerImplMgr.GetXGCate().FirstOrDefault().category_id;//獲取754
                        prodCateMgr = new ProductCategoryMgr(mySqlConnectionString);//實例化對象mgr
                        List<ProductCategory> category = prodCateMgr.QueryAll(new ProductCategory { category_display = 1 });//獲取所有的類別 包括隱藏和顯示的
                        List<ProductCategory> cateXGlist = new List<ProductCategory>();//設定對象保存新館所有類別
                        GetAllCategory_idList(category, XGCateId, ref cateXGlist);//獲取所有新館類別
                        List<Parametersrc> pali = _parameterMgr.GetElementType("banner_cate");

                        List<ProductCategoryBrand> XGCateBrandResult = new List<ProductCategoryBrand>();
                        if (pali.Count != 0)
                        {
                            if (cateXGlist != null)
                            {


                                List<ProductCategory> query = category.FindAll(p => p.category_id == banner_cateid).ToList();//判斷是否是類別專區 
                                List<ProductCategoryBrand> ProList = new List<ProductCategoryBrand>();

                                if (query.Count != 0) //新館專區類別設定
                                {
                                    ProList = _cateBrandMgr.GetSaledProduct(XGCateId, banner_cateid);//獲取所有有效商品 以及對應的品牌和館別
                                }
                                else
                                {
                                    ProList = _cateBrandMgr.GetProductByCondi(XGCateId, banner_cateid);
                                }
                                //ProList = _cateBrandMgr.GetSaledProduct(XGCateId);//獲取所有有效商品

                                foreach (ProductCategoryBrand itemcate in ProList)
                                {
                                    ProductCategory querySingle = cateXGlist.Find(p => p.category_id == itemcate.category_id);
                                    if (querySingle != null)
                                    {
                                        itemcate.category_name = querySingle.category_name;
                                        XGCateBrandResult.Add(itemcate);
                                        GetFatherCateBrand(cateXGlist, XGCateId, itemcate, ref  XGCateBrandResult);
                                    }
                                }
                                json = "{success:true,item:" + JsonConvert.SerializeObject(XGCateBrandResult, Formatting.Indented) + "}";//返回json數據
                            }
                        }
                    }
                }
            }
            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);
                json = "{success:false,data:[]}";
            }


            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
예제 #7
0
        public HttpResponseBase GetProductByCategorySet()
        {
            string resultStr = "{success:false}";
            string str = string.Empty;
            try
            {
                _productMgr = new ProductMgr(mySqlConnectionString);
                ProductQuery query = new ProductQuery();
                query.isjoincate = true;
                query.IsPage = true;
                query.Start = int.Parse(Request.Form["start"] ?? "0");
                if (!string.IsNullOrEmpty(Request.Form["limit"]))
                {
                    query.Limit = Convert.ToInt32(Request.Form["limit"].ToString());
                }
                else
                {
                    query.Limit = 500;
                }
                uint isTryUint = 0;
                if (uint.TryParse(Request.Params["status"].ToString(), out isTryUint))
                {
                    query.Product_Status = Convert.ToUInt32(Request.Params["status"].ToString());
                }
                if (uint.TryParse(Request.Params["brand_id"].ToString(), out isTryUint))
                {
                    query.Brand_Id = Convert.ToUInt32(Request.Params["brand_id"].ToString());
                }
                else
                {
                    if (!string.IsNullOrEmpty(Request.Params["class_id"]))
                    {
                        VendorBrandSetMgr vbsMgr = new VendorBrandSetMgr(mySqlConnectionString);
                        VendorBrandSet vbs = new VendorBrandSet();
                        vbs.class_id = Convert.ToUInt32(Request.Form["class_id"]);
                        List<VendorBrandSet> vbsList = vbsMgr.Query(vbs);
                        foreach (VendorBrandSet item in vbsList)
                        {
                            query.brandArry += item.brand_id;
                            query.brandArry += ",";
                        }
                        query.brandArry = query.brandArry.Substring(0, query.brandArry.Length - 1);
                    }

                }
                if (!string.IsNullOrEmpty(Request.Params["keyCode"].ToString()))
                {
                    if (uint.TryParse(Request.Params["keyCode"].ToString(), out isTryUint))
                    {
                        query.Product_Id = Convert.ToUInt32(Request.Params["keyCode"].ToString());
                    }
                    else
                    {
                        query.Product_Name = Request.Params["keyCode"].ToString();
                    }
                }

                if (!string.IsNullOrEmpty(Request.Params["category_id"].ToString()))
                {
                    if (uint.TryParse(Request.Params["category_id"].ToString(), out isTryUint))
                    {
                        //判斷是否是父節點,若是則獲取所有的category_id
                        prodCateMgr = new ProductCategoryMgr(mySqlConnectionString);
                        List<ProductCategory> category = prodCateMgr.QueryAll(new ProductCategory());
                        GetAllCategory_id(category, Convert.ToUInt32(Request.Params["category_id"].ToString()), ref str);
                        query.categoryArry = str;
                    }
                }
                int totalCount = 0;
                List<ProductDetailsCustom> prods = _productMgr.GetAllProList(query, out totalCount);
                resultStr = "{succes:true,totalCount:" + totalCount + ",item:" + JsonConvert.SerializeObject(prods) + "}";
            }
            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);
                resultStr = "{succes:false,totalCount:0,item:[]}";
            }


            this.Response.Clear();
            this.Response.Write(resultStr);
            this.Response.End();
            return this.Response;
        }
예제 #8
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;
        }
예제 #10
0
        public void PrepareData(List<CombinationExcel> source)
        {
            if (source != null)
            {
                source.ForEach(m => m.Validate());
                var parents = source.Where(m => m.combination.Trim() != "299" && string.IsNullOrEmpty(m.msg));

                _productMgr = new ProductMgr(strConn);
                _productItemMgr = new ProductItemMgr(strConn);
                _vendorMgr = new VendorMgr(strConn);
                _vendorBrandMgr = new VendorBrandMgr(strConn);
                _siteMgr = new SiteMgr(strConn);
                _productMigrationMgr = new ProductMigrationMgr(strConn);
                _productComboMgr = new ProductComboMgr(strConn);
                _cateMgr = new ProductCategoryMgr(strConn);
                _productCategorySetMgr = new ProductCategorySetMgr(strConn);
                _productNoticeSetMgr = new ProductNoticeSetMgr(strConn);
                _productTagSetMgr = new ProductTagSetMgr(strConn);
                _productPictureMgr = new ProductPictureMgr(strConn);
                _productStatusHistoryMgr = new ProductStatusHistoryMgr(strConn);

                foreach (var parent in parents)
                {
                    form.change(1);
                    uint product_id = uint.Parse(parent.product_id);
                    #region Product

                    ProductMigrationMap prodMigra = _productMigrationMgr.GetSingle(new ProductMigrationMap { temp_id = parent.is_exist.ToUpper().Trim().Equals("OLD") ? parent.product_id : parent.temp_id });
                    if (prodMigra != null)
                    {
                        parent.msg = "此記錄暫時編號(temp_id)已經存在;";
                        continue;
                    }

                    Product newPro = parent.is_exist.ToUpper().Trim() == "OLD" ? _productMgr.Query(new Product { Product_Id = product_id }).FirstOrDefault() : new Product();
                    if (newPro == null)
                    {
                        parent.msg = "商品不存在";
                        continue;
                    }
                    newPro.Product_Name = parent.product_name.Trim();
                    VendorBrand brand = _vendorBrandMgr.GetProductBrand(new VendorBrand { Brand_Name = parent.brand_name.Trim() });
                    if (brand == null)
                    {
                        parent.msg = "品牌不存在";
                        continue;
                    }
                    newPro.Brand_Id = brand.Brand_Id;
                    switch (parent.combination.Trim())
                    {
                        case "2":
                            newPro.Combination = 2; break;
                        case "3":
                            newPro.Combination = 3; break;
                        case "4":
                            newPro.Combination = 4; break;
                        default: break;
                    }
                    switch (parent.status.Trim().ToUpper())
                    {
                        case "SAME":
                            break;
                        case "ON":
                            newPro.Product_Status = 5; break;
                        case "OFF":
                            newPro.Product_Status = 6; break;
                        case "NEW":
                            newPro.Product_Status = 0; break;
                        default:
                            break;
                    }
                    newPro.Price_type = 1;
                    newPro.Product_Spec = 0;
                    newPro.Spec_Title_1 = string.Empty;
                    newPro.Spec_Title_2 = string.Empty;
                    newPro.Ignore_Stock = 0;// parent.ignore_stock.ToUpper().Trim() == "Y" ? 1 : 0;
                    newPro.Shortage = 0;// parent.shortage.ToUpper().Trim() == "Y" ? 1 : 0;
                    newPro.Cate_Id = parent.cate_id.Trim();
                    var vendor = _vendorMgr.GetSingle(new Vendor { vendor_id = brand.Vendor_Id });
                    if (vendor == null)
                    {
                        parent.msg = "供應商不存在";
                        continue;
                    }
                    newPro.user_id = vendor.product_manage;
                    if (!string.IsNullOrEmpty(parent.service_fee))
                    { 
                        uint bag_check_money=0;
                        uint.TryParse(parent.service_fee,out bag_check_money);
                        newPro.Bag_Check_Money = bag_check_money;
                    }
                    #endregion

                    bool result = true;
                    ArrayList sqls = new ArrayList();
                    #region PriceMaster

                    Site site = _siteMgr.Query(new Site { Site_Name = parent.site.Trim() }).FirstOrDefault();
                    if (site == null)
                    {
                        parent.msg = "價格檔站臺不存在";
                        result = false;
                        break;
                    }
                    List<PriceMaster> priceMasters = new List<PriceMaster>();
                    //首先默認加入一筆吉甲地站臺
                    PriceMaster newPriceMaster = new PriceMaster { site_id = 1, user_level = 1, same_price = 1, accumulated_bonus = 1, default_bonus_percent = 1, bonus_percent = 1 };
                    newPriceMaster.product_name = newPro.Product_Name;
                    newPriceMaster.price_status = 1;

                    var item = _productItemMgr.Query(new ProductItem { Product_Id = newPro.Product_Id }).FirstOrDefault();
                    if (item == null)
                    {
                        parent.msg = "商品細項不存在";
                        continue;
                    }
                    #region 成本

                    int cost = 0;
                    if (!string.IsNullOrEmpty(parent.cost))
                    {
                        int.TryParse(parent.cost, out cost);
                    }
                    else
                    {
                        cost = Convert.ToInt32(item.Item_Cost);
                    }
                    newPriceMaster.cost = cost;
                    #endregion

                    #region 售價

                    int price = 0;
                    if (!string.IsNullOrEmpty(parent.price))
                    {
                        int.TryParse(parent.price, out price);
                    }
                    else
                    {
                        price = Convert.ToInt32(item.Item_Money);
                    }
                    newPriceMaster.price = price;
                    #endregion

                    newPriceMaster.event_price = Convert.ToInt32(item.Event_Item_Money);
                    newPriceMaster.event_start = item.Event_Product_Start;
                    newPriceMaster.event_end = item.Event_Product_End;
                    priceMasters.Add(newPriceMaster);

                    if (site.Site_Id != 1)
                    {
                        //如果站臺不是吉甲地就把吉甲地站臺的價格狀態改為4(下架)
                        priceMasters[0].price_status = 4;
                        //再加入非吉甲地站臺
                        newPriceMaster = new PriceMaster { site_id = site.Site_Id, user_level = 1, same_price = 1, accumulated_bonus = 1, default_bonus_percent = 1, bonus_percent = 1 };
                        newPriceMaster.product_name = newPro.Product_Name;
                        newPriceMaster.price_status = 1;
                        #region 成本

                        cost = 0;
                        if (!string.IsNullOrEmpty(parent.cost))
                        {
                            int.TryParse(parent.cost, out cost);
                        }
                        else
                        {
                            cost = Convert.ToInt32(item.Item_Cost);
                        }
                        newPriceMaster.cost = cost;
                        #endregion

                        #region 售價

                        price = 0;
                        if (!string.IsNullOrEmpty(parent.price))
                        {
                            int.TryParse(parent.price, out price);
                        }
                        else
                        {
                            price = Convert.ToInt32(item.Item_Money);
                        }
                        newPriceMaster.price = price;
                        #endregion
                        newPriceMaster.event_price = Convert.ToInt32(item.Event_Item_Money);
                        newPriceMaster.event_start = item.Event_Product_Start;
                        newPriceMaster.event_end = item.Event_Product_End;
                        priceMasters.Add(newPriceMaster);
                    }

                    #region 其他站臺價格

                    var child = source.Where(m =>
                                    m.combination.Trim() == "299"
                                    && m.formula.ToUpper().Trim() == parent.temp_id.ToUpper().Trim()
                                    && string.IsNullOrEmpty(m.msg)
                                    && m.new_old.ToUpper().Trim() == "NEW"
                                    && m.formula.ToUpper().Trim().StartsWith("P"));
                    if (child != null)
                    {
                        foreach (var c in child)
                        {
                            item = _productItemMgr.Query(new ProductItem { Product_Id = uint.Parse(c.product_id) }).FirstOrDefault();
                            if (item == null)
                            {
                                c.msg = "價格檔商品細項不存在";
                                result = false;
                                break;
                            }
                            site = _siteMgr.Query(new Site { Site_Name = c.site.Trim() }).FirstOrDefault();
                            if (site == null)
                            {
                                c.msg = "站臺不存在";
                                result = false;
                                break;
                            }
                            if (priceMasters.Exists(m => m.site_id == site.Site_Id))
                            {
                                c.msg = "站臺重複";
                                result = false;
                                break;
                            }
                            newPriceMaster = new PriceMaster { user_level = 1, same_price = 1, accumulated_bonus = 1, default_bonus_percent = 1, bonus_percent = 1 };
                            newPriceMaster.product_name = c.product_name.Trim();
                            newPriceMaster.site_id = site.Site_Id;
                            newPriceMaster.price_status = 1;
                            #region 成本

                            cost = 0;
                            if (!string.IsNullOrEmpty(c.cost))
                            {
                                int.TryParse(c.cost, out cost);
                            }
                            else
                            {
                                cost = Convert.ToInt32(item.Item_Cost);
                            }
                            newPriceMaster.cost = cost;
                            #endregion

                            #region 售價

                            price = 0;
                            if (!string.IsNullOrEmpty(c.price))
                            {
                                int.TryParse(c.price, out price);
                            }
                            else
                            {
                                price = Convert.ToInt32(item.Item_Money);
                            }
                            newPriceMaster.price = price;
                            #endregion
                            newPriceMaster.event_price = Convert.ToInt32(item.Event_Item_Money);
                            newPriceMaster.event_start = item.Event_Product_Start;
                            newPriceMaster.event_end = item.Event_Product_End;
                            priceMasters.Add(newPriceMaster);

                            if (site.Site_Name.Trim().ToLower() == "chinatrust")
                            {
                                ArrayList category_set = CategorySet(c, brand.Brand_Id);
                                if (category_set == null)
                                {
                                    result = false;
                                    break;
                                }
                                else
                                {
                                    sqls.AddRange(category_set);
                                }
                            }
                        }
                        if (!result) continue;
                    }
                    #endregion

                    #endregion

                    #region ProductCombo

                    string[] strIds = parent.formula.IndexOf(",") != -1 ? parent.formula.Trim().Split(',') : new string[] { parent.formula.Trim() };
                    string[] nums = parent.number.IndexOf(",") != -1 ? parent.number.Trim().Split(',') : new string[] { parent.number.Trim() };

                    List<Product> children = new List<Product>();
                    ProductCombo tmp;
                    for (int i = 0; i < strIds.Length; i++)
                    {
                        tmp = new ProductCombo();
                        if (parent.combination.Trim() != "2")
                        {
                            tmp.Buy_Limit = parent.buylimit.Trim().ToUpper() == "Y" ? 1 : 0;
                        }
                        else
                        {
                            tmp.S_Must_Buy = int.Parse(i >= nums.Length ? nums[nums.Length - 1] : nums[i]);
                        }
                        if (parent.combination.Trim() == "3")//為3任選時 數量為G_Must_Buy
                        {
                            tmp.G_Must_Buy = int.Parse(nums[0]);
                        }
                        switch (parent.new_old.Trim().ToUpper())
                        {
                            case "NEW":
                                var map = _productMigrationMgr.GetSingle(new ProductMigrationMap { temp_id = strIds[i] });
                                if (map == null)
                                {
                                    parent.msg = "原料編號未找到對應";
                                    break;
                                }
                                tmp.Child_Id = Convert.ToInt32(map.product_id);
                                break;
                            case "OLD":
                                tmp.Child_Id = int.Parse(strIds[i]);
                                break;
                            case "BOTH":
                                if (strIds[i].ToUpper().Trim().StartsWith("P"))
                                {
                                    var tMap = _productMigrationMgr.GetSingle(new ProductMigrationMap { temp_id = strIds[i] });
                                    if (tMap == null)
                                    {
                                        parent.msg = "原料編號未找到對應";
                                        break;
                                    }
                                    tmp.Child_Id = Convert.ToInt32(tMap.product_id);
                                }
                                else
                                {
                                    tmp.Child_Id = int.Parse(strIds[i]);
                                }
                                break;
                        }
                        if (tmp.Child_Id == 0)
                        {
                            result = false;
                            break;
                        }
                        else
                        {
                            Product tmpPro = _productMgr.Query(new Product { Product_Id = Convert.ToUInt32(tmp.Child_Id) }).FirstOrDefault();
                            if (tmpPro == null)
                            {
                                parent.msg = strIds[i] + "不存在";
                                result = false;
                                break;
                            }
                            if (tmpPro.Product_Status == 0 || tmpPro.Product_Status ==1)
                            {
                                parent.msg = strIds[i] + "商品状态不為新增、申請審核";
                                result = false;
                                break;
                            }
                            if (tmpPro.Combination != 0 && tmpPro.Combination != 1)
                            {
                                parent.msg = strIds[i] + "不是單一商品";
                                result = false;
                                break;
                            }
                            switch (newPro.Product_Freight_Set)
                            {
                                case 1:
                                case 3:
                                    if (tmpPro.Product_Freight_Set != 1 && tmpPro.Product_Freight_Set != 3) 
                                    {
                                        parent.msg = strIds[i] + "运费模式与主商品不匹配";
                                        result = false;
                                    }
                                    break;
                                case 2:
                                case 4:
                                    if (tmpPro.Product_Freight_Set != 2 && tmpPro.Product_Freight_Set != 4)
                                    {
                                        parent.msg = strIds[i] + "运费模式与主商品不匹配";
                                        result = false;
                                    }
                                    break;
                                case 5:
                                case 6:
                                    if (tmpPro.Product_Freight_Set != 5 && tmpPro.Product_Freight_Set != 6)
                                    {
                                        parent.msg = strIds[i] + "运费模式与主商品不匹配";
                                        result = false;
                                    }
                                    break;
                                default:
                                    break;
                            }
                            if (!result) break;
                            children.Add(tmpPro);
                        }
                        sqls.Add(_productComboMgr.Save(tmp));
                    }
                    if (!result) continue;
                    #endregion

                    #region product_category_set
                    if (!string.IsNullOrEmpty(parent.display))
                    {
                        ArrayList category_set = CategorySet(parent, brand.Brand_Id);
                        if (category_set == null)
                            continue;
                        else
                        {
                            foreach (var set in category_set)
                            {
                                if (!sqls.Contains(set))
                                {
                                    sqls.Add(set);
                                }
                            }
                        }
                    }
                    else
                    {
                        sqls.Add(_productCategorySetMgr.SaveFromOtherPro(new ProductCategorySet { Product_Id = product_id }));
                    }
                    #endregion

                    #region product_migration_map

                    ProductMigrationMap pMap = new ProductMigrationMap();
                    if (parent.is_exist.ToUpper().Equals("OLD"))
                    {
                        pMap.temp_id = parent.product_id;
                    }
                    else if (parent.is_exist.ToUpper().Equals("NEW"))
                    {
                        pMap.temp_id = parent.temp_id;
                    }
                    sqls.Add(_productMigrationMgr.SaveNoPrid(pMap));

                    #endregion

                    #region notice tag picture

                    sqls.Add(_productNoticeSetMgr.SaveFromOtherPro(new ProductNoticeSet { product_id = product_id }));
                    sqls.Add(_productTagSetMgr.SaveFromOtherPro(new ProductTagSet { product_id = product_id }));
                    sqls.Add(_productPictureMgr.SaveFromOtherPro(new ProductPicture { product_id = Convert.ToInt32(product_id) }));
                    sqls.Add(_productStatusHistoryMgr.SaveNoProductId(new ProductStatusHistory { type = 7, product_status = Convert.ToInt32(newPro.Product_Status) }));
                    #endregion

                    string str = string.Empty;
                    if (_productMgr.ProductMigration(newPro, priceMasters, null, null, sqls, null))
                    {
                        str = "匯入成功";
                    }
                    else
                    {
                        str = "保存至數據庫失敗";
                    }
                    parent.msg = str;
                    source.FindAll(m =>
                                    m.combination.Trim() == "299"
                                    && m.formula.ToUpper().Trim() == parent.temp_id.ToUpper().Trim()
                                    && string.IsNullOrEmpty(m.msg)
                                    && m.new_old.ToUpper().Trim() == "NEW"
                                    && m.formula.ToUpper().Trim().StartsWith("P")).ForEach(m => m.msg = str);
                }

                #region 其他站臺價格

                var pChild = source.Where(m => m.combination.Trim() == "299" && m.new_old.ToUpper().Trim() == "OLD" && string.IsNullOrEmpty(m.msg));
                if (pChild != null)
                {
                    ProductItem item;
                    PriceMaster newPriceMaster;
                    Site site;
                    _priceMasterMgr = new PriceMasterMgr(strConn);
                    foreach (var c in pChild)
                    {
                        ProductMigrationMap prodMigra = _productMigrationMgr.GetSingle(new ProductMigrationMap { temp_id = c.formula.Trim() });
                        if (prodMigra == null)
                        {
                            c.msg = "原料編號對照不存在";
                            continue;
                        }
                        item = _productItemMgr.Query(new ProductItem { Product_Id = uint.Parse(c.product_id) }).FirstOrDefault();
                        if (item == null)
                        {
                            c.msg = "價格檔商品細項不存在";
                            continue;
                        }
                        site = _siteMgr.Query(new Site { Site_Name = c.site.Trim() }).FirstOrDefault();
                        if (site == null)
                        {
                            c.msg = "站臺不存在";
                            continue;
                        }
                        newPriceMaster = new PriceMaster { user_level = 1, same_price = 1, accumulated_bonus = 1, default_bonus_percent = 1, bonus_percent = 1 };
                        newPriceMaster.product_name = c.product_name.Trim();
                        newPriceMaster.product_id = prodMigra.product_id;
                        newPriceMaster.child_id = Convert.ToInt32(prodMigra.product_id);
                        newPriceMaster.site_id = site.Site_Id;
                        newPriceMaster.price_status = 1;
                        #region 成本

                        int cost = 0;
                        if (!string.IsNullOrEmpty(c.cost))
                        {
                            int.TryParse(c.cost, out cost);
                        }
                        else
                        {
                            cost = Convert.ToInt32(item.Item_Cost);
                        }
                        newPriceMaster.cost = cost;
                        #endregion

                        #region 售價

                        int price = 0;
                        if (!string.IsNullOrEmpty(c.price))
                        {
                            int.TryParse(c.price, out price);
                        }
                        else
                        {
                            price = Convert.ToInt32(item.Item_Money);
                        }
                        newPriceMaster.price = price;
                        #endregion
                        newPriceMaster.event_price = Convert.ToInt32(item.Event_Item_Money);
                        newPriceMaster.event_start = item.Event_Product_Start;
                        newPriceMaster.event_end = item.Event_Product_End;

                        ArrayList category_set = new ArrayList();
                        if (site.Site_Name.Trim().ToLower() == "chinatrust")
                        {
                            Product pro= _productMgr.Query(new Product { Product_Id = item.Product_Id }).FirstOrDefault();
                            if (pro == null)
                            {
                                c.msg = "商品不存在";
                                continue;
                            }
                            #region 更新該站臺商品的 product_category_set
                            
                            bool result = true;
                            System.Text.RegularExpressions.Regex regx = new System.Text.RegularExpressions.Regex("^[0-9]*$");
                            string[] cateArray = c.display.Split(',');
                            foreach (string strcate in cateArray)
                            {
                                if (!string.IsNullOrEmpty(strcate))
                                {
                                    if (regx.IsMatch(strcate))
                                    {
                                        ProductCategory query = _cateMgr.QueryAll(new ProductCategory { category_id = uint.Parse(strcate) }).FirstOrDefault();
                                        if (query == null || strcate.Equals("0"))
                                        {
                                            c.msg = "display:" + strcate + " 不存在;";
                                            result = false;
                                            break;
                                        }
                                        else
                                        {
                                            ProductCategorySet category = new ProductCategorySet { Brand_Id = pro.Brand_Id, Category_Id = uint.Parse(strcate), Product_Id = prodMigra.product_id };
                                            if (_productCategorySetMgr.Query(category).FirstOrDefault() == null)
                                            {
                                                category_set.Add(_productCategorySetMgr.Save(category));
                                            }
                                            else
                                            {
                                                c.msg = "display:" + strcate + " 已存在;";
                                                result = false;
                                                break;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        c.msg = "display:" + strcate + " 格式不正確 ";
                                        result = false;
                                        break;
                                    }
                                }
                            }
                            if (!result) continue;
                            #endregion
                        }

                        string str = string.Empty;
                        if (_priceMasterMgr.Save(newPriceMaster, null, category_set, ref str) > 0)
                        {
                            c.msg = "匯入成功";
                        }
                        else
                        {
                            c.msg = string.IsNullOrEmpty(str) ? "保存至數據庫失敗" : str;
                        }
                    }
                }
                #endregion
            }
        }
예제 #11
0
        public HttpResponseBase GetProductCatagory()
        {
            //吉甲地美安
            string resultStr = "";
            try
            {
                List<Parametersrc> Market = new List<Parametersrc>();
                _ptersrc = new ParameterMgr(mySqlConnectionString);
                Market = _ptersrc.GetAllKindType("market_category");//物流業者
               

                if (Market.Count > 0)
                {
                    ProductCategory category = new ProductCategory();
                    category.category_name = "新館";
                    List<ProductCategory> categoryStore = new List<ProductCategory>();//-------取新館的id用來獲取product_category_banner的子節點
                   // List<ProductCategory> categoryList = new List<ProductCategory>();
                    List<ProductCategoryCustom> cateList = new List<ProductCategoryCustom>();
                  
                    _procateMgr = new ProductCategoryMgr(mySqlConnectionString);
                   
                    categoryStore = _procateMgr.QueryAll(category);//
                    if (categoryStore.Count > 0)//取father_id;//在product_category表查詢新館的編號
                    {
                        category = categoryStore[0];
                    }
                    else 
                    {
                        category.category_id = 754;
                    }
                    ProductCategoryBannerQuery bannerquery = new ProductCategoryBannerQuery();//查詢裡面屬於新錧裡面美安的父元素和子元素
                    bannerquery.banner_cateid = uint.Parse(Market[0].ParameterCode);
                    bannerquery.IsPage = false;
                    _bannerMgr = new ProductCategoryBannerMgr(mySqlConnectionString);
                    List<ProductCategoryBannerQuery> bannerList = new List<ProductCategoryBannerQuery>();
                    int total = 0;
                    bannerList = _bannerMgr.GetProCateBanList(bannerquery, out total);
                   // categoryList = _procateMgr.GetProductCate(new ProductCategory { });

                    //cateList = getCate(categoryList, "2", Market[0].ParameterCode.ToString());
                    cateList = getCate(bannerList,category.category_id.ToString());
                    GetCategoryList(bannerList, ref cateList);
                   // GetCategoryList(categoryList, ref cateList);
                    resultStr = JsonConvert.SerializeObject(cateList);
                }


            }
            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;
        }