wxDateTime.cs :  » GUI » wx-NET » wx » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » GUI » wx NET 
wx NET » wx » wxDateTime.cs
//-----------------------------------------------------------------------------
// wx.NET - DateTime.cs
// 
// The wxDateTime wrapper class.
//
// Written by Bryan Bulten (bryan@bulten.ca)
// (C) 2003 Bryan Bulten
// Licensed under the wxWidgets license, see LICENSE.txt for details.
//
// $Id: wxDateTime.cs,v 1.9 2007/08/23 20:31:36 harald_meyer Exp $
//-----------------------------------------------------------------------------

using System.Runtime.InteropServices;
using System.Drawing;
using System;

namespace wx{
    public class wxDateTime : Object
    {
        [DllImport("wx-c")] static extern IntPtr wxDateTime_ctor();
        [DllImport("wx-c")] static extern void   wxDateTime_dtor(IntPtr self);
        [DllImport("wx-c")] static extern void   wxDateTime_Set(IntPtr self, ushort day, int month, int year, ushort hour, ushort minute, ushort second, ushort millisec);
        [DllImport("wx-c")] static extern ushort wxDateTime_GetYear(IntPtr self);
        [DllImport("wx-c")] static extern int    wxDateTime_GetMonth(IntPtr self);
        [DllImport("wx-c")] static extern ushort wxDateTime_GetDay(IntPtr self);
        [DllImport("wx-c")] static extern ushort wxDateTime_GetHour(IntPtr self);
        [DllImport("wx-c")] static extern ushort wxDateTime_GetMinute(IntPtr self);
        [DllImport("wx-c")] static extern ushort wxDateTime_GetSecond(IntPtr self);
        [DllImport("wx-c")] static extern ushort wxDateTime_GetMillisecond(IntPtr self);
  
        //-----------------------------------------------------------------------------

        public wxDateTime(IntPtr wxObject)
            : base(wxObject) 
  { 
    this.wxObject = wxObject;
  }
  
  internal wxDateTime(IntPtr wxObject, bool memOwn)
      : base(wxObject)
  { 
    this.memOwn = memOwn;
    this.wxObject = wxObject;
  }

        public wxDateTime()
            : this(wxDateTime_ctor(), true) { } 
      
  //---------------------------------------------------------------------
        
  public override void Dispose()
  {
    if (!disposed)
    {
      if (wxObject != IntPtr.Zero)
      {
        if (memOwn)
        {
          wxDateTime_dtor(wxObject);
          memOwn = false;
        }
      }
      RemoveObject(wxObject);
      wxObject = IntPtr.Zero;
            --validInstancesCount;
            disposed = true;
    }
    
    base.Dispose();
    GC.SuppressFinalize(this);
  }
  
  //---------------------------------------------------------------------
  
  ~wxDateTime() 
  {
    Dispose();
  }

        //-----------------------------------------------------------------------------

        public void Set(ushort day, int month, int year, ushort hour, ushort minute, ushort second, ushort millisec)
        {
            wxDateTime_Set(wxObject, day, month, year, hour, minute, second, millisec);
        }

        //-----------------------------------------------------------------------------

        public ushort Year
        {
            get { return wxDateTime_GetYear(wxObject); }
        }

        public int Month
        {
            get { return wxDateTime_GetMonth(wxObject); }
        }

        public ushort Day
        {
            get { return wxDateTime_GetDay(wxObject); }
        }

        public ushort Hour
        {
            get { return wxDateTime_GetHour(wxObject); }
        }

        public ushort Minute
        {
            get { return wxDateTime_GetMinute(wxObject); }
        }

        public ushort Second
        {
            get { return wxDateTime_GetSecond(wxObject); }
        }

        public ushort Millisecond
        {
            get { return wxDateTime_GetMillisecond(wxObject); }
        }

        //-----------------------------------------------------------------------------
        /** Comprehensable output.
         * */
        public override string ToString()
        {
            return string.Format("wxDateTime {0}.{1}.{2} {3}:{4}:{5} {6}/1000", Day, Month, Year, Hour, Minute, Second, Millisecond);
        }
        //-----------------------------------------------------------------------------

        public static implicit operator DateTime (wxDateTime wdt)
        {
            DateTime dt = new DateTime(wdt.Year, (int)wdt.Month+1, (int)wdt.Day, 
                                       (int)wdt.Hour, (int)wdt.Minute, 
                                       (int)wdt.Second, (int)wdt.Millisecond);
            return dt;
        }

        public static implicit operator wxDateTime (DateTime dt)
        {
            wxDateTime wdt = new wxDateTime();
            wdt.Set((ushort)dt.Day, dt.Month-1, dt.Year, (ushort)dt.Hour, 
                    (ushort)dt.Minute, (ushort)dt.Second, 
                    (ushort)dt.Millisecond);
            return wdt;
        }

        //-----------------------------------------------------------------------------

        #region Static Helpers to convert related enumerations.
        /** Converts the int into a DayOfWeek assuming the argumetn to be an index in \e wxWidgets enumeration \c WeekDay.
         * This will throw an System.ArgumentOutOfRangeException on negative arguments.
         */
        static public DayOfWeek FromWxWeekDay(int wxWeekDay)
        {
            if (wxWeekDay < 0) throw new ArgumentOutOfRangeException();
            wxWeekDay = wxWeekDay % 7;
            switch (wxWeekDay)
            {
                case 0: return DayOfWeek.Sunday;
                case 1: return DayOfWeek.Monday;
                case 2: return DayOfWeek.Tuesday;
                case 3: return DayOfWeek.Wednesday;
                case 4: return DayOfWeek.Thursday;
                case 5: return DayOfWeek.Friday;
            }
            return DayOfWeek.Saturday;
        }
        #endregion
    }
}

www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.