C#三层架构修改密码和重置密码

版权声明:转载原创文章请以超链接形式请注明原文章出处,尊重作者,尊重原创!


恰饭广告




实现效果:

实现效果

数据库:

数据库结构

项目的数据模块图:

项目结构图

BLL层:

using FixPwd.DAL;
using FixPwd.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FixPwd.BLL
{
    public class UserInfoBLL
    {
        UserInfoDAL userInfoDal = new UserInfoDAL();
        public int Query(UserInfo user)
        {
            int count = userInfoDal.UserQuery(user);
            return count;
        }
        public void Fix(UserInfo user)
        {
            userInfoDal.PwdFix(user);
        }
        public bool ResetPwd(UserInfo user)
        {
            int count = userInfoDal.UserTel(user);
            if (count>0)
            {
                user.password = "666666";
                userInfoDal.PwdFix(user);
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}

DAL层:

using FixPwd.Model;
using FixPwd.DBHelper;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FixPwd.DAL
{
    public class UserInfoDAL
    {
        SQLHelper sqlHelp = new SQLHelper();
        public int UserQuery(UserInfo user)
        {
            int i = Convert.ToInt32(sqlHelp.ExecuteScalar("select count(*) from userinfo where UserName=@UserName and Pwd=@password",
                 new SqlParameter("@UserName", user.userName),
                  new SqlParameter("@password", user.password)));
            return i;
        }
        public void PwdFix(UserInfo user)
        {
            sqlHelp.ExecuteNonQuery(@"UPDATE userinfo SET Pwd=@password where UserName=@UserName",
                new SqlParameter("@UserName", user.userName),
                new SqlParameter("@password", user.password));
        }
        public int UserTel(UserInfo user)
        {
            int i = (int)sqlHelp.ExecuteScalar("select count(*) from userinfo where UserName=@UserName and Tel=@tel",
                 new SqlParameter("@UserName", user.userName),
                  new SqlParameter("@Tel", user.tel));
            return i;
        }
    }
}

Model层(Entity类):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FixPwd.Model
{
    public class UserInfo
    {
        public string userName { get; set; }
        public string password { get; set; }
        public string tel { get; set; }
    }
}

UI层:

using FixPwd.BLL;
using FixPwd.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 FixPwd
{
    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;
            }
            if (textBox3.Text == "")
            {
                MessageBox.Show("请输入修改密码!");
                return;
            }
            int count = userBll.Query(user);
            if (count > 0)
            {
                user.password = textBox3.Text.Trim();
                userBll.Fix(user);
                MessageBox.Show("修改成功");
            }
            else
            {
                MessageBox.Show("用户名或密码错误");
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            user.userName = textBox5.Text.Trim();
            user.tel = textBox6.Text.Trim();
            if (user.userName=="")
            {
                MessageBox.Show("请输入用户名!");
            }
            if (user.tel=="")
            {
                MessageBox.Show("请输入手机号!");
            }
            if (userBll.ResetPwd(user))
            {
                MessageBox.Show("重置成功");
            }
            else
            {
                MessageBox.Show("用户名或手机号错误");
            }
        }
    }
}

还有数据库访问类(SQLHelper.cs)代码太多就不贴出来了

GitHub源码下载:https://github.com/kiritobin/FixPwdThreeFram

原文链接:https://www.idaobin.com/archives/1080.html

让我恰个饭吧.ヘ( ̄ω ̄ヘ)

支付宝 ——————- 微信
图片加载中图片加载中



恰饭广告

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

8 ÷ = 4