/// <summary> Обработчик события кнопки для добавления нового объекта к привязанному свойству самостоятельного объекта</summary> private void AddButtonForIndependent_Click(object sender, RoutedEventArgs e) { if (this.DataContext != null) { DataStorage dataStorage = this.MainMindow.dataStorage; ListView ObjectsList = (sender as Button).Tag as ListView; PropertyInfo propertyInfo = ObjectsList.Tag as PropertyInfo; Type type = propertyInfo.PropertyType.GetElementType(); List <DBObject> objects = dataStorage.GetDBObjects(new DBEntity(type)).Except(ObjectsList.ItemsSource as DBObject[]).ApplyConditions(propertyInfo); SelectionWindow SelectionWindow = new SelectionWindow(objects); if (SelectionWindow.ShowDialog() == true) { List <DBObject> newValue = ObjectsList.ItemsSource.Cast <DBObject>().ToList(); newValue.Add(SelectionWindow.DBObject); propertyInfo.SetValue(this.DataContext, newValue.ToArray().Cast(type), null); dataStorage.AddToCache(SelectionWindow.DBObject); } } else { System.Windows.MessageBox.Show("Редактируемый объект не выбран!", "Внимание!", MessageBoxButton.OK, MessageBoxImage.Exclamation); } }
void ChangeDBObject_Click(object sender, RoutedEventArgs e) { if (this.DataContext != null) { DBEntity entity = new DBEntity(this.Property.PropertyType); List <DBObject> objects = this.DataStorage.GetDBObjects(entity).ApplyConditions(this.Property); SelectionWindow SelectionWindow = new SelectionWindow(objects); if (SelectionWindow.ShowDialog() == true) { this.Property.SetValue(this.DataContext, SelectionWindow.DBObject, null); this.DataStorage.AddToCache(SelectionWindow.DBObject); } } else { System.Windows.MessageBox.Show("Редактируемый объект не выбран!", "Внимание!", MessageBoxButton.OK, MessageBoxImage.Exclamation); } }