public HttpResponseBase GetPriceMaster()
        {
            string json = string.Empty;

            bool isEdit = false;

            try
            {
                BLL.gigade.Model.Vendor vendorModel = (BLL.gigade.Model.Vendor)Session["vendor"];
                int writerID = (int)vendorModel.vendor_id;
                uint pid = 0;

                if (!string.IsNullOrEmpty(Request.Form["ProductId"]))
                {
                    if (uint.TryParse(Request.Form["ProductId"].ToString(), out pid))
                    {
                        _priceMasterMgr = new PriceMasterMgr(connectionString);
                        List<PriceMasterCustom> proSiteCustom = _priceMasterMgr.Query(new PriceMaster { product_id = pid });
                        StringBuilder strJson = new StringBuilder("[");
                        if (proSiteCustom != null)
                        {
                            foreach (var item in proSiteCustom)
                            {
                                strJson.Append("{");
                                strJson.AppendFormat("price_master_id:{0},product_id:{1},site_id:{2},site_name:\"{3}\"", item.price_master_id, item.product_id, item.site_id, item.site_name);
                                strJson.AppendFormat(",product_name:\"{0}\",bonus_percent:{1},default_bonus_percent:{2}", item.product_name, item.bonus_percent, item.default_bonus_percent);
                                strJson.AppendFormat(",user_level:{0},user_id:{1},user_email:\"{2}\",user_level_name:\"{3}\"", item.user_level, item.user_id, item.user_email, item.user_level_name);
                                strJson.AppendFormat(",event_start:\"{0}\"", item.event_start);
                                strJson.AppendFormat(",event_end:\"{0}\",status:\"{1}\",accumulated_bonus:\"{2}\"", item.event_end, item.status, item.accumulated_bonus);
                                strJson.AppendFormat(",bonus_percent_start:\"{0}\",bonus_percent_end:\"{1}\",valid_start:\"{2}\",valid_end:\"{3}\"", item.bonus_percent_start, item.bonus_percent_end, item.valid_start, item.valid_end);
                                if (item.same_price == 1)
                                {
                                    strJson.Append(",same_price:\"on\"");
                                    strJson.AppendFormat(",item_cost:{0},item_money:{1}", item.cost, item.price);
                                    strJson.AppendFormat(",event_cost:{0},event_money:{1}", item.event_cost, item.event_price);
                                }
                                strJson.Append("}");
                            }
                        }
                        strJson.Append("]");
                        json = strJson.ToString().Replace("}{", "},{");

                    }
                    else
                    {
                        _priceMasterTempMgr = new PriceMasterTempMgr(connectionString);

                        PriceMasterTemp query = new PriceMasterTemp();
                        query.writer_Id = writerID;
                        query.combo_type = COMBO_TYPE;
                        query.product_id = Request.Form["ProductId"].ToString();

                        if (!string.IsNullOrEmpty(Request.Params["IsEdit"]))
                        {
                            isEdit = Request.Params["IsEdit"].ToString() == "true" ? true : false;
                        }
                        if (isEdit)
                        {
                            List<PriceMasterCustom> proSiteCustom = _priceMasterTempMgr.QueryProdSiteByVendor(query);
                            StringBuilder strJson = new StringBuilder("[");
                            if (proSiteCustom != null)
                            {
                                foreach (var item in proSiteCustom)
                                {
                                    strJson.Append("{");
                                    strJson.AppendFormat("price_master_id:{0},product_id:\"{1}\",site_id:{2},site_name:\"{3}\"", item.price_master_id, item.vendor_product_id, item.site_id, item.site_name);
                                    strJson.AppendFormat(",product_name:\"{0}\",bonus_percent:{1},default_bonus_percent:{2}", item.product_name, item.bonus_percent, item.default_bonus_percent);
                                    strJson.AppendFormat(",user_level:{0},user_id:{1},user_email:\"{2}\",user_level_name:\"{3}\"", item.user_level, item.user_id, item.user_email, item.user_level_name);
                                    strJson.AppendFormat(",event_start:\"{0}\"", item.event_start);
                                    strJson.AppendFormat(",event_end:\"{0}\",status:\"{1}\",accumulated_bonus:\"{2}\"", item.event_end, item.status, item.accumulated_bonus);
                                    strJson.AppendFormat(",bonus_percent_start:\"{0}\",bonus_percent_end:\"{1}\",valid_start:\"{2}\",valid_end:\"{3}\"", item.bonus_percent_start, item.bonus_percent_end, item.valid_start, item.valid_end);
                                    if (item.same_price == 1)
                                    {
                                        strJson.Append(",same_price:\"on\"");
                                        strJson.AppendFormat(",item_cost:{0},item_money:{1}", item.cost, item.price);
                                        strJson.AppendFormat(",event_cost:{0},event_money:{1}", item.event_cost, item.event_price);
                                    }
                                    strJson.Append("}");
                                }
                            }
                            strJson.Append("]");
                            json = strJson.ToString().Replace("}{", "},{");

                        }
                        else
                        {
                            json = JsonConvert.SerializeObject(_priceMasterTempMgr.QueryByVendor(query));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                json = "[]";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
        public HttpResponseBase UpdateItemPrice()
        {
            string json = string.Empty;
            try
            {
                BLL.gigade.Model.Vendor vendorModel = (BLL.gigade.Model.Vendor)Session["vendor"];
                int writerID = (int)vendorModel.vendor_id;

                JavaScriptSerializer jsSer = new JavaScriptSerializer();
                uint priceMasterId = uint.Parse(Request.Form["price_master_id"] ?? "0");
                int same_price = (Request.Form["same_price"] ?? "") == "on" ? 1 : 0;
                string start = Request.Form["event_start"] ?? "";
                string end = Request.Form["event_end"] ?? "";
                string valid_start = Request.Form["valid_start"];
                string valid_end = Request.Form["valid_end"];
                string items = Request.Form["Items"];
                List<ItemPrice> newPrices = jsSer.Deserialize<List<ItemPrice>>(items);


                _priceMasterTempMgr = new PriceMasterTempMgr(connectionString);
                PriceMasterCustom PriceMasterTemp = _priceMasterTempMgr.QueryProdSiteByVendor(new PriceMasterTemp { price_master_id = priceMasterId }).FirstOrDefault();
                if (PriceMasterTemp != null)
                {
                    #region 處理PriceMasterTemp
                    PriceMasterTemp.product_name = Request.Form["product_name"] ?? "";
                    PriceMasterTemp.same_price = same_price;
                    PriceMasterTemp.user_level = 1;//会员等级默认为 1:普通会员
                    PriceMasterTemp.user_id = 0;
                    PriceMasterTemp.site_id = 1;//默认站台为吉甲地
                    if (!string.IsNullOrEmpty(start))
                    {
                        PriceMasterTemp.event_start = Convert.ToUInt32(CommonFunction.GetPHPTime(start));
                    }
                    if (!string.IsNullOrEmpty(end))
                    {
                        PriceMasterTemp.event_end = Convert.ToUInt32(CommonFunction.GetPHPTime(end));
                    }

                    if (!string.IsNullOrEmpty(valid_start))
                    {
                        PriceMasterTemp.valid_start = Convert.ToInt32(CommonFunction.GetPHPTime(valid_start));
                    }
                    if (!string.IsNullOrEmpty(valid_end))
                    {
                        PriceMasterTemp.valid_end = Convert.ToInt32(CommonFunction.GetPHPTime(valid_end));
                    }

                    PriceMasterTemp.price = Convert.ToInt32(newPrices.Min(m => m.item_money));
                    PriceMasterTemp.event_price = Convert.ToInt32(newPrices.Min(m => m.event_money));
                    if (same_price == 0)
                    {
                        PriceMasterTemp.max_price = Convert.ToInt32(newPrices.Max(m => m.item_money));
                        PriceMasterTemp.max_event_price = Convert.ToInt32(newPrices.Max(m => m.event_money));
                    }
                    PriceMasterTemp.cost = Convert.ToInt32(newPrices.Min(m => m.item_cost));
                    PriceMasterTemp.event_cost = Convert.ToInt32(newPrices.Min(m => m.event_cost));
                    #endregion

                    bool isExist = false;
                    List<PriceMasterCustom> masterList = _priceMasterTempMgr.QueryProdSiteByVendor(new PriceMasterTemp { site_id = PriceMasterTemp.site_id, user_id = PriceMasterTemp.user_id, user_level = PriceMasterTemp.user_level, product_id = Convert.ToString(PriceMasterTemp.vendor_product_id) });
                    List<PriceMasterCustom> resultList = masterList.Where(p => p.price_master_id != PriceMasterTemp.price_master_id).ToList();
                    if (resultList != null && resultList.Count() > 0)
                    {
                        if (PriceMasterTemp.user_id != 0 || (PriceMasterTemp.user_id == 0 && resultList.Where(p => p.user_id == 0).Count() > 0))
                        {
                            json = "{success:false,msg:'" + Resources.VendorProduct.SITE_EXIST + "'}";
                            isExist = true;
                        }
                    }
                    if (!isExist)
                    {
                        ArrayList excuteSql = new ArrayList();
                        // ProductTemp productTemp = null;
                        if (PriceMasterTemp.site_id == 1 && PriceMasterTemp.user_level == 1 && PriceMasterTemp.user_id == 0)
                        {
                            //没有购物金。所以不处理product_temp
                            //#region 處理productTemp
                            //_productTempMgr = new ProductTempMgr(connectionString);
                            //productTemp = _productTempMgr.GetProTempByVendor(new ProductTemp { product_id = PriceMasterTemp.vendor_product_id, Create_Channel = 2 }).FirstOrDefault();

                            //excuteSql.Add(_productTempMgr.Update(productTemp));
                            //#endregion

                            #region 處理ProductItem
                            _productItemTempMgr = new ProductItemTempMgr(connectionString);
                            List<ProductItemTemp> productItems = _productItemTempMgr.QueryByVendor(new ProductItemTemp { Product_Id = Convert.ToString(PriceMasterTemp.vendor_product_id), Writer_Id = writerID });
                            if (productItems != null)
                            {
                                if (!string.IsNullOrEmpty(start))
                                {
                                    productItems.ForEach(m => m.Event_Product_Start = Convert.ToUInt32(CommonFunction.GetPHPTime(start)));
                                }
                                if (!string.IsNullOrEmpty(end))
                                {
                                    productItems.ForEach(m => m.Event_Product_End = Convert.ToUInt32(CommonFunction.GetPHPTime(end)));
                                }
                                newPrices.ForEach(m => productItems.Find(n => n.Item_Id == m.item_id).Item_Money = m.item_money);
                                newPrices.ForEach(m => productItems.Find(n => n.Item_Id == m.item_id).Item_Cost = m.item_cost);
                                newPrices.ForEach(m => productItems.Find(n => n.Item_Id == m.item_id).Event_Item_Money = m.event_money);
                                newPrices.ForEach(m => productItems.Find(n => n.Item_Id == m.item_id).Event_Item_Cost = m.event_cost);

                                productItems.ForEach(m => excuteSql.Add(_productItemTempMgr.UpdateByVendor(m)));
                            }
                            #endregion
                        }


                        bool result = true;
                        //处理PriceMasterTemp
                        excuteSql.Add(_priceMasterTempMgr.UpdateTs(PriceMasterTemp));
                        _itemPriceTempMgr = new ItemPriceTempMgr(connectionString);
                        if (!_itemPriceTempMgr.UpdateByVendor(excuteSql))//执行sql语句
                        {
                            result = false;
                        }

                        json = "{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);
                json = "{success:false,msg:'" + Resources.VendorProduct.SAVE_FAIL + "'}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
        public HttpResponseBase GetPriceMaster()
        {
            string json = string.Empty;
            try
            {
                List<PriceMasterCustom> proSiteCustom = new List<PriceMasterCustom>();
                if (!string.IsNullOrEmpty(Request.Params["ProductId"]))
                {
                    string Vendor_PId = Request.Params["ProductId"];

                    BLL.gigade.Model.Vendor vendorModel = (BLL.gigade.Model.Vendor)Session["vendor"];
                    int writer_id = Convert.ToInt32(vendorModel.vendor_id);

                    uint product_id = 0;
                    if (uint.TryParse(Request.Form["ProductId"], out product_id)) //正式表數據
                    {
                        _priceMasterMgr = new PriceMasterMgr(connectionString);
                        proSiteCustom = _priceMasterMgr.Query(new PriceMaster { product_id = product_id, child_id = Convert.ToInt32(product_id) });
                    }
                    else
                    {
                        _pMasterTempMgr = new PriceMasterTempMgr(connectionString);
                        proSiteCustom = _pMasterTempMgr.QueryProdSiteByVendor(new PriceMasterTemp { product_id = Vendor_PId, combo_type = COMBO_TYPE, child_id = Vendor_PId, writer_Id = writer_id });
                    }
                    StringBuilder strJson = new StringBuilder("[");
                    if (proSiteCustom != null)
                    {
                        foreach (var item in proSiteCustom)
                        {
                            var vendorpid = item.product_id != 0 ? item.product_id.ToString() : item.vendor_product_id;
                            strJson.Append("{");
                            strJson.AppendFormat("price_master_id:{0},product_id:\"{1}\",site_id:{2},site_name:\"{3}\"", item.price_master_id, vendorpid, item.site_id, item.site_name);
                            strJson.AppendFormat(",product_name:\"{0}\",bonus_percent:{1},default_bonus_percent:{2}", item.product_name, item.bonus_percent, item.default_bonus_percent);
                            strJson.AppendFormat(",user_level_name:\"{0}\",user_email:\"{1}\",user_level:{2}", item.user_level_name, item.user_email, item.user_level);
                            strJson.AppendFormat(",event_start:\"{0}\",user_id:{1}", item.event_start, item.user_id);
                            strJson.AppendFormat(",event_end:\"{0}\"", item.event_end);
                            strJson.AppendFormat(",cost:\"{0}\"", item.cost);
                            strJson.AppendFormat(",event_cost:\"{0}\"", item.event_cost);
                            strJson.AppendFormat(",price_status:\"{0}\"", item.price_status);
                            //if (item.same_price == 1)//edit by hufeng0813w 2014/06/16 Reason:所有單一商品規格不同價時 也去master表中的價格和活動價格
                            //{
                            strJson.AppendFormat(",price:\"{0}\"", item.price);
                            strJson.AppendFormat(",event_price:\"{0}\"", item.event_price);
                            //}
                            strJson.AppendFormat(",status:\"{0}\",accumulated_bonus:{1},bonus_percent_start:\"{2}\",bonus_percent_end:\"{3}\",same_price:{4},valid_start:\"{5}\",valid_end:\"{6}\"", item.status, item.accumulated_bonus, item.bonus_percent_start, item.bonus_percent_end, item.same_price, item.valid_start, item.valid_end);
                            strJson.Append("}");
                        }
                    }
                    strJson.Append("]");
                    json = strJson.ToString().Replace("}{", "},{");
                }
            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                json = "[]";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }