数据库课程设计报告.docx
- 文档编号:9018664
- 上传时间:2023-02-02
- 格式:DOCX
- 页数:40
- 大小:360.45KB
数据库课程设计报告.docx
《数据库课程设计报告.docx》由会员分享,可在线阅读,更多相关《数据库课程设计报告.docx(40页珍藏版)》请在冰豆网上搜索。
数据库课程设计报告
数据库课程设计报告
专业名称:
计算机0701
班级学号:
**********
********
*******
设计时间:
2022年6月25日——2022年7月3日
E-R图
界面设计
登录界面
登录采用用户名和密码认证,输入用户名和密码,与数据库中用户表中的数据相比较,根据应有的权限和选择的权限进入不同的界面。
登录时首先比较用户名,假设没有,那么提示无此用户。
再比较密码,假设不同那么提示密码错误。
最后比较权限,假设超出权限,那么给出提示,假设都符合那么进入所选择的界面。
源代码:
usingSystem;
using
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
using
using
namespacemySQL
{
publicpartialclassForm1:
Form
{
SqlConnectiondataConnection;//数据库连接类
SqlCommanddataCommand;//数据库命令类
SqlDataReaderdataReader;//数据库读出类
StringuID;//存放用户名的String类
StringuPassD;//存放密码的String类
//构造函数
publicForm1()
{
InitializeComponent();
}
//关闭窗口
privatevoidbutton2_Click(objectsender,EventArgse)
{
dataConnection.Close();
this.Dispose();
}
//载入窗口时连接数据库,进展初始化
privatevoidForm1_Load(objectsender,EventArgse)
{
//连接数据库
try
{
dataConnection=newSqlConnection();
dataConnection.ConnectionString="IntegratedSecurity=true;InitialCatalog=mySQL;"+"DataSource=wty-PC";
//dataConnection.Open();
}
//捕获异常
catch(SqlExceptionee)
{
MessageBox.Show(ee.Message);
}
//数据库类之间的互相绑定
finally
{
dataCommand=newSqlCommand();
dataCommand.Connection=dataConnection;
}
}
//进展身份验证,并登录
privatevoidbutton1_Click(objectsender,EventArgse)
{
uID=textBox1.Text;
uPassD=textBox2.Text;
dataConnection.Close();
dataConnection.Open();
if(uID=="")
MessageBox.Show("请输入用户名");
elseif(uID!
="")
{
dataCommand.CommandText=("SELECT*FROM用户WHERE用户名='"+uID+"'");
dataReader=dataCommand.ExecuteReader();
if(!
dataReader.Read())
{
MessageBox.Show("没有此用户!
");
textBox1.Text="";
textBox2.Text=null;
dataConnection.Close();
}
elseif(uPassD!
=dataReader.GetString
(1))
{
MessageBox.Show("密码错误,请重新输入!
");
textBox2.Text="";
dataConnection.Close();
}
else
{
if(radioButton2.Checked)
{
if(dataReader.GetString
(2)=="读者")
{
MessageBox.Show("你没有管理员权限!
");
dataReader.Close();
dataConnection.Close();
}
elseif(dataReader.GetString
(2)=="管理员")
{
dataReader.Close();
dataConnection.Close();
Form3frm3=newForm3(dataConnection,dataCommand,dataReader,uID);
this.Hide();
frm3.ShowDialog();
}
}
elseif(radioButton1.Checked)
{
dataReader.Close();
dataConnection.Close();
Form2frm2=newForm2(dataConnection,dataCommand,dataReader,uID);
this.Hide();
frm2.ShowDialog();
}
}
}
}
//按下ENTER键时,响应验证
privatevoidtextBox2_KeyDown(objectsender,KeyEventArgse)
{
if((int)e.KeyCode==13)
this.button1_Click(sender,e);
}
}
}
读者界面
读者信息,显示你当前的一些信息,包括可借数量和预约数量等,并包括修改密码功能。
查询,可以进展图书的查询,包括模糊查询和准确查询。
通过radiobuttun来判断。
模糊查询不支持ISBN的查询。
选中查询结果的行头,自动填充到借阅/预约界面
借阅/预约,这里的textbox都设置为readonly,主要是为了防止出现图书馆中没有的书进展借阅,这样可以节省查询的时间,并且通过查询界面可以很方便的填入这两项信息。
借阅和预约分别是计入相应的表内。
并可以查询
归还界面,同样,textbox设为readonly,通过查询借书或预约情况,选中行头来填入信息。
归还或取消预约好删除相应元组。
注销界面
注销是返回登录界面重新登陆
退出是退出程序。
源代码:
usingSystem;
using
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
using
using
namespacemySQL
{
publicpartialclassForm2:
Form
{
SqlConnectiondataConnection;//数据库连接类
SqlCommanddataCommand;//数据库命令类
//SqlDataReaderdataReader;//数据库读出类
StringuID;//存放用户名的String类
Int32ynum=0;
Int32lnum=0;//在馆数量
Int32maxnum=0;
Int32dnum=0;
Int32ymaxnum=0;
Int32ydnum=0;
boolbflag=true;
boolyflag=false;
//StringbISBN;//存放ISBN编号
//StringbName;//存放书名
//Int32bNum;//图书数量
//Int32lNum;//在馆数量
//构造函数
publicForm2()
{
InitializeComponent();
}
//传递参数的构造函数
publicForm2(SqlConnectionconn,SqlCommandcomm,SqlDataReaderread,StringID)
{
dataConnection=newSqlConnection();
dataConnection=conn;
dataCommand=newSqlCommand();
dataCommand=comm;
//dataReader=read;
uID=ID;
InitializeComponent();
}
//注销,返回登录界面
privatevoidbutton1_Click(objectsender,EventArgse)
{
Form1frm1=newForm1();
this.Hide();
frm1.ShowDialog();
}
//退出系统
privatevoidbutton2_Click(objectsender,EventArgse)
{
this.Dispose();
}
//清空所有textBox中的内容
privatevoidbutton4_Click(objectsender,EventArgse)
{
this.textBox1.Text="";
this.textBox2.Text="";
this.dataGridView1.DataSource=null;
}
//查询图书
privatevoidbutton3_Click(objectsender,EventArgse)
{
dataConnection.Open();
Stringbookname="";
Stringbookisbn="";
Stringbmark="";
if(textBox1.Text!
="")
bookisbn=("ISBN编号='"+textBox1.Text+"'");
if((textBox2.Text!
="")&&(textBox1.Text!
=""))
bookname=("AND书名='"+textBox2.Text+"'");
elseif(textBox2.Text!
="")
bookname=("书名='"+textBox2.Text+"'");
bmark=bookname+bookisbn;
if(radioButton2.Checked)
{
//添加准确查询的代码
if(bmark!
="")
dataCommand.CommandText="SELECT*FROMbookWHERE"+bmark;
elseif(bmark=="")
MessageBox.Show("请输入查询数据!
");
}
elseif(radioButton1.Checked)
{
if(textBox1.Text!
="")
MessageBox.Show("不支持ISBN的模糊查询!
");
else
{
//添加模糊查询的代码
if(textBox2.Text!
="")
{
bookname=("书名like'%"+textBox2.Text+"%'");
dataCommand.CommandText="SELECT*FROMbookWHERE"+bookname;
}
else//查询所有图书
{
dataCommand.CommandText="SELECT*FROMbook";
}
}
}
else
MessageBox.Show("请选择查询方式!
");
SqlDataReaderdataReader=dataCommand.ExecuteReader();
BindingSourcebs=newBindingSource();
bs.DataSource=dataReader;
this.dataGridView1.DataSource=bs;
if(dataReader.Read())
{
lnum=dataReader.GetInt32(3);
ynum=dataReader.GetInt32(6);
}
dataConnection.Close();
}
//借书
privatevoidbutton5_Click(objectsender,EventArgse)
{
dataConnection.Open();
Stringbookname="";
Stringbookisbn="";
dataCommand.CommandText="SELECT*FROMborrowWHERE读者号='"+uID+"'";
SqlDataReadertempReader=dataCommand.ExecuteReader();
if((textBox3.Text!
="")&&(textBox4.Text!
=""))
{
bookisbn=textBox3.Text;
bookname=textBox4.Text;
boolflag=true;
if(tempReader.Read())
{
if(bookisbn==tempReader.GetString
(1))
{
MessageBox.Show("你已经借了此书了!
");
flag=false;
}
tempReader.Close();
}
elseif(flag==true)
{
tempReader.Close();
if(lnum==0)
{
MessageBox.Show("在馆数量为零,不可借阅");
}
elseif(maxnum<=dnum)
{
MessageBox.Show("你的借书数量已满,无法再借!
");
}
else
{
dataCommand.CommandText="SELECT*FROMborderWHERE读者号='"+uID+"'";
tempReader=dataCommand.ExecuteReader();
if(tempReader.Read())
{
if(bookisbn==tempReader.GetString
(1))
{
MessageBox.Show("你已经预约此书了,该操作将会删除你的预约记录!
");
tempReader.Close();
dataCommand.CommandText="DELETEFROMborderWHEREISBN编号='"+bookisbn+"'";
dataCommand.ExecuteNonQuery();
}
}
tempReader.Close();
dataCommand.CommandText="INSERTINTOborrow(读者号,ISBN编号)VALUES('"+uID+"','"+bookisbn+"')";
dataCommand.ExecuteNonQuery();
dataCommand.CommandText="UPDATEbookSET在馆数量=在馆数量-1WHEREISBN编号='"+bookisbn+"'";
dataCommand.ExecuteNonQuery();
dataCommand.CommandText="UPDATEbookSET可预约数量=可预约数量+1WHEREISBN编号='"+bookisbn+"'";
dataCommand.ExecuteNonQuery();
dataCommand.CommandText="UPDATEreaderSET已借数量=已借数量+1WHERE读者号='"+uID+"'";
dataCommand.ExecuteNonQuery();
MessageBox.Show("借阅成功!
");
dnum++;
textBox3.Text="";
textBox4.Text="";
}
//tempreader_1.Close();
}
}
tempReader.Close();
dataCommand.CommandText="SELECT*FROMBORROWWHERE读者号='"+uID+"'";
SqlDataReaderdataReader=dataCommand.ExecuteReader();
BindingSourcebs=newBindingSource();
bs.DataSource=dataReader;
this.dataGridView2.DataSource=bs;
dataConnection.Close();
}
//将所选图书信息传递至借书模块
privatevoiddataGridView1_RowHeaderMouseClick(objectsender,DataGridViewCellMouseEventArgse)
{
"ISBN编号"].Value.ToString();
textBox4.Text=dataGridView1.Rows[data"书名"].Value.ToString();
lnum=(int"在馆数量"].Value;
ynum=(int"可预约数量"].Value;
}
//查询借书情况
privatevoidbutton7_Click(objectsender,EventArgse)
{
dataConnection.Open();
dataCommand.CommandText="SELECT*FROMBORROWWHERE读者号='"+uID+"'";
SqlDataReaderdataReader=dataCommand.ExecuteReader();
BindingSourcebs=newBindingSource();
bs.DataSource=dataReader;
this.dataGridView2.DataSource=bs;
dataConnection.Close();
}
//查询借书情况
privatevoidbutton8_Click(objectsender,EventArgse)
{
dataConnection.Open();
dataCommand.CommandText="SELECT*FROMBORROWWHERE读者号='"+uID+"'";
SqlDataReaderdataReader=dataCommand.ExecuteReader();
BindingSourcebs=newBindingSource();
bs.DataSource=dataReader;
this.dataGridView3.DataSource=bs;
dataConnection.Close();
bflag=true;
yflag=false;
}
//传递还书信息
privatevoiddataGridView3_RowHeaderMouseClick(objectsender,DataGridViewCellMouseEventArgse)
{
if(bflag==true&&yflag==false)
"ISBN编号"].Value.ToString();
elseif(yflag==true&&bflag==false)
"ISBN编号"].Value.ToString();
}
//还书
privatevoidbutton9_Click(objectsender,EventArgse)
{
dataConnection.Open();
Stringbookisbn;
bookisbn=textBox5.Text;
if(bookisbn!
="")
{
dataCommand.CommandText="DELETEFROMborrowWHEREISBN编号='"+bookisbn+"'";
dataCommand.ExecuteNonQuery();
dataCommand.CommandText="UPDATEbookSET在馆数量=在馆数量+1WHEREISBN编号='"+bookisbn+"'";
dataCommand.ExecuteNonQuery();
dataCommand.CommandText="UPDATEbookSET可预约数量=可预约数量-1WHEREISBN编号='"+bookisbn+"'";
dataCommand.ExecuteNonQuery();
dataCommand.CommandText="UPDATEreaderSET已借数量=已借数量-1WHERE读者号='"+uID+"'";
dataCommand.ExecuteNonQuery();
textBox5.Text="";
MessageBox.Show("归还成功!
");
dnum--;
}
dataConnection.Close();
}
//预约
privatevoidbutton6_Click(objectsender,EventArgse)
{
dataConnection.Open();
Stringbookname="";
String
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据库 课程设计 报告
![提示](https://static.bdocx.com/images/bang_tan.gif)