logindbconn.cs

来自「酒店管理系统」· CS 代码 · 共 64 行

CS
64
字号
using System;
using System.Data;
using System.Data.SqlClient;
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;

/// <summary>
/// LoginDBConn 的摘要说明
/// </summary>
public class LoginDBConn : DBConn
{
    private string sql = null;
    private SqlCommand comm = null;
    private SqlDataReader reader = null;
	public LoginDBConn()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}

    /// <summary>
    /// check if the user name and password is valid and return the role of the user if correct.
    /// </summary>
    /// <param name="id"></param>
    /// <param name="pw"></param>
    /// <returns>
    ///     0  means employee
    ///     1  means manager
    ///     -1 means wrong password
    /// </returns>
    public int getAuthority(string id, string pw){
        this.Open();
        sql = "SELECT [Password] FROM [User] WHERE [ID] = '" + id + "'";
        comm = new SqlCommand(sql, conn);
        reader = comm.ExecuteReader();
        string password = "";
        int authority = -1;
        while (reader.Read())
        {
            password = reader.GetString(0);
        }
        reader.Close();
        if (password.Equals(pw))
        {
            sql = "SELECT [authority] FROM [User] WHERE [ID] = '" + id + "'";
            comm = new SqlCommand(sql, conn);
            reader = comm.ExecuteReader();
            while (reader.Read())
            {
                authority = reader.GetInt32(0);
            }
        }
        reader.Close();
        this.Close();
        return authority;
    }
}

⌨️ 快捷键说明

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