TXT

AssetManager

By Vanessa Watson,2014-04-17 02:29
8 views 0
AssetManager

/*

     * w.java

     *

     * Created on __DATE__, __TIME__

     */

package ui;

    import java.text.SimpleDateFormat; import java.util.Date;

    import java.util.List;

    import javax.swing.DefaultComboBoxModel;

import entity.Asset;

    import entity.Cate;

    import entity.SubCate;

/**

     *

     * @author __USER__

     */

    public class AssetManager extends javax.swing.JPanel {

     //给主界面一个名字?以至于可以用这个名字行使调用主界面的一切内容的权力. :

     private Face face = null;

     /** Creates new form w

     * @param face */

     public AssetManager(Face face) {

     this.face = face;

     initComponents();

     }

     /** This method is called from within the constructor to

     * initialize the form.

     * WARNING: Do NOT modify this code. The content of this method is

     * always regenerated by the Form Editor.

     */

     //GEN-BEGIN:initComponents

     //

     private void initComponents() {

     btnGrp1 = new javax.swing.ButtonGroup();

     rdoAdd = new javax.swing.JRadioButton();

     rdoUpdate = new javax.swing.JRadioButton();

     rdoDel = new javax.swing.JRadioButton();

     jButton1 = new javax.swing.JButton();

     jLabel1 = new javax.swing.JLabel();

     txtDate = new javax.swing.JTextField();

     jLabel2 = new javax.swing.JLabel();

     txtName = new javax.swing.JTextField();

     jLabel3 = new javax.swing.JLabel();

     txtModel = new javax.swing.JTextField();

     jLabel4 = new javax.swing.JLabel();

     txtPrice = new javax.swing.JTextField();

     jLabel5 = new javax.swing.JLabel();

     txtId = new javax.swing.JTextField();

     jLabel6 = new javax.swing.JLabel();

     jLabel7 = new javax.swing.JLabel();

     jLabel8 = new javax.swing.JLabel();

     cboSubCate = new javax.swing.JComboBox();

     cboStatus = new javax.swing.JComboBox();

     cboCate = new javax.swing.JComboBox();

     setLayout(null);

     rdoAdd.setText("\u589e\u52a0");

     rdoAdd.addActionListener(new java.awt.event.ActionListener() {

     public void actionPerformed(java.awt.event.ActionEvent evt) {

     rdoAddActionPerformed(evt);

     }

     });

     add(rdoAdd);

     rdoAdd.setBounds(30, 20, 80, 25);

     rdoUpdate.setText("\u4fee\u6539");

     rdoUpdate.addActionListener(new java.awt.event.ActionListener() {

     public void actionPerformed(java.awt.event.ActionEvent evt) {

     rdoUpdateActionPerformed(evt);

     }

     });

     add(rdoUpdate);

     rdoUpdate.setBounds(130, 20, 110, 25);

     rdoDel.setText("\u5220\u9664");

     rdoDel.addActionListener(new java.awt.event.ActionListener() {

     public void actionPerformed(java.awt.event.ActionEvent evt) {

     rdoDelActionPerformed(evt);

     }

     });

     add(rdoDel);

     rdoDel.setBounds(240, 20, 70, 25);

     jButton1.setText("\u63d0\u4ea4");

     jButton1.addActionListener(new java.awt.event.ActionListener() {

     public void actionPerformed(java.awt.event.ActionEvent evt) {

     jButton1ActionPerformed(evt);

     }

     });

     add(jButton1);

     jButton1.setBounds(371, 20, 80, 25);

     jLabel1.setText("\u767b\u8bb0\u65e5\u671f");

     add(jLabel1);

     jLabel1.setBounds(260, 60, 80, 17);

     txtDate.setText(" ");

     add(txtDate);

     txtDate.setBounds(340, 60, 110, 23);

     jLabel2.setText("\u8d44\u4ea7\u540d\u79f0");

     add(jLabel2);

     jLabel2.setBounds(50, 100, 80, 20);

     txtName.setText(" ");

     add(txtName);

     txtName.setBounds(130, 100, 110, 20);

     jLabel3.setText("\u8d44\u4ea7\u6837\u5f0f");

     add(jLabel3);

     jLabel3.setBounds(50, 140, 80, 17);

     txtModel.setText(" ");

     add(txtModel);

     txtModel.setBounds(130, 140, 110, 23);

     jLabel4.setText("\u8d44\u4ea7\u4ef7\u683c");

     add(jLabel4);

     jLabel4.setBounds(50, 180, 80, 17);

     txtPrice.setText(" ");

     add(txtPrice);

     txtPrice.setBounds(130, 180, 110, 23);

     jLabel5.setText("\u8d44\u4ea7\u7f16\u53f7");

     add(jLabel5);

     jLabel5.setBounds(50, 60, 80, 17);

     txtId.setText(" ");

     add(txtId);

     txtId.setBounds(130, 60, 110, 23);

     jLabel6.setText("\u8d44\u4ea7\u72b6\u6001");

     add(jLabel6);

     jLabel6.setBounds(260, 100, 80, 17);

     jLabel7.setText("\u8d44\u4ea7\u5927\u7c7b");

     add(jLabel7);

     jLabel7.setBounds(260, 140, 80, 17);

     jLabel8.setText("\u8d44\u4ea7\u5c0f\u7c7b");

     add(jLabel8);

     jLabel8.setBounds(260, 180, 80, 17);

     cboSubCate.setModel(new javax.swing.DefaultComboBoxModel(new String[] {

     "Item 1", "Item 2", "Item 3", "Item 4" }));

     add(cboSubCate);

     cboSubCate.setBounds(340, 180, 110, 23);

     cboStatus.setModel(new javax.swing.DefaultComboBoxModel(new String[] {

     "Item 1", "Item 2", "Item 3", "Item 4" }));

     add(cboStatus);

     cboStatus.setBounds(340, 100, 110, 23);

     cboCate.setModel(new javax.swing.DefaultComboBoxModel(new String[] {

     "Item 1", "Item 2", "Item 3", "Item 4" }));

     cboCate.addActionListener(new java.awt.event.ActionListener() {

     public void actionPerformed(java.awt.event.ActionEvent evt) {

     cboCateActionPerformed(evt);

     }

     });

     add(cboCate);

     cboCate.setBounds(340, 140, 110, 23);

     add(cboCate);

     cboCate.setBounds(340, 140, 110, 23);

     cboStatus.setModel(new javax.swing.DefaultComboBoxModel(new String[] {

     "Item 1", "Item 2", "Item 3", "Item 4" }));

     add(cboStatus);

     cboStatus.setBounds(340, 100, 110, 23);

     btnGrp1.add(rdoAdd); btnGrp1.add(rdoUpdate); btnGrp1.add(rdoDel);

     createComboBox();

     }//

     //GEN-END:initComponents

     /*

     * add(cboCate);

     cboCate.setBounds(340, 140, 110, 23);

     cboStatus.setModel(new javax.swing.DefaultComboBoxModel(new String[] {

     "Item 1", "Item 2", "Item 3", "Item 4" }));

     add(cboStatus);

     cboStatus.setBounds(340, 100, 110, 23);

     btnGrp1.add(rdoAdd); btnGrp1.add(rdoUpdate); btnGrp1.add(rdoDel);

     createComboBox();

     */

     //点击确定

     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

     // TODO add your handling code here:

     //拼装资产信息

     Asset a = new Asset();

     //通过各个text的方法得到其内容并且设置为资产a的内容

     a.setAsset_name(txtName.getText());

     a.setPrice(Double.parseDouble(txtPrice.getText()));

     a.setModel(txtModel.getText());

     a.setPurchase_date(txtDate.getText());

     a.setUseby("操作员");

     //取出下拉列表中的数据?注意有类型的转换

     //取出状态下拉列表的内容 更为字符串内容?并且取第一位。更为字符串是只取

    出一位的好做法

     char c = cboStatus.getSelectedItem().toString().charAt(0);

     //将取到的状态封装到资产表中

     a.setStatus(c);

     //在下拉列表中取出当前内容

     Cate cate = (Cate) cboCate.getSelectedItem();

     SubCate sub = (SubCate) cboSubCate.getSelectedItem();

     //将当前内容封装到资产表中

     a.setCateid(cate.getCateid());

     a.setSubcateid(sub.getSubcateid());

// if (!rdoAdd.isSelected()) {

// a.setAssetid(Long.parseLong(txtId.getText()));

    // }

    // if (rdoAdd.isSelected()) {

    // try {

    // face.adao.insert(a);

    // } catch (Exception e) {

    // // TODO Auto-generated catch block // e.printStackTrace();

    // }

    // } else if (rdoDel.isSelected()) { // try {

    // face.adao.delete(a);

    // } catch (Exception e) {

    // // TODO Auto-generated catch block // e.printStackTrace();

    // }

    // } else {

    // try {