Click here to Skip to main content
15,881,840 members
Articles / Desktop Programming / Windows Forms

Task Manager

Rate me:
Please Sign up or sign in to vote.
4.90/5 (105 votes)
1 Jan 2010CPOL4 min read 203.7K   21K   229  
Manage your daily tasks and To-Do list using some exciting features of Windows 7.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TaskManager.Database;

namespace TaskManager.Controls
{
    public partial class TaskViewer : UserControl
    {

        #region Constructor

        /// <summary>
        /// Cosntructor
        /// </summary>
        public TaskViewer()
        {
            InitializeComponent();

            if (this.DesignMode)
            {
                ClearTaskData();
            }
        }
        
        #endregion

        #region Properties

        /// <summary>
        /// get control image
        /// </summary>
        public Bitmap Image
        {

            get
            {

                Bitmap b = new Bitmap(this.Width, this.Height);
                Rectangle newRect = new Rectangle(

                  2,
                  2,
                  this.Width,
                  this.Height);


                this.DrawToBitmap(b, newRect);


                return b;
            }
        }
        
        #endregion

        #region Public Methods

        /// <summary>
        /// load task detail
        /// </summary>
        /// <param name="task">task</param>
        public void SetTaskDetail(Task task)
        {
            if (task == null)
            {
                ClearTaskData();
                return;
            }

            lblTitle.Text = task.Title;
            textEditor1.PlainText = task.Description;

            lblStartDate.Text = task.StartDate.ToShortDateString();
            lblEndDate.Text = task.EndDate.ToShortDateString();
            lblDuration.Text = task.Duration.ToString() + " " + task.DurationType;
            lblPercentComplete.Text = task.PercentComplete + "%";
            lblStatus.Text = task.Status;
            lblPriority.Text = task.Priority;


            lblDueDate.Text = (task.DueDate.HasValue) ? task.DueDate.Value.ToShortDateString() : string.Empty;
            lblCategory.Text = (task.Category != null) ? task.Category.Name : string.Empty;

            lblResources.Text = GetResourceList(task);


        }
        
        #endregion

        #region Private Methods

        /// <summary>
        /// Get comma separate list for resources
        /// </summary>
        /// <param name="task">task</param>
        /// <returns>CSV of resource name</returns>
        private string GetResourceList(Task task)
        {

            string strToReturn = string.Empty;
            if (!task.Resource.IsLoaded)
            {
                task.Resource.Load();
            }

            string[] resNames = new string[task.Resource.Count];

            int i = 0;
            foreach (Resource res in task.Resource)
                resNames[i++] = res.ResourceName;


            return string.Join(", ", resNames);
        }

        /// <summary>
        /// set empty value in control
        /// </summary>
        private void ClearTaskData()
        {
            lblTitle.Text = string.Empty;
            textEditor1.PlainText = string.Empty;


            lblStartDate.Text = string.Empty;
            lblEndDate.Text = string.Empty;
            lblDuration.Text = string.Empty;
            lblPercentComplete.Text = string.Empty;
            lblStatus.Text = string.Empty;
            lblPriority.Text = string.Empty;
            lblResources.Text = string.Empty;

            lblDueDate.Text = string.Empty;
            lblCategory.Text = string.Empty;

        } 

        #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
Chief Technology Officer
Pakistan Pakistan
Passion and positive dedication is essential part of success. I believe on hardworking and sharing knowledge with others. I always try to be a better than I am and think positive for positive result.

My Blogs

My Linked-In Profile

Comments and Discussions