⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 saleviewer.java

📁 Store Manager
💻 JAVA
字号:
/* * SaleViewer.java * * Created on 2007年6月9日, 下午7:01 */package com.studio009.store.ui;import com.studio009.store.StoreApp;import com.studio009.store.entity.Sale;import com.studio009.store.entity.Stock;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Date;import java.util.Vector;import javax.swing.JOptionPane;import javax.swing.table.DefaultTableModel;/** * 销售单查询对话框 * @see Sale * @author  wangs */public class SaleViewer extends javax.swing.JDialog {        /** Creates new form SaleViewer     * @param parent 父窗口     * @param modal 模式     */    public SaleViewer(java.awt.Frame parent, boolean modal) {        super(parent, java.awt.Dialog.ModalityType.APPLICATION_MODAL);                initComponents();                // 设置默认的按钮        this.getRootPane().setDefaultButton(jButton1);                // 设置对话框居中        this.setLocationRelativeTo(parent);    }        /** 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=" Generated Code ">//GEN-BEGIN:initComponents    private void initComponents() {        em = StoreApp.getEntityManagerFactory().createEntityManager();        saleQuery = em.createQuery("select s from Sale s");        saleList = saleQuery.getResultList();        jPanel1 = new javax.swing.JPanel();        jDatePicker1 = new com.sunking.swing.JDatePicker();        jDatePicker2 = new com.sunking.swing.JDatePicker();        jLabel1 = new javax.swing.JLabel();        jLabel2 = new javax.swing.JLabel();        jButton1 = new javax.swing.JButton();        jButton2 = new javax.swing.JButton();        jScrollPane1 = new javax.swing.JScrollPane();        jTable1 = new javax.swing.JTable();        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);        setTitle("\u9500\u552e\u5355\u67e5\u8be2");        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());        jLabel1.setFont(new java.awt.Font("Dialog", 1, 14));        jLabel1.setText("\u65f6\u95f4\u7531:");        jLabel2.setFont(new java.awt.Font("Dialog", 1, 14));        jLabel2.setText("\u81f3:");        jButton1.setFont(new java.awt.Font("Dialog", 1, 14));        jButton1.setText("\u67e5\u8be2");        jButton1.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                jButton1ActionPerformed(evt);            }        });        jButton2.setFont(new java.awt.Font("Dialog", 1, 14));        jButton2.setText("\u67e5\u770b\u9500\u552e\u660e\u7ec6");        jButton2.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                jButton2ActionPerformed(evt);            }        });        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);        jPanel1.setLayout(jPanel1Layout);        jPanel1Layout.setHorizontalGroup(            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(jPanel1Layout.createSequentialGroup()                .addContainerGap()                .addComponent(jLabel1)                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                .addComponent(jDatePicker1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                .addComponent(jLabel2)                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                .addComponent(jDatePicker2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)                .addGap(104, 104, 104)                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)                .addContainerGap(23, Short.MAX_VALUE))        );        jPanel1Layout.setVerticalGroup(            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(jPanel1Layout.createSequentialGroup()                .addContainerGap()                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)                    .addComponent(jDatePicker1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)                    .addComponent(jLabel1)                    .addComponent(jDatePicker2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)                    .addComponent(jLabel2)                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))        );        jTable1.setModel(getSaleTableModel());        jScrollPane1.setViewportView(jTable1);        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());        getContentPane().setLayout(layout);        layout.setHorizontalGroup(            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()                .addContainerGap()                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 756, Short.MAX_VALUE)                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))                .addContainerGap())        );        layout.setVerticalGroup(            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(layout.createSequentialGroup()                .addContainerGap()                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 406, Short.MAX_VALUE)                .addContainerGap())        );        pack();    }// </editor-fold>//GEN-END:initComponents    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed    int row = jTable1.getSelectedRow();    if (row == -1) {        JOptionPane.showMessageDialog(this, "请选择一个销售单!");        return;    }    Sale s = saleList.get(row);    new SaleItemViewer(this, s.getSaleID(), true).setVisible(true);}//GEN-LAST:event_jButton2ActionPerformedprivate void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed    java.util.Date startDate = null;    java.util.Date endDate = null;    try {        startDate = jDatePicker1.getSelectedDate();        endDate = jDatePicker2.getSelectedDate();    } catch (ParseException ex) {        startDate = new Date(0);        endDate = new Date();    }    endDate = new Date(endDate.getTime() + 3600 * 24000);    saleQuery = em.createQuery("select s from Sale s where s.saleTime > :startDate and s.saleTime < :endDate");    saleQuery.setParameter("startDate", startDate);    saleQuery.setParameter("endDate", endDate);    saleList = saleQuery.getResultList();    updateTable();}//GEN-LAST:event_jButton1ActionPerformed/** * 获取用来显示销售单的表格模型 * @return 用来显示销售单的表格模型 */public DefaultTableModel getSaleTableModel() {    Vector columnName=new Vector();    columnName.add("单据编号");    columnName.add("客户名称");    columnName.add("操作员");    columnName.add("售货时间");    columnName.add("实付款");    columnName.add("欠收款");    columnName.add("状态");    Vector content=new Vector();        for( Sale s : saleList) {        Vector row = new Vector();        row.add(s.getSaleID());        row.add(s.getCustomerName().getCustomerName());        row.add(s.getOperatorName().getOperatorName());        row.add(new SimpleDateFormat().format(s.getSaleTime()));        row.add(String.format("%.2f", s.getGetMoney()));        row.add(String.format("%.2f", s.getOweGetMoney()));        if (s.getSaleState() == 1) row.add("正常");        else row.add("已退货");        content.add(row);    }    DefaultTableModel stockItemTableModel=new DefaultTableModel(content,columnName){        public boolean isCellEditable(int row, int col) {            return false;        }    };    return stockItemTableModel;}/** * 更新表格 */private void updateTable(){    jTable1.setModel(getSaleTableModel());}/** * @param args the command line arguments */public static void main(String args[]) {    java.awt.EventQueue.invokeLater(new Runnable() {        public void run() {            SaleViewer dialog = new SaleViewer(new javax.swing.JFrame(), true);            dialog.addWindowListener(new java.awt.event.WindowAdapter() {                public void windowClosing(java.awt.event.WindowEvent e) {                    System.exit(0);                }            });            dialog.setVisible(true);        }    });}    // Variables declaration - do not modify//GEN-BEGIN:variables    private javax.persistence.EntityManager em;    private javax.swing.JButton jButton1;    private javax.swing.JButton jButton2;    private com.sunking.swing.JDatePicker jDatePicker1;    private com.sunking.swing.JDatePicker jDatePicker2;    private javax.swing.JLabel jLabel1;    private javax.swing.JLabel jLabel2;    private javax.swing.JPanel jPanel1;    private javax.swing.JScrollPane jScrollPane1;    private javax.swing.JTable jTable1;    private java.util.List<Sale> saleList;    private javax.persistence.Query saleQuery;    // End of variables declaration//GEN-END:variables    }

⌨️ 快捷键说明

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