productframe.java

来自「基于mvc的java进销存系统」· Java 代码 · 共 439 行 · 第 1/2 页

JAVA
439
字号
/*
 * EmployeeFrame.java
 *
 * Created on 2007年5月16日, 下午1:34
 *  陈诗昭 
 */

package form;

import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import table.Product;
import task.HandleProduct;
import util.ConstentUtil;

/**
 *
 * @author  下雪天
 */
public class ProductFrame extends javax.swing.JInternalFrame {
    
    /** Creates new form EmployeeFrame */
    private boolean add_pasre=false;//添加按钮选择
    private boolean reset_pasre=false;//修改按钮选择
    HandleProduct hu=new HandleProduct();
    Product s=new Product();
    ArrayList v=new ArrayList();
    public ProductFrame() {
        initComponents();
        dissettxt();
        this.closable=true;
        clewlable.setText("可输入编号或者供应商名称进行查询");
        //初始化时,将所有的文本框设为不可编辑
            
        databind();
    }
    private void databind(){
        String[] theader={"商品编号","商品名称","安全库存量","商品数量","建议购买价","建议销售价","最近进货日期","最后购物日期"};
        int j=0;
        v=hu.findAll();
        String[][] tdata=new String[v.size()][8];
        for(int i=0;i<v.size();i++){
            s=(Product)v.get(i);
            tdata[i][0]=s.getProductID();
            tdata[i][1]=s.getProductName();
            tdata[i][2]=String.valueOf(s.getSafeStock());
            tdata[i][3]=String.valueOf(s.getQuantity());
            tdata[i][4]=String.valueOf(s.getSuggestBuyPrice());
            tdata[i][5]=String.valueOf(s.getSuggestSalePrice()); 
            if(s.getLastPurchaseDate()!=null)
            tdata[i][6]=s.getLastPurchaseDate().toString();
            if(s.getLastDeliveryDate()!=null)
            tdata[i][7]=s.getLastDeliveryDate().toString();
        }   
        jTable1.setModel(new DefaultTableModel(tdata,theader));
    }
    //将所有文本框置为空
     public void clear(){
        txtProductName.setText("");
        txtProductID.setText("");
        txtSafeStock.setText("");
        txtQuantity.setText("");
        txtSuggestBuyPrice.setText("");
        txtSuggestSalePrice.setText("");
    }
     private void settxt(){
         txtProductName.setEditable(true); 
        txtSafeStock.setEditable(true); 
        txtQuantity.setEditable(true); 
        txtSuggestBuyPrice.setEditable(true); 
        txtSuggestSalePrice.setEditable(true); 
     }
     private void dissettxt(){
        txtProductName.setEditable(false); 
        txtProductID.setEditable(false);
        txtSafeStock.setEditable(false);
        txtQuantity.setEditable(false); 
        txtSuggestBuyPrice.setEditable(false);
        txtSuggestSalePrice.setEditable(false);
     }
    private void save(){
        s.setProductID(txtProductID.getText());
        s.setProductName(txtProductName.getText());
        s.setSafeStock(Double.parseDouble(txtSafeStock.getText()));
        s.setQuantity(Double.parseDouble(txtQuantity.getText()));
        s.setSuggestBuyPrice(Double.parseDouble(txtSuggestBuyPrice.getText()));
        s.setSuggestSalePrice(Double.parseDouble(txtSuggestSalePrice.getText()));
        hu.save(s);   
    }
    private void rework(){
        s.setProductID(txtProductID.getText());
        s.setProductName(txtProductName.getText());
        s.setSafeStock(Double.parseDouble(txtSafeStock.getText()));
        s.setQuantity(Double.parseDouble(txtQuantity.getText()));
        s.setSuggestBuyPrice(Double.parseDouble(txtSuggestBuyPrice.getText()));
        s.setSuggestSalePrice(Double.parseDouble(txtSuggestSalePrice.getText()));
        hu.update(s);
    }
    /** 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.
     */
    // <editor-fold defaultstate="collapsed" desc=" 生成的代码 ">//GEN-BEGIN:initComponents
    private void initComponents() {
        JPane2 = new javax.swing.JPanel();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        AddButton = new javax.swing.JButton();
        ReworkButton = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtProductID = new javax.swing.JTextField();
        txtSafeStock = new javax.swing.JTextField();
        txtProductName = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txtSuggestBuyPrice = new javax.swing.JTextField();
        txtQuantity = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        txtSuggestSalePrice = new javax.swing.JTextField();
        clewlable = new javax.swing.JLabel();
        Buttonsave = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();

        JPane2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/daying.gif")));

        jButton6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/exit.gif")));
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        AddButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/addgy.gif")));
        AddButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AddButtonActionPerformed(evt);
            }
        });

        ReworkButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/xiugaigy.gif")));
        ReworkButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ReworkButtonActionPerformed(evt);
            }
        });

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/shanchu.gif")));
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jLabel1.setText("\u5546\u54c1\u7f16\u53f7\uff1a");

        jLabel2.setText("\u5b89\u5168\u5e93\u5b58\u91cf\uff1a");

        jLabel3.setText("\u5546\u54c1\u6570\u91cf\uff1a");

        jLabel4.setText("\u5efa\u8bae\u8d2d\u4e70\u4ef7\uff1a");

        jLabel6.setText("\u5546\u54c1\u540d\u79f0\uff1a");

        jLabel7.setText("\u5efa\u8bae\u9500\u552e\u4ef7\uff1a");

        Buttonsave.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/save.gif")));
        Buttonsave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonsaveActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout JPane2Layout = new org.jdesktop.layout.GroupLayout(JPane2);
        JPane2.setLayout(JPane2Layout);
        JPane2Layout.setHorizontalGroup(
            JPane2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, JPane2Layout.createSequentialGroup()
                .add(JPane2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(JPane2Layout.createSequentialGroup()
                        .add(37, 37, 37)
                        .add(JPane2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel1)
                            .add(JPane2Layout.createSequentialGroup()
                                .add(JPane2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                    .add(jLabel4)
                                    .add(jLabel2))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(JPane2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                                    .add(org.jdesktop.layout.GroupLayout.LEADING, txtSuggestBuyPrice)
                                    .add(org.jdesktop.layout.GroupLayout.LEADING, txtProductID)
                                    .add(org.jdesktop.layout.GroupLayout.LEADING, txtSafeStock, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 161, Short.MAX_VALUE))))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 343, Short.MAX_VALUE))
                    .add(JPane2Layout.createSequentialGroup()
                        .add(76, 76, 76)
                        .add(JPane2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(clewlable, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 483, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(JPane2Layout.createSequentialGroup()
                                .add(AddButton)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(ReworkButton)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(JPane2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(JPane2Layout.createSequentialGroup()
                                        .add(6, 6, 6)
                                        .add(jButton4)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(jButton5)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 206, Short.MAX_VALUE)
                                        .add(Buttonsave)
                                        .add(2, 2, 2))
                                    .add(JPane2Layout.createSequentialGroup()
                                        .add(112, 112, 112)
                                        .add(JPane2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?