Exemplo n.º 1
0
        private void RebindUI(bool saveObject, bool rebind)
        {
            // disable events
            this.ResourceBindingSource.RaiseListChangedEvents    = false;
            this.AssignmentsBindingSource.RaiseListChangedEvents = false;
            try
            {
                // unbind the UI
                UnbindBindingSource(this.AssignmentsBindingSource, saveObject, false);
                UnbindBindingSource(this.ResourceBindingSource, saveObject, true);
                this.AssignmentsBindingSource.DataSource = this.ResourceBindingSource;

                // save or cancel changes
                if (saveObject)
                {
                    _resource.ApplyEdit();
                    try
                    {
                        _resource = _resource.Save();
                    }
                    catch (Csla.DataPortalException ex)
                    {
                        MessageBox.Show(ex.BusinessException.ToString(),
                                        "Error saving", MessageBoxButtons.OK,
                                        MessageBoxIcon.Exclamation);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString(),
                                        "Error Saving", MessageBoxButtons.OK,
                                        MessageBoxIcon.Exclamation);
                    }
                }
                else
                {
                    _resource.CancelEdit();
                }
            }
            finally
            {
                // rebind UI if requested
                if (rebind)
                {
                    BindUI();
                }

                // restore events
                this.ResourceBindingSource.RaiseListChangedEvents    = true;
                this.AssignmentsBindingSource.RaiseListChangedEvents = true;

                if (rebind)
                {
                    // refresh the UI if rebinding
                    this.ResourceBindingSource.ResetBindings(false);
                    this.AssignmentsBindingSource.ResetBindings(false);
                }
            }
        }