收藏 分销(赏)

C#图书馆管理系统设计.doc

上传人:二*** 文档编号:4688114 上传时间:2024-10-09 格式:DOC 页数:16 大小:86.50KB 下载积分:5 金币
下载 相关 举报
C#图书馆管理系统设计.doc_第1页
第1页 / 共16页
本文档共16页,全文阅读请下载到手机保存,查看更方便
资源描述
目录 1、绪论2 2、数据库设计3 2.1 数据库分析3 2.1创建数据库 4 3、界面设计 4 3.1 登陆界面 4 3.2 图书管理系统界面 8 3.3 图书信息界面 9 3.4 图书归还界面 11 3.5 图书借阅界面 13 3.6 用户信息界面 15 3.7管理员界面 16 3.8注册界面 18 3.9添加图书界面 19 4、系统测试 21 4.1 登陆功能 21 4.2 借阅图书功能 22 4.3 归还图书库功能 22 4.4 图书信息功能 23 4.5 管理员登陆功能 23 4.6 添加图书功能 24 4.7 用户信息 24 5 、连接数据库 24 5.1连接数据库 25 5.2操作数据库中的数据 25 6 、总结 27 1、绪论 2、数据库设计 2.1 数据库分析 本系统利用Visual Studio 2010处理数据库的功能,实现对图书馆信息的管理。主要功能为管理有关用户、管理员、书籍和借阅的信息等。   本系统的结构分为用户信息管理模块、书籍信息管理模块、借阅信息管理模块、管理者管理信息模块和查询处理模块。 图书馆管理系统框图如图所示 进入图书馆管理系统 借阅图书 查询图书 增加图书 查询图书 图书管理 登录 用户 管理员 失败 成功 2.2创建数据库 3、界面设计 3.1登陆界面 amespace 图书管理系统 { publicpartialclassForm1 : Form { public Form1<> { InitializeComponent<>; } publicstaticForm fm = null; privatestaticint ErrorTimes = 0; privatevoid button3_Click<object sender, EventArgs e> { this.Close<>; } privatevoid textBox1_TextChanged<object sender, EventArgs e> { } privatevoid button1_Click<object sender, EventArgs e> { if <textBox1.Text == "" || textBox2.Text == ""> { MessageBox.Show<"提示:请输入用户名和密码!", "警告">; } SqlConnection conn = newSqlConnection<"Server=PC_201402131602;Integrated Security=true;DataBase=图书管理系统">; conn.Open<>; SqlCommand cmd = newSqlCommand<"select * from Table_1 where id='" + textBox1.Text.Trim<> + "' and us='" + textBox2.Text.Trim<> + "'", conn>; SqlDataReader sdr = cmd.ExecuteReader<>; sdr.Read<>; if <sdr.HasRows> { MessageBox.Show<"登录成功!", "提示">; Form2 fm = newForm2<>; fm.Show<>; this.Hide<>; } else { ErrorTimes++; MessageBox.Show<"用户名或密码不正确!您还有" + <3 - ErrorTimes> + "次输入密码的机会,请重新输入!如果超过3次,系统将自动关闭">; if <ErrorTimes >= 3> { ErrorTimes = 0; conn.Close<>; } } } privatevoid Form1_Load<object sender, EventArgs e> { } privatevoid button4_Click<object sender, EventArgs e> { if <textBox1.Text == "" || textBox2.Text == ""> { MessageBox.Show<"提示:请输入用户名和密码!", "警告">; } SqlConnection conn = newSqlConnection<"Server=PC_201402131602;Integrated Security=true;DataBase=图书管理系统">; conn.Open<>; SqlCommand cmd = newSqlCommand<"select * from Table_2 where uid='" + textBox1.Text.Trim<> + "' and usr='" + textBox2.Text.Trim<> + "'", conn>; SqlDataReader sdr = cmd.ExecuteReader<>; sdr.Read<>; if <sdr.HasRows> { MessageBox.Show<"登录成功!", "提示">; Form7 fm = newForm7<>; fm.Show<>; this.Hide<>; } else { ErrorTimes++; MessageBox.Show<"用户名或密码不正确!您还有" + <3 - ErrorTimes> + "次输入密码的机会,请重新输入!如果超过3次,系统将自动关闭">; if <ErrorTimes >= 3> { ErrorTimes = 0; conn.Close<>; } } } privatevoid button2_Click<object sender, EventArgs e> { Form8 f1=newForm8<>; f1.Show<>; } privatevoid button5_Click<object sender, EventArgs e> { this.Hide<>; Form10 f2 = newForm10<>; f2.Show<>; } } } 3.2图书管理系统界面 namespace 图书管理系统 { publicpartialclassForm2 : Form { public Form2<> { InitializeComponent<>; } privatevoid button5_Click<object sender, EventArgs e> { this.Close<>; } privatevoid button3_Click<object sender, EventArgs e> { Form3 f2 = newForm3<>; f2.Show<>; this.Close<>; MessageBox.Show<"您已成功进入----图书信息!">; } privatevoid button2_Click<object sender, EventArgs e> { Form4 f4 = newForm4<>; f4.Show<>; this.Close<>; MessageBox.Show<"您已成功进入----还书系统!">; } privatevoid button1_Click<object sender, EventArgs e> { Form5 f5 = newForm5<>; f5.Show<>; this.Close<>; MessageBox.Show<"您已成功进入----借书系统!">; } } } 3.3图书信息 namespace 图书管理系统 { publicpartialclassForm3 : Form { public Form3<> { InitializeComponent<>; } privatevoid Form3_Load<object sender, EventArgs e> { // TODO: 这行代码将数据加载到表"图书管理系统DataSet.Table_3"中。您可以根据需要移动或删除它。 this.table_3TableAdapter.Fill<this.图书管理系统DataSet.Table_3>; } privatevoid textBox1_TextChanged<object sender, EventArgs e> { } privatevoid button1_Click<object sender, EventArgs e> { this.Close<>; } } } 3.4归还图书 namespace 图书管理系统 { publicpartialclassForm4 : Form { public Form4<> { InitializeComponent<>; } privatevoid button1_Click<object sender, EventArgs e> { if <textBox1.Text == ""> { MessageBox.Show<"提示:请输入所借书籍编号!", "警告">; } SqlConnection conn = newSqlConnection<"Server=PC_201402131602;Integrated Security=true;DataBase=图书管理系统">; conn.Open<>; SqlCommand cmd = newSqlCommand<"select * from Table_4 where sid='" + textBox1.Text.Trim<> + "' ", conn>; SqlDataReader sdr = cmd.ExecuteReader<>; sdr.Read<>; if <sdr.HasRows> { MessageBox.Show<"该书已还", "提示">; } else { sdr.Close<>; string myinsert = "insert into Table_4 <sid> values <'" + textBox1.Text + "'> "; SqlCommand mycom = newSqlCommand<myinsert, conn>; mycom.ExecuteNonQuery<>; conn.Close<>; conn.Dispose<>; MessageBox.Show<"您已还书成功!">; } } privatevoid Form4_Load<object sender, EventArgs e> { // TODO: 这行代码将数据加载到表"图书管理系统DataSet.Table_4"中。您可以根据需要移动或删除它。 this.table_4TableAdapter.Fill<this.图书管理系统DataSet.Table_4>; // TODO: 这行代码将数据加载到表"图书管理系统DataSet.Table_3"中。您可以根据需要移动或删除它。 this.table_3TableAdapter.Fill<this.图书管理系统DataSet.Table_3>; } privatevoid button2_Click<object sender, EventArgs e> { this.Close<>; Form2 f2 = newForm2<>; f2.Show<>; } } } 3.5已借图书 namespace 图书管理系统 { publicpartialclassForm5 : Form { public Form5<> { InitializeComponent<>; } privatevoid button1_Click<object sender, EventArgs e> { this.Close<>; Form2 f2 = newForm2<>; f2.Show<>; } privatevoid Form5_Load<object sender, EventArgs e> { // TODO: 这行代码将数据加载到表"图书管理系统DataSet.Table_4"中。您可以根据需要移动或删除它。 this.table_4TableAdapter.Fill<this.图书管理系统DataSet.Table_4>; // TODO: 这行代码将数据加载到表"图书管理系统DataSet.Table_3"中。您可以根据需要移动或删除它。 this.table_3TableAdapter.Fill<this.图书管理系统DataSet.Table_3>; } privatevoid button2_Click<object sender, EventArgs e> { if <textBox1.Text == ""> { MessageBox.Show<"提示:请输入所借书籍编号!", "警告">; } SqlConnection conn = newSqlConnection<"Server=PC_201402131602;Integrated Security=true;DataBase=图书管理系统">; conn.Open<>; SqlCommand cmd = newSqlCommand<"select * from Table_4 where sid='" + textBox1.Text.Trim<> + "' ", conn>; SqlDataReader sdr = cmd.ExecuteReader<>; sdr.Read<>; if <sdr.HasRows> { MessageBox.Show<"该书已借", "提示">; } else { sdr.Close<>; string myinsert = "insert into Table_4 <sid> values <'" + textBox1.Text + "'> "; SqlCommand mycom = newSqlCommand<myinsert, conn>; mycom.ExecuteNonQuery<>; conn.Close<>; conn.Dispose<>; MessageBox.Show<"您已借书成功!">; } } privatevoid textBox2_TextChanged<object sender, EventArgs e> { } } 3.6用户信息 namespace 图书管理系统 { publicpartialclassForm6 : Form { public Form6<> { InitializeComponent<>; } privatevoid Form6_Load<object sender, EventArgs e> { // TODO: 这行代码将数据加载到表"图书管理系统DataSet.Table_1"中。您可以根据需要移动或删除它。 this.table_1TableAdapter.Fill<this.图书管理系统DataSet.Table_1>; } privatevoid button1_Click<object sender, EventArgs e> { this.Close<>; } } } 3.7 管理员主界面 namespace 图书管理系统 { publicpartialclassForm7 : Form { public Form7<> { InitializeComponent<>; } privatevoid button2_Click<object sender, EventArgs e> { Form6 f1 = newForm6<>; f1.Show<>; MessageBox.Show<"您已成功进入----用户信息!">; } privatevoid button3_Click<object sender, EventArgs e> { Form3 f2 = newForm3<>; f2.Show<>; MessageBox.Show<"您已成功进入----图书信息!">; } privatevoid button1_Click<object sender, EventArgs e> { Form9 f2 = newForm9<>; f2.Show<>; MessageBox.Show<"您已成功进入----添加图书系统!">; } privatevoid button4_Click<object sender, EventArgs e> { this.Close<>; } } } 3.8注册界面 namespace 图书管理系统 { publicpartialclassForm8 : Form { public Form8<> { InitializeComponent<>; } privatevoid button1_Click<object sender, EventArgs e> { if <textBox1.Text == "" || textBox2.Text == ""> { MessageBox.Show<"提示:请输入用户名和密码!", "警告">; } SqlConnection conn = newSqlConnection<"Server=PC_201402131602;Integrated Security=true;DataBase=图书管理系统">; conn.Open<>; SqlCommand cmd = newSqlCommand<"select * from table_1 where id='" + textBox1.Text.Trim<> + "' and us='" + textBox2.Text.Trim<> + "'", conn>; SqlDataReader sdr = cmd.ExecuteReader<>; sdr.Read<>; if <sdr.HasRows> { MessageBox.Show<"该用户已注册,请使用其他用户名", "提示">; } else { sdr.Close<>; string myinsert = "insert into table_1<id,us> values <'" + textBox1.Text + "','" + textBox2.Text + "'>"; SqlCommand mycom = newSqlCommand<myinsert, conn>; mycom.ExecuteNonQuery<>; conn.Close<>; conn.Dispose<>; MessageBox.Show<"您已注册成功!">; } } privatevoid button2_Click<object sender, EventArgs e> { this.Close<>; } privatevoid Form8_Load<object sender, EventArgs e> { } } } 3.9 添加图书 namespace 图书管理系统 { publicpartialclassForm9 : Form { public Form9<> { InitializeComponent<>; } privatevoid button2_Click<object sender, EventArgs e> { } privatevoid button1_Click<object sender, EventArgs e> { SqlConnection conn = newSqlConnection<"server=PC_201402131602;database=图书管理系统;integrated Security=true">; string sql = "insert into Table_3 <sid,sdata,sname> values<'" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "'>"; conn.Open<>; SqlCommand comm = newSqlCommand<sql, conn>; if <conn.State == ConnectionState.Closed> { conn.Open<>; } if <Convert.ToInt32<comm.ExecuteNonQuery<>> > 0> { label4.Text = "成功!"; MessageBox.Show<"您已成功添加数据!">; } else { label4.Text = "失败!"; } } } } 4、 系统测试 登陆 借阅图书 归还图书 图书信息 管理员登陆 添加图书 用户信息 5、连接数据库 为数据库BookManage和本系统之间建立一个数据连接。   <1>在服务器资源管理器中右击"数据连接"节点<VS 2008中操作>。在弹出的快捷菜单中执行"添加连接"命令,打开Data Link Properties对话框。切换到Provider选项卡,选中列表框中的Microsoft OLE DB Provider for SQL Server项。单击"下一步"切换到Connection选项卡。 <2>在其中的第一个下拉列表框中选择数据库所在服务器名称。输入登录服务器信息后选择数据库BookManage,然后单击测试按钮。如果测试成功,单击"确定"按钮。 5.1 连接数据库 <1>定义数据库连接字符串,代码如下: Private static string ConnectString = "Data Source= <local>\\sqlexpress;DataBase=BookManage.mdf"; <2>创建Connection对象,代码如下: SqlConnection con = new SqlConnection<ConnectString>; <3>打开连接,代码如下: con.Open<>; <4>关闭连接,代码如下: con.Close<>; 5.2操作数据库中的数据 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using System.Data.SqlClient; namespace BookManage { classDataAccess { privatestaticstring ConnectString = @"Data Source =SQLEXPRESS;AttachDbFilename=F:\BookManage\data\BookManage.mdf;Integrated Security=False";//数据库连接字符串 ///<summary> /// 根据表名获取数据集的表 ///</summary> ///<param name="table"></param> ///<returns></returns> publicstaticDataTable GetDataSetByTableName<string table> {using <SqlConnection con = newSqlConnection<ConnectString>>//创建数据库连接对象 { string sql = "select * from " + table + "";//查询sql语句 try {SqlDataAdapter adapter = newSqlDataAdapter<sql, con>;//创建适配器对象 DataSet ds = newDataSet<>;//创建数据集对象 adapter.Fill<ds, "table">;//填充数据集 return ds.Tables[0];//返回数据表 } catch <SqlException ex> { thrownewException<ex.Message>; ;}}} publicstaticDataSet GetDataSetBySql<string sql> { using <SqlConnection con = newSqlConnection<ConnectString>>//创建数据库连接对象 { SqlDataAdapter adapter = newSqlDataAdapter<sql,con>;//创建适配器对象 DataSet ds = newDataSet<>;//创建数据集对象 try { adapter.Fill<ds>;//填充数据集 return ds;//返回数据集 } catch <SqlException ex> {thrownewException<ex.Message>} } publicstaticSqlDataReader GetDataReaderByID<int id> {using <SqlConnection con = newSqlConnection<ConnectString>> {string sql = "select * from bookinfo where bookid=" + id;//sql语句 try {SqlCommand comm = newSqlCommand<sql, con>;//创建Command对象 con.Open<>;//打开连接 SqlDataReader reader = comm.ExecuteReader<>;//创建DataReader对象 reader.Read<>;//读取数据 return reader;//返回DataReader} catch <SqlException ex> {thrownewException<ex.Message>; }} publicstaticbool UpdateDataTable<string sql> {using <SqlConnection con = newSqlConnection<ConnectString>> { try {con.Open<>;//打开连接 SqlCommand comm = newSqlCommand<sql, con>;//创建Command对象 if <comm.ExecuteNonQuery<> > 0> //执行更新 {returntrue;} else {returnfalse;}} catch <SqlException ex> {thrownewException<ex.Message>;}}} publicstaticvoid UpdateDataSet<DataSet ds,string sql> { using <SqlConnection con = newSqlConnection<ConnectString>> {try { SqlDataAdapter adapter = newSqlDataAdapter<sql, con>;//创建适配器 SqlCommandBuilder builder = newSqlCommandBuilder<adapter>;//根据适配器自动生成表单 adapter.Update<ds, "table">;//更新数据库} catch <SqlException ex> { thrownewException<ex.Message>;}}}}} 15 / 16
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 包罗万象 > 大杂烩

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服