📄 stockdetailframe.java
字号:
/*
* StockDetailFrame.java
*
* Created on 2007年5月29日, 下午8:47
*/
package form;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import table.Product;
import table.PurchaseDetail;
import task.HandleProduct;
import task.HandlePurchaseDetail;
/**
*
* @author s
*/
public class StockDetailFrame extends javax.swing.JFrame {
private String str1;
/** Creates new form StockDetailFrame */
public StockDetailFrame(String str) {
initComponents();
str1=str;
databind();
}
private void databind(){
HandleProduct hu=new HandleProduct();
ArrayList v=new ArrayList();
v=hu.findAll();
String[] theader={"商品编号","商品名称","安全库存量","商品数量","建议购买价","建议销售价"};
int j=0;
String[][] tdata=new String[v.size()][8];
for(int i=0;i<v.size();i++){
Product s=new Product();
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());
}
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();
jLabel1 = new javax.swing.JLabel();
txtQuantity = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("\u5546\u54c1\u6570\u91cf\uff1a");
jButton1.setText("\u6dfb\u52a0");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("\u9000\u51fa");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(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(52, 52, 52)
.add(jLabel1)
.add(17, 17, 17)
.add(txtQuantity, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 115, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(26, 26, 26)
.add(jButton1)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 52, Short.MAX_VALUE)
.add(jButton2)
.add(26, 26, 26))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.add(29, 29, 29)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel1)
.add(txtQuantity, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jButton1)
.add(jButton2))
.addContainerGap(34, Short.MAX_VALUE))
);
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null}
},
new String [] {
"标题 1", "标题 2", "标题 3", "标题 4", "标题 5"
}
));
jScrollPane1.setViewportView(jTable1);
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 454, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 359, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap(44, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO 将在此处添加您的处理代码:
this.dispose();
}//GEN-LAST:event_jButton2ActionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO 将在此处添加您的处理代码:
HandleProduct hu=new HandleProduct();
Product p=new Product();
HandlePurchaseDetail hc=new HandlePurchaseDetail();
PurchaseDetail pc=new PurchaseDetail();
ArrayList v=new ArrayList();
v=hu.findAll();
int i=jTable1.getSelectedRow();
Product s=new Product();
s=(Product)v.get(i);
pc.setQuantity(Double.parseDouble(txtQuantity.getText().trim()));
pc.setProductID(s.getProductID());
pc.setPrice(s.getSuggestBuyPrice());
pc.setPurchaseID(str1);
hc.save(pc);
p.setQuantity(Double.parseDouble(txtQuantity.getText()));
p.setProductID(s.getProductID());
hu.addupdate(p);
JOptionPane.showMessageDialog(this,"保存成功!","",JOptionPane.WARNING_MESSAGE);
//StockFrame sf=new StockFrame();
//sf.showout();
}//GEN-LAST:event_jButton1ActionPerformed
/**
* @param args the command line arguments
*/
// public static void main(String args[]) {
// java.awt.EventQueue.invokeLater(new Runnable() {
// public void run() {
// new StockDetailFrame().setVisible(true);
// }
// });
// }
// 变量声明 - 不进行修改//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
private javax.swing.JTextField txtQuantity;
// 变量声明结束//GEN-END:variables
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -