?? departmentinfopanel.java~22~
字號(hào):
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 DepartmentInfoPanel extends InfoPanel {
public DepartmentInfoPanel(boolean e){
try {
initialize(e);//初始化父類(lèi)
} catch (Exception ex) {
}
}
protected void initialize(boolean e){
try {
super.initialize(e);
} catch (Exception ex) {
}
jLabel1.setText("系名");
jTextField_dpname.setText("jTextField1");
jLabel2.setText("系編號(hào)");
jTextField_depart_no.setText("jTextField2");
jLabel4.setText("聯(lián)系電話");
jTextField_phone.setText("jTextField3");
jLabel6.setToolTipText("");
jLabel6.setText("系主任");
jLabel3.setText("簡(jiǎn)介");
jTextArea_introduction.setText("jTextArea1");
jLabel5.setText("學(xué)院");
this.add(jLabel1, new XYConstraints(56, 45, 82, 38));
this.add(jTextField_dpname, new XYConstraints(128, 53, 95, 29));
this.add(jTextField_depart_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));
this.add(jLabel2, new XYConstraints(318, 52, 80, 31));
this.add(jLabel5, new XYConstraints(316, 112, 56, 31));
this.add(jComboBox_coname, new XYConstraints(364, 112, 208, 35));
}
public void setSwingEnable(boolean e) {
jTextField_dpname.setEnabled(e);
jTextField_depart_no.setEnabled(e);
jTextField_phone.setEnabled(e);
jComboBox_tname.setEnabled(e);
jTextArea_introduction.setEditable(e);
}
public boolean delete() {
return SQLRunner.executSql("delete from department where depart_no='"+keyValue+"'");
}
public boolean update() {
try{
String teacher_no;
if(jComboBox_tname.getSelectedItem()==null){
JOptionPane.showMessageDialog(null,"學(xué)院不能為空","系統(tǒng)提示",JOptionPane.ERROR_MESSAGE);
return false;
}else{
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();//不該不抱錯(cuò)
}
String coname= jTextField_dpname.getText().trim();
String depart_no= jTextField_depart_no.getText().trim();
String phone=jTextField_phone.getText().trim();
String introduction=jTextArea_introduction.getText().trim();
String updatesql="update department set DEPART_HEADER='"+teacher_no+"',dphone='"+phone+"',dpname='"+coname+"',INRTODUCTION='"+introduction+"' where depart_no='"+depart_no+"'";
return SQLRunner.executSql(updatesql);
}catch(Exception e){
JOptionPane.showMessageDialog(null,e.toString(),"系統(tǒng)提示",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,college where department.college_no=college.college_no and depart_no='"+keyValue+"'");
if(!rs.next())return;
addItem(jComboBox_coname,"select * from college","coname");//addItem示例,從制定表
jComboBox_coname.setSelectedItem(rs.getString("coname"));//
addItem(jComboBox_tname,"select distinct tname from teacher,department where department.college_no=teacher.college_no and depart_no='"+keyValue+"'","tname");
jTextField_phone.setText(rs.getString("dphone"));
jTextField_depart_no.setText(rs.getString("depart_no"));
jTextField_dpname.setText(rs.getString("dpname").trim());
jTextArea_introduction.setText(rs.getString("INRTODUCTION"));
ResultSet rss=SQLRunner.getResult("select * from college where college_no='"+rs.getString("depart_no")+"'");
ResultSet rpt=SQLRunner.getResult("select distinct * from teacher,department where teacher.teacher_no=department.DEPART_HEADER and department.depart_no='"+keyValue+"'");
if(rpt.next()){
jComboBox_tname.setSelectedItem(rpt.getString("tname"));
}else{
jComboBox_tname.setSelectedItem(null);
}
if(!rss.next())return;
//jLabel_coname.setText(rss.getString("coname"));
} catch (SQLException ex) {
System.out.print(ex.toString());
}
}
public void setAllNew() {
jTextField_dpname.setText("");
jTextField_depart_no.setText("");
jTextField_phone.setText("");
jComboBox_tname.setSelectedItem(null);
jTextArea_introduction.setText("");
addItem(jComboBox_coname,"select * from college","coname");
jComboBox_coname.setSelectedItem(null);
}
JLabel jLabel1 = new JLabel();
JTextField jTextField_dpname = new JTextField();
JLabel jLabel2 = new JLabel();
JTextField jTextField_depart_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();
JLabel jLabel5 = new JLabel();
JComboBox jComboBox_coname = new JComboBox();
public boolean insert() {
try{
String teacher_no;
if(jComboBox_tname.getSelectedItem()==null){
JOptionPane.showMessageDialog(null,"學(xué)院不能為空","系統(tǒng)提示",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();//不該不抱錯(cuò)
}
String depart_no= jTextField_depart_no.getText().trim();
String dpname= jTextField_dpname.getText().trim();
//String college_no= jTextField_depart_no.getText().trim();
//ResultSet ras=SQLRunner.getResult("select * from ")
String phone=jTextField_phone.getText().trim();
String introduction=jTextArea_introduction.getText().trim();
String insertsql="insert into department(college_no,dpname,DEPART_HEADER,dphone,INRTODUCTION,depart_no) values('"+college_no+"','"+dpname+"','"+teacher_no+"','"+phone+"','"+introduction+"','"+depart_no+"')";
return SQLRunner.executSql(insertsql);
}catch(Exception e){
JOptionPane.showMessageDialog(null,e.toString(),"系統(tǒng)提示",JOptionPane.ERROR_MESSAGE);
return false;
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -