📄 inputbasicinfo.java~212~
字号:
xuehao = xingming = shenfenzhenghao = nianling = minzu = zhuanye =
yuanxiao = nianji = banji = jiudu = xingbie = jiguan = "";
jTextField_Name.setText("");
jTextField_SN.setText("");
jTextField_ID.setText("");
jTextField_Age.setText("");
jTextField_Nation.setText("");
jTextField_Major.setText("");
jTextField_College.setText("");
jTextField_Class.setText("");
jTextField_Grade.setText("");
jTextField_Other.setText("");
jTextField_Hometown.setText("");
jComboBox_Sex.setSelectedIndex(0);
jComboBox_Status.setSelectedIndex(0);
hasInput = false;
}
public void input() {
hasInput = false;
try {
getInfo();
Statement stmt;
PreparedStatement pstmt;
ResultSet rs;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:db_STU", "",
"");
stmt = con.createStatement();
String insert = "insert into Basic_Info values('" + xuehao + "','" +
xingming + "','" + shenfenzhenghao + "','" +
xingbie + "','" + nianling + "','" + minzu + "','" +
zhuanye + "','" + yuanxiao + "','" + nianji + "','" +
banji + "','" + jiudu + "','" + jiguan + "','" +
beizhu + "')" ;
rs = stmt.executeQuery("select 学号 from Basic_Info");
System.out.println("HERE123"); //////////////////////////////////////////////
while (rs.next()) {
String tempNumber = rs.getString(1);
System.out.println(tempNumber); ///////////////////////////////////////////
if (tempNumber.equals(xuehao)) {
overRideOrNot = JOptionPane.showConfirmDialog(this,
"已存在学号为“" + xuehao + "”的学生的基本信息!是否将其覆盖(其选课信息完全清空)?",
"覆盖学生基本信息?", 2);
if (overRideOrNot == 0) {
String tempOrder =
"delete from Basic_Info where 学号=(select 学号 from Basic_Info where 学号=" +
"'" + xuehao + "')";
stmt.executeUpdate(tempOrder);
stmt.executeUpdate(insert);
String deleteOrder =
"delete from Result_Info where 学号=(select 学号 from Result_Info where 学号=" +
"'" + xuehao + "')";
String insertOrder =
"insert into Result_Info (学号,姓名) values('" +
xuehao +
"','" + xingming + "')"
;
stmt.executeUpdate(deleteOrder);
stmt.executeUpdate(insertOrder);
//将选课信息一同在Result_Inof中更新
hasInput = true;
break;
}
if (overRideOrNot == 2) {
break;
}
}
}
System.out.println("HERE234"+overRideOrNot); ///////////////////////////////////////////
if (overRideOrNot == -1) {
System.out.println(insert);///////////////////////////////////////////////////////
stmt.executeUpdate(insert);
String order = "insert into Result_Info (学号,姓名) values('" +
xuehao +
"','" + xingming + "')";
stmt.executeUpdate(order); //将学号和姓名一同录入Reslut_Info中
hasInput = true;
}
con.close();
overRideOrNot = -1;
} catch (Exception e) {
e.printStackTrace();
}
if (hasInput) {
JOptionPane.showMessageDialog(this, "该学生的基本信息已成功录入!",
"录入成功!", 1);
jButton_GoOn.setEnabled(true);
}
}
public void getInfo() throws Exception {
int sex = jComboBox_Sex.getSelectedIndex();
status = jComboBox_Status.getSelectedIndex();
xuehao = jTextField_SN.getText().trim();
xingming = jTextField_Name.getText().trim();
shenfenzhenghao = jTextField_ID.getText().toLowerCase().trim();
nianling = jTextField_Age.getText().trim();
minzu = jTextField_Nation.getText().trim();
zhuanye = jTextField_Major.getText().trim();
yuanxiao = jTextField_College.getText().trim();
nianji = jTextField_Grade.getText().trim();
banji = jTextField_Class.getText().trim();
jiguan = jTextField_Hometown.getText().trim();
jiudu = gradeStatus[status];
xingbie = studentSex[sex];
if (!jTextField_Other.getText().equals("")) {
beizhu = jTextField_Other.getText().trim();
}
if (xuehao.equals("") || xingming.equals("")) {
JOptionPane.showMessageDialog(this, "学生的学号和姓名皆不能为空!",
"注意!", 2);
throw new Exception();
}
if (shenfenzhenghao.equals("")) {
JOptionPane.showMessageDialog(this, "学生的身份证号码不能为空!",
"注意!", 2);
throw new Exception();
} else if (!shenfenzhenghao.equals("")) {
if (shenfenzhenghao.length() == 15 ||
shenfenzhenghao.length() == 18) {
for (int i = 0; i < shenfenzhenghao.length(); i++) {
if ((!((int) shenfenzhenghao.charAt(i) >= 48 &&
(int) shenfenzhenghao.charAt(i) <= 57)) &&
(i < shenfenzhenghao.length() - 1)) {
JOptionPane.showMessageDialog(this,
"学生的身份证号码格式不正确!只能为15或18位数字或最后一位为x的15或18位数字",
"注意!", 2);
throw new Exception();
} else {
if ((((int) shenfenzhenghao.charAt(i) >= 48 &&
(int) shenfenzhenghao.charAt(i) <= 57)) ||
(shenfenzhenghao.charAt(shenfenzhenghao.length() -
1) ==
'x')) {} else {
JOptionPane.showMessageDialog(this,
"学生的身份证号码格式不正确!只能为15或18位数字或最后一位为x的15或18位数字",
"注意!", 2);
throw new Exception();
}
}
}
} else {
JOptionPane.showMessageDialog(this,
"学生的身份证号码长度不正确!中国居民身份证号应为15或18位!",
"注意!", 2);
throw new Exception();
}
}
}
public void jComboBox1_actionPerformed(ActionEvent e) {
}
public void jButton_Reset_actionPerformed(ActionEvent e) {
reset();
}
public void jButton_GoOn_actionPerformed(ActionEvent e) {
if (hasInput) {
hasInput = false;
reset();
}
jButton_GoOn.setEnabled(false);
}
public void jButton_Cancel_actionPerformed(ActionEvent e) {
dispose();
}
public void jButton_OK_actionPerformed(ActionEvent e) {
input();
}
public static void main(String[] args) {
new InputBasicInfo(new AFrame(), true);
}
public void jTextField_Other_actionPerformed(ActionEvent e) {
input();
}
}
class InputBasicInfo_jTextField_Other_actionAdapter implements ActionListener {
private InputBasicInfo adaptee;
InputBasicInfo_jTextField_Other_actionAdapter(InputBasicInfo adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jTextField_Other_actionPerformed(e);
}
}
class InputBasicInfo_jButton_OK_actionAdapter implements ActionListener {
private InputBasicInfo adaptee;
InputBasicInfo_jButton_OK_actionAdapter(InputBasicInfo adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton_OK_actionPerformed(e);
}
}
class InputBasicInfo_jButton_Cancel_actionAdapter implements ActionListener {
private InputBasicInfo adaptee;
InputBasicInfo_jButton_Cancel_actionAdapter(InputBasicInfo adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton_Cancel_actionPerformed(e);
}
}
class InputBasicInfo_jButton_GoOn_actionAdapter implements ActionListener {
private InputBasicInfo adaptee;
InputBasicInfo_jButton_GoOn_actionAdapter(InputBasicInfo adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton_GoOn_actionPerformed(e);
}
}
class InputBasicInfo_jButton_Reset_actionAdapter implements ActionListener {
private InputBasicInfo adaptee;
InputBasicInfo_jButton_Reset_actionAdapter(InputBasicInfo adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton_Reset_actionPerformed(e);
}
}
class InputBasicInfo_jComboBox1_actionAdapter implements ActionListener {
private InputBasicInfo adaptee;
InputBasicInfo_jComboBox1_actionAdapter(InputBasicInfo adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jComboBox1_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -