windows form 登录

2021-06-06 02:01

阅读:324

标签:ext   rms   vat   message   register   ted   ali   name   sel   

  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 登录

标签:ext   rms   vat   message   register   ted   ali   name   sel   

原文地址:https://www.cnblogs.com/dz-zs0706/p/14851294.html


评论


亲,登录后才可以留言!