/// <summary>
        /// Generates the list of dates from the end date.
        /// </summary>
        /// <returns>The generated dates list.</returns>
        private List <RightValue> GenerateBackward()
        {
            List <RightValue> dates = new List <RightValue>();
            RightValue        rv;
            int i = 0;

            // Add the dates from the designated end date adding the interval each time
            DateTime tempDate = EndDate;

            while (tempDate.CompareTo(StartDate) > 0)
            {
                rv = RightValue.ConvertFrom(tempDate, true);

                dates.Add(rv);
                tempDate = AddPeriod(Frequency, EndDate, ++i, GenerateSequenceFromStartDate);
            }

            if (tempDate.Equals(StartDate))
            {
                // The end date follow the frequency scheme so no need to control it
                dates.Add(RightValue.ConvertFrom(StartDate, true));
            }
            else
            {
                // The end date doesn't follow the frequency schema so replace the
                // last current date generated with the last date of the sequence
                DateTime startMinPeriod = new DateTime(tempDate.Year, tempDate.Month, 1);
                DateTime endMinPeriod   = AddPeriod(Frequency, startMinPeriod, 1, true);
                if (StartDate.CompareTo(startMinPeriod) >= 0 &&
                    StartDate.CompareTo(endMinPeriod) < 0)
                {
                    if (FollowFrequency)
                    {
                        // Follow the frequency schema strictly
                        dates.Add(RightValue.ConvertFrom(tempDate, true));
                    }
                    else
                    {
                        // Add the start date since the sequence can be generated loosely
                        dates.Add(RightValue.ConvertFrom(StartDate, true));
                    }
                }
                else
                {
                    if (!FollowFrequency)
                    {
                        // Follow the frequency schema strictly
                        dates.Add(RightValue.ConvertFrom(StartDate, true));
                    }
                }
            }

            dates.Reverse();
            if (dates.Count > skipPeriodsParsed)
            {
                dates = dates.Skip(skipPeriodsParsed).ToList();
            }

            return(dates);
        }
Ejemplo n.º 2
0
        public bool Valid()
        {
            ClearErrors();

            if (IsNew && Courses.Any(c => Code == c.Code) || IsNew && Code == 0)
            {
                AddError("Code", Properties.Resources.Error_Exist);
            }
            if (string.IsNullOrEmpty(Title))
            {
                AddError("Title", Properties.Resources.Error_RequiredTitle);
            }
            if (Teacher == null)
            {
                AddError("Teacher", Properties.Resources.Error_Required);
            }
            if (StartDate.CompareTo(FinishDate) > 0 || FinishDate.CompareTo(StartDate) < 0)
            {
                AddError("StartDate", Properties.Resources.Error_StartDate);
                AddError("FinishDate", Properties.Resources.Error_FinishDate);
            }
            if (StartTime.CompareTo(EndTime) > 0)
            {
                AddError("StartTime", Properties.Resources.Error_StartTime);
                AddError("EndTime", Properties.Resources.Error_EndTime);
            }

            RaiseErrors();

            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Compares the current instance with another object of the same type.
        /// </summary>
        /// <returns>
        /// A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has these meanings: Value Meaning Less than zero This instance is less than <paramref name="obj" />. Zero This instance is equal to <paramref name="obj" />. Greater than zero This instance is greater than <paramref name="obj" />.
        /// </returns>
        /// <param name="obj">An object to compare with this instance. </param>
        /// <exception cref="T:System.ArgumentException"><paramref name="obj" /> is not the same type as this instance. </exception><filterpriority>2</filterpriority>
        public int CompareTo(object obj)
        {
            SPSCalendarItem item = obj as SPSCalendarItem;

            if (item != null)
            {
                return(StartDate.CompareTo(item.StartDate));
            }
            return(-1);
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (StartDate.CompareTo(EndDate) > 0)
            {
                InValidDateSelected = true;

                var lc = await _db.LeaveCategories.AsNoTracking().ToListAsync();

                LeaveCategories = new List <SelectListItem>();
                if (lc != null)
                {
                    if (lc.Count > 0)
                    {
                        foreach (var item in lc)
                        {
                            LeaveCategories.Add(new SelectListItem {
                                Value = item.Id.ToString(), Text = item.Title
                            });
                        }
                    }
                }

                ViewData["User_Name"] = _accountManage.User.Name;
                ViewData.Add("ProfileImg", _accountManage.User.ProfileImageSrc);
                return(Page());
            }

            var leavecategory = await _db.LeaveCategories.FindAsync(LeaveCategory);

            var user = await _db.Users.Include(a => a.LeaveApplications).SingleAsync(a => a.Id == _accountManage.User.Id);

            var totalDays = EndDate - StartDate;


            var leaveApplication = new LeaveApplication
            {
                EndDate       = EndDate,
                StartDate     = StartDate,
                LeaveCategory = leavecategory,
                Reason        = Reason,
                Days          = (int)(totalDays.TotalDays + 1),
                User          = user,
                Status        = LeaveApplicationStatus.Pending,
                AppliedDate   = DateTime.Now
            };

            user.LeaveApplications.Add(leaveApplication);

            await _db.SaveChangesAsync();

            return(RedirectToPage("./Leave_Application"));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets a value indicating whether the discount is active now
        /// </summary>
        /// <param name="CouponCodeToValidate">Coupon code to validate</param>
        /// <returns>A value indicating whether the discount is active now</returns>
        public bool IsActive(string CouponCodeToValidate)
        {
            if (this.RequiresCouponCode && !String.IsNullOrEmpty(this.CouponCode))
            {
                if (CouponCodeToValidate != this.CouponCode)
                {
                    return(false);
                }
            }
            DateTime now      = DateTimeHelper.ConvertToUtcTime(DateTime.Now);
            bool     isActive = (!Deleted) && (StartDate.CompareTo(now) < 0) && (EndDate.CompareTo(now) > 0);

            return(isActive);
        }
Ejemplo n.º 6
0
        int IComparable <Event> .CompareTo(Event other)
        {
            var compare = StartDate.CompareTo(other.StartDate);

            if (compare == 0)
            {
                compare = EndDate.CompareTo(other.EndDate);
            }
            if (compare == 0)
            {
                compare = ID.CompareTo(other.ID);
            }
            return(compare);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Set StartDate and EndDate columns to datatable and update their values
        /// </summary>
        /// <param name="dataTable"></param>
        /// <returns></returns>
        private DataTable SetStartDateEndDate(DataTable dataTable)
        {
            DataTable RetVal = dataTable;
            DateTime  StartDate;
            DateTime  EndDate;

            try
            {
                if (dataTable != null)
                {
                    dataTable.Columns.Add(Data.StartDate, typeof(string));
                    dataTable.Columns.Add(Data.EndDate, typeof(string));
                    foreach (DataRow dr in dataTable.Rows)
                    {
                        StartDate = DateTime.MinValue;
                        EndDate   = DateTime.MinValue;
                        TimePeriodFacade.SetStartDateEndDate(dr[Timeperiods.TimePeriod].ToString(), ref StartDate, ref EndDate);

                        if (StartDate.CompareTo(DateTime.MinValue) == 0)
                        {
                            dr[Data.StartDate] = string.Empty;
                        }
                        else
                        {
                            dr[Data.StartDate] = StartDate.ToString("yyyy.MM.dd");
                        }

                        if (EndDate.CompareTo(DateTime.MinValue) == 0)
                        {
                            dr[Data.EndDate] = string.Empty;
                        }
                        else
                        {
                            dr[Data.EndDate] = EndDate.ToString("yyyy.MM.dd");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.Print(ex.Message);
            }

            return(RetVal);
        }
Ejemplo n.º 8
0
        public virtual void Validate(bool isMonthly = false)
        {
            if (StartDate.CompareTo(EndDate) >= 0)
            {
                throw new TException <ValidateExceptionArgs>("起始时间不能大于或等于结束时间。");
            }
            if (!isMonthly)
            {
                if (StartDate.CompareTo(DateTime.Now) > 0)
                {
                    throw new TException <ValidateExceptionArgs>("起始时间不能大于当前时间。");
                }
            }

            if ((EndDate - StartDate).TotalDays > 90 + 3)
            {
                throw new TException <ValidateExceptionArgs>(new ValidateExceptionArgs(),
                                                             string.Format("查询时间间隔不能大于{0}天。", 90));
            }
        }
Ejemplo n.º 9
0
        public bool Export()
        {
            bool        result = false;
            ExcelHelper helper = new ExcelHelper(FilePath);

            if (helper.StartEdit(0) == false)
            {
                GParam.Create().WriteSystemLog(helper.ErrorMessage);
                return(result);
            }

            try
            {
                DataTable exportDt = new DataTable();
                exportDt.Columns.Add("日期", typeof(string));
                foreach (TB_DailyPlanCatalog item in CatalogItems)
                {
                    DataColumn col = new DataColumn();
                    col.ColumnName = item.Name;
                    col.Caption    = item.Name;
                    exportDt.Columns.Add(col);
                }

                while (StartDate.CompareTo(EndDate) <= 0)
                {
                    DataRow temprow = exportDt.NewRow();
                    temprow[0] = StartDate.ToString("yyyy-MM-dd");
                    exportDt.Rows.Add(temprow);
                    StartDate = StartDate.AddDays(1);
                }
                helper.InsertDataTable(exportDt);
                result = helper.Save();
            }
            catch (Exception ex)
            {
                GParam.Create().WriteSystemLog("Export", ex);
            }
            return(result);
        }
Ejemplo n.º 10
0
 public int CompareTo(Record target)
 {
     return(StartDate.CompareTo(target.StartDate));
 }
Ejemplo n.º 11
0
 public int CompareTo(WorkshopListElementModel other)
 {
     return(StartDate.CompareTo(other.StartDate));
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Compares the current object with another object of the same type.
 /// </summary>
 /// <param name="other"> An object to compare with this object.</param>
 /// <returns>A 32-bit signed integer that indicates the relative order of the objects
 /// being compared. The return value has the following meanings: Value Meaning
 /// Less than zero This object is less than the other parameter.Zero This object
 /// is equal to other. Greater than zero This object is greater than other.</returns>
 public int CompareTo(CalendarItemModel other)
 {
     return(StartDate.CompareTo(other.StartDate));
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Compare two free busy time blocks
        /// </summary>
        /// <param name="obj">The free busy time block to compare to</param>
        /// <returns>Comparison value</returns>
        public int CompareTo(object obj)
        {
            FreeBusyTimeBlock block = (FreeBusyTimeBlock)obj;

            return(StartDate.CompareTo(block.StartDate));
        }
Ejemplo n.º 14
0
        private bool SetDate(string dateString)
        {
            DateTime date;

            string[] dateAndTime   = dateString.Split(' ');
            string[] timeSubstring = dateAndTime[1].Split(':');
            int[]    time          = new int[3];
            for (int i = 0; i < 3; i++)
            {
                time[i] = int.Parse(timeSubstring[i]);
            }
            string[] dateSubstring = dateAndTime[0].Split('-', '/');
            // Checks if the string arrays length is differnet than 3 if så something from the file is wrong

            if (dateSubstring.Length != 3)
            {
                return(false);
            }
            // Checks that it can only be digits
            foreach (var subString in dateSubstring)
            {
                if (!subString.All(c => Char.IsDigit(c)))
                {
                    return(false);
                }
            }
            // Converts to ints
            int[] dates = new int[3];
            for (int i = 0; i < 3; i++)
            {
                dates[i] = int.Parse(dateSubstring[i]);
            }
            // Checks that the dates are valid
            if (dates[2] < 1 || dates[2] > 31)
            {
                // Burde kigge efter skudår osv, men det er en mindre implemtations detlaje jeg ikke dømmer værd at lave lige pt
                return(false);
            }
            if (dates[1] < 1 || dates[1] > 12)
            {
                return(false);
            }
            if (dates[0] < 1 || dates[0] > 10000)
            {
                return(false);
            }
            date = new DateTime(dates[0], dates[1], dates[2], time[0], time[1], time[2]);
            // Checks if the end date is after the start date
            if (StartDate.CompareTo(DateTime.MinValue) != 0)  // == If startdate is different than null
            {
                // Hvis enddate kommer efter startdate
                if (date.CompareTo(StartDate) != -1)
                {
                    EndDate = date;
                    return(false);
                }
            }

            StartDate = date;
            return(true);
        }
Ejemplo n.º 15
0
 public int CompareTo(TimeCardModel other)
 {
     return(StartDate.CompareTo(other));
 }
Ejemplo n.º 16
0
        private async void AddEvent()
        {
            if (IsReadOnly)
            {
                return;
            }

            if (string.IsNullOrEmpty(EventTitle) || string.IsNullOrEmpty(EventTitle.Trim()))
            {
                Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, "Event title must not be empty"));
                return;
            }

            if (EndDate.CompareTo(DateTime.UtcNow.ToLocalTime()) != 1 || StartDate.CompareTo(DateTime.UtcNow.ToLocalTime()) != 1)
            {
                Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, "End Date or Start Date must be later than now"));
                return;
            }

            if (EndDate.CompareTo(StartDate) == 0)
            {
                Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, "Start time & end time must be different when the dates are equal"));
                return;
            }

            if (EndDate.CompareTo(StartDate) > 0)
            {
                if (BaseView != null && BaseView.CheckInternetConnection())
                {
                    Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, true));

                    if (IsEditMode)
                    {
                        if (mOldRepeat.Equals("once"))
                        {
                            var result =
                                await mApiService.PutUnavailabilities(Mvx.Resolve <ICacheService>().CurrentUser.UserId, ParkingId, UnavailabilityId, EventTitle, Helpers.TimestampHelpers.DateTimeToTimeStamp(StartDate), Helpers.TimestampHelpers.DateTimeToTimeStamp(EndDate),
                                                                      new Periodicity()
                            {
                            }, "all", true, StartTimestampOfSelectedOccurrence);

                            if (result != null)
                            {
                                //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Result.Equals("success") ? result.Result : string.Format("{0}\n{1}",result.Result, result.ErrorCode )));
                                //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Result.Equals("success") ? result.Result : string.Format("{0}: {1}", result.Result, result.ErrorCode)));
                                if (result.Response.Status.Equals("success"))
                                {
                                    Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Status));
                                }
                                else
                                {
                                    Mvx.Resolve <IMvxMessenger>().Publish(new AlertMessage(this, string.Empty, string.Format("{0}: {1}", result.Response.Status, result.Response.ErrorCode), "Ok", null));
                                }
                            }
                            Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, false));
                            mCacheService.NeedReloadEvent = true;
                            Close(this);
                            return;
                        }
                        //edit unavaiability
                        Mvx.Resolve <IMvxMessenger>().Publish(new AlertMessage(this, SharedTextSource.GetText("EditEventText"), SharedTextSource.GetText("AreYouSureEventText"), SharedTextSource.GetText("CancelText"), null, new string[] { SharedTextSource.GetText("EditFutureEventsText"), SharedTextSource.GetText("EditEventOnlyText") },
                                                                               async() =>
                        {
                            var result =
                                await mApiService.PutUnavailabilities(Mvx.Resolve <ICacheService>().CurrentUser.UserId, ParkingId, UnavailabilityId, EventTitle, Helpers.TimestampHelpers.DateTimeToTimeStamp(StartDate), Helpers.TimestampHelpers.DateTimeToTimeStamp(EndDate),
                                                                      new Periodicity()
                            {
                                Repeat            = SelectedRepeat,
                                OccurrencesAmount = Times,
                                Exceptions        = new List <PeriodicityException>()
                                {
                                }
                            }, "all", false, StartTimestampOfSelectedOccurrence);

                            if (result != null)
                            {
                                //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Result.Equals("success") ? result.Result : string.Format("{0}\n{1}", result.Result, result.ErrorCode)));
                                if (result.Response.Status.Equals("success"))
                                {
                                    Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Status));
                                }
                                else
                                {
                                    Mvx.Resolve <IMvxMessenger>().Publish(new AlertMessage(this, string.Empty, string.Format("{0}: {1}", result.Response.Status, result.Response.ErrorCode), "Ok", null));
                                }
                            }

                            mCacheService.NeedReloadEvent = true;
                            Close(this);
                        }, async() =>
                        {
                            var result =
                                await mApiService.PutUnavailabilities(Mvx.Resolve <ICacheService>().CurrentUser.UserId, ParkingId, UnavailabilityId, EventTitle, Helpers.TimestampHelpers.DateTimeToTimeStamp(StartDate), Helpers.TimestampHelpers.DateTimeToTimeStamp(EndDate),
                                                                      new Periodicity()
                            {
                            }, "all", true, StartTimestampOfSelectedOccurrence);

                            if (result != null)
                            {
                                //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Result.Equals("success") ? result.Result : string.Format("{0}\n{1}",result.Result, result.ErrorCode )));
                                //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Result.Equals("success") ? result.Result : string.Format("{0}: {1}", result.Result, result.ErrorCode)));
                                if (result.Response.Status.Equals("success"))
                                {
                                    Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Status));
                                }
                                else
                                {
                                    Mvx.Resolve <IMvxMessenger>().Publish(new AlertMessage(this, string.Empty, string.Format("{0}: {1}", result.Response.Status, result.Response.ErrorCode), "Ok", null));
                                }
                            }

                            mCacheService.NeedReloadEvent = true;
                            Close(this);
                        }));
                    }
                    else
                    {
                        //add unavaiability
                        var result =
                            await mApiService.CreateUnavailabilities(mCacheService.CurrentUser.UserId, mCacheService.ParkingId, EventTitle, Helpers.TimestampHelpers.DateTimeToTimeStamp(StartDate), Helpers.TimestampHelpers.DateTimeToTimeStamp(EndDate),
                                                                     new Periodicity()
                        {
                            Repeat            = SelectedRepeat,
                            OccurrencesAmount = Times
                        }, "all");

                        if (result != null)
                        {
                            //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Result));
                            //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Equals("success") ? "Success" : string.Format("{0}: {1}", result.Response.Result, result.Response.ErrorCode)));
                            if (result.Response.Status.Equals("success"))
                            {
                                Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Status));
                            }
                            else
                            {
                                if (result.ApiError.Status.Equals("999"))
                                {
                                    Mvx.Resolve <IMvxMessenger> ().Publish(new AlertMessage(this, string.Empty, string.Format("{0}", result.Response.ErrorCode), "Ok", null));
                                }
                                else
                                {
                                    Mvx.Resolve <IMvxMessenger>().Publish(new AlertMessage(this, string.Empty, string.Format("{0}: {1}", result.Response.Status, result.Response.ErrorCode), "Ok", null));
                                }
                            }
                        }

                        mCacheService.NeedReloadEvent = true;
                        Close(this);
                    }



                    Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, false));
                }
                else
                {
                    Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, SharedTextSource.GetText("TurnOnInternetText")));
                }
            }
            else
            {
                Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, "End Date must be later than Start Date"));
            }
        }
Ejemplo n.º 17
0
 public int CompareTo(Employment other)
 {
     return(StartDate.CompareTo(other.StartDate));
 }
Ejemplo n.º 18
0
 public int CompareTo(Reservation other)
 {
     return(StartDate.CompareTo(other.StartDate));
 }
Ejemplo n.º 19
0
 public virtual bool Validate()
 {
     return(StartDate.CompareTo(EndDate) <= 0);
 }