using System;
using System.Web;
using System.IO;
using System.Web;
using System.IO;
namespace WebTool
{
/// <summary>
/// NewTools 的摘要描述。
/// </summary>
public class WebTools
{
/// <summary>
/// 建构函式
/// </summary>
private WebTools()
{
{
/// <summary>
/// NewTools 的摘要描述。
/// </summary>
public class WebTools
{
/// <summary>
/// 建构函式
/// </summary>
private WebTools()
{
}
/// <summary>
/// 在客户端弹出一个全屏的新页面 .
/// </summary>
/// <param name="path"> 新页面的地址。 </param>
/// <remarks> 在客户端弹出一个全屏的新页面 </remarks>
public static void PopupFullWindows(string path)
{
System.Text .StringBuilder sb_tmp=new System .Text .StringBuilder ();
sb_tmp.Append ("<script language=javascript>/r/n");
sb_tmp.Append ("var newWin = window.open('"+path+"','','toolbar=no,location=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes');");
sb_tmp.Append ("newWin.moveTo(-4,-4);");
sb_tmp.Append ("newWin.resizeTo(screen.availWidth+8,screen.availHeight+8);");
sb_tmp.Append ("</script>");
HttpContext.Current.Response.Write(sb_tmp.ToString ());
/// 在客户端弹出一个全屏的新页面 .
/// </summary>
/// <param name="path"> 新页面的地址。 </param>
/// <remarks> 在客户端弹出一个全屏的新页面 </remarks>
public static void PopupFullWindows(string path)
{
System.Text .StringBuilder sb_tmp=new System .Text .StringBuilder ();
sb_tmp.Append ("<script language=javascript>/r/n");
sb_tmp.Append ("var newWin = window.open('"+path+"','','toolbar=no,location=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes');");
sb_tmp.Append ("newWin.moveTo(-4,-4);");
sb_tmp.Append ("newWin.resizeTo(screen.availWidth+8,screen.availHeight+8);");
sb_tmp.Append ("</script>");
HttpContext.Current.Response.Write(sb_tmp.ToString ());
}
/// <summary>
/// 在客户端弹出一个全屏的新页面 .
/// </summary>
/// <param name="path"> 新页面的地址。 </param>
/// <param name="strFeature"> 新窗口的特性 , 可设定 toolbar,location,status,menubar,scrollbars,resizable 等 .</param>
/// <remarks> 在客户端弹出一个全屏的新页面 </remarks>
public static void PopupFullWindows(string path,string strFeature)
{
System.Text .StringBuilder sb_tmp=new System .Text .StringBuilder ();
sb_tmp.Append ("<script language=javascript>/r/n");
sb_tmp.Append ("var newWin = window.open('"+path+"','','"+strFeature+"');");
sb_tmp.Append ("newWin.moveTo(-4,-4);");
sb_tmp.Append ("newWin.resizeTo(screen.availWidth+8,screen.availHeight+8);");
sb_tmp.Append ("</script>");
HttpContext.Current.Response.Write(sb_tmp.ToString ());
/// 在客户端弹出一个全屏的新页面 .
/// </summary>
/// <param name="path"> 新页面的地址。 </param>
/// <param name="strFeature"> 新窗口的特性 , 可设定 toolbar,location,status,menubar,scrollbars,resizable 等 .</param>
/// <remarks> 在客户端弹出一个全屏的新页面 </remarks>
public static void PopupFullWindows(string path,string strFeature)
{
System.Text .StringBuilder sb_tmp=new System .Text .StringBuilder ();
sb_tmp.Append ("<script language=javascript>/r/n");
sb_tmp.Append ("var newWin = window.open('"+path+"','','"+strFeature+"');");
sb_tmp.Append ("newWin.moveTo(-4,-4);");
sb_tmp.Append ("newWin.resizeTo(screen.availWidth+8,screen.availHeight+8);");
sb_tmp.Append ("</script>");
HttpContext.Current.Response.Write(sb_tmp.ToString ());
}
/// <summary>
/// 在客户弹出一个新的页面 .
/// </summary>
/// <param name="path"> 新页面的地址。 </param>
/// <param name="iHeight"> 新页面的高度 </param>
/// <param name="iWidth"> 新页面的宽度 </param>
public static void PopupWindows(string path,int iHeight,int iWidth)
{
System.Text .StringBuilder sb_tmp=new System .Text .StringBuilder ();
sb_tmp.Append ("<script language=javascript>/r/n");
sb_tmp.Append ("<!--/r/n");
sb_tmp.Append ("var features = /"toolbar=no,location=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,/";");
sb_tmp.Append ("features += /"width=/"+"+iWidth+"+/",/";");
sb_tmp.Append ("features += /"height=/"+"+iHeight+"+/",/";");
sb_tmp.Append ("features += /"top= /"+(window.screen.availHeight+8)/2-"+iWidth/2+"+/",/";");
sb_tmp.Append ("features += /"left= /"+(window.screen.availWidth+8)/2-"+iHeight/2+";");
sb_tmp.Append ("window.open('"+path+"','',features)");
sb_tmp.Append ("//-->/r/n");
sb_tmp.Append ("</script>");
HttpContext.Current.Response.Write(sb_tmp.ToString ());
/// 在客户弹出一个新的页面 .
/// </summary>
/// <param name="path"> 新页面的地址。 </param>
/// <param name="iHeight"> 新页面的高度 </param>
/// <param name="iWidth"> 新页面的宽度 </param>
public static void PopupWindows(string path,int iHeight,int iWidth)
{
System.Text .StringBuilder sb_tmp=new System .Text .StringBuilder ();
sb_tmp.Append ("<script language=javascript>/r/n");
sb_tmp.Append ("<!--/r/n");
sb_tmp.Append ("var features = /"toolbar=no,location=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,/";");
sb_tmp.Append ("features += /"width=/"+"+iWidth+"+/",/";");
sb_tmp.Append ("features += /"height=/"+"+iHeight+"+/",/";");
sb_tmp.Append ("features += /"top= /"+(window.screen.availHeight+8)/2-"+iWidth/2+"+/",/";");
sb_tmp.Append ("features += /"left= /"+(window.screen.availWidth+8)/2-"+iHeight/2+";");
sb_tmp.Append ("window.open('"+path+"','',features)");
sb_tmp.Append ("//-->/r/n");
sb_tmp.Append ("</script>");
HttpContext.Current.Response.Write(sb_tmp.ToString ());
}
/// <summary>
/// 在客户弹出一个新的页面 .
/// </summary>
/// <param name="path"> 新页面的地址。 </param>
/// <param name="iHeight"> 新页面的高度 </param>
/// <param name="iWidth"> 新页面的宽度 </param>
/// <param name="strFeature"> 新窗口的特性 , 可设定 toolbar,location,status,menubar,scrollbars,resizable 等 .</param>
public static void PopupWindows(string path,int iHeight,int iWidth,string strFeature)
{
System.Text .StringBuilder sb_tmp=new System .Text .StringBuilder ();
sb_tmp.Append ("<script language=javascript>/r/n");
sb_tmp.Append ("<!--/r/n");
sb_tmp.Append ("var features = /""+strFeature+",/";");
sb_tmp.Append ("features += /"width=/"+"+iWidth+"+/",/";");
sb_tmp.Append ("features += /"height=/"+"+iHeight+"+/",/";");
sb_tmp.Append ("features += /"top= /"+(window.screen.availHeight+8)/2-"+iWidth/2+"+/",/";");
sb_tmp.Append ("features += /"left= /"+(window.screen.availWidth+8)/2-"+iHeight/2+";");
sb_tmp.Append ("window.open('"+path+"','',features)");
sb_tmp.Append ("//-->/r/n");
sb_tmp.Append ("</script>");
HttpContext.Current.Response.Write(sb_tmp.ToString ());
/// 在客户弹出一个新的页面 .
/// </summary>
/// <param name="path"> 新页面的地址。 </param>
/// <param name="iHeight"> 新页面的高度 </param>
/// <param name="iWidth"> 新页面的宽度 </param>
/// <param name="strFeature"> 新窗口的特性 , 可设定 toolbar,location,status,menubar,scrollbars,resizable 等 .</param>
public static void PopupWindows(string path,int iHeight,int iWidth,string strFeature)
{
System.Text .StringBuilder sb_tmp=new System .Text .StringBuilder ();
sb_tmp.Append ("<script language=javascript>/r/n");
sb_tmp.Append ("<!--/r/n");
sb_tmp.Append ("var features = /""+strFeature+",/";");
sb_tmp.Append ("features += /"width=/"+"+iWidth+"+/",/";");
sb_tmp.Append ("features += /"height=/"+"+iHeight+"+/",/";");
sb_tmp.Append ("features += /"top= /"+(window.screen.availHeight+8)/2-"+iWidth/2+"+/",/";");
sb_tmp.Append ("features += /"left= /"+(window.screen.availWidth+8)/2-"+iHeight/2+";");
sb_tmp.Append ("window.open('"+path+"','',features)");
sb_tmp.Append ("//-->/r/n");
sb_tmp.Append ("</script>");
HttpContext.Current.Response.Write(sb_tmp.ToString ());
}
/// <summary>
/// 显示警告消息对话框
/// </summary>
/// <param name="info"> 要显示的消息 </param>
public static void WarningDialog(string info)
{
info = info.Replace(" //","").Replace("/r/n","/n").Replace("/n","//n ");
info = info.Replace("/'","///'").Replace("/"","///"");
System.Text .StringBuilder sb_tmp=new System .Text .StringBuilder ();
sb_tmp.Append ("<script language=javascript>/r/n");
sb_tmp.Append ("alert('"+info+"')/r/n");
sb_tmp.Append ("</script>/r/n");
HttpContext.Current.Response.Write(sb_tmp.ToString ());
}
/// <summary>
/// 显示警告消息对话框
/// </summary>
/// <param name="info"> 要显示的消息 </param>
public static void WarningDialog(string info)
{
info = info.Replace(" //","").Replace("/r/n","/n").Replace("/n","//n ");
info = info.Replace("/'","///'").Replace("/"","///"");
System.Text .StringBuilder sb_tmp=new System .Text .StringBuilder ();
sb_tmp.Append ("<script language=javascript>/r/n");
sb_tmp.Append ("alert('"+info+"')/r/n");
sb_tmp.Append ("</script>/r/n");
HttpContext.Current.Response.Write(sb_tmp.ToString ());
}
/// <summary>
/// 显示确认对话框
/// </summary>
/// <param name="msg"> 确认信息 </param>
/// <param name="distPath"> 当客户端点 ' 取消 ' 时转向的页面 </param>
/// <remarks> 当客户端点 ' 确认 ' 往下执行,当客户端点 ' 取消 ' 时转向另一个页面 </remarks>
public static void ConfirmDialog(string msg, string distPath)
{
msg = msg.Replace(" //","").Replace("/r","//r").Replace("/n","//n ");
/// 显示确认对话框
/// </summary>
/// <param name="msg"> 确认信息 </param>
/// <param name="distPath"> 当客户端点 ' 取消 ' 时转向的页面 </param>
/// <remarks> 当客户端点 ' 确认 ' 往下执行,当客户端点 ' 取消 ' 时转向另一个页面 </remarks>
public static void ConfirmDialog(string msg, string distPath)
{
msg = msg.Replace(" //","").Replace("/r","//r").Replace("/n","//n ");
System.Text.StringBuilder sb_tmp = new System.Text.StringBuilder();
sb_tmp.Append("<script language='javascript'>");
sb_tmp.Append("if(!confirm('"+msg+"')) window.location.href='"+distPath+"'");
sb_tmp.Append("</script>");
HttpContext.Current.Response.Write(sb_tmp.ToString());
}
sb_tmp.Append("<script language='javascript'>");
sb_tmp.Append("if(!confirm('"+msg+"')) window.location.href='"+distPath+"'");
sb_tmp.Append("</script>");
HttpContext.Current.Response.Write(sb_tmp.ToString());
}
/// /// <summary>
/// 从 WEB 页面文件下载
/// </summary>
/// <param name="strFile"> 要下载的文件的绝对路径 </param>
public static void DownloadFile(string strFile)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=/""+HttpUtility.UrlEncode(Path.GetFileName(strFile).Trim())+"/"");
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.WriteFile(strFile);
HttpContext.Current.Response.End();
}
/// <summary>
/// 关闭页面 .
/// </summary>
public static void CloseWindow()
{
HttpContext.Current.Response.Write("<script>window.close()</script>");
}
}
}
/// 从 WEB 页面文件下载
/// </summary>
/// <param name="strFile"> 要下载的文件的绝对路径 </param>
public static void DownloadFile(string strFile)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=/""+HttpUtility.UrlEncode(Path.GetFileName(strFile).Trim())+"/"");
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.WriteFile(strFile);
HttpContext.Current.Response.End();
}
/// <summary>
/// 关闭页面 .
/// </summary>
public static void CloseWindow()
{
HttpContext.Current.Response.Write("<script>window.close()</script>");
}
}
}