📄 stockviewer.java.svn-base
字号:
/* * StockViewer.java * * Created on 2007年6月9日, 下午1:57 */package com.studio009.store.ui;import com.studio009.store.StoreApp;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 Stock * @author wangs */public class StockViewer extends javax.swing.JDialog { /** Creates new form StockViewer * @param parent 父窗口 * @param modal 模式 */ public StockViewer(java.awt.Window 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(); stockQuery = em.createQuery("select s from Stock s"); stockList = stockQuery.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("\u8fdb\u8d27\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\u8fdb\u8d27\u5355\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(118, 118, 118) .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jButton2) .addContainerGap(29, 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, 33, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); jTable1.setModel(getStockTableModel()); 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, 786, 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, 361, 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; } Stock s = stockList.get(row); new StockItemViewer(this, s.getStockID(), 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); stockQuery = em.createQuery("select s from Stock s where s.stockTime > :startDate and s.stockTime < :endDate"); stockQuery.setParameter("startDate", startDate); stockQuery.setParameter("endDate", endDate); stockList = stockQuery.getResultList(); updateTable();}//GEN-LAST:event_jButton1ActionPerformed/** * 获取用来显示进货单的表格模型 * @return 用来显示进货单的表格模型 */public DefaultTableModel getStockTableModel() { Vector columnName=new Vector(); columnName.add("单据编号"); columnName.add("供应商"); columnName.add("操作员"); columnName.add("收货仓库"); columnName.add("进货时间"); columnName.add("实付款"); columnName.add("欠付款"); columnName.add("状态"); Vector content=new Vector(); for( Stock s : stockList) { Vector row = new Vector(); row.add(s.getStockID()); row.add(s.getSupplierName().getSupplierName()); row.add(s.getOperatorName().getOperatorName()); row.add(s.getStoreName().getStoreName()); row.add(new SimpleDateFormat().format(s.getStockTime())); row.add(String.format("%.2f", s.getGiveMoney())); row.add(String.format("%.2f", s.getOweGiveMoney())); if (s.getStockState() == 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(getStockTableModel());}/** * @param args the command line arguments */public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { StockViewer dialog = new StockViewer(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<Stock> stockList; private javax.persistence.Query stockQuery; // End of variables declaration//GEN-END:variables}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -