Пример #1
0
        private bool RebindUI(bool saveObject, bool rebind)
        {
            // disable events
            ProjectBindingSource.RaiseListChangedEvents = false;
            VendorsBindingSource.RaiseListChangedEvents = false;
            try
            {
                // unbind the UI
                UnbindBindingSource(VendorsBindingSource, saveObject, false);
                UnbindBindingSource(ProjectBindingSource, saveObject, true);
                VendorsBindingSource.DataSource = ProjectBindingSource;

                // save or cancel changes
                if (saveObject)
                {
                    Project.ApplyEdit();
                    try
                    {
                        Project = Project.Save();
                    }
                    catch (DataPortalException ex)
                    {
                        MessageBox.Show(ex.BusinessException.ToString(),
                                        "Error saving", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return(false);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString(),
                                        "Error Saving", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return(false);
                    }
                }
                else
                {
                    Project.CancelEdit();
                }

                return(true);
            }
            finally
            {
                // rebind UI if requested
                if (rebind)
                {
                    BindUI();
                }

                // restore events
                ProjectBindingSource.RaiseListChangedEvents = true;
                VendorsBindingSource.RaiseListChangedEvents = true;

                if (rebind)
                {
                    // refresh the UI if rebinding
                    ProjectBindingSource.ResetBindings(false);
                    VendorsBindingSource.ResetBindings(false);
                }
            }
        }
Пример #2
0
 private void Project_PropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     if (e.PropertyName == "IsDirty")
     {
         ProjectBindingSource.ResetBindings(true);
     }
 }