📄 sellticketjpanel.java
字号:
/* * SellTicketJPanel.java * * Created on 2009年1月11日, 下午7:20 */package passengertransportmis;import java.sql.Connection;import java.sql.Date;import java.sql.ResultSet;import java.sql.ResultSetMetaData;import java.sql.SQLException;import java.sql.Statement;import java.sql.Time;import java.sql.Timestamp;import org.jdesktop.application.Action;/** * * @author Degree41 * 此类中的sell方法与一打印机绑定,当点击sell按钮时,连接打印机, * 将车票信息ti打印出来,生成车票 */public class SellTicketJPanel extends javax.swing.JPanel { /** Creates new form SellTicketJPanel */ public SellTicketJPanel() { initComponents(); } @Action public void select() { if(this.beginPointTextField.getText().isEmpty() || this.endPointTextField.getText().isEmpty() ){ javax.swing.JOptionPane.showMessageDialog(this, "要搜索起始地不得为空,请保持正确的数据输入!", "警告", 2/* warning */); return; } // 更新视图 String sql = "select * from ticket_info where start_point = '" + this.beginPointTextField.getText() + "' and end_point = '" + this.endPointTextField.getText() + "'"; ManagerPanelService.initFromDatabase(this.ticketInfoTable, sql); } @Action public void sell() { if(this.yesRadioButton.isSelected()) this.ti.setFare(this.ti.getFare()+1.0); //添加操作员id this.ti.setSell_operator_id(PassengerTransportMISApp.getUserInfo()[0]); //添加售票时间 String sql = "select now() from user where id = '" + this.ti.getSell_operator_id() + "';"; ResultSet rs = null; Timestamp date = null; try { rs = stmt.executeQuery(sql); rs.first(); date = rs.getTimestamp(1); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } this.ti.setSell_time(date); //添加车票编号:由车辆id、日期、是否买保险组成 StringBuffer sb_id = new StringBuffer(); sb_id.append(this.ti.getId()).append(" "); sb_id.append(date.getTime()).append(" "); if(this.ti.isIs_insured())sb_id.append(1).append(" "); else sb_id.append(0).append(" "); this.ti.setId(sb_id.toString()); sql = "insert into ticket_sell values ('" + this.ti.getId() + "'," + this.ti.getFare() + ",'" + (this.ti.isIs_insured() ? "是" : "否") + "','" + this.ti.getStart_point() + "','" + this.ti.getEnd_point() + "'," + "now()" + ",'" + this.ti.getSell_operator_id() + "')"; int i = Database.executeUpdate(stmt, sql); if (i == 1) { this.returnInitState(); } else javax.swing.JOptionPane.showMessageDialog(this, "卖票失败,请正确操作,请求管理员查看日志信息,维护系统!", "错误", 0/* erroe */); } @Action public void reset() { this.ti = new TicketInfo(); this.returnInitState(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { insuranceButtonGroup = new javax.swing.ButtonGroup(); jLabel1 = new javax.swing.JLabel(); beginPointTextField = new javax.swing.JTextField(); jLabel2 = new javax.swing.JLabel(); endPointTextField = new javax.swing.JTextField(); selectButton = new javax.swing.JButton(); jLabel3 = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); jLabel4 = new javax.swing.JLabel(); yesRadioButton = new javax.swing.JRadioButton(); noRadioButton = new javax.swing.JRadioButton(); sellButton = new javax.swing.JButton(); resetButton = new javax.swing.JButton(); setName("Form"); // NOI18N javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(passengertransportmis.PassengerTransportMISApp.class).getContext().getActionMap(SellTicketJPanel.class, this); org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(passengertransportmis.PassengerTransportMISApp.class).getContext().getResourceMap(SellTicketJPanel.class); jLabel1.setFont(resourceMap.getFont("noRadioButton.font")); // NOI18N jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N jLabel1.setName("jLabel1"); // NOI18N beginPointTextField.setFont(resourceMap.getFont("noRadioButton.font")); // NOI18N beginPointTextField.setText(resourceMap.getString("beginPointTextField.text")); // NOI18N beginPointTextField.setName("beginPointTextField"); // NOI18N this.beginPointTextField.setText("武汉"); jLabel2.setFont(resourceMap.getFont("noRadioButton.font")); // NOI18N jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N jLabel2.setName("jLabel2"); // NOI18N endPointTextField.setFont(resourceMap.getFont("noRadioButton.font")); // NOI18N endPointTextField.setText(resourceMap.getString("endPointTextField.text")); // NOI18N endPointTextField.setName("endPointTextField"); // NOI18N endPointTextField.addFocusListener(new java.awt.event.FocusAdapter() { public void focusGained(java.awt.event.FocusEvent evt) { endPointTextFieldFocusGained(evt); } }); selectButton.setAction(actionMap.get("select")); // NOI18N selectButton.setFont(resourceMap.getFont("noRadioButton.font")); // NOI18N selectButton.setText(resourceMap.getString("selectButton.text")); // NOI18N selectButton.setName("selectButton"); // NOI18N jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N jLabel3.setName("jLabel3"); // NOI18N jScrollPane1.setName("jScrollPane1"); // NOI18N ticketInfoTable.setName("ticketInfoTable"); // NOI18N ticketInfoTable.addFocusListener(new java.awt.event.FocusAdapter() { public void focusGained(java.awt.event.FocusEvent evt) { ticketInfoTableFocusGained(evt); } }); jScrollPane1.setViewportView(ticketInfoTable); jLabel4.setFont(resourceMap.getFont("noRadioButton.font")); // NOI18N jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N jLabel4.setName("jLabel4"); // NOI18N yesRadioButton.setFont(resourceMap.getFont("noRadioButton.font")); // NOI18N yesRadioButton.setText(resourceMap.getString("yesRadioButton.text")); // NOI18N yesRadioButton.setName("yesRadioButton"); // NOI18N yesRadioButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { yesRadioButtonActionPerformed(evt);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -