package guanzhi.GUITest;
import guanzhi.pojo.Student;
import guanzhi.service.StudentService;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import java.util.Calendar;
/**
* @author CSDN 观止study
* 碰到问题需要远程协助可添加微信:fsp365study
*/
public class UpdateView extends JFrame {
private JPanel contentPane;
private JTextField sidText;
private JTextField nameText;
private JTextField ageText;
private JTextField majorText;
private JTextField gradeText;
private JTextField loveSubjText;
private JTextField enterTimeText;
private StudentService service = new StudentService();
public UpdateView(final int id, UserListView userListView) {
setTitle("学生编辑");
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setBounds(100, 100, 443, 450);
setLocationRelativeTo(null);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblNewLabel = new JLabel("学号:");
lblNewLabel.setBounds(112, 50, 43, 15);
contentPane.add(lblNewLabel);
sidText = new JTextField();
sidText.setBounds(151, 47, 160, 21);
contentPane.add(sidText);
sidText.setColumns(10);
JLabel lblNewLabel_1 = new JLabel("姓名:");
lblNewLabel_1.setBounds(112, 93, 43, 15);
contentPane.add(lblNewLabel_1);
nameText = new JTextField();
nameText.setBounds(151, 90, 160, 21);
contentPane.add(nameText);
nameText.setColumns(10);
JLabel lblNewLabel_2 = new JLabel("年龄:");
lblNewLabel_2.setBounds(112, 134, 43, 15);
contentPane.add(lblNewLabel_2);
ageText = new JTextField();
ageText.setBounds(151, 130, 160, 21);
contentPane.add(ageText);
ageText.setColumns(10);
JLabel lblNewLabel_3 = new JLabel("专业:");
lblNewLabel_3.setBounds(112, 177, 43, 15);
contentPane.add(lblNewLabel_3);
majorText = new JTextField();
majorText.setBounds(151, 177, 160, 21);
contentPane.add(majorText);
majorText.setColumns(10);
JLabel lblNewLabel_4 = new JLabel("班级:");
lblNewLabel_4.setBounds(111, 220, 43, 15);
contentPane.add(lblNewLabel_4);
gradeText = new JTextField();
gradeText.setBounds(151, 220, 160, 21);
contentPane.add(gradeText);
gradeText.setColumns(10);
JLabel lblNewLabel_5 = new JLabel("偏爱学科:");
lblNewLabel_5.setBounds(90, 263, 70, 15);
contentPane.add(lblNewLabel_5);
loveSubjText = new JTextField();
loveSubjText.setBounds(151, 263, 160, 21);
contentPane.add(loveSubjText);
loveSubjText.setColumns(10);
JLabel lblNewLabel_6 = new JLabel("入学时间:");
lblNewLabel_6.setBounds(90, 303, 70, 15);
contentPane.add(lblNewLabel_6);
enterTimeText = new JTextField();
enterTimeText.setBounds(151, 303, 160, 21);
contentPane.add(enterTimeText);
enterTimeText.setColumns(10);
//保存
JButton saveBtn = new JButton("保存");
saveBtn.addActionListener(e -> {
String sid = sidText.getText();
String name = nameText.getText();
String age = ageText.getText();
String major = majorText.getText();
String grade = gradeText.getText();
String loveSubj = loveSubjText.getText();
String enterTime = enterTimeText.getText();
if (sid == null || "".equals(sid)) {
JOptionPane.showMessageDialog(contentPane, "请输入学号", "系统提示", JOptionPane.WARNING_MESSAGE);
return;
}
if (name == null || "".equals(name)) {
JOptionPane.showMessageDialog(contentPane, "请输入姓名", "系统提示", JOptionPane.WARNING_MESSAGE);
return;
}
if (age == null || "".equals(age)) {
JOptionPane.showMessageDialog(contentPane, "请输入年龄", "系统提示", JOptionPane.WARNING_MESSAGE);
return;
}
if (major == null || "".equals(major)) {
JOptionPane.showMessageDialog(contentPane, "请输入专业", "系统提示", JOptionPane.WARNING_MESSAGE);
return;
}
if (grade == null || "".equals(grade)) {
JOptionPane.showMessageDialog(contentPane, "请输入年纪", "系统提示", JOptionPane.WARNING_MESSAGE);
return;
}
if (loveSubj == null || "".equals(loveSubj)) {
JOptionPane.showMessageDialog(contentPane, "请输入偏爱学科", "系统提示", JOptionPane.WARNING_MESSAGE);
return;
}
if (enterTime == null || "".equals(enterTime)) {
JOptionPane.showMessageDialog(contentPane, "请输入入学时间", "系统提示", JOptionPane.WARNING_MESSAGE);
return;
}
// 判断学号是否重复
Student s = service.selectBySid(sid);
if (s != null && s.getId() != id) {
JOptionPane.showMessageDialog(contentPane, "学号已存在", "系统提示", JOptionPane.WARNING_MESSAGE);
return;
}
// 计算状态
String status;
Calendar calendar = Calendar.getInstance();
// 获取当前年
int now = calendar.get(Calendar.YEAR);
try {
int enter = Integer.parseInt(enterTime);
status = now - enter > 4 ? "毕业" : "在读";
} catch (Exception err) {
JOptionPane.showMessageDialog(contentPane, "入学时间格式错误!");
return;
}
Student student = new Student();
student.setSid(sid);
student.setName(name);
student.setAge(Integer.parseInt(age));
student.setMajor(major);
student.setGrade(grade);
student.setLoveSubj(loveSubj);
student.setEnterTime(enterTime);
student.setStatus(status);
student.setId(id);
//修改并保存重新录入的数据
service.update(student);
dispose();
JOptionPane.showMessageDialog(contentPane, "修改成功!");
userListView.load(null);
});
saveBtn.setBounds(151, 340, 74, 23);
contentPane.add(saveBtn);
//取消
JButton cancelBtn = new JButton("取消");
cancelBtn.addActionListener(e -> dispose());
cancelBtn.setBounds(237, 340, 74, 23);
contentPane.add(cancelBtn);
//数据回显
Student student = service.selectByid(id);
sidText.setText(student.getSid());
nameText.setText(student.getName());
ageText.setText(String.valueOf(student.getAge()));
majorText.setText(student.getMajor());
gradeText.setText(student.getGrade());
loveSubjText.setText(student.getLoveSubj());
enterTimeText.setText(student.getEnterTime());
}
}
荒野大飞
- 粉丝: 1w+
- 资源: 2650
最新资源
- 西电微机原理实验-西安电子科技大学微机原理课程实验概述与指导
- 智慧校园(校园AI 产品) 校园安全 智慧校园 教育数字化 AI校园
- 西电微机原理实验四:8255可编程并行接口的应用
- 基于 Go+Echo 开发的多房间实时通讯系统。详细文档+优秀项目+全部资料.zip
- 基于 Go + Vue 的现代化博客系统详细文档+优秀项目+全部资料.zip
- 基于 go + grpc + consul 的微服务系统详细文档+优秀项目+全部资料.zip
- 基于 golang goframe + vue3 的、前后端分离的后台管理系统快捷使用模板,支持按钮级别的 RBAC。详细文档+优秀项目+全部资料.zip
- 基于 goframe2 和vue3 开发的全栈前后端分离的后台管理系统,详细文档+优秀项目+全部资料.zip
- 基于 Golang 的 容器管理系统 API详细文档+优秀项目+全部资料.zip
- 基于 React 实现的电商后台管理系统的前端项目详细文档+优秀项目+全部资料.zip
- 基于 Golang开发的微服务网关,能够实现高性能 HTTP API 转发、服务编排、多租户管理、API 访问权限控制等目的,拥有强大的自定义插件系统可以自行扩展详细文档+优秀项目+全部资料.zip
- 基于 Vue + Go 实现客户关系管理系统,,主要功能有仪表盘、客户管理、合同管理、产品管理、配置、订阅等功能详细文档+优秀项目+全部资料.zip
- 基于beego v2.0.1框架和AdminLte前端框架,开发的go语言通用后台系统,详细文档+优秀项目+全部资料.zip
- 基于 SpringBoot + Spring + SpringMvc + Mybatis + Shiro+ Redis 开发单点登录管理系统详细文档+优秀项目+全部资料.zip
- 基于beego的简易blog系统详细文档+优秀项目+全部资料.zip
- 基于Beego开发的可切换模板的 BBS 社交博客系统、它安装简单便捷,页面简介优美。前端是HTML+JS+CSS,不需要掌握一些前端技术栈也能轻松自定义页面。详细文档+优秀项目+全部资料.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈