图书管理系统源码(C#版)

上传人:GCG1****010 文档编号:57134929 上传时间:2022-02-23 格式:DOC 页数:34 大小:157KB
返回 下载 相关 举报
图书管理系统源码(C#版)_第1页
第1页 / 共34页
图书管理系统源码(C#版)_第2页
第2页 / 共34页
图书管理系统源码(C#版)_第3页
第3页 / 共34页
点击查看更多>>
资源描述
登录界面: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() 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 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 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 command = 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); 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 SqlCommand(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.WriteLine(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 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(”输入账号与登陆账号不相同,请重新输入,”提示,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(); if (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, EventArgs 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 button4_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 (”两次密码输入不同); 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(”修改成功”); 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 readsearchbook(); 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 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; 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(); 管理员界面;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 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 借书信息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 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_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 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(object 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 class 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.ExecuteReader(); 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 datareader1 = 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 button2_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; private string publisheid(string a) string id = ”; string sqlpublisheid = string。Format(”select publisherid from publisher where publishername=0”, a); try SqlCommand command = new SqlCommand(sqlpublisheid, Dbhelper。connection); Dbhelper。connection。Open(); id = Convert.ToString(command。ExecuteScalar()); catch MessageBox。Show(error ); finally Dbhelper.connection.Close(); return id; private void button1_Click(object sender, EventArgs e) string name =textBox1 。Text ; string writter=textBox2 。Text ; string publisher = comboBox1。Text; string type=comboBox2.Text; string price = textBox4.Text; /string id = textBox5。Text; string typeid = typdid(type); string publisherid = publisheid(publisher); string bianhao = textBox3。Text; try if (bianhao!=”name != ” &writter != ” & publisher!= ” & type != price != ”) Dbhelper。connection。Open(); string sql = string.Format(insert into book (BOOKID,bookname,bookwritter,publisherid,booktypeid,bookprice) values (0,1,2,3,4,5)”,bianhao, name,writter ,publisherid,typeid,price); SqlCommand commmand = new SqlCommand(sql,Dbhelper.connection ); int ab =commmand.ExecuteNonQuery(); if (ab != 0) MessageBox。Show(保存成功, 保存); else MessageBox。Show(”添加失败”); return; else if (name = ” | writter = ” | publisher = ” | type= ” price= ”) MessageBox .Show(请输入所有信息,”错误,MessageBoxButtons 。OK , MessageBoxIcon 。Error ); catch /(exception ex) MessageBox。Show(操作数据库出错”, 提示, MessageBoxButtons.OK, MessageBoxIcon.Information); finally Dbhelper.connection。Close(); private void button3_Click(object sender, EventArgs e) this。Close(); 添加读者信息界面: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 addreader : Form public addreader() InitializeComponent(); /退出窗口 private void button3_Click(object sender, EventArgs e) /Application.Exit(); this。Close(); /清除所有内容 private void button1_Click(object sender, EventArgs e) textBox1。Text = null; textBox2。Text = null; textBox4.Text = null; textBox3.Text = null; textBox5.Text = null; comboBox1。Text = null; comboBox2.Text = null; private void button2_Click(object sender, EventArgs e) /连接数据库 /定义变量 string name =textBox1 。Text ; string age=textBox2 。Text ; string sex = comboBox1。Text; string studentId=textBox3。Text; string dept = textBox4.Text; string zhuanye= textBox5.Text; string maxnumber = comboBox2。Text; string pass = textBox6.Text; try if (name != ” & age != & sex != ” & studentId != & dept != ” & zhuanye != ” & maxnumber!= &pass!=”) Dbhelper.connection.Open(); string sql = string.Format(”insert into reader (readerid,readerpass,readername,readersex,readerage,readerdept,readerzhuanye,maxnumber) values (0,1,2,3,4,5,6,7), studentId, pass,name, sex, age, dept, zhuanye, maxnumber); SqlCommand commmand = new SqlCommand(sql,Dbhelper.connection ); int ab = commmand。ExecuteNonQuery(); if (ab != 0) MessageBox.Show(”保存成功”, ”保存); else MessageBox。Show(”添加失败”); return; else if (name = ” | age = ” | sex = ” studentId = ” dept=” | zhuanye = ” maxnumber = ”) MessageBox 。Show(请输入所有学生信息”,”错误”,MessageBoxButtons .OK , MessageBoxIcon .Error ); catch /(exception ex)
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 生活休闲 > 励志创业


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!