ElmDemo/src/main/java/view/IndentItemView.java
2023-06-21 17:23:20 +08:00

84 lines
2.6 KiB
Java

package view;
import dao.indentItemAbstractDAO;
import dao.specification.indentDAO;
import dao.specification.indentItemDAO;
import entities.IndentItem;
import util.Toolset;
import java.util.Date;
import java.util.Scanner;
public class IndentItemView {
public void IndentItemDB(int chose) throws IllegalAccessException {
switch (chose) {
case 0 -> System.exit(0);
case 1 -> CreateIItem();
case 2 -> DeleteIItem();
case 3 -> UpdateIItem();
case 4 -> SearchIItem(true);//查询全部
case 5 -> SearchIItem(false);//查询ID
}
}
private void CreateIItem() {
indentItemAbstractDAO DML_insert = new indentItemDAO();
Scanner reader = new Scanner(System.in);
IndentItem IItem = new IndentItem();
System.out.println("请输入:菜名|初始价格|折扣|描述|菜单ID");
//菜名
IItem.setName(reader.nextLine());
//初始价格
IItem.setInitialPrice(reader.nextFloat());
//折扣
IItem.setDiscount(reader.nextFloat());
//描述
IItem.setDescription(reader.nextLine());
//菜单ID
Long indentID = reader.nextLong();
indentDAO indent = new indentDAO();
IItem.setIndentID(indent.searchID(indentID));
int flag = DML_insert.insert(IItem);
System.out.println(flag + "行受影响");
}
private void DeleteIItem() {
indentItemAbstractDAO DML_delete = new indentItemDAO();
Scanner reader = new Scanner(System.in);
IndentItem IItem = new IndentItem();
System.out.println("请输入你要删除的ID");
IItem.setId(reader.nextLong());
int flag = DML_delete.delete(IItem);
System.out.println(flag + "行受影响");
}
//TODO 更新订单菜品
private void UpdateIItem() {
indentItemAbstractDAO DML_update = new indentItemDAO();
Scanner reader = new Scanner(System.in);
IndentItem IItem = new IndentItem();
}
private void SearchIItem(boolean b) throws IllegalAccessException {
indentItemAbstractDAO DQL = new indentItemDAO();
Scanner reader = new Scanner(System.in);
IndentItem IItem = new IndentItem();
if (b) {
for (IndentItem item : DQL.search(IItem)) {
System.out.println(Toolset.table(IndentItem.class, item));
}
} else {
System.out.println("请输入你要查询的ID:");
IItem = DQL.searchID(reader.nextLong());
System.out.println(Toolset.table(IndentItem.class, IItem));
}
}
}