customerframe.java

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

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

package form;

import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import table.Customer;
import task.HandleCustomer;
import util.ConstentUtil;

/**
 *
 * @author  下雪天
 */
public class CustomerFrame extends javax.swing.JInternalFrame {
     private boolean add_pasre=false;//添加按钮选择
     private boolean reset_pasre=false;//修改按钮选择
     HandleCustomer hu=new HandleCustomer();
     Customer c=new Customer();
     Vector v=new Vector();
    /** Creates new form EmployeeFrame */
     public CustomerFrame() {
        super("客户资料",false,false,false,true);
        initComponents();
        databind();
        dissettxt();
    }
     public void clear()
     {
        txtCustomerAddress.setText("");
        txtCustomerID.setText("");
        txtCustomerName.setText("");
        txtMobilePhone.setText("");
        txtMobilePhone.setText("");
        txtOwer.setText("");
     }
    public void dissettxt(){
        txtCustomerAddress.setEditable(false);
        txtCustomerID.setEditable(false);
        txtCustomerName.setEditable(false);
        txtMobilePhone.setEditable(false);
        txtMobilePhone.setEditable(false);
        txtOwer.setEditable(false);
    }
    public void settxt(){
        txtCustomerAddress.setEditable(true);
        txtCustomerID.setEditable(true);
        txtCustomerName.setEditable(true);
        txtMobilePhone.setEditable(true);
        txtMobilePhone.setEditable(true);
        txtOwer.setEditable(true); 
    }
    private void rework(){
        c.setCustomerID(txtCustomerID.getText());
        c.setCustomerName(txtCustomerName.getText());
        c.setOwer(txtOwer.getText());
        c.setMobilePhone(txtMobilePhone.getText());
        c.setCustomerAddress(txtCustomerAddress.getText());
        hu.update(c);
    }
    private void save(){
        c.setCustomerID(txtCustomerID.getText());
        c.setCustomerName(txtCustomerName.getText());
        c.setOwer(txtOwer.getText());
        c.setMobilePhone(txtMobilePhone.getText());
        c.setCustomerAddress(txtCustomerAddress.getText());
        hu.save(c); 
    }
    private void databind(){
       //
        String[] theader={"编号","名称","负责人","移动电话","服务员工","地址","最后购物日期"};
        v=hu.findAll();
        String[][] tdata=new String[v.size()][10];
        for(int i=0;i<v.size();i++){
            c=(Customer)v.get(i);
            tdata[i][0]=c.getCustomerID();
            tdata[i][1]=c.getCustomerName();
            tdata[i][2]=c.getOwer();
            tdata[i][3]=c.getMobilePhone();
            tdata[i][4]=c.getSeller();
            tdata[i][5]=c.getCustomerAddress();
            if(c.getLastDeliveryDate()!=null)
            tdata[i][6]=c.getLastDeliveryDate().toString();
        }
        jTable1.setModel(new DefaultTableModel(tdata,theader));
    }
    /** 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() {
        jPanel1 = new javax.swing.JPanel();
        PrintButton = new javax.swing.JButton();
        ExitButton = new javax.swing.JButton();
        AddButton = new javax.swing.JButton();
        ReworkButton = new javax.swing.JButton();
        DeleteButton = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtCustomerID = new javax.swing.JTextField();
        txtCustomerName = new javax.swing.JTextField();
        txtOwer = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txtMobilePhone = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txtCustomerAddress = new javax.swing.JTextField();
        SeveButton = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();

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

        ExitButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/exit.gif")));
        ExitButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ExitButtonActionPerformed(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);
            }
        });

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

        jLabel1.setText("\u5ba2\u6237\u7f16\u53f7\uff1a");

        jLabel2.setText("\u5ba2\u6237\u540d\u79f0\uff1a");

        jLabel3.setText("\u8d1f\u8d23\u4eba\u540d\u79f0\uff1a");

        jLabel4.setText("\u79fb\u52a8\u7535\u8bdd\uff1a");

        jLabel5.setText("\u5ba2\u6237\u5730\u5740\uff1a");

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

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(26, 26, 26)
                .add(AddButton)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(ReworkButton)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(DeleteButton)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(PrintButton)
                .add(58, 58, 58)
                .add(SeveButton)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(ExitButton)
                .addContainerGap(222, Short.MAX_VALUE))
            .add(jPanel1Layout.createSequentialGroup()
                .add(58, 58, 58)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jLabel1)
                    .add(jLabel2)
                    .add(jLabel5))
                .add(38, 38, 38)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(txtCustomerName)
                            .add(txtCustomerID, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 169, Short.MAX_VALUE))
                        .add(29, 29, 29)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(jLabel3)
                            .add(jLabel4))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(txtOwer, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 156, Short.MAX_VALUE)
                            .add(txtMobilePhone, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 156, Short.MAX_VALUE)))
                    .add(txtCustomerAddress, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 430, Short.MAX_VALUE))
                .addContainerGap(122, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()

⌨️ 快捷键说明

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