windows form 登录
2021/6/5 7:22:05
本文主要是介绍windows form 登录,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Data.SqlClient; 6 using System.Drawing; 7 using System.Linq; 8 using System.Text; 9 using System.Threading.Tasks; 10 using System.Windows.Forms; 11 12 namespace 物业管理登录页面 13 { 14 public partial class 登录页面 : Form 15 { 16 public 登录页面() 17 { 18 InitializeComponent(); 19 } 20 21 private void textBox2_TextChanged(object sender, EventArgs e) 22 { 23 this.textBox2.PasswordChar = '*'; 24 } 25 26 private void button1_Click(object sender, EventArgs e) 27 { 28 string sql = "server=.;database=Community system;Integrated Security=true;"; 29 SqlConnection conn = new SqlConnection(sql);//数据库连接 30 conn.Open();//打开数据库 31 string username = this.textBox1.Text; 32 string password = this.textBox2.Text; 33 if (username.Equals("") || password.Equals(""))//用户名或密码为空 34 { 35 MessageBox.Show("用户名或密码不能为空"); 36 } 37 else//用户名或密码不为空 38 { 39 //到数据库中验证 40 //string str = "Select * from userphone where usename='" + username + "' and pwd='" + password + "'"; 41 //在数据库中查看 42 //SqlCommand cmd = new SqlCommand(str, conn); 43 //cmd.CommandType = CommandType.Text; 44 //SqlDataReader sdr; 45 //sdr = cmd.ExecuteReader(); 46 if (radioButton1.Checked==true) 47 { 48 string str = "Select * from Adphone where Adname='" + username + "' and pwd='" + password + "'"; 49 SqlCommand cmd = new SqlCommand(str, conn); 50 cmd.CommandType = CommandType.Text; 51 SqlDataReader sdr; 52 sdr = cmd.ExecuteReader(); 53 if (sdr.Read()) 54 { 55 admin a = new admin(); 56 a.Show(); 57 } 58 else 59 { 60 MessageBox.Show("账号或密码不正确"); 61 } 62 } 63 if (radioButton2.Checked==true) 64 { 65 string str = "Select * from userphone where usename='" + username + "' and pwd='" + password + "'"; 66 SqlCommand cmd = new SqlCommand(str, conn); 67 cmd.CommandType = CommandType.Text; 68 SqlDataReader sdr; 69 sdr = cmd.ExecuteReader(); 70 if (sdr.Read()) 71 { 72 user u = new user(); 73 u.Show(); 74 } 75 else 76 { 77 MessageBox.Show("账号或密码不正确"); 78 } 79 } 80 /*if (sdr.Read()) 81 { 82 MessageBox.Show("登录成功"); 83 }*/ 84 85 } 86 } 87 88 private void button2_Click(object sender, EventArgs e) 89 { 90 register res = new register(); 91 res.Show(); 92 } 93 94 private void button3_Click(object sender, EventArgs e) 95 { 96 checkpwd check = new checkpwd(); 97 check.Show(); 98 } 99 } 100 }
这篇关于windows form 登录的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-10-01基于Python+Vue开发的医院门诊预约挂号系统
- 2024-10-01基于Python+Vue开发的旅游景区管理系统
- 2024-10-01RestfulAPI入门指南:打造简单易懂的API接口
- 2024-10-01初学者指南:了解和使用Server Action
- 2024-10-01Server Component入门指南:搭建与配置详解
- 2024-10-01React 中使用 useRequest 实现数据请求
- 2024-10-01使用 golang 将ETH账户的资产平均分散到其他账户
- 2024-10-01JWT用户校验课程:从入门到实践
- 2024-10-01Server Component课程入门指南
- 2024-09-30Dnd-Kit学习:新手快速入门指南