using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
namespace MyBlog.WEB
{
public class PageBase : System.Web.UI.Page
{
///
/// MD5加密
///
/// 需要加密的字符串
/// 加密后字符串
public static string HashString(string sInputString)
{
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sInputString, "MD5");
}
///
/// MessageBox提示框
///
/// 提示信息
public void MsgBox(string Message)
{
ClientScript.RegisterStartupScript(this.GetType(), "", "alert('" + Message + "');");
return;
}
///
/// MessageBox提示并转向新页面
///
/// 提示信息
/// 跳转的路径
public void MsgBox(string Message, string URL)
{
ClientScript.RegisterStartupScript(this.GetType(), "", "alert('" + Message + "');window.location='" + URL + "';");
return;
}
///
/// 弹出新窗口
///
/// 页面路径
/// 新窗口名称
/// 新窗口宽度
/// 新窗口高度
public void openNewWin(string pagePath, string winName, int winWidth, int winHeight)
{
ClientScript.RegisterStartupScript(this.GetType(), "", "window.open('" + pagePath + "','" + winName + "','toolbar=no,menubar=no,titlebar=no,directories=no,resizable=no,scroll=yes,status=no,fullscreen=no,center=yes,width=" + winWidth + ",height=" + winHeight + "');");
return;
}
///
/// 弹出模态窗口
///
/// 页面路径
/// 窗口宽度
/// 窗口高度
public void openModelWin(string pagePath, int winWidth, int winHeight)
{
string temp;
temp = @"";
temp += (@" var sPath ='" + pagePath + "';");
temp += (@" strFeatures ='dialogWidth=" + winWidth + "px;dialogHeight=" + winHeight + "px;center=yes;scroll=no;help=no;status: No';");
temp += (@" var returnvalue = window.showModalDialog(sPath,'brower',strFeatures);");
temp += (@"");
ClientScript.RegisterStartupScript(this.GetType(), "message", temp);
}
///
/// 弹出控制父窗口的模态窗口
///
/// 页面路径
/// 窗口宽度
/// 窗口高度
/// 控制父窗口路径
public void openModelWin(string pagepath, int width, int height, string frameshref)
{
string temp = @"";
temp += (@" var sPath ='" + pagepath + "';");
temp += (@" strFeatures ='dialogWidth=" + width + "px;dialogHeight=" + height + "px;center=yes;scroll=no;help=no;status=no';");
temp += (@" var returnvalue = window.showModalDialog(sPath,'brower',strFeatures);");
temp += (@" window.location.href = '" + frameshref + "';");
temp += (@"");
ClientScript.RegisterStartupScript(this.GetType(), "message", temp);
}
///
/// 关闭本窗口
///
public void CloseWin()
{
ClientScript.RegisterStartupScript(this.GetType(), "", "window.opener=null;window.close();");
return;
}
///
/// 弹出提示信息,并关闭本窗口
/// 弹出提示信息内容
///
public void CloseWin(string Words)
{
ClientScript.RegisterStartupScript(this.GetType(), "", "alert('"+Words+"');window.opener=null;window.close();");
return;
}
///
/// 关闭本窗口并,重新加载父窗口.
///
/// 父窗口要加载的URL
public void reLoadParentAndClose(string URL)
{
ClientScript.RegisterStartupScript(this.GetType(), "", "window.opener.location='" + URL + "';window.close();");
return;
}
///
/// 显示提示信息,关闭本窗口并,重新加载父窗口.
///
/// 提示消息内容
/// 父窗口要加载的URL
public void ShowWords_reLoadParentAndClose(string Words,string URL)
{
ClientScript.RegisterStartupScript(this.GetType(), "", "alert('" + Words
+ "'); window.opener.location='" + URL + "';window.close();");
return;
}
///
/// 获取客户端IP
///
///
public string GetClientIP()
{
string result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (null == result || result == String.Empty)
{
result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
}
if (null == result || result == String.Empty)
{
result = HttpContext.Current.Request.UserHostAddress;
}
return result;
}
///
/// 获取Session值
///
/// 要获取的Session值
///
public string GetSession(string SessionID)
{
string restr = "unkown";
try
{
restr = Session[SessionID].ToString();
}
catch
{
}
if (restr == "unkown" && restr == null && restr == "")
{
Response.Redirect("/Error.aspx?Type=NoPopedom");
}
return restr;
}
///
/// 写Cookie
///
/// Cookie集名称
/// Cookie名
/// 值
public void WritCookie(string CookiesName, string name, string Value)
{
HttpCookie cookie = new HttpCookie(CookiesName);
cookie.Values.Add(name, Value);
Response.AppendCookie(cookie);
}
///
/// 获取Cookie
///
/// Cookie集名称
/// Cookie名
/// 值
public string GetCookie(string CookiesName, string name)
{
string value = string.Empty;
try
{
HttpCookie cookie = Request.Cookies[CookiesName];
value = cookie.Values[name];
}
catch
{
Response.Redirect("/Error.aspx?Type=GetCookie");
}
return value;
}
}
}