s1(java)项目实战(固定资产管理)(quary_quary )

来源:互联网 发布:java倒直角三角形 编辑:程序博客网 时间:2024/04/28 13:14

package quary;

import java.awt.*;
import javax.swing.*;
import tools.*;
import java.awt.event.*;
import java.util.Vector;
import op.*;

public class quary extends JPanel {
    JButton btn_kinds = new JButton();
    JButton btn_status = new JButton();
    JButton btnEmp = new JButton();
    JButton btn_id = new JButton();
    private DBConnection dcon = null;
    public quary() {
        try {
            jbInit();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        btn_kinds.setBounds(new Rectangle(183, 73, 113, 40));
        btn_kinds.setText("按科目查询");
        this.setLayout(null);
        btn_status.setBounds(new Rectangle(183, 127, 116, 36));
        btn_status.setText("按状态查询");
        btnEmp.setBounds(new Rectangle(183, 175, 117, 36));
        btnEmp.setText("按雇员查询");
        btn_id.setBounds(new Rectangle(183, 224, 113, 40));
        btn_id.setText("按编号查询");
        this.add(btnEmp);
        this.add(btn_status);
        this.add(btn_kinds);
        this.add(btn_id);
        this.setSize(500, 400);
        btn_kinds.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                kindsQuary();
            }
        });
        btn_status.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                statusQuary();
            }
        });
        btnEmp.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                empQuary();
            }
        });
        btn_id.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                idQuary();
            }
        });
    }

    //id
    private void idQuary() {
        String id = null;
        id = JOptionPane.showInputDialog(this, "请输入编号", "按编号查询", 0);
        if (id == null || id.trim().length() == 0) {
            JOptionPane.showMessageDialog(this, "编号不能为空");
        } else {
            dcon = new DBConnection();
            String sql = "select * from asset where asset_id='" + id + "'";
            if (dcon.isNull(sql)) {
                sql = "select * from Action where asset_id = '" + id + "'";
                if (!dcon.isNull(sql)) {
                    AssetFullDialog afd = new AssetFullDialog(id);
                    Dimension frmsize = getSize();
                    Point loc = getLocation();
                    afd.setLocation((frmsize.width - afd.WIDTH) / 2 + loc.x,
                                    (frmsize.height - afd.HEIGHT) / 2 + loc.y);
                    afd.setSize(350, 330);
                    afd.setModal(true);
                    afd.setVisible(true);
                } else {
                    dcon = new DBConnection();
                    sql = "select asset_user from asset where asset_id = '" +
                          id + "'";
                    Vector v = dcon.select(sql);
                    String userid = ((Vector) v.get(0)).get(0).toString().trim();
                    sql =
                            "select employee_name  from Employee where employee_id='" +
                            userid
                            + "'";
                    v = dcon.select(sql);
                    String user = ((Vector) v.get(0)).get(0).toString().trim();
                    AssetReturn ar = new AssetReturn(user, id, userid);
                    Dimension frmsize = getSize();
                    Point loc = getLocation();
                    ar.setLocation((frmsize.width - ar.WIDTH) / 2 + loc.x,
                                   (frmsize.height - ar.HEIGHT) / 2 + loc.y);
                    ar.setSize(350, 450);
                    ar.updownHiden();
                    ar.setModal(true);
                    ar.setVisible(true);
                }
            }else
            {
                JOptionPane.showMessageDialog(this, "没有此编号");
            }
        }
    }

    //employee
    private void empQuary() {
        this.removeAll();
        employee e = new employee();
        this.add(e);
        this.updateUI();

    }

    //status
    private void statusQuary() {
        this.removeAll();
        status s = new status();
        this.add(s);
        this.updateUI();

    }

    //kinds
    private void kindsQuary() {
        this.removeAll();
        kind k = new kind();
        this.add(k);
        this.updateUI();
    }
}