⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readermanagement.java

📁 JAVA编写的图书馆管理系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		JScrollPane scrollPane=new JScrollPane(table,
		                       JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
		                       JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        try{ view();}
		catch(SQLException ed){}
		//--设置各个组件的大小和位置--
        scrollPane.setBounds(10,270,wndsize.width-40,wndsize.height-365);

		//--设置各个组件的字体--
		table.setFont(font1);

		//--将各个组件添加到容器中--
		pane.add(scrollPane);

 content.add(JTB);
 content.add(pane);
 //content.add(jp1);
 frame.setSize(wndsize);
 frame.setResizable(false);
 frame.setVisible(true);
}
/*********************************单击显示表格中数据到文本框中代码************************************************/
 public void valueChanged(ListSelectionEvent el)
 { String tempString="";
	       //JTable的getSelectedRows()与getSelectedColumns()方法会返回已选取表格cell的index Array数据.
	   	  int[] rows=table.getSelectedRows();
	   	  int[] columns=table.getSelectedColumns();

	       //JTable的getValueAt()方法会返回某行的cell数据,返回值是Object数据类型,因此我们要自行转成String数据类型.
	   	    for (int i=0;i<rows.length;i++){
	   	      for (int j=0;j<columns.length;j++)
	                tempString = tempString+(String)table.getValueAt(rows[i], columns[j]);
	   	    }

	   	   jtfd1.setText(tempString);jtfd2.setText(tempString);jtfd3.setText(tempString);jtfd4.setText(tempString);
	   	   jtfd5.setText(tempString);jtfd6.setText(tempString);jtfd7.setText(tempString);jtfd8.setText(tempString);
	   	   jtfd9.setText(tempString);jtfd10.setText(tempString);jtfd11.setText(tempString);jtfd12.setText(tempString);
	   	   jtfd13.setText(tempString);jtfd14.setText(tempString);jtfd15.setText(tempString);jtfd16.setText(tempString);
	   	   jta.setText(tempString);
	   	   try{ Update1();}
		        catch(SQLException ed){}
}
/*********************************查询读者信息代码************************************************/
public void Update1() throws SQLException
		    {
				String strurl=
								"jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=DataBase/Library.mdb";
				  try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
				  catch (ClassNotFoundException eg) {}
				  con= DriverManager.getConnection(strurl);
				  Statement stmt= con.createStatement();
				  ResultSet rs1 = stmt.executeQuery("select * from 读者资料");
				  while(rs1.next())
				  {      String bookname=rs1.getString(1);
						 String bianhao=rs1.getString(2);
						 String bookcode=rs1.getString(3);
						 String fenlei=rs1.getString(4);
						 String zuozhe=rs1.getString(5);
						 String type=rs1.getString(6);
						 String zjhm=rs1.getString(7);
						 String price=rs1.getString(8);
						 String press=rs1.getString(9);
						 String page=rs1.getString(10);
						 String sheefname=rs1.getString(11);
						 String chuban=rs1.getString(12);
						 String ruku=rs1.getString(13);
						 String stock=rs1.getString(14);
						 String zuicang=rs1.getString(15);
						 String borrow=rs1.getString(16);
						 String status=rs1.getString(17);
                         String oparator=rs1.getString(18);
				   if(bianhao.equals(jtfd2.getText().trim())||bookcode.equals(jtfd3.getText().trim()))
				   {
				    jtfd1.setText(bookname);jtfd2.setText(bianhao);jtfd3.setText(bookcode);jtfd4.setText(fenlei);
                    jtfd8.setText(zuozhe);jtfd10.setText(type);jtfd5.setText(zjhm);jtfd6.setText(price);
                    jtfd7.setText(press);jtfd9.setText(page);jtfd11.setText(sheefname);jtfd12.setText(chuban);
                    jtfd13.setText(ruku);jtfd14.setText(stock);jtfd15.setText(zuicang);jtfd16.setText(status);
                    jta.setText(oparator);
			        }
				}
	}
/*********************************各个按钮事件代码************************************************/
 public void actionPerformed(ActionEvent e)
 {str1=jtfd1.getText().trim();
  str2=jtfd2.getText().trim();
  str3=jtfd3.getText().trim();
  str4=jtfd4.getText().trim();
  str5=jtfd8.getText().trim();
  str6=jtfd10.getText().trim();
  str7=jtfd5.getText().trim();
  str8=jtfd6.getText().trim();
  str9=jtfd7.getText().trim();
  str10=jtfd9.getText().trim();
  str11=jtfd11.getText().trim();
  str12=jtfd12.getText().trim();
  str13=jtfd13.getText().trim();
  str14=jtfd14.getText().trim();
  str17=jtfd15.getText().trim();
  str16=jta.getText().trim();
  str15=jtfd16.getText().trim();
  Object obj=(JButton)e.getSource();
  if(obj==btn01)//查询按钮
  {new ReaderCF(this);}
  if(obj==btn02)//刷新按钮
  {try{ view();}
		catch(SQLException ed){}
   }
   if(obj==btn03)//挂失按钮
   {try{ Update();}
		catch(SQLException ed){}
	}
   if(obj==btn04)//解除挂失按钮
   {try{ Update2();}
		catch(SQLException ed){}}
   if(obj==btn05)//到期续证按钮
   {try{ Update3();}
		catch(SQLException ed){}}
   if(obj==btn06)//退出按钮
   {frame.dispose();}
}
/*********************************设置读者状态为已挂失代码************************************************/
public void Update() throws SQLException
{ String status1,status2,status3,status4;
  status1="已挂失";status2="已解除挂失";status3="已到期";
  String strurl =
  	 			  "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=DataBase/Library.mdb";
  try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
  catch (ClassNotFoundException es) {}
  con= DriverManager.getConnection(strurl);
  Statement stmt = con.createStatement();
  if(str2.equals("")|str3.equals(""))
  { JOptionPane.showMessageDialog(frame,"读者编号和条形码不能为空,请您在表格中选择或点击查询按钮!");
    return;
  }
  else { ResultSet rs = stmt.executeQuery("select * from 读者资料  ");
         if(rs.next())
         {
           stmt.executeUpdate("update 读者资料 set 读者状态='"+status1+"'where 条形码='"+str3+"'");
  	       JOptionPane.showMessageDialog(null, "挂失此读者信息成功!");
  	       try{ view();}
		   catch(SQLException ed){}
		   try{ Update1();}
		   catch(SQLException ed){}
         }
       }
      con.close();
}
/*********************************设置读者状态为已解除挂失代码************************************************/
public void Update2() throws SQLException
{ String status1,status2,status3,status4;
  status1="已挂失";status2="正常";status3="已到期";
  String strurl =
  	 			  "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=DataBase/Library.mdb";
  try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
  catch (ClassNotFoundException es) {}
  con= DriverManager.getConnection(strurl);
  Statement stmt = con.createStatement();
  if(str2.equals("")|str3.equals(""))
  { JOptionPane.showMessageDialog(frame,"读者编号和条形码不能为空,请您在表格中选择或点击查询按钮!");
    return;
  }
  else { ResultSet rs = stmt.executeQuery("select * from 读者资料  ");
         if(rs.next())
         {
           stmt.executeUpdate("update 读者资料 set 读者状态='"+status2+"'where 条形码='"+str3+"'");
  	       JOptionPane.showMessageDialog(null, "解除挂失此读者信息成功!");
  	       try{ view();}
		   catch(SQLException ed){}
		   try{ Update1();}
		   catch(SQLException ed){}
         }
       }
      con.close();
}
/*********************************为读者办理续证代码************************************************/
public void Update3() throws SQLException
{ String status1,status2,status3,status4;
  status1="已挂失";status2="正常";status3="已到期";
  String strurl =
  	 			  "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=DataBase/Library.mdb";
  try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
  catch (ClassNotFoundException es) {}
  con= DriverManager.getConnection(strurl);
  Statement stmt = con.createStatement();
  if(str2.equals("")|str3.equals(""))
  { JOptionPane.showMessageDialog(frame,"读者编号和条形码不能为空,请您在表格中选择或点击查询按钮!");
    return;
  }
  else { ResultSet rs = stmt.executeQuery("select * from 读者资料  ");
         if(rs.next())
         {
           stmt.executeUpdate("update 读者资料 set 读者状态='"+status2+"',截止日期='"+str9+"'where 条形码='"+str3+"'");
  	       JOptionPane.showMessageDialog(null, "读者续证成功!");
  	       try{ view();}
		   catch(SQLException ed){}
		   try{ Update1();}
		   catch(SQLException ed){}
         }
       }
      con.close();
}
/*********************************表格和数据库连接代码************************************************/
public void view() throws SQLException
	    { //--连接表格和数据库--
					int i=0;
					try{
						String strurl1 =
									    "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=DataBase/Library.mdb";
						try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
						catch (ClassNotFoundException eg) {}
						con= DriverManager.getConnection(strurl1);
						Statement stmt1= con.createStatement();
						ResultSet rs1 = stmt1.executeQuery("select * from 读者资料 ORDER BY 读者编号");
						while(rs1.next())
						{String bookname=rs1.getString(1);
						 String bianhao=rs1.getString(2);
						 String bookcode=rs1.getString(3);
						 String fenlei=rs1.getString(4);
						 String zuozhe=rs1.getString(5);
						 String type=rs1.getString(6);
						 String zjhm=rs1.getString(7);
						 String price=rs1.getString(8);
						 String press=rs1.getString(9);
						 String page=rs1.getString(10);
						 String sheefname=rs1.getString(11);
						 String chuban=rs1.getString(12);
						 String ruku=rs1.getString(13);
						 String stock=rs1.getString(14);
						 String zuicang=rs1.getString(15);
						 String borrow=rs1.getString(16);
						 String status=rs1.getString(17);
                         String oparator=rs1.getString(18);

						 rowData[i][0]=bookname;
						 rowData[i][1]=bianhao;
						 rowData[i][2]=bookcode;
						 rowData[i][3]=fenlei;
						 rowData[i][4]=zuozhe;
						 rowData[i][5]=type;
						 rowData[i][6]=zjhm;
						 rowData[i][7]=price;
						 rowData[i][8]=press;
						 rowData[i][9]=page;
						 rowData[i][10]=sheefname;
						 rowData[i][11]=chuban;
						 rowData[i][12]=ruku;
						 rowData[i][13]=stock;
						 rowData[i][14]=zuicang;
						 rowData[i][15]=borrow;
						 rowData[i][16]=status;
						 rowData[i][17]=oparator;
						 i++;
			             }
			             table.repaint();
		                 con.close();
					    }
					catch(Exception es){//JOptionPane.showMessageDialog(null, "数据库中没有成绩信息", "警告",
								                                   //JOptionPane.WARNING_MESSAGE);
									es.printStackTrace();}
	}

public static void main(String[]args)
		{   try {
		            UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
		            }
		        catch(Exception e) {
		            e.printStackTrace();
		           }
			new ReaderManagement();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -