package bdqn.studentSys;
/**
* main类
* @author Administrator
*
*/
import java.util.*;
import bdqn.studentSys.Dao.StudentDao;
import bdqn.studentSys.Dao.impl.StudentDaoImpl;
import bdqn.studentSys.entity.Student;
public class StudentSys {
public static void main(String []args){
Scanner in=new Scanner(System.in);
//查询全部学生
getAllStudent();
//添加
System.out.println("==============添加学生信息==============");
System.out.println("请输入学生姓名:");
String name=in.next();
System.out.println("请输入学生密码:");
String pwd=in.next();
System.out.println("请输入学生年龄:");
int age=in.nextInt();
System.out.println("请输入学生性别:");
String sex=in.next();
Student stu=new Student();
stu.setName(name);
stu.setPwd(pwd);
stu.setAge(age);
stu.setSex(sex);
addStudent(stu);
//修改
System.out.println("==============修改学生信息==============");
System.out.println("请输入要修改的学生学号:");
int no=in.nextInt();
System.out.println("请输入学生姓名:");
String name1=in.next();
System.out.println("请输入学生密码:");
String pwd1=in.next();
System.out.println("请输入学生年龄:");
int age1=in.nextInt();
System.out.println("请输入学生性别:");
String sex1=in.next();
Student stu1=new Student();
stu.setName(name1);
stu.setPwd(pwd1);
stu.setAge(age1);
stu.setSex(sex1);
updateStudent(stu1);
//删除
System.out.println("==============删除学生信息==============");
System.out.println("请输入要删除的学生学号:");
int no1=in.nextInt();
delStudent(no1);
}
static StudentDao sdao=new StudentDaoImpl();
//查询全部学生
static void getAllStudent(){
List<Student> slist=sdao.getAllStudent();
System.out.println("姓名 密码 年龄 性别");
for (Student stu : slist) {
System.out.print(stu.getName()+" ");
System.out.print(stu.getPwd()+" ");
System.out.print(stu.getAge()+" ");
System.out.println(stu.getSex()+" ");
}
}
//添加学生信息
static void addStudent(Student stu){
int rel=sdao.addStudent(stu);
try {
if(rel>0){
System.out.println("添加成功!");
}else{
System.out.println("添加失败!");
}
} catch (Exception e) {
System.out.println("操作异常!"+e);
}
}
//修改学生信息
static void updateStudent(Student stu){
int rel=sdao.UpdateStudent(stu);
try {
if(rel>0){
System.out.println("修改成功!");
}else{
System.out.println("添加失败!");
}
} catch (Exception e) {
// TODO: handle exception
System.out.println("操作异常"+e);
}
}
//删除学生信息
static void delStudent(int stuno){
int rel=sdao.delStudent(stuno);
try {
if(rel>0){
System.out.println("删除成功!");
}else{
System.out.println("删除失败");
}
} catch (Exception e) {
// TODO: handle exception
System.out.println("操作异常"+e);
}
}
}