commit a70e809e072592d7dadea974531c3aedc089e7d8 Author: hibobmaster Date: Tue Jul 25 06:53:57 2023 +0800 Publish the code diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..36201d7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,41 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ +backup/ +*.db +*.log + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..96fc890 --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,17 @@ + + + + + sqlite.xerial + true + org.sqlite.JDBC + jdbc:sqlite:C:\Users\BobMaster\IdeaProjects\StudentSystem\student.db + $ProjectFileDir$ + + + file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.40.1/org/xerial/sqlite-jdbc/3.40.1.0/sqlite-jdbc-3.40.1.0.jar + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..dd5e3ad --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml new file mode 100644 index 0000000..226e788 --- /dev/null +++ b/.idea/sqldialects.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.mvn/wrapper/maven-wrapper.jar b/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 0000000..c1dd12f Binary files /dev/null and b/.mvn/wrapper/maven-wrapper.jar differ diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..40ca015 --- /dev/null +++ b/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,2 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.5/apache-maven-3.8.5-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar \ No newline at end of file diff --git a/JavaStudentManageSystem.pdf b/JavaStudentManageSystem.pdf new file mode 100644 index 0000000..c3fbc4f Binary files /dev/null and b/JavaStudentManageSystem.pdf differ diff --git a/README.md b/README.md new file mode 100644 index 0000000..578f539 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +Java学生成绩管理系统课程设计 + +课设报告:[JavaStudentManageSystem.pdf](JavaStudentManageSystem.pdf) diff --git a/lib/SparseBitSet-1.2.jar b/lib/SparseBitSet-1.2.jar new file mode 100644 index 0000000..bdb6771 Binary files /dev/null and b/lib/SparseBitSet-1.2.jar differ diff --git a/lib/bootstrapfx-core-0.4.0.jar b/lib/bootstrapfx-core-0.4.0.jar new file mode 100644 index 0000000..56db4dc Binary files /dev/null and b/lib/bootstrapfx-core-0.4.0.jar differ diff --git a/lib/commons-codec-1.15.jar b/lib/commons-codec-1.15.jar new file mode 100644 index 0000000..f14985a Binary files /dev/null and b/lib/commons-codec-1.15.jar differ diff --git a/lib/commons-collections4-4.4.jar b/lib/commons-collections4-4.4.jar new file mode 100644 index 0000000..da06c3e Binary files /dev/null and b/lib/commons-collections4-4.4.jar differ diff --git a/lib/commons-compress-1.21.jar b/lib/commons-compress-1.21.jar new file mode 100644 index 0000000..4892334 Binary files /dev/null and b/lib/commons-compress-1.21.jar differ diff --git a/lib/commons-io-2.11.0.jar b/lib/commons-io-2.11.0.jar new file mode 100644 index 0000000..be507d9 Binary files /dev/null and b/lib/commons-io-2.11.0.jar differ diff --git a/lib/commons-math3-3.6.1.jar b/lib/commons-math3-3.6.1.jar new file mode 100644 index 0000000..0ff582c Binary files /dev/null and b/lib/commons-math3-3.6.1.jar differ diff --git a/lib/curvesapi-1.07.jar b/lib/curvesapi-1.07.jar new file mode 100644 index 0000000..2b05714 Binary files /dev/null and b/lib/curvesapi-1.07.jar differ diff --git a/lib/ikonli-core-12.2.0.jar b/lib/ikonli-core-12.2.0.jar new file mode 100644 index 0000000..ec29512 Binary files /dev/null and b/lib/ikonli-core-12.2.0.jar differ diff --git a/lib/ikonli-core-12.3.1.jar b/lib/ikonli-core-12.3.1.jar new file mode 100644 index 0000000..47baf5e Binary files /dev/null and b/lib/ikonli-core-12.3.1.jar differ diff --git a/lib/ikonli-materialdesign2-pack-12.2.0.jar b/lib/ikonli-materialdesign2-pack-12.2.0.jar new file mode 100644 index 0000000..ae3e6d4 Binary files /dev/null and b/lib/ikonli-materialdesign2-pack-12.2.0.jar differ diff --git a/lib/jackson-annotations-2.15.2.jar b/lib/jackson-annotations-2.15.2.jar new file mode 100644 index 0000000..f8799c3 Binary files /dev/null and b/lib/jackson-annotations-2.15.2.jar differ diff --git a/lib/jackson-core-2.14.1.jar b/lib/jackson-core-2.14.1.jar new file mode 100644 index 0000000..cc02583 Binary files /dev/null and b/lib/jackson-core-2.14.1.jar differ diff --git a/lib/jackson-core-2.15.2.jar b/lib/jackson-core-2.15.2.jar new file mode 100644 index 0000000..a0e7486 Binary files /dev/null and b/lib/jackson-core-2.15.2.jar differ diff --git a/lib/jackson-databind-2.15.2.jar b/lib/jackson-databind-2.15.2.jar new file mode 100644 index 0000000..86f9a86 Binary files /dev/null and b/lib/jackson-databind-2.15.2.jar differ diff --git a/lib/jackson-dataformat-xml-2.15.2.jar b/lib/jackson-dataformat-xml-2.15.2.jar new file mode 100644 index 0000000..480f6ea Binary files /dev/null and b/lib/jackson-dataformat-xml-2.15.2.jar differ diff --git a/lib/log4j-1.2-api-2.19.0.jar b/lib/log4j-1.2-api-2.19.0.jar new file mode 100644 index 0000000..baf6e41 Binary files /dev/null and b/lib/log4j-1.2-api-2.19.0.jar differ diff --git a/lib/log4j-api-2.18.0.jar b/lib/log4j-api-2.18.0.jar new file mode 100644 index 0000000..b4e933f Binary files /dev/null and b/lib/log4j-api-2.18.0.jar differ diff --git a/lib/log4j-api-2.19.0.jar b/lib/log4j-api-2.19.0.jar new file mode 100644 index 0000000..e55547d Binary files /dev/null and b/lib/log4j-api-2.19.0.jar differ diff --git a/lib/log4j-api-2.20.0.jar b/lib/log4j-api-2.20.0.jar new file mode 100644 index 0000000..29d1b52 Binary files /dev/null and b/lib/log4j-api-2.20.0.jar differ diff --git a/lib/log4j-core-2.20.0.jar b/lib/log4j-core-2.20.0.jar new file mode 100644 index 0000000..54dafcd Binary files /dev/null and b/lib/log4j-core-2.20.0.jar differ diff --git a/lib/poi-5.2.3.jar b/lib/poi-5.2.3.jar new file mode 100644 index 0000000..22b19a3 Binary files /dev/null and b/lib/poi-5.2.3.jar differ diff --git a/lib/poi-ooxml-5.2.3.jar b/lib/poi-ooxml-5.2.3.jar new file mode 100644 index 0000000..2daf4b0 Binary files /dev/null and b/lib/poi-ooxml-5.2.3.jar differ diff --git a/lib/poi-ooxml-lite-5.2.3.jar b/lib/poi-ooxml-lite-5.2.3.jar new file mode 100644 index 0000000..84412a2 Binary files /dev/null and b/lib/poi-ooxml-lite-5.2.3.jar differ diff --git a/lib/sqlite-jdbc-3.42.0.0.jar b/lib/sqlite-jdbc-3.42.0.0.jar new file mode 100644 index 0000000..aba4bb6 Binary files /dev/null and b/lib/sqlite-jdbc-3.42.0.0.jar differ diff --git a/lib/stax2-api-4.2.1.jar b/lib/stax2-api-4.2.1.jar new file mode 100644 index 0000000..28c6a08 Binary files /dev/null and b/lib/stax2-api-4.2.1.jar differ diff --git a/lib/woodstox-core-6.5.1.jar b/lib/woodstox-core-6.5.1.jar new file mode 100644 index 0000000..b22b384 Binary files /dev/null and b/lib/woodstox-core-6.5.1.jar differ diff --git a/lib/xmlbeans-5.1.1.jar b/lib/xmlbeans-5.1.1.jar new file mode 100644 index 0000000..b828ad3 Binary files /dev/null and b/lib/xmlbeans-5.1.1.jar differ diff --git a/mvnw b/mvnw new file mode 100644 index 0000000..8a8fb22 --- /dev/null +++ b/mvnw @@ -0,0 +1,316 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /usr/local/etc/mavenrc ] ; then + . /usr/local/etc/mavenrc + fi + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`\\unset -f command; \\command -v java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + if [ -n "$MVNW_REPOURL" ]; then + jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + else + jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + fi + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + if $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + else + wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + fi + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl -o "$wrapperJarPath" "$jarUrl" -f + else + curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f + fi + + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaClass=`cygpath --path --windows "$javaClass"` + fi + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + $MAVEN_DEBUG_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" \ + "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/mvnw.cmd b/mvnw.cmd new file mode 100644 index 0000000..1d8ab01 --- /dev/null +++ b/mvnw.cmd @@ -0,0 +1,188 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM https://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% ^ + %JVM_CONFIG_MAVEN_PROPS% ^ + %MAVEN_OPTS% ^ + %MAVEN_DEBUG_OPTS% ^ + -classpath %WRAPPER_JAR% ^ + "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ + %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%"=="on" pause + +if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% + +cmd /C exit /B %ERROR_CODE% diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..959125e --- /dev/null +++ b/pom.xml @@ -0,0 +1,86 @@ + + + 4.0.0 + + com.bobmaster + StudentSystem + 1.0-SNAPSHOT + StudentSystem + + + UTF-8 + 5.9.2 + + + + + org.openjfx + javafx-controls + 20 + + + org.openjfx + javafx-fxml + 20 + + + org.controlsfx + controlsfx + 11.1.2 + + + org.kordamp.ikonli + ikonli-javafx + 12.3.1 + + + org.junit.jupiter + junit-jupiter-api + ${junit.version} + test + + + org.junit.jupiter + junit-jupiter-engine + ${junit.version} + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.11.0 + + 20 + 20 + + + + org.openjfx + javafx-maven-plugin + 0.0.8 + + + + default-cli + + com.bobmaster.studentsystem/com.bobmaster.studentsystem.HelloApplication + + app + app + app + true + true + true + + + + + + + \ No newline at end of file diff --git a/src/main/java/com/bobmaster/studentsystem/Config.java b/src/main/java/com/bobmaster/studentsystem/Config.java new file mode 100644 index 0000000..1ab2071 --- /dev/null +++ b/src/main/java/com/bobmaster/studentsystem/Config.java @@ -0,0 +1,29 @@ +package com.bobmaster.studentsystem; +import com.bobmaster.studentsystem.util.GetCWD; +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +public class Config { + public static void SaveConfig(Object object) throws IOException { + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.writeValue(new File(GetCWD.getCWD() + "\\config.json"), object); + } + + public static Object LoadConfig(Class clazz) throws IOException { + File file = new File(GetCWD.getCWD() + "\\config.json"); + if (!file.exists()) { + Map map = new HashMap<>(); + map.put("backupPath", GetCWD.getCWD() + "\\backup"); + map.put("backupInterval", 60); + SaveConfig(map); + } + ObjectMapper objectMapper = new ObjectMapper(); + return objectMapper.readValue(file, clazz); + } + + +} diff --git a/src/main/java/com/bobmaster/studentsystem/Main.java b/src/main/java/com/bobmaster/studentsystem/Main.java new file mode 100644 index 0000000..9951557 --- /dev/null +++ b/src/main/java/com/bobmaster/studentsystem/Main.java @@ -0,0 +1,122 @@ +package com.bobmaster.studentsystem; + +import com.bobmaster.studentsystem.model.Student; +import com.bobmaster.studentsystem.util.DBUtil; +import com.bobmaster.studentsystem.util.ExportToExcel; +import com.bobmaster.studentsystem.util.GenerateRandomTime; +import com.bobmaster.studentsystem.util.Revoke; +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Scene; +import javafx.scene.control.TableView; +import javafx.scene.image.Image; +import javafx.scene.input.KeyCode; +import javafx.scene.layout.AnchorPane; +import javafx.stage.Stage; +import java.io.IOException; +import java.sql.SQLException; +import java.util.Map; +import java.util.Stack; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; + +import static java.util.concurrent.TimeUnit.SECONDS; + + +public class Main extends Application { + private Stage primaryStage; + private AnchorPane rootLayout; + private Scene scene; + // DbPath stack + public static Stack dbPathStack = new Stack<>(); + + public static final Logger logger = LogManager.getLogger(Main.class); + + @Override + public void start(Stage primaryStage) throws IOException { + this.primaryStage = primaryStage; + this.primaryStage.setTitle("学生管理系统"); + this.primaryStage.getIcons().add(new Image("file:src/main/resources/images/icon.png")); + initRootLayout(); + + Map map = (Map) Config.LoadConfig(Map.class); + + // Create Schedule backup task + ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); + scheduler.scheduleAtFixedRate(() -> { + try { + String dbPath = map.get("backupPath").toString() + "\\" + + GenerateRandomTime.Generate() + "\\student.db"; + DBUtil.dbBackup(dbPath); + logger.info("Regular Backup Success: " + dbPath); + } catch (SQLException e) { + throw new RuntimeException(e); + } + }, 0, Long.parseLong(map.get("backupInterval").toString()), SECONDS); + // close scheduler when RootLayout exit + primaryStage.setOnCloseRequest(event -> { + scheduler.shutdown(); + logger.info("Program Exit"); + }); + } + + private void initRootLayout() { + try { + FXMLLoader loader = new FXMLLoader(); + loader.setLocation(Main.class.getResource("RootLayout.fxml")); + rootLayout = loader.load(); + + // keybinding + initKeyBinding(); + + scene = new Scene(rootLayout); + primaryStage.setScene(scene); + primaryStage.setResizable(false); + primaryStage.show(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private void initKeyBinding() { + rootLayout.setOnKeyPressed(event -> { + // exit when press Ctrl+Q + if (event.isControlDown() && event.getCode().equals(KeyCode.Q)) { + try { + DBUtil.dbDisconnect(); + } catch (SQLException e) { + throw new RuntimeException(e); + } + logger.info("Program Exit"); + System.exit(0); + } + + // export to excel when press Ctrl+S + if (event.isControlDown() && event.getCode().equals(KeyCode.S)) { + ExportToExcel.exportToExcel(); + } + + // revoke when press Ctrl+Z + if (event.isControlDown() && event.getCode().equals(KeyCode.Z)) { + try { + TableView node = (TableView) scene.lookup("#studentTable"); + Revoke.revokeEdit(dbPathStack, node); + } catch (SQLException | ClassCastException e) { + e.printStackTrace(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + }); + } + + + public static void main(String[] args) throws SQLException{ + DBUtil.dbInit(); + launch(args); + } +} diff --git a/src/main/java/com/bobmaster/studentsystem/controller/AboutPage.java b/src/main/java/com/bobmaster/studentsystem/controller/AboutPage.java new file mode 100644 index 0000000..c6c7f69 --- /dev/null +++ b/src/main/java/com/bobmaster/studentsystem/controller/AboutPage.java @@ -0,0 +1,14 @@ +package com.bobmaster.studentsystem.controller; + +import javafx.fxml.FXML; +import javafx.scene.input.MouseEvent; +import javafx.scene.layout.AnchorPane; + +public class AboutPage { + @FXML + public AnchorPane aboutPagePane; + + public void handleHideAboutPage(MouseEvent mouseEvent) { + aboutPagePane.getScene().getWindow().hide(); + } +} diff --git a/src/main/java/com/bobmaster/studentsystem/controller/RootLayout.java b/src/main/java/com/bobmaster/studentsystem/controller/RootLayout.java new file mode 100644 index 0000000..9223c38 --- /dev/null +++ b/src/main/java/com/bobmaster/studentsystem/controller/RootLayout.java @@ -0,0 +1,298 @@ +package com.bobmaster.studentsystem.controller; + +import com.bobmaster.studentsystem.Main; +import com.bobmaster.studentsystem.model.Student; +import com.bobmaster.studentsystem.model.StudentDAO; +import com.bobmaster.studentsystem.util.*; +import javafx.collections.ObservableList; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.geometry.Insets; +import javafx.scene.Scene; +import javafx.scene.chart.PieChart; +import javafx.scene.control.*; +import javafx.scene.image.Image; +import javafx.scene.input.MouseEvent; +import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.GridPane; +import javafx.stage.FileChooser; +import javafx.stage.Stage; + +import java.io.File; +import java.io.IOException; +import java.sql.SQLException; + +public class RootLayout { + @FXML + public TextField nameText; + @FXML + public TextField idText; + @FXML + public TextField genderText; + @FXML + public TextField scoreText; + @FXML + public TableView studentTable; + @FXML + public TableColumn stuNameColumn; + @FXML + public TableColumn stuIdColumn; + @FXML + public TableColumn stuGenderColumn; + @FXML + public TableColumn stuScoreColumn; + @FXML + public PieChart scorePieChart; + + public void handleAboutPage(ActionEvent actionEvent) { + try { + FXMLLoader loader = new FXMLLoader(); + loader.setLocation(Main.class.getResource("AboutPage.fxml")); + AnchorPane root = loader.load(); + Stage stage = new Stage(); + stage.setTitle("关于"); + stage.getIcons().add(new Image("file:src/main/resources/images/icon.png")); + stage.setScene(new Scene(root)); + stage.show(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public void handleSettingPage(ActionEvent actionEvent) { + try { + FXMLLoader loader = new FXMLLoader(); + loader.setLocation(Main.class.getResource("SettingPage.fxml")); + AnchorPane root = loader.load(); + Stage stage = new Stage(); + stage.setTitle("设置"); + stage.getIcons().add(new Image("file:src/main/resources/images/setting.png")); + stage.setScene(new Scene(root)); + stage.show(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public void handleExit(ActionEvent actionEvent) { + Main.logger.info("Program Exit"); + System.exit(0); + } + + public void handleExportToExcel(ActionEvent actionEvent) { + ExportToExcel.exportToExcel(); + } + + // initialize the controller class + @FXML + public void initialize() { + // initialize the student table with the four columns + stuNameColumn.setCellValueFactory(cellData -> cellData.getValue().studentNameProperty()); + stuIdColumn.setCellValueFactory(cellData -> cellData.getValue().studentIdProperty()); + stuGenderColumn.setCellValueFactory(cellData -> cellData.getValue().studentGenderProperty()); + stuScoreColumn.setCellValueFactory(cellData -> cellData.getValue().studentScoreProperty().asObject()); + try { + ObservableList studentData = StudentDAO.searchStudents(); + populateStudents(studentData); + // PieChart + UpdatePieChart.updatePieChart(scorePieChart); + } catch (SQLException | IOException e) { + e.printStackTrace(); + } + + } + + // populate the student table with the data + private void populateStudents(ObservableList studentData) { + studentTable.setItems(studentData); + } + + // Insert a student + @FXML + public void handleAddStudent(MouseEvent mouseEvent) throws SQLException{ + // if all the text fields are not empty + if (!nameText.getText().isEmpty() && !idText.getText().isEmpty() + && !genderText.getText().isEmpty() && !scoreText.getText().isEmpty()) { + // check if the student Score is a number + try { + Double.parseDouble(scoreText.getText()); + // if the student id is not in the database + if (StudentDAO.searchStudent(idText.getText()) == null) { + try { + // backup the database + String DbPath = GetCWD.getCWD() + "\\backup\\" + GenerateRandomTime.Generate() + ".db"; + Main.dbPathStack.push(DbPath); + DBUtil.dbBackup(DbPath); + StudentDAO.insertStudent(nameText.getText(), + genderText.getText(), + idText.getText(), + Double.parseDouble(scoreText.getText())); + // clear the text fields + nameText.clear(); + genderText.clear(); + idText.clear(); + scoreText.clear(); + Main.logger.info("成功添加学生-" + nameText.getText()); + ShowMessage.showAlert(Alert.AlertType.INFORMATION, "成功", "添加学生数据成功!"); + // PieChart + UpdatePieChart.updatePieChart(scorePieChart); + } catch (SQLException | IOException e) { + Main.logger.error("添加学生数据失败!"); + ShowMessage.showErrorAlert("错误", "添加学生数据失败!"); + e.printStackTrace(); + } + + ObservableList studentData = StudentDAO.searchStudents(); + populateStudents(studentData); + } else { + // if the student id is in the database + ShowMessage.showErrorAlert("错误", "该学号已存在!"); + } + } catch (NumberFormatException e) { + ShowMessage.showErrorAlert("错误", "成绩必须为数字!"); + } + } else { + // if any of the text fields is empty + ShowMessage.showErrorAlert("错误", "请填写完整!"); + } + } + + // Delete a student + @FXML + public void handleDeleteStudent(MouseEvent mouseEvent) { + Student selectedStudent = studentTable.getSelectionModel().getSelectedItem(); + if (selectedStudent != null) { + try { + // backup the database + String DbPath = GetCWD.getCWD() + "\\backup\\" + GenerateRandomTime.Generate() + ".db"; + Main.dbPathStack.push(DbPath); + DBUtil.dbBackup(DbPath); + StudentDAO.deleteStudent(selectedStudent.getStudentId()); + Main.logger.info("成功删除学生-" + selectedStudent.getName()); + ShowMessage.showAlert(Alert.AlertType.INFORMATION, "成功", "学生" + + selectedStudent.getName() + "的数据删除成功!"); + // PieChart + UpdatePieChart.updatePieChart(scorePieChart); + } catch (SQLException | IOException e) { + Main.logger.error("删除学生数据失败!"); + ShowMessage.showErrorAlert("错误", "删除学生数据失败!"); + e.printStackTrace(); + } + + try { + ObservableList studentData = StudentDAO.searchStudents(); + populateStudents(studentData); + } catch (SQLException e) { + ShowMessage.showErrorAlert("错误", e.getMessage()); + e.printStackTrace(); + } + + } else { + ShowMessage.showErrorAlert("错误", "请选择要删除的学生!"); + } + } + + // Update a student + @FXML + public void handleUpdateStudent(MouseEvent mouseEvent) { + Student selectedStudent = studentTable.getSelectionModel().getSelectedItem(); + if (selectedStudent != null) { + Dialog dialog = new Dialog<>(); + dialog.setTitle("信息修改"); + + ButtonType modifyButtonType = new ButtonType("修改", ButtonBar.ButtonData.OK_DONE); + dialog.getDialogPane().getButtonTypes().addAll(modifyButtonType, ButtonType.CANCEL); + + GridPane gridPane = new GridPane(); + gridPane.setPadding(new Insets(10)); + gridPane.setHgap(10); + gridPane.setVgap(10); + + TextField nameTextField = new TextField(selectedStudent.getName()); + nameTextField.setDisable(true); + TextField genderTextField = new TextField(selectedStudent.getGender()); + genderTextField.setDisable(true); + TextField studentIdTextField = new TextField(selectedStudent.getStudentId()); + studentIdTextField.setDisable(true); + TextField scoreTextField = new TextField(Double.toString(selectedStudent.getScore())); + + gridPane.add(new Label("Name:"), 0, 0); + gridPane.add(nameTextField, 1, 0); + gridPane.add(new Label("Gender:"), 0, 1); + gridPane.add(genderTextField, 1, 1); + gridPane.add(new Label("Student ID:"), 0, 2); + gridPane.add(studentIdTextField, 1, 2); + gridPane.add(new Label("Score:"), 0, 3); + gridPane.add(scoreTextField, 1, 3); + + dialog.getDialogPane().setContent(gridPane); + + dialog.setResultConverter(dialogButton -> { + if (dialogButton == modifyButtonType) { + selectedStudent.setScore(Double.parseDouble(scoreTextField.getText())); + try { + // backup the database + String DbPath = GetCWD.getCWD() + "\\backup\\" + GenerateRandomTime.Generate() + ".db"; + Main.dbPathStack.push(DbPath); + DBUtil.dbBackup(DbPath); + // update the student score + StudentDAO.updateScore(selectedStudent.getStudentId(), selectedStudent.getScore()); + Main.logger.info("学生" + selectedStudent.getName() + "的成绩被修改为: " + + selectedStudent.getScore()); + // PieChart + UpdatePieChart.updatePieChart(scorePieChart); + } catch (SQLException | IOException e) { + throw new RuntimeException(e); + } + return selectedStudent; + } + return null; + }); + + dialog.showAndWait().ifPresent(result -> { + studentTable.refresh(); + }); + } + } + + // handle Revoke + @FXML + public void handleRevoke(ActionEvent actionEvent) { + try { + Revoke.revokeEdit(Main.dbPathStack, studentTable); + + } catch (SQLException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + // restore DB + public void handleRestoreDB(ActionEvent actionEvent) { + FileChooser fileChooser = new FileChooser(); + fileChooser.setTitle("选择数据库文件"); + fileChooser.getExtensionFilters().addAll( + new FileChooser.ExtensionFilter("DB Files", "*.db") + ); + fileChooser.setInitialDirectory(new File(GetCWD.getCWD() + "\\backup\\")); + File file = fileChooser.showOpenDialog(null); + if (file != null) { + try { + DBUtil.dbRestore(file.getAbsolutePath()); + Main.logger.info("成功恢复数据库"); + ShowMessage.showAlert(Alert.AlertType.INFORMATION, "成功", "数据库恢复成功!"); + + ObservableList studentData = StudentDAO.searchStudents(); + populateStudents(studentData); + // PieChart + UpdatePieChart.updatePieChart(scorePieChart); + } catch (IOException | SQLException e) { + Main.logger.error("数据库恢复失败"); + ShowMessage.showErrorAlert("错误", "数据库恢复失败!"); + e.printStackTrace(); + } + } + } +} diff --git a/src/main/java/com/bobmaster/studentsystem/controller/SettingPageLayout.java b/src/main/java/com/bobmaster/studentsystem/controller/SettingPageLayout.java new file mode 100644 index 0000000..5f60c01 --- /dev/null +++ b/src/main/java/com/bobmaster/studentsystem/controller/SettingPageLayout.java @@ -0,0 +1,51 @@ +package com.bobmaster.studentsystem.controller; + +import com.bobmaster.studentsystem.Config; +import com.bobmaster.studentsystem.util.ShowMessage; +import javafx.fxml.FXML; +import javafx.scene.control.Alert; +import javafx.scene.control.TextField; +import javafx.scene.input.MouseEvent; +import javafx.stage.DirectoryChooser; + +import java.io.File; +import java.io.IOException; +import java.util.Map; + +public class SettingPageLayout { + @FXML + public TextField backUpPathText; + + @FXML + public TextField backUpIntervalText; + + @FXML + public Map map = null; + + @FXML + public void initialize() throws IOException { + map = (Map) Config.LoadConfig(Map.class); + backUpPathText.setText(map.get("backupPath").toString()); + backUpIntervalText.setText(map.get("backupInterval").toString()); + } + + @FXML + public void handleSettingBackUpPath(MouseEvent mouseEvent) { + // popup a directory chooser dialog + DirectoryChooser directoryChooser = new DirectoryChooser(); + directoryChooser.setTitle("选择备份路径"); + File file = directoryChooser.showDialog(null); + if (file != null) { + backUpPathText.setText(file.getAbsolutePath()); + } + } + + @FXML + public void handleSettingSave(MouseEvent mouseEvent) throws IOException { + map.put("backupPath", backUpPathText.getText()); + map.put("backupInterval", Integer.parseInt(backUpIntervalText.getText())); + Config.SaveConfig(map); + ShowMessage.showAlert(Alert.AlertType.INFORMATION, "保存成功", "定时任务间隔重启生效"); + backUpPathText.getScene().getWindow().hide(); + } +} diff --git a/src/main/java/com/bobmaster/studentsystem/model/Student.java b/src/main/java/com/bobmaster/studentsystem/model/Student.java new file mode 100644 index 0000000..58c209f --- /dev/null +++ b/src/main/java/com/bobmaster/studentsystem/model/Student.java @@ -0,0 +1,68 @@ +package com.bobmaster.studentsystem.model; +import javafx.beans.property.*; +public class Student { + // Declare Students Table Columns + private final StringProperty name; + private final StringProperty gender; + private final StringProperty studentId; + private final DoubleProperty score; + + // Constructor + public Student() { + this.name = new SimpleStringProperty(); + this.gender = new SimpleStringProperty(); + this.studentId = new SimpleStringProperty(); + this.score = new SimpleDoubleProperty(); + } + + // name + public String getName() { + return name.get(); + } + + public void setName(String name) { + this.name.set(name); + } + + public StringProperty studentNameProperty() { + return name; + } + // gender + public String getGender() { + return gender.get(); + } + + public void setGender(String gender) { + this.gender.set(gender); + } + + public StringProperty studentGenderProperty() { + return gender; + } + + // studentId + public String getStudentId() { + return studentId.get(); + } + + public void setStudentId(String studentId) { + this.studentId.set(studentId); + } + + public StringProperty studentIdProperty() { + return studentId; + } + + // score + public double getScore() { + return score.get(); + } + + public void setScore(double score) { + this.score.set(score); + } + + public DoubleProperty studentScoreProperty() { + return score; + } +} diff --git a/src/main/java/com/bobmaster/studentsystem/model/StudentDAO.java b/src/main/java/com/bobmaster/studentsystem/model/StudentDAO.java new file mode 100644 index 0000000..2c66bcf --- /dev/null +++ b/src/main/java/com/bobmaster/studentsystem/model/StudentDAO.java @@ -0,0 +1,138 @@ +package com.bobmaster.studentsystem.model; + +import com.bobmaster.studentsystem.util.DBUtil; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; + +import java.sql.*; + +public class StudentDAO { + // ******************************* + // select a student + // ******************************* + public static Student searchStudent(String studentId) throws SQLException { + // Declare a SELECT statement + String selectStmt = "SELECT * FROM student WHERE studentId = '" + studentId + "'"; + + // Execute SELECT statement + try { + // Get ResultSet from dbExecuteQuery method + ResultSet rsStudent = DBUtil.dbExecuteQuery(selectStmt); + + // Return student object + return getStudentFromResultSet(rsStudent); + } catch (SQLException e) { + System.out.println("While searching a student with " + studentId + " id, an error occurred: " + e); + // Return exception + throw e; + } + } + + // use ResultSet from DB as parameter and set Student Object's attributes and return student object. + private static Student getStudentFromResultSet(ResultSet rs) throws SQLException { + Student stu = null; + if (rs.next()) { + stu = new Student(); + stu.setName(rs.getString("name")); + stu.setGender(rs.getString("gender")); + stu.setStudentId(rs.getString("studentId")); + stu.setScore(rs.getDouble("score")); + } + return stu; + } + + // ******************************* + // select all students + // ******************************* + public static ObservableList searchStudents() throws SQLException { + // Declare a SELECT statement + String selectStmt = "SELECT * FROM student"; + + // Execute SELECT statement + try { + // Get ResultSet from dbExecuteQuery method + ResultSet rsStudents = DBUtil.dbExecuteQuery(selectStmt); + // Send ResultSet to the getStudentList method and get student object + ObservableList studentList = getStudentList(rsStudents); + + // Return student object + return studentList; + } catch (SQLException e) { + System.out.println("SQL select operation has been failed: " + e); + // Return exception + throw e; + } + } + + // Select * from students operation + private static ObservableList getStudentList(ResultSet rs) throws SQLException { + ObservableList studentList = FXCollections.observableArrayList(); + while (rs.next()) { + Student stu = new Student(); + stu.setName(rs.getString("name")); + stu.setGender(rs.getString("gender")); + stu.setStudentId(rs.getString("studentId")); + stu.setScore(rs.getDouble("score")); + // Add student to the ObservableList + studentList.add(stu); + } + return studentList; + } + + // ******************************* + // insert a student + // ******************************* + public static void insertStudent(String name, String gender, String studentId, double score) throws SQLException { + // Declare a Insert statement + String insertStmt = + "INSERT INTO student\n" + + "(name, gender, studentId, score)\n" + + "VALUES\n" + + "('"+name+"',"+"'"+gender+"',"+"'"+studentId+"',"+score+");"; + // Execute INSERT operation + try { + DBUtil.dbExecuteUpdate(insertStmt); + } catch (SQLException e) { + System.out.print("Error occurred while INSERT Operation: " + e); + throw e; + } + } + + // ******************************* + // update a student + // ******************************* + public static void updateScore(String studentId, double score) throws SQLException { + // Declare a UPDATE statement + String updateStmt = + "BEGIN TRANSACTION;\n" + + "UPDATE student\n" + + "SET score = "+score+"\n" + + "WHERE studentId = '"+studentId+"';\n" + + "COMMIT;"; + // Execute UPDATE operation + try { + DBUtil.dbExecuteUpdate(updateStmt); + } catch (SQLException e) { + System.out.print("Error occurred while UPDATE Operation: " + e); + throw e; + } + } + + // ******************************* + // delete a student + // ******************************* + public static void deleteStudent(String studentId) throws SQLException{ + // Declare a DELETE statement + String deleteStmt = + "BEGIN TRANSACTION;\n" + + "DELETE FROM student\n" + + "WHERE studentId = '"+studentId+"';\n" + + "COMMIT;"; + // Execute DELETE operation + try { + DBUtil.dbExecuteUpdate(deleteStmt); + } catch (SQLException e) { + System.out.print("Error occurred while DELETE Operation: " + e); + } + } +} diff --git a/src/main/java/com/bobmaster/studentsystem/util/DBUtil.java b/src/main/java/com/bobmaster/studentsystem/util/DBUtil.java new file mode 100644 index 0000000..a118501 --- /dev/null +++ b/src/main/java/com/bobmaster/studentsystem/util/DBUtil.java @@ -0,0 +1,113 @@ +package com.bobmaster.studentsystem.util; +import java.io.File; +import java.sql.*; +public class DBUtil { + // Declare sqlite3 URL + private static final String DB_URL = "jdbc:sqlite:student.db"; + + // Connection + private static Connection conn = null; + + // Connect to database + public static void dbConnect() throws SQLException { + try { + conn = DriverManager.getConnection(DB_URL); + } catch (SQLException e) { + System.out.println("Connection failed: " + e.getMessage()); + throw e; + } + } + + // Close connection + public static void dbDisconnect() throws SQLException { + try { + if (conn != null && !conn.isClosed()) { + conn.close(); + } + } catch (SQLException e) { + System.out.println("Disconnection failed: " + e.getMessage()); + throw e; + } + } + + // DB Execute Query Operation + public static ResultSet dbExecuteQuery(String queryStmt) throws SQLException { + Statement stmt = null; + ResultSet resultSet = null; + try { + dbConnect(); + stmt = conn.createStatement(); + resultSet = stmt.executeQuery(queryStmt); + } catch (SQLException e) { + System.out.println("Problem occurred at executeQuery operation: " + e.getMessage()); + throw e; + } + return resultSet; + } + + // DB Execute Update Operation (For Update/Insert/Delete) + public static void dbExecuteUpdate(String sqlStmt) throws SQLException { + Statement stmt = null; + try { + dbConnect(); + stmt = conn.createStatement(); + stmt.executeUpdate(sqlStmt); + } catch (SQLException e) { + System.out.println("Problem occurred at executeUpdate operation: " + e.getMessage()); + throw e; + } + } + + // DB initialize + public static void dbInit() throws SQLException { + Statement stmt = null; + try { + dbConnect(); + stmt = conn.createStatement(); + stmt.execute("CREATE TABLE IF NOT EXISTS student (" + + "id INTEGER PRIMARY KEY AUTOINCREMENT," + + "name TEXT," + + "gender TEXT," + + "studentId TEXT," + + "score REAL"+ + ");" + ); + } catch (SQLException e) { + System.out.println("Problem occurred at dbInit operation: " + e.getMessage()); + throw e; + } + } + + // DB backup + public static void dbBackup(String path) throws SQLException { + // check if directory exists, if not create it + String dir = path.substring(0, path.lastIndexOf("\\")); + File file = new File(dir); + if (!file.exists()) { + file.mkdirs(); + } + + Statement stmt = null; + try { + dbConnect(); + stmt = conn.createStatement(); + stmt.execute("backup to " + path); + } catch (SQLException e) { + System.out.println("Problem occurred at dbBackup operation: " + e.getMessage()); + throw e; + } + } + + // DB restore + public static void dbRestore(String path) throws SQLException { + Statement stmt = null; + try { + dbConnect(); + stmt = conn.createStatement(); + stmt.execute("restore from " + path); + } catch (SQLException e) { + System.out.println("Problem occurred at dbRestore operation: " + e.getMessage()); + throw e; + } + } +} diff --git a/src/main/java/com/bobmaster/studentsystem/util/ExportToExcel.java b/src/main/java/com/bobmaster/studentsystem/util/ExportToExcel.java new file mode 100644 index 0000000..97ae611 --- /dev/null +++ b/src/main/java/com/bobmaster/studentsystem/util/ExportToExcel.java @@ -0,0 +1,92 @@ +package com.bobmaster.studentsystem.util; +import com.bobmaster.studentsystem.Main; +import javafx.scene.control.Alert; +import javafx.stage.FileChooser; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; + + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Date; +import java.util.Optional; + +public class ExportToExcel { + public static void exportToExcel() { + FileChooser fileChooser = new FileChooser(); + fileChooser.setTitle("导出为Excel"); + fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Excel Files", "*.xlsx")); + fileChooser.setInitialFileName("学生信息_" + GenerateRandomTime.Generate() + + ".xlsx"); + + File file = fileChooser.showSaveDialog(null); + if (file != null) { + try { + ResultSet rs = DBUtil.dbExecuteQuery("SELECT name, gender, studentId, " + + "score FROM student ORDER BY score DESC"); + XSSFWorkbook workbook = new XSSFWorkbook(); + workbook.getProperties().getCoreProperties().setCreator("龚智勋"); + workbook.getProperties().getCoreProperties().setCreated(Optional.of(new Date())); + Sheet sheet = workbook.createSheet("学生综合信息表"); + + // Create header row + Row headerRow = sheet.createRow(0); + headerRow.createCell(0).setCellValue("姓名"); + headerRow.createCell(1).setCellValue("性别"); + headerRow.createCell(2).setCellValue("学号"); + headerRow.createCell(3).setCellValue("JP成绩"); + + // Write student data + int rowNum = 1; + while (rs.next()) { + String name = rs.getString("name"); + String gender = rs.getString("gender"); + String studentId = rs.getString("studentId"); + double score = rs.getDouble("score"); + + Row row = sheet.createRow(rowNum++); + row.createCell(0).setCellValue(name); + row.createCell(1).setCellValue(gender); + row.createCell(2).setCellValue(studentId); + row.createCell(3).setCellValue(score); + } + + // Auto size columns + for (int i = 0; i < 4; i++) { +// sheet.autoSizeColumn(i); + if (i == 0) { + sheet.setColumnWidth(i, 256 * 6); + } else if (i == 1) { + sheet.setColumnWidth(i, 256 * 6); + } else if (i == 2) { + sheet.setColumnWidth(i, 256 * 12); + } else { + sheet.setColumnWidth(i, 256 * 6); + } + } + + // Write workbook to file + try { + FileOutputStream fileOutputStream = new FileOutputStream(file); + workbook.write(fileOutputStream); + workbook.close(); + } catch (IOException e) { + ShowMessage.showErrorAlert("导出失败", "Excel文件导出失败"+e.getMessage()); + e.printStackTrace(); + } + Main.logger.info("学生信息导出至: "+file.getAbsolutePath()); + ShowMessage.showAlert(Alert.AlertType.INFORMATION, "导出成功", "Excel文件导出至: "+ + file.getAbsolutePath()); + + } catch (SQLException e ) { + ShowMessage.showErrorAlert("导出失败", "Excel文件导出失败"+e.getMessage()); + e.printStackTrace(); + } + + } + } +} diff --git a/src/main/java/com/bobmaster/studentsystem/util/GenerateRandomTime.java b/src/main/java/com/bobmaster/studentsystem/util/GenerateRandomTime.java new file mode 100644 index 0000000..b3cda4f --- /dev/null +++ b/src/main/java/com/bobmaster/studentsystem/util/GenerateRandomTime.java @@ -0,0 +1,10 @@ +package com.bobmaster.studentsystem.util; + +import java.text.SimpleDateFormat; +import java.util.Date; + +public class GenerateRandomTime { + public static String Generate() { + return new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(new Date()); + } +} diff --git a/src/main/java/com/bobmaster/studentsystem/util/GetCWD.java b/src/main/java/com/bobmaster/studentsystem/util/GetCWD.java new file mode 100644 index 0000000..2f9808d --- /dev/null +++ b/src/main/java/com/bobmaster/studentsystem/util/GetCWD.java @@ -0,0 +1,9 @@ +package com.bobmaster.studentsystem.util; + +import java.nio.file.Paths; + +public class GetCWD { + public static String getCWD() { + return Paths.get("").toAbsolutePath().toString(); + } +} diff --git a/src/main/java/com/bobmaster/studentsystem/util/Revoke.java b/src/main/java/com/bobmaster/studentsystem/util/Revoke.java new file mode 100644 index 0000000..f2b4ed1 --- /dev/null +++ b/src/main/java/com/bobmaster/studentsystem/util/Revoke.java @@ -0,0 +1,28 @@ +package com.bobmaster.studentsystem.util; +import com.bobmaster.studentsystem.model.Student; +import com.bobmaster.studentsystem.model.StudentDAO; +import javafx.collections.ObservableList; +import javafx.scene.Scene; +import javafx.scene.chart.PieChart; +import javafx.scene.control.Alert; +import javafx.scene.control.TableView; + +import java.io.IOException; +import java.sql.SQLException; +import java.util.Stack; + +public class Revoke { + public static void revokeEdit(Stack stack, TableView studentTableView) throws SQLException, IOException { + if (stack.size() != 0) { + String dbPath = stack.pop(); + DBUtil.dbRestore(dbPath); + ObservableList studentData = StudentDAO.searchStudents(); + studentTableView.setItems(studentData); + // Update pieChart + Scene scene = studentTableView.getScene(); + UpdatePieChart.updatePieChart((PieChart) scene.lookup("#scorePieChart")); + } else { + ShowMessage.showAlert(Alert.AlertType.WARNING, "撤销失败", "没有可撤销的操作"); + } + } +} diff --git a/src/main/java/com/bobmaster/studentsystem/util/ShowMessage.java b/src/main/java/com/bobmaster/studentsystem/util/ShowMessage.java new file mode 100644 index 0000000..9d42a4d --- /dev/null +++ b/src/main/java/com/bobmaster/studentsystem/util/ShowMessage.java @@ -0,0 +1,17 @@ +package com.bobmaster.studentsystem.util; + +import javafx.scene.control.Alert; + +public class ShowMessage { + public static void showAlert(Alert.AlertType alertType, String title, String message) { + Alert alert = new Alert(alertType); + alert.setTitle(title); + alert.setHeaderText(null); + alert.setContentText(message); + alert.showAndWait(); + } + + public static void showErrorAlert(String title, String message) { + showAlert(Alert.AlertType.ERROR, title, message); + } +} diff --git a/src/main/java/com/bobmaster/studentsystem/util/UpdatePieChart.java b/src/main/java/com/bobmaster/studentsystem/util/UpdatePieChart.java new file mode 100644 index 0000000..da5d63e --- /dev/null +++ b/src/main/java/com/bobmaster/studentsystem/util/UpdatePieChart.java @@ -0,0 +1,51 @@ +package com.bobmaster.studentsystem.util; + +import com.bobmaster.studentsystem.Main; +import com.bobmaster.studentsystem.controller.RootLayout; +import com.bobmaster.studentsystem.model.StudentDAO; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.fxml.FXMLLoader; +import javafx.scene.Node; +import javafx.scene.chart.PieChart; +import javafx.scene.control.Label; + +import java.io.IOException; +import java.sql.SQLException; + +public class UpdatePieChart { + public static void updatePieChart(PieChart pieChart) throws SQLException, IOException { + ObservableList pieChartData = FXCollections.observableArrayList(); + // calculate the number of students in each score range + int[] scoreRange = new int[6]; + for (int i = 0; i < 5; i++) { + scoreRange[i] = 0; + } + for (int i = 0; i < StudentDAO.searchStudents().size(); i++) { + if (StudentDAO.searchStudents().get(i).getScore() < 60) { + scoreRange[0]++; + } else if (StudentDAO.searchStudents().get(i).getScore() < 70) { + scoreRange[1]++; + } else if (StudentDAO.searchStudents().get(i).getScore() < 80) { + scoreRange[2]++; + } else if (StudentDAO.searchStudents().get(i).getScore() < 90) { + scoreRange[3]++; + } else if (StudentDAO.searchStudents().get(i).getScore() <= 100) { + scoreRange[4]++; + } + } + int total = 0; + for (int i = 0; i < 5; i++) { + total += scoreRange[i]; + } + // add data to pie chart + pieChartData.add(new PieChart.Data("0-60(" + scoreRange[0]*100/total + "%)", scoreRange[0])); + pieChartData.add(new PieChart.Data("60-70(" + scoreRange[1]*100/total + "%)", scoreRange[1])); + pieChartData.add(new PieChart.Data("70-80(" + scoreRange[2]*100/total + "%)", scoreRange[2])); + pieChartData.add(new PieChart.Data("80-90(" + scoreRange[3]*100/total + "%)", scoreRange[3])); + pieChartData.add(new PieChart.Data("90-100(" + scoreRange[4]*100/total + "%)", scoreRange[4])); + + // set pieChart data + pieChart.setData(pieChartData); + } +} diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java new file mode 100644 index 0000000..98551a9 --- /dev/null +++ b/src/main/java/module-info.java @@ -0,0 +1,19 @@ +module com.bobmaster.studentsystem { + requires javafx.controls; + requires javafx.fxml; + + requires org.controlsfx.controls; + requires org.kordamp.ikonli.javafx; + requires java.sql; + requires org.apache.poi.poi; + requires org.apache.poi.ooxml; + requires com.fasterxml.jackson.databind; + requires org.apache.logging.log4j; + requires org.apache.logging.log4j.core; + + opens com.bobmaster.studentsystem to javafx.fxml; + exports com.bobmaster.studentsystem; + exports com.bobmaster.studentsystem.controller; + exports com.bobmaster.studentsystem.model; + exports com.bobmaster.studentsystem.util; +} \ No newline at end of file diff --git a/src/main/resources/com/bobmaster/studentsystem/AboutPage.fxml b/src/main/resources/com/bobmaster/studentsystem/AboutPage.fxml new file mode 100644 index 0000000..0c154ad --- /dev/null +++ b/src/main/resources/com/bobmaster/studentsystem/AboutPage.fxml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/com/bobmaster/studentsystem/RootLayout.fxml b/src/main/resources/com/bobmaster/studentsystem/RootLayout.fxml new file mode 100644 index 0000000..236d7bc --- /dev/null +++ b/src/main/resources/com/bobmaster/studentsystem/RootLayout.fxml @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +