【源码】自己写的Msg

///<summary>
/// 返回提示信息类
///</summary>
public class Msg
{
//sql语句拆解添加换行
public static string SqlAddBr(string sql)
{
sql = sql.ToLower();
if (sql.IndexOf("from") > -1)
{
int i = sql.IndexOf("from");
sql = sql.Substring(0, i) + "<br/><br/>" + sql.Substring(i, sql.Length - i);
}
if (sql.IndexOf("where") > -1)
{
int i = sql.IndexOf("where");
sql = sql.Substring(0, i) + "<br/><br/>" + sql.Substring(i, sql.Length - i);
}
if (sql.IndexOf("group by") > -1)
{
int i = sql.IndexOf("group by");
sql = sql.Substring(0, i) + "<br/><br/>" + sql.Substring(i, sql.Length - i);
}
if (sql.IndexOf("order by") > -1)
{
int i = sql.IndexOf("order by");
sql = sql.Substring(0, i) + "<br/><br/>" + sql.Substring(i, sql.Length - i);
}

return sql;
}
public Msg()
{
//初始化
}
public static void Confirm(string MsgStr)
{
System.Web.HttpContext.Current.Response.Write("<script language=javascript>if(!confirm(' " + MsgStr + "'))history.back();</script>");
}
public static void RedirectDelay(string MsgStr, int DelayTime)
{
string url = System.Web.HttpContext.Current.Request.RawUrl.ToString();
System.Web.HttpContext.Current.Response.Write("<meta http-equiv=refresh content=\"" + DelayTime + ";URL=" + url + "\">");
System.Web.HttpContext.Current.Response.Write(MsgStr);
System.Web.HttpContext.Current.Response.End();
}
public static void RedirectDelay(string MsgStr, string url, int DelayTime)
{
System.Web.HttpContext.Current.Response.Write("<meta http-equiv=refresh content=\"" + DelayTime + ";URL=" + url + "\">");
System.Web.HttpContext.Current.Response.Write(MsgStr);
System.Web.HttpContext.Current.Response.End();
}

///<summary>
/// 转向到某个地址页面,并传送错误信息字串
///</summary>
///<param name="UrlStr"></param>
///<param name="UrlMsg"></param>
public static void direct(string UrlStr, string UrlMsg)
{
System.Web.HttpContext.Current.Response.Redirect(UrlStr + "?ErrMsg=" + UrlMsg);
}
public static void direct(string Url,bool IsTopWindows)
{
string Top = "window.location";
if (IsTopWindows) Top = "top.location";

System.Web.HttpContext.Current.Response.Write("<script language=javascript>" + Top + "='" + Url + "'</script>");
}

///<summary>
/// 将str参数打印在页面上
///</summary>
///<param name="MsgStr">例:"您尚未登陆!"</param>
public static void c1(string MsgStr)
{
System.Web.HttpContext.Current.Response.Write(" <span style='background-color:#FBB7A8;font-size:20px'>" + MsgStr + "</span><hr>\n");
}
public static void c1(string MsgStr,string IsWarp)
{
MsgStr = SqlAddBr(MsgStr);
System.Web.HttpContext.Current.Response.Write(" <span style='background-color:#FBB7A8;font-size:20px'>" + MsgStr + "</span><hr>\n");
}
public static void c1(string MsgStr, bool IsTable)
{
if (IsTable) System.Web.HttpContext.Current.Response.Write(@"<table border=1 cellpadding=0 cellspacing=0 bordercolor=#FFFFFF bordercolorlight=#000000><tr><td>" + MsgStr + "</td></tr></table>");
}
///<summary>
/// 将str参数打印在页面上,并且停止页面执行
///</summary>
///<param name="MsgStr">例:"您尚未登陆!"</param>
///<param name="stop">布尔参数,例:true</param>
public static void c2(string MsgStr)
{
MsgStr = SqlAddBr(MsgStr);
System.Web.HttpContext.Current.Response.Write(" <span style='background-color:#FBB7A8;font-size:20px'>" + MsgStr + "</span><hr><h1 align=center>End</h1>");
System.Web.HttpContext.Current.Response.End();
}
public static void c2(string MsgStr, bool IsTable)
{
if (IsTable) System.Web.HttpContext.Current.Response.Write(@"<table border=1 cellpadding=0 cellspacing=0 bordercolor=#FFFFFF bordercolorlight=#000000><tr><td>" + MsgStr + "</td></tr></table>");
System.Web.HttpContext.Current.Response.End();
}
public static void c2()
{
System.Web.HttpContext.Current.Response.Write("<hr size=1 align=center width=30%><h1 align=center>End</h1>");
System.Web.HttpContext.Current.Response.End();
}

///<summary>
/// 在页面显示错误信息后,停留n秒,跳转到另一页面
///</summary>
///<param name="MsgStr"></param>
///<param name="Url"></param>
///<param name="TimeDiff"></param>
///<param name="Color"></param>
public static void c3(string MsgStr,string Url)
{
System.Web.HttpContext.Current.Response.Write("<center><br><br><br><br><br><br>"+MsgStr+"<br><br>3 秒钟后返回......</center>");
System.Web.HttpContext.Current.Response.Write("<meta http-equiv=\"refresh\" content=\"3;URL="+Url+"\" />");
System.Web.HttpContext.Current.Response.Write("<body bgcolor='white'>");
System.Web.HttpContext.Current.Response.End();
}
public static void c3(string MsgStr,string Url,string TimeDiff)
{
System.Web.HttpContext.Current.Response.Write("<center><br><br><br><br><br><br>"+MsgStr+"<br><br>"+TimeDiff+"秒钟后返回......</center>");
System.Web.HttpContext.Current.Response.Write("<meta http-equiv=\"refresh\" content=\""+TimeDiff+";URL="+Url+"\" />");
System.Web.HttpContext.Current.Response.Write("<body bgcolor='white'>");
System.Web.HttpContext.Current.Response.End();
}

///<summary>
/// 弹出对话框提示信息
///</summary>
///<param name="MsgStr">例:"您尚未登陆!"</param>
public static void Alert(string MsgStr)
{
System.Web.HttpContext.Current.Response.Write("<script language=javascript>alert('"+MsgStr+"');</script>");
}
///<summary>
/// 提示,true 返回前一页,history.back(),false ,不返回,直接关闭窗口
///</summary>
///<param name="MsgStr"></param>
public static void Alert(string MsgStr,bool IsBack)
{
if (IsBack)
{
System.Web.HttpContext.Current.Response.Write("<script language=javascript>alert('" + MsgStr + "');history.back();</script>");
System.Web.HttpContext.Current.Response.End();
}
else
{
System.Web.HttpContext.Current.Response.Write("<script language=javascript>alert('"+MsgStr+"');window.close();</script>");
System.Web.HttpContext.Current.Response.End();
}
}
///<summary>
/// 弹出对话框提示信息,并跳转到指定的页面,rul为空,则默认为前页
///</summary>
///<param name="MsgStr">例:"您尚未登陆!"</param>
///<param name="url">例:"error.aspx",为空则默认前一页面</param>
public static void Alert(string MsgStr, string url)
{
if (url == "")
{
System.Web.HttpContext.Current.Response.Write("<script language=javascript>alert('"+MsgStr+"');window.location='"+System.Web.HttpContext.Current.Request.ServerVariables["HTTP_REFERER"].ToString()+"'</script>");
}
else
{
System.Web.HttpContext.Current.Response.Write("<script language=javascript>alert('"+MsgStr+"');window.location='"+url+"'</script>");
}

System.Web.HttpContext.Current.Response.End();
}
public static void Alert(string MsgStr, string url, bool IsTopWindows)
{
string Top = "window.location";
if (IsTopWindows) Top = "top.location";
if (url == "")
{
System.Web.HttpContext.Current.Response.Write("<script language=javascript>alert('" + MsgStr + "');" + Top + "='" + System.Web.HttpContext.Current.Request.ServerVariables["HTTP_REFERER"].ToString() + "'</script>");
}
else
{
System.Web.HttpContext.Current.Response.Write("<script language=javascript>alert('" + MsgStr + "');" + Top + "='" + url + "'</script>");
}

System.Web.HttpContext.Current.Response.End();
}
}
posted @ 2011-11-28 14:56  心_远  阅读(265)  评论(0编辑  收藏  举报