예제 #1
0
        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 GetPriceMaster()
        {
            string json = string.Empty;
            try
            {
                if (!string.IsNullOrEmpty(Request.Params["ProductId"]))
                {
                    uint productId = uint.Parse(Request.Params["ProductId"]);

                    _priceMasterMgr = new PriceMasterMgr(connectionString);
                    List<PriceMasterCustom> proSiteCustom = _priceMasterMgr.Query(new PriceMaster { product_id = productId, child_id = Convert.ToInt32(productId) });
                    StringBuilder strJson = new StringBuilder("[");
                    if (proSiteCustom != null)
                    {
                        _itemPriceMgr = new ItemPriceMgr(connectionString);
                        ItemPrice query = new ItemPrice { IsPage = true, Limit = 1 };
                        foreach (var item in proSiteCustom)
                        {
                            strJson.Append("{");
                            strJson.AppendFormat("price_master_id:{0},product_id:{1},site_id:{2},site_name:\"{3}\"", item.price_master_id, item.product_id, item.site_id, item.site_name);
                            strJson.AppendFormat(",product_name:\"{0}\",product_name_format:\"{1}\",bonus_percent:{2},default_bonus_percent:{3}", item.product_name, PriceMaster.Product_Name_Op(item.product_name), item.bonus_percent, item.default_bonus_percent);
                            strJson.AppendFormat(",user_level_name:\"{0}\",user_email:\"{1}\",user_level:{2}", item.user_level_name, item.user_email, item.user_level);
                            strJson.AppendFormat(",event_start:\"{0}\",user_id:{1}", item.event_start, item.user_id);
                            strJson.AppendFormat(",event_end:\"{0}\"", item.event_end);
                            strJson.AppendFormat(",cost:\"{0}\"", item.cost);
                            strJson.AppendFormat(",event_cost:\"{0}\"", item.event_cost);
                            strJson.AppendFormat(",price_status:\"{0}\"", item.price_status);
                            //if (item.same_price == 1)//edit by hufeng0813w 2014/06/16 Reason:所有單一商品規格不同價時 也去master表中的價格和活動價格
                            //{
                            strJson.AppendFormat(",price:\"{0}\"", item.price);
                            strJson.AppendFormat(",event_price:\"{0}\"", item.event_price);
                            //}
                            strJson.AppendFormat(",status:\"{0}\",accumulated_bonus:{1},bonus_percent_start:\"{2}\",bonus_percent_end:\"{3}\",same_price:{4},valid_start:\"{5}\",valid_end:\"{6}\"", item.status, item.accumulated_bonus, item.bonus_percent_start, item.bonus_percent_end, item.same_price, item.valid_start, item.valid_end);
                            strJson.Append("}");
                        }
                    }
                    strJson.Append("]");
                    json = strJson.ToString().Replace("}{", "},{");
                }
            }
            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 = "[]";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
예제 #3
0
        public void CreateList(List<MakePriceCustom> PriceStore, PriceMaster pMaster, PriceMasterTemp pMasterTemp, string same_price, List<List<ItemPrice>> ItemPList, List<PriceMasterTemp> pMasterListT,
            List<PriceMaster> pMasterList, List<ItemPrice> update)
        {
            _productItemMgr = new ProductItemMgr(connectionString);

            if (PriceStore.Count > 0)
            {
                //先遍歷群組
                var piles = PriceStore.GroupBy(rec => rec.Pile_Id).ToList();
                piles.ForEach(rec =>
                {
                    if (same_price == "1")
                    {
                        //循環grid的每一行
                        rec.ToList().ForEach(row =>
                        {
                            //生成price_master
                            if (pMasterTemp != null)
                            {
                                PriceMasterTemp pmT = pMasterTemp.Clone() as PriceMasterTemp;
                                pmT.product_name = row.Product_Name;
                                pmT.child_id = row.Child_Id.ToString();
                                pmT.price = int.Parse(row.item_money.ToString());
                                pmT.max_price = int.Parse(row.item_money.ToString());   //edit by xinglu0624w reason 子商品需要给 max_price 值
                                pmT.max_event_price = 0;
                                pmT.cost = int.Parse(row.item_cost.ToString());
                                pmT.event_price = int.Parse(row.event_money.ToString());
                                pmT.event_cost = int.Parse(row.event_cost.ToString());
                                pmT.valid_start = pMasterTemp.valid_start;
                                pmT.valid_end = pMasterTemp.valid_end;
                                pMasterListT.Add(pmT);
                            }
                            else
                            {
                                PriceMaster priceMa = pMaster.Clone() as PriceMaster;
                                priceMa.product_name = row.Product_Name;
                                priceMa.child_id = int.Parse(row.Child_Id.ToString());
                                priceMa.price = int.Parse(row.item_money.ToString());
                                priceMa.max_price = int.Parse(row.item_money.ToString());
                                priceMa.max_event_price = 0;
                                priceMa.cost = int.Parse(row.item_cost.ToString());
                                priceMa.event_price = int.Parse(row.event_money.ToString());
                                priceMa.event_cost = int.Parse(row.event_cost.ToString());
                                priceMa.price_master_id = row.price_master_id;
                                pMasterList.Add(priceMa);
                            }
                            if (row.price_master_id == 0)//新增
                            {

                                //生成item_price
                                List<ProductItem> piList = _productItemMgr.Query(new ProductItem { Product_Id = row.Child_Id });
                                List<ItemPrice> iList = new List<ItemPrice>();
                                piList.ForEach(item =>
                                {
                                    ItemPrice iP = new ItemPrice();
                                    iP.item_id = item.Item_Id;
                                    iP.item_money = row.item_money;
                                    iP.item_cost = row.item_cost;
                                    iP.event_money = row.event_money;
                                    iP.event_cost = row.event_cost;
                                    iList.Add(iP);
                                });
                                ItemPList.Add(iList);
                            }
                            else //更新
                            {
                                ItemPrice ip = new ItemPrice();
                                ip.item_price_id = row.item_price_id;
                                ip.price_master_id = row.price_master_id;
                                ip.item_money = row.item_money;
                                ip.item_cost = row.item_cost;
                                ip.event_money = row.event_money;
                                ip.event_cost = row.event_cost;
                                update.Add(ip);
                            }
                        });
                    }
                    else   //處理各自定價-規格不同價
                    {

                        var children = rec.GroupBy(c => c.Child_Id).ToList();
                        children.ForEach(c =>
                        {
                            List<ItemPrice> differentPrice = new List<ItemPrice>();
                            //生成price_mater
                            var rowData = (from ci in c where ci.Child_Id == c.Key select new { ci.Product_Name, ci.price_master_id }).ToList().First();
                            if (pMasterTemp != null)
                            {
                                PriceMasterTemp pmT = pMasterTemp.Clone() as PriceMasterTemp;
                                pmT.product_name = rowData.Product_Name;
                                pmT.child_id = c.Key.ToString();
                                pmT.price = int.Parse(c.FirstOrDefault().item_money.ToString());
                                pmT.max_price = int.Parse(c.FirstOrDefault().item_money.ToString());
                                //edit by hufeng0813w 2014/06/16 Reason:規格不同價時子商品也需要cost,event_cost,event_money
                                pmT.max_event_price = int.Parse(c.FirstOrDefault().event_money.ToString());
                                pmT.cost = int.Parse(c.FirstOrDefault().item_cost.ToString());
                                pmT.event_price = int.Parse(c.FirstOrDefault().event_money.ToString());
                                pmT.event_cost = int.Parse(c.FirstOrDefault().event_cost.ToString());
                                //edit by hufeng0813w 2014/06/16
                                pMasterListT.Add(pmT);
                            }
                            else
                            {
                                PriceMaster priceMa = pMaster.Clone() as PriceMaster;
                                priceMa.price_master_id = uint.Parse(rowData.price_master_id.ToString());
                                priceMa.product_name = rowData.Product_Name;
                                priceMa.child_id = int.Parse(c.Key.ToString());
                                priceMa.price = int.Parse(c.FirstOrDefault().item_money.ToString());
                                priceMa.max_price = int.Parse(c.FirstOrDefault().item_money.ToString());
                                //edit by hufeng0813w 2014/06/16 Reason:規格不同價時子商品也需要cost,event_cost,event_money
                                priceMa.max_event_price = int.Parse(c.FirstOrDefault().event_money.ToString());
                                priceMa.cost = int.Parse(c.FirstOrDefault().item_cost.ToString());
                                priceMa.event_price = int.Parse(c.FirstOrDefault().event_money.ToString());
                                priceMa.event_cost = int.Parse(c.FirstOrDefault().event_cost.ToString());
                                //edit by hufeng0813w 2014/06/16
                                pMasterList.Add(priceMa);
                            }
                            c.ToList().ForEach(row =>
                            {
                                //生成item_price
                                ItemPrice iP = new ItemPrice();
                                iP.item_id = row.item_id;
                                iP.item_money = row.item_money;
                                iP.item_cost = row.item_cost;
                                iP.event_money = row.event_money;
                                iP.event_cost = row.event_cost;
                                iP.item_price_id = row.item_price_id;
                                iP.price_master_id = row.price_master_id;
                                differentPrice.Add(iP);
                                update.Add(iP);
                            });
                            ItemPList.Add(differentPrice);
                        });

                    }
                });

            }
            //為保證ItemPList.Count=pMasterListT.Count
            ItemPList.Add(null);

        }
예제 #4
0
        public HttpResponseBase specTempSave()
        {
            string resultStr = "{success:true}";
            bool result = true;
            try
            {

                Caller _caller = (Session["caller"] as Caller);
                string specType = Request.Params["specType"];
                string spec1Name = Request.Params["spec1Name"];
                string spec1Result = Request.Params["spec1Result"];
                string spec2Name = "";
                string spec2Result;

                _specMgr = new ProductSpecMgr(connectionString);
                _specTempMgr = new ProductSpecTempMgr(connectionString);
                _productTempMgr = new ProductTempMgr(connectionString);
                _productItemMgr = new ProductItemMgr(connectionString);
                _productItemTempMgr = new ProductItemTempMgr(connectionString);
                _serialMgr = new SerialMgr(connectionString);

                if (!string.IsNullOrEmpty(Request.Params["ProductId"]))
                {
                    uint proId = uint.Parse(Request.Params["ProductId"]);

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

                    #region 正式表修改
                    List<ProductSpec> spec1List = null;
                    List<ProductSpec> spec2List = null;
                    List<ProductSpec> specUpdateList = new List<ProductSpec>();
                    List<ProductSpec> specAddList = new List<ProductSpec>();
                    JavaScriptSerializer jss = new JavaScriptSerializer();
                    spec1List = jss.Deserialize<List<ProductSpec>>(spec1Result);
                    if (spec1List != null)
                    {
                        //規格一處理
                        spec1List.ForEach(m =>
                        {
                            m.product_id = proId;
                            m.spec_type = 1;
                            if (m.spec_id != 0)
                            {
                                specUpdateList.Add(m);
                            }
                            else
                            {
                                specAddList.Add(m);
                            }
                        });
                    }

                    //規格二處理
                    if (specType.Equals("2"))
                    {
                        spec2Name = Request.Params["spec2Name"];
                        spec2Result = Request.Params["spec2Result"];
                        spec2List = jss.Deserialize<List<ProductSpec>>(spec2Result);

                        spec2List.ForEach(m =>
                        {
                            m.product_id = proId;
                            m.spec_type = 2;
                            if (m.spec_id != 0)
                            {
                                specUpdateList.Add(m);
                            }
                            else
                            {
                                specAddList.Add(m);
                            }
                        });
                    }

                    Product proModel = new Product();
                    _productMgr = new ProductMgr(connectionString);
                    _tableHistoryMgr = new TableHistoryMgr(connectionString);
                    proModel = _productMgr.Query(new Product { Product_Id = proId }).FirstOrDefault();
                    proModel.Spec_Title_1 = spec1Name;
                    proModel.Spec_Title_2 = spec2Name;

                    if (specUpdateList.Count() > 0)
                    {
                        for (int i = 0, j = specUpdateList.Count(); i < j; i++)
                        {
                            ArrayList sqls = new ArrayList();
                            sqls.Add(_specMgr.Update(specUpdateList[i]));
                            if (i == 0)
                            {
                                sqls.Add(_productMgr.Update(proModel));
                            }
                            if (!_tableHistoryMgr.SaveHistory<ProductSpec>(specUpdateList[i], batch, sqls))
                            {
                                result = false;
                            }
                        }
                    }

                    if (specAddList.Count() > 0)
                    {

                        List<ProductItem> saveItemList = new List<ProductItem>();
                        List<ProductSpec> spec1ExistList = spec1List.Where(m => m.spec_id != 0).ToList();     //規格一中原本就存在的規格
                        specAddList.ForEach(p => p.spec_id = uint.Parse(_serialMgr.NextSerial(18).ToString()));
                        ProductItem saveTemp;
                        List<PriceMaster> list_price = new List<PriceMaster>();
                        PriceMasterMgr pm = new PriceMasterMgr(connectionString);
                        list_price = pm.GetPriceMasterInfoByID2(proId.ToString());//獲取同一個ID下其他產品的價格信息
                        PriceMaster _p = list_price.FirstOrDefault();//add by wangwei0216w 2014/9/19 獲取同一個ID下其他產品的信息
                        //List<ProductItem> pro_list = new List<ProductItem>();
                        //ProductItemMgr pig = new ProductItemMgr(connectionString);
                        //pro_list = pig.GetProductItemByID(Convert.ToInt32(proId));
                        //ProductItem _product = pro_list.FirstOrDefault();//獲取同一個ID下其他產品的信息
                        foreach (var m in specAddList)
                        {
                            if (specType.Equals("1"))
                            {
                                if (m.spec_type == 1)
                                {
                                    saveTemp = new ProductItem();
                                    if (_p.same_price == 1)             //add by wangwei 0216w 2014/9/19 如果同價 就將價格賦予新增規格
                                    {
                                        //saveTemp.Item_Cost = Convert.ToUInt32(_p.cost);
                                        //saveTemp.Item_Money = Convert.ToUInt32(_p.price);
                                    }
                                    else
                                    {
                                        resultStr = "{success:true,Msg:true}";
                                    }
                                    saveTemp.Spec_Id_1 = m.spec_id;
                                    saveTemp.Product_Id = proId;
                                    // saveTemp.Item_Stock = 10;
                                    saveTemp.Item_Alarm = 1;
                                    saveItemList.Add(saveTemp);
                                }
                                else
                                {
                                    saveTemp = new ProductItem();
                                    if (_p.same_price == 1)             //add by wangwei 0216w 2014/9/19 如果同價 就將價格賦予新增規格
                                    {
                                        //saveTemp.Item_Cost = Convert.ToUInt32(_p.cost);
                                        //saveTemp.Item_Money = Convert.ToUInt32(_p.price);
                                    }
                                    else
                                    {
                                        resultStr = "{success:true,Msg:true}";
                                    }
                                    saveTemp.Spec_Id_2 = m.spec_id;
                                    saveTemp.Product_Id = proId;
                                    //saveTemp.Item_Stock = 10;
                                    saveTemp.Item_Alarm = 1;
                                    saveItemList.Add(saveTemp);
                                }
                            }
                            else
                            {
                                if (m.spec_type == 1)
                                {
                                    foreach (ProductSpec item in spec2List)
                                    {
                                        saveTemp = new ProductItem();
                                        if (_p.same_price == 1)             //add by wangwei 0216w 2014/9/19 如果同價 就將價格賦予新增規格
                                        {
                                            //saveTemp.Item_Cost = Convert.ToUInt32(_p.cost);
                                            //saveTemp.Item_Money = Convert.ToUInt32(_p.price);
                                        }
                                        else
                                        {
                                            resultStr = "{success:true,Msg:true}";
                                        }
                                        saveTemp.Spec_Id_1 = m.spec_id;
                                        saveTemp.Spec_Id_2 = item.spec_id;
                                        //saveTemp.Item_Stock = 10;
                                        saveTemp.Item_Alarm = 1;
                                        saveTemp.Product_Id = proId;
                                        saveItemList.Add(saveTemp);
                                    }
                                }
                                else
                                {
                                    foreach (ProductSpec item2 in spec1ExistList)
                                    {
                                        saveTemp = new ProductItem();
                                        if (_p.same_price == 1)             //add by wangwei 0216w 2014/9/19 如果同價 就將價格賦予新增規格
                                        {
                                            //saveTemp.Item_Cost = Convert.ToUInt32(_p.cost);
                                            //saveTemp.Item_Money = Convert.ToUInt32(_p.price);
                                        }
                                        else
                                        {
                                            resultStr = "{success:true,Msg:true}";
                                        }
                                        saveTemp.Spec_Id_1 = item2.spec_id;
                                        saveTemp.Spec_Id_2 = m.spec_id;
                                        //saveTemp.Item_Stock = 10;
                                        saveTemp.Item_Alarm = 1;
                                        saveTemp.Product_Id = proId;
                                        saveItemList.Add(saveTemp);
                                    }

                                }
                            }
                        }

                        _specMgr.Save(specAddList);
                        _productItemMgr.Save(saveItemList);
                        ProductItem pro;
                        if (proModel.Product_Status != 0) //add by wangwei0216w 2014/9/18 作用:將Export_flag的值設置為1
                        {
                            pro = new ProductItem() { Product_Id = proModel.Product_Id, Export_flag = 1 };
                            _productItemMgr.UpdateExportFlag(pro);
                        }
                        if (result) //如果之前保存規格,插入臨時表登操作有誤,則不執行插入itemprice的操作
                        {
                            List<ProductItem> item_list = _productItemMgr.GetProductNewItem_ID(Convert.ToInt32(proModel.Product_Id));   //得到product_item的新增ID
                            ItemPrice i = new ItemPrice();
                            ItemPriceMgr ipm = new ItemPriceMgr(connectionString);
                            ArrayList liststr = new ArrayList();
                            foreach (PriceMaster p in list_price)
                            {
                                foreach (ProductItem pi in item_list)
                                {
                                    if (p.same_price == 1)
                                    {
                                        i.price_master_id = p.price_master_id;
                                        i.item_id = pi.Item_Id;
                                        i.item_money = Convert.ToUInt32(p.price);
                                        i.item_cost = Convert.ToUInt32(p.cost);
                                        i.event_cost = Convert.ToUInt32(p.event_cost);
                                        i.event_money = Convert.ToUInt32(p.event_price);
                                    }
                                    else
                                    {
                                        i.price_master_id = p.price_master_id;
                                        i.item_id = pi.Item_Id;
                                        i.item_money = 0;
                                        i.item_cost = 0;
                                        i.event_money = 0;
                                        i.event_cost = 0;
                                        resultStr = "{success:true,Msg:true}";
                                    }
                                    liststr.Add(ipm.Save(i));
                                }
                            }
                            ipm.AddItemPricBySpec(liststr, connectionString);
                        }
                    }
                    //若為單一商品,則把product_item.export_flag改為2 edit by xiangwang0413w 2014/06/30
                    //if (proModel.Combination == 1)
                    //{
                    //    _productItemMgr = new ProductItemMgr(connectionString);
                    //    ProductItem pro_Item = new ProductItem() { Product_Id = proModel.Product_Id, Export_flag = 2 };
                    //    _productItemMgr.UpdateExportFlag(pro_Item);
                    //}

                    #endregion
                }
                else
                {
                    #region 臨時表修改
                    _productTempMgr = new ProductTempMgr(connectionString); //add by xiangwang 2014.09.26 可修改庫存預設值為99

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

                    //add by xiangwang 2014.09.26 可修改庫存預設值為99
                    ProductTemp query = _productTempMgr.GetProTemp(new ProductTemp { Writer_Id = _caller.user_id, Combo_Type = COMBO_TYPE, Product_Id = product_id });


                    if (!specType.Equals("0") && !string.IsNullOrEmpty(specType))
                    {
                        #region 有規格
                        List<ProductSpecTemp> spec1List;
                        List<ProductSpecTemp> spec2List;
                        List<ProductSpecTemp> specAllList = new List<ProductSpecTemp>();

                        JavaScriptSerializer jss = new JavaScriptSerializer();
                        spec1List = jss.Deserialize<List<ProductSpecTemp>>(spec1Result);

                        foreach (ProductSpecTemp item in spec1List)
                        {
                            //   specid = _serialMgr.NextSerial(18);
                            //item.spec_id = uint.Parse(specid.ToString());
                            item.Writer_Id = _caller.user_id;
                            item.product_id = product_id;
                            item.spec_type = 1;
                            item.spec_image = "";
                            specAllList.Add(item);
                        }

                        if (specType.Equals("2"))
                        {
                            spec2Name = Request.Params["spec2Name"];
                            spec2Result = Request.Params["spec2Result"];
                            spec2List = jss.Deserialize<List<ProductSpecTemp>>(spec2Result);

                            foreach (ProductSpecTemp item in spec2List)
                            {
                                // specid = _serialMgr.NextSerial(18);
                                //item.spec_id = uint.Parse(specid.ToString());
                                item.Writer_Id = _caller.user_id;
                                item.product_id = product_id;
                                item.spec_type = 2;
                                item.spec_image = "";
                                specAllList.Add(item);
                            }
                        }

                        List<ProductSpecTemp> tempList = _specTempMgr.Query(new ProductSpecTemp { Writer_Id = _caller.user_id, product_id = product_id });
                        if (tempList == null || tempList.Count() <= 0)
                        {
                            #region 保存

                            specAllList.ForEach(p => p.spec_id = uint.Parse(_serialMgr.NextSerial(18).ToString()));

                            bool saveSpecResult = _specTempMgr.Save(specAllList);

                            if (saveSpecResult)
                            {
                                _productItemTempMgr.Delete(new ProductItemTemp { Writer_Id = _caller.user_id, Product_Id = product_id });
                                #region 保存ProductItemTemp

                                List<ProductSpecTemp> specAllResultList = _specTempMgr.Query(new ProductSpecTemp { Writer_Id = _caller.user_id, product_id = product_id });
                                List<ProductSpecTemp> spec1ResultList = specAllResultList.Where(m => m.spec_type == 1).ToList();
                                List<ProductSpecTemp> spec2ResultList = specAllResultList.Where(m => m.spec_type == 2).ToList();

                                List<ProductItemTemp> saveItemList = new List<ProductItemTemp>();

                                if (specType.Equals("1"))
                                {
                                    foreach (ProductSpecTemp specTemp1 in spec1ResultList)
                                    {
                                        ProductItemTemp itemTemp = new ProductItemTemp();
                                        itemTemp.Writer_Id = _caller.user_id;
                                        itemTemp.Product_Id = product_id;
                                        itemTemp.Spec_Id_1 = specTemp1.spec_id;
                                        //itemTemp.Item_Stock = 10;
                                        itemTemp.Item_Alarm = 1;
                                        saveItemList.Add(itemTemp);

                                    }
                                }
                                else if (specType.Equals("2"))
                                {
                                    foreach (ProductSpecTemp specTemp1 in spec1ResultList)
                                    {
                                        foreach (ProductSpecTemp specTemp2 in spec2ResultList)
                                        {
                                            ProductItemTemp itemTemp = new ProductItemTemp();
                                            itemTemp.Writer_Id = _caller.user_id;
                                            itemTemp.Product_Id = product_id;
                                            itemTemp.Spec_Id_1 = specTemp1.spec_id;
                                            itemTemp.Spec_Id_2 = specTemp2.spec_id;
                                            //itemTemp.Item_Stock = 10;
                                            itemTemp.Item_Alarm = 1;
                                            itemTemp.Item_Code = "";
                                            itemTemp.Barcode = "";
                                            saveItemList.Add(itemTemp);
                                        }
                                    }
                                }

                                //add by xiangwang 2014.09.26 可修改庫存預設值為99
                                //saveItemList.ForEach(m => m.SetDefaultItemStock(query));

                                bool saveItemResult = _productItemTempMgr.Save(saveItemList);

                                if (!saveItemResult)
                                {
                                    result = false;
                                }

                                #endregion

                            }
                            else
                            {
                                result = false;
                            }
                            #endregion
                        }
                        else
                        {
                            #region 更新
                            string strSpecInit = Request.Params["specInit"];
                            string[] specs = strSpecInit.Split(',');

                            List<ProductSpecTemp> addList = specAllList.Where(p => p.spec_id == 0).ToList();
                            if (addList.Count() > 0)
                            {
                                addList.ForEach(p => p.spec_id = uint.Parse(_serialMgr.NextSerial(18).ToString()));

                                List<ProductSpecTemp> specAllResultList = _specTempMgr.Query(new ProductSpecTemp { Writer_Id = _caller.user_id, product_id = product_id });
                                List<ProductSpecTemp> spec1ResultList = specAllResultList.Where(m => m.spec_type == 1).ToList();
                                List<ProductSpecTemp> spec2ResultList = specAllResultList.Where(m => m.spec_type == 2).ToList();
                                List<ProductItemTemp> saveItemList = new List<ProductItemTemp>();
                                foreach (ProductSpecTemp item in addList)
                                {
                                    if (specType.Equals("1"))
                                    {
                                        if (item.spec_type == 1)
                                        {
                                            ProductItemTemp saveTemp = new ProductItemTemp();
                                            saveTemp.Writer_Id = _caller.user_id;
                                            saveTemp.Spec_Id_1 = item.spec_id;
                                            saveTemp.Product_Id = product_id;
                                            //saveTemp.Item_Stock = 10;
                                            saveTemp.Item_Alarm = 1;
                                            saveItemList.Add(saveTemp);
                                        }
                                        else
                                        {
                                            ProductItemTemp saveTemp = new ProductItemTemp();
                                            saveTemp.Writer_Id = _caller.user_id;
                                            saveTemp.Spec_Id_2 = item.spec_id;
                                            saveTemp.Product_Id = product_id;
                                            // saveTemp.Item_Stock = 10;
                                            saveTemp.Item_Alarm = 1;
                                            saveItemList.Add(saveTemp);
                                        }
                                    }
                                    else
                                    {
                                        if (item.spec_type == 1)
                                        {
                                            foreach (ProductSpecTemp item1 in spec2ResultList)
                                            {
                                                ProductItemTemp saveTemp = new ProductItemTemp();
                                                saveTemp.Writer_Id = _caller.user_id;
                                                saveTemp.Spec_Id_1 = item.spec_id;
                                                saveTemp.Spec_Id_2 = item1.spec_id;
                                                //saveTemp.Item_Stock = 10;
                                                saveTemp.Item_Alarm = 1;
                                                saveTemp.Product_Id = product_id;
                                                saveItemList.Add(saveTemp);
                                            }

                                            foreach (ProductSpecTemp item1 in addList.Where(p => p.spec_type == 2).ToList())
                                            {
                                                ProductItemTemp saveTemp = new ProductItemTemp();
                                                saveTemp.Writer_Id = _caller.user_id;
                                                saveTemp.Spec_Id_1 = item.spec_id;
                                                saveTemp.Spec_Id_2 = item1.spec_id;
                                                //saveTemp.Item_Stock = 10;
                                                saveTemp.Item_Alarm = 1;
                                                saveTemp.Product_Id = product_id;
                                                saveItemList.Add(saveTemp);
                                            }
                                        }
                                        else
                                        {
                                            foreach (ProductSpecTemp item2 in spec1ResultList)
                                            {
                                                ProductItemTemp saveTemp = new ProductItemTemp();
                                                saveTemp.Writer_Id = _caller.user_id;
                                                saveTemp.Spec_Id_1 = item2.spec_id;
                                                saveTemp.Spec_Id_2 = item.spec_id;
                                                saveTemp.Product_Id = product_id;
                                                // saveTemp.Item_Stock = 10;
                                                saveTemp.Item_Alarm = 1;
                                                saveItemList.Add(saveTemp);
                                            }

                                        }
                                    }
                                }
                                _specTempMgr.Save(addList);

                                //add by xiangwang 2014.09.26 可修改庫存預設值為99
                                //saveItemList.ForEach(m => m.SetDefaultItemStock(query));

                                _productItemTempMgr.Save(saveItemList);

                            }

                            if (specs.Length > 0)
                            {
                                List<ProductSpecTemp> updateList = new List<ProductSpecTemp>();
                                foreach (string initSpecId in specs)
                                {
                                    ProductSpecTemp nowItem = specAllList.Where(p => p.spec_id == uint.Parse(initSpecId)).FirstOrDefault();
                                    if (nowItem != null)
                                    {
                                        updateList.Add(nowItem);
                                    }
                                    else
                                    {

                                        ProductItemTemp delTemp = new ProductItemTemp { Writer_Id = _caller.user_id, Product_Id = product_id };
                                        uint spectype = _specTempMgr.Query(new ProductSpecTemp { spec_id = uint.Parse(initSpecId), product_id = product_id })[0].spec_type;
                                        if (spectype == 1)
                                        {
                                            delTemp.Spec_Id_1 = uint.Parse(initSpecId);
                                        }
                                        else if (spectype == 2)
                                        {
                                            delTemp.Spec_Id_2 = uint.Parse(initSpecId);
                                        }
                                        if (!_productItemTempMgr.Delete(delTemp))
                                        {
                                            result = false;
                                        }
                                        if (!_specTempMgr.Delete(new ProductSpecTemp { spec_id = uint.Parse(initSpecId), Writer_Id = _caller.user_id, product_id = product_id }))
                                        {
                                            result = false;
                                        }
                                        DeletePicOnServer(false, true, false, uint.Parse(initSpecId), product_id);
                                    }

                                }
                                if (!_specTempMgr.Update(updateList, "spec"))
                                {
                                    result = false;
                                }
                            }

                            #endregion
                        }

                        #region 更新Product

                        ProductTemp proTemp = new ProductTemp();
                        proTemp.Writer_Id = _caller.user_id;
                        proTemp.Product_Spec = uint.Parse(specType);
                        proTemp.Spec_Title_1 = spec1Name;
                        proTemp.Spec_Title_2 = spec2Name;
                        proTemp.Combo_Type = COMBO_TYPE;
                        proTemp.Product_Id = product_id;
                        bool saveProductResult = _productTempMgr.SpecInfoSave(proTemp);
                        if (!saveProductResult)
                        {
                            result = false;
                        }
                        #endregion

                        #endregion
                    }
                    else
                    {
                        #region 無規格
                        List<ProductItemTemp> saveList = new List<ProductItemTemp>();
                        //如果原數據有規格
                        if (query.Product_Spec != 0)
                        {
                            //刪除服務器上對應的圖片
                            DeletePicOnServer(false, true, false, 0, product_id);

                            _productItemTempMgr.Delete(new ProductItemTemp { Writer_Id = _caller.user_id, Product_Id = product_id });

                            _specTempMgr.Delete(new ProductSpecTemp { Writer_Id = _caller.user_id, product_id = product_id });

                            _productTempMgr.SpecInfoSave(new ProductTemp { Product_Spec = 0, Spec_Title_1 = "", Spec_Title_2 = "", Writer_Id = _caller.user_id, Combo_Type = COMBO_TYPE, Product_Id = product_id });

                            saveList = new List<ProductItemTemp>();
                            saveList.Add(new ProductItemTemp { Writer_Id = _caller.user_id, Product_Id = product_id/*, Item_Stock = 10*/, Item_Alarm = 1 });
                        }
                        else
                        {
                            List<ProductItemTemp> itemQuery = _productItemTempMgr.Query(new ProductItemTemp { Writer_Id = _caller.user_id, Product_Id = product_id });
                            if (itemQuery.Count() <= 0)
                            {
                                saveList = new List<ProductItemTemp>();
                                saveList.Add(new ProductItemTemp { Writer_Id = _caller.user_id, Product_Id = product_id, /*Item_Stock = 10,*/ Item_Alarm = 1 });
                                // _productItemTempMgr.Save(saveList);
                            }
                        }

                        //add by xiangwang 2014.09.26 可修改庫存預設值為99
                        //saveList.ForEach(m => m.SetDefaultItemStock(query));
                        _productItemTempMgr.Save(saveList);

                        #endregion
                    }
                    #endregion

                    #region 調度或自出商品,商品庫存預設為99
                    var proditemTemp = new ProductItemTemp { Product_Id = product_id, Writer_Id = _caller.user_id };
                    proditemTemp.SetDefaultItemStock(query);
                    _productItemTempMgr.UpdateItemStock(proditemTemp);
                    #endregion
                }
            }
            catch (Exception ex)
            {
                result = false;
                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);
            }

            if (!result)
            {
                resultStr = "{success:false,Msg:false}";
            }

            this.Response.Clear();
            this.Response.Write(resultStr);
            this.Response.End();
            return this.Response;
        }
예제 #5
0
        public HttpResponseBase PriceVerify()
        {
            string json = string.Empty;
            try
            {
                _pMaster = new PriceMasterMgr(connectionString);
                _pMasterTsMgr = new PriceMasterTsMgr(connectionString);
                _itemPriceMgr = new ItemPriceMgr("");
                _itemPriceTsMgr = new ItemPriceTsMgr("");
                _prodMgr = new ProductMgr(connectionString);
                _tableHistoryMgr = new TableHistoryMgr(connectionString);
                _pHMgr = new PriceUpdateApplyHistoryMgr(connectionString);

                List<PriceMaster> priceMasters = JsonConvert.DeserializeObject<List<PriceMaster>>(Request.Params["priceMasters"]);

                List<PriceUpdateApplyHistory> pHList = new List<PriceUpdateApplyHistory>();

                _functionMgr = new FunctionMgr(connectionString);
                string function = Request.Params["function"] ?? "";
                Function fun = _functionMgr.QueryFunction(function, "/ProductList/PriceVerifyList");
                int functionid = fun == null ? 0 : fun.RowId;
                HistoryBatch batch = new HistoryBatch { functionid = functionid, kuser = (Session["caller"] as Caller).user_email };
                string batchNo = CommonFunction.GetPHPTime().ToString() + "_" + (Session["caller"] as Caller).user_id + "_";

                int operationType = int.Parse(Request.Params["type"]);
                //edit by xiangwang0413w 2014/08/12 批量審核價格
                foreach (var item in priceMasters)
                {
                    //加上price_master 表中同一個product_id的所有價格 add by hufeng0813w 2014/06/12 Reason 各自定價父商品和子商品的價格狀態要同時更新
                    List<PriceMaster> ListpM = _pMasterTsMgr.QueryByApplyId(new PriceMaster { product_id = item.product_id, apply_id = item.apply_id });

                    //價格審核詳情
                    PriceUpdateApplyHistory pH = new PriceUpdateApplyHistory();
                    pH.user_id = (Session["caller"] as Caller).user_id;
                    pH.type = operationType;
                    pH.apply_id = (int)ListpM[0].apply_id;
                    foreach (var pM in ListpM)
                    {
                        ArrayList aList = new ArrayList();
                        uint applyId = pM.apply_id;
                        batch.batchno = batchNo + pM.product_id;
                        ItemPrice ip = new ItemPrice { price_master_id = pM.price_master_id, apply_id = pM.apply_id };
                        if (operationType == 1)//核可
                        {
                            pM.apply_id = 0;
                            pM.price_status = 1;

                            pH.price_status = 1; // 價格狀態為 1 :上架
                            pH.type = 2; //操作動作為2:核可
                            pHList.Add(pH);

                            aList.Add(_pMaster.Update(pM));//核可更新price_master表
                            if (pM.product_id != pM.child_id)
                            {
                                aList.Add(_itemPriceMgr.UpdateFromTs(ip));  //將Item_price_ts相對應數據導入Item_price表
                                aList.Add(_itemPriceTsMgr.DeleteTs(ip)); //更新成功後,刪除item_price_ts相應數據
                            }
                        }
                        else//駁回
                        {
                            pM.price_status = 3;
                            pH.price_status = 3; //加個狀態為 申請駁回
                            pH.type = 3; //操作動作為 3:駁回
                            pH.remark = Request.Params["reason"];
                            pHList.Add(pH);
                            if (pM.product_id != pM.child_id)
                            {
                                aList.Add(_itemPriceTsMgr.DeleteTs(ip)); //更新成功後,刪除item_price_ts相應數據
                            }
                        }
                        aList.Add(_pMasterTsMgr.DeleteTs(new PriceMaster { price_master_id = pM.price_master_id, apply_id = applyId }));//審核完成後刪除price_master_ts表
                        _tableHistoryMgr.SaveHistory<PriceMaster>(pM, batch, aList);
                    }
                }

                if (operationType == 1)//核可
                {
                    string[] prodList = (from p in priceMasters select p.product_id.ToString()).ToArray();

                    //將 獲取 時間 代碼提前  是後面獲得的 時間 相同
                    uint TimeNow = uint.Parse(CommonFunction.GetPHPTime(DateTime.Now.ToString()).ToString());

                    for (int i = 0; i < prodList.Length; i++)
                    {
                        ArrayList pList = new ArrayList();
                        //查詢product
                        Product product = _prodMgr.Query(new Product() { Product_Id = uint.Parse(prodList[i]) })[0];
                        if (product.Product_Start < TimeNow && product.Product_End > TimeNow)
                        {
                            product.Product_Start = TimeNow;
                        }
                        //p.Product_Status = 5; //價格審核不應該更改商品狀態 edit by xiangwang0413w 20140826
                        pList.Add(_prodMgr.Update(product));
                        batch.batchno = batchNo + product.Product_Id;
                        _tableHistoryMgr.SaveHistory<Product>(product, batch, pList);
                    }

                }
                //價格審核記錄
                _pHMgr.Save(pHList);
                json = "{success:true}";
            }
            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;
        }
예제 #6
0
        public override bool Exec()
        {
            bool result = true;
            try
            {
                foreach (MigrationDataSet item in mds)
                {
                    form.change(1);
                    if (!item.Combination.Equals("199") && !item.Product_id.Equals("0"))
                    {
                        pMap = _pMap.GetSingle(new ProductMigrationMap { temp_id = item.Product_id });
                        if (pMap != null)
                        {
                            item.OutMessage = "此記錄暫時編號(product_id)已經存在;";
                            continue;
                        }
                        else
                        {
                            pMap = new ProductMigrationMap();
                        }
                    }


                    ArrayList insertList = new ArrayList();


                    //Product
                    prod = _prodMgr.Query(new Product { Product_Id = uint.Parse(item.Product_id) }).FirstOrDefault();
                    //product.user_id:同此品牌廠商之verdor.product_manage
                    if (!string.IsNullOrEmpty(item.Brand_name))
                    {
                        VendorBrand vb = _vendorBrandMgr.GetProductBrand(new VendorBrand { Brand_Id = uint.Parse(item.Brand_name) });
                        Vendor v = _vendorMgr.GetSingle(new Vendor { vendor_id = vb.Vendor_Id });
                        prod.user_id = v.product_manage;
                    }
                    if (!string.IsNullOrEmpty(item.Brand_name)) prod.Brand_Id = uint.Parse(item.Brand_name);
                    prod.Ignore_Stock = 0;        //默認false
                    if (!string.IsNullOrEmpty(item.Cate_id)) prod.Cate_Id = item.Cate_id;
                    if (!string.IsNullOrEmpty(item.Status)) prod.Product_Status = uint.Parse(item.Status);
                    if (!string.IsNullOrEmpty(item.Freight_set)) prod.Product_Freight_Set = uint.Parse(item.Freight_set);
                    if (!string.IsNullOrEmpty(item.Product_mode)) prod.Product_Mode = uint.Parse(item.Product_mode);
                    if (!string.IsNullOrEmpty(item.Tax)) prod.Tax_Type = int.Parse(item.Tax);
                    prod.Shortage = 0;    //默認false
                    if (!string.IsNullOrEmpty(item.Product_name)) prod.Product_Name = item.Product_name;
                    prod.Product_Createdate = uint.Parse(BLL.gigade.Common.CommonFunction.GetPHPTime().ToString());
                    if (!string.IsNullOrEmpty(item.Service_Fee))
                    {
                        uint bag_check_money = 0;
                        uint.TryParse(item.Service_Fee, out bag_check_money);
                        prod.Bag_Check_Money = bag_check_money;
                    }
                    prod.Combination = 1;

                    //product_item
                    List<ProductItem> piList = _prodItemMgr.Query(new ProductItem { Product_Id = uint.Parse(item.Product_id) });
                    if (piList.Count > 0)
                    {
                        piList.ForEach(rec =>
                        {
                            if (!string.IsNullOrEmpty(item.Stock)) rec.Item_Stock = int.Parse(item.Stock);
                            if (!string.IsNullOrEmpty(item.Price)) rec.Item_Money = uint.Parse(item.Price);
                            if (!string.IsNullOrEmpty(item.Cost)) rec.Item_Cost = uint.Parse(item.Cost);
                        });
                    }

                    List<PriceMaster> pmList = new List<PriceMaster>();
                    List<PriceMaster> pmaterList = _priceMgr.PriceMasterQuery(new PriceMaster { product_id = uint.Parse(item.Product_id) });
                    pM.bonus_percent = 1;
                    pM.default_bonus_percent = 1;
                    pM.price_status = 1;
                    if (string.IsNullOrEmpty(item.Price))
                    {
                        pM.price = int.Parse(piList.Min(rec => rec.Item_Money).ToString());
                    }
                    else
                    {
                        pM.price = int.Parse(item.Price);
                    }
                    if (string.IsNullOrEmpty(item.Cost))
                    {
                        pM.cost = int.Parse(piList.Min(rec => rec.Item_Cost).ToString());
                    }
                    else
                    {
                        pM.cost = int.Parse(item.Cost);
                    }
                    pM.user_level = 1;
                    pM.user_id = 0;
                    pM.product_name = prod.Product_Name;
                    pM.same_price = piList.GroupBy(rec => rec.Item_Money).Count() <= 1 ? 1 : 0;
                    pM.child_id = 0;
                    prod.Product_Price_List = uint.Parse(pM.price.ToString());
                    if (pmaterList.Count == 0)
                    {
                        //price_master
                        if (item.Site != "1")//若不為吉甲地,則將吉甲地站臺也加入
                        {
                            //先把添加非吉甲地的站臺
                            pM.site_id = uint.Parse(item.Site);
                            pmList.Add(pM);
                            //再添加吉甲地站臺且價格狀態為4(下架)
                            PriceMaster pMgigade = pM.Clone() as PriceMaster;
                            pMgigade.site_id = 1;
                            pMgigade.price_status = 4;
                            pmList.Add(pMgigade);
                        }
                        else
                        {
                            pM.site_id = 1;
                            pmList.Add(pM);
                        }
                    }
                    else
                    {
                        #region 舊商品price_master中有值
                        PriceMaster pmaster = pmaterList.Where(rec => rec.site_id == 1).FirstOrDefault();
                        List<PriceMaster> oldPriceList = pmaterList.Where(rec => rec.site_id != 1).ToList();

                        if (item.Site == "1")
                        {
                            if (pmaster != null)//存在吉甲地站臺價格
                            {
                                //更新吉甲地站臺價格
                                if (!string.IsNullOrEmpty(item.Price)) { pmaster.price = int.Parse(item.Price); prod.Product_Price_List = uint.Parse(item.Price); }
                                if (!string.IsNullOrEmpty(item.Cost)) pmaster.cost = int.Parse(item.Cost);
                                if (!string.IsNullOrEmpty(item.Product_name)) pmaster.product_name = item.Product_name;
                                pmList.Add(pmaster);
                            }
                            else
                            {
                                pM.site_id = 1;
                                pmList.Add(pM);
                                prod.Product_Price_List = uint.Parse(pM.price.ToString());
                            }

                            //將原商品其他站臺價格複製
                            if (oldPriceList.Count > 0)
                            {
                                oldPriceList.ForEach(rec => pmList.Add(rec));
                            }
                        }
                        else//需匯入的商品價格不為吉甲地站臺價格
                        {
                            if (pmaster != null)//存在吉甲地站臺價格,則複製,否,則新建
                            {
                                pmList.Add(pmaster);
                                prod.Product_Price_List = uint.Parse(pmaster.price.ToString());
                            }
                            else
                            {
                                pM.site_id = 1;
                                pmList.Add(pM);
                                prod.Product_Price_List = uint.Parse(pM.price.ToString());
                            }

                            if (oldPriceList.Count > 0)
                            {
                                //處理當前站臺價格
                                PriceMaster nowPm = oldPriceList.Where(rec => rec.site_id == uint.Parse(item.Site)).FirstOrDefault();
                                if (nowPm != null)
                                {
                                    if (!string.IsNullOrEmpty(item.Price)) { nowPm.price = int.Parse(item.Price); prod.Product_Price_List = uint.Parse(item.Price); }
                                    if (!string.IsNullOrEmpty(item.Cost)) nowPm.cost = int.Parse(item.Cost);
                                    if (!string.IsNullOrEmpty(item.Product_name)) nowPm.product_name = item.Product_name;
                                    pmList.Add(nowPm);
                                }
                                else
                                {
                                    pM.site_id = uint.Parse(item.Site);
                                    pmList.Add(pM);
                                }
                                //處理其他站臺價格
                                List<PriceMaster> otherPriceList = oldPriceList.Where(rec => rec.site_id != uint.Parse(item.Site) && rec.site_id != 1).ToList();
                                if (otherPriceList.Count > 0) otherPriceList.ForEach(rec => pmList.Add(rec));

                            }
                            else//新建當前站臺的價格(按吉甲地站臺價格記錄取值)
                            {
                                pM.site_id = uint.Parse(item.Site);
                                pmList.Add(pM);
                            }
                        }
                        #endregion
                    }


                    #region item_price
                    List<List<ItemPrice>> ipListL = new List<List<ItemPrice>>();
                    List<ItemPrice> ipList = new List<ItemPrice>();
                    if (piList.Count > 0)
                    {
                        foreach (ProductItem proItem in piList)
                        {
                            ItemPrice iP = new ItemPrice();
                            iP.item_id = proItem.Item_Id;
                            iP.item_money = proItem.Item_Money;
                            iP.item_cost = proItem.Item_Cost;
                            ipList.Add(iP);
                        }
                        pmList.ForEach(rec => ipListL.Add(ipList));
                    }

                    #endregion

                    #region product_spec
                    List<ProductSpec> proSpecs = _proSpecMgr.Query(new ProductSpec { product_id = uint.Parse(item.Product_id) });
                    ArrayList specs = new ArrayList();
                    if (proSpecs != null)
                    {
                        StringBuilder str;
                        foreach (var specItem in proSpecs)
                        {
                            str = new StringBuilder();
                            str.Append(_proSpecMgr.SaveFromSpec(new ProductSpec { product_id = specItem.product_id, spec_id = specItem.spec_id }));
                            str.Append(_prodItemMgr.UpdateCopySpecId(new ProductItem { Spec_Id_1 = specItem.spec_id, Spec_Id_2 = specItem.spec_id }));
                            specs.Add(str.ToString());
                        }
                    }
                    #endregion

                    #region product_category_set
                    if (!string.IsNullOrEmpty(item.Display))
                    {
                        string[] cateArray = item.Display.Split(',');
                        foreach (string strcate in cateArray)
                        {
                            categorySet.Brand_Id = uint.Parse(item.Brand_name);
                            categorySet.Category_Id = uint.Parse(strcate);
                            insertList.Add(_productCategorySetMgr.SaveNoPrid(categorySet));
                        }
                    }
                    else
                    {
                        insertList.Add(_productCategorySetMgr.SaveFromOtherPro(new ProductCategorySet { Product_Id = uint.Parse(item.Product_id) }));
                    }

                    #endregion

                    #region product_migration_map
                    pMap.temp_id = item.Product_id;
                    insertList.Add(_pMap.SaveNoPrid(pMap));
                    #endregion

                    //tag notice picture
                    insertList.Add(_productNoticeSetMgr.SaveFromOtherPro(new ProductNoticeSet { product_id = uint.Parse(item.Product_id) }));
                    insertList.Add(_productTagSetMgr.SaveFromOtherPro(new ProductTagSet { product_id = uint.Parse(item.Product_id) }));
                    insertList.Add(_productPictureMgr.SaveFromOtherPro(new ProductPicture { product_id = int.Parse(item.Product_id) }));
                    insertList.Add(_proStatusHistoryMgr.SaveNoProductId(new ProductStatusHistory { product_status = int.Parse(item.Status), type = 7, user_id = 0 }));     //商品歷史記錄
                    result = _prodMgr.ProductMigration(prod, pmList, piList, ipListL, insertList, specs);

                    #region 原update邏輯代碼
                    /*ArrayList saveArray = new ArrayList();
                    saveArray.Add(_prodMgr.Update(prod));

                    PriceMaster queryMaster = _priceMgr.QueryByUserId(new PriceMaster { product_id = uint.Parse(item.Product_id) }).FirstOrDefault();
                    if (queryMaster == null)            //新增
                    {
                        //price_master
                        pM.product_id = uint.Parse(item.Product_id);
                        pM.bonus_percent = 1;
                        pM.default_bonus_percent = 1;
                        pM.price_status = 1;
                        pM.cost = int.Parse(item.Cost);
                        pM.price = int.Parse(item.Price);
                        pM.user_level = 1;
                        pM.site_id = uint.Parse(item.Site);
                        pM.user_id = 0;
                        pM.product_name = item.Product_name;
                        pM.same_price = 1;
                        pM.child_id = 0;

                        //item_price
                        List<ItemPrice> ipList = new List<ItemPrice>();
                        List<ProductItem> queryList = _prodItemMgr.Query(new ProductItem { Product_Id = uint.Parse(item.Product_id) });
                        foreach (ProductItem proItem in queryList)
                        {
                            iPrice.item_id = proItem.Item_Id;
                            iPrice.item_money = uint.Parse(item.Price);
                            iPrice.item_cost = uint.Parse(item.Cost);
                            ipList.Add(iPrice);
                        }

                        //保存
                        string strError = "";
                        if (_priceMgr.Save(pM, ipList, saveArray, ref strError) <= 0)
                        {
                            result = false;
                        }
                    }
                    else      //更新
                    {
                        //price_master
                        queryMaster.cost = int.Parse(item.Cost);
                        queryMaster.price = int.Parse(item.Price);
                        queryMaster.user_level = 1;
                        queryMaster.site_id = uint.Parse(item.Site);
                        queryMaster.user_id = 0;
                        queryMaster.same_price = 1;
                        queryMaster.child_id = 0;
                        saveArray.Add(_priceMgr.Update(queryMaster));

                        //item_price
                        List<ItemPrice> itemPriceList = _itemPriceMgr.itemPriceQuery(new ItemPrice { price_master_id = queryMaster.price_master_id });
                        if (itemPriceList != null && itemPriceList.Count() > 0)     //存在item_price则更新,否则新增item_price
                        {
                            foreach (ItemPrice priceItem in itemPriceList)
                            {
                                priceItem.item_cost = uint.Parse(item.Cost);
                                priceItem.item_money = uint.Parse(item.Price);
                                saveArray.Add(_itemPriceMgr.Update(priceItem));
                            }
                        }
                        else
                        {
                            List<ProductItem> proItemList = _prodItemMgr.Query(new ProductItem { Product_Id = uint.Parse(item.Product_id) });
                            foreach (ProductItem proitemItem in proItemList)
                            {
                                iPrice.price_master_id = queryMaster.price_master_id;
                                iPrice.item_id = proitemItem.Item_Id;
                                iPrice.item_money = uint.Parse(item.Price);
                                iPrice.item_cost = uint.Parse(item.Cost);
                                saveArray.Add(_itemPriceMgr.Save(iPrice));
                            }
                        }

                        BLL.gigade.Dao.MySqlDao _mySqlDao = new BLL.gigade.Dao.MySqlDao(connectionString);
                        result = _mySqlDao.ExcuteSqls(saveArray);
                    }*/

                    #endregion

                }

            }
            catch (Exception)
            {

                throw;
            }

            return result;
        }
예제 #7
0
        public override bool Exec()
        {
            bool result = true;
            PriceMaster priceMaster = new PriceMaster();
            foreach (MigrationDataSet item in mds)
            {
                result = true;
                form.change(1);
                //如果价格档原料编号新旧为new,则从对照表取出formula对应的product_id.
                //if (item.New_old.Equals("new"))
                //{
                ProductMigrationMap mapQuery = _pMap.GetSingle(new ProductMigrationMap { temp_id = item.Formula });
                if (mapQuery != null)
                {
                    item.Formula = mapQuery.product_id.ToString();
                }
                else
                {
                    item.OutMessage = "formula對照不存在";
                    result = false;
                    continue;
                }

                //}

                #region 原逻辑
                //如果价格档中无价格,则取formula对应PriceMaster中站台为gigade的价格.
                //if (string.IsNullOrEmpty(item.Price) || string.IsNullOrEmpty(item.Cost))
                //{

                //    PriceMaster priceQuery = _priceMgr.PriceMasterQuery(new PriceMaster { product_id = uint.Parse(item.Formula), site_id = 1 }).FirstOrDefault();
                //    if (priceQuery != null)
                //    {
                //        item.Cost = priceQuery.cost.ToString();
                //        item.Price = priceQuery.price.ToString();
                //    }
                //    else
                //    {
                //        item.OutMessage = "price,cost不存在";
                //        result = false;
                //        continue;
                //    }
                //} 
                #endregion

                //获取product_id对应product_item中的价格
                if (!item.Product_id.Equals("0"))
                {
                    ProductItem itemQuery = _prodItemMgr.Query(new ProductItem { Product_Id = uint.Parse(item.Product_id) }).FirstOrDefault();
                    if (itemQuery != null)
                    {
                        item.Cost = itemQuery.Item_Cost.ToString();
                        item.Price = itemQuery.Item_Money.ToString();
                    }
                    else
                    {
                        item.OutMessage = "product_item中无product_id信息;";
                        result = false;
                        continue;
                    }
                }
                else
                {
                    item.OutMessage = "product_id不存在;";
                    result = false;
                    continue;
                }



                //price_master
                priceMaster.product_id = uint.Parse(item.Formula);
                priceMaster.cost = int.Parse(item.Cost);
                priceMaster.price = int.Parse(item.Price);
                priceMaster.price_status = 1;
                priceMaster.user_level = 1;
                priceMaster.default_bonus_percent = 1;
                priceMaster.bonus_percent = 1;
                priceMaster.site_id = uint.Parse(item.Site);
                priceMaster.user_id = 0;
                priceMaster.product_name = item.Product_name;
                priceMaster.same_price = 1;
                priceMaster.child_id = 0;

                //item_price
                List<ItemPrice> ipList = new List<ItemPrice>();
                List<ProductItem> queryList = _prodItemMgr.Query(new ProductItem { Product_Id = uint.Parse(item.Formula) });
                foreach (ProductItem proItem in queryList)
                {
                    iPrice = new ItemPrice();
                    iPrice.item_id = proItem.Item_Id;
                    iPrice.item_money = uint.Parse(item.Price);
                    iPrice.item_cost = uint.Parse(item.Cost);
                    ipList.Add(iPrice);
                }
                ArrayList others = new ArrayList();
                Site site = _siteMgr.Query(new Site { Site_Id = uint.Parse(item.Site) }).FirstOrDefault();
                if (site.Site_Name.Trim().ToLower() == "chinatrust")
                {
                    Product pro = _prodMgr.Query(new Product { Product_Id = mapQuery.product_id }).FirstOrDefault();
                    if (pro == null)
                    {
                        item.OutMessage = "商品不存在";
                        continue;
                    }
                    #region 更新該站臺商品的 product_category_set

                    string[] cateArray = item.Display.Split(',');
                    foreach (string strcate in cateArray)
                    {
                        ProductCategorySet category = new ProductCategorySet { Brand_Id = pro.Brand_Id, Category_Id = uint.Parse(strcate), Product_Id = mapQuery.product_id };
                        if (_productCategorySetMgr.Query(category).FirstOrDefault() == null)
                        {
                            others.Add(_productCategorySetMgr.Save(category));
                        }
                        else
                        {
                            item.OutMessage = "display:" + strcate + " 已存在;";
                            result = false;
                            break;
                        }
                    }
                    if (!result) continue;
                }
                    #endregion

                //保存
                string strError = "";
                if (_priceMgr.Save(priceMaster, ipList, others, ref strError) <= 0)
                {
                    result = false;
                    item.OutMessage = strError;
                    if (strError == "")
                    {
                        item.OutMessage = "匯入失敗";
                    }
                }
                else
                {
                    item.OutMessage = "匯入成功";
                }

            }
            return result;
        }