?? showallprodout.java
字號:
package control.view.prodout;import control.view.*;import javax.swing.*;import javax.swing.table.*;import java.util.ArrayList;import java.awt.*;import java.awt.event.*;import control.dao.prodout.ProdOutDAOImpl;import beans.ProdOut;public class ShowAllProdOut extends MainFrame implements ShowProdOut{ private static JTable thisTable=null; private JButton jb_print=new JButton("打印此表",new ImageIcon("images/print.gif")); private JButton jb_find=new JButton("查找",new ImageIcon("images/search.gif")); private JButton jb_add=new JButton("新出庫",new ImageIcon("images/add.gif")); private JButton jb_del=new JButton("刪除選中的",new ImageIcon("images/delete.gif")); private JButton jb_refresh=new JButton("刷新",new ImageIcon("images/refresh.gif")); private JButton jb_exit=new JButton("退出",new ImageIcon("images/exit.gif")); public void actionPerformed(ActionEvent e){ super.actionPerformed(e); if(e.getSource() instanceof JButton){ JButton b=(JButton)e.getSource(); if(b == jb_print){ try{ thisTable.print(); }catch(Exception ee){ ee.printStackTrace(); } }else if (b == jb_refresh){ try{ fresh(); }catch(Throwable te){ } }else if(b == jb_exit){ if( (JOptionPane.showConfirmDialog(this, new String("是否真的退出?")))== JOptionPane.YES_OPTION) { this.dispose(); } }else if(b == jb_add){ new AddProdOut(this,"填寫出庫單",true); }else if(b == jb_del){ int pID; int[] rows=thisTable.getSelectedRows(); int firstRow=thisTable.getSelectedRow(); if(firstRow != -1){ int isdel=JOptionPane.showConfirmDialog(this, new String("確定刪除選中的記錄嗎?")); if(isdel==JOptionPane.YES_OPTION){ for(int i=0; i<rows.length; i++){ pID=Integer.parseInt(thisTable.getValueAt(rows[i], 1).toString()); if(!(del_product(pID))){ JOptionPane.showMessageDialog(this, new String("刪除編號為"+pID+"出錯")); return; } } fresh(); } JOptionPane.showMessageDialog(this, new String("請先選擇某些行記錄")); return; } }else if(b == jb_find){ new FindShow(this,"輸入查詢條件",true); } } } public ShowAllProdOut(String title){ super(title); setMid(900,600,this); this.setResizable(false); addComponent(); this.show(true); } public void addComponent(){ JPanel fraPane=(JPanel)this.getContentPane(); fraPane.setLayout(new BorderLayout()); fraPane.setBackground(new java.awt.Color(189,230,247)); thisTable=addTable(); JScrollPane sp=new JScrollPane(thisTable); fraPane.add(sp,BorderLayout.NORTH); JPanel jp=new JPanel(); jp.setBackground(new java.awt.Color(189,230,247)); jp.setLayout(null); jp.setPreferredSize(new Dimension(900,100)); jb_print.setBounds(70,10,120,35); jb_find.setBounds(210,10,100,35); jb_add.setBounds(330,10,120,35); jb_del.setBounds(470,10,140,35); jb_refresh.setBounds(630,10,100,35); jb_exit.setBounds(740,10,120,35); jp.add(jb_print); jp.add(jb_find); jp.add(jb_add); jp.add(jb_del); jp.add(jb_refresh); jp.add(jb_exit); jb_refresh.addActionListener(this); jb_print.addActionListener(this); jb_exit.addActionListener(this); jb_find.addActionListener(this); jb_add.addActionListener(this); jb_del.addActionListener(this); fraPane.add(jp,BorderLayout.SOUTH); } public JTable addTable(){ ProdOutDAOImpl pdi=new ProdOutDAOImpl(); ArrayList lists=pdi.showAll(); Object[][] data=new Object[lists.size()+1][9]; for(int i=0; i<lists.size();i++){ data[i][0]=i+1; data[i][1]=((ProdOut)lists.get(i)).getPOID(); data[i][2]=((ProdOut)lists.get(i)).getPName(); data[i][3]=((ProdOut)lists.get(i)).getPONum(); data[i][4]=((ProdOut)lists.get(i)).getPOTotalMoney(); data[i][5]=((ProdOut)lists.get(i)).getPOByer(); data[i][6]=((ProdOut)lists.get(i)).getPOStorager(); data[i][7]=((ProdOut)lists.get(i)).getPOTime(); data[i][8]=((ProdOut)lists.get(i)).getPOComment(); } MyModel myModel=new MyModel(data,lists.size(),9); JTable table=new JTable(myModel); table.getColumnModel().getColumn(0).setHeaderValue(new String("序號")); table.getColumnModel().getColumn(1).setHeaderValue(new String("出庫編號")); table.getColumnModel().getColumn(2).setHeaderValue(new String("產品名稱")); table.getColumnModel().getColumn(3).setHeaderValue(new String("出庫數量")); table.getColumnModel().getColumn(4).setHeaderValue(new String("總價")); table.getColumnModel().getColumn(5).setHeaderValue(new String("經辦人")); table.getColumnModel().getColumn(6).setHeaderValue(new String("庫管員")); table.getColumnModel().getColumn(7).setHeaderValue(new String("出庫日期")); table.getColumnModel().getColumn(8).setHeaderValue(new String("備注")); return table; } class MyModel extends AbstractTableModel{ Object data[][]; int rows,cols; public MyModel(Object[][] d,int rows,int cols){ this.rows=rows; this.cols=cols; this.data=d; } public int getColumnCount(){ return this.cols; } public int getRowCount(){ return this.rows; } public Object getValueAt(int row,int col){ return data[row][col].toString(); } public boolean isCellEditable(int row,int col){ return true; } public void setValueAt(Object value,int row,int col){ data[row][col]=(String)value; this.fireTableCellUpdated(row, col); } } public boolean del_product(int pID){ ProdOutDAOImpl pdm=new ProdOutDAOImpl(); if(pdm.delete(pID)==1){ pdm.closeConn(); return true; } else{ pdm.closeConn(); return false; } } public void fresh(){ this.dispose(); new ShowAllProdOut("所有出庫單"); }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -