C# UI常用操作 - Mars的专栏 - 博客频道 - CSDN.NET http://blog.csdn.net/shuyizhi/article/details/6830405

来源:互联网 发布:重庆网站seo 编辑:程序博客网 时间:2024/05/18 00:11
  1. using System;  
  2. using System.Data;  
  3. using System.Configuration;  
  4. using System.Web;  
  5. using System.Web.Security;  
  6. using System.Web.UI;  
  7. using System.Web.UI.WebControls;  
  8. using System.Web.UI.WebControls.WebParts;  
  9. using System.Web.UI.HtmlControls;  
  10. using System.Drawing;  
  11. using System.Text;  
  12. using System.IO;  
  13. using System.Threading;  
  14.   
  15. namespace Demo1  
  16. {  
  17.     public static class UICommon  
  18.     {  
  19.  
  20.         #region  简单弹框功能  
  21.         /// <summary>  
  22.         /// 简单弹出对话框功能  
  23.         /// </summary>  
  24.         /// <param name="pageCurrent">  
  25.         /// 当前的页面(this)  
  26.         /// </param>  
  27.         /// <param name="strMsg">  
  28.         /// 弹出信息的内容  
  29.         /// </param>  
  30.         public static void Alert(System.Web.UI.Page pageCurrent, string strMsg)  
  31.         {  
  32.             //Replace \n  
  33.             strMsg = strMsg.Replace("\n""file://n/");  
  34.             //Replace \r  
  35.             strMsg = strMsg.Replace("\r""file://r/");  
  36.             //Replace "  
  37.             strMsg = strMsg.Replace("\"""\\\"");  
  38.             //Replace '  
  39.             strMsg = strMsg.Replace("\'""\\\'");  
  40.   
  41.             pageCurrent.ClientScript.RegisterStartupScript(pageCurrent.GetType(),  
  42.                 System.Guid.NewGuid().ToString(),  
  43.                 "<script>window.alert('" + strMsg + "')</script>"  
  44.                 );  
  45.         }  
  46.         /// <summary>  
  47.         /// 简单弹出对话框并跳转  
  48.         /// </summary>  
  49.         /// <param name="pageCurrent">当前页面(this)</param>  
  50.         /// <param name="strMsg">信息内容</param>  
  51.         /// <param name="GoBackUrl">跳转URL</param>  
  52.         public static void Alert(System.Web.UI.Page pageCurrent, string strMsg, string GoBackUrl)  
  53.         {  
  54.             //Replace \n  
  55.             strMsg = strMsg.Replace("\n""file://n/");  
  56.             //Replace \r  
  57.             strMsg = strMsg.Replace("\r""file://r/");  
  58.             //Replace "  
  59.             strMsg = strMsg.Replace("\"""\\\"");  
  60.             //Replace '  
  61.             strMsg = strMsg.Replace("\'""\\\'");  
  62.   
  63.             pageCurrent.ClientScript.RegisterStartupScript(pageCurrent.GetType(),  
  64.                 System.Guid.NewGuid().ToString(),  
  65.                 "<script>window.alert('" + strMsg + "');window.location.href='" + GoBackUrl + "'</script>"  
  66.                 );  
  67.         }  
  68.         /// <summary>  
  69.         /// 简单弹出对话框并跳到父页(主要用于框架页)  
  70.         /// </summary>  
  71.         /// <param name="pageCurrent">当前页面(this)</param>  
  72.         /// <param name="strMsg">信息内容</param>  
  73.         /// <param name="GoBackUrl">跳转URL</param>  
  74.         public static void AlertFrame(System.Web.UI.Page pageCurrent, string strMsg, string GoBackUrl)  
  75.         {  
  76.             //Replace \n  
  77.             strMsg = strMsg.Replace("\n""file://n/");  
  78.             //Replace \r  
  79.             strMsg = strMsg.Replace("\r""file://r/");  
  80.             //Replace "  
  81.             strMsg = strMsg.Replace("\"""\\\"");  
  82.             //Replace '  
  83.             strMsg = strMsg.Replace("\'""\\\'");  
  84.   
  85.             pageCurrent.ClientScript.RegisterStartupScript(pageCurrent.GetType(),  
  86.                 System.Guid.NewGuid().ToString(),  
  87.                 "<script>window.alert('" + strMsg + "');window.top.location.href='" + GoBackUrl + "'</script>"  
  88.                 );  
  89.         }  
  90.         /// <summary>  
  91.         /// 弹出简单对话框并关闭页面  
  92.         /// </summary>  
  93.         /// <param name="pageCurrent">当前页面(this)</param>  
  94.         /// <param name="message">信息</param>  
  95.         public static void AlertClose(System.Web.UI.Page pageCurrent,string message)  
  96.         {  
  97.             System.Text.StringBuilder sb = new System.Text.StringBuilder();  
  98.             sb.Append("<script language=\"javascript\">\n");  
  99.             sb.Append("alert(\"" + message.Trim() + "\"); \n");  
  100.             sb.Append("window.close();\n");  
  101.             sb.Append("</script>\n");  
  102.             pageCurrent.ClientScript.RegisterClientScriptBlock(pageCurrent.GetType(),  
  103.                 System.Guid.NewGuid().ToString(), sb.ToString());  
  104.         }  
  105.         /// <summary>  
  106.         /// 显示一个弹出窗口,并转向上一页  
  107.         /// </summary>  
  108.         /// <param name="message"></param>  
  109.         public static void AlertBack(System.Web.UI.Page pageCurrent, string message)  
  110.         {  
  111.             StringBuilder sb = new StringBuilder();  
  112.             sb.Append("<script language=\"javascript\"> \n");  
  113.             sb.Append("alert(\"" + message.Trim() + "\"); \n");  
  114.             sb.Append("var p=document.referrer; \n");  
  115.             sb.Append("window.location.href=p;\n");  
  116.             sb.Append("</script>");  
  117.             pageCurrent.ClientScript.RegisterClientScriptBlock(pageCurrent.GetType(),  
  118.                 System.Guid.NewGuid().ToString(), sb.ToString());  
  119.         }  
  120.         #endregion  
  121.  
  122.         #region 简单的滚动信息栏  
  123.         /// </summary>  
  124.         /// <param name="pageCurrent">  
  125.         /// 当前页面  
  126.         /// </param>  
  127.         /// <param name="strMsg">  
  128.         /// 要滚动的信息  
  129.         /// </param>  
  130.         public static string ScrollMessage(string strMsg)  
  131.         {  
  132.             //Replace \n  
  133.             strMsg = strMsg.Replace("\n""file://n/");  
  134.             //Replace \r  
  135.             strMsg = strMsg.Replace("\r""file://r/");  
  136.             //Replace "  
  137.             strMsg = strMsg.Replace("\"""\\\"");  
  138.             //Replace '  
  139.             strMsg = strMsg.Replace("\'""\\\'");  
  140.   
  141.             StringBuilder sb = new StringBuilder();  
  142.             sb.Append("<MARQUEE>");  
  143.             sb.Append(strMsg);  
  144.             sb.Append("</MARQUEE>");  
  145.             return sb.ToString();  
  146.         }  
  147.   
  148.   
  149.         /**//// <summary>  
  150.         /// 指定滚动文字的详细方法  
  151.         ///   
  152.         /// </summary>  
  153.         /// <param name="pageCurrent">  
  154.         /// 当前的页面  
  155.         /// </param>  
  156.         /// <param name="strMsg">  
  157.         /// 要滚动的文字  
  158.         /// </param>  
  159.         /// <param name="aligh">  
  160.         /// align:是设定活动字幕的位置,居左、居中、居右、靠上和靠下三种位置  
  161.         /// left center  right top bottom   
  162.         /// </param>  
  163.         /// <param name="bgcolor">  
  164.         /// 用于设定活动字幕的背景颜色,一般是十六进制数。如#CCCCCC   
  165.         /// </param>  
  166.         /// <param name="direction">  
  167.         /// 用于设定活动字幕的滚动方向是向左、向右、向上、向下  
  168.         /// left|right|up|down   
  169.         /// </param>  
  170.         /// <param name="behavior">  
  171.         /// 用于设定滚动的方式,主要由三种方式:scroll slide和alternate  
  172.         ///   
  173.         /// </param>  
  174.         /// <param name="height">  
  175.         /// 用于设定滚动字幕的高度  
  176.         ///   
  177.         /// </param>  
  178.         /// <param name="hspace">  
  179.         /// 则设定滚动字幕的宽度  
  180.         /// </param>  
  181.         /// <param name="scrollamount">  
  182.         /// 用于设定活动字幕的滚动距离  
  183.         /// </param>  
  184.         /// <param name="scrolldelay">  
  185.         /// 用于设定滚动两次之间的延迟时间  
  186.         /// </param>  
  187.         /// <param name="width"></param>  
  188.         /// <param name="vspace">  
  189.         /// 分别用于设定滚动字幕的左右边框和上下边框的宽度  
  190.         ///   
  191.         /// </param>  
  192.         /// <param name="loop">  
  193.         /// 用于设定滚动的次数,当loop=-1表示一直滚动下去,直到页面更新  
  194.         /// </param>  
  195.         /// <param name="MarqueejavascriptPath">  
  196.         /// 脚本的存放位置  
  197.         /// </param>  
  198.         /// <returns></returns>  
  199.         public static string ScrollMessage(System.Web.UI.Page pageCurrent, string strMsg, string aligh, string bgcolor,  
  200.                                     string direction, string behavior, string height, string hspace,  
  201.                                     string scrollamount, string scrolldelay, string width, string vspace, string loop,  
  202.                                     string MarqueejavascriptPath)  
  203.         {  
  204.             StreamReader sr = new StreamReader(pageCurrent.MapPath(MarqueejavascriptPath));  
  205.             StringBuilder sb = new StringBuilder();  
  206.             string line;  
  207.             try  
  208.             {  
  209.                 while ((line = sr.ReadLine()) != null)  
  210.                 {  
  211.                     sb.AppendLine(line);  
  212.   
  213.                 }  
  214.                 sr.Close();  
  215.             }  
  216.             catch (Exception ex)  
  217.             {  
  218.                 throw new Exception(ex.Message);  
  219.             }  
  220.             sb.Replace("$strMessage", strMsg);  
  221.             sb.Replace("$aligh", aligh);  
  222.             sb.Replace("$bgcolor", bgcolor);  
  223.             sb.Replace("$direction", direction);  
  224.             sb.Replace("$behavior", behavior);  
  225.             sb.Replace("$height", height);  
  226.             sb.Replace("$hspace", hspace);  
  227.             sb.Replace("$scrollamount", scrollamount);  
  228.             sb.Replace("$scrolldelay", scrolldelay);  
  229.             sb.Replace("$width", width);  
  230.             sb.Replace("$vspace", vspace);  
  231.             sb.Replace("$loop", loop);  
  232.             //pageCurrent.ClientScript.RegisterStartupScript(pageCurrent.GetType(),  
  233.             //            System.Guid.NewGuid().ToString(), sb.ToString());  
  234.             return sb.ToString();  
  235.         }  
  236.  
  237.         #endregion  
  238.  
  239.         #region  简单跳转  
  240.         /// <summary>  
  241.         /// 简单直接跳转  
  242.         /// </summary>  
  243.         /// <param name="pageCurrent">当前页面(this)</param>  
  244.         /// <param name="strPage">要跳出的页面</param>  
  245.         public static void Redirect(System.Web.UI.Page pageCurrent, string strPage)  
  246.         {  
  247.             pageCurrent.ClientScript.RegisterStartupScript(pageCurrent.GetType(),  
  248.                     System.Guid.NewGuid().ToString(),  
  249.                     "<script>window.location.href='" + strPage + "'</script>"  
  250.                     );  
  251.         }  
  252.         /// <summary>  
  253.         /// 主要用于跳出带有框架的页面  
  254.         /// </summary>  
  255.         /// <param name="pageCurrent">当前页面(this)</param>  
  256.         /// <param name="strPage">要跳出的页面</param>  
  257.         public static void RedirectFrame(System.Web.UI.Page pageCurrent, string strPage)  
  258.         {  
  259.             pageCurrent.ClientScript.RegisterStartupScript(pageCurrent.GetType(),  
  260.                     System.Guid.NewGuid().ToString(),  
  261.                     "<script>window.top.location.href='" + strPage + "'</script>"  
  262.                     );  
  263.         }  
  264.  
  265.         #endregion  
  266.  
  267.         #region 添加提示确认取消提示窗口  
  268.         /// <summary>  
  269.         /// Button控件添加提示窗口  
  270.         /// </summary>  
  271.         /// <param name="button">Button id</param>  
  272.         /// <param name="strMsg">信息</param>  
  273.         public static void AddConfirm(System.Web.UI.WebControls.Button button, string strMsg)  
  274.         {  
  275.             strMsg = strMsg.Replace("\n""file://n/");  
  276.             strMsg = strMsg.Replace("\r""file://r/");  
  277.             strMsg = strMsg.Replace("\"""\\\"");  
  278.             strMsg = strMsg.Replace("\'""\\\'");  
  279.             button.Attributes.Add("onClick""return confirm('" + strMsg + "')");  
  280.         }  
  281.         /// <summary>  
  282.         /// ImageButton控件添加提示窗口  
  283.         /// </summary>  
  284.         /// <param name="button">Button id</param>  
  285.         /// <param name="strMsg">信息</param>  
  286.         public static void AddConfirm(System.Web.UI.WebControls.ImageButton button, string strMsg)  
  287.         {  
  288.             strMsg = strMsg.Replace("\n""file://n/");  
  289.             strMsg = strMsg.Replace("\r""file://r/");  
  290.             strMsg = strMsg.Replace("\"""\\\"");  
  291.             strMsg = strMsg.Replace("\'""\\\'");  
  292.             button.Attributes.Add("onClick""return confirm('" + strMsg + "')");  
  293.         }  
  294.         /// <summary>  
  295.         /// LinkButton控件添加提示窗口  
  296.         /// </summary>  
  297.         /// <param name="button">Button id</param>  
  298.         /// <param name="strMsg">信息</param>  
  299.         public static void AddConfirm(System.Web.UI.WebControls.LinkButton button, string strMsg)  
  300.         {  
  301.             strMsg = strMsg.Replace("\n""file://n/");  
  302.             strMsg = strMsg.Replace("\r""file://r/");  
  303.             strMsg = strMsg.Replace("\"""\\\"");  
  304.             strMsg = strMsg.Replace("\'""\\\'");  
  305.             button.Attributes.Add("onClick""return confirm('" + strMsg + "')");  
  306.         }  
  307.         /// <summary>  
  308.         /// GridView选择列 添加提示信息  
  309.         /// </summary>  
  310.         /// <param name="grid">GridView id</param>  
  311.         /// <param name="intColIndex">列号(总列数-1)</param>  
  312.         /// <param name="strMsg">信息</param>  
  313.         public static void AddConfirm(System.Web.UI.WebControls.GridView grid, int intColIndex, string strMsg)  
  314.         {  
  315.             strMsg = strMsg.Replace("\n""file://n/");  
  316.             strMsg = strMsg.Replace("\r""file://r/");  
  317.             strMsg = strMsg.Replace("\"""\\\"");  
  318.             strMsg = strMsg.Replace("\'""\\\'");  
  319.             for (int i = 0; i < grid.Rows.Count; i++)  
  320.             {  
  321.                 grid.Rows[i].Cells[intColIndex].Attributes.Add("onclick""return confirm('" + strMsg + "')");  
  322.             }  
  323.         }  
  324.         #endregion  
  325.  
  326.         #region 按钮添加弹出窗体对话框  
  327.         /// Button添加弹出窗体对话框  
  328.         /// </summary>  
  329.         /// <param name="button">Button id</param>  
  330.         /// <param name="strUrl">对话框rul</param>  
  331.         /// <param name="intWidth">宽度</param>  
  332.         /// <param name="intHeight">高度</param>  
  333.         public static void AddShowDialog(System.Web.UI.WebControls.Button button, string strUrl, int intWidth, int intHeight)  
  334.         {  
  335.             string strScript = "";  
  336.             strScript += "var strFeatures = 'dialogWidth=" + intWidth.ToString() + "px;dialogHeight=" + intHeight.ToString() + "px;center=yes;help=no;status=no';";  
  337.             strScript += "var strName ='';";  
  338.   
  339.             if (strUrl.Substring(0, 1) == "/")  
  340.             {  
  341.                 strUrl = strUrl.Substring(1, strUrl.Length - 1);  
  342.             }  
  343.   
  344.             strUrl = Common.GetScriptUrl() + "DialogFrame.aspx?URL=" + strUrl;  
  345.   
  346.             strScript += "window.showModalDialog(\'" + strUrl + "\',window,strFeatures);return false;";  
  347.   
  348.             button.Attributes.Add("onClick", strScript);  
  349.         }  
  350.         /// LinkButton添加弹出窗体对话框  
  351.         /// </summary>  
  352.         /// <param name="button">LinkButton id</param>  
  353.         /// <param name="strUrl">对话框rul</param>  
  354.         /// <param name="intWidth">宽度</param>  
  355.         /// <param name="intHeight">高度</param>  
  356.         public static void AddShowDialog(System.Web.UI.WebControls.LinkButton button, string strUrl, int intWidth, int intHeight)  
  357.         {  
  358.             string strScript = "";  
  359.             strScript += "var strFeatures = 'dialogWidth=" + intWidth.ToString() + "px;dialogHeight=" + intHeight.ToString() + "px;center=yes;help=no;status=no';";  
  360.             strScript += "var strName ='';";  
  361.   
  362.             if (strUrl.Substring(0, 1) == "/")  
  363.             {  
  364.                 strUrl = strUrl.Substring(1, strUrl.Length - 1);  
  365.             }  
  366.   
  367.             strUrl = Common.GetScriptUrl() + "DialogFrame.aspx?URL=" + strUrl;  
  368.   
  369.             strScript += "window.showModalDialog(\'" + strUrl + "\',strName,strFeatures);return false;";  
  370.   
  371.             button.Attributes.Add("onClick", strScript);  
  372.         }  
  373.         /// ImageButton添加弹出窗体对话框  
  374.         /// </summary>  
  375.         /// <param name="button">ImageButton id</param>  
  376.         /// <param name="strUrl">对话框rul</param>  
  377.         /// <param name="intWidth">宽度</param>  
  378.         /// <param name="intHeight">高度</param>  
  379.         public static void AddShowDialog(System.Web.UI.WebControls.ImageButton button, string strUrl, int intWidth, int intHeight)  
  380.         {  
  381.             string strScript = "";  
  382.             strScript += "var strFeatures = 'dialogWidth=" + intWidth.ToString() + "px;dialogHeight=" + intHeight.ToString() + "px;center=yes;help=no;status=no';";  
  383.             strScript += "var strName ='';";  
  384.   
  385.             if (strUrl.Substring(0, 1) == "/")  
  386.             {  
  387.                 strUrl = strUrl.Substring(1, strUrl.Length - 1);  
  388.             }  
  389.   
  390.             strUrl = Common.GetScriptUrl() + "DialogFrame.aspx?URL=" + strUrl;  
  391.   
  392.             strScript += "window.showModalDialog(\'" + strUrl + "\',window,strFeatures);return false;";  
  393.   
  394.             button.Attributes.Add("onClick", strScript);  
  395.         }  
  396.         #endregion  
  397.  
  398.         #region 清空选定textbox值  
  399.         /**//// <summary>  
  400.         /// 将选定的TextBox值清空  
  401.         /// </summary>  
  402.         /// <param name="myTextBox"></param>  
  403.         public static void ClearTextBox(System.Web.UI.WebControls.TextBox myTextBox)  
  404.         {  
  405.             myTextBox.Attributes.Add("onclick""this.value=''");  
  406.         }  
  407.         #endregion  
  408.  
  409.         #region windows.open方式打开窗体  
  410.         /// <summary>  
  411.         /// windows.open方式打开窗体  
  412.         /// </summary>  
  413.         /// <param name="pageCurrent">当前页面(this)</param>  
  414.         /// <param name="strUrl">窗体路径</param>  
  415.         /// <param name="intWidth">宽度</param>  
  416.         /// <param name="intHeight">高度</param>  
  417.         /// <param name="intLeft">距离左边长度</param>  
  418.         /// <param name="intTop">距离顶部高度</param>  
  419.         /// <param name="WinName">窗体名称</param>  
  420.         public static void OpenWindow(System.Web.UI.Page pageCurrent, string strUrl, int intWidth, int intHeight, int intLeft, int intTop, string WinName)  
  421.         {  
  422.             StringBuilder sb = new StringBuilder();  
  423.             sb.AppendFormat(@"myleft={0};mytop={1};", intLeft.ToString(), intTop.ToString());  
  424.             sb.AppendLine();  
  425.             sb.AppendFormat(@"settings='top=' + mytop + ',left=' + myleft + ',width={0},height={1},location=no,directories=no,menubar=no,toolbar=no,status=no,scrollbars=no,resizable=no,fullscreen=no';",  
  426.                              intWidth.ToString(), intHeight.ToString());  
  427.             sb.AppendLine();  
  428.             sb.AppendFormat(@"window.open('{0}','{1}', settings);", strUrl, WinName);  
  429.   
  430.             pageCurrent.ClientScript.RegisterStartupScript(pageCurrent.GetType(),  
  431.                     System.Guid.NewGuid().ToString(),  
  432.                     "<script language='javascript'>" + sb.ToString() + "</script>"  
  433.                     );  
  434.   
  435.         }  
  436.         #endregion  
  437.  
  438.         #region 打开模式窗体  
  439.         /// <summary>  
  440.         /// 打开模式窗体  
  441.         /// </summary>  
  442.         /// <param name="pageCurrent">当前页面(this)</param>  
  443.         /// <param name="strUrl">打开窗体路径</param>  
  444.         /// <param name="intWidth">宽度</param>  
  445.         /// <param name="intHeight">高度</param>  
  446.         public static void ShowDialog(System.Web.UI.Page pageCurrent, string strUrl, int intWidth, int intHeight)  
  447.         {  
  448.             string strScript = "";  
  449.             strScript += "var strFeatures = 'dialogWidth=" + intWidth.ToString() + "px;dialogHeight=" + intHeight.ToString() + "px;center=yes;help=no;status=no';";  
  450.             strScript += "var strName ='';";  
  451.             if (strUrl.Substring(0, 1) == "/")  
  452.             {  
  453.                 strUrl = strUrl.Substring(1, strUrl.Length - 1);  
  454.             }  
  455.             strUrl = Common.GetScriptUrl() + "DialogFrame.aspx?URL=" + strUrl;  
  456.   
  457.             strScript += "window.showModalDialog(\"" + strUrl + "\",window,strFeatures); ";  
  458.   
  459.             pageCurrent.ClientScript.RegisterStartupScript(  
  460.                 pageCurrent.GetType(), System.Guid.NewGuid().ToString(),  
  461.                 "<script language='javascript'>" + strScript + "</script>"  
  462.                 );  
  463.         }  
  464.         #endregion  
  465.  
  466.         #region 关闭窗体  
  467.         /// <summary>  
  468.         /// 关闭窗体,没有任何提示的关闭窗体  
  469.         /// </summary>  
  470.         /// <param name="pageCurrent">当前页面(this)</param>  
  471.         public static void CloseWindows(System.Web.UI.Page pageCurrent)  
  472.         {  
  473.             StringBuilder sb = new StringBuilder();  
  474.             sb.Append("<script>window.opener=null;window.close();</script>");  
  475.             pageCurrent.ClientScript.RegisterStartupScript(pageCurrent.GetType(),  
  476.                 System.Guid.NewGuid().ToString(), sb.ToString());  
  477.         }  
  478.   
  479.         /// 有提示信息的关闭窗体  
  480.         /// </summary>  
  481.         /// <param name="pageCurrent">当前页面(this)</param>  
  482.         /// <returns></returns>  
  483.         public static void CloseWindows(System.Web.UI.Page pageCurrent, string strMessage)  
  484.         {  
  485.             StringBuilder sb = new StringBuilder();  
  486.             sb.Append("<script>if(confirm(\"" + strMessage + "\")==true){window.close();}</script>");  
  487.             pageCurrent.ClientScript.RegisterStartupScript(pageCurrent.GetType(),  
  488.                                 System.Guid.NewGuid().ToString(), sb.ToString());  
  489.         }  
  490.         /// <summary>  
  491.         /// 有等待时间的关闭窗体(无提示功能)  
  492.         /// </summary>  
  493.         /// <param name="pageCurrent"></param>  
  494.         /// <param name="WaitTime">等待时间,以毫秒为记量单位</param>  
  495.         public static void CloseWindows(System.Web.UI.Page pageCurrent, int WaitTime)  
  496.         {  
  497.             StringBuilder sb = new StringBuilder();  
  498.             sb.Append("<script language=\"javascript\">");  
  499.             sb.Append("window.opener=null;");  
  500.             sb.Append("setTimeout");  
  501.             sb.Append("(");  
  502.             sb.Append("'");  
  503.             sb.Append("window.close()");  
  504.             sb.Append("'");  
  505.             sb.Append(",");  
  506.             sb.Append(WaitTime.ToString());  
  507.             sb.Append(")");  
  508.             sb.Append("</script>");  
  509.             pageCurrent.ClientScript.RegisterStartupScript(pageCurrent.GetType(),  
  510.                         System.Guid.NewGuid().ToString(), sb.ToString());  
  511.   
  512.         }  
  513.         #endregion  
  514.  
  515.         #region  浏览器左下角提示信息  
  516.         /// <summary>  
  517.         /// 浏览器左下角提示信息  
  518.         /// </summary>  
  519.         /// <param name="pageCurrent"> 当前页面</param>  
  520.         /// <param name="StatusString">信息</param>  
  521.         public static void ShowStatus(System.Web.UI.Page pageCurrent, string StatusString)  
  522.         {  
  523.             StringBuilder sb = new StringBuilder();  
  524.             sb.Append("<script language=\"javascript\">");  
  525.             sb.Append("window.status=");  
  526.             sb.Append("\"");  
  527.             sb.Append(StatusString);  
  528.             sb.Append("\"");  
  529.             sb.Append("</script>");  
  530.             pageCurrent.ClientScript.RegisterStartupScript(pageCurrent.GetType(),  
  531.                 System.Guid.NewGuid().ToString(), sb.ToString());  
  532.         }  
  533.         #endregion  
  534.  
  535.         #region  Image水印  
  536.         /**//// <summary>  
  537.         /// 写入图像水印  
  538.         /// </summary>  
  539.         /// <param name="str">水印字符串</param>  
  540.         /// <param name="filePath">原图片位置</param>  
  541.         /// <param name="savePath">水印加入后的位置</param>  
  542.         /// <returns></returns>  
  543.         public static string CreateBackImage(System.Web.UI.Page pageCurrent, string str, string filePath, string savePath, int x, int y)  
  544.         {  
  545.             System.Drawing.Image img = System.Drawing.Image.FromFile(pageCurrent.MapPath(filePath));  
  546.             //创建图片  
  547.             Graphics graphics = Graphics.FromImage(img);  
  548.             //指定要绘制的面积  
  549.             graphics.DrawImage(img, 0, 0, img.Width, img.Height);  
  550.             //定义字段和画笔  
  551.             Font font = new Font("黑体", 16);  
  552.             Brush brush = new SolidBrush(Color.Yellow);  
  553.             graphics.DrawString(str, font, brush, x, y);  
  554.             //保存并输出图片  
  555.             img.Save(pageCurrent.MapPath(savePath), System.Drawing.Imaging.ImageFormat.Jpeg);  
  556.             return savePath;  
  557.   
  558.         }  
  559.         #endregion  
  560.  
  561.         #region 调用Media播放mp3或电影文件  
  562.         /// <summary>  
  563.         /// 调用Media播放mp3或电影文件  
  564.         /// </summary>  
  565.         /// <param name="pageCurrent">  
  566.         /// 当前的页面对象  
  567.         /// </param>  
  568.         /// <param name="PlayFilePath">  
  569.         /// 播放文件的位置  
  570.         /// </param>  
  571.         /// <param name="MediajavascriptPath">  
  572.         /// Mediajavascript的脚本位置  
  573.         /// </param>  
  574.         /// <param name="enableContextMenu">  
  575.         /// 是否可以使用右键  
  576.         /// 指定是否使右键菜单有效  
  577.         /// 指定右键是否好用,默认为0不好用  
  578.         /// 指定为1时就是好用  
  579.         /// </param>  
  580.         /// <param name="uiMode">  
  581.         /// 播放器的大小显示  
  582.         /// None,mini,或full,指定Windows媒体播放器控制如何显示  
  583.         /// </param>  
  584.         public static string PlayMediaFile(System.Web.UI.Page pageCurrent,  
  585.                         string PlayFilePath, string MediajavascriptPath,  
  586.                         string enableContextMenu, string uiMode)  
  587.         {  
  588.             StreamReader sr = new StreamReader(pageCurrent.MapPath(MediajavascriptPath));  
  589.             StringBuilder sb = new StringBuilder();  
  590.             string line;  
  591.             try  
  592.             {  
  593.                 while ((line = sr.ReadLine()) != null)  
  594.                 {  
  595.                     sb.AppendLine(line);  
  596.   
  597.                 }  
  598.                 sr.Close();  
  599.             }  
  600.             catch (Exception ex)  
  601.             {  
  602.                 throw new Exception(ex.Message);  
  603.             }  
  604.             sb.Replace("$URL", pageCurrent.MapPath(PlayFilePath));  
  605.             sb.Replace("$enableContextMenu", enableContextMenu);  
  606.             sb.Replace("$uiMode", uiMode);  
  607.             return sb.ToString();  
  608.         }  
  609.         #endregion  
  610.  
  611.         #region 实现进度条的功能  
  612.         /**/  
  613.         /// <summary>  
  614.         /// 主要实现进度条的功能,这段代码的调用就要实现进度的调度  
  615.         /// 实现主要过程  
  616.         /// default.aspx.cs是调用页面  
  617.         /// 放入page_load事件中  
  618.         ///            UIHelper myUI = new UIHelper();  
  619.         ///            Response.Write(myUI.ShowProgBar(this.Page,"../JS/progressbar.htm"));  
  620.         ///            Thread thread = new Thread(new ThreadStart(ThreadProc));  
  621.         ///            thread.Start();  
  622.         ///            LoadData();//load数据   
  623.         ///            thread.Join();  
  624.         ///            Response.Write("OK");  
  625.         ///   
  626.         /// 其中ThreadProc方法为  
  627.         ///     public void ThreadProc()  
  628.         ///    {  
  629.         ///    string strScript = "<script>setPgb('pgbMain','{0}');</script>";  
  630.         ///    for (int i = 0; i <= 100; i++)  
  631.         ///     {  
  632.         ///        System.Threading.Thread.Sleep(10);  
  633.         ///        Response.Write(string.Format(strScript, i));  
  634.         ///        Response.Flush();  
  635.         ///     }  
  636.         ///    }  
  637.         /// 其中LoadData()  
  638.         ///     public void LoadData()  
  639.         ///        {  
  640.         ///            for (int m = 0; m < 900; m++)  
  641.         ///            {  
  642.         ///                for (int i = 0; i < 900; i++)  
  643.         ///                {  
  644.         ///  
  645.         ///                }  
  646.         ///            }  
  647.         ///        }  
  648.         ///   
  649.         /// </summary>  
  650.         /// <param name="pageCurrent"></param>  
  651.         /// <param name="ShowProgbarScript"></param>  
  652.         /// <returns></returns>  
  653.         public static string ShowProgBar(System.Web.UI.Page pageCurrent, string ShowProgbarScript)  
  654.         {  
  655.             StreamReader sr = new StreamReader(pageCurrent.MapPath(ShowProgbarScript), System.Text.Encoding.Default);  
  656.             StringBuilder sb = new StringBuilder();  
  657.             string line;  
  658.             try  
  659.             {  
  660.                 while ((line = sr.ReadLine()) != null)  
  661.                 {  
  662.                     sb.AppendLine(line);  
  663.   
  664.                 }  
  665.                 sr.Close();  
  666.             }  
  667.             catch (Exception ex)  
  668.             {  
  669.                 throw new Exception(ex.Message);  
  670.             }  
  671.             //pageCurrent.ClientScript.RegisterStartupScript(pageCurrent.GetType(),  
  672.             //            System.Guid.NewGuid().ToString(), sb.ToString());  
  673.             return sb.ToString();  
  674.         }  
  675.         #endregion  
  676.  
  677.         #region 刷新页面  
  678.         public static void refreshPage(System.Web.UI.Page pageCurrent)  
  679.         {  
  680.             StringBuilder sb = new StringBuilder();  
  681.             sb.Append("<script language=\"javascript\">");  
  682.             sb.Append("window.location.href=window.location.href;");  
  683.             sb.Append("</script>");  
  684.             pageCurrent.ClientScript.RegisterStartupScript(pageCurrent.GetType(),  
  685.                         System.Guid.NewGuid().ToString(), sb.ToString());  
  686.   
  687.         }  
  688.         #endregion  
  689.  
  690.         #region 页面被载入和调出时的一些特效  
  691.         //进入页面<meta http-equiv="Page-Enter" content="revealTrans(duration=x, transition=y)">  
  692.         //推出页面<meta http-equiv="Page-Exit" content="revealTrans(duration=x, transition=y)">   
  693.         //这个是页面被载入和调出时的一些特效。duration表示特效的持续时间,以秒为单位。transition表示使用哪种特效,取值为1-23:  
  694.         //  0 矩形缩小   
  695.         //  1 矩形扩大   
  696.         //  2 圆形缩小  
  697.         //  3 圆形扩大   
  698.         //  4 下到上刷新   
  699.         //  5 上到下刷新  
  700.         //  6 左到右刷新   
  701.         //  7 右到左刷新   
  702.         //  8 竖百叶窗  
  703.         //  9 横百叶窗   
  704.         //  10 错位横百叶窗   
  705.         //  11 错位竖百叶窗  
  706.         //  12 点扩散   
  707.         //  13 左右到中间刷新   
  708.         //  14 中间到左右刷新  
  709.         //  15 中间到上下  
  710.         //  16 上下到中间   
  711.         //  17 右下到左上  
  712.         //  18 右上到左下   
  713.         //  19 左上到右下   
  714.         //  20 左下到右上  
  715.         //  21 横条   
  716.         //  22 竖条   
  717.         //  23 以上22种随机选择一种  
  718.   
  719.         public static string Page_revealTrans(System.Web.UI.Page currentPage, string duration,  
  720.                                        string transition)  
  721.         {  
  722.             StringBuilder sb = new StringBuilder();  
  723.             sb.Append("<meta http-equiv=\"Page-Enter\"");  
  724.             sb.Append("content=\"");  
  725.             sb.Append("revealTrans(duration=" + duration);  
  726.             sb.Append(",transition=" + transition);  
  727.             sb.Append(")\">");  
  728.             //currentPage.ClientScript.RegisterStartupScript(currentPage.GetType(),  
  729.             //        System.Guid.NewGuid().ToString(), sb.ToString());  
  730.             return sb.ToString();  
  731.         }  
  732.         #endregion  
  733.  
  734.         #region 调用客户端JavaScript函数  
  735.         /// <summary>  
  736.         /// 调用客户端JavaScript函数  
  737.         /// </summary>  
  738.         /// <param name="page">页面指针,一般为This</param>  
  739.         /// <param name="scriptName">函数名,带参数,如:FunA(1);</param>  
  740.         public static void CallClientScript(System.Web.UI.Page page, string scriptName)  
  741.         {  
  742.             String csname = "PopupScript";  
  743.             Type cstype = page.GetType();  
  744.             System.Web.UI.ClientScriptManager cs = page.ClientScript;  
  745.             if (!cs.IsStartupScriptRegistered(cstype, csname))  
  746.             {  
  747.                 String cstext = scriptName;  
  748.                 cs.RegisterStartupScript(cstype, csname, cstext, true);  
  749.             }  
  750.         }  
  751.         #endregion  
  752.   
  753.     }  
0 0