Esempio n. 1
0
        /// <summary>
        /// Исключения:
        ///   System.ArgumentNullException:
        ///     Параметр model имеет значение null.
        /// </summary>
        /// <param name="model"></param>
        public DetailItemViewModel(IItemModelAdapter <DataModelType> model,
                                   IDataDetailViewModelCreator <DataModelType, DataDetailViewModelType> viewModelCreator,
                                   IItemModelAdapterCreator <DataModelType> itemModelCreator)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model can't be null");
            }
            if (viewModelCreator == null)
            {
                throw new ArgumentNullException("viewModelCreator can't be null");
            }
            if (itemModelCreator == null)
            {
                throw new ArgumentNullException("itemModelCreator can't be null");
            }

            _model          = model;
            _model.Updated += OnUpdate;
            UpdateCommand   = new UpdateItemCommand <DataModelType, DataDetailViewModelType>(this);
            EditCommand     = new EditItemCommand <DataModelType, DataDetailViewModelType>(this);
            SaveCommand     = new SaveItemCommand <DataModelType, DataDetailViewModelType>(this);

            Debug.Assert(_model.DataModel != null);
            _viewModelCreator = viewModelCreator;
            _itemModelCreator = itemModelCreator;
            DataViewModel     = _viewModelCreator.CreateDataDetailViewModel(_model.DataModel);
        }
        void SelectItemByModel(IItemModelAdapter <DataModelType> itemModel)
        {
            CurrentVM = _creator.CreateDetailViewModel(itemModel);

            Debug.Assert(StateCanChanged != null);
            StateCanChanged(this, new EventArgs());
        }
Esempio n. 3
0
        public override IItemModelAdapter <IEventModel> CreateDeepCopyOfItemModel(IItemModelAdapter <IEventModel> model)
        {
            StationEvent stationEvent = (StationEvent)model.DataModel;
            var          deepCopy     = stationEvent.Copy();
            var          newModel     = new ItemModelAdapterForPassive <IEventModel>(deepCopy);

            return(newModel);
        }
        public IItemModelAdapter <ProductModel> CreateDeepCopyOfItemModel(IItemModelAdapter <ProductModel> model)
        {
            var oldDataModel = model.DataModel;
            var newDataModel
                = new ProductModel(oldDataModel.Name, oldDataModel.Count, oldDataModel.Price);
            var newModel = new ItemModelAdapterForPassive <ProductModel>(newDataModel);

            return(newModel);
        }
Esempio n. 5
0
        public IItemModelAdapter <ShopModel> CreateDeepCopyOfItemModel(IItemModelAdapter <ShopModel> model)
        {
            var oldDataModel = model.DataModel;
            var newDataModel
                = new ShopModel(oldDataModel.Name, oldDataModel.Address, oldDataModel.Description);
            var newModel = new ItemModelAdapterForPassive <ShopModel>(newDataModel);

            return(newModel);
        }
Esempio n. 6
0
 public DetailItemViewModelTimer(IItemModelAdapter <DataModelType> model,
                                 IDataDetailViewModelCreator <DataModelType, DataDetailViewModelType> viewModelCreator,
                                 IItemModelAdapterCreator <DataModelType> itemModelCreator, int updateInterval = 5) :
     base(model, viewModelCreator, itemModelCreator)
 {
     timer          = new System.Windows.Threading.DispatcherTimer();
     timer.Tick    += Timer_Tick;
     timer.Interval = new TimeSpan(0, 0, updateInterval);
     timer.Start();
 }
        public void Save(IItemModelAdapter <DataModelType> saveModel)
        {
            try
            {
                DataModel.Save(saveModel.DataModel);

                Updated?.Invoke(this, new ItemModelAdapterEventArgs <DataModelType>(this));
            }
            catch (Exception ex)
            {
                log.Error(ex, "Save");
            }
        }
Esempio n. 8
0
        void OnUpdate(object sender, ItemModelAdapterEventArgs <DataModelType> e)
        {
            if (!IsEditing)
            {
                if (!IsSaved)
                {
                    _model  = _realModel;
                    IsSaved = true;
                }

                DataViewModel.Update();
                NotifyPropertyChanged("DataViewModel");
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Исключения:
        ///   System.ArgumentNullException:
        ///     Параметр model имеет значение null.
        /// </summary>
        /// <param name="model"></param>
        public ItemViewModel(IItemModelAdapter <DataModelType> model, IDataViewModelCreator <DataModelType, DataViewModelType> creator)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model can't be null");
            }
            _model = model;
            if (creator == null)
            {
                throw new ArgumentNullException("creator can't be null");
            }

            DataViewModel   = creator.CreateDataViewModel(_model.DataModel);
            _model.Updated += OnUpdate;
        }
Esempio n. 10
0
 public void Edit()
 {
     if (CanEdit())
     {
         Debug.Assert(_model != null, "_model is null!!");
         _saveTempModel = _itemModelCreator.CreateDeepCopyOfItemModel(_model);
         _realModel     = _model;
         _model         = _saveTempModel;
         DataViewModel  = _viewModelCreator.CreateDataDetailViewModel(_saveTempModel.DataModel);
         IsEditing      = true;
         IsSaved        = false;
         Debug.Assert(StateCanChanged != null);
         StateCanChanged(this, new EventArgs());
     }
 }
        public IItemViewModel <ProductModel, ProductViewModel> CreateItemViewModel(IItemModelAdapter <ProductModel> itemModel)
        {
            var dataViewModelCreator = new ProductDataViewModelCreator();

            return(new ItemViewModel <ProductModel, ProductViewModel>(itemModel, dataViewModelCreator));
        }
        public IDetailItemViewModel <ProductModel, ProductDetailViewModel> CreateDetailViewModel(IItemModelAdapter <ProductModel> model)
        {
            if (_previosDetailViewModel != null)
            {
                _previosDetailViewModel.Dispose();
            }

            _previosDetailViewModel = new DetailItemViewModelTimer <ProductModel, ProductDetailViewModel>(model, new ProductDataDetailViewModelCreator(), new ProductModelAdapterCreator());
            return(_previosDetailViewModel);
        }
        public IItemViewModel <ShopModel, ShopViewModel> CreateItemViewModel(IItemModelAdapter <ShopModel> itemModel)
        {
            var dataViewModelCreator = new ShopDataViewModelCreator();

            return(new ItemViewModel <ShopModel, ShopViewModel>(itemModel, dataViewModelCreator));
        }
Esempio n. 14
0
        public IItemViewModel <IEventModel, IEventViewModel> CreateItemViewModel(IItemModelAdapter <IEventModel> itemModel)
        {
            var dataViewModelCreator = new EventDataViewModelCreator();

            return(new ItemViewModel <IEventModel, IEventViewModel>(itemModel, dataViewModelCreator));
        }
Esempio n. 15
0
 public virtual IDetailItemViewModel <IEventModel, IDetailEventViewModel> CreateDetailViewModel(IItemModelAdapter <IEventModel> model)
 {
     return(new DetailItemViewModel <IEventModel, IDetailEventViewModel>(model,
                                                                         new EventDataDetailViewModelCreator(), new EventModelAdapterCreator()));
 }
Esempio n. 16
0
 public ItemModelAdapterEventArgs(IItemModelAdapter <DataModelType> _item)
 {
     Item = _item;
 }
Esempio n. 17
0
 public override IDetailItemViewModel <IEventModel, IDetailEventViewModel> CreateDetailViewModel(IItemModelAdapter <IEventModel> model)
 {
     return(new DetailItemViewModel <IEventModel, IDetailEventViewModel>(model,
                                                                         new DeliveryEventDataDetailViewModelCreator(), new DeliveryEventModelAdapterCreator()));
 }