commit 69cc12f92042d84ba8e660367e65672c071d1f84 Author: JRNitre Date: Thu Dec 19 17:47:38 2024 +0800 2024-12-19 初始化仓库 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..359bb53 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..a55e7a1 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..0d9ee09 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..a1f07cd --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/.idea/libraries/mysql_connector_j_8_4_0.xml b/.idea/libraries/mysql_connector_j_8_4_0.xml new file mode 100644 index 0000000..ef93e85 --- /dev/null +++ b/.idea/libraries/mysql_connector_j_8_4_0.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..07115cd --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..432e247 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CourseExperiment.iml b/CourseExperiment.iml new file mode 100644 index 0000000..b2f27ce --- /dev/null +++ b/CourseExperiment.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/lib/mysql-connector-j-8.4.0.jar b/lib/mysql-connector-j-8.4.0.jar new file mode 100644 index 0000000..8294fe0 Binary files /dev/null and b/lib/mysql-connector-j-8.4.0.jar differ diff --git a/src/ElmAdminEntry.java b/src/ElmAdminEntry.java new file mode 100644 index 0000000..f137490 --- /dev/null +++ b/src/ElmAdminEntry.java @@ -0,0 +1,104 @@ +/* + * Date: 2024-06-18 + * Design By JRNitre + * */ + +import View.AdminView; +import View.Display; +import po.Admin; + +public class ElmAdminEntry { + public static void main(String[] args){ + new ElmAdminEntry().work(); + } + + // CodeLineNum 2600 + + private static final int exitCode = 10; + + public void work(){ + Display dis = new Display('+', '-', 30); + AdminView adv = new AdminView(); + +// Admin admin = new Admin(); +// admin.setAdminName("jrnitre"); +// admin.setAdminId(1); +// admin.setAdminPassword("1234"); + + // ʵԱ, õ¼ʼ + Admin admin = new AdminView().login(); + + if (admin != null){ + int key; + while (true){ + dis.titleLine("Admin - " + admin.getAdminName(), true); + dis.showItem("[0] ̼б", true); + dis.showItem("[1] ̼", true); + dis.showItem("[2] ½̼", true); + dis.showItem("[3] ɾ̼", true); + dis.showItem("[4] 鿴ԱϢ", true); + dis.showItem("[5] ùԱ", true); + dis.showItem("[6] 鿴Աб (DEBUG)", true); + dis.showItem("[7] 鿴ʳƷб (DEBUG)", true); + dis.showItem("[" + exitCode + "] ˳ϵͳ", true); + dis.showLine(true); + + // ȡ + key = dis.getKeyNumber(); + + // жû + switch (key){ + // ̼б + case 0: + adv.printAllBusinessInfo(); + break; + // ̼ + case 1: + adv.searchBusiness(); + break; + // ½̼ + case 2: + adv.adminAddBusiness(); + break; + // ɾ̼ + case 3: + adv.deleteBusiness(); + break; + // ʾԱϢ + case 4: + adv.printAdminInfo(admin); + break; + // ùԱ + case 5: + adv.updatePassword(admin); + break; + // 鿴Աб + case 6: + adv.printAllAdminInfo(); + break; + // 鿴ʳƷб + case 7: + adv.printAdminAllFoodInfo(); + break; + // Exit system + case exitCode: + if (dis.MessageYesOrNo("ʾ", "Ƿȷ˳ϵͳ?")) { + dis.titleLine("ʾ", true); + System.out.println("+ ϵͳ˳"); + System.exit(0); + } + break; + // :-) + default: + dis.titleLine("ERROR", true); + System.out.println("+ Ϸ!"); + break; + } + } + } else { + dis.titleLine("ERROR", true); + System.out.println("+ ! ˳ϵͳ"); + System.exit(0); + } + } +} \ No newline at end of file diff --git a/src/ElmBusinessEntry.java b/src/ElmBusinessEntry.java new file mode 100644 index 0000000..cd62849 --- /dev/null +++ b/src/ElmBusinessEntry.java @@ -0,0 +1,130 @@ +/* + * Date: 2024-06-18 + * Design By JRNitre + * */ + +import View.Display; +import View.BusinessView; + +import po.Business; + +public class ElmBusinessEntry { + public static void main (String[] args){ + new ElmBusinessEntry().work(); + } + + private static final int exitCode = 10; + + public void work(){ + + Display dis = new Display('+', '-', 30); + BusinessView buv = new BusinessView(); + + // Login ¼ϵͳ + Business business = new BusinessView().login(); + +// Business business = new Business(); +// business.setBusinessPassword("1234"); +// business.setBusinessName("business"); +// business.setBusinessId(1); +// business.setBusinessAddress("null"); +// business.setBusinessExplain("null"); +// business.setBusinessStarPrice(5); +// business.setBusinessDeliveryPrice(1.5); + + if (business != null){ + int key; + while (true){ + dis.titleLine("Business - " + dis.deleteSpaceToString(business.getBusinessName()), true); + dis.showItem("[0] 鿴̼Ϣ", true); + dis.showItem("[1] ޸̼Ϣ", true); + dis.showItem("[2] ޸̼", true); + dis.showItem("[3] ʳƷϢ", true); + dis.showItem("[" + exitCode + "] ˳ϵͳ", true); + dis.showLine(true); + + key = dis.getKeyNumber(); + + switch (key){ + // 鿴̼Ϣ + case 0: + buv.printBusinessInfo(business); + break; + // ޸̼Ϣ + case 1: + buv.updateBusinessInfo(business); + break; + // ޸̼ + case 2: + buv.updatePassword(business); + break; + // ʳƷϢ + case 3: + food_work(business); + break; + case exitCode: + if (dis.MessageYesOrNo("ʾ", "Ƿȷ˳ϵͳ?")) { + dis.titleLine("ʾ", true); + System.out.println("+ ϵͳ˳"); + System.exit(0); + } + break; + default: + dis.titleLine("ERROR", true); + System.out.println("+ Ϸ!"); + break; + } + + } + } else { + dis.titleLine("ERROR", true); + System.out.println("+ ! ˳ϵͳ"); + System.exit(0); + } + } + + public void food_work(Business business){ + Display dis = new Display('+', '-', 30); + BusinessView buv = new BusinessView(); + + int key; + while (true){ + dis.titleLine("̼ʳƷ", true); + dis.showItem("[0] 鿴ʳƷб", true); + dis.showItem("[1] ʳƷ", true); + dis.showItem("[2] ޸ʳƷϢ", true); + dis.showItem("[3] ɾʳƷ", true); + dis.showItem("[" + exitCode + "] ϼ˵", true); + + key = dis.getKeyNumber(); + + switch ( key ){ + // 鿴ʳƷб + case 0: + buv.printAllBusinessFoodInfo(business); + break; + // ʳƷ + case 1: + buv.addBusinessNewFood(business); + break; + // ޸ʳƷϢ + case 2: + buv.updateBusinessFoodInfo(business); + break; + // ɾʳƷ + case 3: + buv.deleteFood(business); + break; + case exitCode: + if (dis.MessageYesOrNo("ʾ", "ȷϼ˵?")) { + return; + } + break; + default: + dis.titleLine("ERROR", true); + System.out.println("+ Ϸ!"); + break; + } + } + } +} \ No newline at end of file diff --git a/src/View/AdminView.java b/src/View/AdminView.java new file mode 100644 index 0000000..f88a0a4 --- /dev/null +++ b/src/View/AdminView.java @@ -0,0 +1,558 @@ +/* +* Date: 2024-06-18 +* Design By JRNitre +* */ + +package View; + +import dao.AdminDaoImpl; +import dao.BusinessDaoImpl; + +import po.Admin; +import po.Business; + +import java.sql.ResultSet; + +import java.util.Objects; +import java.util.Scanner; +import java.util.regex.Pattern; + +public class AdminView { + Display dis = new Display('+', '-', 30); + + /** + * Ա¼ + * ͨ Scanner ӱ׼ȡԱûID룬Խе¼ + * ԱûIDƥɹ򷵻ضӦĹԱ󣻷ԱԶε¼ֱԴþ + * + * @return ɹ¼ʱعԱ󣬷򷵻 null + */ + public Admin login(){ + Scanner sca = new Scanner(System.in); + + // ǰ + int mistake = 0; + // ûԵ + int maxMistake = 3; + // ¼״̬ + int loginCode; + + Admin admin = null; + + while (mistake < maxMistake){ + dis.titleLine("¼ [ô] Ա̨", true); + + // 1 û + if (mistake != 0){ + System.out.println("+ " + mistake + " ʣɳԴ " + (maxMistake - mistake) + " "); + } + + // String ʽû Id + String inputAdminNameOrId; + // ¼ Id ֵ -1 + int inputAdminId = -1; + System.out.print("+ ˻&Id: "); + inputAdminNameOrId = sca.nextLine(); + + // жûַǴ + // ֱòͬķִе¼ + try{ + inputAdminId = Integer.parseInt(inputAdminNameOrId); + loginCode = 0; + } catch (NumberFormatException e){ + loginCode = 1; + } + + // ȡû + String inputAdminPassword; + System.out.print("+ : "); + inputAdminPassword = sca.nextLine(); + + System.out.println("+ ¼ϵͳ..."); + + if (loginCode == 0){ + admin = new AdminDaoImpl().getAdminByIdByPass(inputAdminId, inputAdminPassword); + } + if (loginCode == 1){ + admin = new AdminDaoImpl().getAdminByNameByPass(inputAdminNameOrId, inputAdminPassword); + } + + if (admin != null){ + return admin; + } else { + mistake++; + } + } + return null; + } + + /** + * ¹Ա롣 + * ÷ṩһʽĽ棬ڹԱ֤ǰ벢롣 + * ȷȷԺͰȫԣΪ10ַ + * + * @param admin Ա󣬰ǰԱϢ + */ + public void updatePassword(Admin admin){ + // ʱԱոڼû + Admin tempAdmin = new Admin(admin); + dis.titleLine("", true); + + while (true){ + // ûԭ + Scanner sca = new Scanner(System.in); + String afterAdminPassword; + System.out.print("+ ԭ: "); + afterAdminPassword = sca.nextLine(); + + // ж¾Ƿ + if (afterAdminPassword.equals(tempAdmin.getAdminPassword())){ + System.out.println("+ ȷ"); + + while (true){ + String newAdminPassword; + + // ȷû + while (true){ + String againNewAdminPassword; + System.out.print("+ (10ַ): "); + newAdminPassword = sca.nextLine(); + System.out.print("+ ٴ (10ַ): "); + againNewAdminPassword = sca.nextLine(); + + if (newAdminPassword.equals(againNewAdminPassword)){ + break; + } + + System.out.println("+ ǰ벻һ"); + } + + // ж볤, С 10 + if (newAdminPassword.length() <= 10){ + System.out.println("+ ..."); + // û洢ʱ + tempAdmin.setAdminPassword(newAdminPassword); + + // ݿ + if (new AdminDaoImpl().updateAdminPassword(admin)){ + // ʱе븳ֵû + admin.setAdminPassword(tempAdmin.getAdminPassword()); + System.out.println("+ ³ɹ!"); + } else { + System.out.println("+ ʧ!"); + } + break; + } + System.out.println("+ !"); + } + dis.titleLine("˵", true); + sca.nextLine(); + return; + } else { + System.out.println("+ "); + System.out.print("+ [y] : "); + String exitKey = sca.next(); + if (!Objects.equals(exitKey, "y") && !Objects.equals(exitKey, "Y")){ + return; + } + } + } + } + + /** + * Ա̼ҹܡ + * ÷̨̼ͨϢ̼ID̼ơ̼롢̼ҵַ̼ҽܡͷѺͷѡ + * Ϣ֤󣬽̼ϢӵϵͳС + */ + public void adminAddBusiness(){ + Business business = new Business(); + Display dis = new Display('+', '-', 30); + + dis.titleLine("̼", true); + + // ̼ Id + while(true){ + String inputBusinessId; + Scanner sca = new Scanner(System.in); + + System.out.print("+ ̼λ ID: "); + inputBusinessId = sca.nextLine(); + + // ʽжǷΪλ + if (Pattern.matches("^\\d{4}$", inputBusinessId)) { + int businessId = Integer.parseInt(inputBusinessId); + business.setBusinessId(businessId); + break; + } else { + if (!inputBusinessId.matches("\\d+")){ + System.out.println("+ ַ!"); + } + System.out.println("+ ̼ ID λȷ!"); + } + } + + // ̼ + while (true){ + String inputBusinessName; + int maxDataLength = 10; + System.out.print("+ ̼ (" + maxDataLength + "ַ): "); + + inputBusinessName = dis.getStandString(maxDataLength); + + if (inputBusinessName != null){ + business.setBusinessName(dis.appendSpaceToString(inputBusinessName, maxDataLength)); + break; + } + System.out.println("+ ̼Ϸ!"); + } + + // ̼ + while (true){ + String inputBusinessPassword; + int maxDataLength = 10; + System.out.print("+ ̼ (" + maxDataLength + "ַ): "); + + inputBusinessPassword = dis.getStandString(maxDataLength); + + if (inputBusinessPassword != null){ + business.setBusinessPassword(inputBusinessPassword); + break; + } + System.out.println("+ 벻Ϸ!"); + } + + // ̼ҵַ + while (true){ + String inputBusinessAddress; + int maxDataLength = 20; + System.out.print("+ ̼ҵַ (" + maxDataLength + "ַ): "); + + inputBusinessAddress = dis.getStandString(maxDataLength); + + if (inputBusinessAddress != null){ + business.setBusinessAddress(inputBusinessAddress); + break; + } + System.out.println("+ ̼ҵַϷ!"); + } + + // ̼ҽ + while (true){ + String inputBusinessExplain; + int maxDataLength = 25; + System.out.print("+ ̼ҽ (" + maxDataLength + "ַ): "); + + inputBusinessExplain = dis.getStandString(maxDataLength); + + if (inputBusinessExplain != null){ + business.setBusinessExplain(inputBusinessExplain); + break; + } + System.out.println("+ ̼ҽܲϷ!"); + } + + // ͷ + while (true){ + double inputBusinessStartPrice; + Scanner sca = new Scanner(System.in); + System.out.print("+ ͷ: "); + if (!sca.hasNextDouble()){ + System.out.println("+ һЧ"); + sca.next(); + } else { + inputBusinessStartPrice = sca.nextDouble(); + if (inputBusinessStartPrice > 0 && inputBusinessStartPrice <= 50){ + business.setBusinessStarPrice(inputBusinessStartPrice); + break; + } else { + System.out.println("+ ݷΧ (0 ~ 50)"); + } + } + } + + // ͷ + while (true){ + double inputBusinessDeliveryPrice; + Scanner sca = new Scanner(System.in); + System.out.print("+ ͷ: "); + if (!sca.hasNextDouble()){ + System.out.println("+ һЧ"); + sca.next(); + } else { + inputBusinessDeliveryPrice = sca.nextDouble(); + if (inputBusinessDeliveryPrice > 0 && inputBusinessDeliveryPrice <= 50){ + business.setBusinessDeliveryPrice(inputBusinessDeliveryPrice); + break; + } else { + System.out.println("+ ݷΧ (0 ~ 50)"); + } + } + } + + System.out.println("+ ! ̻..."); + + if (new BusinessDaoImpl().addNewBusiness(business)){ + System.out.println("+ ӳɹ!"); + } else { + System.out.println("+ ʧ!"); + } + + dis.pressEnterToContinue(); + } + + /** + * ӡҵϢ + * ResultSetȡҵϢԸʽķʽӡ + * ÿҵϢҵIDҵơ롢ҵַҵ˵Ǽ۸ͼ۸ + * ҵIDʹλָʽ + * + * @param rs ResultSet󣬰ҵϢݡ + * @return ӡҵϢ + */ + public int printInputBusinessInfo(ResultSet rs) { + // û¼˶Ϣ + int i = 0; + try { + while (rs.next()){ + StringBuilder str = new StringBuilder(); + str.append("| "); + + String formattedNumber = String.format("%04d", rs.getInt("businessId")); + str.append(formattedNumber); + + str.append("\t| "); + str.append(rs.getString("businessName")); + str.append("\t| "); + str.append(rs.getString("password")); + str.append("\t| "); + str.append(rs.getString("businessAddress")); + str.append("\t| "); + str.append(rs.getString("businessExplain")); + str.append("\t| "); + str.append(rs.getDouble("starPrice")); + str.append("\t| "); + str.append(rs.getDouble("deliveryPrice")); + str.append("\t|"); + + System.out.println(str); + i++; + } + } catch (Exception e) { + e.printStackTrace(); + } + return i; + } + + /** + * ӡԱϢ + * ResultSetȡԱIDƺ룬Ըʽʽӡ + * + * @param rs ResultSet󣬰ԱϢݡ + * @return ӡĹԱ + */ + public int printAdminInfo(ResultSet rs) { + int i = 0; + try { + while (rs.next()){ + StringBuilder str = new StringBuilder(); + str.append("| "); + str.append(rs.getInt("adminId")); + str.append("\t| "); + str.append(rs.getString("adminName")); + str.append("\t| "); + str.append(rs.getString("adminPassword")); + str.append("\t|"); + + String finalString = str.toString(); + System.out.println(finalString); + i++; + } + } catch (Exception e) { + e.printStackTrace(); + } + return i; + } + + /** + * ӡйԱϢ + * ˷ȴӡһУȻйԱϢӡʾԱ + * ʹStringBuilderַԼResultSetݿȡĹԱݡ + * ڻȡӡݵĹз쳣ӡ쳣ջ١ + */ + public void printAllAdminInfo(){ + dis.titleLine("ԱϢ", true); + + System.out.println("| ԱID\t| Ա\t| Ա\t|"); + + try { + // ӡ + ResultSet rs = new AdminDaoImpl().getAllAdmin(); + + int num; + + num = this.printAdminInfo(rs); + + System.out.println("+ [" + num + "] Ŀ"); + } catch (Exception e){ + e.printStackTrace(); + } + } + + /** + * ӡԱϢҪûȷϡ + * ÷ԸʽķʽʾԱϸϢIDƺ롣 + * ϢʾҪûȷϣͨɨʵ֡ + * + * @param admin Ա󣬰ҪӡϢ + */ + public void printAdminInfo(Admin admin){ + dis.titleLine("Ա [" + admin.getAdminName() + "]" + " Ϣ", true); + System.out.println("+ Ա ID: " + admin.getAdminId()); + System.out.println("+ Ա : " + admin.getAdminName()); + System.out.println("+ Ա: " + admin.getAdminPassword()); + dis.showLine(true); + Scanner sca = new Scanner(System.in); + sca.nextLine(); + } + + /** + * ӡ̼Ϣ + * ˷ڲѯչʾϵͳе̼Ϣ̼ҵĻϢ + * ʹResultSetѯͨprintInputBusinessInfoӡ̼Ϣ + * 󣬴ӡ̼ҵ + */ + public void printAllBusinessInfo(){ + int num; + + dis.titleLine("̼Ϣ", true); + dis.printInfoTitle(); + + try { + ResultSet rs = new BusinessDaoImpl().printAllBusiness(); + num = this.printInputBusinessInfo(rs); + System.out.println("+ ϼ̼Ŀ [" + num + "]"); + } catch (Exception e){ + e.printStackTrace(); + } + } + + // ̼ + // TODO ߼Ҫ + // TODO ѡĿ + public void searchBusiness(){ + Scanner sca = new Scanner(System.in); + + int key; + // ڽִϺ󷵻ص + ResultSet rs; + + while ( true ) { + dis.titleLine("̼", true); + dis.showItem("[0] ̼ѯ", true); + dis.showLine(true); + + key = dis.getKeyNumber(); + + switch (key){ + case 0: + dis.titleLine("̼ѯ", true); + System.out.print("+ Ҫѯ̼: "); + String businessName = sca.next(); + + try { + System.out.println("+ ѯ..."); + rs = new AdminDaoImpl().fuzzyQueryExampleForName(businessName); + // жǷΪ + if (rs == null){ + dis.titleLine("Error", true); + System.out.println("+ δѯй!"); + return; + } + + dis.printInfoTitle(); + int num; + num = this.printInputBusinessInfo(rs); + + System.out.println("+ ѯ " + num + ""); + } catch (Exception e){ + e.printStackTrace(); + } + + return; + default: + dis.titleLine("ERROR", true); + System.out.println("+ Ϸ!"); + break; + } + } + } + + /** + * ɾ̼ҹܵʵ֡ + * ͨû̼IDƣݿɾӦ̼Ϣ + * ȳԽûΪΪ̼IDɾ + * ʧܣΪû̼ƣͨƽɾ + */ + public void deleteBusiness(){ + Scanner sca = new Scanner(System.in); + + dis.titleLine("ɾ̼", true); + System.out.print("+ Ҫɾ̼ҵ Id : "); + String uin = sca.nextLine(); + + try{ + int uinToNumber = Integer.parseInt(uin); + System.out.println("+ ѯɾ Id Ϊ: " + uin + " ̼..."); + new BusinessDaoImpl().deleteId(uinToNumber); + } catch (NumberFormatException e){ + System.out.println("+ ѯɾΪ: " + uin + " ̼..."); + new BusinessDaoImpl().deleteName(uin); + } + } + + /** + * ӡʳƷϢ + * ÷ڹԱ棬չʾݿʳƷϸϢ + * ͨѯݿȡʳƷϢӡЩϢ + */ + public void printAdminAllFoodInfo(){ + int num = 0; + dis.titleLine("ʳƷб", true); + + try { + System.out.println("+ ѯ..."); + ResultSet rs = new BusinessDaoImpl().getAllFoodInfo(); + // жǷΪ + if (rs == null){ + dis.titleLine("Error", true); + System.out.println("+ δѯй!"); + return; + } + + while ( rs.next() ){ + StringBuilder str = new StringBuilder(); + + str.append("| "); + str.append(rs.getString("foodId")); + str.append("\t| "); + str.append(rs.getString("foodName")); + str.append("\t| "); + str.append(rs.getString("foodExplain")); + str.append("\t| "); + str.append(rs.getDouble("foodPrice")); + str.append("\t| "); + str.append(rs.getInt("businessId")); + str.append("\t|"); + + String finalString = str.toString(); + System.out.println(finalString); + num++; + } + + System.out.println("+ ѯ " + num + " "); + + } catch (Exception e){ + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/src/View/BusinessView.java b/src/View/BusinessView.java new file mode 100644 index 0000000..064938f --- /dev/null +++ b/src/View/BusinessView.java @@ -0,0 +1,616 @@ +/* + * Date: 2024-06-18 + * Design By JRNitre + * */ + +package View; + +import dao.BusinessDaoImpl; +import po.Business; +import po.Food; + +import java.sql.ResultSet; +import java.util.Objects; +import java.util.Scanner; +import java.util.regex.Pattern; + +public class BusinessView { + Display dis = new Display('+', '-', 30); + + /** + * ̻¼ + * ͨ Scanner ӱ׼ȡ̻ûID룬Խе¼ + * ̻ûIDƥɹ򷵻ضӦ̻󣻷̻Զε¼ֱԴþ + * + * @return ɹ¼ʱ̻󣬷򷵻 null + */ + public Business login () { + Scanner sca = new Scanner(System.in); + + // ǰ + int mistake = 0; + // ûԵ + int maxMistake = 3; + + int loginCode; + + Business business = null; + + while ( mistake < maxMistake ) { + + dis.titleLine("¼ [ô] ̼Һ̨", true); + + // 1 û + if ( mistake != 0 ) { + System.out.println("+ " + mistake + " ʣɳԴ " + (maxMistake - mistake) + " "); + } + + String inputBusinessNameOrId; + int inputBusinessId = - 1; + System.out.print("+ ˻&Id: "); + inputBusinessNameOrId = sca.nextLine(); + + try { + inputBusinessId = Integer.parseInt(inputBusinessNameOrId); + loginCode = 0; + } catch ( NumberFormatException e ) { + loginCode = 1; + } + + String inputBusinessPassword; + System.out.print("+ : "); + inputBusinessPassword = sca.nextLine(); + + System.out.println("+ ¼ϵͳ..."); + + if ( loginCode == 0 ) { + business = new BusinessDaoImpl().getBusinessByIdByPass(inputBusinessId, inputBusinessPassword); + } + if ( loginCode == 1 ) { + business = new BusinessDaoImpl().getBusinessByNameByPass(inputBusinessNameOrId, inputBusinessPassword); + } + + if ( business != null ) { + return business; + } else { + mistake++; + } + } + return null; + } + + /** + * ӡ̼Ϣ + * ÷ϸӡ̼ҵĸϢIDơ롢ܡַͷѺͷѡ + * ּΪ̼ҹṩӻϢչʾû鿴͹̼顣 + * + * @param business ̼Ҷ󣬰Ҫӡ̼Ϣ + */ + public void printBusinessInfo (Business business) { + String businessName = dis.deleteSpaceToString(business.getBusinessName()); + String businessPassword = dis.deleteSpaceToString(business.getBusinessPassword()); + String businessExplain = dis.deleteSpaceToString(business.getBusinessExplain()); + String businessAddress = dis.deleteSpaceToString(business.getBusinessAddress()); + + dis.titleLine("̼ [" + businessName + "]" + " Ϣ", true); + + String formattedNumber = String.format("%04d", business.getBusinessId()); + System.out.println("+ ̼ ID: " + formattedNumber); + + System.out.println("+ ̼ :" + businessName); + System.out.println("+ ̼:" + businessPassword); + System.out.println("+ ̼ҽ:" + businessExplain); + System.out.println("+ ̼ҵַ:" + businessAddress); + System.out.println("+ ͷ: " + business.getBusinessStarPrice()); + System.out.println("+ ͷ: " + business.getBusinessDeliveryPrice()); + + dis.showLine(true); + dis.pressEnterToContinue(); + } + + /** + * ӡʳƷϢб + * ÷ ResultSet лȡʳƷϢдӡ + * ּṩӻչʾʳƷϢбû鿴͹ʳƷϢ + * + * @param rs ResultSet 󣬰ҪӡʳƷϢ + * @return ӡʳƷϢб + */ + public int printFoodInfoList (ResultSet rs) { + int num = 0; + try { + while ( rs.next() ) { + StringBuilder str = new StringBuilder(); + + str.append("| "); + String formattedNumber = String.format("%04d", rs.getInt("foodId")); + str.append(formattedNumber); + str.append("\t| "); + str.append(rs.getString("foodName")); + str.append("\t| "); + str.append(rs.getString("foodExplain")); + str.append("\t| "); + str.append(rs.getDouble("foodPrice")); + str.append("\t|"); + + String finalStr = str.toString(); + System.out.println(finalStr); + num++; + } + return num; + } catch ( Exception e ) { + e.printStackTrace(); + } + return num; + } + + /** + * ӡʳƷϢбı⡣ + * ÷ӡʳƷϢбı⣬IDʳƷʳƷܡ۸ֶΡ + * ּṩӻչʾʳƷϢбı⣬û鿴͹ʳƷϢ + */ + public void printFoodInfoListTitle () { + System.out.println("| ID\t| ʳƷ\t\t\t| ʳƷ\t\t\t\t\t| ۸\t|"); + } + + /** + * ӡ̼ʳƷϢ + * ÷ ResultSet лȡ̼ʳƷϢдӡ + * ּṩӻչʾ̼ʳƷϢû鿴͹ʳƷϢ + * + * @param business ̼Ҷ󣬰Ҫӡ̼Ϣ + */ + public void printAllBusinessFoodInfo (Business business) { + dis.titleLine("̼ [" + dis.deleteSpaceToString(business.getBusinessName()) + "] Ʒ", true); + try { + System.out.println("+ ѯ..."); + ResultSet rs = new BusinessDaoImpl().getBusinessFoodInfo(business); + // жǷΪ + if ( rs == null ) { + dis.titleLine("Error", true); + System.out.println("+ δѯй!"); + return; + } + + this.printFoodInfoListTitle(); + int num = this.printFoodInfoList(rs); + + System.out.println("+ ѯ " + num + " "); + } catch ( Exception e ) { + e.printStackTrace(); + } + dis.showLine(true); + dis.pressEnterToContinue(); + } + + /** + * ̼Ϣ + * ÷û̼Ϣ̼̼ҽܡ̼ҵַͷѺͷѵֶΡ + * ּṩӻĸ̼Ϣû̼Ϣ + * + * @param business ̼Ҷ󣬰Ҫµ̼Ϣ + */ + public void updateBusinessInfo (Business business) { + Business newBusiness = new Business(business); + int key; + boolean exitStatus = false; + while ( true ) { + dis.titleLine("̼Ϣ", true); + System.out.println("[0] ̼"); + System.out.println("[1] ̼ҽ"); + System.out.println("[2] ̼ҵַ"); + System.out.println("[3] ̼ͷ"); + System.out.println("[4] ̼ͷ"); + System.out.println("[5] ˳"); + dis.showLine(true); + + key = dis.getKeyNumber(); + + switch ( key ) { + case 0: + while ( true ) { + String newBusinessName; + int maxDataLength = 10; + dis.titleLine("̼", true); + System.out.print("+ ̼ (" + maxDataLength + "ַ): "); + + newBusinessName = dis.getStandString(maxDataLength); + + if (newBusinessName != null){ + newBusiness.setBusinessName(newBusinessName); + break; + } + System.out.println("+ ̼ƲϷ"); + } + break; + case 5: + return; + default: + dis.titleLine("ERROR", true); + System.out.println("+ Ϸ!"); + break; + } + + System.out.println("+ , ǷҪѡĵĿ"); + System.out.println("+ [y] - ȷϸĸ̼"); + System.out.println("+ [n] - Ҫĵ"); + System.out.println("+ [e] - ˳, Ҫĵ"); + System.out.print("+ ҪIJ: "); + + while ( true ) { + Scanner sca = new Scanner(System.in); + String str_key = sca.nextLine(); + if ( str_key.equals("y") || str_key.equals("Y") ) { + System.out.println("+ ..."); + if ( new BusinessDaoImpl().updateBusinessInfo(newBusiness) ) { + System.out.println("+ ..."); + } else { + System.out.println("+ ʧ..."); + } + exitStatus = true; + break; + } + if ( str_key.equals("n") || str_key.equals("N") ) { break; } + if ( str_key.equals("e") || str_key.equals("E") ) { + System.out.println("+ ˳"); + exitStatus = true; + break; + } + System.out.println("+ 벻Ϸ!"); + } + + if ( exitStatus ) { break; } + } + + dis.showLine(true); + dis.pressEnterToContinue(); + } + + /** + * ̼롣 + * ÷ṩһʽĽ棬̼֤ǰ벢롣 + * ȷȷԺͰȫԣΪ10ַ + * + * @param business Ա󣬰ǰԱϢ + */ + public void updatePassword (Business business) { + // ʱ̻ոڼû + Business tempBusiness = new Business(business); + dis.titleLine("", true); + + while (true){ + // ûԭ + Scanner sca = new Scanner(System.in); + String afterBusinessPassword; + System.out.print("+ ԭ: "); + afterBusinessPassword = sca.nextLine(); + + // ж¾Ƿ + if (afterBusinessPassword.equals(tempBusiness.getBusinessPassword())){ + System.out.println("+ ȷ"); + + while (true){ + String newBusinessPassword; + + // ȷû + while (true){ + String againNewBusinessPassword; + System.out.print("+ (10ַ): "); + newBusinessPassword = sca.nextLine(); + System.out.print("+ ٴ (10ַ): "); + againNewBusinessPassword = sca.nextLine(); + + if (newBusinessPassword.equals(againNewBusinessPassword)){ + break; + } + + System.out.println("+ ǰ벻һ"); + } + + // ж볤, С 10 + if (newBusinessPassword.length() <= 10){ + System.out.println("+ ..."); + // û洢ʱ + tempBusiness.setBusinessPassword(newBusinessPassword); + + // ݿ + if (new BusinessDaoImpl().updateBusinessPassword(tempBusiness)){ + // ʱе븳ֵû + business.setBusinessPassword(tempBusiness.getBusinessPassword()); + System.out.println("+ ³ɹ!"); + } else { + System.out.println("+ ʧ!"); + } + break; + } + System.out.println("+ !"); + } + dis.titleLine("˵", true); + sca.nextLine(); + return; + } else { + System.out.println("+ "); + System.out.print("+ [y] : "); + String exitKey = sca.next(); + if (!Objects.equals(exitKey, "y") && !Objects.equals(exitKey, "Y")){ + return; + } + } + } + } + + /** + * µʳƷ + * ÷ṩһʽĽ棬µʳƷ + * ȷʳƷƵȷԺͰȫԣΪ10ַ + * + * @param business Ա󣬰ǰԱϢ + */ + public void addBusinessNewFood (Business business) { + Food food = new Food(); + Display dis = new Display('+', '-', 50); + dis.titleLine("̼ʳƷ", true); + + while ( true ) { + String foodId; + Scanner sca = new Scanner(System.in); + System.out.print("+ ʳƷ (10ַ): "); + + foodId = sca.nextLine(); + + if ( Pattern.matches("^\\d{4}$", foodId) ) { + int foodIdForInt = Integer.parseInt(foodId); + food.setFoodId(foodIdForInt); + break; + } else { + if ( ! foodId.matches("\\d+") ) { + System.out.println("+ ַ!"); + } else { + System.out.println("+ ID λȷ!"); + } + } + } + + while ( true ) { + String foodName; + int max_length = 10; + System.out.print("+ ʳƷ (" + max_length + "ַ): "); + + foodName = dis.getStandString(max_length); + + if (foodName != null){ + food.setFoodName(foodName); + break; + } + System.out.println("+ ʳƷϷ!"); + } + + while ( true ) { + String foodExplain; + int max_length = 25; + System.out.print("+ ʳƷ (" + max_length + "ַ): "); + + foodExplain = dis.getStandString(max_length); + + if (foodExplain != null){ + food.setFoodExplain(foodExplain); + break; + } + System.out.println("+ ʳƷܲϷ!"); + } + + while ( true ) { + double foodPrice; + Scanner sca = new Scanner(System.in); + System.out.print("+ ʳƷ۸: "); + + if ( ! sca.hasNextDouble() ) { + System.out.println("+ 벻Ϸ"); + sca.next(); + } else { + foodPrice = sca.nextDouble(); + if ( foodPrice > 0 && foodPrice <= 9999 ) { + food.setFoodPrice(foodPrice); + break; + } else { + System.out.println("+ ݷΧ (0 ~ 9999)"); + } + } + } + + // ͬ ID + + food.setBusinessId(business.getBusinessId()); + + while ( true ) { + dis.showLine(true); + System.out.println("+ [y] ȷʳƷ"); + System.out.println("+ [n] ȡʳƷ "); + + Scanner sca = new Scanner(System.in); + String exitKey = sca.next(); + + if ( exitKey.equals("y") || exitKey.equals("Y") ) { + if ( new BusinessDaoImpl().addNewFood(food) ) { + System.out.println("+ ӳɹ!"); + } else { + System.out.println("+ ʧ!"); + } + return; + } else if ( exitKey.equals("n") || exitKey.equals("N") ) { + System.out.println("+ ˳"); + return; + } + } + } + + /** + * ʳƷϢ + * ÷ṩһֽʽĽ棬ڸʳƷϢ + * ȷʳƷƵȷԺͰȫԣΪ10ַ + * + * @param business Ա󣬰ǰԱϢ + */ + public void updateBusinessFoodInfo (Business business) { + Display dis = new Display('+', '-', 30); + Food updateFood; + + dis.titleLine("޸ʳƷϢ", true); + System.out.println("+ û [" + business.getBusinessName() + "] ʳƷ±"); + + ResultSet rs = new BusinessDaoImpl().getBusinessFoodInfo(business); + this.printFoodInfoListTitle(); + this.printFoodInfoList(rs); + dis.showLine(true); + + int updateFoodId; + while ( true ){ + Scanner sca = new Scanner(System.in); + System.out.print("+ Ҫ޸ĵʳƷĿ ID: "); + + while ( ! sca.hasNextInt() ) { + System.out.println("+ ID"); + sca.next(); + System.out.print("+ Ҫ޸ĵʳƷĿ ID: "); + } + updateFoodId = sca.nextInt(); + updateFood = new BusinessDaoImpl().getFoodById(updateFoodId, business.getBusinessId()); + + if ( updateFood != null ){ + System.out.println("+ ɹ!"); + break; + } + System.out.println("+ δܲѯָƷ"); + } + + int key; + while ( true ) { + dis.titleLine("ѡҪ޸ĵĿ", true); + dis.showItem("[0] Ʒ", true); + dis.showItem("[1] Ʒ", true); + dis.showItem("[2] Ʒ۸", true); + dis.showItem("[3] ʳƷϢ", true); + dis.showItem("[4] ϼ", true); + dis.showLine(true); + + key = dis.getKeyNumber(); + + switch ( key ) { + case 0: + while ( true ) { + String foodName; + int maxDataLength = 10; + System.out.print("+ ʳƷ (" + maxDataLength + "ַ): "); + + foodName = dis.getStandString(maxDataLength); + + if (foodName != null){ + updateFood.setFoodName(foodName); + break; + } + System.out.println("+ ʳƷϷ"); + } + break; + case 1: + while ( true ) { + String foodExplain; + int maxDataLength = 10; + System.out.print("+ ʳƷ (" + maxDataLength + "ַ): "); + + foodExplain = dis.getStandString(maxDataLength); + + if (foodExplain != null){ + updateFood.setFoodExplain(foodExplain); + break; + } + System.out.println("+ ʳƷܲϷ"); + } + break; + case 2: + while ( true ) { + double foodPrice; + Scanner case2_sca = new Scanner(System.in); + System.out.print("+ ʳƷ۸: "); + + if ( ! case2_sca.hasNextDouble() ) { + System.out.println("+ һЧΪʳƷ۸"); + case2_sca.next(); + } else { + foodPrice = case2_sca.nextDouble(); + if ( foodPrice > 0 && foodPrice <= 9999 ) { + updateFood.setFoodPrice(foodPrice); + break; + } else { + System.out.println("+ ݷΧ! Ҫ (0 ~ 9999)"); + } + } + } + case 3: + while (true){ + dis.titleLine("ȷϸʳƷϢ", true); + System.out.println("+ [y] ȷϸʳƷϢ"); + System.out.print("+ [n] ȡʳƷϢ: "); + + Scanner case3_sca = new Scanner(System.in); + String case3_Key = case3_sca.next(); + + if (case3_Key.equals("y") || case3_Key.equals("Y")) { + updateFood.setFoodId(updateFoodId); + updateFood.setBusinessId(business.getBusinessId()); + if (new BusinessDaoImpl().updateFoodInfo(updateFood, business)){ + System.out.println("+ ³ɹ!"); + break; + } + System.out.println("+ ʧ"); + } else if (case3_Key.equals("n") || case3_Key.equals("N")) { break; } + } + break; + case 4: + if (dis.MessageYesOrNo("ʾ", "ȷϼ˵?")) { + return; + } + break; + default: + dis.titleLine("ERROR", true); + System.out.println("+ Ϸ!"); + break; + } + } + } + + /** + * ɾʳƷϢ + * ͨʳƷIDƣɾӦʳƷ¼ + * ȳԽΪIDʧܣΪʳƷơ + * + * @param business ҵִɾ + */ + public void deleteFood(Business business){ + Scanner sca = new Scanner(System.in); + + dis.titleLine("ɾʳƷ", true); + System.out.print("+ ҪɾʳƷ ID : "); + String uin = sca.nextLine(); + + try{ + int uinToNumber = Integer.parseInt(uin); + System.out.println("+ ѯɾ ID Ϊ: " + uin + " ʳƷ..."); + + if (new BusinessDaoImpl().deleteFoodId(uinToNumber, business)){ + System.out.println("+ ID ɾɹ"); + return; + } + + System.out.println("+ ID ɾʧ"); + } catch (NumberFormatException e){ + System.out.println("+ ѯɾΪ: " + uin + " ʳƷ..."); + + if (new BusinessDaoImpl().deleteFoodName(dis.appendSpaceToString(uin, 10), business)){ + System.out.println("+ NAME ɾɹ"); + return; + } + + System.out.println("+ NAME ɾʧ"); + } + } +} \ No newline at end of file diff --git a/src/View/Display.java b/src/View/Display.java new file mode 100644 index 0000000..0744550 --- /dev/null +++ b/src/View/Display.java @@ -0,0 +1,212 @@ +/* + * Date: 2024-06-18 + * Design By JRNitre + * */ + +package View; + +import java.util.Scanner; + +public class Display { + + // Ա + private char displayNode; // ַ + private char displayLine; // ָ ַ + private Integer displayWidth; // ʾ + + Scanner sca = new Scanner(System.in); + + // 캯 + public Display (char node, char line, Integer width){ + displayNode = node; + displayLine = line; + displayWidth = width; + } + + /** + * ڿ̨Աʽַ + * ݿ̨ȣԶҿհ׿ȣʹʾ + * + * @param title Ҫıַ + * @param newLine ǷСΪtrueУΪfalse򲻻С + */ + public void titleLine (String title, boolean newLine){ + StringBuilder str = new StringBuilder(); + + int space = (displayWidth - title.length() - 2) / 2; + + str.append(displayNode); + str.append(String.valueOf(displayLine).repeat(Math.max(0, space))); + str.append(title); + str.append(String.valueOf(displayLine).repeat(Math.max(0, space))); + str.append(displayNode); + + String finalStr = str.toString(); + System.out.print(finalStr); + if (newLine){ System.out.println(); } + } + + /** + * ڿ̨һĿԶĿҿհ׿ȣʹʾ + * + * @param item ҪĿַ + * @param newLine ǷСΪtrueĿУΪfalse򲻻С + */ + public void showItem(String item, boolean newLine){ + StringBuilder str = new StringBuilder(); + + str.append(displayNode).append(" "); + str.append(item); + + String finalStr = str.toString(); + System.out.print(finalStr); + if (newLine){ System.out.println(); } + } + + /** + * ڿ̨һָߡ + * + * @param newLine ǷСΪtrueָߺУΪfalse򲻻С + */ + public void showLine(boolean newLine){ + StringBuilder str = new StringBuilder(); + + str.append(displayNode); + str.append(String.valueOf(displayLine).repeat(Math.max(0, displayWidth - 2))); + str.append(displayNode); + + String finalStr = str.toString(); + System.out.print(finalStr); + if (newLine){ System.out.println(); } + } + + /** + * ڿ̨һϢѯûǷȷϻȡ + * + * @param title Ϣı⡣ + * @param data Ϣݡ + * @return ûȷϣ򷵻trueûȡ򷵻false + */ + public boolean MessageYesOrNo(String title, String data){ + this.titleLine(title, true); + System.out.println("+ " + data); + System.out.print("+ (y/n) ȷ&ȡ "); + + String key = sca.next(); + + return key.equals("y") || key.equals("Y"); + } + + /** + * ûлȡһ + * ÷ʾûһֱûȷΪֹ + * + * @return ûֵ + */ + public int getKeyNumber(){ + int userInput; + + System.out.print("+ : "); + while(!sca.hasNextInt()){ + this.titleLine("ERROR", true); + System.out.println("+ IJ"); + sca.next(); + System.out.print("+ : "); + } + + userInput = sca.nextInt(); + return userInput; + } + + /** + * ַӿոֱַܳȴﵽָ󳤶ȡ + * ԭʼַijѾڻ򳬹󳤶ȣԭظַ + * + * @param data ԭʼַ + * @param max_length ָ󳤶 + * @return ӿոַ + */ + public String appendSpaceToString(String data, int max_length){ + StringBuilder str = new StringBuilder(); + int dataLength = data.length(); + + if (dataLength < max_length){ + str.append(data); + + int space = max_length - dataLength; + + str.append(" ".repeat(space)); + + return str.toString(); + } else { + return data; + } + + } + + /** + * ɾַĩβĿո + * ַΪջַ򷵻ԭַ + * + * @param data ԭʼַ + * @return ɾĩβոַ + */ + public String deleteSpaceToString(String data){ + // жǷΪ + if (data == null || data.isEmpty()){ + return data; + } + + int length = data.length(); + + while (length > 0 && data.charAt(length - 1) == ' '){ + length--; + } + + return data.substring(0, length); + } + + /** + * ӡϢ⡣ + * ÷ӡһбıʾ̼Ϣ + */ + public void printInfoTitle(){ + System.out.println("| ̼ID\t| ̼\t\t\t| ̼\t\t| ̼ҵַ\t\t\t\t| ̼ҽ\t\t\t\t\t| ͷ\t| ͷ\t|"); + } + + /** + * ȡ׼ַ + * ÷ûлȡһַɾĩβĿո + * ַȳָ󳤶ȣ򷵻null + * + * @param max_length ָ󳤶 + * @return ׼ַַȳָ󳤶ȣ򷵻null + */ + public String getStandString(int max_length){ + StringBuilder str = new StringBuilder(); + Scanner sca = new Scanner(System.in); + + String input = sca.nextLine(); + int inputLength = input.length(); + + // ׷ӿո + if (inputLength < max_length){ + str.append(input); + int space = max_length - inputLength; + str.append(" ".repeat(space)); + return str.toString(); + } + if (inputLength == max_length){ + return input; + } + return null; + } + + /** + * ʾûس + */ + public void pressEnterToContinue(){ + System.out.println("+ س..."); + sca.nextLine(); + } +} \ No newline at end of file diff --git a/src/dao/AdminDao.java b/src/dao/AdminDao.java new file mode 100644 index 0000000..b551338 --- /dev/null +++ b/src/dao/AdminDao.java @@ -0,0 +1,18 @@ +/* + * Date: 2024-06-18 + * Design By JRNitre + * */ + +package dao; + +import po.Admin; + +import java.sql.ResultSet; + +public interface AdminDao { + Admin getAdminByNameByPass(String adminName, String password); + Admin getAdminByIdByPass(int adminId, String password); + boolean updateAdminPassword(Admin admin); + ResultSet fuzzyQueryExampleForName(String name); + ResultSet getAllAdmin(); +} \ No newline at end of file diff --git a/src/dao/AdminDaoImpl.java b/src/dao/AdminDaoImpl.java new file mode 100644 index 0000000..6da680e --- /dev/null +++ b/src/dao/AdminDaoImpl.java @@ -0,0 +1,184 @@ +/* + * Date: 2024-06-18 + * Design By JRNitre + * */ + +package dao; + +import jdbc.JDBC; +import po.Admin; + +import java.sql.*; + +public class AdminDaoImpl implements AdminDao{ + + /** + * ͨûȡԱϢ + * ˷ͨṩûݿмԱ˻Ϣ + * ҵƥĹԱһԱϸϢAdmin + * ûҵƥݿ򷵻null + * + * @param adminName Աû + * @param password Ա롣 + * @return ƥĹԱûҵΪnull + */ + @Override + public Admin getAdminByNameByPass(String adminName, String password) { + Admin admin = null; + try { + // ݿ + Connection conn = JDBC.getConnection(); + Statement stmt = conn.createStatement(); + + String sql = "SELECT * FROM admin WHERE adminName = '" + adminName + "' AND adminPassword = '" + password + "'"; + + ResultSet rs = stmt.executeQuery(sql); + + if (rs.next()) { + admin = new Admin(); + admin.setAdminId(rs.getInt("adminId")); + admin.setAdminName(rs.getString("adminName")); + admin.setAdminPassword(rs.getString("adminPassword")); + } + + conn.close(); + stmt.close(); + rs.close(); + } catch (SQLException e) { + System.err.println("Database error occurred: " + e.getMessage()); + } catch (Exception e) { + System.err.println("Unexpected error: " + e.getMessage()); + } + return admin; + } + + /** + * ͨԱIDȡԱϢ + * ˷ͨṩĹԱIDݿмԱ˻Ϣ + * ҵƥĹԱһԱϸϢAdmin + * ûҵƥݿ򷵻null + * + * @param adminId ԱID + * @param password Ա롣 + * @return ƥĹԱûҵΪnull + */ + @Override + public Admin getAdminByIdByPass(int adminId, String password) { + Admin admin = null; + try { + // ݿ + Connection conn = JDBC.getConnection(); + Statement stmt = conn.createStatement(); + + String sql = "SELECT * FROM admin WHERE adminId = '" + adminId + "' AND adminPassword = '" + password + "'"; + + ResultSet rs = stmt.executeQuery(sql); + + if (rs.next()) { + admin = new Admin(); + admin.setAdminId(rs.getInt("adminId")); + admin.setAdminName(rs.getString("adminName")); + admin.setAdminPassword(rs.getString("adminPassword")); + } + + conn.close(); + stmt.close(); + rs.close(); + } catch (SQLException e) { + System.err.println("Database error occurred: " + e.getMessage()); + } catch (Exception e) { + System.err.println("Unexpected error: " + e.getMessage()); + } + return admin; + } + + /** + * ¹Ա롣 + * ˷Ը¹Ա롣 + * ³ɹ򷵻true + * ʧܻݿ򷵻false + * + * @param admin Ա󣬰ҪµĹԱϢ + * @return ³ɹtrue򷵻false + */ + @Override + public boolean updateAdminPassword(Admin admin) { + try { + Connection conn = JDBC.getConnection(); + Statement stmt = conn.createStatement(); + System.out.println("+ ӵݿ"); + + String sql = "UPDATE admin SET adminPassword = ? WHERE adminId = ?"; + PreparedStatement pst = conn.prepareStatement(sql); + + // ҪµûId + int adminIdToUpdate = admin.getAdminId(); + // Ҫ³ɵ + String newAdminPassword = admin.getAdminPassword(); + + pst.setString(1, newAdminPassword); + pst.setInt(2, adminIdToUpdate); + + int rowsAffected = pst.executeUpdate(); + + stmt.close(); + conn.close(); + pst.close(); + + return rowsAffected > 0; + } catch (Exception e) { + System.err.println("Unexpected error: " + e.getMessage()); + } + return false; + } + + /** + * ͨģѯȡйԱϢ + * ˷ͨģѯݿмйԱϢ + * ҵƥĹԱһԱϸϢResultSet + * ûҵƥݿ򷵻null + * + * @param name Աơ + * @return ƥĹԱûҵΪnull + */ + @Override + public ResultSet fuzzyQueryExampleForName(String name) { + try{ + Connection conn = JDBC.getConnection(); + + String sql = "SELECT * FROM business WHERE businessName LIKE ?"; + + PreparedStatement pstmt = conn.prepareStatement(sql); + pstmt.setString(1, name + "%"); + + return pstmt.executeQuery(); + + } catch (Exception e){ + e.printStackTrace(); + } + return null; + } + + /** + * ȡйԱϢ + * ˷ԴݿмйԱϢ + * ҵƥĹԱһԱϸϢResultSet + * ûҵƥݿ򷵻null + * + * @return йԱûҵΪnull + */ + @Override + public ResultSet getAllAdmin() { + try{ + Connection conn = JDBC.getConnection(); + Statement stmt = conn.createStatement(); + + String sql = "SELECT * FROM admin"; + + return stmt.executeQuery(sql); + } catch (Exception e){ + e.printStackTrace(); + } + return null; + } +} \ No newline at end of file diff --git a/src/dao/BusinessDao.java b/src/dao/BusinessDao.java new file mode 100644 index 0000000..15f2338 --- /dev/null +++ b/src/dao/BusinessDao.java @@ -0,0 +1,29 @@ +/* + * Date: 2024-06-18 + * Design By JRNitre + * */ + +package dao; + +import po.Business; +import po.Food; + +import java.sql.ResultSet; + +public interface BusinessDao { + boolean addNewBusiness(Business business); + ResultSet printAllBusiness(); + Business getBusinessByNameByPass(String name, String password); + Business getBusinessByIdByPass(Integer id, String password); + void deleteId(int id); + void deleteName(String Name); + boolean updateBusinessInfo(Business business); + boolean updateBusinessPassword(Business business); + boolean addNewFood(Food food); + ResultSet getAllFoodInfo(); + boolean updateFoodInfo(Food food, Business business); + Food getFoodById(int foodId, int businessId); + boolean deleteFoodId(int foodId, Business business); + boolean deleteFoodName(String foodName, Business business); + ResultSet getBusinessFoodInfo(Business business); +} \ No newline at end of file diff --git a/src/dao/BusinessDaoImpl.java b/src/dao/BusinessDaoImpl.java new file mode 100644 index 0000000..ae41ef6 --- /dev/null +++ b/src/dao/BusinessDaoImpl.java @@ -0,0 +1,514 @@ +/* + * Date: 2024-06-18 + * Design By JRNitre + * */ + +package dao; + +import View.Display; +import jdbc.JDBC; +import po.Business; +import po.Food; + +import java.sql.*; + +public class BusinessDaoImpl implements BusinessDao{ + + /** + * µ̼Ϣݿ⡣ + * + * @param business ӵ̼Ҷ󣬰̼ҵϢ + * @return ɹ̼Ϣ򷵻true򷵻false + */ + @Override + public boolean addNewBusiness(Business business){ + try { + Connection conn = JDBC.getConnection(); + + String sql = "INSERT INTO business (businessId, password, businessName, businessAddress, businessExplain, starPrice, deliveryPrice) VALUES (?, ?, ?, ?, ?, ?, ?)"; + PreparedStatement pstmt = conn.prepareStatement(sql); + + pstmt.setInt(1, business.getBusinessId()); + pstmt.setString(2, business.getBusinessPassword()); + pstmt.setString(3, business.getBusinessName()); + pstmt.setString(4, business.getBusinessAddress()); + pstmt.setString(5, business.getBusinessExplain()); + pstmt.setDouble(6, business.getBusinessStarPrice()); + pstmt.setDouble(7, business.getBusinessDeliveryPrice()); + + pstmt.executeUpdate(); + pstmt.close(); + conn.close(); + + return true; + } catch (Exception e){ + e.printStackTrace(); + } + return false; + } + + /** + * ѯҵϢؽ + * ͨݿӣStatementִSQLѯ䣬 + * ԻȡҵϢĽڲз쳣ӡ쳣ջ١ + * + * @return ResultSet ҵϢĽ쳣null + */ + @Override + public ResultSet printAllBusiness() { + try{ + Connection conn = JDBC.getConnection(); + Statement stmt = conn.createStatement(); + + String sql = "SELECT * FROM business"; + + return stmt.executeQuery(sql); + } catch (Exception e){ + e.printStackTrace(); + } + return null; + } + + /** + * ƺȡ̼Ϣ + * ͨݿѯƥƺ̼ңϸϢ + * + * @param name ̼ + * @param password ̼ + * @return ƥɹBusiness󣬷򷵻null + */ + @Override + public Business getBusinessByNameByPass(String name, String password) { + Business business = null; + try { + // ݿ + Connection conn = JDBC.getConnection(); + Statement stmt = conn.createStatement(); + + String sql = "SELECT * FROM business WHERE businessName = '" + name + "' AND password = '" + password + "'"; + + ResultSet rs = stmt.executeQuery(sql); + + if (rs.next()) { + business = new Business(); + business.setBusinessId(rs.getInt("businessId")); + business.setBusinessName(rs.getString("businessName")); + business.setBusinessPassword(rs.getString("password")); + business.setBusinessExplain(rs.getString("businessExplain")); + business.setBusinessAddress(rs.getString("businessAddress")); + business.setBusinessStarPrice(rs.getDouble("starPrice")); + business.setBusinessDeliveryPrice(rs.getDouble("deliveryPrice")); + } + + conn.close(); + stmt.close(); + rs.close(); + } catch (SQLException e) { + System.err.println("Database error occurred: " + e.getMessage()); + } catch (Exception e) { + System.err.println("Unexpected error: " + e.getMessage()); + } + return business; + } + + /** + * IDȡ̼Ϣ + * ͨݿѯƥID̼ңϸϢ + * + * @param id ̼ID + * @param password ̼ + * @return ƥɹBusiness󣬷򷵻null + */ + @Override + public Business getBusinessByIdByPass(Integer id, String password) { + Business business = null; + try { + // ݿ + Connection conn = JDBC.getConnection(); + Statement stmt = conn.createStatement(); + + String sql = "SELECT * FROM business WHERE businessId = '" + id + "' AND password = '" + password + "'"; + + ResultSet rs = stmt.executeQuery(sql); + + if (rs.next()) { + business = new Business(); + business.setBusinessId(rs.getInt("businessId")); + business.setBusinessName(rs.getString("businessName")); + business.setBusinessPassword(rs.getString("password")); + business.setBusinessExplain(rs.getString("businessExplain")); + business.setBusinessAddress(rs.getString("businessAddress")); + business.setBusinessStarPrice(rs.getDouble("starPrice")); + business.setBusinessDeliveryPrice(rs.getDouble("deliveryPrice")); + } + + conn.close(); + stmt.close(); + rs.close(); + } catch (SQLException e) { + System.err.println("Database error occurred: " + e.getMessage()); + } catch (Exception e) { + System.err.println("Unexpected error: " + e.getMessage()); + } + return business; + } + + /** + * ȡָ̼ҵʳƷϢ + * ͨݿѯָ̼ҵʳƷϢؽ + * + * @param business ̼Ҷ + * @return ResultSet ָ̼ҵʳƷϢĽ쳣null + */ + @Override + public ResultSet getBusinessFoodInfo(Business business){ + try{ + Connection conn = JDBC.getConnection(); + + String sql = "SELECT * FROM food WHERE businessId = ?"; + + PreparedStatement pstmt = conn.prepareStatement(sql); + pstmt.setInt(1, business.getBusinessId()); + + return pstmt.executeQuery(); + } catch (Exception e){ + e.printStackTrace(); + } + return null; + } + + /** + * IDɾ̼ҡ + * ͨݿɾָID̼ҡ + * + * @param id ̼ID + */ + @Override + public void deleteId(int id) { + try{ + Connection conn = JDBC.getConnection(); + + String sql = "DELETE FROM business WHERE businessId = ?"; + PreparedStatement prep = conn.prepareStatement(sql); + + prep.setInt(1, id); + + int rowsAffected = prep.executeUpdate(); + if (rowsAffected > 0){ + System.out.println("+ ɹɾ " + rowsAffected + " ̼"); + } else { + System.out.println("+ δҵ̼"); + } + + prep.close(); + conn.close(); + + } catch (Exception e){ + e.printStackTrace(); + } + } + + /** + * ɾ̼ҡ + * ͨݿɾָƵ̼ҡ + * + * @param Name ̼ + */ + @Override + public void deleteName(String Name) { + try{ + Connection conn = JDBC.getConnection(); + + String sql = "DELETE FROM business WHERE businessName = ?"; + PreparedStatement prep = conn.prepareStatement(sql); + + prep.setString(1, Name); + + int rowsAffected = prep.executeUpdate(); + if (rowsAffected > 0){ + System.out.println("+ ɹɾ " + rowsAffected + " ̼"); + } else { + System.out.println("+ δҵ̼"); + } + + prep.close(); + conn.close(); + + } catch (Exception e){ + e.printStackTrace(); + } + } + + /** + * ̼Ϣ + * ͨݿָID̼Ϣ + * + * @param business ̼Ҷ + * @return true ³ɹfalse ʧ + */ + @Override + public boolean updateBusinessInfo (Business business) { + try { + Connection conn = JDBC.getConnection(); + Statement stmt = conn.createStatement(); + + String sql = "UPDATE business SET businessName = ?, businessAddress = ?, businessExplain = ?, starPrice = ?, deliveryPrice = ? WHERE businessId = ?"; + PreparedStatement pst = conn.prepareStatement(sql); + + int businessIdToUpdate = business.getBusinessId(); + + pst.setString(1, business.getBusinessName()); + pst.setString(2, business.getBusinessAddress()); + pst.setString(3, business.getBusinessExplain()); + pst.setDouble(4, business.getBusinessStarPrice()); + pst.setDouble(5, business.getBusinessDeliveryPrice()); + pst.setInt(6, businessIdToUpdate); + + int rowsAffected = pst.executeUpdate(); + + stmt.close(); + conn.close(); + pst.close(); + + return rowsAffected > 0; + } catch ( Exception e ){ + e.printStackTrace(); + } + return false; + } + + /** + * ̼롣 + * ͨݿָID̼롣 + * + * @param business ̼Ҷ + * @return true ³ɹfalse ʧ + */ + @Override + public boolean updateBusinessPassword (Business business) { + try { + Connection conn = JDBC.getConnection(); + Statement stmt = conn.createStatement(); + System.out.println("+ ӵݿ"); + + String sql = "UPDATE business SET password = ? WHERE businessId = ?"; + PreparedStatement pst = conn.prepareStatement(sql); + + // ҪµûId + int newBusinessIdToUpdate = business.getBusinessId(); + // Ҫ³ɵ + String newBusinessPassword = business.getBusinessPassword(); + + pst.setString(1, newBusinessPassword); + pst.setInt(2, newBusinessIdToUpdate); + + int rowsAffected = pst.executeUpdate(); + + stmt.close(); + conn.close(); + pst.close(); + + return rowsAffected > 0; + } catch (Exception e) { + System.err.println("Unexpected error: " + e.getMessage()); + } + return false; + } + + /** + * µʳƷ + * ͨݿµʳƷ + * + * @param food ʳƷ + * @return true ӳɹfalse ʧ + */ + @Override + public boolean addNewFood (Food food) { + try { + Connection conn = JDBC.getConnection(); + + String sql = "INSERT INTO food (foodId, foodName, foodExplain, foodPrice, businessId) VALUES (?, ?, ?, ?, ?)"; + PreparedStatement pstmt = conn.prepareStatement(sql); + + pstmt.setInt(1, food.getFoodId()); + pstmt.setString(2, food.getFoodName()); + pstmt.setString(3, food.getFoodExplain()); + pstmt.setDouble(4, food.getFoodPrice()); + pstmt.setInt(5, food.getBusinessId()); + + pstmt.executeUpdate(); + pstmt.close(); + conn.close(); + + return true; + } catch (Exception e){ + e.printStackTrace(); + } + return false; + } + + /** + * ȡʳƷϢ + * ͨݿȡʳƷϢ + * + * @return ResultSet ʳƷϢ + */ + @Override + public ResultSet getAllFoodInfo () { + try{ + Connection conn = JDBC.getConnection(); + Statement stmt = conn.createStatement(); + + String sql = "SELECT * FROM food"; + + return stmt.executeQuery(sql); + } catch (Exception e){ + e.printStackTrace(); + } + return null; + } + + /** + * ʳƷϢ + * ͨݿָIDʳƷϢ + * + * @param food ʳƷ + * @param business ̼Ҷ + * @return true ³ɹfalse ʧ + */ + @Override + public boolean updateFoodInfo (Food food, Business business) { + try { + Connection conn = JDBC.getConnection(); + + // 3. ׼SQL + String sql = "UPDATE food SET foodName = ?, foodExplain = ?, foodPrice = ? WHERE businessId = ? AND foodId = ?"; + PreparedStatement pstmt = conn.prepareStatement(sql); + pstmt.setString(1, food.getFoodName()); + pstmt.setString(2, food.getFoodExplain()); + pstmt.setDouble(3, food.getFoodPrice()); + pstmt.setInt(4, food.getBusinessId()); + pstmt.setInt(5, food.getFoodId()); + + int rowsAffected = pstmt.executeUpdate(); + + pstmt.close(); + conn.close(); + + return rowsAffected > 0; + + + } catch ( Exception e ) { + e.printStackTrace(); + } + return false; + } + + /** + * ʳƷID̼IDȡʳƷϢ + * ͨѯݿȡضIDʳƷϸϢ + * + * @param foodId ʳƷΨһʶID + * @param businessId ̼ҵΨһʶIDȷʳƷĸ̼ҡ + * @return һFood󣬰ѯʳƷϢûҵƥʳƷ򷵻null + */ + @Override + public Food getFoodById (int foodId, int businessId) { + Food food = null; + + try { + // ݿ + Connection conn = JDBC.getConnection(); + Statement stmt = conn.createStatement(); + + String sql = "SELECT * FROM food WHERE foodId = '" + foodId + "' AND businessId = '" + businessId + "'"; + + ResultSet rs = stmt.executeQuery(sql); + + if (rs.next()) { + food = new Food(); + food.setFoodName(rs.getString("foodName")); + food.setFoodExplain(rs.getString("foodExplain")); + food.setFoodPrice(rs.getDouble("foodPrice")); + food.setFoodId(rs.getInt("foodId")); + food.setBusinessId(rs.getInt("businessId")); + } + + conn.close(); + stmt.close(); + rs.close(); + + return food; + } catch (SQLException e) { + System.err.println("Database error occurred: " + e.getMessage()); + } catch (Exception e) { + System.err.println("Unexpected error: " + e.getMessage()); + } + + return food; + } + + /** + * ʳƷID̼IDɾʳƷ + * ͨɾݿеضʳƷ¼ɾʳƷ + * + * @param foodId ʳƷΨһʶID + * @param business ̼ҵΨһʶIDȷʳƷĸ̼ҡ + * @return ɾɹ򷵻true򷵻false + */ + @Override + public boolean deleteFoodId (int foodId, Business business) { + try{ + Connection conn = JDBC.getConnection(); + + String sql = "DELETE FROM food WHERE businessId = ? AND foodId = ?"; + PreparedStatement prep = conn.prepareStatement(sql); + + prep.setInt(1, business.getBusinessId()); + prep.setInt(2, foodId); + + int rowsAffected = prep.executeUpdate(); + + prep.close(); + conn.close(); + + return rowsAffected > 0; + + } catch (Exception e){ + e.printStackTrace(); + } + return false; + } + + /** + * ʳƷƺ̼IDɾʳƷ + * ͨɾݿеضʳƷ¼ɾʳƷ + * + * @param foodName ʳƷơ + * @param business ̼ҵΨһʶIDȷʳƷĸ̼ҡ + * @return ɾɹ򷵻true򷵻false + */ + @Override + public boolean deleteFoodName (String foodName, Business business) { + try{ + Connection conn = JDBC.getConnection(); + + String sql = "DELETE FROM food WHERE businessId = ? AND foodName = ?"; + PreparedStatement prep = conn.prepareStatement(sql); + + prep.setInt(1, business.getBusinessId()); + prep.setString(2, foodName); + + int rowsAffected = prep.executeUpdate(); + + prep.close(); + conn.close(); + + return rowsAffected > 0; + + } catch (Exception e){ + e.printStackTrace(); + } + return false; + } +} \ No newline at end of file diff --git a/src/data/AdminMap.java b/src/data/AdminMap.java new file mode 100644 index 0000000..9b77e0a --- /dev/null +++ b/src/data/AdminMap.java @@ -0,0 +1,15 @@ +package data; + +import java.util.HashMap; +import java.util.Map; + +import po.Admin; + +public class AdminMap { + public static final Map ADMIN_MAP = new HashMap<>(); + + static { + ADMIN_MAP.put(1, new Admin(1, "jrnitre", "123")); + } + +} diff --git a/src/jdbc/JDBC.java b/src/jdbc/JDBC.java new file mode 100644 index 0000000..726dc4c --- /dev/null +++ b/src/jdbc/JDBC.java @@ -0,0 +1,33 @@ +/* + * Date: 2024-06-18 + * Design By JRNitre + * */ + +package jdbc; + +import java.sql.*; + +public class JDBC { + // ??????? + private static final String URL = "jdbc:mysql://124.220.110.170:3306/jrnitre"; + private static final String user = "jrnitre"; + private static final String Password = "npgt1365"; + + /** + * ????????????? + * ?????????????MySQL JDBC??????????????????????????????????????????????????? + * ????????????????????????????????????????????? + * + * @return Connection ???????????????????? + * @throws RuntimeException ???????????????????????????????????? + */ + public static Connection getConnection() { + try { + Class.forName("com.mysql.cj.jdbc.Driver"); + return DriverManager.getConnection(URL, user, Password); + } catch (ClassNotFoundException | SQLException e) { + e.printStackTrace(); + throw new RuntimeException("????????????", e); + } + } +} \ No newline at end of file diff --git a/src/po/Admin.java b/src/po/Admin.java new file mode 100644 index 0000000..2672e03 --- /dev/null +++ b/src/po/Admin.java @@ -0,0 +1,60 @@ +/* + * Date: 2024-06-18 + * Design By JRNitre + * */ + +package po; + +public class Admin { + // 成员变量 + private Integer adminId; // 管理员 ID + private String adminName; // 管理员名 + private String adminPassword; // 管理员密码 + + // 有参构造方法 + // 初始化管理员 + public Admin (Integer id, String name, String passworld){ + super(); + adminId = id; + adminName = name; + adminPassword = passworld; + } + + // 无参构造方法 + public Admin (){ + super(); + } + + // 拷贝构造方法 + public Admin (Admin cpAdmin){ + adminId = cpAdmin.adminId; + adminName = cpAdmin.adminName; + adminPassword = cpAdmin.adminPassword; + } + + // getter + public Integer getAdminId(){ + return adminId; + } + + public String getAdminName(){ + return adminName; + } + + public String getAdminPassword(){ + return adminPassword; + } + + // setter + public void setAdminId(Integer id){ + adminId = id; + } + + public void setAdminName(String name){ + adminName = name; + } + + public void setAdminPassword(String password){ + adminPassword = password; + } +} \ No newline at end of file diff --git a/src/po/Business.java b/src/po/Business.java new file mode 100644 index 0000000..86dd927 --- /dev/null +++ b/src/po/Business.java @@ -0,0 +1,96 @@ +/* + * Date: 2024-06-18 + * Design By JRNitre + * */ + +package po; + +public class Business { + // 成员变量 + private Integer businessId; // 商家 ID + private String businessName; // 商家名称 + private String businessPassword; // 商家密码 + private String businessAddress; // 商家地址 + private String businessExplain; // 商家介绍 + private double businessStarPrice; // 商家 起送费 + private double businessDeliveryPrice; // 商家 配送费 + + // 拷贝构造方法 + public Business (Business cpBusiness){ + this.businessId = cpBusiness.getBusinessId(); + this.businessName = cpBusiness.getBusinessName(); + this.businessPassword = cpBusiness.getBusinessPassword(); + this.businessAddress = cpBusiness.getBusinessAddress(); + this.businessExplain = cpBusiness.getBusinessExplain(); + this.businessStarPrice = cpBusiness.getBusinessStarPrice(); + this.businessDeliveryPrice = cpBusiness.getBusinessDeliveryPrice(); + } + + // 无参构造方法 + public Business () { super(); } + + + // setter + public void setBusinessId(Integer id){ + businessId = id; + } + + public void setBusinessName(String name){ + businessName = name; + } + + public void setBusinessPassword(String password){ + businessPassword = password; + } + + public void setBusinessAddress(String address){ + businessAddress = address; + } + + public void setBusinessExplain(String explain){ + businessExplain = explain; + } + + public void setBusinessStarPrice(double starPrice){ + businessStarPrice = starPrice; + } + + public void setBusinessDeliveryPrice(double deliveryPrice){ + businessDeliveryPrice = deliveryPrice; + } + + // getter + public Integer getBusinessId(){ + return businessId; + } + + public String getBusinessPassword(){ + return businessPassword; + } + + public String getBusinessName(){ + return businessName; + } + + public String getBusinessAddress(){ + return businessAddress; + } + + public String getBusinessExplain(){ + return businessExplain; + } + + public double getBusinessStarPrice(){ + return businessStarPrice; + } + + public double getBusinessDeliveryPrice(){ + return businessDeliveryPrice; + } + + // TODO tototototoString !!! + @Override + public String toString() { + return super.toString(); + } +} \ No newline at end of file diff --git a/src/po/Food.java b/src/po/Food.java new file mode 100644 index 0000000..8efd12e --- /dev/null +++ b/src/po/Food.java @@ -0,0 +1,49 @@ +/* + * Date: 2024-06-18 + * Design By JRNitre + * */ + +package po; + +public class Food { + // 成员变量 + private int foodId; // 食品编号 + private String foodName; // 食品名称 + private String foodExplain; // 食品说明 + private double foodPrice; // 食品价格 + private int businessId; // 所属商家编号 + + // setter + public void setFoodId(int id){ + this.foodId = id; + } + public void setFoodName(String name){ + this.foodName = name; + } + public void setFoodExplain(String explain){ + this.foodExplain = explain; + } + public void setFoodPrice(double price){ + this.foodPrice = price; + } + public void setBusinessId(int id){ + this.businessId = id; + } + + // getter + public int getFoodId(){ + return this.foodId; + } + public String getFoodName(){ + return this.foodName; + } + public String getFoodExplain(){ + return this.foodExplain; + } + public double getFoodPrice(){ + return this.foodPrice; + } + public int getBusinessId(){ + return this.businessId; + } +} \ No newline at end of file