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();

            }
        }
        }//end Cancel_Click

        //code to handle the Add button click event
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            //add the record to the database
            //the ID must be unique and specified or do not proceed with the add
            if (txtCustomerID.Text.Trim() == "")
            {
                MessageBox.Show("Missing unique Customer ID", "Entry error",
                    MessageBoxButton.OK, MessageBoxImage.Error);

                return;
            }

            //add the record
            Customer cust = new Customer();
            cust.CustomerID = txtCustomerID.Text.Trim();
            cust.CompanyName = txtCompanyName.Text.Trim();
            cust.ContactName = txtContactName.Text.Trim();
            cust.ContactTitle = txtContactTitle.Text.Trim();
            cust.Country = txtCountry.Text.Trim();
            cust.City = txtCity.Text.Trim();
            cust.Region = txtRegionState.Text.Trim();
            cust.PostalCode = txtPostalCode.Text.Trim();
            cust.Address = txtAddress.Text.Trim();
            cust.Phone = txtPhone.Text.Trim();
            cust.Fax = txtFax.Text.Trim();

            //main try block
            try
            {
                //create an instance of a data connection to the database customer table
                CustomerDataDataContext con = new CustomerDataDataContext();

                //add new record to the database
                con.Customers.InsertOnSubmit(cust);
                con.SubmitChanges();

                //tell the user this was added successfully
                MessageBox.Show("Customer " + cust.CustomerID + " was added successfully.");

                //refresh the data grid
                Application app = Application.Current;
                MainWindow main = (MainWindow)app.MainWindow;
                main.refreshGrid();

                //exit the dialog window with a success result
                DialogResult = true;
            }
            catch (Exception ex)
            {
                //tell the user this was successful
                MessageBox.Show("The item '" + cust.CustomerID + "' could not be added.  " + ex.ToString());

                //exit the dialog window without doing anything.
                DialogResult = false;
            }
        }//end btnAdd_Click
        public EditRecord(Customer cust)
        {
            InitializeComponent();
            //asign cust to customer object
            this.customer = cust;

            //put customer data into form fields
            ID.Text = customer.CustomerID;
            CompanyName.Text = customer.CompanyName;
            ContactName.Text = customer.ContactName;
            ContactTitle.Text = customer.ContactTitle;
            Country.Text = customer.Country;
            City.Text = customer.City;
            Region.Text = customer.Region;
            PostalCode.Text = customer.PostalCode;
            Address.Text = customer.Address;
            Phone.Text = customer.Phone;
            Fax.Text = customer.Fax;
        }
        private void OK_Click(object sender, RoutedEventArgs e)
        {
            // Add the record to the datbase

            // The ID must be unique and specified or do not proceed with the add
            if (ID.Text.Trim() == "")
            {
                MessageBox.Show("Missing unique customer ID", "Entry error",
                       MessageBoxButton.OK, MessageBoxImage.Error);

                return;
            }

            // Add the record
            Customer cust = new Customer();
            cust.CustomerID = ID.Text.Trim();
            cust.CompanyName = CompanyName.Text.Trim();
            cust.ContactName = ContactName.Text.Trim();
            cust.ContactTitle = ContactTitle.Text.Trim();
            cust.Country = Country.Text.Trim();
            cust.City = City.Text.Trim();
            cust.Region = Region.Text.Trim();
            cust.PostalCode = PostalCode.Text.Trim();
            cust.Address = Address.Text.Trim();
            cust.Phone = Phone.Text.Trim();
            cust.Fax = Fax.Text.Trim();

            // Create an instance of a data connection to the database customer table
            CustomerDataDataContext con = new CustomerDataDataContext();

            // Add new record to the database
            con.Customers.InsertOnSubmit(cust);
            con.SubmitChanges();

            MessageBox.Show("Customer " + cust.CustomerID + " Was added ok");

            //refresh the display grid to show changes
            Application app = Application.Current;
            MainWindow main = (MainWindow) app.MainWindow;
            main.refreshGrid();
            DialogResult = true;
        }
 partial void DeleteCustomer(Customer instance);
 partial void UpdateCustomer(Customer instance);
 partial void InsertCustomer(Customer instance);