public static void AddWorkTime(Person person) { //TODO:Добавить проверку ввода данных Console.WriteLine("Введите дату в формате дд.мм.гггг"); var userTime = Convert.ToDateTime(Console.ReadLine()); var twoDays = new TimeSpan(7, 0, 0, 0); var twoDaysAgo = Convert.ToDateTime(DateTime.Now - twoDays); if (userTime < twoDaysAgo) { Console.WriteLine("Введите количетсво отработанных часов: "); var workHours = int.Parse(Console.ReadLine()); Console.WriteLine("Добавьте коментарий о проделаной работе"); var coments = Console.ReadLine(); var workDay = new HoursWorked { person = person, workDay = userTime, workHours = workHours, coments = coments }; using (var file = new StreamWriter(FilePath.LIST_EMPLOYEES_REPORT, true, Encoding.UTF8)) { file.WriteLine(JsonSerializer.Serialize(workDay)); } } Console.WriteLine("Вы ввели неправильную дату"); }
public static void AddWorkTime(Person person) { try { Console.WriteLine("Введите дату в формате дд.мм.гггг"); var userTime = Convert.ToDateTime(Console.ReadLine()); var month = new TimeSpan(DateTime.Now.Day, 0, 0, 0); var monthAgo = Convert.ToDateTime(DateTime.Now - month); if (userTime > monthAgo) { Console.WriteLine("Введите количетсво отработанных часов: "); var workHours = int.Parse(Console.ReadLine()); Console.WriteLine("Добавьте коментарий о проделаной работе"); var coments = Console.ReadLine(); var workDay = new HoursWorked { person = person, workDay = userTime, workHours = workHours, coments = coments }; using (var file = new StreamWriter(FilePath.LIST_EMPLOYEES_REPORT, true, Encoding.UTF8)) { file.WriteLine(JsonSerializer.Serialize(workDay)); } } else { Console.WriteLine("Дата должна быть текущего месяца"); } } catch (FormatException) { Console.WriteLine("Неверный формат времени"); } }
public static void GetWorkInfo() { var listHoursWorked = LoadFromJson <HoursWorked> .GetListJson(FilePath.LIST_EMPLOYEES_REPORT); HoursWorked checkEmpety = default; foreach (var item in listHoursWorked) { Console.WriteLine(item); } if (checkEmpety == default) { Console.WriteLine("Нет данных"); Console.WriteLine(); } }
public static void GetWorkInfo(DateTime EndDate) { var listHoursWorked = LoadFromJson <HoursWorked> .GetListJson(FilePath.LIST_EMPLOYEES_REPORT); HoursWorked checkEmpety = default; foreach (var item in listHoursWorked) { if (EndDate.CompareTo(item.workDay) == -1 || EndDate.CompareTo(item.workDay) == 0) { Console.WriteLine(item); } } if (checkEmpety == default) { Console.WriteLine("Нет данных"); Console.WriteLine(); } }
public static void GetWorkInfo(DateTime StartDate, DateTime EndDate, Person person) { var listHoursWorked = LoadFromJson <HoursWorked> .GetListJson(FilePath.LIST_EMPLOYEES_REPORT); HoursWorked checkEmpety = default; foreach (var item in listHoursWorked) { if (StartDate <= item.workDay && EndDate >= item.workDay && person == item.person) { Console.WriteLine(item); } } if (checkEmpety == default) { Console.WriteLine("Нет данных"); Console.WriteLine(); } }