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

    技术2022-05-11  81

     package op;

    import java.awt.*;

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

    /** * <p>Title: </p> * * <p>Description: </p> * * <p>Copyright: Copyright (c) 2007</p> * * <p>Company: </p> * * @author not attributable * @version 1.0 */public class EmployeeDialog extends JDialog {

        JComboBox cmb_employeechoice = new JComboBox();    JButton btn_ok = new JButton();    JButton btn_cancle = new JButton();    private HashMap empMap = new HashMap();    DBConnection dcon = new DBConnection();    String id,mid;    JLabel jLabel1 = new JLabel();    JTextField txttime = new JTextField();    JLabel jLabel2 = new JLabel();    JTextArea tare_used = new JTextArea(3,10);    JLabel jLabel3 = new JLabel();    JTextArea tarea_mem = new JTextArea(3,10);    public EmployeeDialog(Frame owner, String title, boolean modal,String _id,String _mid) {        super(owner, title, modal);        try {            id = _id;            mid = _mid;            setDefaultCloseOperation(DISPOSE_ON_CLOSE);            jbInit();            pack();        } catch (Exception exception) {            exception.printStackTrace();        }    }

        public EmployeeDialog(String _id,String Managerid) {        this(new Frame(), "EmployeeDialog", false,_id,Managerid);    }

        //chioce    private void initchoice() {        if (getEmployeeName() != null || getEmployeeName().length != 0) {            String[] s = getEmployeeName();            for (int i = 0; i < s.length; i++) {                cmb_employeechoice.addItem(s[i]);            }        }    }

        private void jbInit() throws Exception {        initchoice();        this.getContentPane().setLayout(null);        btn_cancle.setText("取消");        jLabel1.setFont(new java.awt.Font("宋体", Font.BOLD, 13));        jLabel1.setText("今天是");        jLabel1.setBounds(new Rectangle(14, 59, 53, 28));        txttime.setText(getToday());        txttime.setEditable(false);        txttime.setBounds(new Rectangle(78, 57, 106, 32));        jLabel2.setFont(new java.awt.Font("宋体", Font.BOLD, 13));        jLabel2.setToolTipText("");        jLabel2.setText("用  途");        jLabel2.setBounds(new Rectangle(13, 96, 47, 24));        tare_used.setText("");        tare_used.setBounds(new Rectangle(78, 94, 146, 46));        cmb_employeechoice.setBounds(new Rectangle(68, 7, 134, 31));        jLabel3.setFont(new java.awt.Font("宋体", Font.BOLD, 13));        jLabel3.setToolTipText("");        jLabel3.setText("备  注");        jLabel3.setBounds(new Rectangle(12, 142, 46, 27));        btn_ok.setBounds(new Rectangle(25, 214, 67, 32));        btn_cancle.setBounds(new Rectangle(144, 219, 67, 30));        this.getContentPane().setBackground(SystemColor.control);        this.getContentPane().add(jLabel3);        this.getContentPane().add(tarea_mem);        this.getContentPane().add(cmb_employeechoice);        this.getContentPane().add(btn_cancle);        this.getContentPane().add(btn_ok);        tarea_mem.setText("");        tarea_mem.setBounds(new Rectangle(77, 146, 146, 47));        this.getContentPane().add(jLabel2);        this.getContentPane().add(tare_used);        this.getContentPane().add(jLabel1);        this.getContentPane().add(txttime);        btn_ok.setText("确定");        this.setResizable(false);        btn_ok.addActionListener(new ActionListener(){            public void actionPerformed(ActionEvent e) {                drawAsset();                closeDialog();            }        });        btn_cancle.addActionListener(new ActionListener(){            public void actionPerformed(ActionEvent e) {                closeDialog();            }        });    }    private void drawAsset()    {

            String used = "";        String mem="";        if(tare_used.getText().trim().length()!=0)        {            used = tare_used.getText().trim();        }else        {            used = "";        }        if(tarea_mem.getText().trim().length()!=0)        {            mem = tarea_mem.getText().trim();        }else        {            mem = "";        }        String managerid =getMid().trim();        dcon = new DBConnection();        String userid = getUserID(cmb_employeechoice.getSelectedItem().toString().trim());        String sql = "insert into Action (asset_id,action_time,manager_id,asset_use,remark) values ('";        sql+=id+"','";        sql+=txttime.getText().trim()+"','";        sql+=managerid+"','";        sql+=used+"','";        sql+=mem+"')";        dcon.update(3,sql);        sql = "update Asset set asset_user = '"+userid+"' where asset_id='"+id+"'";        dcon.update(1,sql);        JOptionPane.showMessageDialog(this,"编号为"+id+"借出");    }   //close   private void closeDialog()   {       this.dispose();   }   private String getMid()   {       dcon = new DBConnection();       String sql = "select manager_id,manager_username from Manager where manager_username='"+mid+"'";       Vector v = dcon.select(sql);       return ((Vector)v.get(0)).get(0).toString().trim();   }

       //    private String[] getEmployeeName() {        dcon = new DBConnection();        String sql = "select employee_id,employee_name from Employee";        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;            empMap.put(name, id);        }        return s;    }    //get userID    private String getUserID(String name)    {        if(empMap.get(name) != null)        {            return empMap.get(name).toString().trim();        }else        {            return "";        }    }    //getToday        private String getToday(){           Calendar c = Calendar.getInstance();           int month = c.get(Calendar.MONTH) + 1;           int year = c.get(Calendar.YEAR);           int day = c.get(Calendar.DATE);           String sm;           String sd;           if (month < 10) {               sm = "0" + String.valueOf(month);           } else {               sm = String.valueOf(month);           }           if (day < 10) {               sd = "0" + String.valueOf(day);           } else {               sd = String.valueOf(day);           }           String StrTime = year + sm + sd;            return StrTime;    }}


    最新回复(0)