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 }

 

相关文章

Windows2012R2备用域控搭建 前置操作 域控主域控的主dns:自...
主域控角色迁移和夺取(转载) 转载自:http://yupeizhi.blo...
Windows2012R2 NTP时间同步 Windows2012R2里没有了internet时...
Windows注册表操作基础代码 Windows下对注册表进行操作使用的...
黑客常用WinAPI函数整理之前的博客写了很多关于Windows编程的...
一个简单的Windows Socket可复用框架说起网络编程,无非是建...