Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

Task assigner with Windows Mobile and a Web Service

, 7 Dec 2008
Send messages, commands, tasks etc., to all employees from a central administration point.
WindowsMobile.zip
WindowsMobile
FileTransfer
bin
Debug
FileTransfer.Core.dll
FileTransfer.exe
Microsoft.WindowsMobile.dll
Microsoft.WindowsMobile.PocketOutlook.dll
Microsoft.WindowsMobile.Status.dll
Microsoft.WindowsMobile.Telephony.dll
FileTransfer.csproj.user
Properties
FileTransfer.Core
bin
Debug
FileTransfer.Core.dll
FileTransfer.Core.csproj.user
Properties
Web References
FileService
FileService.disco
FileService.wsdl
Reference.map
WindowsMobileDXCore.Solution
AssemblyCache
2f77ac75ae6d31d51d97939560b8ab.cache
309feae0753ff650e63ee408b82ab36.cache
3510f6dfbaf43e3f0f6e13c7833df66.cache
355d230db4eb910dd52c432d797e30.cache
3b1c59f56f52a2c7d5f3bedaec6f53.cache
70584e332ff1ec8ce0d8af57e8d5b54.cache
7ff78eda7087b727d3b3e761d80eda7.cache
a367f2f0a771278850a4236d80aced8.cache
b9c3ea739c4b4b642d5dc6e2337c1be.cache
c47f85a4333a8aa89d56cebf5ca05e66.cache
da8aae92a375baafa973d384d62826a.cache
daedf418ea1bd9ad1be07859893bf8.cache
db182eb99632bbdc87a7d6a110945bcb.cache
def91fe868c626af2c2247de1708cb.cache
WindowsMobileService.zip
WindowsMobileService
Service
App_Code
Bin
WindowsMobileService.Core.dll
Key.bin
WindowsMobileService.Core
bin
Debug
WindowsMobileService.Core.dll
Properties
WindowsMobileServiceDXCore.Solution
AssemblyCache
12a01da074648ea1185455cfae8fa365.cache
2627823dbc7746889387248946c.cache
59f4b4d6f26c45a48b549edf7a322.cache
64e947902ee5ddf87dafcbe0cf4afa61.cache
6e4eeb558eef8d81c6866fad411899ea.cache
803f9439f94a3a86b02964225eac2cbe.cache
df39d9ae8af205f3fe14a9ede4d6cd4.cache
ed472c622f5e32aadaa4550cabb20.cache
//------------------------------------------------------------------------------
/// <copyright from='1997' to='2005' company='Microsoft Corporation'>
///		Copyright (c) Microsoft Corporation. All Rights Reserved.
///
///   This source code is intended only as a supplement to Microsoft
///   Development Tools and/or on-line documentation.  See these other
///   materials for detailed information regarding Microsoft code samples.
/// </copyright>
//------------------------------------------------------------------------------
using System;
using System.Collections;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Threading;

namespace FileTransfer
{
    sealed class FormCache : CollectionBase
    {
        private System.Collections.ArrayList stack = new ArrayList();
        public static readonly FormCache Instance = new FormCache();

        private FormCache()
        {
        }

        #region Properties
        private Form rootForm;
        public Form RootForm
        {
            get { return rootForm; }
            set { rootForm = value; }
        }

        private bool activation = false;
        public bool Activation
        {
            get { return activation; }
            //set { activation = value; }
        }
        #endregion

        #region Cache Management

        #region Load
        /// <summary>
        /// Create instance of form and add to cache.
        /// </summary>
        /// <param name="formType">Type of form to add to the cache</param>
        /// <returns>Created form</returns>
        public Form Load(Type formType)
        {
            // Check if in cache already, and if so, return instance
            foreach (Form f in List)
            {
                if (f.GetType().Name.Equals(formType.Name))
                {
                    return f;
                }
            }

            // Create new instance, translate, add to collection and return
            Form form = (Form)Activator.CreateInstance(formType);           
            List.Add(form);
            return form;
        }
        #endregion

        #region Dispose
        /// <summary>
        /// Dispose form in cache.
        /// </summary>
        /// <param name="formType">Type of form</param>
        public void DisposeForm(Type formType)
        {
            foreach (Form f in List)
                if (f.GetType().Name.Equals(formType.Name))
                {
                    f.Dispose();
                    List.Remove(f);
                    break;
                }
        }

        /// <summary>
        /// Dispose all forms and clear List.
        /// </summary>
        public void DisposeAllForms()
        {
            foreach (Form f in List)
            {
                f.Dispose();
            }
            List.Clear();
        }
        #endregion

        #endregion

        #region Stack Management

        #region Push
        /// <summary>
        /// Push form to top of stack.
        /// </summary>
        /// <param name="formType">Type of form to push</param>
        public void Push(Type formType)
        {
            Form currentForm = null;

            // Only allow 1 Push at a time to maintain stack and stack integrity
            Monitor.Enter(this);

            Cursor.Current = Cursors.WaitCursor;

            // Find parent (current) form
            if (stack.Count < 1)
            {
                currentForm = rootForm;
            }
            else
            {
                foreach (Form f in List)
                {
                    // Find the last form in the stack
                    if (f.GetType().Name.Equals(stack[stack.Count - 1]))
                    {
                        currentForm = f;
                        break;
                    }
                }
            }
            // Stack new form
            activation = false;
            Form form = Load(formType);
            activation = true;
            form.Visible = true;
            stack.Add(formType.Name);
            currentForm.Visible = false;
            activation = false;

            Monitor.Exit(this);
            Cursor.Current = Cursors.Default;
        }
        #endregion

        #region Pop
        /// <summary>
        /// Hides/pops current visible form in stack.
        /// </summary>
        /// <param name="formsToPop"></param>
        public void Pop(int formsToPop)
        {
            activation = true;

            // Remove all forms in cache?
            if (formsToPop >= stack.Count)
            {
                stack.Clear();
                Form currentForm = null;
                foreach (Form f in List)
                {
                    // Current form?
                    if (f.Visible)
                    {
                        currentForm = f;
                        break;
                    }
                }
                rootForm.Visible = true;
                currentForm.Visible = false;
            }
            else
            {
                // Remove from stack but not from cache
                for (int i = 0; i < formsToPop; i++)
                {
                    stack.RemoveAt(stack.Count - 1);
                }

                Form currentForm = null;
                foreach (Form f in List)
                {
                    // Current form?
                    if (f.Visible)
                        currentForm = f;

                    // Last form in the stack?
                    if (f.GetType().Name.Equals(stack[stack.Count - 1]))
                        f.Visible = true;
                }
                currentForm.Visible = false;
            }
            activation = false;
        }
        #endregion

        #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)

Share

About the Author

Ravenet
Team Leader
Singapore Singapore
- B.Sc. degree in Computer Science.
- 4+ years experience in Visual C#.net and VB.net
- Obsessed in OOP style design and programming.
- Designing and developing Network security tools.
- Designing and developing a client/server application for sharing files among users in a way other than FTP protocol.
- Designing and implementing GSM gateway applications and bulk messaging.
- Windows Mobile and Symbian Programming
- Having knowledge with ERP solutions
 
The summary of my skills:
C#, VB.Net#,ASP.net, VC++, Java, WPF,WCF, Oracle, SQL Server, MS Access, Windows NT administration
 
Cheers
RRave
MCPD,MCTS
http://codegain.com

You may also be interested in...

| Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 7 Dec 2008
Article Copyright 2008 by Ravenet
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid