Пример #1
0
        /// <summary>
        /// 确认添加
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSureUpdate_Click(object sender, RoutedEventArgs e)
        {
            Students students = new Students();

            students.StudentName    = txtName.Text;
            students.Gender         = (radBoy.IsChecked == true ? "男" : "女"); //性别
            students.Birthday       = datePkBirthday.Text;
            students.Age            = Convert.ToInt32(txtAge.Text);           //年龄
            students.CardNo         = txtCardNo.Text;                         //卡号
            students.ClassId        = (int)cmbClassName.SelectedValue;        //选择科目
            students.StudentAddress = txtAddress.Text;
            students.PhoneNumber    = txtPhoneNumber.Text;
            students.StudentIdNo    = txtStuNoId.Text;

            //获取图片的路径
            if (stuImg.Source == new BitmapImage(new Uri("img1/bg/zwzp.jpg", UriKind.RelativeOrAbsolute)))
            {
                students.StuImage = null;
            }
            //判断数据库中的图片是否和目前的上传图片一样
            else
            {
                //证明未修改图片,目前的图片和原来数据库中的一致
                if (image != null && img1.Buffer == image.Buffer)
                {
                    //序列化
                    students.StuImage = Common.BinaryStuObjcet.ZBinaryForStu(image);
                }
                else
                {
                    students.StuImage = Common.BinaryStuObjcet.ZBinaryForStu(img1);
                }
                // GetAddStudent修改的方法,students把上面赋给他的值全部赋给GetAddStudent这个方法
                if (manager.GetAddStudent(students) > 0)//因为用的时增改删所以用的是ExecuteNonQuery这个方法返回数字大于0证明执行成功了
                {
                    System.Windows.MessageBox.Show("添加成功!", "提示");
                    this.Close();
                }
                else
                {
                    System.Windows.MessageBox.Show("添加失败,请稍后再试!", "提示");
                    this.Close();
                }
            }
            //添加进数据库中
            manager.GetAddStudent(students);
        }