EnVisageOnline/Beta/Source/EnVisage/Models/FiscalCalendarModel.cs

129 lines
4.3 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Linq;
using System.Web;
using EnVisage.Code;
namespace EnVisage.Models
{
public class FiscalCalendarModel : IValidatableObject
{
#region Classes and enums
/// <summary>
/// Represents a fiscal calendar type.
/// </summary>
public enum FiscalCalendarType
{
/// <summary>
/// Undefined = -1.
/// </summary>
//[DisplayValue("")]
//Undefined = -1,
/// <summary>
/// Calendar Year = 0.
/// </summary>
[DisplayValue("Calendar Year")]
CalendarYear = 0,
/// <summary>
/// 4-4-5 weeks calendar where each quarter contains of 3 months with 4, 4 and 5 weeks.
/// </summary>
[DisplayValue("4,4,5 weeks Calendar")]
Calendar445 = 1,
/// <summary>
/// 4-5-4 weeks calendar where each quarter contains of 3 months with 4, 5 and 4 weeks.
/// </summary>
[DisplayValue("4,5,4 weeks Calendar")]
Calendar454 = 2,
/// <summary>
/// 5-4-4 weeks calendar where each quarter contains of 3 months with 5, 4 and 4 weeks.
/// </summary>
[DisplayValue("5,4,4 weeks Calendar")]
Calendar544 = 3,
}
/// <summary>
/// Represents a way of ending the calendar year and distribution of weeks between quarters.
/// </summary>
public enum CalendarYearType
{
[DisplayValue("52 weeks only")]
Only52Weeks = 0,
[DisplayValue("Last <Week ending day> of the month")]
LastWeekDay = 1,
[DisplayValue("Standard Year")]
StandardYear = 2
}
/// <summary>
/// Represents a fiscal year record type.
/// </summary>
public enum FiscalYearType
{
Week = 0,
Month = 1,
Quarter = 2,
Year = 3
}
#endregion
#region Constructors
public FiscalCalendarModel()
{
TypeSettingId = StartDateSettingId = WeekEndingSettingId = WeekEndingTypeSettingId = Guid.Empty;
}
#endregion
#region Properties
public Guid TypeSettingId { get; set; }
public Guid StartDateSettingId { get; set; }
public Guid WeekEndingSettingId { get; set; }
public Guid WeekEndingTypeSettingId { get; set; }
[Required]
[Display(Name = "Calendar Type")]
public FiscalCalendarType? Type { get; set; }
[DataType(DataType.Date), DisplayFormat(DataFormatString = "{0:MM/dd/yy}", ApplyFormatInEditMode = true)]
[Display(Name = "Current Year Start Date")]
public DateTime? CurrentYearStartDate { get; set; }
[Display(Name = "Week Ending")]
public DayOfWeek? WeekEnding { get; set; }
[Display(Name = "Year Type")]
public CalendarYearType? WeekEndingType { get; set; }
[Display(Name = "Adjust Period")]
public bool Adjustingperiod { get; set; }
#endregion
#region Methods
/// <summary>
/// Validates an object and returns a collection that holds failed-validation information.
/// </summary>
/// <returns>
/// A collection that holds failed-validation information.
/// </returns>
/// <param name="validationContext">The validation context.</param>
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
switch (Type)
{
case FiscalCalendarType.CalendarYear:
yield break;
default:
if (this.WeekEndingType == null)
yield return new ValidationResult(string.Format(Constants.ERROR_TEMPLATE_REQUIRED, "Week Ending Type"), new [] { "WeekEndingType" });
if (this.CurrentYearStartDate == null)
yield return new ValidationResult(string.Format(Constants.ERROR_TEMPLATE_REQUIRED, "Current Year Start Date"), new[] { "CurrentYearStartDate" });
break;
}
}
#endregion
}
}