C#机房重构—修改密码

开始


   登录窗体做完下一步就准备开始修改密码了,存了好长时间就是没有总结而已,修改密码相对登录来说也是比较简单的,重要的是流程图画完整,有思路,有目的就很轻松了。想干一件事之前还是需要思考下,就和盖房子一样,前期就是建筑图纸设计。后期就采购,施工,每一阶段都有一个完整的工作流程。

步入正题

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;

namespace UI.User
{
    public partial class ChangePassword : Form
    {
        public ChangePassword()
        {
            InitializeComponent();
        }

        private void ButOk_Click(object sender, EventArgs e)
        {
            if (txtOldPassword.Text == "" || txtNewPassword1.Text == "" || txtNewPassword2.Text == "")
            {
                MessageBox.Show("请将信息补充完整");
                return;
            }
            if (txtNewPassword1.Text != txtNewPassword2.Text)
            {
                MessageBox.Show("两次输入的密码不一致,请您重新填写");
                return;
            }
            if (txtOldPassword.Text != UI.Login.PassWord)
            {
                MessageBox.Show("旧密码输入不正确!");
                return;
            }

            Facade.ChangePassword changepassword = new Facade.ChangePassword();
            Entity.UserInfoEntity user = new Entity.UserInfoEntity();
            
            user.userID= UI.Login.CardNo;
            user.pwd = txtNewPassword1.Text;

            Boolean result = false;
            result = changepassword.SelectPassword(user);

            if (result != false)
            {
                MessageBox.Show("操作错误!", "提示");
            }
            else
            {
                MessageBox.Show("修改成功", "提示");
            }
        }
    }
}

外观层:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BLL;
using Entity;
namespace Facade
{
    public class ChangePassword
    {
        public Boolean SelectPassword( Entity.UserInfoEntity user)
        {
            bool flag;
            BLL.ChangePassword cp = new BLL.ChangePassword();

            flag = cp.ChangePasswordBLL(user);

            return flag;
        }
    }
}

实体层:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Entity
{
    public class UserInfoEntity
    {
            //定义用户ID字段
            public int userID { get; set; }
            //定义用户密码字段
            public string pwd { get; set; }
            //定义用户等级字段
            public string Level { get; set; }
        
    }
}

业务逻辑层:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BLL
{
    public class ChangePassword
    {
        public bool ChangePasswordBLL(Entity.UserInfoEntity user)
        {
            Factory.ChangePasswordFactory loginFactory = new Factory.ChangePasswordFactory(); //工厂实例化

            IDAL.IChangePasswordIDAL loginldal = loginFactory.UpdateUserInfo(); //调用工厂方法创建接口

            int table = loginldal.UpdateUserInfo(user);

            bool flag;
            //返回的DataTable类型,如果他的行数等于0,说明没有符合该账户密码的账户
            if (table > 0) //表中的行等于0
            {
                flag = false;
            }
            else
            {
                flag = true;
            }
            return flag;
        }
    }
}

工厂层:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.Reflection;

namespace Factory
{
    public class ChangePasswordFactory
    {
        string StrDB = ConfigurationManager.AppSettings["DB"];

        public IDAL.IChangePasswordIDAL UpdateUserInfo()
        {
            string ClassName = StrDB + "." + "ChangePasswordDAL";

            return (IDAL.IChangePasswordIDAL)Assembly.Load(StrDB).CreateInstance(ClassName);
        }
    }
}

数据访问层:

using Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    public class ChangePasswordDAL : IDAL.IChangePasswordIDAL
    {
        SQLHelper.SqlHelper sqlHelper = new SQLHelper.SqlHelper();
        public int UpdateUserInfo(UserInfoEntity User)
        {
            SqlParameter[] sqlparms = { new SqlParameter("@UserID", User.userID), new SqlParameter("@PWD", User.pwd) };

            string sql = @"UPDATE User_Info SET PWD=@PWD WHERE userID=@UserID";

            int Result = sqlHelper.ExecuteNonQuery(sql, sqlparms, CommandType.Text);

            return Result;
        }
    }
}

接口层:

using Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IDAL
{
    public interface IChangePasswordIDAL
    {
        int UpdateUserInfo(UserInfoEntity user);
    }
}

SQLHelper层和登录的一样。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值