?? studentinfopanel.java
字號:
package StudentManageSystem.factionpanels.infopanel;
import javax.swing.JFormattedTextField;
import javax.swing.JComboBox;
import javax.swing.JTextField;
import javax.swing.JLabel;
import com.borland.jbcl.layout.XYConstraints;
import StudentManageSystem.link.SQLRunner;
import java.sql.ResultSet;
import javax.swing.JOptionPane;
import java.sql.SQLException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Calendar;
import javax.swing.text.DateFormatter;
import java.text.SimpleDateFormat;
import java.text.DateFormat;
//import java.sql.Date;
import java.util.Date;
import java.util.StringTokenizer;
import java.util.GregorianCalendar;
public class StudentInfoPanel extends InfoPanel {
JLabel jLabel_name = new JLabel();
JLabel jLabel_nation = new JLabel();
JLabel jLabel_source = new JLabel();
JLabel jLabel_home_phone = new JLabel();
JLabel jLabel_stu_no = new JLabel();
JLabel jLabel_birthday = new JLabel();
JLabel jLabel_score = new JLabel();
JLabel jLabel_address = new JLabel();
JLabel jLabel_sex = new JLabel();
JLabel jLabel_polity = new JLabel();
JLabel jLabel_college = new JLabel();
JLabel jLabel13 = new JLabel();
JLabel jLabel14 = new JLabel();
JLabel jLabel11 = new JLabel();
JLabel jLabel15 = new JLabel();
JTextField jTextField_name = new JTextField();
JTextField jTextField_stu_no = new JTextField();
JComboBox jComboBox_sex = new JComboBox();
JComboBox jComboBox_nation = new JComboBox();
DateFormat format=new SimpleDateFormat("yyyy-MM-dd");
DateFormatter df=new DateFormatter(format);
JFormattedTextField jFormattedTextField_birthday=new JFormattedTextField(df);
//JFormattedTextField jFormattedTextField_birthday = new JFormattedTextField(new AbstractFormatter());
JComboBox jComboBox_polity = new JComboBox();
JTextField jTextField_score = new JTextField();
JTextField jTextField_home_phone = new JTextField();
JComboBox jComboBox_source = new JComboBox();
JTextField jTextField_address = new JTextField();
JComboBox jComboBox_college = new JComboBox();
JComboBox jComboBox_department = new JComboBox();
JComboBox jComboBox_class = new JComboBox();
JComboBox jComboBox_Build_no = new JComboBox();
JComboBox jComboBox_apartment_no = new JComboBox();
public StudentInfoPanel(boolean e){
try {
initialize(e);//初始化父類
} catch (Exception ex) {
}
}
protected void initialize(boolean e){
try {
super.initialize(e);
jLabel_name.setText("姓名");
jLabel_nation.setText("民族");
jLabel_source.setText("學生來源");
jLabel_home_phone.setText("家庭聯系電話");
jLabel_stu_no.setText("學號");
jLabel_birthday.setText("出生日期");
jLabel_score.setText("入學成績");
jLabel_address.setText("家庭住址");
jLabel_sex.setText("性別");
jLabel_polity.setText("政治面貌");
jLabel_college.setText("學院");
jLabel13.setText("系");
jLabel14.setText("班");
jLabel11.setText("號樓");
jLabel15.setText("宿舍");
this.add(jLabel_birthday, new XYConstraints(38, 102, 97, 42));
this.add(jLabel_score, new XYConstraints(448, 106, 98, 35));
this.add(jLabel_address, new XYConstraints(38, 240, 97, 35));
this.add(jLabel_stu_no, new XYConstraints(183, 38, 36, 38));
this.add(jLabel_name, new XYConstraints(38, 38, 37, 39));
this.add(jLabel_nation, new XYConstraints(505, 40, 46, 36));
this.add(jLabel_source, new XYConstraints(38, 171, 73, 42));
this.add(jLabel_home_phone, new XYConstraints(259, 175, -1, 35));
this.add(jLabel_polity, new XYConstraints(253, 101, 58, 42));
this.add(jTextField_home_phone, new XYConstraints(354, 175, 185, 33));
this.add(jComboBox_source, new XYConstraints(128, 177, 102, 30));
this.add(jComboBox_polity, new XYConstraints(318, 105, 94, 31));
this.add(jComboBox_nation, new XYConstraints(552, 40, 100, 30));
this.add(jTextField_name, new XYConstraints(85, 39, 76, 31));
this.add(jTextField_stu_no, new XYConstraints(218, 40, 94, 30));
//jFormattedTextField_birthday.setValue(new Date());
this.add(jFormattedTextField_birthday, new XYConstraints(104, 107, 140, 32));
this.add(jTextField_score, new XYConstraints(530, 107, 89, 29));
this.add(jTextField_address, new XYConstraints(113, 242, 532, 32));
this.add(jLabel13, new XYConstraints(573, 302, 92, 36));
this.add(jLabel_college, new XYConstraints(274, 302, 103, 36));
this.add(jComboBox_class, new XYConstraints(23, 358, 224, 30));
this.add(jLabel14, new XYConstraints(276, 353, 89, 36));
this.add(jLabel11, new XYConstraints(423, 358, 86, 33));
this.add(jLabel15, new XYConstraints(579, 354, 86, 41));
this.add(jComboBox_college, new XYConstraints(24, 302, 238, 32));
this.add(jComboBox_department, new XYConstraints(386, 304, 175, 31));
this.add(jComboBox_Build_no, new XYConstraints(355, 358, 65, 32));
this.add(jComboBox_apartment_no, new XYConstraints(474, 358, 99, 32));
this.add(jComboBox_sex, new XYConstraints(395, 40, 59, 29));
this.add(jLabel_sex, new XYConstraints(345, 35, 51, 36));
} catch (Exception ex) {
}
jComboBox_college.addActionListener(new
MyStudentInfoPanel_jComboBox_college_actionAdapter(this));
jComboBox_department.addActionListener(new
MyStudentInfoPanel_jComboBox_department_actionAdapter(this));
jComboBox_Build_no.addActionListener(new
MyStudentInfoPanel_jComboBox_Build_no_actionAdapter(this));
}
public void setSwingEnable(boolean e) {//父類初始化調用
jTextField_home_phone.setEnabled(e);
jComboBox_source.setEnabled(e);
jComboBox_polity.setEnabled(e);
jComboBox_nation.setEnabled(e);
jTextField_name.setEnabled(e);
jTextField_stu_no.setEnabled(e);
jFormattedTextField_birthday.setEnabled(e);
jTextField_score.setEnabled(e);
jTextField_address.setEnabled(e);
jComboBox_class.setEnabled(e);
jComboBox_college.setEnabled(e);
jComboBox_department.setEnabled(e);
jComboBox_Build_no.setEnabled(e);
jComboBox_apartment_no.setEnabled(e);
jComboBox_sex.setEnabled(e);
}
public boolean delete() {//父類按鈕響應
try {
ResultSet rss=SQLRunner.getResult("select value from parameter where parametername='stu_delete_limit'");
rss.next();
int deleteLimitDays=rss.getInt("value");
ResultSet rs=SQLRunner.getResult("select * from studentinfo where stu_no='"+keyValue+"'");
if (!rs.next())return false;
String birthday=rs.getString("createdate");
Date d=new Date(Date.parse(birthday));
GregorianCalendar gc=new GregorianCalendar();
gc.setTime(d);
gc.toString();
Date now=new Date();
GregorianCalendar gcn=new GregorianCalendar();
gcn.setTime(now);
gcn.toString();
gc.add(GregorianCalendar.DATE,deleteLimitDays);
if(!gc.after(gcn)){
JOptionPane.showMessageDialog(null,"學生紀錄創建已超過指定天數,不得刪除","系統提示",JOptionPane.ERROR_MESSAGE);
return false;
}
return SQLRunner.executSql("delete from student where stu_no='"+keyValue+"'");
} catch (SQLException ex) {
return false;
}
}
public boolean update() {//父類按鈕響應
try{
boolean roomchanged=true;
String class_no;
if(jComboBox_class.getSelectedItem()==null){
class_no="";
}else{
String clname=(String)(jComboBox_class.getSelectedItem());
ResultSet rs=SQLRunner.getResult("select * from class where clname='"+clname+"'");
if(!rs.next())return false;
class_no=rs.getString("class_no").trim();
}
String score=jTextField_score.getText().trim();
if(score.equals(""))score="null";
String sname=jTextField_name.getText().trim();
if(sname.equals("")){
JOptionPane.showMessageDialog(null,"姓名不能為空","系統提示",JOptionPane.ERROR_MESSAGE);
return false;
}
String stu_no=jTextField_stu_no.getText().trim();
String home_phone=jTextField_home_phone.getText().trim();
String address=jTextField_address.getText().trim();
String birthday=jFormattedTextField_birthday.getText().trim();
String nation;
if(jComboBox_nation.getSelectedItem()==null){
nation="";
}else{
nation=((String)jComboBox_nation.getSelectedItem()).trim();
}String Build_no;
if(jComboBox_Build_no.getSelectedItem()==null){
Build_no="";
}else{
Build_no=((String)jComboBox_Build_no.getSelectedItem()).trim();
}String sex;
if(jComboBox_sex.getSelectedItem()==null){
sex="";
}else{
sex=((String)jComboBox_sex.getSelectedItem()).trim();
}String polity;
if(jComboBox_polity.getSelectedItem()==null){
polity="";
}else{
polity=((String)jComboBox_polity.getSelectedItem()).trim();
}String source;
if(jComboBox_source.getSelectedItem()==null){
source="";
}else{
source=((String)jComboBox_source.getSelectedItem()).trim();
}String dorm_no;
if(jComboBox_Build_no.getSelectedItem()==null||jComboBox_apartment_no.getSelectedItem()==null){
dorm_no="";
}else{
dorm_no=((String)jComboBox_Build_no.getSelectedItem()).trim()+((String)jComboBox_apartment_no.getSelectedItem()).trim();
}
ResultSet rss=SQLRunner.getResult("select distinct dorm_no from studentinfo where stu_no='"+keyValue+"'");
if(!rss.next())return false;
if(dorm_no.equals(rss.getString("dorm_no")))roomchanged=false;
ResultSet rns=SQLRunner.getResult("select livein from dormitory where dorm_no='"+rss.getString("dorm_no")+"'");
if(!rns.next())return false;
String nlive=rns.getString("livein");
ResultSet room=SQLRunner.getResult("select * from dormitory where dorm_no='"+dorm_no+"'");
if(!room.next())return false;
if(!sex.equals(room.getString("sex").trim())){
JOptionPane.showMessageDialog(null,"性別與宿舍不匹配","系統提示",JOptionPane.ERROR_MESSAGE);
return false;
}
String livein=room.getString("livein").trim();
String capacity=room.getString("CAPACITY").trim();
if(Integer.parseInt(livein)>=Integer.parseInt(capacity)&&roomchanged){
JOptionPane.showMessageDialog(null,"宿舍已滿","系統提示",JOptionPane.ERROR_MESSAGE);
return false;
}
String updatesql="update student set class_no='"+class_no+"',dorm_no='"+dorm_no+"',nation='"+nation+"',polity='"+polity+"',sex='"+sex+"',source='"+source+"',home_phone='"+home_phone+"',address='"+address+"',score="+score+",sname='"+sname+"',birthday=to_date('"+birthday+"','yyyy-mm-dd'"+") where stu_no='"+stu_no+"'";
return SQLRunner.executSql(updatesql);
}catch(Exception e){
JOptionPane.showMessageDialog(null,e.toString(),"系統提示",JOptionPane.ERROR_MESSAGE);
return false;
}
}
public boolean insert() {//父類按鈕響應
try{
String class_no;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -