日期:2014-05-20 浏览次数:20677 次
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; } } }