?? fixeddeposit.java
字號:
/*
* FixedDeposit.java
*
* Created on 2007年1月19日, 下午3:55
*/
package javaapplication1;
import java.awt.Toolkit;
import java.sql.*;
import javax.swing.JOptionPane;
/**
*
* @author zzz
*/
public class FixedDeposit extends javax.swing.JFrame {
String staffID = "";
/** Creates new form FixedDeposit */
public FixedDeposit(String ID) {
this.staffID = ID;
connectDB();
initComponents();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
//-------設置窗口位置居中---------------------------------------------------------------
int locationX=(int)(Toolkit.getDefaultToolkit().getScreenSize().getWidth()-getSize().getWidth())/2;
int locationY=(int)(Toolkit.getDefaultToolkit().getScreenSize().getHeight()-getSize().getHeight())/2;
setLocation(locationX,locationY);
//--------------------------------------------------------------------------------------
}
/** 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.
*/
// <editor-fold defaultstate="collapsed" desc=" 生成的代碼 ">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
accountField = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
sumField = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
nameField = new javax.swing.JTextField();
limitTimeComboBox = new javax.swing.JComboBox();
autoComboBox = new javax.swing.JComboBox();
confirmButton = new javax.swing.JButton();
resetButton = new javax.swing.JButton();
cancelButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText(" \u5b9a\u671f\u5b58\u6b3e");
jLabel2.setText("\u5e10\u53f7");
jLabel3.setText("\u5b58\u6b3e\u91d1\u989d");
jLabel4.setText("\u59d3\u540d");
jLabel5.setText("\u5e74\u9650");
jLabel6.setText("\u81ea\u52a8\u8f6c\u5b58");
limitTimeComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" }));
autoComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "\u5426", "\u662f" }));
confirmButton.setText("\u786e\u5b9a");
confirmButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
confirmButtonActionPerformed(evt);
}
});
resetButton.setText("\u91cd\u7f6e");
resetButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
resetButtonActionPerformed(evt);
}
});
cancelButton.setText("\u53d6\u6d88");
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelButtonActionPerformed(evt);
}
});
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(23, 23, 23)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(jLabel6)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(autoComboBox, 0, 158, Short.MAX_VALUE))
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel3)
.add(jLabel4)
.add(jLabel5)
.add(jLabel2))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(nameField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE)
.add(layout.createSequentialGroup()
.add(14, 14, 14)
.add(jLabel1))
.add(sumField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE)
.add(org.jdesktop.layout.GroupLayout.TRAILING, limitTimeComboBox, 0, 158, Short.MAX_VALUE)
.add(accountField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 158, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
.add(44, 44, 44))
.add(layout.createSequentialGroup()
.add(32, 32, 32)
.add(confirmButton)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(resetButton)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(cancelButton)
.addContainerGap(62, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jLabel1)
.add(8, 8, 8)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel2)
.add(accountField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel3)
.add(sumField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel4)
.add(nameField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel5)
.add(limitTimeComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel6)
.add(autoComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(21, 21, 21)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(cancelButton)
.add(resetButton)
.add(confirmButton))
.addContainerGap(45, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
//提交響應事件代碼
private void confirmButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_confirmButtonActionPerformed
// TODO 將在此處添加您的處理代碼:
String accountID = " "+accountField.getText();
String name = nameField.getText();
int sum = Integer.parseInt(sumField.getText());
String auto = (String)autoComboBox.getSelectedItem();
int limitTime = Integer.parseInt((limitTimeComboBox.getSelectedItem()).toString());
CallableStatement proc = null;
try
{
String sql = "select * from deAccount where accountID = '"+accountID+"' and accountType='TE'";
// String sql = "select * from deAccount where state='EF' and accountID = '"+accountID+"' and accountType='TE'";
Statement stat = fixedDeposit.createStatement();
ResultSet result = stat.executeQuery(sql);
if(!result.next())
{
JOptionPane.showMessageDialog(null,"您輸入的定期帳號不存在,請確認后重新輸入!","出錯",JOptionPane.ERROR_MESSAGE);
accountField.setText("");
}
else
{
String sql1 = "select * from deAccount where state='EF' and accountID = '"+accountID+"' and accountType='TE'";
ResultSet result1 = stat.executeQuery(sql1);
if(!result1.next())
{
JOptionPane.showMessageDialog(null,"您輸入的帳號被掛失了,請確認后重新輸入!","出錯",JOptionPane.ERROR_MESSAGE);
accountField.setText("");
}
else
{
proc = fixedDeposit.prepareCall("{ call InsertFixedDeposit(?,?,?,?,?,?) }");
proc.setString(1, staffID);
proc.setString(2, accountID);
proc.setString(3, name);
proc.setInt(4, sum);
proc.setString(5, auto);
proc.setInt(6, limitTime);
proc.execute();
this.dispose();
proc.close();
fixedDeposit.close();
}
}
}
catch(Exception insertAccountException)
{
insertAccountException.printStackTrace();
}
}//GEN-LAST:event_confirmButtonActionPerformed
//重置按鈕響應事件代碼
private void resetButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resetButtonActionPerformed
// TODO 將在此處添加您的處理代碼:
accountField.setText("");
nameField.setText("");
sumField.setText("");
autoComboBox.setSelectedIndex(0);
limitTimeComboBox.setSelectedIndex(0);
}//GEN-LAST:event_resetButtonActionPerformed
//取消按鈕響應事件代碼
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
// TODO 將在此處添加您的處理代碼:
this.dispose();
try
{
fixedDeposit.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}//GEN-LAST:event_cancelButtonActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new FixedDeposit(" 00001").setVisible(true);
}
});
}
//連接數據庫操作------------------------------
private void connectDB()
{
String dbUrl = "jdbc:odbc:afei";
String user = "scott";
String password = "tiger";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
fixedDeposit = DriverManager.getConnection(dbUrl,user,password);
}
catch(Exception connectException)
{
connectException.printStackTrace();
}
}
// 變量聲明 - 不進行修改//GEN-BEGIN:variables
private javax.swing.JTextField accountField;
private javax.swing.JComboBox autoComboBox;
private javax.swing.JButton cancelButton;
private javax.swing.JButton confirmButton;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JComboBox limitTimeComboBox;
private javax.swing.JTextField nameField;
private javax.swing.JButton resetButton;
private javax.swing.JTextField sumField;
// 變量聲明結束//GEN-END:variables
private Connection fixedDeposit;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -