コード例 #1
0
ファイル: DataOperation.cs プロジェクト: lxh2014/gigade-net
        public DataOperation(List<Model.MigrationDataSet> mds, MainForm form)
        {
            this.mds = mds;
            this.connectionString = System.Configuration.ConfigurationSettings.AppSettings["MySqlConnectionString"];
            prod = new Product();
            pItem = new ProductItem();
            pM = new PriceMaster();
            iPrice = new ItemPrice();
            categorySet = new ProductCategorySet();
            pMap = new ProductMigrationMap();
            _prodMgr = new ProductMgr(this.connectionString);
            _priceMgr = new PriceMasterMgr(this.connectionString);
            _prodItemMgr = new ProductItemMgr(this.connectionString);
            _itemPriceMgr = new ItemPriceMgr(this.connectionString);
            _vendorBrandMgr = new VendorBrandMgr(this.connectionString);
            _vendorMgr = new VendorMgr(this.connectionString);
            _pMap = new ProductMigrationMgr(this.connectionString);
            _productCategorySetMgr = new ProductCategorySetMgr(this.connectionString);
            _productNoticeSetMgr = new ProductNoticeSetMgr(this.connectionString);
            _productTagSetMgr = new ProductTagSetMgr(this.connectionString);
            _productPictureMgr = new ProductPictureMgr(this.connectionString);
            _proStatusHistoryMgr = new ProductStatusHistoryMgr(connectionString);
            _proSpecMgr = new ProductSpecMgr(connectionString);
            _siteMgr = new SiteMgr(connectionString);
            this.form = form;

        }
コード例 #2
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;
        }
コード例 #3
0
        public HttpResponseBase tempCategoryAdd()
        {

            Caller _caller = (Session["caller"] as Caller);
            string resultStr = "{success:true}";
            string tempStr = Request.Params["result"];
            string cate_id = Request.Params["cate_id"];
            string deStr = Request["oldresult"] == null ? "0" : Request["oldresult"];

            List<ProductCategorySetTemp> saveTempList = new List<ProductCategorySetTemp>();
            try
            {
                JavaScriptSerializer js = new JavaScriptSerializer();
                List<ProductCategorySetCustom> cateCustomList = js.Deserialize<List<ProductCategorySetCustom>>(tempStr);
                if (string.IsNullOrEmpty(tempStr))
                {
                    cateCustomList = new List<ProductCategorySetCustom>();
                }


                if (!string.IsNullOrEmpty(Request.Params["ProductId"]))
                {
                    #region 修改正式表
                    uint pid = uint.Parse(Request.Params["ProductId"]);
                    _tableHistoryMgr = new TableHistoryMgr(connectionString);
                    _categorySetMgr = new ProductCategorySetMgr(connectionString);
                    _productMgr = new ProductMgr(connectionString);

                    Product pro = new Product();
                    pro = _productMgr.Query(new Product { Product_Id = pid }).FirstOrDefault();
                    pro.Cate_Id = cate_id;

                    _functionMgr = new FunctionMgr(connectionString);
                    string function = Request.Params["function"] ?? "";
                    Function fun = _functionMgr.QueryFunction(function, "/ProductCombo");
                    int functionid = fun == null ? 0 : fun.RowId;
                    HistoryBatch batch = new HistoryBatch { functionid = functionid };
                    batch.batchno = Request.Params["batch"] ?? "";
                    batch.kuser = (Session["caller"] as Caller).user_email;

                    ArrayList sqls = new ArrayList();
                    sqls.Add(_categorySetMgr.Delete(new ProductCategorySet { Product_Id = pid }));
                    sqls.Add(_productMgr.Update(pro));
                    foreach (ProductCategorySetCustom item in cateCustomList)
                    {
                        item.Product_Id = pid;
                        item.Brand_Id = pro.Brand_Id;
                        sqls.Add(_categorySetMgr.Save(item));
                    }

                    if (!_tableHistoryMgr.SaveHistory<ProductCategorySetCustom>(cateCustomList, batch, sqls))
                    {
                        resultStr = "{success:false}";
                    }
                    #endregion
                }
                else
                {
                    #region 修改臨時表

                    string product_id = "0";
                    if (!string.IsNullOrEmpty(Request.Form["OldProductId"]))
                    {
                        product_id = Request.Form["OldProductId"];
                    }
                    _categoryTempSetMgr = new ProductCategorySetTempMgr(connectionString);
                    _productTempMgr = new ProductTempMgr(connectionString);
                    if (string.IsNullOrEmpty(tempStr))
                    {
                        bool result = _categoryTempSetMgr.Delete(new ProductCategorySetTemp { Writer_Id = _caller.user_id, Combo_Type = COMBO_TYPE, Product_Id = product_id }, deStr);
                    }
                    else
                    {
                        ProductCategorySetTemp saveTemp;
                        ProductTemp query = new ProductTemp { Writer_Id = _caller.user_id, Combo_Type = COMBO_TYPE, Product_Id = product_id.ToString() };
                        ProductTemp proTemp = _productTempMgr.GetProTemp(query);
                        foreach (ProductCategorySetCustom item in cateCustomList)
                        {
                            saveTemp = new ProductCategorySetTemp();
                            saveTemp.Writer_Id = _caller.user_id;
                            saveTemp.Product_Id = product_id;
                            saveTemp.Category_Id = item.Category_Id;
                            saveTemp.Brand_Id = proTemp.Brand_Id;
                            saveTemp.Combo_Type = COMBO_TYPE;
                            saveTempList.Add(saveTemp);
                        }

                        if (!_categoryTempSetMgr.Save(saveTempList))
                        {
                            resultStr = "{success:false}";
                        }
                    }

                    if (!_productTempMgr.CategoryInfoUpdate(new ProductTemp { Writer_Id = _caller.user_id, Cate_Id = cate_id, Combo_Type = COMBO_TYPE, Product_Id = product_id.ToString() }))
                    {
                        resultStr = "{success:false}";
                    }

                    #endregion
                }

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

            this.Response.Clear();
            this.Response.Write(resultStr);
            this.Response.End();
            return this.Response;
        }
コード例 #4
0
        public HttpResponseBase SaveBaseInfo()
        {
            string json = "{success:true}";
            int transportDays = -1;///初始化
            uint product_mode = 0;
            uint brand_id = 0;
            try
            {
                string prod_name = (Request.Form["prod_name"] ?? "").Trim();
                string prod_sz = (Request.Form["prod_sz"] ?? "").Trim();
                if (!Product.CheckProdName(prod_name) || !Product.CheckProdName(prod_sz))
                {
                    json = "{success:false,msg:'" + Resources.Product.FORBIDDEN_CHARACTER + "'}";
                    this.Response.Clear();
                    this.Response.Write(json);
                    this.Response.End();
                    return this.Response;
                }
                ProductTemp pTemp = new ProductTemp();
                _productTempMgr = new ProductTempMgr(connectionString);
                _productMgr = new ProductMgr(connectionString);
                Caller _caller = (Session["caller"] as Caller);
                Product p = new Product();
             

                ///add by wwei0216w 2015/8/24
                ///根據product_mode查找供應商對應的自出,寄倉,調度欄位,如果為0則不予保存
                 brand_id = uint.Parse(Request.Form["brand_id"]?? "0");
                 product_mode = uint.Parse(Request.Form["product_mode"]??"0");///獲得product_mode
                 string msg = "寄倉";
                IVendorImplMgr _vendorMgr = new VendorMgr(connectionString);
                List<Vendor> vendorList = _vendorMgr.GetArrayDaysInfo(brand_id);
                if (vendorList.Count > 0)
                {
                    switch (product_mode)
                    {
                        case 1:
                            transportDays = vendorList.FirstOrDefault<Vendor>().self_send_days;
                            msg = "自出";
                            break;
                        case 2:
                            transportDays = vendorList.FirstOrDefault<Vendor>().stuff_ware_days;
                            msg = "寄倉";
                            break;
                        case 3:
                            msg = "調度";
                            transportDays = vendorList.FirstOrDefault<Vendor>().dispatch_days;
                            break;
                        default:
                            break;
                    }
                }

                if (transportDays == 0)
                {
                    json = "{success:false,msg:'" + msg + Resources.Product.TRANSPORT_DAYS + "'}";
                    this.Response.Clear();
                    this.Response.Write(json);
                    this.Response.End();
                    return this.Response;
                }

                //查詢product表。
                if (Request.Params["product_id"] != "")
                {
                    p.Product_Id = uint.Parse(Request.Params["product_id"]);
                    p = _productMgr.Query(p)[0];
                }


                uint product_sort = 0;
                string product_vendor_code = "";
                uint product_start = 0;
                uint product_end = 0;
                uint expect_time = 0;
                uint product_freight_set = 0;
                int tax_type = 0;
                uint combination = 0;
                string expect_msg = string.Empty;
                int show_in_deliver = 0;
                int process_type = 0;
                int product_type = 0;
                uint recommedde_jundge = 0;
                uint recommedde_expend_day = 0;
                string recommededcheckall = string.Empty;
                int purchase_in_advance = 0;
                uint purchase_in_advance_start = 0;
                uint purchase_in_advance_end = 0;
                //庫存
                if (!string.IsNullOrEmpty(Request.Params["ig_sh_InsertValue"]))
                {
                    string[] Value = Request.Params["ig_sh_InsertValue"].Split(',');
                    pTemp.Ignore_Stock = int.Parse(Value[0]);
                    pTemp.Shortage = int.Parse(Value[1]);
                    pTemp.stock_alarm = int.Parse(Value[2]);

                    if (Request.Params["product_id"] != "")
                    {
                        p.Ignore_Stock = int.Parse(Value[0]);
                        p.Shortage = int.Parse(Value[1]);
                        p.stock_alarm = int.Parse(Value[2]);
                    }
                }
                else
                {
                    //brand_id = uint.Parse(Request.Form["brand_id"]);
                    product_sort = uint.Parse(Request.Form["product_sort"]);
                    product_vendor_code = Request.Form["product_vendor_code"];
                    product_start = uint.Parse(CommonFunction.GetPHPTime(Request.Form["product_start"]).ToString());
                    product_end = uint.Parse(CommonFunction.GetPHPTime(Request.Form["product_end"]).ToString());
                    expect_time = uint.Parse(CommonFunction.GetPHPTime(Request.Form["expect_time"]).ToString());
                    product_freight_set = uint.Parse(Request.Form["product_freight_set"]);
                    tax_type = int.Parse(Request.Form["tax_type"]);
                    combination = uint.Parse(Request.Form["combination"]);
                    //product_mode = uint.Parse(Request.Params["product_mode"]);
                    expect_msg = Request.Form["expect_msg"] ?? "";
                    //商品新增欄位 add by  xiangwang0413w 2014/09/15
                    show_in_deliver = int.Parse(Request.Form["show_in_deliver"]);
                    process_type = int.Parse(Request.Form["process_type"]);
                    product_type = int.Parse(Request.Form["product_type"]);
                    //add by dongya 2015/08/26 
                    recommedde_jundge = uint.Parse(Request.Form["recommedde_jundge"]);//是否選擇了推薦商品屬性 1 表示推薦
                    recommedde_expend_day = 0;
                    if (recommedde_jundge == 1)
                    {
                        if (!string.IsNullOrEmpty(Request.Params["recommededcheckall"]))
                        {
                            recommededcheckall = Request.Params["recommededcheckall"].ToString().TrimEnd(',');//選擇的所有的月數
                        }
                        recommedde_expend_day = uint.Parse(Request.Form["recommedde_expend_day"]);
                    }
                    //add by dongya 2015/09/02 
                    purchase_in_advance = Convert.ToInt32(Request.Form["purchase_in_advance"]);
                    purchase_in_advance_start = uint.Parse(Request.Form["purchase_in_advance_start"]);
                    purchase_in_advance_end = uint.Parse(Request.Form["purchase_in_advance_end"]);
                }

             

                if (string.IsNullOrEmpty(Request.Params["product_id"]))
                {
                    pTemp.Brand_Id = brand_id;
                    pTemp.Prod_Name = prod_name;
                    pTemp.Prod_Sz = prod_sz;
                    pTemp.Product_Name = pTemp.GetProductName();

                    pTemp.Product_Sort = product_sort;
                    pTemp.Product_Vendor_Code = product_vendor_code;
                    pTemp.Product_Start = product_start;
                    pTemp.Product_End = product_end;
                    pTemp.Expect_Time = expect_time;
                    pTemp.Product_Freight_Set = product_freight_set;
                    pTemp.Product_Mode = product_mode;
                    pTemp.Tax_Type = tax_type;
                    pTemp.Combination = combination;
                    pTemp.expect_msg = expect_msg;
                    pTemp.Combo_Type = COMBO_TYPE;
                    pTemp.Create_Channel = 1;// 1:後台管理者(manage_user) edit by xiagnwang0413w 2014/08/09
                    //商品新增欄位 add by  xiangwang0413w 2014/09/15
                    pTemp.Show_In_Deliver = show_in_deliver;
                    pTemp.Process_Type = process_type;
                    pTemp.Product_Type = product_type;

                    //add by zhuoqin0830w  增加新的欄位  2015/03/17
                    pTemp.Deliver_Days = 3;
                    pTemp.Min_Purchase_Amount = 1;
                    pTemp.Safe_Stock_Amount = 1;
                    pTemp.Extra_Days = 0;
                    //add by dongya
                    pTemp.recommedde_jundge = recommedde_jundge;//推薦商品 1表示推薦 0表示不推薦
                    pTemp.months = recommededcheckall;//以1,3,這樣的形式顯示
                    pTemp.expend_day = recommedde_expend_day;
                    //add by dongya 2015/09/02 
                    pTemp.purchase_in_advance = purchase_in_advance;
                    pTemp.purchase_in_advance_start = purchase_in_advance_start;
                    pTemp.purchase_in_advance_end = purchase_in_advance_end;

                    if (!string.IsNullOrEmpty(Request.Form["OldProductId"]))
                    {
                        pTemp.Product_Id = Request.Form["OldProductId"];
                    }

                    //查找臨時表是否存在數據,存在:更新,不存在插入
                    pTemp.Writer_Id = _caller.user_id;
                    pTemp.Product_Status = 0;
                    if (!string.IsNullOrEmpty(Request.Form["OldProductId"]))
                    {
                        pTemp.Product_Id = Request.Form["OldProductId"];
                    }

                   

                    ProductTemp query = new ProductTemp { Writer_Id = pTemp.Writer_Id, Combo_Type = COMBO_TYPE, Product_Id = pTemp.Product_Id };
                    ProductTemp pTempList = _productTempMgr.GetProTemp(query);
                    if (pTempList == null)
                    {
                        //插入
                        int result = 0;
                        result = _productTempMgr.baseInfoSave(pTemp);
                        if (result >0)
                        {
                            json = "{success:true}";
                        }
                        else
                        {
                            json = "{success:false}";
                        }
                    }
                    else
                    {

                        //更新
                        if (!string.IsNullOrEmpty(Request.Params["ig_sh_InsertValue"]))
                        {
                            _productTempMgr.ProductTempUpdate(pTemp, "stock");
                        }
                        else
                        {
                            if (pTemp.Product_Mode != 2)
                            {
                                pTemp.Bag_Check_Money = 0;
                            }
                            else
                            {
                                pTemp.Bag_Check_Money = pTempList.Bag_Check_Money;
                            }
                            _productTempMgr.baseInfoUpdate(pTemp);
                        }

                    }
                }
                else
                {
                   
                    if (string.IsNullOrEmpty(Request.Params["ig_sh_InsertValue"]))
                    {
                        p.Brand_Id = brand_id;
                        p.Prod_Name = prod_name;
                        p.Prod_Sz = prod_sz;
                        p.Product_Name = p.GetProductName();

                        p.Product_Sort = product_sort;
                        p.Product_Vendor_Code = product_vendor_code;
                        p.Product_Start = product_start;
                        p.Product_End = product_end;
                        p.Expect_Time = expect_time;
                        p.Product_Freight_Set = product_freight_set;
                        p.Product_Mode = product_mode;
                        p.Tax_Type = tax_type;
                        p.expect_msg = expect_msg;//預留商品信息
                        p.Combination = combination;
                        //商品新增欄位 add by  xiangwang0413w 2014/09/15
                        p.Show_In_Deliver = show_in_deliver;
                        p.Process_Type = process_type;
                        p.Product_Type = product_type;

                        //add by zhuoqin0830w  增加新的欄位  2015/03/17
                        p.Deliver_Days = 3;
                        p.Min_Purchase_Amount = 1;
                        p.Safe_Stock_Amount = 1;
                        p.Extra_Days = 0;
                        p.off_grade = int.Parse(Request.Form["off-grade"]);
                        //add by dongya
                        p.recommedde_jundge = recommedde_jundge;//推薦商品 1表示推薦 0表示不推薦
                        p.months = recommededcheckall;//以1,3,這樣的形式顯示
                        p.expend_day = recommedde_expend_day;
                        //add by dongya 0410j
                        p.purchase_in_advance = purchase_in_advance;
                        p.purchase_in_advance_start = purchase_in_advance_start;
                        p.purchase_in_advance_end = purchase_in_advance_end;
                        //更新正式表
                        p.Product_Id = uint.Parse(Request.Params["product_id"]);
                        if (p.Product_Mode != 2)
                        {
                            p.Bag_Check_Money = 0;
                        }

                        #region ScheduleRelation
                        int scheduleId = int.Parse(Request.Form["schedule_id"]);
                        IScheduleRelationImplMgr _srMgr = new ScheduleRelationMgr(connectionString);
                        _srMgr.Save(new ScheduleRelation { relation_table = "product", relation_id = (int)p.Product_Id, schedule_id = scheduleId });
                        #endregion

                    }
                    _tableHistoryMgr = new TableHistoryMgr(connectionString);
                    _productMgr = new ProductMgr(connectionString);
                    _categorySetMgr = new ProductCategorySetMgr(connectionString);
                    ArrayList aList = new ArrayList();
                    aList.Add(_productMgr.Update(p));
                    aList.Add(_categorySetMgr.UpdateBrandId(new ProductCategorySet { Product_Id = p.Product_Id, Brand_Id = p.Brand_Id })); //add by wwei0216w 2015/2/24 品牌名稱變更后,product_category_set表所對應的品牌名稱也需要更新

                    _functionMgr = new FunctionMgr(connectionString);
                    string function = Request.Params["function"] ?? "";
                    Function fun = _functionMgr.QueryFunction(function, "/ProductCombo");
                    int functionid = fun == null ? 0 : fun.RowId;
                    HistoryBatch batch = new HistoryBatch { functionid = functionid };
                    batch.batchno = Request.Params["batch"] ?? "";
                    batch.kuser = (Session["caller"] as Caller).user_email;

                    if (_tableHistoryMgr.SaveHistory<Product>(p, batch, aList))
                    {
                        #region add by zhuoqin0830w  2015/06/25  判斷修改的商品是否是失格商品  1為失格 0為正常
                        if (!string.IsNullOrEmpty(Request.Params["product_id"]))
                        {
                            _productMgr.UpdateOff_Grade(p.Product_Id, p.off_grade);
                        }
                        #endregion
                        //add by wwei0216 2015/1/9 刪除不符合條件的物品匹配模式
                        if (!p.CheckdStoreFreight())
                        {
                            IProductDeliverySetImplMgr _productDeliverySetMgr = new ProductDeliverySetMgr(connectionString);
                            _productDeliverySetMgr.Delete(
                                new ProductDeliverySet { Freight_big_area = 1, Freight_type = 12 }, p.Product_Id);
                        }

                        #region 推薦商品屬性插入/修改recommended_product_attribute表中做記錄 add by dongya 2015/09/30 ----目前只針對單一商品
                        RecommendedProductAttributeMgr rProductAttributeMgr = new RecommendedProductAttributeMgr(connectionString);
                        RecommendedProductAttribute rPA = new RecommendedProductAttribute();
                        rPA.product_id = Convert.ToUInt32(p.Product_Id);
                        rPA.time_start = 0;
                        rPA.time_end = 0;
                        rPA.expend_day = recommedde_expend_day;
                        rPA.months = recommededcheckall;
                        rPA.combo_type = 2;//組合商品
                        //首先判斷表中是否對該product_id設置為推薦
                        int productId = Convert.ToInt32(rPA.product_id);
                        if (rProductAttributeMgr.GetMsgByProductId(productId) > 0)//如果大於0,表示推薦表中存在數據
                        {
                            if (recommedde_jundge == 1)//==1表示推薦 
                            {
                                rProductAttributeMgr.Update(rPA);
                            }
                            else if (recommedde_jundge == 0)//==0表示不推薦 
                            {
                                rProductAttributeMgr.Delete(productId);
                            }
                        }
                        else
                        {
                            if (recommedde_jundge == 1)//==1表示推薦 
                            {
                                rProductAttributeMgr.Save(rPA);
                            }
                        }
                        #endregion
                        json = "{success:true,msg:'" + Resources.Product.SAVE_SUCCESS + "'}";
                    }
                    else
                    {
                        json = "{success:false,msg:'" + Resources.Product.SAVE_FAIL + "'}";
                    }
                }
            }
            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,msg:'" + Resources.Product.SAVE_FAIL + "'}";
            }

            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
コード例 #5
0
        public ActionResult tempCategoryAdd(int categoryType, int coboType = 1)
        {
            COMBO_TYPE = coboType;
            string resultStr = "{success:true}";
            string oldresult = Request["oldresult"];//add by wwei0216w 2014/12/26 需要刪除的選中項

            if (string.IsNullOrEmpty(oldresult))
            {
                resultStr = "{success:false}";
                return Content(resultStr);
            }
            try
            {
                Caller _caller = (Session["caller"] as Caller);
                string tempStr = "";
                string cate_id = "";
                if (!string.IsNullOrEmpty(Request.Params["result"]))
                {
                    tempStr = Request.Params["result"];
                }

                if (!string.IsNullOrEmpty(Request.Params["cate_id"]))
                {
                    cate_id = Request.Params["cate_id"];
                }

                List<ProductCategorySetTemp> saveTempList = new List<ProductCategorySetTemp>();

                JavaScriptSerializer js = new JavaScriptSerializer();
                List<ProductCategorySetCustom> cateCustomList = js.Deserialize<List<ProductCategorySetCustom>>(tempStr);
                string deStr = "";
                //if (categoryType == 2)//新類別
                //{


                //    if (cateCustomList.Count() <= 0)
                //    {
                //        resultStr = "{success:false,msg:'新類別必選'}";
                //        return Content(resultStr);
                //    }
                //}

                #region 將要刪除的id 拼成 '1,2,3'這種形式
                List<ProductCategorySetCustom> deleteCategorySet = js.Deserialize<List<ProductCategorySetCustom>>(oldresult);

                if (deleteCategorySet.Count() > 0)
                {
                    foreach (var item in deleteCategorySet)
                    {
                        deStr += item.Category_Id + ",";
                    }
                    deStr = deStr.Remove(deStr.Length - 1);
                }
                #endregion



                if (string.IsNullOrEmpty(tempStr))
                {
                    cateCustomList = new List<ProductCategorySetCustom>();
                }


                if (!string.IsNullOrEmpty(Request.Params["ProductId"]))
                {
                    #region 修改正式表
                    uint pid = uint.Parse(Request.Params["ProductId"]);
                    _tableHistoryMgr = new TableHistoryMgr(connectionString);
                    _categorySetMgr = new ProductCategorySetMgr(connectionString);
                    _productMgr = new ProductMgr(connectionString);


                    Product pro = new Product();
                    pro = _productMgr.Query(new Product { Product_Id = pid }).FirstOrDefault();
                    if (pro != null)
                    {
                        _functionMgr = new FunctionMgr(connectionString);
                        string function = Request.Params["function"] ?? "";
                        Function fun = _functionMgr.QueryFunction(function, "/Product/ProductSave");
                        int functionid = fun == null ? 0 : fun.RowId;
                        HistoryBatch batch = new HistoryBatch { functionid = functionid };
                        batch.batchno = Request.Params["batch"] ?? "";
                        batch.kuser = (Session["caller"] as Caller).user_email;



                        ArrayList sqls = new ArrayList();
                        if (deStr != "")
                        {
                            sqls.Add(_categorySetMgr.Delete(new ProductCategorySet { Product_Id = pid }, deStr));
                        }
                        if (categoryType == 1)
                        {
                            pro.Cate_Id = cate_id;
                        }
                        else if (categoryType == 2)  //edit by wwei0216w 如果是新類別 就不進行報表修改
                        {
                            pro.Prod_Classify = Convert.ToInt32(Request["prodClassify"]); //獲得對應館別ID
                            _tableHistoryMgr.SaveHistory<Product>(pro, batch, null);
                        }

                        sqls.Add(_productMgr.Update(pro, _caller.user_id));
                        foreach (ProductCategorySetCustom item in cateCustomList)
                        {
                            item.Product_Id = pid;
                            item.Brand_Id = pro.Brand_Id;
                            sqls.Add(_categorySetMgr.Save(item));
                        }

                        if (!_tableHistoryMgr.SaveHistory<ProductCategorySetCustom>(cateCustomList, batch, sqls))
                        {

                            throw new Exception("there is no History be saved");
                        }
                        //else
                        //{ //若為單一商品,則把product_item.export_flag改為2 edit by xiangwang0413w 2014/06/30
                        //    if (pro.Combination == 1)
                        //    {
                        //        _productItemMgr = new ProductItemMgr(connectionString);
                        //        ProductItem pro_Item = new ProductItem() { Product_Id = pro.Product_Id, Export_flag = 2 };
                        //        _productItemMgr.UpdateExportFlag(pro_Item);
                        //    }
                        //}
                    }
                    else
                    {
                        throw new Exception("None Product has being found");
                    }
                    #endregion
                }
                else
                {
                    #region 修改臨時表
                    string product_id = "0";
                    if (!string.IsNullOrEmpty(Request.Form["OldProductId"]))
                    {
                        product_id = Request.Form["OldProductId"];
                    }
                    _categoryTempSetMgr = new ProductCategorySetTempMgr(connectionString);
                    _productTempMgr = new ProductTempMgr(connectionString);

                    bool result = _categoryTempSetMgr.Delete(new ProductCategorySetTemp { Writer_Id = _caller.user_id, Combo_Type = COMBO_TYPE, Product_Id = product_id }, deStr);

                    ProductTemp query = new ProductTemp { Writer_Id = _caller.user_id, Combo_Type = COMBO_TYPE, Product_Id = product_id };
                    ProductTemp proTemp = _productTempMgr.GetProTemp(query);
                    ProductCategorySetTemp saveTemp;

                    if (proTemp == null)
                    {
                        resultStr = "{success:false}";
                    }
                    else
                    {
                        foreach (ProductCategorySetCustom item in cateCustomList)
                        {
                            saveTemp = new ProductCategorySetTemp();
                            saveTemp.Writer_Id = _caller.user_id;
                            saveTemp.Product_Id = product_id;
                            saveTemp.Category_Id = item.Category_Id;
                            saveTemp.Brand_Id = proTemp.Brand_Id;
                            saveTemp.Combo_Type = COMBO_TYPE;
                            saveTempList.Add(saveTemp);
                        }

                        if (!_categoryTempSetMgr.Save(saveTempList))
                        {
                            resultStr = "{success:false}";
                        }
                    }

                    proTemp.Combo_Type = COMBO_TYPE;
                    proTemp.Product_Id = product_id;
                    if (categoryType == 1)
                    {
                        proTemp.Cate_Id = cate_id;
                    }
                    else if (categoryType == 2)  //edit by wwei0216w 如果是新類別 就不進行報表修改
                    {
                        proTemp.Prod_Classify = Convert.ToInt32(Request["prodClassify"]); //獲得對應館別ID
                    }

                    if (!_productTempMgr.CategoryInfoUpdate(proTemp))
                    {
                        resultStr = "{success:false}";
                    }

                    #endregion
                }

            }
            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}";
                return Content(resultStr);
            }

            return Content(resultStr);
            ////this.Response.Clear();
            ////this.Response.Write(resultStr);
            ////this.Response.End();
            ////return this.Response;
        }
コード例 #6
0
        public HttpResponseBase GetFrontCate()
        {
            string resultStr = "{success:false}";

            try
            {
                if (!string.IsNullOrEmpty(Request.Params["ProductId"]))
                {
                    #region 從正式表獲取
                    uint pid = uint.Parse(Request.Params["ProductId"]);
                    _categorySetMgr = new ProductCategorySetMgr(connectionString);
                    resultStr = "{success:true,data:" + JsonConvert.SerializeObject(_categorySetMgr.Query(new ProductCategorySetCustom { Product_Id = pid })) + "}";
                    #endregion
                }

            }
            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;
        }
コード例 #7
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;
        }
コード例 #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;
        }
コード例 #9
0
ファイル: Combination.cs プロジェクト: lxh2014/gigade-net
        private ArrayList CategorySet(CombinationExcel source, uint brand_id)
        {
            ArrayList sqls = new ArrayList();
            if (!string.IsNullOrEmpty(source.display))
            {
                bool result = true;
                _productCategorySetMgr = new ProductCategorySetMgr(strConn);

                System.Text.RegularExpressions.Regex regx = new System.Text.RegularExpressions.Regex("^[0-9]*$");
                string[] cateArray = source.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"))
                            {
                                source.msg = "display:" + strcate + " 不存在;";
                                result = false;
                                break;
                            }
                            else
                            {
                                sqls.Add(_productCategorySetMgr.SaveNoPrid(new ProductCategorySet { Brand_Id = brand_id, Category_Id = uint.Parse(strcate) }));
                            }
                        }
                        else
                        {
                            source.msg = "display:" + strcate + " 格式不正確 ";
                            result = false;
                            break;
                        }
                    }
                }
                return result ? sqls : null;
            }
            return sqls;
        }
コード例 #10
0
ファイル: Combination.cs プロジェクト: lxh2014/gigade-net
        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
            }
        }