数据库设计
1、要求
(1)绘制所建数据库的E-R模型图
(2)表(实体表和关联表)结构的设计
(3)录入数据的表(每个表5条记录即可)
(4)说明组内分工
2、设计内容
所设计数据库是订餐系统数据库。
此次试验设计的是一款点餐系统,系统主要分为 Admin 和 User 两大部分。
Admin 部分主要可以进行查看订单、对点餐系统的维护管理、添加套餐组合与修改管理员信息操作。
User 部分进行的是用户的操作,新用户可以通过系统注册用户个人信息,注册成功的用户可以通过点餐系统进行用户信息的修改、点餐、个人订单信息的查询操作。
这套系统是为了方便餐厅管理和用户点餐而设计的。我们通过使用 Mysql 设计了系统所需的表,
运用 Navicat 从 Mysql 数据库中调用相关数据,通过 JDBC 连接。
运用 myeclipse 中的 JAVA 可视化界面开发插件 Matisse 开发 UI 界面。
Java 点餐系统中一共四个包:dbconnection、dao、model 和 view。
作用分别为连接数据库;对数据库中的数据进行处理;获取数据库数据以及给用户展示界面并提示用户进行相应的操作。
在进行实际应用操作情景中,根据用户输入的登陆信息,系统会判断使用者是管理员还是普通用户(管理员的信息中 id 系统后台默认的以分辨,登陆界面中注册时没有权限注册管理员,全部为用户id),view 中的类将根据用户的触发项进行相应的页面转跳操作,view 中不同的类会根据用户的操作同
时调用其对应 dao 和 model 包中的类进行操作。
(1)E-R模型
goods表:
Id,goodsName,price,goodsDesc,imageLink
user表:
Id,userName,password,email,rank
order_info表:
orderId,orderStatus,orderNum,orderTotalMoney,userName
order_goods表:
Id,orderld,goodsTotalPrice,goodsId,goodsPrice,goodsNum,goodsName
(2)所有表的设计视图
goods表包含id,goodsName,price,goodsDesc,imageLink
其中id为主键。
CREATE TABLE `goods` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`goodsName` varchar(100) DEFAULT NULL,
`price` float DEFAULT NULL,
`goodsDesc` varchar(200) DEFAULT NULL,
`imageLink` varchar(500) DEFAULT NULL,
PRIMARY KEY (`id`));
insert into `goods`(`id`,`goodsName`,`price`,`goodsDesc`,`imageLink`)
values (3,'宫保鸡丁',21,'宫保鸡丁哦','E:\java\eclipse\'),
(5,'青椒肉丝',22,'青椒肉丝不好吃','E:\java\eclipse\'),
(8,'麻婆豆腐',2,'香辣丝滑','E:\java\eclipse\’),
(9,'鱼香肉丝',9,'四川风味','E:\java\eclipse\'),
(10,'回锅肉',12,NULL,NULL),
(11,'热狗肠',32,'说的','E:\java\eclipse\');
user表包含id,userName,password,email,rank
其中id为主键。
CREATE TABLE `user` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`userName` varchar(100) DEFAULT NULL,
`password` varchar(50) DEFAULT NULL,
`email` varchar(200) DEFAULT NULL,
`rank` int(1) DEFAULT '0',
PRIMARY KEY (`id`));
insert into `user`(`id`,`userName`,`password`,`email`,`rank`)
values
(1,'admin','123',NULL,1),
(8,'aaa','123','ad@1.com',0),
(9,'admin1','123',NULL,0);
order_info表包含orderId,orderStatus,orderNum,orderTotalMoney,userName
其主键为orderId。
CREATE TABLE `order_info` (
`orderId` varchar(50) NOT NULL,`orderStatus` int(10) DEFAULT NULL,
`orderNum` int(10) DEFAULT NULL,`orderTotalMoney` float DEFAULT NULL,
`userName` varchar(100) DEFAULT NULL,PRIMARY KEY (`orderId`));
insert into
`order_info`(`orderId`,`orderStatus`,`orderNum`,`orderTotalMoney`,`userName`)
values ('20130708001514',3,1,12,'admin1'),
('20130708021437',1,1,12,'admin1'),('20130708110510',2,2,31,'aaa'),
('20130708110513',3,2,44,'aaa'),('20130708115503',1,1,2,'admin1'),
('20130708115508',4,2,44,'admin1'),('20130708115512',3,1,22,'admin1'),
('20130708121456',4,1,9,'admin1');
order_goods表包含id,orderld,goodsTotalPrice,goodsId,goodsPrice,goodsNum,goodsName
其中主键为id。
CREATE TABLE `order_goods` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`orderId` varchar(50) DEFAULT NULL,
`goodsTotalPrice` float DEFAULT NULL,
`goodsId` int(10) DEFAULT NULL,
`goodsPrice` float DEFAULT NULL,
`goodsNum` int(10) DEFAULT NULL,
`goodsName` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FK_order_goods_2` (`orderId`),
KEY `FK_order_goods_1` (`goodsId`),
CONSTRAINT `FK_order_goods_1` FOREIGN KEY
(`goodsId`) REFERENCES `goods` (`id`),
CONSTRAINT `FK_order_goods_2` FOREIGN KEY
(`orderId`) REFERENCES `order_info` (`orderId`)
);
Insert into
`order_goods`(`id`,`orderId`,`goodsTotalPrice`,`goodsId`,`goodsPrice`,`goodsNum`,`goodsName`)
values (23,'20130708001514',12,10,12,1,'回锅肉'),
(28,'20130708021437',12,10,12,1,'回锅肉'),
(31,'20130708110510',22,5,22,1,'青椒肉丝'),
(32,'20130708110510',9,9,9,1,'鱼香肉丝'),
(33,'20130708110513',12,10,12,1,'回锅肉'),
(34,'20130708110513',32,11,32,1,'热狗肠'),
(39,'20130708115503',2,8,2,1,'麻婆豆腐'),
(40,'20130708115508',12,10,12,1,'回锅肉'),
(41,'20130708115508',32,11,32,1,'热狗肠'),
(42,'20130708115512',22,5,22,1,'青椒肉丝'),
(43,'20130708121456',9,9,9,1,'鱼香肉丝');
Java 程序设计部分
sut.rj.dao
GoodsDao
package sut.rj.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import sut.rj.model.Goods;
import sut.rj.dbconnection.StringUtil;
@SuppressWarnings("unused")
public class GoodsDao {
public int GoodsAdd(Connection con,Goods goods) throws Exception{
String sql="insert into goods values(null,?,?,?,?)";
PreparedStatement pstmt=con.prepareStatement(sql);
pstmt.setString(1, goods.getGoodsName());
pstmt.setFloat(2, goods.getPrice());
pstmt.setString(3, goods.getGoodsDesc());
pstmt.setString(4, goods.getImageLink());
return pstmt.executeUpdate();
}
public ResultSet goodsList(Connection con,Goods goods) throws Exception{
StringBuffer sb=new StringBuffer("select * from `goods`");
if(StringUtil.isNotEmpty(goods.getGoodsName())){
sb.append(" and goodsName like '%"+goods.getGoodsName()+"%'");
}
if((goods.getPrice1()!=0)&&(goods.getPrice()==0) ){//低价格有,高价格无
sb.append(" and price>="+goods.getPrice1());
}else if(goods.getPrice()>goods.getPrice1()){//中间价格
sb.append(" and price between "+goods.getPrice1()+" and "+goods.getPrice());
}
else if((goods.getPrice()!=0)){//高价格有,低价格无或者和高价格一样
sb.append(" and price<="+goods.getPrice());
}
if(goods.getId()!=0){
sb.append(" and id="+goods.getId());
}
//System.out.println(sb.toString().replaceFirst("and", "where"));
PreparedStatement pstmt=con.prepareStatement(sb.toString().replaceFirst("and", "where"));
return pstmt.executeQuery();
}
public int goodsDelete(Connection con,String id) throws Exception{
String sql="delete from goods where id=?";
PreparedStatement pstmt=con.prepareStatement(sql);
pstmt.setString(1, id);
return pstmt.executeUpdate();
}
public int goodsModify(Connection con,Goods goods) throws Exception{
String sql="update goods set goodsName=?,goodsDesc=?,price=?,imageLink=? where id=?";
PreparedStatement pstmt=con.prepareStatement(sql);
pstmt.setString(1, goods.getGoodsName());
pstmt.setString(2, goods.getGoodsDesc());
pstmt.setFloat(3, goods.getPrice());
pstmt.setString(4, goods.getImageLink());
pstmt.setInt(5, goods.getId());
return pstmt.executeUpdate();
}}
OrderDao
package sut.rj.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import sut.rj.model.Order;
import sut.rj.dbconnection.StringUtil;
@SuppressWarnings("unused")
public class OrderDao {
public int order_goodsAdd(Connection con ,Order order) throws Exception{
String sql="insert into `order_goods` values(null,?,?,?,?,?,?)";
PreparedStatement pstmt=con.prepareStatement(sql);
pstmt.setString(1, order.getOrderId());
pstmt.setFloat(2, order.getGoodsTotalPrice());
pstmt.setInt(3, order.getGoodsId());
pstmt.setFloat(4, order.getGoodsPrice());
pstmt.setInt(5, order.getGoodsNum());
pstmt.setString(6, order.getGoodsName());
return pstmt.executeUpdate();
}
public int order_infoAdd(Connection con ,Order order) throws Exception{
String sql="insert into `order_info` values(?,?,?,?,?)";
PreparedStatement pstmt=con.prepareStatement(sql);
pstmt.setString(1, order.getOrderId());
pstmt.setInt(2, order.getOrderStatus());
pstmt.setInt(3, order.getOrderNum());
pstmt.setFloat(4, order.getOrderTotalMoney());
pstmt.setString(5, order.getUserName());
return pstmt.executeUpdate();
}
public ResultSet orderList(Connection con,Order order) throws Exception{
StringBuffer sb=new StringBuffer("select * from `order_info`");
if(StringUtil.isNotEmpty(order.getOrderId())){
sb.append(" and orderId like '%"+order.getOrderId()+"%'");
}
if(StringUtil.isNotEmpty(order.getUserName())){
sb.append(" and userName like '%"+order.getUserName()+"%'");
}
PreparedStatement pstmt=con.prepareStatement(sb.toString().replaceFirst("and", "where"));
return pstmt.executeQuery();
}
public ResultSet orderGoodsList(Connection con,Order order) throws Exception{
StringBuffer sb=new StringBuffer("select * from `order_goods`");
if(StringUtil.isNotEmpty(order.getOrderId())){
sb.append(" and orderId like '%"+order.getOrderId()+"%'");
}
PreparedStatement pstmt=con.prepareStatement(sb.toString().replaceFirst("and", "where"));
return pstmt.executeQuery();
}
public int orderStatusModify(Connection con,Order order) throws Exception{
String sql="update order_info set orderStatus=? where orderId=?";
PreparedStatement pstmt=con.prepareStatement(sql);
pstmt.setInt(1, order.getOrderStatus());
pstmt.setString(2, order.getOrderId());
return pstmt.executeUpdate();
}//同时删除order_goods和irder_info两张表里的有关orderId的数据 删除顺序要保证主外键关联顺序,不可以互换顺序
public int deleteOrder(Connection con,Order order) throws Exception{
String sql="delete from order_goods where orderId=?";
PreparedStatement pstmt1=con.prepareStatement(sql);
pstmt1.setString(1, order.getOrderId());
pstmt1.executeUpdate();
sql="delete from order_info where orderId=?";
PreparedStatement pstmt2=con.prepareStatement(sql);
pstmt2.setString(1, order.getOrderId());
return pstmt2.executeUpdate();}}
UserDao
package sut.rj.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import sut.rj.model.User;
import sut.rj.dbconnection.StringUtil;
@SuppressWarnings("unused")
public class UserDao {
/**
* 登陆验证
* @param con
* @param user
* @return
* @throws Exception
*/
public User login(Connection con,User user) throws Exception{
User resultUser = null;
String sql="select *from user where userName=? and password=?";
PreparedStatement pstmt=con.prepareStatement(sql);
pstmt.setString(1, user.getUserName());
pstmt.setString(2, user.getPassword());
ResultSet rs=pstmt.executeQuery();
if(rs.next()){
resultUser = new User();
resultUser.setUserName(rs.getString("userName"));
resultUser.setPassword(rs.getString("password"));
resultUser.setRank(rs.getInt("rank"));
resultUser.setId(rs.getInt("id"));
}
return resultUser;
}
public int userAdd(Connection con,User user) throws Exception{
String sql="insert into `user` values(null,?,?,?,?)";
PreparedStatement pstmt=con.prepareStatement(sql);
pstmt.setString(1, user.getUserName());
pstmt.setString(2, user.getPassword());
pstmt.setString(3, user.getEmail());
pstmt.setInt(4, user.getRank());
return pstmt.executeUpdate();
}
public boolean isUserExist(Connection con,User user) throws Exception{
String sql="select *from user where userName=?";
PreparedStatement pstmt=con.prepareStatement(sql);
pstmt.setString(1, user.getUserName());
ResultSet rs =pstmt.executeQuery();
return rs.next();
}
public int userModify(Connection con,User user) throws Exception{
String sql="update `user` set userName=?,password=?,email=? where id=?";
PreparedStatement pstmt=con.prepareStatement(sql);
pstmt.setString(1, user.getUserName());
pstmt.setString(2, user.getPassword());
pstmt.setString(3, user.getEmail());
pstmt.setInt(4, user.getId());;
return pstmt.executeUpdate();}}
sut.rj.dbconnection
DbUtil
package sut.rj.dbconnection;
import java.sql.Connection;
import java.sql.DriverManager;
public class DbUtil {
private String dbUrl="jdbc:mysql://localhost:3306/db_food?useUnicode=true&characterEncoding=utf8";
private String dbUserName="root";
private String dbPassword="admin123";
private String jdbcName="com.mysql.jdbc.Driver";
public Connection getCon() throws Exception{
Class.forName(jdbcName);
Connection con=DriverManager.getConnection(dbUrl,dbUserName,dbPassword);
return con;
}
public void closeCon(Connection con) throws Exception{
if(con!=null){
con.close();
}
}
public static void main(String[] args) {
DbUtil dbUtil=new DbUtil();
try {
dbUtil.getCon();
System.out.println("数据库连接成功");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("数据库连接失败");} }}
StringUtil
package sut.rj.dbconnection;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class StringUtil {
public static boolean isEmpty(String str){
if("".equals(str)||str==null){
return true;
}else{
return false;
}
}
public static boolean isNotEmpty(String str){
if(!"".equals(str)&&str!=null){
return true;
}else{
return false;
}
}
/**
* 验证邮箱地址是否正确
* @param email
* @return
*/
public static boolean checkEmail(String email){
boolean flag = false;
try{
String check = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
Pattern regex = Pattern.compile(check);
Matcher matcher = regex.matcher(email);
flag = matcher.matches();
}catch(Exception e){
flag = false;
}
return flag;
}
/**
* 验证手机号码
* @param mobiles
* @return [0-9]{5,9}
*/
public static boolean isMobileNO(String mobiles){
boolean flag = false;
try{
Pattern p = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");
Matcher m = p.matcher(mobiles);
flag = m.matches();
}catch(Exception e){
flag = false;
}
return flag;
}
//浮点型判断
public static boolean isNum(String str){
return str.matches("^[-+]?(([0-9]+)([.]([0-9]+))?|([.]([0-9]+))?)$");}}
sut.rj.model
Goods
package sut.rj.model;
public class Goods {
private int id;
private String goodsName;
private String goodsDesc;
private float price;//查询价格低高价格
private float price1;//查询价格高价格
private String imageLink;
public Goods() {
super();
// TODO Auto-generated constructor stub
}
public Goods(int id, String goodsName, String goodsDesc, float price,
String imageLink) {
super();
this.id = id;
this.goodsName = goodsName;
this.goodsDesc = goodsDesc;
this.price = price;
this.imageLink = imageLink;
}
public Goods(String goodsName, String goodsDesc, float price,
String imageLink) {
super();
this.goodsName = goodsName;
this.goodsDesc = goodsDesc;
this.price = price;
this.imageLink = imageLink;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getGoodsName() {
return goodsName;
}
public void setGoodsName(String goodsName) {
this.goodsName = goodsName;
}
public String getGoodsDesc() {
return goodsDesc;
}
public void setGoodsDesc(String goodsDesc) {
this.goodsDesc = goodsDesc;
}
public float getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
public float getPrice1() {
return price1;
}
public void setPrice1(float price1) {
this.price1 = price1;
}
public String getImageLink() {
return imageLink;
}
public void setImageLink(String imageLink) {
this.imageLink = imageLink;}}
Order
package sut.rj.model;
public class Order {
private int id;
private String orderId;
private float goodsTotalPrice;
private int goodsId;
private float goodsPrice;
private int goodsNum;
private String goodsName;
private int orderStatus;//订单状态 0 未处理(可以取消)1 已接受烹饪中 2 已送达已付款 3 已付款已完成 4已取消
private int orderNum;
private float orderTotalMoney;
private String userName;
public Order() {
super();
// TODO Auto-generated constructor stub
}
public Order(String orderId, int orderStatus, int orderNum,
float orderTotalMoney, String userName) {
super();
this.orderId = orderId;
this.orderStatus = orderStatus;
this.orderNum = orderNum;
this.orderTotalMoney = orderTotalMoney;
this.userName = userName;
}
public Order(String orderId, float goodsTotalPrice, int goodsId,
float goodsPrice, int goodsNum, String goodsName) {
super();
this.orderId = orderId;
this.goodsTotalPrice = goodsTotalPrice;
this.goodsId = goodsId;
this.goodsPrice = goodsPrice;
this.goodsNum = goodsNum;
this.goodsName = goodsName;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getOrderId() {
return orderId;
}
public void setOrderId(String orderId) {
this.orderId = orderId;
}
public float getGoodsTotalPrice() {
return goodsTotalPrice;
}
public void setGoodsTotalPrice(float goodsTotalPrice) {
this.goodsTotalPrice = goodsTotalPrice;
}
public int getGoodsId() {
return goodsId;
}
public void setGoodsId(int goodsId) {
this.goodsId = goodsId;
}
public float getGoodsPrice() {
return goodsPrice;
}
public void setGoodsPrice(float goodsPrice) {
this.goodsPrice = goodsPrice;
}
public int getGoodsNum() {
return goodsNum;
}
public void setGoodsNum(int goodsNum) {
this.goodsNum = goodsNum;
}
public String getGoodsName() {
return goodsName;
}
public void setGoodsName(String goodsName) {
this.goodsName = goodsName;
}
public int getOrderStatus() {
return orderStatus;
}
public void setOrderStatus(int orderStatus) {
this.orderStatus = orderStatus;
}
public int getOrderNum() {
return orderNum;
}
public void setOrderNum(int orderNum) {
this.orderNum = orderNum;
}
public float getOrderTotalMoney() {
return orderTotalMoney;
}
public void setOrderTotalMoney(float orderTotalMoney) {
this.orderTotalMoney = orderTotalMoney;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;}}
User
package sut.rj.model;
public class User {
private int id;
private String userName;
private String password;
private String email;
private int rank;
public User() {
super();
// TODO Auto-generated constructor stub
}
public User(String userName, String password, String email) {
super();
this.userName = userName;
this.password = password;
this.email = email;
}
public User(String userName, String password) {
super();
this.userName = userName;
this.password = password;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public int getRank() {
return rank;
}
public void setRank(int rank) {
this.rank = rank;}}
*sut.rj.view *
运用 JAVA可视化界面开发插件Matisse
src文件夹上点击右键–>New–>Other弹出如下界面:
选择MyEclipse–>Swing–>Mattise Form弹出如下界面
填入包名和类名后选中JFrame,在右侧的Mattise Palette中展开Swing文件夹就会看到Swing中的组件,如下图:
AccountModifyInterFrm
package sut.rj.view;
import java.sql.Connection;
import javax.swing.*;
import sut.rj.dao.UserDao;
import sut.rj.model.User;
import sut.rj.dbconnection.DbUtil;
import sut.rj.dbconnection.StringUtil;
public class AccountModifyInterFrm extends javax.swing.JInternalFrame {
//GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JButton jb_modify;
private javax.swing.JButton jb_reset;
private javax.swing.JPasswordField newPasswordConfirmTxt;
private javax.swing.JPasswordField newPasswordTxt;
private javax.swing.JPasswordField oldPasswordTxt;
private javax.swing.JTextField userNameTxt;
// End of variables declaration//GEN-END:variables
private static final long serialVersionUID = 1L;
//实现序列化,serialVersionUID 用来表明实现序列化类的不同版本间的兼容性
DbUtil dbUtil = new DbUtil();
UserDao userDao = new UserDao();
/** Creates new form AccountModify */
public AccountModifyInterFrm() {
initComponents();
this.setLocation(320, 100);
this.userNameTxt.setText(LogOnFrm.s_currentUser.getUserName());
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*初始化表单.
*警告:不要修改此代码。这种方法的内容是
*总是由表单编辑器重新生成. **/
//GEN-BEGIN:initComponents
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jb_modify = new javax.swing.JButton();
jb_reset = new javax.swing.JButton();
userNameTxt = new javax.swing.JTextField();
oldPasswordTxt = new javax.swing.JPasswordField();
newPasswordTxt = new javax.swing.JPasswordField();
newPasswordConfirmTxt = new javax.swing.JPasswordField();
setClosable(true);
setIconifiable(true);
setTitle("\u8d26\u6237\u4fe1\u606f\u4fee\u6539");
jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/userName.png"))); // NOI18N
jLabel1.setText("\u7528\u6237\u540d\uff1a");
jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/password.png"))); // NOI18N
jLabel2.setText("\u65e7\u5bc6\u7801\uff1a");
jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/new_password.png"))); // NOI18N
jLabel3.setText("\u65b0\u5bc6\u7801\uff1a");
jLabel4.setText("\u65b0\u5bc6\u7801\u786e\u8ba4\uff1a");
jb_modify.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/edit.png"))); // NOI18N
jb_modify.setText("\u786e\u8ba4\u4fee\u6539");
jb_modify.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jb_modifyActionPerformed(evt); }});
jb_reset.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/reset.png"))); // NOI18N
jb_reset.setText("\u91cd\u7f6e");
jb_reset.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jb_resetActionPerformed(evt);
}
});
userNameTxt.setEnabled(false);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
getContentPane());
getContentPane().setLayout(layout);
layout
.setHorizontalGroup(layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING,
false)
.addGroup(
layout
.createSequentialGroup()
.addGap(
37,
37,
37)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(
jLabel1)
.addComponent(
jLabel2)
.addComponent(
jLabel3)
.addComponent(
jLabel4))
.addGap(
35,
35,
35)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.TRAILING,
false)
.addComponent(
newPasswordConfirmTxt,
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(
newPasswordTxt,
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(
oldPasswordTxt,
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(
userNameTxt,
javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE,
127,
Short.MAX_VALUE)))
.addGroup(
layout
.createSequentialGroup()
.addGap(
47,
47,
47)
.addComponent(
jb_modify)
.addGap(
18,
18,
18)
.addComponent(
jb_reset,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)))
.addContainerGap(65, Short.MAX_VALUE)));
layout
.setVerticalGroup(layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
javax.swing.GroupLayout.Alignment.TRAILING,
layout
.createSequentialGroup()
.addGap(41, 41, 41)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(
userNameTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(
oldPasswordTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(
newPasswordTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(12, 12, 12)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(
newPasswordConfirmTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(30, 30, 30)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jb_modify)
.addComponent(jb_reset))
.addGap(40, 40, 40)));
pack();
}// </editor-fold>
//GEN-END:initComponents
private void jb_modifyActionPerformed(java.awt.event.ActionEvent evt) {
String oldPassword = new String(this.oldPasswordTxt.getPassword());
String newPassword1 = new String(this.newPasswordTxt.getPassword());
String newPassword2 = new String(this.newPasswordConfirmTxt
.getPassword());
if (StringUtil.isEmpty(oldPassword)) {
JOptionPane.showMessageDialog(null, "旧密码不能为空!");
return;
}
if (StringUtil.isEmpty(newPassword1)
|| StringUtil.isEmpty(newPassword2)) {
JOptionPane.showMessageDialog(null, "新密码不能为空!");
return;
}
if (!newPassword1.equals(newPassword2)) {
JOptionPane.showMessageDialog(null, "两次输入的密码不一致!");
return;
}
User user = null;
Connection con = null;
try {
con = dbUtil.getCon();
user = new User(LogOnFrm.s_currentUser.getUserName(), oldPassword);
if (userDao.login(con, user) != null) {
user.setPassword(newPassword1);
user.setId(LogOnFrm.s_currentUser.getId());
int modifyNum = userDao.userModify(con, user);
if (1 == modifyNum) {
JOptionPane.showMessageDialog(null, "修改成功!");
this.oldPasswordTxt.setText("");
this.newPasswordTxt.setText("");
this.newPasswordConfirmTxt.setText("");
} else {
JOptionPane.showMessageDialog(null, "修改失败,请重新输入");
}
} else {
JOptionPane.showMessageDialog(null, "旧密码错误!请重新输入");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
dbUtil.closeCon(con);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}}}
private void jb_resetActionPerformed(java.awt.event.ActionEvent evt) {
this.oldPasswordTxt.setText("");
this.newPasswordTxt.setText("");
this.newPasswordConfirmTxt.setText("");}}
AdminFrm
package sut.rj.view;
import javax.swing.*;
public class AdminFrm extends javax.swing.JFrame {
//GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu3;
private javax.swing.JMenu jMenu4;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jmiDealOrder;
private javax.swing.JMenuItem jmiExit;
private javax.swing.JMenuItem jmiGoodsAdd;
private javax.swing.JMenuItem jmiGoodsManage;
private javax.swing.JMenuItem jmiModify;
private javax.swing.JDesktopPane table;
// End of variables declaration//GEN-END:variables
private static final long serialVersionUID = 1L;
//实现序列化,serialVersionUID 用来表明实现序列化类的不同版本间的兼容性
/** Creates new form AdminFrm */
public AdminFrm() {
initComponents();
//设置最大化
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
* 初始化表单.
* 警告:不要修改此代码。这种方法的内容是
* 总是由表单编辑器重新生成.
*/
//GEN-BEGIN:initComponents
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
table = new javax.swing.JDesktopPane();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jmiGoodsAdd = new javax.swing.JMenuItem();
jmiGoodsManage = new javax.swing.JMenuItem();
jMenu3 = new javax.swing.JMenu();
jmiDealOrder = new javax.swing.JMenuItem();
jMenu4 = new javax.swing.JMenu();
jmiModify = new javax.swing.JMenuItem();
jmiExit = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("\u70b9\u9910\u7cfb\u7edf\u7ba1\u7406\u4e3b\u754c\u9762");
jMenu1.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/base.png"))); // NOI18N
jMenu1.setText("\u5957\u9910\u4fe1\u606f\u7ba1\u7406");
jmiGoodsAdd.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/add.png"))); // NOI18N
jmiGoodsAdd.setText("\u65b0\u589e\u5957\u9910");
jmiGoodsAdd.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jmiGoodsAddActionPerformed(evt);
} });
jMenu1.add(jmiGoodsAdd);
jmiGoodsManage.setIcon(new javax.swing.ImageIcon(getClass()
.getResource("/images/edit.png"))); // NOI18N
jmiGoodsManage.setText("\u5957\u9910\u7ef4\u62a4");
jmiGoodsManage.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jmiGoodsManageActionPerformed(evt); }});
jMenu1.add(jmiGoodsManage);
jMenuBar1.add(jMenu1);
jMenu3.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/bookManager.png"))); // NOI18N
jMenu3.setText("\u8ba2\u5355\u7ba1\u7406");
jmiDealOrder.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/order2.png"))); // NOI18N
jmiDealOrder.setText("\u8ba2\u5355\u5904\u7406");
jmiDealOrder.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jmiDealOrderActionPerformed(evt);
}});
jMenu3.add(jmiDealOrder);
jMenuBar1.add(jMenu3);
jMenu4.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/about.png"))); // NOI18N
jMenu4.setText("\u5176\u4ed6");
jmiModify.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/modify.png"))); // NOI18N
jmiModify.setText("\u4fee\u6539\u5bc6\u7801");
jmiModify.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jmiModifyActionPerformed(evt);
}});
jMenu4.add(jmiModify);
jmiExit.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/exit.png"))); // NOI18N
jmiExit.setText("\u9000\u51fa\u7cfb\u7edf");
jmiExit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jmiExitActionPerformed(evt);
}});
jMenu4.add(jmiExit);
jMenuBar1.add(jMenu4);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addComponent(table,
javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE));
layout.setVerticalGroup(layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addComponent(table,
javax.swing.GroupLayout.DEFAULT_SIZE, 337, Short.MAX_VALUE));
pack();
}// </editor-fold>
//GEN-END:initComponents
//订单处理操作
private void jmiDealOrderActionPerformed(java.awt.event.ActionEvent evt) {
DealOrderInterFrm dealOrderInterFrm = new DealOrderInterFrm();
dealOrderInterFrm.setVisible(true);
this.table.add(dealOrderInterFrm);
}
//修改用户信息操作
void jmiModifyActionPerformed(java.awt.event.ActionEvent evt) {
AccountModifyInterFrm accountModify = new AccountModifyInterFrm();
accountModify.setVisible(true);
this.table.add(accountModify);
}
//套餐维护管理
private void jmiGoodsManageActionPerformed(java.awt.event.ActionEvent evt) {
GoodsManageInterFrm goodsManageInterFrm = new GoodsManageInterFrm();
goodsManageInterFrm.setVisible(true);
this.table.add(goodsManageInterFrm);
}
//套餐添加
private void jmiGoodsAddActionPerformed(java.awt.event.ActionEvent evt) {
GoodsAddInterFrm goodsAddInterFrm = new GoodsAddInterFrm();
goodsAddInterFrm.setVisible(true);
this.table.add(goodsAddInterFrm);
}
//退出系统
private void jmiExitActionPerformed(java.awt.event.ActionEvent evt) {
int result = JOptionPane.showConfirmDialog(null, "是否退出点餐系统?");
//System.out.println(result);
if (result == 0)
this.dispose();}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new AdminFrm().setVisible(true);}});}}
CheckOrderInterFrm
package sut.rj.view;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.Vector;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import sut.rj.dao.GoodsDao;
import sut.rj.dao.OrderDao;
import sut.rj.model.Goods;
import sut.rj.model.Order;
import sut.rj.dbconnection.DbUtil;
import sut.rj.dbconnection.StringUtil;
/**
*
* @author __USER__
*/
public class CheckOrderInterFrm extends javax.swing.JInternalFrame {
//GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JTable cartTable;
private javax.swing.JLabel iamgeLb;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JPanel jPanel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JButton jb_search;
private javax.swing.JButton jb_status;
private javax.swing.JTextField orderIdTxt;
private javax.swing.JTextField orderStatusTxt;
private javax.swing.JTable orderTable;
private javax.swing.JTextField totalMoneyTxt;
private javax.swing.JTextField totalNumTxt;
private javax.swing.JTextField userNameTxt;
// End of variables declaration//GEN-END:variables
private static final long serialVersionUID = 1L;
//实现序列化,serialVersionUID 用来表明实现序列化类的不同版本间的兼容性
@SuppressWarnings("unused")
private static final JTable j_orderTable = null;
DbUtil dbUtil = new DbUtil();
OrderDao orderDao = new OrderDao();
GoodsDao goodsDao = new GoodsDao();
/** Creates new form checkOrderInterFrm */
public CheckOrderInterFrm() {
initComponents();
this.setLocation(320, 100);
this.userNameTxt.setText(LogOnFrm.s_currentUser.getUserName());
}
//GEN-BEGIN:initComponents
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jScrollPane2 = new javax.swing.JScrollPane();
cartTable = new javax.swing.JTable();
jLabel2 = new javax.swing.JLabel();
totalNumTxt = new javax.swing.JTextField();
totalMoneyTxt = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
orderStatusTxt = new javax.swing.JTextField();
jb_status = new javax.swing.JButton();
jLabel4 = new javax.swing.JLabel();
userNameTxt = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
orderIdTxt = new javax.swing.JTextField();
jb_search = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
orderTable = new javax.swing.JTable();
jPanel2 = new javax.swing.JPanel();
iamgeLb = new javax.swing.JLabel();
setClosable(true);
setIconifiable(true);
setTitle("\u67e5\u770b\u8ba2\u5355");
cartTable.setModel(new javax.swing.table.DefaultTableModel(
new Object[][] {}, new String[] { "套餐编号", "套餐名称", "套餐数量", "套餐单价", "套餐金额" }) {
private static final long serialVersionUID = 1L;
boolean[] canEdit = new boolean[] { false, false, false, false,
false };
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit[columnIndex]; }});
cartTable.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
cartTableMousePressed(evt); } });
jScrollPane2.setViewportView(cartTable);
jLabel2.setText("\u603b\u6570\u91cf\uff1a");
totalNumTxt.setEditable(false);
totalMoneyTxt.setEditable(false);
jLabel1.setText("\u603b\u91d1\u989d\uff1a");
jLabel3.setText("\u8ba2\u5355\u72b6\u6001\uff1a");
orderStatusTxt.setEditable(false);
jb_status.setText("\u53d6\u6d88\u8ba2\u5355");
jb_status.setFocusPainted(false);
jb_status.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jb_statusActionPerformed(evt);
}
});
jLabel4.setText("\u70b9\u9910\u4eba\uff1a");
userNameTxt.setEditable(false);
jLabel5.setText("\u8ba2\u5355\u53f7\uff1a");
jb_search.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/1.png"))); // NOI18N
jb_search.setText("\u8ba2\u5355\u67e5\u8be2");
jb_search.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jb_searchActionPerformed(evt);
}});
orderTable.setModel(new javax.swing.table.DefaultTableModel(
new Object[][] {
}, new String[] { "订单编号", "订单商品数量", "订单总金额", "订单状态" }) {
private static final long serialVersionUID = 1L;
boolean[] canEdit = new boolean[] { false, false, false, false };
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit[columnIndex];
}
});
orderTable.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
orderTableMousePressed(evt);
}
});
jScrollPane1.setViewportView(orderTable);
jPanel2.setBorder(javax.swing.BorderFactory
.createTitledBorder("\u5957\u9910\u56fe\u7247"));
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(
jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(jPanel2Layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addComponent(
iamgeLb, javax.swing.GroupLayout.DEFAULT_SIZE, 72,
Short.MAX_VALUE));
jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addComponent(
iamgeLb, javax.swing.GroupLayout.DEFAULT_SIZE, 65,
Short.MAX_VALUE));
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
getContentPane());
getContentPane().setLayout(layout);
layout
.setHorizontalGroup(layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING,
false)
.addGroup(
layout
.createSequentialGroup()
.addGap(
79,
79,
79)
.addComponent(
jLabel5)
.addGap(
36,
36,
36)
.addComponent(
orderIdTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
92,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED,
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addComponent(
jb_search))
.addGroup(
layout
.createSequentialGroup()
.addGap(
29,
29,
29)
.addComponent(
jScrollPane1,
javax.swing.GroupLayout.PREFERRED_SIZE,
367,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(35, 35, 35)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
javax.swing.GroupLayout.Alignment.TRAILING,
layout
.createSequentialGroup()
.addComponent(
jLabel4)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
userNameTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
87,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(
35,
35,
35))
.addComponent(
jScrollPane2,
javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.PREFERRED_SIZE,
510,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(
javax.swing.GroupLayout.Alignment.TRAILING,
layout
.createSequentialGroup()
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addComponent(
jLabel3)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
orderStatusTxt,
javax.swing.GroupLayout.DEFAULT_SIZE,
177,
Short.MAX_VALUE)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
jLabel2)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
totalNumTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
76,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED))
.addGroup(
layout
.createSequentialGroup()
.addComponent(
jb_status)
.addGap(
297,
297,
297)))
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(
layout
.createSequentialGroup()
.addComponent(
jLabel1)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
totalMoneyTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
81,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(
jPanel2,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))))
.addContainerGap(23, Short.MAX_VALUE)));
layout
.setVerticalGroup(layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addContainerGap()
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(
jLabel4)
.addComponent(
userNameTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(
layout
.createSequentialGroup()
.addGap(
18,
18,
18)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(
orderIdTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(
jLabel5)
.addComponent(
jb_search))))
.addGap(23, 23, 23)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addComponent(
jScrollPane2,
javax.swing.GroupLayout.PREFERRED_SIZE,
169,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(
38,
38,
38)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(
jLabel3)
.addComponent(
totalMoneyTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(
jLabel1)
.addComponent(
totalNumTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(
jLabel2)
.addComponent(
orderStatusTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(
jb_status)
.addComponent(
jPanel2,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(
jScrollPane1,
javax.swing.GroupLayout.PREFERRED_SIZE,
199,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(52, Short.MAX_VALUE)));
pack();
}// </editor-fold>
//GEN-END:initComponents
//填充ordertable
@SuppressWarnings("unchecked")
private void fillOrderTable() {
String orderId = this.orderIdTxt.getText();
String userName = this.userNameTxt.getText();
Order order = new Order();
order.setOrderId(orderId);
order.setUserName(userName);
DefaultTableModel dtm = (DefaultTableModel) orderTable.getModel();
dtm.setRowCount(0);
Connection con = null;
try {
con = dbUtil.getCon();
ResultSet rs = orderDao.orderList(con, order);
while (rs.next()) {
Vector v = new Vector();
v.add(rs.getString("orderId"));
v.add(rs.getInt("orderNum"));
v.add(rs.getFloat("orderTotalMoney"));
int status = rs.getInt("orderStatus");
switch (status) {
case 0:
v.add("未处理");
break;
case 1:
v.add("烹饪中");
break;
case 2:
v.add("已送达");
break;
case 3:
v.add("已付款");
break;
case 4:
v.add("已取消");
break;
}
dtm.addRow(v);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
dbUtil.closeCon(con);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace(); } }}
//点击购物车表显示图片
private void cartTableMousePressed(java.awt.event.MouseEvent evt) {
String picturePath = null;
//获取选中的行
int row = cartTable.getSelectedRow();
int goodsId = Integer.parseInt((String) cartTable.getValueAt(row, 0));
Goods goods = new Goods();
goods.setId(goodsId);
Connection con = null;
try {
con = dbUtil.getCon();
ResultSet rs = goodsDao.goodsList(con, goods);
while (rs.next()) {
picturePath = rs.getString("imageLink");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
dbUtil.closeCon(con);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}}
if (StringUtil.isNotEmpty(picturePath)) {
Icon icon = new ImageIcon(picturePath);
this.iamgeLb.setIcon(icon);
} else {
this.iamgeLb.setIcon(null); }}
//取消订单操作
private void jb_statusActionPerformed(java.awt.event.ActionEvent evt) {
//获取选中的行,如果为选中,row默认为-1
int row = orderTable.getSelectedRow();//
if (row < 0) {
JOptionPane.showMessageDialog(null, "请选择一个订单");
return;
}
//获取订单编号
String orderId = (String) orderTable.getValueAt(row, 0);
Order order = new Order();
order.setOrderId(orderId);
order.setOrderStatus(4);//取消订单
try {
Connection con = dbUtil.getCon();
int modifyNum = orderDao.orderStatusModify(con, order);
if (modifyNum == 1) {
JOptionPane.showMessageDialog(null, "取消成功!");
this.orderStatusTxt.setText("已取消");
this.jb_status.setEnabled(false);
fillOrderTable();
} else {
JOptionPane.showMessageDialog(null, "取消订单失败!");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}}
//点击订单table
@SuppressWarnings("unchecked")
private void orderTableMousePressed(java.awt.event.MouseEvent evt) {
//获取选中的行
int row = orderTable.getSelectedRow();
String orderId = (String) orderTable.getValueAt(row, 0);
this.totalNumTxt.setText(orderTable.getValueAt(row, 1) + "");//把int,float型转化为string
this.totalMoneyTxt.setText(orderTable.getValueAt(row, 2) + "");
String orderStatus = (String) orderTable.getValueAt(row, 3);
this.orderStatusTxt.setText(orderStatus);
this.iamgeLb.setIcon(null);
//修改取消订单按钮状态
if (!orderStatus.equals("未处理")) {
jb_status.setEnabled(false);
} else {
jb_status.setEnabled(true);
}
Order order = new Order();
order.setOrderId(orderId);
DefaultTableModel dtm = (DefaultTableModel) cartTable.getModel();
dtm.setRowCount(0);
Connection con = null;
try {
con = dbUtil.getCon();
ResultSet rs = orderDao.orderGoodsList(con, order);
while (rs.next()) {
Vector v = new Vector();
v.add(rs.getString("goodsId"));
v.add(rs.getString("goodsName"));
v.add(rs.getInt("goodsNum"));
v.add(rs.getFloat("goodsPrice"));
v.add(rs.getFloat("goodsTotalPrice"));
dtm.addRow(v);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
dbUtil.closeCon(con);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}}}
//点击查询订单
private void jb_searchActionPerformed(java.awt.event.ActionEvent evt) {
fillOrderTable();}}
DealOrderInterFrm
package sut.rj.view;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.Vector;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import sut.rj.dao.GoodsDao;
import sut.rj.dao.OrderDao;
import sut.rj.model.Goods;
import sut.rj.model.Order;
import sut.rj.dbconnection.DbUtil;
import sut.rj.dbconnection.StringUtil;
public class DealOrderInterFrm extends javax.swing.JInternalFrame {
//GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.JTable cartTable;
private javax.swing.JLabel iamgeLb;
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JPanel jPanel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JButton jb_search;
private javax.swing.JButton jb_status;
private javax.swing.JRadioButton jrb_1;
private javax.swing.JRadioButton jrb_2;
private javax.swing.JRadioButton jrb_3;
private javax.swing.JRadioButton jrb_4;
private javax.swing.JTextField orderIdTxt;
private javax.swing.JTextField orderStatusTxt;
private javax.swing.JTable orderTable;
private javax.swing.JTextField totalMoneyTxt;
private javax.swing.JTextField totalNumTxt;
private javax.swing.JTextField userNameTxt;
// End of variables declaration//GEN-END:variables
private static final long serialVersionUID = 1L;
//实现序列化,serialVersionUID 用来表明实现序列化类的不同版本间的兼容性
@SuppressWarnings("unused")
private static final JTable j_orderTable = null;
DbUtil dbUtil = new DbUtil();
OrderDao orderDao = new OrderDao();
GoodsDao goodsDao = new GoodsDao();
/** Creates new form checkOrderInterFrm */
public DealOrderInterFrm() {
initComponents();
this.setLocation(320, 100);}
//GEN-BEGIN:initComponents
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
buttonGroup1 = new javax.swing.ButtonGroup();
jScrollPane2 = new javax.swing.JScrollPane();
cartTable = new javax.swing.JTable();
jLabel2 = new javax.swing.JLabel();
totalNumTxt = new javax.swing.JTextField();
totalMoneyTxt = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
orderStatusTxt = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
userNameTxt = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
orderIdTxt = new javax.swing.JTextField();
jb_search = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
orderTable = new javax.swing.JTable();
jPanel2 = new javax.swing.JPanel();
iamgeLb = new javax.swing.JLabel();
jrb_1 = new javax.swing.JRadioButton();
jrb_2 = new javax.swing.JRadioButton();
jrb_3 = new javax.swing.JRadioButton();
jrb_4 = new javax.swing.JRadioButton();
jButton1 = new javax.swing.JButton();
jb_status = new javax.swing.JButton();
setClosable(true);
setIconifiable(true);
setTitle("\u67e5\u770b\u8ba2\u5355");
cartTable.setModel(new javax.swing.table.DefaultTableModel(
new Object[][] {
}, new String[] { "套餐编号", "套餐名称", "套餐数量", "套餐单价", "套餐金额" }) {
private static final long serialVersionUID = 1L;
boolean[] canEdit = new boolean[] { false, false, false, false,
false };
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit[columnIndex]; }});
cartTable.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
cartTableMousePressed(evt); }});
jScrollPane2.setViewportView(cartTable);
jLabel2.setText("\u603b\u6570\u91cf\uff1a");
totalNumTxt.setEditable(false);
totalMoneyTxt.setEditable(false);
jLabel1.setText("\u603b\u91d1\u989d\uff1a");
jLabel3.setText("\u8ba2\u5355\u72b6\u6001\uff1a");
orderStatusTxt.setEditable(false);
jLabel4.setText("\u70b9\u9910\u4eba\uff1a");
userNameTxt.setEditable(false);
jLabel5.setText("\u8ba2\u5355\u53f7\uff1a");
jb_search.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/search.png"))); // NOI18N
jb_search.setText("\u8ba2\u5355\u67e5\u8be2");
jb_search.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jb_searchActionPerformed(evt); } });
orderTable.setModel(new javax.swing.table.DefaultTableModel(
new Object[][] {
}, new String[] { "订单编号", "商品总数量", "总金额", "点餐人", "订单状态" }) {
private static final long serialVersionUID = 1L;
boolean[] canEdit = new boolean[] { false, false, false, false,
false };
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit[columnIndex];
}
});
orderTable.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
orderTableMousePressed(evt);
}
});
jScrollPane1.setViewportView(orderTable);
jPanel2.setBorder(javax.swing.BorderFactory
.createTitledBorder("\u5957\u9910\u56fe\u7247"));
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(
jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(jPanel2Layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addComponent(
iamgeLb, javax.swing.GroupLayout.DEFAULT_SIZE, 72,
Short.MAX_VALUE));
jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addComponent(
iamgeLb, javax.swing.GroupLayout.DEFAULT_SIZE, 65,
Short.MAX_VALUE));
buttonGroup1.add(jrb_1);
jrb_1.setText("\u786e\u8ba4\u8ba2\u5355");
buttonGroup1.add(jrb_2);
jrb_2.setText("\u53bb\u9001\u9910");
buttonGroup1.add(jrb_3);
jrb_3.setText("\u5df2\u5b8c\u6210");
buttonGroup1.add(jrb_4);
jrb_4.setText("\u5220\u9664\u8ba2\u5355");
jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/1.png"))); // NOI18N
jButton1.setText("\u63d0\u4ea4");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jb_status.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/reset.png"))); // NOI18N
jb_status.setText("\u53d6\u6d88\u8ba2\u5355");
jb_status.setFocusPainted(false);
jb_status.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jb_statusActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
getContentPane());
getContentPane().setLayout(layout);
layout
.setHorizontalGroup(layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addGap(
79,
79,
79)
.addComponent(
jLabel5)
.addGap(
36,
36,
36)
.addComponent(
orderIdTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
92,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED,
11,
Short.MAX_VALUE)
.addComponent(
jb_search)
.addGap(
107,
107,
107))
.addGroup(
layout
.createSequentialGroup()
.addContainerGap()
.addComponent(
jScrollPane1,
javax.swing.GroupLayout.PREFERRED_SIZE,
423,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
javax.swing.GroupLayout.Alignment.TRAILING,
layout
.createSequentialGroup()
.addComponent(
jLabel4)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
userNameTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
87,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(
35,
35,
35))
.addGroup(
javax.swing.GroupLayout.Alignment.TRAILING,
layout
.createSequentialGroup()
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addComponent(
jLabel3)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
orderStatusTxt,
javax.swing.GroupLayout.DEFAULT_SIZE,
177,
Short.MAX_VALUE)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
jLabel2)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
totalNumTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
76,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(
layout
.createSequentialGroup()
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(
jrb_1)
.addComponent(
jrb_3))
.addGap(
12,
12,
12)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(
jrb_2)
.addComponent(
jrb_4))
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
jButton1))
.addComponent(
jb_status))
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(
layout
.createSequentialGroup()
.addComponent(
jLabel1)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
totalMoneyTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
81,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(
jPanel2,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGroup(
layout
.createSequentialGroup()
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
jScrollPane2,
javax.swing.GroupLayout.PREFERRED_SIZE,
510,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap()));
layout
.setVerticalGroup(layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addGap(
18,
18,
18)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(
orderIdTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(
jLabel5)
.addComponent(
jb_search)))
.addGroup(
layout
.createSequentialGroup()
.addContainerGap()
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(
jLabel4)
.addComponent(
userNameTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(23, 23, 23)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addComponent(
jScrollPane2,
javax.swing.GroupLayout.PREFERRED_SIZE,
169,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(
28,
28,
28)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(
jLabel3)
.addComponent(
totalMoneyTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(
jLabel1)
.addComponent(
totalNumTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(
jLabel2)
.addComponent(
orderStatusTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(
jPanel2,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(
layout
.createSequentialGroup()
.addComponent(
jb_status)
.addGap(
13,
13,
13)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(
jrb_1)
.addComponent(
jrb_2))
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(
jrb_4)
.addComponent(
jrb_3)))
.addComponent(
jButton1)))
.addComponent(
jScrollPane1,
javax.swing.GroupLayout.PREFERRED_SIZE,
199,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(58, Short.MAX_VALUE)));
pack();
}// </editor-fold>
//GEN-END:initComponents
//填充ordertable
@SuppressWarnings("unchecked")
private void fillOrderTable() {
//填充ordertable
String orderId = this.orderIdTxt.getText();
Order order = new Order();
order.setOrderId(orderId);
DefaultTableModel dtm = (DefaultTableModel) orderTable.getModel();
dtm.setRowCount(0);
Connection con = null;
try {
con = dbUtil.getCon();
ResultSet rs = orderDao.orderList(con, order);
while (rs.next()) {
Vector v = new Vector();
v.add(rs.getString("orderId"));
v.add(rs.getInt("orderNum"));
v.add(rs.getFloat("orderTotalMoney"));
v.add(rs.getString("userName"));
int status = rs.getInt("orderStatus");
switch (status) {
case 0:
v.add("未处理");
break;
case 1:
v.add("烹饪中");
break;
case 2:
v.add("已送达");
break;
case 3:
v.add("已付款");
break;
case 4:
v.add("已取消");
}
dtm.addRow(v);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
dbUtil.closeCon(con);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace(); } }}
//重置carttable
private void resetCartTable() {
this.totalNumTxt.setText("");
this.totalMoneyTxt.setText("");
this.userNameTxt.setText("");
this.orderStatusTxt.setText("");
this.iamgeLb.setIcon(null);
DefaultTableModel dtm = (DefaultTableModel) cartTable.getModel();
dtm.setRowCount(0);}
//订单处理操作
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
//获取选中的行
int row = orderTable.getSelectedRow();
if (row < 0) {
JOptionPane.showMessageDialog(null, "请选择一个订单");
return;
}
//获取订单编号
String orderId = (String) orderTable.getValueAt(row, 0);
Order order = new Order();
order.setOrderId(orderId);
//
String orderStatus = this.orderStatusTxt.getText();
int statusNum = 0;//是否为删除订单或者处理订单的标志位
if (this.jrb_1.isSelected()) {//确定订单
orderStatus = "烹饪中";
order.setOrderStatus(1);
} else if (this.jrb_2.isSelected()) {//去送餐
orderStatus = "已送达";
order.setOrderStatus(2);
} else if (this.jrb_3.isSelected()) {//已付款
orderStatus = "已付款";
order.setOrderStatus(3);
} else if (this.jrb_4.isSelected()) {//删除订单
orderStatus = "";
statusNum = 1;
} else {
return;}
if (statusNum != 1) {
try {
Connection con = dbUtil.getCon();
int modifyNum = orderDao.orderStatusModify(con, order);
if (modifyNum == 1) {
JOptionPane.showMessageDialog(null, "操作成功!");
fillOrderTable();
this.orderStatusTxt.setText(orderStatus);
this.jb_status.setEnabled(false);
} else {
JOptionPane.showMessageDialog(null, "订单操作失败!");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (statusNum == 4) {
try {
Connection con = dbUtil.getCon();
int modifyNum = orderDao.deleteOrder(con, order);
if (modifyNum == 1) {
JOptionPane.showMessageDialog(null, "删除成功!");
fillOrderTable();
this.jb_status.setEnabled(false);
resetCartTable();
} else {
JOptionPane.showMessageDialog(null, "订单删除失败!");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace(); } }}
//取消订单操作
private void jb_statusActionPerformed(java.awt.event.ActionEvent evt) {
//获取选中的行,如果为选中,row默认为-1
int row = orderTable.getSelectedRow();
if (row < 0) {
JOptionPane.showMessageDialog(null, "请选择一个订单");
return;
}
//获取订单编号
String orderId = (String) orderTable.getValueAt(row, 0);
Order order = new Order();
order.setOrderId(orderId);
order.setOrderStatus(4);//取消订单
try {
Connection con = dbUtil.getCon();
int modifyNum = orderDao.orderStatusModify(con, order);
if (modifyNum == 1) {
JOptionPane.showMessageDialog(null, "取消成功!");
this.orderStatusTxt.setText("已取消");
this.jb_status.setEnabled(false);
fillOrderTable();
} else {
JOptionPane.showMessageDialog(null, "取消订单失败!");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();}}
//购物车点击显示商品图片
private void cartTableMousePressed(java.awt.event.MouseEvent evt) {
String picturePath = null;
//获取选中的行
int row = cartTable.getSelectedRow();
int goodsId = Integer.parseInt((String) cartTable.getValueAt(row, 0));
Goods goods = new Goods();
goods.setId(goodsId);
Connection con = null;
try {
con = dbUtil.getCon();
ResultSet rs = goodsDao.goodsList(con, goods);
while (rs.next()) {
picturePath = rs.getString("imageLink");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
dbUtil.closeCon(con);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (StringUtil.isNotEmpty(picturePath)) {
Icon icon = new ImageIcon(picturePath);
this.iamgeLb.setIcon(icon);
} else {
this.iamgeLb.setIcon(null); }}
//点击订单表,显示购物车表内容
@SuppressWarnings("unchecked")
private void orderTableMousePressed(java.awt.event.MouseEvent evt) {
//获取选中的行
int row = orderTable.getSelectedRow();
String orderId = (String) orderTable.getValueAt(row, 0);
this.totalNumTxt.setText(orderTable.getValueAt(row, 1) + "");//把int,float型转化为string
this.totalMoneyTxt.setText(orderTable.getValueAt(row, 2) + "");
this.userNameTxt.setText((String) orderTable.getValueAt(row, 3));
String orderStatus = (String) orderTable.getValueAt(row, 4);
this.orderStatusTxt.setText(orderStatus);
this.iamgeLb.setIcon(null);
//修改取消订单按钮状态
if (!orderStatus.equals("未处理")) {
jb_status.setEnabled(false);
} else {
jb_status.setEnabled(true);
}
Order order = new Order();
order.setOrderId(orderId);
DefaultTableModel dtm = (DefaultTableModel) cartTable.getModel();
dtm.setRowCount(0);
Connection con = null;
try {
con = dbUtil.getCon();
ResultSet rs = orderDao.orderGoodsList(con, order);
while (rs.next()) {
Vector v = new Vector();
v.add(rs.getString("goodsId"));
v.add(rs.getString("goodsName"));
v.add(rs.getInt("goodsNum"));
v.add(rs.getFloat("goodsPrice"));
v.add(rs.getFloat("goodsTotalPrice"));
dtm.addRow(v);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
dbUtil.closeCon(con);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace(); } }}
//查找显示订单列表
private void jb_searchActionPerformed(java.awt.event.ActionEvent evt) {
fillOrderTable();}}
GoodsAddInterFrm
package sut.rj.view;
import java.io.File;
import java.sql.Connection;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import sut.rj.dao.GoodsDao;
import sut.rj.model.Goods;
import sut.rj.dbconnection.DbUtil;
import sut.rj.dbconnection.StringUtil;
public class GoodsAddInterFrm extends javax.swing.JInternalFrame {
//GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JTextArea goodsDescTxt;
private javax.swing.JTextField goodsNameTxt;
private javax.swing.JLabel iamgeLb;
private javax.swing.JTextField imageLinkTxt;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JButton jb_add;
private javax.swing.JButton jb_chooser;
private javax.swing.JButton jb_reset;
private javax.swing.JTextField priceTxt;
// End of variables declaration//GEN-END:variables
private static final long serialVersionUID = 1L;
//实现序列化,serialVersionUID 用来表明实现序列化类的不同版本间的兼容性
DbUtil dbUtil = new DbUtil();
GoodsDao goodsDao = new GoodsDao();
/** Creates new form GoodsAddInterFrm */
public GoodsAddInterFrm() {
initComponents();
this.setLocation(200, 80);}
//GEN-BEGIN:initComponents
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jb_chooser = new javax.swing.JButton();
jPanel1 = new javax.swing.JPanel();
iamgeLb = new javax.swing.JLabel();
imageLinkTxt = new javax.swing.JTextField();
goodsNameTxt = new javax.swing.JTextField();
priceTxt = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
goodsDescTxt = new javax.swing.JTextArea();
jb_add = new javax.swing.JButton();
jb_reset = new javax.swing.JButton();
setClosable(true);
setIconifiable(true);
setTitle("\u5957\u9910\u6dfb\u52a0");
jLabel2.setText("\u5957\u9910\u540d\u79f0\uff1a");
jLabel3.setText("\u5957\u9910\u4ef7\u683c\uff1a");
jLabel4.setText("\u5957\u9910\u63cf\u8ff0\uff1a");
jb_chooser.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/2.png"))); // NOI18N
jb_chooser.setText("\u8bf7\u9009\u62e9");
jb_chooser.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jb_chooserActionPerformed(evt); } });
jPanel1.setBorder(javax.swing.BorderFactory
.createTitledBorder("\u5957\u9910\u56fe\u7247"));
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(
jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addGroup(
javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup().addContainerGap(23,
Short.MAX_VALUE).addComponent(iamgeLb,
javax.swing.GroupLayout.PREFERRED_SIZE, 60,
javax.swing.GroupLayout.PREFERRED_SIZE).addGap(21, 21,
21)));
jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addGroup(
jPanel1Layout.createSequentialGroup().addContainerGap()
.addComponent(iamgeLb,
javax.swing.GroupLayout.PREFERRED_SIZE, 60,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(26, Short.MAX_VALUE)));
imageLinkTxt.setEditable(false);
jLabel5.setText("\u5957\u9910\u56fe\u7247\uff1a");
goodsDescTxt.setColumns(20);
goodsDescTxt.setRows(5);
jScrollPane1.setViewportView(goodsDescTxt);
jb_add.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/add.png"))); // NOI18N
jb_add.setText("\u6dfb\u52a0");
jb_add.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jb_addActionPerformed(evt); }});
jb_reset.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/reset.png"))); // NOI18N
jb_reset.setText("\u91cd\u7f6e");
jb_reset.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jb_resetActionPerformed(evt); }});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
getContentPane());
getContentPane().setLayout(layout);
layout
.setHorizontalGroup(layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addContainerGap()
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(
jLabel2)
.addGroup(
layout
.createSequentialGroup()
.addComponent(
jLabel3)
.addGap(
30,
30,
30)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(
priceTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
103,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(
layout
.createSequentialGroup()
.addComponent(
goodsNameTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
135,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(
49,
49,
49)
.addComponent(
jLabel5))
.addComponent(
jScrollPane1,
javax.swing.GroupLayout.PREFERRED_SIZE,
230,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(
jLabel4))
.addGap(
4,
4,
4)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addGap(
47,
47,
47)
.addComponent(
jb_reset))
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(
jPanel1,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(
jb_chooser)
.addComponent(
imageLinkTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
161,
javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGroup(
layout
.createSequentialGroup()
.addGap(
56,
56,
56)
.addComponent(
jb_add)))
.addContainerGap(32, Short.MAX_VALUE)));
layout
.setVerticalGroup(layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addContainerGap()
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(
goodsNameTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5)
.addComponent(
imageLinkTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(
priceTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(
jb_chooser))
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(
jPanel1,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addComponent(
jScrollPane1,
javax.swing.GroupLayout.DEFAULT_SIZE,
125,
Short.MAX_VALUE)
.addComponent(jLabel4))
.addGap(16, 16, 16)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jb_add)
.addComponent(jb_reset))
.addContainerGap()));
pack();
}// </editor-fold>
//GEN-END:initComponents
// 套餐添加操作
private void jb_addActionPerformed(java.awt.event.ActionEvent evt) {
String goodsName = this.goodsNameTxt.getText();
String goodsDesc = this.goodsDescTxt.getText();
String price = this.priceTxt.getText();
String imageLink = this.imageLinkTxt.getText();
if (StringUtil.isEmpty(goodsName)) {
JOptionPane.showMessageDialog(null, "套餐名称不能为空!");
return;
}
if (StringUtil.isEmpty(price)) {
JOptionPane.showMessageDialog(null, "套餐价格不能为空!");
return;
}
if (!StringUtil.isNum(price)) {
JOptionPane.showMessageDialog(null, "请重新输入套餐价格!");
return;
}
Goods goods = new Goods(goodsName, goodsDesc, Float.parseFloat(price),
imageLink);
Connection con = null;
try {
con = dbUtil.getCon();
int n = goodsDao.GoodsAdd(con, goods);
if (n == 1) {
JOptionPane.showMessageDialog(null, "套餐添加成功");
this.resetValues();
} else {
JOptionPane.showMessageDialog(null, "套餐添加失败");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
JOptionPane.showMessageDialog(null, "套餐添加失败2");
}}
//重置函数
private void resetValues() {
this.goodsNameTxt.setText("");
this.goodsDescTxt.setText("");
this.priceTxt.setText("");
this.imageLinkTxt.setText("");
this.iamgeLb.setIcon(null);
}
//重置表单操作
private void jb_resetActionPerformed(java.awt.event.ActionEvent evt) {
resetValues();
}
//点击选择图片操作
private void jb_chooserActionPerformed(java.awt.event.ActionEvent evt) {
JFileChooser chooser = new JFileChooser();//创建文件对话框
FileNameExtensionFilter filter = new FileNameExtensionFilter(
"JPG & GIF Images", "jpg", "gif");//创建文件过滤器
chooser.setFileFilter(filter);//为文件对话框设置文件过滤器
int returnValue = chooser.showOpenDialog(getParent());//打开文件选择对话框
if (returnValue == JFileChooser.APPROVE_OPTION) { // 判断是否选择了文件
File file = chooser.getSelectedFile(); // 获得文件对象
if (file.length() / 1024.0 > 50.0) {
JOptionPane.showMessageDialog(null, "请选择小于等于50KB的图片文件。");
return;
}
String picturePath = file.getAbsolutePath();//获取路径
//System.out.println(picturePath);
Icon icon = new ImageIcon(picturePath);//新建图标
this.iamgeLb.setIcon(icon);//设置图片并显示
this.imageLinkTxt.setText(picturePath);//文本框显示路径}}}
GoodsManageInterFrm
package sut.rj.view;
import java.io.File;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.Vector;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.DefaultTableModel;
import sut.rj.dao.GoodsDao;
import sut.rj.model.Goods;
import sut.rj.dbconnection.DbUtil;
import sut.rj.dbconnection.StringUtil;
public class GoodsManageInterFrm extends javax.swing.JInternalFrame {
//GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JTextArea goodsDescTxt;
private javax.swing.JTextField goodsIdTxt;
private javax.swing.JTextField goodsNameTxt;
private javax.swing.JTable goodsTable;
private javax.swing.JLabel iamgeLb;
private javax.swing.JTextField imageLinkTxt;
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JButton jb_chooser;
private javax.swing.JButton jb_delete;
private javax.swing.JButton jb_modify;
private javax.swing.JButton jb_search;
private javax.swing.JTextField priceTxt;
private javax.swing.JTextField s_goodsName;
private javax.swing.JTextField s_price_1;
private javax.swing.JTextField s_price_2;
// End of variables declaration//GEN-END:variables
private static final long serialVersionUID = 1L;
//实现序列化,serialVersionUID 用来表明实现序列化类的不同版本间的兼容性
DbUtil dbUtil = new DbUtil();
GoodsDao goodsDao = new GoodsDao();
/** Creates new form GoodsManageInterFrm */
public GoodsManageInterFrm() {
initComponents();
this.setLocation(320, 100);
this.filltable(new Goods());
}
//填充table操作,刷新内容
@SuppressWarnings("unchecked")
private void filltable(Goods goods) {
DefaultTableModel dtm = (DefaultTableModel) goodsTable.getModel();
//清空之前显示
dtm.setRowCount(0);
Connection con = null;
try {
con = dbUtil.getCon();
ResultSet rs = goodsDao.goodsList(con, goods);
while (rs.next()) {
Vector v = new Vector();
v.add(rs.getString("id"));
v.add(rs.getString("goodsName"));
v.add(rs.getString("goodsDesc"));
v.add(rs.getString("price"));
v.add(rs.getString("imageLink"));
dtm.addRow(v);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
dbUtil.closeCon(con);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace(); }}}
//GEN-BEGIN:initComponents
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jButton1 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jb_search = new javax.swing.JButton();
s_goodsName = new javax.swing.JTextField();
s_price_1 = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
goodsTable = new javax.swing.JTable();
jPanel1 = new javax.swing.JPanel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
goodsNameTxt = new javax.swing.JTextField();
priceTxt = new javax.swing.JTextField();
jScrollPane2 = new javax.swing.JScrollPane();
goodsDescTxt = new javax.swing.JTextArea();
jLabel6 = new javax.swing.JLabel();
imageLinkTxt = new javax.swing.JTextField();
jPanel2 = new javax.swing.JPanel();
iamgeLb = new javax.swing.JLabel();
jb_modify = new javax.swing.JButton();
jb_delete = new javax.swing.JButton();
jb_chooser = new javax.swing.JButton();
jLabel7 = new javax.swing.JLabel();
goodsIdTxt = new javax.swing.JTextField();
s_price_2 = new javax.swing.JTextField();
jLabel8 = new javax.swing.JLabel();
jButton1.setText("jButton1");
setClosable(true);
setIconifiable(true);
setTitle("\u5957\u9910\u4fe1\u606f\u7ef4\u62a4");
jLabel1.setText("\u5957\u9910\u540d\u79f0\uff1a");
jb_search.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/search.png"))); // NOI18N
jb_search.setText("\u67e5\u8be2");
jb_search.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jb_searchActionPerformed(evt); }});
jLabel2.setText("\u5957\u9910\u4ef7\u683c\u533a\u95f4\uff1a");
goodsTable.setModel(new javax.swing.table.DefaultTableModel(
new Object[][] {
}, new String[] { "序号", "套餐名称", "套餐描述", "套餐价格", "图片地址" }) {
private static final long serialVersionUID = 1L;
boolean[] canEdit = new boolean[] { false, false, false, false,
false };
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit[columnIndex];}});
goodsTable.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
goodsTableMousePressed(evt);}});
jScrollPane1.setViewportView(goodsTable);
jPanel1.setBorder(javax.swing.BorderFactory
.createTitledBorder("\u8868\u5355\u64cd\u4f5c"));
jLabel3.setText("\u5957\u9910\u540d\u79f0\uff1a");
jLabel4.setText("\u5957\u9910\u4ef7\u683c\uff1a");
jLabel5.setText("\u5957\u9910\u63cf\u8ff0\uff1a");
goodsDescTxt.setColumns(20);
goodsDescTxt.setRows(5);
jScrollPane2.setViewportView(goodsDescTxt);
jLabel6.setText("\u5957\u9910\u56fe\u7247\uff1a");
imageLinkTxt.setEnabled(false);
jPanel2.setBorder(javax.swing.BorderFactory
.createTitledBorder("\u5957\u9910\u56fe\u7247"));
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(
jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(jPanel2Layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addGroup(
jPanel2Layout.createSequentialGroup().addContainerGap()
.addComponent(iamgeLb,
javax.swing.GroupLayout.PREFERRED_SIZE, 60,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)));
jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addGroup(
jPanel2Layout.createSequentialGroup().addComponent(iamgeLb,
javax.swing.GroupLayout.PREFERRED_SIZE, 60,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)));
jb_modify.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/modify.png"))); // NOI18N
jb_modify.setText("\u4fee\u6539");
jb_modify.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jb_modifyActionPerformed(evt);}});
jb_delete.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/delete.png"))); // NOI18N
jb_delete.setText("\u5220\u9664");
jb_delete.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jb_deleteActionPerformed(evt);}});
jb_chooser.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/2.png"))); // NOI18N
jb_chooser.setText("\u8bf7\u9009\u62e9");
jb_chooser.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jb_chooserActionPerformed(evt);}});
jLabel7.setText("\u7f16\u53f7\uff1a");
goodsIdTxt.setEditable(false);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(
jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout
.setHorizontalGroup(jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
jPanel1Layout
.createSequentialGroup()
.addContainerGap()
.addGroup(
jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
jPanel1Layout
.createSequentialGroup()
.addComponent(
jLabel3)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
goodsNameTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
76,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(
18,
18,
18)
.addComponent(
jLabel4)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
priceTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
59,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(
jLabel7)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
goodsIdTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
46,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(
37,
37,
37)
.addComponent(
jLabel6))
.addGroup(
jPanel1Layout
.createSequentialGroup()
.addComponent(
jLabel5)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(
jScrollPane2,
javax.swing.GroupLayout.PREFERRED_SIZE,
373,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(
jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING,
false)
.addGroup(
javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout
.createSequentialGroup()
.addGroup(
jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(
jPanel2,
javax.swing.GroupLayout.PREFERRED_SIZE,
85,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(
jb_modify))
.addGroup(
jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(
jb_delete,
javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(
jPanel1Layout
.createSequentialGroup()
.addGap(
30,
30,
30)
.addComponent(
jb_chooser))))
.addComponent(
imageLinkTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
214,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap()));
jPanel1Layout
.setVerticalGroup(jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
jPanel1Layout
.createSequentialGroup()
.addGap(20, 20, 20)
.addGroup(
jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel3)
.addGroup(
jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(
goodsNameTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(
jLabel4)
.addComponent(
priceTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(
jLabel7)
.addComponent(
jLabel6)
.addComponent(
imageLinkTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(
goodsIdTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(33, 33, 33)
.addGroup(
jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
jPanel1Layout
.createSequentialGroup()
.addGroup(
jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(
jLabel5)
.addComponent(
jb_chooser))
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED,
96,
Short.MAX_VALUE)
.addGroup(
jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(
jb_delete)
.addComponent(
jb_modify)))
.addComponent(
jScrollPane2,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(
jPanel2,
javax.swing.GroupLayout.PREFERRED_SIZE,
87,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap()));
jLabel8.setText("\u2014\u2014");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
getContentPane());
getContentPane().setLayout(layout);
layout
.setHorizontalGroup(layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addGap(
51,
51,
51)
.addComponent(
jLabel1)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
s_goodsName,
javax.swing.GroupLayout.PREFERRED_SIZE,
137,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(
18,
18,
18)
.addComponent(
jLabel2)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
s_price_1,
javax.swing.GroupLayout.PREFERRED_SIZE,
68,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(
2,
2,
2)
.addComponent(
jLabel8)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
s_price_2,
javax.swing.GroupLayout.PREFERRED_SIZE,
66,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(
33,
33,
33)
.addComponent(
jb_search))
.addGroup(
layout
.createSequentialGroup()
.addContainerGap()
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(
jPanel1,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(
jScrollPane1,
javax.swing.GroupLayout.PREFERRED_SIZE,
737,
javax.swing.GroupLayout.PREFERRED_SIZE))))
.addContainerGap(128, Short.MAX_VALUE)));
layout
.setVerticalGroup(layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
javax.swing.GroupLayout.Alignment.TRAILING,
layout
.createSequentialGroup()
.addContainerGap(44, Short.MAX_VALUE)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(
s_goodsName,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2)
.addComponent(
s_price_2,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(
s_price_1,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel8)
.addComponent(jb_search))
.addGap(27, 27, 27)
.addComponent(
jScrollPane1,
javax.swing.GroupLayout.PREFERRED_SIZE,
122,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
jPanel1,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap()));
pack();
}// </editor-fold>
//GEN-END:initComponents
/**
* @param evt
*/
//修改操作
private void jb_modifyActionPerformed(java.awt.event.ActionEvent evt) {
String id = this.goodsIdTxt.getText();
if (StringUtil.isEmpty(id)) {
JOptionPane.showMessageDialog(null, "请选择要修改的记录");
return;
}
String goodsName = this.goodsNameTxt.getText();
String goodsDesc = this.goodsDescTxt.getText();
String imageLink = this.imageLinkTxt.getText();
String price = this.priceTxt.getText();
if (StringUtil.isEmpty(goodsName)) {
JOptionPane.showMessageDialog(null, "套餐名称不能为空");
return;
}
if (StringUtil.isEmpty(price)) {
JOptionPane.showMessageDialog(null, "套餐价格不能为空");
return;
}
if (!StringUtil.isNum(price)) {
JOptionPane.showMessageDialog(null, "请重新输入套餐价格");
return;
}
Goods goods = new Goods(Integer.parseInt(id), goodsName, goodsDesc,
Float.parseFloat(price), imageLink);
Connection con = null;
try {
con = dbUtil.getCon();
int modifyNum = goodsDao.goodsModify(con, goods);
if (modifyNum == 1) {
JOptionPane.showMessageDialog(null, "修改成功");
this.filltable(new Goods());//
resetValues();
} else
JOptionPane.showMessageDialog(null, "修改失败");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
JOptionPane.showMessageDialog(null, "修改失败");
} finally {
try {
dbUtil.closeCon(con);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();}}}
//删除操作
private void jb_deleteActionPerformed(java.awt.event.ActionEvent evt) {
String id = this.goodsIdTxt.getText();
if (StringUtil.isEmpty(id)) {
JOptionPane.showMessageDialog(null, "请选择要删除的记录");
return;
}
int n = JOptionPane.showConfirmDialog(null, "确定要删除这条记录吗?");
if (n == 0) {
Connection con = null;
try {
con = dbUtil.getCon();
int deleteNum = goodsDao.goodsDelete(con, id);
if (deleteNum == 1) {
JOptionPane.showMessageDialog(null, "删除成功");
this.filltable(new Goods());
resetValues();
} else
JOptionPane.showMessageDialog(null, "删除失败");
} catch (Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(null, "删除失败");
} finally {
try {
dbUtil.closeCon(con);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();}}}}
//选择图片
private void jb_chooserActionPerformed(java.awt.event.ActionEvent evt) {
JFileChooser chooser = new JFileChooser();//创建文件对话框
FileNameExtensionFilter filter = new FileNameExtensionFilter(
"JPG & GIF Images", "jpg", "gif");//创建文件过滤器
chooser.setFileFilter(filter);//为文件对话框设置文件过滤器
int returnValue = chooser.showOpenDialog(getParent());//打开文件选择对话框
if (returnValue == JFileChooser.APPROVE_OPTION) { // 判断是否选择了文件
File file = chooser.getSelectedFile(); // 获得文件对象
if (file.length() / 1024.0 > 50.0) {
JOptionPane.showMessageDialog(null, "请选择小于等于50KB的图片文件。");
return;}
String picturePath = file.getAbsolutePath();
//System.out.println(picturePath);
Icon icon = new ImageIcon(picturePath);
this.iamgeLb.setIcon(icon);
this.imageLinkTxt.setText(picturePath);}}
//点击table中某一种套餐
private void goodsTableMousePressed(java.awt.event.MouseEvent evt) {
//获取选中的行
int row = goodsTable.getSelectedRow();
//在表单中写入选中的数据
this.goodsIdTxt.setText((String) goodsTable.getValueAt(row, 0));
this.goodsNameTxt.setText((String) goodsTable.getValueAt(row, 1));
this.goodsDescTxt.setText((String) goodsTable.getValueAt(row, 2));
this.priceTxt.setText((String) goodsTable.getValueAt(row, 3));
this.imageLinkTxt.setText((String) goodsTable.getValueAt(row, 4));
String picturePath = (String) goodsTable.getValueAt(row, 4);
if (StringUtil.isNotEmpty(picturePath)) {
Icon icon = new ImageIcon(picturePath);
this.iamgeLb.setIcon(icon);
} else {
this.iamgeLb.setIcon(null);}}
//搜索操作
private void jb_searchActionPerformed(java.awt.event.ActionEvent evt) {
Goods goods = new Goods();
String s_goodsName = this.s_goodsName.getText();
String s_price1 = this.s_price_1.getText();
String s_price2 = this.s_price_2.getText();
if (StringUtil.isNotEmpty(s_price1)) {//price_1低价格非空
if(!StringUtil.isNum(s_price1)){
JOptionPane.showMessageDialog(null, "请重新输入套餐价格范围");
return;
}else{
goods.setPrice1(Float.parseFloat(s_price1));
}}
if (StringUtil.isNotEmpty(s_price2)) {//price_2高价格非空
if(!StringUtil.isNum(s_price2)){
JOptionPane.showMessageDialog(null, "请重新输入套餐价格范围");
return;
}else{
goods.setPrice(Float.parseFloat(s_price2));
}}
if (StringUtil.isNotEmpty(s_price1) && StringUtil.isNotEmpty(s_price2)) {//若都为非空
if(goods.getPrice()<goods.getPrice1()){
JOptionPane.showMessageDialog(null, "请重新输入套餐价格范围");
return;
}else if(goods.getPrice()==goods.getPrice1()){
goods.setPrice(Float.parseFloat(s_price2));
}
else{
goods.setPrice1(Float.parseFloat(s_price1));
goods.setPrice(Float.parseFloat(s_price2));}}
//若都为空则不作为查询条件
goods.setGoodsName(s_goodsName);
this.filltable(goods);
System.out.println(goods.getPrice1());
System.out.println(goods.getPrice());}
private void resetValues() {
this.goodsNameTxt.setText("");
this.goodsDescTxt.setText("");
this.priceTxt.setText("");
this.imageLinkTxt.setText("");
this.iamgeLb.setIcon(null);}}
LogOnFrm
package sut.rj.view;
import java.awt.*;
import javax.swing.*;
import java.sql.Connection;
import sut.rj.dao.UserDao;
import sut.rj.model.User;
import sut.rj.dbconnection.DbUtil;
import sut.rj.dbconnection.StringUtil;
public class LogOnFrm extends javax.swing.JFrame {
//GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JButton jb_logon;
private javax.swing.JButton jb_register;
private javax.swing.JButton jb_reset;
private javax.swing.JPasswordField passwordTxt;
private javax.swing.JTextField userNameTxt;
// End of variables declaration//GEN-END:variables
private static final long serialVersionUID = 1L;
//实现序列化,serialVersionUID 用来表明实现序列化类的不同版本间的兼容性
DbUtil dbUtil = new DbUtil();
UserDao userDao = new UserDao();
public static User s_currentUser = null;//保存登陆用户的参数
/** Creates new form LogOnFrm */
@SuppressWarnings("unchecked")
public LogOnFrm() {
//改变系统默认字体
Font font = new Font("Dialog", Font.PLAIN, 12);
java.util.Enumeration keys = UIManager.getDefaults().keys();
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
Object value = UIManager.get(key);
if (value instanceof javax.swing.plaf.FontUIResource) {
UIManager.put(key, font);}}
initComponents();
//设置frame居中显示
this.setLocationRelativeTo(null);
}
//GEN-BEGIN:initComponents
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jb_logon = new javax.swing.JButton();
jb_register = new javax.swing.JButton();
userNameTxt = new javax.swing.JTextField();
passwordTxt = new javax.swing.JPasswordField();
jb_reset = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("\u9910\u5385\u70b9\u9910\u7cfb\u7edf");
setResizable(false);
jLabel1.setFont(new java.awt.Font("宋体", 1, 24));
jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/OrderMeal.png"))); // NOI18N
jLabel1
.setText("\u9910\u5385\u70b9\u9910\u7cfb\u7edf\u6b22\u8fce\u60a8");
jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/userName.png"))); // NOI18N
jLabel2.setText("\u7528\u6237\u540d\uff1a");
jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/password.png"))); // NOI18N
jLabel3.setText("\u5bc6 \u7801\uff1a");
jb_logon.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/login.png"))); // NOI18N
jb_logon.setText("\u767b\u9646");
jb_logon.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jb_logonActionPerformed(evt);}});
jb_register.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/register.png"))); // NOI18N
jb_register.setText("\u6ce8\u518c\u7528\u6237");
jb_register.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jb_registerActionPerformed(evt);}});
jb_reset.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/reset.png"))); // NOI18N
jb_reset.setText("\u91cd\u7f6e");
jb_reset.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jb_resetActionPerformed(evt);}});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
getContentPane());
getContentPane().setLayout(layout);
layout
.setHorizontalGroup(layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
javax.swing.GroupLayout.Alignment.TRAILING,
layout
.createSequentialGroup()
.addGap(52, 52, 52)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(
jLabel2)
.addComponent(
jLabel3))
.addGap(
33,
33,
33)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING,
false)
.addComponent(
passwordTxt)
.addComponent(
userNameTxt,
javax.swing.GroupLayout.DEFAULT_SIZE,
193,
Short.MAX_VALUE)))
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(
javax.swing.GroupLayout.Alignment.LEADING,
layout
.createSequentialGroup()
.addGap(
8,
8,
8)
.addComponent(
jb_logon)
.addGap(
18,
18,
18)
.addComponent(
jb_reset)
.addGap(
18,
18,
18)
.addComponent(
jb_register))
.addComponent(
jLabel1,
javax.swing.GroupLayout.PREFERRED_SIZE,
304,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(54, Short.MAX_VALUE)));
layout
.setVerticalGroup(layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addGap(18, 18, 18)
.addComponent(
jLabel1,
javax.swing.GroupLayout.PREFERRED_SIZE,
58,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(27, 27, 27)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(
userNameTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(38, 38, 38)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(
passwordTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(37, 37, 37)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jb_logon)
.addComponent(jb_reset)
.addComponent(
jb_register))
.addContainerGap(55, Short.MAX_VALUE)));
pack();
}// </editor-fold>
//GEN-END:initComponents
//显示注册页面
private void jb_registerActionPerformed(java.awt.event.ActionEvent evt) {
this.dispose();
new RegisterFrm().setVisible(true);
}
//登陆验证显示登陆以后界面
private void jb_logonActionPerformed(java.awt.event.ActionEvent evt) {
String userName = this.userNameTxt.getText();
String password = new String(this.passwordTxt.getPassword());
if (StringUtil.isEmpty(userName)) {
JOptionPane.showMessageDialog(null, "用户名不能为空");
return;
}
if (StringUtil.isEmpty(password)) {
JOptionPane.showMessageDialog(null, "密码不能为空");
return;
}
User user = new User(userName, password);
Connection con = null;
try {
con = dbUtil.getCon();
User currentUser = userDao.login(con, user);
if (currentUser != null) {
s_currentUser = currentUser;//保存登陆的用户
int role = currentUser.getRank();
if (role == 1) {
this.dispose();
new AdminFrm().setVisible(true);//进入管理员页面
} else if (role == 0) {
this.dispose();
new UserOrderFrm().setVisible(true);//进入用户点餐界面
}
} else {
JOptionPane.showMessageDialog(null, "用户名或密码错误");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
JOptionPane.showMessageDialog(null, "用户名或密码错误");
} finally {
try {
dbUtil.closeCon(con);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace(); } }}
//重置文本框内容
private void jb_resetActionPerformed(java.awt.event.ActionEvent evt) {
this.passwordTxt.setText("");
this.userNameTxt.setText("");}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new LogOnFrm().setVisible(true);
}});}}
OrderGoodsInterFrm
package sut.rj.view;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.Vector;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import sut.rj.dao.GoodsDao;
import sut.rj.dao.OrderDao;
import sut.rj.model.Goods;
import sut.rj.model.Order;
import sut.rj.dbconnection.DbUtil;
import sut.rj.dbconnection.StringUtil;
public class OrderGoodsInterFrm extends javax.swing.JInternalFrame {
//GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JTable cartTable;
private javax.swing.JTable goodsTable;
private javax.swing.JLabel iamgeLb;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JPanel jPanel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JButton jb_add;
private javax.swing.JButton jb_delete;
private javax.swing.JButton jb_ok;
private javax.swing.JTextField totalMoneyTxt;
private javax.swing.JTextField totalNumTxt;
// End of variables declaration//GEN-END:variables
private static final long serialVersionUID = 1L;
//实现序列化,serialVersionUID 用来表明实现序列化类的不同版本间的兼容性
DbUtil dbUtil = new DbUtil();
GoodsDao goodsDao = new GoodsDao();
OrderDao orderDao = new OrderDao();
/** Creates new form OrderGoodsFrm */
public OrderGoodsInterFrm() {
initComponents();
this.setLocation(220, 100);
this.fillGoodsTable(new Goods());}
@SuppressWarnings("unchecked")
private void fillGoodsTable(Goods goods) {
DefaultTableModel dtm = (DefaultTableModel) goodsTable.getModel();
//清空之前显示
dtm.setRowCount(0);
Connection con = null;
try {
con = dbUtil.getCon();
ResultSet rs = goodsDao.goodsList(con, goods);
while (rs.next()) {
Vector v = new Vector();
v.add(rs.getString("id"));
v.add(rs.getString("goodsName"));
v.add(rs.getString("goodsDesc"));
v.add(rs.getString("price"));
v.add(rs.getString("imageLink"));
dtm.addRow(v);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
dbUtil.closeCon(con);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace(); }}}
//GEN-BEGIN:initComponents
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jScrollPane2 = new javax.swing.JScrollPane();
cartTable = new javax.swing.JTable();
jPanel2 = new javax.swing.JPanel();
iamgeLb = new javax.swing.JLabel();
jb_add = new javax.swing.JButton();
jb_ok = new javax.swing.JButton();
jb_delete = new javax.swing.JButton();
totalMoneyTxt = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
totalNumTxt = new javax.swing.JTextField();
jScrollPane1 = new javax.swing.JScrollPane();
goodsTable = new javax.swing.JTable();
setClosable(true);
setIconifiable(true);
setTitle("\u7528\u6237\u70b9\u9910\u4e3b\u754c\u9762");
cartTable.setModel(new javax.swing.table.DefaultTableModel(
new Object[][] {
}, new String[] { "套餐编号", "套餐名称", "套餐数量", "套餐单价", "套餐金额" }) {
private static final long serialVersionUID = 1L;
boolean[] canEdit = new boolean[] { false, false, false, false,
false };
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit[columnIndex];}});
jScrollPane2.setViewportView(cartTable);
jPanel2.setBorder(javax.swing.BorderFactory
.createTitledBorder("\u5957\u9910\u56fe\u7247"));
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(
jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(jPanel2Layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addComponent(
iamgeLb, javax.swing.GroupLayout.DEFAULT_SIZE, 72,
Short.MAX_VALUE));
jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addComponent(
iamgeLb, javax.swing.GroupLayout.DEFAULT_SIZE, 65,
Short.MAX_VALUE));
jb_add.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/cart.png"))); // NOI18N
jb_add.setText("\u52a0\u5165\u8d2d\u7269\u8f66");
jb_add.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jb_addActionPerformed(evt);}});
jb_ok.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/ok.png"))); // NOI18N
jb_ok.setText("\u7ed3\u7b97");
jb_ok.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jb_okActionPerformed(evt);}});
jb_delete.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/delete.png"))); // NOI18N
jb_delete.setText("\u5220\u9664");
jb_delete.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jb_deleteActionPerformed(evt);}});
totalMoneyTxt.setEditable(false);
jLabel1.setText("\u603b\u91d1\u989d\uff1a");
jLabel2.setText("\u603b\u6570\u91cf\uff1a");
totalNumTxt.setEditable(false);
goodsTable.setModel(new javax.swing.table.DefaultTableModel(
new Object[][] {
}, new String[] { "序号", "套餐名称", "套餐描述", "套餐价格", "图片地址" }) {
private static final long serialVersionUID = 1L;
boolean[] canEdit = new boolean[] { false, false, false, false,
false };
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit[columnIndex];}});
goodsTable.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
goodsTableMousePressed(evt);}});
jScrollPane1.setViewportView(goodsTable);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
getContentPane());
getContentPane().setLayout(layout);
layout
.setHorizontalGroup(layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addContainerGap()
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(
layout
.createSequentialGroup()
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(
jb_add)
.addGroup(
layout
.createSequentialGroup()
.addComponent(
jScrollPane1,
javax.swing.GroupLayout.DEFAULT_SIZE,
449,
Short.MAX_VALUE)
.addGap(
6,
6,
6)
.addComponent(
jPanel2,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING,
false)
.addGroup(
javax.swing.GroupLayout.Alignment.TRAILING,
layout
.createSequentialGroup()
.addComponent(
jb_delete)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED,
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addComponent(
jb_ok))
.addComponent(
jScrollPane2,
javax.swing.GroupLayout.PREFERRED_SIZE,
510,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(
layout
.createSequentialGroup()
.addComponent(
jLabel2)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
totalNumTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
76,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
jLabel1)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
totalMoneyTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
81,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap()));
layout
.setVerticalGroup(layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addGap(32, 32, 32)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(
layout
.createSequentialGroup()
.addComponent(
jPanel2,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED,
60,
Short.MAX_VALUE))
.addGroup(
layout
.createSequentialGroup()
.addComponent(
jScrollPane1,
javax.swing.GroupLayout.PREFERRED_SIZE,
122,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(
18,
18,
18)))
.addComponent(
jb_add))
.addComponent(
jScrollPane2,
javax.swing.GroupLayout.PREFERRED_SIZE,
169,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jLabel2)
.addComponent(
totalNumTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(
totalMoneyTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jb_ok)
.addComponent(jb_delete))
.addContainerGap(43, Short.MAX_VALUE)));
pack();
}// </editor-fold>
//GEN-END:initComponents
private void jb_okActionPerformed(java.awt.event.ActionEvent evt) {
String userName = LogOnFrm.s_currentUser.getUserName();//
//生成订单号
String orderId = new java.text.SimpleDateFormat("yyyyMMddHHmmss")
.format(new java.util.Date());//将当前时间作为订单号码
float orderTotalMoney = Float.parseFloat(this.totalMoneyTxt.getText());//
int orderNum = Integer.parseInt(this.totalNumTxt.getText());//
int rowNum = cartTable.getRowCount();//计算行数
if (rowNum == 0) {
JOptionPane.showMessageDialog(null, "请添加上商品后再结算!");
return;
}
Connection con = null;
try {
con = dbUtil.getCon();
Order order = new Order(orderId, 0, orderNum, orderTotalMoney,
userName);
int addNum = orderDao.order_infoAdd(con, order);//插入数据到order_info表
if (addNum == 1) {
for (int i = 0; i < rowNum; i++) {
int goodsId = Integer.parseInt((String) cartTable
.getValueAt(i, 0));
String goodsName = (String) cartTable.getValueAt(i, 1);
int goodsNum = Integer.parseInt((String) cartTable
.getValueAt(i, 2));
float goodsPrice = Float.parseFloat((String) cartTable
.getValueAt(i, 3));
float goodsTotalPrice = Float.parseFloat((String) cartTable
.getValueAt(i, 4));
order = new Order(orderId, goodsTotalPrice, goodsId,
goodsPrice, goodsNum, goodsName);
//循环插入数据到order_goods表
addNum += orderDao.order_goodsAdd(con, order);
}
} else {
JOptionPane.showMessageDialog(null, "订单提交失败");
}
if (addNum == (1 + rowNum)) {
JOptionPane.showMessageDialog(null, "订单提交成功,请记住您的定单号:"
+ orderId);
} else {
JOptionPane.showMessageDialog(null, "订单提交失败");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
JOptionPane.showMessageDialog(null, "订单提交失败");
} finally {
try {
dbUtil.closeCon(con);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}}
DefaultTableModel dtm = (DefaultTableModel) cartTable.getModel();
//删除选择的行
dtm.setRowCount(0);
fillCartTable();
}
private void fillCartTable() {
//修改商品总数和总金额
int rowNum = cartTable.getRowCount();//计算行数
int totalNum = 0;//总数量
float totalMoney = 0;//总金额
//累加总数量和总金额
for (int i = 0; i < rowNum; i++) {
totalNum += Integer.parseInt((String) cartTable.getValueAt(i, 2));
totalMoney += Float.parseFloat((String) cartTable.getValueAt(i, 4));
}
//文本框赋值
this.totalNumTxt.setText(Integer.toString(totalNum));
this.totalMoneyTxt.setText(Float.toString(totalMoney));
}
private void jb_deleteActionPerformed(java.awt.event.ActionEvent evt) {
int row = cartTable.getSelectedRow();
if (row == -1) {
JOptionPane.showMessageDialog(null, "请选择要删除的行!");
} else {
DefaultTableModel dtm = (DefaultTableModel) cartTable.getModel();
//删除选择的行
dtm.removeRow(row);
}
fillCartTable();
}
@SuppressWarnings("unchecked")
private void jb_addActionPerformed(java.awt.event.ActionEvent evt) {
DefaultTableModel dtm = (DefaultTableModel) cartTable.getModel();
//获取选中的行
int row = goodsTable.getSelectedRow();
if (row < 0) {
JOptionPane.showMessageDialog(null, "请选择一种套餐");
return;
}
//在表单中购物车table中显示加入的数据
int i = 0, flag = 0;//标记是否已经存在
int rowNum = cartTable.getRowCount();
for (i = 0; i < rowNum; i++) {
if (goodsTable.getValueAt(row, 0)
.equals(cartTable.getValueAt(i, 0))) {
flag = 1;
break;}}
if (flag == 0) {
Vector v = new Vector();
v.add((String) goodsTable.getValueAt(row, 0));
v.add((String) goodsTable.getValueAt(row, 1));
v.add("1");
v.add((String) goodsTable.getValueAt(row, 3));
v.add((String) goodsTable.getValueAt(row, 3));
dtm.addRow(v);
} else {
int goodsNum = Integer
.parseInt((String) cartTable.getValueAt(i, 2)) + 1;//获取当前数量
float goodsPrice = Float.parseFloat((String) cartTable.getValueAt(
i, 3));//获取当前单价
goodsPrice = goodsPrice
+ Float.parseFloat((String) cartTable.getValueAt(i, 4));//获取数量修改以后的总价
this.cartTable.setValueAt(Integer.toString(goodsNum), i, 2);
this.cartTable.setValueAt(Float.toString(goodsPrice), i, 4);
}
fillCartTable();}
private void goodsTableMousePressed(java.awt.event.MouseEvent evt) {
//获取选中的行
int row = goodsTable.getSelectedRow();
String picturePath = (String) goodsTable.getValueAt(row, 4);
if (StringUtil.isNotEmpty(picturePath)) {
Icon icon = new ImageIcon(picturePath);
this.iamgeLb.setIcon(icon);
} else {
this.iamgeLb.setIcon(null); }}}
RegisterFrm
package sut.rj.view;
import java.sql.Connection;
import javax.swing.*;
import sut.rj.dao.UserDao;
import sut.rj.model.User;
import sut.rj.dbconnection.DbUtil;
import sut.rj.dbconnection.StringUtil;
public class RegisterFrm extends javax.swing.JFrame {
//GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JTextField emailTxt;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JButton jb_register;
private javax.swing.JButton jb_reset;
private javax.swing.JPasswordField passwordConfirmTxt;
private javax.swing.JPasswordField passwordTxt;
private javax.swing.JTextField userNameTxt;
// End of variables declaration//GEN-END:variables
private static final long serialVersionUID = 1L;
//实现序列化,serialVersionUID 用来表明实现序列化类的不同版本间的兼容性
DbUtil dbUtil = new DbUtil();
UserDao userDao = new UserDao();
/** Creates new form RegisterFrm */
public RegisterFrm() {
initComponents();
//设置frame居中显示
this.setLocationRelativeTo(null);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
//GEN-BEGIN:initComponents
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jb_register = new javax.swing.JButton();
jb_reset = new javax.swing.JButton();
userNameTxt = new javax.swing.JTextField();
emailTxt = new javax.swing.JTextField();
passwordTxt = new javax.swing.JPasswordField();
passwordConfirmTxt = new javax.swing.JPasswordField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("\u65b0\u7528\u6237\u6ce8\u518c");
setResizable(false);
jLabel1.setFont(new java.awt.Font("宋体", 1, 18));
jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/new_register.png"))); // NOI18N
jLabel1.setText("\u65b0\u7528\u6237\u6ce8\u518c");
jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/new_user.png"))); // NOI18N
jLabel2.setText("\u7528\u6237\u540d\uff1a");
jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/new_password.png"))); // NOI18N
jLabel3.setText("\u5bc6\u7801\uff1a");
jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/password_config.png"))); // NOI18N
jLabel4.setText("\u786e\u8ba4\u5bc6\u7801\uff1a");
jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/email.png"))); // NOI18N
jLabel5.setText("\u90ae\u7bb1\uff1a");
jb_register.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/register.png"))); // NOI18N
jb_register.setText("\u6ce8\u518c");
jb_register.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jb_registerActionPerformed(evt);}});
jb_reset.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/reset.png"))); // NOI18N
jb_reset.setText("\u91cd\u7f6e");
jb_reset.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jb_resetActionPerformed(evt);}});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
getContentPane());
getContentPane().setLayout(layout);
layout
.setHorizontalGroup(layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addGap(
95,
95,
95)
.addComponent(
jLabel1))
.addGroup(
layout
.createSequentialGroup()
.addGap(
57,
57,
57)
.addComponent(
jb_register)
.addGap(
63,
63,
63)
.addComponent(
jb_reset)))
.addContainerGap())
.addGroup(
layout
.createSequentialGroup()
.addGap(40, 40, 40)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jLabel5)
.addComponent(jLabel3)
.addComponent(jLabel4))
.addGap(28, 28, 28)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(
passwordConfirmTxt,
javax.swing.GroupLayout.DEFAULT_SIZE,
146,
Short.MAX_VALUE)
.addComponent(
emailTxt,
javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE,
146,
Short.MAX_VALUE)
.addComponent(
userNameTxt,
javax.swing.GroupLayout.DEFAULT_SIZE,
146,
Short.MAX_VALUE)
.addComponent(
passwordTxt,
javax.swing.GroupLayout.DEFAULT_SIZE,
146,
Short.MAX_VALUE))
.addGap(40, 40, 40)));
layout
.setVerticalGroup(layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addGap(19, 19, 19)
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(
userNameTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(
passwordTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED,
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(
passwordConfirmTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(
emailTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5))
.addGap(28, 28, 28)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(
jb_register)
.addComponent(jb_reset))
.addGap(55, 55, 55)));
pack();
}// </editor-fold>
//GEN-END:initComponents
//注册验证操作
private void jb_registerActionPerformed(java.awt.event.ActionEvent evt) {
String userName = this.userNameTxt.getText();
String password = new String(this.passwordTxt.getPassword());
String passwordConfirm = new String(this.passwordConfirmTxt
.getPassword());
String email = this.emailTxt.getText();
if (StringUtil.isEmpty(userName)) {
JOptionPane.showMessageDialog(null, "用户名不能为空");
return;
}
if (StringUtil.isEmpty(password)) {
JOptionPane.showMessageDialog(null, "密码不能为空");
return;
}
if (!password.equals(passwordConfirm)) {
JOptionPane.showMessageDialog(null, "两次输入的密码不一致!");
return;
}
if (!StringUtil.checkEmail(email)) {
JOptionPane.showMessageDialog(null, "邮箱格式错误!");
return;
}
User user = new User(userName, password, email);
Connection con = null;
try {
con = dbUtil.getCon();
if (!userDao.isUserExist(con, user)) {
int addNum = userDao.userAdd(con, user);
if (addNum == 1) {
JOptionPane.showMessageDialog(null, "注册成功!");
this.dispose();
new LogOnFrm().setVisible(true);
} else {
JOptionPane.showMessageDialog(null, "注册失败");
}
} else {
JOptionPane.showMessageDialog(null, "用户名存在,请重新输入!");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
JOptionPane.showMessageDialog(null, "注册失败,请重新注册!");
} finally {
try {
dbUtil.closeCon(con);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}}}
//重置表单
private void jb_resetActionPerformed(java.awt.event.ActionEvent evt) {
this.userNameTxt.setText("");
this.passwordTxt.setText("");
this.passwordConfirmTxt.setText("");
this.emailTxt.setText("");}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new RegisterFrm().setVisible(true);}});}}
UserOrderFrm
package sut.rj.view;
import javax.swing.*;
public class UserOrderFrm extends javax.swing.JFrame {
//GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JMenu jMenu2;
private javax.swing.JMenu jMenu3;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenu jm_order;
private javax.swing.JMenuItem jmiExit;
private javax.swing.JMenuItem jmi_checkOrder;
private javax.swing.JMenuItem jmi_modify;
private javax.swing.JMenuItem jmi_order;
private javax.swing.JDesktopPane table;
// End of variables declaration//GEN-END:variables
private static final long serialVersionUID = 1L;
//实现序列化,serialVersionUID 用来表明实现序列化类的不同版本间的兼容性
/** Creates new form UserFrm */
public UserOrderFrm() {
initComponents();
//设置最大化
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
}
//GEN-BEGIN:initComponents
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
table = new javax.swing.JDesktopPane();
jMenuBar1 = new javax.swing.JMenuBar();
jm_order = new javax.swing.JMenu();
jmi_order = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();
jmi_checkOrder = new javax.swing.JMenuItem();
jMenu3 = new javax.swing.JMenu();
jmi_modify = new javax.swing.JMenuItem();
jmiExit = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("\u7528\u6237\u70b9\u9910\u4e3b\u754c\u9762");
jm_order.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/order3.png"))); // NOI18N
jm_order.setText("\u7528\u6237\u70b9\u9910");
jmi_order.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/cart.png"))); // NOI18N
jmi_order.setText("\u5f00\u59cb\u70b9\u9910");
jmi_order.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jmi_orderActionPerformed(evt);
}
});
jm_order.add(jmi_order);
jMenuBar1.add(jm_order);
jMenu2.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/search1.png"))); // NOI18N
jMenu2.setText("\u8ba2\u5355\u8be6\u60c5");
jmi_checkOrder.setIcon(new javax.swing.ImageIcon(getClass()
.getResource("/images/ok.png"))); // NOI18N
jmi_checkOrder.setText("\u67e5\u770b\u8ba2\u5355");
jmi_checkOrder.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jmi_checkOrderActionPerformed(evt);
}
});
jMenu2.add(jmi_checkOrder);
jMenuBar1.add(jMenu2);
jMenu3.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/order2.png"))); // NOI18N
jMenu3.setText("\u5176\u4ed6");
jmi_modify.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/edit.png"))); // NOI18N
jmi_modify.setText("\u4fe1\u606f\u4fee\u6539");
jmi_modify.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jmi_modifyActionPerformed(evt);
}
});
jMenu3.add(jmi_modify);
jmiExit.setIcon(new javax.swing.ImageIcon(getClass().getResource(
"/images/exit.png"))); // NOI18N
jmiExit.setText("\u9000\u51fa\u7cfb\u7edf");
jmiExit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jmiExitActionPerformed(evt);
}
});
jMenu3.add(jmiExit);
jMenuBar1.add(jMenu3);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addComponent(table,
javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE));
layout.setVerticalGroup(layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addComponent(table,
javax.swing.GroupLayout.DEFAULT_SIZE, 277, Short.MAX_VALUE));
pack();
}// </editor-fold>
//GEN-END:initComponents
//修改用户信息按钮
private void jmi_modifyActionPerformed(java.awt.event.ActionEvent evt) {
AccountModifyInterFrm accountModify = new AccountModifyInterFrm();
accountModify.setVisible(true);
this.table.add(accountModify);
}
//查看订单按钮
private void jmi_checkOrderActionPerformed(java.awt.event.ActionEvent evt) {
CheckOrderInterFrm CheckOrderInterFrm = new CheckOrderInterFrm();
CheckOrderInterFrm.setVisible(true);
this.table.add(CheckOrderInterFrm);
}
//退出按钮
private void jmiExitActionPerformed(java.awt.event.ActionEvent evt) {
int result = JOptionPane.showConfirmDialog(null, "是否退出系统?");
//System.out.println(result);
if (result == 0)
this.dispose();
}
//点餐按钮
private void jmi_orderActionPerformed(java.awt.event.ActionEvent evt) {
OrderGoodsInterFrm orderGoodsInterFrm = new OrderGoodsInterFrm();
orderGoodsInterFrm.setVisible(true);
this.table.add(orderGoodsInterFrm);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new UserOrderFrm().setVisible(true);}});}}