//添加会员读者
 private void btnAdd_Click(object sender, EventArgs e)
 {
     #region 数据验证
     if (this.txtReaderName.Text.Trim().Length == 0)
     {
         MessageBox.Show("读者姓名不能为空", "信息提示");
         this.txtReaderName.Focus();
         return;
     }
     if (this.txtReadingCard.Text.Trim().Length == 0)
     {
         MessageBox.Show("借阅证编号不能为空", "信息提示");
         this.txtReadingCard.Focus();
         return;
     }
     //借阅证不能重复
     if (objReaderManager.ExitReaderCard(this.txtReadingCard.Text.Trim()))
     {
         MessageBox.Show("借阅证编号已存在", "信息提示");
         this.txtReadingCard.Focus();
         return;
     }
     if (this.txtIDCard.Text.Trim().Length == 0)
     {
         MessageBox.Show("身份证不能为空", "信息提示");
         this.txtIDCard.Focus();
         return;
     }
     //身份证不能重复
     if (objReaderManager.ExitIDCard(this.txtIDCard.Text.Trim()))
     {
         MessageBox.Show("身份证已存在", "信息提示");
         this.txtIDCard.Focus();
         return;
     }
     if (!(this.rdoMale.Checked || this.rdoFemale.Checked))
     {
         MessageBox.Show("请选择性别", "信息提示");
         this.rdoMale.Focus();
         return;
     }
     if (this.cboReaderRole.Text.Trim().Length == 0)
     {
         MessageBox.Show("会员角色不能为空", "信息提示");
         this.cboReaderRole.Focus();
         return;
     }
     if (this.txtPhone.Text.Trim().Length == 0)
     {
         MessageBox.Show("会员电话不能为空", "信息提示");
         this.txtPhone.Focus();
         return;
     }
     #endregion
     #region 数据封装
     Reader objReader = new Reader()
     {
         IDCard        = this.txtIDCard.Text.Trim(),
         ReaderName    = this.txtReaderName.Text.Trim(),
         ReadingCard   = this.txtReadingCard.Text.Trim(),
         Gender        = this.rdoMale.Checked ? "男" : "女",
         RoleId        = Convert.ToInt32(this.cboReaderRole.SelectedValue),
         PostCode      = this.txtPostcode.Text == null ? "" : this.txtPostcode.Text.Trim(),
         PhoneNumber   = this.txtPhone.Text.Trim(),
         ReaderAddress = this.txtAddress.Text == null ? "" : this.txtAddress.Text.Trim(),
         ReaderImage   = this.pbReaderPhoto.Image == null ? "" : new Common.SerializeObjectToString().SerializeObject(this.pbReaderPhoto.Image)
     };
     #endregion
     #region 数据会员添加更新
     try
     {
         int result = objReaderManager.AddReader(objReader);
         if (result == 1)
         {
             MessageBox.Show("会员添加成功");
             //清空填写框
             foreach (Control item in this.tabPage2.Controls)
             {
                 if (item is TextBox)
                 {
                     ((TextBox)item).Text = "";
                 }
                 if (item is PictureBox)
                 {
                     ((PictureBox)item).Image = null;
                 }
             }
             this.cboReaderRole.SelectedItem = -1;
         }
         else
         {
             MessageBox.Show("会员添加失败,请检查数据");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     #endregion
 }
Esempio n. 2
0
 private void BtnAdd_Click(object sender, EventArgs e)
 {
     #region 数据验证(非空验证)
     if (this.txtReaderName.Text.Trim().Length == 0)
     {
         MessageBox.Show("请输入读者姓名", "提示信息");
         this.txtReaderName.Focus();
         return;
     }
     if (this.txtReadingCard.Text.Trim().Length == 0)
     {
         MessageBox.Show("请输入借阅证编号", "提示信息");
         this.txtReadingCard.Focus();
         return;
     }
     if (!this.rdoMale.Checked && !this.rdoFemale.Checked)
     {
         MessageBox.Show("请选择性别", "提示信息");
         return;
     }
     if (this.cboReaderRole.SelectedIndex == -1)
     {
         MessageBox.Show("请选择会员角色", "提示信息");
         return;
     }
     if (!Common.DataValidate.IsIdentityCard(this.txtIDCard.Text.Trim()))
     {
         MessageBox.Show("请输入正确的身份证号", "提示信息");
         this.txtIDCard.SelectAll();
         this.txtIDCard.Focus();
         return;
     }
     if (this.txtPhone.Text.Trim().Length == 0)
     {
         MessageBox.Show("请输入联系电话", "提示信息");
         this.txtPhone.Focus();
         return;
     }
     #endregion
     #region 重复验证
     try
     {
         if (objReaderManager.IsExistsReadingCard(this.txtReadingCard.Text.Trim()))
         {
             MessageBox.Show("借阅证号重复,请修改", "提示信息");
             this.txtReadingCard.SelectAll();
             this.txtReadingCard.Focus();
             return;
         }
         if (objReaderManager.IsExistsIDCard(this.txtIDCard.Text.Trim()))
         {
             MessageBox.Show("身份证号重复,请修改", "提示信息");
             this.txtIDCard.SelectAll();
             this.txtIDCard.Focus();
             return;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("校验数据是否重复时发生异常,请重试:" + ex.Message, "提示信息");
         return;
     }
     #endregion
     #region 封装数据
     Reader objReader = new Reader()
     {
         ReaderName    = this.txtReaderName.Text.Trim(),
         ReadingCard   = this.txtReadingCard.Text.Trim(),
         Gender        = this.rdoMale.Checked ? "男" : "女",
         RoleId        = Convert.ToInt32(this.cboReaderRole.SelectedValue),
         IDCard        = this.txtIDCard.Text.Trim(),
         PhoneNumber   = this.txtPhone.Text.Trim(),
         ReaderAddress = this.txtAddress.Text.Trim(),
         PostCode      = this.txtPostcode.Text.Trim(),
         ReaderImage   = this.pbReaderPhoto.Image == null ? "" : new Common.SerializeObjectToString().SerializeObject(this.pbReaderPhoto.Image),
         ReaderPwd     = "123456",
         AdminId       = Program.currentAdmin.AdminId
     };
     #endregion
     #region 调用后台方法执行
     try
     {
         objReaderManager.AddReader(objReader);
         MessageBox.Show("添加成功", "提示信息");
         this.txtReaderName.Clear();
         this.txtReadingCard.Clear();
         this.rdoMale.Checked             = false;
         this.rdoFemale.Checked           = false;
         this.cboReaderRole.SelectedIndex = -1;
         this.txtIDCard.Clear();
         this.txtPhone.Clear();
         this.txtAddress.Clear();
         this.txtPostcode.Clear();
         this.pbReaderPhoto.Image = null;
     }
     catch (Exception ex)
     {
         MessageBox.Show("添加发生异常:" + ex.Message, "异常提示");
     }
     #endregion
 }