using System;
using System.Text;
namespace Common
{
	/// <summary>
	/// ÏÔÊ¾ÏûÏ¢ÌáÊ¾¶Ô»°¿ò¡£
    /// Copyright (C) Maticsoft
	/// </summary>
	public class MessageBox
	{		
		private  MessageBox()
		{			
		}

		/// <summary>
		/// ÏÔÊ¾ÏûÏ¢ÌáÊ¾¶Ô»°¿ò
		/// </summary>
		/// <param name="page">µ±Ç°Ò³ÃæÖ¸Õë£¬Ò»°ãÎªthis</param>
		/// <param name="msg">ÌáÊ¾ÐÅÏ¢</param>
		public static void  Show(System.Web.UI.Page page,string msg)
		{            
            page.ClientScript.RegisterStartupScript(page.GetType(),"message", "<script language='javascript' defer>alert('" + msg.ToString() + "');</script>");
		}

		/// <summary>
		/// ¿Ø¼þµã»÷ ÏûÏ¢È·ÈÏÌáÊ¾¿ò
		/// </summary>
		/// <param name="page">µ±Ç°Ò³ÃæÖ¸Õë£¬Ò»°ãÎªthis</param>
		/// <param name="msg">ÌáÊ¾ÐÅÏ¢</param>
		public static void  ShowConfirm(System.Web.UI.WebControls.WebControl Control,string msg)
		{
			//Control.Attributes.Add("onClick","if (!window.confirm('"+msg+"')){return false;}");
			Control.Attributes.Add("onclick", "return confirm('" + msg + "');") ;
		}

		/// <summary>
		/// ÏÔÊ¾ÏûÏ¢ÌáÊ¾¶Ô»°¿ò£¬²¢½øÐÐÒ³ÃæÌø×ª
		/// </summary>
		/// <param name="page">µ±Ç°Ò³ÃæÖ¸Õë£¬Ò»°ãÎªthis</param>
		/// <param name="msg">ÌáÊ¾ÐÅÏ¢</param>
		/// <param name="url">Ìø×ªµÄÄ¿±êURL</param>
		public static void ShowAndRedirect(System.Web.UI.Page page,string msg,string url)
		{			
            //Response.Write("<script>alert('ÕÊ»§ÉóºËÍ¨¹ý£¡ÏÖÔÚÈ¥ÎªÆóÒµ³äÖµ¡£');window.location=\"" + pageurl + "\"</script>");
            page.ClientScript.RegisterStartupScript(page.GetType(), "message", "<script language='javascript' defer>alert('" + msg + "');window.location=\"" + url + "\"</script>");


		}
        /// <summary>
        /// ÏÔÊ¾ÏûÏ¢ÌáÊ¾¶Ô»°¿ò£¬²¢½øÐÐÒ³ÃæÌø×ª
        /// </summary>
        /// <param name="page">µ±Ç°Ò³ÃæÖ¸Õë£¬Ò»°ãÎªthis</param>
        /// <param name="msg">ÌáÊ¾ÐÅÏ¢</param>
        /// <param name="url">Ìø×ªµÄÄ¿±êURL</param>
        public static void ShowAndRedirects(System.Web.UI.Page page, string msg, string url)
        {
            StringBuilder Builder = new StringBuilder();
            Builder.Append("<script language='javascript' defer>");
            Builder.AppendFormat("alert('{0}');", msg);
            Builder.AppendFormat("top.location.href='{0}'", url);
            Builder.Append("</script>");
            page.ClientScript.RegisterStartupScript(page.GetType(), "message", Builder.ToString());

        }

		/// <summary>
		/// Êä³ö×Ô¶¨Òå½Å±¾ÐÅÏ¢
		/// </summary>
		/// <param name="page">µ±Ç°Ò³ÃæÖ¸Õë£¬Ò»°ãÎªthis</param>
		/// <param name="script">Êä³ö½Å±¾</param>
		public static void ResponseScript(System.Web.UI.Page page,string script)
		{
            page.ClientScript.RegisterStartupScript(page.GetType(), "message", "<script language='javascript' defer>" + script + "</script>");
             
		}

	}
}
