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

📄 ruturninfoupdate.java

📁 图书馆系统
💻 JAVA
字号:
import java.awt.BorderLayout;

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import java.awt.GraphicsConfiguration;
import java.awt.HeadlessException;

import javax.swing.JFrame;
import java.awt.Dimension;
import javax.swing.JLabel;
import java.awt.Rectangle;
import javax.swing.JTextField;
import java.awt.Point;
import javax.swing.JButton;
import java.sql.*;

import javax.swing.JComboBox;

public class ruturnInfoUpdate extends JFrame {

	private static final long serialVersionUID = 1L;

	private JPanel jContentPane = null;

	private JLabel jLabel = null;

	private JLabel jLabel1 = null;

	private JLabel jLabel2 = null;

	private JLabel jLabel3 = null;

	private JLabel jLabel4 = null;

	private JLabel jLabel5 = null;

	private JTextField jTextborrowdate = null;

	private JTextField jTextreturndate = null;

	private JTextField jTextcomment = null;

	private JButton jButtonClear = null;

	private JButton jButtonOK = null;

	private JButton jButtonupdate = null;

	private JButton jButtonexit = null;
	ResultSet rs;
    DBManager db=new DBManager();

	private JComboBox jComboBoxstudentname = null;

	private JComboBox jComboBoxbookname = null;

	public ruturnInfoUpdate() throws HeadlessException {
		// TODO 自动生成构造函数存根
		super();
		initialize();
	}

	public ruturnInfoUpdate(GraphicsConfiguration arg0) {
		super(arg0);
		// TODO 自动生成构造函数存根
		initialize();
	}

	public ruturnInfoUpdate(String arg0) throws HeadlessException {
		super(arg0);
		// TODO 自动生成构造函数存根
		initialize();
	}

	public ruturnInfoUpdate(String arg0, GraphicsConfiguration arg1) {
		super(arg0, arg1);
		// TODO 自动生成构造函数存根
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(455, 323);
		this.setContentPane(getJContentPane());
		this.setTitle("书籍还入信息修改");
		this.addWindowListener(new java.awt.event.WindowAdapter() {
			public void windowOpened(java.awt.event.WindowEvent e) {
				System.out.println("windowOpened()"); // TODO Auto-generated Event stub windowOpened()
				String sql="select Studentname from BookBorrow",SQL="select Bookname from BookBorrow";
				rs=db.getResult(sql);
				boolean isexist=false;
				try{
					isexist=rs.first();
				}
				catch(SQLException ex){
					
				}
				if(!isexist){
					JOptionPane.showMessageDialog(null, "没有用户,请确认", "错误", JOptionPane.ERROR_MESSAGE);
					return;
				}
				else{
					try{
						rs.beforeFirst();
						//循环遍历rs中的数据,将其加到jcomboboxbookname中
						while(rs.next()){
							jComboBoxstudentname.addItem(rs.getString("Studentname"));
						}
					}
					catch(SQLException ex){
						
					}
				}
				rs=db.getResult(SQL);
				isexist=false;
				try{
					isexist=rs.first();
				}
				catch(SQLException ex){
					
				}
				if(!isexist){
					JOptionPane.showMessageDialog(null, "没有用户,请确认", "错误", JOptionPane.ERROR_MESSAGE);
					return;
				}
				else{
					try{
						rs.beforeFirst();
						//循环遍历rs中的数据,将其加到jcomboboxbookname中
						while(rs.next()){
							jComboBoxbookname.addItem(rs.getString("Bookname"));
						}
					}
					catch(SQLException ex){
						
					}
				}
			}
		});
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jLabel5 = new JLabel();
			jLabel5.setBounds(new Rectangle(46, 170, 38, 18));
			jLabel5.setText("备注");
			jLabel4 = new JLabel();
			jLabel4.setBounds(new Rectangle(45, 140, 74, 18));
			jLabel4.setText("还书日期");
			jLabel3 = new JLabel();
			jLabel3.setBounds(new Rectangle(45, 110, 76, 18));
			jLabel3.setText("借阅日期");
			jLabel2 = new JLabel();
			jLabel2.setBounds(new Rectangle(45, 80, 38, 18));
			jLabel2.setText("书名");
			jLabel1 = new JLabel();
			jLabel1.setBounds(new Rectangle(45, 50, 83, 18));
			jLabel1.setText("借阅者姓名");
			jLabel = new JLabel();
			jLabel.setBounds(new Rectangle(10, 8, 355, 18));
			jLabel.setText("输入借阅者姓名或书名点击确定,将调出此书相关信息");
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(jLabel, null);
			jContentPane.add(jLabel1, null);
			jContentPane.add(jLabel2, null);
			jContentPane.add(jLabel3, null);
			jContentPane.add(jLabel4, null);
			jContentPane.add(jLabel5, null);
			jContentPane.add(getJTextborrowdate(), null);
			jContentPane.add(getJTextreturndate(), null);
			jContentPane.add(getJTextcomment(), null);
			jContentPane.add(getJButtonClear(), null);
			jContentPane.add(getJButtonOK(), null);
			jContentPane.add(getJButtonupdate(), null);
			jContentPane.add(getJButtonexit(), null);
			jContentPane.add(getJComboBoxstudentname(), null);
			jContentPane.add(getJComboBoxbookname(), null);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jTextborrowdate	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextborrowdate() {
		if (jTextborrowdate == null) {
			jTextborrowdate = new JTextField();
			jTextborrowdate.setLocation(new Point(180, 110));
			jTextborrowdate.setSize(new Dimension(150, 20));
		}
		return jTextborrowdate;
	}

	/**
	 * This method initializes jTextreturndate	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextreturndate() {
		if (jTextreturndate == null) {
			jTextreturndate = new JTextField();
			jTextreturndate.setLocation(new Point(180, 140));
			jTextreturndate.setSize(new Dimension(150, 20));
		}
		return jTextreturndate;
	}

	/**
	 * This method initializes jTextcomment	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextcomment() {
		if (jTextcomment == null) {
			jTextcomment = new JTextField();
			jTextcomment.setLocation(new Point(180, 170));
			jTextcomment.setSize(new Dimension(150, 20));
		}
		return jTextcomment;
	}

	/**
	 * This method initializes jButtonClear	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonClear() {
		if (jButtonClear == null) {
			jButtonClear = new JButton();
			jButtonClear.setLocation(new Point(60, 210));
			jButtonClear.setText("清空");
			jButtonClear.setSize(new Dimension(60, 20));
			jButtonClear.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
					jComboBoxstudentname.setSelectedItem("");
					jComboBoxbookname.setSelectedItem("");
					jTextreturndate.setText("");
					jTextborrowdate.setText("");
					jTextcomment.setText("");
				}
			});
		}
		return jButtonClear;
	}

	/**
	 * This method initializes jButtonOK	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonOK() {
		if (jButtonOK == null) {
			jButtonOK = new JButton();
			jButtonOK.setLocation(new Point(130, 210));
			jButtonOK.setText("确定");
			jButtonOK.setSize(new Dimension(60, 20));
			jButtonOK.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
					String sql;
					boolean isfirst=true;
					sql="select * from BookBorrow ";
					if(jComboBoxstudentname.getSelectedItem().toString().trim().length()==0){}
					else{	
						sql=sql+" where Studentname='"+jComboBoxstudentname.getSelectedItem().toString().trim()+"'";
						isfirst=false;
					}
					//如果书名的查询条件不为空
					if(jComboBoxbookname.getSelectedItem().toString().trim().length()==0){
						
					}
					else{
						if(isfirst){
							sql=sql+" where Bookname='"+jComboBoxbookname.getSelectedItem().toString().trim()+"'";
						}
						else 
							sql=sql+" and Bookname='"+jComboBoxbookname.getSelectedItem().toString().trim()+"'";
					}
					rs=db.getResult(sql);
					try{
						if(!rs.equals(null)){
							rs.first();
							jComboBoxstudentname.setSelectedItem(rs.getString("Studentname"));
							jComboBoxbookname.setSelectedItem(rs.getString("Bookname"));
							jTextreturndate.setText(rs.getString("Returndate"));
							jTextborrowdate.setText(rs.getString("Borrowdate"));
							jTextcomment.setText(rs.getString("Comment"));
						}
						else{
							JOptionPane.showMessageDialog(null, "无此记录", "错误", JOptionPane.ERROR_MESSAGE);
							return;
						}
					}
					catch(SQLException ex){
						JOptionPane.showMessageDialog(null, "无此记录", "错误", JOptionPane.ERROR_MESSAGE);
						return;
					}
				}
			});
		}
		return jButtonOK;
	}

	/**
	 * This method initializes jButtonupdate	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonupdate() {
		if (jButtonupdate == null) {
			jButtonupdate = new JButton();
			jButtonupdate.setLocation(new Point(200, 210));
			jButtonupdate.setText("更新");
			jButtonupdate.setSize(new Dimension(60, 20));
			jButtonupdate.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
					String strSQL;
					strSQL="update BookBorrow set ";
					strSQL=strSQL+" Borrowdate='"+jTextborrowdate.getText().trim()+"',";
					strSQL=strSQL+" Returndate='"+jTextreturndate.getText().trim()+"',";
					strSQL=strSQL+" Comment='"+jTextcomment.getText().trim()+"'";
					strSQL=strSQL+" where Studentname='"+jComboBoxstudentname.getSelectedItem().toString().trim()+"'";
					strSQL=strSQL+" and Bookname='"+jComboBoxbookname.getSelectedItem().toString().trim()+"'";
					//由数据库执行
					if(db.executeSql(strSQL)){
						JOptionPane.showMessageDialog(null, "更新成功", "成功", JOptionPane.INFORMATION_MESSAGE);
						buttonexit();
					}
					else{
						JOptionPane.showMessageDialog(null, "更新失败,请重新操作", "错误", JOptionPane.ERROR_MESSAGE);
						return;
					}
				}
			});
		}
		return jButtonupdate;
	}

	/**
	 * This method initializes jButtonexit	
	 * 	
	 * @return javax.swing.JButton	
	 */
	public void buttonexit(){
		this.dispose();
	}
	private JButton getJButtonexit() {
		if (jButtonexit == null) {
			jButtonexit = new JButton();
			jButtonexit.setLocation(new Point(270, 210));
			jButtonexit.setText("退出");
			jButtonexit.setSize(new Dimension(60, 20));
			jButtonexit.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
					buttonexit();
				}
			});
		}
		return jButtonexit;
	}

	/**
	 * This method initializes jComboBoxstudentname	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getJComboBoxstudentname() {
		if (jComboBoxstudentname == null) {
			jComboBoxstudentname = new JComboBox();
			jComboBoxstudentname.setLocation(new Point(180, 50));
			jComboBoxstudentname.setEditable(true);
			jComboBoxstudentname.setSize(new Dimension(150, 20));
		}
		return jComboBoxstudentname;
	}

	/**
	 * This method initializes jComboBoxbookname	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getJComboBoxbookname() {
		if (jComboBoxbookname == null) {
			jComboBoxbookname = new JComboBox();
			jComboBoxbookname.setLocation(new Point(180, 80));
			jComboBoxbookname.setEditable(true);
			jComboBoxbookname.setSize(new Dimension(150, 20));
		}
		return jComboBoxbookname;
	}

}  //  @jve:decl-index=0:visual-constraint="10,10"

⌨️ 快捷键说明

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