• C#编程登陆界面代码

    C#编程登陆界面代码 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.OleDb; namespace 人事管理系统 { public partial class FormLogin : Form { public FormLogin() { InitializeComponent(); } private void FormLogin_Load(object sender, EventArgs e) { } public void buttonLogin_Click_1(object sender, EventArgs e) { try { if (textBoxName .Text =="") { MessageBox.Show ("用户名不能为空!","提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Warning ); } else { if (textBoxPassword .Text =="") { MessageBox.Show("密码不能为空!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } else { String connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + "\\人事数据库.mdb"; OleDbConnection conn = new OleDbConnection(connStr); //String sql = "select count(*) from 用户密码表 where username='" + textBoxName.Text + "' and password='" + textBoxPassword.Text + "'"; conn.Open(); string sql = "select count(*) from 用户密码表 where username=@name and password=@pass"; OleDbCommand cmd = new OleDbCommand(sql ,conn ); cmd.Parameters.Add(new OleDbParameter ("@name",OleDbType .Char )); cmd.Parameters["@name"].Value = textBoxName.Text; cmd.Parameters.Add(new OleDbParameter("@pass", OleDbType.Char)); cmd.Parameters["@pass"].Value = textBoxPassword.Text; //OleDbDataAdapter da = new OleDbDataAdapter(sql, conn); //DataTable dt = new DataTable(); //da.Fill(dt); //int i = dt.Rows.Count; int i =(int )cmd.ExecuteScalar (); conn.Close(); if (i > 0) { FormMain fm = new FormMain(); fm.admintime = DateTime.Now.ToShortDateString(); fm.adminname = textBoxName.Text; fm.Show(); this.Hide (); } else { MessageBox.Show("用户名或密码错误!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Error ); { textBoxName.Text = ""; textBoxPassword.Text = ""; textBoxName.Focus(); } } } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } private void button1_Click(object sender, EventArgs e) { if (MessageBox.Show("您确定要退出本系统吗?", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK) { Application.Exit(); } } private void textBoxName_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) { textBoxPassword.Focus(); e.Handled = true; } } private void textBoxPassword_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) { buttonLogin.Focus(); e.Handled = true; } } private void linkLabeladd_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { Form添加 fpty = new Form添加(); fpty.Show(); } private void linkLabelpass_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { Formpasswordmodify fpmd = new Formpasswordmodify(); fpmd.Show(); } } }

    4
    372
    5KB
    2012-01-12
    40
上传资源赚积分or赚钱