📄 findprodout.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 FindProdOut 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(); } }else{ JOptionPane.showMessageDialog(this, new String("请先选择某些行记录")); return; } }else if(b == jb_find){ new FindShow(this,"输入查询条件",true); } } } public FindProdOut(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.find(FindShow.pro); 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 FindProdOut("查询出库单结果"); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -