예제 #1
0
        /// <summary>
        /// 添加书本
        /// </summary>
        public void 添加书本()
        {
            //执行命令
            if (this.txt_goodsname.Text == "")
            {
                MessageBox.Show("书名不能为空", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            else if (this.txt_tiaoxingma.Text == "")
            {
                MessageBox.Show("书的条形码不能为空", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            else if (this.txt_tiaoxingma.Text == "")
            {
                MessageBox.Show("书的条形码不能为空", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            else if (TextBoxBll.Intextnull(this.txt_zhekou.Text, 4))
            {
                MessageBox.Show("折扣必须为0~1的小数", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            else if (TextBoxBll.Intextnull(this.txt_goodsnum.Text, 2))
            {
                MessageBox.Show("书的数量错误", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            else if (decimal.Parse(this.txt_jinjia.Text.ToString()) < 0 || this.txt_jinjia.Text == "")
            {
                MessageBox.Show("请正确填写书的进价", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            else if (decimal.Parse(this.txt_maijia.Text.ToString()) < 0 || this.txt_maijia.Text == "")
            {
                MessageBox.Show("请正确填写书的售价", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            else if (decimal.Parse(this.txt_zhekou.Text.ToString()) > 0 && decimal.Parse(this.txt_zhekou.Text.ToString()) < 1 || this.txt_zhekou.Text == "")
            {
                MessageBox.Show("请正确填写书的折扣", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                return;
            }
            else if (int.Parse(this.txt_goodsnum.Text.ToString()) < 0)
            {
                MessageBox.Show("进货数量不正确", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            Books gs = new Books();

            gs.BooksName  = this.txt_goodsname.Text;
            gs.TypeID     = TypeBLL.GetTypeIDByTypeName(this.cbo_type.Text);
            gs.BarCode    = this.txt_tiaoxingma.Text;
            gs.StorePrice = decimal.Parse(this.txt_jinjia.Text.ToString());
            gs.SalePrice  = decimal.Parse(this.txt_maijia.Text.ToString());
            gs.Discount   = decimal.Parse(this.txt_zhekou.Text.ToString());
            gs.StockNum   = int.Parse(this.txt_goodsnum.Text);
            gs.StockDate  = DateTime.Parse(DateTime.Now.ToString("yyyy年MM月dd日HH:mm:ss"));
            DataTable dt = BooksBLL.SelectBooksTypeByBarCode(this.txt_tiaoxingma.Text);

            //进货
            if (dt.Rows.Count == 1)
            {
                try
                {
                    //进货
                    int newGoods = int.Parse(this.txt_goodsnum.Text);
                    int oldGoods = int.Parse(dt.Rows[0]["StockNum"].ToString());
                    BooksBLL.InsertbooksByBarCod(newGoods, oldGoods, this.txt_tiaoxingma.Text);
                    MessageBox.Show("进货成功", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    this.txt_goodsname.ReadOnly  = false;
                    this.txt_jinjia.ReadOnly     = false;
                    this.txt_maijia.ReadOnly     = false;
                    this.txt_tiaoxingma.ReadOnly = false;
                    this.txt_zhekou.ReadOnly     = false;
                    this.cbo_type.Enabled        = true;
                    //初始化数据
                    this.cbo_type.Text       = "";
                    this.txt_goodsname.Text  = "";
                    this.txt_goodsnum.Text   = "";
                    this.txt_jinjia.Text     = "";
                    this.txt_maijia.Text     = "";
                    this.txt_tiaoxingma.Text = "";
                    this.txt_zhekou.Text     = "";
                }
            }
            else
            {
                try
                {
                    //执行添加操作
                    if (BooksBLL.InsertBooks(gs))
                    {
                        MessageBox.Show("添加成功", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    //初始化数据
                    this.cbo_type.SelectedIndex = 0;
                    this.txt_goodsname.Text     = "";
                    this.txt_goodsnum.Text      = "";
                    this.txt_jinjia.Text        = "";
                    this.txt_maijia.Text        = "";
                    this.txt_tiaoxingma.Text    = "";
                    this.txt_zhekou.Text        = "";
                }
            }
        }