Пример #1
0
        private void btInsert_Click(object sender, EventArgs e)
        {
            if (tbProductNumber.TextLength == 0)
            {
                MessageBox.Show("请输入产品编号!");
                return;
            }
            if (cbbQuantifier.Text == "")
            {
                MessageBox.Show("请输入单位!");
                return;
            }
            if (tbProductName.TextLength == 0)
            {
                MessageBox.Show("请输入产品名称!");
                return;
            }
            if (tbProductCount.TextLength == 0)
            {
                MessageBox.Show("请输入产品数量!");
                return;
            }
            if (tbProductPrice.TextLength == 0)
            {
                MessageBox.Show("请输入产品单价!");
                return;
            }
            if (cbbQuantifier.Text == "")
            {
                MessageBox.Show("请选择单位!");
                return;
            }
            if (cbType.Text == "")
            {
                MessageBox.Show("请选择产品类型!");
                return;
            }
            if (tbProductName.Enabled == false)//数据库中已经存在该产品
            {
                int i = db.StockUpdate(tbProductNumber.Text, double.Parse(tbProductCount.Text));
                if (i != 0)
                {
                    f.FormStock_Load(sender, e);
                    this.Close();
                    return;
                }
                MessageBox.Show("添加失败!");
                return;
            }
            int quantifier = db.GetQuantifierID(cbbQuantifier.Text);
            int category   = db.GetCategoryID(cbType.Text);

            if (db.InsertProuduct(tbProductNumber.Text, tbProductName.Text, quantifier, category, tbProductSize.Text, double.Parse(tbProductPrice.Text), tbNote.Text, double.Parse(tbProductCount.Text)) != 0)
            {
                if (fps == null)
                {
                    f.FormStock_Load(sender, e);
                }
                else
                {
                    fps.FormProductSearch_Load(sender, e);
                }
                this.Close();
                return;
            }
            MessageBox.Show("添加失败!");
        }