〇、项目介绍
本系统实现技术为Java Swing图形界面,加上Sql Server数据库,使用jdbc连接数据库和Java。
该系统功能主要为能够实现电影信息管理〔电影忽称、上映时间、导演、演员、电影类型等)、用户信息管理〔用户姓名、手机号、会员等级等)以及购票功能。用户可以查询电影信息并购买电影票,系统会记录购票信息和用户的会员等级,同时可以显示已购买的电影票。将电影信息、用户信息以及购票情况保存到本地文本TXT文件中。
一、界面的展示如下:
1、登陆界面:包括管理员角色和用户角色的登录
2、管理中心首页:可以查看用系统中的购票记录,还包括用户管理菜单和电影信息管理菜单
3、用户管理页面:包括对用户信息的增删改查、对用户的模糊搜索,同时将用户的更新信息导出为txt文件并存于本地。
4、电影管理页面:包括对电影信息的增删改查、对电影的模糊搜索,同时将电影的更新信息导出为txt文件并存于本地。
5、用户购票界面
二、关键代码
1、登录功能
private int infoVerify(String Ausername,String Apassword,int flag) throws SQLException {
common.connectDB();
String sql="select user_name,user_password from user1 where user_name='"+Ausername+"' and user_password='"+Apassword+"' and user_role='"+flag+"'";
ps=common.conn.prepareStatement(sql);
ResultSet rs=ps.executeQuery();
if(rs.next()) {
common.connectClose();
return 1;//登陆验证成功
}
else {
common.connectClose();
return 0;//登陆验证失败
}
}
2、购票功能:
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
row=jTable1.getSelectedRow();
System.out.println(row);
if (row<0){
JOptionPane.showMessageDialog(null,"请点击对应电影选项后购买");
return;
}
if (AdminLogin.Ausername==null){
JOptionPane.showMessageDialog(null,"没有个人信息");
return;
}
int flag=JOptionPane.showConfirmDialog(null,"您选择的电影票为:"+jTable1.getValueAt(row, 1)+";导演为:"+jTable1.getValueAt(row, 1));
System.out.println(flag);
if (flag==0){
try {
common.connectDB();
stmt = common.conn.createStatement();
SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
newDate=simpleDateFormat.format(new Date());
System.out.println(newDate);
String sql3="insert into purchase(user_id,movie_id,purchase_time)" + "values((select user_id from user1 where user_name='"+AdminLogin.Ausername+"'),'"+jTable1.getValueAt(row,0)+"','"+newDate+"')";
stmt.executeUpdate(sql3);
common.connectClose();
} catch (SQLException e) {
System.out.println(e);
JOptionPane.showMessageDialog(null, "数据源错误!!!");
return;
}
JOptionPane.showMessageDialog(null, "恭喜您购票成功!祝您生活愉快!");
Purchase.this.setVisible(false);
Purchase Purchase =new Purchase();
Purchase.setVisible(true);
}else{
JOptionPane.showMessageDialog(null,"您已取消购票。");
}
}