}//end mnuitemAddRecord_Click //menu item click event for Edit Record private void mnuitemEditRecord_Click(object sender, RoutedEventArgs e) { //local variables string rowID; //figure out which row in the datagrid is selected object item = CustomerDataGrid.SelectedItem; //try block to prevent an error found during coding. The delete method throws an error if no row //is selected in the datagrid. try { rowID = (CustomerDataGrid.SelectedCells[0].Column.GetCellContent(item) as TextBlock).Text; } catch { //no rows are highlighted in the grid MessageBox.Show("Please select a row in the datagrid to edit and try again."); return; } //check to make sure we received a valid rowID if (rowID != null) { //show the Edit Record window EditRecord editRecordWindow = new EditRecord(rowID); editRecordWindow.ShowDialog(); } }//end mnuitemEditRecord_Click
private void FindRecord_Click(object sender, RoutedEventArgs e) { //create a new empty customer object Customer find = new Customer(); //get customer ID from form String CustID = FindID.Text.Trim(); // Create an instance of a data connection to the database customer table CustomerDataDataContext con = new CustomerDataDataContext(); //find customer based upod ID find = (from cust in con.Customers where (cust.CustomerID == CustID) select cust).FirstOrDefault(); //if a matching customer is not found if (object.Equals(find, default(Customer))) { MessageBox.Show("Customer Does not Exist!"); } //if found proceed else { // Close the find edit window DialogResult = false; //open the edit record window EditRecord editRecordWindow = new EditRecord(find); editRecordWindow.ShowDialog(); } }