예제 #1
0
        /// <summary>
        /// 将 studentDetail 输入框的值 封装为 stduentModel 返回
        /// </summary>
        /// <returns></returns>
        private studentModel FillStudentModelData()
        {
            studentModel stu = new studentModel();

            stu.StudentName = TextBox9.Text.Trim();
            stu.StudentNum  = TextBox1.Text.Trim();
            stu.StudentSex  = TextBox2.Text.Trim();
            stu.Mobile      = TextBox3.Text.Trim();
            stu.Pwd         = TextBox4.Text.Trim();
            stu.Birthday    = TextBox5.Text.Trim();
            stu.Province    = TextBox6.Text.Trim();
            stu.City        = TextBox7.Text.Trim();
            stu.District    = TextBox8.Text.Trim();
            stu.ClassId     = TextBox10.Text.Trim();
            return(stu);
        }
예제 #2
0
        /// <summary>
        /// 添加一个学生信息
        /// </summary>
        private void AddUser()
        {
            studentModel stu = FillStudentModelData();

            if (stu == null)
            {
                return;
            }
            if (Button2.CommandName == "insert")
            {
                //判断学号或手机号是否唯一
                if (IsMobile(stu.StudentNum, stu.Mobile))
                {
                    //如果学号或手机号码 不是唯一的 进行 insert 语句拼接 并执行
                    string sql = @"INSERT INTO studentInfo (studentName,studentNum,studentSex,mobile,password,birthday,province,city,district,classId) VALUES  (N'" + stu.StudentName + "',N'" + stu.StudentNum + "',N'" + stu.StudentSex + "',N'" + stu.Mobile + "',N'"
                                 + stu.Pwd + "','" + stu.Birthday + "',N'" + stu.Province + "',N'" + stu.City + "',N'" + stu.District + "', N'" + stu.ClassId + "')";
                    if (OperaterBase.CommitBySql(sql) > 0)
                    {
                        Label11.Text = "插入成功";
                        // 跳转
                        Response.Redirect("/studentInfo.aspx");
                    }
                }
                else
                {
                    Label11.Text = "插入失败 。。。。";
                }
            }
            else if (Button2.CommandName == "updata")
            {
                // 更新数据
                string upData = "update studentInfo set studentName = N'" + stu.StudentName + "', studentNum = N'" + stu.StudentNum + "' ,studentSex = N'" + stu.StudentSex + "', mobile = N'" + stu.Mobile + "' , password = N'" + stu.Pwd + "', birthday = N'" + stu.Birthday + "',pro" +
                                "vince = N' " + stu.Province + "', city = N'" + stu.City + "',district = N'" + stu.District + " ', classId = 'N" + stu.ClassId + "'";
                if (OperaterBase.CommitBySql(upData) > 0)
                {
                    Label11.Text = "修改成功";
                }
            }
        }