Click here to Skip to main content
15,885,537 members
Articles / Desktop Programming / WPF

GoalBook - A Hybrid Smart Client

Rate me:
Please Sign up or sign in to vote.
4.86/5 (24 votes)
25 Sep 2009CPOL10 min read 79K   834   69  
A WPF hybrid smart client that synchronises your goals with the Toodledo online To-do service.
//===============================================================================
// Goal Book.
// Copyright © 2009 Mark Brownsword. 
//===============================================================================

#region Using Statements
using System.ComponentModel;
using GoalBook.Infrastructure.Interfaces;
using GoalBook.Infrastructure.ObjectModel;
#endregion

namespace GoalBook.Goals.Views
{
    public class GoalsDialogViewPresenter
    {
        #region Constants and Enums
        #endregion

        #region Inner Classes and Structures
        #endregion

        #region Delegates and Events
        #endregion

        #region Instance and Shared Fields
        private readonly IPersistenceService _persistenceService;
        #endregion

        #region Constructors
        /// <summary>
        /// Constructor.
        /// </summary>        
        public GoalsDialogViewPresenter(Goal editGoal, IPersistenceService persistenceService)
        {
            //Reference to PersistenceService.
            _persistenceService = persistenceService;

            //Initialise Model.
            Model = new GoalsDialogViewPresentationModel();
            Model.EditGoal = editGoal;            
            Model.EditGoal.PropertyChanged += new PropertyChangedEventHandler(AddGoal_PropertyChanged);

            //Initialise ReferenceData
            Model.LevelList = _persistenceService.FetchLevelList();
            Model.ContributesList = _persistenceService.FetchContributesList(editGoal.GoalID, editGoal.LevelID);                              
        }               
        #endregion

        #region Properties
        /// <summary>
        /// Reference to Model.
        /// </summary>
        public GoalsDialogViewPresentationModel Model { get; private set; }
        /// <summary>
        /// Reference to View.
        /// </summary>
        public GoalsDialogView View { get; set; }
        #endregion

        #region Private and Protected Methods
        /// <summary>
        /// Handle AddGoal_PropertyChanged event.
        /// </summary>        
        private void AddGoal_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            View.RaiseErrorInfoChanged(Model.EditGoal as IDataErrorInfo);
        }
        /// <summary>
        /// Handle View_LevelChanged event.
        /// </summary>        
        private void View_LevelChanged(GoalBook.Infrastructure.Events.LevelChangedEventArgs e)
        {
            //Reset the ContributesList for the selected Level.
            Model.ContributesList = _persistenceService.FetchContributesList(Model.EditGoal.GoalID, e.LevelID);

            //Reset ComboBoxContributes with new list.
            //View.comboBoxContributes.ItemsSource = null;
            //View.comboBoxContributes.ItemsSource = Model.ContributesList;
            //View.comboBoxContributes.IsEnabled = (Model.ContributesList.Count > 0);

            //Model.EditGoal.ContributesID = Guid.Empty;
        }
        #endregion

        #region Public and internal Methods
        /// <summary>
        /// Initialise the View.
        /// </summary>
        public void InitView()
        {
            View.DataContext = Model;
            View.LevelChanged += new GoalBook.Infrastructure.Events.LevelChangedEventHandler(View_LevelChanged);
            View.comboBoxContributes.IsEnabled = (Model.ContributesList.Count > 0);            
        }
        #endregion

        #region Event Handlers
        #endregion

        #region Base Class Overrides
        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Australia Australia
I've been working as a software developer since 2000 and hold a Bachelor of Business degree from The Open Polytechnic of New Zealand. Computers are for people and I aim to build applications for people that they would want to use.

Comments and Discussions