Exemple #1
0
        private void BtnEdit_Click(object sender, RoutedEventArgs e)
        {
            if (controlsEnabled == false)
            {
                controlsEnabled = EnableControls();
                btnBack.Content = "Cancel";
                btnEdit.Content = "Save Changes";
            }
            else
            {
                MessageBoxResult result = MessageBox.Show("Save Changes?", "Confirmation", MessageBoxButton.YesNo);

                if (result == MessageBoxResult.Yes)
                {
                    string queryUpdateItem = string.Format("UPDATE items " +
                                                           "SET " +
                                                           "item_name=@item_name, " +
                                                           "item_price=@item_price " +
                                                           "WHERE " +
                                                           "item_code=@item_code");

                    try
                    {
                        if (SqlQueries.UpdateItem(queryUpdateItem, txtItemName.Text, Convert.ToInt32(txtItemPrice.Text), lblItemCode.Content.ToString()) == true)
                        {
                            MessageBox.Show("Item Edited");

                            main.Load_Items();

                            this.Close();
                        }
                        else
                        {
                            MessageBox.Show("Something went wrong");
                        }
                    }
                    catch (Exception err)
                    {
                        MessageBox.Show(err.Message);
                    }
                }
            }
        }