日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

西工大数据库实验大作业 火锅店菜品管理系统

發布時間:2024/3/26 windows 47 豆豆
生活随笔 收集整理的這篇文章主要介紹了 西工大数据库实验大作业 火锅店菜品管理系统 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

西工大數據庫實驗大作業 火鍋店菜品管理系統

文章目錄

  • 西工大數據庫實驗大作業 火鍋店菜品管理系統
    • 前言:
    • 一.大作業簡單的需求分析:
    • 二.數據流圖:
    • 三.數據字典:
    • 四.E-R圖:
    • 五.關系模式設計:
    • 六.各種視圖以及各種約束、存儲過程、觸發器腳本描述:
        • 1.視圖:
        • 2.約束:
        • 3.存儲過程:
        • 4.觸發器:
        • 5.索引設計:
    • 七.大作業環境配置:
    • 八.大作業界面效果演示:
    • 九.關于源代碼:
        • 1.關于JDBC的演示:
        • 2.關于Food實體的演示:
        • 3.關于FoodDao類的演示:
        • 4.關于主界面mainframe設計的代碼:
        • 5.關于菜品添加界面FoodAddInterFirm設計的代碼:
        • 6.關于菜品信息管理界面FoodManageInterFirm設計的代碼:

前言:

本學期數據庫實驗結束了,在最后的大作業階段,經過本人調研結合所學之后,結合MySQL JDBC Java Swing等技術整合出的此系統,其中相關的學習視頻參考鏈接在:B站學習視頻:圖書管理系統,本篇將以實驗報告的形式對本系統做出相關的介紹

一.大作業簡單的需求分析:

本次實驗中本人所設計的系統是“河底撈”火鍋店的菜品管理系統,“民以食為天”,此系統正是本人在吃飯時尋找到的實驗靈感。通過采訪和調研火鍋店的服務員以及經理,將火鍋店背后完整的系統進行分析與設計。其中作為火鍋店的經理,即對于菜品部分專門負責的經理需掌握三個方面的管理:第一是關于菜品類別的管理,即火鍋店中涉及的菜品需進行分類,如:底料,葷菜,素菜等等,分門別類會更加便于管理;第二是關于菜品的管理,同時也是本系統的核心,一個菜品管理系統中通過記錄各種菜品對應的儲量,售價,分類等等才能更高效的保證火鍋店的經營;第三是供貨商管理,針對一個火鍋店的菜品,當菜品的儲量較低時需要進貨,這就牽扯到了供貨商進貨的問題了,因此將一個菜品管理系統整個就分成這么三部分的管理內容:菜品類別,菜品,供貨商,轉化為數據庫中即將三者分別設計為實體,并通過對于三個實體的增刪改查操作來管理和維護整個菜品管理系統。

二.數據流圖:

頂層數據流圖:

0層數據流圖:

三.數據字典:

數據加工:

元素編號名稱類型說明
B01菜品管理系統處理對菜品類別,菜品和供貨商進行管理的系統進行加工
B02登錄系統處理菜品管理系統的登錄界面
S01身份信息數據流管理員的身份信息
S02菜品類別信息數據流菜品的類別名稱以及菜品類別描述
S03菜品信息數據流菜品名稱,菜品儲備,菜品售價,菜品所屬類別以及菜品描述
S04供貨商信息數據流供貨商姓名,供貨商聯系電話,供應菜品以及供應價格
IP01菜品類別管理處理添加菜品類別和菜品類別具體管理兩個模塊
IP02菜品管理處理添加菜品和菜品具體管理兩個模塊
IP03供貨商管理處理添加供貨商和供貨商具體管理兩個模塊
IP04菜品類別添加處理添加菜品類別名稱以及菜品類別描述
IP05菜品類別具體管理處理對菜品類別進行增刪改查
IP06菜品添加處理添加菜品名稱,菜品儲備,菜品售價,菜品所屬類別以及菜品描述
IP07菜品具體管理處理對菜品進行增刪改查
IP08供貨商添加處理添加供貨商姓名,供貨商聯系電話,供應菜品以及供應價格
IP09供貨商具體管理處理對供應商進行增刪改查

數據流:

  • 數據流名稱:S01身份信息:
數據項數據類型長度備注
user_idint整型管理員編號
user_namevarchar45管理員姓名
user_passwordvarchar45管理員密碼
  • 數據流名稱:S02菜品類別信息:
數據項數據類型長度備注
foodtype_idint整型菜品類型編號
foodtype_namevarchar45菜品類型名稱
foodtype_descvarchar45菜品類型描述
  • 數據流名稱:S03菜品信息:
數據項數據類型長度備注
food_idint整型菜品編號
food_namevarchar45菜品名稱
food_storageint整型菜品儲備(單位:份)
food_pricefloat浮點型菜品售價(單位:元/份)
food_typeidint整型菜品所屬類別
food_descvarchar45菜品描述
  • 數據流名稱:S04供應商信息:
數據項數據類型長度備注
s_idint整型供貨商編號
s_namevarchar45供貨商姓名
s_telvarchar45供貨商電話
s_foodidint整型供應菜品編號
s_pricefloat浮點型供應價格(單位:元/份)

四.E-R圖:

五.關系模式設計:

在E-R圖中出現的實體有:

  • 管理員{編號,姓名,密碼,(編號->姓名,編號->密碼)};
  • 菜品類別{編號,名稱,描述,(編號->名稱,編號->描述)};
  • 菜品{編號,名稱,儲備,售價,所屬類別,描述(編號->名稱,編號->儲備,編號->售價,編號->所屬類別,編號->描述)},其中所屬類別作為菜品類別中編號的外碼;
  • 供應商{編號,姓名,電話,供應菜品,供應價,(編號->姓名,編號->電話,編號->供應菜品,編號->供應價)},其中供應菜品作為菜品中編號的外碼;

則在上面的描述中對應各個關系實體有:

  • 1)在整個設計中各個實體中的屬性不可分割且獨立,則符合1NF
  • 2)各個實體中的屬性不存在對碼的傳遞依賴和部分依賴,則符合2NF,3NF

六.各種視圖以及各種約束、存儲過程、觸發器腳本描述:

1.視圖:

由于本系統是面向全體管理員的,因此不需要使用視圖來進行安全性和查詢上面的一些維護

2.約束:

  • 在上面的設計中對于每個關系的主鍵,三個關系中的編號均設置為PRIMARY KEY,并且都要求NOT NULL以及ATUO INCREMENT
  • 對于四個關系之間存在兩個外鍵,即:菜品的所屬類別與菜品的編號之間,供應商的供應菜品與菜品的編號之間,具體如下:
  • 針對某些列中設計的CHECK約束,在建好的表上使用alter添加約束:
-- 菜品儲備必須>=0: alter table food add constraint check_storage check(food_storage>0); -- 菜品中售價必須>0: alter table food add constraint check_price check(food_price>0); -- 供應價格必須>0: alter table supply add constraint check_price_s check(s_price>0);

運行結果:

3.存儲過程:

本存儲過程用于更新售價,假定所有菜品的售價是基于供貨商供應價而定的,并且利潤為40%,即在更新供應價格后結合觸發器對于售價進行改變,于是定義的存儲過程如下:

delimiter$$ create procedure `changeprice` (in foodid int,in price_in float) begin declare price_out float; select s_price into price_in from supply where s_id = foodid; set price_out = price_in*1.4; update food set food_price = price_out where food_id = foodid; end $$

運行結果:

4.觸發器:

本系統中的觸發器即是結合上面設計的存儲過程在供應商表發生變化時執行上面的存儲過程并獲得輸出,后利用輸出更新菜品表中的售價,具體如下:

delimiter $$ -- 添加插入觸發器 create trigger `update_price_on_food` after insert on supply for each row begin call `changeprice` (new.s_foodid,new.s_price); end $$ -- 添加更新觸發器 create trigger `update_price_on_food_update` after update on supply for each row begin call `changeprice` (new.s_foodid,new.s_price); end $$

運行結果:

5.索引設計:

針對數據量較大的關系中頻繁使用的查詢條件增加索引:菜品中的菜品名稱列增加對應的索引,具體如下:

七.大作業環境配置:

  • mysql版本:mysql 8.0
  • 實現系統界面使用的語言:java
  • 使用的IDE:eclipse
  • 使用的完成界面的插件:WindowBuilder

八.大作業界面效果演示:

  • 登錄界面:
  • 主界面:
  • 關于我們界面:
  • 菜品數據維護中的菜單截圖:
  • 菜品類別添加界面:
  • 菜品類別管理界面:
  • 菜品添加界面:
  • 菜品管理界面:
  • 供貨商添加界面:
  • 供貨商信息更改界面:
  • 安全退出:

九.關于源代碼:

本次在代碼編程時使用的是java語言,其中設計符合model-dao-view的模式,并且將JDBC連接和字符串判空的工具類放在utils目錄中,將圖片放在images目錄中,關于代碼的結構如下圖所示:

1.關于JDBC的演示:

import java.sql.Connection; import java.sql.DriverManager;public class JDBCtest {//配置JDBC連接的基本參數:private static String dbURL = "jdbc:mysql:///bighomework?useSSL=false&serverTimezone=UTC&characterEncoding=UTF-8&allowPublicKeyRetrieval=true";private static String dbUSERNAME = "root";private static String dbPASSWORD = "123456";private static String JDBCname="com.mysql.cj.jdbc.Driver";//獲取數據庫的連接public static Connection getCon() throws Exception{Class.forName(JDBCname);Connection conn = DriverManager.getConnection(dbURL, dbUSERNAME, dbPASSWORD);return conn;}//關閉數據庫連接(占用內存很多)public static void closeCon(Connection conn) throws Exception{if(conn!=null){conn.close();}}public static void main(String[] args) throws Exception{JDBCtest jdbc = new JDBCtest();try{Connection conn = jdbc.getCon();System.out.println("數據庫連接成功!");System.out.println(conn);jdbc.closeCon(conn);} catch (Exception e) {e.printStackTrace();System.out.println("數據庫連接失敗!");}} }

2.關于Food實體的演示:

//菜品的實體 public class Food {private int id; //菜品編號private String name; //菜品名稱private int storage; //菜品存貨(份)private float price; //菜品售賣價格private int typeid; //菜品類別idprivate String typename; //菜品類別名稱private String desc; //菜品描述//供貨商階段會用到的構造方法:public String getTypename() {return typename;}public Food(String name) {super();this.name = name;}public Food(String name, int typeid) {super();this.name = name;this.typeid = typeid;}public void setTypename(String typename) {this.typename = typename;}public Integer getTypeid() {return typeid;}public Food(int id, String name, int storage, float price, int typeid, String desc) {super();this.id = id;this.name = name;this.storage = storage;this.price = price;this.typeid = typeid;this.desc = desc;}public Food(String name, int storage, float price, int typeid, String desc) {super();this.name = name;this.storage = storage;this.price = price;this.typeid = typeid;this.desc = desc;}public void setTypeid(int typeid) {this.typeid = typeid;}public Food() {super();}public int getId() {return id;}public void setId(int id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getStorage() {return storage;}public void setStorage(int storage) {this.storage = storage;}public float getPrice() {return price;}public void setPrice(float price) {this.price = price;}public String getDesc() {return desc;}public void setDesc(String desc) {this.desc = desc;}@Overridepublic String toString() {return name;} }

3.關于FoodDao類的演示:

import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import jdbc.model.Food; import jdbc.utils.StringUtil;//菜品的Dao類 public class FoodDao {//菜品添加函數:public int add(Connection conn,Food food) throws Exception{String sql = "insert into food values(null,?,?,?,?,?)";PreparedStatement pstmt = conn.prepareStatement(sql);pstmt.setString(1,food.getName());pstmt.setInt(2,food.getStorage());pstmt.setFloat(3,food.getPrice());pstmt.setInt(4, food.getTypeid());pstmt.setString(5,food.getDesc());return pstmt.executeUpdate();}//菜品信息查詢:public ResultSet list(Connection conn,Food food)throws Exception {StringBuffer sb = new StringBuffer("select * from food f,food_type ft where f.food_typeid = ft.foodtype_id");if(StringUtil.isNotEmpty(food.getName())){sb.append(" and f.food_name like '%" + food.getName() +"%'");}if(food.getTypeid()!= null && food.getTypeid()!=-1 && food.getTypeid()!= 0) {sb.append(" and f.food_typeid ="+food.getTypeid());}PreparedStatement pstmt = conn.prepareStatement(sb.toString());return pstmt.executeQuery();}//菜品信息刪除:public int delete(Connection conn,String id)throws Exception{String sql = "delete from food where food_id=?";PreparedStatement pstmt = conn.prepareStatement(sql);pstmt.setString(1, id);return pstmt.executeUpdate();}//菜品信息修改:public int update(Connection conn,Food food)throws Exception{String sql = "update food set food_name=?,food_storage=?,food_price=?,food_typeid=?,food_desc=? where food_id=?";PreparedStatement pstmt = conn.prepareStatement(sql);pstmt.setString(1, food.getName());pstmt.setInt(2, food.getStorage());pstmt.setFloat(3, food.getPrice());pstmt.setInt(4, food.getTypeid());pstmt.setString(5, food.getDesc());pstmt.setInt(6, food.getId());return pstmt.executeUpdate();}//判斷菜品類型下是否有菜品:public boolean existFoodByFoodTypeId(Connection conn,String foodtypeid)throws Exception{String sql = "select * from food where food_typeid = ?";PreparedStatement pstmt = conn.prepareStatement(sql);pstmt.setString(1, foodtypeid);ResultSet rs = pstmt.executeQuery();return rs.next(); }//初始化供貨商下拉框:public ResultSet list_supply(Connection conn,Food food)throws Exception {StringBuffer sb = new StringBuffer("select * from food");if(StringUtil.isNotEmpty(food.getName())){sb.append(" and foodtype_name like '%"+food.getName()+"%'");}PreparedStatement pstmt = conn.prepareStatement(sb.toString().replaceFirst("and","where"));return pstmt.executeQuery();} }

4.關于主界面mainframe設計的代碼:

import java.awt.BorderLayout; import java.awt.EventQueue;import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import javax.swing.JMenuBar; import javax.swing.JMenu; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.GroupLayout; import javax.swing.GroupLayout.Alignment; import javax.swing.JDesktopPane; import java.awt.Color; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.ImageIcon; import javax.swing.JLabel;public class mainframe extends JFrame {private JPanel contentPane;private JDesktopPane table = null;/*** Launch the application.*/public static void main(String[] args) {EventQueue.invokeLater(new Runnable() {public void run() {try {mainframe frame = new mainframe();frame.setVisible(true);} catch (Exception e) {e.printStackTrace();}}});}/*** Create the frame.*/public mainframe() {setTitle("\u201C\u6CB3\u5E95\u635E\u201D\u83DC\u54C1\u7BA1\u7406\u7CFB\u7EDF\u4E3B\u754C\u9762");setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setBounds(100, 100, 1550, 790);JMenuBar menuBar = new JMenuBar();setJMenuBar(menuBar);JMenu mnNewMenu = new JMenu("\u83DC\u54C1\u6570\u636E\u7EF4\u62A4");mnNewMenu.setIcon(new ImageIcon("C:\\Users\\86135\\eclipse-workspace\\ResturantOrder\\src\\images\\\u6570\u636E.png"));menuBar.add(mnNewMenu);JMenu mnNewMenu_2 = new JMenu("\u83DC\u54C1\u7C7B\u522B\u7BA1\u7406");mnNewMenu_2.setIcon(new ImageIcon("C:\\Users\\86135\\eclipse-workspace\\ResturantOrder\\src\\images\\\u83DC\u54C1\u7C7B\u522B\u7BA1\u7406.png"));mnNewMenu.add(mnNewMenu_2);JMenuItem mntmNewMenuItem_2 = new JMenuItem("\u83DC\u54C1\u7C7B\u522B\u6DFB\u52A0");mntmNewMenuItem_2.setIcon(new ImageIcon("C:\\Users\\86135\\eclipse-workspace\\ResturantOrder\\src\\images\\\u83DC\u54C1\u7C7B\u522B_\u6DFB\u52A0.png"));mntmNewMenuItem_2.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {FoodTypeInterFirm foodtypeinterfirm = new FoodTypeInterFirm();foodtypeinterfirm.setVisible(true);table.add(foodtypeinterfirm);}});mnNewMenu_2.add(mntmNewMenuItem_2);JMenuItem mntmNewMenuItem_1 = new JMenuItem("\u83DC\u54C1\u7C7B\u522B\u7EF4\u62A4");mntmNewMenuItem_1.setIcon(new ImageIcon("C:\\Users\\86135\\eclipse-workspace\\ResturantOrder\\src\\images\\\u83DC\u54C1\u7C7B\u522B_\u7EF4\u62A4.png"));mntmNewMenuItem_1.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {FoodTypeManageInterFirm foodtypemanageinterfirm = new FoodTypeManageInterFirm();foodtypemanageinterfirm.setVisible(true);table.add(foodtypemanageinterfirm);}});mnNewMenu_2.add(mntmNewMenuItem_1);JMenu mnNewMenu_3 = new JMenu("\u83DC\u54C1\u7BA1\u7406");mnNewMenu_3.setIcon(new ImageIcon("C:\\Users\\86135\\eclipse-workspace\\ResturantOrder\\src\\images\\\u83DC\u54C1\u7BA1\u7406.png"));mnNewMenu.add(mnNewMenu_3);JMenuItem mntmNewMenuItem_3 = new JMenuItem("\u83DC\u54C1\u6DFB\u52A0");mntmNewMenuItem_3.setIcon(new ImageIcon("C:\\Users\\86135\\eclipse-workspace\\ResturantOrder\\src\\images\\\u83DC\u54C1_\u6DFB\u52A0.png"));mntmNewMenuItem_3.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {FoodAddInterFirm foodaddinterfirm = new FoodAddInterFirm();foodaddinterfirm.setVisible(true);table.add(foodaddinterfirm);}});mnNewMenu_3.add(mntmNewMenuItem_3);JMenuItem mntmNewMenuItem_4 = new JMenuItem("\u83DC\u54C1\u7EF4\u62A4");mntmNewMenuItem_4.setIcon(new ImageIcon("C:\\Users\\86135\\eclipse-workspace\\ResturantOrder\\src\\images\\\u83DC\u54C1_\u7EF4\u62A4.png"));mntmNewMenuItem_4.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {FoodManageInterFirm foodmanageinterfirm = new FoodManageInterFirm();foodmanageinterfirm.setVisible(true);table.add(foodmanageinterfirm);}});mnNewMenu_3.add(mntmNewMenuItem_4);JMenu mnNewMenu_4 = new JMenu("\u4F9B\u8D27\u5546\u7BA1\u7406");mnNewMenu_4.setIcon(new ImageIcon("C:\\Users\\86135\\eclipse-workspace\\ResturantOrder\\src\\images\\\u4F9B\u8D27\u5546.png"));mnNewMenu.add(mnNewMenu_4);JMenuItem mntmNewMenuItem_6 = new JMenuItem("\u4F9B\u8D27\u5546\u6DFB\u52A0");mntmNewMenuItem_6.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {SupplyAddInterFirm supplyAddInterFirm = new SupplyAddInterFirm();supplyAddInterFirm.setVisible(true);table.add(supplyAddInterFirm);}});mntmNewMenuItem_6.setIcon(new ImageIcon("C:\\Users\\86135\\eclipse-workspace\\ResturantOrder\\src\\images\\\u4F9B\u8D27\u5546_\u6DFB\u52A0.png"));mnNewMenu_4.add(mntmNewMenuItem_6);JMenuItem mntmNewMenuItem_7 = new JMenuItem("\u4F9B\u8D27\u5546\u4FE1\u606F\u66F4\u6539");mntmNewMenuItem_7.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {SupplyManageInterFirm supplyManageInterFirm = new SupplyManageInterFirm();supplyManageInterFirm.setVisible(true);table.add(supplyManageInterFirm);}});mntmNewMenuItem_7.setIcon(new ImageIcon("C:\\Users\\86135\\eclipse-workspace\\ResturantOrder\\src\\images\\\u4F9B\u8D27\u5546_\u7EF4\u62A4.png"));mnNewMenu_4.add(mntmNewMenuItem_7);JMenuItem mntmNewMenuItem_5 = new JMenuItem("\u5B89\u5168\u9000\u51FA");mntmNewMenuItem_5.setIcon(new ImageIcon("C:\\Users\\86135\\eclipse-workspace\\ResturantOrder\\src\\images\\\u9000\u51FA.png"));mntmNewMenuItem_5.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {int result = JOptionPane.showConfirmDialog(null, "是否退出系統?");//System.out.println(result);if(result == 0) {dispose();}}});mnNewMenu.add(mntmNewMenuItem_5);JMenu mnNewMenu_1 = new JMenu("\u5173\u4E8E\u6211\u4EEC");mnNewMenu_1.setIcon(new ImageIcon("C:\\Users\\86135\\eclipse-workspace\\ResturantOrder\\src\\images\\\u706B\u95051.png"));menuBar.add(mnNewMenu_1);JMenuItem mntmNewMenuItem = new JMenuItem("\u6CB3\u5E95\u635E\u706B\u9505");mntmNewMenuItem.setIcon(new ImageIcon("C:\\Users\\86135\\eclipse-workspace\\ResturantOrder\\src\\images\\\u706B\u95052.png"));mntmNewMenuItem.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {AboutUsInterFirm aboutusinterfirm = new AboutUsInterFirm();aboutusinterfirm.setVisible(true);table.add(aboutusinterfirm);}});mnNewMenu_1.add(mntmNewMenuItem);contentPane = new JPanel();contentPane.setBackground(new Color(255, 255, 255));contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));setContentPane(contentPane);contentPane.setLayout(new BorderLayout(0,0));table = new JDesktopPane();contentPane.add(table,BorderLayout.CENTER);JLabel lblNewLabel = new JLabel("");lblNewLabel.setIcon(new ImageIcon("C:\\Users\\86135\\eclipse-workspace\\ResturantOrder\\src\\images\\mf-bg.jpg"));lblNewLabel.setBounds(10, 0, 1532, 717);table.add(lblNewLabel);//運行設置JFrame最大化:this.setExtendedState(JFrame.MAXIMIZED_BOTH);} }

5.關于菜品添加界面FoodAddInterFirm設計的代碼:

import java.awt.Color; import java.awt.EventQueue; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.Connection; import java.sql.ResultSet;import javax.swing.GroupLayout; import javax.swing.GroupLayout.Alignment; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JInternalFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JTextField; import javax.swing.LayoutStyle.ComponentPlacement; import javax.swing.border.LineBorder;import jdbc.dao.FoodDao; import jdbc.dao.FoodTypeDao; import jdbc.model.Food; import jdbc.model.FoodType; import jdbc.utils.JDBCtest; import jdbc.utils.StringUtil;public class FoodAddInterFirm extends JInternalFrame {private JTextField nameTXT;private JTextField storageTXT;private JTextField priceTXT;private JTextField descTXT;private JComboBox foodtypeCB;private JDBCtest jdbctest = new JDBCtest();private FoodTypeDao foodtypedao = new FoodTypeDao();private FoodDao fooddao = new FoodDao();/*** Launch the application.*/public static void main(String[] args) {EventQueue.invokeLater(new Runnable() {public void run() {try {FoodAddInterFirm frame = new FoodAddInterFirm();frame.setVisible(true);} catch (Exception e) {e.printStackTrace();}}});}/*** Create the frame.*/public FoodAddInterFirm() {getContentPane().setBackground(new Color(255, 99, 71));getContentPane().setForeground(new Color(255, 99, 71));setClosable(true);setIconifiable(true);setTitle("\u83DC\u54C1\u6DFB\u52A0");setBounds(100, 100, 607, 446);JLabel lblNewLabel = new JLabel("\u83DC\u54C1\u540D\u79F0\uFF1A");lblNewLabel.setIcon(new ImageIcon("C:\\Users\\86135\\eclipse-workspace\\ResturantOrder\\src\\images\\\u8FA3\u6912.png"));lblNewLabel.setForeground(new Color(255, 255, 255));lblNewLabel.setFont(new Font("等線 Light", Font.PLAIN, 16));nameTXT = new JTextField();nameTXT.setColumns(10);JLabel lblNewLabel_1 = new JLabel("\u83DC\u54C1\u50A8\u91CF\uFF1A");lblNewLabel_1.setIcon(new ImageIcon("C:\\Users\\86135\\eclipse-workspace\\ResturantOrder\\src\\images\\\u50A8\u91CF.png"));lblNewLabel_1.setForeground(new Color(255, 255, 255));lblNewLabel_1.setFont(new Font("等線 Light", Font.PLAIN, 16));storageTXT = new JTextField();storageTXT.setColumns(10);JLabel lblNewLabel_2 = new JLabel("\u83DC\u54C1\u552E\u4EF7\uFF1A");lblNewLabel_2.setIcon(new ImageIcon("C:\\Users\\86135\\eclipse-workspace\\ResturantOrder\\src\\images\\\u552E\u4EF7.png"));lblNewLabel_2.setForeground(new Color(255, 255, 255));lblNewLabel_2.setFont(new Font("等線 Light", Font.PLAIN, 16));priceTXT = new JTextField();priceTXT.setColumns(10);JLabel lblNewLabel_3 = new JLabel("\u83DC\u54C1\u63CF\u8FF0/\u5907\u6CE8\uFF1A");lblNewLabel_3.setIcon(new ImageIcon("C:\\Users\\86135\\eclipse-workspace\\ResturantOrder\\src\\images\\\u7F8E\u98DF.png"));lblNewLabel_3.setForeground(new Color(255, 255, 255));lblNewLabel_3.setFont(new Font("等線 Light", Font.PLAIN, 16));descTXT = new JTextField();descTXT.setColumns(10);//文本域加邊框:descTXT.setBorder(new LineBorder(new java.awt.Color(127,157,185),1,false));JButton btnNewButton = new JButton("\u6DFB\u52A0");btnNewButton.setIcon(new ImageIcon("C:\\Users\\86135\\eclipse-workspace\\ResturantOrder\\src\\images\\\u6DFB\u52A0.png"));btnNewButton.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {FoodAddActionPerformed(e);}});btnNewButton.setFont(new Font("等線 Light", Font.PLAIN, 16));JButton btnNewButton_1 = new JButton("\u91CD\u7F6E");btnNewButton_1.setIcon(new ImageIcon("C:\\Users\\86135\\eclipse-workspace\\ResturantOrder\\src\\images\\\u91CD\u7F6E.png"));btnNewButton_1.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {FoodResetActionPerformed(e);}});btnNewButton_1.setFont(new Font("等線 Light", Font.PLAIN, 16));JLabel lblNewLabel_4 = new JLabel("\u83DC\u54C1\u7C7B\u522B\uFF1A");lblNewLabel_4.setIcon(new ImageIcon("C:\\Users\\86135\\eclipse-workspace\\ResturantOrder\\src\\images\\\u83DC\u54C1\u7C7B\u522B.png"));lblNewLabel_4.setForeground(new Color(255, 255, 255));lblNewLabel_4.setFont(new Font("等線 Light", Font.PLAIN, 16));foodtypeCB = new JComboBox();foodtypeCB.setBackground(new Color(211, 211, 211));GroupLayout groupLayout = new GroupLayout(getContentPane());groupLayout.setHorizontalGroup(groupLayout.createParallelGroup(Alignment.LEADING).addGroup(groupLayout.createSequentialGroup().addGap(105).addComponent(btnNewButton, GroupLayout.PREFERRED_SIZE, 97, GroupLayout.PREFERRED_SIZE).addPreferredGap(ComponentPlacement.RELATED, 174, Short.MAX_VALUE).addComponent(btnNewButton_1, GroupLayout.PREFERRED_SIZE, 97, GroupLayout.PREFERRED_SIZE).addGap(130)).addGroup(groupLayout.createSequentialGroup().addGap(50).addGroup(groupLayout.createParallelGroup(Alignment.LEADING).addComponent(descTXT, GroupLayout.PREFERRED_SIZE, 475, GroupLayout.PREFERRED_SIZE).addGroup(groupLayout.createSequentialGroup().addGroup(groupLayout.createParallelGroup(Alignment.LEADING).addGroup(groupLayout.createSequentialGroup().addGroup(groupLayout.createParallelGroup(Alignment.LEADING).addComponent(lblNewLabel_2, GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE).addComponent(lblNewLabel_1).addComponent(lblNewLabel_4, GroupLayout.PREFERRED_SIZE, 119, GroupLayout.PREFERRED_SIZE)).addPreferredGap(ComponentPlacement.RELATED)).addGroup(groupLayout.createSequentialGroup().addPreferredGap(ComponentPlacement.RELATED).addComponent(lblNewLabel).addGap(22))).addGroup(groupLayout.createParallelGroup(Alignment.LEADING).addComponent(nameTXT, GroupLayout.DEFAULT_SIZE, 142, Short.MAX_VALUE).addComponent(foodtypeCB, 0, 142, Short.MAX_VALUE).addComponent(priceTXT, GroupLayout.DEFAULT_SIZE, 142, Short.MAX_VALUE).addComponent(storageTXT, 142, 142, Short.MAX_VALUE)).addGap(222)).addComponent(lblNewLabel_3, GroupLayout.PREFERRED_SIZE, 165, GroupLayout.PREFERRED_SIZE)).addGap(70)));groupLayout.setVerticalGroup(groupLayout.createParallelGroup(Alignment.LEADING).addGroup(groupLayout.createSequentialGroup().addGap(40).addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(lblNewLabel).addComponent(nameTXT, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addGap(18).addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(lblNewLabel_1).addComponent(storageTXT, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addGap(18).addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(priceTXT, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(lblNewLabel_2)).addGap(18).addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(lblNewLabel_4).addComponent(foodtypeCB, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addPreferredGap(ComponentPlacement.UNRELATED).addComponent(lblNewLabel_3, GroupLayout.PREFERRED_SIZE, 26, GroupLayout.PREFERRED_SIZE).addGap(14).addComponent(descTXT, GroupLayout.PREFERRED_SIZE, 86, GroupLayout.PREFERRED_SIZE).addGap(32).addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(btnNewButton).addComponent(btnNewButton_1)).addContainerGap(44, Short.MAX_VALUE)));getContentPane().setLayout(groupLayout);//初始化下拉框:fillFoodType();}//重置事件處理:private void FoodResetActionPerformed(ActionEvent evt) {// TODO Auto-generated method stubresetValue();}//菜品添加事件處理:private void FoodAddActionPerformed(ActionEvent evt) {// TODO Auto-generated method stubString name = this.nameTXT.getText();String storage = this.storageTXT.getText();String price = this.priceTXT.getText();String desc = this.descTXT.getText();if(StringUtil.isEmpty(name)) {JOptionPane.showMessageDialog(null, "菜品名稱不能為空!!");return;}if(StringUtil.isEmpty(storage)) {JOptionPane.showMessageDialog(null, "菜品儲備不能為空!!");return;}if(StringUtil.isEmpty(price)) {JOptionPane.showMessageDialog(null, "菜品售價不能為空!!");return;}FoodType foodtype = (FoodType)foodtypeCB.getSelectedItem();int foodtype_id = foodtype.getFoodtype_id();Connection conn = null;try {Food food = new Food(name,Integer.parseInt(storage),Float.parseFloat(price),foodtype_id,desc);conn = jdbctest.getCon();int addNUM = fooddao.add(conn, food);if(addNUM == 1) {JOptionPane.showMessageDialog(null, "菜品添加成功!!");resetValue();}else {JOptionPane.showMessageDialog(null, "菜品添加失敗!!");}}catch(Exception e) {e.printStackTrace();JOptionPane.showMessageDialog(null, "菜品添加失敗!!");}finally {try {jdbctest.closeCon(conn);} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}}}//清空表單private void resetValue() {this.nameTXT.setText("");this.storageTXT.setText("");this.priceTXT.setText("");this.descTXT.setText("");//關于菜品類別有:當沒有類別時的處理if(this.foodtypeCB.getItemCount()>0) {this.foodtypeCB.setSelectedIndex(0);}}//初始化菜品類別下拉框:private void fillFoodType() {Connection conn = null;FoodType foodtype = null;try {conn = jdbctest.getCon();ResultSet rs = foodtypedao.list(conn, new FoodType());while(rs.next()) {foodtype = new FoodType();foodtype.setFoodtype_id(rs.getInt("foodtype_id"));foodtype.setFoodtype_name(rs.getString("foodtype_name"));//需要對方法進行重寫:this.foodtypeCB.addItem(foodtype);//不直接將字符串傳進去是因為傳一個對象進去可以獲得對應的ID}}catch(Exception e) {e.printStackTrace();}finally {try {jdbctest.closeCon(conn);} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}}} }

6.關于菜品信息管理界面FoodManageInterFirm設計的代碼:

import java.awt.EventQueue; import java.awt.Font; import java.sql.Connection; import java.sql.ResultSet; import java.util.Vector;import javax.swing.GroupLayout; import javax.swing.GroupLayout.Alignment; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JInternalFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JTextField; import javax.swing.LayoutStyle.ComponentPlacement; import javax.swing.border.LineBorder; import javax.swing.border.TitledBorder; import javax.swing.table.DefaultTableModel;import jdbc.dao.FoodDao; import jdbc.dao.FoodTypeDao; import jdbc.model.Food; import jdbc.model.FoodType; import jdbc.utils.JDBCtest; import jdbc.utils.StringUtil;import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.Color; import javax.swing.ImageIcon; import javax.swing.JTextArea; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent;public class FoodManageInterFirm extends JInternalFrame {private JTable foodtable;private JTextField s_nameTXT;private JComboBox s_typeCB;private JTextArea fooddescTXT;private JComboBox foodtypeCB;private JDBCtest jdbctest = new JDBCtest();private FoodTypeDao foodtypedao = new FoodTypeDao();private FoodDao fooddao = new FoodDao();private JTextField foodidTXT;private JTextField foodnameTXT;private JTextField foodstorageTXT;private JTextField foodpriceTXT;/*** Launch the application.*/public static void main(String[] args) {EventQueue.invokeLater(new Runnable() {public void run() {try {FoodManageInterFirm frame = new FoodManageInterFirm();frame.setVisible(true);} catch (Exception e) {e.printStackTrace();}}});}/*** Create the frame.*/public FoodManageInterFirm() {getContentPane().setBackground(new Color(255, 99, 71));setIconifiable(true);setClosable(true);setTitle("\u83DC\u54C1\u7BA1\u7406");setBounds(100, 100, 674, 570);JScrollPane scrollPane = new JScrollPane();JPanel panel = new JPanel();panel.setForeground(new Color(255, 255, 255));panel.setBackground(new Color(255, 99, 71));panel.setBorder(new TitledBorder(null, "\u641C\u7D22\u6761\u4EF6", TitledBorder.LEADING, TitledBorder.TOP, null, null));JPanel panel_1 = new JPanel();panel_1.setBackground(new Color(255, 99, 71));panel_1.setBorder(new TitledBorder(null, "\u8868\u5355\u64CD\u4F5C", TitledBorder.LEADING, TitledBorder.TOP, null, null));GroupLayout groupLayout = new GroupLayout(getContentPane());groupLayout.setHorizontalGroup(groupLayout.createParallelGroup(Alignment.LEADING).addGroup(groupLayout.createSequentialGroup().addGap(21).addGroup(groupLayout.createParallelGroup(Alignment.TRAILING, false).addComponent(panel_1, Alignment.LEADING, 0, 0, Short.MAX_VALUE).addComponent(panel, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(scrollPane, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 628, Short.MAX_VALUE)).addGap(44)));groupLayout.setVerticalGroup(groupLayout.createParallelGroup(Alignment.LEADING).addGroup(groupLayout.createSequentialGroup().addGap(25).addComponent(panel, GroupLayout.PREFERRED_SIZE, 60, GroupLayout.PREFERRED_SIZE).addPreferredGap(ComponentPlacement.RELATED).addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 169, GroupLayout.PREFERRED_SIZE).addGap(18).addComponent(panel_1, GroupLayout.DEFAULT_SIZE, 198, Short.MAX_VALUE).addContainerGap()));JLabel lblNewLabel_2 = new JLabel("\u83DC\u54C1\u7F16\u53F7\uFF1A");lblNewLabel_2.setIcon(new ImageIcon("C:\\Users\\86135\\eclipse-workspace\\ResturantOrder\\src\\images\\\u7F16\u53F7.png"));lblNewLabel_2.setForeground(new Color(255, 255, 255));lblNewLabel_2.setFont(new Font("等線 Light", Font.PLAIN, 16));foodidTXT = new JTextField();foodidTXT.setEditable(false);foodidTXT.setColumns(10);JLabel lblNewLabel_3 = new JLabel("\u83DC\u54C1\u540D\u79F0\uFF1A");lblNewLabel_3.setIcon(new ImageIcon("C:\\Users\\86135\\eclipse-workspace\\ResturantOrder\\src\\images\\\u8FA3\u6912.png"));lblNewLabel_3.setForeground(new Color(255, 255, 255));lblNewLabel_3.setFont(new Font("等線 Light", Font.PLAIN, 16));foodnameTXT = new JTextField();foodnameTXT.setColumns(10);JLabel lblNewLabel_4 = new JLabel("\u83DC\u54C1\u50A8\u5907\uFF1A");lblNewLabel_4.setIcon(new ImageIcon("C:\\Users\\86135\\eclipse-workspace\\ResturantOrder\\src\\images\\\u50A8\u91CF.png"));lblNewLabel_4.setFont(new Font("等線 Light", Font.PLAIN, 16));lblNewLabel_4.setForeground(new Color(255, 255, 255));foodstorageTXT = new JTextField();foodstorageTXT.setColumns(10);JLabel lblNewLabel_5 = new JLabel("\u83DC\u54C1\u552E\u4EF7\uFF1A");lblNewLabel_5.setIcon(new ImageIcon("C:\\Users\\86135\\eclipse-workspace\\ResturantOrder\\src\\images\\\u552E\u4EF7.png"));lblNewLabel_5.setForeground(new Color(255, 255, 255));lblNewLabel_5.setFont(new Font("等線 Light", Font.PLAIN, 16));foodpriceTXT = new JTextField();foodpriceTXT.setColumns(10);JLabel lblNewLabel_6 = new JLabel("\u83DC\u54C1\u7C7B\u522B\uFF1A");lblNewLabel_6.setIcon(new ImageIcon("C:\\Users\\86135\\eclipse-workspace\\ResturantOrder\\src\\images\\\u83DC\u54C1\u7C7B\u522B.png"));lblNewLabel_6.setForeground(new Color(255, 255, 255));lblNewLabel_6.setFont(new Font("等線 Light", Font.PLAIN, 16));foodtypeCB = new JComboBox();JLabel lblNewLabel_7 = new JLabel("\u83DC\u54C1\u63CF\u8FF0\uFF1A");lblNewLabel_7.setIcon(new ImageIcon("C:\\Users\\86135\\eclipse-workspace\\ResturantOrder\\src\\images\\\u7F8E\u98DF.png"));lblNewLabel_7.setForeground(new Color(255, 255, 255));lblNewLabel_7.setFont(new Font("等線 Light", Font.PLAIN, 16));fooddescTXT = new JTextArea();//文本域加邊框:fooddescTXT.setBorder(new LineBorder(new java.awt.Color(127,157,185),1,false));JButton btnNewButton_1 = new JButton("\u4FEE\u6539");btnNewButton_1.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {foodUpdateActionPerformed(e);}});btnNewButton_1.setIcon(new ImageIcon("C:\\Users\\86135\\eclipse-workspace\\ResturantOrder\\src\\images\\\u4FEE\u6539.png"));btnNewButton_1.setFont(new Font("等線 Light", Font.PLAIN, 16));JButton btnNewButton_2 = new JButton("\u5220\u9664");btnNewButton_2.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {foodDeleteActionPerformed(e);}});btnNewButton_2.setIcon(new ImageIcon("C:\\Users\\86135\\eclipse-workspace\\ResturantOrder\\src\\images\\\u5220\u96642.png"));btnNewButton_2.setForeground(new Color(0, 0, 0));btnNewButton_2.setFont(new Font("等線 Light", Font.PLAIN, 16));GroupLayout gl_panel_1 = new GroupLayout(panel_1);gl_panel_1.setHorizontalGroup(gl_panel_1.createParallelGroup(Alignment.LEADING).addGroup(gl_panel_1.createSequentialGroup().addContainerGap().addGroup(gl_panel_1.createParallelGroup(Alignment.TRAILING, false).addComponent(lblNewLabel_7, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(lblNewLabel_5, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(lblNewLabel_2, Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 82, Short.MAX_VALUE)).addPreferredGap(ComponentPlacement.RELATED).addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING).addGroup(Alignment.TRAILING, gl_panel_1.createSequentialGroup().addComponent(btnNewButton_1, GroupLayout.PREFERRED_SIZE, 97, GroupLayout.PREFERRED_SIZE).addPreferredGap(ComponentPlacement.RELATED, 218, Short.MAX_VALUE).addComponent(btnNewButton_2, GroupLayout.PREFERRED_SIZE, 97, GroupLayout.PREFERRED_SIZE).addGap(175)).addGroup(gl_panel_1.createSequentialGroup().addGroup(gl_panel_1.createParallelGroup(Alignment.TRAILING).addGroup(gl_panel_1.createSequentialGroup().addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING).addGroup(gl_panel_1.createSequentialGroup().addComponent(foodidTXT, GroupLayout.PREFERRED_SIZE, 53, GroupLayout.PREFERRED_SIZE).addGap(31).addComponent(lblNewLabel_3)).addComponent(foodpriceTXT, GroupLayout.PREFERRED_SIZE, 115, GroupLayout.PREFERRED_SIZE)).addPreferredGap(ComponentPlacement.RELATED).addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING).addGroup(gl_panel_1.createSequentialGroup().addComponent(lblNewLabel_6).addPreferredGap(ComponentPlacement.RELATED).addComponent(foodtypeCB, GroupLayout.PREFERRED_SIZE, 91, GroupLayout.PREFERRED_SIZE)).addGroup(gl_panel_1.createSequentialGroup().addComponent(foodnameTXT, GroupLayout.PREFERRED_SIZE, 98, GroupLayout.PREFERRED_SIZE).addGap(18).addComponent(lblNewLabel_4).addPreferredGap(ComponentPlacement.RELATED).addComponent(foodstorageTXT, GroupLayout.DEFAULT_SIZE, 65, Short.MAX_VALUE)))).addComponent(fooddescTXT, Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 483, GroupLayout.PREFERRED_SIZE)).addGap(104)))));gl_panel_1.setVerticalGroup(gl_panel_1.createParallelGroup(Alignment.LEADING).addGroup(gl_panel_1.createSequentialGroup().addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE).addComponent(lblNewLabel_2, GroupLayout.PREFERRED_SIZE, 29, GroupLayout.PREFERRED_SIZE).addComponent(foodidTXT, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(lblNewLabel_3, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE).addComponent(foodnameTXT, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(lblNewLabel_4, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE).addComponent(foodstorageTXT, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addPreferredGap(ComponentPlacement.UNRELATED).addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE).addComponent(lblNewLabel_5).addComponent(foodpriceTXT, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(lblNewLabel_6).addComponent(foodtypeCB, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addPreferredGap(ComponentPlacement.UNRELATED).addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING).addComponent(lblNewLabel_7).addComponent(fooddescTXT, GroupLayout.PREFERRED_SIZE, 48, GroupLayout.PREFERRED_SIZE)).addGap(40).addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE).addComponent(btnNewButton_2).addComponent(btnNewButton_1)).addContainerGap(43, Short.MAX_VALUE)));panel_1.setLayout(gl_panel_1);JLabel lblNewLabel = new JLabel("\u83DC\u54C1\u540D\u79F0\uFF1A");lblNewLabel.setIcon(new ImageIcon("C:\\Users\\86135\\eclipse-workspace\\ResturantOrder\\src\\images\\\u8FA3\u6912.png"));lblNewLabel.setForeground(new Color(255, 255, 255));lblNewLabel.setFont(new Font("等線 Light", Font.PLAIN, 16));s_nameTXT = new JTextField();s_nameTXT.setColumns(10);JLabel lblNewLabel_1 = new JLabel("\u83DC\u54C1\u7C7B\u522B\uFF1A");lblNewLabel_1.setIcon(new ImageIcon("C:\\Users\\86135\\eclipse-workspace\\ResturantOrder\\src\\images\\\u83DC\u54C1\u7C7B\u522B.png"));lblNewLabel_1.setForeground(new Color(255, 255, 255));lblNewLabel_1.setFont(new Font("等線 Light", Font.PLAIN, 16));s_typeCB = new JComboBox();JButton btnNewButton = new JButton("\u67E5\u8BE2");btnNewButton.setIcon(new ImageIcon("C:\\Users\\86135\\eclipse-workspace\\ResturantOrder\\src\\images\\\u67E5\u8BE2.png"));btnNewButton.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {FoodSearchActionPerformed(e);}});btnNewButton.setFont(new Font("等線 Light", Font.PLAIN, 16));GroupLayout gl_panel = new GroupLayout(panel);gl_panel.setHorizontalGroup(gl_panel.createParallelGroup(Alignment.LEADING).addGroup(gl_panel.createSequentialGroup().addContainerGap().addComponent(lblNewLabel).addPreferredGap(ComponentPlacement.RELATED).addComponent(s_nameTXT, GroupLayout.PREFERRED_SIZE, 90, GroupLayout.PREFERRED_SIZE).addGap(18).addComponent(lblNewLabel_1).addPreferredGap(ComponentPlacement.RELATED).addComponent(s_typeCB, GroupLayout.PREFERRED_SIZE, 97, GroupLayout.PREFERRED_SIZE).addPreferredGap(ComponentPlacement.RELATED, 15, Short.MAX_VALUE).addComponent(btnNewButton, GroupLayout.PREFERRED_SIZE, 97, GroupLayout.PREFERRED_SIZE).addContainerGap()));gl_panel.setVerticalGroup(gl_panel.createParallelGroup(Alignment.LEADING).addGroup(gl_panel.createSequentialGroup().addGroup(gl_panel.createParallelGroup(Alignment.BASELINE).addComponent(lblNewLabel, GroupLayout.DEFAULT_SIZE, 23, Short.MAX_VALUE).addComponent(s_nameTXT, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(lblNewLabel_1).addComponent(s_typeCB, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(btnNewButton)).addContainerGap()));panel.setLayout(gl_panel);foodtable = new JTable();foodtable.addMouseListener(new MouseAdapter() {@Overridepublic void mousePressed(MouseEvent me) {foodTableMousePressed(me);}});foodtable.setFont(new Font("等線 Light", Font.PLAIN, 14));foodtable.setModel(new DefaultTableModel(new Object[][] {},new String[] {"\u83DC\u54C1\u7F16\u53F7", "\u83DC\u54C1\u540D\u79F0", "\u83DC\u54C1\u50A8\u5907", "\u83DC\u54C1\u552E\u4EF7", "\u83DC\u54C1\u7C7B\u522B\u7F16\u53F7", "\u83DC\u54C1\u63CF\u8FF0", "\u83DC\u54C1\u7C7B\u522B\u540D\u79F0"}));foodtable.getColumnModel().getColumn(0).setPreferredWidth(63);foodtable.getColumnModel().getColumn(1).setPreferredWidth(61);foodtable.getColumnModel().getColumn(2).setPreferredWidth(59);foodtable.getColumnModel().getColumn(3).setPreferredWidth(61);foodtable.getColumnModel().getColumn(4).setPreferredWidth(86);foodtable.getColumnModel().getColumn(6).setPreferredWidth(84);scrollPane.setViewportView(foodtable);getContentPane().setLayout(groupLayout);this.fillFoodType("search");this.fillFoodType("modify");this.fillTable(new Food());}//菜品刪除事件處理private void foodDeleteActionPerformed(ActionEvent evt) {// TODO Auto-generated method stubString id = foodidTXT.getText();if(StringUtil.isEmpty(id)) {JOptionPane.showMessageDialog(null, "請選擇要刪除的記錄!!");return;}int n = JOptionPane.showConfirmDialog(null, "確定要刪除該記錄嗎?");if( n == 0) {Connection conn = null;try {conn = JDBCtest.getCon();int deleteNUM = fooddao.delete(conn, id);//JOptionPane.showMessageDialog(null, deleteNUM);if(deleteNUM != 0) {JOptionPane.showMessageDialog(null, "刪除成功!!");this.resetValue();this.fillTable(new Food());}else {JOptionPane.showMessageDialog(null, "刪除失敗!!");}}catch(Exception e) {e.printStackTrace();JOptionPane.showMessageDialog(null, "刪除失敗!!");}finally {try {JDBCtest.closeCon(conn);} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}}}}//修改菜品信息事件處理:private void foodUpdateActionPerformed(ActionEvent evt) {// TODO Auto-generated method stubString name = this.foodnameTXT.getText();String storage = this.foodstorageTXT.getText();String price = this.foodpriceTXT.getText();String desc = this.fooddescTXT.getText();String id = this.foodidTXT.getText();if(StringUtil.isEmpty(id)) {JOptionPane.showMessageDialog(null, "請選擇要修改的記錄!!");return;}if(StringUtil.isEmpty(storage)) {JOptionPane.showMessageDialog(null, "菜品儲備不能為空!!");return;}if(StringUtil.isEmpty(price)) {JOptionPane.showMessageDialog(null, "菜品售價不能為空!!");return;}if(StringUtil.isEmpty(name)) {JOptionPane.showMessageDialog(null, "菜品名稱不能為空!!");return;}FoodType foodtype = (FoodType)foodtypeCB.getSelectedItem();int typeid = foodtype.getFoodtype_id();Food food = new Food(Integer.parseInt(id),name,Integer.parseInt(storage),Float.parseFloat(price),typeid,desc);Connection conn = null;try {conn = jdbctest.getCon();int addNUM = fooddao.update(conn, food);if(addNUM == 1) {JOptionPane.showMessageDialog(null, "菜品修改成功!!");resetValue();this.fillTable(new Food());}else {JOptionPane.showMessageDialog(null, "菜品修改失敗!!");}}catch(Exception e) {e.printStackTrace();JOptionPane.showMessageDialog(null, "菜品修改失敗!!");}finally {try {jdbctest.closeCon(conn);} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}}}//重置表單事件:private void resetValue() {// TODO Auto-generated method stubthis.foodidTXT.setText("");this.foodnameTXT.setText("");this.foodstorageTXT.setText("");this.foodpriceTXT.setText("");this.fooddescTXT.setText("");//關于菜品類別有:當沒有類別時的處理if(this.foodtypeCB.getItemCount()>0) {this.foodtypeCB.setSelectedIndex(0);}}//表格行的鼠標點擊事件處理:private void foodTableMousePressed(MouseEvent me) {// TODO Auto-generated method stubint row = this.foodtable.getSelectedRow();this.foodidTXT.setText((String)foodtable.getValueAt(row, 0));this.foodnameTXT.setText((String)foodtable.getValueAt(row, 1));this.foodstorageTXT.setText((String)foodtable.getValueAt(row, 2));this.foodpriceTXT.setText((String)foodtable.getValueAt(row, 3));this.fooddescTXT.setText((String)foodtable.getValueAt(row, 5));String foodtypename = (String)this.foodtable.getValueAt(row, 6);int n = this.foodtypeCB.getItemCount();for(int i=0;i<n;i++) {FoodType item = (FoodType)this.foodtypeCB.getItemAt(i);if(item.getFoodtype_name().equals(foodtypename)) {this.foodtypeCB.setSelectedIndex(i);}}}//菜品搜索查詢事件處理:private void FoodSearchActionPerformed(ActionEvent evt) {// TODO Auto-generated method stubString foodname = s_nameTXT.getText();FoodType foodtype = (FoodType) this.s_typeCB.getSelectedItem();int foodtypeid = foodtype.getFoodtype_id();Food food = new Food(foodname,foodtypeid);this.fillTable(food);}//填充一個下拉框:private void fillFoodType(String type) {Connection conn = null;try {conn = jdbctest.getCon();ResultSet rs = foodtypedao.list(conn, new FoodType());if("search".equals(type)) {FoodType foodtype = new FoodType();foodtype.setFoodtype_name("請選擇...");foodtype.setFoodtype_id(-1);this.s_typeCB.addItem(foodtype);}while(rs.next()) {FoodType foodtype = new FoodType();foodtype.setFoodtype_name(rs.getString("foodtype_name"));foodtype.setFoodtype_id(rs.getInt("foodtype_id"));//分兩種情況:if("search".equals(type)) {this.s_typeCB.addItem(foodtype);}else if("modify".equals(type)) {this.foodtypeCB.addItem(foodtype);}}}catch(Exception e) {e.printStackTrace();}finally {try {jdbctest.closeCon(conn);} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}}}//初始化表格數據:private void fillTable(Food food) {//初始化:清空表格DefaultTableModel dtm =(DefaultTableModel) foodtable.getModel();//表格設置成0行:dtm.setRowCount(0);Connection conn = null;try {conn = jdbctest.getCon();ResultSet rs = fooddao.list(conn, food);while(rs.next()) {Vector v = new Vector();v.add(rs.getString("food_id"));v.add(rs.getString("food_name"));v.add(rs.getString("food_storage"));v.add(rs.getString("food_price"));v.add(rs.getString("food_typeid"));v.add(rs.getString("food_desc"));v.add(rs.getString("foodtype_name"));dtm.addRow(v);}}catch(Exception e) {e.printStackTrace();}finally {try {jdbctest.closeCon(conn);} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}}} }

總結

以上是生活随笔為你收集整理的西工大数据库实验大作业 火锅店菜品管理系统的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 亚洲第一区av | 丝袜制服中文字幕 | 天堂va蜜桃一区 | 成人在线天堂 | 成人精品毛片 | 嫩草视频在线免费观看 | 无码人妻久久一区二区三区蜜桃 | 日本一区中文字幕 | 精品久久久久久久久中文字幕 | 中文字幕无码毛片免费看 | 伊人网中文字幕 | 中文在线√天堂 | 亚洲天堂资源网 | 一个人看的视频www 色就是色网站 | 亚洲色中色 | 好色视频tv | 男人天堂网站 | 欧美黑人多人双交 | 激情久久网站 | 白丝动漫美女 | av观看国产| 欧美日韩在线国产 | 色吧综合网 | 色噜噜亚洲 | 中文天堂在线观看 | 奇米综合 | 欧美激情三区 | 在线中文字幕播放 | 人妻少妇精品一区二区 | 欧美另类xxxx | 黑人玩弄人妻一区二区三区影院 | 精品国产乱码久久久人妻 | 最新av网址在线观看 | 成人精品福利视频 | 在线视频 亚洲 | 朝鲜美女黑毛bbw | 精品久久久久久亚洲综合网站 | 国产中文字幕在线视频 | 九色在线播放 | 亚洲v| 免费中文字幕视频 | a级在线播放 | 国产精品成人va在线观看 | 日本色中色 | 亚洲国产精品一区二区久久hs | 久久精品一本 | 国产精品日本一区二区在线播放 | 久草视频在线免费看 | 国产成人精品一区二区三区四区 | 少妇黄色片 | 91精品国产91久久久久青草 | 久久九九精品 | 欧美成人激情 | 人人插人人插 | 日韩人妻无码精品综合区 | 日本一二三区视频在线 | 日本久久成人 | www.国产视频 | 91视频分类| 久色视频在线 | 久久亚洲AV无码专区成人国产 | 久久一区视频 | 99精品无码一区二区 | 无码人妻久久一区二区三区不卡 | 俄罗斯黄色大片 | 波多野结衣视频免费看 | 咪咪色图 | 欧美精品一二三区 | 欧美日韩1区 | 秋霞国产午夜精品免费视频 | 成人h片在线观看 | 亚洲精品视频在线观看免费 | 97干在线 | 国产精品xxxx喷水欧美 | 我爱av好色| 欧美粗暴jizz性欧美20 | 被两个男人吃奶三p爽文 | 国产露出视频 | 欧美人体视频一区二区三区 | 68日本xxxxxⅹxxx22 | 国产操女人 | 国产大片一区二区三区 | 欧美人与性动交xxⅹxx | 一本大道熟女人妻中文字幕在线 | 日本在线精品 | 国产精品久久久久久久妇 | av一区二区在线播放 | 波波野结衣 | 成人综合社区 | 国产成人91 | 美丽姑娘免费观看在线观看 | 亚洲动漫精品 | a少妇| 日产精品久久久一区二区 | 国产av一区不卡 | 欧美性做爰猛烈叫床潮 | 欧美日韩一区二区精品 | 天天干天天玩 | wwwxxx日本免费 |