Example #1
0
        public HoursTracker()
        {
            InitializeComponent();
            uxGroupsDefaultLocation = uxGroupsGroup.Location;
            uxHoursDefaultLocation = uxSavedHoursGroup.Location;

            clockInTime = DateTime.Now;
            clockOutTime = DateTime.Now;

            groupManager = new TimeGroupManager();

            SystemTimeTimer.Enabled = true;
            SystemTimeTimer_Tick(null, null);

            //Do some whack ObjectListView things

            //set up the typed olvs
            typedGroupView = new TypedObjectListView<TimeGrouping>(this.uxGroupsView);
            typedTimeView = new TypedObjectListView<TimedInstance>(this.uxSavedHoursView);

            //set up weird delegate things
            for(int i = 0; i < uxSavedHoursView.Columns.Count; i++)
            {
                typedTimeView.GetColumn(i).GroupKeyGetter = delegate (TimedInstance timedInstance)
                {
                    TimedInstance time = timedInstance;
                    return time.CurrentGroup;
                };
            }//end setting all columns to use group name as group key

            for(int i = 0; i < uxSavedHoursView.AllColumns.Count; i++)
            {
                uxSavedHoursView.AllColumns[i].GroupKeyToTitleConverter = delegate (object groupKey)
                {
                    if (groupKey == null) return "No Group Found";
                    TimeGrouping groupObj = (TimeGrouping)groupKey;
                    return groupObj.GroupName;
                };//end setting GroupKeyToTitleConverter
            }//end looping to set groupKeyToTitleConverter for all the columns
            
            // do the group formatters

            uxStartDateColumn.GroupFormatter = (OLVGroup group,
                GroupingParameters parms) =>
            {
                parms.GroupComparer = Comparer<OLVGroup>.Create
                (
                    (x, y) => (((TimeGrouping)x.Key).EarliestDate.TimeSpan.Ticks.CompareTo(
                        ((TimeGrouping)y.Key).EarliestDate.TimeSpan.Ticks)
                    )
                );//end group comparer definition
            };//end group formatter for start date

            uxEndDateColumn.GroupFormatter = (OLVGroup group,
                GroupingParameters parms) =>
            {
                parms.GroupComparer = Comparer<OLVGroup>.Create
                (
                    (x, y) => (((TimeGrouping)x.Key).EarliestDate.TimeSpan.Ticks.CompareTo(
                        ((TimeGrouping)y.Key).EarliestDate.TimeSpan.Ticks)
                    )
                );//end group comparer definition
            };//end group formatter for end date

            uxStartTimeColumn.GroupFormatter = (OLVGroup group,
                GroupingParameters parms) =>
            {
                parms.GroupComparer = Comparer<OLVGroup>.Create
                (
                    (x, y) => (((TimeGrouping)x.Key).EarliestTime.TimeSpan.Ticks.CompareTo(
                        ((TimeGrouping)y.Key).EarliestTime.TimeSpan.Ticks)
                    )
                );//end group comparer definition
            };//end group formatter for start time

            uxEndTimeColumn.GroupFormatter = (OLVGroup group,
                GroupingParameters parms) =>
            {
                parms.GroupComparer = Comparer<OLVGroup>.Create
                (
                    (x, y) => (((TimeGrouping)x.Key).EarliestTime.TimeSpan.Ticks.CompareTo(
                        ((TimeGrouping)y.Key).EarliestTime.TimeSpan.Ticks)
                    )
                );//end group comparer definition
            };//end group formatter for end time

            uxHoursColumn.GroupFormatter = (OLVGroup group, GroupingParameters parms) =>
            {
                parms.GroupComparer = Comparer<OLVGroup>.Create
                    (
                        (x, y) => ((TimeGrouping)x.Key).TotalHours.CompareTo(
                        ((TimeGrouping)y.Key).TotalHours)
                    );//end GroupCompareer
            };//end GroupFormatter for Hours

            uxMinutesColumn.GroupFormatter = (OLVGroup group, GroupingParameters parms) =>
            {
                parms.GroupComparer = Comparer<OLVGroup>.Create
                    (
                        (x, y) => ((TimeGrouping)x.Key).TotalMinutes.CompareTo(
                        ((TimeGrouping)y.Key).TotalMinutes)
                    );//end GroupCompareer
            };//end GroupFormatter for Minutes

            uxInstanceColumn.GroupFormatter = (OLVGroup group, GroupingParameters parms) =>
            {
                parms.GroupComparer = Comparer<OLVGroup>.Create
                (
                    (x, y) => ((TimeGrouping)x.Key).GroupName.CompareTo(((TimeGrouping)y.Key).GroupName)
                );//end groupComparer
            };//end GroupFormatter for InstanceName
        }//end constructor
Example #2
0
        }//end ToString()

        /// <summary>
        /// checks if the supplied object is the same as this one. TimedGrouping
        /// objects with the same name are considered equal.
        /// </summary>
        /// <param name="group">the object you wish to compare to this one</param>
        /// <returns>returns true if they're equal and false otherwise</returns>
        public bool Equals(TimeGrouping group)
        {
            return this.groupName.Equals(group.groupName);
        }//end Equals