set increase and decrease button without exceed condition

Refresh

2 weeks ago

Views

7 time

0

I'm trying to make a button which triggered for ascending and descending order of for restocking item.

I have tried do some code, it seems normal for ascending order. The problem i'm facing is that, whenever the number is decreasing, the number is not back to normal in balance field.

private void addStock_Btn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                reStock = Int32.Parse(restock_tb.Text);
                if (reStock >= 0 && reStock < Int32.Parse(qtyAvailable_tb.Text))
                {
                    reStock++;
                    restock_tb.Text = reStock.ToString();
                    qtyBalance = Int32.Parse(qtyAvailable_tb.Text) - Int32.Parse(restock_tb.Text);
                    qtyBalance_tb.Text = qtyBalance.ToString();

                }
            }
            catch
            {
                MessageBox.Show("No item selected to be restock!");
            }        
        }

private void minusStock_Btn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                reStock = Int32.Parse(restock_tb.Text);
                if (reStock > 0)
                {
                    reStock--;
                    restock_tb.Text = reStock.ToString();
                    qtyBalance = Int32.Parse(qtyBalance_tb.Text) + Int32.Parse(restock_tb.Text);
                    qtyBalance_tb.Text = qtyBalance.ToString();
                }
            }
            catch
            {
                MessageBox.Show("No item selected to be restock!");
            }
        }

Expected Output for descending func:

Available: 11, 11, 11, 11, 11, etc...

restock: 11, 10, 9, 8, 7, ... , 0

Balance: 0, 1, 2, 3, 4, ... 11

Current Output that i get is:

Available: 11, 11, 11, 11, 11, etc...

restock: 11, 10, 9, 8, 7, ... , 0

Balance: 0, 10, 19, 27, 34, ... 55

0 answers