📄 dialogupdatestudents.java
字号:
textAreaLike.setFont(new java.awt.Font("宋体", 0, 12)); } } { scrollPaneRemarks = new JScrollPane(); panelNorth.add(scrollPaneRemarks); scrollPaneRemarks.setBounds(427, 231, 196, 154); { textAreaRemarks = new JTextArea(); scrollPaneRemarks.setViewportView(textAreaRemarks); textAreaRemarks.setLineWrap(true); textAreaRemarks.setFont(new java.awt.Font("宋体", 0, 12)); } } } { panelDown = new JPanel(); panelCenter.add(panelDown, BorderLayout.SOUTH); panelDown.setBackground(new java.awt.Color(236, 233, 216)); { buttonSubmit = new JButton(); panelDown.add(buttonSubmit); buttonSubmit.setText("确认修改信息"); buttonSubmit.setFont(new java.awt.Font("宋体", 0, 12)); buttonSubmit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { buttonSubmitActionPerformed(evt); } }); } { buttonReset = new JButton(); panelDown.add(buttonReset); buttonReset.setText("重新修改信息"); buttonReset.setFont(new java.awt.Font("宋体", 0, 12)); buttonReset.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { buttonResetActionPerformed(evt); } }); } { buttonExit = new JButton(); panelDown.add(buttonExit); buttonExit.setText("取消修改信息"); buttonExit.setFont(new java.awt.Font("宋体", 0, 12)); buttonExit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { buttonExitActionPerformed(evt); } }); } } } this.setSize(677, 524); this.setTitle("修改学生信息"); /* * 设置窗口显示居中 */ int windowsWidth = Toolkit.getDefaultToolkit().getScreenSize().width;// 获取桌面宽度 int windowsHeight = Toolkit.getDefaultToolkit().getScreenSize().height;// 获取桌面高度 int frameWidth = getSize().width;// 获取窗体宽度 int frameHeight = getSize().height;// 获取窗体高度 int startX = (windowsWidth - frameWidth) / 2;// 计算窗体显示的初始横坐标 int startY = (windowsHeight - frameHeight) / 2;// 计算窗体显示的初始纵坐标 this.setLocation(startX, startY);// 设置窗体显示位置 } catch (Exception e) { e.printStackTrace(); } } /** * 《确认修改信息》按钮事件处理方法 * * @param evt */ private void buttonSubmitActionPerformed(ActionEvent evt) { update(); } /** * 《重新修改信息》按钮事件处理方法 * * @param evt */ private void buttonResetActionPerformed(ActionEvent evt) { initial(); } /** * 《取消修改信息》按钮事件处理方法 * * @param evt */ private void buttonExitActionPerformed(ActionEvent evt) { this.dispose(); } /** * 界面初始化方法 */ private void initial() { sqlStr = "Select * from Students where ID = " + id; rs = SQLOperate.getResultSet(sqlStr); try { if (rs.next()) { this.textFieldID.setText(rs.getString("Student_ID")); studentID = rs.getString("Student_ID"); this.textFieldName.setText(rs.getString("Student_Name")); this.comboBoxSex.setSelectedItem(rs.getString("Student_Sex")); this.comboBoxAge.setSelectedItem(rs.getString("Student_Age")); this.textFieldPhone.setText(rs.getString("Student_Phone")); this.textFieldHandset.setText(rs.getString("Student_Handset")); this.textFieldAddress.setText(rs.getString("Student_Address")); this.comboBoxNative.setSelectedItem(rs.getString("Student_Native")); this.comboBoxEdu.setSelectedItem(rs.getString("Student_Edu")); this.comboBoxMarry.setSelectedItem(rs.getString("Student_Marry")); this.comboBoxWork.setSelectedItem(rs.getString("Student_Work")); this.comboBoxStage.setSelectedItem(rs.getString("Student_Stage")); this.comboBoxClass.setSelectedItem(rs.getString("Student_Class")); this.date = rs.getString("Student_StartClassTime"); this.comboBoxY.setSelectedItem(date.split("-")[0]); this.comboBoxM.setSelectedItem(date.split("-")[1]); this.comboBoxD.setSelectedItem(date.split("-")[2]); this.textAreaLike.setText(rs.getString("Student_Like")); this.textAreaRemarks.setText(rs.getString("Student_Remarks")); } } catch (SQLException e) { e.printStackTrace(); } } /** * 获取表单并进行验证,更新数据库 */ private void update() { /* * 《学生编号》 */ String student_ID = this.textFieldID.getText().trim(); if (!FormChecked.mustNotNull("学生编号", student_ID)) { this.textFieldID.requestFocus(); return; } if (!FormChecked.mustNumber("学生编号", student_ID)) { this.textFieldID.requestFocus(); return; } if (!FormChecked.charEqualNumber("学生编号", student_ID, 5)) { this.textFieldID.requestFocus(); return; } // System.out.println(student_ID + "=" + studentID); if (!student_ID.equals(studentID)) if (!FormChecked.mustNotRepeat("学生编号", student_ID, "Students", "Student_ID")) { this.textFieldID.requestFocus(); return; } if (!FormChecked.charCheck("学生编号", student_ID)) { this.textFieldID.requestFocus(); return; } /* * 《学生姓名》 */ String student_Name = this.textFieldName.getText().trim(); if (!FormChecked.mustNotNull("学生姓名", student_Name)) { this.textFieldName.requestFocus(); return; } if (!FormChecked.charBigNumber("学生姓名", student_Name, 2)) { this.textFieldName.requestFocus(); return; } if (!FormChecked.charCheck("学生姓名", student_Name)) { this.textFieldName.requestFocus(); return; } /* * 《学生性别》 */ String student_Sex = this.comboBoxSex.getSelectedItem().toString(); /* * 《学生年龄》 */ String student_Age = this.comboBoxAge.getSelectedItem().toString(); /* * 《家庭电话》 */ String student_Phone = this.textFieldPhone.getText().trim(); if (!FormChecked.mustNumber("家庭电话", student_Phone)) { this.textFieldPhone.requestFocus(); return; } /* * 《手机号码》 */ String student_Handset = this.textFieldHandset.getText().trim(); if (!FormChecked.mustNumber("手机号码", student_Handset)) { this.textFieldHandset.requestFocus(); return; } /* * 《家庭住址》 */ String student_Address = this.textFieldAddress.getText().trim(); if (!FormChecked.mustNotNull("家庭住址", student_Address)) { this.textFieldAddress.requestFocus(); return; } if (!FormChecked.charCheck("家庭住址", student_Address)) { this.textFieldAddress.requestFocus(); return; } /* * 《学生籍贯》 */ String student_Native = this.comboBoxNative.getSelectedItem().toString(); /* * 《学生学历》 */ String student_Edu = this.comboBoxEdu.getSelectedItem().toString(); /* * 《婚姻状况》 */ String student_Marry = this.comboBoxMarry.getSelectedItem().toString(); /* * 《工作经验》 */ String student_Work = this.comboBoxWork.getSelectedItem().toString(); /* * 《学习阶段》 */ String student_Stage = this.comboBoxStage.getSelectedItem().toString(); /* * 《所在班级》 */ String student_Class = this.comboBoxClass.getSelectedItem().toString(); /* * 《入学时间》 */ String date_Y = this.comboBoxY.getSelectedItem().toString(); String date_M = this.comboBoxM.getSelectedItem().toString(); String date_D = this.comboBoxD.getSelectedItem().toString(); String student_StartClassTime = date_Y + "-" + date_M + "-" + date_D; /* * 《兴趣爱好》 */ String student_Like = this.textAreaLike.getText(); if (!FormChecked.charCheck("兴趣爱好", student_Like)) { this.textAreaLike.requestFocus(); return; } /* * 《学生点评》 */ String student_Remarks = this.textAreaRemarks.getText(); if (!FormChecked.charCheck("学生点评", student_Remarks)) { this.textAreaRemarks.requestFocus(); return; } /* * 系统自动添加的插入时间、更新时间、更新人 */ // String teacher_InsertTime = SQLOperate.getPreciseDate(); String teacher_UpdateTime = SQLOperate.getPreciseDate(); String teacher_UpdateName = "边疆"; /** * 生成 SQL 语句 */ sqlStr = "Update Students set " + "Student_ID = " + student_ID + " , " + "Student_Name = '" + student_Name + "' , " + "Student_Sex = '" + student_Sex + "' , " + "Student_Age = '" + student_Age + "' , " + "Student_Phone = '" + student_Phone + "' , " + "Student_Handset = '" + student_Handset + "' , " + "Student_Address = '" + student_Address + "' , " + "Student_Native = '" + student_Native + "' , " + "Student_Edu = '" + student_Edu + "' , " + "Student_Marry = '" + student_Marry + "' , " + "Student_Work = '" + student_Work + "' , " + "Student_Stage = '" + student_Stage + "' , " + "Student_Class = '" + student_Class + "' , " + "Student_StartClassTime = '" + student_StartClassTime + "' , " + "Student_Like = '" + student_Like + "' , " + "Student_Remarks = '" + student_Remarks + "' , " + "Student_UpdateTime = '" + teacher_UpdateTime + "' , " + "Student_UpdateName = '" + teacher_UpdateName + "' " + "where ID = " + id; // System.out.println(sqlStr); st = SQLOperate.getStatement(); try { st.executeUpdate(sqlStr); } catch (SQLException e) { // e.printStackTrace(); SQLOperate.closeST(); FormChecked.lose("修改学生", "修改失败!数据库访问错误!"); return; } FormChecked.success("修改学生", "成功修改学生信息"); this.dispose(); // SQLOperate.selectAllFromData("Students", tableStudents); // initial(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -