PIBD-22. Denisov V.D. LabWork_3 #4

Closed
kisame wants to merge 3 commits from LabWork_3 into LabWork_2
2 changed files with 28 additions and 34 deletions
Showing only changes of commit 5def95e150 - Show all commits

View File

@ -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<TableReport>().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<TableReport>().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()

View File

@ -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<string[]> GetData(int doctorId, DateTime startDate, DateTime endDate)
private List<string[]> 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<string[]> GetDrugData(int doctorId, DateTime startDate, DateTime endDate)
private List<string[]> 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<string[]>
{
{
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;
}
}