📄 addstockitemjdialog.java.svn-base
字号:
/* * AddStockItemJDialog.java * * Created on 2007年6月6日, 下午5:25 */package com.studio009.store.ui;import com.studio009.store.StoreApp;import com.studio009.store.entity.Goods;import com.studio009.store.entity.StockItem;import java.math.BigDecimal;import java.util.Vector;import javax.persistence.EntityManager;import javax.persistence.Query;import javax.swing.JOptionPane;import javax.swing.table.DefaultTableModel;/** * 添加一个商品已经存在的进货明细 * @author wangs */public class AddStockItemJDialog extends javax.swing.JDialog { /** Creates new form AddStoreItemsJDialog * @param parent 父窗口 * @param stockItem 进货明细 * @param modal 模式 */ public AddStockItemJDialog(java.awt.Window parent, StockItem stockItem, boolean modal) { super(parent, java.awt.Dialog.ModalityType.APPLICATION_MODAL); this.stockItem = stockItem; initComponents(); // 设置对话框居中 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() { stockItem = stockItem; jScrollPane1 = new javax.swing.JScrollPane(); jTable1 = new javax.swing.JTable(); jLabel3 = new javax.swing.JLabel(); jLabel12 = new javax.swing.JLabel(); okButton = new javax.swing.JButton(); cancelButton = new javax.swing.JButton(); jNumberField1 = new com.sunking.swing.JNumberField(12,2); jNumberField2 = new com.sunking.swing.JNumberField(12,2); setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); setTitle("\u6dfb\u52a0\u5df2\u6709\u5546\u54c1"); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { formWindowClosing(evt); } }); jTable1.setModel(getGoodsTableModel()); jScrollPane1.setViewportView(jTable1); jLabel3.setFont(new java.awt.Font("Dialog", 1, 18)); jLabel3.setText("\u8fdb\u4ef7:"); jLabel12.setFont(new java.awt.Font("Dialog", 1, 18)); jLabel12.setText("\u6570\u91cf:"); okButton.setText("\u786e\u5b9a"); okButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { okButtonActionPerformed(evt); } }); cancelButton.setText("\u53d6\u6d88"); cancelButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cancelButtonActionPerformed(evt); } }); jNumberField1.setText("jNumberField1"); jNumberField2.setText("jNumberField2"); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(64, 64, 64) .addComponent(jLabel3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jNumberField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(34, 34, 34) .addComponent(jLabel12) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jNumberField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 563, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap(259, Short.MAX_VALUE) .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(68, 68, 68) .addComponent(cancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(60, 60, 60)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 256, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(32, 32, 32) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3) .addComponent(jNumberField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel12) .addComponent(jNumberField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGap(33, 33, 33) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(cancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap()) ); pack(); }// </editor-fold>//GEN-END:initComponents private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing stockItem = null; this.dispose();}//GEN-LAST:event_formWindowClosingprivate void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed stockItem = null; this.dispose();}//GEN-LAST:event_cancelButtonActionPerformedprivate void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed int row = jTable1.getSelectedRow(); if (row == -1) { JOptionPane.showMessageDialog(this, "请选择一种商品!", "", JOptionPane.ERROR_MESSAGE ); return; } Goods g = goodsList.get(row); stockItem.setGoodsID(g); if (jNumberField1.getText().isEmpty()) { JOptionPane.showMessageDialog(this, "请输入进价!", "", JOptionPane.ERROR_MESSAGE ); jNumberField1.requestFocus(); return; } if (jNumberField2.getText().isEmpty()) { JOptionPane.showMessageDialog(this, "请输入数量!", "", JOptionPane.ERROR_MESSAGE ); jNumberField2.requestFocus(); return; } stockItem.setCostPrice(new BigDecimal(jNumberField1.getText())); stockItem.setStockQuantity(Double.parseDouble(jNumberField2.getText())); stockItem.setStockitemState(0); if (stockItem.getCostPrice().doubleValue() < 0 || stockItem.getStockQuantity() <= 0) { JOptionPane.showMessageDialog(this, "价格和数量必须为正数!", "", JOptionPane.ERROR_MESSAGE ); return; } this.dispose();}//GEN-LAST:event_okButtonActionPerformed/** * 获取用来显示商品的表格模型 * @return 用来显示商品的表格模型 */public DefaultTableModel getGoodsTableModel() { EntityManager em = StoreApp.getSingleEntityManager(); Query query = em.createQuery("select g from Goods g"); goodsList = (Vector<Goods>) query.getResultList(); Vector columnName=new Vector(); columnName.add("商品名称"); columnName.add("规格"); columnName.add("颜色"); columnName.add("单位"); columnName.add("单价"); Vector content=new Vector(); for( Goods g : goodsList) { Vector row = new Vector(); row.add(g.getGoodsName()); row.add(g.getSpec()); row.add(g.getColor()); row.add(g.getUnit()); row.add(String.format("%,.2f", g.getPrice())); content.add(row); } DefaultTableModel stockItemTableModel=new DefaultTableModel(content,columnName){ public boolean isCellEditable(int row, int col) { return false; } }; return stockItemTableModel;}/** * 显示该对话框并返回进货明细 * @return 编辑完成的进货明细 */public StockItem showDialog() { this.setVisible(true); return stockItem;} // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton cancelButton; private javax.swing.JLabel jLabel12; private javax.swing.JLabel jLabel3; private com.sunking.swing.JNumberField jNumberField1; private com.sunking.swing.JNumberField jNumberField2; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTable jTable1; private javax.swing.JButton okButton; private com.studio009.store.entity.StockItem stockItem; // End of variables declaration//GEN-END:variables Vector<Goods> goodsList;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -