83 lines
2.5 KiB
Java
83 lines
2.5 KiB
Java
![]() |
package view;
|
|||
|
|
|||
|
import dao.indentAbstractDAO;
|
|||
|
import dao.specification.indentDAO;
|
|||
|
import dao.specification.merchantsDAO;
|
|||
|
import dao.specification.userDAO;
|
|||
|
import entities.Indent;
|
|||
|
import entities.IndentItem;
|
|||
|
import entities.Users;
|
|||
|
import util.Toolset;
|
|||
|
|
|||
|
import java.util.Scanner;
|
|||
|
|
|||
|
public class IndentView {
|
|||
|
public void IndentDB(int chose) throws IllegalAccessException {
|
|||
|
|
|||
|
|
|||
|
//TODO 这个交互有点难搞
|
|||
|
switch (chose) {
|
|||
|
case 0 -> System.exit(0);
|
|||
|
case 1 -> CreateIndent();
|
|||
|
case 2 -> DeleteIndent();
|
|||
|
case 3 -> UpdateIndent();
|
|||
|
case 4 -> SearchIndent(true);//查询全部
|
|||
|
case 5 -> SearchIndent(false);//按ID查询
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void CreateIndent() {
|
|||
|
indentAbstractDAO DML_insert = new indentDAO();
|
|||
|
Scanner reader = new Scanner(System.in);
|
|||
|
Indent indent = new Indent();
|
|||
|
System.out.println("请输入:下单用户id|餐厅id|总价|备注");
|
|||
|
//用户
|
|||
|
Long userID = reader.nextLong();
|
|||
|
userDAO user = new userDAO();
|
|||
|
indent.setUserID(user.searchID(userID));
|
|||
|
//餐厅
|
|||
|
Long merchantID = reader.nextLong();
|
|||
|
merchantsDAO merchant = new merchantsDAO();
|
|||
|
indent.setMerchantsID(merchant.searchID(merchantID));
|
|||
|
//总价
|
|||
|
indent.setAllPrice(reader.nextFloat());
|
|||
|
//备注
|
|||
|
indent.setMessage(reader.nextLine());
|
|||
|
|
|||
|
int flag = DML_insert.insert(indent);
|
|||
|
System.out.println(flag + "行受影响");
|
|||
|
}
|
|||
|
|
|||
|
private void DeleteIndent() {
|
|||
|
indentAbstractDAO DML_delete = new indentDAO();
|
|||
|
Scanner reader = new Scanner(System.in);
|
|||
|
Indent indent = new Indent();
|
|||
|
|
|||
|
System.out.println("请输入你要删除的ID");
|
|||
|
indent.setId(reader.nextLong());
|
|||
|
|
|||
|
int flag = DML_delete.delete(indent);
|
|||
|
System.out.println(flag + "行受影响");
|
|||
|
}
|
|||
|
|
|||
|
//TODO 更新订单
|
|||
|
private void UpdateIndent() {
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private void SearchIndent(boolean b) throws IllegalAccessException {
|
|||
|
Indent indent = new Indent();
|
|||
|
indentAbstractDAO DQL = new indentDAO();
|
|||
|
Scanner reader = new Scanner(System.in);
|
|||
|
if (b) {//b 为 true 查询全部
|
|||
|
for (Indent item : DQL.search(indent)) {
|
|||
|
System.out.println(Toolset.table(Indent.class, item));
|
|||
|
}
|
|||
|
} else {
|
|||
|
System.out.println("请输入你要查询的ID:");
|
|||
|
indent = DQL.searchID(reader.nextLong());
|
|||
|
System.out.println(Toolset.table(Indent.class, indent));
|
|||
|
}
|
|||
|
}
|
|||
|
}
|