• Java模拟公司置办货物系统(二)


    採用MVC风格,将数据写入文件,模拟公司置办货物系统。 
    A类表示普通员工,B类表示部门精力,C类表示採购部,D类表示资源管理部。

    订单状态 1.表示申请状态 2.表示通过审批 3.表示未通过审批 4.表示订单完毕,购物完毕

    第三步:创建Po类,代表採购部批准的订单类.

    package com.jereh14;
    
    public class Po implements java.io.Serializable{
    
        public int getPor_no() {
            return por_no;
        }
        public void setPor_no(int por_no) {
            this.por_no = por_no;
        }
        public String getPart_desc() {
            return part_desc;
        }
        public int getPo_no() {
            return po_no;
        }
        public void setPo_no(int po_no) {
            this.po_no = po_no;
        }
        public double getPrice() {
            return price;
        }
        public void setPrice(double price) {
            this.price = price;
        }
        public String getComp() {
            return comp;
        }
        public void setComp(String comp) {
            this.comp = comp;
        }
        public String getOrd_date() {
            return ord_date;
        }
        public void setOrd_date(String ord_date) {
            this.ord_date = ord_date;
        }
        public String getOrd_emp() {
            return ord_emp;
        }
        public void setOrd_emp(String ord_emp) {
            this.ord_emp = ord_emp;
        }
        public void setPart_desc(String part_desc) {
            this.part_desc = part_desc;
        }
        public String getPart_type() {
            return part_type;
        }
        public void setPart_type(String part_type) {
            this.part_type = part_type;
        }
        public int getCount() {
            return count;
        }
        public void setCount(int count) {
            this.count = count;
        }
    
        public String getPnd() {
            return pnd;
        }
        public void setPnd(String pnd) {
            this.pnd = pnd;
        }
    
        public int getStus() {
            return stus;
        }
        public void setStus(int stus) {
            this.stus = stus;
        }
    
        private int po_no;
        private int por_no;
        private String part_desc;
        private String part_type;
        private int count;
        private double price;
        private String comp;
        private String pnd;
        private String ord_date;
        private String ord_emp;
        private int stus;
    
    }
    

    定义PoBiz类,实现购买的物品入库方法.

    package com.jereh14;
    
    import java.io.*;
    import java.util.*;
    
    public class PoBiz {
    
    private List<Po> list = new ArrayList<Po>();
    
        public void addPo(Po po){
    
            readDb();
            list.add(po);
            writeDb();
        }
        public void showPo(){
    
            readDb();
            Iterator<Po> i = list.iterator();
                while(i.hasNext()){
                    Po p = i.next();
                    System.out.println(p.getPo_no()+"	"+p.getPor_no()+"	"+p.getPart_desc()+"	"+p.getPart_type()+"	"+
                            p.getCount()+"	"+p.getPrice()+"	"+p.getStus()+"	"+p.getComp()+"	"+p.getPnd()+"	"+p.getOrd_date()+"	"+
                            p.getOrd_emp());
                }
            writeDb();
        }
    
        public boolean check(int por_no){
            Iterator<Po> i = list.iterator();
            boolean bool = false;
            while(i.hasNext()){
                Po p = i.next();
                if(p.getPor_no() == por_no){
                    bool = true;
                    break;
                }else{
                    bool = false;
                }
            }
            return bool;
        }
    
        public void readDb(){
    
            FileInputStream fis  = null;
            ObjectInputStream is = null;
            try {
                fis = new FileInputStream("F:\test\Po.txt");
                is = new ObjectInputStream(fis);
                list = (List<Po>) is.readObject();
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } finally {
                try {
                    is.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
    
        }
    
        public void writeDb(){
    
            FileOutputStream fos  = null;
            ObjectOutputStream os = null;
            try {
                fos = new FileOutputStream("F:\test\Po.txt");
                os  = new ObjectOutputStream(fos);
                os.writeObject(list);
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } finally {
                try {
                    os.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    }

    定义PoView类,用于採购部确定经过审批的界面。订单状态变为4。

    package com.jereh14;
    
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.Scanner;
    
    public class PoView {
    
        private int i = 0;
        public void showInfoView(){
    
            Scanner scn = new Scanner(System.in);
            PorBiz pb   = new PorBiz();
            PoBiz  pbz  = new PoBiz();
            Po po = null;
            Por por = null;
    
    
            System.out.println("=======================================订单审批=======================================
    ");
            System.out.println("编号	名称	型号	数量	用途	须要日期	申请日期	状态	申请者	批准日期	审核者
    ");
            pb.showPor(3);
            while(true){
    
                System.out.println("
    ******************************1、选单订货		2、退出*******************************");
                System.out.print("请选择您的操作:");
                int chooseNum = scn.nextInt();
                int porId = -1;
                switch(chooseNum){
                case 1:
                    System.out.print("请输入您要操作的单号:");
                    porId = scn.nextInt();
                    if((por=pb.getPor(porId))!=null){
                        System.out.print("请输入订货数量:");
                        int por_num = scn.nextInt();
                        System.out.print("请输入单位价格:");
                        double price = scn.nextDouble();
                        System.out.print("请输入供应商:");
                        String comp = scn.next();
    
                        Date date = new Date();
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
                        po = new Po();
                        po.setPo_no(i++);
                        po.setPor_no(por.getPor_no());
                        po.setPart_desc(por.getPart_desc());
                        po.setPart_type(por.getPart_type());
                        po.setCount(por_num);
                        po.setPrice(price);
                        po.setComp(comp);
                        po.setPnd(por.getPnd());
                        po.setOrd_date(sdf.format(date));
                        po.setOrd_emp(por.getRgdt_emp());
                        po.setStus(4);
    
                        pbz.addPo(po);
                        pb.changeStuts(porId, 3);
                        if(pb.check(porId)){
                            System.out.println("--加入成功!

    --"); }else{ System.out.println("--加入失败!

    --"); } }else{ System.out.println("--该订单不存在。-- "); } break; case 2: System.exit(0); System.out.println("谢谢您的使用!"); break; default: System.out.println("--输入有误。--"); break; } } } }

    这里写图片描写叙述
    定义PoCfView类,用来仓库物品查询.

    package com.jereh14;
    
    import java.util.Scanner;
    
    public class PoCfView {
    
        public void showInfoView(){
            Scanner scn = new Scanner(System.in);
            PorBiz pb   = new PorBiz();
            PoBiz  pbz  = new PoBiz();
    
            while(true){
                System.out.println("=======================================仓库查询=======================================
    ");
                System.out.println("========================请选择您的操作:1、查看仓库		2、退出======================");
                int chooseNum = scn.nextInt();
                switch(chooseNum){
                case 1:
                    System.out.println("
    订货编号	申请编号	名称	型号	数量	单位价格	状态	供应商	须要日期	订货日期	订货者
    ");
                    pbz.showPo();
                    System.out.println("
    ************************************************************************************");               break;
                case 2:
                    System.out.println("谢谢您的使用。");
                    System.exit(0);
                    break;
                    default:
                        System.out.println("--输入有误!

    --"); break; } } } }

    执行效果图:这里写图片描写叙述
    第四歩:定义Test类将各个View组合起来。

    package com.jereh14;
    
    import java.util.Scanner;
    
    public class Test {
    
        public static void main(String[] args){
    
            Scanner scn      = new Scanner(System.in);
            EmployeerBiz elb = new EmployeerBiz();
            EmployeerView elv = new EmployeerView();
            PorView prv       = new PorView();
            PorCfView pcv    = new PorCfView();
            PoCfView pfv      = new PoCfView();
            PoView pv        = new PoView();
    
    
            System.out.println("==========================欢迎来到大冰公司===========================");
            while(true){    
                System.out.print("
    			请输入工号:");
                int userId = scn.nextInt();
                System.out.print("			请输入密码:");
                String password = scn.next();
                String type = elb.searchPor(userId, password);
                if(type!=null){
                    char ch = type.charAt(0);
                    switch(ch){
                    case 'A':
                        System.out.println("
    经检測,你的身份是普通员工,能够进行订单申请
    ");
                        prv.porView();
                        break;
                    case 'B':
                        System.out.println("
    经检測。你的身份是部门经理,能够进行订单处理
    ");
                        pcv.showInfoView();
                        break;
                    case 'C':
                        System.out.println("
    经检測,你的身份是採购部人员,能够将批准的订单
    ");
                        pv.showInfoView();
                        break;
                    case 'D':
                        System.out.println("
    经检測,你的身份是资源管理部人员
    ");
                        pfv.showInfoView();
                        break;
                        default:
                            break;
                    }
                }else if(userId==0&&password.equals("0")){
                    System.out.println("
    经检測您是尊贵的管理员
    ");
                    elv.empView();
                }else{
                    System.out.println("你不是本公司员工!

    "); } } } }

  • 相关阅读:
    样式的使用
    样式的使用
    jqurey基础一
    jQuery三天复习.md
    webstorm快捷键大全
    计算机的进制与编码
    2016-4-29HTML标记的使用
    HTML的基本概况
    Apache Maven 入门篇 ( 上 )
    ehcache.xml 分布试缓存
  • 原文地址:https://www.cnblogs.com/llguanli/p/8728654.html
Copyright © 2020-2023  润新知