Esempio n. 1
0
        /// <summary>
        /// 保存学生
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Btn_save_Click(object sender, EventArgs e)
        {
            Student studentEntity = new Student();

            studentEntity.Name = this.txt_name.Text;
            int age;

            if (int.TryParse(this.txt_age.Text, out age))
            {
                if (age <= 0 || age > 100)
                {
                    MessageBox.Show("请输入正确的年龄!");
                    return;
                }
                studentEntity.Age = age;
            }
            else
            {
                MessageBox.Show("请输入正确的年龄!");
                this.txt_age.Text = "";
                return;
            }

            if (this.radioButton_man.Checked)
            {
                studentEntity.Sex = 1;
            }
            else
            {
                studentEntity.Sex = 2;
            }
            studentEntity.Birthday = this.dateTimePicker_birthday.Value.Date;

            //数据库操作
            StudentDao studentDao = new StudentDao();

            if (student == null)
            {
                var id = studentDao.Insert(studentEntity);
                studentEntity.Id = id;
                student          = new StudentViewModel(studentEntity);
            }
            else
            {
                studentEntity.Id = student.Id;
                studentDao.Update(studentEntity);
                student.Name     = studentEntity.Name;
                student.Age      = studentEntity.Age;
                student.Sex      = studentEntity.Sex == 1?"男":"女";
                student.Birthday = studentEntity.Birthday;
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Esempio n. 2
0
        /// <summary>
        /// 添加学生
        /// </summary>
        /// <param name="student">学生实体</param>
        /// <returns></returns>
        public Enums.OpResult Insert(Student student)
        {
            int count = dao.Insert(student);

            if (count > 0)
            {
                return(Enums.OpResult.添加成功);
            }
            else
            {
                return(Enums.OpResult.添加失败);
            }
        }
Esempio n. 3
0
        public ActionResult StudentApply(int id)
        {
            var student = ManageStudent.TABULARs.Find(id);

            if (student != null)
            {
                var stu = new StudentDao();
                stu.Insert(student);
                student.Status = true;
                ManageStudent.SaveChanges();
                Mail(student);
            }
            return(View("Admission", GetAdmission()));
        }
Esempio n. 4
0
        public ActionResult Create(Model.EF.Student student)
        {
            var session = (AdminLogin)Session[CommonConstants.USER_SESSION];

            if (session.id_permission != 1)
            {
                return(View("Error"));
            }
            ViewBag.AdminName = session.name;
            if (ModelState.IsValid)
            {
                var dao = new StudentDao();
                if (!string.IsNullOrEmpty(student.password) && dao.IsUserNameExist(student.username))
                {
                    ModelState.AddModelError("", "Tên đăng nhập đã tồn tại.");
                }
                else
                {
                    if (!string.IsNullOrEmpty(student.password))
                    {
                        var encryptedMd5Pas = Encryptor.MD5Hash(student.password);
                        student.password = encryptedMd5Pas;
                    }
                    int id = dao.Insert(student);
                    if (id > 0)
                    {
                        //để thông báo thêm thành công
                        SetNotice("Hệ thống đã thêm thành công.", "success");
                        return(RedirectToAction("Create"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Thêm sinh viên không thành công.");
                    }
                }
            }
            SetViewBag();
            return(View());
        }