Добавил формы для списков

This commit is contained in:
Никита Потапов 2024-05-08 12:55:18 +04:00
parent 9dc3fe3a2f
commit 3c5363ea86
17 changed files with 458 additions and 126 deletions

View File

@ -1,4 +1,5 @@
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
namespace MedicalDatabaseContracts.Models
{

View File

@ -2,13 +2,12 @@
using Microsoft.Extensions.Logging;
using Npgsql;
using System.Data;
using System.Diagnostics;
namespace MedicalPostgresqlDatabase.Storages
{
public class DiagnosesStorage : AbstractPostgresqlStorage<Diagnose>
public class DiagnoseStorage : AbstractPostgresqlStorage<Diagnose>
{
public DiagnosesStorage(ILogger<DiagnosesStorage> logger) : base(logger, "diagnoses", "diagnose_id", "diagnoses_id_seq") { }
public DiagnoseStorage(ILogger<DiagnoseStorage> logger) : base(logger, "diagnoses", "diagnose_id", "diagnoses_id_seq") { }
protected override Diagnose CreateEntityFromReader(NpgsqlDataReader reader)
{

View File

@ -5,9 +5,9 @@ using System.Data;
namespace MedicalPostgresqlDatabase.Storages
{
public class DoctorsStorage : AbstractPostgresqlStorage<Doctor>
public class DoctorStorage : AbstractPostgresqlStorage<Doctor>
{
public DoctorsStorage(ILogger<DoctorsStorage> logger) : base(logger, "doctors", "doctor_id", "doctors_id_seq") { }
public DoctorStorage(ILogger<DoctorStorage> logger) : base(logger, "doctors", "doctor_id", "doctors_id_seq") { }
protected override Doctor CreateEntityFromReader(NpgsqlDataReader reader)
{
@ -18,7 +18,7 @@ namespace MedicalPostgresqlDatabase.Storages
Surname = Convert.ToString(reader.GetValue("surname")),
Patronymic = Convert.ToString(reader.GetValue("patronymic")),
PhoneNumber = Convert.ToString(reader.GetValue("phone_number")),
SpecializationId = Convert.ToInt32(reader.GetValue("specializaton_id"))
SpecializationId = Convert.ToInt32(reader.GetValue("specialization_id"))
};
}

View File

@ -4,7 +4,7 @@ using Microsoft.Extensions.Logging;
using Npgsql;
using System.Data;
namespace MedicalPostgresqlDatabase
namespace MedicalPostgresqlDatabase.Storages
{
public class VisitStorage : AbstractPostgresqlStorage<Visit>
{

View File

@ -2,54 +2,13 @@
using MedicalDatabaseContracts.Models;
using Microsoft.Extensions.Logging;
namespace MedicalView
namespace MedicalView.Diagnoses
{
public partial class FormDiagnoses : Form
public class FormDiagnoses : FormAbstractList<Diagnose>
{
private ILogger _logger;
private IStorage<Diagnose> _diagnosesStorage;
public FormDiagnoses(ILogger<FormDiagnoses> logger, IStorage<Diagnose> diagnosesStorage)
public FormDiagnoses(ILogger<FormAbstractList<Diagnose>> logger, IStorage<Diagnose> storage) : base(logger, storage)
{
InitializeComponent();
_logger = logger;
_diagnosesStorage = diagnosesStorage;
}
private void FormDiagnoses_Load(object sender, EventArgs e)
{
LoadData();
}
private void RefreshToolStripMenuItem_Click(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
SetStatusStripText("Загрузка диагнозов...");
try
{
long elapsed;
var items = _diagnosesStorage.GetAll(out elapsed);
dataGridView.DataSource = items;
dataGridView.Columns["Id"].Visible = false;
_logger.LogInformation("Список диагнозов загружен успешно");
SetStatusStripText($"Готово. Загружено записей: {items.Count}, время загрузки {elapsed} мск");
}
catch (Exception ex)
{
string errorMessage = "Ошибка загрузки списка диагнозов";
_logger.LogError(string.Join(", ", errorMessage, $"\"{ex.Message}\""));
MessageBox.Show(string.Join("\n\n", errorMessage, $"{ex.Message}"), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
SetStatusStripText($"Ошибка загрузки");
}
}
private void SetStatusStripText(string text)
{
toolStripStatusLabel.Text = text;
Text = "Список диагнозов";
}
}
}

View File

@ -0,0 +1,14 @@
using MedicalDatabaseContracts;
using MedicalDatabaseContracts.Models;
using Microsoft.Extensions.Logging;
namespace MedicalView.Doctors
{
public class FormDoctors : FormAbstractList<Doctor>
{
public FormDoctors(ILogger<FormAbstractList<Doctor>> logger, IStorage<Doctor> storage) : base(logger, storage)
{
Text = "Список врачей";
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -1,6 +1,6 @@
namespace MedicalView
{
partial class FormDiagnoses
partial class FormAbstractList<T>
{
/// <summary>
/// Required designer variable.
@ -28,7 +28,6 @@
/// </summary>
private void InitializeComponent()
{
dataGridView = new DataGridView();
menuStrip = new MenuStrip();
обновитьToolStripMenuItem = new ToolStripMenuItem();
добавитьToolStripMenuItem = new ToolStripMenuItem();
@ -36,11 +35,65 @@
удалитьToolStripMenuItem = new ToolStripMenuItem();
statusStrip = new StatusStrip();
toolStripStatusLabel = new ToolStripStatusLabel();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
dataGridView = new DataGridView();
menuStrip.SuspendLayout();
statusStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// menuStrip
//
menuStrip.ImageScalingSize = new Size(20, 20);
menuStrip.Items.AddRange(new ToolStripItem[] { обновитьToolStripMenuItem, добавитьToolStripMenuItem, изменитьToolStripMenuItem, удалитьToolStripMenuItem });
menuStrip.Location = new Point(0, 0);
menuStrip.Name = "menuStrip";
menuStrip.Size = new Size(800, 28);
menuStrip.TabIndex = 0;
menuStrip.Text = "menuStrip1";
//
// обновитьToolStripMenuItem
//
обновитьToolStripMenuItem.Name = "обновитьToolStripMenuItem";
обновитьToolStripMenuItem.Size = new Size(92, 24);
обновитьToolStripMenuItem.Text = "Обновить";
обновитьToolStripMenuItem.Click += RefreshItemsToolStripMenuItem_Click;
//
// добавитьToolStripMenuItem
//
добавитьToolStripMenuItem.Name = обавитьToolStripMenuItem";
добавитьToolStripMenuItem.Size = new Size(90, 24);
добавитьToolStripMenuItem.Text = "Добавить";
добавитьToolStripMenuItem.Click += AddItemToolStripMenuItem_Click;
//
// изменитьToolStripMenuItem
//
изменитьToolStripMenuItem.Name = "изменитьToolStripMenuItem";
изменитьToolStripMenuItem.Size = new Size(92, 24);
изменитьToolStripMenuItem.Text = "Изменить";
изменитьToolStripMenuItem.Click += EsitItemToolStripMenuItem_Click;
//
// удалитьToolStripMenuItem
//
удалитьToolStripMenuItem.Name = "удалитьToolStripMenuItem";
удалитьToolStripMenuItem.Size = new Size(79, 24);
удалитьToolStripMenuItem.Text = "Удалить";
удалитьToolStripMenuItem.Click += DeleteItemToolStripMenuItem_Click;
//
// statusStrip
//
statusStrip.ImageScalingSize = new Size(20, 20);
statusStrip.Items.AddRange(new ToolStripItem[] { toolStripStatusLabel });
statusStrip.Location = new Point(0, 428);
statusStrip.Name = "statusStrip";
statusStrip.Size = new Size(800, 22);
statusStrip.TabIndex = 1;
statusStrip.Text = "statusStrip1";
//
// toolStripStatusLabel
//
toolStripStatusLabel.Name = "toolStripStatusLabel";
toolStripStatusLabel.Size = new Size(0, 16);
//
// dataGridView
//
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
@ -53,88 +106,39 @@
dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 29;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(800, 422);
dataGridView.TabIndex = 3;
dataGridView.Size = new Size(800, 400);
dataGridView.TabIndex = 2;
//
// menuStrip
//
menuStrip.ImageScalingSize = new Size(20, 20);
menuStrip.Items.AddRange(new ToolStripItem[] { обновитьToolStripMenuItem, добавитьToolStripMenuItem, изменитьToolStripMenuItem, удалитьToolStripMenuItem });
menuStrip.Location = new Point(0, 0);
menuStrip.Name = "menuStrip";
menuStrip.Size = new Size(800, 28);
menuStrip.TabIndex = 4;
menuStrip.Text = "menuStrip1";
//
// обновитьToolStripMenuItem
//
обновитьToolStripMenuItem.Name = "обновитьToolStripMenuItem";
обновитьToolStripMenuItem.Size = new Size(92, 24);
обновитьToolStripMenuItem.Text = "Обновить";
обновитьToolStripMenuItem.Click += RefreshToolStripMenuItem_Click;
//
// добавитьToolStripMenuItem
//
добавитьToolStripMenuItem.Name = обавитьToolStripMenuItem";
добавитьToolStripMenuItem.Size = new Size(90, 24);
добавитьToolStripMenuItem.Text = "Добавить";
//
// изменитьToolStripMenuItem
//
изменитьToolStripMenuItem.Name = "изменитьToolStripMenuItem";
изменитьToolStripMenuItem.Size = new Size(92, 24);
изменитьToolStripMenuItem.Text = "Изменить";
//
// удалитьToolStripMenuItem
//
удалитьToolStripMenuItem.Name = "удалитьToolStripMenuItem";
удалитьToolStripMenuItem.Size = new Size(79, 24);
удалитьToolStripMenuItem.Text = "Удалить";
//
// statusStrip
//
statusStrip.ImageScalingSize = new Size(20, 20);
statusStrip.Items.AddRange(new ToolStripItem[] { toolStripStatusLabel });
statusStrip.Location = new Point(0, 428);
statusStrip.Name = "statusStrip";
statusStrip.Size = new Size(800, 22);
statusStrip.TabIndex = 5;
statusStrip.Text = "statusStrip1";
//
// toolStripStatusLabel
//
toolStripStatusLabel.Name = "toolStripStatusLabel";
toolStripStatusLabel.Size = new Size(0, 16);
//
// FormDiagnoses
// FormAbstractList
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(statusStrip);
Controls.Add(dataGridView);
Controls.Add(statusStrip);
Controls.Add(menuStrip);
MainMenuStrip = menuStrip;
Name = "FormDiagnoses";
Text = "Диагнозы";
Load += FormDiagnoses_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
Name = "FormAbstractList";
Text = "FormAbstractList";
Load += FormAbstractList_Load;
menuStrip.ResumeLayout(false);
menuStrip.PerformLayout();
statusStrip.ResumeLayout(false);
statusStrip.PerformLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private DataGridView dataGridView;
private MenuStrip menuStrip;
private StatusStrip statusStrip;
private ToolStripMenuItem обновитьToolStripMenuItem;
private ToolStripMenuItem добавитьToolStripMenuItem;
private ToolStripMenuItem изменитьToolStripMenuItem;
private ToolStripMenuItem удалитьToolStripMenuItem;
private StatusStrip statusStrip;
private ToolStripStatusLabel toolStripStatusLabel;
private DataGridView dataGridView;
}
}

View File

@ -0,0 +1,77 @@
using MedicalDatabaseContracts;
using MedicalDatabaseContracts.Models;
using Microsoft.Extensions.Logging;
namespace MedicalView
{
public partial class FormAbstractList<T> : Form where T : AbstractModel
{
protected ILogger _logger;
protected IStorage<T> _storage;
public FormAbstractList(ILogger<FormAbstractList<T>> logger, IStorage<T> storage)
{
InitializeComponent();
_logger = logger;
_storage = storage;
}
private void FormAbstractList_Load(object sender, EventArgs e)
{
LoadData();
}
private void RefreshItemsToolStripMenuItem_Click(object sender, EventArgs e)
{
LoadData();
}
private void AddItemToolStripMenuItem_Click(object sender, EventArgs e)
{
// code
}
private void EsitItemToolStripMenuItem_Click(object sender, EventArgs e)
{
// code
}
private void DeleteItemToolStripMenuItem_Click(object sender, EventArgs e)
{
// code
}
protected virtual void LoadData()
{
SetStatusStripText("Загрузка списка...");
try
{
long elapsed;
var items = _storage.GetAll(out elapsed);
dataGridView.DataSource = items;
foreach (DataGridViewTextBoxColumn column in dataGridView.Columns)
{
if (column.Name.Contains("Id"))
{
column.Visible = false;
}
}
dataGridView.ReadOnly = true;
_logger.LogInformation("Список загружен успешно");
SetStatusStripText($"Готово. Загружено записей: {items.Count}, время загрузки {elapsed} мск");
}
catch (Exception ex)
{
string errorMessage = "Ошибка загрузки списка";
_logger.LogError(string.Join(", ", errorMessage, $"\"{ex.Message}\""));
MessageBox.Show(string.Join("\n\n", errorMessage, $"{ex.Message}"), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
SetStatusStripText($"Ошибка загрузки");
}
}
protected virtual void SetStatusStripText(string text)
{
toolStripStatusLabel.Text = text;
}
}
}

View File

@ -121,6 +121,6 @@
<value>17, 17</value>
</metadata>
<metadata name="statusStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>145, 17</value>
<value>153, 17</value>
</metadata>
</root>

View File

@ -41,9 +41,12 @@
buttonAdd = new Button();
dateTimePicker1 = new DateTimePicker();
comboBoxDoctor = new ComboBox();
statusStrip = new StatusStrip();
toolStripStatusLabel = new ToolStripStatusLabel();
menuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
panel.SuspendLayout();
statusStrip.SuspendLayout();
SuspendLayout();
//
// menuStrip
@ -67,39 +70,46 @@
// специализацииToolStripMenuItem
//
специализацииToolStripMenuItem.Name = "специализацииToolStripMenuItem";
специализацииToolStripMenuItem.Size = new Size(224, 26);
специализацииToolStripMenuItem.Size = new Size(203, 26);
специализацииToolStripMenuItem.Text = "Специализации";
специализацииToolStripMenuItem.Click += SpecializationsToolStripMenuItem_Click;
//
// диагнозыToolStripMenuItem
//
диагнозыToolStripMenuItem.Name = "диагнозыToolStripMenuItem";
диагнозыToolStripMenuItem.Size = new Size(224, 26);
диагнозыToolStripMenuItem.Size = new Size(203, 26);
диагнозыToolStripMenuItem.Text = "Диагнозы";
диагнозыToolStripMenuItem.Click += DiagnosesToolStripMenuItem_Click;
//
// врачиToolStripMenuItem
//
врачиToolStripMenuItem.Name = рачиToolStripMenuItem";
врачиToolStripMenuItem.Size = new Size(224, 26);
врачиToolStripMenuItem.Size = new Size(203, 26);
врачиToolStripMenuItem.Text = "Врачи";
врачиToolStripMenuItem.Click += DoctorsToolStripMenuItem_Click;
//
// пациентыToolStripMenuItem1
//
пациентыToolStripMenuItem1.Name = "пациентыToolStripMenuItem1";
пациентыToolStripMenuItem1.Size = new Size(94, 24);
пациентыToolStripMenuItem1.Text = "Пациенты";
пациентыToolStripMenuItem1.Click += PatientsToolStripMenuItem1_Click;
//
// dataGridView
//
dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Dock = DockStyle.Fill;
dataGridView.Location = new Point(0, 30);
dataGridView.Location = new Point(0, 70);
dataGridView.Margin = new Padding(3, 4, 3, 4);
dataGridView.MultiSelect = false;
dataGridView.Name = "dataGridView";
dataGridView.ReadOnly = true;
dataGridView.RowHeadersVisible = false;
dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 25;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(863, 371);
dataGridView.Size = new Size(863, 331);
dataGridView.TabIndex = 1;
//
// panel
@ -169,11 +179,27 @@
comboBoxDoctor.Size = new Size(196, 28);
comboBoxDoctor.TabIndex = 0;
//
// statusStrip
//
statusStrip.ImageScalingSize = new Size(20, 20);
statusStrip.Items.AddRange(new ToolStripItem[] { toolStripStatusLabel });
statusStrip.Location = new Point(0, 379);
statusStrip.Name = "statusStrip";
statusStrip.Size = new Size(863, 22);
statusStrip.TabIndex = 3;
statusStrip.Text = "statusStrip1";
//
// toolStripStatusLabel
//
toolStripStatusLabel.Name = "toolStripStatusLabel";
toolStripStatusLabel.Size = new Size(0, 16);
//
// FormMain
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(863, 401);
Controls.Add(statusStrip);
Controls.Add(panel);
Controls.Add(dataGridView);
Controls.Add(menuStrip);
@ -187,6 +213,8 @@
menuStrip.PerformLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
panel.ResumeLayout(false);
statusStrip.ResumeLayout(false);
statusStrip.PerformLayout();
ResumeLayout(false);
PerformLayout();
}
@ -206,5 +234,7 @@
private Button buttonDelete;
private Button buttonAdd;
private Button buttonEdit;
private StatusStrip statusStrip;
private ToolStripStatusLabel toolStripStatusLabel;
}
}

View File

@ -1,15 +1,28 @@
namespace MedicalView.Visits
using MedicalView.Doctors;
using MedicalView.Specializations;
using MedicalView.Diagnoses;
using MedicalView.Patients;
using Microsoft.Extensions.Logging;
using MedicalDatabaseContracts;
using MedicalDatabaseContracts.Models;
using System.Windows.Forms;
namespace MedicalView.Visits
{
public partial class FormMain : Form
{
public FormMain()
private ILogger _logger;
private IStorage<Visit> _visitStorage;
public FormMain(ILogger<FormMain> logger, IStorage<Visit> visitStorage)
{
InitializeComponent();
_logger = logger;
_visitStorage = visitStorage;
}
private void FormMain_Load(object sender, EventArgs e)
{
LoadData();
}
private void DiagnosesToolStripMenuItem_Click(object sender, EventArgs e)
@ -20,5 +33,66 @@
form.ShowDialog();
}
}
private void SpecializationsToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSpecializations));
if (service is FormSpecializations form)
{
form.ShowDialog();
}
}
private void DoctorsToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormDoctors));
if (service is FormDoctors form)
{
form.ShowDialog();
}
}
private void PatientsToolStripMenuItem1_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormPatients));
if (service is FormPatients form)
{
form.ShowDialog();
}
}
protected virtual void LoadData()
{
SetStatusStripText("Загрузка списка...");
try
{
long elapsed;
var items = _visitStorage.GetAll(out elapsed);
dataGridView.DataSource = items;
foreach (DataGridViewTextBoxColumn column in dataGridView.Columns)
{
if (column.Name.Contains("Id"))
{
column.Visible = false;
}
}
dataGridView.ReadOnly = true;
_logger.LogInformation("Список загружен успешно");
SetStatusStripText($"Готово. Загружено записей: {items.Count}, время загрузки {elapsed} мск");
}
catch (Exception ex)
{
string errorMessage = "Ошибка загрузки списка";
_logger.LogError(string.Join(", ", errorMessage, $"\"{ex.Message}\""));
MessageBox.Show(string.Join("\n\n", errorMessage, $"{ex.Message}"), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
SetStatusStripText($"Ошибка загрузки");
}
}
protected virtual void SetStatusStripText(string text)
{
toolStripStatusLabel.Text = text;
}
}
}

View File

@ -120,4 +120,7 @@
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="statusStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>145, 17</value>
</metadata>
</root>

View File

@ -0,0 +1,14 @@
using MedicalDatabaseContracts;
using MedicalDatabaseContracts.Models;
using Microsoft.Extensions.Logging;
namespace MedicalView.Patients
{
public class FormPatients : FormAbstractList<Patient>
{
public FormPatients(ILogger<FormAbstractList<Patient>> logger, IStorage<Patient> storage) : base(logger, storage)
{
Text = "Список пациентов";
}
}
}

View File

@ -1,6 +1,10 @@
using MedicalDatabaseContracts;
using MedicalDatabaseContracts.Models;
using MedicalPostgresqlDatabase.Storages;
using MedicalView.Diagnoses;
using MedicalView.Doctors;
using MedicalView.Patients;
using MedicalView.Specializations;
using MedicalView.Visits;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
@ -35,10 +39,18 @@ namespace MedicalView
option.SetMinimumLevel(LogLevel.Information);
option.AddNLog("nlog.config");
});
services.AddTransient<IStorage<Diagnose>, DiagnosesStorage>();
services.AddTransient<IStorage<Diagnose>, DiagnoseStorage>();
services.AddTransient<IStorage<Doctor>, DoctorStorage>();
services.AddTransient<IStorage<Patient>, PatientStorage>();
services.AddTransient<IStorage<Specialization>, SpecializationStorage>();
services.AddTransient<IStorage<Visit>, VisitStorage>();
services.AddTransient<FormMain>();
services.AddTransient<FormDiagnoses>();
services.AddTransient<FormDoctors>();
services.AddTransient<FormPatients>();
services.AddTransient<FormSpecializations>();
services.AddTransient<FormVisits>();
}
}
}

View File

@ -0,0 +1,14 @@
using MedicalDatabaseContracts;
using MedicalDatabaseContracts.Models;
using Microsoft.Extensions.Logging;
namespace MedicalView.Specializations
{
public class FormSpecializations : FormAbstractList<Specialization>
{
public FormSpecializations(ILogger<FormAbstractList<Specialization>> logger, IStorage<Specialization> storage) : base(logger, storage)
{
Text = "Список специализаций";
}
}
}

View File

@ -0,0 +1,11 @@
using MedicalDatabaseContracts;
using MedicalDatabaseContracts.Models;
using Microsoft.Extensions.Logging;
namespace MedicalView.Visits
{
public class FormVisits : FormAbstractList<Visit>
{
public FormVisits(ILogger<FormAbstractList<Visit>> logger, IStorage<Visit> storage) : base(logger, storage) { }
}
}