而不是拥有一组新数据,我该如何添加项目数量

时间:2019-02-04 05:48:29

标签: c# mysql

我有2个datagridview 1是DgCahier 2是DgAddtoCart

将数据从dgcashier传递到dgAddtoCart时,我的代码是这样的:

 private void button7_Click(object sender, EventArgs e)
    {
        if (add1.Text == "Change Quantity")
        {
            select = DGAddToCart.Rows[i];
            select.Cells[5].Value = quan.Text;
            select.Cells[7].Value = subTotal.Text;
            String str = "update tbl_book 
                          set book_quan=book_quan - " + quan.Text + " 
                          where book_code = " + code.Text + "";
            db.updateData1(str);
           String srt="update tbl_damagebook 
                       set dbook_quan=dbook_quan - " + quan.Text + "
                       where dam_id = " + code.Text + "";
            db.updateData1(srt);
            add1.Text = "Add to Cart";
            Total();
            clear1();
        }
        else
        {
            if (quan.Text == "")
            {
                MessageBox.Show("Input Quantity", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (quan.Text.StartsWith("-"))
            {
                MessageBox.Show("Do not input neagtive quntity", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

            } else if (int.Parse(textBox1.Text) < int.Parse(quan.Text))
            {
                MessageBox.Show("Not enough Stocks!", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                DGAddToCart.Rows.Add(code.Text, title.Text, author.Text, edition.Text,year.Text, quan.Text, price.Text, subTotal.Text);



                String strq = "update tbl_book 
                               set book_quan=book_quan - " + quan.Text + " 
                               where book_code=" + code.Text + "";
                db.updateData1(strq);

                String str1 = "update tbl_damagebook 
                               set dbook_quan=dbook_quan - " + quan.Text + " 
                               where dam_id=" + code.Text + "";
                db.updateData1(str1);

我的问题是,如果我添加具有相同描述的相同项目,那么它不会添加所选的当前项目,而是会添加具有相同描述的新项目。

enter image description here

0 个答案:

没有答案