《图书管理系统源码(C#版)(共35页).doc》由会员分享,可在线阅读,更多相关《图书管理系统源码(C#版)(共35页).doc(35页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、精选优质文档-倾情为你奉上登录界面:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Data.SqlClient;namespace book public partial class login : Form public string password; /用来存储密码 public login()
2、InitializeComponent(); private void button2_Click(object sender, EventArgs e) Application.Exit(); private bool yanzhengshuru() password = textBox3.Text; if (Typename.Text.Trim() = ) MessageBox.Show(请选择登录类型, 登录提示, MessageBoxButtons.OK, MessageBoxIcon.Information); Typename.Focus(); return false; else
3、 if (loginid.Text.Trim() = ) MessageBox.Show(请输入用户名, 登录提示, MessageBoxButtons.OK, MessageBoxIcon.Information); loginid.Focus(); return false; else if (password = ) MessageBox.Show(请输入密码, 登录提示, MessageBoxButtons.OK, MessageBoxIcon.Information); textBox3.Focus(); return false; else return true; private
4、 void button1_Click(object sender, EventArgs e) userhelper.adminid= loginid.Text; /用户账号 password = textBox3.Text;/用户密码 if (yanzhengshuru() if (Typename.Text.Trim() = 管理员) string sql = string.Format(Select count(*) from admin where adminId=0 and adminpass=1, loginid.Text, password); try SqlCommand co
5、mmand = new SqlCommand(sql, Dbhelper.connection); Dbhelper.connection.Open(); int count = (int)command.ExecuteScalar(); if (count 1) MessageBox.Show(用户或密码不存在!); /result = false; else admin admin = new admin(); admin.Show(); catch (Exception ex) MessageBox.Show(操作数据库出错!); Console.WriteLine(ex.Message
6、); finally Dbhelper.connection.Close(); if (Typename.Text.Trim() = 借阅者) userhelper.readerid =Convert .ToString (loginid.Text); string sql = string.Format(Select count(*) from reader where readerId=0 and readerpass=1, userhelper.readerid,textBox3.Text); try / 创建 Command 对象 SqlCommand command = new Sq
7、lCommand(sql, Dbhelper.connection); / 打开数据库连接 Dbhelper.connection.Open(); / 验证是否为合法用户 int count = (int)command.ExecuteScalar(); if (count 1) MessageBox.Show(用户或密码不存在!); /result = false; else reader reader = new reader(); reader.Show(); catch (Exception ex) MessageBox.Show(操作数据库出错!); Console.WriteLin
8、e(ex.Message); /result = false; finally / 关闭数据库连接 Dbhelper.connection.Close(); private void login_Load(object sender, EventArgs e) 读者界面;using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using
9、System.Data.Sql;using System.Data.SqlClient;namespace book public partial class reader : Form public reader() InitializeComponent(); private void button3_Click(object sender, EventArgs e) string id =Convert.ToString (textBox1.Text); if (id!=userhelper.readerid) MessageBox.Show(输入账号与登陆账号不相同,请重新输入,提示,
10、MessageBoxButtons.OK,MessageBoxIcon.Warning); textBox1.Text = ; textBox1.Focus(); else try string sql = string.Format(update reader set islost=0where readerid=1, 是,id); Dbhelper.connection.Open(); SqlCommand command = new SqlCommand(sql,Dbhelper.connection); int result = command.ExecuteNonQuery(); i
11、f (result 1) MessageBox.Show(修改失败); else MessageBox.Show(挂失成功); catch MessageBox.Show(error); finally Dbhelper.connection.Close(); private void toolStripButton3_Click(object sender, EventArgs e) groupBox1.Visible = false; groupBox2.Visible = true; private void toolStripButton4_Click(object sender, E
12、ventArgs e) groupBox1.Visible = true; groupBox2.Visible = false; private void button5_Click(object sender, EventArgs e) textBox2.Text = ; textBox4.Text = ; textBox5.Text = ; private void Form1_Load(object sender, EventArgs e) toolStrip1.Text = string.Format(学生:0,userhelper.readerid); private void bu
13、tton4_Click(object sender, EventArgs e) string id =Convert.ToString (textBox2.Text); if (id!=userhelper.readerid) MessageBox.Show(输入账号与登陆账号不相同,请重新输入,提示,MessageBoxButtons.OK,MessageBoxIcon.Warning); textBox1.Text = ; textBox1.Focus(); else if (textBox4.Text!=textBox5.Text) MessageBox.Show (两次密码输入不同);
14、 else try string sql = string.Format(update reader set readerpass=0 where readerid=1, textBox4.Text,id); Dbhelper.connection.Open(); SqlCommand command = new SqlCommand(sql,Dbhelper.connection); int result = command.ExecuteNonQuery(); if (result 1) MessageBox.Show(修改失败); else MessageBox.Show(修改成功);
15、catch MessageBox.Show(error); finally Dbhelper.connection.Close(); private void toolStripButton6_Click(object sender, EventArgs e) addreader addreader = new addreader(); addreader = new addreader(); private void toolStripButton1_Click(object sender, EventArgs e) readsearchbook searchbook = new reads
16、earchbook(); searchbook.Show(); private void toolStripButton2_Click(object sender, EventArgs e) borrow a = new borrow(); a.Show(); private void toolStripButton5_Click(object sender, EventArgs e) readerseacherinfo a = new readerseacherinfo(); a.Show(); private void 图书查询ToolStripMenuItem1_Click(object
17、 sender, EventArgs e) readsearchbook a = new readsearchbook(); a.Show(); this.Close(); private void 结束查询ToolStripMenuItem_Click(object sender, EventArgs e) borrow a = new borrow(); a.Show(); this.Close(); private void 修改密码ToolStripMenuItem_Click(object sender, EventArgs e) groupBox1.Visible = false;
18、 groupBox2.Visible = true; private void 挂失ToolStripMenuItem_Click(object sender, EventArgs e) groupBox1.Visible = true; groupBox2.Visible = false; private void 退出ToolStripMenuItem_Click(object sender, EventArgs e) this.Close(); private void button2_Click(object sender, EventArgs e) Application.Exit(
19、); 管理员界面;using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace book public partial class admin : Form public admin() InitializeComponent(); private void 退出ToolStripMenuItem_Click(object
20、sender, EventArgs e) this.Close(); private void admin_Load(object sender, EventArgs e) toolStrip1.Text=string.Format (管理员:登录,userhelper.adminid); private void toolStripButton4_Click(object sender, EventArgs e)/录入学生信息 addreader addreader = new addreader(); addreader.Show(); this.Close(); private void
21、 借书信息ToolStripMenuItem_Click(object sender, EventArgs e) adminborrow a = new adminborrow(); a.Show(); private void 还书信息ToolStripMenuItem_Click(object sender, EventArgs e) adminborrow a = new adminborrow(); a.Show(); private void 添加图书ToolStripMenuItem_Click(object sender, EventArgs e) addbook a = new
22、 addbook(); a.Show(); private void 删除图书ToolStripMenuItem_Click(object sender, EventArgs e) adminearchbook a = new adminearchbook(); a.Show(); private void 查询图书ToolStripMenuItem_Click(object sender, EventArgs e) adminearchbook a = new adminearchbook(); a.Show(); private void 查询出版社信息ToolStripMenuItem_
23、Click(object sender, EventArgs e) publisher a = new publisher(); a.Show(); this.Close(); private void 修改出版社信息ToolStripMenuItem_Click(object sender, EventArgs e) publisher a = new publisher(); a.Show(); this.Close(); private void 查询学生借阅信息ToolStripMenuItem_Click(object sender, EventArgs e) adminborrow
24、 a = new adminborrow(); a.Show(); private void toolStripButton6_Click_1(object sender, EventArgs e)/借书信息 booksborrow a = new booksborrow(); a.Show(); private void 添加ToolStripMenuItem_Click(object sender, EventArgs e) readerinfo a = new readerinfo(); a.Show(); private void 删除ToolStripMenuItem_Click(o
25、bject sender, EventArgs e) deletereader a = new deletereader(); a.Show(); 添加图书信息界面:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Data.SqlClient;namespace book public partial c
26、lass addbook : Form public addbook() InitializeComponent(); private void addbook_Load(object sender, EventArgs e) try string sql1 = select booktypename from booktype; SqlCommand command = new SqlCommand(sql1, Dbhelper.connection); Dbhelper.connection.Open(); SqlDataReader datareader = command.Execut
27、eReader(); string typename = ; while (datareader.Read() typename = (string)datareader0; comboBox2.Items.Add(typename); datareader.Close(); string sql2 = select publishername from publisher; SqlCommand command1 = new SqlCommand(sql2, Dbhelper.connection); /Dbhelper.connection.Open(); SqlDataReader da
28、tareader1 = command1.ExecuteReader(); string publishername = ; while (datareader1.Read() publishername = (string)datareader10; /MessageBox.Show(publishername); comboBox1.Items.Add(publishername); datareader1.Close(); catch MessageBox.Show(error); finally Dbhelper.connection.Close(); private void but
29、ton2_Click(object sender, EventArgs e) textBox1.Text = null; textBox2.Text = null; textBox4.Text = null; comboBox2.Text = null; comboBox1.Text = null; private string typdid(string a) string id = ; string sqltypeid = string.Format(select booktypeid from booktype where booktypename=0, a); try SqlCommand command=new SqlCommand (sqltypeid,Dbhelper.connection); Dbhelper.connection.Open(); id = Convert.ToString(command.ExecuteScalar(); catch MessageBox.Show(error ); finally Dbhelper.connection.Close(); return id; priva