public void addStudent() { try { Student student = new Student(); setValue(student, context); HttpPostedFile hpf = context.Request.Files["headImgFile"]; if (hpf != null) { string serverPath = "/uploadFile/headImg/" + System.DateTime.Now.Ticks + "." + hpf.FileName.Split('.')[1]; string savePath = context.Server.MapPath(serverPath);//路径,相对于服务器当前的路径 hpf.SaveAs(savePath);//保存 student.HeadImage = serverPath; } string FacultyID = context.Request.Form.Get("Faculty"); DepartmentService ds = new DepartmentService(); string professionID = context.Request.Form.Get("Profession"); if (!string.IsNullOrEmpty(professionID)) { Profession profession = ds.getProfessionByID(professionID); if (profession != null) student.Profession = profession; } string ClassGradeID = context.Request.Form.Get("ClassGrade"); if (!string.IsNullOrEmpty(ClassGradeID)) { ClassGrade classGrade = ds.getClassGradeByID(ClassGradeID); if (classGrade != null) student.ClassGrade = classGrade; } StudentService s = new StudentService(); student.Password = student.Sn; s.save(student); context.Response.Write("1"); } catch (Exception e) { context.Response.Write("0"); } }
public void updateStudent() { try { Student student = new Student(); setValue(student, context); HttpPostedFile hpf = context.Request.Files["headImgFile"]; if (hpf != null) { string savepath = context.Server.MapPath("/uploadFile/headImg/" + student.Id + "." + hpf.GetType());//路径,相对于服务器当前的路径 hpf.SaveAs(savepath);//保存 student.HeadImage = savepath; } DepartmentService ds = new DepartmentService(); string professionID = context.Request.Form.Get("Profession"); if (!string.IsNullOrEmpty(professionID)) { Profession profession = ds.getProfessionByID(professionID); if (profession != null) student.Profession = profession; } string ClassGradeID = context.Request.Form.Get("ClassGrade"); if (!string.IsNullOrEmpty(ClassGradeID)) { ClassGrade classGrade = ds.getClassGradeByID(ClassGradeID); if (classGrade != null) student.ClassGrade = classGrade; } StudentService s = new StudentService(); s.save(student); context.Response.Write("1"); } catch (Exception e) { context.Response.Write("0"); } }