?? collegeinfopanel.java~11~
字號:
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;
import javax.swing.JTextArea;
public class CollegeInfoPanel extends InfoPanel {
public CollegeInfoPanel(boolean e){
try {
initialize(e);//初始化父類
} catch (Exception ex) {
}
}
protected void initialize(boolean e){
try {
super.initialize(e);
} catch (Exception ex) {
}
jLabel1.setText("學院名");
jTextField_coname.setText("jTextField1");
jLabel2.setText("學院編號");
jTextField_college_no.setText("jTextField2");
jLabel4.setText("聯系電話");
jTextField_phone.setText("jTextField3");
jLabel6.setText("院長");
jLabel3.setText("簡介");
jTextArea_introduction.setText("jTextArea1");
this.add(jLabel1, new XYConstraints(56, 45, 82, 38));
this.add(jTextField_coname, new XYConstraints(128, 53, 95, 29));
this.add(jLabel2, new XYConstraints(297, 51, 80, 31));
this.add(jTextField_college_no, new XYConstraints(427, 52, 96, 30));
this.add(jLabel6, new XYConstraints(56, 112, 71, 37));
this.add(jComboBox_tname, new XYConstraints(128, 113, 163, 32));
this.add(jLabel4, new XYConstraints(54, 169, 67, 33));
this.add(jTextField_phone, new XYConstraints(128, 167, 180, 32));
this.add(jLabel3, new XYConstraints(54, 213, 58, 31));
this.add(jTextArea_introduction, new XYConstraints(126, 221, 396, 108));
}
public void setSwingEnable(boolean e) {
jTextField_coname.setEnabled(e);
jTextField_college_no.setEnabled(e);
jTextField_phone.setEnabled(e);
jComboBox_tname.setEnabled(e);
jTextArea_introduction.setEditable(e);
}
public boolean delete() {
return SQLRunner.executSql("delete from college where college_no='"+keyValue+"'");
}
public boolean update() {
try{
String teacher_no;
if(jComboBox_tname.getSelectedItem()==null){
JOptionPane.showMessageDialog(null,"學院不能為空","系統提示",JOptionPane.ERROR_MESSAGE);
return false;
}else{
String tname=(String)(jComboBox_tname.getSelectedItem());
ResultSet rs=SQLRunner.getResult("select * from teacher where tname='"+tname+"'");
if(!rs.next())return false;//System.out.println("can't find clname");
teacher_no=rs.getString("teacher_no").trim();//不該不抱錯
}
String coname= jTextField_coname.getText().trim();
String college_no=jTextField_college_no.getText().trim();
String phone=jTextField_phone.getText().trim();
String introduction=jTextArea_introduction.getText().trim();
String updatesql="update college set PRESIDENT='"+teacher_no+"',phone='"+phone+"',coname='"+coname+"',INTRODUCTON='"+introduction+"' where college_no='"+college_no+"'";
return SQLRunner.executSql(updatesql);
}catch(Exception e){
JOptionPane.showMessageDialog(null,e.toString(),"系統提示",JOptionPane.ERROR_MESSAGE);
return false;
}
}
public void setAllInfo(String keyValue) {
updateModel=true;//
this.keyValue=keyValue;//
try {
//rs.next();
ResultSet rs=SQLRunner.getResult("select * from department where depart_no='"+keyValue+"'");
if(!rs.next())return;
addItem(jComboBox_tname,"select tname from teacher,college where teacher.college_no='"+keyValue+"' group by tname","tname");
String tname;
ResultSet rpt=SQLRunner.getResult("select * from teacher,college where teacher.teacher_no=college.PRESIDENT and college.college_no='"+keyValue+"'");
if(rpt.next()){
jComboBox_tname.setSelectedItem(rpt.getString("tname"));
}else{
jComboBox_tname.setSelectedItem(null);
}
jComboBox_tname.setSelectedItem("");
jTextField_phone.setText(rs.getString("phone"));
jTextField_college_no.setText(rs.getString("college_no"));
jTextField_coname.setText(rs.getString("coname").trim());
jTextArea_introduction.setText(rs.getString("INTRODUCTON"));
} catch (SQLException ex) {
System.out.print(ex.toString());
}
}
public void setAllNew() {
jTextField_coname.setText("");
jTextField_college_no.setText("");
jTextField_phone.setText("");
jComboBox_tname.removeAllItems();
jTextArea_introduction.setText("");
}
JLabel jLabel1 = new JLabel();
JTextField jTextField_coname = new JTextField();
JLabel jLabel2 = new JLabel();
JTextField jTextField_college_no = new JTextField();
JLabel jLabel4 = new JLabel();
JTextField jTextField_phone = new JTextField();
JLabel jLabel6 = new JLabel();
JComboBox jComboBox_tname = new JComboBox();
JLabel jLabel3 = new JLabel();
JTextArea jTextArea_introduction = new JTextArea();
public boolean insert() {
try{
String teacher_no;
if(jComboBox_tname.getSelectedItem()==null){
JOptionPane.showMessageDialog(null,"學院不能為空","系統提示",JOptionPane.ERROR_MESSAGE);
return false;
}else{
String tname=(String)(jComboBox_tname.getSelectedItem());
ResultSet rs=SQLRunner.getResult("select * from teacher where tname='"+tname+"'");
if(!rs.next())return false;//System.out.println("can't find clname");
teacher_no=rs.getString("teacher_no").trim();//不該不抱錯
}
String coname= jTextField_coname.getText().trim();
String college_no=jTextField_college_no.getText().trim();
String phone=jTextField_phone.getText().trim();
String introduction=jTextArea_introduction.getText().trim();
String insertsql="insert into college(college_no,coname,PRESIDENT,phone,INTRODUCTON) values('"+college_no+"','"+coname+"','"+teacher_no+"','"+phone+"','"+introduction+"')";
return SQLRunner.executSql(insertsql);
}catch(Exception e){
JOptionPane.showMessageDialog(null,e.toString(),"系統提示",JOptionPane.ERROR_MESSAGE);
return false;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -