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

            List <VariableConventionalPlant> dataObjects = VariableThermalPlantsDataAccess.GetObjects();

            foreach (VariableConventionalPlant dataObject in dataObjects)
            {
                UIObjects.Add(new VariableConventionalPlantViewModel(dataObject));
            }

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

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

            return(UIObjects);
        }
示例#3
0
        void ObjectsItemEndEdit(IEditableObject sender)
        {
            VariableConventionalPlantViewModel UIObject = sender as VariableConventionalPlantViewModel;

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