图书馆管理信息系统界面与代码.doc_第1页
图书馆管理信息系统界面与代码.doc_第2页
图书馆管理信息系统界面与代码.doc_第3页
图书馆管理信息系统界面与代码.doc_第4页
图书馆管理信息系统界面与代码.doc_第5页
已阅读5页,还剩24页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

- 29 -图书馆管理信息系统界面与代码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 图书馆管理信息系统 public partial class frmLogin : Form public frmLogin() InitializeComponent(); private void btnLogin_Click(object sender, EventArgs e) try if (txtUserName.Text = ) /判断用户是否输入了用户名 MessageBox.Show(用户名不能为空); else if (txtPwd.Text = ) MessageBox.Show(密码不能为空); /判断用户是否输入了密码 else SqlConnection con = DBCon.createCon();/创建数据库连接 con.Open(); SqlCommand cmd = new SqlCommand(select count(*)from Users where UserName= + txtUserName.Text + and UserPwd= + txtPwd.Text + , con); int i = Convert.ToInt32(cmd.ExecuteScalar(); /获取返回值 if (i 0) if (cmbLogin.Text = ) MessageBox.Show(请选择登录界面); cmbLogin.Focus(); return; else if (cmbLogin.Text = 普通用户使用界面) frmMain main = new frmMain(); main.adminname = txtUserName.Text; main.admintime = DateTime.Now.ToShortDateString(); main.Show(); this.Hide();/隐藏登录窗体 else ptMain ptmain = new ptMain(); ptmain.adminname = txtUserName.Text; ptmain.Show(); this.Hide(); else MessageBox.Show(用户名或者密码错误!); /弹出提示 catch (Exception ex) MessageBox.Show(ex.ToString(); private void btnCancel_Click(object sender, EventArgs e) this.Close(); private void txtPwd_KeyPress(object sender, KeyPressEventArgs e) if (e.KeyChar = 13) /判断是否按下Enter键 btnLogin_Click(sender, e); /调用“登录”按钮的Click事件 DBCon.csusing System;using System.Collections.Generic;using System.Text;using System.Data.SqlClient;namespace 图书馆管理信息系统 class DBCon public static SqlConnection createCon() /SqlConnection con = new SqlConnection(server=yyw;database=LibDB;uid=sa;pwd= ); SqlConnection con = new SqlConnection(workstation id=-localhost;Integrated Security=SSPI;database=LibDB); return con; using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace 图书馆管理信息系统 public partial class ptMain : Form public ptMain() InitializeComponent(); public string adminname; private void ptMain_Load(object sender, EventArgs e) toolStripStatusLabel2.Text = adminname; toolStripStatusLabel5.Text = DateTime.Now.ToString(); private bool checkChildFrmExist(string childFrmName) foreach (Form childFrm in this.MdiChildren) /用子窗体的Name进行判断,如果存在则将他激活 if (childFrm.Name = childFrmName) if (childFrm.WindowState = FormWindowState.Minimized) childFrm.WindowState = FormWindowState.Normal; childFrm.Activate(); return true; return false; private void toolStripMenuItem1_Click(object sender, EventArgs e) if (MessageBox.Show(确定退出本系统吗?, 提示, MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk) = DialogResult.OK) this.Close(); /退出系统 /-显示读者信息设置窗体- private void 读者信息查询ToolStripMenuItem_Click(object sender, EventArgs e) /通过窗体名称查询该窗体是否已经存在,如存在则显示,否则就新创建一个 if (this.checkChildFrmExist(readerInfo) = true) return; readerInfo readerinfo = new readerInfo(); readerinfo.MdiParent = this; readerinfo.Show(); /-显示图书信息设置窗体- private void 图书信息增删ToolStripMenuItem_Click(object sender, EventArgs e) /通过窗体名称查询该窗体是否已经存在,如存在则显示,否则就新创建一个 if (this.checkChildFrmExist(bookInfo) = true) return; bookInfo bookinfo = new bookInfo(); bookinfo.MdiParent = this; bookinfo.Show(); /-显示图书超期通知窗体- private void 图书超期通知ToolStripMenuItem_Click(object sender, EventArgs e) /通过窗体名称查询该窗体是否已经存在,如存在则显示,否则就新创建一个 if (this.checkChildFrmExist(bookOverDate) = true) return; bookOverDate bookoverdate = new bookOverDate(); bookoverdate.MdiParent = this; bookoverdate.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 图书馆管理信息系统 public partial class readerInfo : Form public int flag; public string str; public readerInfo() InitializeComponent(); /-在DataGridView控件下面textBox控件显示内容- private void show() try this.textBox1.Text = this.dataGridView1.CurrentRow.Cells0.Value.ToString(); this.textBox2.Text = this.dataGridView1.CurrentRow.Cells1.Value.ToString(); this.textBox3.Text = this.dataGridView1.CurrentRow.Cells2.Value.ToString(); this.textBox4.Text = this.dataGridView1.CurrentRow.Cells3.Value.ToString(); this.textBox5.Text = this.dataGridView1.CurrentRow.Cells4.Value.ToString(); this.textBox6.Text = this.dataGridView1.CurrentRow.Cells5.Value.ToString(); this.textBox7.Text = this.dataGridView1.CurrentRow.Cells6.Value.ToString(); this.textBox8.Text = this.dataGridView1.CurrentRow.Cells7.Value.ToString(); this.textBox9.Text = this.dataGridView1.CurrentRow.Cells8.Value.ToString(); this.textBox10.Text =this.dataGridView1.CurrentRow.Cells9.Value.ToString(); catch (Exception ex) MessageBox.Show(不能对列进行排序); /-DataGridView控件随着选中行的不同,显示不同的内容- private void dataGridView1_SelectionChanged(object sender, EventArgs e) show(); /-让DataGridView交替显示行的不同的颜色- private void alternate() if (this.dataGridView1.Rows.Count != 0) for (int i = 0; i this.dataGridView1.Rows.Count; ) this.dataGridView1.Rowsi.DefaultCellStyle.BackColor = System.Drawing.Color.Pink; i += 2; private void readerInfo_Load(object sender, EventArgs e) SqlConnection con = DBCon.createCon(); SqlDataAdapter sda=new SqlDataAdapter(select ReaderId as 读者ID,Name as 姓名,Pwdas 密码,Sexas 性别,Position as 职别,Unit as 单位,Majoras 专业,Class as 班级,Tel as 电话,Addressas 地址 from Reader ,con); DataSet ds = new DataSet(); sda.Fill(ds,table); this.dataGridView1.DataSource = ds.Tables0.DefaultView; show(); /-工具栏事务处理- private void toolBar1_ButtonClick(object sender, ToolBarButtonClickEventArgs e) if (e.Button.ToolTipText= 首记录) alternate(); this.dataGridView1.ClearSelection(); this.dataGridView1.Rows0.Selected = true; this.dataGridView1.CurrentCell =dataGridView10, 0; show(); if (e.Button.ToolTipText = 上一记录) alternate(); int row = this.dataGridView1.CurrentCell.RowIndex; if (this.dataGridView1.CurrentCell.RowIndex= 0) this.dataGridView1.ClearSelection(); /取消原选中的行 this.dataGridView1.Rows0.Selected = true; /选中当前行 this.dataGridView1.CurrentCell = dataGridView10,0; /设置当前行的行指针 else this.dataGridView1.ClearSelection(); this.dataGridView1.Rowsrow - 1.Selected = true; this.dataGridView1.CurrentCell = dataGridView10,row-1; show(); return; if (e.Button.ToolTipText = 下一记录) alternate(); int row = this.dataGridView1.CurrentCell.RowIndex; if (this.dataGridView1.CurrentCell.RowIndex=this.dataGridView1.Rows.Count-1) this.dataGridView1.ClearSelection(); this.dataGridView1.Rowsrow.Selected = true; this.dataGridView1.CurrentCell = dataGridView10, row; else this.dataGridView1.ClearSelection(); this.dataGridView1.Rowsrow + 1.Selected = true; this.dataGridView1.CurrentCell = dataGridView10, row + 1; show(); return; if (e.Button.ToolTipText = 尾记录) alternate(); int row = this.dataGridView1.Rows.Count - 1; this.dataGridView1.ClearSelection(); this.dataGridView1.Rowsrow.Selected = true; this.dataGridView1.CurrentCell = dataGridView10, row; show(); return; if (e.Button.ToolTipText = 新增) this.textBox1.Enabled = true; if (str = this.textBox1.Text.ToString() != ) if (MessageBox.Show(您确定要新增本条记录吗?, 提示, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.Yes) flag = 1; MessageBox.Show(请输入读者ID并且按提交按钮,才能新增成功!); return; if (e.Button.ToolTipText =修改) if (str = this.textBox1.Text.ToString() != ) if (MessageBox.Show(您确定要修改本条记录吗?, 提示, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.Yes) flag = 2; MessageBox.Show(请按提交按钮,才能修改成功!); return; if (e.Button.ToolTipText = 删除) if (str = this.textBox1.Text.ToString() != ) if (MessageBox.Show(您确定要删除本条记录吗?, 提示, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.Yes) flag = 3; MessageBox.Show(请按提交按钮,才能删除成功!); return; if (e.Button.ToolTipText = 提交) if (flag = 1 ) SqlConnection con = DBCon.createCon(); con.Open(); /在原表中新建一个新行,然后再数据添加到新行中 SqlCommand cmd = new SqlCommand(insert into Reader values(ReaderId,Name,Pwd,Sex,Position,Unit,Major,Class,Tel,Address),con); cmd.Parameters.Add(ReaderId,SqlDbType.Char,10).Value = textBox1.Text; cmd.Parameters.Add(Name, SqlDbType.Char, 10).Value = textBox2.Text; cmd.Parameters.Add(Pwd, SqlDbType.Char, 20).Value = textBox3.Text; cmd.Parameters.Add(Sex, SqlDbType.Char, 2).Value = textBox4.Text; cmd.Parameters.Add(Position, SqlDbType.Char, 10).Value = textBox5.Text; cmd.Parameters.Add(Unit, SqlDbType.Char, 40).Value = textBox6.Text; cmd.Parameters.Add(Major, SqlDbType.Char, 20).Value = textBox7.Text; cmd.Parameters.Add(Class, SqlDbType.Char, 20).Value = textBox8.Text; cmd.Parameters.Add(Tel, SqlDbType.Char, 11).Value = textBox9.Text; cmd.Parameters.Add(Address, SqlDbType.Char, 30).Value = textBox10.Text; cmd.Connection = con; cmd.ExecuteNonQuery(); con.Close(); SqlDataAdapter sda = new SqlDataAdapter(select ReaderId as 读者ID,Name as 姓名,Pwdas 密码,Sexas 性别,Position as 职别,Unit as 单位,Majoras 专业,Class as 班级,Tel as 电话,Addressas 地址 from Reader , con); DataSet ds = new DataSet(); sda.Fill(ds, table); this.dataGridView1.DataSource = ds.Tables0.DefaultView; this.textBox1.Enabled = false; MessageBox.Show(新增记录成功!); try show(); catch (Exception ex) MessageBox.Show(没有记录显示!); flag = 0; if (flag = 2 & str != ) SqlConnection con = DBCon.createCon(); con.Open(); SqlCommand cmd = new SqlCommand(update Reader set Name= + textBox2.Text.ToString() + ,Pwd= + textBox3.Text.ToString() + ,Sex= + textBox4.Text.ToString() + ,Position= + textBox5.Text.ToString() + ,Unit= + textBox6.Text.ToString() + ,Major= + textBox7.Text.ToString() + ,Class= + textBox8.Text.ToString() + ,Tel= + textBox9.Text.ToString() + ,Address = + textBox10.Text.ToString() + where ReaderID= + str + , con); cmd.Connection = con; cmd.ExecuteNonQuery(); con.Close(); SqlDataAdapter sda = new SqlDataAdapter(select ReaderID as 读者ID,Name as 姓名,Pwd as 密码,Sex as 性别,Position as 职别,Unit as 单位,Major as 专业,Class as 班级,Tel as 电话,Addressas 地址 from Reader , con); DataSet ds = new DataSet(); sda.Fill(ds, table); this.dataGridView1.DataSource = ds.Tables0.DefaultView; try show(); catch (Exception ex) MessageBox.Show(没有记录显示!); MessageBox.Show(修改成功!); flag = 0; if (flag=3&str != ) SqlConnection con = DBCon.createCon(); con.Open(); SqlCommand cmd = new SqlCommand(delete from Reader where ReaderID=+str+,con); cmd.Connection = con; cmd.ExecuteNonQuery(); con.Close(); SqlDataAdapter sda=new SqlDataAdapter(select ReaderId as 读者ID,Name as 姓名,Pwdas 密码,Sexas 性别,Position as 职别,Unit as 单位,Majoras 专业,Class as 班级,Tel as 电话,Addressas 地址 from Re

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论