Ejemplo n.º 1
0
 public DateEvent(Contact contact, DateTime date, TimeMeasure timeMeasure, uint quantity)
 {
     this._contact     = contact;
     this._date        = date;
     this._timeMeasure = timeMeasure;
     this._quantity    = quantity;
 }
Ejemplo n.º 2
0
        public TimeMeasure Add(string name, TimeSpan duration)
        {
            TimeMeasure timeMeasure = new TimeMeasure(name, duration);

            timeMeasure.Id = this.GetNextId();
            this._timeMeasures.Add(timeMeasure);
            this._timeMeasureDictionary.Add(timeMeasure.Id, timeMeasure);
            return(timeMeasure);
        }
Ejemplo n.º 3
0
        public static TimeMeasureCollection Generate()
        {
            TimeMeasureCollection measureCollection = new TimeMeasureCollection();
            string      name1        = "Seconds";
            TimeSpan    duration1    = TimeSpan.FromSeconds(1.0);
            TimeMeasure timeMeasure1 = measureCollection.Add(name1, duration1);

            timeMeasure1.Strings.Add(Measure.One, "секунда");
            timeMeasure1.Strings.Add(Measure.Few, "секунды");
            timeMeasure1.Strings.Add(Measure.Many, "секунд");
            string      name2        = "Minutes";
            TimeSpan    duration2    = TimeSpan.FromMinutes(1.0);
            TimeMeasure timeMeasure2 = measureCollection.Add(name2, duration2);

            timeMeasure2.Strings.Add(Measure.One, "минута");
            timeMeasure2.Strings.Add(Measure.Few, "минуты");
            timeMeasure2.Strings.Add(Measure.Many, "минут");
            string      name3        = "Hours";
            TimeSpan    duration3    = TimeSpan.FromHours(1.0);
            TimeMeasure timeMeasure3 = measureCollection.Add(name3, duration3);

            timeMeasure3.Strings.Add(Measure.One, "час");
            timeMeasure3.Strings.Add(Measure.Few, "часа");
            timeMeasure3.Strings.Add(Measure.Many, "часов");
            string      name4        = "Days";
            TimeSpan    duration4    = TimeSpan.FromDays(1.0);
            TimeMeasure timeMeasure4 = measureCollection.Add(name4, duration4);

            timeMeasure4.Strings.Add(Measure.One, "день");
            timeMeasure4.Strings.Add(Measure.Few, "дня");
            timeMeasure4.Strings.Add(Measure.Many, "дней");
            string      name5        = "Weeks";
            TimeSpan    duration5    = TimeSpan.FromDays(7.0);
            TimeMeasure timeMeasure5 = measureCollection.Add(name5, duration5);

            timeMeasure5.Strings.Add(Measure.One, "неделя");
            timeMeasure5.Strings.Add(Measure.Few, "недели");
            timeMeasure5.Strings.Add(Measure.Many, "недель");
            string      name6        = "Monthes";
            TimeSpan    zero1        = TimeSpan.Zero;
            TimeMeasure timeMeasure6 = measureCollection.Add(name6, zero1);

            timeMeasure6.Strings.Add(Measure.One, "месяц");
            timeMeasure6.Strings.Add(Measure.Few, "месяца");
            timeMeasure6.Strings.Add(Measure.Many, "месяцев");
            string      name7        = "Years";
            TimeSpan    zero2        = TimeSpan.Zero;
            TimeMeasure timeMeasure7 = measureCollection.Add(name7, zero2);

            timeMeasure7.Strings.Add(Measure.One, "год");
            timeMeasure7.Strings.Add(Measure.Few, "года");
            timeMeasure7.Strings.Add(Measure.Many, "лет");
            return(measureCollection);
        }
Ejemplo n.º 4
0
        private List <DateEvent> GetMonthEvents(int step, TimeMeasure measure)
        {
            List <DateEvent> dateEventList = new List <DateEvent>();
            DateTime         dateTime1     = this._startDate;
            DateTime         dateTime2     = dateTime1.AddYears(100);
            uint             num           = 0;

            while (dateTime1 < dateTime2)
            {
                dateTime1 = dateTime1.AddMonths(step);
                num      += (uint)step;
                dateEventList.Add(new DateEvent()
                {
                    Date        = dateTime1,
                    Quantity    = num,
                    TimeMeasure = measure
                });
            }
            return(dateEventList);
        }
Ejemplo n.º 5
0
        private List <DateEvent> GetEvents(uint step, TimeSpan stepTime, TimeMeasure measure)
        {
            List <DateEvent> dateEventList = new List <DateEvent>();
            DateTime         startDate     = this._startDate;
            DateTime         dateTime      = startDate.AddYears(100);
            uint             num           = 0;

            while (startDate < dateTime)
            {
                startDate += stepTime;
                num       += step;
                dateEventList.Add(new DateEvent()
                {
                    Date        = startDate,
                    Quantity    = num,
                    TimeMeasure = measure
                });
            }
            return(dateEventList);
        }
Ejemplo n.º 6
0
        private DateEvent Add(Contact contact, DateTime date, TimeMeasure timeMeasure, uint quantity)
        {
            if (this._dateEvents.Exists((Predicate <DateEvent>)(de =>
            {
                if (de.Contact.Id == contact.Id && (int)de.Quantity == (int)quantity)
                {
                    return(de.TimeMeasure.Id == timeMeasure.Id);
                }
                return(false);
            })))
            {
                return((DateEvent)null);
            }
            DateEvent dateEvent = new DateEvent(contact, date, timeMeasure, quantity);

            dateEvent.Id = this.GetNextId();
            this._dateEvents.Add(dateEvent);
            this._dateEventDictionary.Add(dateEvent.Id, dateEvent);
            this._dateEvents.Sort(new Comparison <DateEvent>(DateEvent.Comparer));
            return(dateEvent);
        }
Ejemplo n.º 7
0
        public void Add(Contact contact, TimeMeasureCollection timeMeasures, Settings settings)
        {
            if (settings.UseSeconds)
            {
                TimeMeasure timeMeasure = timeMeasures.Find("Seconds");
                if (timeMeasure != null)
                {
                    this.CalculateEvents(contact, timeMeasure, settings);
                }
            }
            if (settings.UseMinutes)
            {
                TimeMeasure timeMeasure = timeMeasures.Find("Minutes");
                if (timeMeasure != null)
                {
                    this.CalculateEvents(contact, timeMeasure, settings);
                }
            }
            if (settings.UseHours)
            {
                TimeMeasure timeMeasure = timeMeasures.Find("Hours");
                if (timeMeasure != null)
                {
                    this.CalculateEvents(contact, timeMeasure, settings);
                }
            }
            if (settings.UseDays)
            {
                TimeMeasure timeMeasure = timeMeasures.Find("Days");
                if (timeMeasure != null)
                {
                    this.CalculateEvents(contact, timeMeasure, settings);
                }
            }
            if (settings.UseWeeks)
            {
                TimeMeasure timeMeasure = timeMeasures.Find("Weeks");
                if (timeMeasure != null)
                {
                    this.CalculateEvents(contact, timeMeasure, settings);
                }
            }
            if (settings.UseMonthes)
            {
                TimeMeasure timeMeasure = timeMeasures.Find("Monthes");
                if (timeMeasure != null)
                {
                    this.CalculateLongEvents(contact, timeMeasure, settings);
                }
            }
            if (!settings.UseYears)
            {
                return;
            }
            TimeMeasure timeMeasure1 = timeMeasures.Find("Years");

            if (timeMeasure1 == null)
            {
                return;
            }
            this.CalculateLongEvents(contact, timeMeasure1, settings);
        }
Ejemplo n.º 8
0
        private void CalculateLongEvents(Contact contact, TimeMeasure timeMeasure, Settings settings)
        {
            if (timeMeasure.Name != "Monthes" && timeMeasure.Name != "Years")
            {
                return;
            }
            DateTime date1     = contact.BirthDate;
            DateTime dateTime1 = DateTime.Now + TimeSpan.FromDays((double)settings.NextDaysQuantity);
            DateTime dateTime2 = DateTime.Now - TimeSpan.FromDays((double)settings.PreviousDaysQuantity);

            if (settings.UseExponentCalc)
            {
                int months = 1;
                while (date1 < dateTime1)
                {
                    if (timeMeasure.Name == "Years" && settings.CalcEveryYear)
                    {
                        date1 = date1.AddYears(1);
                        if (date1 > dateTime2 && date1 < dateTime1)
                        {
                            this.Add(contact, date1, timeMeasure, (uint)months);
                        }
                        ++months;
                    }
                    else
                    {
                        for (int index = 1; index <= 10; ++index)
                        {
                            if (timeMeasure.Name == "Monthes")
                            {
                                date1 = date1.AddMonths(months);
                            }
                            else if (timeMeasure.Name == "Years")
                            {
                                date1 = date1.AddYears(months);
                            }
                            if (date1 > dateTime2 && date1 < dateTime1)
                            {
                                this.Add(contact, date1, timeMeasure, (uint)(index * months));
                            }
                            if (date1 > dateTime1)
                            {
                                break;
                            }
                        }
                        months *= 10;
                    }
                }
            }
            if (settings.UseSameDigitsCalc)
            {
                int num = 1;
                date1 = contact.BirthDate;
                while (date1 < dateTime1)
                {
                    int months = 0;
                    for (int index = 0; index < num; ++index)
                    {
                        months += (int)Math.Pow(10.0, (double)index);
                    }
                    ++num;
                    date1 = contact.BirthDate;
                    for (uint index = 1; index < 10U; ++index)
                    {
                        if (timeMeasure.Name == "Monthes")
                        {
                            date1 = date1.AddMonths(months);
                        }
                        else if (timeMeasure.Name == "Years")
                        {
                            date1 = date1.AddYears(months);
                        }
                        if (date1 > dateTime2 && date1 < dateTime1)
                        {
                            this.Add(contact, date1, timeMeasure, (uint)((ulong)index * (ulong)months));
                        }
                        if (date1 > dateTime1)
                        {
                            break;
                        }
                    }
                }
            }
            foreach (double midNum in settings.MidNums)
            {
                int months1 = 1;
                while (timeMeasure.Name == "Monthes" && contact.BirthDate.AddMonths(months1) < dateTime1 || timeMeasure.Name == "Years" && contact.BirthDate.AddYears(months1) < dateTime1)
                {
                    int months2 = (int)((double)months1 * midNum);
                    if ((double)months2 == (double)months1 * midNum)
                    {
                        DateTime date2 = DateTime.MinValue;
                        if (timeMeasure.Name == "Monthes")
                        {
                            date2 = contact.BirthDate.AddMonths(months2);
                        }
                        else if (timeMeasure.Name == "Years")
                        {
                            date2 = contact.BirthDate.AddYears(months2);
                        }
                        if (date2 > dateTime2 && date2 < dateTime1)
                        {
                            this.Add(contact, date2, timeMeasure, (uint)months2);
                        }
                    }
                    months1 *= 10;
                }
            }
        }
Ejemplo n.º 9
0
        private void CalculateEvents(Contact contact, TimeMeasure timeMeasure, Settings settings)
        {
            DateTime birthDate1 = contact.BirthDate;
            DateTime dateTime1  = DateTime.Now + TimeSpan.FromDays((double)settings.NextDaysQuantity);
            DateTime dateTime2  = DateTime.Now - TimeSpan.FromDays((double)settings.PreviousDaysQuantity);

            if (settings.UseExponentCalc)
            {
                uint     num  = 1;
                DateTime date = birthDate1 + TimeSpan.FromTicks(timeMeasure.Duration.Ticks * (long)num);
                while (date < dateTime1)
                {
                    for (uint index = 1; index < 10U; ++index)
                    {
                        if (date > dateTime2 && date < dateTime1)
                        {
                            this.Add(contact, date, timeMeasure, index * num);
                        }
                        date += TimeSpan.FromTicks(timeMeasure.Duration.Ticks * (long)num);
                        if (date > dateTime1)
                        {
                            break;
                        }
                    }
                    num *= 10U;
                }
            }
            if (settings.UseSameDigitsCalc)
            {
                int      num1       = 1;
                DateTime birthDate2 = contact.BirthDate;
                while (birthDate2 < dateTime1)
                {
                    uint num2 = 0;
                    for (int index = 0; index < num1; ++index)
                    {
                        num2 += (uint)Math.Pow(10.0, (double)index);
                    }
                    ++num1;
                    birthDate2 = contact.BirthDate;
                    for (uint index = 1; index < 10U; ++index)
                    {
                        birthDate2 += TimeSpan.FromTicks(timeMeasure.Duration.Ticks * (long)num2);
                        if (birthDate2 > dateTime2 && birthDate2 < dateTime1)
                        {
                            this.Add(contact, birthDate2, timeMeasure, index * num2);
                        }
                        if (birthDate2 > dateTime1)
                        {
                            break;
                        }
                    }
                }
            }
            foreach (double midNum in settings.MidNums)
            {
                uint num = 1;
                while (contact.BirthDate.AddTicks(timeMeasure.Duration.Ticks * (long)num) < dateTime1)
                {
                    uint quantity = (uint)((double)num * midNum);
                    if ((double)quantity == (double)num * midNum)
                    {
                        DateTime date = contact.BirthDate.AddTicks(timeMeasure.Duration.Ticks * (long)quantity);
                        if (date > dateTime2 && date < dateTime1)
                        {
                            this.Add(contact, date, timeMeasure, quantity);
                        }
                    }
                    num *= 10U;
                }
            }
        }
Ejemplo n.º 10
0
        private void Calculate()
        {
            this._settings.SecondsStep    = (int)this.nudSecondsStep.Value;
            this._settings.MinutesStep    = (int)this.nudMinutesStep.Value;
            this._settings.HoursStep      = (int)this.nudHoursStep.Value;
            this._settings.DaysStep       = (int)this.nudDaysStep.Value;
            this._settings.WeeksStep      = (int)this.nudWeeksStep.Value;
            this._settings.MonthesStep    = (int)this.nudMonthesStep.Value;
            this._settings.UseSecondsStep = this.chbSeconds.Checked;
            this._settings.UseMinutesStep = this.chbMinutes.Checked;
            this._settings.UseHoursStep   = this.chbHours.Checked;
            this._settings.UseDaysStep    = this.chbDays.Checked;
            this._settings.UseWeeksStep   = this.chbWeeks.Checked;
            this._settings.UseMonthesStep = this.chbMonthes.Checked;
            this._settings.Save();
            TimeMeasureCollection measureCollection = TimeMeasureCollection.Generate();

            this.dgvEvents.DataSource = (object)null;
            List <DateEvent> dateEventList = new List <DateEvent>();

            if (this.chbSeconds.Checked && this.nudSecondsStep.Value > Decimal.Zero)
            {
                TimeMeasure measure = measureCollection.Find("Seconds");
                if (measure != null)
                {
                    dateEventList.AddRange((IEnumerable <DateEvent>) this.GetEvents((uint)this.nudSecondsStep.Value, TimeSpan.FromSeconds((double)(uint)this.nudSecondsStep.Value), measure));
                }
            }
            if (this.chbMinutes.Checked && this.nudMinutesStep.Value > Decimal.Zero)
            {
                TimeMeasure measure = measureCollection.Find("Minutes");
                if (measure != null)
                {
                    dateEventList.AddRange((IEnumerable <DateEvent>) this.GetEvents((uint)this.nudMinutesStep.Value, TimeSpan.FromMinutes((double)(uint)this.nudMinutesStep.Value), measure));
                }
            }
            if (this.chbHours.Checked && this.nudHoursStep.Value > Decimal.Zero)
            {
                TimeMeasure measure = measureCollection.Find("Hours");
                if (measure != null)
                {
                    dateEventList.AddRange((IEnumerable <DateEvent>) this.GetEvents((uint)this.nudHoursStep.Value, TimeSpan.FromHours((double)(uint)this.nudHoursStep.Value), measure));
                }
            }
            if (this.chbDays.Checked && this.nudDaysStep.Value > Decimal.Zero)
            {
                TimeMeasure measure = measureCollection.Find("Days");
                if (measure != null)
                {
                    dateEventList.AddRange((IEnumerable <DateEvent>) this.GetEvents((uint)this.nudDaysStep.Value, TimeSpan.FromDays((double)(uint)this.nudDaysStep.Value), measure));
                }
            }
            if (this.chbWeeks.Checked && this.nudWeeksStep.Value > Decimal.Zero)
            {
                TimeMeasure measure = measureCollection.Find("Weeks");
                if (measure != null)
                {
                    dateEventList.AddRange((IEnumerable <DateEvent>) this.GetEvents((uint)this.nudWeeksStep.Value, TimeSpan.FromDays((double)(7U * (uint)this.nudWeeksStep.Value)), measure));
                }
            }
            if (this.chbMonthes.Checked && this.nudMonthesStep.Value > Decimal.Zero)
            {
                TimeMeasure measure = measureCollection.Find("Monthes");
                if (measure != null)
                {
                    dateEventList.AddRange((IEnumerable <DateEvent>) this.GetMonthEvents((int)this.nudMonthesStep.Value, measure));
                }
            }
            if (this.rbResultByDates.Checked)
            {
                dateEventList.Sort(new Comparison <DateEvent>(DateEvent.Comparer));
            }
            this.dgvEvents.DataSource = (object)dateEventList;
        }