public override void ApplyTimeOffset(TimeSpan offset)
        {
            StartDate = StartDate.Add(offset);
            EndDate   = EndDate.Add(offset);

            foreach (DateStackStatsResult s in Stats)
            {
                s.Date = s.Date.Add(offset);
            }
        }
Exemple #2
0
        /// <summary>
        /// Determines if the timer is within its active time span.
        /// </summary>
        /// <returns></returns>
        private bool IsActive()
        {
            if (EndDate == default(DateTime))
            {
                return(true);
            }

            var end = EndDate.Add(StartTime == default(DateTime) ? TimeSpan.Zero : StartTime.TimeOfDay);

            return(end >= DateTime.Now);
        }
Exemple #3
0
        public void AddTime(TimeSpan time)
        {
            using (var con = new SQLiteConnection(Constants.Values.DB_CONNECTION_STRING))
            {
                con.Open();
                var stm = "UPDATE BIDS SET END_DATE = @endDate WHERE ID = @id";
                using (var cmd = new SQLiteCommand(stm, con))
                {
                    cmd.Parameters.AddWithValue("@endDate", EndDate.Add(time));
                    cmd.Parameters.AddWithValue("id", ID);

                    cmd.ExecuteNonQuery();
                }
            }
        }
 public void AddValidationErrors(CustomValidationContext context)
 {
     if (DateTime.Compare(StartDate.Add(StartTime), EndDate.Add(EndTime)) >= 0)
     {
         context.Results.Add(new ValidationResult("Data początkowa nie może być później niż końcowa!"));
     }
     if (DateTime.Compare(DateTime.Now, StartDate.Add(StartTime)) >= 0)
     {
         context.Results.Add(new ValidationResult("Data początkowa nie może być w przeszłości!"));
     }
     if (HasAccomodationBooked && String.IsNullOrEmpty(AccomodationId))
     {
         context.Results.Add(new ValidationResult($"Brak Id dla miejsca zakwaterowania!"));
     }
     if (PreferedTravelModes == null || PreferedTravelModes.Count == 0)
     {
         context.Results.Add(new ValidationResult("Brak preferowanych środków transportu!"));
     }
 }
        public override void ApplyTimeOffset(TimeSpan offset)
        {
            StartDate = StartDate.Add(offset);
            EndDate   = EndDate.Add(offset);

            //foreach (var r in MostFrequent.Results) {
            //    r.FirstOccurrence = r.FirstOccurrence.Add(offset);
            //    r.LastOccurrence = r.LastOccurrence.Add(offset);
            //}

            //foreach (var r in MostRecent.Results) {
            //    r.FirstOccurrence = r.FirstOccurrence.Add(offset);
            //    r.LastOccurrence = r.LastOccurrence.Add(offset);
            //}

            foreach (DateProjectStatsResult s in Stats)
            {
                s.Date = s.Date.Add(offset);
            }
        }
        /// <summary>
        /// Checks whether the given time intersects with this entry.
        /// </summary>
        /// <param name="timeToTest"></param>
        /// <returns></returns>
        protected override bool Clash(DateTime timeToTest)
        {
            DateTime testTime = (Options & ScheduleEntryOptions.EVETime) != 0 ? timeToTest.ToUniversalTime() : timeToTest;

            ScheduleDateTimeRange range = GetRangeForDay(testTime.Date);

            if (range == null)
            {
                return(false);
            }

            DateTime startDate = StartDate.Add(range.From.TimeOfDay);

            // in the event m_endDate is set to Forever (DateTime.MaxValue) we can't add anything to it
            DateTime endDate = EndDate == DateTime.MaxValue ? EndDate : EndDate.Add(range.From.TimeOfDay);

            if (startDate < testTime && testTime < endDate)
            {
                return(range.From < testTime && testTime < range.To);
            }

            return(false);
        }
Exemple #7
0
        //Haalt de data (verlofaanvraag) op uit de View, geeft het door aan de controller
        public VacationRequest ToVacationRequest(VacationRequest vacreq = null)
        {
            if (vacreq == null)
            {
                vacreq                 = new VacationRequest();
                vacreq.UserID          = SecurityHelper.GetUserId();
                vacreq.ReasonRejection = "";
                vacreq.DateSubmission  = DateTime.Now;
                vacreq.IsRejected      = false;
                vacreq.IsApproved      = false;
                vacreq.IsInTreatment   = true;
                vacreq.IsActive        = true;
                vacreq.DateCreated     = DateTime.Now;
                vacreq.DateChanged     = DateTime.Now;
                vacreq.CreateUser      = SecurityHelper.GetUserId();
                vacreq.ChangeUser      = SecurityHelper.GetUserId();
                vacreq.IsTotalDays     = CompleteDays;
            }

            //Wanneer de checkbox "hele dagen" is aangevinkt, wordt er uitgegaan van 8 uur verlof per opgegeven dag. De begintijd en eindtijd wordt vastgezet
            if (CompleteDays == true)
            {
                TimeSpan BeginTime = new TimeSpan(9, 00, 0);

                vacreq.BeginDate = BeginDate.Add(BeginTime);


                TimeSpan EndTime = new TimeSpan(17, 00, 0);

                vacreq.EndDate    = EndDate.Add(EndTime);
                vacreq.BeginOfDay = BeginDate;
                vacreq.EndOfDay   = EndDate;
            }

            //De tijd wordt toegevoegd aan de datetime die zal worden opgeslagen
            else
            {
                BeginDate        = BeginDate.Add(BeginTime);
                vacreq.BeginDate = BeginDate;

                EndDate        = EndDate.Add(EndTime);
                vacreq.EndDate = EndDate;

                vacreq.BeginOfDay = BeginDate.Date.Add(UserBeginTime);
                vacreq.EndOfDay   = EndDate.Date.Add(UserEndTime);
            }

            //Verschil in dagen wordt berekend
            TimeSpan DifferenceDayInHours = UserEndTime - UserBeginTime;

            if (DifferenceDayInHours.TotalMinutes > 480)
            {
                int minutesoverload = (DifferenceDayInHours.Minutes % 480) * -1;
                UserEndTime = UserEndTime.Add(new TimeSpan(0, minutesoverload, 0));
            }
            TimeSpan differencehours = EndTime - BeginTime;

            if (differencehours.TotalMinutes > 480)
            {
                int minutesoverload = (differencehours.Minutes % 480) * -1;
                EndTime = EndTime.Add(new TimeSpan(0, minutesoverload, 0));
            }
            TimeSpan DifferenceInDays = EndDate - BeginDate;
            int      TotalDays        = DifferenceInDays.Days;

            if (DifferenceInDays.Hours == 8)
            {
                TotalDays = TotalDays + 1;
            }

            if (CompleteDays == true)
            {
                TotalDays = TotalDays + 1;
            }

            //Het totaal aantal minuten in de verlofaanvraag worden berekend (als checkbox "hele dagen" is aangevinkt).
            if (CompleteDays == true)
            {
                int      CountHours = 0;
                DateTime t          = BeginDate;
                for (int i = 1; i <= TotalDays; i++)
                {
                    if (t.DayOfWeek == DayOfWeek.Monday || t.DayOfWeek == DayOfWeek.Tuesday || t.DayOfWeek == DayOfWeek.Wednesday || t.DayOfWeek == DayOfWeek.Thursday || t.DayOfWeek == DayOfWeek.Friday)
                    {
                        CountHours = CountHours + 8;
                    }

                    if (t.DayOfWeek == DayOfWeek.Saturday || t.DayOfWeek == DayOfWeek.Sunday)
                    {
                        CountHours = CountHours + 0;
                    }
                    t = t.AddDays(1);
                }
                int TotalMinutes = CountHours * 60;
                vacreq.TotalMinutes = TotalMinutes;
            }

            if (CompleteDays == false)
            {
                DifferenceInDays = EndDate.Date - BeginDate.Date;


                if (DifferenceInDays.Days < 1)
                {
                    int DifferenceHours   = 0;
                    int DifferenceMinutes = 0;

                    if (BeginTime < EndTime)
                    {
                        DifferenceHours = EndTime.Hours - BeginTime.Hours;

                        if (EndTime.Minutes == BeginTime.Minutes)
                        {
                            DifferenceMinutes = 0;
                        }

                        if (BeginTime.Minutes < EndTime.Minutes)
                        {
                            DifferenceMinutes = EndTime.Minutes - BeginTime.Minutes;
                        }

                        if (BeginTime.Minutes > EndTime.Minutes)
                        {
                            if (EndTime.Minutes == 0)
                            {
                                DifferenceMinutes = 60 - BeginTime.Minutes;
                                DifferenceHours   = DifferenceHours - 1;
                            }

                            if (BeginTime.Minutes > EndTime.Minutes && EndTime.Minutes != 0)
                            {
                                DifferenceMinutes = 60 - (BeginTime.Minutes - EndTime.Minutes);
                                DifferenceHours   = DifferenceHours - 1;
                            }
                        }


                        vacreq.TotalMinutes = (DifferenceHours * 60) + DifferenceMinutes;
                    }

                    if (vacreq.TotalMinutes > 480)
                    {
                        vacreq.TotalMinutes = 480;
                    }
                }

                if (DifferenceInDays.Days >= 1 && DifferenceInDays.Days < 2)
                {
                    int DifferenceHours   = 0;
                    int DifferenceMinutes = 0;
                    int MinutesFirstDay   = 0;
                    int MinutesSecondDay  = 0;

                    DifferenceHours = (UserEndTime.Hours - BeginTime.Hours) + (EndTime.Hours - UserBeginTime.Hours);

                    if (UserEndTime.Minutes == BeginTime.Minutes)
                    {
                        MinutesFirstDay = 0;
                    }

                    if (UserEndTime.Minutes > BeginTime.Minutes)
                    {
                        MinutesFirstDay = (UserEndTime.Minutes - BeginTime.Minutes);
                    }

                    if (UserEndTime.Minutes < BeginTime.Minutes)
                    {
                        if (UserEndTime.Minutes == 0)
                        {
                            MinutesFirstDay = 60 - BeginTime.Minutes;
                            DifferenceHours = DifferenceHours - 1;
                        }

                        if (UserEndTime.Minutes != 0)
                        {
                            MinutesFirstDay = 60 - (BeginTime.Minutes - UserEndTime.Minutes);
                            DifferenceHours = DifferenceHours - 1;
                        }
                    }

                    if (EndTime.Minutes == UserBeginTime.Minutes)
                    {
                        MinutesSecondDay = 0;
                    }

                    if (EndTime.Minutes > UserBeginTime.Minutes)
                    {
                        MinutesSecondDay = (EndTime.Minutes - UserBeginTime.Minutes);
                    }

                    if (EndTime.Minutes < UserBeginTime.Minutes)
                    {
                        if (EndTime.Minutes == 0)
                        {
                            MinutesSecondDay = 60 - UserBeginTime.Minutes;
                            DifferenceHours  = DifferenceHours - 1;
                        }

                        if (EndTime.Minutes != 0)
                        {
                            MinutesSecondDay = 60 - (UserBeginTime.Minutes - EndTime.Minutes);
                            DifferenceHours  = DifferenceHours - 1;
                        }
                    }

                    DifferenceMinutes = MinutesFirstDay + MinutesSecondDay;
                    if (DifferenceMinutes > 59)
                    {
                        DifferenceHours   = DifferenceHours + 1;
                        DifferenceMinutes = DifferenceMinutes - 60;
                    }

                    vacreq.TotalMinutes = (DifferenceHours * 60) + DifferenceMinutes;
                }

                if (DifferenceInDays.Days >= 2)
                {
                    int      totaldaysbetween = 0;
                    DateTime startDate        = BeginDate;
                    for (int i = 1; i <= DifferenceInDays.Days; i++)
                    {
                        if (startDate.DayOfWeek == DayOfWeek.Monday || startDate.DayOfWeek == DayOfWeek.Tuesday || startDate.DayOfWeek == DayOfWeek.Wednesday || startDate.DayOfWeek == DayOfWeek.Thursday || startDate.DayOfWeek == DayOfWeek.Friday)
                        {
                            totaldaysbetween = totaldaysbetween + 1;
                        }

                        startDate = startDate.AddDays(1);
                    }

                    totaldaysbetween = totaldaysbetween - 1;


                    int DifferenceHours   = 0;
                    int DifferenceMinutes = 0;
                    int MinutesFirstDay   = 0;
                    int MinutesSecondDay  = 0;

                    DifferenceHours = (UserEndTime.Hours - BeginTime.Hours) + (EndTime.Hours - UserBeginTime.Hours);

                    if (UserEndTime.Minutes == BeginTime.Minutes)
                    {
                        MinutesFirstDay = 0;
                    }

                    if (UserEndTime.Minutes > BeginTime.Minutes)
                    {
                        MinutesFirstDay = (UserEndTime.Minutes - BeginTime.Minutes);
                    }

                    if (UserEndTime.Minutes < BeginTime.Minutes)
                    {
                        if (UserEndTime.Minutes == 0)
                        {
                            MinutesFirstDay = 60 - BeginTime.Minutes;
                            DifferenceHours = DifferenceHours - 1;
                        }

                        if (UserEndTime.Minutes != 0)
                        {
                            MinutesFirstDay = 60 - (BeginTime.Minutes - UserEndTime.Minutes);
                            DifferenceHours = DifferenceHours - 1;
                        }
                    }

                    if (EndTime.Minutes == UserBeginTime.Minutes)
                    {
                        MinutesSecondDay = 0;
                    }

                    if (EndTime.Minutes > UserBeginTime.Minutes)
                    {
                        MinutesSecondDay = (EndTime.Minutes - UserBeginTime.Minutes);
                    }

                    if (EndTime.Minutes < UserBeginTime.Minutes)
                    {
                        if (EndTime.Minutes == 0)
                        {
                            MinutesSecondDay = 60 - UserBeginTime.Minutes;
                            DifferenceHours  = DifferenceHours - 1;
                        }

                        if (EndTime.Minutes != 0)
                        {
                            MinutesSecondDay = 60 - (UserBeginTime.Minutes - EndTime.Minutes);
                            DifferenceHours  = DifferenceHours - 1;
                        }
                    }

                    DifferenceMinutes = MinutesFirstDay + MinutesSecondDay;
                    if (DifferenceMinutes > 59)
                    {
                        DifferenceHours   = DifferenceHours + 1;
                        DifferenceMinutes = DifferenceMinutes - 60;
                    }

                    var      totalhoursindays       = DifferenceHours;
                    TimeSpan DifferenceBeginEndTime = (new TimeSpan(vacreq.EndOfDay.Value.Hour, vacreq.EndOfDay.Value.Minute, 00)) - (new TimeSpan(vacreq.BeginOfDay.Value.Hour, vacreq.BeginOfDay.Value.Minute, 00));
                    if (DifferenceBeginEndTime.TotalMinutes > 480)
                    {
                        var minutesoverload = (DifferenceBeginEndTime.TotalMinutes % 480) * -1;
                        DifferenceBeginEndTime = DifferenceBeginEndTime.Add(new TimeSpan(0, Convert.ToInt32(minutesoverload), 0));
                    }

                    vacreq.TotalMinutes = (totalhoursindays * 60) + DifferenceMinutes + (Convert.ToInt32(DifferenceBeginEndTime.TotalMinutes) * totaldaysbetween);
                }
            }

            vacreq.Reason = Reason;
            if (vacreq.IsTotalDays == true)
            {
                vacreq.BeginDate = BeginDate.Add(new TimeSpan(08, 00, 00));
                vacreq.EndDate   = EndDate.Add(new TimeSpan(18, 00, 00));
            }
            vacreq.HasDeadlines   = HasDeadlines;
            vacreq.IsCommunicated = IsCommunicated;

            return(vacreq);
        }
 public Termin ToTermin(string SchulungGUID)
 {
     return(new Termin {
         SchulungGUID = SchulungGUID, Start = StartDate.Add(StartTime), End = EndDate.Add(EndTime)
     });
 }