首页 > 其他分享 >上位机学习记录(3)编写用户登录模块

上位机学习记录(3)编写用户登录模块

时间:2023-03-16 17:44:15浏览次数:37  
标签:LoginName SysAdminService 登录 void FrmLogin 上位 模块 LoginPwd public

上位机学习记录(3)编写用户登录模块

(一)业务逻辑说明

FrmLogin界面的cmb_LoginName控件进行数据绑定,通过SysAdminService.GetAllAdminDB()获取到所有的用户信息

(二)界面初始化逻辑

登陆逻辑:

  1. Program.cs: 先调用FrmLogin界面,当FrmLogin完成登陆验证后返回ok,然后启动FrmMain主界面
  2. FrmLogin.cs:
    1. 将数据封装为Admin对象
    2. 传入SysAdminService方法
    3. 当SysAdminService查询,查询到返回对象;查询不到返回null
    4. FrmLogin检测Admin对象是否为null,当不为空,返回ok;为null,调用FrmConfirmSingle弹出错误对话框

登陆界面美化:

  1. 登陆页面使用无边框。
  2. 可以使用鼠标进行拖动

代码展示:

SysAdminService.cs

   public  class SysAdminService
    {
        /// <summary>
        /// 返回所有的用户对象
        /// </summary>
        /// <returns>用户对象集合</returns>
        public static List<SysAdmin> GetAllAdminDB()
        {
            return SqlSugarHelper.SqlSugarClient.Queryable<SysAdmin>().Where(c=>c.LoginName.ToLower()!="admin").ToList();      
        }

        /// <summary>
        /// 验证用户登录结果
        /// </summary>
        /// <param name="admin">用户对象</param>
        /// <returns>用户对象</returns>
        public static SysAdmin AdminLogin(SysAdmin admin)
        {
            var list= SqlSugarHelper.SqlSugarClient.Queryable<SysAdmin>().Where(c => c.LoginName==admin.LoginName&&c.LoginPwd==admin.LoginPwd).ToList();

            return list.Count == 0 ? null : list[0];
        }
     }

SqlSugarService.cs

    public class SqlSugarService
    {
        public static void SetConnectionString(string ConnectionString)
        {
            SqlSugarHelper.ConnectionString = ConnectionString;
        }

    }

SysAdmin.cs

   public class SysAdmin
    {
        public int LoginID { get; set; }

        public string LoginName { get; set; }

        public string LoginPwd { get; set; }

        public int Role { get; set; }

    }

FrmLogin.cs (LoginPwd使用了md5加密)

   public partial class FrmLogin : Form
    {
        public FrmLogin()
        {
            InitializeComponent();
        }

        private void FrmLogin_Load(object sender, EventArgs e)
        {
            this.cmb_LoginName.DataSource = SysAdminService.GetAllAdminDB();

            this.cmb_LoginName.DisplayMember = "LoginName";
        }

        private void btn_Login_Click(object sender, EventArgs e)
        {
            //验证

            if (this.txt_LoginPwd.Text.Trim().Length == 0)
            {
                new FrmConfirmSingle("登录提示", "请输入密码!") { TopMost = true }.ShowDialog();
                this.txt_LoginPwd.Focus();
                return;
            }

            //封装
            SysAdmin objAdmin = new SysAdmin()
            {
                LoginName = this.cmb_LoginName.Text,
                LoginPwd = AuthorizationHelper.Encrypt(this.txt_LoginPwd.Text.Trim())
            };

            objAdmin = SysAdminService.AdminLogin(objAdmin);

            if (objAdmin == null)
            {
                new FrmConfirmSingle("登录提示", "用户名或密码错误!") { TopMost = true }.ShowDialog();
            }
            else
            {
                CommonMethod.sysAdmin = objAdmin;

                this.DialogResult = DialogResult.OK;
            }

        }

        private void MainPanel_DoubleClick(object sender, EventArgs e)
        {
            this.Close();
        }


        Point mPoint;

        private void MainPanel_MouseDown(object sender, MouseEventArgs e)
        {
            mPoint = new Point(e.X, e.Y);
        }

        private void MainPanel_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                this.Location = new Point(this.Location.X + e.X - mPoint.X, this.Location.Y + e.Y - mPoint.Y);
            }
        }


        private void txt_LoginPwd_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                this.btn_Login_Click(null, null);
            }
        }
    }

标签:LoginName,SysAdminService,登录,void,FrmLogin,上位,模块,LoginPwd,public
From: https://www.cnblogs.com/LtWf/p/17223611.html

相关文章

  • 用户user退出登录
    /***用户退出登录*@paramrequest*@return*/@PostMapping("/loginout")publicR<String>loginout(HttpServletRequestrequest)......
  • python datetime模块常用功能
    时间的转换:时间戳转日期(datetime.date.fromtimestamp(1234567896)),返回日期年-月-日时间戳转年月日时分秒(datetime.datetime.fromtimestamp(123456789......
  • QtConcurrent 并发 模块使用
    原文链接我的代码example//startathread,executealgorithmQFuture<void>future=QtConcurrent::run(this,&Deployment::useAlgorithm,......
  • 爬虫 相关 requests模块介绍、requests发送get请求、requests携带参数、url编码解码、
    爬虫介绍爬虫是什么爬虫就是程序---》从互联网中,各个网站上,爬取数据[能浏览的页面才能爬],做数据清洗,入库爬虫的本质模拟方式http请求,获取数据---》入库......
  • github更新项目中的子模块
    若a项目已经引入了b项目作为子模块,可以使用以下步骤来同步更新b子模块:进入a项目的根目录,执行以下命令来切换到b子模块的目录:cdb执行以下命令,将b子模块更新到最新版本:git......
  • 谈谈项目中单点登录的实现原理?
    单点登录在现在的系统架构中广泛存在,它将多个子系统的认证体系打通,实现了一个入口多处使用,而在架构单点登录时,也会遇到一些小问题,在不同的应用环境中可以采用不同的单点登......
  • 0307-0314模块与包
    0307-03141.模块的简介#1.定义:一系列功能的集合#2.作用:拿来主义,极大提高开发效率#3.来源: 1.内置:#python解释器自带的,直接拿来使用的 2.第三方:#别人写的,如果想......
  • Oracle SQL Developer 提示无法安装某些模块错误
    如果博友遇到启动时弹出警告--无法安装某些模块(Warning-couldnotinstallsomemodules):之后是一大堆的包解决方法:把C:\Users\${你自己的用户名}\AppData\Roaming\S......
  • ChatGPT登录显示所在国家/地区不允许访问
    在浏览器地址栏输入avascript:window.localStorage.removeItem(Object.keys(window.localStorage).find(i=>i.startsWith('@@auth0spajs')))在上述代码的头部加上字......
  • android的google三方登录一直返回10
    标题:com.Google.android.gms.common.api.apiException:10:为何一直报错,这个问题的来源是可参考这里的状态码:googleStatusCodes配置其实都很简单,可参考:googleAndroid登录......