C#三层架构登录系统的实现

C#三层架构登录系统的实现

DAL数据库SQLhelp类

namespace DAL
{
public class SQLHelper
{
private static string Constr = “Data Source=HAINUXG-B7CDF23;Initial Catalog=LOGIN;Integrated Security=True”;
public ArrayList ExecuteReArrList(string CommandText)
{
ArrayList arr =new ArrayList();
SqlConnection conn=new SqlConnection(Constr);
SqlCommand cmd=new SqlCommand(CommandText,conn);
conn.Open();
SqlDataReader reader=cmd.ExecuteReader();
while(reader.Read())
{
for(int i=0;i {
arr.Add(reader[i]);
}
}
conn.Close();
return arr;

    }
}

}

业务逻辑层
namespace BLL
{
public class LoginManager
{
DAL.SQLHelper sql = new DAL.SQLHelper();
public int UserLogin(int ID, string PWD)
{
ArrayList arr = new ArrayList();
String CommandText = “select count(LoginID) from Login where LoginID =”+ID+" and password =’"+PWD+"’";
arr = sql.ExecuteReArrList(CommandText);
if (arr[0].ToString().Equals(“0”))
{
return 0;
}
else
{
return 1;
}
}
}
}

实体层
namespace MODEL
{
public class UserInfo
{
public int UserID { get;set; }
public string Userpwd { get; set; }

}

}

表示层
namespace Login
{
public partial class login : Form
{
public login()
{
InitializeComponent();
}
MODEL.UserInfo user = new MODEL.UserInfo();
BLL.LoginManager bll = new BLL.LoginManager();

    private void btnLogin_Click(object sender, EventArgs e)
    {
       user.UserID = int.Parse(txtID.Text.Trim());
       user.Userpwd = txtpwd.Text.Trim();
       if (bll.UserLogin(user.UserID, user.Userpwd) > 0)
       {
           MessageBox.Show("登录成功");
       }
       else
       {
           MessageBox.Show("登录失败");
       }
    }
}

}
最后,希望能帮到有需要的人

你可能感兴趣的:(登录)