Exemplo n.º 1
0
        /// <summary>
        /// 新增一个学生信息 HttpGet
        /// </summary>
        /// <returns></returns>
        public ViewResult Edit(string Id, bool isEdit = false)
        {
            StudnetEditViewModel model = GetSutdentEditModel(Id);

            if (model == null)
            {
                RedirectToAction("List");
            }
            ViewBag.isEdit = isEdit;
            return(View(model));
        }
Exemplo n.º 2
0
        private StudnetEditViewModel GetInitStudentEditModel()
        {
            StudnetEditViewModel model = new StudnetEditViewModel
            {
                Student       = new td_students(),
                Banjis        = XmlHelper.GetListByXpath("SimpleData.xml", "/DD/DItems[@DValue='banji']", ""),
                Depts         = XmlHelper.GetListByXpath("deptlist.xml", "/Departments", "", "Dept_name", "Dept_code"),
                Genders       = XmlHelper.GetListByXpath("SimpleData.xml", "/DD/DItems[@DValue='gender']", ""),
                Grades        = XmlHelper.GetListByXpath("SimpleData.xml", "/DD/DItems[@DValue='grade']", ""),
                Majors        = new List <SelectListItem>(),
                Nation        = XmlHelper.GetListByXpath("SimpleData.xml", "/DD/DItems[@DValue='nation']", ""),
                Politicstatus = XmlHelper.GetListByXpath("SimpleData.xml", "/DD/DItems[@DValue='political']", ""),
                Proviences    = XmlHelper.GetListByXpath("Provinces.xml", "/Provinces", "", "ProvinceName", "ID"),
                Cities        = new List <SelectListItem>(),
                Districts     = new List <SelectListItem>()
            };

            return(model);
        }
Exemplo n.º 3
0
        public ActionResult Edit(td_students student, string province = "", string city = "", string district = "")
        {
            if (!ModelState.IsValid)
            {
                //获取所有错误的Key
                List <string> Keys = ModelState.Keys.ToList();
                //获取每一个key对应的ModelStateDictionary
                foreach (var key in Keys)
                {
                    var errors = ModelState[key].Errors.ToList();
                    //将错误描述输出到控制台
                    foreach (var error in errors)
                    {
                        TempData["Errmsg"] += error.ErrorMessage + "\r\n";
                    }
                }
                StudnetEditViewModel model = GetSutdentEditModel(student.id);
                model.Student = student;
                return(View(model));
            }
            if (province != "" && city != "" && district != "")
            {
                student.native_place = string.Format("{0}-{1}-{2}", province, city, district);
            }
            if (string.IsNullOrEmpty(student.id))
            {
                student.id    = TableIDCodingRule.newID("td_students", "");
                student.audit = false;
                student.@lock = false;
                StudentService.Add(student);
            }

            else
            {
                StudentService.Update(student);
            }
            TempData["Message"] = string.Format("学号{0} 姓名{1} 数据已保存", student.school_code, student.student_name);
            return(RedirectToAction("List"));
        }
Exemplo n.º 4
0
        private StudnetEditViewModel GetSutdentEditModel(string Id)
        {
            td_students          student = StudentService.GetEntities(p => p.id == Id).FirstOrDefault();
            StudnetEditViewModel model   = null;

            if (student == null)
            {
                model = GetInitStudentEditModel();
            }
            else
            {
                model = new StudnetEditViewModel
                {
                    Student       = student,
                    Banjis        = XmlHelper.GetListByXpath("banji", student.banji),
                    Depts         = XmlHelper.GetListByXpath("deptlist.xml", "/Departments", student.dept, "Dept_name", "Dept_code"),
                    Genders       = XmlHelper.GetListByXpath("gender", student.gender),
                    Grades        = XmlHelper.GetListByXpath("grade", student.grade),
                    Majors        = XmlHelper.GetListByXpath("Major.xml", string.Format("/Majors/DItems[@DValue='{0}']", student.dept), student.major),
                    Nation        = XmlHelper.GetListByXpath("nation", student.nation),
                    Politicstatus = XmlHelper.GetListByXpath("political", student.politicstatus)
                };
                string[] nativePlaces = string.IsNullOrEmpty(student.native_place) ? null : student.native_place.Split('-');
                if (nativePlaces != null)
                {
                    model.Proviences = XmlHelper.GetListByXpath("Provinces.xml", "/Provinces", nativePlaces[0], "ProvinceName", "ID");
                    model.Cities     = XmlHelper.GetListByXpath("Cities.xml", string.Format("/Cities/*[@PID='{0}']", nativePlaces[0]), nativePlaces[1], "CityName", "ID", false);
                    model.Districts  = XmlHelper.GetListByXpath("Districts.xml", string.Format("/Districts/*[@CID='{0}']", nativePlaces[1]), nativePlaces[2], "DistrictName", "ID", false);
                }
                else
                {
                    model.Proviences = XmlHelper.GetListByXpath("Provinces.xml", "/Provinces", "", "ProvinceName", "ID");
                    model.Cities     = new List <SelectListItem>();
                    model.Districts  = new List <SelectListItem>();
                }
            }

            return(model);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 新增一个学生信息 HttpGet
        /// </summary>
        /// <returns></returns>
        public ViewResult Create()
        {
            StudnetEditViewModel model = GetInitStudentEditModel();

            return(View("Edit", model));
        }