目录
项目开发用的是Microsoft Visual Studio 2010语言是C#连接Access数据库,第一次做代码有些不简洁希望各位大佬理解
一、界面设计
登录界面
注册界面
借还界面
图书管理界面
二、代码部分
1.登录模块: 为了判断用户和管理员身份代码有重复部分,看起来有点复杂
private void button1_Click(object sender, EventArgs e)
{
string oleCon = "provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:DataBase Password='';User Id='admin';Data source=|DataDirectory|Database2.mdb";
OleDbConnection conn = new OleDbConnection(oleCon);
conn.Open();
string judna = "select `userna` from `user_table` where `userna`='" + this.textBox1.Text + "'";
OleDbCommand cmd = new OleDbCommand(judna, conn);
OleDbDataReader read = cmd.ExecuteReader();
if (read.Read() == true)
{
read.Close();
if (this.radioButton1.Checked == true)//用户登录界面
{
string judid = "select `userna`,`uid` from `user_table` where `userna`='"+this.textBox1.Text +"' and `uid`='"+this.radioButton1.Text+"'";
OleDbCommand cmd1 = new OleDbCommand(judid, conn);
OleDbDataReader readid = cmd1.ExecuteReader();
if (readid.Read() == true)
{
string judpa = "select `userna`,`userpa` from `user_table` where `userna`='"+this.textBox1.Text+"' and `userpa`='" + this.textBox2.Text + "'";
OleDbCommand cmd2 = new OleDbCommand(judpa, conn);
OleDbDataReader read1 = cmd2.ExecuteReader();
if (read1.Read() == true)
{
string sname = "select `uname`,`uid` from `user_table` where `userna`='" + this.textBox1.Text + "' ";
OleDbCommand cmd5 = new OleDbCommand(sname, conn);
Class1.username = Convert.ToString(cmd5.ExecuteScalar().ToString());
Class1.useracc = Convert.ToString(this.textBox1.Text);
Form f1 = new Form1();
this.Hide();
f1.ShowDialog();
}
else
{
MessageBox.Show("密码错误,请重新输入");
this.textBox2.Focus();
}
}
else
{
MessageBox.Show("身份错误");
}
}
else {
string judid1 = "select `userna`,`uid` from `user_table` where `userna`='" + this.textBox1.Text + "' and `uid`='" + this.radioButton2.Text + "'";
OleDbCommand cmd3 = new OleDbCommand(judid1, conn);
OleDbDataReader readid1 = cmd3.ExecuteReader();
if (readid1.Read() == true)
{
string judpa1 = "select `userna`,`userpa` from `user_table` where `userna`='" + this.textBox1.Text + "' and `userpa`='" + this.textBox2.Text + "'";
OleDbCommand c