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

            List <HydroElement> dataObjects = HydroElementsDataAccess.GetObjects();

            foreach (HydroElement dataObject in dataObjects)
            {
                UIObjects.Add(new HydroElementViewModel(dataObject));
            }

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

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

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

            try
            {
                if (UIObject.Name != null)
                {
                    int id = HydroElementsDataAccess.UpdateObject(UIObject.GetDataObject());
                    if (id != -1)
                    {
                        UIObject.Id = id;
                    }
                }
            }
            catch
            {
                UIObjects.Remove(UIObject);
                RadWindow.Alert(new DialogParameters
                {
                    Content = MessageUtil.FormatMessage("ERROR.DuplicatedEntryName", UIObject.Name)
                });
            }
        }