📄 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 + -