学号:200318070147
二零零四年十二月二十一日
一、实训课题
1、课题名称:
图书馆信息管理系统。
2、设计要求:
设计一个简单的《图书馆信息管理系统》计算机软件。
本系统为某学院图书馆实现图信息管理计算机化而设计。该学院图书馆现有藏书20万册,每天图书流量在500册左右。本系统要求实现该馆图书信息的计算机管理,它应当包括如下基本功能:系统登录、书目索引查询、借出管理、还书管理、图书信息录入、读者信息录入和用户信息录入等。
二、程序功能图
三、数据库设计
字段名 编号 书名 类别 作者 出版社 价格 库存数 在库数
数值类型 文本 文本 文本 文本 文本 货币 长整型 长整型
数据宽度 20 30 20 20 20 8 20 20
是否能为空 否 否 否 否 否 否 否 否
是否主键 是 否 否 否 否 否 否 否
字段名 编号 姓名 性别 单位 手机 电子邮箱 ICQ OICQ
数值类型 文本 文本 文本 文本 文本 文本 文本 文本
数据宽度 10 5 1 30 20 30 20 20
是否能为空 否 否 否 是 是 是 是 是
是否主键 是 否 否 否 否 否 否 否
字段名 用户名 密码 姓名 性别 手机 办公地址 ICQ OICQ 电子邮箱
数值类型 文本 文本 文本 文本 文本 文本 文本 文本 文本
数据宽度 20 20 5 1 20 50 20 20 30
是否能为空 否 否 否 否 是 是 是 是 是
是否主键 是 否 否 否 否 否 否 否 否
字段名 编号 读者编号 图书编号 借书日期
数值类型 长整型 文本 文本 日期时间型
数据宽度 8 10 20 8
是否能为空 否 否 否 否
是否主键 是 否 否 否
四、程序界面
五、程序代码
主窗体代码
... {
Process[] processes;
int count=0;
processes=Process.GetProcesses();
foreach(Process instance in processes)
...{
if(instance.ProcessName=="图书馆信息管理系统")
count++;
}
if(count>1) //如果图书馆信息管理系统已经运行,就退出。
...{
this.Close();
}
this.menuItemdzgl.Enabled=false;
this.menuItemtsgl.Enabled=false;
this.menuItemjshs.Enabled=false;
this.menuItemyggl.Enabled=false;
this.menuItemaq.Enabled=false;
this.menuItembz.Enabled=false;
this.menuItemjs.Enabled=false;
this.menuItemhs.Enabled=false;
this.menuItemsd.Enabled=false;
this.toolBarButton5.Visible=false;
dlWin MyDl=new dlWin();
if( MyDl.ShowDialog() ==DialogResult.Yes)
...{
if( MyDl.SystemAdministrator) //登录成功再判断是为管理员还是为员工
...{
this.menuItemdzgl.Enabled=true;
this.menuItemtsgl.Enabled=true;
this.menuItemjshs.Enabled=true;
this.menuItemyggl.Enabled=true;
this.menuItemaq.Enabled=true;
this.menuItembz.Enabled=true;
this.menuItemjs.Enabled=true;
this.menuItemhs.Enabled=true;
this.menuItemsd.Enabled=true;
this.menuItemdzzc.Enabled=true;
this.menuItemxxxg.Enabled=true;
this.menuItemdzzx.Enabled=true;
this.menuItemtjts.Enabled=true;
this.menuItemscts.Enabled=true;
this.menuItemjlxg.Enabled=true;
this.menuItemzjyg.Enabled=true;
this.menuItemscyg.Enabled=true;
this.menuItemcxyg.Enabled=true;
this.menuItemzlxg.Enabled=true;
this.toolBarButton5.Visible=true;
}
else
...{
MessageBox.Show("非系统管理员,功能将受到限制.","登录提示:”,MessageBoxButtons.OK,MessageBoxIcon.Information);
this.menuItemdzgl.Enabled=true;
this.menuItemtsgl.Enabled=true;
this.menuItemjshs.Enabled=true;
this.menuItemyggl.Enabled=true;
this.menuItemaq.Enabled=true;
this.menuItembz.Enabled=true;
this.menuItemjs.Enabled=true;
this.menuItemhs.Enabled=true;
this.menuItemsd.Enabled=true;
this.menuItemdzzc.Enabled=false;
this.menuItemxxxg.Enabled=false;
this.menuItemdzzx.Enabled=false;
this.menuItemtjts.Enabled=false;
this.menuItemscts.Enabled=false;
this.menuItemjlxg.Enabled=false;
this.menuItemzjyg.Enabled=false;
this.menuItemscyg.Enabled=false;
this.menuItemcxyg.Enabled=false;
this.menuItemzlxg.Enabled=false;
}
}
Else //否则登录失败,退出。
...{
MessageBox.Show("登录失败,请证实你的用户名和密码后再登录!!!","登录提示:",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.Close();
}
}
登录窗体代码
... {
try
...{
System.Data.OleDb.OleDbCommand MySelectYh = this.oleDbConnection1.CreateCommand();
System.Data.OleDb.OleDbCommand MySelectXt = this.oleDbConnection1.CreateCommand();
MySelectYh.CommandText = "SELECT * FROM ygxxb WHERE 用户名='"+this.textBox1.Text+"' AND 密码='"+this.textBox2.Text+"'";
MySelectXt.CommandText = "SELECT * FROM ygxxb WHERE 系统管理员='是'and 用户名='"+this.textBox1.Text+"'";
this.oleDbDataAdapter1.SelectCommand = MySelectYh;
this.oleDbConnection1.Open();
if( oleDbDataAdapter1.Fill(this.dataSet21,"ygxxb") == 0)
...{
Dlcs++;
if( Dlcs>=3)
...{
this.DialogResult = DialogResult.No;
}
else
...{
MessageBox.Show("用户名或密码错误!你已经登录"+Dlcs.ToString()+"次.","登录提示:",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
}
}
else
...{
this.oleDbDataAdapter1.SelectCommand = MySelectXt;
if( oleDbDataAdapter1.Fill(this.dataSet21,"ygxxb")==0 )
this.ifSyAd=false;
else
this.ifSyAd=true;
this.DialogResult = DialogResult.Yes;
this.Close();
}
this.oleDbConnection1.Close();
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.Close();
}
}
private void textBox1_TextChanged( object sender, System.EventArgs e)
... {
if(this.textBox1.Text != "" || this.textBox2.Text != "")
...{
this.button2.Text="重填";
}
else
...{
this.button2.Text="退出";
}
}
private void textBox2_TextChanged( object sender, System.EventArgs e)
... {
this.textBox1_TextChanged(null,null);
}
private void button2_Click( object sender, System.EventArgs e)
... {
if(this.button2.Text=="重填")
...{
this.textBox1.Text="";
this.textBox2.Text="";
this.textBox1.Focus();
}
else
...{
if( MessageBox.Show("你还没登录就要退出吗?","登录提示:",MessageBoxButtons.OKCancel,MessageBoxIcon.Question) == DialogResult.OK)
...{
this.DialogResult=DialogResult.No;
this.Close();
}
}
}
private void textBox1_KeyDown( object sender, System.Windows.Forms.KeyEventArgs e) // 光标按键
... {
int Key=(int)e.KeyCode;
switch(Key)
...{
case 27: //按了Esc
if( MessageBox.Show("你还没登录就要退出吗?","登录提示:",MessageBoxButtons.OKCancel,MessageBoxIcon.Question) == DialogResult.OK)
...{
this.DialogResult=DialogResult.No;
this.Close();
}
break;
case 13: //按Enter
this.button1_Click(null,null);
break;
case 38: //按了向上和向左光标键
case 37:
if( this.textBox1.Focused)
...{
this.button2.Focus();
}
else
...{
if( this.button2.Focused)
...{
this.button1.Focus();
}
else
...{
if( this.button1.Focused)
...{
this.textBox2.Focus();
}
else
...{
if( this.textBox2.Focused)
...{
this.textBox1.Focus();
}
}
}
}
break;
case 40: //按了向下或向右光标键
case 39:
if( this.textBox1.Focused)
...{
this.textBox2.Focus();
}
else
...{
if( this.textBox2.Focused)
...{
this.button1.Focus();
}
}
break;
}
}
private void textBox2_KeyDown( object sender, System.Windows.Forms.KeyEventArgs e)
... {
this.textBox1_KeyDown(null,e);
}
private void dlWin_Load( object sender, System.EventArgs e)
... {
this.textBox1.Focus();
}
读者查询窗体代码
... { //更新按钮,实现更新。
try
...{
this.dataSet21.Clear();
System.Data.OleDb.OleDbCommand MySelect = this.oleDbConnection1.CreateCommand();
MySelect.CommandText = "SELECT * FROM dzxxb";
this.oleDbDataAdapter1.SelectCommand = MySelect;
this.oleDbConnection1.Open();
this.oleDbDataAdapter1.Fill(this.dataSet21,"dzxxb");
this.oleDbConnection1.Close();
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
private void button2_Click( object sender, System.EventArgs e)
... { //查看按钮,实现查看。
try
...{
this.oleDbConnection1.Open();
this.oleDbDataAdapter1.Fill(this.dataSet21,"dzxxb");
this.oleDbConnection1.Close();
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
private void button3_Click( object sender, System.EventArgs e)
... { //返回按钮,关闭当前窗口。
this.Close();
}
private void button5_Click( object sender, System.EventArgs e)
... { //返回按钮,关闭当前窗口。
this.Close();
}
private void button4_Click( object sender, System.EventArgs e)
... { //按编号查询按钮,实现按编号查询。
try
...{
System.Data.OleDb.OleDbCommand MySelect = this.oleDbConnection1.CreateCommand();
MySelect.CommandText = "SELECT * FROM dzxxb WHERE 编号='"+this.textBox1.Text+"'";
this.oleDbDataAdapter1.SelectCommand = MySelect;
this.dataSet21.Clear();
this.oleDbConnection1.Open();
this.oleDbDataAdapter1.Fill(this.dataSet21,"dzxxb");
this.oleDbConnection1.Close();
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
private void button5_KeyDown( object sender, System.Windows.Forms.KeyEventArgs e)
... { //同上,按键处理。
switch((int)e.KeyCode)
...{
case 13:
button4_Click(null,null);
break;
case 27:
this.Close();
break;
case 38:
case 37:
if(this.button5.Focused)
...{
this.button4.Focus();
}
else
...{
if(this.button4.Focused)
...{
this.textBox1.Focus();
}
else
...{
if(this.textBox1.Focused)
...{
this.button5.Focus();
}
}
}
break;
case 40:
case 39:
if(this.textBox1.Focused)
...{
this.button4.Focus();
}
else
...{
if(this.button4.Focused)
...{
this.button5.Focus();
}
else
...{
if(this.button5.Focused)
...{
this.textBox1.Focus();
}
}
}
break;
}
}
private void button7_Click( object sender, System.EventArgs e)
... { //返回按钮,关闭当前窗口。
this.Close();
}
private void button6_Click( object sender, System.EventArgs e)
... { //按姓名查询按钮,实现按姓名查找。
try
...{
System.Data.OleDb.OleDbCommand MySelect = this.oleDbConnection1.CreateCommand();
MySelect.CommandText = "SELECT * FROM dzxxb WHERE 姓名='"+this.textBox2.Text+"'";
this.oleDbDataAdapter1.SelectCommand = MySelect;
this.dataSet21.Clear();
this.oleDbConnection1.Open();
this.oleDbDataAdapter1.Fill(this.dataSet21,"dzxxb");
this.oleDbConnection1.Close();
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
private void textBox2_KeyDown( object sender, System.Windows.Forms.KeyEventArgs e)
... { //同上,按键处理。
switch((int)e.KeyCode)
...{
case 13:
button6_Click(null,null);
break;
case 27:
this.Close();
break;
case 38:
case 37:
if(this.button7.Focused)
...{
this.button6.Focus();
}
else
...{
if(this.button6.Focused)
...{
this.textBox2.Focus();
}
else
...{
if(this.textBox2.Focused)
...{
this.button7.Focus();
}
}
}
break;
case 40:
case 39:
if(this.textBox2.Focused)
...{
this.button6.Focus();
}
else
...{
if(this.button6.Focused)
...{
this.button7.Focus();
}
else
...{
if(this.button7.Focused)
...{
this.textBox2.Focus();
}
}
}
break;
}
}
private void dzcx_Activated( object sender, System.EventArgs e)
... { //每次成为当前窗使用按钮一成为焦点按钮。
this.button1.Focus();
}
读者注消窗体代码
... { //根据用户所提供条件查询,越祥细查找越准确。
string ComStr="";
try
...{
System.Data.OleDb.OleDbCommand MySelect = this.oleDbConnection1.CreateCommand();
if( this.textBox1.Text != "")
...{
ComStr="SELECT * FROM dzxxb WHERE 编号='"+this.textBox1.Text+"'";
}
else
...{
if(this.textBox2.Text != "")
...{
if( ComStr == "")
...{
ComStr="SELECT * FROM dzxxb WHERE 姓名='"+this.textBox2.Text+"'";
}
else
...{
ComStr+=" AND 姓名='"+this.textBox2.Text+"'";
}
}
if(this.textBox3.Text != "")
...{
if(ComStr == "")
...{
ComStr="SELECT * FROM dzxxb WHERE 手机='"+this.textBox3.Text+"'";
}
else
...{
ComStr+=" AND 手机='"+this.textBox3.Text+"'";
}
}
if(ComStr=="")
...{
MessageBox.Show("无查询条件,默认查找所有记录.","查找提示: ",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
ComStr="SELECT * FROM dzxxb";
}
}
MySelect.CommandText=ComStr;
this.oleDbDataAdapter1.SelectCommand=MySelect;
this.dataSet21.Clear();
this.oleDbConnection1.Open();
this.oleDbDataAdapter1.Fill(dataSet21,"dzxxb");
this.oleDbConnection1.Close();
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
private void button4_Click( object sender, System.EventArgs e)
... { //返回按钮,关闭当前窗口。
this.Close();
}
private void button3_Click( object sender, System.EventArgs e)
... { //更新按钮,更新当前数据。
try
...{
System.Data.OleDb.OleDbCommand MySelect = this.oleDbConnection1.CreateCommand();
MySelect.CommandText="SELECT * FROM dzxxb";
this.oleDbDataAdapter1.SelectCommand=MySelect;
this.dataSet21.Clear();
this.oleDbConnection1.Open();
this.oleDbDataAdapter1.Fill(this.dataSet21,"dzxxb");
this.oleDbConnection1.Close();
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
private void button2_Click( object sender, System.EventArgs e)
... { //删除按钮,请用户确认删除当前记录。
try
...{
int ReN = this.dataGrid1.CurrentRowIndex;
if(ReN == -1)
...{
MessageBox.Show("当前没有记录可以删除!!!","删除提示:",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
else
...{
string BH=dataSet21.Tables["dzxxb"].Rows[ReN]["编号"].ToString();
System.Data.OleDb.OleDbCommand MyDel=this.oleDbConnection1.CreateCommand();
MyDel.CommandText="DELETE * FROM dzxxb WHERE 编号='"+BH+"'";
this.oleDbDataAdapter1.DeleteCommand=MyDel;
if(MessageBox.Show("删除是不可恢复的,真的要删除吗?","删除提示:",MessageBoxButtons.YesNo,MessageBoxIcon.Exclamation) == DialogResult.Yes)
...{
this.oleDbConnection1.Open();
MyDel.ExecuteNonQuery();
this.oleDbConnection1.Close();
button3_Click(null,null);
}
}
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
private void textBox3_KeyDown( object sender, System.Windows.Forms.KeyEventArgs e)
... { //同上,按键处理。
switch((int)e.KeyCode)
...{
case 27:
this.Close();
break;
case 13:
if(this.button1.Focused || this.textBox1.Focused || this.textBox2.Focused || this.textBox3.Focused)
...{
button1_Click(null,null);
}
if(this.button2.Focused)
...{
button2_Click(null,null);
}
if(this.button3.Focused)
...{
button3_Click(null,null);
}
if(this.button4.Focused)
...{
this.Close();
}
break;
case 38:
case 37:
if(this.textBox3.Focused)
...{
this.textBox2.Focus();
}
else
...{
if(this.textBox2.Focused)
...{
this.textBox1.Focus();
}
else
...{
if(this.textBox1.Focused)
...{
this.textBox3.Focus();
}
}
}
break;
case 40:
case 39:
if(this.textBox1.Focused)
...{
this.textBox2.Focus();
}
else
...{
if(this.textBox2.Focused)
...{
this.textBox3.Focus();
}
else
...{
if(this.textBox3.Focused)
...{
this.textBox1.Focus();
}
}
}
break;
}
}
private void textBox3_TextChanged( object sender, System.EventArgs e)
... { //手机号只为以数字,不允许用户输入非数字。
string s="";
for(int i=0;i
if(Char.IsDigit(textBox3.Text[i])==true)
s=s+textBox3.Text[i].ToString();
textBox3.Text=s;
textBox3.SelectionStart=textBox3.Text.Length;
}
private void dataGrid1_DoubleClick( object sender, System.EventArgs e)
... { //双击当前记录,调用删除按钮。
button2_Click(null,null);
}
读者注册窗体代码
... { //指定焦点。
this.textBox1.Focus();
}
private void button3_Click( object sender, System.EventArgs e)
... { //返回按钮。
this.Close();
}
private void button2_Click( object sender, System.EventArgs e)
... { //重填按钮。
this.textBox1.Text="";
this.textBox2.Text="";
this.textBox3.Text="";
this.textBox4.Text="";
this.textBox5.Text="";
this.textBox6.Text="";
this.textBox7.Text="";
this.textBox1.Focus();
}
private void button1_Click( object sender, System.EventArgs e)
... { //注册按钮,实现注册。
try
...{
System.Data.OleDb.OleDbCommand MySelect = this.oleDbConnection1.CreateCommand();
MySelect.CommandText="SELECT * FROM dzxxb WHERE 编号='"+this.textBox1.Text+"'";
this.oleDbDataAdapter1.SelectCommand=MySelect;
if(this.textBox1.Text=="")
...{
MessageBox.Show("编号不能为空,请输入编号!","输入提示:",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.textBox1.Focus();
}
else
...{
if(this.textBox2.Text=="")
...{
MessageBox.Show("姓名不能为空,请输入姓名!","输入提示:",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.textBox2.Focus();
}
else
...{
this.oleDbConnection1.Open();
int If=this.oleDbDataAdapter1.Fill(this.dataSet21,"dzxxb");
this.oleDbConnection1.Close();
if(If!=0)
...{
MessageBox.Show("该编号已经存在,请输入另外编号!","输入提示:",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.textBox1.Focus();
}
else
...{
string xb;
if(this.radioButton1.Checked)
xb="男";
else
xb="女";
System.Data.OleDb.OleDbCommand MyInsert = this.oleDbConnection1.CreateCommand();
MyInsert.CommandText="INSERT INTO dzxxb (编号,姓名,性别,单位,手机,电子邮箱,ICQ,OICQ) VALUES ('"+this.textBox1.Text+"','"+this.textBox2.Text+"','"+xb+"','"+this.textBox3.Text+"','"+this.textBox4.Text+"','"+this.textBox5.Text+"','"+this.textBox6.Text+"','"+this.textBox7.Text+"')";
this.oleDbDataAdapter1.InsertCommand=MyInsert;
this.oleDbConnection1.Open();
MyInsert.ExecuteNonQuery();
this.oleDbConnection1.Close();
MessageBox.Show("读者注册成功!!!","员工添加提示:",MessageBoxButtons.OK,MessageBoxIcon.Asterisk);
this.textBox1.Text="";
this.textBox2.Text="";
this.textBox3.Text="";
this.textBox4.Text="";
this.textBox5.Text="";
this.textBox6.Text="";
this.textBox7.Text="";
this.textBox1.Focus();
}
}
}
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
private void textBox3_KeyDown( object sender, System.Windows.Forms.KeyEventArgs e)
... { //同上,按键处理。
switch((int)e.KeyCode)
...{
case 27:
this.Close();
break;
case 13:
if(this.button2.Focused)
...{
button2_Click(null,null);
}
else
...{
if(this.button3.Focused)
...{
this.Close();
}
else
...{
this.button1_Click(null,null);
}
}
break;
case 38:
case 37:
if(this.textBox7.Focused)
...{
this.textBox6.Focus();
}
else
...{
if(this.textBox6.Focused)
...{
this.textBox5.Focus();
}
else
...{
if(this.textBox5.Focused)
...{
this.textBox4.Focus();
}
else
...{
if(this.textBox4.Focused)
...{
this.textBox3.Focus();
}
else
...{
if(this.textBox3.Focused)
...{
this.textBox2.Focus();
}
else
...{
if(this.textBox2.Focused)
...{
this.textBox1.Focus();
}
else
...{
if(this.textBox1.Focused)
...{
this.textBox7.Focus();
}
}
}
}
}
}
}
break;
case 40:
case 39:
if(this.textBox1.Focused)
...{
this.textBox2.Focus();
}
else
...{
if(this.textBox2.Focused)
...{
this.textBox3.Focus();
}
else
...{
if(this.textBox3.Focused)
...{
this.textBox4.Focus();
}
else
...{
if(this.textBox4.Focused)
...{
this.textBox5.Focus();
}
else
...{
if(this.textBox5.Focused)
...{
this.textBox6.Focus();
}
else
...{
if(this.textBox6.Focused)
...{
this.textBox7.Focus();
}
else
...{
if(this.textBox7.Focused)
...{
this.textBox1.Focus();
}
}
}
}
}
}
}
break;
}
}
private void textBox4_TextChanged( object sender, System.EventArgs e)
... { //只允许用户输入数字。
string s="";
for(int i=0;i
if(Char.IsDigit(textBox4.Text[i])==true)
s=s+textBox4.Text[i].ToString();
textBox4.Text=s;
textBox4.SelectionStart=textBox4.Text.Length;
}
private void textBox6_TextChanged( object sender, System.EventArgs e)
... { //只允许用户输入数字。
string s="";
for(int i=0;i
if(Char.IsDigit(textBox6.Text[i])==true)
s=s+textBox6.Text[i].ToString();
textBox6.Text=s;
textBox6.SelectionStart=textBox6.Text.Length;
}
private void textBox7_TextChanged( object sender, System.EventArgs e)
... { //只允许用户输入数字。
string s="";
for(int i=0;i
if(Char.IsDigit(textBox7.Text[i])==true)
s=s+textBox7.Text[i].ToString();
textBox7.Text=s;
textBox7.SelectionStart=textBox7.Text.Length;
}
}
读者信息修改窗体代码
... { //返回按钮。
this.Close();
}
private void button1_Click( object sender, System.EventArgs e)
... { //据据用户提供的信息查询记录,越祥细越准确。
string ComStr="";
try
...{
System.Data.OleDb.OleDbCommand MySelect = this.oleDbConnection1.CreateCommand();
if( this.textBox1.Text != "")
...{
ComStr="SELECT * FROM dzxxb WHERE 编号='"+this.textBox1.Text+"'";
}
else
...{
if(this.textBox2.Text != "")
...{
if(ComStr=="")
...{
ComStr="SELECT * FROM dzxxb WHERE 姓名='"+this.textBox2.Text+"'";
}
else
...{
ComStr+=" AND 姓名='"+this.textBox2.Text+"'";
}
}
if(this.textBox3.Text != "")
...{
if(ComStr=="")
...{
ComStr="SELECT * FROM dzxxb WHERE 手机='"+this.textBox3.Text+"'";
}
else
...{
ComStr+=" AND 手机='"+this.textBox3.Text+"'";
}
}
if(ComStr=="")
...{
MessageBox.Show("无查询条件,默认查找所有记录.","查找提示: ",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
ComStr="SELECT * FROM dzxxb";
}
}
MySelect.CommandText=ComStr;
this.oleDbDataAdapter1.SelectCommand=MySelect;
this.dataSet21.Clear();
this.oleDbConnection1.Open();
this.oleDbDataAdapter1.Fill(dataSet21,"dzxxb");
this.oleDbConnection1.Close();
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
private void button2_Click( object sender, System.EventArgs e)
... { //更新按钮,更新当前记录。
try
...{
System.Data.OleDb.OleDbCommand MySelect = this.oleDbConnection1.CreateCommand();
MySelect.CommandText="SELECT * FROM dzxxb";
this.oleDbDataAdapter1.SelectCommand=MySelect;
this.dataSet21.Clear();
this.oleDbConnection1.Open();
this.oleDbDataAdapter1.Fill(this.dataSet21,"dzxxb");
this.oleDbConnection1.Close();
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
private void button3_Click( object sender, System.EventArgs e)
... { //保存按钮,保存记录信息。
try
...{
this.oleDbConnection1.Open();
this.oleDbDataAdapter1.Update(this.dataSet21,"dzxxb");
this.oleDbConnection1.Close();
MessageBox.Show("信息已经保存.","保存提示:",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.dataSet21.Clear();
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
private void button2_KeyDown( object sender, System.Windows.Forms.KeyEventArgs e)
... { //同上,按键处理。
switch((int)e.KeyCode)
...{
case 27:
this.Close();
break;
case 13:
if(this.button1.Focused || this.textBox1.Focused || this.textBox2.Focused || this.textBox3.Focused)
...{
button1_Click(null,null);
}
if(this.button2.Focused)
...{
button2_Click(null,null);
}
if(this.button3.Focused)
...{
button3_Click(null,null);
}
if(this.button4.Focused)
this.Close();
break;
case 38:
case 37:
if(this.textBox3.Focused)
...{
this.textBox2.Focus();
}
else
...{
if(this.textBox2.Focused)
...{
this.textBox1.Focus();
}
else
...{
if(this.textBox1.Focused)
...{
this.textBox3.Focus();
}
}
}
break;
case 40:
case 39:
if(this.textBox1.Focused)
...{
this.textBox2.Focus();
}
else
...{
if(this.textBox2.Focused)
...{
this.textBox3.Focus();
}
else
...{
if(this.textBox3.Focused)
...{
this.textBox1.Focus();
}
}
}
break;
}
}
private void textBox3_TextChanged( object sender, System.EventArgs e)
... { //只允许用户输入数字数据。
string s="";
for(int i=0;i
if(Char.IsDigit(textBox3.Text[i])==true)
s=s+textBox3.Text[i].ToString();
textBox3.Text=s;
textBox3.SelectionStart=textBox3.Text.Length;
}
书目查询窗口代码
... { //查找所有记录。
System.Data.OleDb.OleDbCommand MySelect = this.oleDbConnection1.CreateCommand();
MySelect.CommandText="SELECT * FROM tsxxb";
this.oleDbDataAdapter1.SelectCommand=MySelect;
this.dataSet21.Clear();
try
...{
this.oleDbConnection1.Open();
this.oleDbDataAdapter1.Fill(this.dataSet21,"tsxxb");
this.oleDbConnection1.Close();
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
private void button2_Click( object sender, System.EventArgs e)
... { //清空数据。
this.dataSet21.Clear();
}
private void button4_Click( object sender, System.EventArgs e)
... { //返回按钮。
this.Close();
}
private void button1_Click( object sender, System.EventArgs e)
... { //根据用户输入信息查询相应记录。
string ComStr="";
try
...{
System.Data.OleDb.OleDbCommand MySelect = this.oleDbConnection1.CreateCommand();
if(this.textBox1.Text != "")
...{
ComStr="SELECT * FROM tsxxb WHERE 编号='"+this.textBox1.Text+"'";
}
else
...{
if(this.textBox2.Text != "")
...{
if(ComStr == "")
...{
ComStr="SELECT * FROM tsxxb WHERE 书名='"+this.textBox2.Text+"'";
}
else
...{
ComStr+=" AND 书名='"+this.textBox2.Text+"'";
}
}
if(this.textBox3.Text != "")
...{
if(ComStr == "")
...{
ComStr="SELECT * FROM tsxxb WHERE 类别='"+this.textBox3.Text+"'";
}
else
...{
ComStr+=" AND 类别='"+this.textBox3.Text+"'";
}
}
if(this.textBox4.Text != "")
...{
if(ComStr == "")
...{
ComStr="SELECT * FROM tsxxb WHERE 作者='"+this.textBox4.Text+"'";
}
else
...{
ComStr+=" AND 作者='"+this.textBox4.Text+"'";
}
}
if(this.textBox5.Text != "")
...{
if(ComStr == "")
...{
ComStr="SELECT * FROM tsxxb WHERE 出版社='"+this.textBox5.Text+"'";
}
else
...{
ComStr+=" AND 出版社='"+this.textBox5.Text+"'";
}
}
if(ComStr == "")
...{
MessageBox.Show("无查询条件,默认查询所有记录.","查询提示:",MessageBoxButtons.OK,MessageBoxIcon.Information);
ComStr="SELECT * FROM tsxxb";
}
}
MySelect.CommandText=ComStr;
this.oleDbDataAdapter1.SelectCommand=MySelect;
this.dataSet21.Clear();
this.oleDbConnection1.Open();
this.oleDbDataAdapter1.Fill(dataSet21,"tsxxb");
this.oleDbConnection1.Close();
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
private void button4_KeyDown( object sender, System.Windows.Forms.KeyEventArgs e)
... { //按键处理。
switch((int)e.KeyCode)
...{
case 27:
this.Close();
break;
case 13:
if(this.button1.Focused || this.textBox1.Focused || this.textBox2.Focused || this.textBox3.Focused || this.textBox4.Focused || this.textBox5.Focused)
...{
button1_Click(null,null);
}
if(this.button2.Focused)
...{
button2_Click(null,null);
}
if(this.button3.Focused)
...{
button3_Click(null,null);
}
if(this.button4.Focused)
...{
this.Close();
}
break;
case 38:
case 37:
if(this.textBox5.Focused)
...{
this.textBox4.Focus();
}
else
...{
if(this.textBox4.Focused)
...{
this.textBox3.Focus();
}
else
...{
if(this.textBox3.Focused)
...{
this.textBox2.Focus();
}
else
...{
if(this.textBox2.Focused)
...{
this.textBox1.Focus();
}
else
...{
if(this.textBox1.Focused)
...{
this.textBox5.Focus();
}
}
}
}
}
break;
case 40:
case 39:
if(this.textBox5.Focused)
...{
this.textBox1.Focus();
}
else
...{
if(this.textBox1.Focused)
...{
this.textBox2.Focus();
}
else
...{
if(this.textBox2.Focused)
...{
this.textBox3.Focus();
}
else
...{
if(this.textBox3.Focused)
...{
this.textBox4.Focus();
}
else
...{
if(this.textBox4.Focused)
...{
this.textBox5.Focus();
}
}
}
}
}
break;
}
}
public void CXBH(jsgl V)
... { //为窗体间传递数据做准备。
V.textBox2.Text=BH;
}
private void smcx_Closing( object sender, System.ComponentModel.CancelEventArgs e)
... { //将当前记录的编号作为传递内容。
int ReN = this.dataGrid1.CurrentRowIndex;
if(ReN == -1)
...{
BH="";
}
else
...{
BH=dataSet21.Tables["tsxxb"].Rows[ReN]["编号"].ToString();
}
}
添加图书窗体代码
... { //查找该图书是否已存在。
System.Data.OleDb.OleDbCommand MySelect=this.oleDbConnection1.CreateCommand();
MySelect.CommandText="SELECT * FROM tsxxb WHERE 编号='"+this.textBox1.Text+"'";
this.oleDbDataAdapter1.SelectCommand=MySelect;
this.dataSet21.Clear();
try
...{
if(this.oleDbDataAdapter1.Fill(this.dataSet21,"tsxxb") !=0)
...{ //若存在,则只要输入购入数即可。
this.Exist=true;
this.textBox2.ReadOnly=true;
this.textBox3.ReadOnly=true;
this.textBox4.ReadOnly=true;
this.textBox5.ReadOnly=true;
this.textBox6.ReadOnly=true;
this.textBox2.Text=dataSet21.Tables["tsxxb"].Rows[0]["书名"].ToString();
this.textBox3.Text=dataSet21.Tables["tsxxb"].Rows[0]["类别"].ToString();
this.textBox4.Text=dataSet21.Tables["tsxxb"].Rows[0]["作者"].ToString();
this.textBox6.Text=dataSet21.Tables["tsxxb"].Rows[0]["出版社"].ToString();
this.textBox5.Text=dataSet21.Tables["tsxxb"].Rows[0]["价格"].ToString();
this.label10.Text=dataSet21.Tables["tsxxb"].Rows[0]["库存数"].ToString();
this.label11.Text=dataSet21.Tables["tsxxb"].Rows[0]["在库数"].ToString();
this.textBox7.Text="";
this.textBox7.Focus();
}
else
...{
this.Exist=false;
this.textBox2.ReadOnly=false;
this.textBox3.ReadOnly=false;
this.textBox4.ReadOnly=false;
this.textBox5.ReadOnly=false;
this.textBox6.ReadOnly=false;
this.textBox2.Text="";
this.textBox3.Text="";
this.textBox4.Text="";
this.textBox5.Text="";
this.textBox6.Text="";
this.textBox7.Text="";
if(this.textBox1.Text!="")
...{
this.label10.Text="0";
this.label11.Text="0";
}
else
...{
this.label10.Text="";
this.label11.Text="";
}
}
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
private void button3_Click( object sender, System.EventArgs e)
... { //返回按钮。
this.Close();
}
private void button2_Click( object sender, System.EventArgs e)
... { //重填按钮。
this.textBox1.Text="";
this.textBox2.Text="";
this.textBox3.Text="";
this.textBox4.Text="";
this.textBox5.Text="";
this.textBox6.Text="";
this.textBox7.Text="";
this.textBox1.ReadOnly=false;
this.textBox2.ReadOnly=false;
this.textBox3.ReadOnly=false;
this.textBox4.ReadOnly=false;
this.textBox5.ReadOnly=false;
this.textBox6.ReadOnly=false;
this.textBox7.ReadOnly=false;
this.label10.Text="";
this.label11.Text="";
this.textBox1.Focus();
}
private bool NotText5If()
... { //只能为数字且只允许一个小数点。
string Str=this.textBox5.Text;
int i=0;
while(i
...{
if( (Str[i]<'0' || Str[i] > '9') && Str[i] != '.')
return true;
i++;
}
return false;
}
private bool NotText7If()
... { //为更输入数据检测做准备。
string Str=this.textBox7.Text;
int i=0;
while(i
...{
if(Str[i]<'0' || Str[i] > '9')
return true;
i++;
}
return false;
}
private void button1_Click( object sender, System.EventArgs e)
... { //添加按钮,添加图书。
try
...{
if(this.Exist)
...{
if(this.textBox7.Text != "")
...{
System.Data.OleDb.OleDbCommand MyUpdate = this.oleDbConnection1.CreateCommand();
MyUpdate.CommandText="UPDATE tsxxb SET 库存数=库存数+"+this.textBox7.Text+",在库数=在库数+"+this.textBox7.Text+" WHERE 编号='"+this.textBox1.Text+"'";
this.oleDbDataAdapter1.UpdateCommand=MyUpdate;
this.oleDbConnection1.Open();
MyUpdate.ExecuteNonQuery();
this.oleDbConnection1.Close();
MessageBox.Show("图书添加成功,请查看。","添加提示:",MessageBoxButtons.OK,MessageBoxIcon.Information);
button2_Click(null,null);
}
else
...{
MessageBox.Show("请输入你要添加的数量。","添加提示:",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.textBox7.Focus();
}
}
else
...{
if(this.textBox1.Text == "")
...{
MessageBox.Show("编号不能为空,请输入编号。","添加提示:",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
}
else
...{
if(this.textBox2.Text == "")
...{
MessageBox.Show("书名不能为空,请输入书名。","添加提示:",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.textBox2.Focus();
}
else
...{
if(this.textBox3.Text == "")
...{
MessageBox.Show("类别不能为空,请输入类别。","添加提示:",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.textBox3.Focus();
}
else
...{
if(this.textBox4.Text == "")
...{
MessageBox.Show("作者不能为空,请输入作者姓名。","添加提示:",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.textBox4.Focus();
}
else
...{
if(this.textBox5.Text == "")
...{
MessageBox.Show("价格不能为空,请输入价格。","添加提示:",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.textBox5.Focus();
}
else
...{
if(this.textBox6.Text == "")
...{
MessageBox.Show("出版社不能为空,请输入出版社。","添加提示:",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.textBox6.Focus();
}
else
...{
if(this.textBox7.Text == "")
...{
MessageBox.Show("请输入你要添加的数量。","添加提示:",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.textBox7.Focus();
}
else
...{
if(NotText5If())
...{
MessageBox.Show("价格为非数字,请重新输入.","数据输入提示:",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.textBox5.Focus();
}
else
...{
if(NotText7If())
...{
MessageBox.Show("添加数量为非数字,请重新输入.","数据输入提示:",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.textBox7.Focus();
}
else
...{
System.Data.OleDb.OleDbCommand MyInsert = this.oleDbConnection1.CreateCommand();
MyInsert.CommandText="INSERT INTO tsxxb VALUES('"+this.textBox1.Text+"','"+this.textBox2.Text+"','"+this.textBox3.Text+"','"+this.textBox4.Text+"','"+this.textBox6.Text+"',"+this.textBox5.Text+","+this.textBox7.Text +","+this.textBox7.Text+")";
this.oleDbDataAdapter1.InsertCommand=MyInsert;
this.oleDbConnection1.Open();
MyInsert.ExecuteNonQuery();
this.oleDbConnection1.Close();
MessageBox.Show("图书添加成功,请查看。","添加提示:",MessageBoxButtons.OK,MessageBoxIcon.Information);
button2_Click(null,null);
}
}
}
}
}
}
}
}
}//
}
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
private void tjts_Activated( object sender, System.EventArgs e)
... { //使焦点定位到输入框一中。
this.textBox1.Focus();
}
private void textBox4_KeyDown( object sender, System.Windows.Forms.KeyEventArgs e)
... { //同上,按键处理。
switch((int)e.KeyCode)
...{
case 27:
this.Close();
break;
case 13:
if(this.textBox1.Focused || this.textBox2.Focused || this.textBox3.Focused || this.textBox4.Focused || this.textBox5.Focused || this.textBox6.Focused || this.textBox7.Focused || this.button1.Focused)
...{
button1_Click(null,null);
}
if(this.button2.Focused)
...{
this.button2_Click(null,null);
}
if(this.button3.Focused)
...{
this.Close();
}
break;
case 38:
case 37:
if(this.textBox7.Focused)
...{
this.textBox6.Focus();
}
else
...{
if(this.textBox6.Focused)
...{
this.textBox5.Focus();
}
else
...{
if(this.textBox5.Focused)
...{
this.textBox4.Focus();
}
else
...{
if(this.textBox4.Focused)
...{
this.textBox3.Focus();
}
else
...{
if(this.textBox3.Focused)
...{
this.textBox2.Focus();
}
else
...{
if(this.textBox2.Focused)
...{
this.textBox1.Focus();
}
else
...{
if(this.textBox1.Focused)
...{
this.textBox7.Focus();
}
}
}
}
}
}
}
break;
case 40:
case 39:
if(this.textBox1.Focused)
...{
this.textBox2.Focus();
}
else
...{
if(this.textBox2.Focused)
...{
this.textBox3.Focus();
}
else
...{
if(this.textBox3.Focused)
...{
this.textBox4.Focus();
}
else
...{
if(this.textBox4.Focused)
...{
this.textBox5.Focus();
}
else
...{
if(this.textBox5.Focused)
...{
this.textBox6.Focus();
}
else
...{
if(this.textBox6.Focused)
...{
this.textBox7.Focus();
}
else
...{
if(this.textBox7.Focused)
...{
this.textBox1.Focus();
}
}
}
}
}
}
}
break;
}
}
private void textBox5_KeyDown( object sender, System.Windows.Forms.KeyEventArgs e)
... { //同上,按键处理。
if((int)e.KeyCode == 13)
textBox4_KeyDown(null,e);
}
private void textBox5_TextChanged( object sender, System.EventArgs e)
... { //只允许为数字,且只允许有一个小数点。
string s="";
int j=0;
for(int i=0;i
if(Char.IsDigit(textBox5.Text[i])==true || textBox5.Text[i] == '.')
...{
if(textBox5.Text[i] == '.')
...{
j++;
if(j>1)
...{
MessageBox.Show("只能有一个小数点,请重新输入。","输入提示:",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.textBox5.Focus();
}
}
if(j<=1)
s=s+textBox5.Text[i].ToString();
}
textBox5.Text=s;
textBox5.SelectionStart=textBox5.Text.Length;
}
private void textBox7_TextChanged( object sender, System.EventArgs e)
... { //只允许输入数字。
string s="";
for(int i=0;i
if(Char.IsDigit(textBox7.Text[i])==true)
s=s+textBox7.Text[i].ToString();
textBox7.Text=s;
textBox7.SelectionStart=textBox7.Text.Length;
}
删除图书窗口代码
... { //返回按钮,关闭当前窗口。
this.Close();
}
private void button3_Click( object sender, System.EventArgs e)
... { //更新按钮,更新当前数据。
try
...{
System.Data.OleDb.OleDbCommand MySelect = this.oleDbConnection1.CreateCommand();
MySelect.CommandText="SELECT * FROM tsxxb";
this.oleDbDataAdapter1.SelectCommand=MySelect;
this.dataSet21.Clear();
this.oleDbConnection1.Open();
this.oleDbDataAdapter1.Fill(this.dataSet21,"tsxxb");
this.oleDbConnection1.Close();
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
private void button2_Click( object sender, System.EventArgs e)
... { //删除当前用户选中的记录。
try
...{
int ReN = this.dataGrid1.CurrentRowIndex;
if(ReN == -1)
...{
MessageBox.Show("当前没有记录可以删除!!!","删除提示:",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
else
...{
string BH=dataSet21.Tables["tsxxb"].Rows[ReN]["编号"].ToString();
System.Data.OleDb.OleDbCommand MyDel=this.oleDbConnection1.CreateCommand();
MyDel.CommandText="DELETE * FROM tsxxb WHERE 编号='"+BH+"'";
this.oleDbDataAdapter1.DeleteCommand=MyDel;
if(MessageBox.Show("删除是不可恢复的,真的要删除吗?","删除提示:",MessageBoxButtons.YesNo,MessageBoxIcon.Exclamation) == DialogResult.Yes)
...{
this.oleDbConnection1.Open();
MyDel.ExecuteNonQuery();
this.oleDbConnection1.Close();
button3_Click(null,null);
}
}
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
private void button1_Click( object sender, System.EventArgs e)
... { //查询按钮,按用户提供的信息查询记录。
string ComStr="";
try
...{
System.Data.OleDb.OleDbCommand MySelect = this.oleDbConnection1.CreateCommand();
if( this.textBox1.Text != "")
...{
ComStr="SELECT * FROM tsxxb WHERE 编号='"+this.textBox1.Text+"'";
}
else
...{
if(this.textBox2.Text != "")
...{
if(ComStr == "")
...{
ComStr="SELECT * FROM tsxxb WHERE 书名='"+this.textBox2.Text+"'";
}
else
...{
ComStr+=" AND 书名='"+this.textBox2.Text+"'";
}
}
if(this.textBox3.Text != "")
...{
if(ComStr == "")
...{
ComStr="SELECT * FROM tsxxb WHERE 作者='"+this.textBox3.Text+"'";
}
else
...{
ComStr+=" AND 作者='"+this.textBox3.Text+"'";
}
}
if(ComStr=="")
...{
MessageBox.Show("无查询条件,默认查找所有记录.","查找提示: ",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
ComStr="SELECT * FROM tsxxb";
}
}
MySelect.CommandText=ComStr;
this.oleDbDataAdapter1.SelectCommand=MySelect;
this.dataSet21.Clear();
this.oleDbConnection1.Open();
this.oleDbDataAdapter1.Fill(dataSet21,"tsxxb");
this.oleDbConnection1.Close();
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
private void textBox2_KeyDown( object sender, System.Windows.Forms.KeyEventArgs e)
... { //同上,按键处理。
switch((int)e.KeyCode)
...{
case 27:
this.Close();
break;
case 13:
if(this.button1.Focused || this.textBox1.Focused || this.textBox2.Focused || this.textBox3.Focused)
...{
button1_Click(null,null);
}
if(this.button2.Focused)
...{
button2_Click(null,null);
}
if(this.button3.Focused)
...{
button3_Click(null,null);
}
if(this.button4.Focused)
...{
this.Close();
}
break;
case 38:
case 37:
if(this.textBox3.Focused)
...{
this.textBox2.Focus();
}
else
...{
if(this.textBox2.Focused)
...{
this.textBox1.Focus();
}
else
...{
if(this.textBox1.Focused)
...{
this.textBox3.Focus();
}
}
}
break;
case 40:
case 39:
if(this.textBox1.Focused)
...{
this.textBox2.Focus();
}
else
...{
if(this.textBox2.Focused)
...{
this.textBox3.Focus();
}
else
...{
if(this.textBox3.Focused)
...{
this.textBox1.Focus();
}
}
}
break;
}
}
private void dataGrid1_DoubleClick( object sender, System.EventArgs e)
... { //双击当前记录,调用删除按钮功能。
button2_Click(null,null);
}
图书信息修改窗体代码
... { //保存按钮,保存用户修改的信息。
try
...{
this.oleDbConnection1.Open();
this.oleDbDataAdapter1.Update(this.dataSet21,"tsxxb");
this.oleDbConnection1.Close();
MessageBox.Show("信息已经保存.","保存提示:",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.dataSet21.Clear();
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
private void button2_Click( object sender, System.EventArgs e)
... { //更新按钮,更新当前记录。
try
...{
System.Data.OleDb.OleDbCommand MySelect = this.oleDbConnection1.CreateCommand();
MySelect.CommandText="SELECT * FROM tsxxb";
this.oleDbDataAdapter1.SelectCommand=MySelect;
this.dataSet21.Clear();
this.oleDbConnection1.Open();
this.oleDbDataAdapter1.Fill(this.dataSet21,"tsxxb");
this.oleDbConnection1.Close();
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
private void button1_Click( object sender, System.EventArgs e)
... { //按用户提供信息查询,越祥细越准确。
string ComStr="";
try
...{
System.Data.OleDb.OleDbCommand MySelect = this.oleDbConnection1.CreateCommand();
if( this.textBox1.Text != "")
...{
ComStr="SELECT * FROM tsxxb WHERE 编号='"+this.textBox1.Text+"'";
}
else
...{
if(this.textBox2.Text != "")
...{
if(ComStr=="")
...{
ComStr="SELECT * FROM tsxxb WHERE 书名='"+this.textBox2.Text+"'";
}
else
...{
ComStr+=" AND 书名='"+this.textBox2.Text+"'";
}
}
if(this.textBox3.Text != "")
...{
if(ComStr=="")
...{
ComStr="SELECT * FROM tsxxb WHERE 作者='"+this.textBox3.Text+"'";
}
else
...{
ComStr+=" AND 作者='"+this.textBox3.Text+"'";
}
}
if(this.textBox4.Text != "")
...{
if(ComStr=="")
...{
ComStr="SELECT * FROM tsxxb WHERE 出版社='"+this.textBox4.Text+"'";
}
else
...{
ComStr+=" AND 出版社='"+this.textBox4.Text+"'";
}
}
if(ComStr=="")
...{
MessageBox.Show("无查询条件,默认查找所有记录.","查找提示: ",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
ComStr="SELECT * FROM tsxxb";
}
}
MySelect.CommandText=ComStr;
this.oleDbDataAdapter1.SelectCommand=MySelect;
this.dataSet21.Clear();
this.oleDbConnection1.Open();
this.oleDbDataAdapter1.Fill(dataSet21,"tsxxb");
this.oleDbConnection1.Close();
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
private void textBox3_KeyDown( object sender, System.Windows.Forms.KeyEventArgs e)
... { //同上,按键处理。
switch((int)e.KeyCode)
...{
case 27:
this.Close();
break;
case 13:
if(this.button1.Focused || this.textBox1.Focused || this.textBox2.Focused || this.textBox3.Focused || this.textBox4.Focused)
...{
button1_Click(null,null);
}
if(this.button2.Focused)
...{
button2_Click(null,null);
}
if(this.button3.Focused)
...{
button3_Click(null,null);
}
if(this.button4.Focused)
this.Close();
break;
case 38:
case 37:
if(this.textBox4.Focused)
...{
this.textBox3.Focus();
}
else
...{
if(this.textBox3.Focused)
...{
this.textBox2.Focus();
}
else
...{
if(this.textBox2.Focused)
...{
this.textBox1.Focus();
}
else
...{
if(this.textBox1.Focused)
...{
this.textBox4.Focus();
}
}
}
}
break;
case 40:
case 39:
if(this.textBox1.Focused)
...{
this.textBox2.Focus();
}
else
...{
if(this.textBox2.Focused)
...{
this.textBox3.Focus();
}
else
...{
if(this.textBox3.Focused)
...{
this.textBox4.Focus();
}
else
...{
if(this.textBox4.Focused)
...{
this.textBox1.Focus();
}
}
}
}
break;
}
}
}
借书管理窗体代码
... { //返回按钮,关闭当前窗口。
this.Close();
}
private void JSXX()
... { //为显示读者所借书信息准备。
try
...{
System.Data.OleDb.OleDbCommand MySelect = this.oleDbConnection1.CreateCommand();
MySelect.CommandText="SELECT * FROM jsxxb WHERE 读者编号='"+this.textBox1.Text+"'";
this.oleDbDataAdapter3.SelectCommand=MySelect;
this.dataSet21.Clear();
this.oleDbConnection1.Open();
this.oleDbDataAdapter3.Fill(this.dataSet21,"jsxxb");
this.oleDbConnection1.Close();
string []TSBH=new string[dataSet21.Tables["jsxxb"].Rows.Count];
string []JSRQ=new string[dataSet21.Tables["jsxxb"].Rows.Count];
for(int i=0; i
...{
TSBH[i] = dataSet21.Tables["jsxxb"].Rows[i]["图书编号"].ToString();
JSRQ[i] = dataSet21.Tables["jsxxb"].Rows[i]["借书日期"].ToString();
}
int GJ=TSBH.Length;
string []TEXT=new string[GJ];
float JG=0.00F;
System.Data.OleDb.OleDbCommand MySelectTs = this.oleDbConnection1.CreateCommand();
for(int i=0; i
MySelectTs.CommandText="SELECT * FROM tsxxb WHERE 编号='"+TSBH[i]+"'";
this.oleDbDataAdapter2.SelectCommand=MySelectTs;
this.dataSet21.Clear();
this.oleDbDataAdapter2.Fill(this.dataSet21,"tsxxb");
TEXT[i] = "书名:"+dataSet21.Tables["tsxxb"].Rows[0]["书名"].ToString()+" 价格:"+dataSet21.Tables["tsxxb"].Rows[0]["价格"].ToString()+"元 借书日期:"+JSRQ[i];
JG += float.Parse( dataSet21.Tables["tsxxb"].Rows[0]["价格"].ToString());
}
this.labelgj.Text=GJ.ToString()+"本";
this.textBox3.Lines=TEXT;
this.labelzj.Text=JG.ToString()+"元";
}
catch (Exception Exc)
... {
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
private void textBox1_Leave( object sender, System.EventArgs e)
... { //显示该读者已借书的相关信息。
this.labeldzxm.Text="";
this.labeldzxb.Text="";
this.labeldzsj.Text="";
this.labelxm.Text="";
this.labelxb.Text="";
this.labelgj.Text="";
this.labelzj.Text="";
this.textBox3.Text="";
System.Data.OleDb.OleDbCommand MySelect = this.oleDbConnection1.CreateCommand();
MySelect.CommandText="SELECT * FROM dzxxb WHERE 编号='"+this.textBox1.Text+"'";
System.Data.OleDb.OleDbCommand MySelectCount=this.oleDbConnection1.CreateCommand();
MySelectCount.CommandText="SELECT * FROM jsxxb WHERE 读者编号='"+this.textBox1.Text+"'";
this.oleDbDataAdapter1.SelectCommand=MySelect;
this.oleDbDataAdapter3.SelectCommand=MySelectCount;
this.dataSet21.Clear();
try
...{
this.oleDbConnection1.Open();
int If=this.oleDbDataAdapter1.Fill(this.dataSet21,"dzxxb");
this.oleDbConnection1.Close();
if(If==0)
...{
DZ=true;
}
else
...{
DZ=false;
this.labeldzxm.Text=dataSet21.Tables["dzxxb"].Rows[0]["姓名"].ToString();
this.labeldzxb.Text=dataSet21.Tables["dzxxb"].Rows[0]["性别"].ToString();
this.labeldzsj.Text=dataSet21.Tables["dzxxb"].Rows[0]["手机"].ToString();
this.labelxm.Text=dataSet21.Tables["dzxxb"].Rows[0]["姓名"].ToString();
this.labelxb.Text=dataSet21.Tables["dzxxb"].Rows[0]["性别"].ToString();
JSXX();
}
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
public void textBox2_Leave( object sender, System.EventArgs e)
... { //显示该图书的相关信息。
this.labeltssm.Text="";
this.labeltszz.Text="";
this.labeltsjg.Text="";
System.Data.OleDb.OleDbCommand MySelect = this.oleDbConnection1.CreateCommand();
MySelect.CommandText="SELECT * FROM tsxxb WHERE 编号='"+this.textBox2.Text+"'";
this.oleDbDataAdapter2.SelectCommand=MySelect;
this.dataSet21.Clear();
try
...{
this.oleDbConnection1.Open();
int If=this.oleDbDataAdapter2.Fill(this.dataSet21,"tsxxb");
this.oleDbConnection1.Close();
if(If==0)
...{
TS=true;
}
else
...{
TS=false;
this.labeltssm.Text=dataSet21.Tables["tsxxb"].Rows[0]["书名"].ToString();
this.labeltszz.Text=dataSet21.Tables["tsxxb"].Rows[0]["作者"].ToString();
this.labeltsjg.Text=dataSet21.Tables["tsxxb"].Rows[0]["价格"].ToString();
}
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
private void button1_Click( object sender, System.EventArgs e)
... { //借书按钮,当条件符合后就开始借书。
if(DZ)
...{
MessageBox.Show("该读者不存在,不能借书!!!","借书提示:",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.textBox1.Focus();
}
else
...{
if(TS)
...{
MessageBox.Show("该图书不存在,不能借书!!!","借书提示:",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.textBox2.Focus();
}
else
...{
try
...{
System.Data.OleDb.OleDbCommand MySelect = this.oleDbConnection1.CreateCommand();
MySelect.CommandText="SELECT * FROM tsxxb WHERE 编号='"+this.textBox2.Text+"'";
this.oleDbDataAdapter2.SelectCommand=MySelect;
this.dataSet21.Clear();
this.oleDbConnection1.Open();
int If=this.oleDbDataAdapter2.Fill(this.dataSet21,"tsxxb");
this.oleDbConnection1.Close();
if((int)dataSet21.Tables["tsxxb"].Rows[0]["在库数"]<=0)
...{
MessageBox.Show("该图书已经借完,不能借书!!!","借书提示:",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
}
else
...{
string Date=DateTime.Now.Year.ToString()+"/"+DateTime.Now.Month.ToString()+"/"+DateTime.Now.Day.ToString()+" "+DateTime.Now.Hour.ToString()+":"+DateTime.Now.Minute.ToString()+":"+DateTime.Now.Second.ToString();
System.Data.OleDb.OleDbCommand MyInsert=this.oleDbConnection1.CreateCommand();
MyInsert.CommandText="INSERT INTO jsxxb (读者编号,图书编号,借书日期) VALUES('"+this.textBox1.Text+"','"+this.textBox2.Text+"','"+Date+"')";
this.oleDbDataAdapter3.InsertCommand=MyInsert;
System.Data.OleDb.OleDbCommand MyUpdate = this.oleDbConnection1.CreateCommand();
MyUpdate.CommandText="UPDATE tsxxb SET 在库数=在库数-1 WHERE 编号='"+this.textBox2.Text+"'";
this.oleDbDataAdapter2.UpdateCommand=MyUpdate;
this.oleDbConnection1.Open();
MyInsert.ExecuteNonQuery();
MyUpdate.ExecuteNonQuery();
this.oleDbConnection1.Close();
JSXX();
string Mess="<<"+dataSet21.Tables["tsxxb"].Rows[0]["书名"].ToString()+">>借出成功!!!";
MessageBox.Show(Mess,"借书提示:",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
}
}
private void button2_KeyDown( object sender, System.Windows.Forms.KeyEventArgs e)
... { //同上,按键处理。
switch((int)e.KeyCode)
...{
case 27:
this.Close();
break;
case 13:
if(this.button1.Focused || this.textBox1.Focused || this.textBox2.Focused)
...{
button1_Click(null,null);
}
if(this.button2.Focused)
...{
this.Close();
}
break;
case 38:
case 37:
if(this.button2.Focused)
...{
this.button1.Focus();
}
else
...{
if(this.button1.Focused)
...{
this.textBox2.Focus();
}
else
...{
if(this.textBox2.Focused)
...{
this.textBox1.Focus();
}
else
...{
if(this.textBox1.Focused)
...{
this.button2.Focus();
}
}
}
}
break;
case 40:
case 39:
if(this.button2.Focused)
...{
this.textBox1.Focus();
}
else
...{
if(this.textBox1.Focused)
...{
this.textBox2.Focus();
}
else
...{
if(this.textBox2.Focused)
...{
this.button1.Focus();
}
else
...{
if(this.button1.Focused)
...{
this.button2.Focus();
}
}
}
}
break;
}
}
private void jsgl_Activated( object sender, System.EventArgs e)
... { //设定焦点。
this.textBox1.Focus();
}
public void SetForm1(Form1 v)
... { //为窗体间传递数据做准备。
this.F=v;
}
private void textBox2_DoubleClick( object sender, System.EventArgs e)
... { //当双击图书编号输入框时打开书目查询窗口。
smcx2 MySmcx=new smcx2();
MySmcx.MdiParent=F;
MySmcx.CXBH(this);
MySmcx.Show();
}
private void textBox2_KeyPress( object sender, System.Windows.Forms.KeyPressEventArgs e)
... { //当用户在图书编号框中输入的是问号时也打开书目查询窗口。
if(e.KeyChar==63)
textBox2_DoubleClick(null,null);
}
还书管理窗体代码
... { //为显示该读者所有已借的书的信息。
try
...{
System.Data.OleDb.OleDbCommand MySelect = this.oleDbConnection1.CreateCommand();
MySelect.CommandText="SELECT * FROM jsxxb WHERE 读者编号='"+this.textBox1.Text+"'";
this.oleDbDataAdapter3.SelectCommand=MySelect;
this.dataSet21.Clear();
this.oleDbConnection1.Open();
this.oleDbDataAdapter3.Fill(this.dataSet21,"jsxxb");
this.oleDbConnection1.Close();
string []TSBH=new string[dataSet21.Tables["jsxxb"].Rows.Count];
string []JSRQ=new string[dataSet21.Tables["jsxxb"].Rows.Count];
for(int i=0; i
...{
TSBH[i] = dataSet21.Tables["jsxxb"].Rows[i]["图书编号"].ToString();
JSRQ[i] = dataSet21.Tables["jsxxb"].Rows[i]["借书日期"].ToString();
}
int GJ=TSBH.Length;
string []TEXT=new string[GJ];
float JG=0.00F;
System.Data.OleDb.OleDbCommand MySelectTs = this.oleDbConnection1.CreateCommand();
for(int i=0; i
MySelectTs.CommandText="SELECT * FROM tsxxb WHERE 编号='"+TSBH[i]+"'";
this.oleDbDataAdapter2.SelectCommand=MySelectTs;
this.dataSet21.Clear();
this.oleDbDataAdapter2.Fill(this.dataSet21,"tsxxb");
TEXT[i] = "书名:"+dataSet21.Tables["tsxxb"].Rows[0]["书名"].ToString()+" 价格:"+dataSet21.Tables["tsxxb"].Rows[0]["价格"].ToString()+"元 借书日期:"+JSRQ[i];
JG += float.Parse( dataSet21.Tables["tsxxb"].Rows[0]["价格"].ToString());
}
this.labelgj.Text=GJ.ToString()+"本";
this.textBox3.Lines=TEXT;
this.labelzj.Text=JG.ToString()+"元";
}
catch (Exception Exc)
... {
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
private void hsgl_Activated( object sender, System.EventArgs e)
... { //设置当前焦点。
this.textBox1.Focus();
}
private void textBox1_Leave( object sender, System.EventArgs e)
... { //查询该读者已借书的信息。
this.labeldzxm.Text="";
this.labeldzxb.Text="";
this.labeldzsj.Text="";
this.labelxm.Text="";
this.labelxb.Text="";
this.labelgj.Text="";
this.labelzj.Text="";
this.textBox3.Text="";
System.Data.OleDb.OleDbCommand MySelect = this.oleDbConnection1.CreateCommand();
MySelect.CommandText="SELECT * FROM dzxxb WHERE 编号='"+this.textBox1.Text+"'";
System.Data.OleDb.OleDbCommand MySelectCount=this.oleDbConnection1.CreateCommand();
MySelectCount.CommandText="SELECT * FROM jsxxb WHERE 读者编号='"+this.textBox1.Text+"'";
this.oleDbDataAdapter1.SelectCommand=MySelect;
this.oleDbDataAdapter3.SelectCommand=MySelectCount;
this.dataSet21.Clear();
try
...{
this.oleDbConnection1.Open();
int If=this.oleDbDataAdapter1.Fill(this.dataSet21,"dzxxb");
this.oleDbConnection1.Close();
if(If==0)
...{
DZ=true;
}
else
...{
DZ=false;
this.labeldzxm.Text=dataSet21.Tables["dzxxb"].Rows[0]["姓名"].ToString();
this.labeldzxb.Text=dataSet21.Tables["dzxxb"].Rows[0]["性别"].ToString();
this.labeldzsj.Text=dataSet21.Tables["dzxxb"].Rows[0]["手机"].ToString();
this.labelxm.Text=dataSet21.Tables["dzxxb"].Rows[0]["姓名"].ToString();
this.labelxb.Text=dataSet21.Tables["dzxxb"].Rows[0]["性别"].ToString();
JSXX();
}
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
public void textBox2_Leave( object sender, System.EventArgs e)
... { //查询该图书的相关信息。
this.labeltssm.Text="";
this.labeltszz.Text="";
this.labeltsjg.Text="";
System.Data.OleDb.OleDbCommand MySelect = this.oleDbConnection1.CreateCommand();
MySelect.CommandText="SELECT * FROM tsxxb WHERE 编号='"+this.textBox2.Text+"'";
this.oleDbDataAdapter2.SelectCommand=MySelect;
this.dataSet21.Clear();
try
...{
this.oleDbConnection1.Open();
int If=this.oleDbDataAdapter2.Fill(this.dataSet21,"tsxxb");
this.oleDbConnection1.Close();
if(If==0)
...{
TS=true;
}
else
...{
TS=false;
this.labeltssm.Text=dataSet21.Tables["tsxxb"].Rows[0]["书名"].ToString();
this.labeltszz.Text=dataSet21.Tables["tsxxb"].Rows[0]["作者"].ToString();
this.labeltsjg.Text=dataSet21.Tables["tsxxb"].Rows[0]["价格"].ToString();
}
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
private void button2_Click( object sender, System.EventArgs e)
... { //返回按钮,关闭当前窗口。
this.Close();
}
private void textBox2_KeyDown( object sender, System.Windows.Forms.KeyEventArgs e)
... { //同上,按键处理。
switch((int)e.KeyCode)
...{
case 27:
this.Close();
break;
case 13:
if(this.button1.Focused || this.textBox1.Focused || this.textBox2.Focused)
...{
button1_Click(null,null);
}
if(this.button2.Focused)
...{
this.Close();
}
break;
case 38:
case 37:
if(this.button2.Focused)
...{
this.button1.Focus();
}
else
...{
if(this.button1.Focused)
...{
this.textBox2.Focus();
}
else
...{
if(this.textBox2.Focused)
...{
this.textBox1.Focus();
}
else
...{
if(this.textBox1.Focused)
...{
this.button2.Focus();
}
}
}
}
break;
case 40:
case 39:
if(this.button2.Focused)
...{
this.textBox1.Focus();
}
else
...{
if(this.textBox1.Focused)
...{
this.textBox2.Focus();
}
else
...{
if(this.textBox2.Focused)
...{
this.button1.Focus();
}
else
...{
if(this.button1.Focused)
...{
this.button2.Focus();
}
}
}
}
break;
}
}
private void button1_Click( object sender, System.EventArgs e)
... { //当所有条件符合时开始还书。
if(DZ)
...{
MessageBox.Show("该读者不存在,不能还书!!!","还书提示:",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.textBox1.Focus();
}
else
...{
if(TS)
...{
MessageBox.Show("该图书不存在,不能还书!!!","还书提示:",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.textBox2.Focus();
}
else
...{
try
...{
System.Data.OleDb.OleDbCommand MySelect=this.oleDbConnection1.CreateCommand();
MySelect.CommandText="SELECT * FROM jsxxb WHERE 读者编号='"+this.textBox1.Text+"' AND 图书编号='"+this.textBox2.Text+"'";
this.oleDbDataAdapter3.SelectCommand=MySelect;
this.dataSet21.Clear();
this.oleDbConnection1.Open();
int R=this.oleDbDataAdapter3.Fill(dataSet21,"jsxxb");
this.oleDbConnection1.Close();
if(R==0)
...{
MessageBox.Show("该读者没有借这本书,无法完成还书操作!","还书提示:",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
}
else
...{
string BH=dataSet21.Tables["jsxxb"].Rows[0]["编号"].ToString();
System.Data.OleDb.OleDbCommand MyDel=this.oleDbConnection1.CreateCommand();
System.Data.OleDb.OleDbCommand MyUpdate = this.oleDbConnection1.CreateCommand();
MyUpdate.CommandText="UPDATE tsxxb SET 在库数=在库数+1 WHERE 编号='"+this.textBox2.Text+"'";
MyDel.CommandText="DELETE * FROM jsxxb WHERE 编号=" + BH;
this.oleDbDataAdapter3.DeleteCommand=MyDel;
this.oleDbDataAdapter2.UpdateCommand=MyUpdate;
this.oleDbConnection1.Open();
MyDel.ExecuteNonQuery();
MyUpdate.ExecuteNonQuery();
this.oleDbConnection1.Close();
MessageBox.Show("该读者还书成功!","还书提示:",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.textBox2.Focus();
}
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
JSXX();
}
}
}
public void SetForm1(Form1 v)
... { //为窗体间传递数据做准备。
this.F=v;
}
private void textBox2_KeyPress( object sender, System.Windows.Forms.KeyPressEventArgs e)
... { //当用户在图书编号输入框输入问号时显示书目查询窗口。
if(e.KeyChar==63)
textBox2_DoubleClick(null,null);
}
private void textBox2_DoubleClick( object sender, System.EventArgs e)
... { //当用户在图书编号输入框双击时显示书目查询窗口。
smcx3 MySmcx=new smcx3();
MySmcx.MdiParent=F;
MySmcx.CXBH(this);
MySmcx.Show();
}
查询员工窗体代码
private void button3_Click( object sender, System.EventArgs e)
... { //返回按钮,关闭当前窗口。
this.Close();
}
private void button2_Click( object sender, System.EventArgs e)
... { //更新按钮,更新当前数据信息。
try
...{
this.oleDbConnection1.Open();
this.oleDbDataAdapter1.Fill(this.dataSet21,"ygxxb");
this.oleDbConnection1.Close();
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
private void button1_Click( object sender, System.EventArgs e)
... { //查询所有员工信息按钮。
try
...{
this.dataSet21.Clear();
System.Data.OleDb.OleDbCommand MySelect = this.oleDbConnection1.CreateCommand();
MySelect.CommandText = "SELECT * FROM ygxxb";
this.oleDbDataAdapter1.SelectCommand = MySelect;
this.oleDbConnection1.Open();
this.oleDbDataAdapter1.Fill(this.dataSet21,"ygxxb");
this.oleDbConnection1.Close();
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
private void button4_Click( object sender, System.EventArgs e)
... { //按用户名查询员工信息。
try
...{
System.Data.OleDb.OleDbCommand MySelect = this.oleDbConnection1.CreateCommand();
MySelect.CommandText = "SELECT * FROM ygxxb WHERE 用户名='"+this.textBox1.Text+"'";
this.oleDbDataAdapter1.SelectCommand = MySelect;
this.dataSet21.Clear();
this.oleDbConnection1.Open();
this.oleDbDataAdapter1.Fill(this.dataSet21,"ygxxb");
this.oleDbConnection1.Close();
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
private void button5_Click( object sender, System.EventArgs e)
... { //按姓名查询员工信息。
try
...{
System.Data.OleDb.OleDbCommand MySelect = this.oleDbConnection1.CreateCommand();
MySelect.CommandText = "SELECT * FROM ygxxb WHERE 姓名='"+this.textBox2.Text+"'";
this.oleDbDataAdapter1.SelectCommand = MySelect;
this.dataSet21.Clear();
this.oleDbConnection1.Open();
this.oleDbDataAdapter1.Fill(this.dataSet21,"ygxxb");
this.oleDbConnection1.Close();
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
private void button6_Click( object sender, System.EventArgs e)
... { //返回按钮,关闭当前窗口。
this.Close();
}
private void button7_Click( object sender, System.EventArgs e)
... { //返回按钮,关闭当前窗口。
this.Close();
}
private void cxyg_Load( object sender, System.EventArgs e)
... { //设置当前焦点。
this.button1.Focus();
}
private void button6_KeyDown( object sender, System.Windows.Forms.KeyEventArgs e)
... { //同上,按键处理。
switch((int)e.KeyCode)
...{
case 13:
button4_Click(null,null);
break;
case 27:
this.Close();
break;
case 38:
case 37:
if(this.button6.Focused)
...{
this.button4.Focus();
}
else
...{
if(this.button4.Focused)
...{
this.textBox1.Focus();
}
else
...{
if(this.textBox1.Focused)
...{
this.button6.Focus();
}
}
}
break;
case 40:
case 39:
if(this.textBox1.Focused)
...{
this.button4.Focus();
}
else
...{
if(this.button4.Focused)
...{
this.button6.Focus();
}
else
...{
if(this.button6.Focused)
...{
this.textBox1.Focus();
}
}
}
break;
}
}
private void button7_KeyDown( object sender, System.Windows.Forms.KeyEventArgs e)
... { //同上,按键处理。
switch((int)e.KeyCode)
...{
case 13:
button5_Click(null,null);
break;
case 27:
this.Close();
break;
case 38:
case 37:
if(this.button7.Focused)
...{
this.button5.Focus();
}
else
...{
if(this.button5.Focused)
...{
this.textBox2.Focus();
}
else
...{
if(this.textBox2.Focused)
...{
this.button7.Focus();
}
}
}
break;
case 40:
case 39:
if(this.textBox2.Focused)
...{
this.button5.Focus();
}
else
...{
if(this.button5.Focused)
...{
this.button7.Focus();
}
else
...{
if(this.button7.Focused)
...{
this.textBox2.Focus();
}
}
}
break;
}
}
private void cxyg_Activated( object sender, System.EventArgs e)
... { //设置当前焦点。
this.button1.Focus();
}
增加员工窗体代码
private void button3_Click( object sender, System.EventArgs e)
... { //返回按钮,关闭当前窗口。
this.Close();
}
private void button2_Click( object sender, System.EventArgs e)
... { //重填按钮。
this.textBox1.Text="";
this.textBox2.Text="";
this.textBox3.Text="否";
this.textBox4.Text="";
this.textBox5.Text="男";
this.textBox6.Text="";
this.textBox7.Text="";
this.textBox8.Text="";
this.textBox9.Text="";
this.textBox10.Text="";
this.textBox11.Text="";
this.textBox1.Focus();
}
private void button1_Click( object sender, System.EventArgs e)
... { //增加员工按钮,输入合法的信息后开始增加员工。
try
...{
if( this.textBox1.Text=="" )
...{
MessageBox.Show("用名不能为空,请输入用户名.","数据输入提示:",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.textBox1.Focus();
}
else
...{
System.Data.OleDb.OleDbCommand MySelect=this.oleDbConnection1.CreateCommand();
MySelect.CommandText="SELECT 用户名 FROM ygxxb WHERE 用户名='"+this.textBox1.Text+"'";
this.oleDbDataAdapter1.SelectCommand=MySelect;
this.oleDbConnection1.Open();
int IFUSER=this.oleDbDataAdapter1.Fill(this.dataSet21,"ygxxb");;
this.oleDbConnection1.Close();
if(IFUSER ==0)
...{
if(this.textBox2.Text=="" || this.textBox11.Text=="")
...{
MessageBox.Show("用户密码不能为空,请输入.","数据输入提示:",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.textBox2.Focus();
}
else
...{
if(this.textBox2.Text != this.textBox11.Text)
...{
MessageBox.Show("两次密码不一样,请重新输入.","数据输入提示:",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.textBox11.Focus();
}
else
...{
if(this.textBox4.Text=="")
...{
MessageBox.Show("用户姓名不能为空,请输入.","数据输入提示:",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.textBox4.Focus();
}
else
...{
if(this.textBox3.Text=="")
...{
MessageBox.Show("是否为管理员不能为空!!!","数据输入提示:",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.textBox3.Focus();
}
else
...{
if(this.textBox3.Text !="是" & this.textBox3.Text != "否")
...{
MessageBox.Show("管理员只有是与不是,请输入"是"或"否"","数据输入提示:",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.textBox3.Focus();
}
else
...{
if(this.textBox5.Text=="")
...{
MessageBox.Show("用户性别不能为空,请输入.","数据输入提示:",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.textBox5.Focus();
}
else
...{
if(this.textBox5.Text != "男" & this.textBox5.Text != "女")
...{
MessageBox.Show("用户性别只能为男或女,请重新输入.","数据输入提示:",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.textBox5.Focus();
}
else
...{
System.Data.OleDb.OleDbCommand MyInsert = this.oleDbConnection1.CreateCommand();
MyInsert.CommandText="INSERT INTO ygxxb(用户名,密码,系统管理员,姓名,性别,手机,办公地址,ICQ,OICQ,电子邮箱) VALUES ('"+this.textBox1.Text+"','"+this.textBox2.Text+"','"+this.textBox3.Text+"','"+this.textBox4.Text+"','"+this.textBox5.Text+"','"+this.textBox6.Text+"','"+this.textBox7.Text+"','"+this.textBox8.Text+"','"+this.textBox9.Text+"','"+this.textBox10.Text+"')";
this.oleDbDataAdapter1.InsertCommand=MyInsert;
this.oleDbConnection1.Open();
MyInsert.ExecuteNonQuery();
this.oleDbConnection1.Close();
MessageBox.Show("员工添加成功!!!","员工添加提示:",MessageBoxButtons.OK,MessageBoxIcon.Asterisk);
this.textBox1.Text="";
this.textBox2.Text="";
this.textBox3.Text="否";
this.textBox4.Text="";
this.textBox5.Text="男";
this.textBox6.Text="";
this.textBox7.Text="";
this.textBox8.Text="";
this.textBox9.Text="";
this.textBox10.Text="";
this.textBox11.Text="";
this.textBox1.Focus();
}
}
}
}
}
}
}
}
else
...{
MessageBox.Show("用名已经存在,请换用另外的用户名.","数据输入提示:",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.textBox1.Focus();
}
}
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
private void textBox11_KeyDown( object sender, System.Windows.Forms.KeyEventArgs e)
... { //同上,按键处理。
switch((int)e.KeyCode)
...{
case 13:
button1_Click(null,null);
break;
case 27:
this.Close();
break;
case 38:
case 37:
if(this.textBox10.Focused)
...{
this.textBox9.Focus();
}
else
...{
if(this.textBox9.Focused)
...{
this.textBox8.Focus();
}
else
...{
if(this.textBox8.Focused)
...{
this.textBox7.Focus();
}
else
...{
if(this.textBox7.Focused)
...{
this.textBox6.Focus();
}
else
...{
if(this.textBox6.Focused)
...{
this.textBox5.Focus();
}
else
...{
if(this.textBox5.Focused)
...{
this.textBox4.Focus();
}
else
...{
if(this.textBox4.Focused)
...{
this.textBox3.Focus();
}
else
...{
if(this.textBox3.Focused)
...{
this.textBox11.Focus();
}
else
...{
if(this.textBox11.Focused)
...{
this.textBox2.Focus();
}
else
...{
if(this.textBox2.Focused)
...{
this.textBox1.Focus();
}
else
...{
if(this.textBox1.Focused)
...{
this.textBox10.Focus();
}
}
}
}
}
}
}
}
}
}
}
break;
case 40:
case 39:
if(this.textBox1.Focused)
...{
this.textBox2.Focus();
}
else
...{
if(this.textBox2.Focused)
...{
this.textBox11.Focus();
}
else
...{
if(this.textBox11.Focused)
...{
this.textBox3.Focus();
}
else
...{
if(this.textBox3.Focused)
...{
this.textBox4.Focus();
}
else
...{
if(this.textBox4.Focused)
...{
this.textBox5.Focus();
}
else
...{
if(this.textBox5.Focused)
...{
this.textBox6.Focus();
}
else
...{
if(this.textBox6.Focused)
...{
this.textBox7.Focus();
}
else
...{
if(this.textBox7.Focused)
...{
this.textBox8.Focus();
}
else
...{
if(this.textBox8.Focused)
...{
this.textBox9.Focus();
}
else
...{
if(this.textBox9.Focused)
...{
this.textBox10.Focus();
}
else
...{
if(this.textBox10.Focused)
...{
this.textBox1.Focus();
}
}
}
}
}
}
}
}
}
}
}
break;
}
}
private void zjyg_Load( object sender, System.EventArgs e)
... { //设置焦点,并设置部分默认值。
this.textBox1.Focus();
this.textBox3.Text="否";
this.textBox5.Text="男";
}
private void textBox6_TextChanged( object sender, System.EventArgs e)
... { //不允许用户输入非数字数据。
string s="";
for(int i=0;i
if(Char.IsDigit(textBox6.Text[i])==true)
s=s+textBox6.Text[i].ToString();
textBox6.Text=s;
textBox6.SelectionStart=textBox6.Text.Length;
}
private void textBox8_TextChanged( object sender, System.EventArgs e)
... { //不允许用户输入非数字数据。
string s="";
for(int i=0;i
if(Char.IsDigit(textBox8.Text[i])==true)
s=s+textBox8.Text[i].ToString();
textBox8.Text=s;
textBox8.SelectionStart=textBox8.Text.Length;
}
private void textBox9_TextChanged( object sender, System.EventArgs e)
... { //不允许用户输入非数字数据
string s="";
for(int i=0;i
if(Char.IsDigit(textBox9.Text[i])==true)
s=s+textBox9.Text[i].ToString();
textBox9.Text=s;
textBox9.SelectionStart=textBox9.Text.Length;
}
删除员工窗体代码
... { //更新按钮,更新当前数据记录。
try
...{
System.Data.OleDb.OleDbCommand MySelect = this.oleDbConnection1.CreateCommand();
MySelect.CommandText="SELECT * FROM ygxxb";
this.oleDbDataAdapter1.SelectCommand=MySelect;
this.dataSet21.Clear();
this.oleDbConnection1.Open();
this.oleDbDataAdapter1.Fill(this.dataSet21,"ygxxb");
this.oleDbConnection1.Close();
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
private void button1_Click( object sender, System.EventArgs e)
... { //查询按钮,根据用户输入的信息查询相关记录。
string ComStr="";
try
...{
System.Data.OleDb.OleDbCommand MySelect = this.oleDbConnection1.CreateCommand();
if( this.textBox1.Text != "")
...{
ComStr="SELECT * FROM ygxxb WHERE 用户名='"+this.textBox1.Text+"'";
}
else
...{
if(this.textBox2.Text != "")
...{
if(ComStr == "")
...{
ComStr="SELECT * FROM ygxxb WHERE 姓名='"+this.textBox2.Text+"'";
}
else
...{
ComStr+=" AND 姓名='"+this.textBox2.Text+"'";
}
}
if(this.textBox3.Text != "")
...{
if(ComStr == "")
...{
ComStr="SELECT * FROM ygxxb WHERE 手机='"+this.textBox3.Text+"'";
}
else
...{
ComStr+=" AND 手机='"+this.textBox3.Text+"'";
}
}
if(ComStr=="")
...{
MessageBox.Show("无查询条件,默认查找所有记录.","查找提示: ",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
ComStr="SELECT * FROM ygxxb";
}
}
MySelect.CommandText=ComStr;
this.oleDbDataAdapter1.SelectCommand=MySelect;
this.dataSet21.Clear();
this.oleDbConnection1.Open();
this.oleDbDataAdapter1.Fill(dataSet21,"ygxxb");
this.oleDbConnection1.Close();
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
private void button2_Click( object sender, System.EventArgs e)
... { //删除用户选中的记录,请用户确认。
try
...{
int ReN = this.dataGrid1.CurrentRowIndex;
if(ReN == -1)
...{
MessageBox.Show("当前没有记录可以删除!!!","删除提示:",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
else
...{
string YHM=dataSet21.Tables["ygxxb"].Rows[ReN]["用户名"].ToString();
System.Data.OleDb.OleDbCommand MyDel=this.oleDbConnection1.CreateCommand();
MyDel.CommandText="DELETE * FROM ygxxb WHERE 用户名='"+YHM+"'";
this.oleDbDataAdapter1.DeleteCommand=MyDel;
if(MessageBox.Show("删除是不可恢复的,真的要删除吗?","删除提示:",MessageBoxButtons.YesNo,MessageBoxIcon.Exclamation) == DialogResult.Yes)
...{
this.oleDbConnection1.Open();
MyDel.ExecuteNonQuery();
this.oleDbConnection1.Close();
button3_Click(null,null);
}
}
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
private void scyg_Load( object sender, System.EventArgs e)
... { //设置焦点。
this.textBox1.Focus();
}
private void textBox1_KeyDown( object sender, System.Windows.Forms.KeyEventArgs e)
... { //同上,按键处理。
switch((int)e.KeyCode)
...{
case 27:
this.Close();
break;
case 13:
if(this.button1.Focused || this.textBox1.Focused || this.textBox2.Focused || this.textBox3.Focused)
...{
button1_Click(null,null);
}
if(this.button2.Focused)
...{
button2_Click(null,null);
}
if(this.button3.Focused)
...{
button3_Click(null,null);
}
if(this.button4.Focused)
...{
this.Close();
}
break;
case 38:
case 37:
if(this.textBox3.Focused)
...{
this.textBox2.Focus();
}
else
...{
if(this.textBox2.Focused)
...{
this.textBox1.Focus();
}
else
...{
if(this.textBox1.Focused)
...{
this.textBox3.Focus();
}
}
}
break;
case 40:
case 39:
if(this.textBox1.Focused)
...{
this.textBox2.Focus();
}
else
...{
if(this.textBox2.Focused)
...{
this.textBox3.Focus();
}
else
...{
if(this.textBox3.Focused)
...{
this.textBox1.Focus();
}
}
}
break;
}
}
private void button4_Click( object sender, System.EventArgs e)
... { //返回按钮,关闭当前窗口。
this.Close();
}
private void button4_KeyDown( object sender, System.Windows.Forms.KeyEventArgs e)
... { //同样,按键处理。
textBox1_KeyDown(null,null);
}
private void textBox3_TextChanged( object sender, System.EventArgs e)
... { //只允许用户输入数字数据。
string s="";
for(int i=0;i
if(Char.IsDigit(textBox3.Text[i])==true)
s=s+textBox3.Text[i].ToString();
textBox3.Text=s;
textBox3.SelectionStart=textBox3.Text.Length;
}
private void dataGrid1_DoubleClick( object sender, System.EventArgs e)
... { //用户双击当前记录,调用删除功能。
button2_Click(null,null);
}
员工资料修改窗体代码
private void button3_Click( object sender, System.EventArgs e)
... { //返回按钮,关闭当前窗口。
this.Close();
}
private void button4_Click( object sender, System.EventArgs e)
... { //返回按钮,关闭当前窗口。
this.Close();
}
private void zlxg_Load( object sender, System.EventArgs e)
... { //设置当前焦点。
this.textBox1.Focus();
}
private void button2_Click( object sender, System.EventArgs e)
... { //更新按钮,更新当前数据信息。
try
...{
System.Data.OleDb.OleDbCommand MySelect = this.oleDbConnection1.CreateCommand();
MySelect.CommandText="SELECT * FROM ygxxb";
this.oleDbDataAdapter1.SelectCommand=MySelect;
this.dataSet21.Clear();
this.oleDbConnection1.Open();
this.oleDbDataAdapter1.Fill(this.dataSet21,"ygxxb");
this.oleDbConnection1.Close();
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
private void button1_Click( object sender, System.EventArgs e)
... { //查询按钮,根据用户提供信息查询相关信息。
string ComStr="";
try
...{
System.Data.OleDb.OleDbCommand MySelect = this.oleDbConnection1.CreateCommand();
if( this.textBox1.Text != "")
...{
ComStr="SELECT * FROM ygxxb WHERE 用户名='"+this.textBox1.Text+"'";
}
else
...{
if(this.textBox2.Text != "")
...{
if(ComStr=="")
...{
ComStr="SELECT * FROM ygxxb WHERE 姓名='"+this.textBox2.Text+"'";
}
else
...{
ComStr+=" AND 姓名='"+this.textBox2.Text+"'";
}
}
if(this.textBox3.Text != "")
...{
if(ComStr=="")
...{
ComStr="SELECT * FROM ygxxb WHERE 手机='"+this.textBox3.Text+"'";
}
else
...{
ComStr+=" AND 手机='"+this.textBox3.Text+"'";
}
}
if(ComStr=="")
...{
MessageBox.Show("无查询条件,默认查找所有记录.","查找提示: ",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
ComStr="SELECT * FROM ygxxb";
}
}
MySelect.CommandText=ComStr;
this.oleDbDataAdapter1.SelectCommand=MySelect;
this.dataSet21.Clear();
this.oleDbConnection1.Open();
this.oleDbDataAdapter1.Fill(dataSet21,"ygxxb");
this.oleDbConnection1.Close();
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
private void button3_Click_1( object sender, System.EventArgs e)
... { //保存按钮,保存用户修改的信息。
try
...{
this.oleDbConnection1.Open();
this.oleDbDataAdapter1.Update(this.dataSet21,"ygxxb");
this.oleDbConnection1.Close();
MessageBox.Show("信息已经保存.","保存提示:",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.dataSet21.Clear();
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
private void button2_KeyDown( object sender, System.Windows.Forms.KeyEventArgs e)
... { //同上,按键处理。
switch((int)e.KeyCode)
...{
case 27:
this.Close();
break;
case 13:
if(this.button1.Focused || this.textBox1.Focused || this.textBox2.Focused || this.textBox3.Focused)
...{
button1_Click(null,null);
}
if(this.button2.Focused)
...{
button2_Click(null,null);
}
if(this.button3.Focused)
...{
button3_Click(null,null);
}
if(this.button4.Focused)
this.Close();
break;
case 38:
case 37:
if(this.textBox3.Focused)
...{
this.textBox2.Focus();
}
else
...{
if(this.textBox2.Focused)
...{
this.textBox1.Focus();
}
else
...{
if(this.textBox1.Focused)
...{
this.textBox3.Focus();
}
}
}
break;
case 40:
case 39:
if(this.textBox1.Focused)
...{
this.textBox2.Focus();
}
else
...{
if(this.textBox2.Focused)
...{
this.textBox3.Focus();
}
else
...{
if(this.textBox3.Focused)
...{
this.textBox1.Focus();
}
}
}
break;
}
}
private void textBox3_TextChanged( object sender, System.EventArgs e)
... { //不允许用户输入非数字数据。
string s="";
for(int i=0;i
if(Char.IsDigit(textBox3.Text[i])==true)
s=s+textBox3.Text[i].ToString();
textBox3.Text=s;
textBox3.SelectionStart=textBox3.Text.Length;
}
密码修改窗体代码
... { //根据用户是否输入有信息而改变按钮提示。
if(this.textBox1.Text != "" || this.textBox2.Text != "" || this.textBox3.Text != "" || this.textBox4.Text != "" )
...{
this.button2.Text="重填";
}
else
...{
this.button2.Text="返回";
}
}
private void textBox2_TextChanged( object sender, System.EventArgs e)
... { //根据用户是否输入有信息而改变按钮提示。
textBox1_TextChanged(null,null);
}
private void textBox3_TextChanged( object sender, System.EventArgs e)
... { //根据用户是否输入有信息而改变按钮提示。
textBox1_TextChanged(null,null);
}
private void textBox4_TextChanged( object sender, System.EventArgs e)
... { //根据用户是否输入有信息而改变按钮提示。
textBox1_TextChanged(null,null);
}
private void mmxg_Load( object sender, System.EventArgs e)
... { //设置当前焦点。
this.textBox1.Focus();
}
private void button2_Click( object sender, System.EventArgs e)
... { //根据按钮信息实现清除信息或退出。
if(this.button2.Text == "重填")
...{
this.textBox1.Text="";
this.textBox2.Text="";
this.textBox3.Text="";
this.textBox4.Text="";
this.textBox1.Focus();
}
else
...{
this.Close();
}
}
private void button1_Click( object sender, System.EventArgs e)
... { //符合条件就开始修改密码。
try
...{
System.Data.OleDb.OleDbCommand MySelect = this.oleDbConnection1.CreateCommand();
MySelect.CommandText = "SELECT 用户名 FROM ygxxb WHERE 用户名='"+this.textBox1.Text+"' and 密码='"+this.textBox2.Text+"'";
this.oleDbDataAdapter1.SelectCommand = MySelect;
System.Data.OleDb.OleDbCommand MyUpdata = this.oleDbConnection1.CreateCommand();
MyUpdata.CommandText = "UPDATE ygxxb SET 密码='"+this.textBox3.Text+"' WHERE 用户名='"+this.textBox1.Text+"'";
this.oleDbDataAdapter1.UpdateCommand = MyUpdata;
if(this.textBox1.Text == "")
...{
MessageBox.Show("请输入用户名!!!","修改提示:",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.textBox1.Focus();
}
else
...{
if(this.textBox2.Text == "")
...{
MessageBox.Show("请输入当前密码,否则无权修改密码!!!","修改提示:",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.textBox2.Focus();
}
else
...{
if(this.textBox3.Text == "")
...{
MessageBox.Show("为了安全,请输入新密码!!!","修改提示:",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.textBox3.Focus();
}
else
...{
if(this.textBox3.Text != this.textBox4.Text)
...{
MessageBox.Show("两次密码不一样!重新输入.","修改提示:",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.textBox4.Focus();
}
else
...{
this.oleDbConnection1.Open();
int If=this.oleDbDataAdapter1.Fill(this.dataSet21,"ygxxb");
this.oleDbConnection1.Close();
if( If== 0)
...{
MessageBox.Show("当前密码错误,你无权修改!!!","修改提示:",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.Close();
}
else
...{
this.oleDbConnection1.Open();
MyUpdata.ExecuteNonQuery();
this.oleDbConnection1.Close();
MessageBox.Show("密码修改成功,请记住你的新密码.","修改提示:",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.Close();
}
}
}
}
}
}
catch(Exception Exc)
...{
MessageBox.Show(Exc.Message);
this.oleDbConnection1.Close();
}
}
private void button1_KeyDown( object sender, System.Windows.Forms.KeyEventArgs e)
... { //同上,按键处理。
int Key=(int)e.KeyCode;
switch(Key)
...{
case 27:
this.Close();
break;
case 13:
this.button1_Click(null,null);
break;
case 38:
case 37:
if(this.textBox1.Focused)
...{
this.button2.Focus();
}
else
...{
if(this.textBox2.Focused)
...{
this.textBox1.Focus();
}
else
...{
if(this.textBox3.Focused)
...{
this.textBox2.Focus();
}
else
...{
if(this.textBox4.Focused)
...{
this.textBox3.Focus();
}
else
...{
if(this.button1.Focused)
...{
this.textBox4.Focus();
}
else
...{
if(this.button2.Focused)
...{
this.button1.Focus();
}
}
}
}
}
}
break;
case 40:
case 39:
if( this.textBox1.Focused)
...{
this.textBox2.Focus();
}
else
...{
if( this.textBox2.Focused)
...{
this.textBox3.Focus();
}
else
...{
if( this.textBox3.Focused)
...{
this.textBox4.Focus();
}
else
...{
if( this.textBox4.Focused)
...{
this.button1.Focus();
}
else
...{
if(this.button1.Focused)
...{
this.button2.Focus();
}
}
}
}
}
break;
}
}
锁定系统功能的实现代码
private void menuItemsd_Click( object sender, System.EventArgs e)
... { //提示用户,然后调用主窗口的登录窗口。
MessageBox.Show("请注意思关闭不安全的窗口!!!","锁定提示:",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
Form1_Load(null,null);
}
帮助窗体代码
private void bz_Load( object sender, System.EventArgs e)
... { //打开帮助文件并显示其中的内容。
Stream theStream=null;
try
...{
FileInfo File = new FileInfo ("./Help.hp");
int byteCount =(int) File.Length;
byte [] buffer = new byte[byteCount];
theStream =File.Open(System.IO.FileMode.Open,System.IO.FileAccess.Read,System.IO.FileShare.None);
theStream.Read (buffer,0,byteCount);
this.textBox1.Text=System.Text.Encoding.Default.GetString(buffer,0,byteCount);
theStream.Close();
}
catch(Exception Exc)
...{
MessageBox.Show("帮助文件丢失,或"+Exc,"系统提示:",MessageBoxButtons.OK,MessageBoxIcon.Error);
theStream.Close();
}
}
关于实训窗体代码
private void gy_Click( object sender, System.EventArgs e)
... { //当用户单击窗体任意地方时关闭当前窗口。
this.Close();
}
工具栏相关代码
private void toolBar1_ButtonClick( object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
... { //根据提示调用相关功能。
switch(e.Button.Text)
...{
case "借书":
menuItemjsgl_Click(null,null);
break;
case "还书":
menuItemhsgl_Click(null,null);
break;
case "查书":
menuItemsmcx_Click(null,null);
break;
case "查读者":
menuItemdzcx_Click(null,null);
break;
case "查员工":
menuItemcxyg_Click(null,null);
break;
case "密码":
menuItemmmxg_Click(null,null);
break;
case "锁定":
menuItemsdxt_Click(null,null);
break;
case "隐藏":
this.toolBar1.Visible=false;
break;
case "帮助":
menuItemsysm_Click(null,null);
break;
}
}
右键相关代码
在相关的菜单单击事件中已调用。