// Confirm Button private void confirmButton_Click(object sender, RoutedEventArgs e) { conn.Close(); try { if (currentQty.Text == "") { MessageBox.Show("Fields cannot be empty", "Refund", MessageBoxButton.OK, MessageBoxImage.Warning); } else if (int.Parse(currentQty.Text) > int.Parse(datasalesinventoryQty)) { MessageBox.Show("Your input is too large, " + datasalesinventoryQty + " is the max", "Refund", MessageBoxButton.OK, MessageBoxImage.Warning); } else if (int.Parse(currentQty.Text) == int.Parse(datasalesinventoryQty)) { string query = "UPDATE datainventory SET prodQty = (prodQty + @prodQty) WHERE prodNo = @prodNo"; conn.query(query); conn.Open(); conn.bind("@prodQty", currentQty.Text); conn.bind("@prodNo", data2); conn.cmd().Prepare(); var success = conn.execute(); if (success > 0) { MessageBox.Show(currentQty.Text + " has been returned to the database", "Refund", MessageBoxButton.OK, MessageBoxImage.Information); } conn.Close(); //// // Delete this stock out item record string removeRecord = "DELETE FROM datasalesinventory WHERE refNo = @refno"; conn.query(removeRecord); conn.Open(); conn.bind("@refno", data); conn.bind("@prodno", data2); conn.cmd().Prepare(); conn.execute(); conn.Close(); this.Close(); win_refund.fetchData(); win_refund.itemQuantity.IsEnabled = false; win_refund.itemRefund.IsEnabled = false; } else { // Add data to datainventory string query = "UPDATE datainventory SET prodQty = (prodQty + @prodQty) WHERE prodNo = @prodNo"; conn.query(query); conn.Open(); conn.bind("@prodQty", currentQty.Text); conn.bind("@prodNo", data2); conn.cmd().Prepare(); var success = conn.execute(); if (success > 0) { MessageBox.Show(currentQty.Text + " has been returned to the database", "Refund", MessageBoxButton.OK, MessageBoxImage.Information); } conn.Close(); //// string reduceFromStockout = "UPDATE datasalesinventory SET salesQty = (salesQty - @salesQty) WHERE refno = @refno"; conn.query(reduceFromStockout); conn.Open(); conn.bind("@refno", data); conn.bind("@salesQty", currentQty.Text); conn.cmd().Prepare(); conn.execute(); conn.Close(); //// this.Close(); win_refund.fetchData(); win_refund.itemQuantity.IsEnabled = false; win_refund.itemRefund.IsEnabled = false; } } catch (Exception) { conn.Close(); MessageBox.Show("Something went wrong returning your item, try again later"); } }