使用三层异步登录时
Dal层中的上下文类(Model1)执行查询功能
public async Task<Student> GetStuByNameAndPwd(string name, string pwd)
{
var result = await Students.Where(s => s.SName == name && s.Pwd == pwd).FirstOrDefaultAsync();
return result;
}
BLL层使用DAL中的方法
public async Task<bool> DoLogin(string name, string pwd)
{
using (Model1 dbContext = new Model1())
{
Student stu = await dbContext.GetStuByNameAndPwd(name, pwd);
return stu != null ? true : false;
}
}
UI层获取输入信息
string name = textEdit1.EditValue.ToString().Trim();
string pwd = textEdit2.EditValue.ToString().Trim();
if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(pwd))
XtraMessageBox.Show("请完整输入");
//调用BLL层的方法执行登录
var isSuccess = await studentBLL.DoLogin(name, pwd);
if (isSuccess)
{
XtraMessageBox.Show("登录成功");
}
else
{
XtraMessageBox.Show("登录失败");
}