1,登录界面的设计
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.Threading.Tasks; 9 using System.Windows.Forms; 10 using System.Data.SqlClient; 11 using System.Reflection; 12 13 14 namespace WindowsFormsApplication2 15 { 16 public partial class Form0 : Form 17 { 18 public Form0() 19 { 20 InitializeComponent(); 21 } 22 23 //SqlConnection conn = new SqlConnection("server=.;database=wisystem;integrated security=true;"); 24 25 /*窗体间的传值*/ 26 public static string username = string.Empty; 27 28 private void button1_Click(object sender, EventArgs e) //login 29 { 30 if (ID.Text == "" || Passwd.Text == "" || ID.TextLength < 5 ) 31 { 32 MessageBox.Show("请输入完整的信息", "信息提示", 33 System.Windows.Forms.MessageBoxButtons.OK, 34 System.Windows.Forms.MessageBoxIcon.Warning); 35 ID.Text = "输入账号"; 36 Passwd.Text = "请输入密码"; 37 } 38 else if (ID.Text != "" && Passwd.Text != "") 39 { 40 string connection = "Data Source=.;integrated security = SSPI;Initial Catalog=wisystem;"; 41 SqlConnection con = new SqlConnection(connection); 42 con.Open(); 43 string strsql = "select ID,Passwd from user$ where ID='" + ID.Text.ToString().Trim() 44 + "' and Passwd='" + Passwd.Text.ToString().Trim() + "'"; 45 DataSet ds = new DataSet(); 46 SqlDataAdapter da = new SqlDataAdapter(strsql, con); 47 da.Fill(ds); 48 string c = this.Identify.SelectedIndex.ToString (); 49 50 if (ds.Tables[0].Rows.Count > 0 && (ID.Text.ToString() == "admin") && Convert.ToInt32(Identify.SelectedIndex.ToString()) == 0) 51 { 52 53 MessageBox.Show("登录成功", "提示"); 54 Form1 form1 = new Form1(); 55 form1.Show(); 56 this.Hide(); 57 } 58 else 59 if(ds.Tables[0].Rows.Count > 0 && (ID.Text.ToString() == "admin") && Convert.ToInt32(Identify.SelectedIndex.ToString()) == 1) 60 { 61 MessageBox.Show("身份验证错误,已更改身份", "提示信息", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Warning); 62 Identify.SelectedIndex = 0; 63 } 64 else 65 if (ds.Tables[0].Rows.Count > 0 && (Passwd.Text.ToString() == "123456") && Convert.ToInt32(Identify.SelectedIndex.ToString()) == 1) 66 { 67 MessageBox.Show("登录成功", "提示"); 68 username = ID.Text; 69 Form4 form4 = new Form4(); 70 form4.Show(); 71 this.Hide(); 72 } 73 else 74 if (ds.Tables[0].Rows.Count > 0 && (Passwd.Text.ToString() == "123456") && Convert.ToInt32(Identify.SelectedIndex.ToString()) == 0) 75 { 76 MessageBox.Show("身份验证错误,已更改身份", "提示信息",System .Windows .Forms .MessageBoxButtons .OK, System.Windows.Forms.MessageBoxIcon.Warning); 77 Identify.SelectedIndex = 1; 78 } 79 else 80 { 81 MessageBox.Show("用户名或密码输入错误!"); 82 } 83 con.Close(); 84 } 85 } 86 87 private void Form0_Load(object sender, EventArgs e) 88 { 89 Identify.SelectedIndex = 1; 90 ID.Text = "输入账号"; 91 Passwd.Text = "请输入密码"; 92 timer1.Enabled = true; 93 } 94 95 private void ID_MouseClick(object sender, MouseEventArgs e) 96 { 97 ID.Text = ""; 98 Passwd.Text = ""; 99 } 100 101 private void Passwd_KeyDown(object sender, KeyEventArgs e) 102 { 103 Passwd.PasswordChar = '*'; 104 } 105 106 private void timer1_Tick(object sender, EventArgs e) 107 { 108 this.label4.Left -= 2; 109 if (label4.Right < 0) 110 { 111 this.label4.Left = 900; 112 } 113 114 } 115 116 private void timer2_Tick(object sender, EventArgs e) 117 { 118 this.textBox1.Text = DateTime.Now.ToString(); 119 } 120 121 } 122 }