diff --git a/RegistrationOfPatients/RegistrationOfPatients/Entities/Medicine.cs b/RegistrationOfPatients/RegistrationOfPatients/Entities/Medicine.cs index 93e645d..5e620f6 100644 --- a/RegistrationOfPatients/RegistrationOfPatients/Entities/Medicine.cs +++ b/RegistrationOfPatients/RegistrationOfPatients/Entities/Medicine.cs @@ -6,19 +6,22 @@ namespace RegistrationOfPatients.Entities; public class Medicine { - public int Id { get; set; } public MedicineType MedicineType { get; private set; } public string Name { get; private set; } = string.Empty; public string Description { get; private set; } = string.Empty; - public static Medicine CreateEntity(int id, MedicineType medicineType, string name, string description) + public int Count { get; private set; } + public DateTime Date { get; private set; } + public static Medicine CreateEntity(int id, MedicineType medicineType, string name, string description, int count, DateTime date) { return new Medicine { Id = id, MedicineType = medicineType, Name = name, - Description = description ?? string.Empty + Description = description ?? string.Empty, + Count = count, + Date = date }; } } diff --git a/RegistrationOfPatients/RegistrationOfPatients/Entities/Payment.cs b/RegistrationOfPatients/RegistrationOfPatients/Entities/Payment.cs index f9182ec..403dccd 100644 --- a/RegistrationOfPatients/RegistrationOfPatients/Entities/Payment.cs +++ b/RegistrationOfPatients/RegistrationOfPatients/Entities/Payment.cs @@ -15,7 +15,7 @@ public class Payment Id = id, Salary = salary, TotalPatients = totalPatients, - Date = DateTime.Now, + Date = date, PercentageOfRecoveries = percentageOfRecoveries, DoctorId = doctorId }; diff --git a/RegistrationOfPatients/RegistrationOfPatients/Entities/Reception.cs b/RegistrationOfPatients/RegistrationOfPatients/Entities/Reception.cs index 05dcc6b..6119f47 100644 --- a/RegistrationOfPatients/RegistrationOfPatients/Entities/Reception.cs +++ b/RegistrationOfPatients/RegistrationOfPatients/Entities/Reception.cs @@ -16,7 +16,7 @@ public class Reception return new Reception { Id = id, - Date = DateTime.Now, + Date = date, HealthStatus = healthStatus, Illness = illness ?? string.Empty, PatientId = patientId, @@ -30,7 +30,10 @@ public class Reception return new Reception { Id = tempReceptionMedicine.Id, - Date = tempReceptionMedicine.Date, + Date = tempReceptionMedicine.Date, + HealthStatus = tempReceptionMedicine.HealthStatus, + Illness = tempReceptionMedicine.Illness ?? string.Empty, + PatientId = tempReceptionMedicine.PatientId, DoctorId = tempReceptionMedicine.DoctorId, ReceptionMedicine = receptionMedicine }; diff --git a/RegistrationOfPatients/RegistrationOfPatients/Entities/ReceptionMedicine.cs b/RegistrationOfPatients/RegistrationOfPatients/Entities/ReceptionMedicine.cs index b07b585..abc6bdd 100644 --- a/RegistrationOfPatients/RegistrationOfPatients/Entities/ReceptionMedicine.cs +++ b/RegistrationOfPatients/RegistrationOfPatients/Entities/ReceptionMedicine.cs @@ -2,16 +2,16 @@ public class ReceptionMedicine { - public int Id { get; set; } + public int ReceptionId { get; set; } public int MedicineId { get; private set; } - public int Count { get; private set; } - public static ReceptionMedicine CreateElement(int id, int medicineId, int count) + public int Count { get; private set; } + public static ReceptionMedicine CreateElement(int receptionId, int medicineId, int count) { return new ReceptionMedicine { - Id = id, + ReceptionId = receptionId, MedicineId = medicineId, - Count = count, + Count = count }; } -} +} \ No newline at end of file diff --git a/RegistrationOfPatients/RegistrationOfPatients/Entities/TempReceptionMedicine.cs b/RegistrationOfPatients/RegistrationOfPatients/Entities/TempReceptionMedicine.cs index 4ee005c..a59d282 100644 --- a/RegistrationOfPatients/RegistrationOfPatients/Entities/TempReceptionMedicine.cs +++ b/RegistrationOfPatients/RegistrationOfPatients/Entities/TempReceptionMedicine.cs @@ -1,4 +1,5 @@ -using System; +using RegistrationOfPatients.Entities.Enums; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -10,9 +11,13 @@ public class TempReceptionMedicine { public int Id { get; private set; } - public int DoctorId { get; private set; } + //public int ReceptionId { get; private set; } + public HealthStatus HealthStatus { get; private set; } public DateTime Date { get; private set; } + public string Illness { get; private set; } = string.Empty; + public int PatientId { get; private set; } + public int DoctorId { get; private set; } public int MedicineId { get; private set; } diff --git a/RegistrationOfPatients/RegistrationOfPatients/FormRegistration.Designer.cs b/RegistrationOfPatients/RegistrationOfPatients/FormRegistration.Designer.cs index fe40dda..9e373e7 100644 --- a/RegistrationOfPatients/RegistrationOfPatients/FormRegistration.Designer.cs +++ b/RegistrationOfPatients/RegistrationOfPatients/FormRegistration.Designer.cs @@ -39,6 +39,7 @@ отчетыToolStripMenuItem = new ToolStripMenuItem(); DirectoryReportToolStripMenuItem = new ToolStripMenuItem(); MedicineReportToolStripMenuItem = new ToolStripMenuItem(); + MedicineDistributionToolStripMenuItem = new ToolStripMenuItem(); menuStrip.SuspendLayout(); SuspendLayout(); // @@ -103,7 +104,7 @@ // // отчетыToolStripMenuItem // - отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { DirectoryReportToolStripMenuItem, MedicineReportToolStripMenuItem }); + отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { DirectoryReportToolStripMenuItem, MedicineReportToolStripMenuItem, MedicineDistributionToolStripMenuItem }); отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; отчетыToolStripMenuItem.Size = new Size(73, 24); отчетыToolStripMenuItem.Text = "Отчеты"; @@ -124,6 +125,14 @@ MedicineReportToolStripMenuItem.Text = "Движение лекарств"; MedicineReportToolStripMenuItem.Click += MedicineReportToolStripMenuItem_Click; // + // MedicineDistributionToolStripMenuItem + // + MedicineDistributionToolStripMenuItem.Name = "MedicineDistributionToolStripMenuItem"; + MedicineDistributionToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.P; + MedicineDistributionToolStripMenuItem.Size = new Size(350, 26); + MedicineDistributionToolStripMenuItem.Text = "Распределние лекарств"; + MedicineDistributionToolStripMenuItem.Click += MedicineDistributionToolStripMenuItem_Click; + // // FormRegistration // AutoScaleDimensions = new SizeF(8F, 20F); @@ -155,5 +164,6 @@ private ToolStripMenuItem MedicinesToolStripMenuItem; private ToolStripMenuItem DirectoryReportToolStripMenuItem; private ToolStripMenuItem MedicineReportToolStripMenuItem; + private ToolStripMenuItem MedicineDistributionToolStripMenuItem; } } \ No newline at end of file diff --git a/RegistrationOfPatients/RegistrationOfPatients/FormRegistration.cs b/RegistrationOfPatients/RegistrationOfPatients/FormRegistration.cs index fcbac4e..4660009 100644 --- a/RegistrationOfPatients/RegistrationOfPatients/FormRegistration.cs +++ b/RegistrationOfPatients/RegistrationOfPatients/FormRegistration.cs @@ -95,4 +95,16 @@ public partial class FormRegistration : Form MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + + private void MedicineDistributionToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } } \ No newline at end of file diff --git a/RegistrationOfPatients/RegistrationOfPatients/Forms/FormMedicine.Designer.cs b/RegistrationOfPatients/RegistrationOfPatients/Forms/FormMedicine.Designer.cs index f509064..f02fe85 100644 --- a/RegistrationOfPatients/RegistrationOfPatients/Forms/FormMedicine.Designer.cs +++ b/RegistrationOfPatients/RegistrationOfPatients/Forms/FormMedicine.Designer.cs @@ -36,6 +36,11 @@ ButtonCancel = new Button(); textBoxName = new TextBox(); label3 = new Label(); + label4 = new Label(); + numericUpDownCount = new NumericUpDown(); + dateTimePickerMedicine = new DateTimePicker(); + label5 = new Label(); + ((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit(); SuspendLayout(); // // label1 @@ -58,7 +63,7 @@ // label2 // label2.AutoSize = true; - label2.Location = new Point(65, 217); + label2.Location = new Point(65, 304); label2.Name = "label2"; label2.Size = new Size(82, 20); label2.TabIndex = 2; @@ -66,7 +71,7 @@ // // textBoxDescription // - textBoxDescription.Location = new Point(195, 217); + textBoxDescription.Location = new Point(195, 304); textBoxDescription.Multiline = true; textBoxDescription.Name = "textBoxDescription"; textBoxDescription.Size = new Size(247, 72); @@ -74,7 +79,7 @@ // // ButtonSave // - ButtonSave.Location = new Point(65, 314); + ButtonSave.Location = new Point(65, 401); ButtonSave.Name = "ButtonSave"; ButtonSave.Size = new Size(94, 29); ButtonSave.TabIndex = 4; @@ -84,7 +89,7 @@ // // ButtonCancel // - ButtonCancel.Location = new Point(195, 314); + ButtonCancel.Location = new Point(195, 401); ButtonCancel.Name = "ButtonCancel"; ButtonCancel.Size = new Size(94, 29); ButtonCancel.TabIndex = 5; @@ -109,11 +114,47 @@ label3.TabIndex = 6; label3.Text = "Название:"; // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(65, 214); + label4.Name = "label4"; + label4.Size = new Size(93, 20); + label4.TabIndex = 8; + label4.Text = "Количество:"; + // + // numericUpDownCount + // + numericUpDownCount.Location = new Point(195, 214); + numericUpDownCount.Name = "numericUpDownCount"; + numericUpDownCount.Size = new Size(247, 27); + numericUpDownCount.TabIndex = 10; + // + // dateTimePickerMedicine + // + dateTimePickerMedicine.Location = new Point(195, 253); + dateTimePickerMedicine.Name = "dateTimePickerMedicine"; + dateTimePickerMedicine.Size = new Size(178, 27); + dateTimePickerMedicine.TabIndex = 14; + // + // label5 + // + label5.AutoSize = true; + label5.Location = new Point(65, 253); + label5.Name = "label5"; + label5.Size = new Size(44, 20); + label5.TabIndex = 13; + label5.Text = "Дата:"; + // // FormMedicine // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(593, 421); + ClientSize = new Size(593, 499); + Controls.Add(dateTimePickerMedicine); + Controls.Add(label5); + Controls.Add(numericUpDownCount); + Controls.Add(label4); Controls.Add(textBoxName); Controls.Add(label3); Controls.Add(ButtonCancel); @@ -125,6 +166,7 @@ Name = "FormMedicine"; StartPosition = FormStartPosition.CenterParent; Text = "Лекарства"; + ((System.ComponentModel.ISupportInitialize)numericUpDownCount).EndInit(); ResumeLayout(false); PerformLayout(); } @@ -139,5 +181,9 @@ private Button ButtonCancel; private TextBox textBoxName; private Label label3; + private Label label4; + private NumericUpDown numericUpDownCount; + private DateTimePicker dateTimePickerMedicine; + private Label label5; } } \ No newline at end of file diff --git a/RegistrationOfPatients/RegistrationOfPatients/Forms/FormMedicine.cs b/RegistrationOfPatients/RegistrationOfPatients/Forms/FormMedicine.cs index 1efb3ed..0ccdede 100644 --- a/RegistrationOfPatients/RegistrationOfPatients/Forms/FormMedicine.cs +++ b/RegistrationOfPatients/RegistrationOfPatients/Forms/FormMedicine.cs @@ -92,6 +92,6 @@ public partial class FormMedicine : Form { medicineType |= (MedicineType)elem; } - return Medicine.CreateEntity(id, medicineType, textBoxName.Text, textBoxDescription.Text); + return Medicine.CreateEntity(id, medicineType, textBoxName.Text, textBoxDescription.Text, Convert.ToInt32(numericUpDownCount.Value), dateTimePickerMedicine.Value); } } diff --git a/RegistrationOfPatients/RegistrationOfPatients/Forms/FormMedicineReport.cs b/RegistrationOfPatients/RegistrationOfPatients/Forms/FormMedicineReport.cs index 917187c..e12d1fd 100644 --- a/RegistrationOfPatients/RegistrationOfPatients/Forms/FormMedicineReport.cs +++ b/RegistrationOfPatients/RegistrationOfPatients/Forms/FormMedicineReport.cs @@ -52,7 +52,7 @@ public partial class FormMedicineReport : Form if (comboBoxMedicine.SelectedIndex < 0) { - throw new Exception("Не выбран корм"); + throw new Exception("Не выбран лекарство"); } if (dateTimePickerDateEnd.Value <= dateTimePickerDateBegin.Value) diff --git a/RegistrationOfPatients/RegistrationOfPatients/Forms/FormPayment.Designer.cs b/RegistrationOfPatients/RegistrationOfPatients/Forms/FormPayment.Designer.cs index 8f873ac..45e6797 100644 --- a/RegistrationOfPatients/RegistrationOfPatients/Forms/FormPayment.Designer.cs +++ b/RegistrationOfPatients/RegistrationOfPatients/Forms/FormPayment.Designer.cs @@ -91,7 +91,6 @@ // // dateTimePickerPayment // - dateTimePickerPayment.Enabled = false; dateTimePickerPayment.Location = new Point(235, 238); dateTimePickerPayment.Name = "dateTimePickerPayment"; dateTimePickerPayment.Size = new Size(178, 27); diff --git a/RegistrationOfPatients/RegistrationOfPatients/Forms/FormReception.Designer.cs b/RegistrationOfPatients/RegistrationOfPatients/Forms/FormReception.Designer.cs index 10e37e2..14d3fbd 100644 --- a/RegistrationOfPatients/RegistrationOfPatients/Forms/FormReception.Designer.cs +++ b/RegistrationOfPatients/RegistrationOfPatients/Forms/FormReception.Designer.cs @@ -40,10 +40,10 @@ ButtonCancel = new Button(); groupBoxMedicine = new GroupBox(); dataGridViewMedicines = new DataGridView(); - label5 = new Label(); - dateTimePickerReception = new DateTimePicker(); ColumnMedicine = new DataGridViewComboBoxColumn(); ColumnCount = new DataGridViewTextBoxColumn(); + label5 = new Label(); + dateTimePickerReception = new DateTimePicker(); groupBoxMedicine.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridViewMedicines).BeginInit(); SuspendLayout(); @@ -168,23 +168,6 @@ dataGridViewMedicines.Size = new Size(276, 121); dataGridViewMedicines.TabIndex = 0; // - // label5 - // - label5.AutoSize = true; - label5.Location = new Point(69, 214); - label5.Name = "label5"; - label5.Size = new Size(44, 20); - label5.TabIndex = 11; - label5.Text = "Дата:"; - // - // dateTimePickerReception - // - dateTimePickerReception.Enabled = false; - dateTimePickerReception.Location = new Point(276, 214); - dateTimePickerReception.Name = "dateTimePickerReception"; - dateTimePickerReception.Size = new Size(178, 27); - dateTimePickerReception.TabIndex = 12; - // // ColumnMedicine // ColumnMedicine.HeaderText = "Лекарство"; @@ -197,6 +180,22 @@ ColumnCount.MinimumWidth = 6; ColumnCount.Name = "ColumnCount"; // + // label5 + // + label5.AutoSize = true; + label5.Location = new Point(69, 214); + label5.Name = "label5"; + label5.Size = new Size(44, 20); + label5.TabIndex = 11; + label5.Text = "Дата:"; + // + // dateTimePickerReception + // + dateTimePickerReception.Location = new Point(276, 214); + dateTimePickerReception.Name = "dateTimePickerReception"; + dateTimePickerReception.Size = new Size(178, 27); + dateTimePickerReception.TabIndex = 12; + // // FormReception // AutoScaleDimensions = new SizeF(8F, 20F); diff --git a/RegistrationOfPatients/RegistrationOfPatients/Forms/FormReceptionDistributionReport.Designer.cs b/RegistrationOfPatients/RegistrationOfPatients/Forms/FormReceptionDistributionReport.Designer.cs new file mode 100644 index 0000000..75a1096 --- /dev/null +++ b/RegistrationOfPatients/RegistrationOfPatients/Forms/FormReceptionDistributionReport.Designer.cs @@ -0,0 +1,130 @@ +namespace RegistrationOfPatients.Forms +{ + partial class FormReceptionDistributionReport + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + ButtonSelectFileName = new Button(); + label1 = new Label(); + dateTimePicker = new DateTimePicker(); + ButtonCreate = new Button(); + comboBoxSelectMedicine = new ComboBox(); + label2 = new Label(); + labelFileName = new Label(); + SuspendLayout(); + // + // ButtonSelectFileName + // + ButtonSelectFileName.Location = new Point(36, 24); + ButtonSelectFileName.Name = "ButtonSelectFileName"; + ButtonSelectFileName.Size = new Size(146, 29); + ButtonSelectFileName.TabIndex = 0; + ButtonSelectFileName.Text = "Выбрать файл"; + ButtonSelectFileName.UseVisualStyleBackColor = true; + ButtonSelectFileName.Click += ButtonSelectFileName_Click; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(36, 120); + label1.Name = "label1"; + label1.Size = new Size(44, 20); + label1.TabIndex = 1; + label1.Text = "Дата:"; + // + // dateTimePicker + // + dateTimePicker.Location = new Point(148, 115); + dateTimePicker.Name = "dateTimePicker"; + dateTimePicker.Size = new Size(181, 27); + dateTimePicker.TabIndex = 2; + // + // ButtonCreate + // + ButtonCreate.Location = new Point(81, 258); + ButtonCreate.Name = "ButtonCreate"; + ButtonCreate.Size = new Size(179, 29); + ButtonCreate.TabIndex = 3; + ButtonCreate.Text = "Сформировать"; + ButtonCreate.UseVisualStyleBackColor = true; + ButtonCreate.Click += ButtonCreate_Click; + // + // comboBoxSelectMedicine + // + comboBoxSelectMedicine.FormattingEnabled = true; + comboBoxSelectMedicine.Location = new Point(148, 168); + comboBoxSelectMedicine.Name = "comboBoxSelectMedicine"; + comboBoxSelectMedicine.Size = new Size(181, 28); + comboBoxSelectMedicine.TabIndex = 4; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(36, 171); + label2.Name = "label2"; + label2.Size = new Size(27, 20); + label2.TabIndex = 5; + label2.Text = "ID:"; + // + // labelFileName + // + labelFileName.AutoSize = true; + labelFileName.Location = new Point(232, 24); + labelFileName.Name = "labelFileName"; + labelFileName.Size = new Size(45, 20); + labelFileName.TabIndex = 6; + labelFileName.Text = "Файл"; + // + // FormReceptionDistributionReport + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(362, 351); + Controls.Add(labelFileName); + Controls.Add(label2); + Controls.Add(comboBoxSelectMedicine); + Controls.Add(ButtonCreate); + Controls.Add(dateTimePicker); + Controls.Add(label1); + Controls.Add(ButtonSelectFileName); + Name = "FormReceptionDistributionReport"; + Text = "FormReceptionDistributionReport"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button ButtonSelectFileName; + private Label label1; + private DateTimePicker dateTimePicker; + private Button ButtonCreate; + private ComboBox comboBoxSelectMedicine; + private Label label2; + private Label labelFileName; + } +} \ No newline at end of file diff --git a/RegistrationOfPatients/RegistrationOfPatients/Forms/FormReceptionDistributionReport.cs b/RegistrationOfPatients/RegistrationOfPatients/Forms/FormReceptionDistributionReport.cs new file mode 100644 index 0000000..20498b5 --- /dev/null +++ b/RegistrationOfPatients/RegistrationOfPatients/Forms/FormReceptionDistributionReport.cs @@ -0,0 +1,70 @@ +using PdfSharp.Drawing; +using RegistrationOfPatients.Reports; +using RegistrationOfPatients.Repositories; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Unity; + +namespace RegistrationOfPatients.Forms; + +public partial class FormReceptionDistributionReport : Form +{ + private string _fileName = string.Empty; + private readonly IUnityContainer _container; + public FormReceptionDistributionReport(IUnityContainer container, IMedicineRepository medicineRepository) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + + comboBoxSelectMedicine.DataSource = medicineRepository.ReadMedicine(); + comboBoxSelectMedicine.DisplayMember = "Name"; + comboBoxSelectMedicine.ValueMember = "Id"; + } + + private void ButtonSelectFileName_Click(object sender, EventArgs e) + { + var sfd = new SaveFileDialog() + { + Filter = "Pdf Files | *.pdf" + }; + if (sfd.ShowDialog() == DialogResult.OK) + { + _fileName = sfd.FileName; + labelFileName.Text = Path.GetFileName(_fileName); + } + } + + private void ButtonCreate_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(_fileName)) + { + throw new Exception("Отсутствует имя файла для отчета"); + } + if (comboBoxSelectMedicine.SelectedIndex < 0) + { + throw new Exception("Не выбрана запись"); + } + if (_container.Resolve().CreateChart(_fileName, dateTimePicker.Value, (int)comboBoxSelectMedicine.SelectedValue!)) + { + MessageBox.Show("Документ сформирован", "Формирование документа", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Возникли ошибки при формировании документа.Подробности в логах", "Формирование документа", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при создании очета", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } +} diff --git a/RegistrationOfPatients/RegistrationOfPatients/Forms/FormReceptionDistributionReport.resx b/RegistrationOfPatients/RegistrationOfPatients/Forms/FormReceptionDistributionReport.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/RegistrationOfPatients/RegistrationOfPatients/Forms/FormReceptionDistributionReport.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/RegistrationOfPatients/RegistrationOfPatients/RegistrationOfPatients.csproj b/RegistrationOfPatients/RegistrationOfPatients/RegistrationOfPatients.csproj index e587b00..4c8aefe 100644 --- a/RegistrationOfPatients/RegistrationOfPatients/RegistrationOfPatients.csproj +++ b/RegistrationOfPatients/RegistrationOfPatients/RegistrationOfPatients.csproj @@ -16,6 +16,7 @@ + diff --git a/RegistrationOfPatients/RegistrationOfPatients/Reports/ChartReport.cs b/RegistrationOfPatients/RegistrationOfPatients/Reports/ChartReport.cs new file mode 100644 index 0000000..f2bc440 --- /dev/null +++ b/RegistrationOfPatients/RegistrationOfPatients/Reports/ChartReport.cs @@ -0,0 +1,51 @@ +using Microsoft.Extensions.Logging; +using RegistrationOfPatients.Entities; +using RegistrationOfPatients.Repositories; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RegistrationOfPatients.Reports; + +public class ChartReport +{ + private readonly IReceptionRepository _receptionRepository; + private readonly ILogger _logger; + + public ChartReport(IReceptionRepository receptionRepository, ILogger logger) + { + _receptionRepository = receptionRepository ?? throw new ArgumentNullException(nameof(receptionRepository)); + _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + } + public bool CreateChart(string filePath, DateTime dateTime, int medicineId) + { + try + { + new PdfBuilder(filePath) + .AddHeader("Записи") + .AddPieChart("Виды записей", GetData(dateTime, medicineId)) + .Build(); + return true; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при формировании документа"); + return false; + } + } + private List<(string Caption, double Value)> GetData(DateTime dateTime, int medicineId) + { + return _receptionRepository + .ReadReceptions() + .Where(x => x.Date.Date == dateTime.Date) + .GroupBy(x => x.Id, (key, group) => new + { + Id = key, + Count = group.Sum(x => x.ReceptionMedicine.FirstOrDefault(y => y.MedicineId == medicineId)?.Count ?? 0) + }) + .Select(x => (x.Id.ToString(), (double)x.Count)) + .ToList(); + } +} diff --git a/RegistrationOfPatients/RegistrationOfPatients/Reports/ExcelBuilder.cs b/RegistrationOfPatients/RegistrationOfPatients/Reports/ExcelBuilder.cs index 1ca6a4a..909e05b 100644 --- a/RegistrationOfPatients/RegistrationOfPatients/Reports/ExcelBuilder.cs +++ b/RegistrationOfPatients/RegistrationOfPatients/Reports/ExcelBuilder.cs @@ -35,7 +35,7 @@ internal class ExcelBuilder public ExcelBuilder AddHeader(string header, int startIndex, int count) { - CreateCell(startIndex, _rowIndex, header, StyleIndex.SimpleTextWithoutBorder); + CreateCell(startIndex, _rowIndex, header, StyleIndex.BoldTextWithoutBorder); for (int i = startIndex + 1; i < startIndex + count; ++i) { CreateCell(i, _rowIndex, "", StyleIndex.SimpleTextWithoutBorder); @@ -84,7 +84,7 @@ internal class ExcelBuilder })); for (var j = 0; j < data.First().Length; ++j) { - CreateCell(j, _rowIndex, data.First()[j], StyleIndex.SimpleTextWithoutBorder); + CreateCell(j, _rowIndex, data.First()[j], StyleIndex.BoldTextWithBorder); } _rowIndex++; @@ -92,7 +92,7 @@ internal class ExcelBuilder { for (var j = 0; j < data[i].Length; ++j) { - CreateCell(j, _rowIndex, data[i][j], StyleIndex.SimpleTextWithoutBorder); + CreateCell(j, _rowIndex, data[i][j], StyleIndex.SimpleTextWithBorder); } _rowIndex++; @@ -100,7 +100,7 @@ internal class ExcelBuilder for (var j = 0; j < data.Last().Length; ++j) { - CreateCell(j, _rowIndex, data.Last()[j], StyleIndex.SimpleTextWithoutBorder); + CreateCell(j, _rowIndex, data.Last()[j], StyleIndex.BoldTextWithBorder); } _rowIndex++; @@ -159,15 +159,15 @@ internal class ExcelBuilder }); // TODO добавить шрифт с жирным fonts.Append(new DocumentFormat.OpenXml.Spreadsheet.Font - { - Bold = new Bold() { Val = true }, + { FontSize = new FontSize() { Val = 11 }, FontName = new FontName() { Val = "Calibri" }, FontFamilyNumbering = new FontFamilyNumbering() { Val = 2 }, FontScheme = new FontScheme() { Val = new EnumValue(FontSchemeValues.Minor) - } + }, + Bold = new Bold() { Val = true } }); workbookStylesPart.Stylesheet.Append(fonts); @@ -289,7 +289,7 @@ internal class ExcelBuilder } var newCell = row.Elements() - .FirstOrDefault(c => c.CellReference != null && c.CellReference.Value == columnName + rowIndex); + .FirstOrDefault(c => c.CellReference != null && c.CellReference.Value == columnName + rowIndex); if (newCell == null) { Cell? refCell = null; diff --git a/RegistrationOfPatients/RegistrationOfPatients/Reports/PdfBuilder.cs b/RegistrationOfPatients/RegistrationOfPatients/Reports/PdfBuilder.cs new file mode 100644 index 0000000..445c90e --- /dev/null +++ b/RegistrationOfPatients/RegistrationOfPatients/Reports/PdfBuilder.cs @@ -0,0 +1,91 @@ +using MigraDoc.DocumentObjectModel; +using MigraDoc.DocumentObjectModel.Shapes.Charts; +using MigraDoc.Rendering; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RegistrationOfPatients.Reports; + +public class PdfBuilder +{ + private readonly string _filePath; + private readonly Document _document; + public PdfBuilder(string filePath) + { + if (string.IsNullOrWhiteSpace(filePath)) + { + throw new ArgumentNullException(nameof(filePath)); + } + if (File.Exists(filePath)) + { + File.Delete(filePath); + } + _filePath = filePath; + _document = new Document(); + DefineStyles(); + } + + public PdfBuilder AddHeader(string header) + { + _document.AddSection().AddParagraph(header, "NormalBold"); + return this; + } + public PdfBuilder AddPieChart(string title, List<(string Caption, double Value)> data) + { + if (data == null || data.Count == 0) + { + return this; + } + + var chart = new Chart(ChartType.Pie2D); + var series = chart.SeriesCollection.AddSeries(); + series.Add(data.Select(x => x.Value).ToArray()); + + var xseries = chart.XValues.AddXSeries(); + xseries.Add(data.Select(x => x.Caption).ToArray()); + + chart.DataLabel.Type = DataLabelType.Percent; + chart.DataLabel.Position = DataLabelPosition.OutsideEnd; + + chart.Width = Unit.FromCentimeter(16); + chart.Height = Unit.FromCentimeter(12); + + chart.TopArea.AddParagraph(title); + + chart.XAxis.MajorTickMark = TickMarkType.Outside; + + chart.YAxis.MajorTickMark = TickMarkType.Outside; + chart.YAxis.HasMajorGridlines = true; + + chart.PlotArea.LineFormat.Width = 1; + chart.PlotArea.LineFormat.Visible = true; + + chart.TopArea.AddLegend(); + + _document.LastSection.Add(chart); + + return this; + } + + public void Build() + { + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + var renderer = new PdfDocumentRenderer(true) + { + Document = _document + }; + + renderer.RenderDocument(); + renderer.PdfDocument.Save(_filePath); + } + private void DefineStyles() + { + var style = _document.Styles.AddStyle("NormalBold", "Normal"); + style.Font.Bold = true; + style.Font.Size = 14; + style.ParagraphFormat.Alignment = ParagraphAlignment.Center; + } +} diff --git a/RegistrationOfPatients/RegistrationOfPatients/Reports/TableReport.cs b/RegistrationOfPatients/RegistrationOfPatients/Reports/TableReport.cs index 496d7ef..8bb356e 100644 --- a/RegistrationOfPatients/RegistrationOfPatients/Reports/TableReport.cs +++ b/RegistrationOfPatients/RegistrationOfPatients/Reports/TableReport.cs @@ -12,16 +12,16 @@ internal class TableReport { private readonly IReceptionRepository _receptionRepository; - private readonly IPaymentRepository _paymentRepository; + private readonly IMedicineRepository _medicineRepository; private readonly ILogger _logger; - internal static readonly string[] item = ["Доктор", "Дата", "Количество пришло", "Количество ушло"]; + internal static readonly string[] item = ["Дата", "Количество лекарства ушло", "Количество лекарства пришло"]; - public TableReport(IPaymentRepository paymentRepository, IReceptionRepository receptionRepository, ILogger logger) + public TableReport(IMedicineRepository medicineRepository, IReceptionRepository receptionRepository, ILogger logger) { _receptionRepository = receptionRepository ?? throw new ArgumentNullException(nameof(receptionRepository)); - _paymentRepository = paymentRepository ?? throw new ArgumentNullException(nameof(paymentRepository)); + _medicineRepository = medicineRepository ?? throw new ArgumentNullException(nameof(medicineRepository)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); } @@ -30,9 +30,9 @@ internal class TableReport try { new ExcelBuilder(filePath) - .AddHeader("Сводка по движению лекарств", 0, 4) + .AddHeader("Сводка по движению лекарств", 0, 3) .AddParagraph("за период", 0) - .AddTable([10, 10, 15, 15], GetData(medicineId, startDate, endDate)) + .AddTable([15, 15, 15], GetData(medicineId, startDate, endDate)) .Build(); return true; } @@ -49,24 +49,23 @@ internal class TableReport .ReadReceptions() .Where(x => x.Date >= startDate && x.Date <= endDate && x.ReceptionMedicine.Any(y => y.MedicineId == medicineId)) .Select(x => new - { - x.DoctorId, + { Date = x.Date, CountIn = x.ReceptionMedicine.FirstOrDefault(y => y.MedicineId == medicineId)?.Count, CountOut = (int?)null }) .Union( - _paymentRepository - .ReadPayment() - .Where(x => x.Date >= startDate && x.Date <= endDate && x.DoctorId == medicineId) - .Select(x => new { x.DoctorId, Date = x.Date, CountIn = (int?)null, CountOut = (int?)null })) + _medicineRepository + .ReadMedicine() + .Where(x => x.Date >= startDate && x.Date <= endDate && x.Id == medicineId) + .Select(x => new { Date = x.Date, CountIn = (int?)null, CountOut = (int?)x.Count })) .OrderBy(x => x.Date); return new List() { item } .Union( data - .Select(x => new string[] { x.DoctorId.ToString(), x.Date.ToString(), x.CountIn?.ToString() ?? string.Empty, x.CountOut?.ToString() ?? string.Empty })) + .Select(x => new string[] { x.Date.ToString(), x.CountIn?.ToString() ?? string.Empty, x.CountOut?.ToString() ?? string.Empty })) .Union( - [["Всего", "", data.Sum(x => x.CountIn ?? 0).ToString(), data.Sum(x => x.CountOut ?? 0).ToString()]]) + [["Всего", data.Sum(x => x.CountIn ?? 0).ToString(), data.Sum(x => x.CountOut ?? 0).ToString()]]) .ToList(); } } diff --git a/RegistrationOfPatients/RegistrationOfPatients/Repositories/Implementations/MedicineRepository.cs b/RegistrationOfPatients/RegistrationOfPatients/Repositories/Implementations/MedicineRepository.cs index 016cba3..38e688b 100644 --- a/RegistrationOfPatients/RegistrationOfPatients/Repositories/Implementations/MedicineRepository.cs +++ b/RegistrationOfPatients/RegistrationOfPatients/Repositories/Implementations/MedicineRepository.cs @@ -27,7 +27,7 @@ public class MedicineRepository : IMedicineRepository try { using var connection = new NpgsqlConnection(_connectionString.ConnectionString); - var queryInsert = @" INSERT INTO Medicine (MedicineType, Description, Name) VALUES (@MedicineType, @Description, @Name)"; + var queryInsert = @" INSERT INTO Medicine (Date, Count, MedicineType, Description, Name) VALUES (@Date, @Count, @MedicineType, @Description, @Name)"; connection.Execute(queryInsert, medicine); } catch (Exception ex) @@ -44,7 +44,7 @@ public class MedicineRepository : IMedicineRepository try { using var connection = new NpgsqlConnection(_connectionString.ConnectionString); - var queryUpdate = @" UPDATE Medicine SET MedicineType=@MedicineType, Description=@Description, Name=@Name WHERE Id=@Id"; connection.Execute(queryUpdate, medicine); + var queryUpdate = @" UPDATE Medicine SET Date=@Date, Count=@Count, MedicineType=@MedicineType, Description=@Description, Name=@Name WHERE Id=@Id"; connection.Execute(queryUpdate, medicine); } catch (Exception ex) { diff --git a/RegistrationOfPatients/RegistrationOfPatients/Repositories/Implementations/ReceptionRepository.cs b/RegistrationOfPatients/RegistrationOfPatients/Repositories/Implementations/ReceptionRepository.cs index 61629c1..79ba525 100644 --- a/RegistrationOfPatients/RegistrationOfPatients/Repositories/Implementations/ReceptionRepository.cs +++ b/RegistrationOfPatients/RegistrationOfPatients/Repositories/Implementations/ReceptionRepository.cs @@ -35,10 +35,10 @@ public class ReceptionRepository : IReceptionRepository using var connection = new NpgsqlConnection(_connectionString.ConnectionString); connection.Open(); using var transaction = connection.BeginTransaction(); - var queryInsert = @" INSERT INTO Reception (Date, HealthStatus, Illness, PatientId, DoctorId) VALUES (@Date, @HealthStatus, @Illness, @PatientId, @DoctorId); SELECT MAX(Id) FROM Reception"; + var queryInsert = @" INSERT INTO Reception (Date, HealthStatus, Illness, PatientID, DoctorID) VALUES (@Date, @HealthStatus, @Illness, @PatientID, @DoctorID); SELECT MAX(Id) FROM Reception"; var receptionId = connection.QueryFirst(queryInsert, reception, transaction); - var querySubInsert = @" INSERT INTO ReceptionMedicine (ReceptionID, MedicineId, Count) VALUES (@ReceptionId, @MedicineId, @Count)"; + var querySubInsert = @" INSERT INTO ReceptionMedicine (ReceptionID, MedicineId, Count) VALUES (@ReceptionID, @MedicineID, @Count)"; foreach (var elem in reception.ReceptionMedicine) { @@ -64,7 +64,7 @@ public class ReceptionRepository : IReceptionRepository try { using var connection = new NpgsqlConnection(_connectionString.ConnectionString); - var querySelect = @"SELECT r.Id AS ReceptionId, r.DoctorId, r.Patient.Id, r.Date, rm.MedicineId, rm.Count FROM Reception r INNER JOIN ReceptionMedicine rm ON r.DoctorID = r.ID"; + var querySelect = @"SELECT r.*, rm.MedicineID, rm.Count FROM Reception r INNER JOIN ReceptionMedicine rm on rm.ReceptionID = r.ID"; var receptions = connection.Query(querySelect); _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(receptions)); return receptions.GroupBy(x => x.Id, y => y,