目录
前言
一、ER图
二、系统结构图
三、学生登录和注册界面
四、教师登录界面
五、学生登录后界面
六、教师登录后界面
一、 查询
二、增加
三、删除
四、修改
七、管理员登录
一、教师管理
二、学生管理
八、全部代码
一、主代码 ==== Main
二、链接数据库,SQL语句的操作
三、声明
九、数据库
这是学习过MySQL和JavaFX所做的一个阶段作品,不过内容有点混乱只用了三个类,这是第一次能够比较清晰的写出作品,虽然还有很多不足,但是依然收获满满。
可以直接看最下面的全码,你一定能看懂。
//初始界面,学生登录界面
public static void begin() {
stage.setTitle("学校管理系统");
GridPane gp = new GridPane();
// 调整空隙
gp.setHgap(10);
gp.setVgap(10);
// 新建文本标签
Label l1 = new Label("学生名称");
// 新建输入框
TextField name = new TextField();
// 新建文本标签:用户密码
Label l2 = new Label("登录密码");
// 新建密码框
PasswordField pwd = new PasswordField();
gp.add(l1, 0, 0);
gp.add(name, 1, 0);
gp.add(l2, 0, 1);
gp.add(pwd, 1, 1);
Scene sc = new Scene(gp, 500, 400);
stage.setScene(sc);
gp.setAlignment(Pos.CENTER);
// 按钮的创建
Button b1 = new Button("学生登录");
Button b2 = new Button("学生注册");
Button b3 = new Button("教师登录");
Button b4 = new Button("管理员");
//字体类型和大小
gp.setStyle("-fx-font-family: 'FangSong';-fx-font-size: 18;");
gp.add(b1, 0, 2);
gp.add(b2, 1, 2);
gp.add(b3, 0, 3);
gp.add(b4, 1, 3);
b1.setOnAction(a -> {
try {
if (link.pupil(name.getText(), pwd.getText(),stage)) {
score(name.getText(), pwd.getText());
}
} catch (Exception e) {
e.printStackTrace();
}
});
b2.setOnAction(a -> {
longht();
System.out.println("前往注册");
});
b3.setOnAction(a -> {
try {
right();
} catch (Exception e) {
throw new RuntimeException(e);
}
});
b4.setOnAction(a ->{
try {
tuble();
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}
// 学生注册界面
public static void longht() {
GridPane gp = new GridPane();
stage.setTitle("学校管理系统");
// 设置居中方式
gp.setAlignment(Pos.CENTER);
// 调整空隙
gp.setHgap(10);
gp.setVgap(10);
// 新建文本标签
Label l1 = new Label("名称");
// 新建输入框
TextField f1 = new TextField();
// 新建文本标签:用户密码
Label l2 = new Label("密码");
// 新建密码框
PasswordField f2 = new PasswordField();
Label l3 = new Label("性别");
//性别单选框
ToggleGroup group = new ToggleGroup();
RadioButton men = new RadioButton("男");
RadioButton miss = new RadioButton("女");
HBox h1 = new HBox();
// 按钮的创建
Button b1 = new Button("注册");
// 注册按钮的创建
Button b2 = new Button("取消");
//字体类型和大小
gp.setStyle("-fx-font-family: 'FangSong';-fx-font-size: 18;");
b1.setOnAction(a -> {
String name = f1.getText();
String pwd = f2.getText();
String sex = "男";
if (miss.isSelected()) {
sex = "女";
}
if (f1.getText()!=null&&!f1.getText().trim().equals("")&&f2.getText()!=null&&!f2.getText().trim().equals("")){
try {
// 储存在数据库
link.rigister(f1.getText(), f2.getText(), sex);
tips("注册成功,请返回登录",stage);
} catch (Exception e) {
throw new RuntimeException(e);
}
}else {
tips("请输入完整",stage);
}
System.out.println("姓名:" + f1.getText());
System.out.println("性别:" + sex);
System.out.println("密码:" + f2.getText());
});
b2.setOnAction(a -> {
begin();
});
h1.getChildren().addAll(l1, l2, b1);
men.setToggleGroup(group);
miss.setToggleGroup(group);
men.setSelected(true);
h1.getChildren().addAll(men, miss);
//用户名
gp.add(l1, 0, 0);
gp.add(f1, 1, 0);
//密码
gp.add(l2, 0, 1);
gp.add(f2, 1, 1);
//用户性别
gp.add(l3, 0, 2);
gp.add(h1, 1, 2);
//按钮
gp.add(b1, 0, 3);
gp.add(b2, 1, 3);
//生成场景并完成布局绑定,同时设置场景大小
Scene sc = new Scene(gp, 500, 400);
stage.setTitle("用户注册");
stage.setScene(sc);
stage.show();
}
管理员登录界面和教师登录界面相通,只是SQL语句不同,所以进入不同的界面,大部分的代码是相同的,教师不能自己注册,只能由管理员给其添加。
//教师登录界面
public static void right() {
// 窗口名称
stage.setTitle("教师登录");
GridPane gp = new GridPane();
// 调整空隙
gp.setHgap(10);
gp.setVgap(10);
// 新建文本标签
Label l1 = new Label("教师名称");
// 新建输入框
TextField name = new TextField();
// 新建文本标签:用户密码
Label l2 = new Label("教师密码");
// 新建密码框
PasswordField pwd = new PasswordField();
Label l3=new Label("教师登录界面");
gp.add(l1, 0, 1);
gp.add(name, 1, 1);
gp.add(l2, 0, 2);
gp.add(pwd, 1, 2);
// gp.add(l3,0,0);
Scene sc = new Scene(gp, 500, 400);
// 设置居中方式
gp.setAlignment(Pos.CENTER);
// 按钮的创建
Button b1 = new Button("登录");
// 注册按钮的创建
Button b2 = new Button("取消");
//字体类型和大小
gp.setStyle("-fx-font-family: 'FangSong';-fx-font-size: 18;");
b1.setOnAction(a -> {
try {
link.login(name.getText(), pwd.getText(),stage);
} catch (Exception e) {
throw new RuntimeException(e);
}
});
b2.setOnAction(a -> {
try {
begin();
} catch (Exception e) {
throw new RuntimeException(e);
}
});
gp.add(b1, 0, 3);
gp.add(b2, 1, 3);
stage.setScene(sc);
}
学生只能查询到自己的基本信息,不能做任何的修改。
//学生查询界面
public static void score(String name, String code) throws Exception {
Student student = new Student();
link.score(student, name, code);
int id = Integer.parseInt(student.getC0());
link.scor(student, id);
Label l0 = new Label("学号 : " + student.getC0());
Label l1 = new Label("姓名 : " + student.getC1());
Label l2 = new Label("密码 : " + student.getC2());
Label l3 = new Label("性别 : " + student.getC3());
Label l4 = new Label("语文 : " + student.getC4());
Label l5 = new Label("数学 : " + student.getC5());
Label l6 = new Label("英语 : " + student.getC6());
Label l7 = new Label("化学 : " + student.getC7());
Label l8 = new Label("历史 : " + student.getC8());
Label l9 = new Label("班级 : " + student.getC9());
Label l10 = new Label("总分 : " + (student.getC4() + student.getC5() + student.getC6() + student.getC7() + student.getC8()));
Button b2 = new Button("返回");
GridPane gp = new GridPane();
gp.add(l0, 2, 0);
gp.add(l1, 2, 2);
gp.add(l2, 2, 3);
gp.add(l3, 2, 4);
gp.add(l4, 2, 5);
gp.add(l5, 2, 6);
gp.add(l6, 2, 7);
gp.add(l7, 2, 8);
gp.add(l8, 2, 9);
gp.add(l9, 2, 1);
gp.add(l10, 2, 10);
gp.add(b2, 2, 12);
// 调整空隙
gp.setHgap(10);
gp.setVgap(10);
b2.setOnAction(a -> {
begin();
});
gp.setAlignment(Pos.CENTER);
//字体类型和大小
gp.setStyle("-fx-font-family: 'FangSong';-fx-font-size: 18;");
Scene sc = new Scene(gp, 300, 450);
stage.setScene(sc);
stage.show();
}
// 名字模糊<<<<查询>>>>>表格--------------教师---查询学生----班级或姓名
static void refer(String name,int squad) {
BorderPane bp = new BorderPane();
stage.setTitle("学校管理系统");
Scene sc = new Scene(bp, 870, 450);
stage.setScene(sc);
stage.show();
FlowPane fp1 = new FlowPane();
Label l1 = new Label("名称");
TextField f1 = new TextField();
Label l2 =new Label("班级");
TextField f2 =new TextField();
Button b1 = new Button("查询");
Button b2 = new Button("返回");
ArrayList students = new ArrayList<>();
//学生成绩表格 //id查询后表格
magin1(bp, students, name,squad);
b1.setOnAction(a -> {
if (!f1.getText().trim().equals("") && f2.getText().trim().equals("")) { //姓名
refer( f1.getText(), 1);
} else if (f1.getText().trim().equals("") && !f2.getText().trim().equals("")) { //班级
refer(f2.getText(), 2);
} else if (!f1.getText().trim().equals("") && !f2.getText().trim().equals("")) { //姓名+班级
refer1(f1.getText(), f2.getText());
}
});
b2.setOnAction(a -> {
deng();
});
fp1.getChildren().addAll(l1, f1,l2,f2, b1, b2);
fp1.setHgap(15);
fp1.setPadding(new Insets(20));
bp.setTop(fp1);
}
这里是重新调用了注册方法,不过加入了一个性别判断。
//判断性别
if(f4.getText().equals("男") || f4.getText().equals("女")){
System.out.println("性别合规")
} else {
System.out.println("性别不合规")
}
输入ID,就能直接运用SQL语句把信息从数据库删除,
这里进行了ID不能修改的命令,并且判断了性别是否合规。
//学号不可更改
f1.setEditable(false);
//<<>>是ID那个输入框
管理员能够同时修改学生和教师的信息,其中对学生信息的修改和教师对学生信息的修改功能相同。对教师信息的修改添加了电话号码长度的判断
和教师对学生的管理相同
package com.example.max;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.*;
import javafx.stage.Modality;
import javafx.stage.Stage;
import java.util.ArrayList;
public class Main extends Application {
private static Stage stage;
private static int anum=0;
private static int number=0;
private static Student student0;
public static void main(String[] args) {
launch();
}
@Override
public void start(Stage stage) throws Exception {
// 方法里有形参不要再new Stage stage=new Stage();
// 给窗口赋予静态属性
Main.stage = stage;
//设置窗口不可调
stage.setResizable(false);
begin();
stage.show();
}
// --------------------------------------------------------------------
//初始界面,学生登录界面
public static void begin() {
stage.setTitle("学校管理系统");
GridPane gp = new GridPane();
// 调整空隙
gp.setHgap(10);
gp.setVgap(10);
// 新建文本标签
Label l1 = new Label("学生名称");
// 新建输入框
TextField name = new TextField();
// 新建文本标签:用户密码
Label l2 = new Label("登录密码");
// 新建密码框
PasswordField pwd = new PasswordField();
gp.add(l1, 0, 0);
gp.add(name, 1, 0);
gp.add(l2, 0, 1);
gp.add(pwd, 1, 1);
Scene sc = new Scene(gp, 500, 400);
stage.setScene(sc);
gp.setAlignment(Pos.CENTER);
// 按钮的创建
Button b1 = new Button("学生登录");
Button b2 = new Button("学生注册");
Button b3 = new Button("教师登录");
Button b4 = new Button("管理员");
//字体类型和大小
gp.setStyle("-fx-font-family: 'FangSong';-fx-font-size: 18;");
gp.add(b1, 0, 2);
gp.add(b2, 1, 2);
gp.add(b3, 0, 3);
gp.add(b4, 1, 3);
b1.setOnAction(a -> {
try {
if (link.pupil(name.getText(), pwd.getText(),stage)) {
score(name.getText(), pwd.getText());
}
} catch (Exception e) {
e.printStackTrace();
}
});
b2.setOnAction(a -> {
longht();
System.out.println("前往注册");
});
b3.setOnAction(a -> {
try {
right();
} catch (Exception e) {
throw new RuntimeException(e);
}
});
b4.setOnAction(a ->{
try {
tuble();
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}
// ---------------------------------------------------------------
// 学生查看成绩界面
public static void score(String name, String code) throws Exception {
Student student = new Student();
link.score(student, name, code);
int id = Integer.parseInt(student.getC0());
link.scor(student, id);
Label l0 = new Label("学号 : " + student.getC0());
Label l1 = new Label("姓名 : " + student.getC1());
Label l2 = new Label("密码 : " + student.getC2());
Label l3 = new Label("性别 : " + student.getC3());
Label l4 = new Label("语文 : " + student.getC4());
Label l5 = new Label("数学 : " + student.getC5());
Label l6 = new Label("英语 : " + student.getC6());
Label l7 = new Label("化学 : " + student.getC7());
Label l8 = new Label("历史 : " + student.getC8());
Label l9 = new Label("班级 : " + student.getC9());
Label l10 = new Label("总分 : " + (student.getC4() + student.getC5() + student.getC6() + student.getC7() + student.getC8()));
Button b2 = new Button("返回");
GridPane gp = new GridPane();
gp.add(l0, 2, 0);
gp.add(l1, 2, 2);
gp.add(l2, 2, 3);
gp.add(l3, 2, 4);
gp.add(l4, 2, 5);
gp.add(l5, 2, 6);
gp.add(l6, 2, 7);
gp.add(l7, 2, 8);
gp.add(l8, 2, 9);
gp.add(l9, 2, 1);
gp.add(l10, 2, 10);
gp.add(b2, 2, 12);
// 调整空隙
gp.setHgap(10);
gp.setVgap(10);
b2.setOnAction(a -> {
begin();
});
gp.setAlignment(Pos.CENTER);
//字体类型和大小
gp.setStyle("-fx-font-family: 'FangSong';-fx-font-size: 18;");
Scene sc = new Scene(gp, 300, 450);
stage.setScene(sc);
stage.show();
}
// ------------------------------------------------------------------
// 学生注册界面
public static void longht() {
GridPane gp = new GridPane();
stage.setTitle("学校管理系统");
// 设置居中方式
gp.setAlignment(Pos.CENTER);
// 调整空隙
gp.setHgap(10);
gp.setVgap(10);
// 新建文本标签
Label l1 = new Label("名称");
// 新建输入框
TextField f1 = new TextField();
// 新建文本标签:用户密码
Label l2 = new Label("密码");
// 新建密码框
PasswordField f2 = new PasswordField();
Label l3 = new Label("性别");
//性别单选框
ToggleGroup group = new ToggleGroup();
RadioButton men = new RadioButton("男");
RadioButton miss = new RadioButton("女");
HBox h1 = new HBox();
// 按钮的创建
Button b1 = new Button("注册");
// 注册按钮的创建
Button b2 = new Button("取消");
//字体类型和大小
gp.setStyle("-fx-font-family: 'FangSong';-fx-font-size: 18;");
b1.setOnAction(a -> {
String name = f1.getText();
String pwd = f2.getText();
String sex = "男";
if (miss.isSelected()) {
sex = "女";
}
if (f1.getText()!=null&&!f1.getText().trim().equals("")&&f2.getText()!=null&&!f2.getText().trim().equals("")){
try {
// 储存在数据库
link.rigister(f1.getText(), f2.getText(), sex);
tips("注册成功,请返回登录",stage);
} catch (Exception e) {
throw new RuntimeException(e);
}
}else {
tips("请输入完整",stage);
}
System.out.println("姓名:" + f1.getText());
System.out.println("性别:" + sex);
System.out.println("密码:" + f2.getText());
});
b2.setOnAction(a -> {
begin();
});
h1.getChildren().addAll(l1, l2, b1);
men.setToggleGroup(group);
miss.setToggleGroup(group);
men.setSelected(true);
h1.getChildren().addAll(men, miss);
//用户名
gp.add(l1, 0, 0);
gp.add(f1, 1, 0);
//密码
gp.add(l2, 0, 1);
gp.add(f2, 1, 1);
//用户性别
gp.add(l3, 0, 2);
gp.add(h1, 1, 2);
//按钮
gp.add(b1, 0, 3);
gp.add(b2, 1, 3);
//生成场景并完成布局绑定,同时设置场景大小
Scene sc = new Scene(gp, 500, 400);
stage.setTitle("用户注册");
stage.setScene(sc);
stage.show();
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//教师登录界面
public static void right() {
// 窗口名称
stage.setTitle("教师登录");
GridPane gp = new GridPane();
// 调整空隙
gp.setHgap(10);
gp.setVgap(10);
// 新建文本标签
Label l1 = new Label("教师名称");
// 新建输入框
TextField name = new TextField();
// 新建文本标签:用户密码
Label l2 = new Label("教师密码");
// 新建密码框
PasswordField pwd = new PasswordField();
Label l3=new Label("教师登录界面");
gp.add(l1, 0, 1);
gp.add(name, 1, 1);
gp.add(l2, 0, 2);
gp.add(pwd, 1, 2);
// gp.add(l3,0,0);
Scene sc = new Scene(gp, 500, 400);
// 设置居中方式
gp.setAlignment(Pos.CENTER);
// 按钮的创建
Button b1 = new Button("登录");
// 注册按钮的创建
Button b2 = new Button("取消");
//字体类型和大小
gp.setStyle("-fx-font-family: 'FangSong';-fx-font-size: 18;");
b1.setOnAction(a -> {
try {
link.login(name.getText(), pwd.getText(),stage);
} catch (Exception e) {
throw new RuntimeException(e);
}
});
b2.setOnAction(a -> {
try {
begin();
} catch (Exception e) {
throw new RuntimeException(e);
}
});
gp.add(b1, 0, 3);
gp.add(b2, 1, 3);
stage.setScene(sc);
}
// ---------------------------------------------------------------------
// 教师登录后界面-----管理学生
public static void deng(){
BorderPane bp = new BorderPane();
stage.setTitle("学校管理系统");
Scene sc = new Scene(bp, 870, 500);
stage.setScene(sc);
stage.show();
FlowPane fp1 = new FlowPane();
Label l1 = new Label("姓名");
TextField f1 = new TextField();
Label l2 = new Label("班级");
TextField f2 = new TextField();
Button b1 = new Button("查询");
Button b2 = new Button("增加");
Button b3 = new Button("删除");
Button b4 = new Button("修改");
Button b5 = new Button("退出");
b1.setOnAction(a -> {
if (!f1.getText().trim().equals("") && f2.getText().trim().equals("")) { //姓名
ArrayList students = new ArrayList<>();
refer( f1.getText(), 1);
} else if (f1.getText().trim().equals("") && !f2.getText().trim().equals("")) { //班级
ArrayList students = new ArrayList<>();
refer(f2.getText(), 2);
} else if (!f1.getText().trim().equals("") && !f2.getText().trim().equals("")) { //姓名+班级
ArrayList students = new ArrayList<>();
refer1(f1.getText(),f2.getText());
}
});
b2.setOnAction(a -> {
increase(bp,stage);
});
b3.setOnAction(a -> {
delete(bp,stage);
});
b4.setOnAction(a -> {
amend(bp,stage);
});
b5.setOnAction(a -> {
begin();
});
fp1.getChildren().addAll(l1, f1,l2,f2, b1, b2, b3, b4, b5);
fp1.setHgap(15);
fp1.setPadding(new Insets(20));
bp.setTop(fp1);
//学生成绩表格
ArrayList students = new ArrayList<>();
maginit(bp, students);
}
//-------------------------------------------------------------------------
// 学生成绩表格
static void maginit(BorderPane bp, ArrayList students) {
TableView tv = new TableView();
//定义表格的行标
TableColumn ID = new TableColumn("学号");
TableColumn number = new TableColumn("班级");
TableColumn name = new TableColumn("姓名");
TableColumn sex = new TableColumn("性别");
TableColumn code = new TableColumn("密码");
TableColumn chinese = new TableColumn("语文");
TableColumn mathematics = new TableColumn("数学");
TableColumn english = new TableColumn("英语");
TableColumn chemistry = new TableColumn("化学");
TableColumn history = new TableColumn("历史");
TableColumn compellation = new TableColumn("班主任");
TableColumn peace = new TableColumn("总分");
//表格列宽宽度设置
ID.setMinWidth(65);
name.setMinWidth(72);
number.setMinWidth(75);
sex.setMinWidth(65);
code.setMinWidth(74);
chinese.setMinWidth(75);
mathematics.setMinWidth(75);
english.setMinWidth(75);
chemistry.setMinWidth(75);
history.setMinWidth(75);
peace.setMinWidth(70);
compellation.setMinWidth(70);
//确定数据导入的列
ID.setCellValueFactory(
new PropertyValueFactory<>("id"));
number.setCellValueFactory(
new PropertyValueFactory<>("number"));
name.setCellValueFactory(
new PropertyValueFactory<>("name"));
sex.setCellValueFactory(
new PropertyValueFactory<>("sex"));
code.setCellValueFactory(
new PropertyValueFactory<>("code"));
chinese.setCellValueFactory(
new PropertyValueFactory<>("chinese"));
mathematics.setCellValueFactory(
new PropertyValueFactory<>("mathematics"));
english.setCellValueFactory(
new PropertyValueFactory<>("english"));
chemistry.setCellValueFactory(
new PropertyValueFactory<>("chemistry"));
history.setCellValueFactory(
new PropertyValueFactory<>("history"));
peace.setCellValueFactory(
new PropertyValueFactory<>("peace"));
compellation.setCellValueFactory(
new PropertyValueFactory<>("compellation"));
tv.getColumns().addAll(ID, number, name, sex, code, chinese, mathematics, english, chemistry, history, peace,compellation);
try {
link.magstudent(students);
} catch (Exception e) {
throw new RuntimeException(e);
}
tv.getItems().addAll(students);
bp.setCenter(tv);
}
// --------------------------------------------------------------------
// 名字模糊<<<<查询>>>>>表格--------------教师---查询学生----班级或姓名
static void refer(String name,int squad) {
BorderPane bp = new BorderPane();
stage.setTitle("学校管理系统");
Scene sc = new Scene(bp, 870, 450);
stage.setScene(sc);
stage.show();
FlowPane fp1 = new FlowPane();
Label l1 = new Label("名称");
TextField f1 = new TextField();
Label l2 =new Label("班级");
TextField f2 =new TextField();
Button b1 = new Button("查询");
Button b2 = new Button("返回");
ArrayList students = new ArrayList<>();
//学生成绩表格 //id查询后表格
magin1(bp, students, name,squad);
b1.setOnAction(a -> {
if (!f1.getText().trim().equals("") && f2.getText().trim().equals("")) { //姓名
refer( f1.getText(), 1);
} else if (f1.getText().trim().equals("") && !f2.getText().trim().equals("")) { //班级
refer(f2.getText(), 2);
} else if (!f1.getText().trim().equals("") && !f2.getText().trim().equals("")) { //姓名+班级
refer1(f1.getText(), f2.getText());
}
});
b2.setOnAction(a -> {
deng();
});
fp1.getChildren().addAll(l1, f1,l2,f2, b1, b2);
fp1.setHgap(15);
fp1.setPadding(new Insets(20));
bp.setTop(fp1);
}
// --------------------------------------------------------------------
// 模糊<<<<查询>>>>>表格-----------教师---查询学生----班级和姓名
static void refer1(String name,String squad) {
BorderPane bp = new BorderPane();
stage.setTitle("学校管理系统");
Scene sc = new Scene(bp, 871, 450);
stage.setScene(sc);
stage.show();
FlowPane fp1 = new FlowPane();
Label l1 = new Label("名称");
TextField f1 = new TextField();
Label l2 =new Label("班级");
TextField f2 =new TextField();
Button b1 = new Button("查询");
Button b2 = new Button("返回");
ArrayList students = new ArrayList<>();
//学生成绩表格 //id查询后表格
magin2(bp, students, name,squad);
b1.setOnAction(a -> {
if (!f1.getText().trim().equals("") && f2.getText().trim().equals("")) { //姓名
refer( f1.getText(), 1);
} else if (f1.getText().trim().equals("") && !f2.getText().trim().equals("")) { //班级
refer(f2.getText(), 2);
} else if (!f1.getText().trim().equals("") && !f2.getText().trim().equals("")) { //姓名+班级
refer1(f1.getText(), f2.getText());
}
});
b2.setOnAction(a -> {
deng();
});
fp1.getChildren().addAll(l1, f1,l2,f2, b1, b2);
fp1.setHgap(15);
fp1.setPadding(new Insets(20));
bp.setTop(fp1);
}
//查询表格-------查询学生
// ----------------------------------------------------------------------------
public static void magin(BorderPane bp, ArrayList students, String xing) {
TableView tv = new TableView();
//定义表格的行标
TableColumn ID = new TableColumn("学号");
TableColumn number = new TableColumn("班级");
TableColumn name = new TableColumn("姓名");
TableColumn sex = new TableColumn("性别");
TableColumn code = new TableColumn("密码");
TableColumn chinese = new TableColumn("语文");
TableColumn mathematics = new TableColumn("数学");
TableColumn english = new TableColumn("英语");
TableColumn chemistry = new TableColumn("化学");
TableColumn history = new TableColumn("历史");
TableColumn peace = new TableColumn("总分");
TableColumn compellation = new TableColumn("班主任");
//表格列宽宽度设置
ID.setMinWidth(65);
name.setMinWidth(72);
number.setMinWidth(75);
sex.setMinWidth(65);
code.setMinWidth(74);
chinese.setMinWidth(75);
mathematics.setMinWidth(75);
english.setMinWidth(75);
chemistry.setMinWidth(75);
history.setMinWidth(75);
peace.setMinWidth(70);
compellation.setMinWidth(70);
//确定数据导入的列
ID.setCellValueFactory(
new PropertyValueFactory<>("id"));
number.setCellValueFactory(
new PropertyValueFactory<>("number"));
name.setCellValueFactory(
new PropertyValueFactory<>("name"));
sex.setCellValueFactory(
new PropertyValueFactory<>("sex"));
code.setCellValueFactory(
new PropertyValueFactory<>("code"));
chinese.setCellValueFactory(
new PropertyValueFactory<>("chinese"));
mathematics.setCellValueFactory(
new PropertyValueFactory<>("mathematics"));
english.setCellValueFactory(
new PropertyValueFactory<>("english"));
chemistry.setCellValueFactory(
new PropertyValueFactory<>("chemistry"));
history.setCellValueFactory(
new PropertyValueFactory<>("history"));
peace.setCellValueFactory(
new PropertyValueFactory<>("peace"));
compellation.setCellValueFactory(
new PropertyValueFactory<>("compellation")
);
tv.getColumns().addAll(ID, number, name, sex, code, chinese, mathematics, english, chemistry, history, peace,compellation);
try {
link.inquire(students, xing);
} catch (Exception e) {
throw new RuntimeException(e);
}
tv.getItems().addAll(students);
bp.setCenter(tv);
}
//查询表格-------查询学生
// ----------------------------------------------------------------------------
public static void magin1(BorderPane bp, ArrayList students, String xing,int a) {
TableView tv = new TableView();
//定义表格的行标
TableColumn ID = new TableColumn("学号");
TableColumn number = new TableColumn("班级");
TableColumn name = new TableColumn("姓名");
TableColumn sex = new TableColumn("性别");
TableColumn code = new TableColumn("密码");
TableColumn chinese = new TableColumn("语文");
TableColumn mathematics = new TableColumn("数学");
TableColumn english = new TableColumn("英语");
TableColumn chemistry = new TableColumn("化学");
TableColumn history = new TableColumn("历史");
TableColumn peace = new TableColumn("总分");
TableColumn compellation = new TableColumn("班主任");
//表格列宽宽度设置
ID.setMinWidth(65);
name.setMinWidth(72);
number.setMinWidth(75);
sex.setMinWidth(65);
code.setMinWidth(74);
chinese.setMinWidth(75);
mathematics.setMinWidth(75);
english.setMinWidth(75);
chemistry.setMinWidth(75);
history.setMinWidth(75);
peace.setMinWidth(70);
compellation.setMinWidth(70);
//确定数据导入的列
ID.setCellValueFactory(
new PropertyValueFactory<>("id"));
number.setCellValueFactory(
new PropertyValueFactory<>("number"));
name.setCellValueFactory(
new PropertyValueFactory<>("name"));
sex.setCellValueFactory(
new PropertyValueFactory<>("sex"));
code.setCellValueFactory(
new PropertyValueFactory<>("code"));
chinese.setCellValueFactory(
new PropertyValueFactory<>("chinese"));
mathematics.setCellValueFactory(
new PropertyValueFactory<>("mathematics"));
english.setCellValueFactory(
new PropertyValueFactory<>("english"));
chemistry.setCellValueFactory(
new PropertyValueFactory<>("chemistry"));
history.setCellValueFactory(
new PropertyValueFactory<>("history"));
peace.setCellValueFactory(
new PropertyValueFactory<>("peace"));
compellation.setCellValueFactory(
new PropertyValueFactory<>("compellation")
);
tv.getColumns().addAll(ID, number, name, sex, code, chinese, mathematics, english, chemistry, history, peace,compellation);
try {
link.inquire1(students, xing, a);
} catch (Exception e) {
throw new RuntimeException(e);
}
tv.getItems().addAll(students);
bp.setCenter(tv);
}
//查询表格-------查询学生
// ----------------------------------------------------------------------------
public static void magin2(BorderPane bp, ArrayList students, String xing,String a) {
TableView tv = new TableView();
//定义表格的行标
TableColumn ID = new TableColumn("学号");
TableColumn number = new TableColumn("班级");
TableColumn name = new TableColumn("姓名");
TableColumn sex = new TableColumn("性别");
TableColumn code = new TableColumn("密码");
TableColumn chinese = new TableColumn("语文");
TableColumn mathematics = new TableColumn("数学");
TableColumn english = new TableColumn("英语");
TableColumn chemistry = new TableColumn("化学");
TableColumn history = new TableColumn("历史");
TableColumn peace = new TableColumn("总分");
TableColumn compellation = new TableColumn("班主任");
//表格列宽宽度设置
ID.setMinWidth(65);
name.setMinWidth(72);
number.setMinWidth(75);
sex.setMinWidth(65);
code.setMinWidth(74);
chinese.setMinWidth(75);
mathematics.setMinWidth(75);
english.setMinWidth(75);
chemistry.setMinWidth(75);
history.setMinWidth(75);
peace.setMinWidth(70);
compellation.setMinWidth(70);
//确定数据导入的列
ID.setCellValueFactory(
new PropertyValueFactory<>("id"));
number.setCellValueFactory(
new PropertyValueFactory<>("number"));
name.setCellValueFactory(
new PropertyValueFactory<>("name"));
sex.setCellValueFactory(
new PropertyValueFactory<>("sex"));
code.setCellValueFactory(
new PropertyValueFactory<>("code"));
chinese.setCellValueFactory(
new PropertyValueFactory<>("chinese"));
mathematics.setCellValueFactory(
new PropertyValueFactory<>("mathematics"));
english.setCellValueFactory(
new PropertyValueFactory<>("english"));
chemistry.setCellValueFactory(
new PropertyValueFactory<>("chemistry"));
history.setCellValueFactory(
new PropertyValueFactory<>("history"));
peace.setCellValueFactory(
new PropertyValueFactory<>("peace"));
compellation.setCellValueFactory(
new PropertyValueFactory<>("compellation")
);
tv.getColumns().addAll(ID, number, name, sex, code, chinese, mathematics, english, chemistry, history, peace,compellation);
try {
link.inquire2(students, xing, a);
} catch (Exception e) {
throw new RuntimeException(e);
}
tv.getItems().addAll(students);
bp.setCenter(tv);
}
// ------------------------------------------------------------------
// 学生增加界面
public static void increase(BorderPane bp ,Stage stage) {
GridPane gp = new GridPane();
stage.setTitle("学校管理系统");
// 设置居中方式
gp.setAlignment(Pos.CENTER);
Stage stage1 = new Stage();
// 调整空隙
gp.setHgap(10);
gp.setVgap(10);
// 新建文本标签
Label l1 = new Label("ID");
// 新建文本标
Label l3 = new Label("姓名");
// 新建文本标签
Label l4 = new Label("性别");
// 新建文本标签
Label l5 = new Label("密码");
// 新建输入框
TextField f1 = new TextField();
// 新建输入框
TextField f3 = new TextField();
// 新建输入框
TextField f4 = new TextField();
// 新建输入框
TextField f5 = new TextField();
gp.add(l1, 0, 1);
gp.add(f1, 1, 1);
gp.add(l3, 0, 2);
gp.add(f3, 1, 2);
gp.add(l4, 0, 3);
gp.add(f4, 1, 3);
gp.add(l5, 0, 4);
gp.add(f5, 1, 4);
Button b1 = new Button("确定");
b1.setOnAction(a -> {
if ( !f3.getText().trim().equals("") && !f5.getText().trim().equals("") && !f4.getText().trim().equals("") && !f1.getText().trim().equals("")){
if(f4.getText().equals("男") || f4.getText().equals("女")){
try {
link.rigister(f3.getText(), f5.getText(), f4.getText(), f1.getText());
ArrayList students = new ArrayList<>();
// maginit(bp, students);
deng();
tips("添加成功",stage1);
} catch (Exception e) {
throw new RuntimeException(e);
}
}else {
tips("性别不合规",stage1);
}
}else {
tips("请填写完整",stage1);
}
});
gp.add(b1, 1, 7);
gp.setStyle("-fx-font-family: 'FangSong';-fx-font-size: 15;");
Scene sc = new Scene(gp, 300, 300);
//只能操作该窗口
stage1.initOwner(stage);
stage1.initModality(Modality.WINDOW_MODAL);
//设置窗口不可调
stage1.setResizable(false);
stage1.setScene(sc);
stage1.show();
}
// ----------------------------------------------------------------------
// 学生删除界面
static void delete(BorderPane bp,Stage stage) {
// anum++;
GridPane gp = new GridPane();
// 设置间距
gp.setVgap(10);
gp.setHgap(10);
Stage stage1 = new Stage();
gp.setAlignment(Pos.CENTER);
// 文本
Label l0 = new Label("ID");
Button b1 = new Button("提交");
// 文本框
TextField t0 = new TextField();
b1.setOnAction(actionEvent -> {
// if (number == 0) {
try {
if (t0.getText().trim().equals("")) {
tips("删除失败",stage1);
} else {
if (link.delete(Integer.valueOf(t0.getText()))) {
tips("删除成功",stage1);
ArrayList students = new ArrayList<>();
maginit(bp, students);
}
}
} catch (Exception e) {
e.printStackTrace();
}
// }
});
// 添加到面板中
gp.add(l0, 0, 0);
gp.add(t0, 1, 0);
gp.add(b1, 2, 0);
gp.setStyle("-fx-font-family: 'FangSong';-fx-font-size: 16;");
// 添加场景舞台
Scene sc = new Scene(gp, 300, 260);
stage1.initOwner(stage);
stage1.initModality(Modality.WINDOW_MODAL);
// 窗口关闭时减一
stage1.setOnCloseRequest(windowEvent -> {
// anum--;
});
//设置窗口不可调
stage1.setResizable(false);
stage1.setScene(sc);
stage1.setTitle("删除界面");
stage1.show();
}
// -----------------------------------------------------------------------
// 学生修改界面
public static void amend(BorderPane bp,Stage stage) {
GridPane gp=new GridPane();
Stage stage1 = new Stage();
TextField f1 = new TextField();
Button b2=new Button("查询");
Label b1 = new Label("学号");
// 设置间距
gp.setVgap(10);
gp.setHgap(10);
gp.add(b1,0,0);
gp.add(f1,1,0);
gp.add(b2,1,1);
// 设置居中方式
gp.setAlignment(Pos.CENTER);
gp.setStyle("-fx-font-family: 'FangSong';-fx-font-size: 16;");
Scene sc = new Scene(gp, 350, 220);
stage1.initOwner(stage);
stage1.initModality(Modality.WINDOW_MODAL);
b2.setOnAction(a ->{
if(f1.getText()==null || f1.getText().equals("")){
tips("请输入正确的学号",stage1);
}else {
try {
alter(bp,f1.getText(),stage);
stage1.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
stage1.setScene(sc);
//设置窗口不可调
stage1.setResizable(false);
stage1.setTitle("修改界面");
stage1.show();
}
public static void alter(BorderPane bp,String id,Stage stage1) throws Exception {
GridPane gp = new GridPane();
Stage stage2 = new Stage();
stage.setTitle("学校管理系统");
// 设置居中方式
gp.setAlignment(Pos.CENTER);
// 调整空隙
gp.setHgap(10);
gp.setVgap(10);
// 新建文本标签
Label l1 = new Label("学号");
// 新建文本标签:用户密码
Label l2 = new Label("班级");
// 新建文本标签
Label l3 = new Label("姓名");
// 新建文本标签:用户密码
Label l4 = new Label("性别");
// 新建文本标签
Label l5 = new Label("密码");
// 新建文本标签:用户密码
Label l6 = new Label("语文");
// 新建文本标签
Label l7 = new Label("数学");
// 新建文本标签:用户密码
Label l8 = new Label("英语`");
// 新建文本标签
Label l9 = new Label("化学");
// 新建文本标签:用户密码
Label l10 = new Label("历史");
// 新建输入框
TextField f1 = new TextField();
// 新建输入框
TextField f2 = new TextField();
// 新建输入框
TextField f3 = new TextField();
// 新建输入框
TextField f4 = new TextField();
// 新建输入框
TextField f5 = new TextField();
// 新建输入框
TextField f6 = new TextField();
// 新建输入框
TextField f7 = new TextField();
// 新建输入框
TextField f8 = new TextField();
// 新建输入框
TextField f9 = new TextField();
// 新建输入框
TextField f10 = new TextField();
Student student = new Student();
//输入原生数据
link.revamp1(student,id);
link.revamp2(student,id);
f1.setText(student.getC0());
f3.setText(student.getC1());
f5.setText(student.getC2());
f4.setText(student.getC3());
f6.setText(Integer.toString(student.getC4()));
f7.setText(Integer.toString(student.getC5()));
f8.setText(Integer.toString(student.getC6()));
f9.setText(Integer.toString(student.getC7()));
f10.setText(Integer.toString(student.getC8()));
f2.setText(Integer.toString(student.getC9()));
//学号不可更改
f1.setEditable(false);
gp.add(l1, 0, 0);
gp.add(f1, 1, 0);
gp.add(l2, 0, 1);
gp.add(f2, 1, 1);
gp.add(l3, 0, 2);
gp.add(f3, 1, 2);
gp.add(l4, 0, 3);
gp.add(f4, 1, 3);
gp.add(l5, 0, 4);
gp.add(f5, 1, 4);
gp.add(l6, 0, 5);
gp.add(f6, 1, 5);
gp.add(l7, 0, 6);
gp.add(f7, 1, 6);
gp.add(l8, 0, 7);
gp.add(f8, 1, 7);
gp.add(l9, 0, 8);
gp.add(f9, 1, 8);
gp.add(l10, 0, 9);
gp.add(f10, 1, 9);
Button b1 = new Button("确定");
gp.add(b1, 1, 11);
gp.setStyle("-fx-font-family: 'FangSong';-fx-font-size: 16;");
ArrayList students=new ArrayList<>();
b1.setOnAction(a ->{
if(f4.getText().equals("男") || f4.getText().equals("女")){
link.revamp3(f1.getText(),f3.getText(),f4.getText(),f5.getText());
link.revamp4(f1.getText(), f6.getText(), f7.getText(),f8.getText(), f9.getText(),f10.getText(), f2.getText());
// maginit(bp,students);
deng();
tips("修改成功",stage2);
} else {
tips("性别不合规",stage2);
}
});
Scene sc = new Scene(gp, 300, 450);
stage2.initOwner(stage);
stage2.initModality(Modality.WINDOW_MODAL);
//设置窗口不可调
stage2.setResizable(false);
stage2.setScene(sc);
stage2.show();
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// 管理员登录界面
public static void tuble() {
// 窗口名称
stage.setTitle("管理员登录");
GridPane gp = new GridPane();
// 调整空隙
gp.setHgap(10);
gp.setVgap(10);
// 新建文本标签
Label l1 = new Label("名称");
// 新建输入框
TextField name = new TextField();
// 新建文本标签:用户密码
Label l2 = new Label("密码");
// 新建密码框
PasswordField pwd = new PasswordField();
gp.add(l1, 0, 0);
gp.add(name, 1, 0);
gp.add(l2, 0, 1);
gp.add(pwd, 1, 1);
Scene sc = new Scene(gp, 500, 400);
// 设置居中方式
gp.setAlignment(Pos.CENTER);
//字体类型和大小
gp.setStyle("-fx-font-family: 'FangSong';-fx-font-size: 18;");
// 按钮的创建
Button b1 = new Button("登录");
// 注册按钮的创建
Button b2 = new Button("取消");
b1.setOnAction(a -> {
try {
// System.out.println("5555");
link.tube(name.getText(), pwd.getText(),stage);
} catch (Exception e) {
throw new RuntimeException(e);
}
});
b2.setOnAction(a -> {
try {
begin();
} catch (Exception e) {
throw new RuntimeException(e);
}
});
gp.add(b1, 0, 2);
gp.add(b2, 1, 2);
stage.setScene(sc);
}
// ------------------------------------------------------------
// 管理员登录后界面
public static void transfer(){
GridPane gp=new GridPane();
Button b1=new Button("教师管理");
Button b2=new Button("学生管理");
Button b3=new Button("退出系统");
stage.setTitle("管理员界面`");
// 调整空隙
gp.setHgap(10);
gp.setVgap(10);
// 按钮的创建
b1.setOnAction(a ->{
educator();
});
b2.setOnAction(a ->{
deng1();
});
b3.setOnAction(a ->{
begin();
});
gp.add(b1, 0, 1);
gp.add(b2, 0, 3);
gp.add(b3, 0, 5);
//字体类型和大小
gp.setStyle("-fx-font-family: 'FangSong';-fx-font-size: 18;");
Scene sc = new Scene(gp, 400, 300);
stage.setScene(sc);
gp.setAlignment(Pos.CENTER);
}
// --------------------------------------------------------------------
// 管理员---------------------+++++++++++++++管理学生+++++++++++++++++++
public static void deng1() {
BorderPane bp = new BorderPane();
stage.setTitle("学校管理系统");
Scene sc = new Scene(bp, 870, 500);
stage.setScene(sc);
stage.show();
FlowPane fp1 = new FlowPane();
Label l1 = new Label("名称");
TextField f1 = new TextField();
Button b1 = new Button("查询");
Button b2 = new Button("增加");
Button b3 = new Button("删除");
Button b4 = new Button("修改");
Button b5 = new Button("退出");
b1.setOnAction(a -> {
// ArrayList students=new ArrayList<>();
refer1(f1.getText());
});
b2.setOnAction(a -> {
increase(bp,stage);
});
b3.setOnAction(a -> {
delete(bp,stage);
});
b4.setOnAction(a -> {
amend(bp,stage);
});
b5.setOnAction(a -> {
transfer();
});
fp1.getChildren().addAll(l1, f1, b1, b2, b3, b4, b5);
fp1.setHgap(15);
fp1.setPadding(new Insets(20));
bp.setTop(fp1);
//学生成绩表格
ArrayList students = new ArrayList<>();
maginit(bp, students);
}
// --------------------------------------------------------------
// 名字模糊<<<<查询>>>>>表格--------------管理员----查询学生
static void refer1(String name) {
BorderPane bp = new BorderPane();
stage.setTitle("学校管理系统");
Scene sc = new Scene(bp, 870, 450);
stage.setScene(sc);
stage.show();
FlowPane fp1 = new FlowPane();
Label l1 = new Label("名称");
TextField f1 = new TextField();
Button b1 = new Button("查询");
Button b2 = new Button("返回");
ArrayList students = new ArrayList<>();
//学生成绩表格 //id查询后表格
magin(bp, students, name);
b1.setOnAction(a -> {
refer1(f1.getText());
});
b2.setOnAction(a -> {
deng1();
});
fp1.getChildren().addAll(l1, f1, b1, b2);
fp1.setHgap(15);
fp1.setPadding(new Insets(20));
bp.setTop(fp1);
}
// --------------------------------------------------------------------
// -------------管理员------+++++++++++++++++教师管理++++++++++++
public static void educator(){
BorderPane bp = new BorderPane();
stage.setTitle("学校管理系统");
Scene sc = new Scene(bp, 870, 500);
stage.setScene(sc);
stage.show();
FlowPane fp1 = new FlowPane();
Label l1 = new Label("名称");
TextField f1 = new TextField();
Button b1 = new Button("查询");
Button b2 = new Button("增加");
Button b3 = new Button("删除");
Button b4 = new Button("修改");
Button b5 = new Button("退出");
b1.setOnAction(a -> {
refer3(f1.getText());
});
b2.setOnAction(a -> {
increase1(bp,stage);
});
b3.setOnAction(a -> {
delete1(bp,stage);
});
b4.setOnAction(a -> {
amend1(stage);
});
b5.setOnAction(a -> {
transfer();
});
fp1.getChildren().addAll(l1, f1, b1, b2, b3, b4, b5);
fp1.setHgap(15);
fp1.setPadding(new Insets(20));
bp.setTop(fp1);
//学生成绩表格
ArrayList students = new ArrayList<>();
sheet(bp, students);
}
//------------------------------------------------------------------
// 教师信息表格
public static void sheet(BorderPane bp, ArrayList students){
TableView tv = new TableView();
//定义表格的行标
TableColumn ID = new TableColumn("编号");
TableColumn number = new TableColumn("班级");
TableColumn compellation = new TableColumn("姓名");
TableColumn sex = new TableColumn("性别");
TableColumn code = new TableColumn("密码");
TableColumn age = new TableColumn("年龄");
TableColumn graduate=new TableColumn<>("毕业学校");
TableColumn salary = new TableColumn("工资");
TableColumn phone=new TableColumn<>("电话号码");
//表格列宽宽度设置
ID.setMinWidth(96);
number.setMinWidth(96);
sex.setMinWidth(96);
code.setMinWidth(96);
compellation.setMinWidth(96);
age.setMinWidth(96);
graduate.setMinWidth(96);
salary.setMinWidth(96);
phone.setMinWidth(101);
//确定数据导入的列
ID.setCellValueFactory(
new PropertyValueFactory<>("id"));
number.setCellValueFactory(
new PropertyValueFactory<>("number"));
age.setCellValueFactory(
new PropertyValueFactory<>("age"));
sex.setCellValueFactory(
new PropertyValueFactory<>("sex"));
code.setCellValueFactory(
new PropertyValueFactory<>("code"));
graduate.setCellValueFactory(
new PropertyValueFactory<>("graduate"));
compellation.setCellValueFactory(
new PropertyValueFactory<>("compellation"));
phone.setCellValueFactory(
new PropertyValueFactory<>("phone"));
salary.setCellValueFactory(
new PropertyValueFactory<>("salary"));
tv.getColumns().addAll(ID, number,compellation , sex, code,age, graduate,salary,phone);
try {
link.initial(students);
} catch (Exception e) {
throw new RuntimeException(e);
}
tv.getItems().addAll(students);
bp.setCenter(tv);
}
// ------------------------------------------------------------------------
// 教师增加界面
public static void increase1(BorderPane bp ,Stage stage) {
GridPane gp = new GridPane();
stage.setTitle("学校管理系统");
// 设置居中方式
gp.setAlignment(Pos.CENTER);
Stage stage1 = new Stage();
// 调整空隙
gp.setHgap(10);
gp.setVgap(10);
// 新建文本标签
Label l1 = new Label("编号");
// 新建文本标签:用户密码
Label l2 = new Label("班级");
// 新建文本标签
Label l3 = new Label("姓名");
// 新建文本标签:用户密码
Label l4 = new Label("性别");
// 新建文本标签
Label l5 = new Label("密码");
Label l6 = new Label("年龄");
// 新建文本标签
Label l7 = new Label("毕业学校");
Label l8 = new Label("工资");
// 新建文本标签
Label l9 = new Label("电话号码");
// 新建输入框
TextField f1 = new TextField();
// 新建输入框
TextField f2 = new TextField();
// 新建输入框
TextField f3 = new TextField();
// 新建输入框
TextField f4 = new TextField();
// 新建输入框
TextField f5 = new TextField();
TextField f6 = new TextField();
// 新建输入框
TextField f7 = new TextField();
// 新建输入框
TextField f8 = new TextField();
// 新建输入框
TextField f9 = new TextField("请输入13位数字");
gp.add(l1, 0, 0);
gp.add(f1, 1, 0);
gp.add(l2, 0, 1);
gp.add(f2, 1, 1);
gp.add(l3, 0, 2);
gp.add(f3, 1, 2);
gp.add(l4, 0, 3);
gp.add(f4, 1, 3);
gp.add(l5, 0, 4);
gp.add(f5, 1, 4);
gp.add(l6, 0, 5);
gp.add(f6, 1, 5);
gp.add(l7, 0, 6);
gp.add(f7, 1, 6);
gp.add(l8, 0, 7);
gp.add(f8, 1, 7);
gp.add(l9, 0, 8);
gp.add(f9, 1, 8);
Button b1 = new Button("确定");
b1.setOnAction(a -> {
if ( !f3.getText().trim().equals("") && !f5.getText().trim().equals("") && !f4.getText().trim().equals("") && !f1.getText().trim().equals("")&& !f2.getText().trim().equals("")&& !f6.getText().trim().equals("")&& !f7.getText().trim().equals("")&& !f8.getText().trim().equals("")&& !f9.getText().trim().equals("")){
int length=f9.getText().length();
if(f4.getText().equals("男") || f4.getText().equals("女")){
if(length==11){
try {
link.rigister1(f3.getText(), f5.getText(), f4.getText(), f1.getText(), f2.getText(), f6.getText(), f7.getText(),f8.getText(), f9.getText() );
ArrayList students = new ArrayList<>();
sheet(bp, students);
tips("添加成功",stage1);
} catch (Exception e) {
throw new RuntimeException(e);
}
}else {
tips("电话号码长度不合规",stage1);
}
}else {
tips("性别不和规",stage1);
}
}else {
tips("请填写完整",stage1);
}
});
gp.add(b1, 1, 9);
gp.setStyle("-fx-font-family: 'FangSong';-fx-font-size: 15;");
Scene sc = new Scene(gp, 300, 500);
//只能操作该窗口
stage1.initOwner(stage);
stage1.initModality(Modality.WINDOW_MODAL);
//设置窗口不可调
stage1.setResizable(false);
stage1.setScene(sc);
stage1.show();
}
// ---------------------------------------------------------------------------
// 教师修改界面
public static void amend1(Stage stage) {
BorderPane bp=new BorderPane();
Stage stage1 = new Stage();
FlowPane fp1 = new FlowPane();
TextField f1 = new TextField();
Button b2=new Button("查询");
Label b1 = new Label("编号");
b2.setOnAction(a ->{
if(f1.getText()==null || f1.getText().equals("")){
// tips("请输入正确的编号");
}else {
try {
alter1(bp,f1.getText(),stage1);
stage1.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
fp1.getChildren().addAll( b1,f1, b2);
fp1.setHgap(20);
fp1.setPadding(new Insets(60));
fp1.setStyle("-fx-font-family: 'FangSong';-fx-font-size: 16;");
Scene sc = new Scene(fp1, 420, 250);
stage1.initOwner(stage);
stage1.initModality(Modality.WINDOW_MODAL);
stage1.setScene(sc);
//设置窗口不可调
stage1.setResizable(false);
stage1.setTitle("教师修改界面");
stage1.show();
}
public static void alter1(BorderPane bp,String id,Stage stage1) throws Exception {
GridPane gp = new GridPane();
stage.setTitle("学校管理系统");
// 设置居中方式
gp.setAlignment(Pos.CENTER);
// 调整空隙
gp.setHgap(10);
gp.setVgap(10);
// 新建文本标签
Label l1 = new Label("编号");
// 新建文本标签:用户密码
Label l2 = new Label("班级");
// 新建文本标签
Label l3 = new Label("姓名");
// 新建文本标签:用户密码
Label l4 = new Label("性别");
// 新建文本标签
Label l5 = new Label("密码");
Label l6 = new Label("年龄");
// 新建文本标签
Label l7 = new Label("毕业学校");
Label l8 = new Label("工资");
// 新建文本标签
Label l9 = new Label("电话号码");
// 新建输入框
TextField f1 = new TextField();
// 新建输入框
TextField f2 = new TextField();
// 新建输入框
TextField f3 = new TextField();
// 新建输入框
TextField f4 = new TextField();
// 新建输入框
TextField f5 = new TextField();
TextField f6 = new TextField();
// 新建输入框
TextField f7 = new TextField();
// 新建输入框
TextField f8 = new TextField();
// 新建输入框
TextField f9 = new TextField("请输入13位数字");
Student student = new Student();
//输入原生数据
link.ranp(student,id);
f1.setText(Integer.toString(student.getId()));
f2.setText(Integer.toString(student.getNumber()));
f3.setText(student.getCompellation());
f4.setText(student.getSex());
f5.setText(student.getCode());
f6.setText(Integer.toString(student.getAge()));
f7.setText(student.getGraduate());
f8.setText(student.getSalary());
f9.setText(student.getPhone());
gp.add(l1, 0, 0);
gp.add(f1, 1, 0);
gp.add(l2, 0, 1);
gp.add(f2, 1, 1);
gp.add(l3, 0, 2);
gp.add(f3, 1, 2);
gp.add(l4, 0, 3);
gp.add(f4, 1, 3);
gp.add(l5, 0, 4);
gp.add(f5, 1, 4);
gp.add(l6, 0, 5);
gp.add(f6, 1, 5);
gp.add(l7, 0, 6);
gp.add(f7, 1, 6);
gp.add(l8, 0, 7);
gp.add(f8, 1, 7);
gp.add(l9, 0, 8);
gp.add(f9, 1, 8);
// 设置ID不能更改
f1.setEditable(false);
Button b1 = new Button("确定");
gp.add(b1, 1, 11);
Stage stage2 = new Stage();
b1.setOnAction(a ->{
if ( !f3.getText().trim().equals("") && !f5.getText().trim().equals("") && !f4.getText().trim().equals("") && !f1.getText().trim().equals("")&& !f2.getText().trim().equals("")&& !f6.getText().trim().equals("")&& !f7.getText().trim().equals("")&& !f8.getText().trim().equals("")&& !f9.getText().trim().equals("")){
int length=f9.getText().length();
if(f4.getText().equals("男") || f4.getText().equals("女")){
if(length==11){
try {
link.ranp1(f1.getText(),f2.getText(),f3.getText(),f4.getText(),f5.getText(),f6.getText(),f7.getText(),f8.getText(),f9.getText());
tips("修改成功",stage2);
ArrayList students=new ArrayList<>();
// sheet(bp,students);
educator();
stage2.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
}else {
tips("电话号码长度不合规",stage2);
}
}else {
tips("性别不合规",stage2);
}
}else {
tips("请填写完整",stage2);
}
});
gp.setStyle("-fx-font-family: 'FangSong';-fx-font-size: 16;");
Scene sc = new Scene(gp, 300, 450);
// Stage stage2 = new Stage();
stage2.initOwner(stage);
stage2.initModality(Modality.WINDOW_MODAL);
//设置窗口不可调
stage2.setResizable(false);
stage2.setScene(sc);
stage2.show();
}
// --------------------------------------------------------------------
// 删除教师界面
static void delete1(BorderPane bp,Stage stage) {
// anum++;
GridPane gp = new GridPane();
// 设置间距
gp.setVgap(10);
gp.setHgap(10);
Stage stage1 = new Stage();
gp.setAlignment(Pos.CENTER);
// 文本
Label l0 = new Label("ID");
Button b1 = new Button("提交");
// 文本框
TextField t0 = new TextField();
b1.setOnAction(actionEvent -> {
// if (number == 0) {
try {
if (t0.getText().trim().equals("")) {
tips("删除失败",stage1);
} else {
if (link.delete1(Integer.valueOf(t0.getText()))) {
tips("删除成功",stage1);
ArrayList students = new ArrayList<>();
sheet(bp, students);
}
}
} catch (Exception e) {
e.printStackTrace();
}
// }
});
// 添加到面板中
gp.add(l0, 0, 0);
gp.add(t0, 1, 0);
gp.add(b1, 2, 0);
gp.setStyle("-fx-font-family: 'FangSong';-fx-font-size: 16;");
// 添加场景舞台
Scene sc = new Scene(gp, 300, 260);
stage1.initOwner(stage);
stage1.initModality(Modality.WINDOW_MODAL);
// 窗口关闭时减一
stage1.setOnCloseRequest(windowEvent -> {
// anum--;
});
//设置窗口不可调
stage1.setResizable(false);
stage1.setScene(sc);
stage1.setTitle("删除界面");
stage1.show();
}
// --------------------------------------------------------------------
// 模糊查询------------管理员------------查询教师--------
static void refer3(String name){
BorderPane bp = new BorderPane();
stage.setTitle("学校管理系统");
Scene sc = new Scene(bp, 870, 450);
stage.setScene(sc);
stage.show();
FlowPane fp1 = new FlowPane();
Label l1 = new Label("名称");
TextField f1 = new TextField();
Button b1 = new Button("查询");
Button b2 = new Button("返回");
ArrayList students = new ArrayList<>();
//学生成绩表格 //id查询后表格
sheet1(bp, students, name);
b1.setOnAction(a -> {
refer3(f1.getText());
});
b2.setOnAction(a -> {
educator();
});
fp1.getChildren().addAll(l1, f1, b1, b2);
fp1.setHgap(15);
fp1.setPadding(new Insets(20));
bp.setTop(fp1);
}
// -------------------------------------------------------------------
// 查询表格--------查询教师
public static void sheet1(BorderPane bp, ArrayList students,String name){
TableView tv = new TableView();
//定义表格的行标
TableColumn ID = new TableColumn("编号");
TableColumn number = new TableColumn("班级");
TableColumn compellation = new TableColumn("姓名");
TableColumn sex = new TableColumn("性别");
TableColumn code = new TableColumn("密码");
TableColumn age = new TableColumn("年龄");
TableColumn graduate=new TableColumn<>("毕业学校");
TableColumn salary = new TableColumn("工资");
TableColumn phone=new TableColumn<>("电话号码");
//表格列宽宽度设置
ID.setMinWidth(96);
number.setMinWidth(96);
sex.setMinWidth(96);
code.setMinWidth(96);
compellation.setMinWidth(96);
age.setMinWidth(96);
graduate.setMinWidth(96);
salary.setMinWidth(96);
phone.setMinWidth(101);
//确定数据导入的列
ID.setCellValueFactory(
new PropertyValueFactory<>("id"));
number.setCellValueFactory(
new PropertyValueFactory<>("number"));
age.setCellValueFactory(
new PropertyValueFactory<>("age"));
sex.setCellValueFactory(
new PropertyValueFactory<>("sex"));
code.setCellValueFactory(
new PropertyValueFactory<>("code"));
graduate.setCellValueFactory(
new PropertyValueFactory<>("graduate"));
compellation.setCellValueFactory(
new PropertyValueFactory<>("compellation"));
phone.setCellValueFactory(
new PropertyValueFactory<>("phone"));
salary.setCellValueFactory(
new PropertyValueFactory<>("salary"));
tv.getColumns().addAll(ID, number,compellation , sex, code,age, graduate,salary,phone);
try {
link.initia(students,name);
} catch (Exception e) {
throw new RuntimeException(e);
}
tv.getItems().addAll(students);
bp.setCenter(tv);
}
// 提示框
static void tips(String str,Stage stage) {
// 窗口数+1
number++;
// 添加文本
Label l1 = new Label(str);
Button b1 = new Button("返回");
// 创建面板
VBox vb = new VBox(l1, b1);
Scene sc = new Scene(vb, 130, 130);
vb.setSpacing(10);
vb.setAlignment(Pos.CENTER);
Stage stage1 = new Stage();
stage1.setScene(sc);
// 设置窗口大小不可调节
stage1.setResizable(false);
stage1.setOnCloseRequest(windowEvent -> {
number--;
});
b1.setOnAction(actionEvent -> {
number--;
stage1.close();
});
//只能操作该窗口
stage1.initOwner(stage);
stage1.initModality(Modality.WINDOW_MODAL);
stage1.setAlwaysOnTop(true); //设置在窗口永远在最上层
stage1.setTitle("提示");
stage1.show();
}
}
package com.example.max;
import javafx.stage.Stage;
import java.sql.*;
import java.util.ArrayList;
import java.util.Objects;
public class link {
/**
* URL地址
*/
private static final String URL = "jdbc:mysql://127.0.0.1:3306/guanlixitong?useSSL=false";
/**
* 登录数据库服务器的账号
*/
private static final String USER = "root";
/**
* 登录数据库服务器的密码
*/
private static final String PASSWORD = "123456";
static String jdbc = "com.mysql.cj.jdbc.Driver";
static ResultSet rst = null;
static Connection cont = null;
static Statement ppst = null;
/**
* 返回数据库连接对象
*
* @return
*/
public static Connection getConn() {
try {
return DriverManager.getConnection(URL, USER, PASSWORD);
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
/**
* 关闭资源
*
* @param rs
* @param stat
* @param conn
*/
public static void close(ResultSet rs, Statement stat, Connection conn) {
try {
if (rs != null) {
rs.close();
}
if (stat != null) {
stat.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
/**
* 封装通用的更新操作(即通过该方法实现对弈任意数据表的insert,update,delete操作)
*
* @return 执行结果
*/
public static boolean exeUpdate(String sql, Object... params) {
//获取连接对象
Connection conn = getConn();
PreparedStatement ps = null;
try {
//获取预编译对象
ps = conn.prepareStatement(sql);
//执行参数赋值操作
if (Objects.nonNull(params)) {
//循环将所有的参数赋值
for (int i = 0; i < params.length; i++) {
ps.setObject(i + 1, params[i]);
}
}
//执行更新
return ps.executeUpdate() > 0;
} catch (SQLException e) {
e.printStackTrace();
} finally {
//关闭资源
close(null, ps, conn);
}
return false;
}
// --------------------------------------------------------------------
//注册账号
public static boolean rigister(String name, String code, String sex) throws Exception {
// 判断账号是否存在
String sql = "select * from rigister where name=?and code=?";
PreparedStatement pstmt = getConn().prepareStatement(sql);
pstmt.setString(1, name);
pstmt.setString(2, code);
ResultSet rs = pstmt.executeQuery();
if (!rs.next()) { //如果不存在
sql = "insert into rigister(name,code,sex) values (?,?,?)";
System.out.println("注册成功");
return exeUpdate(sql, name, code, sex);
} else { //存在
System.out.println("===以被注册===");
return false;
}
}
//添加学生账号
public static boolean rigister(String name, String code, String sex, String id) throws Exception {
// 判断账号是否存在
String sql1 = "select * from rigister where id=?";
String sql2= "select * from rigister where id=?";
PreparedStatement pstmt = getConn().prepareStatement(sql1);
pstmt.setString(1, id);
ResultSet rs = pstmt.executeQuery();
if (!rs.next()) { //如果不存在
sql1 = "insert into rigister(name,code,sex,id) values (?,?,?,?)";
System.out.println("注册成功");
return exeUpdate(sql1, name, code, sex, id);
} else { //存在
System.out.println("===以被注册===");
return false;
}
}
//添加教师账号
public static boolean rigister1(String compellation, String code, String sex, String id,String number,String age,String graduate,String salary,String phone) throws Exception {
// 判断账号是否存在
String sql1 = "select * from teacher where id=?";
PreparedStatement pstmt = getConn().prepareStatement(sql1);
pstmt.setString(1, id);
ResultSet rs = pstmt.executeQuery();
if (!rs.next()) { //如果不存在
sql1 = "insert into teacher(compellation,code,sex,id,number,age,salary,phone,graduate) values (?,?,?,?,?,?,?,?,?)";
System.out.println("注册成功");
return exeUpdate(sql1,compellation,code,sex,id,number,age,salary,phone,graduate);
} else { //存在
System.out.println("===以被注册===");
return false;
}
}
//添加账号
// public static boolean append(String id, String chinese, String mathematics, String english, String chemistry, String history, String number) throws Exception {
// String sql = "select * from grade where id=?";
// PreparedStatement pstmt = getConn().prepareStatement(sql);
// pstmt.setString(1, id);
// ResultSet rs = pstmt.executeQuery();
// if (!rs.next()) { //如果不存在
// sql = "insert into grade(chinese,mathematics,english,chemistry,history,number) values (?,?,?,?,?,?)";
// System.out.println("注册成功");
// return exeUpdate(sql, chinese, mathematics, english, chemistry, history, number);
// } else { //存在
// System.out.println("===请注册===");
// return false;
// }
// }
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// 检验学生的密码和账号
public static boolean pupil(String name, String code,Stage stage) throws Exception {
//防止SQL注入
String sql = "select*from rigister where name=?and code=?";
PreparedStatement pstmt = getConn().prepareStatement(sql);
pstmt.setString(1, name);
pstmt.setString(2, code);
ResultSet rs = pstmt.executeQuery();
if (!rs.next()) {
Main.tips("账号不存在",stage);
System.out.println("账号不存在,请注册");
return false;
} else {
System.out.println("登录成功");
return true;
}
}
// --------------------------------------------------------------------
//检验教师的密码和账号
public static boolean login(String name, String code,Stage stage) throws Exception {
//防止SQL注入
String sql = "select * from teacher where compellation=? and code=?";
PreparedStatement pstmt = getConn().prepareStatement(sql);
pstmt.setString(1, name);
pstmt.setString(2, code);
ResultSet rs = pstmt.executeQuery();
if (!rs.next()) {
System.out.println("账号不存在,请注册");
Main.tips("账号不存在",stage);
return false;
} else {
Main.deng();
System.out.println("登录成功");
return false;
}
}
// -------------------------------------------------------------------------------
//检验管理员的密码和账号
public static boolean tube(String name, String code, Stage steage) throws Exception {
//防止SQL注入
String sql = "select * from administrator where `name`=? and code=?";
PreparedStatement pstmt = getConn().prepareStatement(sql);
pstmt.setString(1, name);
pstmt.setString(2, code);
ResultSet rs = pstmt.executeQuery();
if (!rs.next()) {
System.out.println("账号不存在,请注册");
Main.tips("账号不存在",steage);
return false;
} else {
Main.transfer();
System.out.println("登录成功");
return false;
}
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// 学生查询信息
public static void score(Student student, String name, String code) throws Exception {
String sql = "select * from rigister where name=? and code=?";
PreparedStatement pstmt = getConn().prepareStatement(sql);
pstmt.setString(1, name);
pstmt.setString(2, code);
ResultSet rs = pstmt.executeQuery();
if (rs.next()) {
student.setC0(rs.getString("id"));
student.setC1(rs.getString("name"));
student.setC2(rs.getString("code"));
student.setC3(rs.getString("sex"));
}
// 释放资源
rs.close();
pstmt.close();
}
// --------------------------------------------------------------------
// 学生查询信息
public static void scor(Student student, int id) throws Exception {
String sql = "select * from grade where id=? ";
PreparedStatement pstmt = getConn().prepareStatement(sql);
pstmt.setInt(1, id);
ResultSet rs = pstmt.executeQuery();
if (rs.next()) {
student.setC4(rs.getInt("chinese"));
student.setC5(rs.getInt("mathematics"));
student.setC6(rs.getInt("english"));
student.setC7(rs.getInt("chemistry"));
student.setC8(rs.getInt("history"));
student.setC9(rs.getInt("number"));
}
// 释放资源
rs.close();
pstmt.close();
}
//--------------------------------------------------------------------
// 学生类初始化--管理员
public static void magstudent(ArrayList list) throws Exception {
String sql = " SELECT g.id,g.number,r.name,r.`code`,r.sex,g.chinese,g.mathematics,g.english,g.history,g.chemistry,mathematics+chemistry+history+chinese+english 'peace',t.compellation\n" +
" FROM grade g,rigister r,teacher t \n" +
" WHERE g.id=r.id and t.number = g.number;";
PreparedStatement pstmt = getConn().prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
// 获取数据
String name = rs.getString("name");
String sex = rs.getString("sex");
String code = rs.getString("code");
String compellation=rs.getString("compellation");
int id = rs.getInt("id");
int number = rs.getInt("number");
int chinese = rs.getInt("chinese");
int mathematics = rs.getInt("mathematics");
int english = rs.getInt("english");
int chemistry = rs.getInt("chemistry");
int history = rs.getInt("history");
int peace = rs.getInt("peace");
// 封装数据
Student student = new Student();
student.setId(id);
student.setName(name);
student.setCode(code);
student.setSex(sex);
student.setNumber(number);
student.setChinese(chinese);
student.setEnglish(english);
student.setChemistry(chemistry);
student.setMathematics(mathematics);
student.setHistory(history);
student.setPeace(peace);
student.setCompellation(compellation);
list.add(student);
}
// 释放资源
rs.close();
pstmt.close();
}
// --------------------------------------------------------------------
//删除学生界面
public static boolean delete(int id) {
String sql="delete from rigister where id=?";
return exeUpdate(sql,id);
}
//查询界面
// -----------------------------------------------------
// 模糊查询,多表查询++++++++++++++++姓名+++++++++++++++++
public static void inquire(ArrayList list, String nam) throws Exception {
String sql = "SELECT g.id,g.number,name,r.`code`,r.sex,chinese,mathematics,english,history,chemistry,mathematics+chemistry+history+chinese+english 'peace',t.compellation FROM grade g,rigister r,teacher t WHERE t.number=g.number and g.id=r.id and name like ?;";
PreparedStatement pstmt = getConn().prepareStatement(sql);
pstmt.setString(1, "%" + nam + "%");
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
String name = rs.getString("name");
String sex = rs.getString("sex");
String code = rs.getString("code");
String compellation=rs.getString("compellation");
int id = rs.getInt("id");
int number = rs.getInt("number");
int chinese=rs.getInt("chinese");
int mathematics=rs.getInt("mathematics");
int english=rs.getInt("english");
int chemistry=rs.getInt("chemistry");
int history=rs.getInt("history");
int peace=rs.getInt("peace");
// 封装数据
Student student = new Student();
student.setId(id);
student.setName(name);
student.setCode(code);
student.setSex(sex);
student.setNumber(number);
student.setChinese(chinese);
student.setEnglish(english);
student.setChemistry(chemistry);
student.setMathematics(mathematics);
student.setHistory(history);
student.setPeace(peace);
student.setCompellation(compellation);
list.add(student);
}
// 释放资源
rs.close();
pstmt.close();
}
// -----------------------------------------------------
// 模糊查询,多表查询 ++++++++++++++++班级或姓名+++++++++++
public static void inquire1(ArrayList list, String nam,int a) throws Exception {
String sql="";
if(a==1){
sql="SELECT g.id,g.number,name,r.`code`,r.sex,chinese,mathematics,english,history,chemistry,mathematics+chemistry+history+chinese+english 'peace',t.compellation FROM grade g,rigister r,teacher t WHERE t.number=g.number and g.id=r.id and name like ?;";
} else if (a==2) {
sql="SELECT g.id,g.number,name,r.`code`,r.sex,chinese,mathematics,english,history,chemistry,mathematics+chemistry+history+chinese+english 'peace',t.compellation FROM grade g,rigister r,teacher t WHERE t.number=g.number and g.id=r.id and g.number like ?;";
}
// String sql = "SELECT g.id,g.number,name,r.`code`,r.sex,chinese,mathematics,english,history,chemistry,mathematics+chemistry+history+chinese+english 'peace',t.compellation FROM grade g,rigister r,teacher t WHERE t.number=g.number and g.id=r.id and name like ?;";
PreparedStatement pstmt = getConn().prepareStatement(sql);
pstmt.setString(1, "%" + nam + "%");
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
String name = rs.getString("name");
String sex = rs.getString("sex");
String code = rs.getString("code");
String compellation=rs.getString("compellation");
int id = rs.getInt("id");
int number = rs.getInt("number");
int chinese=rs.getInt("chinese");
int mathematics=rs.getInt("mathematics");
int english=rs.getInt("english");
int chemistry=rs.getInt("chemistry");
int history=rs.getInt("history");
int peace=rs.getInt("peace");
// 封装数据
Student student = new Student();
student.setId(id);
student.setName(name);
student.setCode(code);
student.setSex(sex);
student.setNumber(number);
student.setChinese(chinese);
student.setEnglish(english);
student.setChemistry(chemistry);
student.setMathematics(mathematics);
student.setHistory(history);
student.setPeace(peace);
student.setCompellation(compellation);
list.add(student);
}
// 释放资源
rs.close();
pstmt.close();
}
// -----------------------------------------------------
// 模糊查询,多表查询 ++++++++++++++++班级和姓名+++++++++++
public static void inquire2(ArrayList list, String nam,String gra) throws Exception {
String sql = "SELECT g.id,g.number,name,r.`code`,r.sex,chinese,mathematics,english,history,chemistry,mathematics+chemistry+history+chinese+english 'peace',t.compellation FROM grade g,rigister r,teacher t WHERE t.number=g.number and g.id=r.id and name like ? and g.number like ?;";
PreparedStatement pstmt = getConn().prepareStatement(sql);
pstmt.setString(1, "%" + nam + "%");
pstmt.setString(2, "%" + gra + "%");
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
String name = rs.getString("name");
String sex = rs.getString("sex");
String code = rs.getString("code");
String compellation=rs.getString("compellation");
int id = rs.getInt("id");
int number = rs.getInt("number");
int chinese=rs.getInt("chinese");
int mathematics=rs.getInt("mathematics");
int english=rs.getInt("english");
int chemistry=rs.getInt("chemistry");
int history=rs.getInt("history");
int peace=rs.getInt("peace");
// 封装数据
Student student = new Student();
student.setId(id);
student.setName(name);
student.setCode(code);
student.setSex(sex);
student.setNumber(number);
student.setChinese(chinese);
student.setEnglish(english);
student.setChemistry(chemistry);
student.setMathematics(mathematics);
student.setHistory(history);
student.setPeace(peace);
student.setCompellation(compellation);
list.add(student);
}
// 释放资源
rs.close();
pstmt.close();
}
//---------------------------------------------------------------------------------------
// 修改界面------------------学生数据读取-----------------------------
public static void revamp1(Student student, String id) throws Exception {
String sql = "select * from rigister where id=?";
PreparedStatement pstmt = getConn().prepareStatement(sql);
pstmt.setString(1, id);
// pstmt.setString(2, code);
ResultSet rs = pstmt.executeQuery();
if (rs.next()) {
student.setC0(rs.getString("id"));
student.setC1(rs.getString("name"));
student.setC2(rs.getString("code"));
student.setC3(rs.getString("sex"));
}
// 释放资源
rs.close();
pstmt.close();
}
public static void revamp2(Student student, String id) throws Exception {
String sql = "select * from grade where id=? ";
PreparedStatement pstmt = getConn().prepareStatement(sql);
pstmt.setString(1, id);
ResultSet rs = pstmt.executeQuery();
if (rs.next()) {
student.setC4(rs.getInt("chinese"));
student.setC5(rs.getInt("mathematics"));
student.setC6(rs.getInt("english"));
student.setC7(rs.getInt("chemistry"));
student.setC8(rs.getInt("history"));
student.setC9(rs.getInt("number"));
}
// 释放资源
rs.close();
pstmt.close();
}
//--------------------------------------------------------------------------
// 修改界面------------------学生数据更改------------------------
public static boolean revamp3(String id,String name, String sex, String code){
String sql=" UPDATE rigister SET `name`=?,sex=?,code=? WHERE id=?;";
return exeUpdate(sql,name,sex,code,id) ;
}
public static boolean revamp4(String id, String chinese, String mathematics, String english, String chemistry, String history, String number){
// System.out.println(chinese);
String sql="update grade set chinese=?,mathematics=?,english=?,chemistry=?,history=?,number=? where id=?";
return exeUpdate(sql,chinese,mathematics,english,chemistry,history,number,id);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// 教师信息初始化
public static void initial(ArrayList list)throws Exception{
String sql="select * from teacher";
PreparedStatement pstmt = getConn().prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
while (rs.next()){
// 获取数据
String graduate = rs.getString("graduate");
String sex = rs.getString("sex");
String code = rs.getString("code");
String compellation=rs.getString("compellation");
String phone=rs.getString("phone");
String salary=rs.getString("salary");
int id = rs.getInt("id");
int age=rs.getInt("age");
int number = rs.getInt("number");
// 封装数据
Student student = new Student();
student.setId(id);
student.setGraduate(graduate);
student.setCode(code);
student.setSex(sex);
student.setNumber(number);
student.setCompellation(compellation);
student.setAge(age);
student.setPhone(phone);
student.setSalary(salary);
list.add(student);
}
// 释放资源
rs.close();
pstmt.close();
}
// --------------------------------------------
// -----管理员------模糊查询-------<<教师查询>>-----
public static void initia(ArrayList list,String name)throws Exception{
String sql="select * from teacher where compellation like ?";
PreparedStatement pstmt = getConn().prepareStatement(sql);
pstmt.setString(1, "%" + name + "%");
ResultSet rs = pstmt.executeQuery();
while (rs.next()){
// 获取数据
String graduate = rs.getString("graduate");
String sex = rs.getString("sex");
String code = rs.getString("code");
String compellation=rs.getString("compellation");
String phone=rs.getString("phone");
String salary=rs.getString("salary");
int id = rs.getInt("id");
int age=rs.getInt("age");
int number = rs.getInt("number");
// 封装数据
Student student = new Student();
student.setId(id);
student.setGraduate(graduate);
student.setCode(code);
student.setSex(sex);
student.setNumber(number);
student.setCompellation(compellation);
student.setAge(age);
student.setPhone(phone);
student.setSalary(salary);
list.add(student);
}
// 释放资源
rs.close();
pstmt.close();
}
// -----------------------------------------------------------------
// 修改界面---------------------------教师数据读取------------
public static void ranp(Student student,String id) throws Exception{
String sql="select *from teacher where id=?";
PreparedStatement pstmt= getConn().prepareStatement(sql);
pstmt.setString(1,id);
ResultSet rs=pstmt.executeQuery();
if(rs.next()){
student.setId(rs.getInt("id"));
student.setCompellation(rs.getString("compellation"));
student.setSex(rs.getString("sex"));
student.setCode(rs.getString("code"));
student.setNumber(rs.getInt("number"));
student.setSalary(rs.getString("salary"));
student.setAge(rs.getInt("age"));
student.setPhone(rs.getString("phone"));
student.setGraduate(rs.getString("graduate"));
}
// 释放资源
rs.close();
pstmt.close();
}
// --------------------------------------------------------------------------------------
// 修改界面-------------------------------------教师数据修改------------------
public static boolean ranp1(String id,String number,String compellation,String sex,String code,String age,String graduate,String salary,String phone){
String sql="update teacher set number=?,compellation=?,sex=?,code=?,age=?,graduate=?,salary=?,phone=? where id=?";
return exeUpdate(sql,number,compellation,sex,code,age,graduate,salary,phone,id);
}
// --------------------------------------------------------------------
//删除教师`界面
public static boolean delete1(int id) {
String sql="delete from teacher where id=?";
return exeUpdate(sql,id);
}
//-----------------------------------------------------------------------------
}
package com.example.max;
import javafx.scene.control.TableView;
public class Student {
public int age;
private int id;
private String name;
private String sex;
private String code;
private String graduate;
private String compellation;
private String salary;
private String phone;
private String c0;
private String c1;
private String c2;
private String c3;
private int c4;
private int c5;
private int c6;
private int c7;
private int c8;
private int c9;
private int english;
private int mathematics;
private int chinese;
private int chemistry;
private int history;
private int number;
private int peace;
public int getAge(){
return age;
}
public void setAge(int age){
this.age=age;
}
public String getSalary(){
return salary;
}
public void setSalary(String salary){
this.salary=salary;
}
public String getGraduate(){
return graduate;
}
public void setGraduate(String graduate){
this.graduate=graduate;
}
public String getPhone(){
return phone;
}
public void setPhone(String phone){
this.phone=phone;
}
public String getC0() {
return c0;
}
public String getC1() {
return c1;
}
public String getC2() {
return c2;
}
public String getC3() {
return c3;
}
public int getC4() {
return c4;
}
public int getC5() {
return c5;
}
public int getC6() {
return c6;
}
public int getC7() {
return c7;
}
public int getC8() {
return c8;
}
public int getC9() {
return c9;
}
public void setC0(String c0){
this.c0=c0;
}
public void setC1(String c1){
this.c1=c1;
}
public void setC2(String c2){
this.c2=c2;
}
public void setC3(String c3){
this.c3=c3;
}
public void setC4(int c4){
this.c4=c4;
}
public void setC5(int c5){
this.c5=c5;
}
public void setC6(int c6){
this.c6=c6;
}
public void setC7(int c7){
this.c7=c7;
}
public void setC8(int c8){
this.c8=c8;
}
public void setC9(int c9){
this.c9=c9;
}
public String getSex(){
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public int getPeace(){
return peace;
}
public void setPeace(int peace){
this.peace=peace;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getCompellation() {
return compellation;
}
public void setCompellation(String compellation) {
this.compellation = compellation;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public void setCenter(TableView tv) {
}
public int getEnglish(){
return english;
}
public void setEnglish(int english){
this.english=english;
}
public int getChinese(){
return chinese;
}
public void setChinese(int chinese){
this.chinese=chinese;
}
public int getChemistry(){
return chemistry;
}
public void setChemistry(int chemistry){
this.chemistry=chemistry;
}
public int getMathematics(){
return mathematics;
}
public void setMathematics(int mathematics){
this.mathematics=mathematics;
}
public int getHistory(){
return history;
}
public void setHistory(int history){
this.history=history;
}
public int getNumber(){
return number;
}
public void setNumber(int number){
this.number=number;
}
}
我的数据库是用的Navicat软件,可以运用触发器,更好的实现功能,当一个表改变的时候使另一个表也改变,不仅是删除,注册的时候也需要使用到。