版权声明:转载原创文章请以超链接形式请注明原文章出处,尊重作者,尊重原创!
恰饭广告
数据库:
项目的数据模块图:
BLL层:
using Register.DAL; using Register.Model; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Register.BLL { public class UserInfoBLL { UserInfoDAL userInfoDal = new UserInfoDAL(); public int Login(UserInfo user) { int count = userInfoDal.UserLogin(user); return count; } public void Insert(UserInfo user) { userInfoDal.Insert(user); } } }
DAL层:
using Register.DBHelper; using Register.Model; using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Register.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", new SqlParameter("@UserName", user.userName))); return i; } public void Insert(UserInfo user) { sqlHelp.ExecuteNonQuery(@"INSERT INTO T_login (UserName,PassWord) VALUES (@UserName,@password)", new SqlParameter("@UserName", user.userName), new SqlParameter("@password", user.password)); } } }
Model层(Entity类):
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Register.Model { public class UserInfo { public string userName { get; set; } public string password { get; set; } } }
UI层:
using Register.BLL; using Register.Model; 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; namespace Register { public partial class Form1 : Form { public Form1() { InitializeComponent(); } UserInfo user = new UserInfo(); UserInfoBLL userBll = new UserInfoBLL(); public bool Insert { get; set; } 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 { if (Insert == false) { userBll.Insert(user); MessageBox.Show("注册成功!"); } else { MessageBox.Show("注册失败"); } } } } }
还有数据库访问类(SQLHelper.cs)代码太多就不贴出来了
GitHub源码下载:https://github.com/kiritobin/RegThreeFram
原文链接:https://www.idaobin.com/archives/1077.html
让我恰个饭吧.ヘ( ̄ω ̄ヘ)
恰饭广告