示例#1
0
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            // the current binder's customer to edit
            CustomerEntity customerToSave = (CustomerEntity)_customersBinder.Current;

            // there are errors, cancel the save until the user fixes them.
            if (customerToSave.GetEntityFieldsErrors() != string.Empty)
            {
                MessageBox.Show("There are errors in the entity. Please fix them prior to save.", "Please fix the errors.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            // there are not field errors
            else
            {
                // save the current customer
                try
                {
                    customerToSave.Save();
                    DisableEditControls();
                }

                // there are entity errors. Show them to the user
                catch (ORMEntityValidationException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
        private void saveCustomerButton_Click(object sender, System.EventArgs e)
        {
            // unbind orders, so the grids won't interfere with the save results.
            UnbindOrders();

            // save the changes to the persistent storage.
            bool succeeded = _currentCustomer.Save();

            // rebind orders
            BindOrders();

            if (succeeded)
            {
                MessageBox.Show("Save was succesful!", "Save result", MessageBoxButtons.OK, MessageBoxIcon.Information);
                saveCustomerButton.Enabled = false;
            }
            else
            {
                MessageBox.Show(this, "Save was NOT succesful!", "Save result", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }