namespace SWCNToolkit { #region using Namespace using Microsoft.VisualBasic; using System; using System.Collections; using System.Data; using System.Data.OleDb; using System.Data.SqlClient; using System.Drawing; using System.IO; using System.Net; using System.Text; using System.Text.RegularExpressions; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Web.Security; using SWCNToolkit; #endregion #region class BaseKit public class BaseKit { #region private object private Hashtable __ht; #endregion #region public BaseKit() public BaseKit() : base() { this.__ht = new Hashtable(); this["_RegularExpressionOptions"] = RegexOptions.Compiled | RegexOptions.IgnoreCase; } #endregion #region public object this[object key] public object this[object key] { get { return this.__ht[key]; } set { if (this.__ht[key] == null) { this.__ht.Add(key, value); } else { this.__ht[key] = value; } } } #endregion } #endregion #region unuse /* public class CharsetKit : BaseKit { public CharsetKit() : base() { } public string Simple2Tradition(string value) { return Strings.StrConv(value , VbStrConv.TraditionalChinese , 0); } public string Tradition2Simple(string value) { return Strings.StrConv(value , VbStrConv.SimplifiedChinese , 0); } } //Web page translation toolkit public class WebRequestTranslationKit : BaseKit { // public string Simple2Tradition(string url , string bufPath) private StringBuilder _sb; private string _strServiceUrl; public string ServiceUrl { get { return this._strServiceUrl; } set { this._strServiceUrl = value; } } public WebRequestTranslationKit() : base() { this._sb = new StringBuilder(); this.ServiceUrl = ""; } public string Simple2Tradition(string url , string bufPath) { FileInfo fiCompiled = new FileInfo(bufPath + FormsAuthentication.HashPasswordForStoringInConfigFile(url , "MD5") + ".htm"); if (fiCompiled.Exists == true) { return fiCompiled.Name; } WebRequest rq = WebRequest.Create(url); WebResponse rp = rq.GetResponse(); Stream stm = rp.GetResponseStream(); StreamReader stmrd = new StreamReader(stm , Encoding.GetEncoding("gb2312")); char[] chrsBuf = new char[256]; int intCount = stmrd.Read(chrsBuf , 0 , chrsBuf.Length); this._sb = new StringBuilder(); while (intCount > 0) { this._sb.Append(new String(chrsBuf , 0 , intCount)); intCount = stmrd.Read(chrsBuf , 0 , chrsBuf.Length); } rp.Close(); string strDomain = ""; string strDomainRoot = ""; string strDomainPath = ""; string strDomainFile = ""; strDomain = rp.ResponseUri.Scheme + "://" + rp.ResponseUri.Host + ":" + rp.ResponseUri.Port.ToString(); strDomainRoot = strDomain + "/"; string _strROS = rp.ResponseUri.OriginalString; strDomainFile = strDomain; for (int i = 0 ; i < rp.ResponseUri.Segments.Length ; i++) { strDomainFile += rp.ResponseUri.Segments[i]; } strDomainPath = strDomainFile.Substring(0 , strDomainFile.LastIndexOf("/")) + "/"; strDomainFile = strDomainRoot.Substring(0 , strDomainRoot.Length-1) + rp.ResponseUri.AbsolutePath; ArrayList arlRegexs = new ArrayList(); ArrayList arlReplaces = new ArrayList(); RegexOptions rxopt = RegexOptions.Compiled | RegexOptions.IgnoreCase; //Change charset definition for the page // arlRegexs.Add(new Regex(@"<meta\s+http-equiv=\x22Content-Type\x22\s+content=\x22text/html;\s+charset=gb2312\x22>" , _rxopt)); // arlReplaces.Add("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">"); //Clean more than 2 blank characters arlRegexs.Add(new Regex(@"\s{2,}" , rxopt)); arlReplaces.Add(" "); //<iframe src=http:// arlRegexs.Add(new Regex(@"<iframe\s*href\s*=\s*(?!'|\x22|\?)http://" , rxopt)); arlReplaces.Add("<iframe src=" + this.ServiceUrl + "http://"); //<iframe src='http:// arlRegexs.Add(new Regex(@"<iframe\s*href\s*=\s*'(?!\?)http://" , rxopt)); arlReplaces.Add("<iframe src='" + this.ServiceUrl + "http://"); //<iframe src="http:// arlRegexs.Add(new Regex(@"<iframe\s*href\s*=\s*\x22(?!\?)http://" , rxopt)); arlReplaces.Add("<iframe src=\""+this.ServiceUrl + "http://"); //src=/ arlRegexs.Add(new Regex(@"\s*src\s*=\s*(?!'|\x22)/" , rxopt)); arlReplaces.Add(" src=" + strDomainRoot); //src='/ arlRegexs.Add(new Regex(@"\s*src\s*=\s*'/" , rxopt)); arlReplaces.Add(" src='" + strDomainRoot); //src="/ arlRegexs.Add(new Regex(@"\s*src\s*=\s*\x22/" , rxopt)); arlReplaces.Add(" src=\"" + strDomainRoot); //src= arlRegexs.Add(new Regex(@"\s*src\s*=\s*(?!'|\x22|http://)" , rxopt)); arlReplaces.Add(" src=" + strDomainPath); //src=' arlRegexs.Add(new Regex(@"\s*src\s*=\s*'(?!http://)" , rxopt)); arlReplaces.Add(" src='" + strDomainPath); //src=" arlRegexs.Add(new Regex(@"\s*src\s*=\s*\x22(?!http://)" , rxopt)); arlReplaces.Add(" src=\"" + strDomainPath); //action=' arlRegexs.Add(new Regex(@"\s*action\s*=\s*'(?!/|\?)" , rxopt)); arlReplaces.Add(" action='" + strDomainPath); //action=" arlRegexs.Add(new Regex(@"\s*action\s*=\s*\x22(?!/|\?)" , rxopt)); arlReplaces.Add(" action=\"" + strDomainPath); //action='/ arlRegexs.Add(new Regex(@"\s*action\s*=\s*'/(?!\?)" , rxopt)); arlReplaces.Add(" action='" + strDomainRoot); //action="/ arlRegexs.Add(new Regex(@"\s*action\s*=\s*\x22/(?!\?)" , rxopt)); arlReplaces.Add(" action=\"" + strDomainRoot); //action='? arlRegexs.Add(new Regex(@"\s*action\s*=\s*'\?" , rxopt)); arlReplaces.Add(" action='" + strDomainFile + "?"); //action="? arlRegexs.Add(new Regex(@"\s*action\s*=\s*\x22\?" , rxopt)); arlReplaces.Add(" action=\"" + strDomainFile + "?"); //backgorund=/ arlRegexs.Add(new Regex(@"\s*background\s*=\s*(?!'|\x22)/" , rxopt)); arlReplaces.Add(" background=" + strDomainRoot); //background='/ arlRegexs.Add(new Regex(@"\s*background\s*=\s*'/" , rxopt)); arlReplaces.Add(" background='" + strDomainRoot); //background="/ arlRegexs.Add(new Regex(@"\s*background\s*=\s*\x22/" , rxopt)); arlReplaces.Add(" background=\"" + strDomainRoot); //background= arlRegexs.Add(new Regex(@"\s*background\s*=\s*(?!'|\x22|http://)" , rxopt)); arlReplaces.Add(" background=" + strDomainPath); //background=' arlRegexs.Add(new Regex(@"\s*background\s*=\s*'(?!http://)" , rxopt)); arlReplaces.Add(" background='" + strDomainPath); //background=" arlRegexs.Add(new Regex(@"\s*background\s*=\s*\x22(?!http://)" , rxopt)); arlReplaces.Add(" background=\"" + strDomainPath); //href=http:// arlRegexs.Add(new Regex(@"\s*href\s*=\s*(?!'|\x22|\?)http://" , rxopt)); arlReplaces.Add(" href=" + this.ServiceUrl + "http://"); //href='http:// arlRegexs.Add(new Regex(@"\s*href\s*=\s*'(?!\?)http://" , rxopt)); arlReplaces.Add(" href='" + this.ServiceUrl + "http://"); //href="http:// arlRegexs.Add(new Regex(@"\s*href\s*=\s*\x22(?!\?)http://" , rxopt)); arlReplaces.Add(" href=\"" + this.ServiceUrl + "http://"); //href=.. arlRegexs.Add(new Regex(@"\s*href\s*=\s*(?!'|\x22|\?)\.\." , rxopt)); arlReplaces.Add(" href=" + this.ServiceUrl + strDomainPath + ".."); //href='.. arlRegexs.Add(new Regex(@"\s*href\s*=\s*'(?!\?)\.\." , rxopt)); arlReplaces.Add(" href='" + this.ServiceUrl + strDomainPath + ".."); //href=".. arlRegexs.Add(new Regex(@"\s*href\s*=\s*\x22(?!\?)\.\." , rxopt)); arlReplaces.Add(" href=\"" + this.ServiceUrl + strDomainPath + ".."); //href=/ arlRegexs.Add(new Regex(@"\s*href\s*=\s*(?!'|\x22|\?)/" , rxopt)); arlReplaces.Add(" href=" + this.ServiceUrl + strDomainRoot); //href='/ arlRegexs.Add(new Regex(@"\s*href\s*=\s*'(?!\?)/" , rxopt)); arlReplaces.Add(" href='" + this.ServiceUrl + strDomainRoot); //href="/ arlRegexs.Add(new Regex(@"\s*href\s*=\s*\x22(?!\?)/" , rxopt)); arlReplaces.Add(" href=\"" + this.ServiceUrl + strDomainRoot); //href=? arlRegexs.Add(new Regex(@"\s*href\s*=\s*(?!'|\x22|\?)\?" , rxopt)); arlReplaces.Add(" href=" + this.ServiceUrl + strDomainFile + "?"); //href='? arlRegexs.Add(new Regex(@"\s*href\s*=\s*'\?" , rxopt)); arlReplaces.Add(" href='" + this.ServiceUrl + strDomainFile + "?"); //href="? arlRegexs.Add(new Regex(@"\s*href\s*=\s*\x22\?" , rxopt)); arlReplaces.Add(" href=\"" + this.ServiceUrl + strDomainFile + "?"); //href= arlRegexs.Add(new Regex(@"\s*href\s*=\s*(?!'|\x22|\?|mailto:|http://|\.\.)" , rxopt)); arlReplaces.Add(" href=" + this.ServiceUrl + strDomainPath); //href=' arlRegexs.Add(new Regex(@"\s*href\s*=\s*'(?!mailto:|http://|\?|\.\.)" , rxopt)); arlReplaces.Add(" href='" + this.ServiceUrl + strDomainPath); //href=" arlRegexs.Add(new Regex(@"\s*href\s*=\s*\x22(?!mailto:|http://|\?|\.\.)" , rxopt)); arlReplaces.Add(" href=\"" + this.ServiceUrl + strDomainPath); //<link href=http://localhost/stot/?u= arlRegexs.Add(new Regex(@"<link\s*(rel=\x22stylesheet\x22\s*)?href\s*=\s*" + this.ServiceUrl.Replace("?" , @"\?") , rxopt)); arlReplaces.Add("<link rel=stylesheet href="); //<link href='http://localhost/stot/?u= arlRegexs.Add(new Regex(@"<link\s*(rel=\x22stylesheet\x22\s*)?href\s*=\s*'" + this.ServiceUrl.Replace("?" , @"\?") , rxopt)); arlReplaces.Add("<link rel='stylesheet' href='"); //<link href="http://localhost/stot/?u= arlRegexs.Add(new Regex(@"<link\s*(rel=\x22stylesheet\x22\s*)?href\s*=\s*\x22" + this.ServiceUrl.Replace("?" , @"\?") , rxopt)); arlReplaces.Add("<link rel=\"stylesheet\" href=\""); //url(/ arlRegexs.Add(new Regex(@"\s*url\s*\((?!'|\x22)/" , rxopt)); arlReplaces.Add(" url(" + strDomainRoot); //url('/ arlRegexs.Add(new Regex(@"\s*url\s*\('/" , rxopt)); arlReplaces.Add(" url('" + strDomainRoot); //url("/ arlRegexs.Add(new Regex(@"\s*url\s*\(\x22/" , rxopt)); arlReplaces.Add(" url(\"" + strDomainRoot); //url( arlRegexs.Add(new Regex(@"\s*url\s*\((?!'|\x22|http://)" , rxopt)); arlReplaces.Add(" url(" + strDomainPath); //url(' arlRegexs.Add(new Regex(@"\s*url\s*\('(?!http://)" , rxopt)); arlReplaces.Add(" url('" + strDomainPath); //url(" arlRegexs.Add(new Regex(@"\s*url\s*\(\x22(?!http://)" , rxopt)); arlReplaces.Add(" url(\"" + strDomainPath); //<param name=movie value=/ arlRegexs.Add(new Regex(@"<param\s+name=(?!'|\x22)movie(?!'|\x22)\s+value=(?!'|\x22)/" , rxopt)); arlReplaces.Add("<param name=movie value=" + strDomainRoot); //<param name='movie' value='/ arlRegexs.Add(new Regex(@"<param\s+name='movie'\s+value='/" , rxopt)); arlReplaces.Add("<param name='movie' value='" + strDomainRoot); //<param name="movie" value="/ arlRegexs.Add(new Regex(@"<param\s+name=\x22movie\x22\s+value=\x22/" , rxopt)); arlReplaces.Add("<param name=\"movie\" value=\"" + strDomainRoot); //<param name=movie value= arlRegexs.Add(new Regex(@"<param\s+name=(?!'|\x22)movie(?!'|\x22)\s+value=(?!'|\x22|http://)" , rxopt)); arlReplaces.Add("<param name=movie value=" + strDomainPath); //<param name='movie' value=' arlRegexs.Add(new Regex(@"<param\s+name='movie'\s+value='(?!http://)" , rxopt)); arlReplaces.Add("<param name='movie' value='" + strDomainPath); //<param name="movie" value=" arlRegexs.Add(new Regex(@"<param\s+name=\x22movie\x22\s+value=\x22(?!http://)" , rxopt)); arlReplaces.Add("<param name=\"movie\" value=\"" + strDomainPath); //<param name=src value=/ arlRegexs.Add(new Regex(@"<param\s+name=(?!'|\x22)src(?!'|\x22)\s+value=\s*(?!'|\x22)/" , rxopt)); arlReplaces.Add("<param name=src value=" + strDomainRoot); //<param name='src' value='/ arlRegexs.Add(new Regex(@"<param\s+name='src'\s+value=\s*'/" , rxopt)); arlReplaces.Add("<param name='src' value='" + strDomainRoot); //<param name="src" value="/ arlRegexs.Add(new Regex(@"<param\s+name=\x22src\x22\s+value=\s*\x22/" , rxopt)); arlReplaces.Add("<param name=\"src\" value=\"" + strDomainRoot); //<param name=src value= arlRegexs.Add(new Regex(@"<param\s+name=(?!'|\x22)src(?!'|\x22)\s+value=(?!'|\x22)(?!http://)" , rxopt)); arlReplaces.Add("<param name=src value=" + strDomainPath); //<param name='src' value=' arlRegexs.Add(new Regex(@"<param\s+name='src'\s+value='(?!http://)" , rxopt)); arlReplaces.Add("<param name='src' value='" + strDomainPath); //<param name="src" value=" arlRegexs.Add(new Regex(@"<param\s+name=\x22src\x22\s+value=\x22(?!http://)" , rxopt)); arlReplaces.Add("<param name=\"src\" value=\"" + strDomainPath); IEnumerator ienmRegexs = arlRegexs.GetEnumerator(); IEnumerator ienmReplaces = arlReplaces.GetEnumerator(); while (ienmRegexs.MoveNext() == true && ienmReplaces.MoveNext() == true) { Regex ex = (Regex)ienmRegexs.Current; string strReplace = this.C2S(ienmReplaces.Current); this._sb = new StringBuilder(ex.Replace(this._sb.ToString() , strReplace)); } StreamWriter stmwt = new StreamWriter(fiCompiled.FullName , false , Encoding.GetEncoding("gb2312")); stmwt.Write(new CharsetKit().Simple2Tradition(this._sb.ToString())); stmwt.Close(); return fiCompiled.Name; } } */ #endregion #region class SQLSDbKit : BaseKit public class SQLSDbKit : BaseKit { #region private void _eh_votepage(object o, DataGridPageChangedEventArgs e) private void _eh_votepage(object o, DataGridPageChangedEventArgs e) { DataGrid dg = (DataGrid)o; try { dg.CurrentPageIndex = e.NewPageIndex; } catch (Exception expt) { dg.CurrentPageIndex = 0; } dg.DataBind(); } #endregion #region private void _eh_changingpage(object o, GridViewPageEventArgs e) private void _eh_changingpage(object o, GridViewPageEventArgs e) { GridView gv = (GridView)o; try { gv.PageIndex = e.NewPageIndex; } catch (Exception expt) { gv.PageIndex = 0; } gv.DataBind(); } #endregion #region private void _eh_repeater_HierarchicalRepeaterItemDataBound(object sender, RepeaterItemEventArgs e) private void _eh_repeater_HierarchicalRepeaterItemDataBound(object sender, RepeaterItemEventArgs e) { Repeater rptChild = (Repeater)e.Item.FindControl(new VariantKit().C2S(this["HierarchicalChildID"])); DataRowView rowv = (DataRowView)e.Item.DataItem; if (rptChild != null && rowv != null) { this.DataBind(rptChild, new StringKit().GetFormatString(new VariantKit().C2S(this["HierarchicalSQLFormatString"]), rowv[(new VariantKit().C2S(this["HierarchicalSQLFormatStringKeyField"]))].ToString())); } } #endregion #region private void _eh_repeater_HierarchicalDataGridItemDataBound(object sender, RepeaterItemEventArgs e) private void _eh_repeater_HierarchicalDataGridItemDataBound(object sender, RepeaterItemEventArgs e) { DataGrid dgChild = (DataGrid)e.Item.FindControl(new VariantKit().C2S(this["HierarchicalChildID"])); DataRowView rowv = (DataRowView)e.Item.DataItem; if (dgChild != null && rowv != null) { this.DataBind(dgChild, new StringKit().GetFormatString(new VariantKit().C2S(this["HierarchicalSQLFormatString"]), rowv[(new VariantKit().C2S(this["HierarchicalSQLFormatStringKeyField"]))].ToString())); } } #endregion #region public SQLSDbKit() public SQLSDbKit() : base() { this["ConnectionString"] = ""; this["Debugging"] = false; this["DebuggingTipFormatString"] = "<script language=\"javascript\">var t_{0}=\"{0}\"; var c_{0}=\"{1}\";</script><a class=\"DebuggingTip\" href=\"javascript:MessageBoxTip(t_{0}, c_{0});\" title=\"View SQL\">{0}</a>"; this["PageableRepeaterPaggingFormatString"] = "<div class=\"AlignCenter\"><a href=\"{0}={1}\" class=\"PaggingArrow\">9</a><a href=\"{0}={2}\" class=\"PaggingArrow\">7</a> {3} / {4} / {5} <a href=\"{0}={6}\" class=\"PaggingArrow\">8</a><a href=\"{0}={7}\" class=\"PaggingArrow\">:</a></div>"; } #endregion #region public int DataBind(Repeater rpt, object sql) public int DataBind(Repeater rpt, object sql) { int intReturn = 0; DataSet ds = new DataSet(); intReturn = new SqlDataAdapter(new VariantKit().C2S(sql), new VariantKit().C2S(this["ConnectionString"])).Fill(ds, "#"); rpt.DataSource = ds.Tables["#"]; rpt.DataBind(); DebugKit dk = new DebugKit(this["Debugging"]); Literal ltr = null; try { ltr = ((Literal)((RepeaterItem)rpt.Controls[0]).FindControl(dk.TrackInfoViewerID)); } catch (Exception expt) { ; } if (ltr != null && dk.Debugging == true) { ltr.Text = new StringKit().GetFormatString(this["DebuggingTipFormatString"], rpt.ID, sql); } return intReturn; } #endregion #region public int DataBind(PagedDataSource pds, object sql) public int DataBind(PagedDataSource pds, object sql) { int intReturn = 0; DataSet ds = new DataSet(); intReturn = new SqlDataAdapter(new VariantKit().C2S(sql), new VariantKit().C2S(this["ConnectionString"])).Fill(ds, "#"); pds.DataSource = ds.Tables["#"].DefaultView; return intReturn; } #endregion #region public int DataBindPageableRepeater(Repeater rpt, object sql, BaseKit pageinfo) public int DataBindPageableRepeater(Repeater rpt, object sql, BaseKit pageinfo) { int intReturn = 0; PagedDataSource pds = new PagedDataSource(); this.DataBind(pds, sql); pds.AllowPaging = true; pds.PageSize = new VariantKit().C2I32(pageinfo["PageSize"]); pds.CurrentPageIndex = new VariantKit().C2I32(pageinfo["PageIndex"]) < 1 ? new VariantKit().C2I32(pageinfo["PageIndex"]) : new VariantKit().C2I32(pageinfo["PageIndex"]) - 1; rpt.DataSource = pds; rpt.DataBind(); int pageindex = 1; int pageprevious = 1; int pagenext = 1; int pagecount = 1; pageindex = pds.CurrentPageIndex + 1; pagecount = pds.PageCount; pageprevious = pageindex <= 1 ? pagecount : pageindex - 1; pagenext = pageindex >= pagecount ? 1 : pageindex + 1; Literal navigator = new Literal(); navigator.ID = "navigator"; navigator.Text = new StringKit().GetFormatString(this["PageableRepeaterPaggingFormatString"], pageinfo["PageQueryFormatString"], 1, pageprevious, pds.PageSize, pageindex, pagecount, pagenext, pagecount); rpt.Controls.Add(navigator); DebugKit dk = new DebugKit(this["Debugging"]); Literal ltr = null; try { ltr = ((Literal)((RepeaterItem)rpt.Controls[0]).FindControl(dk.TrackInfoViewerID)); } catch (Exception expt) { ; } if (ltr != null && dk.Debugging == true) { ltr.Text = new StringKit().GetFormatString(this["DebuggingTipFormatString"], rpt.ID, sql); } return intReturn; } #endregion #region public int DataBindHierarchicalRepeater(Repeater rpt, object sql) public int DataBindHierarchicalRepeater(Repeater rpt, object sql) { int intReturn = 0; DataSet ds = new DataSet(); intReturn = new SqlDataAdapter(new VariantKit().C2S(sql), new VariantKit().C2S(this["ConnectionString"])).Fill(ds, "#"); rpt.DataSource = ds.Tables["#"]; rpt.ItemDataBound += this._eh_repeater_HierarchicalRepeaterItemDataBound; rpt.DataBind(); DebugKit dk = new DebugKit(this["Debugging"]); Literal ltr = null; try { ltr = ((Literal)((RepeaterItem)rpt.Controls[0]).FindControl(dk.TrackInfoViewerID)); } catch (Exception expt) { ; } if (ltr != null && dk.Debugging == true) { ltr.Text = new StringKit().GetFormatString(this["DebuggingTipFormatString"], rpt.ID, sql); } return intReturn; } #endregion #region public int DataBindHierarchicalDataGrid(Repeater rpt, object sql) public int DataBindHierarchicalDataGrid(Repeater rpt, object sql) { int intReturn = 0; DataSet ds = new DataSet(); intReturn = new SqlDataAdapter(new VariantKit().C2S(sql), new VariantKit().C2S(this["ConnectionString"])).Fill(ds, "#"); rpt.DataSource = ds.Tables["#"]; rpt.ItemDataBound += this._eh_repeater_HierarchicalDataGridItemDataBound; rpt.DataBind(); return intReturn; } #endregion #region public int DataBind(DataGrid dg, object sql) public int DataBind(DataGrid dg, object sql) { int intReturn = 0; DataSet ds = new DataSet(); intReturn = new SqlDataAdapter(new VariantKit().C2S(sql), new VariantKit().C2S(this["ConnectionString"])).Fill(ds, "#"); dg.AutoGenerateColumns = false; dg.GridLines = GridLines.None; dg.AllowPaging = true; dg.Width = new Unit(100, UnitType.Percentage); dg.PagerStyle.Visible = ds.Tables["#"].Rows.Count == 0 ? false : true; dg.PagerStyle.BackColor = Color.FromArgb(0x78eeeeee); dg.PagerStyle.Mode = PagerMode.NumericPages; dg.PagerStyle.HorizontalAlign = HorizontalAlign.Center; dg.PageIndexChanged += this._eh_votepage; try { dg.DataSource = ds.Tables["#"]; dg.CurrentPageIndex = 0; dg.DataBind(); } catch (Exception expt) { dg.CurrentPageIndex = 0; dg.DataBind(); } return intReturn; } #endregion #region public int DataBind(GridView gv, object sql) public int DataBind(GridView gv, object sql) { int intReturn = 0; DataSet ds = new DataSet(); intReturn = new SqlDataAdapter(new VariantKit().C2S(sql), new VariantKit().C2S(this["ConnectionString"])).Fill(ds, "#"); gv.AutoGenerateColumns = false; gv.ShowFooter = true; gv.FooterStyle.HorizontalAlign = HorizontalAlign.Center; gv.EmptyDataText = "[Nothing]"; gv.GridLines = GridLines.None; gv.AllowPaging = true; gv.Width = new Unit(100, UnitType.Percentage); gv.PagerStyle.BackColor = Color.FromArgb(0xeeeeee); gv.PagerStyle.HorizontalAlign = HorizontalAlign.Center; gv.PagerSettings.Mode = PagerButtons.NumericFirstLast; gv.PageIndexChanging += new GridViewPageEventHandler(this._eh_changingpage); try { gv.DataSource = ds.Tables["#"]; gv.DataBind(); } catch (Exception expt) { gv.DataBind(); } return intReturn; } #endregion #region public object GetScalar(object sql) public object GetScalar(object sql) { SqlCommand cmd = new SqlCommand(new VariantKit().C2S(sql), new SqlConnection(new VariantKit().C2S(this["ConnectionString"]))); cmd.Connection.Open(); return cmd.ExecuteScalar(); } #endregion #region public void Execute(object sql) public void Execute(object sql) { SqlCommand cmd = new SqlCommand(new VariantKit().C2S(sql), new SqlConnection(new VariantKit().C2S(this["ConnectionString"]))); cmd.Connection.Open(); cmd.ExecuteNonQuery(); } #endregion #region public DataTable ExecuteDataTable(object sql) public DataTable ExecuteDataTable(object sql) { DataSet ds = new DataSet(); new SqlDataAdapter(new VariantKit().C2S(sql), new VariantKit().C2S(this["ConnectionString"])).Fill(ds, "#"); return ds.Tables["#"]; } #endregion } #endregion #region class HtmlKit : BaseKit public class HtmlKit : BaseKit { #region public HtmlKit() public HtmlKit() : base() { } #endregion #region public string GetDecode(object value) public string GetDecode(object value) { return new Regex(@"<\w*(\s\w*=\w*)*>|</\w*>|( )*|\s*", (RegexOptions)this["_RegularExpressionOptions"]).Replace(new VariantKit().C2S(value), ""); } #endregion } #endregion #region class StringKit : BaseKit public class StringKit : BaseKit { #region public StringKit() public StringKit() : base() { this["__StringBuilder"] = new StringBuilder(); } #endregion #region public void Reset() public void Reset() { this["__StringBuilder"] = new StringBuilder(); } #endregion #region public void Reset2(object value) public void Reset2(object value) { this["__StringBuilder"] = new StringBuilder(new VariantKit().C2S(value)); } #endregion #region public void Append(object value) public void Append(object value) { ((StringBuilder)this["__StringBuilder"]).Append(new VariantKit().C2S(value)); } #endregion #region public void Append(object format, params object[] args) public void Append(object format, params object[] args) { ((StringBuilder)this["__StringBuilder"]).AppendFormat(new VariantKit().C2S(format), args); } #endregion #region public void AppendLine(object value) public void AppendLine(object value) { ((StringBuilder)this["__StringBuilder"]).AppendLine(new VariantKit().C2S(value)); } #endregion #region public void AppendLine() public void AppendLine() { ((StringBuilder)this["__StringBuilder"]).AppendLine(); } #endregion #region public string GetContent() public string GetContent() { return ((StringBuilder)this["__StringBuilder"]).ToString(); } #endregion #region public string GetSubString(object value, int startIndex, int length) public string GetSubString(object value, int startIndex, int length) { string ret = new VariantKit().C2S(value); if (startIndex > ret.Length) { ret = ""; } else { if (length > ret.Length - startIndex) { length = ret.Length - startIndex; } ret = ret.Substring(startIndex, length); } return ret; } #endregion #region public string GetSubString(object value, int length) public string GetSubString(object value, int length) { return this.GetSubString(value, 0, length); } #endregion #region public string GetFormatString(object format, params object[] args) public string GetFormatString(object format, params object[] args) { return String.Format(new VariantKit().C2S(format), args); } #endregion #region public bool HasContent(object value) public bool HasContent(object value) { bool ret = true; switch (new VariantKit().C2S(value).Length) { case 0: { ret = false; break; } default: { ret = true; break; } } return ret; } #endregion #region public int GetContentLength(object value) public int GetContentLength(object value) { return new VariantKit().C2S(value).Length; } #endregion } #endregion #region class SQLQueryKit : StringKit public class SQLQueryKit : StringKit { #region public enum Key public enum Key { Select, From, Where, And, Or, OrderBy, Desc, Asc, Union, All, UnionSelect, UnionAllSelect, IfIsNull, IfIsNotNull, DropTable, Into, NotIn, In, Top }; #endregion #region public void Append(Key sk) public void Append(Key sk) { switch (sk) { case Key.Union: { this.Append(" UNION "); break; } case Key.All: { this.Append(" ALL "); break; } case Key.Top: { this.Append(" TOP "); break; } default: { break; } } } #endregion #region public void Append(Key sk, object value) public void Append(Key sk, object value) { switch (sk) { case Key.Select: { this.Append(this.GetFormatString(" SELECT {0} ", value)); break; } case Key.UnionSelect: { this.Append(this.GetFormatString(" UNION SELECT {0} ", value)); break; } case Key.UnionAllSelect: { this.Append(this.GetFormatString(" UNION ALL SELECT {0} ", value)); break; } case Key.From: { this.Append(this.GetFormatString(" FROM {0} ", value)); break; } case Key.Where: { this.Append(this.GetFormatString(" WHERE {0} ", value)); break; } case Key.And: { this.Append(this.GetFormatString(" AND {0} ", value)); break; } case Key.Or: { this.Append(this.GetFormatString(" OR {0} ", value)); break; } case Key.OrderBy: { this.Append(this.GetFormatString(" ORDER BY {0} ", value)); break; } case Key.Desc: { this.Append(this.GetFormatString(" {0} DESC ", value)); break; } case Key.Asc: { this.Append(this.GetFormatString(" {0} ASC ", value)); break; } case Key.IfIsNull: { this.Append(this.GetFormatString(" IF {0} IS NULL ", value)); break; } case Key.IfIsNotNull: { this.Append(this.GetFormatString(" IF {0} IS NOT NULL ", value)); break; } case Key.DropTable: { this.Append(this.GetFormatString(" DROP TABLE {0} ", value)); break; } case Key.Into: { this.Append(this.GetFormatString(" INTO {0} ", value)); break; } case Key.In: { this.Append(this.GetFormatString(" IN {0} ", value)); break; } case Key.NotIn: { this.Append(this.GetFormatString(" NOT IN {0} ", value)); break; } case Key.Top: { this.Append(this.GetFormatString(" TOP {0} ", value)); break; } default: { break; } } } #endregion #region public void Append(Key sk, object format, params object[] args) public void Append(Key sk, object format, params object[] args) { switch (sk) { case Key.Select: { this.Append(this.GetFormatString(" SELECT {0} ", format), args); break; } case Key.UnionSelect: { this.Append(this.GetFormatString(" UNION SELECT {0} ", format), args); break; } case Key.UnionAllSelect: { this.Append(this.GetFormatString(" UNION ALL SELECT {0} ", format), args); break; } case Key.From: { this.Append(this.GetFormatString(" FROM {0} ", format), args); break; } case Key.Where: { this.Append(this.GetFormatString(" WHERE {0} ", format), args); break; } case Key.And: { this.Append(this.GetFormatString(" AND {0} ", format), args); break; } case Key.Or: { this.Append(this.GetFormatString(" OR {0} ", format), args); break; } case Key.OrderBy: { this.Append(this.GetFormatString(" ORDER BY {0} ", format), args); break; } case Key.Desc: { this.Append(this.GetFormatString(" {0} DESC ", format), args); break; } case Key.Asc: { this.Append(this.GetFormatString(" {0} ASC ", format), args); break; } case Key.IfIsNull: { this.Append(this.GetFormatString(" IF {0} IS NULL ", format), args); break; } case Key.IfIsNotNull: { this.Append(this.GetFormatString(" IF {0} IS NOT NULL ", format), args); break; } case Key.DropTable: { this.Append(this.GetFormatString(" DROP TABLE {0} ", format), args); break; } case Key.Into: { this.Append(this.GetFormatString(" INTO {0} ", format), args); break; } case Key.In: { this.Append(this.GetFormatString(" IN {0} ", format), args); break; } case Key.NotIn: { this.Append(this.GetFormatString(" NOT IN {0} ", format), args); break; } case Key.Top: { this.Append(this.GetFormatString(" TOP {0} ", format), args); break; } default: { break; } } } #endregion } #endregion #region class VariantKit : BaseKit public class VariantKit : BaseKit { #region public VariantKit() public VariantKit() : base() { this["__RegularExpression"] = new Regex(@"'|\x22", ((RegexOptions)this["_RegularExpressionOptions"])); } #endregion #region public string C2S(object value) public string C2S(object value) { return Convert.ToString(value); } #endregion #region public int C2I32(object value) public int C2I32(object value) { try { return Convert.ToInt32(value); } catch (Exception expt) { return 0; } } #endregion #region public bool C2B(object value) public bool C2B(object value) { try { return Convert.ToBoolean(value); } catch (Exception expt) { return false; } } #endregion #region public string GetSafeQueryString(object value) public string GetSafeQueryString(object value) { return ((Regex)this["__RegularExpression"]).Replace(new VariantKit().C2S(value), ""); } #endregion #region public object GetSafeValue(object value, object swapvalue) public object GetSafeValue(object value, object swapvalue) { return value == null ? swapvalue : value; } #endregion #region public object GetSafeValue(object condition, object value, object swapvalue) public object GetSafeValue(object condition, object value, object swapvalue) { return this.C2B(condition) == true ? value : swapvalue; } #endregion } #endregion #region class ExceptionKit : BaseKit public class ExceptionKit : BaseKit { #region public ExceptionKit() public ExceptionKit() : base() { this["__PresentFormatString"] = "<div style=\"padding:10px; margin:10px; border:1px solid #ccc;\"><h3 style=\"color:#c00;\">.: Runtime exception :.</h3><h5>{0}</h5></div>"; } #endregion #region public string GetHTMLPresent(object expt) public string GetHTMLPresent(object expt) { return new StringKit().GetFormatString(new VariantKit().C2S(this["__PresentFormatString"]), expt); } #endregion } #endregion #region class DebugKit : BaseKit public class DebugKit : BaseKit { #region public DebugKit() public DebugKit() : base() { this["__Debugging"] = true; this["__TrackInfoViewerID"] = "__TrackInfoViewer__"; } #endregion #region public DebugKit(object debugging) public DebugKit(object debugging) : base() { this["__Debugging"] = new VariantKit().C2B(debugging); this["__TrackInfoViewerID"] = "__TrackInfoViewer__"; } #endregion #region public bool Debugging public bool Debugging { get { return new VariantKit().C2B(this["__Debugging"]); } set { this["__Debugging"] = new VariantKit().C2B(value); } } #endregion #region public string TrackInfoViewerID public string TrackInfoViewerID { get { return new VariantKit().C2S(this["__TrackInfoViewerID"]); } set { this["__TrackInfoViewerID"] = new VariantKit().C2S(value); } } #endregion #region public string GetTrackInfo(object value) public string GetTrackInfo(object value) { return this.Debugging == true ? new VariantKit().C2S(value) : ""; } #endregion } #endregion #region class StyleSheetKit : StringKit public class StyleSheetKit : StringKit { public StyleSheetKit() : base() { this["StyleSheetPrefix"] = "<style><!--"; this["StyleSheetPostfix"] = "--></style>"; } public string GetStyleSheetElement() { this.Reset(); this.Append(this["StyleSheetPrefix"]); this.Append(this["StyleSheetPostfix"]); return this.GetContent(); } public string GetStyleSheetClass() { this.Reset(); this.Append(this["StyleSheetPrefix"]); this.Append(this["StyleSheetPostfix"]); return this.GetContent(); } public string GetStyleSheetObject() { this.Reset(); this.Append(this["StyleSheetPrefix"]); this.Append(this["StyleSheetPostfix"]); return this.GetContent(); } } #endregion }