图书管理系统源码c版.docx
《图书管理系统源码c版.docx》由会员分享,可在线阅读,更多相关《图书管理系统源码c版.docx(56页珍藏版)》请在冰豆网上搜索。
![图书管理系统源码c版.docx](https://file1.bdocx.com/fileroot1/2023-7/15/12077ef1-712c-43e2-9729-57c3e3392874/12077ef1-712c-43e2-9729-57c3e33928741.gif)
图书管理系统源码c版
登录界面:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
usingSystem.Windows.Forms;
usingSystem.Data.SqlClient;
namespacebook
{
publicpartialclasslogin:
Form
{
publicstringpassword;//用来存储密码
publiclogin()
{
InitializeComponent();
}
privatevoidbutton2_Click(objectsender,EventArgse)
{
Application.Exit();
}
privateboolyanzhengshuru()
{
password=textBox3.Text;
if(Typename.Text.Trim()=="")
{
MessageBox.Show("请选择登录类型","登录提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
Typename.Focus();
returnfalse;
}
elseif(loginid.Text.Trim()=="")
{
MessageBox.Show("请输入用户名","登录提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
loginid.Focus();
returnfalse;
}
elseif(password=="")
{
MessageBox.Show("请输入密码","登录提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
textBox3.Focus();
returnfalse;
}
else
{
returntrue;
}
}
privatevoidbutton1_Click(objectsender,EventArgse)
{
userhelper.adminid=loginid.Text;//用户账号
password=textBox3.Text;//用户密码
if(yanzhengshuru())
{
if(Typename.Text.Trim()=="管理员")
{
stringsql=string.Format("Selectcount(*)fromadminwhereadminId='{0}'andadminpass='{1}'",loginid.Text,password);
try
{
SqlCommandcommand=newSqlCommand(sql,Dbhelper.connection);
Dbhelper.connection.Open();
intcount=(int)command.ExecuteScalar();
if(count<1)
{
MessageBox.Show("用户或密码不存在!
");
//result=false;
}
else
{
adminadmin=newadmin();
admin.Show();
}
}
catch(Exceptionex)
{
MessageBox.Show("操作数据库出错!
");
Console.WriteLine(ex.Message);
}
finally
{
Dbhelper.connection.Close();
}
}
if(Typename.Text.Trim()=="借阅者")
{
userhelper.readerid=Convert.ToString(loginid.Text);
stringsql=string.Format("Selectcount(*)fromreaderwherereaderId='{0}'andreaderpass='{1}'",userhelper.readerid,textBox3.Text);
try
{
//创建Command对象
SqlCommandcommand=newSqlCommand(sql,Dbhelper.connection);
//打开数据库连接
Dbhelper.connection.Open();
//验证是否为合法用户
intcount=(int)command.ExecuteScalar();
if(count<1)
{
MessageBox.Show("用户或密码不存在!
");
//result=false;
}
else
{
readerreader=newreader();
reader.Show();
}
}
catch(Exceptionex)
{
MessageBox.Show("操作数据库出错!
");
Console.WriteLine(ex.Message);
//result=false;
}
finally
{
//关闭数据库连接
Dbhelper.connection.Close();
}
}
}
}
privatevoidlogin_Load(objectsender,EventArgse)
{
}
}
}读者界面;
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
usingSystem.Windows.Forms;
usingSystem.Data.Sql;
usingSystem.Data.SqlClient;
namespacebook
{
publicpartialclassreader:
Form
{
publicreader()
{
InitializeComponent();
}
privatevoidbutton3_Click(objectsender,EventArgse)
{
stringid=Convert.ToString(textBox1.Text);
if(id!
=userhelper.readerid)
{
MessageBox.Show("输入账号与登陆账号不相同,请重新输入","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
textBox1.Text="";
textBox1.Focus();
}
else
try
{
stringsql=string.Format("updatereadersetislost='{0}'wherereaderid='{1}'",'是',id);
Dbhelper.connection.Open();
SqlCommandcommand=newSqlCommand(sql,Dbhelper.connection);
intresult=command.ExecuteNonQuery();
if(result<1)
{
MessageBox.Show("修改失败");
}
elseMessageBox.Show("挂失成功");
}
catch
{
MessageBox.Show("error");
}
finally
{
Dbhelper.connection.Close();
}
}
privatevoidtoolStripButton3_Click(objectsender,EventArgse)
{
groupBox1.Visible=false;
groupBox2.Visible=true;
}
privatevoidtoolStripButton4_Click(objectsender,EventArgse)
{
groupBox1.Visible=true;
groupBox2.Visible=false;
}
privatevoidbutton5_Click(objectsender,EventArgse)
{
textBox2.Text="";
textBox4.Text="";
textBox5.Text="";
}
privatevoidForm1_Load(objectsender,EventArgse)
{
toolStrip1.Text=string.Format("学生:
{0}",userhelper.readerid);
}
privatevoidbutton4_Click(objectsender,EventArgse)
{
stringid=Convert.ToString(textBox2.Text);
if(id!
=userhelper.readerid)
{
MessageBox.Show("输入账号与登陆账号不相同,请重新输入","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
textBox1.Text="";
textBox1.Focus();
}
elseif(textBox4.Text!
=textBox5.Text)
{
MessageBox.Show("两次密码输入不同");
}
elsetry
{
stringsql=string.Format("updatereadersetreaderpass='{0}'wherereaderid='{1}'",textBox4.Text,id);
Dbhelper.connection.Open();
SqlCommandcommand=newSqlCommand(sql,Dbhelper.connection);
intresult=command.ExecuteNonQuery();
if(result<1)
{
MessageBox.Show("修改失败");
}
elseMessageBox.Show("修改成功");
}
catch
{
MessageBox.Show("error");
}
finally
{
Dbhelper.connection.Close();
}
}
privatevoidtoolStripButton6_Click(objectsender,EventArgse)
{
addreaderaddreader=newaddreader();
addreader=newaddreader();
}
privatevoidtoolStripButton1_Click(objectsender,EventArgse)
{
readsearchbooksearchbook=newreadsearchbook();
searchbook.Show();
}
privatevoidtoolStripButton2_Click(objectsender,EventArgse)
{
borrowa=newborrow();
a.Show();
}
privatevoidtoolStripButton5_Click(objectsender,EventArgse)
{
readerseacherinfoa=newreaderseacherinfo();
a.Show();
}
privatevoid图书查询ToolStripMenuItem1_Click(objectsender,EventArgse)
{
readsearchbooka=newreadsearchbook();
a.Show();
this.Close();
}
privatevoid结束查询ToolStripMenuItem_Click(objectsender,EventArgse)
{
borrowa=newborrow();
a.Show();
this.Close();
}
privatevoid修改密码ToolStripMenuItem_Click(objectsender,EventArgse)
{
groupBox1.Visible=false;
groupBox2.Visible=true;
}
privatevoid挂失ToolStripMenuItem_Click(objectsender,EventArgse)
{
groupBox1.Visible=true;
groupBox2.Visible=false;
}
privatevoid退出ToolStripMenuItem_Click(objectsender,EventArgse)
{
this.Close();
}
privatevoidbutton2_Click(objectsender,EventArgse)
{
Application.Exit();
}
}
}
管理员界面;
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
usingSystem.Windows.Forms;
namespacebook
{
publicpartialclassadmin:
Form
{
publicadmin()
{
InitializeComponent();
}
privatevoid退出ToolStripMenuItem_Click(objectsender,EventArgse)
{
this.Close();
}
privatevoidadmin_Load(objectsender,EventArgse)
{
toolStrip1.Text=string.Format("管理员:
{}登录",userhelper.adminid);
}
privatevoidtoolStripButton4_Click(objectsender,EventArgse)//录入学生信息
{
addreaderaddreader=newaddreader();
addreader.Show();
this.Close();
}
privatevoid借书信息ToolStripMenuItem_Click(objectsender,EventArgse)
{
adminborrowa=newadminborrow();
a.Show();
}
privatevoid还书信息ToolStripMenuItem_Click(objectsender,EventArgse)
{
adminborrowa=newadminborrow();
a.Show();
}
privatevoid添加图书ToolStripMenuItem_Click(objectsender,EventArgse)
{
addbooka=newaddbook();
a.Show();
}
privatevoid删除图书ToolStripMenuItem_Click(objectsender,EventArgse)
{
adminearchbooka=newadminearchbook();
a.Show();
}
privatevoid查询图书ToolStripMenuItem_Click(objectsender,EventArgse)
{
adminearchbooka=newadminearchbook();
a.Show();
}
privatevoid查询出版社信息ToolStripMenuItem_Click(objectsender,EventArgse)
{
publishera=newpublisher();
a.Show();
this.Close();
}
privatevoid修改出版社信息ToolStripMenuItem_Click(objectsender,EventArgse)
{
publishera=newpublisher();
a.Show();
this.Close();
}
privatevoid查询学生借阅信息ToolStripMenuItem_Click(objectsender,EventArgse)
{
adminborrowa=newadminborrow();
a.Show();
}
privatevoidtoolStripButton6_Click_1(objectsender,EventArgse)//借书信息
{
booksborrowa=newbooksborrow();
a.Show();
}
privatevoid添加ToolStripMenuItem_Click(objectsender,EventArgse)
{
readerinfoa=newreaderinfo();
a.Show();
}
privatevoid删除ToolStripMenuItem_Click(objectsender,EventArgse)
{
deletereadera=newdeletereader();
a.Show();
}}}
添加图书信息界面:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
usingSystem.Windows.Forms;
usingSystem.Data.SqlClient;
namespacebook
{
publicpartialclassaddbook:
Form
{
publicaddbook()
{
InitializeComponent();
}
privatevoidaddbook_Load(objectsender,EventArgse)
{
try
{
stringsql1="selectbooktypenamefrombooktype";
SqlCommandcommand=newSqlCommand(sql1,Dbhelper.connection);
Dbhelper.connection.Open();
SqlDataReaderdatareader=command.ExecuteReader();
stringtypename="";
while(datareader.Read())
{
typename=(string)datareader[0];
comboBox2.Items.Add(typename);
}
datareader.Close();
stringsql2="selectpublishernamefrompublisher";
SqlCommandcommand1=newSqlCommand(sql2,Dbhelper.connection);
//Dbhelper.connection.Open();
SqlDataReaderdatareader1=command1.ExecuteReader();
stringpublishername="";
while(datareader1.Read())
{
publishername=(string)datareader1[0];
//MessageBox.Show(publishername);
comboBox1.Items.Add(publishername);
}
datareader1.Close();
}
catch
{
MessageBox.Show("error");
}
finally
{
Dbhelper.connection.Close();
}
}
privatevoidbutton2_Click(objectsender,EventArgse)
{
textBox1.Text=null;
textBox2.Text=null;
textBox4.Text=null;
comboBox2.Text=null;
comboBox1.Text=null;
}
privatestringtypdid(stringa)
{
stringid="";
stringsqltypeid=string.Format("selectbooktypeidfrombooktype