void ObjectsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e.Action == NotifyCollectionChangedAction.Remove) { try { foreach (object item in e.OldItems) { ZoneViewModel UIObject = item as ZoneViewModel; ZonesDataAccess.DeleteZone(UIObject.GetDataObject()); } } catch (Exception ex) { log.Error(ex.StackTrace); } } }
private void ZonesCollection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e.Action == NotifyCollectionChangedAction.Remove) { foreach (object item in e.OldItems) { ZoneViewModel deletedZone = item as ZoneViewModel; IEnumerable <ZonesListBox> currentZones = ZonesWrapPanel.ChildrenOfType <ZonesListBox>(); foreach (ZonesListBox zoneListBox in currentZones) { ZoneViewModel currentZone = zoneListBox.DataContext as ZoneViewModel; if (currentZone.Equals(deletedZone)) { ZonesWrapPanel.Children.Remove(zoneListBox); } } ZonesDataAccess.DeleteAllPlantsFromZone(deletedZone.Name); } } }
public ZonesCollectionViewModel GetObjects() { UIObjects = new ZonesCollectionViewModel(); List <Zone> dataObjects = ZonesDataAccess.GetZones(); foreach (Zone dataObject in dataObjects) { UIObjects.Add(new ZoneViewModel(dataObject)); } if (UIObjects.Count == 0) { UIObjects.Add(new ZoneViewModel()); } UIObjects.ItemEndEdit += new ItemEndEditEventHandler(ObjectsItemEndEdit); UIObjects.CollectionChanged += new NotifyCollectionChangedEventHandler(ObjectsCollectionChanged); return(UIObjects); }
private void Plants_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e.Action == NotifyCollectionChangedAction.Add) { foreach (object item in e.NewItems) { if (item is string newPlant) { ZonesDataAccess.AddPlantToZone(Name, newPlant); } } } else if (e.Action == NotifyCollectionChangedAction.Remove) { foreach (object item in e.OldItems) { if (item is string removedPlant) { ZonesDataAccess.DeletePlantFromZone(Name, removedPlant); } } } }
void ObjectsItemEndEdit(IEditableObject sender) { ZoneViewModel UIObject = sender as ZoneViewModel; try { if (UIObject.Name != null) { int id = ZonesDataAccess.UpdateZone(UIObject.GetDataObject()); if (id != -1) { UIObject.Id = id; } } } catch { UIObjects.Remove(UIObject); RadWindow.Alert(new DialogParameters { Content = MessageUtil.FormatMessage("ERROR.DuplicatedZone", UIObject.Name, UIObject.Type) }); } }