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

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

package quary;

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


public class employee 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 = "";
    HashMap hashmap = new HashMap();
    private String user = "";
    JTabbedPane jTabbedPane1 = new JTabbedPane();
    JComboBox cbmkind;
    JButton btn_return = new JButton();
    public employee() {
        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();
                } 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)
                {
                    mxCard();
                }else
                {
                    JOptionPane.showMessageDialog(jScrollPane1,"请选择要操作的编号");
                }
            }
        });
        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()
    {
        AssetReturn ar = new AssetReturn(cbmkind.getSelectedItem().toString().
                                        trim(), tempID,
                                        getID(cbmkind.getSelectedItem().
                                              toString().
                                              trim()));
       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.hiden();
       ar.setModal(true);
       ar.setVisible(true);

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

    private String[] getKindsList() {
        dcon = new DBConnection();
        String sql = "select a.Asset_user,b.employee_name from asset as a, employee as b where(a.Asset_user = b.employee_id) group by a.Asset_user,b.employee_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;
            hashmap.put(name,id);
        }
        return s;
    }
    //getid
    private String getID(String name)
    {
       return hashmap.get(name).toString().trim();
    }


    //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) {
        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 b.employee_name = '"+name+"'  order by a.asset_id asc ";
        return dcon.select(sql);
    }

}
 

原创粉丝点击