using System;
using System.IO;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Xml;
using System.Drawing.Imaging;
using System.Xml.Serialization;
namespace Arcsoft.ToDoListPPC
{
/// <summary>
/// <name>frmMain</name>
/// <namespace>Arcsoft.ToDoListPPC</namespace>
/// <version>1.0</version>
/// <author>Andy Aspell-Clark</author>
/// <description>
/// </description>
/// <history>
/// <historyitem> 1 Aug 2004 1.0 ARA Initial Version.</historyitem>
/// </history>
/// </summary>
public class frmTodoListPPC : Arcsoft.Common.Ipaq.UI.ArcsoftForm
{
/// <summary>
/// Create a logger for use in this class
/// </summary>
protected static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(frmTodoListPPC));
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
Font font = new Font("Comic Sans MS", 10, FontStyle.Regular);
// This will instruct log4net to look for a configuration file
// called ConsoleApp.exe.config in the application base
// directory (i.e. the directory containing ConsoleApp.exe)
log4net.Config.XmlConfigurator.Configure();
// Create a logger
log4net.ILog log = log4net.LogManager.GetLogger(typeof(frmTodoListPPC));
// Log an info level message
if (log.IsInfoEnabled) log.Info("Application [TodoListPPC] Start");
Application.Run(new frmTodoListPPC(font));
if (log.IsInfoEnabled) log.Info("Application [TodoListPPC] Stop");
// It's not possible to use shutdown hooks in the .NET Compact Framework,
// so you have manually shutdown log4net to free all resoures.
log4net.LogManager.Shutdown();
}
#region Member Variables
private const string M_NEW_TASK_NAME = "New Task";
private PreferencesXml m_preferences = null;
private TodoListTreeNode m_SelectedNode = null;
private bool m_bEncrypt = false;
private bool m_bStarting = false;
private bool m_fNotes;
private string m_strFile = "TodoList.xml";
private int m_iLevel;
private CTask m_selectedTask;
private bool m_bDataChanged = false;
private bool m_bNodeDataChanged = false;
private bool m_bResizeRunning = false;
private int m_iPrevWidth = 0;
private int m_iPrevHeight = 0;
private string m_sFileFormat = "6";
private string m_sProjectName = null;
private Int16 m_iNextUniqueID = -1;
private string m_sFileVersion = "1";
private string m_sLastModified = null;
private string m_sLastSortBy = null;
private string m_sLastSortDir = null;
private System.Windows.Forms.MenuItem mnuView;
private System.Windows.Forms.MenuItem mnuViewAll;
private System.Windows.Forms.MenuItem mnuViewActive;
private System.Windows.Forms.MenuItem mnuViewComplete;
private System.Windows.Forms.ImageList imglstTodo;
private System.Windows.Forms.MenuItem mnuViewRefresh;
private System.Windows.Forms.MenuItem mnuViewDetails;
private System.Windows.Forms.MenuItem mnuNew;
private System.Windows.Forms.MenuItem mnuNewTask;
private System.Windows.Forms.MenuItem mnuToolsExit;
private System.Windows.Forms.MenuItem mnuToolsAbout;
private System.Windows.Forms.MenuItem mnuToolsOpen;
private System.Windows.Forms.MenuItem mnuToolsSave;
private System.Windows.Forms.MenuItem mnuToolsSaveAs;
private System.Windows.Forms.SaveFileDialog m_saveFileDialog;
private System.Windows.Forms.TabControl tcDetails;
private System.Windows.Forms.TabPage m_tpTaskDetails;
private System.Windows.Forms.TextBox txtTitle;
private System.Windows.Forms.Label m_lblName;
private System.Windows.Forms.TextBox txtAllocatedTo;
private System.Windows.Forms.TextBox txtTimeEstimate;
private System.Windows.Forms.TextBox m_tbxPercentComplete;
private System.Windows.Forms.Label m_lblAllocatedTo;
private System.Windows.Forms.Label m_lblTimeEst;
private System.Windows.Forms.Label m_lblPcntComplete;
private System.Windows.Forms.TextBox m_tbxPriority;
private System.Windows.Forms.Label m_lblPriority;
private System.Windows.Forms.TabPage m_tpTaskDates;
private System.Windows.Forms.TextBox m_tbxCompletedDate;
private System.Windows.Forms.TextBox m_tbxDueDate;
private System.Windows.Forms.Label m_lblDateCompleted;
private System.Windows.Forms.TextBox m_tbxStartDate;
private System.Windows.Forms.Label m_lblDateDue;
private System.Windows.Forms.Label m_lblDateStart;
private System.Windows.Forms.TabPage m_tpProjectDetails;
private System.Windows.Forms.ComboBox m_cmbSortBy;
private System.Windows.Forms.ComboBox m_cmbSortDirection;
private System.Windows.Forms.Label m_lblSortDirection;
private System.Windows.Forms.Label m_lblSortBy;
private System.Windows.Forms.TextBox m_tbxProjectName;
private System.Windows.Forms.Label m_lblProjectName;
private System.Windows.Forms.TabPage m_tpTaskNotes;
private System.Windows.Forms.TextBox txtNotes;
private System.Windows.Forms.Panel m_pnlTask;
private System.Windows.Forms.Label m_lblProject;
private System.Windows.Forms.TreeView m_tvTodoList;
private System.Windows.Forms.Panel m_pnlTodoList;
private System.Windows.Forms.Panel m_pnlDetails;
private System.Windows.Forms.MainMenu m_mnuMain;
private System.Windows.Forms.ContextMenu m_mnuCntxt;
private System.Windows.Forms.MenuItem m_mnuCntxtDetails;
private System.Windows.Forms.MenuItem m_mnuCntxtRefresh;
private System.Windows.Forms.MenuItem m_mnuCntxtNewChild;
private System.Windows.Forms.MenuItem m_mnuCntxtDelete;
private Microsoft.WindowsCE.Forms.InputPanel m_inputPanel;
#endregion
#region Properties
#endregion
/// <summary>
///
/// </summary>
public frmTodoListPPC(Font pFont)
:base ( pFont )
{
DisplayMsg( "frmTodoListPPC(): starting" );
m_preferences = new PreferencesXml();
LoadPreferences();
DisplayMsg( "frmTodoListPPC(): preferences loaded" );
m_bStarting = true;
InitializeComponent();
DisplayMsg( "frmTodoListPPC(): components initialised" );
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
DisplayMsg( "InitializeComponent():" );
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmTodoListPPC));
this.m_mnuMain = new System.Windows.Forms.MainMenu();
this.mnuToolsOpen = new System.Windows.Forms.MenuItem();
this.mnuToolsSave = new System.Windows.Forms.MenuItem();
this.mnuToolsSaveAs = new System.Windows.Forms.MenuItem();
this.mnuToolsAbout = new System.Windows.Forms.MenuItem();
this.mnuToolsExit = new System.Windows.Forms.MenuItem();
this.mnuView = new System.Windows.Forms.MenuItem();
this.mnuViewAll = new System.Windows.Forms.MenuItem();
this.mnuViewActive = new System.Windows.Forms.MenuItem();
this.mnuViewComplete = new System.Windows.Forms.MenuItem();
this.mnuViewDetails = new System.Windows.Forms.MenuItem();
this.mnuViewRefresh = new System.Windows.Forms.MenuItem();
this.mnuNew = new System.Windows.Forms.MenuItem();
this.mnuNewTask = new System.Windows.Forms.MenuItem();
this.m_mnuCntxt = new System.Windows.Forms.ContextMenu();
this.m_mnuCntxtDetails = new System.Windows.Forms.MenuItem();
this.m_mnuCntxtRefresh = new System.Windows.Forms.MenuItem();
this.m_mnuCntxtNewChild = new System.Windows.Forms.MenuItem();
this.m_mnuCntxtDelete = new System.Windows.Forms.MenuItem();
this.imglstTodo = new System.Windows.Forms.ImageList();
this.m_saveFileDialog = new System.Windows.Forms.SaveFileDialog();
this.m_inputPanel = new Microsoft.WindowsCE.Forms.InputPanel();
this.m_pnlTodoList = new System.Windows.Forms.Panel();
this.m_lblProject = new System.Windows.Forms.Label();
this.m_pnlDetails = new System.Windows.Forms.Panel();
this.tcDetails = new System.Windows.Forms.TabControl();
this.m_tpTaskDetails = new System.Windows.Forms.TabPage();
this.txtTitle = new System.Windows.Forms.TextBox();
this.m_lblName = new System.Windows.Forms.Label();
this.txtAllocatedTo = new System.Windows.Forms.TextBox();
this.txtTimeEstimate = new System.Windows.Forms.TextBox();
this.m_tbxPercentComplete = new System.Windows.Forms.TextBox();
this.m_lblAllocatedTo = new System.Windows.Forms.Label();
this.m_lblTimeEst = new System.Windows.Forms.Label();
this.m_lblPcntComplete = new System.Windows.Forms.Label();
this.m_tbxPriority = new System.Windows.Forms.TextBox();
this.m_lblPriority = new System.Windows.Forms.Label();
this.m_tpTaskDates = new System.Windows.Forms.TabPage();
this.m_tbxCompletedDate = new System.Windows.Forms.TextBox();
this.m_tbxDueDate = new System.Windows.Forms.TextBox();
this.m_lblDateCompleted = new System.Windows.Forms.Label();
this.m_tbxStartDate = new System.Windows.Forms.TextBox();
this.m_lblDateDue = new System.Windows.Forms.Label();
this.m_lblDateStart = new System.Windows.Forms.Label();
this.m_tpTaskNotes = new System.Windows.Forms.TabPage();
this.txtNotes = new System.Windows.Forms.TextBox();
this.m_tpProjectDetails = new System.Windows.Forms.TabPage();
this.m_cmbSortBy = new System.Windows.Forms.ComboBox();
this.m_cmbSortDirection = new System.Windows.Forms.ComboBox();
this.m_lblSortDirection = new System.Windows.Forms.Label();
this.m_lblSortBy = new System.Windows.Forms.Label();
this.m_tbxProjectName = new System.Windows.Forms.TextBox();
this.m_lblProjectName = new System.Windows.Forms.Label();
this.m_pnlTask = new System.Windows.Forms.Panel();
this.m_tvTodoList = new System.Windows.Forms.TreeView();
//
// m_mnuMain
//
ArcsoftMainMenu.MenuItems.Add(this.mnuView);
ArcsoftMainMenu.MenuItems.Add(this.mnuNew);
//
// mnuTools
//
DisplayMsg( "mnuTools" );
this.mnuTools.MenuItems.Add(this.mnuToolsOpen);
//this.mnuTools.MenuItems.Add(this.mnuSeperator);
this.mnuTools.MenuItems.Add(this.mnuToolsSave);
this.mnuTools.MenuItems.Add(this.mnuToolsSaveAs);
// this.mnuTools.MenuItems.Add(this.mnuSeperator);
this.mnuTools.Text = "Tools";
//
// mnuToolsOpen
//
DisplayMsg( "mnuToolsOpen" );
this.mnuToolsOpen.Text = "Open List";
this.mnuToolsOpen.Click += new System.EventHandler(this.mnuToolsOpen_Click);
//
// mnuToolsSave
//
this.mnuToolsSave.Text = "Save";
this.mnuToolsSave.Click += new System.EventHandler(this.mnuToolsSave_Click);
//
// mnuToolsSaveAs
//
this.mnuToolsSaveAs.Text = "Save As...";
this.mnuToolsSaveAs.Click += new System.EventHandler(this.mnuToolsSaveAs_Click);
//
// mnuToolsAbout
//
this.mnuToolsAbout.Text = "About";
this.mnuToolsAbout.Click += new System.EventHandler(this.mnuToolsAbout_Click);
//
// mnuToolsExit
//
this.mnuToolsExit.Text = "Exit";
this.mnuToolsExit.Click += new System.EventHandler(this.mnuToolsExit_Click);
//
// mnuView
//
this.mnuView.MenuItems.Add(this.mnuViewAll);
this.mnuView.MenuItems.Add(this.mnuViewActive);
this.mnuView.MenuItems.Add(this.mnuViewComplete);
//this.mnuView.MenuItems.Add(this.mnuSeperator);
this.mnuView.MenuItems.Add(this.mnuViewDetails);
//this.mnuView.MenuItems.Add(this.mnuSeperator);
this.mnuView.MenuItems.Add(this.mnuViewRefresh);
this.mnuView.Text = "View";
//
// mnuViewAll
//
this.mnuViewAll.Checked = true;
this.mnuViewAll.Text = "All";
this.mnuViewAll.Click += new System.EventHandler(this.mnuViewAll_Click);
//
// mnuViewActive
//
this.mnuViewActive.Text = "Active";
this.mnuViewActive.Click += new System.EventHandler(this.mnuViewActive_Click);
//
// mnuViewComplete
//
this.mnuViewComplete.Text = "Complete";
this.mnuViewComplete.Click += new System.EventHandler(this.mnuViewComplete_Click);
//
// mnuViewDetails
//
this.mnuViewDetails.Text = "Details";
this.mnuViewDetails.Click += new System.EventHandler(this.mnuViewDetails_Click);
//
// mnuViewRefresh
//
this.mnuViewRefresh.Text = "Refresh";
this.mnuViewRefresh.Click += new System.EventHandler(this.mnuViewRefresh_Click);
//
// mnuNew
//
this.mnuNew.MenuItems.Add(this.mnuNewTask);
this.mnuNew.Text = "New";
//
// mnuNewTask
//
this.mnuNewTask.Text = "Task";
this.mnuNewTask.Click += new System.EventHandler(this.mnuNewTask_Click);
//
// m_mnuCntxt
//
this.m_mnuCntxt.MenuItems.Add(this.m_mnuCntxtDetails);
this.m_mnuCntxt.MenuItems.Add(this.m_mnuCntxtRefresh);
this.m_mnuCntxt.MenuItems.Add(this.m_mnuCntxtNewChild);
this.m_mnuCntxt.MenuItems.Add(this.m_mnuCntxtDelete);
//
// m_mnuCntxtDetails
//
this.m_mnuCntxtDetails.Text = "Details";
this.m_mnuCntxtDetails.Click += new System.EventHandler(this.m_mnuCntxtDetails_Click);
//
// m_mnuCntxtRefresh
//
this.m_mnuCntxtRefresh.Text = "Refresh";
this.m_mnuCntxtRefresh.Click += new System.EventHandler(this.m_mnuCntxtRefresh_Click);
//
// m_mnuCntxtNewChild
//
this.m_mnuCntxtNewChild.Text = "New Child";
this.m_mnuCntxtNewChild.Click += new System.EventHandler(this.m_mnuCntxtNewChild_Click);
//
// m_mnuCntxtDelete
//
this.m_mnuCntxtDelete.Text = "Delete";
this.m_mnuCntxtDelete.Click += new System.EventHandler(this.m_mnuCntxtDelete_Click);
//
// imglstTodo
//
if (log.IsInfoEnabled) log.Info("adding bitmap resources 1");
//this.imglstTodo.Images.Add(((System.Drawing.Image)(resources.GetObject("resource"))));
// this.imglstTodo.Images.Add(((System.Drawing.Image)(resources.GetObject("checked.bmp"))));
if (log.IsInfoEnabled) log.Info("adding bitmap resources 2");
//this.imglstTodo.Images.Add(((System.Drawing.Image)(resources.GetObject("resource1"))));
//this.imglstTodo.Images.Add(((System.Drawing.Image)(resources.GetObject("unchecked.bmp"))));
//this.imglstTodo.ImageSize = new System.Drawing.Size(16, 16);
//
// m_inputPanel
//
this.m_inputPanel.EnabledChanged += new System.EventHandler(this.m_inputPanel_EnabledChanged);
//
// m_pnlTodoList
//
this.m_pnlTodoList.Controls.Add(this.m_lblProject);
this.m_pnlTodoList.Controls.Add(this.m_pnlDetails);
this.m_pnlTodoList.Controls.Add(this.m_pnlTask);
this.m_pnlTodoList.Size = new System.Drawing.Size(280, 272);
this.m_pnlTodoList.Resize += new System.EventHandler(this.m_pnlTodoList_Resize);
//
// m_lblProject
//
this.m_lblProject.ContextMenu = this.m_mnuCntxt;
this.m_lblProject.Location = new System.Drawing.Point(0, 8);
this.m_lblProject.Size = new System.Drawing.Size(240, 16);
//
// m_pnlDetails
//
this.m_pnlDetails.Controls.Add(this.tcDetails);
this.m_pnlDetails.Location = new System.Drawing.Point(0, 168);
this.m_pnlDetails.Size = new System.Drawing.Size(240, 112);
this.m_pnlDetails.Resize += new System.EventHandler(this.m_pnlDetails_Resize);
//
// tcDetails
//
this.tcDetails.ContextMenu = this.m_mnuCntxt;
this.tcDetails.Controls.Add(this.m_tpTaskDetails);
this.tcDetails.Controls.Add(this.m_tpTaskDates);
this.tcDetails.Controls.Add(this.m_tpTaskNotes);
this.tcDetails.Controls.Add(this.m_tpProjectDetails);
this.tcDetails.SelectedIndex = 0;
this.tcDetails.Size = new System.Drawing.Size(314, 112);
//
// m_tpTaskDetails
//
this.m_tpTaskDetails.ContextMenu = this.m_mnuCntxt;
this.m_tpTaskDetails.Controls.Add(this.txtTitle);
this.m_tpTaskDetails.Controls.Add(this.m_lblName);
this.m_tpTaskDetails.Controls.Add(this.txtAllocatedTo);
this.m_tpTaskDetails.Controls.Add(this.txtTimeEstimate);
this.m_tpTaskDetails.Controls.Add(this.m_tbxPercentComplete);
this.m_tpTaskDetails.Controls.Add(this.m_lblAllocatedTo);
this.m_tpTaskDetails.Controls.Add(this.m_lblTimeEst);
this.m_tpTaskDetails.Controls.Add(this.m_lblPcntComplete);
this.m_tpTaskDetails.Controls.Add(this.m_tbxPriority);
this.m_tpTaskDetails.Controls.Add(this.m_lblPriority);
this.m_tpTaskDetails.Location = new System.Drawing.Point(4, 4);
this.m_tpTaskDetails.Size = new System.Drawing.Size(306, 86);
this.m_tpTaskDetails.Text = "Details";
//
// txtTitle
//
this.txtTitle.ContextMenu = this.m_mnuCntxt;
this.txtTitle.Location = new System.Drawing.Point(88, 4);
this.txtTitle.Size = new System.Drawing.Size(136, 20);
this.txtTitle.Text = "";
this.txtTitle.GotFocus += new System.EventHandler(this.txtTitle_GotFocus);
this.txtTitle.TextChanged += new System.EventHandler(this.txtTitle_TextChanged);
//
// m_lblName
//
this.m_lblName.ContextMenu = this.m_mnuCntxt;
this.m_lblName.Location = new System.Drawing.Point(8, 4);
this.m_lblName.Size = new System.Drawing.Size(72, 20);
this.m_lblName.Text = "Name";
//
// txtAllocatedTo
//
this.txtAllocatedTo.ContextMenu = this.m_mnuCntxt;
this.txtAllocatedTo.Location = new System.Drawing.Point(88, 64);
this.txtAllocatedTo.Size = new System.Drawing.Size(136, 20);
this.txtAllocatedTo.Text = "";
this.txtAllocatedTo.TextChanged += new System.EventHandler(this.txtAllocatedTo_TextChanged);
//
// txtTimeEstimate
//
this.txtTimeEstimate.ContextMenu = this.m_mnuCntxt;
this.txtTimeEstimate.Location = new System.Drawing.Point(88, 24);
this.txtTimeEstimate.ReadOnly = true;
this.txtTimeEstimate.Size = new System.Drawing.Size(48, 20);
this.txtTimeEstimate.Text = "";
//
// m_tbxPercentComplete
//
this.m_tbxPercentComplete.ContextMenu = this.m_mnuCntxt;
this.m_tbxPercentComplete.Location = new System.Drawing.Point(88, 44);
this.m_tbxPercentComplete.Size = new System.Drawing.Size(48, 20);
this.m_tbxPercentComplete.Text = "";
this.m_tbxPercentComplete.TextChanged += new System.EventHandler(this.m_tbxPercentComplete_TextChanged);
//
// m_lblAllocatedTo
//
this.m_lblAllocatedTo.ContextMenu = this.m_mnuCntxt;
this.m_lblAllocatedTo.Location = new System.Drawing.Point(8, 64);
this.m_lblAllocatedTo.Size = new System.Drawing.Size(72, 20);
this.m_lblAllocatedTo.Text = "Allocated To";
//
// m_lblTimeEst
//
this.m_lblTimeEst.ContextMenu = this.m_mnuCntxt;
this.m_lblTimeEst.Location = new System.Drawing.Point(8, 24);
this.m_lblTimeEst.Size = new System.Drawing.Size(80, 20);
this.m_lblTimeEst.Text = "Time Est (hr)";
//
// m_lblPcntComplete
//
this.m_lblPcntComplete.ContextMenu = this.m_mnuCntxt;
this.m_lblPcntComplete.Location = new System.Drawing.Point(8, 44);
this.m_lblPcntComplete.Size = new System.Drawing.Size(72, 20);
this.m_lblPcntComplete.Text = "% Complete";
//
// m_tbxPriority
//
this.m_tbxPriority.ContextMenu = this.m_mnuCntxt;
this.m_tbxPriority.Location = new System.Drawing.Point(192, 24);
this.m_tbxPriority.Size = new System.Drawing.Size(32, 20);
this.m_tbxPriority.Text = "";
this.m_tbxPriority.TextChanged += new System.EventHandler(this.m_tbxPriority_TextChanged);
//
// m_lblPriority
//
this.m_lblPriority.ContextMenu = this.m_mnuCntxt;
this.m_lblPriority.Location = new System.Drawing.Point(144, 25);
this.m_lblPriority.Size = new System.Drawing.Size(48, 20);
this.m_lblPriority.Text = "Priority";
//
// m_tpTaskDates
//
this.m_tpTaskDates.ContextMenu = this.m_mnuCntxt;
this.m_tpTaskDates.Controls.Add(this.m_tbxCompletedDate);
this.m_tpTaskDates.Controls.Add(this.m_tbxDueDate);
this.m_tpTaskDates.Controls.Add(this.m_lblDateCompleted);
this.m_tpTaskDates.Controls.Add(this.m_tbxStartDate);
this.m_tpTaskDates.Controls.Add(this.m_lblDateDue);
this.m_tpTaskDates.Controls.Add(this.m_lblDateStart);
this.m_tpTaskDates.Location = new System.Drawing.Point(4, 4);
this.m_tpTaskDates.Size = new System.Drawing.Size(306, 86);
this.m_tpTaskDates.Text = "Dates";
//
// m_tbxCompletedDate
//
this.m_tbxCompletedDate.ContextMenu = this.m_mnuCntxt;
this.m_tbxCompletedDate.Location = new System.Drawing.Point(104, 56);
this.m_tbxCompletedDate.ReadOnly = true;
this.m_tbxCompletedDate.Size = new System.Drawing.Size(112, 20);
this.m_tbxCompletedDate.Text = "";
this.m_tbxCompletedDate.TextChanged += new System.EventHandler(this.m_tbxCompletedDate_TextChanged);
//
// m_tbxDueDate
//
this.m_tbxDueDate.ContextMenu = this.m_mnuCntxt;
this.m_tbxDueDate.Location = new System.Drawing.Point(104, 32);
this.m_tbxDueDate.ReadOnly = true;
this.m_tbxDueDate.Size = new System.Drawing.Size(112, 20);
this.m_tbxDueDate.Text = "";
this.m_tbxDueDate.TextChanged += new System.EventHandler(this.m_tbxDueDate_TextChanged);
//
// m_lblDateCompleted
//
this.m_lblDateCompleted.ContextMenu = this.m_mnuCntxt;
this.m_lblDateCompleted.Location = new System.Drawing.Point(8, 57);
this.m_lblDateCompleted.Size = new System.Drawing.Size(88, 20);
this.m_lblDateCompleted.Text = "Completed Date";
this.m_lblDateCompleted.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// m_tbxStartDate
//
this.m_tbxStartDate.ContextMenu = this.m_mnuCntxt;
this.m_tbxStartDate.Location = new System.Drawing.Point(104, 8);
this.m_tbxStartDate.ReadOnly = true;
this.m_tbxStartDate.Size = new System.Drawing.Size(112, 20);
this.m_tbxStartDate.Text = "";
this.m_tbxStartDate.TextChanged += new System.EventHandler(this.m_tbxStartDate_TextChanged);
//
// m_lblDateDue
//
this.m_lblDateDue.ContextMenu = this.m_mnuCntxt;
this.m_lblDateDue.Location = new System.Drawing.Point(8, 33);
this.m_lblDateDue.Size = new System.Drawing.Size(88, 20);
this.m_lblDateDue.Text = "Due Date";
this.m_lblDateDue.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// m_lblDateStart
//
this.m_lblDateStart.ContextMenu = this.m_mnuCntxt;
this.m_lblDateStart.Location = new System.Drawing.Point(8, 9);
this.m_lblDateStart.Size = new System.Drawing.Size(88, 20);
this.m_lblDateStart.Text = "Start Date";
this.m_lblDateStart.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// m_tpTaskNotes
//
this.m_tpTaskNotes.ContextMenu = this.m_mnuCntxt;
this.m_tpTaskNotes.Controls.Add(this.txtNotes);
this.m_tpTaskNotes.Location = new System.Drawing.Point(4, 4);
this.m_tpTaskNotes.Size = new System.Drawing.Size(306, 86);
this.m_tpTaskNotes.Text = "Notes";
//
// txtNotes
//
this.txtNotes.BackColor = System.Drawing.Color.White;
this.txtNotes.ContextMenu = this.m_mnuCntxt;
this.txtNotes.Multiline = true;
this.txtNotes.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtNotes.Size = new System.Drawing.Size(232, 80);
this.txtNotes.Text = "";
this.txtNotes.TextChanged += new System.EventHandler(this.txtNotes_TextChanged);
//
// m_tpProjectDetails
//
this.m_tpProjectDetails.ContextMenu = this.m_mnuCntxt;
this.m_tpProjectDetails.Controls.Add(this.m_cmbSortBy);
this.m_tpProjectDetails.Controls.Add(this.m_cmbSortDirection);
this.m_tpProjectDetails.Controls.Add(this.m_lblSortDirection);
this.m_tpProjectDetails.Controls.Add(this.m_lblSortBy);
this.m_tpProjectDetails.Controls.Add(this.m_tbxProjectName);
this.m_tpProjectDetails.Controls.Add(this.m_lblProjectName);
this.m_tpProjectDetails.Location = new System.Drawing.Point(4, 4);
this.m_tpProjectDetails.Size = new System.Drawing.Size(306, 86);
this.m_tpProjectDetails.Text = "Project";
//
// m_cmbSortBy
//
this.m_cmbSortBy.Items.Add("Task Id");
this.m_cmbSortBy.Items.Add("Title");
this.m_cmbSortBy.Items.Add("Status");
this.m_cmbSortBy.Items.Add("Priority");
this.m_cmbSortBy.Items.Add("Percent Complete");
this.m_cmbSortBy.Location = new System.Drawing.Point(56, 24);
this.m_cmbSortBy.Size = new System.Drawing.Size(164, 21);
this.m_cmbSortBy.SelectedIndexChanged += new System.EventHandler(this.m_cmbSortBy_SelectedIndexChanged);
//
// m_cmbSortDirection
//
this.m_cmbSortDirection.Items.Add("Ascending");
this.m_cmbSortDirection.Items.Add("Decending");
this.m_cmbSortDirection.Location = new System.Drawing.Point(56, 44);
this.m_cmbSortDirection.Size = new System.Drawing.Size(164, 21);
this.m_cmbSortDirection.SelectedIndexChanged += new System.EventHandler(this.m_cmbSortDirection_SelectedIndexChanged);
//
// m_lblSortDirection
//
this.m_lblSortDirection.Location = new System.Drawing.Point(4, 48);
this.m_lblSortDirection.Size = new System.Drawing.Size(56, 16);
this.m_lblSortDirection.Text = "Direction";
//
// m_lblSortBy
//
this.m_lblSortBy.Location = new System.Drawing.Point(4, 24);
this.m_lblSortBy.Size = new System.Drawing.Size(52, 16);
this.m_lblSortBy.Text = "Sort By:";
//
// m_tbxProjectName
//
this.m_tbxProjectName.Location = new System.Drawing.Point(56, 4);
this.m_tbxProjectName.Size = new System.Drawing.Size(164, 20);
this.m_tbxProjectName.Text = "";
this.m_tbxProjectName.TextChanged += new System.EventHandler(this.m_tbxProjectName_TextChanged);
//
// m_lblProjectName
//
this.m_lblProjectName.Location = new System.Drawing.Point(4, 4);
this.m_lblProjectName.Size = new System.Drawing.Size(40, 16);
this.m_lblProjectName.Text = "Name:";
//
// m_pnlTask
//
this.m_pnlTask.Controls.Add(this.m_tvTodoList);
this.m_pnlTask.Size = new System.Drawing.Size(240, 156);
this.m_pnlTask.Resize += new System.EventHandler(this.m_pnlTask_Resize);
//
// m_tvTodoList
//
this.m_tvTodoList.CheckBoxes = true;
this.m_tvTodoList.ContextMenu = this.m_mnuCntxt;
this.m_tvTodoList.Location = new System.Drawing.Point(0, 16);
this.m_tvTodoList.Size = new System.Drawing.Size(240, 140);
this.m_tvTodoList.AfterCheck += new System.Windows.Forms.TreeViewEventHandler(this.m_tvTodoList_AfterCheck);
this.m_tvTodoList.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.m_tvTodoList_AfterSelect);
//
// frmMain
//
MainAppPanel.ClientSize = new System.Drawing.Size(314, 369);
MainAppPanel.Controls.Add(this.m_pnlTodoList);
if (log.IsInfoEnabled) log.Info("adding app icon");
//this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Text = "ToDoListPPC";
this.Resize += new System.EventHandler(this.frmMain_Resize);
this.Closing += new System.ComponentModel.CancelEventHandler(this.frmMain_Closing);
this.Load += new System.EventHandler(this.frmMain_Load);
}
#endregion
private void SetPref(string psName, string psValue)
{
m_preferences.setPreference(psName, psValue);
SavePreferences();
}
private string GetPref(string psName)
{
return m_preferences.getPreference(psName);
}
private void SavePreferences()
{
m_preferences.writeToFile();
}
private void LoadPreferences()
{
m_preferences.readFromFile();
}
private void FillTree()
{
Cursor.Current = Cursors.WaitCursor;
DialogResult loseChanges = DialogResult.No;
if (m_bDataChanged)
{
//ask to lose changes???
loseChanges = MessageBox.Show("Lose Changes you have made to this todo list?", "Lose Changes?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
}
else
{
loseChanges = DialogResult.Yes;
}
m_bDataChanged = false;
if (loseChanges == DialogResult.Yes)
{
XmlDocument xmlTodoList;
XmlNode xndList;
TodoListTreeNode tnParent;
try
{
xmlTodoList = new XmlDocument();
xmlTodoList.Load(m_strFile);
m_tvTodoList.BeginUpdate();
m_tvTodoList.Nodes.Clear();
if(xmlTodoList.GetElementsByTagName("TODOLIST").Count > 0)
{
xndList = xmlTodoList.GetElementsByTagName("TODOLIST").Item(0);
m_sProjectName = xndList.Attributes.GetNamedItem("PROJECTNAME").InnerText;
m_tbxProjectName.Text = m_sProjectName;
m_sFileFormat = xndList.Attributes.GetNamedItem("FILEFORMAT").InnerText;
m_iNextUniqueID = Convert.ToInt16(xndList.Attributes.GetNamedItem("NEXTUNIQUEID").InnerText);
try {m_sLastSortBy = xndList.Attributes.GetNamedItem("LASTSORTBY").InnerText;} catch {}
try {m_sFileVersion = xndList.Attributes.GetNamedItem("FILEVERSION").InnerText;} catch {}
try {m_sLastSortDir = xndList.Attributes.GetNamedItem("LASTSORTDIR").InnerText;} catch {}
try {m_sLastModified = xndList.Attributes.GetNamedItem("LASTMODIFIED").InnerText;} catch {}
m_lblProject.Text = m_sProjectName + " [v" + m_sFileVersion + " - " + m_sLastModified + "]";
if(xndList.HasChildNodes == true)
{
for(int i = 0; i < xndList.ChildNodes.Count; i++)
{
AppendTask(null, xndList.ChildNodes.Item(i));
}
}
}
m_tvTodoList.Font = AppFont;
m_tvTodoList.EndUpdate();
}
catch
{
tnParent = new TodoListTreeNode("Invalid Todo List File");
tnParent.ImageIndex = 4;
tnParent.SelectedImageIndex = 4;
m_tvTodoList.Nodes.Add(tnParent);
tnParent.Expand();
}
}
foreach (TodoListTreeNode childNode in m_tvTodoList.Nodes)
{
SetChecked(childNode);
}
Cursor.Current = Cursors.Default;
}//FillTree()
private void SetChecked(TodoListTreeNode pNode)
{
if (pNode.Nodes.Count > 0)
{
foreach (TodoListTreeNode childNode in pNode.Nodes)
{
SetChecked(childNode);
}
}
CTask clsTask = pNode.Task;
pNode.Checked = clsTask.Complete;
}//SetChecked()
private void AppendTask(TodoListTreeNode tnParent, XmlNode xndTask)
{
TodoListTreeNode tnChild;
CTask clsTask;
if(xndTask.Name.ToUpper() == "TASK")
{
clsTask = new CTask();
clsTask.readFromXml(xndTask);
tnChild = new TodoListTreeNode(clsTask.Title);
tnChild.TaskId = clsTask.TaskId;
tnChild.Task = clsTask;
if (tnParent != null)
{
tnChild.ParentTaskId = tnParent.TaskId;
}
if(xndTask.HasChildNodes == true)
{
for(int i = 0; i < xndTask.ChildNodes.Count; i++)
{
AppendTask(tnChild, xndTask.ChildNodes.Item(i));
}
}
tnChild.Checked = clsTask.Complete;
if((m_iLevel == 0) || ((m_iLevel == 1) && (clsTask.Complete == false)) || ((m_iLevel == 1) && (clsTask.Complete == true) && (tnChild.GetNodeCount(false) > 0)) || ((m_iLevel == 2) && (clsTask.Complete == true)) || ((m_iLevel == 2) && (clsTask.Complete == false) && (tnChild.GetNodeCount(false) > 0)))
{
if(tnParent == null)
{
m_tvTodoList.Nodes.Add(tnChild);
}
else
{
tnParent.Nodes.Add(tnChild);
}
}
}
else if(xndTask.Name.ToUpper() == "COMMENTS")
{
if(tnParent != null)
{
clsTask = tnParent.Task;
clsTask.Notes = xndTask.InnerText;
tnParent.Task = clsTask;
}
}
}//AppendTask()
private void mnuToolsOpen_Click(object sender, System.EventArgs e)
{
DialogResult saveChanges = DialogResult.Yes;
if (m_bDataChanged)
{
//ask to lose changes???
saveChanges = MessageBox.Show("Save Changes you have made to this todo list?", "Save Changes?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
}
else
{
saveChanges = DialogResult.No;
}
if (saveChanges == DialogResult.Yes)
{
if (m_strFile == "")
{
SaveAs();
}
else
{
writeTodoListFile();
}
}
OpenFileDialog ofdTodoList = new OpenFileDialog();
ofdTodoList.InitialDirectory = "" + System.IO.Path.DirectorySeparatorChar;
ofdTodoList.Filter = "Todolist files|*.xml;*.tdl|All files|*.*" ;
ofdTodoList.FilterIndex = 1 ;
if(ofdTodoList.ShowDialog() == DialogResult.OK)
{
m_strFile = ofdTodoList.FileName;
SetPref("LastOpenedFile", m_strFile);
FillTree();
}
m_bDataChanged = false;
}
private void mnuListExit_Click(object sender, System.EventArgs e)
{
Close();
}
private void mnuViewAll_Click(object sender, System.EventArgs e)
{
SetViewFilter(0);
}
private void mnuViewActive_Click(object sender, System.EventArgs e)
{
SetViewFilter(1);
}
private void mnuViewComplete_Click(object sender, System.EventArgs e)
{
SetViewFilter(2);
}
private void mnuViewRefresh_Click(object sender, System.EventArgs e)
{
FillTree();
}
private void mnuViewDetails_Click(object sender, System.EventArgs e)
{
EnableDetailsView(!m_fNotes);
}
private void m_mnuCntxtRefresh_Click(object sender, System.EventArgs e)
{
FillTree();
}
private void m_mnuCntxtDetails_Click(object sender, System.EventArgs e)
{
EnableDetailsView(!m_fNotes);
}
private void m_tvTodoList_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
TodoListTreeNode tlNode = e.Node as TodoListTreeNode;
if (m_SelectedNode != null && m_bNodeDataChanged)
{
//save changes to node
}
if(tlNode.Task != null)
{
m_selectedTask = tlNode.Task;
if (m_selectedTask.Priority > 0)
{
m_tbxPriority.Text = m_selectedTask.Priority.ToString();
}
else
{
m_tbxPriority.Text = "";
}
if (m_selectedTask.HoursEst > 0)
{
txtTimeEstimate.Text = m_selectedTask.HoursEst.ToString();
}
else
{
txtTimeEstimate.Text = "";
}
if(m_selectedTask.PercentComplete > 0)
{
m_tbxPercentComplete.Text = m_selectedTask.PercentComplete.ToString();
}
else
{
m_tbxPercentComplete.Text = "";
}
txtTitle.Text = m_selectedTask.Title;
txtAllocatedTo.Text = m_selectedTask.AllocatedTo;
m_tbxStartDate.Text = m_selectedTask.StartDateStr;
m_tbxDueDate.Text = m_selectedTask.DueDateStr;
m_tbxCompletedDate.Text = m_selectedTask.DoneDateStr;
txtNotes.Text = m_selectedTask.Notes;
}
}//m_tvTodoList_AfterSelect()
private void SetViewFilter(Int16 iLevel)
{
mnuViewAll.Checked = false;
mnuViewActive.Checked = false;
mnuViewComplete.Checked = false;
if(iLevel == 0)
{
mnuViewAll.Checked = true;
}
else if(iLevel == 1)
{
mnuViewActive.Checked = true;
}
else if(iLevel == 2)
{
mnuViewComplete.Checked = true;
}
m_iLevel = iLevel;
FillTree();
}
private void frmMain_Load(object sender, System.EventArgs e)
{
m_lblProject.Height = 19;
m_iLevel = 0;
this.Font = AppFont;
m_lblName.Font = AppFont;
txtTitle.Font = AppFont;
txtAllocatedTo.Font = AppFont;
txtTimeEstimate.Font = AppFont;
m_tbxPercentComplete.Font = AppFont;
m_lblAllocatedTo.Font = AppFont;
m_lblTimeEst.Font = AppFont;
m_lblProject.Font = AppFont;
m_lblAllocatedTo.Font = AppFont;
m_lblDateCompleted.Font = AppFont;
m_lblPcntComplete.Font = AppFont;
m_tbxPriority.Font = AppFont;
m_lblPriority.Font = AppFont;
m_tbxCompletedDate.Font = AppFont;
m_tbxDueDate.Font = AppFont;
m_lblDateCompleted.Font = AppFont;
m_tbxStartDate.Font = AppFont;
m_lblDateDue.Font = AppFont;
m_lblDateStart.Font = AppFont;
m_cmbSortBy.Font = AppFont;
m_cmbSortDirection.Font = AppFont;
m_lblSortBy.Font = AppFont;
m_tbxProjectName.Font = AppFont;
m_lblProjectName.Font = AppFont;
//m_tpTaskNotes.Font = AppFont;
txtNotes.Font = AppFont;
m_lblProject.Font = AppFont;
//m_tvTodoList.Font = AppFont;
txtNotes.Width = m_tpTaskNotes.Width;
txtNotes.Height = m_tpTaskNotes.Height;
m_pnlTodoList.Height = m_inputPanel.VisibleDesktop.Height-22;
m_bStarting = false;
if (GetPref("DetailsViewEnabled") == "Yes")
{
EnableDetailsView(true);
}
else
{
EnableDetailsView(false);
}
m_strFile = GetPref("LastOpenedFile");
if (File.Exists(m_strFile) == true)
{
m_bDataChanged = false;
try
{
FillTree();
}
catch {}
}
else
{
// tnParent = new TodoListTreeNode("Last opened file not found");
// tnParent.ImageIndex = 4;
// tnParent.SelectedImageIndex = 4;
// m_tvTodoList.Nodes.Add(tnParent);
// tnParent.Expand();
}
}
private void frmMain_Resize(object sender, System.EventArgs e)
{
if ((!m_bResizeRunning) && ((m_iPrevHeight != this.Height) || (m_iPrevWidth != this.Width)))
{
doResize();
}
m_bResizeRunning = false;
}//frmMain_Resize()
private void doResize()
{
if (Screen.PrimaryScreen.Bounds.Width > Screen.PrimaryScreen.Bounds.Height)
{
Landscape();
}
else
{
Portrait();
}
}//doResize()
/// <summary>
///
/// </summary>
protected override void Portrait()
{
m_pnlTodoList.Size = new Size(Screen.PrimaryScreen.Bounds.Width, m_inputPanel.VisibleDesktop.Height);
}//Portrait()
/// <summary>
///
/// </summary>
protected override void Landscape()
{
m_pnlTodoList.Size = new Size(Screen.PrimaryScreen.Bounds.Width, m_inputPanel.VisibleDesktop.Height);
}//Landscape()
private void m_pnlTodoList_Resize(object sender, System.EventArgs e)
{
EnableDetailsView(m_pnlDetails.Visible);
}//m_pnlTodoList_Resize()
private void m_pnlDetails_Resize(object sender, System.EventArgs e)
{
m_tpTaskDetails.Height = m_pnlDetails.Height;
m_tbxProjectName.Width = m_pnlDetails.Width - m_lblProject.Width - 30;
txtTitle.Width = m_pnlDetails.Width - m_lblName.Width - 30;
txtNotes.Width = m_pnlDetails.Width;
EnableDetailsView(m_pnlDetails.Visible);
}//m_pnlDetails_Resize()
private void EnableDetailsView(bool pbEnabled)
{
if (m_bStarting == false)
{
if(pbEnabled == false)
{
//Turn it off
m_pnlDetails.Visible = false;
m_pnlTask.Bounds = new Rectangle(0, 0, m_pnlTodoList.Width, m_pnlTodoList.Height);
mnuViewDetails.Checked = false;
m_mnuCntxtDetails.Checked = false;
m_fNotes = false;
}
else
{
//Turn it on
m_pnlDetails.Visible = true;
DisplayMsg(" pnlDetails top [" + m_pnlDetails.Top + "] and height [" + m_pnlDetails.Height + "]");
m_pnlTask.Bounds = new Rectangle(0, 0, m_pnlTodoList.Width, m_pnlTodoList.Height - m_pnlDetails.Height);
m_pnlDetails.Bounds = new Rectangle(0, m_pnlTask.Height, m_pnlTodoList.Width, m_pnlDetails.Height);
mnuViewDetails.Checked = true;
m_mnuCntxtDetails.Checked = true;
m_fNotes = true;
}
if (pbEnabled)
{
SetPref("DetailsViewEnabled", "Yes");
}
else
{
SetPref("DetailsViewEnabled", "No");
}
}
}//EnableDetailsView()
private void m_pnlTask_Resize(object sender, System.EventArgs e)
{
m_lblProject.Bounds = new Rectangle(0, 0, m_pnlTodoList.Width, 20);
m_tvTodoList.Bounds = new Rectangle(0, m_lblProject.Height, m_pnlTask.Width, m_pnlTask.Height - m_lblProject.Height);
}//m_pnlTask_Resize()
private void m_inputPanel_EnabledChanged(object sender, System.EventArgs e)
{
if (m_inputPanel.Enabled == true)
{
m_pnlTodoList.Height = m_inputPanel.VisibleDesktop.Height;
}
else
{
m_pnlTodoList.Height = m_inputPanel.VisibleDesktop.Height-22;
}
}//m_inputPanel_EnabledChanged()
private void m_mnuCntxtNewChild_Click(object sender, System.EventArgs e)
{
TodoListTreeNode selectedNode = m_tvTodoList.SelectedNode as TodoListTreeNode;
CTask tmpTask = new CTask();
tmpTask.TaskId = m_iNextUniqueID++;
tmpTask.Title = M_NEW_TASK_NAME;
TodoListTreeNode newNode = new TodoListTreeNode(M_NEW_TASK_NAME);
newNode.Task = tmpTask;
newNode.TaskId = tmpTask.TaskId;
m_bDataChanged = true;
selectedNode.Nodes.Add(newNode);
}//m_mnuCntxtNewChild_Click
private void m_mnuCntxtDelete_Click(object sender, System.EventArgs e)
{
TodoListTreeNode selectedNode = m_tvTodoList.SelectedNode as TodoListTreeNode;
m_tvTodoList.Nodes.Remove(selectedNode);
m_bDataChanged = true;
}//m_mnuCntxtDelete_Click()
private void mnuToolsExit_Click(object sender, System.EventArgs e)
{
Close();
}
private void mnuToolsAbout_Click(object sender, System.EventArgs e)
{
using (Arcsoft.Common.Ipaq.UI.FrmAboutBox frmObj = new Arcsoft.Common.Ipaq.UI.FrmAboutBox())
{
frmObj.AppTitle = "ToDoListPPC";
frmObj.AppDescription = "Pocket PC Todolist";
string sTmpText = this.Text;
this.Text = "";
frmObj.Text = sTmpText;
frmObj.ShowDialog();
this.Text = sTmpText;
frmObj.Dispose();
}
}
private void mnuNewTask_Click(object sender, System.EventArgs e)
{
CTask tmpTask = new CTask();
tmpTask.TaskId = m_iNextUniqueID++;
tmpTask.Title = M_NEW_TASK_NAME;
TodoListTreeNode newNode = new TodoListTreeNode(M_NEW_TASK_NAME);
newNode.Task = tmpTask;
newNode.TaskId = tmpTask.TaskId;
m_bDataChanged = true;
m_tvTodoList.Nodes.Add(newNode);
}
private void frmMain_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
DialogResult saveChanges = DialogResult.Yes;
if (m_bDataChanged)
{
//ask to lose changes???
saveChanges = MessageBox.Show("Save Changes you have made to this todo list?", "Save Changes?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
}
else
{
saveChanges = DialogResult.No;
}
if (saveChanges == DialogResult.Yes)
{
if (m_strFile == "")
{
SaveAs();
}
else
{
writeTodoListFile();
}
}
}
private void mnuToolsSave_Click(object sender, System.EventArgs e)
{
if (m_strFile == "")
{
SaveAs();
}
else
{
writeTodoListFile();
}
}
private void mnuToolsSaveAs_Click(object sender, System.EventArgs e)
{
m_bDataChanged = true;
SaveAs();
}
private void SaveAs()
{
SaveFileDialog sfdTodoList = new SaveFileDialog();
sfdTodoList.InitialDirectory = "" + System.IO.Path.DirectorySeparatorChar;
sfdTodoList.Filter = "XML files (*.xml)|*.xml|All files (*.*)|*.*" ;
sfdTodoList.FilterIndex = 1 ;
sfdTodoList.FileName = m_strFile;
if(sfdTodoList.ShowDialog() == DialogResult.OK)
{
m_strFile = sfdTodoList.FileName;
m_sProjectName = m_strFile;
writeTodoListFile();
}
}//mnuToolsSaveAs_Click()
private void writeOutEncryptedFile( XmlTextWriter xmlWriter )
{
/*
BOOL CXmlFileEx::Encrypt(const CString& sPassword)
{
if (sPassword.IsEmpty() || !InitEncryptor())
return FALSE;
// 1. export everything below the root to a string
CExportToXml e2xml;
CString sXml, sItemXml;
POSITION pos = m_xiRoot.GetFirstItemPos();
int nItem = 1;
while (pos)
{
const CXmlItem* pXI = m_xiRoot.GetNextItem(pos);
ASSERT (pXI);
e2xml.Export(pXI, 1, nItem, sItemXml);
sXml += sItemXml;
nItem++;
}
// 2. encrypt it
unsigned char* pEncrypted = NULL;
int nLenEncrypted = 0;
if (!m_pEncryptor->Encrypt((unsigned char*)(LPCTSTR)sXml, sXml.GetLength() + 1, sPassword, // RB - Added sPassword parameter instead of NULL
pEncrypted, nLenEncrypted))
return FALSE;
// 3. convert the binary to a string
Base64Coder b64;
b64.Encode(pEncrypted, nLenEncrypted);
const char* pEncodedDataBuffer = b64.EncodedMessage();
// 4. replace file contents with a single CDATA item
m_xiRoot.DeleteAllItems();
m_xiRoot.AddItem(CDATA, pEncodedDataBuffer);
m_xiRoot.AddItem("DATALEN", nLenEncrypted);
// 5. cleanup
m_pEncryptor->FreeBuffer(pEncrypted);
return TRUE;
}
BOOL CXmlFileEx::Load(LPCTSTR szFilePath, LPCTSTR szRootItemName, IXmlParse* pCallback, BOOL bDecrypt)
{
m_bDecrypt = bDecrypt;
return CXmlFile::Load(szFilePath, szRootItemName, pCallback);
}
BOOL CXmlFileEx::LoadEx(LPCTSTR szRootItemName, IXmlParse* pCallback)
{
if (!CXmlFile::LoadEx(szRootItemName, pCallback))
return FALSE;
// we assume the file is encrypted if it contains a single CDATA element
if (m_bDecrypt)
{
CXmlItem* pXI = GetItem(CDATA);
if (pXI && !pXI->GetSibling())
{
// we don't try to decrypt if no encryption capabilities
if (!CanEncrypt())
{
CString sExplanation;
sExplanation.Format("The file '%s' is encrypted, but you do not have the necessary components installed to decrypt it.",
GetFilePath());
AfxMessageBox(sExplanation, MB_OK);
m_nLoadError = XFL_CANCELLED;
return FALSE;
}
// else keep getting password till success or user cancels
while (TRUE)
{
CString sPassword(m_sPassword);
if (sPassword.IsEmpty())
{
CString sExplanation;
sExplanation.Format("The file '%s' is encrypted.\n\nPlease enter your password below.",
GetFilePath());
if (!CPasswordDialog::RetrievePassword(FALSE, sPassword, sExplanation, 5))
{
// RB - Set m_nLoadError to avoid "The selected task list could not be opened..." message when cancelling
m_nLoadError = XFL_CANCELLED;
return FALSE;
}
}
CString sFile;
if (Decrypt(pXI->GetValue(), sFile, sPassword))
{
m_sPassword = sPassword;
sFile.TrimLeft();
sFile.TrimRight();
// delete the cdata item
m_xiRoot.DeleteItem(pXI);
LPCTSTR szFile = sFile;
// reparse decrypted xml
ParseItem(m_xiRoot, szFile);
return TRUE;
}
else
{
// RB - Added code to format the error message before calling AfxMessage
CString sExplanation;
sExplanation.Format("The file '%s' could not be decrypted using the supplied password.\n\nWound you like to try again?",
GetFilePath());
if (IDNO == AfxMessageBox(sExplanation, MB_YESNO))
{
m_nLoadError = XFL_CANCELLED;
return FALSE;
}
}
}
}
}
return TRUE; // might be garbage. who knows?
}
BOOL CXmlFileEx::Decrypt(LPCTSTR szInput, CString& sOutput, LPCTSTR szPassword)
{
if (!InitEncryptor())
return FALSE;
// 1. convert the input string back to binary
Base64Coder b64;
b64.Decode(szInput);
DWORD nReqBufLen = 0;
unsigned char* pDecodedDataBuffer = b64.DecodedMessage(nReqBufLen);
nReqBufLen = GetItemValueI("DATALEN");
// 2. decrypt it
unsigned char* pDecrypted = NULL;
int nLenDecrypted = 0;
if (!m_pEncryptor->Decrypt((unsigned char*)pDecodedDataBuffer, nReqBufLen, szPassword,
pDecrypted, nLenDecrypted))
return FALSE;
// 3. result should be a null-terminated string
sOutput = pDecrypted;
// 4. cleanup
m_pEncryptor->FreeBuffer(pDecrypted);
return TRUE;
}
*/
}
private void writeOutPlainTextFile( XmlTextWriter xmlWriter )
{
//write out the root element - Project
xmlWriter.WriteStartElement("TODOLIST");
xmlWriter.WriteAttributeString("", "FILEFORMAT", "", m_sFileFormat);
xmlWriter.WriteAttributeString("", "PROJECTNAME", "", m_sProjectName);
xmlWriter.WriteAttributeString("", "NEXTUNIQUEID", "", m_iNextUniqueID.ToString());
int iFileVer = Convert.ToInt32(m_sFileVersion);
iFileVer++;
m_sFileVersion = iFileVer.ToString();
xmlWriter.WriteAttributeString("", "FILEVERSION", "", m_sFileVersion);
m_sLastModified = DateTime.Now.ToString("yyyy-mm-dd");
xmlWriter.WriteAttributeString("", "LASTMODIFIED", "", m_sLastModified);
//write out the tree nodes
foreach (TodoListTreeNode tmpNode in m_tvTodoList.Nodes)
{
OutputNodes(xmlWriter, tmpNode);
}
xmlWriter.WriteEndElement();
}
private void writeTodoListFile()
{
if (m_strFile == "")
{
m_strFile = "TodoList.xml";
}
if (m_bDataChanged == true)
{
if (File.Exists(m_strFile))
{
if (File.Exists(m_strFile + ".bak"))
{
File.Delete(m_strFile + ".bak");
}
File.Move(m_strFile, m_strFile + ".bak");
}
XmlTextWriter xmlWriter = new XmlTextWriter(m_strFile, System.Text.Encoding.ASCII);
xmlWriter.WriteStartDocument();
if (m_bEncrypt)
{
writeOutEncryptedFile( xmlWriter );
}
else
{
writeOutPlainTextFile( xmlWriter );
}//if (m_bEncrypt)
xmlWriter.WriteEndDocument();
xmlWriter.Flush();
xmlWriter.Close();
m_bDataChanged = false;
m_lblProject.Text = m_sProjectName + " [v" + m_sFileVersion + " - " + m_sLastModified + "]";
}//if (m_bDataChanged)
}//writeTodoListFile()
private void OutputNodes(XmlTextWriter pXmlWriter, TodoListTreeNode pNode)
{
CTask currTask = pNode.Task;
currTask.writeToXml(pXmlWriter);
foreach (TodoListTreeNode tmpNode in pNode.Nodes)
{
OutputNodes(pXmlWriter, tmpNode);
}
currTask.endWriteToXml(pXmlWriter);
}
private void txtTimeEstimate_TextChanged(object sender, System.EventArgs e)
{
TodoListTreeNode selectedNode = m_tvTodoList.SelectedNode as TodoListTreeNode;
CTask tmpTask = selectedNode.Task;
//tmpTask.HoursEst = Convert.toFloat(txtTimeEstimate.Text);
m_bDataChanged = true;
}
private void m_tbxPriority_TextChanged(object sender, System.EventArgs e)
{
TodoListTreeNode selectedNode = m_tvTodoList.SelectedNode as TodoListTreeNode;
CTask tmpTask = selectedNode.Task;
try { tmpTask.Priority = Convert.ToInt16(m_tbxPriority.Text); } catch {}
m_bDataChanged = true;
}
private void m_tbxPercentComplete_TextChanged(object sender, System.EventArgs e)
{
TodoListTreeNode selectedNode = m_tvTodoList.SelectedNode as TodoListTreeNode;
CTask tmpTask = selectedNode.Task;
try { tmpTask.PercentComplete = Convert.ToInt16(m_tbxPercentComplete.Text); } catch {}
if (tmpTask.Complete) { selectedNode.ImageIndex = 1; selectedNode.SelectedImageIndex = 1;}
m_bDataChanged = true;
}
private void txtAllocatedTo_TextChanged(object sender, System.EventArgs e)
{
TodoListTreeNode selectedNode = m_tvTodoList.SelectedNode as TodoListTreeNode;
CTask tmpTask = selectedNode.Task;
tmpTask.AllocatedTo = txtAllocatedTo.Text;
m_bDataChanged = true;
}
private void m_tbxStartDate_TextChanged(object sender, System.EventArgs e)
{
TodoListTreeNode selectedNode = m_tvTodoList.SelectedNode as TodoListTreeNode;
CTask tmpTask = selectedNode.Task;
//try { tmpTask.StartDate = new DateTime(m_tbxStartDate.Text); } catch {}
m_bDataChanged = true;
}//m_tbxStartDate_TextChanged()
private void m_tbxDueDate_TextChanged(object sender, System.EventArgs e)
{
TodoListTreeNode selectedNode = m_tvTodoList.SelectedNode as TodoListTreeNode;
CTask tmpTask = selectedNode.Task;
//try { tmpTask.DueDate = new DateTime(m_tbxDueDate.Text); } catch {}
m_bDataChanged = true;
}//m_tbxDueDate_TextChanged()
private void m_tbxCompletedDate_TextChanged(object sender, System.EventArgs e)
{
TodoListTreeNode selectedNode = m_tvTodoList.SelectedNode as TodoListTreeNode;
CTask tmpTask = selectedNode.Task;
//try { tmpTask.DoneDate = new DateTime(m_tbxCompletedDate.Text); } catch {}
m_bDataChanged = true;
}//m_tbxCompletedDate_TextChanged()
private void txtNotes_TextChanged(object sender, System.EventArgs e)
{
TodoListTreeNode selectedNode = m_tvTodoList.SelectedNode as TodoListTreeNode;
CTask tmpTask = selectedNode.Task;
tmpTask.Notes = txtNotes.Text;
m_bDataChanged = true;
}//txtNotes_TextChanged()
private void txtTitle_TextChanged(object sender, System.EventArgs e)
{
TodoListTreeNode selectedNode = m_tvTodoList.SelectedNode as TodoListTreeNode;
CTask tmpTask = selectedNode.Task;
tmpTask.Title = txtTitle.Text;
selectedNode.Text = tmpTask.Title;
m_bDataChanged = true;
}//txtTitle_TextChanged()
private void tcDetails_SelectedIndexChanged(object sender, System.EventArgs e)
{
}//tcDetails_SelectedIndexChanged()
private void m_tbxProjectName_TextChanged(object sender, System.EventArgs e)
{
m_sProjectName = m_tbxProjectName.Text;
m_lblProject.Text = m_sProjectName;
m_bDataChanged = true;
}//m_tbxProjectName_TextChanged()
private void m_cmbSortBy_SelectedIndexChanged(object sender, System.EventArgs e)
{
//m_bDataChanged = true;
}//m_cmbSortBy_SelectedIndexChanged()
private void m_cmbSortDirection_SelectedIndexChanged(object sender, System.EventArgs e)
{
//m_bDataChanged = true;
}//m_cmbSortDirection_SelectedIndexChanged()
private void txtTitle_GotFocus(object sender, System.EventArgs e)
{
m_inputPanel.Enabled = true;
}//txtTitle_GotFocus()
private void m_tvTodoList_AfterCheck(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
TodoListTreeNode tlNode = e.Node as TodoListTreeNode;
tlNode.Clicked(tlNode.Checked);
TodoListTreeNode selectedNode = m_tvTodoList.SelectedNode as TodoListTreeNode;
if (selectedNode.TaskId == tlNode.TaskId)
{
if(tlNode.Task.PercentComplete > 0)
{
m_tbxPercentComplete.Text = tlNode.Task.PercentComplete.ToString();
}
else
{
m_tbxPercentComplete.Text = "";
}
}
m_bDataChanged = true;
}//m_tvTodoList_AfterCheck()
/// <summary>
///
/// </summary>
protected override void createSamples()
{
}
/// <summary>
///
/// </summary>
protected override void fontSizeChanged()
{
DisplayMsg ( "fontSizeChanged()" );
Graphics g = this.CreateGraphics();
int iLabelHeight = Convert.ToInt16(g.MeasureString("A", AppFont).Height);
DisplayMsg(" iLabelHeight [" + iLabelHeight + "] : pnlDetails top [" + m_pnlDetails.Top + "] and height [" + m_pnlDetails.Height + "]");
m_pnlDetails.Height = iLabelHeight*5;
DisplayMsg(" iLabelHeight [" + iLabelHeight + "] : pnlDetails top [" + m_pnlDetails.Top + "] and height [" + m_pnlDetails.Height + "]");
if (m_tvTodoList != null)
{
m_tvTodoList.Font = AppFont;
}
if (txtNotes != null)
{
txtNotes.Font = AppFont;
}
if (m_lblName != null)
{
m_lblName.Font = AppFont;
m_lblName.Height = iLabelHeight;
}
if (m_lblPriority != null)
{
m_lblPriority.Font = AppFont;
m_lblPriority.Height = iLabelHeight;
}
if (m_lblPcntComplete != null)
{
m_lblPcntComplete.Font = AppFont;
m_lblPcntComplete.Height = iLabelHeight;
}
if (m_lblTimeEst != null)
{
m_lblTimeEst.Font = AppFont;
m_lblTimeEst.Height = iLabelHeight;
}
if (txtTimeEstimate != null)
{
txtTimeEstimate.Font = AppFont;
txtTimeEstimate.Height = iLabelHeight;
}
if (txtTitle != null)
{
txtTitle.Font = AppFont;
txtTitle.Height = iLabelHeight;
}
if (txtAllocatedTo != null)
{
txtAllocatedTo.Font = AppFont;
txtAllocatedTo.Height = iLabelHeight;
}
if (m_tbxCompletedDate != null)
{
m_tbxCompletedDate.Font = AppFont;
m_tbxCompletedDate.Height = iLabelHeight;
}
if (m_tbxDueDate != null)
{
m_tbxDueDate.Font = AppFont;
m_tbxDueDate.Height = iLabelHeight;
}
if (m_tbxPercentComplete != null)
{
m_tbxPercentComplete.Font = AppFont;
m_tbxPercentComplete.Height = iLabelHeight;
}
if (m_tbxPriority != null)
{
m_tbxPriority.Font = AppFont;
m_tbxPriority.Height = iLabelHeight;
}
if (m_lblProjectName != null)
{
m_lblProjectName.Font = AppFont;
m_lblProjectName.Height = iLabelHeight;
}
if (m_tbxProjectName != null)
{
m_tbxProjectName.Font = AppFont;
m_tbxProjectName.Height = iLabelHeight;
}
if (m_tbxStartDate != null)
{
m_tbxStartDate.Font = AppFont;
m_tbxStartDate.Height = iLabelHeight;
}
if (m_lblAllocatedTo != null)
{
m_lblAllocatedTo.Font = AppFont;
m_lblAllocatedTo.Height = iLabelHeight;
}
if (m_cmbSortBy != null)
{
m_cmbSortBy.Font = AppFont;
m_cmbSortBy.Height = iLabelHeight;
}
if (m_cmbSortDirection != null)
{
m_cmbSortDirection.Font = AppFont;
m_cmbSortDirection.Height = iLabelHeight;
}
if (m_lblSortBy != null)
{
m_lblSortBy.Font = AppFont;
m_lblSortBy.Height = iLabelHeight;
}
if (m_lblSortDirection != null)
{
m_lblSortDirection.Font = AppFont;
m_lblSortDirection.Height = iLabelHeight;
}
if (m_lblDateDue != null)
{
m_lblDateDue.Font = AppFont;
m_lblDateDue.Height = iLabelHeight;
}
if (m_lblDateCompleted != null)
{
m_lblDateCompleted.Font = AppFont;
m_lblDateCompleted.Height = iLabelHeight;
}
if (m_lblDateStart != null)
{
m_lblDateStart.Font = AppFont;
m_lblDateStart.Height = iLabelHeight;
}
}
}//class()
}//namespace()