view 包
HelpView.java
package com.imau.view;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import com.imau.base.BaseFraem;
public class HelpView extends BaseFraem {
private JTextArea ldoc;
private JScrollPane pane;
private String doc = "一、认证特权\r\n" + "1、认证前人数最多只支持1000人,认证后可提高企业的使用人数。不同认证方式对应的具体人数不同,如下:\r\n" + "1)全新认证:\r\n"
+ "填写人数后需要提交相应的人数证明材料,之后由第三方审核公司进行审核,审核通过后人数满足企业的实际需要。\r\n" + "2)已是企业号认证:\r\n" + "企业微信将同步对应企业号的人数上限。\r\n"
+ "3)已是订阅号、服务号认证:\r\n" + "1000人以下不需要提交人数证明;1000人以上需要提交人数证明;\r\n" + "2、后续可使用更多功能,提高企业运作效率。\r\n" + "\r\n"
+ "二、支持的认证主体类型\r\n" + "企业微信支持以下几种认证主体:\r\n" + "1、企业(企业法人、非企业法人、个体工商、外资企业驻华代表处 ) ;\r\n" + "2、政府及事业单位 ;\r\n"
+ "3、其他组织 (社会团体、民办非组织、其他盈利组织等);\r\n" + "\r\n" + "三、各类型认证主体需要提交的资质材料\r\n" + "包括但不限于以下材料:\r\n"
+ "1、企业法人 :《组织机构代码证》;《企业工商营业执照》;\r\n" + "2、个体工商户:《个体工商营业执照》;\r\n" + "3、政府及事业单位:《组织机构代码证》;\r\n"
+ "4、其他组织-免费:《组织机构代码证》;相关登记证书、批文或证明等:基金会请上传《基金会法人登记证书》,外地常设机构请上传其驻在地政府主管部门的批文,外国驻华机构请上传国家有关主管部门的批文或证明,居民委员会、村民委员会、社区委员会等其他组织请上传主管部门的批文或证明,独立核算的附属机构请上传主管部门的基本存款账户开户许可证和批文。\r\n"
+ "5、社会团体:《组织机构代码证》;《社会团体登记证证书》;如果是宗教团体还需要提供宗教事务管理部门的批文或证明。\r\n"
+ "6、民办非企业:《组织机构代码证》;《民办非企业登记证书》;非事业单位的培训教育机构,需要提交其自身所有权的《办学许可证》;非事业单位的医疗机构包括美容,需要提交其自身所有权的《医疗机构执业许可证》等。\r\n"
+ "7、其他盈利组织:《组织机构代码证》;相关登记证书、批文或证明等。";
public HelpView() {
this.setJMenuBar(initMenu());
init();
setFraem();
}
private void init() {
ldoc = new JTextArea(doc,30,30);
pane=new JScrollPane(ldoc);
this.add(pane);
}
}
LoginView.java
package com.imau.view;
import javax.swing.*;
import com.imau.controller.UserController;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class LoginView extends JFrame {
//请求
private UserController controller;
private JLabel lname;
private JLabel lpass;
private JTextField tname;
private JPasswordField tpass;
private JButton login;
private void initEvnet() {
login.addActionListener(new MyListener());
}
private void init() {
lname=new JLabel("用户名");
lpass=new JLabel("密 码");
tname=new JTextField(14);
tpass=new JPasswordField(14);
login=new JButton("登录");
initEvnet();
this.setLayout(new FlowLayout(FlowLayout.CENTER));
this.add(lname);
this.add(tname);
this.add(lpass);
this.add(tpass);
this.add(login);
//1.获取屏幕大小
//2.设置为大小
Dimension dim=getToolkit().getScreenSize();
int w=dim.width/2;
int h=dim.height/2;
this.setResizable(false);
this.setTitle("用户登录");
this.setSize(255,180);
this.setLocation(w-255/2, h-180/2);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public LoginView() {
init();
controller=new UserController();
}
public void close() {
this.setVisible(false);
}
class MyListener implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
String uname=tname.getText();
String upass=tpass.getText();
if(uname==null || uname.equals("") || upass==null || upass.equals("")) {
JOptionPane.showMessageDialog(null, "请输入用户名密码");
tname.setFocusable(true);
}else if(controller.login(uname, upass)) {//检查用户名密码
//保存用户信息
controller.saveUserInfo(uname, upass);
//关闭当前页面
dispose();
//显示主页面
new MainView();
}else {
JOptionPane.showMessageDialog(null, "用户名密码错误");
tname.setText("");
tpass.setText("");
tname.setFocusable(true);
}
}
}
}
MainView.java
package com.imau.view;
import javax.swing.JLabel;
import javax.swing.JMenuBar;
import com.imau.base.BaseFraem;
/**
*
* @author yangzj
* 系统主页面:
*/
public class MainView extends BaseFraem{
private JLabel label;
public MainView() {
label=new JLabel("欢迎使用学生管理系统!!",JLabel.CENTER);
this.add(label);
this.setJMenuBar(initMenu());
setFraem();
}
}
StudentInfoView.java
package com.imau.view;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import com.imau.base.BaseFraem;
import com.imau.controller.StudentController;
import com.imau.entry.Student;
/**
*
* @author yangzj id,name,sex,age,image,民族
*/
public class StudentInfoView extends BaseFraem {
private static final long serialVersionUID = 1L;
private StudentController controller;
// 组件
private JLabel lid;
private JLabel lname;
private JLabel lno;
private JLabel lsex;
private JLabel lage;
private JLabel limage;
private JLabel lnation;
private JTextField tid;
private JTextField tname;
private JTextField tsex;
private JTextField tno;
private JTextField tage;
private JTextField timage;
private JTextField tnation;
private JButton submit, cancel;
private JPanel panel;
private Student student;
public StudentInfoView(Student student) {
controller=new StudentController();
this.setJMenuBar(initMenu());
this.student=student;
init();
setFraem();
}
private void init() {
lid = new JLabel("ID");
lname = new JLabel("姓名");
lno = new JLabel("学号");
lage = new JLabel("年龄");
lsex = new JLabel("性別");
lnation = new JLabel("民族");
limage = new JLabel("头像");
tid = new JTextField(10);
tid.setEnabled(false);
tname = new JTextField(10);
tno = new JTextField(10);
tsex = new JTextField(10);
tage = new JTextField(10);
timage = new JTextField(10);
tnation = new JTextField(10);
submit=new JButton("确定");
cancel=new JButton("取消");
//学生有信息;填充
if(student!=null) {
tid.setText(student.getId()+"");
tname.setText(student.getName());
tno.setText(student.getNo());
tage.setText(student.getAge()+"");
tsex.setText(student.getSex());
tnation.setText(student.getNation());
}
this.setLayout(new FlowLayout());
panel = new JPanel();
panel.setLayout(new GridLayout(7, 2));
panel.add(lid);
panel.add(tid);
panel.add(lname);
panel.add(tname);
panel.add(lno);
panel.add(tno);
panel.add(lage);
panel.add(tage);
panel.add(lsex);
panel.add(tsex);
panel.add(lnation);
panel.add(tnation);
panel.add(submit);
panel.add(cancel);
this.add(panel);
addEvent();
}
private void addEvent() {
submit.addActionListener(new MyListener2());
cancel.addActionListener(new MyListener2());
}
class MyListener2 implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==submit)
{
//1.获取输入信心
String id=tid.getText();
String name = tname.getText();
String no = tno.getText();
long age = Integer.valueOf(tage.getText());
String sex=tsex.getText();
String nation=tnation.getText();
if(id!=null && !id.equals("")) {
//修改请求
Student student=new Student(Long.valueOf(id),name, no, age, sex, nation);
if(controller.update(student)) {
JOptionPane.showMessageDialog(null, "操作成功");
new StudentListView();
dispose();
}else {
JOptionPane.showMessageDialog(null, "操作失败");
}
}else {
Student student=new Student(name, no, age, sex, nation);
//2. 添加请求
if (controller.add(student)) {
JOptionPane.showMessageDialog(null, "操作成功");
new StudentListView();
dispose();
}else {
JOptionPane.showMessageDialog(null, "操作失败");
}
}
}else {
new StudentListView();
dispose();
}
}
}
}
StudentListView.java
package com.imau.view;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import com.imau.base.BaseFraem;
import com.imau.controller.StudentController;
import com.imau.dao.student.StudentDaoImpl;
import com.imau.entry.PageEntity;
import com.imau.entry.Student;
public class StudentListView extends BaseFraem {
private StudentController controller;
private PageEntity<Student> pageEntity;
// 组件
// 第一部分
// 搜索框
private JTextField tsearch;
// 搜索按钮
private JButton searchBtn;
private JComboBox<String> searchBox;
private String item[] = { "姓名", "学号", "年龄", "性别" };
// 添加学生按钮
private JButton addStu;
private JButton updateStu;
private JButton delStu;
// 第二部分
// 学生列表
private JTable table;
private String columnNames[] = { "序号", "ID", "姓名", "学号", "年龄", "性别", "民族" };
private Object rowData[][];
private JScrollPane scrollPane;
DefaultTableModel tableModel;
// 第三部分
// 首页 上一页 下一页 尾页 跳转 按钮
private JButton homeBtn, upBtn, nextBtn, endBtn, jumpBtn;
// 跳转输入框
private JTextField tjump;
// 显示页面基本信息
private JLabel lpage;
// 装载每一部分的组件
private JPanel panel, panel3;
public StudentListView() {
controller = new StudentController();
pageEntity = new PageEntity<>(new StudentDaoImpl());
initListData();
this.setJMenuBar(initMenu());
init();
setFraem();
}
// 初始表格数据
private void initListData() {
List<Student> list = pageEntity.getPageData();
rowData = new Object[list.size()][7];
for (int i = 0; i < list.size(); i++) {
rowData[i][0] = i + 1;
rowData[i][1] = list.get(i).getId();
rowData[i][2] = list.get(i).getName();
rowData[i][3] = list.get(i).getNo();
rowData[i][4] = list.get(i).getAge();
rowData[i][5] = list.get(i).getSex();
rowData[i][6] = list.get(i).getNation();
}
}
// 参数:数据列表
private void UpTabltUI(List<Student> list) {
// 2.数据清空
tableModel.setRowCount(0);
// 3.重新添加数据
for (int i = 0; i < list.size(); ++i) {
Object data[] = new Object[tableModel.getColumnCount()];
data[0] = i + 1;
data[1] = list.get(i).getId();
data[2] = list.get(i).getName();
data[3] = list.get(i).getNo();
data[4] = list.get(i).getAge();
data[5] = list.get(i).getSex();
data[6] = list.get(i).getNation();
tableModel.addRow(data);
}
String info = "共" + pageEntity.getTotalCount() + "条 " + pageEntity.getPageNo() + "/"
+ pageEntity.getTotalPage();
lpage.setText(info);
// 4.刷新
// 数据更新
table.invalidate();
// 数据更新
// tableModel.fireTableDataChanged();
}
private void initEnvent() {
searchBtn.addActionListener(new MyListener2());
addStu.addActionListener(new MyListener2());
updateStu.addActionListener(new MyListener2());
delStu.addActionListener(new MyListener2());
homeBtn.addActionListener(new MyListener2());
upBtn.addActionListener(new MyListener2());
nextBtn.addActionListener(new MyListener2());
endBtn.addActionListener(new MyListener2());
jumpBtn.addActionListener(new MyListener2());
}
private void init() {
tsearch = new JTextField(10);
searchBtn = new JButton("搜索");
searchBox = new JComboBox<>(item);
addStu = new JButton("添加");
updateStu = new JButton("修改");
delStu = new JButton("删除");
tableModel = new DefaultTableModel(rowData, columnNames);
table = new JTable(tableModel);
table.setRowHeight(30);
scrollPane = new JScrollPane(table);
homeBtn = new JButton("首页");
upBtn = new JButton("上一页");
nextBtn = new JButton("下一页");
endBtn = new JButton("尾页");
jumpBtn = new JButton("跳转");
tjump = new JTextField(5);
String info = "共" + pageEntity.getTotalCount() + "条 " + pageEntity.getPageNo() + "/"
+ pageEntity.getTotalPage();
lpage = new JLabel(info);
panel = new JPanel();
panel3 = new JPanel();
panel.add(searchBox);
panel.add(tsearch);
panel.add(searchBtn);
panel.add(addStu);
panel.add(updateStu);
panel.add(delStu);
panel3.add(lpage);
panel3.add(homeBtn);
panel3.add(upBtn);
panel3.add(nextBtn);
panel3.add(endBtn);
panel3.add(tjump);
panel3.add(jumpBtn);
this.add(panel, BorderLayout.NORTH);
this.add(scrollPane, BorderLayout.CENTER);
this.add(panel3, BorderLayout.SOUTH);
this.pack();
initEnvent();
}
class MyListener2 implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
// 添加学生
if (e.getSource() == addStu) {
new StudentInfoView(null);
dispose();
}
// 修改学生
if (e.getSource() == updateStu) {
// 1.选择行
int row = table.getSelectedRow();
if (row != -1) {
// 2.获取选择行ID的列值
long id = (Long) table.getValueAt(row, 1);
// 3.查询对象
Student student = controller.findStudent(id);
// 4.传入到修改页面
new StudentInfoView(student);
dispose();
} else {
}
}
// 删除学生
if (e.getSource() == delStu) {
// 1.选择行
int row = table.getSelectedRow();
if (row != -1) {
// 2.获取选择行ID的列值
long id = (Long) table.getValueAt(row, 1);
// 3.删除
if(controller.delStudent(id)) {
JOptionPane.showMessageDialog(null, "删除成功");
pageEntity.init();
UpTabltUI(pageEntity.homePage());
}else {
JOptionPane.showMessageDialog(null, "删除失败");
}
} else {
JOptionPane.showMessageDialog(null, "请选择数据");
}
}
// 页面导航
if (e.getSource() == homeBtn) {
List<Student> list=pageEntity.homePage();
UpTabltUI(list);
}
if (e.getSource() == nextBtn) {
List<Student> list=pageEntity.nextPage();
UpTabltUI(list);
}
if (e.getSource() == upBtn) {
List<Student> list=pageEntity.previouPage();
UpTabltUI(list);
}
if (e.getSource() == endBtn) {
List<Student> list=pageEntity.endPage();
UpTabltUI(list);
}
if (e.getSource() == jumpBtn) {
String pageNo=tjump.getText();
if(pageNo!=null&&!pageNo.equals(""))
{
List<Student> list=pageEntity.getListDataByPageNo(Integer.valueOf(pageNo));
UpTabltUI(list);
}else {
}
}
if(e.getSource()==searchBtn) {
//选择字段
String item=(String) searchBox.getSelectedItem();
String field;
Object value =tsearch.getText();
if(item.equals("姓名")) {
field="name";
}else if(item.equals("学号")) {
field="no";
}else if(item.equals("年龄")) {
field="age";
}else {
field="sex";
}
List<Student> list=controller.search(field, value);
UpTabltUI(list);
}
}
}
}
UserPassEditView.java
package com.imau.view;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import com.imau.base.BaseFraem;
import com.imau.controller.UserController;
import com.imau.entry.User;
import com.imau.util.UserInfo;
import com.imau.view.LoginView.MyListener;
public class UserPassEditView extends BaseFraem {
private UserController controller;
private JLabel loldPass;
private JLabel lnewPass;
private JLabel lnewPssConfim;
private JPasswordField toldPass;
private JPasswordField tnewPass;
private JPasswordField tnewPssConfim;
private JButton submit, cancel;
private JPanel panel;
public UserPassEditView() {
controller = new UserController();
this.setJMenuBar(initMenu());
init();
setFraem();
}
private void init() {
loldPass = new JLabel("旧密码");
lnewPass = new JLabel("新密码");
lnewPssConfim = new JLabel("确认新密码");
toldPass = new JPasswordField(10);
tnewPass = new JPasswordField(10);
tnewPssConfim = new JPasswordField(10);
submit = new JButton("确认");
cancel = new JButton("取消");
panel = new JPanel();
panel.add(loldPass);
panel.add(toldPass);
panel.add(lnewPass);
panel.add(tnewPass);
panel.add(lnewPssConfim);
panel.add(tnewPssConfim);
panel.add(submit);
panel.add(cancel);
this.add(panel);
initEvnet();
}
private void initEvnet() {
submit.addActionListener(new MyListener2());
cancel.addActionListener(new MyListener2());
}
class MyListener2 implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
String newPss=tnewPass.getText();
String oldPss=toldPass.getText();
String newPssConfim=tnewPssConfim.getText();
if(e.getSource()==submit) {
//判断旧密码正确?
if(!UserInfo.getUser().getUpass().equals(oldPss)) {
JOptionPane.showMessageDialog(null, "旧密码输入不正确");
}
//新密码 确认一样
if(!newPss.equals(newPssConfim)) {
JOptionPane.showMessageDialog(null, "两次密码输入不一样");
}
User user =UserInfo.getUser();
user.setUpass(newPss);
if(controller.editPass(user))
{
JOptionPane.showMessageDialog(null, "操作成功");
}else {
JOptionPane.showMessageDialog(null, "操作失败");
}
}else {
tnewPass.setText("");
toldPass.setText("");
tnewPssConfim.setText("");
}
}
}
}