コード例 #1
0
ファイル: Week.cs プロジェクト: GrzegorzMalina94/TimeManager
        public static void PrepareWeekComboBox(ComboBox weekComboBox, Period period, byte month = 0)
        {
            if (period != Period.Year && period != Period.Month)
            {
                throw new ArgumentException("Period argument must be Period.Month or Period.Year.", "period");
            }

            DateTime firstDay;
            DateTime endLoopDate;
            int      pastPeriodDays = VariousTools.FirstWeekDaysInPastPeriod(period, month);

            if (period == Period.Year)
            {
                firstDay    = new DateTime(DateTime.Today.Year, 1, 1);
                endLoopDate = new DateTime(DateTime.Today.Year + 1, 1, 1);
            }
            else
            {
                firstDay    = new DateTime(DateTime.Today.Year, month, 1);
                endLoopDate = new DateTime(DateTime.Today.Year, month + 1, 1);
            }

            DateTime weekStart        = firstDay.AddDays(-pastPeriodDays);
            DateTime weekEnd          = weekStart.AddDays(6);
            int      currentWeekIndex = 0;

            weekComboBox.Items.Clear();

            for (byte i = 1; weekStart < endLoopDate; i++)
            {
                weekComboBox.Items.Add(Week.PrepareWeekString(weekStart, weekEnd, i));
                if (weekStart <= DateTime.Today && DateTime.Today <= weekEnd)
                {
                    currentWeekIndex = i - 1;
                }
                weekStart = weekStart.AddDays(7);
                weekEnd   = weekEnd.AddDays(7);
            }
            weekComboBox.SelectedIndex = currentWeekIndex;
        }
コード例 #2
0
        /// <summary>
        /// Updates part of content of StatisticsWindow according to chosen values of ComboBoxes.
        /// </summary>
        public void UpdateStatisticsVisualisation()
        {
            int    firstQuarter   = 0;
            int    lastQuarter    = 1;
            Period selectedPeriod = (Period)PeriodComboBox.SelectedIndex;

            switch (selectedPeriod)
            {
            case Period.Day:
            {
                firstQuarter  = VariousTools.NumberOfFirstQuarterOfFirstWeekInMonth(CurrSlctdMonth);
                firstQuarter += StatWindWeekComboBox.SelectedIndex * 7 * 96 + DayComboBox.SelectedIndex * 96;
                lastQuarter   = firstQuarter + 96 - 1;
                break;
            }

            case Period.Week:
            {
                firstQuarter  = VariousTools.NumberOfFirstQuarterOfFirstWeekInMonth(CurrSlctdMonth);
                firstQuarter += StatWindWeekComboBox.SelectedIndex * 7 * 96;
                lastQuarter   = firstQuarter + 96 * 7 - 1;
                break;
            }

            case Period.Month:
            {
                firstQuarter = VariousTools.NumberOfFirstQuarterOfFirstWeekInMonth(CurrSlctdMonth);
                lastQuarter  = firstQuarter + 96 * 7 * StatWindWeekComboBox.Items.Count - 1;
                break;
            }

            default:
            {
                break;
            }
            }

            List <Activity> activities = ActivitiesManager.GetInstance().Activities;

            ClearStatisticsVisualisation();

            foreach (Activity activity in activities)
            {
                bool  firstActivity      = activity == activities.First();
                short numOfQrtsAccToPlan = (short)_dbAccess.CountActivityAppearences(activity, QrtrsMrkngMode.Planning,
                                                                                     firstQuarter, lastQuarter);
                short numOfQrtsAccToReport = (short)_dbAccess.CountActivityAppearences(activity, QrtrsMrkngMode.Reporting,
                                                                                       firstQuarter, lastQuarter);
                double rltyToPlan = (double)numOfQrtsAccToReport / numOfQrtsAccToPlan;

                ActivityControl activityLabel  = PrepareLabel(activity, firstActivity) as ActivityControl;
                Label           QrtQntAccToPln = (Label)PrepareLabel(numOfQrtsAccToPlan, firstActivity);
                Label           QrtsQnttInRlty = (Label)PrepareLabel(numOfQrtsAccToReport, firstActivity);
                Label           RltyToPlan     = (Label)PrepareLabel(Double.IsNaN(rltyToPlan) || Double.IsInfinity(rltyToPlan) ?
                                                                     "Not planned" : Math.Round(rltyToPlan * 100, 2).ToString(), firstActivity);
                ActivityName.Children.Add(activityLabel);
                QrtsQnttyPlnnd.Children.Add(QrtQntAccToPln);
                QrtsQnttyRlty.Children.Add(QrtsQnttInRlty);
                RltyToPlanSP.Children.Add(RltyToPlan);
            }
        }