From fd1f8e103bd40445122693c23e92ac905aa531b0 Mon Sep 17 00:00:00 2001 From: m1aksim1 Date: Tue, 14 Mar 2023 21:44:42 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BA=D0=BE=D0=BD=D1=82=D1=80=D0=BE=D0=BB=D0=B5=D1=80?= =?UTF-8?q?=20=D0=B4=D0=BB=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B=20?= =?UTF-8?q?=D1=81=20=D0=B1=D0=B0=D0=B7=D0=BE=D0=B9=20=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=BD=D1=8B=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WorkTime/WorkTime/Controller.cs | 57 +++++++++++++++++++++++++++++++ WorkTime/WorkTime/HelloText.txt | 9 +++++ WorkTime/WorkTime/Program.cs | 55 +++++++++++++++++++++++++---- WorkTime/WorkTime/WorkTime.csproj | 1 + 4 files changed, 116 insertions(+), 6 deletions(-) create mode 100644 WorkTime/WorkTime/Controller.cs create mode 100644 WorkTime/WorkTime/HelloText.txt diff --git a/WorkTime/WorkTime/Controller.cs b/WorkTime/WorkTime/Controller.cs new file mode 100644 index 0000000..ac6bdb7 --- /dev/null +++ b/WorkTime/WorkTime/Controller.cs @@ -0,0 +1,57 @@ +using Microsoft.EntityFrameworkCore; +using WorkTime.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ConsoleTableExt; + +namespace WorkTime +{ + internal class Controller + { + private readonly CourseContext _context; + + public Controller(CourseContext scheduleContext) + { + _context = scheduleContext; + } + + public void GetWorkers() + { + ConsoleTableBuilder.From(_context.Workers.Select(x => new { x.Id, x.Name,x.DateEmployment}).ToList()) + .WithTitle("Workers") + .ExportAndWriteLine(); + } + public void GetProject() + { + ConsoleTableBuilder.From(_context.Projects.Select(x => new { x.Id, x.Name, x.Ready }).ToList()) + .WithTitle("Workers") + .ExportAndWriteLine(); + } + public void GetSalary() + { + ConsoleTableBuilder.From(_context.SalaryWithAllowances.Select(x => new { x.Id, x.Name, x.Должность, x.CalcSalary }).ToList()) + .WithTitle("Workers") + .ExportAndWriteLine(); + } + public void GetSalaryOnCurrentMonth() + { + ConsoleTableBuilder.From(_context.GetSalaryOnCurrentMonths.Select(x => new { x.WorkerId, x.Name, x.Salary, x.Hours}).ToList()) + .WithTitle("Workers") + .ExportAndWriteLine(); + } + public void GetPosts() + { + ConsoleTableBuilder.From(_context.Posts.Select(x => new { x.Id,x.Name, x.Salary }).ToList()) + .WithTitle("Workers") + .ExportAndWriteLine(); + } + public void AddWorker(Worker worker) + { + _context.Workers.Add(worker); + _context.SaveChanges(); + } + } +} \ No newline at end of file diff --git a/WorkTime/WorkTime/HelloText.txt b/WorkTime/WorkTime/HelloText.txt new file mode 100644 index 0000000..b4f20fa --- /dev/null +++ b/WorkTime/WorkTime/HelloText.txt @@ -0,0 +1,9 @@ +Запущена программа. +Нажмите 0 для выхода. +1 для получения списка всех сотрудников +2 для получения списка всех проектов +3 для получения зароботной платы сотрудника с надбавками" +4 для получения зароботной платы сотрудника за тякущий месяц" +5 для получения всех должностей +6 Добавить сотрудника +7 запустить тестирование всех функций \ No newline at end of file diff --git a/WorkTime/WorkTime/Program.cs b/WorkTime/WorkTime/Program.cs index f6e3454..52e7e95 100644 --- a/WorkTime/WorkTime/Program.cs +++ b/WorkTime/WorkTime/Program.cs @@ -1,16 +1,59 @@ -namespace WorkTime +using WorkTime; +using WorkTime.Models; +using System.Diagnostics; + +namespace WorkTime { class Program { public static void Main(string[] args) { - using (var context = new CourseContext()) + string text; + using (var sr = new StreamReader("HelloText.txt")) { - foreach (var salary in context.SalaryWithAllowances) - { - Console.WriteLine($"{salary.Name} {salary.CalcSalary}"); - } + text = sr.ReadToEnd(); } + + using var context = new CourseContext(); + Controller controller = new(context); + string operation = ""; + do + { + Console.WriteLine(text); + operation = Console.ReadLine() ?? ""; + switch (operation) + { + case "1": + controller.GetWorkers(); + break; + case "2": + controller.GetProject(); + break; + case "3": + controller.GetSalary(); + break; + case "4": + controller.GetSalaryOnCurrentMonth(); + break; + case "5": + controller.GetPosts(); + break; + case "6": + Worker worker = new() + { + Name = Console.ReadLine(), + PostId = int.Parse(Console.ReadLine()), + }; + controller.AddWorker(worker); + break; + case "7": + + break; + default: + Console.WriteLine("Некорректно введенный номер операции"); + break; + } + } while (operation != "0"); } } } \ No newline at end of file diff --git a/WorkTime/WorkTime/WorkTime.csproj b/WorkTime/WorkTime/WorkTime.csproj index e5eaa66..27a0ea8 100644 --- a/WorkTime/WorkTime/WorkTime.csproj +++ b/WorkTime/WorkTime/WorkTime.csproj @@ -8,6 +8,7 @@ + all runtime; build; native; contentfiles; analyzers; buildtransitive