C#实现简单学生信息管理系统
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990//构造方法public Login(){InitializeComponent();this.label3.Parent = this;this.label1.BackColor = Color.Transparent;this.label2.BackColor = Color.Transparent;this.label3.BackColor = Color.Transparent;this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;}//对登录按钮的事件实现代码private void button1_Click(object sender, EventArgs e){string ss = ConfigurationManager.ConnectionStrings["Stu"].ToString();SqlConnection conn = new SqlConnection(ss);try{//开启连接conn.Open();// MessageBox.Show("数据库连接成功!");}catch (Exception){//MessageBox.Show("数据库连接失败!");}String uname = txtName.Text.Trim();string pword = txtPass.Text.Trim();if(uname == ""|| pword == ""){MessageBox.Show("请输入用户名或密码!");return;}else{SqlCommand cmd = conn.CreateCommand();SqlDataAdapter adp = new SqlDataAdapter();string sql2 = "select * from account where name='"+ uname + " 'and pass='" + pword + " ' ";cmd.CommandText = sql2;adp.SelectCommand = cmd;DataSet dat = new DataSet();adp.Fill(dat, "account");if(dat.Tables["account"].Rows.Count == 0){MessageBox.Show("用户名或密码错误!");return;}else{Form1.isLogin = true;Form1.username = this.txtName.Text;this.Close();}cmd.Clone();}conn.Close();}//实现按ESC键关闭该窗口protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData){switch (keyData){case Keys.Escape:this.Close();//esc关闭窗体break;}return false;}//重置按钮清空文本框private void button2_Click(object sender, EventArgs e){txtName.Text = "";txtPass.Text = "";}//密码输入完成后实现敲击enter键触发登录按钮private void txtPass_KeyDown(object sender, KeyEventArgs e){if(e.KeyCode == Keys.Enter){this.button1_Click(sender, e);}}//实现按enter键使焦点转移到下一文本框,与tab键通用private void txtName_KeyPress(object sender, KeyPressEventArgs e){if (e.KeyChar == (char)Keys.Enter){SendKeys.Send("{tab}");}}