using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace CitySunlight { /// /// 网页数据管理类 /// public static class HttpUtils { /// /// 通过标签名获取数据 /// /// 标签名称 /// 标签数据 public static String getElementsbyName(String tagName) { if (HttpContext.Current.Request.Form[tagName] != null) return HttpContext.Current.Request.Form[tagName].ToString().Trim().Replace("'", ""); else return null; } /// /// 查询Get标签数据 /// /// Get标签 /// 标签数据 public static String getQueryString(String tagName) { if (HttpContext.Current.Request.QueryString[tagName] != null) return HttpContext.Current.Request.QueryString[tagName]; else return null; } /// /// 通过标签获取文件数据 /// /// 文件标签 /// 文件数据 public static HttpPostedFile getFilebyName(String tagName) { HttpPostedFile file = HttpContext.Current.Request.Files[tagName]; if (file != null && file.ContentLength > 0) return file; else return null; } /// /// 获得1970年1月1日到现在的秒数 /// /// 1970年1月1日到现在的秒数 public static long currentTimeMillis() { return (long)((DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds); } /// /// 添加Td /// /// Td的html代码 public static String addTd() { return ""; } public static String addThs(params String[] head) { String ths = ""; foreach (String th in head) { ths += "" + th + ""; } return String.Format("{0}", ths); } public static String addTds(params String[] head) { String ths = ""; foreach (String th in head) { ths += "" + th + ""; } return String.Format("{0}", ths); } /// /// 添加Td(带内容) /// /// 内容 /// Td带内容的Html代码 public static String addTd(String s) { return String.Format("{0}", s); } /// /// 可配置大小的Td标签 /// /// 内容 /// 宽 /// 高 /// public static String addTd(String s, int col, int row) { String td = "{0}", s); } /// /// String尝试转换为Int(扩展方法) /// /// /// public static int ToInt(this string s) { int i; if (!int.TryParse(s, out i)) { i = 0; } return i; } /// /// String尝试转换为decimal(扩展方法) /// /// /// public static decimal Todecimal(this string s) { decimal i; if (!decimal.TryParse(s, out i)) { i = 0; } return i; } /// /// String尝试转换为double(扩展方法) /// /// /// public static double Todouble(this string s) { double i; if (!double.TryParse(s, out i)) { i = 0; } return i; } } }