• 简单的登录


    一:数据库,表如下图,id自动增长:

    二:解决资源管理器的图

    三:登录的代码

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.SqlClient;
    
    namespace login1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            int errorTime = 0;
            private void button1_Click(object sender, EventArgs e)
            {
                
                if(tb_name.Text.Length<=0)
                {
                    MessageBox.Show("请输入用户名");
                    return;
                }
                if (tb_pwd.Text.Length <= 0)
                {
                    MessageBox.Show("请输入密码");
                    return;
                }
                if (errorTime >= 3)
                {
                    MessageBox.Show("用户已锁定");
                }
                else
                {
                    DataTable table = sqlhelper.datatable("select * from T_Users where UserName=@UserName",
                        new SqlParameter("@UserName", tb_name.Text));
    
    
    
                    if (table.Rows.Count < 1)
                    {
                        MessageBox.Show("用户名不存在");
                        errorTime += 1;
                        return;
                    }
                    if (table.Rows.Count > 1)
                    {
                        throw new Exception("用户名重复了");
                    }
                    else
                    {
                        DataRow row = table.Rows[0];
                        if ((string)row["Passwod"] != tb_pwd.Text)
                        {
                            MessageBox.Show("密码错误");
                            errorTime += 1;
                            sqlhelper.ExecuteNon("update T_Users set ErrorTimes=@ErrorTimes",
                                new SqlParameter("@ErrorTimes", errorTime));
                            return;
                        }
                        else
                        {
                            if (errorTime >= 3)
                                MessageBox.Show("用户已锁定");
                            else
                                MessageBox.Show("登录成功");
                        }
                    }
    
                }
    
    
    
            }
        }
    }

    四:登录的简单流程

    五:总结,本次中有太多的if嵌套,如果没有流程图,读起来会比较麻烦,还需要改进

  • 相关阅读:
    如何彻底卸载Oracle11g
    Oracle 11g的安装
    python 循环队列的实现
    numpy模块学习笔记
    Python 进程之间共享数据
    python异步加协程获取比特币市场信息
    MySQL中, 如何查询某一天, 某一月, 某一年的数据.
    js获取时间
    nodejs爬虫笔记(五)---利用nightmare模拟点击下一页
    nodejs爬虫笔记(四)---利用nightmare解决加载更多问题
  • 原文地址:https://www.cnblogs.com/hongmaju/p/3611098.html
Copyright © 2020-2023  润新知