public List <Student> selectJiaoWuStudent(List <Student> ps, JiaoWu j) { List <Student> result = new List <Student>(); foreach (Student t in ps) { if (t.StuMajorID == j.JiaoWuMajorID) { result.Add(t); } } return(result); }
private bool testJiaoWu(int userId, string Passwd) { List <JiaoWu> ps = dbhelper.getJiaoWuByJId(userId); //dbhelper.getProfessorByProId(userId); if (ps.Count == 0) { return(false); } else { JiaoWu p = ps[0]; User u = dbhelper.getUserByUserId(p.UserID); if (u.UserPassword == Passwd) { return(true); } } return(false); }
public string getStudents(int p) { HttpCookie accountCookie = Request.Cookies["Account"]; int usertype = int.Parse(accountCookie["type"]); int userId = int.Parse(accountCookie["userId"]); string rel = ""; List <Student> ps = null; int order = 1; AdminStudent ap = null; List <AdminStudent> list = new List <AdminStudent>(); if (p == 0) { ps = dbhelper.findAllStudents(); } else if (p == 1) { ps = dbhelper.findNoInfoStudents(); } else if (p == 2) { ps = dbhelper.findNoWillStudents(); } else if (p == 3) { ps = dbhelper.findNoFinalWillStudents(); } else { return(rel); } if (ps == null) { return(rel); } else { foreach (Student t in ps) { ap = new AdminStudent(); ap.Order = order++; ap.UserId = t.UserID; if (t.StuFinalWill == 0) { ap.StuFinalWill = "无"; } else { List <Professor> temlist = dbhelper.getProfessorByProId(t.StuFinalWill); ap.StuFinalWill = temlist[0].ProName; } ap.StuID = t.StuID; if (t.StuInfoChecked) { ap.StuInfoChecked = "是"; } else { ap.StuInfoChecked = "否"; } ap.StuName = t.StuName; if (t.StuWillChecked) { ap.StuWillChecked = "是"; } else { ap.StuWillChecked = "否"; } if (usertype == 1) { List <JiaoWu> jlist = dbhelper.getJiaoWuByJId(userId); JiaoWu j = jlist[0]; if (j.JiaoWuMajorID == t.StuMajorID) { list.Add(ap); } } else { list.Add(ap); } } JavaScriptSerializer serializer = new JavaScriptSerializer(); var json = serializer.Serialize(list); rel = json.ToString(); serializer = null; } return(rel); }
/* * @param file: excel文件 * @功能:excel批量导入j教务 * */ public string batchCreateJiaoWus(HttpPostedFileBase file) { var severPath = this.Server.MapPath("/ExcelFiles/"); if (!Directory.Exists(severPath)) { Directory.CreateDirectory(severPath); } var savePath = Path.Combine(severPath, file.FileName); JiaoWu teacher = null; string result = "{}"; List <JiaoWu> listTeachers = new List <JiaoWu>(); Workbook workbook = new Workbook(); Worksheet sheet = null; string error = ""; 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 tempTitle; int idcol = -11; int namecol = -11; int titlecol = -11; int idrow = -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; } if (tempId.Equals("姓名")) { namecol = j; } if (tempId.Equals("负责专业编号")) { titlecol = j; } } if (idcol >= 0 && namecol >= 0) { break; } } if (idcol < 0 || namecol < 0) { throw new Exception("不是教师表"); } for (int i = idrow; i < row; i++) { tempId = cellrange[i * col + idcol].Value; tempName = cellrange[i * col + namecol].Value; tempTitle = cellrange[i * col + titlecol].Value; if (tempName != "") { teacher = new JiaoWu(); teacher.JiaoWuID = int.Parse(tempId); teacher.JiaoWuName = tempName; teacher.JiaoWuMajorID = int.Parse(tempTitle); listTeachers.Add(teacher); } } error = dbhelper.batchAddJiaoWus(listTeachers); // error = dbhelper.batchAddTeachers(listTeachers); if (error.StartsWith("error")) { throw new Exception("数据库更新出错"); } } catch (Exception e) { if (e.Message.Equals("数据库更新出错")) { result = "{\"error\":\"" + error + "\"}"; } else if (e.Message.Equals("文件格式不正确")) { result = "{\"error\":\"文件格式不正确\"}"; } else { result = "{\"error\":\"在服务器端发生错误请联系管理员\"}"; } } finally { workbook.Dispose(); sheet = null; workbook = null; } return(result); }
public string searchStudents(string name, int p) { HttpCookie accountCookie = Request.Cookies["Account"]; int usertype = int.Parse(accountCookie["type"]); int userId = int.Parse(accountCookie["userId"]); string rel = ""; List <Student> ps = null; int order = 1; JiaoWuStudent ap = null; List <JiaoWuStudent> list = new List <JiaoWuStudent>(); List <JiaoWu> jiaoWus = dbhelper.getJiaoWuByJId(userId); JiaoWu jiaoWu = new JiaoWu(); if (jiaoWus.Count <= 0) { return(rel); } else { jiaoWu = jiaoWus[0]; } if (p == 0) { ps = dbhelper.findAllStudents(); } else if (p == 1) { ps = dbhelper.findNoInfoStudents(); } else if (p == 2) { ps = dbhelper.findNoWillStudents(); } else if (p == 3) { ps = dbhelper.findNoFinalWillStudents(); } else { return(rel); } ps = selectJiaoWuStudent(ps, jiaoWu); if (ps == null) { return(rel); } else { foreach (Student t in ps) { ap = new JiaoWuStudent(); ap.Order = order++; ap.UserId = t.UserID; if (t.StuFinalWill == 0) { ap.StuFinalWill = "无"; } else { List <Professor> temlist = dbhelper.getProfessorByProId(t.StuFinalWill); ap.StuFinalWill = temlist[0].ProName; } ap.StuID = t.StuID; if (t.StuInfoChecked) { ap.StuInfoChecked = "是"; } else { ap.StuInfoChecked = "否"; } ap.StuName = t.StuName; if (t.StuWillChecked) { ap.StuWillChecked = "是"; } else { ap.StuWillChecked = "否"; } list.Add(ap); } } if (name == "") { JavaScriptSerializer serializer = new JavaScriptSerializer(); var json = serializer.Serialize(list); rel = json.ToString(); serializer = null; } else { foreach (JiaoWuStudent s in list) { if (s.StuName.Equals(name)) { List <JiaoWuStudent> tem = new List <JiaoWuStudent>(); tem.Add(s); JavaScriptSerializer serializer = new JavaScriptSerializer(); var json = serializer.Serialize(tem); rel = json.ToString(); serializer = null; } } } return(rel); }