예제 #1
0
        /// <summary>
        /// 获取用户输入的内容,并封装到model中
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnUpadate_Click(object sender, EventArgs e)
        {
            Stmodel model = new Stmodel();

            #region ***************对非空选项:为空,就报警!*************
            if (string.IsNullOrEmpty(this.txtName.Text.Trim()))
            {
                MessageBox.Show("姓名不能为空!", "SQL提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            string STR_Birthday = this.cmbYear.Text.Trim() + "-" + this.cmbMonth.Text.Trim() + "-" + this.cmbDay.Text.Trim();
            if (string.IsNullOrEmpty(cmbYear.Text.Trim()) || string.IsNullOrEmpty(cmbYear.Text.Trim()) || string.IsNullOrEmpty(cmbDay.Text.Trim()))
            {
                MessageBox.Show("年、月、日不能为空!", "SQL提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (this.radioMan.Checked.Equals(false) && this.radioWomen.Checked.Equals(false))
            {
                MessageBox.Show("性别不能为空!", "SQL提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            #endregion

            #region ********对可空的选型:如果内容为空,不做任何处理;否则,进行格式验证***************
            IsOkForm yanzheng = new IsOkForm();
            //身高是可以为空的
            if (string.IsNullOrEmpty(this.txtHeight.Text))
            {
                model.Sheight = null;                            //为空赋值为null
            }
            else if (!(yanzheng.IsDecimal(this.txtHeight.Text))) //不为空就验证,验证通过就在下面继续赋值
            {
                MessageBox.Show("身高非数字或格式不正确!", "SQL提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            //体重是可以为空的
            if (string.IsNullOrEmpty(this.txtWeight.Text))
            {
                model.Sweight = null;                                                                                 //为空赋值为null
            }
            else if (!(yanzheng.IsIntNumber(this.txtWeight.Text) && yanzheng.IsIntNumberLength(this.txtWeight.Text))) //不为空就验证,验证通过就在下面继续赋值
            {
                MessageBox.Show("体重为非数字或格式不正确!", "SQL提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            #endregion

            #region 在这里进行这样的故事:1.数据的类型转换(难点五星级)2.文本输入的格式控制(自己百度的!))
            string bithday = STR_Birthday;
            bool   gender  = false;
            if (this.radioMan.Checked)
            {
                gender = true;
            }

            string heightYanZhengHou = this.txtHeight.Text.Trim();
            string weightYanZhengHou = this.txtWeight.Text.Trim();

            model.Sname     = this.txtName.Text.Trim();
            model.Sbirthday = DateTime.Parse(Convert.ToDateTime(bithday).ToString("yyyy-MM-dd"));
            model.Sgender   = gender;

            #region 对身高、体重使用Decimal.TryParse(),Int32.TryParse()这种转化方法,不使用Convert.toDecimal()这种,因为这个转化处理为空的情况,报异常多(能让你抓狂!!)
            decimal result = 0;
            if (Decimal.TryParse(heightYanZhengHou, out result))
            {
                model.Sheight = result;
            }
            else
            {
                model.Sheight = 0;
            }

            int result1 = 0;
            if (Int32.TryParse(weightYanZhengHou, out result1))
            {
                model.Sweight = result1;
            }
            else
            {
                model.Sweight = 0;
            }
            #endregion
            //model.Sweight = Convert.ToInt32(weightYanZhengHou);//就是这个:不建议使用的方法!!
            model.Saddress = this.txtAddress.Text.Trim();
            #endregion



            #region 调用业务逻辑层的返回值(可以这么讲,有没有添加成功:业务逻辑层StInfoAdd()方法说了算数;

            if (Bll.StInfoAdd(model))//业务逻辑层返回时为"真"就是添加成功
            {
                MessageBox.Show("添加成功!", "SQL提示", MessageBoxButtons.OK);
                this.Hide();
                Main main = new Main();
                main.Show();
            }
            else
            {
                MessageBox.Show("添加失败!", "SQL提示", MessageBoxButtons.OK);
            }
            #endregion
        }
예제 #2
0
        private void btnUpadate_Click(object sender, EventArgs e)
        {
            //点击“更新”按钮事件:将修该过的每个属性封装为实体model传递到Bll层
            Stmodel  model    = new Stmodel();
            IsOkForm yanzheng = new IsOkForm();


            #region  ***************对非空选项:为空,就报警!*************
            if (string.IsNullOrEmpty(this.txtName.Text.Trim()))
            {
                MessageBox.Show("姓名不能为空!", "SQL提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            string STR_Birthday = cmbYear.Text.Trim() + "-" + cmbMonth.Text.Trim() + "-" + cmbDay.Text.Trim();
            //如果年、月、日有一个是空的就报警!
            if (string.IsNullOrEmpty(cmbYear.Text.Trim()) || string.IsNullOrEmpty(cmbYear.Text.Trim()) || string.IsNullOrEmpty(cmbDay.Text.Trim()))
            {
                MessageBox.Show("年、月、日不能为空!", "SQL提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (this.radioMan.Checked.Equals(false) && this.radioWomen.Checked.Equals(false))
            {
                MessageBox.Show("性别不能为空!", "SQL提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            #endregion


            #region ********对可空的选型处理:如果内容为空,不做任何处理;否则,进行格式验证***************
            if (string.IsNullOrEmpty(this.txtHeight.Text))
            {
                model.Sheight = null;                            //为空赋值为null
            }
            else if (!(yanzheng.IsDecimal(this.txtHeight.Text))) //不为空就验证,验证通过就在下面继续赋值
            {
                MessageBox.Show("身高非数字或格式不正确!", "SQL提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            //体重是可以为空的
            if (string.IsNullOrEmpty(this.txtWeight.Text))
            {
                model.Sweight = null;                                                                                 //为空赋值为null
            }
            else if (!(yanzheng.IsIntNumber(this.txtWeight.Text) && yanzheng.IsIntNumberLength(this.txtWeight.Text))) //不为空就验证,验证通过就在下面继续赋值
            {
                MessageBox.Show("体重为非数字或格式不正确!", "SQL提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            #endregion

            string heightYanZhengHou = this.txtHeight.Text.Trim();
            string weightYanZhengHou = this.txtWeight.Text.Trim();

            model.Sname     = this.txtName.Text;
            model.Sbirthday = DateTime.Parse(Convert.ToDateTime(STR_Birthday).ToString("yyyy-MM-dd"));
            if (this.radioMan.Checked == true)//若是Man被选中,就给model赋值为true
            {
                model.Sgender.Equals(true);
            }
            else
            {
                model.Sgender.Equals(false);
            };
            #region 对身高、体重使用.TryParse(),不使用Convert.toDecimal()这种,因为这个转化处理为空,报异常多
            decimal result = 0;
            if (Decimal.TryParse(heightYanZhengHou, out result))
            {
                model.Sheight = result;
            }
            else
            {
                model.Sheight = 0;
            }

            int result1 = 0;
            if (Int32.TryParse(weightYanZhengHou, out result1))
            {
                model.Sweight = result1;
            }
            else
            {
                model.Sweight = 0;
            }
            #endregion
            model.Saddress = this.txtAddress.Text;


            model.Sid = Sid;//id还没有,所以要把id传进来,通过构造函数来传递


            //通过业务逻辑层中的StInfoUpdate()将封装好的model进行处理,根据Bll处理结果写如下
            if (Bll.StInfoUpdate(model))
            {
                MessageBox.Show("修改成功!", "SQL提示", MessageBoxButtons.OK);
                this.Hide();
                Main main = new Main();
                main.Show();
            }
            else
            {
                MessageBox.Show("修改失败!", "SQL提示", MessageBoxButtons.OK);
            }
        }
예제 #3
0
        /// <summary>
        /// 获取用户输入的内容,并封装到model中
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnUpadate_Click(object sender, EventArgs e)
        {
            Stmodel model = new Stmodel();

            #region ***************对非空选项:为空,就报警!*************
            if (string.IsNullOrEmpty(this.txtName.Text.Trim()))
            {
                MessageBox.Show("姓名不能为空!", "SQL提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            string STR_Birthday = this.cmbYear.Text.Trim() + "-" + this.cmbMonth.Text.Trim() + "-" + this.cmbDay.Text.Trim();
            if (string.IsNullOrEmpty(cmbYear.Text.Trim()) || string.IsNullOrEmpty(cmbYear.Text.Trim()) || string.IsNullOrEmpty(cmbDay.Text.Trim()))
            {
                MessageBox.Show("年、月、日不能为空!", "SQL提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (this.radioMan.Checked.Equals(false) && this.radioWomen.Checked.Equals(false))
            {
                MessageBox.Show("性别不能为空!", "SQL提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            #endregion

            #region ********对可空的选型:如果内容为空,不做任何处理;否则,进行格式验证***************
            IsOkForm yanzheng = new IsOkForm();
            //身高是可以为空的
            if (string.IsNullOrEmpty(this.txtHeight.Text))
            {

                model.Sheight = null;//为空赋值为null

            }
            else if (!(yanzheng.IsDecimal(this.txtHeight.Text)))//不为空就验证,验证通过就在下面继续赋值
            {
                MessageBox.Show("身高非数字或格式不正确!", "SQL提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;


            }
            //体重是可以为空的
            if (string.IsNullOrEmpty(this.txtWeight.Text))
            {

                model.Sweight = null;//为空赋值为null
            }
            else if (!(yanzheng.IsIntNumber(this.txtWeight.Text) && yanzheng.IsIntNumberLength(this.txtWeight.Text)))//不为空就验证,验证通过就在下面继续赋值
            {
                MessageBox.Show("体重为非数字或格式不正确!", "SQL提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            #endregion

            #region 在这里进行这样的故事:1.数据的类型转换(难点五星级)2.文本输入的格式控制(自己百度的!))
            string bithday = STR_Birthday;
            bool gender = false;
            if (this.radioMan.Checked)
            {
                gender = true;
            }

            string heightYanZhengHou = this.txtHeight.Text.Trim();
            string weightYanZhengHou = this.txtWeight.Text.Trim();

            model.Sname = this.txtName.Text.Trim();
            model.Sbirthday = DateTime.Parse(Convert.ToDateTime(bithday).ToString("yyyy-MM-dd"));
            model.Sgender = gender;

            #region 对身高、体重使用Decimal.TryParse(),Int32.TryParse()这种转化方法,不使用Convert.toDecimal()这种,因为这个转化处理为空的情况,报异常多(能让你抓狂!!)
            decimal result = 0;
            if (Decimal.TryParse(heightYanZhengHou, out result))
            {

                model.Sheight = result;
            }
            else
            {
                model.Sheight = 0;
            }

            int result1 = 0;
            if (Int32.TryParse(weightYanZhengHou, out result1))
            {
                model.Sweight = result1;
            }
            else
            {
                model.Sweight = 0;
            }
            #endregion
            //model.Sweight = Convert.ToInt32(weightYanZhengHou);//就是这个:不建议使用的方法!!
            model.Saddress = this.txtAddress.Text.Trim();
            #endregion



            #region 调用业务逻辑层的返回值(可以这么讲,有没有添加成功:业务逻辑层StInfoAdd()方法说了算数;

            if (Bll.StInfoAdd(model))//业务逻辑层返回时为"真"就是添加成功
            {
                MessageBox.Show("添加成功!", "SQL提示", MessageBoxButtons.OK);
                this.Hide();
                Main main = new Main();
                main.Show();

            }
            else
            {
                MessageBox.Show("添加失败!", "SQL提示", MessageBoxButtons.OK);
            }
            #endregion

        } 
예제 #4
0
        private void btnUpadate_Click(object sender, EventArgs e)
        {
            //点击“更新”按钮事件:将修该过的每个属性封装为实体model传递到Bll层
            Stmodel model = new Stmodel();
            IsOkForm yanzheng = new IsOkForm();


            #region  ***************对非空选项:为空,就报警!*************
            if (string.IsNullOrEmpty(this.txtName.Text.Trim()))
            {
                MessageBox.Show("姓名不能为空!", "SQL提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            string STR_Birthday = cmbYear.Text.Trim() + "-" + cmbMonth.Text.Trim() + "-" + cmbDay.Text.Trim();
            //如果年、月、日有一个是空的就报警!
            if (string.IsNullOrEmpty(cmbYear.Text.Trim()) || string.IsNullOrEmpty(cmbYear.Text.Trim()) || string.IsNullOrEmpty(cmbDay.Text.Trim()))
            {
                MessageBox.Show("年、月、日不能为空!", "SQL提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (this.radioMan.Checked.Equals(false) && this.radioWomen.Checked.Equals(false))
            {
                MessageBox.Show("性别不能为空!", "SQL提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            #endregion


            #region ********对可空的选型处理:如果内容为空,不做任何处理;否则,进行格式验证***************
            if (string.IsNullOrEmpty(this.txtHeight.Text))
            {

                model.Sheight = null;//为空赋值为null

            }
            else if (!(yanzheng.IsDecimal(this.txtHeight.Text)))//不为空就验证,验证通过就在下面继续赋值
            {
                MessageBox.Show("身高非数字或格式不正确!", "SQL提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;


            }
            //体重是可以为空的
            if (string.IsNullOrEmpty(this.txtWeight.Text))
            {

                model.Sweight = null;//为空赋值为null
            }
            else if (!(yanzheng.IsIntNumber(this.txtWeight.Text) && yanzheng.IsIntNumberLength(this.txtWeight.Text)))//不为空就验证,验证通过就在下面继续赋值
            {
                MessageBox.Show("体重为非数字或格式不正确!", "SQL提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            #endregion

            string heightYanZhengHou = this.txtHeight.Text.Trim();
            string weightYanZhengHou = this.txtWeight.Text.Trim();

            model.Sname = this.txtName.Text;
            model.Sbirthday = DateTime.Parse(Convert.ToDateTime(STR_Birthday).ToString("yyyy-MM-dd"));
            if (this.radioMan.Checked == true)//若是Man被选中,就给model赋值为true
            {
                model.Sgender.Equals(true);
            }
            else
            {
                model.Sgender.Equals(false);
            };
            #region 对身高、体重使用.TryParse(),不使用Convert.toDecimal()这种,因为这个转化处理为空,报异常多
            decimal result = 0;
            if (Decimal.TryParse(heightYanZhengHou, out result))
            {

                model.Sheight = result;
            }
            else
            {
                model.Sheight = 0;
            }

            int result1 = 0;
            if (Int32.TryParse(weightYanZhengHou, out result1))
            {
                model.Sweight = result1;
            }
            else
            {
                model.Sweight = 0;
            }
            #endregion
            model.Saddress = this.txtAddress.Text;


            model.Sid = Sid;//id还没有,所以要把id传进来,通过构造函数来传递


            //通过业务逻辑层中的StInfoUpdate()将封装好的model进行处理,根据Bll处理结果写如下
            if (Bll.StInfoUpdate(model))
            {
                MessageBox.Show("修改成功!", "SQL提示", MessageBoxButtons.OK);
                this.Hide();
                Main main = new Main();
                main.Show();
            }
            else
            {
                MessageBox.Show("修改失败!", "SQL提示", MessageBoxButtons.OK);
            }
        }