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

    技术2022-05-11  80

    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.AssetReturn;

    public class status 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 status() {        try {            jbInit();        } catch (Exception ex) {            ex.printStackTrace();        }    }

        private void jbInit() throws Exception {        model = new Mytable(4);        model.setTitle(getTitle());        String[] s = {"正常", "维修", "报废"};        cbmkind = new JComboBox(s);        model.setContent(getContents(cbmkind.getSelectedItem().toString().trim()));        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){                mxStatus();            }else            {                JOptionPane.showMessageDialog(table,"请选择要操作的记录");            }            }        });        btn_return.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent e) {                returnQuary();            }        });        cbmkind.addItemListener(new ItemListener() {            public void itemStateChanged(ItemEvent e) {                choice();

                }        });    }    private void mxStatus()    {        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();    }

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


    最新回复(0)