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

📄 findbook.java

📁 用java实现图书资料管理系统 操作系统:Windows 数据库:Windows Access 数据库 开发平台:NetBeans 开发语言:Java 语言
💻 JAVA
字号:
/*
 * register.java
 *
 * Created on 2007年12月18日, 下午11:12
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

/**
 *
 * @author Owner
 */
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.ButtonGroup;
import java.sql.*;
import java.util.*;
import java.util.Date;

public class findbook extends JPanel implements ActionListener
{
    Panel pcenter;
    CardLayout card;
    Box basebox,box1,box2,box3,box4,box5;
    JButton certainquery,uncertainquery,reset,allbook;
    JTextField isbn,bookname,author,price,barcode;
    JTextArea content;
    Choice publisherlist,bookclasslist;
    Connection con;
    Statement sql;
    ResultSet rs;
    String s;
    userflag userflag;
    int publisherindex,bookclassindex;
    /** Creates a new instance of register */
    public findbook(userflag userflag,Panel pcenter,CardLayout card) {
        this.pcenter=pcenter;
        this.card=card;
        this.userflag=userflag;
        if(userflag.flag==false)
        {
            JOptionPane.showMessageDialog(this,"您还没登录");
            add(new Label("请先登录"),BorderLayout.CENTER);
        }
        else
        {
            isbn=new JTextField(15);
            barcode=new JTextField(15);
            bookname=new JTextField(15);
            author=new JTextField(15);
            price=new JTextField(15);
            content=new JTextArea(6,15);
            publisherlist=new Choice();
            bookclasslist=new Choice();
            try
            {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            }
            catch(ClassNotFoundException e2){}
            try
            {
                con=DriverManager.getConnection("jdbc:odbc:sample","std","123");
                sql=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
                s="select * from publisher";
                rs=sql.executeQuery(s);
                publisherlist.add("请选择出版商");
                while(rs.next())
                {
                    publisherlist.add(rs.getString("publishername"));
                }
                s="select * from bookclass";
                rs=sql.executeQuery(s);
                bookclasslist.add("请选择图书类型");
                while(rs.next())
                {
                    bookclasslist.add(rs.getString("bookclassname"));
                }
                publisherlist.select(0);
                bookclasslist.select(0);
            }
            catch(SQLException e3)
            {
               System.out.println(e3);
            }
            allbook=new JButton("所有图书");
            certainquery=new JButton("精确查找");
            uncertainquery=new JButton("模糊查找");
            reset=new JButton("    重设    ");
            allbook.addActionListener(this);
            certainquery.addActionListener(this);
            uncertainquery.addActionListener(this);
            reset.addActionListener(this);

            box1=Box.createVerticalBox();
            box1.add(new Label("图书标识"));
            box1.add(Box.createVerticalStrut(8));
            box1.add(new Label("图书ISBN"));
            box1.add(Box.createVerticalStrut(8));
            box1.add(new Label("图书名称"));
            box1.add(Box.createVerticalStrut(8));
            box1.add(new Label("出版商"));
            box1.add(Box.createVerticalStrut(8));
            box1.add(new Label("图书类型"));
            box1.add(Box.createVerticalStrut(8));
            box1.add(new Label("作者"));
            box1.add(Box.createVerticalStrut(8));
            box1.add(new Label("价格"));
            box1.add(Box.createVerticalStrut(8));
            box1.add(new Label("内容简介"));
            box1.add(Box.createVerticalStrut(90));

            box2=Box.createVerticalBox();
            box2.add(barcode);
            box2.add(Box.createVerticalStrut(8));
            box2.add(isbn);
            box2.add(Box.createVerticalStrut(8));
            box2.add(bookname);
            box2.add(Box.createVerticalStrut(8));
            box2.add(publisherlist);
            box2.add(Box.createVerticalStrut(8));
            box2.add(bookclasslist);
            box2.add(Box.createVerticalStrut(8));
            box2.add(author);
            box2.add(Box.createVerticalStrut(8));
            box2.add(price);
            box2.add(Box.createVerticalStrut(15));
            box2.add(content);


            box3=Box.createHorizontalBox();
            box3.add(box1);
            box3.add(Box.createHorizontalStrut(10));
            box3.add(box2);

            box4=Box.createHorizontalBox();
            box4.add(certainquery);
            box4.add(Box.createHorizontalStrut(35));
            box4.add(uncertainquery);

            box5=Box.createHorizontalBox();
            box5.add(allbook);
            box5.add(Box.createHorizontalStrut(35));
            box5.add(reset);

            basebox=Box.createVerticalBox();
            basebox.add(new Label("请输入要查找的图书信息:"));
            basebox.add(Box.createVerticalStrut(15));
            basebox.add(box3);
            basebox.add(Box.createVerticalStrut(15));
            basebox.add(box4);
            basebox.add(Box.createVerticalStrut(15));
            basebox.add(box5);
            add(basebox);
        }
    }
    public void actionPerformed(ActionEvent e)
    {
        if(e.getSource()==allbook)
        {
            String s="select * from bookinfo,publisher,bookclass where bookinfo.publisherid=publisher.id and bookinfo.bookclassid=bookclass.id";
            showbook show=new showbook(pcenter,card,s);
            pcenter.add("showbook",show);
            card.show(pcenter,"showbook");
        }
        else if(e.getSource()==certainquery)
        {           
           if(publisherlist.getSelectedIndex()==0&&bookclasslist.getSelectedIndex()==0&&content.getText().equals("")&&isbn.getText().equals("")&&barcode.getText().equals("")&&author.getText().equals("")&&bookname.getText().equals("")&&price.getText().equals(""))
            {
                JOptionPane.showMessageDialog(this,"图书信息不能全部为空");
            }
            else
            {
                String s="select * from bookinfo,publisher,bookclass where bookinfo.publisherid=publisher.id and bookinfo.bookclassid=bookclass.id";
                if(!barcode.getText().equals(""))
                    s=s+" and barcode='"+barcode.getText()+"'";
                if(!bookname.getText().equals(""))
                    s=s+" and bookname='"+bookname.getText()+"'";
                if(!price.getText().equals(""))
                    s=s+" and price='"+price.getText()+"'";
                if(!isbn.getText().equals(""))
                    s=s+" and isbn='"+isbn.getText()+"'";
                if(!content.getText().equals(""))
                    s=s+" and content='"+content.getText()+"'";
                if(!author.getText().equals(""))
                    s=s+" and author='"+author.getText()+"'";
                if(publisherlist.getSelectedIndex()!=0)
                    s=s+" and publisherid='"+publisherlist.getSelectedIndex()+"'";
                if(bookclasslist.getSelectedIndex()!=0)
                    s=s+" and bookclassid='"+bookclasslist.getSelectedIndex()+"'";
                System.out.println(s);
                showbook show=new showbook(pcenter,card,s);
                pcenter.add("showbook",show);
                card.show(pcenter,"showbook");
                
            }
        }
         else if(e.getSource()==uncertainquery)
        {           
           if(publisherlist.getSelectedIndex()==0&&bookclasslist.getSelectedIndex()==0&&content.getText().equals("")&&isbn.getText().equals("")&&barcode.getText().equals("")&&author.getText().equals("")&&bookname.getText().equals("")&&price.getText().equals(""))
            {
                JOptionPane.showMessageDialog(this,"图书信息不能全部为空");
            }
            else
            {
                String s="select * from bookinfo,publisher,bookclass where bookinfo.publisherid=publisher.id and bookinfo.bookclassid=bookclass.id";
                if(!barcode.getText().equals(""))
                    s=s+" and barcode like '%"+barcode.getText()+"%'";
                if(!bookname.getText().equals(""))
                    s=s+" and bookname like '%"+bookname.getText()+"%'";
                if(!price.getText().equals(""))
                    s=s+" and price like '%"+price.getText()+"%'";
                if(!isbn.getText().equals(""))
                    s=s+" and isbn like '%"+isbn.getText()+"%'";
                if(!content.getText().equals(""))
                    s=s+" and content like '%"+content.getText()+"%'";
                if(!author.getText().equals(""))
                    s=s+" and author like '%"+author.getText()+"%'";
                if(publisherlist.getSelectedIndex()!=0)
                    s=s+" and publisherid='"+publisherlist.getSelectedIndex()+"'";
                if(bookclasslist.getSelectedIndex()!=0)
                    s=s+" and bookclassid='"+bookclasslist.getSelectedIndex()+"'";
                System.out.println(s);
                showbook show=new showbook(pcenter,card,s);
                pcenter.add("showbook",show);
                card.show(pcenter,"showbook");
                
            }
        }
        else if(e.getSource()==reset)
        {
            barcode.setText(null);
            isbn.setText(null);
            price.setText(null);
            bookname.setText(null);
            author.setText(null);
            content.setText(null);
            publisherlist.select(0);
            bookclasslist.select(0);
        }
    }
}

⌨️ 快捷键说明

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