Exemplo n.º 1
0
        protected void ImageButton_submit_Click(object sender, ImageClickEventArgs e)
        {
            if (check())
            {
                ClassBLL classBLL = new ClassBLL();
                StudentBLL stuBLL = new StudentBLL();
                UserBLL userBLL = new UserBLL();

                string stuId = TextBox_stuId.Text.Trim();
                string name = TextBox_name.Text.Trim();
                string gender = RadioButton_male.Checked ? "男" : "女";
                string birth = DropDownList_yearPart1.SelectedValue + DropDownList_yearPart2.SelectedValue + DropDownList_yearPart3.SelectedValue + DropDownList_yearPart4.SelectedValue;
                birth += DropDownList_month.SelectedValue;
                string phone = TextBox_phone.Text.Trim();
                string address = TextBox_address.Text.Trim();
                string classID = DropDownList_class.SelectedValue;

                if (stuBLL.getByStuId(stuId) == null)
                {
                    if (userBLL.getByUsername(stuId) == null)
                    {
                        #region 在用户表中创建新用户
                        User user = new User();
                        user.UserName = stuId;
                        user.Password = EncryptUtil.MD5Encrypt("12345678");
                        user.Type = "4";
                        userBLL.save(user);
                        #endregion

                        Class clazz = classBLL.get(classID);
                        clazz.StudCount = (Convert.ToInt32(clazz.StudCount) + 1).ToString();
                        classBLL.update(clazz);

                        Student stu = new Student();
                        stu.StuId = stuId;
                        stu.Name = name;
                        stu.Gender = gender;
                        stu.Birth = birth;
                        stu.Phone = phone;
                        stu.Address = address;
                        stu.ClassID = classID;
                        stu.UserID = userBLL.getByUsername(stuId).Id;

                        stuBLL.save(stu);
                        Response.Write("<script>alert('添加成功!');location.href='addStudent.aspx';</script>");
                    }
                    else
                        Response.Write("<script>alert('添加失败,用户名已存在!');location.href='addStudent.aspx';</script>");
                }
                else
                {
                    checkStuId.ErrorMessage = "学号已存在!";
                    checkStuId.IsValid = false;
                }

            }
        }
Exemplo n.º 2
0
        protected void ImageButton_delete_Click(object sender, ImageClickEventArgs e)
        {
            ImageButton imageButton = sender as ImageButton;

            string id = imageButton.CommandArgument;

            ClassBLL classBLL = new ClassBLL();
            StudentBLL stuBLL = new StudentBLL();
            UserBLL userBLL = new UserBLL();

            Student stu = stuBLL.get(id);
            User user = userBLL.get(stu.UserID);

            stuBLL.delete(stu);
            userBLL.delete(user);

            Class clazz = classBLL.get(stu.ClassID);
            clazz.StudCount = (Convert.ToInt32(clazz.StudCount) - 1).ToString();
            classBLL.update(clazz);

            Response.Write("<script>alert('删除成功!');location.href='showStudents.aspx';</script>");
        }