📄 deleteprodutframe.java
字号:
/*
* DeleteProdutFrame.java
*
* Created on 2007年5月30日, 下午5:33
*/
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 下雪天
*/
public class DeleteProdutFrame extends javax.swing.JFrame {
private String str1;
/** Creates new form DeleteProdutFrame */
public DeleteProdutFrame(String str) {
initComponents();
str1=str;
showout();
}
public void showout(){
HandlePurchaseDetail hp=new HandlePurchaseDetail();
ArrayList a=new ArrayList();
a=hp.find(str1);
String[] theader={"商品编号"," 商品数量","商品价格","总金额"};
String[][] tdata=new String[a.size()][8];
for(int i=0;i<a.size();i++){
PurchaseDetail u=new PurchaseDetail();
u=(PurchaseDetail)a.get(i);
tdata[i][0]=u.getProductID();
tdata[i][1]=Double.toString(u.getQuantity());
tdata[i][2]=Double.toString(u.getPrice());
tdata[i][3]=Double.toString(u.getAmount());
}
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() {
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);
jButton1.setText("\u5220\u9664");
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);
}
});
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}
},
new String [] {
"标题 1", "标题 2", "标题 3", "标题 4"
}
));
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()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(98, 98, 98)
.add(jButton1)
.add(70, 70, 70)
.add(jButton2))
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 412, Short.MAX_VALUE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 275, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 66, Short.MAX_VALUE)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jButton2)
.add(jButton1))
.add(26, 26, 26))
);
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 s=new Product();
HandlePurchaseDetail hc=new HandlePurchaseDetail();
PurchaseDetail pc=new PurchaseDetail();
ArrayList a=new ArrayList();
a=hc.find(str1);
int i=jTable1.getSelectedRow();
pc=(PurchaseDetail)a.get(i);
s.setProductID(pc.getProductID());
s.setQuantity(pc.getQuantity());
if(hu.isdelete(s)){
hu.updateQuantity(s);
hc.delete(pc);
JOptionPane.showMessageDialog(this,"成功删除!","",JOptionPane.WARNING_MESSAGE);
}
else
JOptionPane.showMessageDialog(this,"不能删除!","",JOptionPane.WARNING_MESSAGE);
showout();
//ArrayList v=new ArrayList();
//v=hu.findAll();
//s=(Product)v.get(i);
//pc.setQuantity(Double.parseDouble(txtQuantity.getText().trim()));
//pc.setProductID(s.getProductID());
//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 DeleteProdutFrame().setVisible(true);
// }
// });
// }
// 变量声明 - 不进行修改//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
// 变量声明结束//GEN-END:variables
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -