?? pmainmenu.java
字號:
public void jComboBox2_actionPerformed(ActionEvent e) {
this.getTime();
this.txtDate.setEditable(false);
if(this.jComboBox2.getSelectedItem().equals("修改")){
txtName.setEnabled(false);
this.txtSex.setEnabled(false);
this.txtAge.setEnabled(false);
}
if(this.jComboBox2.getSelectedItem().equals("增加")){
this.txtAge.setEnabled(true);
this.txtDate.setEnabled(false);
this.txtId.setEnabled(false);
this.txtName.setEnabled(true);
this.txtAdd.setEnabled(true);
this.txtPhone.setEnabled(true);
this.txtSex.setEnabled(true);
}
}
public void jComboBox2_mouseClicked(MouseEvent e) {
}
//jTable2單擊事件
public void jTable2_mouseClicked(MouseEvent e) {
jTable2.setSelectionBackground(Color.green );
String id = null; // 編號
String name = null; //姓名
String sex = null; //性別
String age = null; //年齡
String duty = null; //職務
String phone = null; //電話
String add = null; //地址
String stat = null; //狀態
String time = null; //時間
id = this.jTable2.getValueAt(this.jTable2.getSelectedRow(), 0).toString();
name = this.jTable2.getValueAt(this.jTable2.getSelectedRow(), 1).toString();
sex = this.jTable2.getValueAt(this.jTable2.getSelectedRow(), 2).toString();
age = this.jTable2.getValueAt(this.jTable2.getSelectedRow(), 3).toString();
duty = this.jTable2.getValueAt(this.jTable2.getSelectedRow(), 4).toString();
phone = this.jTable2.getValueAt(this.jTable2.getSelectedRow(), 5).toString();
add = this.jTable2.getValueAt(this.jTable2.getSelectedRow(), 6).toString();
stat = this.jTable2.getValueAt(this.jTable2.getSelectedRow(), 7).toString();
time = this.jTable2.getValueAt(this.jTable2.getSelectedRow(), 8).toString();
this.txtId.setText(id);
this.txtName.setText(name);
this.txtDate.setText(time);
this.txtSex.setText(sex);
this.txtAge.setText(age);
this.txtPhone.setText(phone);
this.txtAdd.setText(add);
}
/**
* 刪除按鈕點擊事件
* @param e ActionEvent
* @throws SQLException
*/
public void jButton11_actionPerformed(ActionEvent e) throws SQLException {
SPerControl sp = new SPerControl();
if(this.jComboBox1.getSelectedItem().equals("編號")){
String id = txtTiao.getText(); //獲得選擇的編號
if (id.equals("")) {
JOptionPane.showMessageDialog(this, "請輸入該條件的文本值");
return;
}
int arraylist = sp.amend1(id);
if (arraylist == 0) {
JOptionPane.showMessageDialog(this, "沒有此編號");
} else {
JOptionPane.showMessageDialog(this, "刪除成功");
this.jbInit1();
}
}
if(this.jComboBox1.getSelectedItem().equals("姓名")){
String name = txtTiao.getText(); //獲得姓名
if (name.equals("")) {
JOptionPane.showMessageDialog(this, "請輸入該條件的文本值");
return;
}
int arraylist = sp.amend2(name);
if (arraylist == 0) {
JOptionPane.showMessageDialog(this, "沒有此姓名");
} else {
JOptionPane.showMessageDialog(this, "刪除成功");
this.jbInit1();
}
}
if(this.jComboBox1.getSelectedItem().equals("性別")){
String sex = txtTiao.getText(); //獲得性別
if(sex.equals("")){
JOptionPane.showMessageDialog(this,"請輸入該條件的文本值");
return;
}
if(!(sex.equals("女"))&&!(sex.equals("男"))){
JOptionPane.showMessageDialog(this, "性別輸入不對");
return;
}
int arraylist = sp.amend3(sex);
if (arraylist == 0) {
JOptionPane.showMessageDialog(this, "沒有此性別");
} else {
JOptionPane.showMessageDialog(this, "刪除成功");
this.jbInit1();
}
}
if(this.jComboBox1.getSelectedItem().equals("年齡")){
String age = txtTiao.getText();
if(age.equals("")){
JOptionPane.showMessageDialog(this,"請輸入該條件的文本值");
return;
}
try {
Integer.parseInt(txtTiao.getText());
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, "年齡必須為整數");
return;
}
if((Integer.parseInt(age)<18)||(Integer.parseInt(age)>60)){
JOptionPane.showMessageDialog(this, "沒有此段年齡的人員");
return;
}
int arraylist = sp.amend4(age);
if (arraylist == 0) {
JOptionPane.showMessageDialog(this, "沒有此年齡的人員");
} else {
JOptionPane.showMessageDialog(this, "刪除成功");
this.jbInit1();
}
}
if(this.jComboBox1.getSelectedItem().equals("地址")){
String add = txtTiao.getText();
if(add.equals("")){
JOptionPane.showMessageDialog(this,"請輸入該條件的文本值");
return;
}
int arraylist = sp.amend5(add);
if (arraylist == 0) {
JOptionPane.showMessageDialog(this, "沒有此地址的人員");
} else {
JOptionPane.showMessageDialog(this, "刪除成功");
this.jbInit1();
}
}
if(this.jComboBox1.getSelectedItem().equals("職務")){
String stat = txtTiao.getText();
if(stat.equals("")){
JOptionPane.showMessageDialog(this,"請輸入該條件的文本值");
return;
}
if(!(stat.equals("經理"))&&!(stat.equals("主管"))&&!(stat.equals("職員"))){
JOptionPane.showMessageDialog(this,"沒有此職務的人員");
return;
}
int arraylist = sp.amend6(stat);
if (arraylist == 0) {
JOptionPane.showMessageDialog(this, "沒有此職務的人員");
} else {
JOptionPane.showMessageDialog(this, "刪除成功");
this.jbInit1();
}
}
if(this.jComboBox1.getSelectedItem().equals("電話")){
String phone = txtTiao.getText();
if(phone.equals("")){
JOptionPane.showMessageDialog(this,"請輸入該條件的文本值");
return;
}
try {
Float.parseFloat(txtTiao.getText());
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, "電話號碼必須為整數字的");
return;
}
if(!(phone.length() == 11)){
JOptionPane.showMessageDialog(this, "電話號碼必須為11位正數字");
return;
}
float num1;
float num2;
num1 = Float.parseFloat(phone.substring(0,2));
num2 = Float.parseFloat(phone.substring(0,3));
if(!(num1 == 13)&&!(num2 == 159)){
JOptionPane.showMessageDialog(this, "電話號碼輸入有誤");
return;
}
int arraylist = sp.amend7(phone);
if (arraylist == 0) {
JOptionPane.showMessageDialog(this, "沒有此電話的人員");
} else {
JOptionPane.showMessageDialog(this, "刪除成功");
this.jbInit1();
}
}
}
/**
* 查詢按鈕點擊事件
* @param e ActionEvent
* @throws SQLException
*/
public void jButton12_actionPerformed(ActionEvent e) throws SQLException {
SPerControl sp = new SPerControl();
if(this.jComboBox1.getSelectedItem().equals("編號")){
String id = txtTiao.getText();
if(id.equals("")){
JOptionPane.showMessageDialog(this,"請輸入該條件的文本值");
return;
}
Vector ve = sp.query1(id);
if(ve.size() == 0){
JOptionPane.showConfirmDialog(this,"沒有此編號");
return;
}
SPerTitle spe = new SPerTitle();
Vector vec = spe.titleName();
JTable jTable2 = new JTable(ve,vec);
jScrollPane2.getViewport().add(jTable2);
jTable2.addMouseListener(new PMainMenu_jTable2_mouseAdapter(this));
}
if(this.jComboBox1.getSelectedItem().equals("姓名")){
String name = txtTiao.getText();
if(name.equals("")){
JOptionPane.showMessageDialog(this,"請輸入該條件的文本值");
return;
}
Vector ve = sp.query2(name);
if (ve.size() == 0) {
JOptionPane.showConfirmDialog(this, "沒有此姓名的人員");
return;
}
SPerTitle spe = new SPerTitle();
Vector vec = spe.titleName();
JTable jTable2 = new JTable(ve, vec);
jScrollPane2.getViewport().add(jTable2);
jTable2.addMouseListener(new PMainMenu_jTable2_mouseAdapter(this));
}
if(this.jComboBox1.getSelectedItem().equals("性別")){
String sex = txtTiao.getText();
if (sex.equals("")) {
JOptionPane.showMessageDialog(this, "請輸入該條件的文本值");
return;
}
if(!(sex.equals("女"))&&!(sex.equals("男"))){
JOptionPane.showMessageDialog(this, "性別輸入不對");
return;
}
Vector ve = sp.query3(sex);
if (ve.size() == 0) {
JOptionPane.showConfirmDialog(this, "沒有此性別");
return;
}
SPerTitle spe = new SPerTitle();
Vector vec = spe.titleName();
JTable jTable2 = new JTable(ve, vec);
jScrollPane2.getViewport().add(jTable2);
jTable2.addMouseListener(new PMainMenu_jTable2_mouseAdapter(this));
}
if(this.jComboBox1.getSelectedItem().equals("年齡")){
String age = txtTiao.getText();
if(age.equals("")){
JOptionPane.showMessageDialog(this,"請輸入該條件的文本值");
return;
}
try {
Integer.parseInt(txtTiao.getText());
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, "年齡必須為整數");
return;
}
if((Integer.parseInt(age)<18)||(Integer.parseInt(age)>60)){
JOptionPane.showMessageDialog(this, "沒有此段年齡的人員");
return;
}
Vector ve = sp.query4(age);
if (ve.size() == 0) {
JOptionPane.showConfirmDialog(this, "沒有此年齡的人員");
return;
}
SPerTitle spe = new SPerTitle();
Vector vec = spe.titleName();
JTable jTable2 = new JTable(ve, vec);
jScrollPane2.getViewport().add(jTable2);
jTable2.addMouseListener(new PMainMenu_jTable2_mouseAdapter(this));
}
if(this.jComboBox1.getSelectedItem().equals("地址")){
String add = txtTiao.getText();
if (add.equals("")) {
JOptionPane.showMessageDialog(this, "請輸入該條件的文本值");
return;
}
Vector ve = sp.query5(add);
if (ve.size() == 0) {
JOptionPane.showConfirmDialog(this, "沒有此地址的人員");
return;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -