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

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

package quary;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2007</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import tools.*;
import op.*;

public class kind extends JPanel {
    private JButton btn_mx = new JButton();
    private JScrollPane jScrollPane1 = new JScrollPane();
    private DBConnection dcon = null;
    private JTable table;
    private Mytable model;
    private String tempID = "";
    private String tempUser = "";
    HashMap KindMap = new HashMap();
    JTabbedPane jTabbedPane1 = new JTabbedPane();
    JComboBox cbmkind;
    JButton btn_return = new JButton();
    public kind() {
        try {
            jbInit();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        model = new Mytable(4);
        model.setTitle(getTitle());
        if (getKindsList() != null) {
            cbmkind = new JComboBox(getKindsList());
            if (cbmkind.getSelectedItem() != null) {
                model.setContent(getContents(cbmkind.getSelectedItem().toString().
                                             trim()));
            } else {
                model.setContent(getContents(""));
            }

        }

        table = new JTable(model);
        table.setRowSelectionAllowed(false);
        this.setLayout(null);
        btn_mx.setBounds(new Rectangle(229, 22, 92, 32));
        btn_mx.setToolTipText("");
        btn_mx.setText("详细情况");

        jScrollPane1.setBounds(new Rectangle(15, 71, 477, 223));
        jTabbedPane1.setBounds(new Rectangle( -44, 86, 5, 5));
        cbmkind.setBounds(new Rectangle(42, 21, 148, 33));
        btn_return.setBounds(new Rectangle(359, 22, 90, 31));
        btn_return.setText("返回");
        this.add(jScrollPane1);
        this.add(jTabbedPane1);
        this.add(cbmkind);
        this.add(btn_mx);
        this.add(btn_return);
        this.setSize(500, 400);
        jScrollPane1.getViewport().add(table);
        //行选择编号改变
        table.addMouseListener(new MouseListener() {
            public void mouseClicked(MouseEvent e) {
                if (table.getSelectedRow() != -1 &&
                    table.getSelectedColumn() != -1) {
                    tempID = table.getValueAt(table.getSelectedRow(), 0).
                             toString();
                    if(table.getValueAt(table.getSelectedRow(), 6) == null)
                    {
                        tempUser = "";
                    }else
                    {
                        tempUser = table.getValueAt(table.getSelectedRow(), 6).
                                   toString();
                    }
                } else {
                    tempID = "";
                }
            }

            public void mousePressed(MouseEvent e) {
            }

            public void mouseReleased(MouseEvent e) {
            }

            public void mouseEntered(MouseEvent e) {
            }

            public void mouseExited(MouseEvent e) {
            }
        });
        btn_mx.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (tempID.trim().length() == 0) {
                    JOptionPane.showMessageDialog(table, "请选择要操作的记录");

                } else {
                    mxCard();
                }
            }
        });
        btn_return.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                returnQuary();
            }
        });
        cbmkind.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
                choice();
            }
        });
    }

    //mxCard();
    private void mxCard() {
        dcon = new DBConnection();
        String sql = "select * from Action where asset_id = '" + tempID + "'";
        if (!dcon.isNull(sql)) {
            AssetFullDialog afd = new AssetFullDialog(tempID);
            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 {
            sql = "select employee_id from Employee where employee_name='" + tempUser + "'";
            Vector v = dcon.select(sql);
            String userid = ((Vector) v.get(0)).get(0).toString().trim();
            AssetReturn ar = new AssetReturn(tempUser, tempID,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);

        }
    }

    //changed
    private void choice() {
        model.setContent(getContents(cbmkind.getSelectedItem().toString().
                                     trim()));
        tempID = "";
        table.updateUI();
        this.updateUI();
    }

    private String[] getKindsList() {
        dcon = new DBConnection();
        String sql = "select b.childkind_id,b.childkind_name from asset as a, childkind as b where(a.childkind_id = b.childkind_id) group by  b.childkind_id,b.childkind_name";
        Vector v = dcon.select(sql);
        int count = v.size();
        String[] s = new String[count];
        for (int i = 0; i < count; i++) {
            String id = ((Vector) v.get(i)).get(0).toString().trim();
            String name = ((Vector) v.get(i)).get(1).toString().trim();
            s[i] = name;
            KindMap.put(name, id);
        }
        return s;
    }

    //get id
    private String getKindsID(String name) {
        KindMap.get(name);
        if (KindMap.get(name) != null) {
            return KindMap.get(name).toString().trim();
        }
        return "";
    }

    //return Quarry
    private void returnQuary() {
        this.removeAll();
        quary q = new quary();
        this.add(q);
        this.updateUI();
    }

    //获取表格的列表
    private String[] getTitle() {

        dcon = new DBConnection();
        String sql = "select a.asset_id as 编号, a.asset_name as 名称,a.asset_type as 类型,a.asset_price as 单价,a.asset_buytime as 购买时间,a.asset_status as 状态,b.employee_name as 用户,a.remark as 备注,a.childkind_id as 科目 from asset as a left join  employee as b on a.asset_user = b.employee_id  order by a.asset_id asc ";
        return dcon.getColumnname(sql);
    }

//获取表格的内容
    private Vector getContents(String name) {
        String id = getKindsID(name);
        dcon = new DBConnection();
        String sql = "select a.asset_id as 编号, a.asset_name as 名称,a.asset_type as 类型,a.asset_price as 单价,a.asset_buytime as 购买时间,a.asset_status as 状态,b.employee_name as 用户,a.remark as 备注,a.childkind_id as 科目 from asset as a left join  employee as b on a.asset_user = b.employee_id where  a.childkind_id = '" +
                     id + "'  order by a.asset_id asc ";
        return dcon.select(sql);
    }

}
 

原创粉丝点击