自己构造公用程序(2)--消息处理
//===========================================
//项目名称:
//类名: MsgTool
//创建者: Applegreen
//修改时间:2004-7-22
//内容描述:消息处理
//===========================================
using System;
using System.Collections;
using System.Web;
using System.Text;
namespace RoleCom
{
/// <summary>
/// MsgTool B/S系统中。
/// </summary>
public class MsgTool
{
private bool m_result=false;
private string m_message="";
private ICollection m_append=null;
/// <summary>
/// 用来设置和取得结果属性
/// </summary>
public bool Result
{
get
{
return m_result;
}
set
{
m_result=value;
}
}
/// <summary>
/// 用来设置和取得信息属性
/// </summary>
public string Message
{
get
{
return m_message;
}
set
{
m_message=value;
}
}
/// <summary>
/// 用来设置和取得添加信息
/// </summary>
public ICollection append
{
get
{
return m_append;
}
set
{
m_append=value;
}
}
public MsgTool()
{
}
/// <summary>
/// 创建含结果和提示信息,还有添加信息的的消息工具
/// </summary>
/// <param name="b_result">是否成功</param>
/// <param name="s_message">提示信息</param>
/// <param name="append">添加信息集合</param>
public MsgTool(bool b_result,string s_message,ICollection append)
{
this.m_result=b_result;
this.m_message=s_message;
this.m_append=append;
}
/// <summary>
/// 创建含结果和提示信息的消息工具
/// </summary>
/// <param name="b_result">是否成功</param>
/// <param name="s_message">提示信息</param>
public MsgTool(bool b_result,string s_message)
{
this.m_result=b_result;
this.m_message=s_message;
}
/// <summary>
/// 弹出信息提示
/// </summary>
/// <param name="response">封装来自ASP.NET操作的HTTP响应信息</param>
public void MessageBox(HttpResponse response)
{
if (m_message!="")
{
String msgScript=GetAlertScript(m_message);
response.Write(msgScript);
}
}
/// <summary>
/// 弹出信息提示
/// </summary>
/// <param name="response">封装来自ASP.NET操作的HTTP响应信息</param>
public void MessageWindow(HttpResponse response)
{
if (m_message!="")
{
MessageBox(response);
}
}
/// <summary>
/// 返回带含有提示信息的脚本
/// </summary>
/// <param name="strMessage">提示信息</param>
/// <returns></returns>
public string GetAlertScript(string strMessage)
{
strMessage =strMessage.Replace("\n","");
strMessage =strMessage.Replace("\t","");
strMessage =strMessage.Replace("\r","");
strMessage =strMessage.Replace("\"","\\\"");
return "<script language=\"javascript\">alert(\""+strMessage +"\");</script>";
}
}
}