コード例 #1
0
        public HttpResponseBase AddSitePriceByGroup(string priceMasters, string priceCondition, int chkCost = 0)
        {
            string priceType = "price";
            if (priceCondition == "1") { priceType = "discount"; }
            else if (priceCondition == "2") { priceType = "price"; }
            string error = "";
            string json = "{success:true}";
            List<PriceMasterCustom> list = JsonConvert.DeserializeObject<List<PriceMasterCustom>>(priceMasters);
            foreach (var item in list)
            {
                if (!PriceMaster.CheckProdName(item.product_name))
                {
                    json = "{success:false,msg:'" + Resources.Product.FORBIDDEN_CHARACTER + "'}";
                    this.Response.Clear();
                    this.Response.Write(json);
                    this.Response.End();
                    return this.Response;
                }
                if (item.prod_sz != "")
                {
                    item.product_name = PriceMaster.Product_Name_FM("`LM`" + item.product_name + "`LM`" + item.prod_sz + "`LM`");
                }
            }
            string productIdss = "";
            uint[] productIds = (from p in list select p.product_id).ToArray();
            for (int i = 0; i < productIds.Length; i++)
            {
                productIdss += productIds[i].ToString() + ",";
            }
            productIdss = productIdss.Remove(productIdss.Length - 1, 1);
            _priceMasterMgr = new PriceMasterMgr(connectionString);
            List<PriceMaster> list_priceMaster = _priceMasterMgr.GetPriceMasterInfo(productIdss, Convert.ToInt32(list[0].site_id));

            //產生批號
            HistoryBatch batch = new HistoryBatch();
            _functionMgr = new FunctionMgr(connectionString);
            string function = "newSitePrice";
            Function fun = _functionMgr.QueryFunction(function, "/ProductSelect/IndexForStation");
            int functionid = fun == null ? 0 : fun.RowId;
            batch.functionid = functionid;
            string batchNo = CommonFunction.GetPHPTime().ToString() + "_" + (Session["caller"] as Caller).user_id + "_";
            batch.kuser = (Session["caller"] as Caller).user_email;
            try
            {
                int writer_id = (Session["caller"] as Caller).user_id;
                foreach (var pm in list)
                {
                    batch.batchno = batchNo + pm.product_id;//批號
                    List<MakePriceCustom> PriceStore = new List<MakePriceCustom>();
                    if (!string.IsNullOrEmpty(pm.product_id.ToString()))//如果商品編號不為空
                    {
                        // List<PriceMaster> pMList = new List<PriceMaster>();
                        _priceMasterMgr = new PriceMasterMgr(connectionString);
                        _priceMasterTsMgr = new PriceMasterTsMgr(connectionString);
                        //PriceMaster pMaster = new PriceMaster();
                        string result = string.Empty;
                        if (pm.combination != 0)
                        {
                            if (pm.price_type == 2)
                            {
                                //add by zhuoqin0830w  2015/04/02  判斷是否是  依原成本設定值
                                result = ProductByPriceEach(pm, batch, list_priceMaster, chkCost);
                            }
                            else
                            {
                                //add by zhuoqin0830w  2015/04/02  判斷是否是  依原成本設定值
                                result = AddItemProduct(pm, batch, priceType, list_priceMaster, chkCost);
                            }
                            if (result != "success")
                            {
                                error += result + ",";
                            }
                        }
                        else
                        {
                            error += "異常數據" + ",";
                        }
                    }
                }
                if (error != "")
                {
                    json = "{success:false,msg:'" + error.Remove(error.Length - 1, 1) + "'}";
                }
                // json = "{success:false,msg:'" + error.Remove(error.Length - 1, 1) + "'}";
            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                json = "{success:false,msg:'" + Resources.Product.SAVE_FAIL + "'}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }