From 5def95e1506d034203fe79e60bc5bcabe75121f2 Mon Sep 17 00:00:00 2001 From: kisame Date: Mon, 16 Dec 2024 02:14:35 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B2=D1=81=D1=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProjectPolyclinic/Forms/FormPayReport.cs | 16 +++++-- .../ProjectPolyclinic/Reports/TableReport.cs | 46 +++++++------------ 2 files changed, 28 insertions(+), 34 deletions(-) diff --git a/ProjectPolyclinic/ProjectPolyclinic/Forms/FormPayReport.cs b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormPayReport.cs index 63527aa..828a9dc 100644 --- a/ProjectPolyclinic/ProjectPolyclinic/Forms/FormPayReport.cs +++ b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormPayReport.cs @@ -28,7 +28,6 @@ namespace ProjectPolyclinic.Forms comboBoxDoctor.DisplayMember = "Last_Name"; comboBoxDoctor.ValueMember = "Id"; } - private void buttonBuild_Click(object sender, EventArgs e) { try @@ -40,7 +39,7 @@ namespace ProjectPolyclinic.Forms if (comboBoxDoctor.SelectedIndex < 0) { - throw new Exception("Не выбран спортсмен"); + throw new Exception("Не выбран врач"); } if (dateTimePickerDateEnd.Value <= dateTimePickerDateBegin.Value) @@ -48,7 +47,15 @@ namespace ProjectPolyclinic.Forms throw new Exception("Дата начала должна быть раньше даты окончания"); } - if (_container.Resolve().CreateTable(textBoxFilePath.Text, (int)comboBoxDoctor.SelectedValue!, dateTimePickerDateBegin.Value, dateTimePickerDateEnd.Value)) + // Приведение дат к началу и концу месяца + var startDate = new DateTime(dateTimePickerDateBegin.Value.Year, dateTimePickerDateBegin.Value.Month, 1); + var endDate = new DateTime(dateTimePickerDateEnd.Value.Year, dateTimePickerDateEnd.Value.Month, 1).AddMonths(1).AddDays(-1); + + if (_container.Resolve().CreateTable( + textBoxFilePath.Text, + (int)comboBoxDoctor.SelectedValue!, + startDate, + endDate)) { MessageBox.Show("Документ сформирован", "Формирование документа", MessageBoxButtons.OK, MessageBoxIcon.Information); @@ -61,11 +68,12 @@ namespace ProjectPolyclinic.Forms } catch (Exception ex) { - MessageBox.Show(ex.Message, "Ошибка при создании очета", + MessageBox.Show(ex.Message, "Ошибка при создании отчета", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + private void buttonSelectFilePath_Click(object sender, EventArgs e) { var sfd = new SaveFileDialog() diff --git a/ProjectPolyclinic/ProjectPolyclinic/Reports/TableReport.cs b/ProjectPolyclinic/ProjectPolyclinic/Reports/TableReport.cs index fde970f..f19ef1b 100644 --- a/ProjectPolyclinic/ProjectPolyclinic/Reports/TableReport.cs +++ b/ProjectPolyclinic/ProjectPolyclinic/Reports/TableReport.cs @@ -29,21 +29,27 @@ public class TableReport throw new ArgumentNullException(nameof(logger)); } + + public bool CreateTable(string filePath, int doctorId, DateTime startDate, DateTime endDate) { try { + // Приведение дат к началу и концу месяцев + var startOfMonth = new DateTime(startDate.Year, startDate.Month, 1); + var endOfMonth = new DateTime(endDate.Year, endDate.Month, 1).AddMonths(1).AddDays(-1); + var excelBuilder = new ExcelBuilder(filePath) .AddHeader("Сводка по оплате", 0, 3) - .AddParagraph($"За период с {startDate:MM.yyyy} по {endDate:MM.yyyy}", 0) + .AddParagraph($"За период с {startOfMonth:MM.yyyy} по {endOfMonth:MM.yyyy}", 0) .AddParagraph($"Id врача: {doctorId}", 0) - .AddTable(new[] { 25, 25, 25 }, GetData(doctorId, startDate, endDate)); + .AddTable(new[] { 25, 25, 25 }, GetData(doctorId, startOfMonth, endOfMonth)); excelBuilder.AddParagraph("", 0); excelBuilder .AddHeader("Назначенные лекарства", 0, 2) - .AddTable(new[] { 25, 25 }, GetDrugData(doctorId, startDate, endDate)); + .AddTable(new[] { 25, 25 }, GetDrugData(doctorId, startOfMonth, endOfMonth)); excelBuilder.Build(); return true; @@ -56,21 +62,13 @@ public class TableReport } - - - - private List GetData(int doctorId, DateTime startDate, DateTime endDate) + private List GetData(int doctorId, DateTime startOfMonth, DateTime endOfMonth) { - //перевод даты к началу и концу месяца - var startOfMonth = new DateTime(startDate.Year, startDate.Month, 1); - var endOfMonth = new DateTime(endDate.Year, endDate.Month, 1).AddMonths(1).AddDays(-1); - var data = _doctorPayRepository .ReadDoctorPayments() .Where(x => { var paymentMonth = DateTime.ParseExact(x.Month, "yyyy-MM", System.Globalization.CultureInfo.InvariantCulture); - return paymentMonth >= startOfMonth && paymentMonth <= endOfMonth && x.IdDoctor == doctorId; }) .Select(x => new @@ -105,24 +103,17 @@ public class TableReport return result; } - - - private List GetDrugData(int doctorId, DateTime startDate, DateTime endDate) + private List GetDrugData(int doctorId, DateTime startOfMonth, DateTime endOfMonth) { - - var startOfMonth = new DateTime(startDate.Year, startDate.Month, 1); - - var endOfMonth = new DateTime(endDate.Year, endDate.Month, 1).AddMonths(1).AddDays(-1); - var medicalHistories = _medicalHistoryRepository .ReadMedicalHistory(startOfMonth, endOfMonth, null, doctorId) - .Where(mh => mh.DoctorId == doctorId && mh.VisitDate >= startDate && mh.VisitDate <= endDate) + .Where(mh => mh.DoctorId == doctorId && mh.VisitDate >= startOfMonth && mh.VisitDate <= endOfMonth) .ToList(); var result = new List - { + { new[] { "Дата", "Назначенные лекарства" } - }; + }; var sortedDrugData = medicalHistories .Where(mh => mh.DrugMedHistory != null && mh.DrugMedHistory.Any()) @@ -139,17 +130,12 @@ public class TableReport { item.Date.ToString("dd.MM.yyyy"), item.Count.ToString() - }) - ); + })); + var totalDrugs = sortedDrugData.Sum(x => x.Count); result.Add(new[] { "Всего", totalDrugs.ToString() }); return result; } - - - - - } \ No newline at end of file