⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logic.cs

📁 报错请联系wangyuhan@staff.chinabyte.com qq:17540808
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
//该源码下载自www.51aspx.com(51aspx.com)

using xmlOp;    //引用XmlOp类的命名空间

/// <summary>
/// Logic 的摘要说明
/// </summary>
public class Logic
{
    /// <summary>
    /// 构造函数
    /// </summary>
    public Logic()
    { }

    //读取配置文件的Xml文件路径
    string xmlFile=System.Configuration.ConfigurationManager.AppSettings["xmlFile"];

    /// <summary>
    /// 超级管理员登陆身份验证,登陆成功后把用户信息写入Session
    /// </summary>
    /// <param name="admin">账号</param>
    /// <param name="pwd">密码</param>
    /// <returns></returns>
    public bool SuperAdmin(string admin, string pwd)
    {
        //利用Web.Security类下的验证方法验证身份
        if (System.Web.Security.FormsAuthentication.Authenticate(admin, pwd))
        {
            HttpContext.Current.Session["SuperAdmin"] = "yes";  //超级管理员
            HttpContext.Current.Session["NormalAdmin"] = "yes"; //一般管理员
            return true;
        }
        else
        {
            return false;
        }
    }

    /// <summary>
    /// 同学录成员登陆验证,验证成功后把信息写入Cookie
    /// </summary>
    /// <param name="userName">姓名</param>
    /// <param name="userPwd">密码</param>
    /// <returns></returns>
    public bool UserLogin(string userName, string userPwd, int cookieDay)
    {
        XmlOp op = new XmlOp(xmlFile);
        if (op.SelectNode("//Root/Student", 0, userName) && op.SelectNode("//Root/Student", 2, userPwd))
        {
            HttpCookie cookie = new HttpCookie("userInfo"); //创建Cookie对象
            cookie["userName"] = userName;
            cookie["userPwd"] = userPwd;
            cookie.Expires = DateTime.Now.AddDays(cookieDay);
            HttpContext.Current.Response.Cookies.Add(cookie);   //写入Cookie值
            return true;
        }
        else
        {
            return false;
        }
    }

    /// <summary>
    /// 弹出对话框
    /// </summary>
    /// <param name="msg">对话框消息</param>
    public void Msg(string msg)
    {
        Page pg = (Page)HttpContext.Current.Handler;
        string script = "alert('" + msg + "');";
        //调用Page.ClientScript.RegisterStartupScript方法
        pg.ClientScript.RegisterStartupScript(pg.GetType(), Guid.NewGuid().ToString(), script, true);
    }

    /// <summary>
    /// 删除图片
    /// </summary>
    /// <param name="fileName">图片虚拟路径</param>
    public void DeleteFile(string fileName)
    {
        if (System.IO.File.Exists(HttpContext.Current.Server.MapPath(fileName)))
        {
            try
            {
                System.IO.File.Delete(HttpContext.Current.Server.MapPath(fileName));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -