日期:2014-05-20  浏览次数:20694 次

小弟愚蠢,这个功能只实现一半,实在苦恼!
小弟愚蠢,这个功能只实现一半,实在苦恼!

做了一两天了,跟这个网站的产品筛选功能类似的。
http://sports.8t8x.com/product/yumaoqiu.htm
下面的代码我只能处理URL参数里有的字段,让它不追加重复的筛选ID,但是同类的切无法让它不追加,比如
"材质分类:"这个选项里有"碳素纤维 铝合金 铝碳一体 铁合金"
我选了碳素纤维,碳素纤维的ID是1。现在再选铝合金,铝合金的URL参数不应该包含1的。可是我无法实现
C# code

using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MTC.Web.Aspx
{
    public partial class Test : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string allSelectField = "48,49,-48,50,-48,51,-|45,46,-45,47,-|2,3,-2,4,-2,5,-2,29,-2,30,-2,31,-2,32,-2,33,-2,34,-2,35,-2,36,-2,37,-|1,6,-

1,7,-1,52,-1,53,-|8,9,-8,10,-8,11,-|38,39,-38,40,-38,41,-|42,43,-42,44,-|";
            allSelectField = allSelectField.Replace(",-|", "|");
            allSelectField = allSelectField.Replace(",-", "-");
            allSelectField = allSelectField.Substring(0,allSelectField.Length - 1);
            string[] groupArray = allSelectField.Split('|');  //组数组
            string[] fieldArray; //大类数组
            string[] SmallFieldArray; //小类数组

            string url = "50-46-29"; //提交的查询URL
            string[] urlArray = url.Split('-');  //URL数组
            Response.Write("URL is:" + url + "<br />");
            for (int i = 0; i < groupArray.Length; i++) //遍历组
            {
                fieldArray = groupArray[i].Split('-');
                for (int ii = 0; ii < fieldArray.Length; ii++)//遍历大类
                {
                    SmallFieldArray = fieldArray[ii].Split(',');
                    Response.Write(myTest2(url, urlArray, SmallFieldArray, fieldArray[ii], groupArray[i]));
                }
            }

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="url">提交的查询URL</param>
        /// <param name="urlArray">URL数组</param>
        /// <param name="SmallFieldArray">小类数组</param>
        /// <param name="fieldArray">大类数组</param>
        /// <param name="groupArray">组数组</param><returns>
        /// <returns>返回的URL参数</returns>
        public string myTest2(string url, string[] urlArray, string[] SmallFieldArray, string fieldArray, string groupArray)
        {
            string myStr = string.Empty;
            int fieldParentId = 0; //上级ID
            int fieldParentId2 = 0; //上级ID
            int field = 0;//下级ID

            for (int ii = 0; ii < urlArray.Length; ii++)
            {
                if (urlArray[ii] == SmallFieldArray[1])
                {

                    fieldParentId = Convert.ToInt32(SmallFieldArray[0]);

                }


                if (fieldParentId != 0 || fieldParentId2 != 0)
                {
                    myStr = url + "-" + fieldParentId + "***********<br />";
                }
         
                else
                {
                    myStr = url + "-" + SmallFieldArray[1] + "<br />";
                }
             
            }
            return myStr;
        }

    }
}




------解决方案--------------------
你现在的思路是都进来后再做字符串处理,你可以在进来之前控制数据,同一类型只能选一个。
------解决方案--------------------
学习了