📄 logindbconn.cs
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -