Java入门代码————菜鸟驿站

package bird;

import javax.swing.*;
import java.awt.*;
import java.time.LocalDate;
import java.util.Locale;


public class Bird {
    public static int times = 2;
    public static int times2 = 0;

    public static String[] users = new String[10];
    public static String[] pwds = new String[10];
    public static int[] level = new int[10];

    //当前用户
    public static int nowUser = -1;

    public static String[] getGoodsNum = new String[10];
    public static String[] getGoodsPeople = new String[10];
    public static String[] getGoodsTel = new String[10];
    public static String[] inTime = new String[10];
    public static String[] getTime = new String[10];
    public static String[] receivePeo = new String[10];
    public static String[] passByPeople = new String[10];

    public static void main(String[] args) {

        //初始化一个管理员一个员工
        users[0] = "ww";
        pwds[0] = "1122";
        //0为管理员1为员工
        level[0] = 0;

        users[1] = "www";
        pwds[1] = "1122";
        level[1] = 1;

        login();


    }

    //初始登陆界面
    private static void login() {
        String x = JOptionPane.showInputDialog(null, "欢迎使用菜鸟驿站系统\n1.登录系统\n2.退出系统");
        if (x.equals("1")) {
            chooseLogin();
        }
        System.exit(0);
    }

    //判断登陆界面
    public static void chooseLogin() {
        for (int j = 0; j < 3; j++) {
            String x = JOptionPane.showInputDialog(null, "输入用户名");
            String y = JOptionPane.showInputDialog(null, "输入密码");
            for (int i = 0; i < times; i++) {
                if (users[i].equals(x) && y.equals(pwds[i])) {
                    nowUser = i;
                    System.out.println(nowUser);
                    switchUser(level[i]);
                    break;
                }
            }

            if (j == 2) {
                JOptionPane.showMessageDialog(null, "输入多次信息失败,将返回初始界面");
                login();
            }
            JOptionPane.showMessageDialog(null, "没有相关信息,请重新输入");
        }
    }


    //判断登陆界面
    private static void switchUser(int i) {
        switch (i) {
            case 0:
                management();
                break;
            case 1:
                staffUser();
                break;
        }
    }


    //员工界面
    private static void staffUser() {
        String str = "欢迎使用员工管理系统\n1.入库\n2.客户取货\n3.查看未收货的订单\n4.按取货码进行查询\n5.按名字进行查询\n6.修改密码\n7.安全退出";

        while (true) {
            String x = JOptionPane.showInputDialog(null, str);
            switch (x) {
                case "1":
                    putIn();
                    break;
                case "2":
                    takeOut();
                    break;
                case "3":
                    checkUnTake();
                    break;
                case "4":
                    findById();
                    break;
                case "5":
                    findByName();
                    break;
                case "6":
                    changePassword();
                    break;
                case "7":
                    login();
                    break;
            }
        }

    }


    //根据用户姓名查找
    private static void findByName() {
        String x = "取货码  收货人  收货人电话  入库时间  取货时间  收货人  经办人\n";
        String str = JOptionPane.showInputDialog(null, "输入查询的客户姓名");
        System.out.println(times2);
        for (int f = 0; f < times2; f++) {
            if (getGoodsPeople[f].equals(str)) {
                x += getGoodsNum[f] + "  " + getGoodsPeople[f] + "  " + getGoodsTel[f] + "  " + inTime[f] + "  " + getTime[f] + "  " + receivePeo[f] + "  " + passByPeople[f] + "\n";
            }
        }
        JOptionPane.showMessageDialog(null, x);
    }


    //根据取货吗查找
    private static void findById() {
        String x = "取货码  收货人  收货人电话  入库时间  取货时间  收货人  经办人\n";
        String str = JOptionPane.showInputDialog(null, "输入查询的订单号码");
        int f = findGoods(str);
        if (f == -1) {
            JOptionPane.showMessageDialog(null, "该号码不存在");
            return;
        }
        JOptionPane.showMessageDialog(null, x + getGoodsNum[f] + "  " + getGoodsPeople[f] + "  " + getGoodsTel[f] + "  " + inTime[f] + "  " + getTime[f] + "  " + receivePeo[f] + "  " + passByPeople[f] + "\n");
    }



    //查找是否存在某货物
    private static int findGoods(String str) {
        for (int i = 0; i < times2; i++) {
            if (str.equals(getGoodsNum[i])) {
                return i;
            }
        }
        return -1;
    }


    //取出货物
    private static void takeOut() {
        String str = "取货码  收货人  收货人电话  入库时间  取货时间  收货人  经办人\n";
        String i = JOptionPane.showInputDialog(null, "输入取货号码");
        int f = findGoods(i);
        if (f == -1) {
            JOptionPane.showMessageDialog(null, "该号码不存在");
            return;
        }
        if (receivePeo[f].equals("暂无")) {
            str += getGoodsNum[f] + "  " + getGoodsPeople[f] + "  " + getGoodsTel[f] + "  " + inTime[f] + "  " + getTime[f] + "  " + receivePeo[f] + "  " + passByPeople[f] + "\n";
        }

        JOptionPane.showMessageDialog(null, str + "\n立刻取出");
        String receivePeople = JOptionPane.showInputDialog(null, "取货人签字");


        getTime[f] = LocalDate.now() + "";
        receivePeo[f] = receivePeople;
        passByPeople[f] = users[nowUser];

    }


    //检查是否取出
    private static void checkUnTake() {
        String str = "取货码  收货人  收货人电话  入库时间  取货时间  收货人  经办人\n";
        for (int i = 0; i < times2; i++) {
            if (receivePeo[i].equals("暂无")) {
                str += getGoodsNum[i] + "  " + getGoodsPeople[i] + "  " + getGoodsTel[i] + "  " + inTime[i] + "  " + getTime[i] + "  " + receivePeo[i] + "  " + passByPeople[i] + "\n";
            }
        }
        JOptionPane.showMessageDialog(null, str);
    }


    //入库新订单
    private static void putIn() {
        String str = "订单入库\n\n";
        String num = JOptionPane.showInputDialog(null, str + "请输入取货码");

        int x = findGoods(num);
        if (x != -1) {
            JOptionPane.showMessageDialog(null, "已经有此取货号码");
            return;
        }

        String people = JOptionPane.showInputDialog(null, "请输入取货人");
        String tel = JOptionPane.showInputDialog(null, "请输入取货电话");
        String inTime1 = LocalDate.now() + "";

        getGoodsNum[times2] = num;
        getGoodsPeople[times2] = people;
        getGoodsTel[times2] = tel;
        inTime[times2] = inTime1;
        getTime[times2] = "未取货";
        receivePeo[times2] = "暂无";
        passByPeople[times2] = "暂无";
        times2++;
        if (times2 == getGoodsNum.length) {
            addNewG();
        }
    }


    //扩容订单数组
    private static void addNewG() {
        String[] newGetGoodsNum = new String[times2 + 10];
        String[] newGetGoodsPeople = new String[times2 + 10];
        String[] newGetGoodsTel = new String[times2 + 10];
        String[] newInTime = new String[times2 + 10];
        String[] newGetTime = new String[times2 + 10];
        String[] newReceivePeople = new String[times2 + 10];
        String[] newPassByPeople = new String[times2 + 10];

        for (int i = 0; i < times2; i++) {
            newGetGoodsNum[i] = getGoodsNum[i];
            newGetGoodsPeople[i] = getGoodsPeople[i];
            newGetGoodsTel[i] = getGoodsTel[i];
            newInTime[i] = inTime[i];
            newGetTime[i] = getTime[i];
            newReceivePeople[i] = receivePeo[i];
            newPassByPeople[i] = passByPeople[i];
        }
        getGoodsNum = newGetGoodsNum;
        getGoodsPeople = newGetGoodsPeople;
        getGoodsTel = newGetGoodsTel;
        inTime = newInTime;
        getTime = newGetTime;
        receivePeo = newReceivePeople;
        passByPeople = newPassByPeople;
    }


    //员工管理界面
    private static void management() {
        String str = "欢迎使用员工管理系统\n\n1.查看所有员工\n2.添加员工\n3.删除员工\n4.修改密码\n5.安全退出";
        while (true) {
            String x = JOptionPane.showInputDialog(null, str);
            switch (x) {
                case "1":
                    showAllStaff();
                    break;
                case "2":
                    addNewStaff();
                    break;
                case "3":
                    deleteStaff();
                    break;
                case "4":
                    changePassword();
                    break;
                case "5":
                    login();
                    break;


            }

        }
    }


    //查找员工是否存在
    private static int findStaff(String str) {
        for (int i = 0; i < times; i++) {
            if (users[i].equals(str) && level[i] == 1) {
                return i;
            }
        }
        return -1;
    }


    //更改密码
    private static void changePassword() {
        String x = JOptionPane.showInputDialog(null, "输入你的旧密码");
        if (!x.equals(pwds[nowUser])) {
            JOptionPane.showMessageDialog(null, "旧密码输入有误,请核对后再输入");
            return;
        }
        String y = JOptionPane.showInputDialog(null, "输入你的新密码");
        String y2 = JOptionPane.showInputDialog(null, "再次输入你的新密码");
        if (!y.equals(y2)) {
            JOptionPane.showMessageDialog(null, "两次密码输入不符,请核对后再输入");
            return;
        }
        pwds[nowUser] = y;
        JOptionPane.showMessageDialog(null, "修改成功");
    }


    //删除员工
    private static void deleteStaff() {
        String str = JOptionPane.showInputDialog(null, "输入你要删除的员工");
        int x = findStaff(str);
        if (x != -1) {
            for (int j = x; j < times - 1; j++) {
                users[j] = users[j + 1];
                level[j] = level[j + 1];
                pwds[j] = pwds[j + 1];
            }
            times--;
            JOptionPane.showMessageDialog(null, "删除成功");
        } else {
            JOptionPane.showMessageDialog(null, "查无此人");
        }

    }


    //添加员工
    private static void addNewStaff() {
        String name = JOptionPane.showInputDialog(null, "输入员工姓名");
        String l = JOptionPane.showInputDialog(null, "输入员工等级");
        int lev = l.equals("管理员") ? 0 : 1;
        System.out.println(times);
        users[times] = name;
        pwds[times] = "666";
        level[times] = lev;
        times++;
        if (times == users.length) {
            addNewGroup();
        }
    }



    //添加新容量
    private static void addNewGroup() {
        String[] newPwd = new String[times + 10];
        String[] newName = new String[times + 10];
        int[] newLevel = new int[times + 10];
        for (int i = 0; i < times; i++) {
            newPwd[i] = pwds[i];
            newName[i] = users[i];
            newLevel[i] = level[i];
        }
        pwds = newPwd;
        users = newName;
        level = newLevel;

    }

    private static void showAllStaff() {
        String str = "姓名  等级\n";
        for (int i = 0; i < times; i++) {
            String str2 = level[i] == 0 ? "管理员" : "员工";
            str += users[i] + "  " + str2 + "\n";
        }
        JOptionPane.showMessageDialog(null, str);
    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值