Ejemplo n.º 1
0
        /// <summary>
        /// 修改书本
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void skinButton3_Click(object sender, EventArgs e)
        {
            if (id == 0)
            {
                return;
            }
            //获取类型ID
            booktype = TypeBLL.GetTypeIDByTypeName(this.cbo_type.Text);
            if (booktype == 0)
            {
                MessageBox.Show("请选择书本类型", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            try
            {
                if (error)
                {
                    //修改书本
                    string pattern = @"^[0]+(\.[0-9]{1,3})?$";
                    Match  m       = Regex.Match(this.txt_zhekou.Text, pattern); // 匹配正则表达式

                    if (this.txt_goodname.Text == "" || this.txt_jinjia.Text == "" || this.txt_kucun.Text == "" || this.txt_shoujia.Text == "" || this.txt_tiaoxingma.Text == "" || this.txt_zhekou.Text == "")
                    {
                        MessageBox.Show("带*号不能为空", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    }
                    else if (float.Parse(txt_zhekou.Text) > 1 || float.Parse(txt_zhekou.Text) < 0)
                    {
                        MessageBox.Show("折扣必须输入0~1的数", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    }
                    else if (this.txt_tiaoxingma.Text.Length >= 50)
                    {
                        MessageBox.Show("条形码长度过长", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    }
                    else if (!m.Success && this.txt_zhekou.Text != "1" && this.txt_zhekou.Text != "1.0")
                    {
                        MessageBox.Show("折扣请输入0~1的数字", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        return;
                    }
                    else
                    {
                        if (int.Parse(this.txt_kucun.Text) >= 0)
                        {
                            Books gs = new Books();
                            gs.BooksName  = this.txt_goodname.Text;
                            gs.TypeID     = booktype;
                            gs.BarCode    = this.txt_tiaoxingma.Text;
                            gs.StorePrice = decimal.Parse(this.txt_jinjia.Text.ToString());
                            gs.SalePrice  = decimal.Parse(this.txt_shoujia.Text.ToString());
                            gs.Discount   = decimal.Parse(this.txt_zhekou.Text.ToString());
                            gs.StockNum   = int.Parse(this.txt_kucun.Text);
                            gs.StockDate  = DateTime.Parse(this.dtp_riqi.Text.ToString());
                            gs.BooksID    = id;
                            if (BooksBLL.UpdateBooks(gs))
                            {
                                MessageBox.Show("修改成功", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                                flag = true;
                            }
                        }
                        else
                        {
                            MessageBox.Show("库存必须为正整数,请重新操作", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("书本信息填写失误", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("请联系管理员:" + ex.Message, "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            finally
            {
                if (flag)
                {
                    //绑定数据源
                    this.dgv_goods.DataSource = BooksBLL.GetBooksandType();
                }
            }
        }