WEB开发中常用的函数

using System;
using System.Web;
using System.IO;
namespace WebTool
{
 /// <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>
  /// 在客户端弹出一个全屏的新页面 .
  /// </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>
  /// 在客户弹出一个新的页面 .
  /// </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="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());
  }
  ///   /// <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>");
  }
  
 }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值