Exemplo n.º 1
0
 public string addMajor(string name)
 {
     try
     {
         MajorDao majorDao = new MajorDao();
         int      res      = majorDao.addMajor(name);
         if (res == 1)
         {
             return("success");
         }
         else if (res == 0)
         {
             return("fail:已存在该专业");
         }
         else
         {
             return("fail:添加失败");
         }
     }
     catch (Exception e)
     {
         LogUtil.writeLogToFile(e, Request);
         return("fail:" + e.Message);
     }
 }
Exemplo n.º 2
0
        public string getAllDeans()
        {
            string rel = "";

            try
            {
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                DeanDao  deanDao  = new DeanDao();
                MajorDao majorDao = new MajorDao();

                List <Dean> deans = new List <Dean>();
                deans = deanDao.listAllDeans();
                List <RetDean> ret      = new List <RetDean>();
                Major          tmpMajor = new Major();
                foreach (Dean tmp in deans)
                {
                    RetDean tmpdean = new RetDean();
                    tmpMajor                 = majorDao.getMajorById(tmp.majorId);
                    tmpdean.Number           = tmp.id;
                    tmpdean.MajorResponsible = tmpMajor.name;
                    tmpdean.TeacherName      = tmp.name;
                    ret.Add(tmpdean);
                }
                var json = serializer.Serialize(ret);
                rel = json.ToString();
                return(rel);
            }
            catch (Exception e)
            {
                LogUtil.writeLogToFile(e, Request);
                return("[]");
            }
        }
Exemplo n.º 3
0
        public void TestMajorMethod_major_deleteAll()
        {
            MajorDao      majorDao = new MajorDao();
            List <String> ids      = new List <String>();

            ids.Add("a1223456");
            ids.Add("a123456");
            Assert.AreEqual(0, majorDao.deleteMajorsByIds(ids));
        }
Exemplo n.º 4
0
        public string getStudentInfo()
        {
            string              res           = "";
            StudentDao          studentDao    = new StudentDao();
            MajorDao            majorDao      = new MajorDao();
            ProfessorDao        professorDao  = new ProfessorDao();
            List <Student>      students      = studentDao.listAllStudent();
            List <AdminStudent> adminStudents = new List <AdminStudent>();
            List <Major>        majors        = majorDao.listAllMajor();

            if (students == null)
            {
                return(res);
            }
            else
            {
                foreach (Student s in students)
                {
                    AdminStudent Astudent = new AdminStudent();
                    Astudent.id      = s.id;
                    Astudent.StuName = s.name;
                    Astudent.major   = majorDao.getMajorById(s.majorId).name;
                    //专业方向?
                    Astudent.infoCommited = s.infoChecked;
                    if (s.firstWill != null && s.secondWill != null)
                    {
                        Astudent.twoWillCommited = true;
                    }
                    else
                    {
                        Astudent.twoWillCommited = false;
                    }
                    if (s.firstWillState == 1)
                    {
                        Astudent.FinalTutor = professorDao.getProfessorById(s.firstWill).name;
                    }
                    else if (s.secondWillState == 1)
                    {
                        Astudent.FinalTutor = professorDao.getProfessorById(s.secondWill).name;
                    }
                    else if (s.dispensedWill == null || s.dispensedWill == "")
                    {
                        Astudent.FinalTutor = null;
                    }
                    else
                    {
                        Astudent.FinalTutor = professorDao.getProfessorById(s.dispensedWill).name;
                    }
                    adminStudents.Add(Astudent);
                }
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                var json = serializer.Serialize(adminStudents);
                res        = json.ToString();
                serializer = null;
            }
            return(res);
        }
Exemplo n.º 5
0
        public void TestMajorMethod_major_listAll_changeName()
        {
            MajorDao     majorDao = new MajorDao();
            List <Major> majors   = majorDao.listAllByMajor();

            foreach (var major in majors)
            {
                Console.WriteLine(major.id);
            }
            string name = "地理";

            Assert.AreEqual(1, majorDao.changeNameById(majors[0].id, name));
        }
Exemplo n.º 6
0
 public string getAllMajor2()
 {
     try
     {
         MajorDao             majorDao   = new MajorDao();
         List <Major>         majors     = majorDao.listAllMajor();
         JavaScriptSerializer serializer = new JavaScriptSerializer();
         var json = serializer.Serialize(majors);
         return(json);
     }
     catch (Exception e)
     {
         return("fail:查询失败!");
     }
 }
Exemplo n.º 7
0
        public ActionResult StudentInfo(string stuId)
        {
            ProfessorDao professorDao = new ProfessorDao();
            StudentDao   studentDao   = new StudentDao();
            MajorDao     majorDao     = new MajorDao();
            Student      s            = studentDao.getStudentById(stuId);

            ViewBag.Id        = s.id;
            ViewBag.Name      = s.name;
            ViewBag.Age       = s.age;
            ViewBag.Gender    = s.gender ? "男" : "女";
            ViewBag.Email     = s.email;
            ViewBag.Major     = majorDao.getMajorById(s.majorId).name;
            ViewBag.OnJob     = (s.onTheJob ? "在职" : "脱产");
            ViewBag.Phone     = s.phoneNumber;
            ViewBag.ResumeUrl = s.resumeUrl;
            if (s.firstWill != null)
            {
                ViewBag.FirstWillName = professorDao.getProfessorById(s.firstWill).name;
            }
            if (s.secondWill != null)
            {
                ViewBag.SecondWillName = professorDao.getProfessorById(s.secondWill).name;
            }
            if (s.dispensedWill != null)
            {
                ViewBag.DispensedWillName = professorDao.getProfessorById(s.dispensedWill).name;
            }
            if (s.firstWillState == 1)
            {
                ViewBag.FinalWillName = ViewBag.FirstWillName;
            }
            else if (s.secondWillState == 1)
            {
                ViewBag.FinalWillName = ViewBag.SecondWillName;
            }
            else if (s.dispensedWill != null && s.dispensedWill != "")
            {
                ViewBag.FinalWillName = ViewBag.DispensedWillName;
            }
            else
            {
                ViewBag.FinalWillName = "无";
            }
            return(View());
        }
Exemplo n.º 8
0
 public string getAllMajor()
 {
     try
     {
         MajorDao             majorDao   = new MajorDao();
         List <Major>         majors     = majorDao.listAllMajor();
         JavaScriptSerializer serializer = new JavaScriptSerializer();
         var    json   = serializer.Serialize(majors);
         string retStr = json.ToString();
         return(retStr);
     }
     catch (Exception e)
     {
         LogUtil.writeLogToFile(e, Request);
         return("fail:查询失败!");
     }
 }
Exemplo n.º 9
0
 public string deleteMajorById(string id)
 {
     try
     {
         MajorDao majorDao = new MajorDao();
         int      res      = majorDao.deleteMajorById(int.Parse(id));
         if (res == 1)
         {
             return("success");
         }
         else
         {
             return("fail:不存在该专业");
         }
     }catch (Exception e)
     {
         LogUtil.writeLogToFile(e, Request);
         return("fail:" + e.Message);
     }
 }
Exemplo n.º 10
0
        public void TestMajorMethod_major_add_get_delete()
        {
            MajorDao majorDao = new MajorDao();
            Major    major    = new Major();

            // major.id = "a323456";
            major.name   = "英语";
            major.remark = "123sdaSDSA";
            // majorDao.addMajor(major);
            major = majorDao.getMajorById(major.id);
            ValidResult validResult = ValidateHelper.IsValid(major);

            Assert.AreEqual(1, majorDao.deleteMajorById(major.id));
            if (!validResult.IsVaild)
            {
                foreach (ErrorMember errorMember in validResult.ErrorMembers)
                {
                    Debug.WriteLine(errorMember.ErrorMemberName + ":" + errorMember.ErrorMessage);
                }
            }
        }
Exemplo n.º 11
0
 public string editMajor(string id, string name)
 {
     try
     {
         MajorDao majorDao = new MajorDao();
         int      res      = majorDao.changeNameById(int.Parse(id), name);
         if (res == 1)
         {
             return("success");
         }
         else
         {
             return("fail:不存在该专业");
         }
     }
     catch (Exception e)
     {
         LogUtil.writeLogToFile(e, Request);
         return("fail:" + e.Message);
     }
 }
        public ActionResult Index()
        {
            HttpCookie accountCookie = Request.Cookies["Account"];
            string     id            = accountCookie["userId"];
            StudentDao studentDao    = new StudentDao();
            Student    student       = studentDao.getStudentById(id);

            ViewBag.StuName      = student.name;
            ViewBag.StuAge       = student.age.ToString();
            ViewBag.StuGender    = student.gender ? "男" : "女";
            ViewBag.StuTel       = student.phoneNumber;
            ViewBag.StuEmail     = student.email;
            ViewBag.StuId        = student.id;
            ViewBag.StuGraSchool = student.graSchool;
            ViewBag.StuGraMajor  = student.graMajor;
            ViewBag.ResumeUrl    = student.resumeUrl;
            ViewBag.OnTheJob     = student.onTheJob;

            MajorDao majorDao = new MajorDao();
            Major    major    = majorDao.getMajorById(student.majorId);

            ViewBag.StuMajor = major.name;

            SettingDao settingDao = new SettingDao();
            Setting    setting    = settingDao.getCurrentSetting();

            if (setting.mode == 1)
            {
                ViewBag.Deadline = setting.infoEnd;
            }
            else
            {
                ViewBag.Deadline = "";
            }
            return(View());
        }
Exemplo n.º 13
0
        public string batchAddStudents(HttpPostedFileBase file)
        {
            var severPath = this.Server.MapPath("/ExcelFiles/");

            if (!Directory.Exists(severPath))
            {
                Directory.CreateDirectory(severPath);
            }
            var            savePath     = Path.Combine(severPath, file.FileName);
            Student        student      = null;
            StudentDao     studentDao   = new StudentDao();
            string         result       = "{}";
            bool           flag         = false;
            int            addres       = 0;
            List <Student> listStudents = new List <Student>();
            Workbook       workbook     = new Workbook();
            Worksheet      sheet        = null;

            Response.ContentType = "application/json";
            Response.Charset     = "utf-8";

            try
            {
                if (string.Empty.Equals(file.FileName) || (".xls" != Path.GetExtension(file.FileName) && ".xlsx" != Path.GetExtension(file.FileName)))
                {
                    throw new Exception("文件格式不正确");
                }

                file.SaveAs(savePath);
                workbook.LoadFromFile(savePath);
                sheet = workbook.Worksheets[0];
                int    row = sheet.Rows.Length;    //获取不为空的行数
                int    col = sheet.Columns.Length; //获取不为空的列数
                string tempId;
                string tempName;
                string tempPasswd;
                string tempMajor;
                string tempGender;

                int idcol     = -11;
                int namecol   = -11;
                int Passwdcol = -11;
                int Majorcol  = -11;
                int Gendercol = -11;
                int idrow     = -11;
                //int maxnumcol = -11;
                CellRange[] cellrange   = sheet.Cells;
                int         rangelength = cellrange.Length;
                for (int i = 0; i < row; i++)
                {
                    for (int j = 0; j < col; j++)
                    {
                        tempId = cellrange[i * col + j].Value;
                        if (tempId.Equals("学号"))
                        {
                            idcol = j;
                            idrow = i + 1;
                        }
                        else if (tempId.Equals("姓名"))
                        {
                            namecol = j;
                        }
                        else if (tempId.Equals("密码"))
                        {
                            Passwdcol = j;
                        }
                        else if (tempId.Equals("专业方向"))
                        {
                            Majorcol = j;
                        }
                        else if (tempId.Equals("性别"))
                        {
                            Gendercol = j;
                        }
                    }
                    if (idcol >= 0 && namecol >= 0)
                    {
                        break;
                    }
                }

                if (idcol < 0 || namecol < 0)
                {
                    throw new Exception("表格格式不正确");
                }

                MajorDao     majorDao = new MajorDao();
                List <Major> majors   = majorDao.listAllMajor();

                for (int i = idrow; i < row; i++)
                {
                    tempId     = cellrange[i * col + idcol].Value;
                    tempName   = cellrange[i * col + namecol].Value;
                    tempPasswd = cellrange[i * col + Passwdcol].Value;
                    tempMajor  = cellrange[i * col + Majorcol].Value;
                    tempGender = cellrange[i * col + Gendercol].Value;
                    if (tempName != "")
                    {
                        if (studentDao.getStudentById(tempId) != null)
                        {
                            flag    = true;
                            result += "已存在教师:id:" + tempId + " 姓名:" + tempName + " 专业:" + tempId + "\n";
                            continue;
                        }
                        student      = new Student();
                        student.id   = tempId;
                        student.name = tempName;
                        bool majorExist = false;
                        foreach (Major m in majors)
                        {
                            if (m.name == tempMajor)
                            {
                                student.majorId = m.id;
                                majorExist      = true;
                            }
                        }
                        if (!majorExist)
                        {
                            result += "无法识别名为‘" + tempMajor + "’的专业名称:id:" + tempId + " 姓名:" + tempName + " 专业:" + tempId + "\n";
                            flag    = true;
                            continue;
                        }
                        student.password = CryptoUtil.Md5Hash(tempPasswd);
                        student.gender   = tempGender == "女" ? false : true;
                        addres           = studentDao.addStudent(student);
                        if (addres < 1)
                        {
                            throw new Exception("数据库连接出错");
                        }
                    }
                }
            }
            catch (Exception e)
            {
                LogUtil.writeLogToFile(e, Request);
                return("{\"error\":\"" + e.Message + "\"}");
            }
            finally
            {
                workbook.Dispose();
                sheet    = null;
                workbook = null;
            }
            if (flag)
            {
                return("{\"error\":\"" + result + "\"}");
            }
            return("{" +
                   "\"initialPreview\":" +
                   "[\"<div style=\\\"text-align:center;padding:50px 25px;color:#00a65a\\\"><i class=\\\"fa fa-check-square-o\\\" style=\\\"font-size:60px;opacity:0.6\\\"></i><p style=\\\"padding-top:10px;font-size:18px\\\">添加成功</p></div>\"]" +
                   "}");
        }