예제 #1
0
 void ObjectsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
 {
     if (e.Action == NotifyCollectionChangedAction.Remove)
     {
         try
         {
             foreach (object item in e.OldItems)
             {
                 VariableHydroPlantViewModel UIObject = item as VariableHydroPlantViewModel;
                 VariableHydroPlantsDataAccess.DeleteObject(UIObject.GetDataObject());
             }
         }
         catch (Exception ex)
         {
             log.Error(ex.StackTrace);
         }
     }
 }
예제 #2
0
        public VariableHydroPlantsCollectionViewModel GetObjects()
        {
            UIObjects = new VariableHydroPlantsCollectionViewModel();

            List <VariableHydroPlant> dataObjects = VariableHydroPlantsDataAccess.GetObjects();

            foreach (VariableHydroPlant dataObject in dataObjects)
            {
                UIObjects.Add(new VariableHydroPlantViewModel(dataObject));
            }

            if (UIObjects.Count == 0)
            {
                UIObjects.Add(new VariableHydroPlantViewModel());
            }

            UIObjects.ItemEndEdit       += new ItemEndEditEventHandler(ObjectsItemEndEdit);
            UIObjects.CollectionChanged += new NotifyCollectionChangedEventHandler(ObjectsCollectionChanged);

            return(UIObjects);
        }
예제 #3
0
        void ObjectsItemEndEdit(IEditableObject sender)
        {
            VariableHydroPlantViewModel UIObject = sender as VariableHydroPlantViewModel;

            try
            {
                if (UIObject.Name != null && UIObject.Reservoir != null)
                {
                    int id = VariableHydroPlantsDataAccess.UpdateObject(UIObject.GetDataObject());
                    if (id != -1)
                    {
                        UIObject.Id = id;
                    }
                }
            }
            catch
            {
                UIObjects.Remove(UIObject);
                MessageBox.Show(MessageUtil.FormatMessage("ERROR.DuplicatedVariableHydroPlant", UIObject.Name, UIObject.Reservoir, UIObject.Segment, UIObject.Case),
                                "DHOG", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
        }