package com.sorce.service;
import java.util.Scanner;
import java.util.Vector;
import com.score.dao.StudentDao;
import com.score.dao.TeacherDao;
import com.score.start.Start;
import com.sorce.bean.Admin;
import com.sorce.bean.College;
import com.sorce.bean.Course;
import com.sorce.bean.Score;
import com.sorce.bean.Student;
public class TeacherService {
private Scanner input = new Scanner(System.in);
private Admin teacher = new Admin();
private TeacherDao tdao = new TeacherDao();
private StudentDao sdao = new StudentDao();
public boolean teacherLogin(){
System.out.println("请输入你的账号:");
teacher.setAdmin_name(input.nextLine());
System.out.println("请输入你的密码:");
teacher.setAdmin_pwd(input.nextLine());
return tdao.tacherLogin(teacher);
}
public void teacherService(){
System.out.println("***********" + teacher.getAdmin_name() + "欢迎你回来********");
System.out.println("请选择操作:");
System.out.println("\t1:添加学生\t2:查看学生信息");
System.out.println("\t3:查看学生成绩\t4:学生成绩录入");
System.out.println("\t5:添加课程\t6:返回上一级");
String choose = input.nextLine();
if("1".equals(choose)){
addStudent();
}
else if("2".equals(choose)){
viewStudentInfo();
}
else if("3".equals(choose)){
viewStudentScore();
}
else if("4".equals(choose)){
inserScore();
}
else if("5".equals(choose)){
addCourse();
}
else if("6".equals(choose)){
new Start().init();
}
else {
System.out.println("你的输入有误!");
teacherService();
}
}
private void addStudent(){
System.out.println("请输入学生的学号(1-6个数字):");
String stu_id = input.nextLine();
if(Util.isNumber(stu_id)){
int id = Integer.parseInt(stu_id);
if(tdao.getStudent_id().contains(id)){
System.out.println("该学号已经存在");
addStudent();
}
else{
Student student = new Student();
student.setStu_id(id);
System.out.println("请输入学生姓名:");
student.setStu_name(input.nextLine());
System.out.println("请输入学生性别(男/女):");
student.setSex(input.nextLine());
System.out.println("请输入学生生日:");
student.setBirthday(input.nextLine());
student.setCollege(input_colleage_id());
System.out.println("输入班级号:");
student.setClass_num(input.next());
student.setStu_pwd(stu_id);
tdao.insertStudent(student);
System.out.println("成功插入学生,初始密码和学号相同");
new Start().init();
}
}
else{
System.out.println("学号必须为数字");
addStudent();
}
}
private int input_colleage_id(){
Vector<College> allColleges = tdao.getAllCollege();
int college_id = 0;
System.out.println("请输入对应的学院编号:");
for(College college : allColleges){
System.out.print(college.getCollege_id() + ":" + college.getCollege_name() + " ");
}
System.out.println("");
String input_id = input.nextLine();
if(Util.isNumber(input_id)){
int id = Integer.parseInt(input_id);
if(tdao.getAllCollege_id().contains(id)){
college_id = id;
}
else{
System.out.println("你输入的学院编号在数据库中不存在。");
college_id = input_colleage_id();
}
}
else{
System.out.println("学院编号必须为数字!");
college_id = input_colleage_id();
}
return college_id;
}
private void viewStudentInfo(){
System.out.println("\t1:按学号查看\t2:查看全部\t3:返回上一级");
String choose = input.nextLine();
if("1".equals(choose)){
System.out.println("请输入学号:");
String id = input.nextLine();
if(Util.isNumber(id)){
Student student = new Student();
student.setStu_id(Integer.parseInt(id));
student = sdao.getStudentById(student);
if(student == null){
System.out.println("你输入的学号不存在");
viewStudentInfo();
}
else{
System.out.println("学号:" + student.getStu_id() + "\t姓名:" + student.getStu_name() + "\t性别:" + student.getSex() +
"\t学院:" + sdao.getCollegeBYStuID(student) + "\t班级:" + student.getClass_num());
teacherService();
}
}
else{
System.out.println("学号必须为数字");
viewStudentInfo();
}
}
else if("2".equals(choose)){
Vector<Student> allStudents = sdao.getAllStudent();
if(allStudents.size() == 0)
System.out.println("当前系统中没有学生信息.");
else{
for(Student student : allStudents){
System.out.println("学号:" + student.getStu_id() + "\t姓名:" + student.getStu_name() + "\t性别:" + student.getSex() +
"\t学院:" + sdao.getCollegeBYStuID(student) + "\t班级:" + student.getClass_num());
}
teacherService();
}
}
else if("3".equals(choose)){
teacherService();
}
else{
System.out.println("你的输入有误!");
viewStudentInfo();
}
}
public void viewStudentScore(){
System.out.println("\t1:按学号查看\t2:查看全部\t3:返回上一级");
String choose = input.nextLine();
if("1".equals(choose)){
System.out.println("请输入学号:");
String id = input.nextLine();
if(Util.isNumber(id)){
Student student = new Student();
student.setStu_id(Integer.parseInt(id));
student = sdao.getStudentById(student);
if(student == null){
System.out.println("你输入的学号不存在");
viewStudentScore();
}
else{
Vector<Score> stuScores = sdao.getScoreBYStuID(student);
if(stuScores.size() == 0)
System.out.println("该学生现在还没有成绩!");
else{
for(Score score : stuScores){
System.out.println(student.getStu_name() + ":" + sdao.courseName_byID(score.getCourse_id()) + ":" + score.getScore());
}
}
teacherService();
}
}
else{
System.out.println("学号必须为数字");
viewStudentScore();
}
}
else if("2".equals(choose)){
Vector<Student> allStudents = sdao.getAllStudent();
if(allStudents.size() == 0)
System.out.println("当前系统中没有学生信息.");
else{
for(Student student : allStudents){
Vector<Score> stuScores = sdao.getScoreBYStuID(student);
if(stuScores.size() == 0)
System.out.println( student.getStu_name() + " 现在还没有成绩!");
else{
for(Score score : stuScores){
System.out.println(student.getStu_name() + ":" + sdao.courseName_byID(score.getCourse_id()) + ":" + score.getScore());
}
}
}
teacherService();
}
}
else if("3".equals(choose)){
teacherService();
}
else{
System.out.println("你的输入有误!");
viewStudentScore();
}
}
public void inserScore(){
System.out.println("\t1:成绩录入\t2:返回上一级");
String choose = input.nextLine();
if("1".equals(choose)){
System.out.println("请输入要录入成绩学生的学号:");
String id = input.nextLine();
if(Util.isNumber(id)){
Student student = new Student();
student.setStu_id(Integer.parseInt(id));
student = sdao.getStudentById(student);
if(student == null){
System.out.println("你输入的学号不存在");
inserScore();
}
else{
Score score = new Score();
System.out.println("系统中的课程数如下:");
Vector<Course> allCourses = sdao.getAllCourse();
for(Course course : allCourses){
System.out.print("编号:" + course.getCourse_id() + "\t课程名:" + course.getCourse_name() + " ");
}
System.out.println("");
score.setCourse_id(inputCourseID());
score.setStu_id(student.getStu_id());
score.setScore_id(sdao.getAllScore().size() + 1);
score.setScore(inputScore());
sdao.inserScore(score);
System.out.println(student.getStu_name() + ":" + sdao.courseName_byID(score.getCourse_id()) +
":" + score.getScore() + ",录入成功");
inserScore();
}
}
else{
System.out.println("学号必须为数字");
inserScore();
}
}
else if("2".equals(choose)){
teacherService();
}
el