コード例 #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
ファイル: DataOperation.cs プロジェクト: lxh2014/gigade-net
        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;
        }
コード例 #3
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
            }
        }