Asp.net源码专业站
首页->影音娱乐->三层音乐网站源码>>Music.Common/ATools.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:三层音乐网站源码
当前文件:文件类型 ThreeLayerMusic/Music.Common/ATools.cs[13K,2009-6-12 11:57:32]打开代码结构图
普通视图
		            
1using System; 2using System.Web; 3using System.Collections.Generic; 4using System.Linq; 5using System.Text; 6using System.Drawing; 7using System.Drawing.Imaging; 8using System.IO; 9 10namespace Music.Common 11{ 12 /// <summary> 13 /// ATools工具操作类..如Session,Cookie... 14 /// </summary> 15 public class ATools 16 { 17 18 /// <summary> 19 /// 返回Session信息 20 /// </summary> 21 /// <param name="strName">Session名称</param> 22 /// <returns></returns> 23 public static string GetSession(string strName) 24 { 25 if (HttpContext.Current.Session[strName] == null) 26 { 27 return ""; 28 } 29 return HttpContext.Current.Session[strName].ToString(); 30 } 31 32 /// <summary> 33 /// 写Session信息 34 /// </summary> 35 /// <param name="strName">Session名称</param> 36 /// <param name="strValue"></param> 37 public static void WriteSession(string strName,string strValue) 38 { 39 if (strName != "" && strValue!="") 40 { 41 HttpContext.Current.Session[strName] = strValue; 42 } 43 } 44 45 /// <summary> 46 /// 写cookie值 47 /// </summary> 48 /// <param name="strName">名称</param> 49 /// <param name="strValue"></param> 50 public static void WriteCookie(string strName, string strValue) 51 { 52 HttpCookie cookie = HttpContext.Current.Request.Cookies[strName]; 53 if (cookie == null) 54 { 55 cookie = new HttpCookie(strName); 56 } 57 cookie.Value = strValue; 58 HttpContext.Current.Response.AppendCookie(cookie); 59 60 } 61 /// <summary> 62 /// 写cookie值 63 /// </summary> 64 /// <param name="strName">名称</param> 65 /// <param name="strValue"></param> 66 /// <param name="expires">过期时间(分钟)</param> 67 public static void WriteCookie(string strName, string strValue, int expires) 68 { 69 HttpCookie cookie = HttpContext.Current.Request.Cookies[strName]; 70 if (cookie == null) 71 { 72 cookie = new HttpCookie(strName); 73 } 74 cookie.Value = strValue; 75 cookie.Expires = DateTime.Now.AddMinutes(expires); 76 HttpContext.Current.Response.AppendCookie(cookie); 77 78 } 79 80 /// <summary> 81 /// 读cookie值 82 /// </summary> 83 /// <param name="strName">名称</param> 84 /// <returns>cookie值</returns> 85 public static string GetCookie(string strName) 86 { 87 if (HttpContext.Current.Request.Cookies != null && HttpContext.Current.Request.Cookies[strName] != null) 88 { 89 return HttpContext.Current.Request.Cookies[strName].Value.ToString(); 90 } 91 92 return ""; 93 } 94 95 96 97 public static string CreateCheckCodeString() 98 { 99 //定义验证码的字符数组 100 char[] allCharArray = { '0','1','2','3','4','5','6','7','8','9', 101 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O', 102 'P','Q','R','S','T','U','V','W','X','Y','Z'}; 103 104 //定义验证码字符串 105 string randomCode = ""; 106 Random rand = new Random(); 107 108 //生成6位验证码字符串 109 for (int i = 0; i < 6; i++) 110 randomCode += allCharArray[rand.Next(allCharArray.Length)]; 111 return randomCode; 112 } 113 114 /// <summary> 115 /// 生成验证码图片 116 /// </summary> 117 /// <param name="checkCode"></param> 118 public static void CreateCheckCodeImage() 119 { 120 string checkCode = CreateCheckCodeString(); 121 122 //定义图片宽度 123 int iWidth = 80; 124 //定义图片高度 125 int iHeight = 22; 126 //定义大小为12pt的 Arial字体,用于绘制文字 127 Font font = new Font("Arial", 12, FontStyle.Bold); 128 //定义黑色的单色画笔,用于绘制文字 129 SolidBrush brush = new SolidBrush(Color.Red); 130 //定义钢笔,用户绘制干扰线 131 Pen pen1 = new Pen(Color.SeaGreen, 0); //注意这里直接获得一个现有的Color对象 132 Pen pen2 = new Pen(Color.FromArgb(255, 255, 255), 0); //注意这里根据Argb值获得了一个Color对象 133 134 //创建一个px*20px的图象 135 Bitmap image = new Bitmap(iWidth, iHeight); 136 //从图象获得一个绘图面 137 Graphics g = Graphics.FromImage(image); 138 //清除整个绘图画面并以指定颜色填充 139 g.Clear(ColorTranslator.FromHtml("#FFFFFF")); //注意这里从html颜色代码获取Color对象 140 //定义文字的绘制矩形区域 141 RectangleF rect = new RectangleF(8, 3, iWidth, iHeight); 142 //定义一个随机对象,用于绘制干扰线 143 Random rand = new Random(); 144 //生成两条横向干扰线 145 for (int i = 0; i < 3; i++) 146 { 147 //定义起点 148 Point p1 = new Point(0, rand.Next(iHeight)); 149 //定义终点 150 Point p2 = new Point(iWidth, rand.Next(iHeight)); 151 //绘制直线 152 g.DrawLine(pen1, p1, p2); 153 } 154 155 //生成4条纵向干扰线 156 for (int i = 0; i < 5; i++) 157 { 158 //定义起点 159 Point p1 = new Point(rand.Next(iHeight), 0); 160 //定义终点 161 Point p2 = new Point(rand.Next(iHeight), iHeight); 162 //绘制直线 163 g.DrawLine(pen2, p1, p2); 164 } 165 166 //绘制验证码文字 167 g.DrawString(checkCode, font, brush, rect); 168 //保存图片为Jpeg格式 169 //ImageFormat.后面能更改保存图片的格式类型 170 MemoryStream ms = new MemoryStream(); 171 image.Save(ms, ImageFormat.Jpeg); 172 HttpContext.Current.Response.ClearContent(); 173 HttpContext.Current.Response.ContentType = "image/Jpeg"; 174 HttpContext.Current.Response.BinaryWrite(ms.ToArray()); 175 HttpContext.Current.Session["code"] = checkCode; 176 //释放对象 177 g.Dispose(); 178 image.Dispose(); 179 } 180 181 182 /// <summary> 183 /// 获得页码显示链接 184 /// </summary> 185 /// <param name="curPage">当前页数</param> 186 /// <param name="countPage">总页数</param> 187 /// <param name="url">超级链接地址</param> 188 /// <param name="extendPage">周边页码显示个数上限</param> 189 /// <returns>页码html</returns> 190 public static string GetPageNumbers(int curPage, int countPage, string url, int extendPage) 191 { 192 return GetPageNumbers(curPage, countPage, url, extendPage, "page"); 193 } 194 195 /// <summary> 196 /// 获得页码显示链接 197 /// </summary> 198 /// <param name="curPage">当前页数</param> 199 /// <param name="countPage">总页数</param> 200 /// <param name="url">超级链接地址</param> 201 /// <param name="extendPage">周边页码显示个数上限</param> 202 /// <param name="pagetag">页码标记</param> 203 /// <returns>页码html</returns> 204 public static string GetPageNumbers(int curPage, int countPage, string url, int extendPage, string pagetag) 205 { 206 //return GetPageNumbers(curPage, countPage, url, extendPage, pagetag, null); 207 if (pagetag == "") 208 pagetag = "page"; 209 int startPage = 1; 210 int endPage = 1; 211 212 if (url.IndexOf("?") > 0) 213 { 214 url = url + "&"; 215 } 216 else 217 { 218 url = url + "?"; 219 } 220 221 222 string t1 = "<a href=\"javascript:void(0);\" onclick=\"linkto('" + url + "&" + pagetag + "=1" + "')\">&laquo;</a>"; 223 string t2 = "<a href=\"javascript:void(0);\" onclick=\"linkto('" + url + "&" + pagetag + "=" + countPage + "')\">&raquo;</a>"; 224 225 if (countPage < 1) 226 countPage = 1; 227 if (extendPage < 3) 228 extendPage = 2; 229 230 if (countPage > extendPage) 231 { 232 if (curPage - (extendPage / 2) > 0) 233 { 234 if (curPage + (extendPage / 2) < countPage) 235 { 236 startPage = curPage - (extendPage / 2); 237 endPage = startPage + extendPage - 1; 238 } 239 else 240 { 241 endPage = countPage; 242 startPage = endPage - extendPage + 1; 243 t2 = ""; 244 } 245 } 246 else 247 { 248 endPage = extendPage; 249 t1 = ""; 250 } 251 } 252 else 253 { 254 startPage = 1; 255 endPage = countPage; 256 t1 = ""; 257 t2 = ""; 258 } 259 260 StringBuilder s = new StringBuilder(""); 261 262 s.Append(t1); 263 for (int i = startPage; i <= endPage; i++) 264 { 265 if (i == curPage) 266 { 267 s.Append("<span>"); 268 s.Append(i); 269 s.Append("</span>"); 270 } 271 else 272 { 273 s.Append("<a href=\"javascript:void(0);\" onclick=\"linkto('"); 274 s.Append(url); 275 s.Append(pagetag); 276 s.Append("="); 277 s.Append(i); 278 s.Append("')\">"); 279 s.Append(i); 280 s.Append("</a>"); 281 } 282 } 283 s.Append(t2); 284 285 return s.ToString(); 286 } 287 288 ///// <summary> 289 ///// 获得页码显示链接 290 ///// </summary> 291 ///// <param name="curPage">当前页数</param> 292 ///// <param name="countPage">总页数</param> 293 ///// <param name="url">超级链接地址</param> 294 ///// <param name="extendPage">周边页码显示个数上限</param> 295 ///// <param name="pagetag">页码标记</param> 296 ///// <param name="anchor">锚点</param> 297 ///// <returns>页码html</returns> 298 //public static string GetPageNumbers(int curPage, int countPage, string url, int extendPage, string pagetag, string anchor) 299 //{ 300 // if (pagetag == "") 301 // pagetag = "page"; 302 // int startPage = 1; 303 // int endPage = 1; 304 305 // if (url.IndexOf("?") > 0) 306 // { 307 // url = url + "&"; 308 // } 309 // else 310 // { 311 // url = url + "?"; 312 // } 313 314 // string t1 = "<a href=\"" + url + "&" + pagetag + "=1"; 315 // string t2 = "<a href=\"" + url + "&" + pagetag + "=" + countPage; 316 // if (anchor != null) 317 // { 318 // t1 += anchor; 319 // t2 += anchor; 320 // } 321 // t1 += "\">&laquo;</a>"; 322 // t2 += "\">&raquo;</a>"; 323 324 // if (countPage < 1) 325 // countPage = 1; 326 // if (extendPage < 3) 327 // extendPage = 2; 328 329 // if (countPage > extendPage) 330 // { 331 // if (curPage - (extendPage / 2) > 0) 332 // { 333 // if (curPage + (extendPage / 2) < countPage) 334 // { 335 // startPage = curPage - (extendPage / 2); 336 // endPage = startPage + extendPage - 1; 337 // } 338 // else 339 // { 340 // endPage = countPage; 341 // startPage = endPage - extendPage + 1; 342 // t2 = ""; 343 // } 344 // } 345 // else 346 // { 347 // endPage = extendPage; 348 // t1 = ""; 349 // } 350 // } 351 // else 352 // { 353 // startPage = 1; 354 // endPage = countPage; 355 // t1 = ""; 356 // t2 = ""; 357 // } 358 359 // StringBuilder s = new StringBuilder(""); 360 361 // s.Append(t1); 362 // for (int i = startPage; i <= endPage; i++) 363 // { 364 // if (i == curPage) 365 // { 366 // s.Append("<span>"); 367 // s.Append(i); 368 // s.Append("</span>"); 369 // } 370 // else 371 // { 372 // s.Append("<a href=\""); 373 // s.Append(url); 374 // s.Append(pagetag); 375 // s.Append("="); 376 // s.Append(i); 377 // if (anchor != null) 378 // { 379 // s.Append(anchor); 380 // } 381 // s.Append("\">"); 382 // s.Append(i); 383 // s.Append("</a>"); 384 // } 385 // } 386 // s.Append(t2); 387 388 // return s.ToString(); 389 //} 390 } 391} 392
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:三层音乐网站源码
51Aspx.com 版权所有 CopyRight © 2006-2010. 京ICP备06046876号 本站法律顾问:ITlaw-庄毅雄律师
返回顶部
客户服务:点击这里进行客户咨询 业务合作:点击这里洽谈业务合作 合作热线:010-68880146