Пример #1
0
        protected void DrawBars(    Graphics                    gr, 
                                    WorkingHoursConfiguration   config, 
                                    List< EventEntry >[]        days, 
                                    DateTime                    start_of_week, 
                                    DateTime                    end_of_week, 
                                    out double                  work_hours_week, 
                                    out double                  unlocked_hours_week )
        {
            double work_hours_day       = 0;
            double unlocked_hours_day   = 0;
            int work_days               = 0;
            work_hours_week             = 0;
            unlocked_hours_week         = 0;
            BarCreator bar_creator      = new BarCreator( config, start_of_week, end_of_week );

            for ( int i = 0; i < days.Length; i++ )
            {
                work_hours_day     = 0;
                unlocked_hours_day = 0;

                foreach ( EventEntry ee in days[ i ] )
                {
                    Bar bar = bar_creator.GetBar( ee );
                    if ( config.show_detailed_weeks || bar == null )
                    {
                        DrawBar( gr, config, bar );
                    }
                    else
                    {
                        if ( bar.is_unlocked )
                        {
                            unlocked_hours_day += bar.Height;
                        }
                        else
                        {
                            work_hours_day += bar.Height;
                        }
                    }
                }

                foreach ( Bar b in bar_creator.GetFinalBarsForDay() ) // last unlock - now
                {
                    if ( config.show_detailed_weeks )
                    {
                        DrawBar( gr, config, b );
                    }
                    else
                    {
                        if ( b.is_unlocked )
                        {
                            unlocked_hours_day += b.Height;
                        }
                        else
                        {
                            work_hours_day += b.Height;
                        }
                    }
                }
                if ( !config.show_detailed_weeks )
                {
                    Bar b1 = new Bar( new SolidBrush( config.work_bar_color     ), i, false, start_of_week.AddDays( i ), start_of_week.AddDays( i + work_hours_day     / 24 ) );
                    Bar b2 = new Bar( new SolidBrush( config.unlocked_bar_color ), i, true,  start_of_week.AddDays( i ), start_of_week.AddDays( i + unlocked_hours_day / 24 ) );
                    DrawBar( gr, config, b1 );
                    DrawBar( gr, config, b2 );
                }

                if ( work_hours_day > 0 || unlocked_hours_day > 0 )
                {
                    work_days++;
                }

                work_hours_week     += work_hours_day;
                unlocked_hours_week += unlocked_hours_day;
            }
            work_hours_week     /= work_days;
            unlocked_hours_week /= work_days;
        }
Пример #2
0
        public Bar GetBar( EventEntry e )
        {
            Bar bar = null;

            if ( e.event_type == SessionSwitchReason.SessionLogon )
            {
                if ( !Valid( first_unlock_date ) )
                {
                    first_unlock_date = e.date;
                }
                last_unlock_date = e.date;
            }
            else if ( e.event_type == SessionSwitchReason.SessionLogoff )
            {
                last_lock_date = e.date;
                if ( Valid( last_unlock_date ) && config.show_unlocked_hours )
                {
                    bar = new Bar( unlocked_color, e.date.MondayFirstDoW(), true, last_unlock_date, last_lock_date );
                }
            }

            return bar;
        }
Пример #3
0
        protected void DrawBar( Graphics gr, WorkingHoursConfiguration config, Bar bar )
        {
            if ( bar == null ) return;

            float height    = (float)bar.Height;
            float start     = (float)config.time_end - (float)bar.start.TimeOfDay.TotalHours - height;
            float x_offset  = 0;

            // center for lone bars
            if (     config.show_unlocked_hours && !config.show_work_hours ||
                    !config.show_unlocked_hours &&  config.show_work_hours )
            {
                x_offset = 2;
            }
            else if ( bar.is_unlocked ) // right for the second bar (unlocked bar)
            {
                x_offset = 8;
            }

            if ( config.show_detailed_weeks )
            {
                gr.FillRectangle( bar.color, 25 + bar.day_of_week*20 + x_offset, 10 + start * config.zoom_amount, 7, height * config.zoom_amount );
            }
            else
            {
                if ( !bar.is_unlocked && bar.Height > 0 )
                {
                    gr.DrawString( bar.Height.ToHourMinuteString(), font_small, Brushes.Black, 21 + bar.day_of_week*20 + x_offset, -5 + (float)( config.GraphHours - bar.Height ) * config.zoom_amount );
                }
                gr.FillRectangle( bar.color, 25 + bar.day_of_week*20 + x_offset, 10 + (float)(config.GraphHours - bar.Height) * config.zoom_amount, 7, (float)bar.Height * config.zoom_amount );
            }
        }