重写Filter类就可以了。
用法:
if(Session["big5"].ToString()=="2"){Response.Filter = new DreamZone.Core.CG2BFilter(Response.Filter);}
CG2BFilter.cs文件如下:
1using System;
2using System.Text;
3using System.Text.RegularExpressions;
4using System.IO;
5using System.Web;
6namespace DreamZone.Core
7{
8 /// <summary>
9 /// CG2BFilter 的摘要说明。
10 /// </summary>
11
12 public class CG2BFilter : Stream
13 {
14 Stream responseStream;
15 long position;
16 StringBuilder responseHtml;
17
18 public CG2BFilter (Stream inputStream)
19 {
20 responseStream = inputStream;
21 responseHtml = new StringBuilder ();
22 }
23
24 Filter overrides
76
77 转换任务
88自定义函数
100 }
101}
102
103
2using System.Text;
3using System.Text.RegularExpressions;
4using System.IO;
5using System.Web;
6namespace DreamZone.Core
7{
8 /// <summary>
9 /// CG2BFilter 的摘要说明。
10 /// </summary>
11
12 public class CG2BFilter : Stream
13 {
14 Stream responseStream;
15 long position;
16 StringBuilder responseHtml;
17
18 public CG2BFilter (Stream inputStream)
19 {
20 responseStream = inputStream;
21 responseHtml = new StringBuilder ();
22 }
23
24 Filter overrides
76
77 转换任务
88自定义函数
100 }
101}
102
103
2.新转换类CG2BFilter(要引用Microsoft.VisualBasic.dll)
1using System;
2using System.Text;
3using System.Text.RegularExpressions;
4using System.IO;
5using System.Web;
6
7/// <summary>
8/// CG2BFilter 的摘要说明。
9/// </summary>
10public class CG2BFilter : Stream
11{
12 Stream responseStream;
13 long position;
14 StringBuilder responseHtml;
15
16 public CG2BFilter()
17 {
18 //后期添加,以便可以对文本直接转换
19 }
20
21 public CG2BFilter(Stream inputStream)
22 {
23 responseStream = inputStream;
24 responseHtml = new StringBuilder();
25 }
26
27 Filter overrides
79
80 转换任务
91 自定义函数
103}
104
2using System.Text;
3using System.Text.RegularExpressions;
4using System.IO;
5using System.Web;
6
7/// <summary>
8/// CG2BFilter 的摘要说明。
9/// </summary>
10public class CG2BFilter : Stream
11{
12 Stream responseStream;
13 long position;
14 StringBuilder responseHtml;
15
16 public CG2BFilter()
17 {
18 //后期添加,以便可以对文本直接转换
19 }
20
21 public CG2BFilter(Stream inputStream)
22 {
23 responseStream = inputStream;
24 responseHtml = new StringBuilder();
25 }
26
27 Filter overrides
79
80 转换任务
91 自定义函数
103}
104
3.页面基类BasePage
1using System;
2using System.Data;
3using System.Configuration;
4using System.Web;
5using System.Web.Security;
6using System.Web.UI;
7using System.Web.UI.WebControls;
8using System.Web.UI.WebControls.WebParts;
9using System.Web.UI.HtmlControls;
10
11/// <summary>
12/// BasePage 的摘要说明
13/// </summary>
14public class BasePage : System.Web.UI.Page
15{
16 public BasePage()
17 {
18 //
19 // TODO: 在此处添加构造函数逻辑
20 //
21 }
22
23 protected override void OnInit(EventArgs e)
24 {
25 //if (!String.IsNullOrEmpty(Request.QueryString["lan"]) && Request.QueryString["lan"].ToLower() == "big5")
26 //{
27 // Response.Filter = new CG2BFilter(Response.Filter);
28 //}
29 if (Session["SiteLanguage"] == "Big5")
30 {
31 Response.Filter = new CG2BFilter(Response.Filter);
32 }
33
34 }
35}
36
2using System.Data;
3using System.Configuration;
4using System.Web;
5using System.Web.Security;
6using System.Web.UI;
7using System.Web.UI.WebControls;
8using System.Web.UI.WebControls.WebParts;
9using System.Web.UI.HtmlControls;
10
11/// <summary>
12/// BasePage 的摘要说明
13/// </summary>
14public class BasePage : System.Web.UI.Page
15{
16 public BasePage()
17 {
18 //
19 // TODO: 在此处添加构造函数逻辑
20 //
21 }
22
23 protected override void OnInit(EventArgs e)
24 {
25 //if (!String.IsNullOrEmpty(Request.QueryString["lan"]) && Request.QueryString["lan"].ToLower() == "big5")
26 //{
27 // Response.Filter = new CG2BFilter(Response.Filter);
28 //}
29 if (Session["SiteLanguage"] == "Big5")
30 {
31 Response.Filter = new CG2BFilter(Response.Filter);
32 }
33
34 }
35}
36
4.切换控件Header.ascx
1 <asp:ImageButton
2 ID="SiteLanguage" runat="server" ImageUrl="~/Images/big5.gif" OnClick="SiteLanguage_Click" CausesValidation="false" /></li>
3
4
5
6using System;
7using System.Data;
8using System.Configuration;
9using System.Collections;
10using System.Web;
11using System.Web.Security;
12using System.Web.UI;
13using System.Web.UI.WebControls;
14using System.Web.UI.WebControls.WebParts;
15using System.Web.UI.HtmlControls;
16
17public partial class Controls_Header : System.Web.UI.UserControl
18{
19 protected bool _isindex;
20 public bool IsIndex
21 {
22 get { return _isindex; }
23 set { _isindex = value; }
24 }
25 protected void Page_Load(object sender, EventArgs e)
26 {
27 ShowLanguage();
28 }
29
30 protected void SiteLanguage_Click(object sender, ImageClickEventArgs e)
31 {
32 switchLanguage();
33 Response.Redirect(Request.RawUrl);
34 //ShowLanguage();
35 }
36
37
38 private void switchLanguage()
39 {
40 if (Session["SiteLanguage"] == "Big5")
41 {
42 Session["SiteLanguage"] = "GB";
43 }
44 else
45 {
46 Session["SiteLanguage"] = "Big5";
47 }
48 }
49
50 private void ShowLanguage()
51 {
52 //string url = Request.RawUrl.ToLower();
53 //if (url.IndexOf("lan=gb") > 0 || url.IndexOf("lan=big5")>0)
54 //{
55 // url = url.Replace("lan=gb", "lan={t}").Replace("lan=big5", "lan={t}");
56 //}
57 //else
58 //{
59 // if (url.IndexOf("?") > 0)
60 // {
61 // url = url + "&lan={t}";
62 // }
63 // else
64 // {
65 // url = url + "?lan={t}";
66 // }
67 //}
68 //if (String.IsNullOrEmpty(Request.QueryString["lan"]) || Request.QueryString["lan"].ToLower()=="gb")
69 //{
70 // url = url.Replace("lan={t}", "lan=big5");
71 // navurl.Text = "<a href='" + url + "'><img src='/images/big5.gif' border='0' /></a>";
72 //}
73 //else
74 //{
75 // url = url.Replace("lan={t}", "lan=gb");
76 // navurl.Text = "<a href='" + url + "'><img src='/images/gb.gif' border='0' /></a>";
77 //}
78 if (Session["SiteLanguage"] == "Big5")
79 {
80 SiteLanguage.ImageUrl = "~/Images/gb.gif";
81 SiteLanguage.ToolTip = "简体版本";
82 }
83 else
84 {
85 SiteLanguage.ImageUrl = "~/Images/big5.gif";
86 SiteLanguage.ToolTip = "繁体版本";
87 }
88
89 }
90
91}
92
2 ID="SiteLanguage" runat="server" ImageUrl="~/Images/big5.gif" OnClick="SiteLanguage_Click" CausesValidation="false" /></li>
3
4
5
6using System;
7using System.Data;
8using System.Configuration;
9using System.Collections;
10using System.Web;
11using System.Web.Security;
12using System.Web.UI;
13using System.Web.UI.WebControls;
14using System.Web.UI.WebControls.WebParts;
15using System.Web.UI.HtmlControls;
16
17public partial class Controls_Header : System.Web.UI.UserControl
18{
19 protected bool _isindex;
20 public bool IsIndex
21 {
22 get { return _isindex; }
23 set { _isindex = value; }
24 }
25 protected void Page_Load(object sender, EventArgs e)
26 {
27 ShowLanguage();
28 }
29
30 protected void SiteLanguage_Click(object sender, ImageClickEventArgs e)
31 {
32 switchLanguage();
33 Response.Redirect(Request.RawUrl);
34 //ShowLanguage();
35 }
36
37
38 private void switchLanguage()
39 {
40 if (Session["SiteLanguage"] == "Big5")
41 {
42 Session["SiteLanguage"] = "GB";
43 }
44 else
45 {
46 Session["SiteLanguage"] = "Big5";
47 }
48 }
49
50 private void ShowLanguage()
51 {
52 //string url = Request.RawUrl.ToLower();
53 //if (url.IndexOf("lan=gb") > 0 || url.IndexOf("lan=big5")>0)
54 //{
55 // url = url.Replace("lan=gb", "lan={t}").Replace("lan=big5", "lan={t}");
56 //}
57 //else
58 //{
59 // if (url.IndexOf("?") > 0)
60 // {
61 // url = url + "&lan={t}";
62 // }
63 // else
64 // {
65 // url = url + "?lan={t}";
66 // }
67 //}
68 //if (String.IsNullOrEmpty(Request.QueryString["lan"]) || Request.QueryString["lan"].ToLower()=="gb")
69 //{
70 // url = url.Replace("lan={t}", "lan=big5");
71 // navurl.Text = "<a href='" + url + "'><img src='/images/big5.gif' border='0' /></a>";
72 //}
73 //else
74 //{
75 // url = url.Replace("lan={t}", "lan=gb");
76 // navurl.Text = "<a href='" + url + "'><img src='/images/gb.gif' border='0' /></a>";
77 //}
78 if (Session["SiteLanguage"] == "Big5")
79 {
80 SiteLanguage.ImageUrl = "~/Images/gb.gif";
81 SiteLanguage.ToolTip = "简体版本";
82 }
83 else
84 {
85 SiteLanguage.ImageUrl = "~/Images/big5.gif";
86 SiteLanguage.ToolTip = "繁体版本";
87 }
88
89 }
90
91}
92
5.WebService转换
1 /// <summary>
2 /// 品牌下类别
3 /// </summary>
4 /// <param name="knownCategoryValues"></param>
5 /// <param name="category"></param>
6 /// <returns></returns>
7 [WebMethod(EnableSession = true)]
8 public AjaxControlToolkit.CascadingDropDownNameValue[] QueryCategoriesByBrand(string knownCategoryValues,
9 string category)
10 {
11 StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
12
13 if (!kv.ContainsKey("Brand") || String.IsNullOrEmpty(kv["Brand"]))
14 return null;
15 string _brand = kv["Brand"];
16 DataSet ds = SqlHelper.ExecuteDataset(SqlHelper.ConnectionString, "SP_QueryCategoriesByBrand", _brand);
17 List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
18 foreach (DataRow dr in ds.Tables[0].Rows)
19 {
20 string tmpStr = dr["CategoryName"].ToString();
21 if (Session["SiteLanguage"] == "Big5")
22 {
23 CG2BFilter switchLanguage = new CG2BFilter();
24 tmpStr = switchLanguage.Simplified2Traditional(tmpStr);
25 }
26 values.Add(new CascadingDropDownNameValue(tmpStr, dr["CategoryID"].ToString()));
27 }
28 return values.ToArray();
29 }
2 /// 品牌下类别
3 /// </summary>
4 /// <param name="knownCategoryValues"></param>
5 /// <param name="category"></param>
6 /// <returns></returns>
7 [WebMethod(EnableSession = true)]
8 public AjaxControlToolkit.CascadingDropDownNameValue[] QueryCategoriesByBrand(string knownCategoryValues,
9 string category)
10 {
11 StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
12
13 if (!kv.ContainsKey("Brand") || String.IsNullOrEmpty(kv["Brand"]))
14 return null;
15 string _brand = kv["Brand"];
16 DataSet ds = SqlHelper.ExecuteDataset(SqlHelper.ConnectionString, "SP_QueryCategoriesByBrand", _brand);
17 List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
18 foreach (DataRow dr in ds.Tables[0].Rows)
19 {
20 string tmpStr = dr["CategoryName"].ToString();
21 if (Session["SiteLanguage"] == "Big5")
22 {
23 CG2BFilter switchLanguage = new CG2BFilter();
24 tmpStr = switchLanguage.Simplified2Traditional(tmpStr);
25 }
26 values.Add(new CascadingDropDownNameValue(tmpStr, dr["CategoryID"].ToString()));
27 }
28 return values.ToArray();
29 }
6.页面继承BasePage