/// <summary> /// Override the default behavior of the delete button on the Customer's BindingNavigator /// - Select the delete button in the property window of the BindingNavigator, a ComboBox /// is displayed, select none. Next double click on the delete button which created the /// event below. If you don't follow the steps above then the default action (delete) /// will happen then your code in the click event below /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e) { if (KarenDialogs.Question("Do you really want to remove the current customer?")) { customersBindingSource.RemoveCurrent(); } }
public void PromptToRemoveCurrentRecordInDataGridViewFromBindingSource() { if (DataGridView.IsValidDataGridViewButton(RemoveButtonName)) { if (KarenDialogs.Question($"Remove '{BindingSource.CurrentRow().Field<string>("CompanyName")}'")) { if (Operations.FakeRemoveCustomer(BindingSource.CurrentRow().Field <int>("CustomerIdentifier"))) { BindingSource.RemoveCurrent(); } } } }
public void UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) { if (KarenDialogs.Question($"Remove '{BindingSource.CurrentRow().Field<string>("CompanyName")}'")) { if (Operations.FakeRemoveCustomer(BindingSource.CurrentRow().Field <int>("CustomerIdentifier"))) { BindingSource.RemoveCurrent(); } } else { e.Cancel = true; } }
/// <summary> /// Remove current customer and all orders /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MasterBindingNavigatorDeleteCustomer_Click(object sender, EventArgs e) { if (KarenDialogs.Question("Do you really want to remove this customer and all their orders?")) { var ops = new Operations(); int customerId = ((DataRowView)bsMaster.Current).Row.Field <int>("id"); if (ops.RemoveCustomerAndOrders(customerId)) { bsMaster.RemoveCurrent(); } else { MessageBox.Show($"Failed to remove data{Environment.NewLine}{ops.ExceptionMessage}"); } } }
private void DetailsBindingNavigatorDeleteItem_Click(object sender, EventArgs e) { if (KarenDialogs.Question("Remove this order?")) { int OrderId = ((DataRowView)bsDetails.Current).Row.Field <int>("id"); var ops = new Operations(); if (!(ops.RemoveSingleOrder(OrderId))) { MessageBox.Show($"Failed to update: {ops.ExceptionMessage}"); } else { bsDetails.RemoveCurrent(); } } }
private void customersBindingNavigatorSaveItem_Click_1(object sender, EventArgs e) { if (northWindDataSet.HasChanges()) { if (KarenDialogs.Question("Save changes back to database?")) { this.Validate(); this.customersBindingSource.EndEdit(); /* * Manually added */ this.ordersBindingSource.EndEdit(); this.tableAdapterManager.UpdateAll(this.northWindDataSet); } } else { MessageBox.Show("There are no changes"); } }
/// <summary> /// Simple example to add rows to our child table /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <remarks> /// This has already been executed running this again would /// duplicate the row. So we could run the following (super simple) /// /// SELECT id FROM EventAttachments WHERE FileBaseName = 'CPR' /// /// To ensure it does not exists, of course we would do more conditions /// in the WHERE for a real app. /// </remarks> private void button3_Click(object sender, EventArgs e) { if (KarenDialogs.Question("You might want to read comments first, continue?")) { var ops = new DataOperations(); var fileName = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "EventFiles", "CPR_2.docx"); // new identifier returned var Identifier = 0; // existing row in parent table var EventIdentifier = 1; if (ops.FilePutForEvents(fileName, ref Identifier, EventIdentifier)) { MessageBox.Show("Success"); } else { MessageBox.Show($"Failed: {ops.ExceptionMessage}"); } } }