ÎÂܰÌáʾ£º´úÂëÔÚÏßä¯ÀÀ¹¦ÄÜÖ»ÄÜ×öΪԴÂëä¯ÀÀ²Î¿¼£¬²»ÄÜչʾÏîÄ¿µÄÈ«²¿£¬Èç¹ûÏë¸ü½øÒ»²½Á˽â¸Ã´úÂëÇëÏÂÔØ£ºXMLͬѧ¼ϵͳԴÂ루±ÏÒµÉè¼Æ£©
µ±Ç°Îļþ·¾¶£ºXMLClassBooks/App_Code/Logic.cs

1using System; 2
using System.Data; 3
using System.Configuration; 4
using System.Web; 5
using System.Web.Security; 6
using System.Web.UI; 7
using System.Web.UI.WebControls; 8
using System.Web.UI.WebControls.WebParts; 9
using System.Web.UI.HtmlControls; 10
//¸ÃÔ´ÂëÏÂÔØ×Ôwww.51aspx.com(£µ£±£á£óp£ø£®£ã£ï£í) 11
12
using xmlOp; //ÒýÓÃXmlOpÀàµÄÃüÃû¿Õ¼ä 13
14
/// <summary> 15
/// Logic µÄժҪ˵Ã÷ 16
/// </summary> 17
public class Logic 18
{ 19
/// <summary> 20
/// ¹¹Ô캯Êý 21
/// </summary> 22
public Logic() 23
{ } 24
25
//¶ÁÈ¡ÅäÖÃÎļþµÄXmlÎļþ·¾¶ 26
string xmlFile=System.Configuration.ConfigurationManager.AppSettings["xmlFile"]; 27
28
/// <summary> 29
/// ³¬¼¶¹ÜÀíÔ±µÇ½Éí·ÝÑéÖ¤£¬µÇ½³É¹¦ºó°ÑÓû§ÐÅϢдÈëSession 30
/// </summary> 31
/// <param name="admin">Õ˺Å</param> 32
/// <param name="pwd">ÃÜÂë</param> 33
/// <returns></returns> 34
public bool SuperAdmin(string admin, string pwd) 35
{ 36
//ÀûÓÃWeb.SecurityÀàϵÄÑéÖ¤·½·¨ÑéÖ¤Éí·Ý 37
if (System.Web.Security.FormsAuthentication.Authenticate(admin, pwd)) 38
{ 39
HttpContext.Current.Session["SuperAdmin"] = "yes"; //³¬¼¶¹ÜÀíÔ± 40
HttpContext.Current.Session["NormalAdmin"] = "yes"; //Ò»°ã¹ÜÀíÔ± 41
return true; 42
} 43
else 44
{ 45
return false; 46
} 47
} 48
49
/// <summary> 50
/// ͬѧ¼³ÉÔ±µÇ½ÑéÖ¤£¬ÑéÖ¤³É¹¦ºó°ÑÐÅϢдÈëCookie 51
/// </summary> 52
/// <param name="userName">ÐÕÃû</param> 53
/// <param name="userPwd">ÃÜÂë</param> 54
/// <returns></returns> 55
public bool UserLogin(string userName, string userPwd, int cookieDay) 56
{ 57
XmlOp op = new XmlOp(xmlFile); 58
if (op.SelectNode("//Root/Student", 0, userName) && op.SelectNode("//Root/Student", 2, userPwd)) 59
{ 60
HttpCookie cookie = new HttpCookie("userInfo"); //´´½¨Cookie¶ÔÏó 61
cookie["userName"] = userName; 62
cookie["userPwd"] = userPwd; 63
cookie.Expires = DateTime.Now.AddDays(cookieDay); 64
HttpContext.Current.Response.Cookies.Add(cookie); //дÈëCookieÖµ 65
return true; 66
} 67
else 68
{ 69
return false; 70
} 71
} 72
73
/// <summary> 74
/// µ¯³ö¶Ô»°¿ò 75
/// </summary> 76
/// <param name="msg">¶Ô»°¿òÏûÏ¢</param> 77
public void Msg(string msg) 78
{ 79
Page pg = (Page)HttpContext.Current.Handler; 80
string script = "alert('" + msg + "');"; 81
//µ÷ÓÃPage.ClientScript.RegisterStartupScript·½·¨ 82
pg.ClientScript.RegisterStartupScript(pg.GetType(), Guid.NewGuid().ToString(), script, true); 83
} 84
85
/// <summary> 86
/// ɾ³ýͼƬ 87
/// </summary> 88
/// <param name="fileName">ͼƬÐéÄâ·¾¶</param> 89
public void DeleteFile(string fileName) 90
{ 91
if (System.IO.File.Exists(HttpContext.Current.Server.MapPath(fileName))) 92
{ 93
try 94
{ 95
System.IO.File.Delete(HttpContext.Current.Server.MapPath(fileName)); 96
} 97
catch (Exception ex) 98
{ 99
throw ex; 100
} 101
} 102
} 103
} 104







