?? courseinfopanel.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;
import javax.swing.JTextArea;
public class CourseInfoPanel extends InfoPanel {
public CourseInfoPanel(boolean e){
try {
initialize(e);//初始化父類
} catch (Exception ex) {
}
}
protected void initialize(boolean e){
try {
super.initialize(e);
} catch (Exception ex) {
}
jLabel1.setText("課程名");
jTextField_csname.setText("jTextField1");
jLabel2.setText("課程編號");
jTextField_course_no.setText("jTextField2");
jLabel4.setText("學分");
jTextField_credit.setText("jTextField3");
jLabel6.setToolTipText("");
jLabel6.setText("課程類別");
jTextArea_introduction.setText("jTextArea1");
jLabel5.setText("學院");
this.add(jLabel1, new XYConstraints(56, 45, 82, 38));
this.add(jTextField_csname, new XYConstraints(128, 53, 95, 29));
this.add(jTextField_course_no, new XYConstraints(427, 52, 96, 30));
this.add(jLabel6, new XYConstraints(56, 112, 71, 37));
this.add(jComboBox_cskind, new XYConstraints(128, 113, 163, 32));
this.add(jLabel4, new XYConstraints(54, 169, 67, 33));
this.add(jTextField_credit, 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_csname.setEnabled(e);
jTextField_course_no.setEnabled(e);
jTextField_credit.setEnabled(e);
jComboBox_cskind.setEnabled(e);
jComboBox_coname.setEnabled(e);
jTextArea_introduction.setEditable(e);
}
public boolean delete() {
return SQLRunner.executSql("delete from course where COURSE_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 cskind;
if(jComboBox_cskind.getSelectedItem()!=null)cskind=(String)jComboBox_cskind.getSelectedItem();
else{
JOptionPane.showMessageDialog(null,"類別不能為空","系統提示",JOptionPane.ERROR_MESSAGE);
return false;
}
String csname= jTextField_csname.getText().trim();
String course_no= jTextField_course_no.getText().trim();
String credit= jTextField_credit.getText().trim();
if(credit.equals(""))credit="null";
String introduction=jTextArea_introduction.getText().trim();
String updatesql="update course set cskind='"+cskind+"',credit="+credit+",college_no='"+college_no+"',csname='"+csname+"',INTRODUCTION='"+introduction+"' where COURSE_NO='"+course_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;//
jButton_remove.setVisible(enable);
try {
//rs.next();
ResultSet rs=SQLRunner.getResult("select distinct * from course,college where course.college_no=college.college_no and course_no='"+keyValue+"'");
if(!rs.next())return;
addItemFromDic(jComboBox_cskind,"course_kind");
jComboBox_cskind.setSelectedItem(rs.getString("cskind"));
//addItem(jComboBox_coname,"select * from college","coname");
//jComboBox_cskind.setSelectedItem(rs.getString("coname"));
addItem(jComboBox_coname,"select * from college","coname");//addItem示例,從制定表
jComboBox_coname.setSelectedItem(rs.getString("coname"));//
jTextField_csname.setText(rs.getString("csname"));
jTextField_course_no.setText(rs.getString("course_no"));
jTextField_credit.setText(rs.getString("credit"));
jTextArea_introduction.setText(rs.getString("INTRODUCTION"));
} catch (SQLException ex) {
System.out.print(ex.toString());
}
}
public void setAllNew() {
jButton_remove.setVisible(false);
jTextField_csname.setText("");
jTextField_course_no.setText("");
jTextField_credit.setText("");
addItemFromDic(jComboBox_cskind,"course_kind");
jComboBox_cskind.setSelectedItem(null);
jTextArea_introduction.setText("");
addItem(jComboBox_coname,"select * from college","coname");
jComboBox_coname.setSelectedItem(null);
}
JLabel jLabel1 = new JLabel();
JTextField jTextField_csname = new JTextField();
JLabel jLabel2 = new JLabel();
JTextField jTextField_course_no = new JTextField();
JLabel jLabel4 = new JLabel();
JTextField jTextField_credit = new JTextField();
JLabel jLabel6 = new JLabel();
JComboBox jComboBox_cskind = 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 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 cskind;
if(jComboBox_cskind.getSelectedItem()!=null)cskind=(String)jComboBox_cskind.getSelectedItem();
else{
JOptionPane.showMessageDialog(null,"類別不能為空","系統提示",JOptionPane.ERROR_MESSAGE);
return false;
}
String csname= jTextField_csname.getText().trim();
String course_no= jTextField_course_no.getText().trim();
String credit= jTextField_credit.getText().trim();
if(credit.equals(""))credit="null";
String introduction=jTextArea_introduction.getText().trim();
//String insertsql="update department set cskind='"+cskind+"',credit="+credit+"',college_no="+college_no+",csname='"+csname+"',INRTODUCTION='"+introduction+"' where course_no='"+course_no+"'";
//String insertsql="insert into college(college_no,coname,PRESIDENT,phone,INTRODUCTON) values('"+college_no+"','"+coname+"','"+teacher_no+"','"+phone+"','"+introduction+"')";
String insertsql="insert into course(college_no,csname,cskind,credit,INTRODUCTION,COURSE_NO) values('"+college_no+"','"+csname+"','"+cskind+"',"+credit+",'"+introduction+"','"+course_no+"')";
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 + -