软件项目开发总结报告模版

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

火车票系统的开发
1引言
研究报告(1.研究计划;2.完成的研究内容、研究方法、研究过程与结论、成果;3.比照研究计划,分析超过或未达到预定目标、进度、研究内容的原因;4.参考文献等。


随着人们生活水平和经济水平的提高,网络科技的全球化的发展,出游和出差的频率越来越多。

这大大的激发了交通水平的发展。

其中,火车这种又方便有便宜的交通工具作为人们的首选,火车站的客运列车增加,客运量也随之增加。

原有的售票的方式已经不再能满足旅客的需求了。

为了方便旅客售票系统不仅仅只能售票也能够了解列车的各种信息。

这样才能成为现在网络社会的真的适应者。

2需求分析
该售票系统是融合了火车票销售、退票、列车管理、车票管理、售票员管理、列车管理信息,以及售票信息查询为一体的综合系统。

该系统主要编写的功能是列车和售票信息的查询及售票功能。

2.1用户
该系统主要有两类用户:管理员和售票员。

管理员主要工作有车次管理,车票管理和售票员管理。

对于每项功能都有添加,删除和修改的功能。

售票的主要工作是售票和退票。

2.2主要功能
该系统从功能方面可以分为四个方面:
登录。

不管你是管理员还是售票员必须登录以后才可以进行系统允许的操作。

当然要
登录的管理员和售票员都必须是再数据库中已经发布的。

基本设置:该模块主要是修改售票员的相关信息,修改列车的相关信息和修改车票的相关信息。

这一块的功能只有管理员才可以操作。

其他的售票员是不可以对他进行操作的。

售票和退票:这部分工作主要是售票员来操作的。

售票员根据买票人员提出的要求进行查询。

查询的方式有两种:一是根据车次查询;一是根据目的地来查询。

退票主要是将已经出售的车票在列车开出之前再一次的返回到数据库中,并继续出售。

列车和车票查询;当需要查询列车信息或者是车票信息是所做的操作。

2.3基本流程
3开发过程
3.1内容
该程序包括三个部分数据库的设计、通用模块的实现、各个模块的实现。

3.1.1 数据库的设计:
将本系统所需的所有的数据都存储到数据库中。

需要在数据库中管理员表、
售票员表、列车信息表和车票信息表。

如图所示:
管理员表:
售票员表:
列车信息表:
车票信息表:
3.1.2通用模块的实现:
通用模块为了减少代码的重复。

在该系统中,对经常使用的操作进行封装,如将多次需要调用的数据库和操作数库的增、删、改和查等操作进行封装。

使代码有很好的重用性,即使出现错误也很容易调试。

如本程序中的Conn.java
import java.sql.*;
public class Conn {
private static Connection con;
private static final String DRIVER = "com.mysql.jdbc.Driver";
private static final String URL ="jdbc:mysql://localhost:3306/newdatabase";
private static final String NAME="root";
private static final String PASSWORD="021*********";
static{
try {
Class.forName(DRIVER);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public static Connection getConnection(){
try {
con=DriverManager.getConnection(URL,NAME,PASSWORD);
} catch (SQLException e) {
e.printStackTrace();
}
return con;
}
public static void closeCon(Connection con){
try {
if(con!=null)
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
public static void closePt(PreparedStatement pt){ try {
if(pt!=null)
pt.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void closeRs(ResultSet rs){ try {
if(rs!=null)
rs.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
用户登录界面的设计、主界面的设计、基本设置模块、销售及退票模块和列车及车票查询模块。

用户登录模块:该部分是通过设计login.java来实现的。

这部分代码的作用是用户首先选择自己的登录的是管理员还是售票员,然后输入账号和密码。

单击登录,用户先判断用户登录的类型,然后给sql变量赋SQL语句值,系统调用DAO.java类的login()传入sql 变量。

.
Login 代码是:
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.Image;
import yout.*;
import org.eclipse.swt.widgets.*;
import com.huizhi.dao.DAO;
public class Login {
private Text nameText;
private Text passText;
private Combo combo;
private String type;
private Display display = new Display();
private Shell shell = new Shell(display);
public Login(){
FormLayout layout = new FormLayout();
layout.marginHeight =40;
layout.marginWidth =40;
shell.setLayout(layout);
shell.setText("login");
Image image = new Image(display,"2.jpg"); shell.setBackgroundImage(image);
setUIControl();
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
private void setUIControl(){
Label username = new Label(shell, SWT.NONE);
username.setText("username");
nameText = new Text(shell, SWT.SINGLE | SWT.BORDER);
Label password = new Label(shell, SWT.NONE);
password.setText("password");
passText = new Text(shell, SWT.SINGLE | SWT.BORDER| SWT.PASSWORD); // passText.setEchoChar('*');
Label select=new Label(shell, SWT.NONE);
select.setText(" select ");
Button submit = new Button(shell,SWT.PUSH);
submit.setText("login ");
submit.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e){
type=combo.getText();
String name=nameText.getText();
String pass=passText.getText();
String sql=null;
boolean flag=false;
MessageBox box=new MessageBox(shell,SWT.OK);
if("".equals(type)||"".equals(name)||"".equals(pass))
{
box.setMessage("please input all the information");
box.open();
return ;
}
DAO dao=new DAO();
if("users".equals(type)){
sql="select * from users where username='"+name+"' and password='"+pass+"'";
}else if("admin".equals(type)){
sql="select * from admin where username='"+name+"' and password='"+pass+"'";
}
flag=dao.login(sql);
if(flag)
{
shell.dispose();
new Main(type);
}else{
box.setMessage("wrong name or password");
box.open();
}
}
});
Button reset = new Button(shell, SWT.PUSH);
reset.setText("cancel");
String value[]={"users","admin"};
combo=new Combo(shell,SWT.DROP_DOWN);
combo.setItems(value);
FormData data = new FormData();
data.top = new FormAttachment(30,0);
username.setLayoutData(data);
data = new FormData();
data.top = new FormAttachment(username,0,SWT.CENTER); data.left = new FormAttachment(username,10, SWT.RIGHT); nameText.setLayoutData(data);
data = new FormData();
data.top = new FormAttachment(select,0,SWT.CENTER);
data.left = new FormAttachment(select,10, SWT.RIGHT); combo.setLayoutData(data);
data = new FormData();
data.top = new FormAttachment(username,10, SWT.BOTTOM); password.setLayoutData(data);
data = new FormData();
data.top = new FormAttachment(password,0,SWT.CENTER); data.left = new FormAttachment(nameText,0,SWT.LEFT);
passText.setLayoutData(data);
data=new FormData();
data.top=new FormAttachment(password,10,SWT.BOTTOM);
submit.setLayoutData(data);
data=new FormData();
data.top=new FormAttachment(submit,0,SWT.CENTER);
data.left=new FormAttachment(submit,20,SWT.RIGHT);
reset.setLayoutData(data);
}
public static void main(String[] args) { new Login();
}
}
DAO.java的login()代码:
public boolean login(String sql){
boolean flag=false;
con=Conn.getConnection();
try {
pt=con.prepareStatement(sql);
rs=pt.executeQuery();
if(rs.next()){
flag=true;
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
Conn.closeRs(rs);
Conn.closePt(pt);
Conn.closeCon(con);
}
return flag;
}
图示为;
实现主界面:
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*; import yout.*; import org.eclipse.swt.events.*; public class Main {
private String type;
Display display=Display.getCurrent();
Shell shell=new Shell(display);
public Main(String type){
this.type=type;
shell.setText("Train ticketing system");
shell.setLayout(new FillLayout());
Menu menu=new Menu(shell,SWT.BAR);
//第一个菜单
MenuItem basic=new MenuItem(menu,SWT.CASCADE);
basic.setText("Basic Settings");
if("users".equals(type))
{
basic.setEnabled(false);
}
Menu filemenu=new Menu(shell,SWT.DROP_DOWN);
MenuItem train=new MenuItem(filemenu,SWT.PUSH); train.setText("Trains Management");
train.addSelectionListener(new SelectionAdapter(){ public void widgetSelected(SelectionEvent e){ new TrainManage();
}
});
MenuItem ticket=new MenuItem(filemenu,SWT.PUSH); ticket.setText("Tickets Management");
ticket.addSelectionListener(new SelectionAdapter(){ public void widgetSelected(SelectionEvent e){ new TicketManage();
}
});
MenuItem users=new MenuItem(filemenu,SWT.PUSH); users.setText("Users Management");
users.addSelectionListener(new SelectionAdapter(){ public void widgetSelected(SelectionEvent e){ new UsersManage();
}
});
MenuItem exit=new MenuItem(filemenu,SWT.PUSH);
exit.setText("quit");
basic.setMenu(filemenu);
exit.addSelectionListener(new SelectionAdapter(){ public void widgetSelected(SelectionEvent e){
display.dispose();
}
});
//第二个菜单
MenuItem market=new MenuItem(menu,SWT.CASCADE); market.setText("Sales and Refunds");
Menu editMenu=new Menu(shell,SWT.DROP_DOWN);
MenuItem marketItem=new MenuItem(editMenu,SWT.PUSH); marketItem.setText("Sales Tickets");
marketItem.addSelectionListener(new SelectionAdapter(){ public void widgetSelected(SelectionEvent e){ new XiaosTicket();
}
});
MenuItem refundItem=new MenuItem(editMenu,SWT.PUSH); refundItem.setText("Refunds Tickets");
market.setMenu(editMenu);
refundItem.addSelectionListener(new SelectionAdapter(){ public void widgetSelected(SelectionEvent e){ new TuiTicket();
}
});
//第三个菜单
MenuItem find=new MenuItem(menu,SWT.CASCADE);
find.setText("Trains and Tickets query");
Menu taiMenu=new Menu(shell,SWT.DROP_DOWN);
MenuItem trainFind=new MenuItem(taiMenu,SWT.PUSH); trainFind.setText("Trains query");
trainFind.addSelectionListener(new SelectionAdapter(){ public void widgetSelected(SelectionEvent e){ new FindTrain();
}
});
MenuItem ticketFind=new MenuItem(taiMenu,SWT.PUSH); ticketFind.setText("Ticket query");
find.setMenu(taiMenu);
ticketFind.addSelectionListener(new SelectionAdapter(){ public void widgetSelected(SelectionEvent e){
new FindTicket();
}
});
shell.setMenuBar(menu);
shell.setSize(500,400);
shell.open();
while(!shell.isDisposed()){
if(!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
图示为:
基本设置模块包括车次管理,车票管理和售票员管理。

车次管理主要是是对于列车的增加,删除和修改等操作。

其中包括它的相关的信息等。

它是由TrainManagement.java.代码如下:
import java.util.List;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import yout.*;
import org.eclipse.swt.widgets.*;
import com.huizhi.dao.DAO;
import com.huizhi.vo.Train;
public class TrainManage {
Display display=Display.getCurrent();
Shell tmshell=new Shell(display);
final Table table=new Table(tmshell,SWT.SINGLE|SWT.H_SCROLL|SWT.V_SCROLL|SWT.H_SCROLL|SWT.BORDER|SWT .FULL_SELECTION);
TrainManage tm=this;
public TrainManage(){
RowLayout rowLayout=new RowLayout();
rowLayout.pack=true;
rowLayout.wrap=true;
rowLayout.justify=false;
rowLayout.marginTop=20;
tmshell.setLayout(rowLayout);
final TableColumn column1=new TableColumn(table,SWT.LEFT); column1.setText("Train ID");
column1.setWidth(80);
final TableColumn column2=new TableColumn(table,SWT.LEFT); column2.setText("TrainNum");
column2.setWidth(80);
final TableColumn column3=new TableColumn(table,SWT.LEFT); column3.setText("TrainType");
column3.setWidth(80);
final TableColumn column4=new TableColumn(table,SWT.LEFT); column4.setText("Starting");
column4.setWidth(80);
final TableColumn column5=new TableColumn(table,SWT.LEFT); column5.setText("startingTime");
column5.setWidth(80);
final TableColumn column6=new TableColumn(table,SWT.LEFT); column6.setText("terminal");
column6.setWidth(80);
final TableColumn column7=new TableColumn(table,SWT.LEFT); column7.setText("terminal Time");
column7.setWidth(80);
final TableColumn column8=new TableColumn(table,SWT.LEFT); column8.setText("is kongtiao");
column8.setWidth(80);
final TableColumn column9=new TableColumn(table,SWT.LEFT); column9.setText("price");
column9.setWidth(80);
final TableColumn column10=new TableColumn(table,SWT.LEFT);
column10.setText("middleStation");
column10.setWidth(80);
final TableColumn column11=new TableColumn(table,SWT.LEFT); column11.setText("yzNum");
column11.setWidth(80);
final TableColumn column12=new TableColumn(table,SWT.LEFT); column12.setText("rzNum");
column12.setWidth(80);
final TableColumn column13=new TableColumn(table,SWT.LEFT); column13.setText("ywNum");
column13.setWidth(80);
final TableColumn column14=new TableColumn(table,SWT.LEFT); column14.setText("rwNum");
column14.setWidth(80);
table.setHeaderVisible(true);
table.setLinesVisible(true);
freshData();
table.setSize(800,200);
Button add=new Button(tmshell,SWT.PUSH);
add.setText("add trains");
add.addSelectionListener(new SelectionAdapter(){ public void widgetSelected(SelectionEvent e){ new AddTrain(tm);
}
});
Button update=new Button(tmshell,SWT.PUSH); update.setText("modify");
update.addSelectionListener(new SelectionAdapter(){ public void widgetSelected(SelectionEvent e){ TableItem[] selection=table.getSelection();
TableItem selectedRow=selection[0];
Train train=new Train();
train.setId(Integer.parseInt(selectedRow.getText(0)));
train.setTrainNum(selectedRow.getText(1));
train.setTrainType(selectedRow.getText(2));
train.setStarting(selectedRow.getText(3));
train.setStartingTime(selectedRow.getText(4));
train.setTerminal(selectedRow.getText(5));
train.setTerminalTime(selectedRow.getText(6));
train.setIskongTiao(selectedRow.getText(7));
train.setPrice(Float.parseFloat(selectedRow.getText(8)));
train.setMiddleStation(selectedRow.getText(9));
train.setYzNum(Integer.parseInt(selectedRow.getText(10)));
train.setRzNum(Integer.parseInt(selectedRow.getText(11)));
train.setYwNum(Integer.parseInt(selectedRow.getText(12)));
train.setRwNum(Integer.parseInt(selectedRow.getText(13)));
new UpdateTrain(train,tm);
}
});
Button delete=new Button(tmshell,SWT.PUSH);
delete.setText("cancel");
delete.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e){
MessageBox box=new MessageBox(tmshell,SWT.YES|SWT.NO);
box.setMessage("Are you sure to cancel?");
int num=box.open();
if(num==128)
return ;
TableItem[] selection=table.getSelection();
TableItem selectedRow=selection[0];
DAO dao=new DAO();
String sql="delete from train where id="+selectedRow.getText(0)+"";
int i=dao.update(sql);
if(i>0){
box.setMessage("succeed");
box.open();
table.remove(table.getSelectionIndex());
}else{
box.setMessage("failure");
box.open();
}
}
});
tmshell.setSize(1200,400);
tmshell.setText("train Management");
tmshell.open();
while(!tmshell.isDisposed()){
if(!display.readAndDispatch())
display.sleep();
}
tmshell.dispose();
}
public void freshData(){
table.removeAll();
try{
DAO dao=new DAO();
List list=dao.getAllTrain();
int number=list.size();
for(int i=0;i<list.size();i++){
Train train=(Train)list.get(i);
final TableItem item[]=new TableItem[number];
item[i]=new TableItem(table,SWT.None);
item[i].setText(new
String[]{Integer.toString(train.getId()),train.getTrainNum(),train.getTrainTyp e(),train.getStarting(),
train.getStartingTime(),train.getTerminal(),train.getTerminalTime(),train. getIskongTiao(),Float.toString(train.getPrice()),train.getMiddleStation(),Inte
ger.toString(train.getYzNum()),
Integer.toString(train.getRzNum()),Integer.toString(train.getYwNum()),Inte ger.toString(train.getYwNum())});
}
}catch(Exception e){
e.printStackTrace();
}
}
}
在该段代码中调用了DAO.java类中的getAllTrain()方法来获得所有的车辆信息,然后以表格的形式显示出来。

DAO.java类中的getAllTrain()和update()方法如下:public int update(String sql){
int i=0;
con=Conn.getConnection();
try {
pt=con.prepareStatement(sql);
i=pt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}finally{
Conn.closePt(pt);
Conn.closeCon(con);
}return i;
}
public List getAllTrain(){
List list=new ArrayList();
con=Conn.getConnection();
try {
pt=con.prepareStatement("select * from train");
rs=pt.executeQuery();
while(rs.next()){
Train train=new Train();
train.setId(rs.getInt(1));
train.setTrainNum(rs.getString(2));
train.setTrainType(rs.getString(3));
train.setStarting(rs.getString(4));
train.setStartingTime(rs.getString(5));
train.setTerminal(rs.getString(6));
train.setTerminalTime(rs.getString(7));
train.setIskongTiao(rs.getString(8));
train.setPrice(rs.getFloat(9));
train.setMiddleStation(rs.getString(10));
train.setYzNum(rs.getInt(11));
train.setRzNum(rs.getInt(12));
train.setYwNum(rs.getInt(13));
train.setRwNum(rs.getInt(14));
list.add(train);
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
Conn.closeRs(rs);
Conn.closePt(pt);
Conn.closeCon(con);
}return list;
}
其中的update的功能是,首先连接数据库,然后用传递过来的SQl语句在列表中删除某辆列车的信息。

getAllTrain()方法是显示所有的列车的信息。

图示如下:
在车次管理中的对于列车信息添加的功能是通过AddTrain.java 来实现的。

代码如下:import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import yout.*;
import org.eclipse.swt.widgets.*;
import com.huizhi.dao.DAO;
public class AddTrain {
Display display=Display.getCurrent();
Shell tmshell=new Shell(display);
TrainManage trainmanage=null;
public AddTrain(TrainManage tm){
trainmanage=tm;
GridLayout gridlayout=new GridLayout();
tmshell.setText("add trains information");
gridlayout.numColumns=2;
gridlayout.makeColumnsEqualWidth=true;
tmshell.setLayout(gridlayout);
GridData gd = new GridData(GridData.FILL_BOTH);
Label l=new Label(tmshell,SWT.LEFT);
l.setText("trainNum");
l.setLayoutData(gd);
gd = new GridData(GridData.FILL_BOTH);
final Text trainNum=new Text(tmshell,SWT.NONE);
trainNum.setLayoutData(gd);
gd = new GridData(GridData.FILL_BOTH);
Label l1=new Label(tmshell,SWT.LEFT);
l1.setText("trainType");
l1.setLayoutData(gd);
gd = new GridData(GridData.FILL_BOTH);
final Text trainType=new Text(tmshell,SWT.LEFT);
trainType.setSize(30,40);
trainType.setLayoutData(gd);
gd = new GridData(GridData.FILL_BOTH);
Label l2=new Label(tmshell,SWT.LEFT);
l2.setText("starting");
l2.setLayoutData(gd);
gd = new GridData(GridData.FILL_BOTH);
final Text starting=new Text(tmshell,SWT.LEFT);
starting.setLayoutData(gd);
gd = new GridData(GridData.FILL_BOTH);
Label l3=new Label(tmshell,SWT.LEFT);
l3.setText("startingtime");
l3.setLayoutData(gd);
gd = new GridData(GridData.FILL_BOTH);
final Text startingTime=new Text(tmshell,SWT.LEFT); startingTime.setSize(30,40);
startingTime.setLayoutData(gd);
Label l4=new Label(tmshell,SWT.LEFT);
l4.setText("terminal");
l4.setLayoutData(gd);
gd = new GridData(GridData.FILL_BOTH);
final Text terminal=new Text(tmshell,SWT.LEFT); terminal.setSize(30,40);
gd = new GridData(GridData.FILL_BOTH);
Label l5=new Label(tmshell,SWT.LEFT);
l5.setText("terminaltime");
l5.setLayoutData(gd);
gd = new GridData(GridData.FILL_BOTH);
final Text terminalTime=new Text(tmshell,SWT.LEFT); terminalTime.setSize(30,40);
terminalTime.setLayoutData(gd);
gd = new GridData(GridData.FILL_BOTH);
Label l6=new Label(tmshell,SWT.LEFT);
l6.setText("iskongtiao");
l6.setLayoutData(gd);
gd = new GridData(GridData.FILL_BOTH);
final Text iskongTiao=new Text(tmshell,SWT.LEFT); iskongTiao.setSize(30,40);
gd = new GridData(GridData.FILL_BOTH);
Label l7=new Label(tmshell,SWT.LEFT);
l7.setText("price");
l7.setLayoutData(gd);
gd = new GridData(GridData.FILL_BOTH);
final Text price=new Text(tmshell,SWT.LEFT);
price.setSize(30,40);
price.setLayoutData(gd);
gd = new GridData(GridData.FILL_BOTH);
Label l8=new Label(tmshell,SWT.LEFT);
l8.setText("middleStation");
l8.setLayoutData(gd);
gd = new GridData(GridData.FILL_BOTH);
final Text middleStation=new Text(tmshell,SWT.LEFT); middleStation.setSize(30,40);
middleStation.setLayoutData(gd);
gd = new GridData(GridData.FILL_BOTH);
Label l9=new Label(tmshell,SWT.LEFT);
l9.setText("yzNum");
l9.setLayoutData(gd);
gd = new GridData(GridData.FILL_BOTH);
final Text yzNum=new Text(tmshell,SWT.LEFT); yzNum.setSize(30,40);
yzNum.setLayoutData(gd);
gd = new GridData(GridData.FILL_BOTH);
Label l10=new Label(tmshell,SWT.LEFT);
l10.setText("rzNum");
l10.setLayoutData(gd);
gd = new GridData(GridData.FILL_BOTH);
final Text rzNum=new Text(tmshell,SWT.LEFT); rzNum.setSize(30,40);
rzNum.setLayoutData(gd);
gd = new GridData(GridData.FILL_BOTH);
Label l11=new Label(tmshell,SWT.LEFT);
l11.setText("ywNum");
l11.setLayoutData(gd);
gd = new GridData(GridData.FILL_BOTH);
final Text ywNum=new Text(tmshell,SWT.LEFT); ywNum.setSize(30,40);
ywNum.setLayoutData(gd);
gd = new GridData(GridData.FILL_BOTH);
Label l12=new Label(tmshell,SWT.LEFT);
l12.setText("rwNum");
l12.setLayoutData(gd);
gd = new GridData(GridData.FILL_BOTH);
final Text rwNum=new Text(tmshell,SWT.LEFT); rwNum.setSize(30,40);
rwNum.setLayoutData(gd);
Button b=new Button(tmshell,SWT.LEFT);
b.setText("add");
b.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e){
MessageBox box = new MessageBox( tmshell ,SWT.OK);
if("".equals(trainNum.getText())||"".equals(trainType.getText())||"".equal s(starting.getText())
||"".equals(startingTime.getText())||"".equals(terminal.getText())||"".equals( terminalTime.getText())
||"".equals(iskongTiao.getText())||"".equals(price.getParent())||"".equals(mid dleStation.getText())||"".equals(yzNum.getText())
||"".equals(rzNum.getText())||"".equals(ywNum.getText())||"".equals(rwNum.getT ext())){
box.setMessage("please input the right information");
return ;
}
DAO dao=new DAO();
String sql="insert into train(trainNum,trainType,starting1,startingTime,terminal,terminalTime,iskongTi ao,price," +
"middleStation,yzNum,rzNum,ywNum,rwNum)values('"+trainNum.getText()+"','"+ trainType.getText()+"','"+starting.getText()+"'," +
"'"+startingTime.getText()+"','"+terminal.getText()+"','"+terminalTime.get Text()+"','"+iskongTiao.getText()+"'," +
"'"+price.getText()+"','"+middleStation.getText()+"','"+yzNum.getText()+"' ,'"+rzNum.getText()+"','"+ywNum.getText()+"','"+rwNum.getText()+"')";
int i=dao.update(sql);
if(i>0){
box.setMessage("add");
fresh();
}
}
});
Button b1=new Button(tmshell,SWT.LEFT);
b1.setText("quit");
b1.addSelectionListener(new SelectionAdapter(){ public void widgetSelected(SelectionEvent e){ tmshell.setVisible(false);
}
});
yout();
tmshell.setSize(500,450);
tmshell.open();
while(!tmshell.isDisposed()){
if(!display.readAndDispatch())
display.sleep();
}
tmshell.dispose();
}
public void fresh(){
trainmanage.freshData();
}
}
图示为:
修改列车功能是在UpdateTrain.java.类中实现的。

代码如下:import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import yout.*;
import org.eclipse.swt.widgets.*;
import com.huizhi.dao.DAO;
import com.huizhi.vo.Train;
public class UpdateTrain {
private Train train;
Display display=Display.getCurrent();
Shell utrainshell=new Shell(display);
TrainManage trainmanage=null;
public UpdateTrain(Train train,TrainManage tm){
this.trainmanage=tm;
this.train=train;
GridLayout gridlayout=new GridLayout();
utrainshell.setText("modify train information");
gridlayout.numColumns=2;
gridlayout.makeColumnsEqualWidth=true;
utrainshell.setLayout(gridlayout);
GridData gd = new GridData(GridData.FILL_BOTH);
Label ll=new Label(utrainshell,SWT.LEFT);
ll.setText("train ID");
ll.setLayoutData(gd);
gd = new GridData(GridData.FILL_BOTH);
final Text num=new Text(utrainshell,SWT.NONE); num.setText(Integer.toString(train.getId())); num.setEnabled(false);
num.setSize(50,60);
num.setLayoutData(gd);
gd = new GridData(GridData.FILL_BOTH);
Label l=new Label(utrainshell,SWT.LEFT);
l.setText("TrainNum");
l.setLayoutData(gd);
gd = new GridData(GridData.FILL_BOTH);
final Text trainNum=new Text(utrainshell,SWT.NONE); trainNum.setText(train.getTrainNum());
trainNum.setSize(50,60);
trainNum.setLayoutData(gd);
gd = new GridData(GridData.FILL_BOTH);
Label l1=new Label(utrainshell,SWT.LEFT);
l1.setText("TrainType");
l1.setLayoutData(gd);
gd = new GridData(GridData.FILL_BOTH);
final Text trainType=new Text(utrainshell,SWT.LEFT);
trainType.setText(train.getTrainType());
trainType.setSize(30,40);
trainType.setLayoutData(gd);
gd = new GridData(GridData.FILL_BOTH);
Label l2=new Label(utrainshell,SWT.LEFT);
l2.setText("starting");
l2.setLayoutData(gd);
gd = new GridData(GridData.FILL_BOTH);
final Text starting=new Text(utrainshell,SWT.LEFT);
starting.setText(train.getStarting());
starting.setSize(30,40);
starting.setLayoutData(gd);
gd = new GridData(GridData.FILL_BOTH);
Label l3=new Label(utrainshell,SWT.LEFT);
l3.setText("startingTime");
l3.setLayoutData(gd);
gd = new GridData(GridData.FILL_BOTH);
final Text startingTime=new Text(utrainshell,SWT.LEFT); startingTime.setText(train.getStartingTime()); startingTime.setSize(30,40);
startingTime.setLayoutData(gd);
Label l4=new Label(utrainshell,SWT.LEFT);
l4.setText("terminal");
l4.setLayoutData(gd);
gd = new GridData(GridData.FILL_BOTH);
final Text terminal=new Text(utrainshell,SWT.LEFT); terminal.setText(train.getTerminal());
terminal.setSize(30,40);
terminal.setLayoutData(gd);
gd = new GridData(GridData.FILL_BOTH);
Label l5=new Label(utrainshell,SWT.LEFT);
l5.setText("terminalTime");
l5.setLayoutData(gd);
gd = new GridData(GridData.FILL_BOTH);
final Text terminalTime=new Text(utrainshell,SWT.LEFT); terminalTime.setText(train.getTerminalTime()); terminalTime.setSize(30,40);
terminalTime.setLayoutData(gd);
gd = new GridData(GridData.FILL_BOTH);
Label l6=new Label(utrainshell,SWT.LEFT);
l6.setText("iskongtiao");
l6.setLayoutData(gd);
gd = new GridData(GridData.FILL_BOTH);
final Text iskongTiao=new Text(utrainshell,SWT.LEFT); iskongTiao.setText(train.getIskongTiao()); iskongTiao.setSize(30,40);
iskongTiao.setLayoutData(gd);
gd = new GridData(GridData.FILL_BOTH);
Label l7=new Label(utrainshell,SWT.LEFT);
l7.setText("price");
l7.setLayoutData(gd);
gd = new GridData(GridData.FILL_BOTH);
final Text price=new Text(utrainshell,SWT.LEFT); price.setText(Float.toString(train.getPrice())); price.setSize(30,40);
price.setLayoutData(gd);
gd = new GridData(GridData.FILL_BOTH);。

相关文档
最新文档