Esempio n. 1
0
        /// <summary>
        /// Unbinds the binding source and the Data object. Use this Method to safely disconnect the data object from a BindingSource before saving data.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="cancel">if set to <c>true</c> then call CancelEdit else call EndEdit.</param>
        /// <param name="isRoot">if set to <c>true</c> this BindingSource contains the Root object. Set to <c>false</c> for nested BindingSources</param>
        public static void UnbindBindingSource(BindingSource source, bool cancel, bool isRoot)
        {
            IEditableObject current = null;

            // position may be -1 if bindigsource is already unbound which results in Exception when trying to address current
            if ((source.DataSource != null) && (source.Position > -1))
            {
                current = source.Current as IEditableObject;
            }

            // set Raise list changed to True
            source.RaiseListChangedEvents = false;
            // tell currency manager to suspend binding
            source.SuspendBinding();

            if (isRoot)
            {
                source.DataSource = null;
            }
            if (current == null)
            {
                return;
            }

            if (cancel)
            {
                current.CancelEdit();
            }
            else
            {
                current.EndEdit();
            }
        }
Esempio n. 2
0
        public void UpdateItemViaListSavedEvent()
        {
            UnitTestContext context = GetContext();

            DataPortal.ProxyTypeName = typeof(SynchronizedWcfProxy).AssemblyQualifiedName;
            WcfProxy.DefaultUrl      = cslalighttest.Properties.Resources.RemotePortalUrl;
            ApplicationContext.GlobalContext.Clear();

            RootSingleItemsList.GetRootSingleItemsList(1, 2, (o, e) =>
            {
                context.Assert.Try(() =>
                {
                    context.Assert.IsNotNull(e.Object);
                    RootSingleItemsList list = e.Object;
                    context.Assert.AreEqual(2, list.Count, "Count should be 2");
                    list.Saved += (o1, e1) =>
                    {
                        context.Assert.IsNull(e1.Error);
                        context.Assert.AreEqual(2, list.Count, "Incorrect count after remove");
                        context.Assert.AreEqual("DataPortal_Update", ((SingleItem)e1.NewObject).MethodCalled, "Object should have been updated");
                        context.Assert.IsFalse(list[0].IsDirty, "Object should not be dirty");
                        context.Assert.Success();
                    };

                    // simulate grid edit
                    SingleItem item     = list[0];
                    IEditableObject obj = (IEditableObject)item;
                    obj.BeginEdit();
                    item.Name = "test";
                    obj.EndEdit();
                });
            });
            context.Complete();
        }
        public void Entity_EndEditValidatesRequiredProperties()
        {
            // Start with an entity that doesn't have its required properties
            // satisfied (Name is required)
            Cities.City     city         = new Cities.City();
            IEditableObject editableCity = (IEditableObject)city;

            RequiredAttribute template           = new RequiredAttribute();
            string            expectedMemberName = "CityName";
            string            expectedError      = template.FormatErrorMessage(expectedMemberName);

            // Begin the edit transaction
            editableCity.BeginEdit();

#if SILVERLIGHT
            string expectedMember = "Name";

            // End the edit transaction, which performs property and entity-level validation
            editableCity.EndEdit();
            Assert.AreEqual <int>(1, city.ValidationErrors.Count, "After EndEdit");
            Assert.AreEqual <int>(1, city.ValidationErrors.Single().MemberNames.Count(), "MemberNames count after EndEdit");
            Assert.AreEqual <string>(expectedMember, city.ValidationErrors.Single().MemberNames.Single(), "Member name after EndEdit");
            Assert.AreEqual <string>(expectedError, city.ValidationErrors.Single().ErrorMessage, "ErrorMessage after EndEdit");
#else
            ExceptionHelper.ExpectException <ValidationException>(delegate
            {
                ((IEditableObject)city).EndEdit();
            }, expectedError);
#endif
        }
        /// <summary>
        /// Unbind the binding source and the Data object.
        /// Use this Method to safely disconnect the data object from a BindingSource before saving data.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="cancel">if set to <c>true</c> then call CancelEdit else call EndEdit.</param>
        /// <param name="isRoot">if set to <c>true</c> this BindingSource contains the Root object. Set to <c>false</c> for nested BindingSources</param>
        public static void Unbind(this BindingSource source, bool cancel, bool isRoot)
        {
            IEditableObject current = null;

            // position may be -1 when bindigsource is already unbound
            // and accessing source.Current will then throw Exception.
            if ((source.DataSource != null) && (source.Position > -1))
            {
                current = source.Current as IEditableObject;
            }

            // set Raise list changed to True
            source.RaiseListChangedEvents = false;
            // tell currency manager to suspend binding
            source.SuspendBinding();

            if (isRoot)
            {
                source.DataSource = null;
            }

            if (current == null)
            {
                return;
            }

            if (cancel)
            {
                current.CancelEdit();
            }
            else
            {
                current.EndEdit();
            }
        }
        public void Entity_EndEditValidatesPropertyValues()
        {
            // Start with an entity that has required properties satisfied, but has
            // an invalid property value (for StateName)
            Cities.City city = new Cities.City("This is an invalid state name")
            {
                Name = "Redmond"
            };
            IEditableObject editableCity = (IEditableObject)city;

            StringLengthAttribute template = new StringLengthAttribute(2);
            string expectedMember          = "StateName";
            string expectedError           = template.FormatErrorMessage(expectedMember);

            // Begin the edit transaction
            editableCity.BeginEdit();

#if SILVERLIGHT
            // End the edit transaction, which performs property and entity-level validation
            editableCity.EndEdit();
            Assert.AreEqual <int>(1, city.ValidationErrors.Count, "After EndEdit");
            Assert.AreEqual <int>(1, city.ValidationErrors.Single().MemberNames.Count(), "MemberNames count after EndEdit");
            Assert.AreEqual <string>(expectedMember, city.ValidationErrors.Single().MemberNames.Single(), "Member name after EndEdit");
            Assert.AreEqual <string>(expectedError, city.ValidationErrors.Single().ErrorMessage, "ErrorMessage after EndEdit");
#else
            ExceptionHelper.ExpectException <ValidationException>(delegate
            {
                ((IEditableObject)city).EndEdit();
            }, expectedError);
#endif
        }
        /// <summary>
        /// Commits the current entity editing and exits the editing mode.
        /// </summary>
        /// <param name="dataItem">The entity being edited</param>
        /// <returns>True if a commit operation was invoked.</returns>
        public bool EndEdit(object dataItem)
        {
            IEditableCollectionView editableCollectionView = this.EditableCollectionView;

            if (editableCollectionView != null)
            {
                // IEditableCollectionView.CommitEdit can potentially change currency. If it does,
                // we don't want to attempt a second commit inside our CurrentChanging event handler.
                this._owner.NoCurrentCellChangeCount++;
                this.CommittingEdit = true;
                try
                {
                    editableCollectionView.CommitEdit();
                }
                finally
                {
                    this._owner.NoCurrentCellChangeCount--;
                    this.CommittingEdit = false;
                }
                return(true);
            }

            IEditableObject editableDataItem = dataItem as IEditableObject;

            if (editableDataItem != null)
            {
                editableDataItem.EndEdit();
            }

            return(true);
        }
Esempio n. 7
0
        /// <summary>
        /// Removes the first occurrence of a specific object from the <see cref="T:System.Collections.Generic.ICollection`1"/>.
        /// </summary>
        /// <param name="item">The object to remove from the <see cref="T:System.Collections.Generic.ICollection`1"/>.</param>
        /// <returns>
        /// true if <paramref name="item"/> was successfully removed from the <see cref="T:System.Collections.Generic.ICollection`1"/>; otherwise, false. This method also returns false if <paramref name="item"/> is not found in the original <see cref="T:System.Collections.Generic.ICollection`1"/>.
        /// </returns>
        /// <exception cref="T:System.NotSupportedException">
        /// The <see cref="T:System.Collections.Generic.ICollection`1"/> is read-only.
        /// </exception>
        public bool Remove(TDataItem item)
        {
            int index = this.IndexOf(item);

            if (index != -1)
            {
                if (this.IsDataBound)
                {
                    int count = this.currencyManager.List.Count;

                    IEditableObject itemAsIEditable = item.DataBoundItem as IEditableObject;

                    if (itemAsIEditable != null)
                    {
                        itemAsIEditable.EndEdit();
                    }

                    this.currencyManager.List.Remove(item.DataBoundItem);

                    if (this.currencyManager.List is IBindingList)
                    {
                        return(count != this.currencyManager.List.Count);
                    }
                }

                this.RemoveItem(index);
                return(true);
            }

            return(false);
        }
Esempio n. 8
0
        // Customer changes are about to being saved to database
        private void viewModel_Saving(object sender, ViewModelEventArgs e)
        {
            IEditableObject customer = DataGridCustomers.SelectedItem as Customer;

            customer.EndEdit();

            DataFormCustomer.CommitEdit(true);
        }
Esempio n. 9
0
        protected override void EndEditCore()
        {
            DataGridContext dataGridContext = DataGridControl.GetDataGridContext(this);

            base.EndEditCore();

            DataGridCollectionViewBase dataGridCollectionViewBase =
                (dataGridContext == null) ? null : dataGridContext.ItemsSourceCollection as DataGridCollectionViewBase;

            try
            {
                if (dataGridCollectionViewBase != null)
                {
                    if (dataGridCollectionViewBase.CurrentEditItem == this.DataContext)
                    {
                        dataGridCollectionViewBase.CommitEdit();
                    }
                }
                else
                {
                    IEditableObject editableObject = this.EditableObject;

                    // editableObject can be equal to this when the datarow is directly inserted as Items in the DataGridControl.
                    if ((editableObject != null) && (editableObject != this))
                    {
                        editableObject.EndEdit();
                    }
                }
            }
            catch (Exception exception)
            {
                // Note that we do not update the created cell's Content from the source in case the IEditableObject EndEdit implementation
                // throwed an exception.  This is mainly due because we want to make sure that we do not lose all of the edited cells values.
                // This way, the end user will have the chance to correct the mistakes without loosing everything he typed.

                // If EndEdit throwed, call BeginEdit on the IEditableObject to make sure that it stays in edit mode.
                // We don't have to do this when bound to a DataGridCollectionView since it will take care of it.
                if (dataGridCollectionViewBase == null)
                {
                    IEditableObject editableObject = this.EditableObject;

                    // editableObject can be equal to this when the datarow is directly inserted as Items in the DataGridControl.
                    if ((editableObject != null) && (editableObject != this))
                    {
                        editableObject.BeginEdit();
                    }
                }

                // This method will set a validation error on the row and throw back a DataGridValidationException so that
                // the row stays in edition.
                Row.SetRowValidationErrorOnException(this, exception);
            }

            // Update the created cell's Content from the source in case the IEditableObject EndEdit implementation rectified
            // some values.
            this.UpdateCellsContentBindingTarget();
        }
Esempio n. 10
0
        public void EndEdit()
        {
            IEditableObject wrappedObject = _wrappedObject as IEditableObject;

            if (wrappedObject != null)
            {
                wrappedObject.EndEdit();
            }
        }
Esempio n. 11
0
        /// <include file='doc\PropertyManager.uex' path='docs/doc[@for="PropertyManager.EndCurrentEdit"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public override void EndCurrentEdit()
        {
            PullData();
            IEditableObject obj = this.Current as IEditableObject;

            if (obj != null)
            {
                obj.EndEdit();
            }
        }
Esempio n. 12
0
        public override void EndCurrentEdit()
        {
            PullData(out bool success);

            if (success)
            {
                IEditableObject obj = Current as IEditableObject;
                obj?.EndEdit();
            }
        }
Esempio n. 13
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            if (DataContext is IEditableObject)
            {
                _context = (IEditableObject)DataContext;
            }

            var edit = (Button)GetTemplateChild("EditButton");

            edit.Click += (s, e) =>
            {
                if (_context != null)
                {
                    _context.BeginEdit();
                }
                _hostContent.ContentTemplate = EditTemplate;
                VisualStateManager.GoToState(this, "Edit", true);
            };

            var cancelEdit = (Button)GetTemplateChild("CancelButton");

            cancelEdit.Click += (s, e) =>
            {
                if (_context != null)
                {
                    _context.CancelEdit();
                }
                _hostContent.ContentTemplate = ReadOnlyTemplate;
                VisualStateManager.GoToState(this, "ReadOnly", true);
            };

            var saveButton = (Button)GetTemplateChild("SaveButton");

            saveButton.Click += (s, e) =>
            {
                if (_context != null)
                {
                    if (_context is ICanSave)
                    {
                        if (((ICanSave)_context).CanSave())
                        {
                            _context.EndEdit();
                            _hostContent.ContentTemplate = ReadOnlyTemplate;
                            VisualStateManager.GoToState(this, "ReadOnly", true);
                        }
                    }
                }
            };

            _hostContent                 = (ContentControl)GetTemplateChild("HostContent");
            _hostContent.Content         = DataContext;
            _hostContent.ContentTemplate = ReadOnlyTemplate;
        }
Esempio n. 14
0
        public override void EndCurrentEdit()
        {
            PullData();

            IEditableObject editable = data_source as IEditableObject;

            if (editable == null)
            {
                return;
            }
            editable.EndEdit();
        }
Esempio n. 15
0
        /// <summary>
        /// Override this to provide the logic that undoes the action
        /// </summary>
        protected override void UnExecuteCore()
        {
            IEditableObject edit = ParentObject as IEditableObject;

            if (edit != null)
            {
                edit.BeginEdit();
            }
            Property.SetValue(ParentObject, OldValue, null);
            if (edit != null)
            {
                edit.EndEdit();
            }
        }
        public override void EndCurrentEdit()
        {
            bool flag;

            base.PullData(out flag);
            if (flag)
            {
                IEditableObject current = this.Current as IEditableObject;
                if (current != null)
                {
                    current.EndEdit();
                }
            }
        }
Esempio n. 17
0
        /// <include file='doc\PropertyManager.uex' path='docs/doc[@for="PropertyManager.EndCurrentEdit"]/*' />
        public override void EndCurrentEdit()
        {
            bool success;

            PullData(out success);

            if (success)
            {
                IEditableObject obj = this.Current as IEditableObject;
                if (obj != null)
                {
                    obj.EndEdit();
                }
            }
        }
Esempio n. 18
0
        public bool EndEdit(object dataItem)
        {
            //



            IEditableObject editableDataItem = dataItem as IEditableObject;

            if (editableDataItem != null)
            {
                editableDataItem.EndEdit();
                return(true);
            }

            return(true);
        }
Esempio n. 19
0
        private void SetSubPropertyValue(string propertyPath, object dataObject, object value)
        {
            PropertyDescriptor innerDescriptor = (PropertyDescriptor)null;
            object             innerObject     = (object)null;

            this.GetSubPropertyByPath(propertyPath, dataObject, out innerDescriptor, out innerObject);
            if (innerDescriptor == null)
            {
                return;
            }
            IEditableObject editableObject = innerObject as IEditableObject;

            editableObject?.BeginEdit();
            innerDescriptor.SetValue(innerObject, value);
            editableObject?.EndEdit();
        }
        private void gridTables_CellValueChanged(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
        {
            IEditableObject editableObject = e.Row.DataBoundItem as IEditableObject;

            if (editableObject != null)
            {
                editableObject.EndEdit();
            }

            SyncTables table = e.Row.DataBoundItem as SyncTables;

            if (table != null)
            {
                _entities.Remove(table);
                _entities.Add(table);
            }
        }
Esempio n. 21
0
 public override void EndCurrentEdit()
 {
     if ((this.Count > 0) && this.CurrencyManager_PullData())
     {
         object          obj2 = ((this.Position >= 0) && (this.Position < this.list.Count)) ? this.list[this.Position] : null;
         IEditableObject obj3 = obj2 as IEditableObject;
         if (obj3 != null)
         {
             obj3.EndEdit();
         }
         ICancelAddNew list = this.list as ICancelAddNew;
         if (list != null)
         {
             list.EndNew(this.Position);
         }
     }
 }
Esempio n. 22
0
        public void CanCreateADynamicMultiMockFromTwoInterfacesGenericAndAssertWasCalled()
        {
            IDemo           demo     = MockRepository.GenerateMock <IDemo, IEditableObject>();
            IEditableObject editable = demo as IEditableObject;

            demo.ReturnIntNoArgs();
            editable.BeginEdit();
            editable.CancelEdit(); // we don't care about this
            editable.EndEdit();

            demo.AssertWasCalled(x => x.ReturnIntNoArgs());
            editable.AssertWasCalled(x => x.BeginEdit());
            editable.AssertWasCalled(x => x.EndEdit());

            // Double check all expectations were verified
            editable.VerifyAllExpectations();
        }
Esempio n. 23
0
        public void EndEdit()
        {
            if (beginEditCalled)
            {
                backupData      = new CustomerData();
                beginEditCalled = false;
                Console.WriteLine("Done EndEdit - " + this.custData.id + this.custData.lastName);
                if (ForwardEditableObject != null)
                {
                    ForwardEditableObject.EndEdit();
                }

                if (ParentCollection != null && modified)
                {
                    this.ParentCollection.RaiseListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, ParentCollection.IndexOf(this), -1));
                }
                modified = false;
            }
        }
Esempio n. 24
0
        private void Save_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            IEditableObject meeting = (Meeting)this.LayoutRoot.DataContext;

            meeting.EndEdit();

            this.meetingContext.SubmitChanges(op =>
            {
                if (op.HasError)
                {
                    op.MarkErrorAsHandled();

                    if (op.EntitiesInError.Any())
                    {
                        this.EntityHeader.Focus();
                    }
                }
            }, null);
        }
Esempio n. 25
0
        public int Add(params object[] values)
        {
            if (this.owner.IsVirtualRows)
            {
                return(-1);
            }
            GridViewRowInfo gridViewRowInfo1 = values[0] as GridViewRowInfo;

            if (gridViewRowInfo1 != null)
            {
                this.Add(gridViewRowInfo1);
                return(gridViewRowInfo1.Index);
            }
            if (this.OnRowsChanging(new GridViewCollectionChangingEventArgs(this.owner, NotifyCollectionChangedAction.Add, (object)null, this.Count, -1)))
            {
                return(-1);
            }
            bool notifyUpdates = this.Count == 0;

            this.owner.ListSource.BeginUpdate();
            GridViewRowInfo gridViewRowInfo2 = this.owner.ListSource.AddNew();
            IEditableObject dataBoundItem    = gridViewRowInfo2.DataBoundItem as IEditableObject;

            dataBoundItem?.BeginEdit();
            int num = Math.Min(this.owner.Columns.Count, values.Length);

            for (int index = 0; index < num; ++index)
            {
                GridViewDataColumn column = this.owner.Columns[index];
                gridViewRowInfo2[(GridViewColumn)column] = RadDataConverter.Instance.Parse((IDataConversionInfoProvider)column, values[index]);
            }
            dataBoundItem?.EndEdit();
            this.owner.ListSource.EndUpdate(notifyUpdates);
            ((ICancelAddNew)this.owner.ListSource).EndNew(this.owner.ListSource.Count - 1);
            gridViewRowInfo2.Attach();
            if (this.owner.DataSource == null && this.owner.SortDescriptors.Count > 0)
            {
                this.owner.SortDescriptors.BeginUpdate();
                this.owner.SortDescriptors.EndUpdate(true);
            }
            return(gridViewRowInfo2.Index);
        }
        private static void CanCreateADynamicMultiMockFromTwoInterfacesCommon(IDemo demo, IEditableObject editable)
        {
            Assert.NotNull(demo);
            Assert.NotNull(editable);

            // Set expectation on one member on each interface

            demo.Expect(x => demo.ReadOnly).Return("foo");
            editable.Expect(x => x.BeginEdit());

            // Drive two members on each interface to check dynamic nature

            Assert.Equal("foo", demo.ReadOnly);
            demo.VoidNoArgs();

            editable.BeginEdit();
            editable.EndEdit();

            demo.VerifyAllExpectations();
        }
Esempio n. 27
0
        public override void EndCurrentEdit()
        {
            if (listposition == -1)
            {
                return;
            }

            IEditableObject editable = Current as IEditableObject;

            if (editable != null)
            {
                editing = false;
                editable.EndEdit();
            }

            if (list is ICancelAddNew)
            {
                ((ICancelAddNew)list).EndNew(listposition);
            }
        }
Esempio n. 28
0
        public bool EndEdit(object dataItem)
        {
            //



            IEditableObject editableDataItem = dataItem as IEditableObject;

            if (editableDataItem != null)
            {
                // BeginInvoke this so the Binding has a chance to update the item's value before EndEdit is called
                this._owner.Dispatcher.BeginInvoke(delegate
                {
                    editableDataItem.EndEdit();
                });
                return(true);
            }

            return(true);
        }
Esempio n. 29
0
        protected void UnbindBindingSource(BindingSource source, bool apply, bool isRoot)
        {
            IEditableObject current = source.Current as IEditableObject;

            if (isRoot)
            {
                source.DataSource = null;
            }
            if (current != null)
            {
                if (apply)
                {
                    current.EndEdit();
                }
                else
                {
                    current.CancelEdit();
                }
            }
        }
Esempio n. 30
0
        /// <summary>
        /// Commits the current entity editing and exits the editing mode.
        /// </summary>
        /// <param name="dataItem">The entity being edited</param>
        /// <returns>True if a commit operation was invoked.</returns>
        public bool EndEdit(object dataItem)
        {
#if FEATURE_IEDITABLECOLLECTIONVIEW
            IEditableCollectionView editableCollectionView = this.EditableCollectionView;
            if (editableCollectionView != null)
            {
                // IEditableCollectionView.CommitEdit can potentially change currency. If it does,
                // we don't want to attempt a second commit inside our CurrentChanging event handler.
                _owner.NoCurrentCellChangeCount++;
                this.EndingEdit = true;
                try
                {
                    if (editableCollectionView.IsAddingNew && dataItem == editableCollectionView.CurrentAddItem)
                    {
                        editableCollectionView.CommitNew();
                    }
                    else
                    {
                        editableCollectionView.CommitEdit();
                    }
                }
                finally
                {
                    _owner.NoCurrentCellChangeCount--;
                    this.EndingEdit = false;
                }

                return(true);
            }
#endif

            IEditableObject editableDataItem = dataItem as IEditableObject;
            if (editableDataItem != null)
            {
                editableDataItem.EndEdit();
            }

            return(true);
        }
Esempio n. 31
0
        private static void CanCreateADynamicMultiMockFromTwoInterfacesCommon(MockRepository mocks, IDemo demo, IEditableObject editable)
        {
            Assert.NotNull(demo);
            Assert.NotNull(editable);

            // Set expectation on one member on each interface

            Expect.Call(demo.ReadOnly).Return("foo");
            editable.BeginEdit();

            mocks.ReplayAll();

            // Drive two members on each interface to check dynamic nature

            Assert.Equal("foo", demo.ReadOnly);
            demo.VoidNoArgs();

            editable.BeginEdit();
            editable.EndEdit();

            mocks.VerifyAll();
        }
Esempio n. 32
0
        private static void CanCreateADynamicMultiMockFromTwoInterfacesCommon(IDemo demo, IEditableObject editable)
        {
            Assert.IsNotNull(demo, "IDemo null");
              Assert.IsNotNull(editable, "IEditableObject null");

              // Set expectation on one member on each interface

              demo.Expect(x => demo.ReadOnly).Return("foo");
              editable.Expect(x => x.BeginEdit());

              // Drive two members on each interface to check dynamic nature

              Assert.AreEqual("foo", demo.ReadOnly);
              demo.VoidNoArgs();

              editable.BeginEdit();
              editable.EndEdit();

              demo.VerifyAllExpectations();
        }