static void Main(string[] args) { Console.Write("\nPlease Enter a number between 1 and 12 : "); string userInput = Console.ReadLine(); if (int.TryParse(userInput, out int input)) { if (input >= 1 && input <= 12) { MonthsOfYear month = (MonthsOfYear)input; Console.Write($"You have entered the value : {input}"); Console.Write($". This is the month : {month}\n"); } else { Console.WriteLine("Please, only enter a value of 1-12"); } } else { Console.WriteLine("Please, only enter a number"); } Console.ReadKey(); }
static void Main() { // intro Console.WriteLine("------| Our months of the year converter |------"); Console.WriteLine(); // Getting user input for entered number Console.Write("Please enter the month you want returned, enter a number from 1 to 12: "); string getUserInputString = Console.ReadLine(); int monthInt = Convert.ToInt32(getUserInputString); // check to make sure the input is valid if (monthInt > 0 && monthInt <= 12) { // print out the month name, we also do the explicit convert from an int MonthsOfYear month = (MonthsOfYear)monthInt; Console.WriteLine($"You entered {getUserInputString}, the Month is: {month}."); } else // if none of the correct numbers are used, print error and start again { Console.WriteLine("You did not enter a valid number, there are only 12 options, please try again..."); Console.WriteLine("Press enter to restart..."); Console.ReadKey(); Console.Clear(); // loop back to start Program.Main(); } Console.ReadKey(); }
public void SampleYear(MonthsOfYear months) { switch (months) { case MonthsOfYear.Jan: case MonthsOfYear.Feb: case MonthsOfYear.Mar: case MonthsOfYear.Apr: case MonthsOfYear.May: Console.WriteLine("Spring is here"); break; case MonthsOfYear.Jun: case MonthsOfYear.Jul: case MonthsOfYear.Aug: Console.WriteLine("Summer is here"); break; case MonthsOfYear.Sep: case MonthsOfYear.Oct: case MonthsOfYear.Nov: Console.WriteLine("Fall is here" + "I am happy" + "The winter is going by by"); break; } }
static void Main(string[] args) { //1. Days of the Week //DaysOfWeek today; //today = DaysOfWeek.Wednesday; //Console.WriteLine($"today: {today}"); //int dayAsInt = (int)DaysOfWeek.Saturday; // Converts Sat to int which is 6 //Console.WriteLine($"dayAsInt: {dayAsInt}"); //today = (DaysOfWeek)dayAsInt; // Converts 6 to DaysOfWeek type which is Saturday //Console.WriteLine($"today: {today}"); //2. TIO: Page 85: Months of the Year Console.WriteLine("Enter a month number 1 - 12:"); string monthAsString = Console.ReadLine(); int monthAsInt = Convert.ToInt32(monthAsString); Console.WriteLine($"month: {monthAsInt}"); if (monthAsInt > 0 && monthAsInt <= 12) { MonthsOfYear selectedMonth = (MonthsOfYear)monthAsInt; Console.WriteLine($"selectedMonth: {selectedMonth}"); } else { Console.WriteLine($"The number you provided is not within the month integer range: {monthAsInt}"); } Console.ReadKey(); }
private string getMonthOfYearDescription() { MonthsOfYear months = (MonthsOfYear)MonthsOfYearBitmask; if (months.HasFlag(MonthsOfYear.January)) { return("Jan"); } if (months.HasFlag(MonthsOfYear.February)) { return("Feb"); } if (months.HasFlag(MonthsOfYear.March)) { return("Mar"); } if (months.HasFlag(MonthsOfYear.April)) { return("Apr"); } if (months.HasFlag(MonthsOfYear.May)) { return("May"); } if (months.HasFlag(MonthsOfYear.June)) { return("Jun"); } if (months.HasFlag(MonthsOfYear.July)) { return("Jul"); } if (months.HasFlag(MonthsOfYear.August)) { return("Aug"); } if (months.HasFlag(MonthsOfYear.September)) { return("Sep"); } if (months.HasFlag(MonthsOfYear.October)) { return("Oct"); } if (months.HasFlag(MonthsOfYear.November)) { return("Nov"); } if (months.HasFlag(MonthsOfYear.December)) { return("Dec"); } return(""); }
public IEnumerable <DateTime> GetScheduledTimes(DateTime start, TimeSpan howFarAhead) { IEnumerable <DateTime> monthDates; var endDate = start + howFarAhead; bool IsValid(DateTime dt) => dt >= start && dt <= endDate; if (MonthsOfYear.Any()) { var months = new List <DateTime>(); for (var monthDate = start; monthDate < endDate;) { months.Add(monthDate); monthDate = monthDate.AddMonths(1); monthDate = new DateTime(monthDate.Year, monthDate.Month, 1); } monthDates = months.ToArray(); } else { monthDates = new[] { start }; } IEnumerable <DateTime> dayDates; if (!DaysOfMonth.Any() && !WeekDays.Any()) { dayDates = new[] { start }; } else { dayDates = monthDates.SelectMany(m => DaysOfMonth.Select(d => new DateTime(m.Year, m.Month, d, 0, 0, 0))).Where(IsValid); var dayDates2 = monthDates.SelectMany(m => WeekDays.SelectMany(wd => DayOfWeekDatesForMonth(wd, m.Year, m.Month))).Where(IsValid); if (dayDates.Any() && dayDates2.Any()) { dayDates = dayDates.Intersect(dayDates2); } else { dayDates = dayDates.Concat(dayDates2); } } if (Times.Any()) { dayDates = dayDates.SelectMany(d => Times.Select(t => new DateTime(d.Year, d.Month, d.Day, t.Hour, t.Minute ?? 0, 0))).Where(IsValid); } if (Every.HasValue) { dayDates = dayDates.SelectMany(d => PartsInValidTime(d, Every.Value)).Where(IsValid); } return(dayDates); }
internal static List <bool> GetFlagsFromEnum(MonthsOfYear value) { List <bool> checkboxes = new List <bool>(); var month = 0; for (int i = 0; i < 12; i++) { month = (i == 0) ? 1 : month * 2; checkboxes.Add((value & (MonthsOfYear)Enum.Parse(typeof(MonthsOfYear), month.ToString())) != 0); } return(checkboxes); }
public static List <MonthsOfYear> GetValues(this MonthsOfYear Flags) { var ret = new List <MonthsOfYear>(Order.Length); foreach (var item in Order) { if (Flags.HasFlag(item)) { ret.Add(item); } } return(ret); }
internal static MonthsOfYear CalculateEnum(List <bool> checkboxes) { MonthsOfYear value = 0; var month = 0; for (int i = 0; i < 12; i++) { month = (i == 0) ? 1 : month * 2; if (checkboxes[i]) { value |= (MonthsOfYear)Enum.Parse(typeof(MonthsOfYear), month.ToString()); } } return(value); }
public async Task OnGetAsync() { IQueryable <Person> personIQ = _context.People .Include(p => p.ApplicationUser) .Include(p => p.PersonFiles); personIQ = PersonFilter.Process(personIQ); personIQ = PersonSort.Process(personIQ); personIQ = PersonPaginate.Process(personIQ); Person = await personIQ.AsNoTracking().ToListAsync(); ViewData["MonthsOfYear"] = new SelectList(MonthsOfYear.GetDictionary(), "Key", "Value"); ViewData["PageSize"] = new SelectList(PersonPaginate.PageSizeDictionary, "Key", "Value", PersonPaginate.PageSize); }
static void Main(string[] args) { while (true) { Console.Write("Введите номер месяца: "); int monthNum = Convert.ToInt32(Console.ReadLine()); if (monthNum > 0 && monthNum < 13) { MonthsOfYear value = (MonthsOfYear)monthNum; Console.WriteLine($"Введенный месяц - это {value}"); return; } else { Console.WriteLine("Ошибка: введите число от 1 до 12"); } } }
static void Main(string[] args) { Console.WriteLine("Please enter a number 1 - 12"); var userInput = Console.ReadLine(); var inputAsNumber = Convert.ToInt32(userInput); if (inputAsNumber < 0 || inputAsNumber > 12) { Console.WriteLine("Invalid entry. Please enter a number 1 - 12"); userInput = Console.ReadLine(); } MonthsOfYear inputAsEnum = (MonthsOfYear)inputAsNumber; Console.WriteLine(inputAsEnum); }
public static int GetMonth(this MonthsOfYear Month) { var ret = 0; var FlagValues = GetValues(Month); if (FlagValues.Count > 0) { for (int i = 0; i < Order.Length; ++i) { if (Order[i] == FlagValues[0]) { ret = i + 1; break; } } } return(ret); }
public bool IsTime(DateTime currentTime) { if (MonthsOfYear.Any() && !MonthsOfYear.Any(x => (int)x == currentTime.Month)) { return(false); } if (DaysOfMonth.Any() && !DaysOfMonth.Any(x => x == currentTime.Day)) { return(false); } if (WeekDays.Any() && !WeekDays.Any(x => x == currentTime.DayOfWeek)) { return(false); } if (Times.Any() && !Times.Any(x => x.IsTime(currentTime))) { return(false); } return(true); }
static void Main(string[] args) { // Gets month as a number from user Console.WriteLine("Please provide a number between 1 and 12 to represent a month."); string monthAsString = Console.ReadLine(); // Converts to int and checks if the value is in the range 1-12 int monthAsInt = Convert.ToInt32(monthAsString); if (monthAsInt > 0 && monthAsInt < 13) { // Explicit cast is required MonthsOfYear userMonth = (MonthsOfYear)monthAsInt; // The book states to use a switch or if statement to print the month's name. // I chose to not use either, as I can seemingly get the desired effect without either. Console.WriteLine($"\nYou entered the number {monthAsString}, which equals {userMonth}."); } else { Console.WriteLine($"\nSorry, that entry is not valid. Please rerun this program to try again."); } }
public MonthsOfTheYearCondition() { this.MonthsOfTheYear = MonthsOfYear.None; }
public void Add(MonthsOfYear MonthsOfTheYear) { this.MonthsOfTheYear |= MonthsOfTheYear; }
public void Remove(MonthsOfYear MonthsOfTheYear) { this.MonthsOfTheYear &= ~MonthsOfTheYear; }
public static T On <T>(this T Composite, MonthsOfYear MonthsOfTheYear) where T : IContainsConditions { Composite.Conditions <MonthsOfTheYearCondition>().Add(MonthsOfTheYear); return(Composite); }
public async Task <int> AddAsync(int makeId, int modelId, int driveId, int bodyId, MonthsOfYear month, int year, ColorType color, ICollection <int> inputFeatures, IEnumerable <string> inputImages, int mileage, decimal price, string inputMainImage, string description, string userId) { var car = new Car { UserId = userId, MakeId = makeId, ModelId = modelId, DriveId = driveId, BodyId = bodyId, FirstRegistration = new DateTime(year, (int)month, 1), Color = color, Price = price, Mileage = mileage, MainImage = inputMainImage, Description = description, }; foreach (var imageUrl in inputImages) { var image = new Image { Url = imageUrl, Car = car, }; car.Images.Add(image); } foreach (var featureId in inputFeatures) { var feature = this.featureRepository.All().FirstOrDefault(x => x.Id == featureId); if (feature == null) { continue; } car.CarsFeatures.Add(new CarFeature { Car = car, Feature = feature, }); } await this.carRepository.AddAsync(car); await this.carRepository.SaveChangesAsync(); return(car.Id); }
public override void Validate() { base.Validate(); if (DurationCountInYears <= 0 || DurationCountInYears > PolicyConstants.MaxAllowedRetentionDurationCount) { throw new ArgumentException(Resources.RetentionDurationCountInvalidException); } if (MonthsOfYear == null || MonthsOfYear.Count == 0 || MonthsOfYear.Count != MonthsOfYear.Distinct().Count()) { throw new ArgumentException(Resources.YearlyScheduleMonthsOfYearException); } if (RetentionScheduleFormatType == RetentionScheduleFormat.Daily) { if (RetentionScheduleDaily == null) { throw new ArgumentException(Resources.MonthlyYearlyRetentionDailySchedulePolicyNULLException); } RetentionScheduleDaily.Validate(); } if (RetentionScheduleFormatType == RetentionScheduleFormat.Weekly) { if (RetentionScheduleWeekly == null) { throw new ArgumentException(Resources.MonthlyYearlyRetentionWeeklySchedulePolicyNULLException); } RetentionScheduleWeekly.Validate(); } }
public async Task <int> EditAsync(int carId, int makeId, int modelId, int driveId, int bodyId, MonthsOfYear month, int year, ColorType color, ICollection <int> inputFeatures, int mileage, decimal price, string description) { var car = this.carRepository.All().FirstOrDefault(m => m.Id == carId); car.MakeId = makeId; car.ModelId = modelId; car.DriveId = driveId; car.BodyId = bodyId; car.FirstRegistration = new DateTime(year, (int)month, 1); car.Color = color; car.Mileage = mileage; car.Price = price; car.Description = description; var currentFeatures = this.carFeatureRepository.All().Where(x => x.CarId == carId); foreach (var item in currentFeatures) { this.carFeatureRepository.HardDelete(item); } await this.carFeatureRepository.SaveChangesAsync(); foreach (var featureId in inputFeatures) { var feature = this.featureRepository.All().FirstOrDefault(x => x.Id == featureId); if (feature == null) { continue; } car.CarsFeatures.Add(new CarFeature { Car = car, Feature = feature, }); } this.carRepository.Update(car); await this.carRepository.SaveChangesAsync(); return(car.Id); }
public override void Validate() { base.Validate(); int MinDurationCountInYears = 1, MaxDurationCountInYears = PolicyConstants.MaxAllowedRetentionDurationCountYearly; if (BackupManagementType == Management.RecoveryServices.Backup.Models.BackupManagementType.AzureStorage) { MinDurationCountInYears = PolicyConstants.AfsYearlyRetentionMin; MaxDurationCountInYears = PolicyConstants.AfsYearlyRetentionMax; } if (DurationCountInYears < MinDurationCountInYears || DurationCountInYears > MaxDurationCountInYears) { throw new ArgumentException(Resources.RetentionDurationCountInvalidException); } if (MonthsOfYear == null || MonthsOfYear.Count == 0 || MonthsOfYear.Count != MonthsOfYear.Distinct().Count()) { throw new ArgumentException(Resources.YearlyScheduleMonthsOfYearException); } if (RetentionScheduleFormatType == RetentionScheduleFormat.Daily) { if (RetentionScheduleDaily == null) { throw new ArgumentException(Resources.MonthlyYearlyRetentionDailySchedulePolicyNULLException); } RetentionScheduleDaily.Validate(); } if (RetentionScheduleFormatType == RetentionScheduleFormat.Weekly) { if (RetentionScheduleWeekly == null) { throw new ArgumentException(Resources.MonthlyYearlyRetentionWeeklySchedulePolicyNULLException); } RetentionScheduleWeekly.Validate(); } }
public static bool Matches(this MonthsOfYear Flags, DateTime DateTime) { return((Flags & GetMonth(DateTime.Month)) != MonthsOfYear.None); }
private string getMonthsOfYearDescription() { string monthsDesc = string.Empty; MonthsOfYear months = (MonthsOfYear)MonthsOfYearBitmask; if (months.HasFlag(MonthsOfYear.January) && months.HasFlag(MonthsOfYear.February) && months.HasFlag(MonthsOfYear.March) && months.HasFlag(MonthsOfYear.April) && months.HasFlag(MonthsOfYear.May) && months.HasFlag(MonthsOfYear.June) && months.HasFlag(MonthsOfYear.July) && months.HasFlag(MonthsOfYear.August) && months.HasFlag(MonthsOfYear.September) && months.HasFlag(MonthsOfYear.October) && months.HasFlag(MonthsOfYear.November) && months.HasFlag(MonthsOfYear.December)) { monthsDesc = "every month"; return(monthsDesc); } else { if (months.HasFlag(MonthsOfYear.January)) { monthsDesc += " Jan,"; } if (months.HasFlag(MonthsOfYear.February)) { monthsDesc += " Feb,"; } if (months.HasFlag(MonthsOfYear.March)) { monthsDesc += " Mar,"; } if (months.HasFlag(MonthsOfYear.April)) { monthsDesc += " Apr,"; } if (months.HasFlag(MonthsOfYear.May)) { monthsDesc += " May,"; } if (months.HasFlag(MonthsOfYear.June)) { monthsDesc += " Jun,"; } if (months.HasFlag(MonthsOfYear.July)) { monthsDesc += " Jul,"; } if (months.HasFlag(MonthsOfYear.August)) { monthsDesc += " Aug,"; } if (months.HasFlag(MonthsOfYear.September)) { monthsDesc += " Sep,"; } if (months.HasFlag(MonthsOfYear.October)) { monthsDesc += " Oct,"; } if (months.HasFlag(MonthsOfYear.November)) { monthsDesc += " Nov,"; } if (months.HasFlag(MonthsOfYear.December)) { monthsDesc += " Dec,"; } } // remove leading space and trailing comma return(monthsDesc.Trim().Substring(0, monthsDesc.Length - 2)); }
public MonthsOfTheYearCondition(MonthsOfYear MonthsOfTheYear) { this.MonthsOfTheYear = MonthsOfTheYear; }
public Catalog_Reports_Subscription() { DaysOfWeek = new DaysOfWeek(); MonthsOfYear = new MonthsOfYear(); }