版权声明:转载原创文章请以超链接形式请注明原文章出处,尊重作者,尊重原创!
恰饭广告
数据库:
项目的数据模块图:
BLL层:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Login.DAL; using Login.Model; namespace Login.BLL { public class UserinfoBLL { UserInfoDAL userInfoDal = new UserInfoDAL(); public int Login(UserInfo user) { int count = userInfoDal.UserLogin(user); return count; } } }
DAL层:
using Login.Model; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data; using System.Data.SqlClient; using Login.DBHelper; namespace Login.DAL { public class UserInfoDAL { SQLHelper sqlHelp = new SQLHelper(); public int UserLogin(UserInfo user) { int i = Convert.ToInt32(sqlHelp.ExecuteScalar("select count(*) from T_login where username=@UserName and password=@PassWord", new SqlParameter("@UserName", user.userName), new SqlParameter("@PassWord", user.password))); return i; } } }
Model层(Entity类):
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Login.Model { public class UserInfo { public string userName { get; set; } public string password { get; set; } } }
UI层:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using Login.Model; using Login.BLL; namespace Login { public partial class Form1 : Form { public Form1() { InitializeComponent(); } UserInfo user = new UserInfo(); UserinfoBLL userBll = new UserinfoBLL(); private void button1_Click(object sender, EventArgs e) { user.userName = textBox1.Text.Trim(); user.password = textBox2.Text.Trim(); if (user.userName == "") { MessageBox.Show("请输入用户名!"); return; } if (user.password == "") { MessageBox.Show("请输入密码!"); return; } int count = userBll.Login(user); if (count>0) { MessageBox.Show("登录成功"); } else { MessageBox.Show("用户名密码错误"); } } } }
还有数据库访问类(SQLHelper.cs)代码太多就不贴出来了
GitHub源码下载:https://github.com/kiritobin/LoginThreeFram
原文链接:https://www.idaobin.com/archives/1074.html
让我恰个饭吧.ヘ( ̄ω ̄ヘ)
恰饭广告