package demo3;
import java.util.ArrayList;
import java.util.Objects;
import java.util.Scanner;
public class WarehouseManagement {
public static void main(String[] args) {
ArrayList<WarehouseInformation> list = new ArrayList<>();
boolean key = true;
while (key) {
System.out.println("**********************************************************");
System.out.println("石家庄铁道大学前进22软件开发有限公司");
System.out.println("仓库管理系统2022版");
System.out.println("**********************************************************");
System.out.println("1、商品入库管理");
System.out.println("2、商品信息修改");
System.out.println("3、商品出库管理");
System.out.println("4、仓库盘点管理");
System.out.println("**********************************************************");
Scanner sc = new Scanner(System.in);
System.out.println("请输入数字");
int m = sc.nextInt();
switch (m)
{
case 1:
goodsManage(list);break;
case 2:
goodsModify(list);break;
case 3:
goodsOutbound(list);break;
case 4:
goodsOutput(list);break;
}
}
}
public static void goodsManage(ArrayList<WarehouseInformation> list) {
WarehouseInformation w1= new WarehouseInformation();
Scanner s=new Scanner(System.in);
while(true) {
System.out.println("请输入商品编号");
String n1=s.next();
boolean b1=num(n1);
if(b1){
w1.setItemnumnow(n1);
break;
}else{
System.out.println("输入错误请从新输入");
continue;
}
}
System.out.println("请输入商品名称");
String n2=s.next();
w1.setItemname(n2);
System.out.println("请输入供货商信息");
String n3=s.next();
w1.setSuppliername(n3);
while(true) {
System.out.println("请输入入库时间");
String n4 = s.next();
boolean b4=num(n4);
if(b4){
w1.setWarehousingtime(n4);
break;
}else{
System.out.println("输入错误请从新输入");
continue;
}
}
while(true) {
System.out.println("请输入存放仓库号");
String n5=s.next();
boolean b5=num(n5);
if(b5){
w1.setWarehousenumber(n5);
break;
}else{
System.out.println("输入错误请从新输入");
continue;
}
}
while(true) {
System.out.println("请输入存放位置信息");
String n6=s.next();
boolean b6=num(n6);
if(b6){
w1.setWarehouseplace(n6);
break;
}else{
System.out.println("输入错误请从新输入");
continue;
}
}
System.out.println("请输入商品数量");
int n7=s.nextInt();
w1.setItemnumber(n7);
Print1(w1);
System.out.println("该商品入库操作已完成,是否提交(Y/N)");
System.out.println("**********************************************************");
System.out.println("请输入Y或N");
String k=s.next();
if(Objects.equals(k, "Y")){
list.add(w1);
}else{
return;
}
}
public static void goodsModify(ArrayList<WarehouseInformation>list) {
while(true) {
Scanner c = new Scanner(System.in);
System.out.println("***********************************************************");
System.out.println("石家庄铁道大学前进22软件开发有限公司");
System.out.println("仓库管理系统2022版");
System.out.println("**********************************************************");
System.out.println("请输入商品编号:");
String now = c.next();
int count = Ergodic(list, now);
if (count < 0) {
System.out.println("查询不到此商品信息");
continue;
}
WarehouseInformation m=list.get(count);
Print2(m);
System.out.println("请选择需要修改的信息编号(1-7):");
int n=c.nextInt();
switch (n){
case 1:
System.out.println("请输入修改后的商品编号:");
String h1=c.next();
m.setItemnumnow(h1);
break;
case 2:
System.out.println("请输入修改后的商品名称:");
String h2=c.next();
m.setItemname(h2);
break;
case 3:
System.out.println("请输入修改后的供货商名字:");
String h3=c.next();
m.setSuppliername(h3);
break;
case 4:
System.out.println("请输入修改后的入库时间");
String h4=c.next();
m.setWarehousingtime(h4);
break;
case 5:
System.out.println("请输入修改后的存放仓库号");
String h5=c.next();
m.setWarehousenumber(h5);
break;
case 6:
System.out.println("请输入修改后的仓库位置");
String h6=c.next();
m.setWarehouseplace(h6);
break;
case 7:
System.out.println("请输入修改后的商品数量");
int h7=c.nextInt();
m.setItemnumber(h7);
break;
default:
throw new IllegalStateException("输入错误: " + n);
}
System.out.println("**********************************************************");
System.out.println("请输入Y保存信息,N不保存");
String key1=c.next();
if(key1.equals("Y")){
list.remove(count);
list.add(m);
System.out.println("数据修改成功");
break;
}else{
break;
}
}
}
public static void goodsOutbound(ArrayList<WarehouseInformation>list){
Scanner l=new Scanner(System.in);
while(true){
System.out.println("***********************************************************");
System.out.println("石家庄铁道大学前进22软件开发有限公司");
System.out.println("仓库管理系统2022版");
System.out.println("***********************************************************");
System.out.print("请输入商品编号:");
String k=l.next();
int p= Ergodic(list,k);
System.out.println("**********************************************************");
if(p<0){
System.out.println("输入错误,请从新输入");
continue;
}
WarehouseInformation kk=list.get(p);
Print1(kk);
System.out.print("出库时间:");
int chu=l.nextInt();
System.out.print("出库数量:");
int shu=l.nextInt();
kk.setOutnumber(shu);
int m=kk.getItemnumber()-shu;
if(m<0){
System.out.println("出库失败");
}else{
System.out.println("请输入Y保存信息,N不修改");
String key1=l.next();
if(key1.equals("Y")){
list.remove(p);
list.add(kk);
break;
}else if(key1.equals("N"))
{
break;
}
}
}
}
public static void goodsOutput(ArrayList<WarehouseInformation>list){
System.out.println("***********************************************************");
System.out.println("石家庄铁道大学前进22软件开发有限公司");
System.out.println("仓库管理系统2022版");
System.out.println("***********************************************************");
for(int i=0;i< list.size();i++){
WarehouseInformation w=list.get(i);
int n1=w.getItemnumber();
int n2=w.getOutnumber();
int number=n1-n2;
System.out.println("1. 商品编号:"+w.getItemnumnow()+"、商品名称:"+w.getItemname()+"、库存数量:"+number);
}
System.out.println("**********************************************************");
}
public static void Print1(WarehouseInformation w2){
System.out.println("*");
System.out.println("石家庄铁道大学前进22软件开发有限公司");
System.out.println("仓库管理系统2022版");
System.out.println("**********************************************************");
System.out.println("商品编号:"+w2.getItemnumnow());
System.out.println("商品名称:"+w2.getItemname());
System.out.println("供货商信息:"+w2.getSuppliername());
System.out.println("入库时间:"+w2.getWarehousingtime());
System.out.println("存放仓库号:"+w2.getWarehousenumber());
System.out.println("存放位置信息:"+w2.getWarehouseplace());
System.out.println("入库商品数量:"+w2.getItemnumber());
}
public static void Print2(WarehouseInformation w2){
System.out.println("*");
System.out.println("石家庄铁道大学前进22软件开发有限公司");
System.out.println("仓库管理系统2022版");
System.out.println("**********************************************************");
System.out.println("1.商品编号:"+w2.getItemnumnow());
System.out.println("2.商品名称:"+w2.getItemname());
System.out.println("3.供货商信息:"+w2.getSuppliername());
System.out.println("4.入库时间:"+w2.getWarehousingtime());
System.out.println("5.存放仓库号:"+w2.getWarehousenumber());
System.out.println("6.存放位置信息:"+w2.getWarehouseplace());
System.out.println("7.入库商品数量:"+w2.getItemnumber());
}
public static boolean num(String m){
for(int i=0;i<m.length();i++)
{
char a=m.charAt(i);
if(a<'0'||a>'9'){
return false;
}
}
return true;
}
public static int Ergodic(ArrayList<WarehouseInformation>list, String m){
for(int i=0;i<list.size();i++)
{
WarehouseInformation ww=list.get(i);
if(m.equals(ww.getItemnumnow())){
return i;
}
}
return -1;
}
}