⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addprodout.java

📁 利用java swing实现简单的单机版仓库管理
💻 JAVA
字号:
package control.view.prodout;import control.view.*;import javax.swing.*;import java.awt.event.*;import java.awt.*;import java.util.Date;import beans.ProdOut;import control.dao.prodout.ProdOutDAOImpl;import control.view.product.AddProduct;public class AddProdOut extends JDialog implements ActionListener,FocusListener{    private static String msg="";        private JButton jb_save=new JButton("出库");    private JButton jb_exit=new JButton("取消");    private JTextField tf_pName=new JTextField();    private JTextField tf_pINum=new JTextField();    private JTextField tf_pIUnit=new JTextField();    private JTextField tf_pITotalMoney=new JTextField();    private JTextField tf_pIByer=new JTextField();    private JTextField tf_pIStorager=new JTextField();    Date now=new Date();    private JTextField tf_pITime_y=new JTextField(new Integer(now.getYear()+1900).toString(),4);    private JTextField tf_pITime_m=new JTextField(new Integer(now.getMonth()+1).toString(),2);    private JTextField tf_pITime_d=new JTextField(new Integer(now.getDate()).toString(),2);    private JTextArea tf_pIComment=new JTextArea(5,20);        private JLabel la_pName=new JLabel("产品名称:");    private JLabel la_pINum=new JLabel("出库数量:");    private JLabel la_pIUnit=new JLabel("出库单价:");    private JLabel la_pITotalMoney=new JLabel("总价:");    private JLabel la_pIByer=new JLabel("经办人:");    private JLabel la_pIStorager=new JLabel("库管员:");    private JLabel la_pITime=new JLabel("出库日期:");    private JLabel la_pITime_y=new JLabel("年");    private JLabel la_pITime_m=new JLabel("月");    private JLabel la_pITime_d=new JLabel("日");    private JLabel la_pIComment=new JLabel("备注:");    public void focusGained(FocusEvent e){            }     public void focusLost(FocusEvent e)  {        try{            int pINum=Integer.parseInt(tf_pINum.getText());            double pIUnit=Double.parseDouble(tf_pIUnit.getText());            double pITotal=pIUnit*pINum;            tf_pITotalMoney.setText(new Double(pITotal).toString());        }catch(Exception ep){            System.out.println(ep.getMessage());        }    }    public void actionPerformed(ActionEvent e){                if(e.getSource() instanceof JButton){            JButton b=(JButton)e.getSource();                       if(b == jb_save){                try{                    if(getProduct() == null){                        throw new Exception(msg);                    }                    int sFlag=saveProdOut(getProduct());                    if(sFlag==-2){                        JOptionPane.showMessageDialog(this, new String("库存不足!请减少出库量"));                    }else if(sFlag==-1){                        int n=JOptionPane.showConfirmDialog(this, msg+",是否现在入库该新产品?");                        if(n==JOptionPane.OK_OPTION){                            this.dispose();                            new AddProduct((JFrame)this.getParent(), "入库新产品", true);                        }                    }else if(sFlag == 1){                        JOptionPane.showMessageDialog(this, new String("出库成功"));                        this.dispose();                        ((JFrame)this.getParent()).dispose();                        new ShowAllProdOut("所有出库单");                    }else{                        JOptionPane.showMessageDialog(this, new String(msg));                    }                }catch(Exception ee){                    System.out.println(ee.getMessage());                    JOptionPane.showMessageDialog(this, new String(msg));                }            }else if(b == jb_exit){                    this.dispose();            }        }    }        private ProdOut getProduct() throws Exception{        try{            if(tf_pName.getText().equals("") ||                     tf_pINum.getText().equals("") ||                    tf_pITotalMoney.getText().equals("") ||                    tf_pIByer.getText().equals("") ||                    tf_pIStorager.getText().equals("") ||                    tf_pITime_y.getText().equals("") ||                    tf_pITime_m.getText().equals("") ||                    tf_pITime_d.getText().equals("") )            {                msg="请填写各项内容!";                return null;            }            Double pITotalMoney=Double.parseDouble(tf_pITotalMoney.getText());            Integer pINum=Integer.parseInt(tf_pINum.getText());            int pITime_y=Integer.parseInt(tf_pITime_y.getText());            int pITime_m=Integer.parseInt(tf_pITime_m.getText());            int pITime_d=Integer.parseInt(tf_pITime_d.getText());            System.out.println(pITime_y+"   "+pITime_d+"  "+pITime_m);            if( pITotalMoney.isNaN()){                msg="请确认金额输入是数字";                return null;            }            if((pITime_m>12) || (pITime_m <1) || (pITime_d>31) || (pITime_d<1)){                msg="请确认日期输入正确";                return null;            }        }catch(Exception e){            System.out.println(e.getMessage());            msg="请确认输入的数据正确";        }        String pITime=tf_pITime_y.getText()+"-"                +tf_pITime_m.getText()+"-"+tf_pITime_d.getText();        return new ProdOut(            tf_pName.getText(),            new Integer(tf_pINum.getText()),            new Double(tf_pITotalMoney.getText()),            tf_pIByer.getText(),            tf_pIStorager.getText(),            pITime,            tf_pIComment.getText()        );    }        public AddProdOut(JFrame fra,String title,boolean model){        super(fra,title,model);        setMid(500,550,this);        this.setResizable(false);                addComponent();        this.show(true);        this.pack();    }    private void addComponent(){                this.getContentPane().setLayout(null);            la_pName.setBounds(100,20,110,30);        la_pINum.setBounds(100,70,110,30);        la_pIUnit.setBounds(100,120,110,30);        la_pITotalMoney.setBounds(100,170,110,30);        la_pIByer.setBounds(100,220,110,30);        la_pIStorager.setBounds(100,270,110,30);        la_pITime.setBounds(100,320,110,30);        la_pIComment.setBounds(100,370,110,30);                tf_pName.setBounds(210,20,150,30);        tf_pINum.setBounds(210,70,50,30);        tf_pIUnit.setBounds(210,120,50,30);        tf_pITotalMoney.setBounds(210,170,50,30);        tf_pIByer.setBounds(210,220,150,30);        tf_pIStorager.setBounds(210,270,150,30);                tf_pITime_y.setBounds(205,320,35,30);        la_pITime_y.setBounds(240,320,20,30);        tf_pITime_m.setBounds(260,320,30,30);        la_pITime_m.setBounds(290,320,20,30);        tf_pITime_d.setBounds(310,320,30,30);        la_pITime_d.setBounds(340,320,20,30);                tf_pIComment.setBounds(210,370,200,100);        tf_pIComment.setBorder(new javax.swing.border.LineBorder(Color.BLACK));        jb_save.setBounds(100,480,100,35);        jb_exit.setBounds(220,480,100,35);                this.add(la_pName);        this.add(tf_pName);        this.add(la_pINum);        this.add(tf_pINum);        this.add(tf_pIUnit);        this.add(la_pIUnit);        this.add(la_pITotalMoney);        this.add(tf_pITotalMoney);         this.add(la_pIByer);        this.add(tf_pIByer);        this.add(la_pIStorager);        this.add(tf_pIStorager);        this.add(la_pITime);        this.add(tf_pITime_y);        this.add(tf_pITime_m);        this.add(tf_pITime_d);        this.add(la_pITime_y);        this.add(la_pITime_m);        this.add(la_pITime_d);        this.add(la_pIComment);        this.add(tf_pIComment);                tf_pIUnit.addFocusListener(this);        jb_save.addActionListener(this);        jb_exit.addActionListener(this);                this.add(jb_save);        this.add(jb_exit);    }        private int saveProdOut(ProdOut pro){        ProdOutDAOImpl pd=new ProdOutDAOImpl();        int rows=pd.insert(pro);        if (rows == -1){            msg="相应的产品还没有入库,请先添加该产品";            return -1;        }        if(rows == -2){            msg="库存不足!请减少出库量";        }        if(rows==1) return 1;        else return 0;    }        public void setMid(int width,int height,java.awt.Window fra){        Dimension ds=Toolkit.getDefaultToolkit().getScreenSize();        int x=new Double( (ds.getWidth()-width)/2 ).intValue();        int y=new Double( (ds.getHeight()-height)/2 ).intValue();        fra.setBounds(x,y,width,height);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -