Esempio n. 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;

        }
        public HttpResponseBase vaiteVerifyBack()
        {
            string resultStr = "{success:false}";
            bool result = true;
            try
            {
                string productIds = Request.Params["productIds"];
                string backReason = Request.Params["backReason"];

                Caller _caller = (Session["caller"] as Caller);
                _applyMgr = new ProductStatusApplyMgr(connectionString);
                _statusHistoryMgr = new ProductStatusHistoryMgr(connectionString);
                _prodMgr = new ProductMgr(connectionString);
                _tableHistoryMgr = new TableHistoryMgr(connectionString);
                string[] products = productIds.Split(',');

                _functionMgr = new FunctionMgr(connectionString);
                string function = Request.Params["function"] ?? "";
                Function fun = _functionMgr.QueryFunction(function, "/ProductList/VerifyList");
                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 + "_";

                foreach (string item in products)
                {
                    Product product = _prodMgr.Query(new Product { Product_Id = uint.Parse(item) }).FirstOrDefault();
                    ArrayList sqls = new ArrayList();
                    if (_applyMgr.Query(new ProductStatusApply { product_id = uint.Parse(item) }) != null)
                    {
                        ProductStatusApply queryApply = _applyMgr.Query(new ProductStatusApply { product_id = uint.Parse(item) });
                        uint prev_status = queryApply.prev_status;
                        product.Product_Status = prev_status;
                        sqls.Add(_prodMgr.Update(product, _caller.user_id));

                        ProductStatusHistory save = new ProductStatusHistory();
                        save.product_id = product.Product_Id;
                        save.user_id = uint.Parse(_caller.user_id.ToString());
                        save.type = 3;           //操作類型(駁回)
                        save.product_status = int.Parse(product.Product_Status.ToString());
                        save.remark = backReason;
                        sqls.Add(_statusHistoryMgr.Save(save));

                        batch.batchno = batchNo + product.Product_Id;

                        sqls.Add(_applyMgr.Delete(queryApply));
                        if (!_tableHistoryMgr.SaveHistory<Product>(product, batch, sqls))
                        {
                            result = false;
                            break;
                        }
                    }
                    else
                    {
                        result = false;
                        break;
                    }
                }

                resultStr = "{success:" + result.ToString().ToLower() + "}";

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

            Response.Clear();
            Response.Write(resultStr);
            Response.End();
            return this.Response;
        }
        public HttpResponseBase vaiteVerifyPass()
        {
            string resultStr = "{success:false}";
            bool result = true;
            try
            {
                Caller _caller = (Session["caller"] as Caller);
                _applyMgr = new ProductStatusApplyMgr(connectionString);
                _statusHistoryMgr = new ProductStatusHistoryMgr(connectionString);
                _prodMgr = new ProductMgr(connectionString);
                _pMaster = new PriceMasterMgr(connectionString);
                _tableHistoryMgr = new TableHistoryMgr(connectionString);
                string productIds = Request.Params["prodcutIdStr"];
                string[] products = productIds.Split(',');

                _functionMgr = new FunctionMgr(connectionString);
                string function = Request.Params["function"] ?? "";
                Function fun = _functionMgr.QueryFunction(function, "/ProductList/VerifyList");
                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 + "_";

                foreach (string item in products)
                {
                    Product product = _prodMgr.Query(new Product { Product_Id = uint.Parse(item) }).FirstOrDefault();

                    ArrayList sqls = new ArrayList();
                    if (_applyMgr.Query(new ProductStatusApply { product_id = uint.Parse(item) }) != null)
                    {
                        batch.batchno = batchNo + product.Product_Id;
                        //更改商品价格之状态
                        PriceMaster pmQuery = new PriceMaster();
                        if (product.Combination != 0 && product.Combination != 1)   //组合商品
                        {
                            pmQuery.child_id = int.Parse(item);
                        }
                        else
                        {
                            pmQuery.child_id = 0;
                        }
                        pmQuery.product_id = uint.Parse(item);
                        pmQuery.price_status = 2;       //只更改价格状态为申请审核的商品价格        
                        List<PriceMaster> pmResultList = _pMaster.PriceMasterQuery(pmQuery);
                        if (pmResultList != null && pmResultList.Count() > 0)
                        {
                            _pHMgr = new PriceUpdateApplyHistoryMgr(connectionString);
                            List<PriceUpdateApplyHistory> pHList = new List<PriceUpdateApplyHistory>();
                            foreach (var pm in pmResultList)
                            {
                                ArrayList priceUpdateSqls = new ArrayList();
                                pm.price_status = 1;      //价格状态为上架
                                pm.apply_id = 0;
                                priceUpdateSqls.Add(_pMaster.Update(pm));
                                if (!_tableHistoryMgr.SaveHistory<PriceMaster>(pm, batch, priceUpdateSqls))
                                {
                                    result = false;
                                    break;
                                }

                                //价格异动记录(price_update_apply_history)                            
                                PriceUpdateApplyHistory pH = new PriceUpdateApplyHistory();
                                pH.apply_id = int.Parse(pm.apply_id.ToString());
                                pH.user_id = (Session["caller"] as Caller).user_id;
                                pH.price_status = 1;
                                pH.type = 1;
                                pHList.Add(pH);
                            }
                            if (!_pHMgr.Save(pHList))
                            {
                                result = false;
                                break;
                            }
                        }

                        //更改商品之状态
                        ProductStatusApply queryApply = _applyMgr.Query(new ProductStatusApply { product_id = uint.Parse(item) });
                        uint online_mode = queryApply.online_mode;
                        //申請狀態為審核後立即上架時將上架時間改為當前時間,商品狀態改為上架
                        if (online_mode == 2)
                        {
                            product.Product_Status = 5;
                            product.Product_Start = uint.Parse(BLL.gigade.Common.CommonFunction.GetPHPTime(DateTime.Now.ToLongTimeString()).ToString());
                        }
                        else
                        {
                            product.Product_Status = 2;
                            //product.Product_Start = online_mode;
                        }
                        sqls.Add(_prodMgr.Update(product, _caller.user_id));

                        ProductStatusHistory save = new ProductStatusHistory();
                        save.product_id = product.Product_Id;
                        save.user_id = uint.Parse(_caller.user_id.ToString());
                        save.type = 2;           //操作類型(核可)
                        save.product_status = int.Parse(product.Product_Status.ToString());

                        sqls.Add(_statusHistoryMgr.Save(save));         //保存历史记录

                        sqls.Add(_applyMgr.Delete(queryApply));         //刪除審核申請表中的數據

                        if (!_tableHistoryMgr.SaveHistory<Product>(product, batch, sqls))
                        {
                            result = false;
                            break;
                        }
                    }
                    else
                    {
                        result = false;
                        break;
                    }
                }
                resultStr = "{success:" + result.ToString().ToLower() + "}";
            }
            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);
            }

            Response.Clear();
            Response.Write(resultStr);
            Response.End();
            return this.Response;
        }
        public HttpResponseBase verifyApply()
        {
            List<QueryandVerifyCustom> resultList = new List<QueryandVerifyCustom>();
            string result = "{success:false}";
            bool resl = true;
            try
            {
                string prodcutIdStr = Request.Params["prodcutIdStr"];
                string[] productIds = prodcutIdStr.Split(',');
                string method = Request.Params["method"];
                Caller _caller = (Session["caller"] as Caller);
                _prodMgr = new ProductMgr(connectionString);
                _applyMgr = new ProductStatusApplyMgr(connectionString);
                _statusHistoryMgr = new ProductStatusHistoryMgr(connectionString);
                _tableHistoryMgr = new TableHistoryMgr(connectionString);
                _functionMgr = new FunctionMgr(connectionString);
                string function = Request.Params["function"] ?? "";
                Function fun = _functionMgr.QueryFunction(function, "/ProductList") ?? _functionMgr.QueryFunction(function, "/ProductList/ReplaceVerify");
                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 + "_";

                string msg = "";
                foreach (string item in productIds.Distinct())
                {
                    ArrayList sqls = new ArrayList();
                    Product update = _prodMgr.Query(new Product { Product_Id = uint.Parse(item) }).FirstOrDefault();
                    //選擇自動上架時間時更改商品上架時間為選定時間
                    if (method.Equals("3"))
                    {
                        update.Product_Start = uint.Parse(BLL.gigade.Common.CommonFunction.GetPHPTime(Request.Params["product_start"]).ToString());
                        method = "1";
                    }
                    //若當前商品狀態不是新建商品或下架,則跳過申請
                    if (update.Product_Status != 0 && update.Product_Status != 6 && update.Product_Status!=7)
                    {
                        break;
                    }
                    //判斷商品是否失格 則 直接取消申請  add by  zhuoqin0830w 20105/07/01
                    if (update.off_grade == 1)
                    {
                        msg += "【" + update.Product_Id + "】商品是失格商品,不可申請審核!</br>";
                        break;
                    }
                    ProductStatusApply apply = new ProductStatusApply();
                    apply.product_id = uint.Parse(item);
                    apply.prev_status = update.Product_Status;
                    apply.online_mode = uint.Parse(method);
                    sqls.Add(_applyMgr.Save(apply));

                    ProductStatusHistory history = new ProductStatusHistory();
                    history.product_id = uint.Parse(item);
                    history.user_id = uint.Parse(_caller.user_id.ToString());
                    history.type = 1;               //操作類型        ???????????????????                      
                    history.product_status = 1;     //操作後狀態
                    //edit by zhuoqin0830w  2015/06/30  添加備註欄位
                    history.remark = Request.Form["Remark"];
                    sqls.Add(_statusHistoryMgr.Save(history));

                    batch.batchno = batchNo + update.Product_Id;
                    update.Product_Status = 1;    //狀態 -> 申請審核
                    sqls.Add(_prodMgr.Update(update, _caller.user_id));
                    if (!_tableHistoryMgr.SaveHistory<Product>(update, batch, sqls))
                    {
                        resl = false;
                    }
                    //若當前商品為單一商品並且商品狀態為新建商品,則將product_item.export_flag改為1
                    if (resl && update.Combination == 1 && apply.prev_status == 0)
                    {
                        _productItemMgr = new ProductItemMgr(connectionString);
                        ProductItem proItem = new ProductItem() { Product_Id = update.Product_Id, Export_flag = 1 };
                        _productItemMgr.UpdateExportFlag(proItem);
                    }
                }
                result = "{success:" + resl.ToString().ToLower() + ",'msg':'" + msg + "'}";
            }
            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);
            }
            Response.Clear();
            Response.Write(result);
            Response.End();
            return this.Response;
        }
        public HttpResponseBase ProductUp()
        {
            string json = "{success:true}";
            try
            {
                if (!string.IsNullOrEmpty(Request.Form["Product_Id"]))
                {
                    string[] pro_Ids = Request.Form["Product_Id"].Split('|');

                    _functionMgr = new FunctionMgr(connectionString);
                    string function = Request.Params["function"] ?? "";
                    Function fun = _functionMgr.QueryFunction(function, "/ProductList");
                    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 + "_";

                    _prodMgr = new ProductMgr(connectionString);
                    _tableHistoryMgr = new TableHistoryMgr(connectionString);
                    _productStatusHistoryMgr = new ProductStatusHistoryMgr("");
                    ProductStatusHistory proStatusHistory = new ProductStatusHistory { product_status = 5, type = 6, user_id = Convert.ToUInt32((Session["caller"] as Caller).user_id) };
                    ArrayList sqls;
                    foreach (string str in pro_Ids.Distinct())
                    {
                        if (!string.IsNullOrEmpty(str))
                        {
                            uint product_id = uint.Parse(str);
                            Product pro = _prodMgr.Query(new Product { Product_Id = product_id }).FirstOrDefault();
                            //上架商品不能為失格商品  eidt by  zhuoqin0830w 20105/07/01  pro.off_grade != 1
                            string msg = "";
                            if (pro.off_grade == 1)
                            {
                                msg += "【" + pro.Product_Id + "】商品是失格商品,不可上架!</br>";
                                json = "{success:false,'msg':'" + msg + "'}";
                                break;
                            }
                            if (pro != null && pro.Product_Status == 2)//&& pro.user_id == (Session["caller"] as Caller).user_id 
                            {
                                pro.Product_Status = 5;//上架
                                pro.Product_Start = Convert.ToUInt32(CommonFunction.GetPHPTime());
                                sqls = new ArrayList();
                                sqls.Add(_prodMgr.Update(pro));

                                batch.batchno = batchNo + pro.Product_Id;

                                proStatusHistory.product_id = product_id;
                                //edit by zhuoqin0830w  2015/06/26  添加備註欄位
                                proStatusHistory.remark = Request.Form["Remark"];
                                sqls.Add(_productStatusHistoryMgr.Save(proStatusHistory));
                                if (!_tableHistoryMgr.SaveHistory<Product>(pro, batch, sqls))
                                {
                                    json = "{success:false}";
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                json = "{success:false}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
        public HttpResponseBase ProductDown(int type = 1)
        {
            string json = "{success:true}";
            try
            {
                if (!string.IsNullOrEmpty(Request.Form["Product_Id"]))
                {
                    string[] pro_Ids = Request.Form["Product_Id"].Split('|');
                    uint product_end =0 ;
                    if (!string.IsNullOrEmpty(Request.Form["Product_End"]))
                    {
                        product_end = Convert.ToUInt32(CommonFunction.GetPHPTime(Request.Form["Product_End"]));
                    }
                    //立即下架不改變下架時間
                    //else
                    //{
                    //    product_end = Convert.ToUInt32(CommonFunction.GetPHPTime());
                    //}

                    _functionMgr = new FunctionMgr(connectionString);
                    string function = Request.Params["function"] ?? "";
                    Function fun = _functionMgr.QueryFunction(function, "/ProductList");
                    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 + "_";

                    _prodMgr = new ProductMgr(connectionString);
                    _tableHistoryMgr = new TableHistoryMgr(connectionString);
                    _productStatusHistoryMgr = new ProductStatusHistoryMgr("");
                    ProductStatusHistory proStatusHistory = new ProductStatusHistory { product_status = 6, type = 4, user_id = Convert.ToUInt32((Session["caller"] as Caller).user_id) };
                    ArrayList sqls;
                    foreach (string str in pro_Ids.Distinct())
                    {
                        if (!string.IsNullOrEmpty(str))
                        {
                            uint product_id = uint.Parse(str);
                            Product pro = _prodMgr.Query(new Product { Product_Id = product_id }).FirstOrDefault();
                            if (type == 1 && product_end == 0)//說明是立即下架,就用原來的時間
                            {
                                product_end = pro.Product_End;
                            }
                            //edit by zhuoqin0830w  2015/06/26  添加備註欄位
                            string remark = "";
                            if (pro != null && pro.Product_Status == 5)// && pro.user_id == (Session["caller"] as Caller).user_id
                            {
                                switch (type)
                                {
                                    case 1:
                                        pro.Product_Status = 6;//下架
                                        remark = Request.Form["UnShelve"]; //edit by zhuoqin0830w  2015/06/26  添加備註欄位
                                        pro.Product_End = product_end;  //將 pro.Product_End = product_end 代碼提前  避免下架不販售的時候沒有下架時間  edit by zhuoqin0830w  2015/07/15
                                        break;
                                    case 2:
                                        pro.Product_Status = 99;//下架不販售
                                        remark = Request.Form["Remark"]; //edit by zhuoqin0830w  2015/06/26  添加備註欄位
                                        IProductExtImplMgr _prodExtMgr = new ProductExtMgr(connectionString);
                                        _prodExtMgr.UpdatePendDel(product_id, true);
                                        break;
                                }

                                sqls = new ArrayList();
                                sqls.Add(_prodMgr.Update(pro));
                                batch.batchno = batchNo + pro.Product_Id;
                                proStatusHistory.product_id = product_id;
                                //edit by zhuoqin0830w  2015/06/26  添加備註欄位
                                proStatusHistory.remark = remark;
                                sqls.Add(_productStatusHistoryMgr.Save(proStatusHistory));
                                if (!_tableHistoryMgr.SaveHistory<Product>(pro, batch, sqls))
                                {
                                    json = "{success:false}";
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                json = "{success:false}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
Esempio n. 7
0
        public void PrepareData(List<CombinationExcel> source)
        {
            if (source != null)
            {
                source.ForEach(m => m.Validate());
                var parents = source.Where(m => m.combination.Trim() != "299" && string.IsNullOrEmpty(m.msg));

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

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

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

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

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

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

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

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

                    #region 售價

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

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

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

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

                        #region 售價

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

                    #region 其他站臺價格

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

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

                            #region 售價

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

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

                    #endregion

                    #region ProductCombo

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

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

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

                    #region product_migration_map

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

                    #endregion

                    #region notice tag picture

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

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

                #region 其他站臺價格

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

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

                        #region 售價

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

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

                        string str = string.Empty;
                        if (_priceMasterMgr.Save(newPriceMaster, null, category_set, ref str) > 0)
                        {
                            c.msg = "匯入成功";
                        }
                        else
                        {
                            c.msg = string.IsNullOrEmpty(str) ? "保存至數據庫失敗" : str;
                        }
                    }
                }
                #endregion
            }
        }