前一段时间,学校安排的软件课程设计,要求用Java写界面,并且连接本地数据库,实现“剧院票务管理系统”(以下简称TTMS)。项目已经完成一个多月了,今天来总结一下该项目开发的要点,以及大概过程吧。
开发环境:Windows系统,eclipse,SQLServer2008R2
1.首先,数据库已经是老师提前搭建好的。我只是在开发过程中,对一些变量的类型进行了修改,没有太大的改动。
有关于Java和数据库的连接,我在这里就不多说了,这里粘贴一段连接测试的代码仅供参考
import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class TestJDBC {
public static Connection getConnection() throws SQLException,ClassNotFoundException{
//加载JDBC的驱动
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url = "jdbc:sqlserver://localhost:1433; DatabaseName=TTMS";
String username = "sa";
String password = "123";
//创建与数据库类的连接实例
Connection connection = DriverManager.getConnection(url,username,password);
return connection;
}
public static <E> void main(String[] args){
try{
//获取连接实例connection,用connection创建Statement对象类实例sql_statement
Connection connection = getConnection();
Statement sql_statement = connection.createStatement();
//对play表的验证
//进行查询,用ResultSet类的对象,返回查询的结果
String query = "select * from play";
ResultSet result = sql_statement.executeQuery(query);
//显示数据中seat表的内容
System.out.println("play表的数据如下:");
//对获得的查询结果进行处理
while(result.next()){
int a = result.getInt("play_id");
int b = result.getInt("play_type_id");
int c = result.getInt("play_lang_id");
String d = result.getString("play_name");
String e = result.getString("play_introduction");
String f = result.getString("play_image");
int g = result.getInt("play_length");
int h = result.getInt("play_ticket_price");
int i = result.getInt("play_status");
System.out.println(a+" "+b+" "+c+" "+d+" "+e+" "+f+" "+g+" "+h+" "+i);
}
//关闭连接和声明
sql_statement.close();
connection.close();
}catch(ClassNotFoundException e){
System.err.print("ClassNotFoundException:");
System.err.println(e.getMessage());
}catch(SQLException e){
System.err.print("SQLException:");
System.err.println(e.getMessage());
}
}
}
2.在Java代码的编写中,我采用了三层架构的模式进行开发。即界面层(UI),业务逻辑层(Service),持久化层(DAO)。
下面说一下关于核心用例的思路
eg1:售票 (在这里偷个懒,就用答辩时候的PPT截图了)
eg2:销售统计与分析
3.以上是两个较为复杂的用例的实现思路,其余的演出厅管理,剧目信息管理,座位管理,员工信息管理等,就是实现基本的增删改查就好了。下面附上一些界面的截图:
(1)登录界面(由售票员登录,管理员登录,经理登录这三个标签页组合而成)
(2)影片信息展示界面
(3)演出计划界面(由于点击后需要遍历座位,加载耗时,所以开启线程,增加了进度条)
(4)座位以及售票界面
如果选择的座位对应的票未被售出,则进行支付,购票
如果该座位的票已经被预定(即红色座位),则会给出提示,不能订票
(5)剧目信息管理界面(在这里使用了数据字典,方便对影片类型以及语言类型进行添加)
其余几个界面类似,都可以进行复用,就不再一一展示了
(6)销售统计界面(分为按剧目统计和按演出厅统计两个部分,其中每一项又分为总销售统计和当天销售统计,按月统计还未实现)
按剧目总销售统计
按剧目当天销售统计
(7)销售数据分析(在这一部分,采用了GUI绘图,通过条形统计图对总销售额进行统计,当然也可以再添加折线以及扇形统计图)
按影片名称进行统计
按演出厅进行统计
统计图的绘制也很简单,导入三个jar包,就很简单了(百度一下就好)
代码下载地址如下:https://download.csdn.net/download/pary__for/9910259
github地址如下:https://github.com/pray-for/TTMS_JAVA