博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
简单版用户登录
阅读量:4314 次
发布时间:2019-06-06

本文共 3596 字,大约阅读时间需要 11 分钟。

简单实现:

1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Windows.Forms; 9 using System.Data.SqlClient;10 using System.Text.RegularExpressions;11 12 namespace 用户登录13 {14     public partial class Form1 : Form15     {16         public Form1()17         {18             InitializeComponent();19         }20         private void but1_Click(object sender, EventArgs e)21         {22             if (string.IsNullOrWhiteSpace(textb1.Text) ||23                 textb2.Text == "" ||24                 textb3.Text == "")25             {26                 MessageBox.Show("请输入正确的信息");27                 return;28             }29             if (textb2.Text.Trim() != textb3.Text.Trim())30             {31                 MessageBox.Show("两次密码输入不正确");32                 return;33             }34             string uid = textb1.Text.Trim();35             string pwd = textb2.Text.Trim();36             string sqlconn = @"server=.;database=MyDataBase;Integrated security=true";37             string sql = string.Format("insert into UseLogin(name,pwd) values('{0}','{1}');", uid, pwd);38             using (SqlConnection conn = new SqlConnection(sqlconn))39             {40                 using (SqlCommand cmd = new SqlCommand(sql, conn))41                 {42                     if (conn.State == ConnectionState.Closed)43                     {44                         conn.Open();45                     }46                     try47                     {48                         int res = cmd.ExecuteNonQuery();49                         textb1.Clear();50                         textb2.Text = string.Empty;51                         textb3.Text = "";52                         MessageBox.Show(string.Format("{0}行受影响", res));53                     }54                     catch (Exception ex)55                     {56                         MessageBox.Show(ex.Message);57                     }58                 }59             }60         }61         private void textb1_Leave(object sender, EventArgs e)62         {63             string sqlconn = @"server=.;database=MyDataBase;Integrated security=true";64             string sql = string.Format(@"select count(*) from uselogin where name='{0}'", textb1.Text.Trim());65             using (SqlConnection conn = new SqlConnection(sqlconn))66             {67                 using (SqlCommand cmd = new SqlCommand(sql, conn))68                 {69                     if (conn.State == ConnectionState.Closed)70                     {71                         conn.Open();72                     }73                     int set = Convert.ToInt32(cmd.ExecuteScalar());74                     if (Regex.IsMatch(textb1.Text.Trim(), @"^\w{0,10}$"))75                     {76                         if (set != 0)77                         {78                             label4.ForeColor = Color.Red;79                             label4.Text = "该用户名存在,请重新输入";80                         }81                         else82                         {83                             label4.ForeColor = Color.Blue;84                             label4.Text = "√";85                         }86                     }87                     else88                     {89                         label4.ForeColor = Color.Red;90                         label4.Text = "该用户长度,请重新输入";91                     }92                 }93             }94         }95     }96 }

转载于:https://www.cnblogs.com/yoosou/archive/2012/07/13/2588984.html

你可能感兴趣的文章
CentOs7安装rabbitmq
查看>>
(转))iOS App上架AppStore 会遇到的坑
查看>>
解决vmware与主机无法连通的问题
查看>>
做好产品
查看>>
项目管理经验
查看>>
笔记:Hadoop权威指南 第8章 MapReduce 的特性
查看>>
JMeter响应数据出现乱码的处理-三种解决方式
查看>>
获取设备实际宽度
查看>>
Notes on <High Performance MySQL> -- Ch3: Schema Optimization and Indexing
查看>>
Alpha冲刺(10/10)
查看>>
数组Array的API2
查看>>
为什么 Redis 重启后没有正确恢复之前的内存数据
查看>>
No qualifying bean of type available问题修复
查看>>
第四周助教心得体会
查看>>
spfile
查看>>
Team Foundation Service更新:改善了导航和项目状态速查功能
查看>>
WordPress资源站点推荐
查看>>
Python性能鸡汤
查看>>
android Manifest.xml选项
查看>>
Cookie/Session机制具体解释
查看>>