private string GetBrandJson(int ScenceID, int CategoryID)
        {
            StringBuilder result = new StringBuilder();
            StringWriter sw = new StringWriter(result);
            JsonWriter writer = new JsonWriter(sw);

            writer.Formatting = Formatting.Indented;

            DataTable dt = new CategoryConditionBll().GetConditionBrandList(ScenceID, CategoryID);
            //new BrandCategoryRelationBll().GetCategoryBrandList(CategoryID);

            writer.WriteStartArray();

            foreach (DataRow row in dt.Rows)
            {
                writer.WriteStartObject();

                WriteJsonKeyValue(writer, "brandid", row["brandid"].ToString());
                WriteJsonKeyValue(writer, "brandname", row["brandname"].ToString());

                writer.WriteEndObject();
            }

            writer.WriteEndArray();
            writer.Close();

            return result.ToString();
        }
        private void SaveCateConditions()
        {
            CategoryConditionBll ccbll = new CategoryConditionBll();
            CategoryConditionModel pmodel =null;
            int scenceId = int.Parse(lblSenceId.Text);
            int cateId = int.Parse(lblCateId.Text);
            pmodel = GetPriceCondition(scenceId, cateId);
            if (pmodel != null)
            {
                ccbll.Save(pmodel);
            }
            pmodel = GetBrandCondition(scenceId, cateId);
            if (pmodel != null)
            {
                ccbll.Save(pmodel);
            }
            pmodel = GetSubCondition(scenceId, cateId);
            if (pmodel != null)
            {
                ccbll.Save(pmodel);
            }

            foreach (RepeaterItem item in rpItems.Items)
            {
                pmodel = GetParaCondition(scenceId, cateId, item);
                if (pmodel != null)
                {
                    ccbll.Save(pmodel);
                }
            }
        }
 private void PresetConditionItems(int scenceId, int cateId)
 {
     CategoryConditionBll ccbll = new CategoryConditionBll();
     List<CategoryConditionModel> cclist = ccbll.GetModelList(scenceId, cateId);
     foreach (CategoryConditionModel ccmodel in cclist)
     {
         if (ccmodel.IsPrice) // 如果是价格:between 0 and 100
         {
             string regPrice = @"between (?<min>\d+) and (?<max>\d+)";
             Match match = Regex.Match(ccmodel.RuleValue, regPrice, RegexOptions.IgnoreCase);
             if (match.Success)
             {
                 if (match.Groups["min"].Success)
                     txtMinPrice.Text = match.Groups["min"].Value;
                 if (match.Groups["max"].Success)
                     txtMaxPrice.Text = match.Groups["max"].Value;
             }
         }
         else if (ccmodel.IsBrand) // 如果是品牌: in (0,2,3,4)
         {
             string[] sels = ccmodel.RuleValue.Substring(3).TrimEnd(')').Split(',');
             foreach (string str in sels)
             {
                 ListItem item = cblBrands.Items.FindByValue(str);
                 if (item != null)
                 {
                     item.Selected = true;
                 }
             }
         }
         else if (ccmodel.IsSubCategory) // 如果是子分类(最终分类):in (2,3,4)
         {
             string[] sels = ccmodel.RuleValue.Substring(3).TrimEnd(')').Split(',');
             foreach (string str in sels)
             {
                 ListItem item = cblSubCate.Items.FindByValue(str);
                 if (item != null)
                 {
                     item.Selected = true;
                 }
             }
         }
         else if (ccmodel.IsParameter)
         {
             string paraidreg = @"paraid=(?<paraid>\d+)";
             Match match = Regex.Match(ccmodel.RuleName, paraidreg, RegexOptions.IgnoreCase);
             if (match.Success && match.Groups["paraid"].Success)
             {
                 string paraid = match.Groups["paraid"].Value;
                 foreach (RepeaterItem item in rpItems.Items)
                 {
                     Label lblPropName = item.FindControl("lblPropName") as Label;
                     CheckBoxList cblPara = item.FindControl("cblPara") as CheckBoxList;
                     if (lblPropName.ToolTip == paraid)
                     {
                         foreach (ListItem citem in cblPara.Items)
                         {
                             citem.Selected = ccmodel.RuleValue.IndexOf("'" + citem.Value + "'") >= 0;
                         }
                     }
                 }
             }
         }
     }
 }
        private string GetProductListJson(int ScenceID, int CategoryID,int FatherCategoryID, int BrandID, string ProductName,int OrderType)
        {
            bool HasSubCateogry;
            DataTable dt = new CategoryConditionBll().GetCategoryProductList(ScenceID, CategoryID, FatherCategoryID, BrandID, ProductName,OrderType,out HasSubCateogry);

            StringBuilder result = new StringBuilder();
            StringWriter sw = new StringWriter(result);
            JsonWriter writer = new JsonWriter(sw);

            writer.Formatting = Formatting.Indented;

            writer.WriteStartArray();

            foreach (DataRow row in dt.Rows)
            {
                writer.WriteStartObject();
                WriteJsonKeyValue(writer, "productid", row["productid"].ToString());
                WriteJsonKeyValue(writer, "productname", row["productname"].ToString());
                WriteJsonKeyValue(writer, "url", String.Format("/product-{0}.html", row["productid"]));
                WriteJsonKeyValue(writer, "image", ProductMainImageRule.GetMainImageUrl(row["smallimage"].ToString()));
                WriteJsonKeyValue(writer, "price", row["merchantprice"].ToString());
                WriteJsonKeyValue(writer, "categoryid", HasSubCateogry ? row["cateid"].ToString() : "0");
                writer.WriteEndObject();
            }

            writer.WriteEndArray();
            writer.Close();

            return result.ToString();
        }
        private string GetCategoryJson(int ScenceID)
        {
            StringBuilder result = new StringBuilder();
            StringWriter sw = new StringWriter(result);
            JsonWriter writer = new JsonWriter(sw);

            writer.Formatting = Formatting.Indented;

            List<SolutionCategoryModel> Categories = new SolutionCategoryBll().GetModelList("senceid = " + ScenceID);

            writer.WriteStartArray();

            foreach (SolutionCategoryModel model in Categories)
            {
                writer.WriteStartObject();

                WriteJsonKeyValue(writer, "categoryid", model.CateId.ToString());
                WriteJsonKeyValue(writer, "categoryname", model.Remark);

                writer.WritePropertyName("subcates");
                writer.WriteStartArray();
                DataTable subTable = new CategoryConditionBll().GetConditionSubCategory(ScenceID, model.CateId);
                if(subTable!=null)
                    foreach (DataRow row in subTable.Rows)
                    {
                        writer.WriteStartObject();

                        WriteJsonKeyValue(writer, "categoryid", row["cateid"].ToString());
                        WriteJsonKeyValue(writer, "categoryname", row["catename"].ToString());

                        writer.WriteEndObject();
                    }
                writer.WriteEndArray();

                writer.WriteEndObject();
            }

            writer.WriteEndArray();
            writer.Close();

            return result.ToString();
        }