?? teacherinfopanel.java
字號:
package StudentManageSystem.factionpanels.infopanel;
import com.borland.jbcl.layout.XYConstraints;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import StudentManageSystem.link.SQLRunner;
import java.sql.ResultSet;
import javax.swing.JOptionPane;
import java.sql.SQLException;
public class TeacherInfoPanel extends InfoPanel {
public TeacherInfoPanel(boolean e){
try {
initialize(e);//初始化父類
} catch (Exception ex) {
}
}
protected void initialize(boolean e){
try {
super.initialize(e);
} catch (Exception ex) {
}
jLabel1.setText("姓名");
jTextField_tname.setText("jTextField1");
jLabel2.setText("職工號");
jTextField_teacher_no.setText("jTextField2");
jLabel3.setText("性別");
jLabel4.setText("聯系電話");
jTextField_phone.setText("jTextField3");
jLabel5.setText("職稱");
jLabel6.setText("學院");
this.add(jLabel1, new XYConstraints(56, 45, 82, 38));
this.add(jTextField_tname, new XYConstraints(128, 53, 95, 29));
this.add(jLabel2, new XYConstraints(297, 51, 80, 31));
this.add(jTextField_teacher_no, new XYConstraints(427, 52, 96, 30));
this.add(jLabel3, new XYConstraints(56, 113, 60, 31));
this.add(jComboBox_sex, new XYConstraints(128, 115, 96, 31));
this.add(jLabel5, new XYConstraints(297, 113, 65, 34));
this.add(jLabel6, new XYConstraints(57, 176, 71, 37));
this.add(jComboBox_coname, new XYConstraints(128, 181, 163, 32));
this.add(jLabel4, new XYConstraints(56, 241, 67, 33));
this.add(jTextField_phone, new XYConstraints(128, 243, 180, 32));
this.add(jComboBox_post, new XYConstraints(427, 116, 145, 32));
}
public void setSwingEnable(boolean e) {
jTextField_tname.setEnabled(e);
jTextField_teacher_no.setEnabled(e);
jComboBox_sex.setEnabled(e);
jTextField_phone.setEnabled(e);
jComboBox_post.setEnabled(e);
jComboBox_coname.setEnabled(e);
}
public boolean delete() {
return SQLRunner.executSql("delete from teacher where teacher_no='"+keyValue+"'");
}
public boolean update() {
try{
String college_no;
if(jComboBox_coname.getSelectedItem()==null){
JOptionPane.showMessageDialog(null,"學院不能為空","系統提示",JOptionPane.ERROR_MESSAGE);
return false;
}else{
String coname=(String)(jComboBox_coname.getSelectedItem());
ResultSet rs=SQLRunner.getResult("select * from college where coname='"+coname+"'");
if(!rs.next())return false;//System.out.println("can't find clname");
college_no=rs.getString("college_no").trim();//不該不抱錯
}
String tname= jTextField_tname.getText().trim();
String teacher_no=jTextField_teacher_no.getText().trim();
String phone=jTextField_phone.getText().trim();
String sex;
if(jComboBox_sex.getSelectedItem()==null){
JOptionPane.showMessageDialog(null,"性別不能為空","系統提示",JOptionPane.ERROR_MESSAGE);
return false;
}else{
sex=((String)jComboBox_sex.getSelectedItem()).trim();
}String post;
if(jComboBox_post.getSelectedItem()==null){
post="";
}else{
post=((String)jComboBox_post.getSelectedItem()).trim();
}String updatesql="update teacher set college_no='"+college_no+"',post='"+post+"',sex='"+sex+"',phone='"+phone+"',tname='"+tname+"' where teacher_no='"+teacher_no+"'";
return SQLRunner.executSql(updatesql);
}catch(Exception e){
JOptionPane.showMessageDialog(null,e.toString(),"系統提示",JOptionPane.ERROR_MESSAGE);
return false;
}
}
public boolean insert() {
try{
String college_no;
if(jComboBox_coname.getSelectedItem()==null){
JOptionPane.showMessageDialog(null,"學院不能為空","系統提示",JOptionPane.ERROR_MESSAGE);
return false;
}else{
String coname=(String)(jComboBox_coname.getSelectedItem());
ResultSet rs=SQLRunner.getResult("select * from college where coname='"+coname+"'");
if(!rs.next())return false;//System.out.println("can't find clname");
college_no=rs.getString("college_no").trim();//不該不抱錯
}
String tname= jTextField_tname.getText().trim();
String teacher_no=jTextField_teacher_no.getText().trim();
String phone=jTextField_phone.getText().trim();
String sex;
if(jComboBox_sex.getSelectedItem()==null){
JOptionPane.showMessageDialog(null,"性別不能為空","系統提示",JOptionPane.ERROR_MESSAGE);
return false;
}else{
sex=((String)jComboBox_sex.getSelectedItem()).trim();
}String post;
if(jComboBox_post.getSelectedItem()==null){
post="";
}else{
post=((String)jComboBox_post.getSelectedItem()).trim();
}String insertsql="insert into teacher(teacher_no,tname,sex,phone,post,college_no) values('"+teacher_no+"','"+tname+"','"+sex+"','"+phone+"','"+post+"','"+college_no+"')";
return SQLRunner.executSql(insertsql);
}catch(Exception e){
JOptionPane.showMessageDialog(null,e.toString(),"系統提示",JOptionPane.ERROR_MESSAGE);
return false;
}
}
public void setAllInfo(String keyValue) {
updateModel=true;//
this.keyValue=keyValue;//
jButton_remove.setVisible(enable);
try {
//rs.next();
ResultSet rs=SQLRunner.getResult("select * from teacher,college where teacher.college_no=college.college_no and teacher_no='"+keyValue+"'");
if(!rs.next())return;
addItemFromDic(jComboBox_sex,"sex");//從字典加
jComboBox_sex.setSelectedItem(rs.getString("sex"));
addItemFromDic(jComboBox_post,"post");
jComboBox_post.setSelectedItem(rs.getString("post"));
addItem(jComboBox_coname,"select * from college","coname");//addItem示例,從制定表
jComboBox_coname.setSelectedItem(rs.getString("coname"));//
jTextField_phone.setText(rs.getString("phone"));
jTextField_teacher_no.setText(rs.getString("teacher_no"));
jTextField_tname.setText(rs.getString("tname"));
} catch (SQLException ex) {
System.out.print(ex.toString());
}
}
public void setAllNew() {
jButton_remove.setVisible(false);
addItem(jComboBox_coname,"select * from college","coname");
addItemFromDic(jComboBox_post,"post");
addItemFromDic(jComboBox_sex,"sex");
jComboBox_coname.setSelectedItem(null);
jComboBox_post.setSelectedItem(null);
jComboBox_sex.setSelectedItem(null);
jTextField_tname.setText("");
jTextField_teacher_no.setText("");
jTextField_phone.setText("");
}
JLabel jLabel1 = new JLabel();
JTextField jTextField_tname = new JTextField();
JLabel jLabel2 = new JLabel();
JTextField jTextField_teacher_no = new JTextField();
JLabel jLabel3 = new JLabel();
JComboBox jComboBox_sex = new JComboBox();
JLabel jLabel4 = new JLabel();
JTextField jTextField_phone = new JTextField();
JLabel jLabel5 = new JLabel();
JComboBox jComboBox_post = new JComboBox();
JLabel jLabel6 = new JLabel();
JComboBox jComboBox_coname = new JComboBox();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -