package neusoft.controller;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import neusoft.model.Goods;
import neusoft.model.User;
import neusoft.util.InitData;
import neusoft.util.SysUtil;
import neusoft.util.InitData;
import neusoft.view.SysDisplay;
import neusoft.view.SysInput;
public class Purchase {
public User user;
public Map m = new HashMap();
public List typelist = new ArrayList();
public List goodslist = new ArrayList();
public Purchase() {
user = InitData.initUserData();
m = InitData.init();
typelist = (List) m.get(InitData.TYPENAME);
SysDisplay.show("欢迎使用采购系统\n请按提示操作");
}
/**
* 登录操作
*/
public void purchaseLogin() {
String userName = SysInput.readString("请输入用户名:");
String password = SysInput.readString("请输入密码:");
while (true) {
if (user.getUserName().equals(userName) && user.getPassword().equals(password)) {
break;
} else {
System.out.println("用户名或密码错误,请重新输入!");
userName = SysInput.readString("请输入用户名:");
password = SysInput.readString("请输入密码:");
}
}
SysDisplay.show("【" + user.getRealName() + "】登录成功,购物愉快!");
purchaseOperation();
}
/**
* 商品采购系统整体操作
*/
public void purchaseOperation() {
System.out.println("商品种类如下:");
for (int i = 0; i < typelist.size(); i++) {
System.out.println((i + 1) + "、" + typelist.get(i));
goodslist.add(i, (List) m.get(typelist.get(i)));
}
try {
SysDisplay.show();
int type = SysInput.readInt("请选择商品种类:") - 1;
selectGoodsType(type);
int s = SysInput.readInt("请输入商品购买序号:") - 1;
Goods buyGoods = (Goods)((List) goodslist.get(type)).get(s);
purchaseGoods(buyGoods,type);
} catch (Exception e) {
System.out.println("\n请输入正确的序号!!\n");
purchaseOperation();
}
}
/**
* 商品种类查询
* @param type商品种类
*/
public void selectGoodsType(int type) {
if (type > goodslist.size() - 1 || type < 0) {
System.out.println("\n请输入正确的序号!!\n");
purchaseOperation();
} else {
List list = new ArrayList();
list = (List) goodslist.get(type);
for (int i = 0; i < list.size(); i++) {
System.out.println("商品购买序号:" + (i + 1));
System.out.println(list.get(i));
SysDisplay.show();
}
}
}
/**
* 购买商品操作
* @param 购买的商品
* @param type 商品类性
*/
public void purchaseGoods(Goods buyGoods, int type) {
int n = SysInput.readInt("请输入购买数量:");
while (n <= 0) {
System.out.println("\n请输入大于0的整数!\n");
n = SysInput.readInt("请输入购买数量:");
}
SysDisplay.show();
System.out.println("订单号:" + SysUtil.generateOrderId());
System.out.println("购买方:" + user.getRealName());
System.out.println("商品总数量:" + n);
System.out.println("应付总价:" + SysUtil.generateCashFormat(buyGoods.price * n));
System.out.println("生成时间:" + SysUtil.generateSysDate());
System.out.println("购买商品详细信息如下:");
SysDisplay.show();
System.out.println(buyGoods);
System.out.println();
SysDisplay.show();
System.out.println();
SysDisplay.show("订单已生成,谢谢使用!再见~");
System.exit(0);
}
}
飞翔的佩奇
- 粉丝: 6170
- 资源: 1607
最新资源
- Python基于用户的协同过滤算法和项目的协同过滤算法实现的电影推荐系统源码+报告
- 永磁电机结构介绍和设计分析
- YOLO框架讲解新版PDF
- unity-shader制作绘制网格贪吃蛇
- SIMATIC S7 Distributed Safety V5.4 SP5 更新 2-链接地址.txt
- 常见功率dBm与电压v转换表
- IBM Intelligent Data Fabric数据经纬和数据虚拟化
- 易优CMS+响应式建站模板PHP+Mysql+E000570机械扫雪设备类网站模板.zip
- 互联网安全试题及答案 选择题
- ubuntu server安装PDF
- AI Agent 技术白皮书 2024.pdf
- Javascript基础-Javascript学习笔记(一)PDF
- 2024年第九届全国固态电池研讨会(脱敏)PPT合集(41份).zip
- WebSocket连接负载平衡的实现PDF
- 基于朴素贝叶斯算法解决新闻分类问题项目源码
- 基于朴素贝叶斯的文本数据的分类与分析实验项目源码+数据(高分项目)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈