?? web158_com_server_stulist.java
字號:
submit.setFont(font);
submit.setToolTipText("添加考生");
submit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
String stuname=stuname_input.getText();
stuname=stuname.replaceAll("'","''");
//考號
String stuid=stuid_input.getText();
stuid=stuid.replaceAll("'","''");
//處理有沒有填寫的
if(stuname.equals("")||stuid.equals(""))
{
JOptionPane.showMessageDialog(null, "請把考生姓名和考號正確填寫");
return;
}
String sql="select * from stu_list where stuid='"+stuid+"'";
try
{
rs=db.getResult(sql);
if(rs.next())
{
JOptionPane.showMessageDialog(null, "要添加的考生準考證號碼已經存在");
return ;
}
db.Close();
}catch(Exception es)
{
JOptionPane.showMessageDialog(null, "查詢考生是否存在時失敗");
db.Close();
return;
}
//記錄不存在則添加
sql="insert into stu_list(stuname,stuid,stuscore,stuoperate,examed,submited) values('"+stuname+"','"+stuid+"',0,0,'false','false')";
boolean insok=db.executeSql(sql);
if(insok)
{
JOptionPane.showMessageDialog(null, "考生信息已經成功錄入!如不再添加請點擊上面菜單進行跳轉!");
//清空表單
stuname_input.setText("");
stuid_input.setText("");
}
else
{
JOptionPane.showMessageDialog(null, "添加考生信息失敗,請重試");
}
}
});
//把按鈕添加到面板
stusubmit_panel.add(submit);
stusubmit_panel.setPreferredSize(new Dimension(520,60));
stusubmit_panel.setOpaque(false);
add(stusubmit_panel);
}
public void actionPerformed(ActionEvent e)
{
}
}
//考生操作類
//添加考生面板
class stuOperate extends JPanel implements ActionListener
{
//////////////////////////////////////////////////////////////////////
//操作提示欄
JPanel title_panel=new JPanel();
//說明文字
JLabel title_label=new JLabel("添加考生信息");
//考生姓名板面/////////////////////////////////////////////////////////
JPanel stuname_panel=new JPanel();
//文字
JLabel stuname_txt=new JLabel();
//文本框
JTextField stuname_input=new JTextField();
//準考證號板面/////////////////////////////////////////////////////////
JPanel stuid_panel=new JPanel();
//文字
JLabel stuid_txt=new JLabel();
//文本框
JTextField stuid_input=new JTextField();
//選擇題分數/////////////////////////////////////////////////////////
JPanel stuchoose_panel=new JPanel();
//文字
JLabel stuchoose_txt=new JLabel();
//文本框
JTextField stuchoose_input=new JTextField();
//操作題目分數/////////////////////////////////////////////////////////
JPanel stuoperate_panel=new JPanel();
//文字
JLabel stuoperate_txt=new JLabel();
//文本框
JTextField stuoperate_input=new JTextField();
//充許重取試卷/////////////////////////////////////////////////////////
JPanel get_panel=new JPanel();
//文字
JRadioButton rad=new JRadioButton("是否允許重取試卷?");
//操作按鈕/////////////////////////////////////////////////////////
JPanel stusubmit_panel=new JPanel();
//提交
JButton submit=new JButton(" 更新考生信息 ");
//刪除
JButton delsubmit=new JButton(" 刪除考生信息 ");
//板面字體
Font font = new Font("宋體",0,12);
//數據庫連接
Web158_Com_Server_DBConn db=new Web158_Com_Server_DBConn();
ResultSet rs=null;
String sql="";
//全局變量學生考號
String stuid="";
//程序入口
stuOperate()
{
this.setPreferredSize(new Dimension(520,445));
this.setOpaque(false);
title_label.setPreferredSize(new Dimension(510,30));
title_label.setText("更新考生信息(需加照片請把120*150的gif格試照片以考號命名放到系統/web158_com_stupic/中)");
title_label.setFont(font);
title_panel.add(title_label);
title_panel.setPreferredSize(new Dimension(520,60));
title_panel.setOpaque(false);
add(title_panel);
//考生姓名文字
stuname_txt.setPreferredSize(new Dimension(90,18));
stuname_txt.setText("考生姓名:");
stuname_txt.setFont(font);
stuname_panel.add(stuname_txt);
//考生姓名面板
stuname_input.setPreferredSize(new Dimension(120,18));
stuname_input.setBorder(BorderFactory.createLineBorder(new Color(200,125,140)));
stuname_input.setEditable(false);
stuname_panel.add(stuname_input);
stuname_panel.setPreferredSize(new Dimension(520,60));
stuname_panel.setOpaque(false);
add(stuname_panel);
//準考證號文字
stuid_txt.setPreferredSize(new Dimension(90,18));
stuid_txt.setText("準考證號:");
stuid_txt.setFont(font);
stuid_panel.add(stuid_txt);
//準考證號面板
stuid_input.setPreferredSize(new Dimension(120,18));
stuid_input.setBorder(BorderFactory.createLineBorder(new Color(200,125,140)));
stuid_input.setEditable(false);
stuid_panel.add(stuid_input);
stuid_panel.setPreferredSize(new Dimension(520,60));
stuid_panel.setOpaque(false);
add(stuid_panel);
//選擇題文字
stuchoose_txt.setPreferredSize(new Dimension(90,18));
stuchoose_txt.setText("選擇題分數:");
stuchoose_txt.setFont(font);
stuchoose_panel.add(stuchoose_txt);
//選擇題面板
stuchoose_input.setPreferredSize(new Dimension(120,18));
stuchoose_input.setBorder(BorderFactory.createLineBorder(new Color(200,125,140)));
stuchoose_input.setToolTipText("考生選擇題分數");
stuchoose_input.setText("");
stuchoose_input.setEditable(false);
stuchoose_panel.add(stuchoose_input);
stuchoose_panel.setPreferredSize(new Dimension(520,60));
stuchoose_panel.setOpaque(false);
add(stuchoose_panel);
//操作題文字
stuoperate_txt.setPreferredSize(new Dimension(90,18));
stuoperate_txt.setText("操作題分數:");
stuoperate_txt.setFont(font);
stuoperate_panel.add(stuoperate_txt);
//操作題面板
stuoperate_input.setPreferredSize(new Dimension(120,18));
stuoperate_input.setBorder(BorderFactory.createLineBorder(new Color(200,125,140)));
stuoperate_input.setToolTipText("考生操作題分數");
stuoperate_input.setText("您不可操作");
//stuoperate_input.setEnabled(false);
stuoperate_panel.add(stuoperate_input);
stuoperate_panel.setPreferredSize(new Dimension(520,60));
stuoperate_panel.setOpaque(false);
add(stuoperate_panel);
rad.setFont(font);
rad.setBackground(new Color(207,207,157));
rad.setCursor(new Cursor(Cursor.HAND_CURSOR));
rad.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
if(rad.isSelected())
{
rad.setText("當前選擇了允許重取試卷--------允許后成績將重計");
}
if(!rad.isSelected())
{
rad.setText("當前選擇了不許重取試卷");
}
}
});
get_panel.add(rad);
//允許重取試卷
get_panel.setPreferredSize(new Dimension(520,60));
get_panel.setOpaque(false);
add(get_panel);
//添加按鈕
submit.setPreferredSize(new Dimension(120,18));
submit.setBorder(null);
submit.setBackground(new Color(207,207,157));
submit.setCursor(new Cursor(Cursor.HAND_CURSOR));
submit.setFont(font);
submit.setToolTipText("更新信息");
submit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
//取得要更新的考生準考證號碼
String stuid=stuid_input.getText();
int operate,choose;
String sqlext="";
try
{
operate=Integer.parseInt(stuoperate_input.getText());
choose=Integer.parseInt(stuchoose_input.getText());
}
catch(Exception ef)
{
JOptionPane.showMessageDialog(null, "操作題分數應是數字");
return;
}
//是否允許重新取
String ifcan="true";
if(rad.isSelected())
{
ifcan="false";
}
//如果是允許重取題剛成績都是0
if(ifcan.equals("false"))
{
operate=0;
choose=0;
sqlext=",examed='false',submited='false'";
}
sql="update stu_list set stuscore="+choose+", stuoperate="+operate+" ";
sql+=sqlext;
sql+=" where stuid='"+stuid+"'";
//更改成功
if(db.executeSql(sql))
{
JOptionPane.showMessageDialog(null, "考生信息更新成功");
setID(stuid);
initStuinfo();
}
else
{
JOptionPane.showMessageDialog(null, "更新失敗,請重試");
}
}
});
//把按鈕添加到面板
stusubmit_panel.add(submit);
//添加按鈕
delsubmit.setPreferredSize(new Dimension(120,18));
delsubmit.setBorder(null);
delsubmit.setBackground(new Color(207,207,157));
delsubmit.setCursor(new Cursor(Cursor.HAND_CURSOR));
delsubmit.setFont(font);
delsubmit.setToolTipText("刪除考生");
delsubmit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
String stuname=stuname_input.getText();
String stuid=stuid_input.getText();
JOptionPane.showMessageDialog(null, "當前刪除:\n考生:"+stuname+"\n學號:"+stuid+"\n的記錄");
sql="delete from stu_list where stuid='"+stuid+"'";
if(db.executeSql(sql))
{
JOptionPane.showMessageDialog(null, "考生:"+stuname+"\n學號:"+stuid+"\n的記錄已經成功刪除");
stuname_input.setText("");
//考號
stuid_input.setText("");
//選擇題目分數
stuchoose_input.setText("");
//操作題目
stuoperate_input.setText("");
rad.setText("是否允許重取試卷?");
rad.setSelected(false);
submit.setEnabled(false);
delsubmit.setEnabled(false);
}
else
{
JOptionPane.showMessageDialog(null, "記錄刪除失敗,請重試");
}
}
});
//把按鈕添加到面板
stusubmit_panel.add(delsubmit);
stusubmit_panel.setPreferredSize(new Dimension(520,60));
stusubmit_panel.setOpaque(false);
add(stusubmit_panel);
}
public void actionPerformed(ActionEvent e)
{
}
//取得學生ID號
public void setID(String id)
{
this.stuid=id;
}
//初始化
public void initStuinfo()
{
try
{
sql="select top 1 * from stu_list where stuid='"+stuid+"'";
rs=db.getResult(sql);
if(!rs.next())
{
JOptionPane.showMessageDialog(null, "記錄不存在,請在上面重新輸入要查詢的考生考號");
stuname_input.setText("");
//考號
stuid_input.setText("");
//選擇題目分數
stuchoose_input.setText("");
//操作題目
stuoperate_input.setText("");
rad.setText("是否允許重取試卷?");
rad.setSelected(false);
submit.setEnabled(false);
delsubmit.setEnabled(false);
}
else
{
String stuname=rs.getString("stuname");
stuname_input.setText(stuname);
//考號
String stuid=rs.getString("stuid");
stuid_input.setText(stuid);
//選擇題目分數
int stuchoose=rs.getInt("stuscore");
stuchoose_input.setText(""+stuchoose);
//操作題目
int stuoperate=rs.getInt("stuoperate");
stuoperate_input.setText(""+stuoperate);
rad.setText("是否允許重取試卷?");
rad.setSelected(false);
//按鈕可用
submit.setEnabled(true);
delsubmit.setEnabled(true);
}
db.Close();
}
catch(Exception ef)
{
JOptionPane.showMessageDialog(null, "查詢考生記錄時出現錯誤"+ef.getMessage());
db.Close();
return;
}
}//end of public void initStuinfo
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -