大家好,又见面了,我是你们的朋友全栈君。
代码写得烂,写博客纯属记录! 微信公众号:BugLass
码云仓库地址:https://gitee.com/ynavc/tourism_sys
源代码及文档打包下载:https://download.csdn.net/download/weixin_44893902/12819432
目录
一、需求简介:
该旅游管理信息系统可以为游客和公司业务管理员提供服务。游客可以对旅游路线,旅游班次,旅游团,保险,导游,交通工具以及宾馆的信息查询,并且游客可以在线报名旅游。同时公司业务管理员可以对所有报名信息进行处理,确认之后导出报名信息交由旅行社。
业务流程及系统概念模型如下:
游客:
业务管理员:
旅游业务模型:
整体概要设计:
二、界面示例:
首页:
点击报名:如果没有登录提示游客登录
登录界面:
注册界面:
报名:
报名信息管理界面:
报名信息导出生成EXCEL表格:
三、实现代码:
1、数据库:
/*
Navicat MySQL Data Transfer
Source Server : test
Source Server Version : 50646
Source Host : localhost:3306
Source Database : travel_manage
Target Server Type : MYSQL
Target Server Version : 50646
File Encoding : 65001
Date: 2020-09-02 10:15:48
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for tourism_group
-- ----------------------------
DROP TABLE IF EXISTS `tourism_group`;
CREATE TABLE `tourism_group` (
`group_num` int(10) NOT NULL AUTO_INCREMENT,
`group_name` varchar(20) NOT NULL,
`group_contact` varchar(20) NOT NULL,
`group_address` varchar(20) NOT NULL,
`group_phone` varchar(20) NOT NULL,
PRIMARY KEY (`group_num`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of tourism_group
-- ----------------------------
INSERT INTO `tourism_group` VALUES ('1', '魔方格旅游团', '杨文', '云南省昆明市五华区龙翔街道茭菱路128号', '18214217246');
-- ----------------------------
-- Table structure for tourism_line
-- ----------------------------
DROP TABLE IF EXISTS `tourism_line`;
CREATE TABLE `tourism_line` (
`route_num` int(10) NOT NULL AUTO_INCREMENT,
`origin` varchar(30) NOT NULL,
`destination` varchar(30) NOT NULL,
`day_num` int(10) NOT NULL,
`attractions` varchar(30) NOT NULL,
PRIMARY KEY (`route_num`)
) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of tourism_line
-- ----------------------------
INSERT INTO `tourism_line` VALUES ('1', '昆明', '丽江', '10', '丽江古城');
INSERT INTO `tourism_line` VALUES ('2', '昆明', '大理', '5', '大理古城');
INSERT INTO `tourism_line` VALUES ('10', '昆明', '丽江', '10', '大观楼');
INSERT INTO `tourism_line` VALUES ('11', '昆明', '湖南', '5', '翠湖');
INSERT INTO `tourism_line` VALUES ('12', '昆明', '上海', '3', '世博园');
INSERT INTO `tourism_line` VALUES ('13', '昆明', '南京', '6', '花之城');
INSERT INTO `tourism_line` VALUES ('14', '昆明', '上海', '7', '瀑布公园');
INSERT INTO `tourism_line` VALUES ('15', '昆明', '武汉', '8', '花之城');
INSERT INTO `tourism_line` VALUES ('16', '昆明', '成都', '3', '世博园');
INSERT INTO `tourism_line` VALUES ('17', '昆明', '四川', '11', '翠湖');
INSERT INTO `tourism_line` VALUES ('18', '昆明', '贵州', '4', '湿地公园');
INSERT INTO `tourism_line` VALUES ('19', '昆明', '遵义', '14', '花之城');
INSERT INTO `tourism_line` VALUES ('20', '昆明', '长沙', '8', '陆军讲武堂');
INSERT INTO `tourism_line` VALUES ('21', '昆明', '建水', '9', '大观楼');
INSERT INTO `tourism_line` VALUES ('22', '昆明', '红河', '7', '翠湖');
-- ----------------------------
-- Table structure for tourist
-- ----------------------------
DROP TABLE IF EXISTS `tourist`;
CREATE TABLE `tourist` (
`tourist_num` int(20) NOT NULL AUTO_INCREMENT,
`user_id` int(20) NOT NULL,
`tourist_name` varchar(20) NOT NULL,
`tourist_sex` char(10) NOT NULL,
`tourist_age` int(20) NOT NULL,
`tourist_idcard` varchar(20) NOT NULL,
`tourist_address` varchar(50) NOT NULL,
`tourist_phone` varchar(20) NOT NULL,
`group_num` int(11) NOT NULL,
`accompanied` varchar(20) NOT NULL,
`accommodation` varchar(20) NOT NULL,
PRIMARY KEY (`tourist_num`)
) ENGINE=InnoDB AUTO_INCREMENT=52 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Table structure for user
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`user_id` int(11) NOT NULL AUTO_INCREMENT,
`user_account` varchar(20) NOT NULL,
`user_password` varchar(20) NOT NULL,
`user_type` varchar(20) NOT NULL,
`user_state` varchar(20) NOT NULL,
PRIMARY KEY (`user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of user
-- ----------------------------
INSERT INTO `user` VALUES ('1', '杨明金', '123456', '管理员', '已登录');
INSERT INTO `user` VALUES ('2', '颜权昌', '111111', '游客', '未登录');
INSERT INTO `user` VALUES ('4', '郭超', '111111', '游客', '未登录');
INSERT INTO `user` VALUES ('5', '冯润泽', '111111', '游客', '未登录');
2、Java
com.ynavc.Bean
Tourism_Group.Java
package com.ynavc.Bean;
//旅游团表
public class Tourism_Group {
String group_num;//团号
String group_name;//团名
String group_contact;//联系人
String group_address;//地址
String group_phone;//电话
@Override
public String toString() {
return "Tourism_Group [group_num=" + group_num + ", group_name=" + group_name + ", group_contact="
+ group_contact + ", group_address=" + group_address + ", group_phone=" + group_phone + "]";
}
public Tourism_Group(String group_num, String group_name, String group_contact, String group_address,
String group_phone) {
super();
this.group_num = group_num;
this.group_name = group_name;
this.group_contact = group_contact;
this.group_address = group_address;
this.group_phone = group_phone;
}
public Tourism_Group() {
super();
}
public String getGroup_num() {
return group_num;
}
public void setGroup_num(String group_num) {
this.group_num = group_num;
}
public String getGroup_name() {
return group_name;
}
public void setGroup_name(String group_name) {
this.group_name = group_name;
}
public String getGroup_contact() {
return group_contact;
}
public void setGroup_contact(String group_contact) {
this.group_contact = group_contact;
}
public String getGroup_address() {
return group_address;
}
public void setGroup_address(String group_address) {
this.group_address = group_address;
}
public String getGroup_phone() {
return group_phone;
}
public void setGroup_phone(String group_phone) {
this.group_phone = group_phone;
}
}
Tourism_Line.Java
package com.ynavc.Bean;
//旅游线路表
public class Tourism_Line {
String route_num;//路线号
String origin;//起点
String destination;//终点
String day_num;//天数
String attractions;//主要景点
@Override
public String toString() {
return "Tourism_Line [route_num=" + route_num + ", origin=" + origin + ", destination=" + destination
+ ", day_num=" + day_num + ", attractions=" + attractions + "]";
}
public Tourism_Line(String route_num, String origin, String destination, String day_num, String attractions) {
super();
this.route_num = route_num;
this.origin = origin;
this.destination = destination;
this.day_num = day_num;
this.attractions = attractions;
}
public Tourism_Line() {
super();
}
public String getRoute_num() {
return route_num;
}
public void setRoute_num(String route_num) {
this.route_num = route_num;
}
public String getOrigin() {
return origin;
}
public void setOrigin(String origin) {
this.origin = origin;
}
public String getDestination() {
return destination;
}
public void setDestination(String destination) {
this.destination = destination;
}
public String getDay_num() {
return day_num;
}
public void setDay_num(String day_num) {
this.day_num = day_num;
}
public String getAttractions() {
return attractions;
}
public void setAttractions(String attractions) {
this.attractions = attractions;
}
}
Tourist.Java
package com.ynavc.Bean;
//游客信息表
public class Tourist {
String tourist_num;//游客编号
String user_id;//用户ID
String tourist_name;//姓名
String tourist_sex;//性别
String tourist_age;//年龄
String tourist_idCard;//身份证号码
String tourist_address;//地址
String tourist_phone;//电话
String group_num;//旅游团号
String accompanied;//陪同
String accommodation;//食宿
@Override
public String toString() {
return "Tourist [tourist_num=" + tourist_num + ", user_id=" + user_id + ", tourist_name=" + tourist_name
+ ", tourist_sex=" + tourist_sex + ", tourist_age=" + tourist_age + ", tourist_idCard=" + tourist_idCard
+ ", tourist_address=" + tourist_address + ", tourist_phone=" + tourist_phone + ", group_num="
+ group_num + ", acompanied=" + accompanied + ", accommdation=" + accommodation + "]";
}
public Tourist(String tourist_num, String user_id, String tourist_name, String tourist_sex, String tourist_age,
String tourist_idCard, String tourist_address, String tourist_phone, String group_num, String acompanied,
String accommdation) {
super();
this.tourist_num = tourist_num;
this.user_id = user_id;
this.tourist_name = tourist_name;
this.tourist_sex = tourist_sex;
this.tourist_age = tourist_age;
this.tourist_idCard = tourist_idCard;
this.tourist_address = tourist_address;
this.tourist_phone = tourist_phone;
this.group_num = group_num;
this.accompanied = acompanied;
this.accommodation = accommdation;
}
public Tourist() {
super();
}
public String getTourist_num() {
return tourist_num;
}
public void setTourist_num(String tourist_num) {
this.tourist_num = tourist_num;
}
public String getUser_id() {
return user_id;
}
public void setUser_id(String user_id) {
this.user_id = user_id;
}
public String getTourist_name() {
return tourist_name;
}
public void setTourist_name(String tourist_name) {
this.tourist_name = tourist_name;
}
public String getTourist_sex() {
return tourist_sex;
}
public void setTourist_sex(String tourist_sex) {
this.tourist_sex = tourist_sex;
}
public String getTourist_age() {
return tourist_age;
}
public void setTourist_age(String tourist_age) {
this.tourist_age = tourist_age;
}
public String getTourist_idCard() {
return tourist_idCard;
}
public void setTourist_idCard(String tourist_idCard) {
this.tourist_idCard = tourist_idCard;
}
public String getTourist_address() {
return tourist_address;
}
public void setTourist_address(String tourist_address) {
this.tourist_address = tourist_address;
}
public String getTourist_phone() {
return tourist_phone;
}
public void setTourist_phone(String tourist_phone) {
this.tourist_phone = tourist_phone;
}
public String getGroup_num() {
return group_num;
}
public void setGroup_num(String group_num) {
this.group_num = group_num;
}
public String getAccompanied() {
return accompanied;
}
public void setAccompanied(String accompanied) {
this.accompanied = accompanied;
}
public String getAccommodation() {
return accommodation;
}
public void setAccommodation(String accommdation) {
this.accommodation = accommdation;
}
}
User.Java
package com.ynavc.Bean;
//用户登录信息表
public class User {
String user_id;//用户ID
String user_account;//用户账户
String user_password;//用户密码
String user_type;//用户类型
@Override
public String toString() {
return "User [user_id=" + user_id + ", user_account=" + user_account + ", user_password=" + user_password
+ ", user_type=" + user_type + "]";
}
public User() {
super();
}
public User(String user_id, String user_account, String user_password, String user_type) {
super();
this.user_id = user_id;
this.user_account = user_account;
this.user_password = user_password;
this.user_type = user_type;
}
public String getUser_id() {
return user_id;
}
public void setUser_id(String user_id) {
this.user_id = user_id;
}
public String getUser_account() {
return user_account;
}
public void setUser_account(String user_account) {
this.user_account = user_account;
}
public String getUser_password() {
return user_password;
}
public void setUser_password(String user_password) {
this.user_password = user_password;
}
public String getUser_type() {
return user_type;
}
public void setUser_type(String user_type) {
this.user_type = user_type;
}
}
com.ynavc.Controller
Select.Java
package com.ynavc.Controller;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import com.ynavc.Bean.Tourism_Line;
import com.ynavc.Bean.Tourist;
import com.ynavc.Dao.DbConnection;
public class Select{
//查询数据条数
public int getCount(String sql) {
ResultSet resultSet=DbConnection.query(sql);
try {
if (resultSet.next()) {
return resultSet.getInt(1);
}
} catch (SQLException e) {
e.printStackTrace();
}
return 0;
}
//得到一条数据
public String getString(String sql) {
ResultSet resultSet=DbConnection.query(sql);
try {
if (resultSet.next()) {
return resultSet.getString(1);
}
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
//用户登录
public int Select(String account ,String password) {
String sql="select * from UserInfo where password='"+password+"' and account='"+account+"'";
ResultSet resultSet=DbConnection.query(sql);
int a=0;
try {
while (resultSet.next()) {
a=1;
}
} catch (SQLException e) {
e.printStackTrace();
}
return a;
}
//旅游信息表
public Object[][] getLineInfo() {
String sql="SELECT * FROM tourism_line";
ResultSet resultSet = DbConnection.query(sql);
ArrayList<Tourism_Line> list=new ArrayList<Tourism_Line>();
try {
while (resultSet.next()) {
Tourism_Line t=new Tourism_Line();
t.setRoute_num(resultSet.getString(1));
t.setOrigin(resultSet.getString(2));
t.setDestination(resultSet.getString(3));
t.setDay_num(resultSet.getString(4));
t.setAttractions(resultSet.getString(5));
list.add(t);
}
} catch (SQLException e) {
e.printStackTrace();
}
Object[][] objects=new Object[list.size()][5];
for(int i=0;i<list.size();i++) {
objects[i][0]=list.get(i).getRoute_num();
objects[i][1]=list.get(i).getOrigin();
objects[i][2]=list.get(i).getDestination();
objects[i][3]=list.get(i).getDay_num();
objects[i][4]=list.get(i).getAttractions();
}
return objects;
}
//旅游信息表
public Object[][] getTourist(String sql) {
// String sql="SELECT * FROM tourist";
ResultSet resultSet = DbConnection.query(sql);
ArrayList<Tourist> list=new ArrayList<Tourist>();
try {
while (resultSet.next()) {
Tourist t=new Tourist();
t.setTourist_num(resultSet.getString(1));
t.setUser_id(resultSet.getString(2));
t.setTourist_name(resultSet.getString(3));
t.setTourist_sex(resultSet.getString(4));
t.setTourist_age(resultSet.getString(5));
t.setTourist_idCard(resultSet.getString(6));
t.setTourist_address(resultSet.getString(7));
t.setTourist_phone(resultSet.getString(8));
t.setGroup_num(resultSet.getString(9));
t.setAccompanied(resultSet.getString(10));
t.setAccommodation(resultSet.getString(11));
list.add(t);
}
} catch (SQLException e) {
e.printStackTrace();
}
Object[][] objects=new Object[list.size()][10];
for(int i=0;i<list.size();i++) {
objects[i][0]=list.get(i).getTourist_num();
// objects[i][1]=list.get(i).getUser_id();
objects[i][1]=list.get(i).getTourist_name();
objects[i][2]=list.get(i).getTourist_sex();
objects[i][3]=list.get(i).getTourist_age();
objects[i][4]=list.get(i).getTourist_idCard();
objects[i][5]=list.get(i).getTourist_address();
objects[i][6]=list.get(i).getTourist_phone();
objects[i][7]=list.get(i).getGroup_num();
objects[i][8]=list.get(i).getAccompanied();
objects[i][9]=list.get(i).getAccommodation();
}
return objects;
}
}
Updata.Java
package com.ynavc.Controller;
import com.ynavc.Dao.DbConnection;
public class Updata {
//添加数据
public int addData(String sql) {
return DbConnection.updataInfo(sql);
}
}
com.ynavc.Dao
DbConnection.Java
package com.ynavc.Dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;
import com.mysql.jdbc.Statement;
public class DbConnection {
//驱动类的类名
private static final String DRIVERNAME="com.mysql.jdbc.Driver";
//连接数据的URL路径
// private static final String URL="jdbc:mysql://118.31.124.77:3306/mydb23660";
private static final String URL="jdbc:mysql://127.0.0.1:3306/travel_manage";
//数据库登录账号
// private static final String USER="mydb23660";
private static final String USER="root";
//数据库登录密码
// private static final String PASSWORD="Hmsyfjdglxt66";
private static final String PASSWORD="root123";
//加载驱动
static{
try {
Class.forName(DRIVERNAME);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
//获取数据库连接
public static Connection getConnection() {
try {
return DriverManager.getConnection(URL,USER,PASSWORD);
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
//查询
public static ResultSet query(String sql) {
System.out.println(sql);
//获取连接
Connection connection=getConnection();
PreparedStatement psd;
try {
psd = connection.prepareStatement(sql);
return psd.executeQuery();
} catch (SQLException e) {
JOptionPane.showMessageDialog(null,"执行语句出错\n"+e.toString());
e.printStackTrace();
}
return null;
}
//增、删、改、查
public static int updataInfo(String sql) {
System.out.println(sql);
//获取连接
Connection connection=getConnection();
try {
PreparedStatement psd=connection.prepareStatement(sql);
return psd.executeUpdate();
} catch (SQLException e) {
JOptionPane.showMessageDialog(null,"执行语句出错\n"+e.toString());
e.printStackTrace();
}
return 0;
}
//关闭连接
public static void colse(ResultSet rs,Statement stmt,Connection conn) throws Exception{
try { if (rs != null){ rs.close(); }
if (stmt != null) { stmt.cancel(); }
if (conn != null) { conn.close(); }
} catch (Exception e) {
e.printStackTrace(); throw new Exception();
}
}
}
com.ynavc.View
MainJframe.Java
package com.ynavc.View;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ScrollPaneConstants;
import javax.swing.Timer;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import com.ynavc.Controller.Select;
import com.ynavc.Controller.Updata;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
public class MainJframe extends JFrame {
Select select = new Select();
Updata updata = new Updata();
Object[] header= {"线路号","起点","终点","天数","主要景点"};
Object[][] data=select.getLineInfo();
public MainJframe() {
super("旅游管理信息系统");
this.setBounds(0, 0, 1200, 700);
this.setLocationRelativeTo(null);//让窗口在屏幕中间显示
this.setResizable(false);//让窗口大小不可改变
getContentPane().setLayout(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//用户单击窗口的关闭按钮时程序执行的操作
//按钮
ImageIcon i1 = new ImageIcon("img/Icon1.png");
JButton xxcx = new JButton("旅游信息查询",i1);
xxcx.setBounds(14, 11, 145, 35);
xxcx.setFocusPainted(false);//去掉按钮周围的焦点框
xxcx.setContentAreaFilled(false);//设置按钮透明背景
getContentPane().add(xxcx);
xxcx.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
JOptionPane.showMessageDialog(null, "此功能暂未开放!");
}
});
ImageIcon i2 = new ImageIcon("img/Icon2.png");
JButton bmly = new JButton("报名旅游",i2);
bmly.setBounds(164, 11, 110, 35);
bmly.setFocusPainted(false);//去掉按钮周围的焦点框
bmly.setContentAreaFilled(false);//设置按钮透明背景
getContentPane().add(bmly);
bmly.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
//判断当前是否有用户登录
String sql = "SELECT COUNT(*) FROM `user` WHERE user_state='已登录'";
int reselt = select.getCount(sql);
if (reselt>0) {
Registration_Info r = new Registration_Info();
r.setVisible(true);
} else {
JOptionPane.showMessageDialog(null, "请先登录!");
Login l = new Login();
l.setVisible(true);
dispose();
}
}
});
ImageIcon i3 = new ImageIcon("img/Icon3.png");
JButton ywgl = new JButton("业务管理员",i3);
ywgl.setBounds(279, 11, 130, 35);
ywgl.setFocusPainted(false);//去掉按钮周围的焦点框
ywgl.setContentAreaFilled(false);//设置按钮透明背景
getContentPane().add(ywgl);
ywgl.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
//判断当前是否有用户登录
String sql = "SELECT COUNT(*) FROM `user` WHERE user_state='已登录'";
int reselt = select.getCount(sql);
if (reselt>0) {
//判断当前登录的用户身份
String user_type = select.getString("SELECT user_type FROM `user` WHERE user_state='已登录'");
if (user_type.equals("管理员")) {
Registration_Management r = new Registration_Management();
r.setVisible(true);
dispose();
}else{
JOptionPane.showMessageDialog(null, "当前无权限!请登录管理员账号!");
}
} else {
JOptionPane.showMessageDialog(null, "请先登录!");
Login l = new Login();
l.setVisible(true);
dispose();
}
}
});
ImageIcon i4 = new ImageIcon("img/Icon4.png");
JButton yhdl = new JButton("登录",i4);
yhdl.setBounds(414, 11, 85, 35);
yhdl.setFocusPainted(false);//去掉按钮周围的焦点框
yhdl.setContentAreaFilled(false);//设置按钮透明背景
getContentPane().add(yhdl);
yhdl.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
//判断当前是否有用户登录
String sql = "SELECT COUNT(*) FROM `user` WHERE user_state='已登录'";
int reselt = select.getCount(sql);
if (reselt>0) {
String i = select.getString("SELECT user_account FROM `user` WHERE user_state='已登录'");
JOptionPane.showMessageDialog(null, "当前已有用户"+" ”"+i+"” "+"登录");
}else {
Login l = new Login();
l.setVisible(true);
dispose();
}
}
});
ImageIcon i5 = new ImageIcon("img/Icon5.png");
JButton yhzc = new JButton("注册",i5);
yhzc.setBounds(504, 11, 85, 35);
yhzc.setFocusPainted(false);//去掉按钮周围的焦点框
yhzc.setContentAreaFilled(false);//设置按钮透明背景
getContentPane().add(yhzc);
yhzc.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
//判断当前是否有用户登录
String sql = "SELECT COUNT(*) FROM `user` WHERE user_state='已登录'";
int reselt = select.getCount(sql);
if (reselt>0) {
String i = select.getString("SELECT user_account FROM `user` WHERE user_state='已登录'");
// JOptionPane.showMessageDialog(null, "当前已有用户"+" ”"+i+"” "+"登录!是否注销?");
int a = JOptionPane.showConfirmDialog(null,"当前已有用户"+" ”"+i+"” "+"登录!是否注销?","注销提示",0,1);
if(a == JOptionPane.OK_OPTION){
JOptionPane.showMessageDialog(null, "已注销前账户!");
updata.addData("UPDATE user SET user_state='未登录' WHERE user_account='"+i+"';");
Registered r = new Registered();
r.setVisible(true);
dispose();
}
}else {
Registered r = new Registered();
r.setVisible(true);
dispose();
}
}
});
ImageIcon i6 = new ImageIcon("img/Icon6.png");
JButton tcxt = new JButton("退出系统",i6);
tcxt.setBounds(594, 11, 110, 35);
tcxt.setFocusPainted(false);//去掉按钮周围的焦点框
tcxt.setContentAreaFilled(false);//设置按钮透明背景
getContentPane().add(tcxt);
tcxt.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
int result = JOptionPane.showConfirmDialog(null,"您现在要关闭系统吗?关闭后同时注销账号!","退出提示",0,1);
if(result == JOptionPane.OK_OPTION){
JOptionPane.showMessageDialog(null, "已退出系统,欢迎下次使用!");
updata.addData("UPDATE user SET user_state='未登录';");
System.exit(0);
}
}
});
ImageIcon i7 = new ImageIcon("img/Icon7.png");
JButton help = new JButton("帮助",i2);
help.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, "系统管理员电话:18214217246");
}
});
help.setBounds(709, 11, 85, 35);
help.setFocusPainted(false);//去掉按钮周围的焦点框
help.setContentAreaFilled(false);//设置按钮透明背景
getContentPane().add(help);
JLabel dqsj = new JLabel("当前时间 :");
// dqsj.setForeground(Color.decode("#7784BD"));
dqsj.setBounds(857, 13, 85, 35);
dqsj.setFont(new Font("微软雅黑", Font.BOLD, 15));
getContentPane().add(dqsj);
JLabel time1 = new JLabel();
// time1.setForeground(Color.decode("#7784BD"));
time1.setBounds(944, 14, 236, 35);
time1.setFont(new Font("宋体", Font.CENTER_BASELINE, 15));
getContentPane().add(time1);
this.setTimer(time1);
//创建表模型
DefaultTableModel dt=new DefaultTableModel(data,header){
//设置表格内容不可被编辑
public boolean isCellEditable(int row, int column) {
return false;//返回true表示能编辑,false表示不能编辑
}
};
JTable jTable=new JTable(dt);//创建表格
jTable.getTableHeader().setFont(new Font(null, Font.BOLD, 14)); // 设置表头名称字体样式
jTable.getTableHeader().setForeground(Color.black); // 设置表头名称字体颜色
jTable.getTableHeader().setResizingAllowed(false); // 设置不允许手动改变列宽
jTable.getTableHeader().setReorderingAllowed(false);//设置表头不允许拖动
int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;//水平滚动条
int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;//垂直滚动条
JScrollPane jsp=new JScrollPane(jTable,v,h);//创建滚动容器
jsp.setBounds(14, 68, 1166, 584);
getContentPane().add(jsp);
//设置单元格内容居中显示
DefaultTableCellRenderer r = new DefaultTableCellRenderer();
r.setHorizontalAlignment(JLabel.CENTER);
jTable.setDefaultRenderer(Object.class, r);
}
// 设置Timer 1000ms实现一次动作 实际是一个线程
private void setTimer(JLabel time) {
final JLabel varTime = time;
Timer timeAction = new Timer(100, new ActionListener() {
public void actionPerformed(ActionEvent e) {
long timemillis = System.currentTimeMillis();
// 转换日期显示格式
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
varTime.setText(df.format(new Date(timemillis)));
}
});
timeAction.start();
}
public static void main(String[] args) {
MainJframe m = new MainJframe();
m.setVisible(true);
}
}
Login.Java
package com.ynavc.View;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import com.ynavc.Controller.Select;
import com.ynavc.Controller.Updata;
import javax.swing.JButton;
public class Login extends JFrame {
Select select = new Select();
Updata updata = new Updata();
private JTextField textField_zh;
private JPasswordField textField_mm;
public Login() {
super.setTitle("系统登录");
this.setBounds(0, 0, 700, 550);//设置大小
this.setLocationRelativeTo(null);//让窗口在屏幕中间显示
this.setResizable(false);//让窗口大小不可改变
getContentPane().setLayout(null);
JLabel label_zh = new JLabel("账号:");
label_zh.setFont(new Font("宋体", Font.CENTER_BASELINE, 15));
label_zh.setBounds(183, 135, 72, 18);
getContentPane().add(label_zh);
textField_zh = new JTextField();
textField_zh.setBounds(233, 130, 270, 34);
getContentPane().add(textField_zh);
textField_zh.setColumns(10);
JLabel label_mm = new JLabel("密码:");
label_mm.setFont(new Font("宋体", Font.CENTER_BASELINE, 15));
label_mm.setBounds(183, 205, 72, 18);
getContentPane().add(label_mm);
textField_mm = new JPasswordField();
textField_mm.setBounds(233, 200, 270, 34);
getContentPane().add(textField_mm);
textField_mm.setColumns(10);
JButton button = new JButton("登录");
button.setFont(new Font("宋体", Font.BOLD, 20));
button.setBounds(282, 299, 113, 34);
button.setFocusPainted(false);//去掉按钮周围的焦点框
button.setContentAreaFilled(false);//设置按钮透明背景
getContentPane().add(button);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String account=textField_zh.getText();
String password=textField_mm.getText();
if (account.equals("")&&password.equals("")) {
JOptionPane.showMessageDialog(null, "账户名或密码未填写!");
} else {
String sql = "select COUNT(*) from user where user_password='"+password+"' and user_account='"+account+"'";
int reselt = select.getCount(sql);
int i = updata.addData("UPDATE user SET user_state='已登录' WHERE user_account='"+account+"';");
if (reselt>0&&i>0) {
JOptionPane.showMessageDialog(null, "登录成功!欢迎使用!");
MainJframe m = new MainJframe();
m.setVisible(true);
dispose();
} else {
JOptionPane.showMessageDialog(null, "登录失败!账户名或密码不正确!请重新输入!");
}
}
}
});
JLabel ljzc = new JLabel("没有账号?立即注册!");
ljzc.setFont(new Font("宋体", Font.ITALIC, 16));
ljzc.setForeground(Color.blue);
ljzc.setBounds(271, 380, 168, 27);
getContentPane().add(ljzc);
ljzc.addMouseListener(new MouseListener(){
public void mouseClicked(MouseEvent e) {
// 处理鼠标点击
Registered m = new Registered();
m.setVisible(true);
dispose();
}
public void mouseEntered(MouseEvent e) {
// 处理鼠标移入
ljzc.setForeground(Color.red);
}
public void mouseExited(MouseEvent e) {
// 处理鼠标离开
ljzc.setForeground(Color.blue);
}
public void mousePressed(MouseEvent e) {
// 处理鼠标按下
}
public void mouseReleased(MouseEvent e) {
// 处理鼠标释放
}
});
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
super.windowClosing(e);
//加入动作
MainJframe m = new MainJframe();
m.setVisible(true);
}
});
}
}
Registered.Java
package com.ynavc.View;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import com.ynavc.Controller.Updata;
public class Registered extends JFrame {
Updata updata = new Updata();
private JTextField textField_zh;
private JPasswordField textField_srmm;
private JPasswordField textField_qrmm;
public Registered() {
super.setTitle("账号注册");
this.setBounds(0, 0, 700, 550);//设置大小
this.setLocationRelativeTo(null);//让窗口在屏幕中间显示
this.setResizable(false);//让窗口大小不可改变
getContentPane().setLayout(null);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
super.windowClosing(e);
//加入动作
MainJframe m = new MainJframe();
m.setVisible(true);
}
});
JLabel label_zh = new JLabel("账号名:");
label_zh.setFont(new Font("宋体", Font.CENTER_BASELINE, 15));
label_zh.setBounds(165, 138, 72, 18);
getContentPane().add(label_zh);
textField_zh = new JTextField();
textField_zh.setBounds(248, 130, 255, 34);
getContentPane().add(textField_zh);
textField_zh.setColumns(10);
JLabel label_srmm = new JLabel("输入密码:");
label_srmm.setFont(new Font("宋体", Font.CENTER_BASELINE, 15));
label_srmm.setBounds(165, 208, 83, 18);
getContentPane().add(label_srmm);
textField_srmm = new JPasswordField();
textField_srmm.setBounds(248, 267, 255, 34);
getContentPane().add(textField_srmm);
textField_srmm.setColumns(10);
JLabel label_qrmm = new JLabel("确认密码:");
label_qrmm.setFont(new Font("宋体", Font.CENTER_BASELINE, 15));
label_qrmm.setBounds(165, 275, 92, 18);
getContentPane().add(label_qrmm);
textField_qrmm = new JPasswordField();
textField_qrmm.setBounds(248, 200, 255, 34);
getContentPane().add(textField_qrmm);
textField_qrmm.setColumns(10);
JButton button = new JButton("注册");
button.setFont(new Font("宋体", Font.BOLD, 20));
button.setBounds(282, 362, 113, 34);
button.setFocusPainted(false);//去掉按钮周围的焦点框
button.setContentAreaFilled(false);//设置按钮透明背景
getContentPane().add(button);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String yhm = textField_zh.getText();
String srmm = textField_srmm.getText();
String qrmm = textField_qrmm.getText();
//确认输入的信息是否为空
if (yhm.equals("")&&srmm.equals("")&&qrmm.equals("")) {
JOptionPane.showMessageDialog(null, "请完整输入信息!");
}else {
//判断两次密码是否一致
if (srmm.equals(qrmm)) {
String sql = "INSERT INTO `user` VALUES (null, '"+yhm+"', '"+srmm+"', '游客', '未登录');";
int reselt = updata.addData(sql);
if (reselt>0) {
JOptionPane.showMessageDialog(null, "注册成功!将跳转到登录页面!");
Login l = new Login();
l.setVisible(true);
dispose();
}else {
JOptionPane.showMessageDialog(null, "注册失败!");
}
}else {
JOptionPane.showMessageDialog(null, "两次输入的密码不一致!请检查!");
}
}
}
});
}
}
Registration_Info.Java
package com.ynavc.View;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import com.ynavc.Controller.Select;
import com.ynavc.Controller.Updata;
import com.ynavc.Utils.ValidateUtils;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.awt.event.ActionEvent;
import java.awt.Font;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
public class Registration_Info extends JFrame {
private JTextField textField_name;//姓名
private JTextField textField_age;//年龄
private JTextField textField_IDcard;//身份证号码
private JTextField textField_address;//地址
private JTextField textField_phone;//电话
private JTextField textField_th;//团号
private JTextField textField_pt;//陪同
private JTextField textField_ss;//食宿
Select select = new Select();
Updata updata = new Updata();
String name,sex,age,Idcard,address,phone,th,pt,ss;
public Registration_Info() {
super("填写报名信息");
this.setBounds(0, 0, 930, 700);
this.setLocationRelativeTo(null);//让窗口在屏幕中间显示
this.setResizable(false);//让窗口大小不可改变
getContentPane().setLayout(null);
JLabel lblNewLabel_name= new JLabel("姓名:");
lblNewLabel_name.setBounds(138, 79, 72, 18);
getContentPane().add(lblNewLabel_name);
textField_name = new JTextField();
textField_name.setBounds(191, 76, 240, 24);
getContentPane().add(textField_name);
textField_name.setColumns(10);
JLabel lblNewLabel_sex= new JLabel("性别:");
lblNewLabel_sex.setBounds(138, 125, 72, 18);
getContentPane().add(lblNewLabel_sex);
JComboBox comboBox_sez = new JComboBox();
comboBox_sez.setModel(new DefaultComboBoxModel(new String[] {"男", "女"}));
comboBox_sez.setBounds(191, 122, 240, 24);
getContentPane().add(comboBox_sez);
JLabel lblNewLabel_age= new JLabel("年龄:");
lblNewLabel_age.setBounds(138, 168, 72, 18);
getContentPane().add(lblNewLabel_age);
textField_age = new JTextField();
textField_age.setBounds(191, 165, 240, 24);
getContentPane().add(textField_age);
textField_age.setColumns(10);
JLabel lblNewLabel_IDcard= new JLabel("身份证号码:");
lblNewLabel_IDcard.setBounds(93, 213, 117, 18);
getContentPane().add(lblNewLabel_IDcard);
textField_IDcard = new JTextField();
textField_IDcard.setBounds(191, 210, 240, 24);
getContentPane().add(textField_IDcard);
textField_IDcard.setColumns(10);
JLabel lblNewLabel_address= new JLabel("住址:");
lblNewLabel_address.setBounds(138, 254, 72, 18);
getContentPane().add(lblNewLabel_address);
textField_address = new JTextField();
textField_address.setBounds(191, 251, 240, 24);
getContentPane().add(textField_address);
textField_address.setColumns(10);
JLabel lblNewLabel_phone= new JLabel("电话:");
lblNewLabel_phone.setBounds(138, 295, 72, 18);
getContentPane().add(lblNewLabel_phone);
textField_phone = new JTextField();
textField_phone.setBounds(191, 292, 240, 24);
getContentPane().add(textField_phone);
textField_phone.setColumns(10);
JLabel lblNewLabel_th= new JLabel("团号:");
lblNewLabel_th.setBounds(138, 335, 72, 18);
getContentPane().add(lblNewLabel_th);
textField_th = new JTextField();
textField_th.setBounds(191, 332, 240, 24);
getContentPane().add(textField_th);
textField_th.setColumns(10);
JLabel lblNewLabel_pt= new JLabel("陪同:");
lblNewLabel_pt.setBounds(138, 382, 72, 18);
getContentPane().add(lblNewLabel_pt);
textField_pt = new JTextField();
textField_pt.setText("是否选择导游陪同?");
textField_pt.setToolTipText("");
textField_pt.setBounds(191, 379, 240, 24);
getContentPane().add(textField_pt);
textField_pt.setColumns(10);
JLabel lblNewLabel_ss= new JLabel("食宿:");
lblNewLabel_ss.setBounds(138, 427, 72, 18);
getContentPane().add(lblNewLabel_ss);
textField_ss = new JTextField();
textField_ss.setText("是否选择宾馆住宿?");
textField_ss.setBounds(191, 424, 240, 24);
getContentPane().add(textField_ss);
textField_ss.setColumns(10);
JButton button_1 = new JButton("查看旅游团信息");
button_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
button_1.setBounds(453, 331, 158, 27);
button_1.setFocusPainted(false);//去掉按钮周围的焦点框
button_1.setContentAreaFilled(false);//设置按钮透明背景
getContentPane().add(button_1);
JButton button_2 = new JButton("显示选择结果");
button_2.setBounds(625, 331, 146, 27);
button_2.setFocusPainted(false);//去掉按钮周围的焦点框
button_2.setContentAreaFilled(false);//设置按钮透明背景
getContentPane().add(button_2);
JButton button_3 = new JButton("是");
button_3.setBounds(453, 378, 72, 27);
button_3.setFocusPainted(false);//去掉按钮周围的焦点框
button_3.setContentAreaFilled(false);//设置按钮透明背景
getContentPane().add(button_3);
button_3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
textField_pt.setText("是");
}
});
JButton button_4 = new JButton("否");
button_4.setBounds(539, 378, 72, 27);
button_4.setFocusPainted(false);//去掉按钮周围的焦点框
button_4.setContentAreaFilled(false);//设置按钮透明背景
getContentPane().add(button_4);
button_4.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
textField_pt.setText("无");
}
});
JButton button_5 = new JButton("显示选择结果");
button_5.setBounds(625, 378, 146, 27);
button_5.setFocusPainted(false);//去掉按钮周围的焦点框
button_5.setContentAreaFilled(false);//设置按钮透明背景
getContentPane().add(button_5);
JButton button_6 = new JButton("是");
button_6.setBounds(453, 421, 72, 27);
button_6.setFocusPainted(false);//去掉按钮周围的焦点框
button_6.setContentAreaFilled(false);//设置按钮透明背景
getContentPane().add(button_6);
button_6.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
textField_ss.setText("是");
}
});
JButton button_7 = new JButton("否");
button_7.setBounds(539, 421, 72, 27);
button_7.setFocusPainted(false);//去掉按钮周围的焦点框
button_7.setContentAreaFilled(false);//设置按钮透明背景
getContentPane().add(button_7);
button_7.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
textField_ss.setText("无");
}
});
JButton button_8 = new JButton("显示选择结果");
button_8.setBounds(625, 423, 146, 27);
button_8.setFocusPainted(false);//去掉按钮周围的焦点框
button_8.setContentAreaFilled(false);//设置按钮透明背景
getContentPane().add(button_8);
JButton btnNewButton = new JButton("报名");
btnNewButton.setFont(new Font("微软雅黑", Font.PLAIN, 18));
btnNewButton.setBounds(388, 516, 124, 33);
btnNewButton.setFocusPainted(false);//去掉按钮周围的焦点框
btnNewButton.setContentAreaFilled(false);//设置按钮透明背景
getContentPane().add(btnNewButton);
btnNewButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
name = textField_name.getText();
sex = comboBox_sez.getSelectedItem().toString();
age = textField_age.getText();
Idcard = textField_IDcard.getText();
address = textField_address.getText();
phone = textField_phone.getText();
th = textField_th.getText();
pt = textField_pt.getText();
if (pt.equals("是否选择导游陪同?")) {
pt="无";
}
ss = textField_ss.getText();
if (ss.equals("是否选择宾馆住宿?")) {
ss="无";
}
//判断输入的信息是否为空,是否完整
if (name.equals("")||sex.equals("")||age.equals("")||Idcard.equals("")||address.equals("")||phone.equals("")||th.equals("")||pt.equals("")||ss.equals("")) {
JOptionPane.showMessageDialog(null, "请输入完整信息!");
} else {
//判断身份证号码
if (!ValidateUtils.IDcard(Idcard)) {
JOptionPane.showMessageDialog(null, "身份证号码错误!请检查!");
} else {
String i = select.getString("SELECT user_id FROM `user` WHERE user_state='已登录'");
String sql = "INSERT INTO `tourist` VALUES (null, '"+i+"', '"+name+"', '"+sex+"', '"+age+"', '"+Idcard+"', '"+address+"', '"+phone+"', '"+th+"', '"+pt+"', '"+ss+"');";
int result = updata.addData(sql);
//判断手机号
String regex = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(17[013678])|(18[0,5-9]))\\d{8}$";
if(phone.length() != 11){
JOptionPane.showMessageDialog(null, "手机号应为11位数!");
}else{
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(phone);
boolean isMatch = m.matches();
if(!isMatch){
JOptionPane.showMessageDialog(null, "您的手机号" + phone + "是错误格式!!!");
}else {
//判断插入结果
if (result>0) {
JOptionPane.showMessageDialog(null, "报名成功!");
dispose();
MainJframe m1 = new MainJframe();
m1.setVisible(true);
} else {
JOptionPane.showMessageDialog(null, "报名失败,请与管理员联系!");
}
}
}
}
}
}
});
}
}
Registration_Management.Java
package com.ynavc.View;
import java.awt.Color;
import java.awt.FileDialog;
import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ScrollPaneConstants;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import com.ynavc.Bean.Tourist;
import com.ynavc.Controller.Select;
import com.ynavc.Controller.Updata;
import javax.swing.JTextField;
import javax.imageio.ImageIO;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.awt.event.ActionEvent;
public class Registration_Management extends JFrame {
Select select = new Select();
Updata updata = new Updata();
JButton btnNewButton_Export;
JTable jTable;
DefaultTableModel dt;
// String name,sex,age,Idcard,address,phone,th,pt,ss;
Object[] header= {"游客编号","姓名","性别","年龄","身份证号","住址","电话","旅游团","陪同","食宿"};
Object[][] data=select.getTourist("SELECT * FROM tourist");
private JTextField textField_ykbh;
private JTextField textField_th;
private JTextField textField_name;
public Registration_Management() {
super("报名信息管理");
this.setBounds(0, 0, 1200, 700);
this.setLocationRelativeTo(null);//让窗口在屏幕中间显示
this.setResizable(false);//让窗口大小不可改变
getContentPane().setLayout(null);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
super.windowClosing(e);
//加入动作
MainJframe m = new MainJframe();
m.setVisible(true);
}
});
//创建表模型
dt=new DefaultTableModel(data,header){
//设置表格内容不可被编辑
public boolean isCellEditable(int row, int column) {
return false;//返回true表示能编辑,false表示不能编辑
}
};
jTable=new JTable(dt);//创建表格
jTable.getTableHeader().setFont(new Font(null, Font.BOLD, 14)); // 设置表头名称字体样式
jTable.getTableHeader().setForeground(Color.black); // 设置表头名称字体颜色
// jTable.getTableHeader().setResizingAllowed(false); // 设置不允许手动改变列宽
jTable.getTableHeader().setReorderingAllowed(false);//设置表头不允许拖动
int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;//水平滚动条
int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;//垂直滚动条
JScrollPane jsp=new JScrollPane(jTable,v,h);//创建滚动容器
jsp.setBounds(0, 0, 976, 675);
getContentPane().add(jsp);
JLabel label_ykbh = new JLabel("游客编号:");
label_ykbh.setBounds(990, 74, 89, 18);
getContentPane().add(label_ykbh);
textField_ykbh = new JTextField();
textField_ykbh.setBounds(1066, 71, 114, 24);
getContentPane().add(textField_ykbh);
textField_ykbh.setColumns(10);
JLabel label_th = new JLabel("团号:");
label_th.setBounds(1000, 122, 52, 18);
getContentPane().add(label_th);
textField_th = new JTextField();
textField_th.setColumns(10);
textField_th.setBounds(1066, 119, 114, 24);
getContentPane().add(textField_th);
JLabel label_name = new JLabel("姓名:");
label_name.setBounds(1000, 168, 52, 18);
getContentPane().add(label_name);
textField_name = new JTextField();
textField_name.setColumns(10);
textField_name.setBounds(1066, 165, 114, 24);
getContentPane().add(textField_name);
JButton btnNewButton_Query = new JButton("查询");
btnNewButton_Query.setBounds(1031, 224, 113, 27);
btnNewButton_Query.setFocusPainted(false);//去掉按钮周围的焦点框
btnNewButton_Query.setContentAreaFilled(false);//设置按钮透明背景
getContentPane().add(btnNewButton_Query);
btnNewButton_Query.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String ykbh,th,name,sql;
ykbh = textField_ykbh.getText();
th = textField_th.getText();
name = textField_name.getText();
if (ykbh.equals("")&&th.equals("")&&name.equals("")) {
sql = "SELECT * FROM tourist";
}else if(ykbh.equals("")&&th.equals("")){
sql = "SELECT * FROM tourist WHERE tourist_name='"+name+"';";
}else if(name.equals("")&&th.equals("")){
sql = "SELECT * FROM tourist WHERE tourist_num='"+ykbh+"';";
}else if(ykbh.equals("")&&name.equals("")){
sql = "SELECT * FROM tourist WHERE group_num='"+th+"';";
}else if(ykbh.equals("")){
sql = "SELECT * FROM tourist WHERE group_num='"+th+"' and tourist_name='"+name+"';";
}else if(th.equals("")){
sql = "SELECT * FROM tourist WHERE tourist_num='"+ykbh+"' and tourist_name='"+name+"';";
}else if(name.equals("")){
sql = "SELECT * FROM tourist WHERE tourist_num='"+ykbh+"' and group_num='"+th+"';";
}else {
sql = "SELECT * FROM tourist WHERE tourist_num='"+ykbh+"' and group_num='"+th+"' and tourist_name='"+name+"';";
}
data = select.getTourist(sql);
dt.setDataVector(data,header);
}
});
JButton btnNewButton_Alter = new JButton("修改");
btnNewButton_Alter.setBounds(1031, 278, 113, 27);
btnNewButton_Alter.setFocusPainted(false);//去掉按钮周围的焦点框
btnNewButton_Alter.setContentAreaFilled(false);//设置按钮透明背景
getContentPane().add(btnNewButton_Alter);
btnNewButton_Alter.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (jTable.getSelectedRow()<0) {
JOptionPane.showMessageDialog(null, "您未选中要修改的数据!");
} else {
//获取用户选择的数据
String name,sex,age,Idcard,address,phone,th,pt,ss;
String id=jTable.getValueAt(jTable.getSelectedRow(), 0).toString();
String user_id = select.getString("SELECT user_id FROM `user` WHERE user_state='已登录'");
name=jTable.getValueAt(jTable.getSelectedRow(), 1).toString();
sex=jTable.getValueAt(jTable.getSelectedRow(), 2).toString();
age=jTable.getValueAt(jTable.getSelectedRow(), 3).toString();
Idcard=jTable.getValueAt(jTable.getSelectedRow(), 4).toString();
address=jTable.getValueAt(jTable.getSelectedRow(), 5).toString();
phone=jTable.getValueAt(jTable.getSelectedRow(), 6).toString();
th=jTable.getValueAt(jTable.getSelectedRow(), 7).toString();
pt=jTable.getValueAt(jTable.getSelectedRow(), 8).toString();
ss=jTable.getValueAt(jTable.getSelectedRow(), 9).toString();
Tourist tourist=new Tourist(id, user_id, name, sex, age, Idcard, address, phone, th, pt, ss);
RegistrationInfo_Change frame=new RegistrationInfo_Change(tourist);
frame.setVisible(true);
}
}
});
JButton btnNewButton_Add = new JButton("添加");
btnNewButton_Add.setBounds(1031, 330, 113, 27);
btnNewButton_Add.setFocusPainted(false);//去掉按钮周围的焦点框
btnNewButton_Add.setContentAreaFilled(false);//设置按钮透明背景
getContentPane().add(btnNewButton_Add);
btnNewButton_Add.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
Registration_Info r = new Registration_Info();
r.setVisible(true);
}
});
JButton btnNewButton_Delete = new JButton("删除");
btnNewButton_Delete.setBounds(1031, 383, 113, 27);
btnNewButton_Delete.setFocusPainted(false);//去掉按钮周围的焦点框
btnNewButton_Delete.setContentAreaFilled(false);//设置按钮透明背景
getContentPane().add(btnNewButton_Delete);
btnNewButton_Delete.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (jTable.getSelectedRow()<0) {
JOptionPane.showMessageDialog(null, "您未选中要删除的数据!");
} else {
//获取用户选择的数据
String id=jTable.getValueAt(jTable.getSelectedRow(), 0).toString();
String name=jTable.getValueAt(jTable.getSelectedRow(), 1).toString();
int result = JOptionPane.showConfirmDialog(null,"您确定要删除用户 “"+name+"” 的报名信息吗?","删除提示",0,1);
if(result == JOptionPane.OK_OPTION){
int i = updata.addData("DELETE FROM tourist WHERE tourist_num='"+id+"';");
if (i>0){
JOptionPane.showMessageDialog(null, "用户 “"+name+"” ,已被删除成功!");
} else {
JOptionPane.showMessageDialog(null, "删除失败!");
}
data=select.getTourist("SELECT * FROM tourist");
dt.setDataVector(data,header);
}
}
}
});
JButton btnNewButton_Tip = new JButton("提示");
btnNewButton_Tip.setBounds(1031, 436, 113, 27);
btnNewButton_Tip.setFocusPainted(false);//去掉按钮周围的焦点框
btnNewButton_Tip.setContentAreaFilled(false);//设置按钮透明背景
getContentPane().add(btnNewButton_Tip);
btnNewButton_Tip.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, "<html>查询:直接点击将列出所有报名信息,也可填写游客编号、团号和性别查询。<br>修改:点击游客将会将游客编号绑定到文本框中,可以对该游客编号对应的游客进行团号和性别修改。<br>删除:点击要删除的信息,点击删除即可。<br>添加:对报名信息进行添加。</html>");
}
});
btnNewButton_Export = new JButton("<html>将数据导出到<br>  Excel 表中</html>");
btnNewButton_Export.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButtonActionPerformed(e);
}
});
btnNewButton_Export.setBounds(1016, 525, 138, 51);
btnNewButton_Export.setFocusPainted(false);//去掉按钮周围的焦点框
btnNewButton_Export.setContentAreaFilled(false);//设置按钮透明背景
getContentPane().add(btnNewButton_Export);
//设置单元格内容居中显示
DefaultTableCellRenderer r = new DefaultTableCellRenderer();
r.setHorizontalAlignment(JLabel.CENTER);
jTable.setDefaultRenderer(Object.class, r);
}
//导出
private void jButtonActionPerformed(java.awt.event.ActionEvent evt) {
FileDialog fd = new FileDialog(this, "将数据保存到", FileDialog.SAVE);
fd.setLocation(1100, 600);
fd.setVisible(true);
String stringfile = fd.getDirectory()+fd.getFile()+".xlsx";
try {
// ExcelExporter export = new ExcelExporter();
this.exportTable(jTable, new File(stringfile));
} catch (IOException ex) {
ex.printStackTrace();
}
}
/**导出JTable到excel */
public void exportTable(JTable table, File file) throws IOException {
TableModel model = table.getModel();
BufferedWriter bWriter = new BufferedWriter(new FileWriter(file));
for(int i=0; i < model.getColumnCount(); i++) {
bWriter.write(model.getColumnName(i));
bWriter.write("\t");
}
bWriter.newLine();
for(int i=0; i< model.getRowCount(); i++) {
for(int j=0; j < model.getColumnCount(); j++) {
bWriter.write(model.getValueAt(i,j).toString());
bWriter.write("\t");
}
bWriter.newLine();
}
bWriter.close();
}
}
RegistrationInfo_Change.Java
package com.ynavc.View;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import com.ynavc.Bean.Tourist;
import com.ynavc.Controller.Select;
import com.ynavc.Controller.Updata;
import com.ynavc.Utils.ValidateUtils;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.awt.event.ActionEvent;
import java.awt.Font;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
public class RegistrationInfo_Change extends JFrame {
private JTextField textField_name;//姓名
private JTextField textField_age;//年龄
private JTextField textField_IDcard;//身份证号码
private JTextField textField_address;//地址
private JTextField textField_phone;//电话
private JTextField textField_th;//团号
private JTextField textField_pt;//陪同
private JTextField textField_ss;//食宿
Select select = new Select();
Updata updata = new Updata();
String name,sex,age,Idcard,address,phone,th,pt,ss;
public RegistrationInfo_Change(Tourist tourist) {
super("修改报名信息");
this.setBounds(0, 0, 930, 700);
this.setLocationRelativeTo(null);//让窗口在屏幕中间显示
this.setResizable(false);//让窗口大小不可改变
getContentPane().setLayout(null);
JLabel lblNewLabel_name= new JLabel("姓名:");
lblNewLabel_name.setBounds(138, 79, 72, 18);
getContentPane().add(lblNewLabel_name);
textField_name = new JTextField();
textField_name.setBounds(191, 76, 240, 24);
getContentPane().add(textField_name);
textField_name.setColumns(10);
JLabel lblNewLabel_sex= new JLabel("性别:");
lblNewLabel_sex.setBounds(138, 125, 72, 18);
getContentPane().add(lblNewLabel_sex);
JComboBox comboBox_sex= new JComboBox();
comboBox_sex.setModel(new DefaultComboBoxModel(new String[] {"男", "女"}));
comboBox_sex.setBounds(191, 122, 240, 24);
getContentPane().add(comboBox_sex);
JLabel lblNewLabel_age= new JLabel("年龄:");
lblNewLabel_age.setBounds(138, 168, 72, 18);
getContentPane().add(lblNewLabel_age);
textField_age = new JTextField();
textField_age.setBounds(191, 165, 240, 24);
getContentPane().add(textField_age);
textField_age.setColumns(10);
JLabel lblNewLabel_IDcard= new JLabel("身份证号码:");
lblNewLabel_IDcard.setBounds(93, 213, 117, 18);
getContentPane().add(lblNewLabel_IDcard);
textField_IDcard = new JTextField();
textField_IDcard.setBounds(191, 210, 240, 24);
getContentPane().add(textField_IDcard);
textField_IDcard.setColumns(10);
JLabel lblNewLabel_address= new JLabel("住址:");
lblNewLabel_address.setBounds(138, 254, 72, 18);
getContentPane().add(lblNewLabel_address);
textField_address = new JTextField();
textField_address.setBounds(191, 251, 240, 24);
getContentPane().add(textField_address);
textField_address.setColumns(10);
JLabel lblNewLabel_phone= new JLabel("电话:");
lblNewLabel_phone.setBounds(138, 295, 72, 18);
getContentPane().add(lblNewLabel_phone);
textField_phone = new JTextField();
textField_phone.setBounds(191, 292, 240, 24);
getContentPane().add(textField_phone);
textField_phone.setColumns(10);
JLabel lblNewLabel_th= new JLabel("团号:");
lblNewLabel_th.setBounds(138, 335, 72, 18);
getContentPane().add(lblNewLabel_th);
textField_th = new JTextField();
textField_th.setBounds(191, 332, 240, 24);
getContentPane().add(textField_th);
textField_th.setColumns(10);
JLabel lblNewLabel_pt= new JLabel("陪同:");
lblNewLabel_pt.setBounds(138, 382, 72, 18);
getContentPane().add(lblNewLabel_pt);
textField_pt = new JTextField();
textField_pt.setText("是否选择导游陪同?");
textField_pt.setToolTipText("");
textField_pt.setBounds(191, 379, 240, 24);
getContentPane().add(textField_pt);
textField_pt.setColumns(10);
JLabel lblNewLabel_ss= new JLabel("食宿:");
lblNewLabel_ss.setBounds(138, 427, 72, 18);
getContentPane().add(lblNewLabel_ss);
textField_ss = new JTextField();
textField_ss.setText("是否选择宾馆住宿?");
textField_ss.setBounds(191, 424, 240, 24);
getContentPane().add(textField_ss);
textField_ss.setColumns(10);
JButton button_1 = new JButton("查看旅游团信息");
button_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
button_1.setBounds(453, 331, 158, 27);
button_1.setFocusPainted(false);//去掉按钮周围的焦点框
button_1.setContentAreaFilled(false);//设置按钮透明背景
getContentPane().add(button_1);
JButton button_2 = new JButton("显示选择结果");
button_2.setBounds(625, 331, 146, 27);
button_2.setFocusPainted(false);//去掉按钮周围的焦点框
button_2.setContentAreaFilled(false);//设置按钮透明背景
getContentPane().add(button_2);
JButton button_3 = new JButton("是");
button_3.setBounds(453, 378, 72, 27);
button_3.setFocusPainted(false);//去掉按钮周围的焦点框
button_3.setContentAreaFilled(false);//设置按钮透明背景
getContentPane().add(button_3);
button_3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
textField_pt.setText("是");
}
});
JButton button_4 = new JButton("否");
button_4.setBounds(539, 378, 72, 27);
button_4.setFocusPainted(false);//去掉按钮周围的焦点框
button_4.setContentAreaFilled(false);//设置按钮透明背景
getContentPane().add(button_4);
button_4.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
textField_pt.setText("无");
}
});
JButton button_5 = new JButton("显示选择结果");
button_5.setBounds(625, 378, 146, 27);
button_5.setFocusPainted(false);//去掉按钮周围的焦点框
button_5.setContentAreaFilled(false);//设置按钮透明背景
getContentPane().add(button_5);
JButton button_6 = new JButton("是");
button_6.setBounds(453, 421, 72, 27);
button_6.setFocusPainted(false);//去掉按钮周围的焦点框
button_6.setContentAreaFilled(false);//设置按钮透明背景
getContentPane().add(button_6);
button_6.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
textField_ss.setText("是");
}
});
JButton button_7 = new JButton("否");
button_7.setBounds(539, 421, 72, 27);
button_7.setFocusPainted(false);//去掉按钮周围的焦点框
button_7.setContentAreaFilled(false);//设置按钮透明背景
getContentPane().add(button_7);
button_7.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
textField_ss.setText("无");
}
});
JButton button_8 = new JButton("显示选择结果");
button_8.setBounds(625, 423, 146, 27);
button_8.setFocusPainted(false);//去掉按钮周围的焦点框
button_8.setContentAreaFilled(false);//设置按钮透明背景
getContentPane().add(button_8);
textField_name.setText(tourist.getTourist_name());
String t = tourist.getTourist_sex();
comboBox_sex.setSelectedItem(t);
textField_age.setText(tourist.getTourist_age());
textField_IDcard.setText(tourist.getTourist_idCard());
textField_address.setText(tourist.getTourist_address());
textField_phone.setText(tourist.getTourist_phone());
textField_th.setText(tourist.getGroup_num());
textField_pt.setText(tourist.getAccompanied());
textField_ss.setText(tourist.getAccommodation());
JButton btnNewButton = new JButton("确认修改");
btnNewButton.setFont(new Font("微软雅黑", Font.PLAIN, 18));
btnNewButton.setBounds(388, 516, 124, 33);
btnNewButton.setFocusPainted(false);//去掉按钮周围的焦点框
btnNewButton.setContentAreaFilled(false);//设置按钮透明背景
getContentPane().add(btnNewButton);
btnNewButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String id = tourist.getTourist_num();
name = textField_name.getText();
sex = comboBox_sex.getSelectedItem().toString();
age = textField_age.getText();
Idcard = textField_IDcard.getText();
address = textField_address.getText();
phone = textField_phone.getText();
th = textField_th.getText();
pt = textField_pt.getText();
if (pt.equals("是否选择导游陪同?")) {
pt="无";
}
ss = textField_ss.getText();
if (ss.equals("是否选择宾馆住宿?")) {
ss="无";
}
//判断输入的信息是否为空,是否完整
if (name.equals("")||sex.equals("")||age.equals("")||Idcard.equals("")||address.equals("")||phone.equals("")||th.equals("")||pt.equals("")||ss.equals("")) {
JOptionPane.showMessageDialog(null, "请输入完整信息!");
} else {
//判断身份证号码
if (!ValidateUtils.IDcard(Idcard)) {
JOptionPane.showMessageDialog(null, "身份证号码错误!请检查!");
} else {
String i = select.getString("SELECT user_id FROM `user` WHERE user_state='已登录'");
String sql = "UPDATE tourist SET tourist_name='"+name+"',tourist_sex='"+sex+"',tourist_age='"+age+"',tourist_idcard='"+Idcard+"',tourist_address='"+address+"',tourist_phone='"+phone+"',group_num='"+th+"',accompanied='"+pt+"',accommodation='"+ss+"' WHERE tourist_num='"+id+"';";
int result = updata.addData(sql);
//判断手机号
String regex = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(17[013678])|(18[0,5-9]))\\d{8}$";
if(phone.length() != 11){
JOptionPane.showMessageDialog(null, "手机号应为11位数!");
}else{
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(phone);
boolean isMatch = m.matches();
if(!isMatch){
JOptionPane.showMessageDialog(null, "您的手机号" + phone + "是错误格式!!!");
}else {
//判断插入结果
if (result>0) {
JOptionPane.showMessageDialog(null, "修改成功!");
Registration_Management r = new Registration_Management();
r.dispose();
r.setVisible(true);
dispose();
} else {
JOptionPane.showMessageDialog(null, "修改失败,请与管理员联系!");
}
}
}
}
}
}
});
}
}
com.ynavc.Test
Main.java
package com.ynavc.Test;
import com.ynavc.View.MainJframe;
public class Main {
public static void main(String[] args) {
MainJframe m = new MainJframe();
m.setVisible(true);
}
}
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/130571.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...