java实现选课系统和课程管理

//javafx用jdk8
import javafx.application.*;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.geometry.*;
import java.sql.*;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.util.StringConverter;
import javafx.scene.control.*;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.ScrollPane.ScrollBarPolicy;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.text.*;
import javax.swing.JScrollPane;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.Date;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javafx.geometry.HPos;
public class CourseSelectionSystem extends Application{
	private static String driver="com.mysql.cj.jdbc.Driver";
	private static String url="jdbc:mysql://localhost:3306/courseselectsystem?serverTimezone=UTC";
	private static String user="root";
	private static String password="123456";
	@Override
	public void start(Stage primaryStage) throws Exception{
		Login login=new Login();
		login.start(new Stage());
	}
}
class Login extends Application
{
	private static String driver="com.mysql.cj.jdbc.Driver";
	private static String url="jdbc:mysql://localhost:3306/courseselectsystem?serverTimezone=UTC";
	private static String user="root";
	private static String password="123456";
	Connection conn=null;
	PreparedStatement ps=null;
	ResultSet rs=null;
	@Override
	public void start(Stage stage)
	{
		Alert alert=new Alert(AlertType.INFORMATION);
		alert.setTitle("提示");
		alert.setHeaderText(null);
		Text t=new Text("欢迎进入选课系统");
		t.setFont(new Font("黑体",20));
		StackPane spane=new StackPane();
		spane.getChildren().add(t);
		spane.setAlignment(Pos.CENTER);
		spane.setPadding(new Insets(80));
		Label labelogin=new Label("用户:");
		Label labelregister=new Label("密码:");
		TextField username=new TextField();
		username.setPromptText("学工号/学号");
		PasswordField passfield=new PasswordField();
		passfield.setPromptText("请输入密码");
		Button buttonlogin=new Button("登录");
		Button buttonregister=new Button("注册");
		Button buttonforget=new Button("忘记密码");
		HBox hboxuser=new HBox(10);
		hboxuser.getChildren().addAll(labelogin,username);
		HBox hboxpassword=new HBox(10);
		hboxpassword.getChildren().addAll(labelregister,passfield);
		HBox hboxbutton=new HBox(10);
		hboxbutton.getChildren().addAll(buttonlogin,buttonregister,buttonforget);
		hboxbutton.setTranslateX(45);
		hboxbutton.setTranslateY(10);
		VBox vb=new VBox(10);
		vb.setTranslateX(110);
		vb.setTranslateY(-30);
		vb.getChildren().addAll(hboxuser,hboxpassword,hboxbutton);
		BorderPane bpane=new BorderPane();
		bpane.setTop(spane);
		bpane.setCenter(vb);
		stage.setTitle("登录");
		Scene scene=new Scene(bpane,500,400);
		stage.setScene(scene);
		stage.show();
		buttonregister.setOnAction(event->{
			Register register=new Register();
			register.start(new Stage());
			stage.close();
		});
		buttonlogin.setOnAction(event->{
			if(username.getText().equals("")) {
				alert.setContentText("用户名不能为空!");
				alert.showAndWait();
			}else if(passfield.getText().equals("")) {
				alert.setContentText("密码不能为空!");
				alert.showAndWait();
			}else {
				String selectsql="select unum from users";
				try(
				Connection con=DriverManager.getConnection(url,user,password);
				Statement stmt=con.createStatement();
				ResultSet resultset=stmt.executeQuery(selectsql);
				) {
					boolean bool=true;
					Class.forName(driver);
					while(resultset.next()) {
						String num=resultset.getString("unum");
						if(username.getText().equals(num)) {
							String select="select upassword from users where unum=?";
							try {
								conn=DriverManager.getConnection(url,user,password);
								ps=conn.prepareStatement(select);
								ps.setString(1, num);
								rs=ps.executeQuery();
								while(rs.next()) {
								    String pw=rs.getString("upassword");
								    if(passfield.getText().equals(pw)) {
								    	stage.close();
								    	CourseSelect courseselect=new CourseSelect();
								    	courseselect.User=username.getText();
								    	courseselect.start(new Stage());
								    	ManagerMessage mm=new ManagerMessage();
								    	mm.User=username.getText();
								    	IdentityAuthentication ia=new IdentityAuthentication();
								    	ia.User=username.getText();
										break;
									}else {
										alert.setContentText("密码错误,请重新输入");
										alert.showAndWait();
										passfield.setText("");
									}
								}
								
							}catch(Exception e) {
								e.printStackTrace();
							}
							break;
						}else {
							bool=false;
						}
					}
					if(!bool) {
						alert.setContentText("没有该用户,请先注册!");
						alert.showAndWait();
						username.setText("");
					}
				}catch(Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
}
class Register extends Application
{
	private static String driver="com.mysql.cj.jdbc.Driver";
	private static String url="jdbc:mysql://localhost:3306/courseselectsystem?serverTimezone=UTC";
	private static String user="root";
	private static String password="123456";
	Connection conn=null;
	PreparedStatement ps=null;
	ResultSet rs=null;
	@Override
	public void start(Stage stage)
	{
		Alert alert=new Alert(AlertType.INFORMATION);
		alert.setTitle("提示");
		alert.setHeaderText(null);
		Text t=new Text("欢迎注册");
		t.setFont(new Font("黑体",20));
		StackPane spane=new StackPane();
		spane.getChildren().add(t);
		spane.setAlignment(Pos.CENTER);
		spane.setPadding(new Insets(50));
		Label labelogin=new Label("用   户:");
		Label labelregister=new Label("密   码:");
		TextField username=new TextField();
		username.setPromptText("学工号/学号");
		PasswordField passfield=new PasswordField();
		passfield.setPromptText("请输入密码");
		Label labeltel=new Label("电   话:");
		TextField telephone=new TextField();
		telephone.setPromptText("请输入电话");
		Label labelcode=new Label("验证码:");
		TextField code=new TextField();
		code.setPromptText("验证码");
		code.setPrefWidth(100);
		Label labelmail=new Label("邮   箱:");
		TextField mail=new TextField();
		mail.setPromptText("邮箱");
		Button buttoncode=new Button("获取验证码");
		buttoncode.setTextFill(Color.WHITE);
		buttoncode.setStyle("-fx-background-color:red");
		Button buttonregister=new Button("立即注册");
		buttonregister.setPrefWidth(200);
		buttonregister.setTranslateX(60);
		HBox hboxuser=new HBox(10);
		hboxuser.getChildren().addAll(labelogin,username);
		HBox hboxpassword=new HBox(10);
		hboxpassword.getChildren().addAll(labelregister,passfield);
		HBox hboxtel=new HBox(10);
		hboxtel.getChildren().addAll(labeltel,telephone);
		HBox hboxcode=new HBox(10);
		hboxcode.getChildren().addAll(labelcode,code,buttoncode);
		HBox hboxmail=new HBox(10);
		hboxmail.getChildren().addAll(labelmail,mail);
		VBox vb=new VBox(10);
		vb.setTranslateX(110);
		vb.setTranslateY(-30);
		vb.getChildren().addAll(hboxuser,hboxpassword,hboxtel,hboxcode,hboxmail,buttonregister);
		BorderPane bpane=new BorderPane();
		bpane.setTop(spane);
		bpane.setCenter(vb);
		stage.setTitle("注册");
		Scene scene=new Scene(bpane,500,400);
		stage.setScene(scene);
		stage.show();
		buttonregister.setOnAction(event->{
			if(username.getText().equals("")) {
				alert.setContentText("用户字段不能为空!");
				alert.showAndWait();
			}else if(passfield.getText().equals("")) {
				alert.setContentText("密码不能为空!");
				alert.showAndWait();
			}else if(mail.getText().equals("")) {
				alert.setContentText("邮箱不能为空!");
				alert.showAndWait();
			}else if(telephone.getText().equals("")) {
				alert.setContentText("电话不能为空!");
				alert.showAndWait();
			}else if(telephone.getText().length()!=11) {
				alert.setContentText("电话输入错误,请重新输入!");
				alert.showAndWait();
				telephone.setText("");
			}else if(passfield.getText().length()<6) {
				alert.setContentText("密码长度不能少于6位!");
				alert.showAndWait();
				passfield.setText("");
			}else {
				String insertsql="insert into users values(?,?,?,?)";
				try {
					Class.forName(driver);
					conn=DriverManager.getConnection(url,user,password);
					ps=conn.prepareStatement(insertsql);
					ps.setString(1, username.getText());
					ps.setString(2, passfield.getText());
					ps.setString(3, telephone.getText());
					ps.setString(4, mail.getText());
					ps.executeUpdate();
					alert.setContentText("注册成功!");
					alert.showAndWait();
					stage.close();
					Login login=new Login();
					login.start(new Stage());
				}catch(Exception e) {
					e.printStackTrace();
				}finally {
					try {
						if(ps!=null)ps.close();
						if(conn!=null)conn.close();
					}catch(Exception e) {
						e.printStackTrace();
					}
				}
			}
		});
		
	}
}
class CourseSelect extends Application
{
	private static String driver="com.mysql.cj.jdbc.Driver";
	private static String url="jdbc:mysql://localhost:3306/courseselectsystem?serverTimezone=UTC";
	private static String user="root";
	private static String password="123456";
	static int Num=0;
	static  boolean[] turn=new boolean[100];
	static boolean on=true;
	static String User;
	Connection conn=null;
	PreparedStatement ps=null;
	ResultSet rs=null;
	@Override
	public void start(Stage stage)
	{
		String selectcount="select count(*) from course";
		try (
			Connection conn=DriverManager.getConnection(url,user,password);
			Statement stmt=conn.createStatement();
			ResultSet resultset=stmt.executeQuery(selectcount);){
			Class.forName(driver);
			while(resultset.next()) {
				String strnum=resultset.getString("count(*)");
				int count=Integer.parseInt(strnum);
				Num=count;
			
			}
		}catch(Exception e) {
			e.printStackTrace();
		}
		Alert alert=new Alert(AlertType.INFORMATION);
		alert.setTitle("提示");
		alert.setHeaderText(null);
		BorderPane bpane=new BorderPane();
		bpane.setStyle("-fx-background-color:white");
		Text t=new Text("选课信息一体化服务平台");
		t.setFont(new Font("微软雅黑",23));
		t.setStyle("-fx-font-weight:bold");
		t.setFill(Color.WHITE);
		HBox hboxtop=new HBox(10);
		Button button=new Button("身份认证");
		Button buttonpassword=new Button("账号管理");
		Button buttonresult=new Button("信息维护");
		Button buttonuser=new Button("切换账号");
		Button buttonexit=new Button("退出系统");
		hboxtop.getChildren().addAll(button,buttonpassword,buttonresult,buttonuser,buttonexit);
		HBox hbox=new HBox(770);
		hbox.getChildren().addAll(t,hboxtop);
		hbox.setPadding(new Insets(20));
		hbox.setAlignment(Pos.CENTER);
		hbox.setStyle("-fx-background-color:red");
		HBox hboxtime=new HBox();
		hboxtime.setStyle("-fx-background-color:whitesmoke");
		hboxtime.setPadding(new Insets(5));
		hboxtime.setTranslateY(-10);
		Date now = new Date(); 
		SimpleDateFormat dateFormat = new SimpleDateFormat(" yyyy年MM月dd日        HH:mm:ss");
		String time = dateFormat.format( now );  
		Text texttime=new Text(time);
		hboxtime.getChildren().add(texttime);
		HBox hbtext=new HBox();
		Text te=new Text("在线选课");
		te.setFont(new Font("黑体",20));
		hbtext.getChildren().add(te);
		Button clear=new Button("重选");
		clear.setTranslateX(660);
		clear.setStyle("-fx-border-radius:20");
		HBox hbtextbutton=new HBox();
		hbtextbutton.getChildren().addAll(te,clear);
		hbtextbutton.setAlignment(Pos.CENTER);
		hbtextbutton.setStyle("-fx-background-color:whitesmoke");
		hbtextbutton.setPadding(new Insets(10));
		VBox vb=new VBox(10);
		Text text=new Text("以下课程最短选修6学分,最少选修4学分;最多选修3门,最少选修1门");
		text.setTranslateX(10);
		vb.getChildren().addAll(hbox,hboxtime,hbtextbutton,text);
		GridPane bp=new GridPane();
		bp.setPadding(new Insets(10));
		int number=100;
		VBox[] div=new VBox[number];
		Label[] course=new Label[number];
		Label[] coursestate=new Label[number];
		Label[] state=new Label[number];
		HBox[] hbox1=new HBox[number];
		HBox[] hbox2=new HBox[number];
		HBox[]hboxteacher=new HBox[number];
		Label[] teacher=new Label[number];
		Label[] teachername=new Label[number];
		HBox[] hboxlimit=new HBox[number];
		Label[] limitnum=new Label[number];
		Label[] num=new Label[number];
		HBox[] hboxselectnum=new HBox[number];
		Label[] selected=new Label[number];
		Label[] selectnum=new Label[number];
		HBox[] hboxcredit=new HBox[number];
		Label[] labelcredit=new Label[number];
		Label[] credit=new Label[number];		
		HBox[] hboxclass=new HBox[number];
		Label[] labelclass=new Label[number];
		Label[] cs=new Label[number];	
		HBox[] hboxperiod=new HBox[number];
		Label[] coursenature=new Label[number];
		Label[] nature=new Label[number];
		HBox[] hboxweekperiod=new HBox[number];
		HBox[] hboxnature=new HBox[number];		
		Label[] labeldivide=new Label[number];
		HBox[] hboxcampus=new HBox[number];
		HBox[] hboxdivide=new HBox[number];
		Label[] divide=new Label[number];	
		Label[] labelcountcredit=new Label[number];
		Label[] period=new Label[number];	
		Label[] labelweekperiod=new Label[number];
		Label[] weekperiod=new Label[number];	
		Label[] labelcampus=new Label[number];
		Label[] campus=new Label[number];		
		Label[] labeltimetable=new Label[number];
		Label[] timetable=new Label[number];	
		HBox[] hboxtimetable=new HBox[number];
		Label[] labelgrade=new Label[number];
		Label[] grade=new Label[number];
		HBox[] hboxgrade=new HBox[number];
		CheckBox[] chk=new CheckBox[number];
		VBox[] box1=new VBox[number];
		VBox[] box2=new VBox[number];
		VBox[] box3=new VBox[number];
		VBox[] box4=new VBox[number];
		VBox[] box5=new VBox[number];
		VBox[] box6=new VBox[number];
		for(int i=0;i<Num;i++) {
			div[i]=new VBox(10);
			div[i].setPadding(new Insets(20));
			div[i].setPrefWidth(1490);
			course[i]=new Label("");
			coursestate[i]=new Label("");
			coursestate[i].setText("/选课状态:");
			coursestate[i].setTranslateY(5);
			state[i]=new Label("");
			state[i].setText("可选");
			state[i].setTranslateY(5);
			coursestate[i].setFont(new Font("黑体",16));
			state[i].setFont(new Font("黑体",16));
			state[i].setTextFill(Color.GREEN);
			hbox1[i]=new HBox(5);
			hbox1[i].getChildren().addAll(course[i],coursestate[i],state[i]);
			course[i].setFont(new Font("黑体",24));
			course[i].setStyle("-fx-font-weight:bold");
			hbox2[i]=new HBox(60);
			teacher[i]=new Label("任课教师:");
			teachername[i]=new Label("");
			teachername[i].setTextFill(Color.BLUE);
			box1[i]=new VBox(10);
			hboxteacher[i]=new HBox(5);
			hboxteacher[i].getChildren().addAll(teacher[i],teachername[i]);
			limitnum[i]=new Label("限制人数:");
			num[i]=new Label("");		
			num[i].setTextFill(Color.BLUE);
			hboxlimit[i]=new HBox(5);
			hboxlimit[i].getChildren().addAll(limitnum[i],num[i]);
			selected[i]=new Label("已选人数:");
			selectnum[i]=new Label("");
			selectnum[i].setText("0");
			selectnum[i].setTextFill(Color.BLUE);
			hboxselectnum[i]=new HBox(5);
			hboxselectnum[i].getChildren().addAll(selected[i],selectnum[i]);
			labelcredit[i]=new Label("学分:");
			credit[i]=new Label("");		
			credit[i].setTextFill(Color.BLUE);
			hboxcredit[i]=new HBox(5);
			hboxcredit[i].getChildren().addAll(labelcredit[i],credit[i]);
			labelclass[i]=new Label("课程类别:");
			cs[i]=new Label("");		
			cs[i].setTextFill(Color.BLUE);
			hboxclass[i]=new HBox(5);
			hboxclass[i].getChildren().addAll(labelclass[i],cs[i]);
			coursenature[i]=new Label("课程性质:");
			nature[i]=new Label("");	
			nature[i].setTextFill(Color.BLUE);
			hboxnature[i]=new HBox(5);
			hboxnature[i].getChildren().addAll(coursenature[i],nature[i]);				
			chk[i]=new CheckBox();
			labeldivide[i]=new Label("学时分类:");
			divide[i]=new Label("");		
			divide[i].setTextFill(Color.BLUE);
			hboxdivide[i]=new HBox(5);
			hboxdivide[i].getChildren().addAll(labeldivide[i],divide[i]);
			labelcountcredit[i]=new Label("开课总学时:");
			period[i]=new Label("");			
			period[i].setTextFill(Color.BLUE);
			hboxperiod[i]=new HBox(5);
			hboxperiod[i].getChildren().addAll(labelcountcredit[i],period[i]);
			labelweekperiod[i]=new Label("周学时:");
			weekperiod[i]=new Label("");	
			weekperiod[i].setTextFill(Color.BLUE);
			hboxweekperiod[i]=new HBox(5);			
			hboxweekperiod[i].getChildren().addAll(labelweekperiod[i],weekperiod[i]);
			labelcampus[i]=new Label("开课校区:");
			campus[i]=new Label("");
			campus[i].setTextFill(Color.BLUE);
			hboxcampus[i]=new HBox(5);
			hboxcampus[i].getChildren().addAll(labelcampus[i],campus[i]);
			labeltimetable[i]=new Label("课表信息:");
			timetable[i]=new Label("");
			timetable[i].setTextFill(Color.BLUE);
			hboxtimetable[i]=new HBox(5);
			hboxtimetable[i].getChildren().addAll(labeltimetable[i],timetable[i]);
			labelgrade[i]=new Label("限选年级:");
			grade[i]=new Label("");
			hboxgrade[i]=new HBox(5);
			hboxgrade[i].getChildren().addAll(labelgrade[i],grade[i]);
			box1[i]=new VBox(10);
			box2[i]=new VBox(10);
			box3[i]=new VBox(10);
			box4[i]=new VBox(10);
			box5[i]=new VBox(10);
			box6[i]=new VBox(10);
			box1[i].getChildren().addAll(hboxteacher[i],hboxdivide[i]);
			box2[i].getChildren().addAll(hboxlimit[i],hboxperiod[i]);
			box3[i].getChildren().addAll(hboxselectnum[i],hboxweekperiod[i]);
			box4[i].getChildren().addAll(hboxcredit[i],hboxcampus[i]);
			box5[i].getChildren().addAll(hboxclass[i],hboxtimetable[i]);
			box6[i].getChildren().addAll(hboxnature[i],hboxgrade[i]);
			box1[i].setPrefWidth(130);
			box2[i].setPrefWidth(130);
			box3[i].setPrefWidth(120);
			box4[i].setPrefWidth(130);
			box5[i].setPrefWidth(310);
			box6[i].setPrefWidth(200);
			hbox2[i].getChildren().addAll(box1[i],box2[i],box3[i],box4[i],box5[i],box6[i],chk[i]);
			div[i].getChildren().addAll(hbox1[i],hbox2[i]);
			div[i].setStyle("-fx-border-style:solid inside;"+ "-fx-border-width:1;" +"-fx-border-insets:5;" 
					+ "-fx-border-radius:0;" + "-fx-border-color:lightgrey;");
			bp.add(div[i], 0, i);
		}
		try {
			int i=0;
			Class.forName(driver);
			String select="select * from course ";
			conn=DriverManager.getConnection(url,user,password);
			Statement stmt=conn.createStatement();
			rs=stmt.executeQuery(select);
			int n=i+1;
			String coursenum=String.valueOf(n);
			int ns=0;
			while(rs.next()) {
				String cname=rs.getString("cname");
				String steacher=rs.getString("teacher");
				String climit=rs.getString("climit");
				String scredit=rs.getString("credit");
				String coursetype=rs.getString("coursetype");
				String property=rs.getString("property");
				String sdivide=rs.getString("divide");
				String speriod=rs.getString("period");
				String sweekperiod=rs.getString("weekperiod");
				String site=rs.getString("site");
				String classtable=rs.getString("classtable");
				String sgrade=rs.getString("grade");
				course[i].setText(cname);
				teachername[i].setText(steacher);
				num[i].setText(climit);
				credit[i].setText(scredit);
				cs[i].setText(coursetype);
				nature[i].setText(property);
				divide[i].setText(sdivide);
				period[i].setText(speriod);
				weekperiod[i].setText(sweekperiod);
				campus[i].setText(site);
				timetable[i].setText(classtable);
				grade[i].setText(sgrade);
				i++;
			}
		}catch(Exception e) {
			e.printStackTrace();
		}
		HBox submit=new HBox(10);
		Button butsubmit=new Button("提交");
		butsubmit.setTextFill(Color.WHITE);
		butsubmit.setStyle("-fx-background-color:red");
		Button butsave=new Button("保存");
		butsave.setTextFill(Color.WHITE);
		butsave.setStyle("-fx-background-color:red");
		submit.getChildren().addAll(butsave,butsubmit);
		submit.setAlignment(Pos.BASELINE_RIGHT);
		submit.setTranslateX(-20);
		submit.setPadding(new Insets(10));
		ScrollPane sp = new ScrollPane();
		sp.setVmax(440);
        sp.setPrefSize(115, 150);
        sp.setContent(bp);
		StackPane spane=new StackPane();
		bp.setStyle("-fx-background-color: white");
	    spane.setStyle("-fx-border-style:solid inside;"+ "-fx-border-width:1;" +"-fx-border-insets:5;" 
					+ "-fx-border-radius:5;" + "-fx-border-color:black;");
	    spane.getChildren().add(sp);
		bpane.setTop(vb);
		bpane.setCenter(spane);
		bpane.setBottom(submit);
		stage.setTitle("选课");
		Scene scene=new Scene(bpane,1545,950);
		stage.setScene(scene);
		stage.show();
		button.setOnAction(event->{
			IdentityAuthentication ia=new IdentityAuthentication();
			ia.start(new Stage());
		});
		buttonpassword.setOnAction(event->{
			ManagerMessage mm=new ManagerMessage();
			mm.start(new Stage());
		});
		buttonresult.setOnAction(event->{
			stage.close();
			Administrator administrator=new Administrator();
			administrator.start(new Stage());
		});
		buttonuser.setOnAction(event->{
			stage.close();
			Login login=new Login();
			login.start(new Stage());
		});
		buttonexit.setOnAction(event->{
			Platform.exit();
		});
		int[] count=new int[100];
		String[] strcount=new String[100];
		for(int i=0;i<Num;i++) {
			count[i]=0;
			turn[i]=true;
			int n=i;
		     chk[i].selectedProperty().addListener(event->{
		    	 String cnum = null;
		    	 count[n]+=1;
		    	 strcount[n]=String.valueOf(count[n]);
		    	 try {
		    		String cnumsql="select cnum from course where cname=?";
					ps=conn.prepareStatement(cnumsql);
					ps.setString(1, course[n].getText());
					rs=ps.executeQuery();
					while(rs.next()) {
						 cnum=rs.getString("cnum");
					}

		    	 }catch(Exception e) {
		    		 e.printStackTrace();
		    	 }
		    	 if(turn[n]) {
						String table=timetable[n].getText();
						int tableindex=table.indexOf(";");
						table=table.substring(0,tableindex);
						try {	
							String selectsname="select sname from student where snum=?";
							conn=DriverManager.getConnection(url,user,password);
							ps=conn.prepareStatement(selectsname);
							ps.setString(1, User);
							rs=ps.executeQuery();
							while(rs.next()) {
								String sname=rs.getString("sname");
								if(sname==null) {
									chk[n].setSelected(false);
									alert.setContentText("请先进行身份认证!");
									alert.showAndWait();
									break;
								}else {
									int limitcount = 0;
									try {
										String selectlimit="select climit from course where cname=?";
										conn=DriverManager.getConnection(url,user,password);
										
										ps=conn.prepareStatement(selectlimit);
										ps.setString(1, course[n].getText());
										rs=ps.executeQuery();
										while(rs.next()) {
											limitcount=rs.getInt("climit");
										}
									}catch(Exception e) {
										e.printStackTrace();
									}
									if(count[n]<=limitcount) {
										try {
											selectnum[n].setText(strcount[n]);
											String insert="insert into courseselect values(?,?)";
											String selecttime="select course.classtable from course , courseselect where courseselect.cnum=course.cnum and courseselect.snum=?";
											String select="select cnum from courseselect where snum=?";
											String scount="select count(*) from courseselect";
											conn=DriverManager.getConnection(url,user,password);
											ps=conn.prepareStatement(scount);
											rs=ps.executeQuery();
											while(rs.next()) {
												if(rs.getString("count(*)").equals("0")) {													
													
													ps=conn.prepareStatement(insert);
													ps.setString(1, User);
													ps.setString(2, cnum);
													ps.executeUpdate();
												}else {
													ps=conn.prepareStatement(selecttime);
													ps.setString(1, User);
													rs=ps.executeQuery();
													while(rs.next()) {
														String classtable=rs.getString("classtable");
														int index=classtable.indexOf(";");
														String subclasstable=classtable.substring(0,index);
														if(subclasstable.equals(table)) {
															chk[n].setSelected(false);
															chk[n].setText("冲突");
															chk[n].setTextFill(Color.RED);
															break;
														}else {
															ps=conn.prepareStatement(insert);
															ps.setString(1, User);
															ps.setString(2, cnum);
															ps.executeUpdate();
															chk[n].setDisable(false);
															chk[n].setSelected(true);
															chk[n].setText("");
														}
													}
													
												}
											}
											
										}catch(Exception e) {
											e.printStackTrace();
										}
									}else {
										String lc=String.valueOf(limitcount);
										selectnum[n].setText(lc);
										chk[n].setSelected(false);
										chk[n].setDisable(true);
										chk[n].setText("已满");
										chk[n].setTextFill(Color.RED);
									}
								}
							}
						}catch(Exception e) {
							e.printStackTrace();
						}
						turn[n]=false;
					}else {
						count[n]=count[n]-2;
						strcount[n]=String.valueOf(count[n]);
						if(count[n]<=0) count[n]=0;
						String str=String.valueOf(strcount[n]);
						selectnum[n].setText(str);
						String sdelete="delete from courseselect where cnum=?";
						try {
							ps=conn.prepareStatement(sdelete);
							ps.setString(1, cnum);
							ps.executeUpdate();
						} catch (SQLException e) {
							e.printStackTrace();
						}
						turn[n]=true;
					}
		     });
		}
		clear.setOnAction(event->{
			for(int j=0;j<Num;j++) {
				chk[j].setSelected(false);
				chk[j].setText("");
				String sdelete="delete from courseselect where snum=?";
				try {
					ps=conn.prepareStatement(sdelete);
					ps.setString(1, User);
					ps.executeUpdate();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		});
		butsubmit.setOnAction(event->{
			 int n = JOptionPane.showConfirmDialog(null, "确认提交吗?提交之后无法修改", "确认对话框", JOptionPane.YES_NO_OPTION); 
			 if (n == JOptionPane.YES_OPTION){ 
				 clear.setDisable(true);
					for(int j=0;j<Num;j++) {
						chk[j].setDisable(true);
					}
				 JOptionPane.showMessageDialog(new JFrame(),"提交成功");
			    }
		});
		butsave.setOnAction(event->{
			alert.setContentText("保存成功!");
			alert.showAndWait();
		});
	}
}
class IdentityAuthentication extends Application
{
	private static String driver="com.mysql.cj.jdbc.Driver";
	private static String url="jdbc:mysql://localhost:3306/courseselectsystem?serverTimezone=UTC";
	private static String user="root";
	private static String password="123456";
	static String User,time;
	Connection conn=null;
	PreparedStatement ps=null;
	ResultSet rs=null;
	@Override
	public void start(Stage stage) {
		Alert alert=new Alert(AlertType.INFORMATION);
		alert.setTitle("提示");
		alert.setHeaderText(null);
		Text t=new Text("身份认证");
		t.setFont(new Font("黑体",20));
		StackPane spane=new StackPane();
		spane.getChildren().add(t);
		spane.setAlignment(Pos.CENTER);
		spane.setPadding(new Insets(50));
		Label labelnum=new Label("学   号:");
		Label labelname=new Label("姓   名:");
		Label labelsex=new Label("性   别:");
		Label labeldept=new Label("学   院:");
		TextField num=new TextField();
		num.setPromptText("学号");
		HBox hboxnum=new HBox(10);
		hboxnum.getChildren().addAll(labelnum,num);
		TextField name=new TextField();
		name.setPromptText("姓名");
		HBox hboxname=new HBox(10);
		hboxname.getChildren().addAll(labelname,name);
		RadioButton boy=new RadioButton("男");
		RadioButton girl=new RadioButton("女");
		girl.setTranslateX(10);
		ToggleGroup tog=new ToggleGroup();
		boy.setToggleGroup(tog);
		girl.setToggleGroup(tog);
		tog.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
	           @Override
	           public void changed(ObservableValue<? extends Toggle> ov, Toggle old_toggle, Toggle new_toggle) {
	               if (tog.getSelectedToggle() != null) {
	                   RadioButton button = (RadioButton) tog.getSelectedToggle();
	               }
	           }
	       });
		HBox hboxbirthday=new HBox(10);
		DatePicker checkInDatePicker;
        String pattern = "yyyy-MM-dd";
        Locale.setDefault(Locale.US);
        checkInDatePicker = new DatePicker();
        StringConverter converter = new StringConverter<LocalDate>() {
            DateTimeFormatter dateFormatter = 
                DateTimeFormatter.ofPattern(pattern);
            @Override
            public String toString(LocalDate date) {
                if (date != null) {
                	time=dateFormatter.format(date);
                    return dateFormatter.format(date);
                } else {
                    return "";
                }
            }
            @Override
            public LocalDate fromString(String string) {
                if (string != null && !string.isEmpty()) {
                    return LocalDate.parse(string, dateFormatter);
                } else {
                    return null;
                }
            }
        };             
        checkInDatePicker.setConverter(converter);
        checkInDatePicker.setPromptText(pattern.toLowerCase());
        GridPane gridPane = new GridPane();
        gridPane.setHgap(10);
        gridPane.setVgap(10);
        Label checkInlabel = new Label("生   日:");
        gridPane.add(checkInlabel, 0, 0);
        GridPane.setHalignment(checkInlabel, HPos.LEFT);
        gridPane.add(checkInDatePicker, 1, 0);
        hboxbirthday.getChildren().add(gridPane);
        checkInDatePicker.requestFocus();
        checkInDatePicker.setPrefWidth(200);
		HBox hboxsex=new HBox(10);
		hboxsex.getChildren().addAll(labelsex,boy,girl);
		TextField dept=new TextField();
		dept.setPromptText("学院");
		HBox hboxdept=new HBox(10);
		hboxdept.getChildren().addAll(labeldept,dept);
		Button button=new Button("提交");
		button.setPrefWidth(200);
		button.setTranslateX(60);
		VBox vb=new VBox(10);
		vb.setTranslateX(110);
		vb.setTranslateY(-30);
		vb.getChildren().addAll(hboxnum,hboxname,hboxsex,hboxbirthday,hboxdept,button);
		BorderPane bpane=new BorderPane();
		bpane.setTop(spane);
		bpane.setCenter(vb);
		stage.setTitle("身份认证");
		Scene scene=new Scene(bpane,500,400);
		stage.setScene(scene);
		stage.show();
		button.setOnAction(event->{
			if(num.getText().equals("")) {
				alert.setContentText("学号为必填字段,不能为空!");
				alert.showAndWait();
			}else if(name.getText().equals("")) {
				alert.setContentText("姓名为必填字段,不能为空!");
				alert.showAndWait();
			}else if(boy.getText().equals("")||girl.getText().equals("")){
				alert.setContentText("性别不能为空!");
				alert.showAndWait();
			}else if(dept.getText().equals("")) {
				alert.setContentText("学院为必填字段,不能为空!");
				alert.showAndWait();
			}else {
				  String strsex=null;
				  if(boy.isSelected()) {
						strsex=boy.getText();
					}
				   if(girl.isSelected()) {
					   strsex=girl.getText();
				   }
				String insertsql="update student set sname=?,sex=?,birthday=?,dept=? where snum=?";
				try {
					Class.forName(driver);
					conn=DriverManager.getConnection(url,user,password);
					ps=conn.prepareStatement(insertsql);
					ps.setString(1, name.getText());
					ps.setString(2, strsex);
					ps.setString(3, time);
					ps.setString(4, dept.getText());
					ps.setString(5, User);
					ps.executeUpdate();
					alert.setContentText("认证成功!");
					alert.showAndWait();
					stage.close();
				}catch(Exception e) {
					e.printStackTrace();
				}finally {
					try {
						if(ps!=null)ps.close();
						if(conn!=null)conn.close();
					}catch(Exception e) {
						e.printStackTrace();
					}
				}
			}
		});
	}
}
class ManagerMessage extends Application
{
	private static String driver="com.mysql.cj.jdbc.Driver";
	private static String url="jdbc:mysql://localhost:3306/courseselectsystem?serverTimezone=UTC";
	private static String user="root";
	private static String password="123456";
	static String User;
	Connection conn=null;
	PreparedStatement ps=null;
	ResultSet rs=null;
	@Override
	public void start(Stage stage)
	{
		Alert alert=new Alert(AlertType.INFORMATION);
		alert.setTitle("提示");
		alert.setHeaderText(null);
		Label lab1=new Label("修改密码");
		lab1.setFont(new Font("黑体",17));
		Label lab2=new Label("原密码:");
		lab2.setFont(new Font("黑体",15));
		Label lab3=new Label("新密码:");
		lab3.setFont(new Font("黑体",15));
		Label lab4=new Label("电话更改");
		lab4.setFont(new Font("黑体",17));
		Label lab5=new Label("原电话:");
		lab5.setFont(new Font("黑体",15));
		Label lab6=new Label("新电话:");
		lab6.setFont(new Font("黑体",15));
		PasswordField oldpf=new PasswordField();
		PasswordField newpf=new PasswordField();
		TextField oldtf=new TextField();
		TextField newtf=new TextField();
		oldpf.setPromptText("请输入原密码");
		newpf.setPromptText("请输入新密码");
		oldtf.setPromptText("请输入旧的电话号码");
		newtf.setPromptText("请输入新的电话号码");
		Button save=new Button("保存");
		Button cannel =new Button("取消");
		save.setPrefWidth(84);
		cannel.setPrefWidth(84);
		HBox hb1=new HBox(10);
		hb1.getChildren().addAll(lab2,oldpf);
		HBox hb2=new HBox(10);
		hb2.getChildren().addAll(lab3,newpf);
		VBox vb1=new VBox(10);
		vb1.getChildren().addAll(hb1,hb2);
		HBox hb3=new HBox(10);
		hb3.getChildren().addAll(lab5,oldtf);
		HBox hb4=new HBox(10);
		hb4.getChildren().addAll(lab6,newtf);
		VBox vb2=new VBox(10);
		vb2.getChildren().addAll(hb3,hb4);
		vb1.setTranslateX(20);
		vb2.setTranslateX(20);
		HBox hb5=new HBox(20);
		hb5.getChildren().addAll(save,cannel);
		hb5.setTranslateX(-170);
		GridPane gpane=new GridPane();
		gpane.add(lab1, 0, 0);
		gpane.add(vb1, 0, 1);
		gpane.add(lab4, 0, 2);
		gpane.add(vb2, 0, 3);
		gpane.add(hb5, 1, 4);
		gpane.setAlignment(Pos.CENTER);
		gpane.setTranslateX(70);
		gpane.setVgap(10);
		String select="select upassword,telephone from users where unum=?";
		String updatepf="update users set upassword=? where unum=?";
		String updatetf="update users set telephone=? where unum=?";
		save.setOnAction(e->{
			try {
				conn=DriverManager.getConnection(url,user,password);
				ps=conn.prepareStatement(select);
				Class.forName(driver);
				ps.setString(1, User);
				rs=ps.executeQuery();
				while(rs.next()) {				
					String strpassword=rs.getString("upassword");
					String strteltephone=rs.getString("telephone");				
					if(!oldpf.getText().equals("")) {
						if(oldpf.getText().equals(strpassword)) {
							ps=conn.prepareStatement(updatepf);
							ps.setString(1,newpf.getText());
							ps.setString(2, User);
							ps.executeUpdate();
							alert.setContentText("密码修改成功!");
							alert.showAndWait();
							oldpf.setText("");
							newpf.setText("");
							break;
						}else {
							alert.setContentText("原密码错误,请重新输入!");
							alert.showAndWait();
							oldpf.setText("");
							break;
						}
					}if(oldtf.getText().length()==11) {
						if(oldtf.getText().equals(strteltephone)) {
							ps=conn.prepareStatement(updatetf);
							ps.setString(1,newtf.getText());
							ps.setString(2, User);
							ps.executeUpdate();
							alert.setContentText("电话修改成功!");
							alert.showAndWait();
							oldtf.setText("");
							newtf.setText("");
							break;
						}else {
							alert.setContentText("原号码错误,请重新输入!");
							alert.showAndWait();
							oldpf.setText("");
							break;
						}	
					}if(oldpf.getText()==null&&newpf.getText()==null&&oldtf.getText()==null&&newtf.getText()==null) {
						alert.setContentText("修改的内容不能为空!");
						alert.showAndWait();
					}
				}
				
			}catch(Exception ex) {
				ex.printStackTrace();
			}
		});
		cannel.setOnAction(e->{
			stage.close();
		});
		stage.setTitle("修改信息");
		StackPane stack=new StackPane();
		stack.getChildren().add(gpane);
		Scene scene=new Scene(stack,500,400);
		stage.setScene(scene);
		stage.show();
	}
}
class Administrator extends Application
{
	private static String driver="com.mysql.cj.jdbc.Driver";
	private static String url="jdbc:mysql://localhost:3306/courseselectsystem?serverTimezone=UTC";
	private static String user="root";
	private static String password="123456";
	Connection conn=null;
	PreparedStatement ps=null;
	ResultSet rs=null;
	@Override
	public void start(Stage stage)
	{
		Alert alert=new Alert(AlertType.INFORMATION);
		alert.setTitle("提示");
		alert.setHeaderText(null);
		Text t=new Text("欢迎进入后台管理");
		t.setFont(new Font("黑体",20));
		StackPane spane=new StackPane();
		spane.getChildren().add(t);
		spane.setAlignment(Pos.CENTER);
		spane.setPadding(new Insets(80));
		Label labelogin=new Label("用户:");
		Label labelregister=new Label("密码:");
		TextField username=new TextField();
		username.setPromptText("请输入管理员账号");
		PasswordField passfield=new PasswordField();
		passfield.setPromptText("请输入密码");
		Button buttonlogin=new Button("登录");
		Button buttonregister=new Button("注册");
		Button buttonforget=new Button("忘记密码");
		HBox hboxuser=new HBox(10);
		hboxuser.getChildren().addAll(labelogin,username);
		HBox hboxpassword=new HBox(10);
		hboxpassword.getChildren().addAll(labelregister,passfield);
		HBox hboxbutton=new HBox(10);
		hboxbutton.getChildren().addAll(buttonlogin,buttonregister,buttonforget);
		hboxbutton.setTranslateX(45);
		hboxbutton.setTranslateY(10);
		VBox vb=new VBox(10);
		vb.setTranslateX(110);
		vb.setTranslateY(-30);
		vb.getChildren().addAll(hboxuser,hboxpassword,hboxbutton);
		BorderPane bpane=new BorderPane();
		bpane.setTop(spane);
		bpane.setCenter(vb);
		stage.setTitle("管理员登录");
		Scene scene=new Scene(bpane,500,400);
		stage.setScene(scene);
		stage.show();
		buttonregister.setOnAction(event->{
			Register register=new Register();
			register.start(new Stage());
			stage.close();
		});
		buttonlogin.setOnAction(event->{
			if(username.getText().equals("")) {
				alert.setContentText("用户名不能为空!");
				alert.showAndWait();
			}else if(passfield.getText().equals("")) {
				alert.setContentText("密码不能为空!");
				alert.showAndWait();
			}else {
				String select="select apassword from administrator where aname=?";
				try {
					conn=DriverManager.getConnection(url,user,password);
					ps=conn.prepareStatement(select);
					ps.setString(1, username.getText());
					rs=ps.executeQuery();
					while(rs.next()) {
					    String pw=rs.getString("apassword");
					    if(passfield.getText().equals(pw)) {
					    	stage.close();
					    	CourseSelectResult cs=new CourseSelectResult();
					    	cs.start(new Stage());
							break;
						}else {
							alert.setContentText("密码错误,请重新输入");
							alert.showAndWait();
							passfield.setText("");
						}
					}
					
				}catch(Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
}
class CourseSelectResult extends Application
{
	private static String driver="com.mysql.cj.jdbc.Driver";
	private static String url="jdbc:mysql://localhost:3306/courseselectsystem?serverTimezone=UTC";
	private static String user="root";
	private static String password="123456";
	static int Num=0;
	static  boolean[] turn=new boolean[100];
	static int index=0;
	Connection conn=null;
	PreparedStatement ps=null;
	ResultSet rs=null;
	@Override
	public void start(Stage stage)
	{
		String selectcount="select count(*) from course";
		try (
			Connection conn=DriverManager.getConnection(url,user,password);
			Statement stmt=conn.createStatement();
			ResultSet resultset=stmt.executeQuery(selectcount);){
			Class.forName(driver);
			while(resultset.next()) {
				String strnum=resultset.getString("count(*)");
				int count=Integer.parseInt(strnum);
				Num=count;
			
			}
		}catch(Exception e) {
			e.printStackTrace();
		}
		Alert alert=new Alert(AlertType.INFORMATION);
		alert.setTitle("提示");
		alert.setHeaderText(null);
		BorderPane bpane=new BorderPane();
		bpane.setStyle("-fx-background-color:white");
		Text t=new Text("选课信息一体化服务平台");
		t.setFont(new Font("微软雅黑",23));
		t.setStyle("-fx-font-weight:bold");
		t.setFill(Color.WHITE);
		HBox hboxtop=new HBox(10);
		Button add=new Button("增加课程");
		Button delete=new Button("删除课程");
		Button buttonexit=new Button("退出系统");
		hboxtop.getChildren().addAll(add,delete,buttonexit);
		HBox hbox=new HBox(770);
		hbox.getChildren().addAll(t,hboxtop);
		hbox.setPadding(new Insets(20));
		hbox.setAlignment(Pos.CENTER);
		hbox.setStyle("-fx-background-color:red");
		HBox hboxtime=new HBox();
		hboxtime.setStyle("-fx-background-color:whitesmoke");
		hboxtime.setPadding(new Insets(5));
		hboxtime.setTranslateY(-10);
		Date now = new Date(); 
		SimpleDateFormat dateFormat = new SimpleDateFormat(" yyyy年MM月dd日        HH:mm:ss");
		String time = dateFormat.format( now );  
		Text texttime=new Text(time);
		hboxtime.getChildren().add(texttime);
		HBox hbtext=new HBox();
		Text te=new Text("选课系统后台管理");
		te.setFont(new Font("黑体",20));
		hbtext.getChildren().add(te);
		Button clear=new Button("重选");
		HBox hb=new HBox(10);
		hb.getChildren().addAll(clear);
		hb.setTranslateX(630);
		HBox hbtextbutton=new HBox();
		hbtextbutton.getChildren().addAll(te,hb);
		hbtextbutton.setAlignment(Pos.CENTER);
		hbtextbutton.setStyle("-fx-background-color:whitesmoke");
		hbtextbutton.setPadding(new Insets(10));
		VBox vb=new VBox(10);
		Text text=new Text("以下课程最短选修6学分,最少选修4学分;最多选修3门,最少选修1门");
		text.setTranslateX(10);
		vb.getChildren().addAll(hbox,hboxtime,hbtextbutton,text);
		GridPane bp=new GridPane();
		bp.setPadding(new Insets(10));
		int number=100;
		VBox[] div=new VBox[number];
		Label[] course=new Label[number];
		HBox[] hbox1=new HBox[number];
		HBox[] hbox2=new HBox[number];
		HBox[]hboxteacher=new HBox[number];
		Label[] teacher=new Label[number];
		Label[] teachername=new Label[number];
		HBox[] hboxlimit=new HBox[number];
		Label[] limitnum=new Label[number];
		Label[] num=new Label[number];
		HBox[] hboxselectnum=new HBox[number];
		Label[] selected=new Label[number];
		Label[] selectnum=new Label[number];
		HBox[] hboxcredit=new HBox[number];
		Label[] labelcredit=new Label[number];
		Label[] credit=new Label[number];		
		HBox[] hboxclass=new HBox[number];
		Label[] labelclass=new Label[number];
		Label[] cs=new Label[number];	
		HBox[] hboxperiod=new HBox[number];
		Label[] coursenature=new Label[number];
		Label[] nature=new Label[number];
		HBox[] hboxweekperiod=new HBox[number];
		HBox[] hboxnature=new HBox[number];		
		Label[] labeldivide=new Label[number];
		HBox[] hboxcampus=new HBox[number];
		HBox[] hboxdivide=new HBox[number];
		Label[] divide=new Label[number];	
		Label[] labelcountcredit=new Label[number];
		Label[] period=new Label[number];	
		Label[] labelweekperiod=new Label[number];
		Label[] weekperiod=new Label[number];	
		Label[] labelcampus=new Label[number];
		Label[] campus=new Label[number];		
		Label[] labeltimetable=new Label[number];
		Label[] timetable=new Label[number];	
		HBox[] hboxtimetable=new HBox[number];
		Label[] labelgrade=new Label[number];
		Label[] grade=new Label[number];
		HBox[] hboxgrade=new HBox[number];
		CheckBox[] chk=new CheckBox[number];
		VBox[] box1=new VBox[number];
		VBox[] box2=new VBox[number];
		VBox[] box3=new VBox[number];
		VBox[] box4=new VBox[number];
		VBox[] box5=new VBox[number];
		VBox[] box6=new VBox[number];
		for(int i=0;i<Num;i++) {
			div[i]=new VBox(10);
			div[i].setPadding(new Insets(20));
			div[i].setPrefWidth(1490);
			course[i]=new Label("");
			hbox1[i]=new HBox(5);
			hbox1[i].getChildren().addAll(course[i]);
			course[i].setFont(new Font("黑体",24));
			course[i].setStyle("-fx-font-weight:bold");
			hbox2[i]=new HBox(60);
			teacher[i]=new Label("任课教师:");
			teachername[i]=new Label("");
			teachername[i].setTextFill(Color.BLUE);
			box1[i]=new VBox(10);
			hboxteacher[i]=new HBox(5);
			hboxteacher[i].getChildren().addAll(teacher[i],teachername[i]);
			limitnum[i]=new Label("限制人数:");
			num[i]=new Label("");		
			num[i].setTextFill(Color.BLUE);
			hboxlimit[i]=new HBox(5);
			hboxlimit[i].getChildren().addAll(limitnum[i],num[i]);
			selected[i]=new Label("已选人数:");
			selectnum[i]=new Label("");
			selectnum[i].setText("0");
			selectnum[i].setTextFill(Color.BLUE);
			hboxselectnum[i]=new HBox(5);
			hboxselectnum[i].getChildren().addAll(selected[i],selectnum[i]);
			labelcredit[i]=new Label("学分:");
			credit[i]=new Label("");		
			credit[i].setTextFill(Color.BLUE);
			hboxcredit[i]=new HBox(5);
			hboxcredit[i].getChildren().addAll(labelcredit[i],credit[i]);
			labelclass[i]=new Label("课程类别:");
			cs[i]=new Label("");		
			cs[i].setTextFill(Color.BLUE);
			hboxclass[i]=new HBox(5);
			hboxclass[i].getChildren().addAll(labelclass[i],cs[i]);
			coursenature[i]=new Label("课程性质:");
			nature[i]=new Label("");	
			nature[i].setTextFill(Color.BLUE);
			hboxnature[i]=new HBox(5);
			hboxnature[i].getChildren().addAll(coursenature[i],nature[i]);				
			chk[i]=new CheckBox();
			chk[i].setDisable(true);
			labeldivide[i]=new Label("学时分类:");
			divide[i]=new Label("");		
			divide[i].setTextFill(Color.BLUE);
			hboxdivide[i]=new HBox(5);
			hboxdivide[i].getChildren().addAll(labeldivide[i],divide[i]);
			labelcountcredit[i]=new Label("开课总学时:");
			period[i]=new Label("");			
			period[i].setTextFill(Color.BLUE);
			hboxperiod[i]=new HBox(5);
			hboxperiod[i].getChildren().addAll(labelcountcredit[i],period[i]);
			labelweekperiod[i]=new Label("周学时:");
			weekperiod[i]=new Label("");	
			weekperiod[i].setTextFill(Color.BLUE);
			hboxweekperiod[i]=new HBox(5);			
			hboxweekperiod[i].getChildren().addAll(labelweekperiod[i],weekperiod[i]);
			labelcampus[i]=new Label("开课校区:");
			campus[i]=new Label("");
			campus[i].setTextFill(Color.BLUE);
			hboxcampus[i]=new HBox(5);
			hboxcampus[i].getChildren().addAll(labelcampus[i],campus[i]);
			labeltimetable[i]=new Label("课表信息:");
			timetable[i]=new Label("");
			timetable[i].setTextFill(Color.BLUE);
			hboxtimetable[i]=new HBox(5);
			hboxtimetable[i].getChildren().addAll(labeltimetable[i],timetable[i]);
			labelgrade[i]=new Label("限选年级:");
			grade[i]=new Label("");
			hboxgrade[i]=new HBox(5);
			hboxgrade[i].getChildren().addAll(labelgrade[i],grade[i]);
			box1[i]=new VBox(10);
			box2[i]=new VBox(10);
			box3[i]=new VBox(10);
			box4[i]=new VBox(10);
			box5[i]=new VBox(10);
			box6[i]=new VBox(10);
			box1[i].getChildren().addAll(hboxteacher[i],hboxdivide[i]);
			box2[i].getChildren().addAll(hboxlimit[i],hboxperiod[i]);
			box3[i].getChildren().addAll(hboxselectnum[i],hboxweekperiod[i]);
			box4[i].getChildren().addAll(hboxcredit[i],hboxcampus[i]);
			box5[i].getChildren().addAll(hboxclass[i],hboxtimetable[i]);
			box6[i].getChildren().addAll(hboxnature[i],hboxgrade[i]);
			box1[i].setPrefWidth(130);
			box2[i].setPrefWidth(130);
			box3[i].setPrefWidth(120);
			box4[i].setPrefWidth(130);
			box5[i].setPrefWidth(310);
			box6[i].setPrefWidth(200);
			hbox2[i].getChildren().addAll(box1[i],box2[i],box3[i],box4[i],box5[i],box6[i],chk[i]);
			div[i].getChildren().addAll(hbox1[i],hbox2[i]);
			div[i].setStyle("-fx-border-style:solid inside;"+ "-fx-border-width:1;" +"-fx-border-insets:5;" 
					+ "-fx-border-radius:0;" + "-fx-border-color:lightgrey;");
			bp.add(div[i], 0, i);
		}
		try {
			int i=0;
			Class.forName(driver);
			String select="select * from course ";
			conn=DriverManager.getConnection(url,user,password);
			Statement stmt=conn.createStatement();
			rs=stmt.executeQuery(select);
			int n=i+1;
			String coursenum=String.valueOf(n);
			int ns=0;
			while(rs.next()) {
				String cname=rs.getString("cname");
				String steacher=rs.getString("teacher");
				String climit=rs.getString("climit");
				String scredit=rs.getString("credit");
				String coursetype=rs.getString("coursetype");
				String property=rs.getString("property");
				String sdivide=rs.getString("divide");
				String speriod=rs.getString("period");
				String sweekperiod=rs.getString("weekperiod");
				String site=rs.getString("site");
				String classtable=rs.getString("classtable");
				String sgrade=rs.getString("grade");
				course[i].setText(cname);
				teachername[i].setText(steacher);
				num[i].setText(climit);
				credit[i].setText(scredit);
				cs[i].setText(coursetype);
				nature[i].setText(property);
				divide[i].setText(sdivide);
				period[i].setText(speriod);
				weekperiod[i].setText(sweekperiod);
				campus[i].setText(site);
				timetable[i].setText(classtable);
				grade[i].setText(sgrade);
				i++;
			}
		}catch(Exception e) {
			e.printStackTrace();
		}
		HBox submit=new HBox(10);
		Button butall=new Button("全选");
		butall.setTextFill(Color.WHITE);
		butall.setStyle("-fx-background-color:red");
		Button butdel=new Button("删除");
		butdel.setTextFill(Color.WHITE);
		butdel.setStyle("-fx-background-color:red");
		submit.getChildren().addAll(butall,butdel);
		submit.setAlignment(Pos.BASELINE_RIGHT);
		submit.setTranslateX(-20);
		submit.setPadding(new Insets(10));
		ScrollPane sp = new ScrollPane();
		sp.setVmax(440);
        sp.setPrefSize(115, 150);
        sp.setContent(bp);
		StackPane spane=new StackPane();
		bp.setStyle("-fx-background-color: white");
	    spane.setStyle("-fx-border-style:solid inside;"+ "-fx-border-width:1;" +"-fx-border-insets:5;" 
					+ "-fx-border-radius:5;" + "-fx-border-color:black;");
	    spane.getChildren().add(sp);
		bpane.setTop(vb);
		bpane.setCenter(spane);
		bpane.setBottom(submit);
		stage.setTitle("后台管理");
		Scene scene=new Scene(bpane,1545,950);
		stage.setScene(scene);
		stage.show();
		delete.setOnAction(event->{
			for(int j=0;j<Num;j++) {
				chk[j].setDisable(false);
			}
			butall.setOnAction(E->{
				for(int j=0;j<Num;j++) {
					chk[j].setSelected(true);
					butdel.setDisable(false);
				}
			});
		});
		for(int i=0;i<Num;i++) {
			int k=i;
		     chk[i].setOnMouseClicked(E->{
		    	 index=k;
		     });
		}
		butdel.setOnAction(Event->{
			 int n = JOptionPane.showConfirmDialog(null, "确认删除吗?", "确认对话框", JOptionPane.YES_NO_OPTION); 
			 if (n == JOptionPane.YES_OPTION){ 
 				String sdelete="delete from course where cname=?";
 				try {
 					ps=conn.prepareStatement(sdelete);
 					ps.setString(1, course[index].getText());
 					ps.executeUpdate();
 				} catch (SQLException e) {
 					e.printStackTrace();
 				}
 				JOptionPane.showMessageDialog(new JFrame(),course[index].getText()+"已成功删除");
 				stage.close();
				CourseSelectResult cr=new CourseSelectResult();
				cr.start(new Stage());
			 }
		});
		add.setOnAction(event->{
			Add a=new Add();
			a.start(new Stage());
		});
		buttonexit.setOnAction(event->{
			stage.close();
		});
		clear.setOnAction(event->{
			for(int j=0;j<Num;j++) {
				chk[j].setSelected(false);
				chk[j].setText("");
				
			}
		});
	}
}
class Add extends Application
{
	private static String driver="com.mysql.cj.jdbc.Driver";
	private static String url="jdbc:mysql://localhost:3306/courseselectsystem?serverTimezone=UTC";
	private static String user="root";
	private static String password="123456";
	Connection conn=null;
	PreparedStatement ps=null;
	ResultSet rs=null;
	@Override 
	public void start(Stage stage) {
		Alert alert=new Alert(AlertType.INFORMATION);
		alert.setTitle("提示");
		alert.setHeaderText(null);
		Text t=new Text("添加课程");
		t.setFont(new Font("黑体",20));
		StackPane spane=new StackPane();
		spane.getChildren().add(t);
		spane.setAlignment(Pos.CENTER);
		spane.setPadding(new Insets(20));
		Label labecourse=new Label("科目名称:");
		TextField course=new TextField();
		HBox hboxcourse=new HBox(10);
		hboxcourse.getChildren().addAll(labecourse,course);
		Label labelteacher=new Label("任课教师:");
		TextField teacher=new TextField();
		HBox hboxteacher=new HBox(10);
		hboxteacher.getChildren().addAll(labelteacher,teacher);
		HBox hbox1=new HBox(30);
		hbox1.getChildren().addAll(hboxcourse,hboxteacher);
		Label labellimit=new Label("限选人数:");
		TextField limit=new TextField();
		HBox hboxlimit=new HBox(10);
		hboxlimit.getChildren().addAll(labellimit,limit);
		Label labelcredit=new Label("学       分:");
		TextField credit=new TextField();
		HBox hboxcredit=new HBox(10);
		hboxcredit.getChildren().addAll(labelcredit,credit);
		HBox hbox2=new HBox(30);
		hbox2.getChildren().addAll(hboxlimit,hboxcredit);
		Label labelclass=new Label("课程类别:");
		TextField tclass=new TextField();
		HBox hboxclass=new HBox(10);
		hboxclass.getChildren().addAll(labelclass,tclass);
		Label labelnature=new Label("课程性质:");
		TextField nature=new TextField();
		HBox hboxnature=new HBox(10);
		hboxnature.getChildren().addAll(labelnature,nature);
		HBox hbox3=new HBox(30);
		hbox3.getChildren().addAll(hboxclass,hboxnature);
		Label labeldivide=new Label("学时分类:");
		TextField divide=new TextField();
		HBox hboxdivide=new HBox(10);
		hboxdivide.getChildren().addAll(labeldivide,divide);
		Label labelperiod=new Label("开课学时:");
		TextField period=new TextField();
		HBox hboxperiod=new HBox(10);
		hboxperiod.getChildren().addAll(labelperiod,period);
		HBox hbox4=new HBox(30);
		hbox4.getChildren().addAll(hboxdivide,hboxperiod);
		Label labelweek=new Label("周 学 时 :");
		TextField week=new TextField();
		HBox hboxweek=new HBox(10);
		hboxweek.getChildren().addAll(labelweek,week);
		Label labelsite=new Label("开课校区:");
		TextField site=new TextField();
		HBox hboxsite=new HBox(10);
		hboxsite.getChildren().addAll(labelsite,site);
		HBox hbox5=new HBox(30);
		hbox5.getChildren().addAll(hboxweek,hboxsite);
		Label labeltable=new Label("课表信息:");
		TextField table=new TextField();
		HBox hboxtable=new HBox(10);
		hboxtable.getChildren().addAll(labeltable,table);
		Label labelgrade=new Label("限选年级:");
		TextField grade=new TextField();
		HBox hboxgrade=new HBox(10);
		hboxgrade.getChildren().addAll(labelgrade,grade);
		HBox hbox6=new HBox(30);
		hbox6.getChildren().addAll(hboxtable,hboxgrade);
		Button button=new Button("提交");
		button.setPrefWidth(200);
		button.setTranslateX(260);
		button.setTranslateY(-50);
		VBox vb=new VBox(10);
		vb.setTranslateX(50);
		vb.getChildren().addAll(hbox1,hbox2,hbox3,hbox4,hbox5,hbox6);
		BorderPane bpane=new BorderPane();
		bpane.setTop(spane);
		bpane.setCenter(vb);
		bpane.setBottom(button);
		stage.setTitle("添加课程");
		Scene scene=new Scene(bpane,700,400);
		stage.setScene(scene);
		stage.show();
		button.setOnAction(event->{
			if(course.getText().equals("")) {
				alert.setContentText("课程名称不能为空!");
				alert.showAndWait();
			}else if(teacher.getText().equals("")) {
				alert.setContentText("任课教师不能为空!");
				alert.showAndWait();
			}else if(limit.getText().equals("")) {
				alert.setContentText("限制人数不能为空!");
				alert.showAndWait();
			}else if(credit.getText().equals("")) {
				alert.setContentText("学分不能为空!");
				alert.showAndWait();
			}else if(tclass.getText().equals("")) {
				alert.setContentText("课程类别不能为空!");
				alert.showAndWait();
			}else if(nature.getText().equals("")) {
				alert.setContentText("课程性质不能为空!");
				alert.showAndWait();
			}else if(divide.getText().equals("")) {
				alert.setContentText("学时分类不能为空!");
				alert.showAndWait();
			}else if(period.getText().equals("")) {
				alert.setContentText("开课总学时不能为空!");
				alert.showAndWait();
			}else if(week.getText().equals("")) {
				alert.setContentText("周学时不能为空!");
				alert.showAndWait();
			}else if(site.getText().equals("")) {
				alert.setContentText("开课校区不能为空!");
				alert.showAndWait();
			}else if(table.getText().equals("")) {
				alert.setContentText("课表信息不能为空!");
				alert.showAndWait();
			}else if(grade.getText().equals("")) {
				alert.setContentText("限选年级不能为空!");
				alert.showAndWait();
			}else {
				String insertsql="insert into course values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
				String count="select count(*) from course";
				try {
					Class.forName(driver);
					conn=DriverManager.getConnection(url,user,password);
					Statement stmt=conn.createStatement();
					rs=stmt.executeQuery(count);
					String numbers = null;
					while(rs.next()) {
						numbers=rs.getString("count(*)");
						int number=Integer.parseInt(numbers);
						number+=1;
						numbers=String.valueOf(number);
					}
					
					ps=conn.prepareStatement(insertsql);
					ps.setString(1, numbers);
					ps.setString(2, course.getText());
					ps.setString(3, teacher.getText());
					String slimit=limit.getText();
					int Limit=Integer.parseInt(slimit);
					ps.setInt(4, Limit);
					ps.setInt(5, 0);
					String scredit=credit.getText();
					int Credit=Integer.parseInt(scredit);
					ps.setInt(6, Credit);
					ps.setString(7, tclass.getText());
					ps.setString(8, nature.getText());
					ps.setString(9, divide.getText());
					ps.setString(10, period.getText());
					ps.setString(11, week.getText());
					ps.setString(12, site.getText());
					ps.setString(13, table.getText());
					ps.setString(14, grade.getText());
					ps.executeUpdate();
					alert.setContentText("添加成功!");
					CourseSelectResult cr=new CourseSelectResult();
					cr.start(new Stage());
				}catch(Exception e) {
					e.printStackTrace();
				}finally {
					try {
						if(ps!=null)ps.close();
						if(conn!=null)conn.close();
					}catch(Exception e) {
						e.printStackTrace();
					}
				}
			}
		});
	}
}

/*
Navicat Premium Data Transfer

Source Server : 本地
Source Server Type : MySQL
Source Server Version : 80026
Source Host : localhost:3306
Source Schema : courseselectsystem

Target Server Type : MySQL
Target Server Version : 80026
File Encoding : 65001

Date: 31/05/2022 17:02:38
*/

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;


– Table structure for administrator


DROP TABLE IF EXISTS administrator;
CREATE TABLE administrator (
aname char(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
apassword char(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;


– Table structure for course


DROP TABLE IF EXISTS course;
CREATE TABLE course (
cnum char(9) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
cname char(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
teacher char(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
climit int(0) NULL DEFAULT NULL,
credit int(0) NULL DEFAULT NULL,
coursetype char(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
property char(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
divide char(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
period int(0) NULL DEFAULT NULL,
weekperiod int(0) NULL DEFAULT NULL,
site char(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
classtable char(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
grade char(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;


– Table structure for courseselect


DROP TABLE IF EXISTS courseselect;
CREATE TABLE courseselect (
snum char(9) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
cnum char(9) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;


– Table structure for student


DROP TABLE IF EXISTS student;
CREATE TABLE student (
snum char(9) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
sname char(12) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
sex char(2) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
birthday char(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
dept char(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
PRIMARY KEY (snum) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;


– Table structure for users


DROP TABLE IF EXISTS users;
CREATE TABLE users (
unum char(9) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
upassword char(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
telephone char(11) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
mail char(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
PRIMARY KEY (unum, telephone) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;

SET FOREIGN_KEY_CHECKS = 1;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值