1、C#图书馆管理系统2.1创建数据库 43.7管理员界面 163.8注册界面 183.9添加图书界面 194.6 添加图书功能 244.7 用户信息 245.1连接数据库 255.2操作数据库中的数据 251、绪论2、数据库设计2.1 数据库分析本系统利用Visual Studio 2010处理数据库的功能,实现对图书馆信息的管理。主要功能为管理有关用户、管理员、书籍和借阅的信息等。本系统的结构分为用户信息管理模块、书籍信息管理模块、借阅信息管理模块、管理者管理信息模块和查询处理模块。图书馆管理系统框图如图所示 失败 成功 2.2创建数据库3、界面设计3.1登陆界面amespace 图书管理系统
2、 public partial class Form1 : Form public Form1() InitializeComponent(); public static Form fm = null; private static int ErrorTimes = 0; private void button3_Click(object sender, EventArgs e) this.Close(); private void textBox1_TextChanged(object sender, EventArgs e) private void button1_Click(obje
3、ct sender, EventArgs e) if (textBox1.Text = | textBox2.Text = ) MessageBox.Show(提示:请输入用户名和密码!, 警告); SqlConnection conn = new SqlConnection(Server=PC_201402131602;Integrated Security=true;DataBase=图书管理系统); conn.Open(); SqlCommand cmd = new SqlCommand(select * from Table_1 where id= + textBox1.Text.Tr
4、im() + and us= + textBox2.Text.Trim() + , conn); SqlDataReader sdr = cmd.ExecuteReader(); sdr.Read(); if (sdr.HasRows) MessageBox.Show(登录成功!, 提示); Form2 fm = new Form2(); fm.Show(); this.Hide(); else ErrorTimes+; MessageBox.Show(用户名或密码不正确!您还有 + (3 - ErrorTimes) + 次输入密码的机会,请重新输入!如果超过3次,系统将自动关闭); if (
5、ErrorTimes = 3) ErrorTimes = 0; conn.Close(); private void Form1_Load(object sender, EventArgs e) private void button4_Click(object sender, EventArgs e) if (textBox1.Text = | textBox2.Text = ) MessageBox.Show(提示:请输入用户名和密码!, 警告); SqlConnection conn = new SqlConnection(Server=PC_201402131602;Integrate
6、d Security=true;DataBase=图书管理系统); conn.Open(); SqlCommand cmd = new SqlCommand(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 = new Form7()
7、; fm.Show(); this.Hide(); else ErrorTimes+; MessageBox.Show(用户名或密码不正确!您还有 + (3 - ErrorTimes) + 次输入密码的机会,请重新输入!如果超过3次,系统将自动关闭); if (ErrorTimes = 3) ErrorTimes = 0; conn.Close(); private void button2_Click(object sender, EventArgs e) Form8 f1=new Form8(); f1.Show(); private void button5_Click(object s
8、ender, EventArgs e) this.Hide(); Form10 f2 = new Form10(); f2.Show(); 3.2图书管理系统界面namespace 图书管理系统 public partial class Form2 : Form public Form2() InitializeComponent(); private void button5_Click(object sender, EventArgs e) this.Close(); private void button3_Click(object sender, EventArgs e) Form3
9、f2 = new Form3(); f2.Show(); this.Close(); MessageBox.Show(您已成功进入-图书信息!); private void button2_Click(object sender, EventArgs e) Form4 f4 = new Form4(); f4.Show(); this.Close(); MessageBox.Show(您已成功进入-还书系统!); private void button1_Click(object sender, EventArgs e) Form5 f5 = new Form5(); f5.Show(); t
10、his.Close(); MessageBox.Show(您已成功进入-借书系统!); 3.3图书信息namespace 图书管理系统 public partial class Form3 : Form public Form3() InitializeComponent(); private void Form3_Load(object sender, EventArgs e) / TODO: 这行代码将数据加载到表“图书管理系统DataSet.Table_3”中。您可以根据需要移动或删除它。 this.table_3TableAdapter.Fill(this.图书管理系统DataSet.
11、Table_3); private void textBox1_TextChanged(object sender, EventArgs e) private void button1_Click(object sender, EventArgs e) this.Close(); 3.4归还图书namespace 图书管理系统 public partial class Form4 : Form public Form4() InitializeComponent(); private void button1_Click(object sender, EventArgs e) if (text
12、Box1.Text = ) MessageBox.Show(提示:请输入所借书籍编号!, 警告); SqlConnection conn = new SqlConnection(Server=PC_201402131602;Integrated Security=true;DataBase=图书管理系统); conn.Open(); SqlCommand cmd = new SqlCommand(select * from Table_4 where sid= + textBox1.Text.Trim() + , conn); SqlDataReader sdr = cmd.ExecuteRe
13、ader(); sdr.Read(); if (sdr.HasRows) MessageBox.Show(该书已还, 提示); else sdr.Close(); string myinsert = insert into Table_4 (sid) values ( + textBox1.Text + ) ; SqlCommand mycom = new SqlCommand(myinsert, conn); mycom.ExecuteNonQuery(); conn.Close(); conn.Dispose(); MessageBox.Show(您已还书成功!); private voi
14、d 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); private void button2_Cl
15、ick(object sender, EventArgs e) this.Close(); Form2 f2 = new Form2(); f2.Show(); 3.5已借图书namespace 图书管理系统 public partial class Form5 : Form public Form5() InitializeComponent(); private void button1_Click(object sender, EventArgs e) this.Close(); Form2 f2 = new Form2(); f2.Show(); private void Form5_
16、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); private void button2_Click(obje
17、ct sender, EventArgs e) if (textBox1.Text = ) MessageBox.Show(提示:请输入所借书籍编号!, 警告); SqlConnection conn = new SqlConnection(Server=PC_201402131602;Integrated Security=true;DataBase=图书管理系统); conn.Open(); SqlCommand cmd = new SqlCommand(select * from Table_4 where sid= + textBox1.Text.Trim() + , conn); S
18、qlDataReader 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 = new SqlCommand(myinsert, conn); mycom.ExecuteNonQuery(); conn.Close(); conn.Dispose(); Messa
19、geBox.Show(您已借书成功!); private void textBox2_TextChanged(object sender, EventArgs e) 3.6用户信息namespace 图书管理系统 public partial class Form6 : Form public Form6() InitializeComponent(); private void Form6_Load(object sender, EventArgs e) / TODO: 这行代码将数据加载到表“图书管理系统DataSet.Table_1”中。您可以根据需要移动或删除它。 this.table
20、_1TableAdapter.Fill(this.图书管理系统DataSet.Table_1); private void button1_Click(object sender, EventArgs e) this.Close(); 3.7 管理员主界面namespace 图书管理系统 public partial class Form7 : Form public Form7() InitializeComponent(); private void button2_Click(object sender, EventArgs e) Form6 f1 = new Form6(); f1.S
21、how(); MessageBox.Show(您已成功进入-用户信息!); private void button3_Click(object sender, EventArgs e) Form3 f2 = new Form3(); f2.Show(); MessageBox.Show(您已成功进入-图书信息!); private void button1_Click(object sender, EventArgs e) Form9 f2 = new Form9(); f2.Show(); MessageBox.Show(您已成功进入-添加图书系统!); private void butto
22、n4_Click(object sender, EventArgs e) this.Close(); 3.8注册界面namespace 图书管理系统 public partial class Form8 : Form public Form8() InitializeComponent(); private void button1_Click(object sender, EventArgs e) if (textBox1.Text = | textBox2.Text = ) MessageBox.Show(提示:请输入用户名和密码!, 警告); SqlConnection conn = n
23、ew SqlConnection(Server=PC_201402131602;Integrated Security=true;DataBase=图书管理系统); conn.Open(); SqlCommand cmd = new SqlCommand(select * from table_1 where id= + textBox1.Text.Trim() + and us= + textBox2.Text.Trim() + , conn); SqlDataReader sdr = cmd.ExecuteReader(); sdr.Read(); if (sdr.HasRows) Mes
24、sageBox.Show(该用户已注册,请使用其他用户名, 提示); else sdr.Close(); string myinsert = insert into table_1(id,us) values ( + textBox1.Text + , + textBox2.Text + ); SqlCommand mycom = new SqlCommand(myinsert, conn); mycom.ExecuteNonQuery(); conn.Close(); conn.Dispose(); MessageBox.Show(您已注册成功!); private void button2
25、_Click(object sender, EventArgs e) this.Close(); private void Form8_Load(object sender, EventArgs e) 3.9 添加图书namespace 图书管理系统 public partial class Form9 : Form public Form9() InitializeComponent(); private void button2_Click(object sender, EventArgs e) private void button1_Click(object sender, Event
26、Args e) SqlConnection conn = new SqlConnection(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 = new SqlCommand(sql, conn); if (conn.
27、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
28、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;
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1