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);
}
}
飞翔的佩奇
- 粉丝: 6124
- 资源: 1603
最新资源
- Desktop (2).zip
- 考研冲刺模拟试题50道及解析
- 11月美宝莲专卖店店内海报 店内海报完稿310mmX360mm-op.ai
- Python 中实现十大排序算法
- 基于 Java 实现的24点卡牌游戏课程设计
- 基于ssm台球俱乐部管理系统 框架html + css + jquery + jsp + java + ssm + MySQL 用户类型 管理员 admin 123456 普通用户 002 0
- 纸中世界-跳跃游戏.sb3
- 通过示例在 Python 中解释 SOLID 原则 .zip
- 11月美宝莲专卖店背柜完稿740mmX400mm
- 基于ssm台球俱乐部管理系统 框架html + css + jquery + jsp + java + ssm + MySQL
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈