您好,欢迎访问三七文档
当前位置:首页 > IT计算机/网络 > 数据库 > 图书管理系统(内附源代码)
本人是一个初学者,2个月前学习C#,学习过程中遇到过许多困难无法独立解决,现在做成了第一个系统:图书管理系统,各项功能均能顺利实现,因为知道很多初学者和我一样苦无求学之道,现在将部分主要源码上传,希望能得到高手的指点。下面就是该系统的主要功能及代码:1.登陆界面主要代码:publicpartialclassLoginForm:Form{publicstaticstringuacc;publicstaticstringupsw;publicstaticstringuname;publicstaticstringusex;publicstaticstringupart;publicstaticstringuright;publicLoginForm(){InitializeComponent();}privatevoidloginbtn_Click(objectsender,EventArgse){if(this.useracctxt.Text.Trim()==&&this.pswtxt.Text==){MessageBox.Show(请输入您的用户名和密码!,提示!);return;}try{stringsql;sql=select*fromtb_userwhereuacc='+this.useracctxt.Text+'andupsw='+this.pswtxt.Text+';OleDbDataReaderdr=DBHelp.OleReader(sql);dr.Read();if(dr.HasRows){uacc=this.useracctxt.Text;upsw=this.pswtxt.Text;uname=dr[uname].ToString();usex=dr[usex].ToString();upart=dr[upart].ToString();uright=dr[uright].ToString();MainFormaf=newMainForm(this);this.Hide();this.useracctxt.Clear();this.pswtxt.Clear();af.Show();}else{MessageBox.Show(账号或密码错误!,提示!);this.useracctxt.Clear();this.pswtxt.Clear();this.useracctxt.Focus();}}catch(Exception){MessageBox.Show(数据库无法连接!,警告!);}}privatevoidcancelbtn_Click(objectsender,EventArgse){Application.Exit();}privatevoidLoginForm_Closing(objectsender,FormClosingEventArgse){Application.Exit();}}2.主界面(图较小,自己可以拉大点)主要代码就不写了,很简单。3.权限设置主要代码:publicpartialclassRightSet:Form{publicRightSet(){InitializeComponent();}privatevoidRightSet_Load(objectsender,EventArgse){this.rightbox.SelectedIndex=0;//this.treeright.ExpandAll();Fill();}privatevoidokbtn_Click(objectsender,EventArgse){if(this.txtnum.Text==string.Empty){MessageBox.Show(请输入最大借阅图书数量!,提示!);return;}if(this.txtday.Text==string.Empty){MessageBox.Show(请输入最大借阅图书时间!,提示!);return;}if(this.txtcost.Text==string.Empty){MessageBox.Show(请输入借书押金金额!,提示!);return;}if(this.txtfine.Text==string.Empty){MessageBox.Show(请输入超期罚款金额!,提示!);return;}if(this.txttim.Text==string.Empty){MessageBox.Show(请输入图书遗失罚款倍数!,提示!);return;}ArrayListarr=newArrayList();foreach(TreeNodenodesinthis.treeright.Nodes){if(nodes.Checked){arr.Add(1);}else{arr.Add(0);}foreach(TreeNodenodeinnodes.Nodes){if(node.Checked){arr.Add(1);}else{arr.Add(0);}}}string[]a=newstring[11];for(inti=0;iarr.Count;i++){if(arr[i].ToString().Trim()==1){a[i]=yes;}else{a[i]=no;}}stringsql=string.Empty;sql+=select*fromtb_rightwhereuright='+this.rightbox.Text+';DataTabledt=DBHelp.ExeOleCommand(sql);boolb=false;while(dt.Rows.Count!=0){b=true;break;}stringsql1;if(b){sql1=updatetb_rightset;sql1+=maxbook='+this.txtnum.Text+',;sql1+=maxdate='+this.txtday.Text+',;sql1+=rcost='+this.txtcost.Text+',;sql1+=rfine='+this.txtfine.Text+',;sql1+=rtim='+this.txttim.Text+',;sql1+=rbm='+a[0]+',;sql1+=rum='+a[1]+',;sql1+=rrm='+a[2]+',;sql1+=rborm='+a[3]+',;sql1+=ris='+a[4]+',;sql1+=rbis='+a[5]+',;sql1+=ruis='+a[6]+',;sql1+=rboris='+a[7]+',;sql1+=rblp='+a[8]+',;sql1+=rbl='+a[9]+',;sql1+=rlp='+a[10]+';sql1+=whereuright='+this.rightbox.Text+';}else{sql1=insertintotb_right(uright,maxbook,maxdate,rcost,rfine,rtim,rbm,rum,rrm,rborm,ris,rbis,ruis,rboris,rblp,rbl,rlp);sql1+=values('+this.rightbox.Text+','+this.txtnum.Text+','+this.txtday.Text+','+this.txtcost.Text+','+this.txtfine.Text+','+this.txttim.Text+','+a[0]+','+a[1]+','+a[2]+','+a[3]+','+a[4]+','+a[5]+','+a[6]+','+a[7]+','+a[8]+','+a[9]+','+a[10]+');}DataTabledt1=DBHelp.ExeOleCommand(sql1);Fill();}privatevoidFill(){stringsql;sql=selectridasID号,urightas用户身份,maxbookas最大借书数量,maxdateas最大借阅时间,rcostas押金,rfineas超期罚率,rtimas遗失赔率,rbmas图书管理,rumas用户管理,rrmas权限管理,rbormas借阅管理,risas信息查询,rbisas图书信息查询,ruisas用户信息查询,rborisas借阅历史查询,rblpas图书挂失处理,rblas图书挂失,rlpas挂失处理fromtb_right;DataTabledt=DBHelp.ExeOleCommand(sql);this.dataGridView1.DataSource=dt;}privatevoidcell_click(objectsender,DataGridViewCellEventArgse){this.rightbox.Text=this.dataGridView1[1,this.dataGridView1.CurrentCell.RowIndex].Value.ToString().Trim();this.txtnum.Text=this.dataGridView1[2,this.dataGridView1.CurrentCell.RowIndex].Value.ToString().Trim();this.txtday.Text=this.dataGridView1[3,this.dataGridView1.CurrentCell.RowIndex].Value.ToString().Trim();this.txtcost.Text=this.dataGridView1[4,this.dataGridView1.CurrentCell.RowIndex].Value.ToString().Trim();this.txtfine.Text=this.dataGridView1[5,this.dataGridView1.CurrentCell.RowIndex].Value.ToString().Trim();this.txttim.Text=this.dataGridView1[6,this.dataGridView1.CurrentCell.RowIndex].Value.ToString().Trim();ArrayListlist=newArrayList();stringsql=select*fromtb_rightwhereuright='+this.rightbox.Text+';DataTabledt=DBHelp.ExeOleCommand(sql);if(dt.Rows.Count!=0){for(inti=0;i11;i++){list.Add(dt.Rows[0][7+i].ToString());}ArrayListarr=newArrayList();foreach(TreeNodenodesinthis.treeright.Nodes){arr.Add(nodes);foreach(TreeNodenodeinnodes.Nodes){arr.Add(node);}}for(inti=0;ilist.Count;i++){if(list[i].ToString()==yes){((TreeNode)arr[i]).Checked=true;}else{((TreeNode)arr[i]).Checked=false;}}}}4.权限修改主要代码:publicpartialclassUserRight:Form{publicUserRight(){InitializeComponent();}privatevoidbtncancel_Click(objectsender,EventArgse){this.Close();}privatevoidUserRight_Load(objectsender,EventArgse){this.checkbox.SelectedInd
本文标题:图书管理系统(内附源代码)
链接地址:https://www.777doc.com/doc-3967294 .html