基于java+mysql的swing+mysql火车票售票管理系统(java+swing+mysql+gui)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
管理员管理车票和用户、用户购买车票等
技术框架
Java Swing MySQL
基于java+mysql的Swing+MySQL火车票售票管理系统(java+swing+mysql+gui)
String password = rs.getString(5);
User user0 = new User(userid0, name, identity_number, account, password);
user.add(user0);
}
Util.closeAll(con, stmt, rs);
return user;
}
@Override
public boolean SlectAcPs(String account, String password) throws SQLException {
boolean flag = false;
String sql = "select account,password from user";
Connection con = Util.getConnection();
PreparedStatement stmt = con.prepareStatement(sql);
ResultSet rr = stmt.executeQuery();
while (rr.next()) {
String account1 = rr.getString(1);
String password1 = rr.getString(2);
if (account.equals(account1) && password.equals(password1)) {
flag = true;
break;
}
}
Util.closeAll(con, stmt, rr);
return flag;
}
@Override
public List<AcPs> getAC(String account, String password) throws SQLException {
String account0 = account;
String password0 = password;
List<AcPs> acps = new ArrayList<>();
AcPs acpss = new AcPs(account0, password0);
acps.add(acpss);
return acps;
}
@Override
public int GetUseridbyaccount(String account) throws SQLException {
Connection con = Util.getConnection();
String sql = "select userid from user where account = ?";
JLabel label_8 = new JLabel("发售站:");
label_8.setBounds(280, 357, 146, 23);
add(label_8);
txtticket_office = new JTextField();
txtticket_office.setBounds(350, 357, 146, 23);
add(txtticket_office);
txtticket_office.setColumns(10);
txtticket_office.setText(ticket.getTicket_office());
ticketDao = new TicketImpl();
JButton btnNewButton = new JButton("修改车票");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (txtstation_arrival.getText().equals("")) { //判断用户输入是否为空;
JOptionPane.showMessageDialog(null, "请输入到达站", "警告对话框", JOptionPane.WARNING_MESSAGE);
return;
} else if (txtstation_depart.getText().equals("")) {
JOptionPane.showMessageDialog(null, "请输入乘车站", "警告对话框", JOptionPane.WARNING_MESSAGE);
return;
} else if (txtdepart_date.getText().equals("")) {
JOptionPane.showMessageDialog(null, "请输入发车日期", "警告对话框", JOptionPane.WARNING_MESSAGE);
return;
} else if (txtdepart_time.getText().equals("")) {
JOptionPane.showMessageDialog(null, "请输入发车时间", "警告对话框", JOptionPane.WARNING_MESSAGE);
return;
} else if (txtticket_number.getText().equals("")) {
JOptionPane.showMessageDialog(null, "请输入车次", "警告对话框", JOptionPane.WARNING_MESSAGE);
return;
} else if (txttickets_left.getText().equals("")) {
JOptionPane.showMessageDialog(null, "请输入余票", "警告对话框", JOptionPane.WARNING_MESSAGE);
return;
} else if (txtfares.getText().equals("")) {
JOptionPane.showMessageDialog(null, "请输入票价", "警告对话框", JOptionPane.WARNING_MESSAGE);
return;
} else if (txtticket_office.getText().equals("")) {
JOptionPane.showMessageDialog(null, "请输入发售站", "警告对话框", JOptionPane.WARNING_MESSAGE);
return;
}
int ticketid = ticket.getTicketid();
String station_arrival = txtstation_arrival.getText();
String station_depart = txtstation_depart.getText();
String depart_date = txtdepart_date.getText();
String depart_time = txtdepart_time.getText();
String ticket_number0 = txtticket_number.getText();
int ticket_number = Integer.parseInt(ticket_number0);
Seattype seattype = (Seattype) cmbseattype.getSelectedItem();
String seattypeid = String.valueOf(seattype.getSeattypename()).toString();
add(txtticket_number);
txtticket_number.setColumns(10);
txtticket_number.setText(String.valueOf(ticket.getTicket_number()));
JLabel label_4 = new JLabel("车票余量:");
label_4.setBounds(280, 227, 146, 23);
add(label_4);
txttickets_left = new JTextField();
txttickets_left.setBounds(350, 227, 146, 23);
add(txttickets_left);
txttickets_left.setColumns(10);
txttickets_left.setText(String.valueOf(ticket.getTickets_left()));
tickettypeDao = new TickettypeImpl();
List<Tickettype> list = tickettypeDao.queryAll();
System.out.println(list);
JLabel label_5 = new JLabel("机车类型:");
label_5.setBounds(280, 260, 146, 23);
add(label_5);
cmbtickettype = new JComboBox(list.toArray());
cmbtickettype.setBounds(350, 260, 146, 23);
add(cmbtickettype);
seattypeDao = new SeattypeImpl();
List<Seattype> list1 = seattypeDao.queryAll();
JLabel label_6 = new JLabel("座位类型:");
label_6.setBounds(280, 292, 146, 23);
add(label_6);
cmbseattype = new JComboBox(list1.toArray());
cmbseattype.setBounds(350, 292, 146, 23);
add(cmbseattype);
JLabel label_7 = new JLabel("车票价格:");
label_7.setBounds(280, 325, 146, 23);
add(label_7);
txtfares = new JTextField();
txtfares.setBounds(350, 325, 146, 23);
add(txtfares);
txtfares.setColumns(10);
// TODO Auto-generated catch block
e2.printStackTrace();
}
try {
loadData();
} catch (SQLException e1) {
e1.printStackTrace();
}
}
});
}
public void loadData() throws SQLException {
// 清除旧的数据
model.getDataVector().clear();
ticketDao = new TicketImpl();
Inqurie_sg iqs = new Inqurie_sg();
List<Ticket> list = ticketDao.quetida(iqs.getStation_arrival00(), iqs.getStation_depart00(), iqs.getDepart_date00());
// 遍历每一条数据,添加到model中
for (Ticket ticket : list) {
// 添加 行数据
// cob.setSelectedItem(new Tickettype(ticket.getTicketid()));
model.addRow(new Object[]{ticket.getTicketid(), ticket.getStation_arrival(), ticket.getStation_depart(),
ticket.getDepart_date(), ticket.getDepart_time(), ticket.getTicket_number(), ticket.getSeattypeid(),
ticket.getTickettypeid(), ticket.getTickets_left(), ticket.getFares(),
ticket.getTicket_office()
});
}
}
/**
* 购票方法
*
* @throws Exception
*/
public void buy() throws Exception {
if (table.getSelectedRowCount() <= 0) {
JOptionPane.showMessageDialog(null, "请选择要购买的车票");
return;
}
System.out.println(table.getSelectedColumn());
int result = JOptionPane.showConfirmDialog(null, "是否确定要购买该车票");
// 判断用户是否点击
if (result == JOptionPane.OK_OPTION) {
int ticketidd = Integer.valueOf(table.getValueAt(
table.getSelectedRow(), 0).toString());
Userlogin_db dg = new Userlogin_db();
depart_date, depart_time, ticket_number, seattype, tickettype,
tickets_left, fares, ticket_office);
try {
ticketDao.update(ticket);
} catch (SQLException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
try {
loadData();
} catch (SQLException e1) {
e1.printStackTrace();
}
}
});
}
public void loadData() throws SQLException {
// 清除旧的数据
model.getDataVector().clear();
ticketDao = new TicketImpl();
Inqurie_sg iqs = new Inqurie_sg();
List<Ticket> list = ticketDao.quetida(iqs.getStation_arrival00(), iqs.getStation_depart00(), iqs.getDepart_date00());
// 遍历每一条数据,添加到model中
for (Ticket ticket : list) {
// 添加 行数据
// cob.setSelectedItem(new Tickettype(ticket.getTicketid()));
model.addRow(new Object[]{ticket.getTicketid(), ticket.getStation_arrival(), ticket.getStation_depart(),
ticket.getDepart_date(), ticket.getDepart_time(), ticket.getTicket_number(), ticket.getSeattypeid(),
ticket.getTickettypeid(), ticket.getTickets_left(), ticket.getFares(),
ticket.getTicket_office()
});
}
}
/**
* 购票方法
*
* @throws Exception
*/
public void buy() throws Exception {
if (table.getSelectedRowCount() <= 0) {
JOptionPane.showMessageDialog(null, "请选择要购买的车票");
return;
}
System.out.println(table.getSelectedColumn());
int result = JOptionPane.showConfirmDialog(null, "是否确定要购买该车票");
// 判断用户是否点击
if (result == JOptionPane.OK_OPTION) {
int ticketidd = Integer.valueOf(table.getValueAt(
// 判断用户是否点击
if (result == JOptionPane.OK_OPTION) {
int ticketid = Integer.valueOf(table.getValueAt(table.getSelectedRow(), 0).toString());
String station_arrival = table.getValueAt(table.getSelectedRow(), 1).toString();
String station_depart = table.getValueAt(table.getSelectedRow(), 2).toString();
String depart_date = table.getValueAt(table.getSelectedRow(), 3).toString();
String depart_time = table.getValueAt(table.getSelectedRow(), 4).toString();
int ticket_number = Integer.valueOf(table.getValueAt(table.getSelectedRow(), 5).toString());
String seattypeid = table.getValueAt(table.getSelectedRow(), 6).toString();
String tickettypeid = table.getValueAt(table.getSelectedRow(), 7).toString();
int tickets_left = Integer.valueOf(table.getValueAt(table.getSelectedRow(), 8).toString());
String fares = table.getValueAt(table.getSelectedRow(), 9).toString();
String ticket_office = table.getValueAt(table.getSelectedRow(), 10).toString();
Ticket ticket = new Ticket(ticketid, station_arrival, station_depart, depart_date, depart_time,
ticket_number, seattypeid, tickettypeid, tickets_left, fares, ticket_office);
UpdataTicket updataticket = new UpdataTicket(ticket);
updataticket.setVisible(true);
}
}
}
/**
* 车票信息修改
*/
public class UpdataTicket extends JFrame {
int userid0 = rs.getInt(1);
String name = rs.getString(2);
String identity_number = rs.getString(3);
String account = rs.getString(4);
String password = rs.getString(5);
User user0 = new User(userid0, name, identity_number, account, password);
user.add(user0);
}
Util.closeAll(con, stmt, rs);
return user;
}
public List<User> queryAll() throws SQLException {
Connection con = Util.getConnection();
String sqladd = "select * from user";
PreparedStatement stmt = con.prepareStatement(sqladd);
ResultSet rs = stmt.executeQuery();
List<User> user = new ArrayList<>();
while (rs.next()) {
int userid0 = rs.getInt(1);
String name = rs.getString(2);
String identity_number = rs.getString(3);
String account = rs.getString(4);
String password = rs.getString(5);
User user0 = new User(userid0, name, identity_number, account, password);
user.add(user0);
}
Util.closeAll(con, stmt, rs);
return user;
}
@Override
public boolean SlectAcPs(String account, String password) throws SQLException {
boolean flag = false;
String sql = "select account,password from user";
Connection con = Util.getConnection();
PreparedStatement stmt = con.prepareStatement(sql);
ResultSet rr = stmt.executeQuery();
while (rr.next()) {
String account1 = rr.getString(1);
String password1 = rr.getString(2);
if (account.equals(account1) && password.equals(password1)) {
flag = true;
stmttt.setInt(1, userticketticketid);
stmttt.executeUpdate();
String sql = "delete from userticket where userticketid=?";
PreparedStatement stmt = con.prepareStatement(sql);
stmt.setInt(1, userticketid);
stmt.executeUpdate();
return true;
}
@Override
public boolean SelectUidTid(int ticketid, int userid) throws SQLException {
boolean flag = true;
String sql = "select userticketuserid,userticketticketid from userticket";
Connection con = Util.getConnection();
PreparedStatement stmt = con.prepareStatement(sql);
ResultSet rr = stmt.executeQuery();
while (rr.next()) {
int useridd = rr.getInt(1);
int ticketidd = rr.getInt(2);
if (useridd == userid && ticketidd == ticketid) {
flag = false;
break;
}
}
Util.closeAll(con, stmt, rr);
return flag;
/*String sql = "select userticketuserid,userticketticketid";
PreparedStatement stmt = con.prepareStatement(sql);
stmt.setInt(1, ticketid);
stmt.executeUpdate();
ResultSet rs = null;
DBcon.closeAll(stmt, rs);
return true;*/
}
@Override
public boolean Left(int ticketid) throws SQLException {
boolean flag = false;
Connection conn = Util.getConnection();
String sqladd = "select tickets_left from ticket where ticketid=?";
PreparedStatement stmt = conn.prepareStatement(sqladd);
stmt.setInt(1, ticketid);
ResultSet rt = stmt.executeQuery();
while (rt.next()) {
int useridd = rt.getInt(1);
if (useridd > 0) {
flag = true;
break;
}
panel.add(btnUpd);
btnUpd.setActionCommand("upd");
tzyh = new JButton("用户管理");
panel.add(tzyh);
tuichu = new JButton("退出");
panel.add(tuichu);
tuichu.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});
tzyh.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Usermanagement_ui yhgl = new Usermanagement_ui();
yhgl.setVisible(true);
}
});
panelBottom = new JPanel();
contentPane.add(panelBottom, BorderLayout.CENTER);
panelBottom.setLayout(new BorderLayout(0, 0));
btnQue.addActionListener(this);
btnDel.addActionListener(this);
btnAdd.addActionListener(this);
btnUpd.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
System.out.println(command);
if (command.equals("add")) {
panelBottom.removeAll();
try {
add = new AddTicket();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
panelBottom.add(add, BorderLayout.CENTER);
panelBottom.updateUI();
} else if (command.equals("que")) {
JButton btnNewButton = new JButton("添加用户");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (txtname.getText().equals("")) { //判断用户输入是否为空;
JOptionPane.showMessageDialog(null, "请输入姓名", "警告对话框", JOptionPane.WARNING_MESSAGE);
return;
}
if (txtidentity_number.getText().equals("")) { //判断用户输入是否为空;
JOptionPane.showMessageDialog(null, "请输入身份证号", "警告对话框", JOptionPane.WARNING_MESSAGE);
return;
}
if (txtaccout.getText().equals("")) { //判断用户输入是否为空;
JOptionPane.showMessageDialog(null, "请输入账号", "警告对话框", JOptionPane.WARNING_MESSAGE);
return;
}
if (txtPassword.getText().equals("")) { //判断用户输入是否为空;
JOptionPane.showMessageDialog(null, "请输入密码", "警告对话框", JOptionPane.WARNING_MESSAGE);
return;
}
String name = txtname.getText();
String identity_number = txtidentity_number.getText();
String account = txtaccout.getText();
String password = txtPassword.getText();
if (account.length() < 1) {
JOptionPane.showMessageDialog(null, "账号必须大于0位!");
txtname.setText("");
txtidentity_number.setText("");
txtaccout.setText("");
txtPassword.setText("");
return;
}
if (password.length() < 1) {
JOptionPane.showMessageDialog(null, "添密码必须大于0位!");
txtname.setText("");
txtidentity_number.setText("");
txtaccout.setText("");
txtPassword.setText("");
return;
}
boolean flag;
try {
flag = userDao.add(name, identity_number, account, password);
try {
if (flag) {
JOptionPane.showMessageDialog(null, "添加成功");
txtname.setText("");
txtidentity_number.setText("");
String station_arrival = table.getValueAt(e.getLastRow(), 1).toString();
String station_depart = table.getValueAt(e.getLastRow(), 2).toString();
String depart_date = table.getValueAt(e.getLastRow(), 3).toString();
String depart_time = table.getValueAt(e.getLastRow(), 4).toString();
int ticket_number = Integer.valueOf(table.getValueAt(e.getLastRow(),
5).toString());
String seattype = table.getValueAt(e.getLastRow(), 6).toString();
String tickettype = table.getValueAt(e.getLastRow(), 7).toString();
int tickets_left = Integer.valueOf(table.getValueAt(e.getLastRow(),
8).toString());
String fares = table.getValueAt(e.getLastRow(), 9).toString();
String ticket_office = table.getValueAt(e.getLastRow(), 10).toString();
Ticket ticket = new Ticket(ticketid, station_arrival, station_depart,
depart_date, depart_time, ticket_number, seattype, tickettype,
tickets_left, fares, ticket_office);
try {
ticketDao.update(ticket);
} catch (SQLException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
try {
loadData();
} catch (SQLException e1) {
e1.printStackTrace();
}
}
});
}
public void loadData() throws SQLException {
// 清除旧的数据
model.getDataVector().clear();
ticketDao = new TicketImpl();
Inqurie_sg iqs = new Inqurie_sg();
List<Ticket> list = ticketDao.quetida(iqs.getStation_arrival00(), iqs.getStation_depart00(), iqs.getDepart_date00());
// 遍历每一条数据,添加到model中
for (Ticket ticket : list) {
// 添加 行数据
// cob.setSelectedItem(new Tickettype(ticket.getTicketid()));
model.addRow(new Object[]{ticket.getTicketid(), ticket.getStation_arrival(), ticket.getStation_depart(),
ticket.getDepart_date(), ticket.getDepart_time(), ticket.getTicket_number(), ticket.getSeattypeid(),
ticket.getTickettypeid(), ticket.getTickets_left(), ticket.getFares(),
ticket.getTicket_office()
});
}
Util.closeAll(con, stmt, rs);
return ticket;
}
@Override
public List<Ticket> queryAll() throws SQLException {
Connection con = Util.getConnection();
String sqladd = "select * from ticket ";
PreparedStatement stmt = con.prepareStatement(sqladd);
ResultSet rs = stmt.executeQuery();
List<Ticket> ticket = new ArrayList<>();
while (rs.next()) {
int ticketid0 = rs.getInt(1);
String station_arrival = rs.getString(2);
String station_depart = rs.getString(3);
String depart_date = rs.getString(4);
String depart_time = rs.getString(5);
int ticket_number = (rs.getInt(6));
String seattypeid = rs.getString(7);
String tickettypeid = rs.getString(8);
int tickets_left = rs.getInt(9);
String fares = rs.getString(10);
String ticket_office = rs.getString(11);
Ticket ticket2 = new Ticket(ticketid0, station_arrival,
station_depart, depart_date, depart_time, ticket_number,
seattypeid, tickettypeid, tickets_left, fares, ticket_office);
ticket.add(ticket2);
}
Util.closeAll(con, stmt, rs);
return ticket;
}
@Override
public List<Ticket> quetida(String station_arrival, String station_depart, String depart_date) throws SQLException {
Connection con = Util.getConnection();
String sqladd = "select * from ticket where station_arrival=? and station_depart=? and depart_date=? ";
PreparedStatement stmt = con.prepareStatement(sqladd);
stmt.setString(1, station_arrival);
stmt.setString(2, station_depart);
stmt.setString(3, depart_date);
ResultSet rs = stmt.executeQuery();
List<Ticket> ticket = new ArrayList<>();
while (rs.next()) {
int ticketid0 = rs.getInt(1);
String station_arrival0 = rs.getString(2);
String station_depart0 = rs.getString(3);
String depart_date0 = rs.getString(4);
String depart_time = rs.getString(5);
int ticket_number = (rs.getInt(6));
String seattypeid = rs.getString(7);
String account = table.getValueAt(table.getSelectedRow(), 3).toString();
String password = table.getValueAt(table.getSelectedRow(), 4).toString();
User user = new User(userid, name, identity_number, account, password);
UpdataUser upd = new UpdataUser(user);
upd.setVisible(true);
}
}
public void chongzhi() {
if (table.getSelectedRowCount() <= 0) {
JOptionPane.showMessageDialog(null, "请选择要修改的数据行");
return;
}
int result = JOptionPane.showConfirmDialog(null, "是否确定要充值");
// 判断用户是否点击
if (result == JOptionPane.OK_OPTION) {
int userid = Integer.valueOf(table.getValueAt(table.getSelectedRow(), 0).toString());
top_up tu = new top_up(userid);
tu.setVisible(true);
}
}
}
/**
* 用户信息修改
*/
public class UpdataUser extends JFrame {
JPanel contentPane;
private JTextField txtname;
private JTextField txtidentity_number;
private JTextField txtaccout;
private JTextField txtPassword;
private UserDaoImpl userDao;
label_7.setBounds(280, 325, 146, 23);
add(label_7);
txtfares = new JTextField();
txtfares.setBounds(350, 325, 146, 23);
add(txtfares);
txtfares.setColumns(10);
txtfares.setText(ticket.getFares());
JLabel label_8 = new JLabel("发售站:");
label_8.setBounds(280, 357, 146, 23);
add(label_8);
txtticket_office = new JTextField();
txtticket_office.setBounds(350, 357, 146, 23);
add(txtticket_office);
txtticket_office.setColumns(10);
txtticket_office.setText(ticket.getTicket_office());
ticketDao = new TicketImpl();
JButton btnNewButton = new JButton("修改车票");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (txtstation_arrival.getText().equals("")) { //判断用户输入是否为空;
JOptionPane.showMessageDialog(null, "请输入到达站", "警告对话框", JOptionPane.WARNING_MESSAGE);
return;
} else if (txtstation_depart.getText().equals("")) {
JOptionPane.showMessageDialog(null, "请输入乘车站", "警告对话框", JOptionPane.WARNING_MESSAGE);
return;
} else if (txtdepart_date.getText().equals("")) {
JOptionPane.showMessageDialog(null, "请输入发车日期", "警告对话框", JOptionPane.WARNING_MESSAGE);
return;
} else if (txtdepart_time.getText().equals("")) {
JOptionPane.showMessageDialog(null, "请输入发车时间", "警告对话框", JOptionPane.WARNING_MESSAGE);
return;
} else if (txtticket_number.getText().equals("")) {
JOptionPane.showMessageDialog(null, "请输入车次", "警告对话框", JOptionPane.WARNING_MESSAGE);
return;
} else if (txttickets_left.getText().equals("")) {
JOptionPane.showMessageDialog(null, "请输入余票", "警告对话框", JOptionPane.WARNING_MESSAGE);
return;
} else if (txtfares.getText().equals("")) {
JOptionPane.showMessageDialog(null, "请输入票价", "警告对话框", JOptionPane.WARNING_MESSAGE);
return;
ticketDao = new TicketImpl();
JButton btnNewButton = new JButton("添加车票");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (txtstation_arrival.getText().equals("")) { //判断用户输入是否为空;
JOptionPane.showMessageDialog(null, "请输入到达站", "警告对话框", JOptionPane.WARNING_MESSAGE);
return;
} else if (txtstation_depart.getText().equals("")) {
JOptionPane.showMessageDialog(null, "请输入乘车站", "警告对话框", JOptionPane.WARNING_MESSAGE);
return;
} else if (txtdepart_date.getText().equals("")) {
JOptionPane.showMessageDialog(null, "请输入发车日期", "警告对话框", JOptionPane.WARNING_MESSAGE);
return;
} else if (txtdepart_time.getText().equals("")) {
JOptionPane.showMessageDialog(null, "请输入发车时间", "警告对话框", JOptionPane.WARNING_MESSAGE);
return;
} else if (txtticket_number.getText().equals("")) {
JOptionPane.showMessageDialog(null, "请输入车次", "警告对话框", JOptionPane.WARNING_MESSAGE);
return;
} else if (txttickets_left.getText().equals("")) {
JOptionPane.showMessageDialog(null, "请输入余票", "警告对话框", JOptionPane.WARNING_MESSAGE);
return;
} else if (txtfares.getText().equals("")) {
JOptionPane.showMessageDialog(null, "请输入票价", "警告对话框", JOptionPane.WARNING_MESSAGE);
return;
} else if (txtticket_office.getText().equals("")) {
JOptionPane.showMessageDialog(null, "请输入发售站", "警告对话框", JOptionPane.WARNING_MESSAGE);
return;
}
String station_arrival = txtstation_arrival.getText();
String station_depart = txtstation_depart.getText();
String depart_date = txtdepart_date.getText();
String depart_time = txtdepart_time.getText();
String ticket_number0 = txtticket_number.getText();
int ticket_number = Integer.parseInt(ticket_number0);
Seattype seattype = (Seattype) cmbseattype.getSelectedItem();
String seattypeid = String.valueOf(seattype.getSeattypename()).toString();
Tickettype tickettype = (Tickettype) cmbtickettype.getSelectedItem();
String tickettypeid = String.valueOf(tickettype);
String tickets_left0 = txttickets_left.getText();
int tickets_left = Integer.parseInt(tickets_left0);
if (result == JOptionPane.OK_OPTION) {
int userid = Integer.valueOf(table.getValueAt(table.getSelectedRow(), 0).toString());
String name = table.getValueAt(table.getSelectedRow(), 1).toString();
String identity_number = table.getValueAt(table.getSelectedRow(), 2).toString();
String account = table.getValueAt(table.getSelectedRow(), 3).toString();
String password = table.getValueAt(table.getSelectedRow(), 4).toString();
User user = new User(userid, name, identity_number, account, password);
UpdataUser upd = new UpdataUser(user);
upd.setVisible(true);
}
}
public void chongzhi() {
if (table.getSelectedRowCount() <= 0) {
JOptionPane.showMessageDialog(null, "请选择要修改的数据行");
return;
}
int result = JOptionPane.showConfirmDialog(null, "是否确定要充值");
// 判断用户是否点击
if (result == JOptionPane.OK_OPTION) {
int userid = Integer.valueOf(table.getValueAt(table.getSelectedRow(), 0).toString());
top_up tu = new top_up(userid);
tu.setVisible(true);
}
}
}
/**
* 用户信息修改
*/
public class UpdataUser extends JFrame {
JPanel contentPane;
private JTextField txtname;
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
btnNewButton.setBounds(320, 400, 116, 23);
add(btnNewButton);
}
}
/**
* 用户查找
*/
public class QueryUser extends JPanel {
private JTable table;
private DefaultTableModel model;// 用于存储表格数据
private UserDao userDao;
private String oldValue = "";// 保存单元格编辑 前的值