diff --git a/ProjectPolyclinic/ProjectPolyclinic/Entities/Diagnosis.cs b/ProjectPolyclinic/ProjectPolyclinic/Entities/Diagnosis.cs new file mode 100644 index 0000000..eb2cd98 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Entities/Diagnosis.cs @@ -0,0 +1,17 @@ +namespace ProjectPolyclinic.Entities; + +public class Diagnosis +{ + public int Id { get; private set; } + + public string Name { get; private set; } = string.Empty; + + public static Diagnosis CreateDiagnosis(int id, string name) + { + return new Diagnosis + { + Id = id, + Name = name, + }; + } +} diff --git a/ProjectPolyclinic/ProjectPolyclinic/Entities/Doctor.cs b/ProjectPolyclinic/ProjectPolyclinic/Entities/Doctor.cs new file mode 100644 index 0000000..0cae83e --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Entities/Doctor.cs @@ -0,0 +1,25 @@ +using ProjectPolyclinic.Entities.Enums; + +namespace ProjectPolyclinic.Entities; + +public class Doctor +{ + public int Id { get; private set; } + + public string FirstName { get; private set; } = string.Empty; + + public string LastName { get; private set; } = string.Empty; + + public DoctorSpeciality DoctorSpeciality { get; private set; } + + public static Doctor CreateEntity(int id, string first, string last, DoctorSpeciality doctorSpeciality) + { + return new Doctor + { + Id = id, + FirstName = first ?? string.Empty, + LastName = last ?? string.Empty, + DoctorSpeciality = doctorSpeciality + }; + } +} diff --git a/ProjectPolyclinic/ProjectPolyclinic/Entities/Enums/DoctorSpeciality.cs b/ProjectPolyclinic/ProjectPolyclinic/Entities/Enums/DoctorSpeciality.cs new file mode 100644 index 0000000..e5f9870 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Entities/Enums/DoctorSpeciality.cs @@ -0,0 +1,16 @@ +namespace ProjectPolyclinic.Entities.Enums; + +public enum DoctorSpeciality +{ + None = 0, + + Cardiologist = 1, + + Neurologist = 2, + + Dermatologist = 3, + + Surgeon = 4, + + Pediatrician = 5 +} diff --git a/ProjectPolyclinic/ProjectPolyclinic/Entities/Enums/MedicinesStatement.cs b/ProjectPolyclinic/ProjectPolyclinic/Entities/Enums/MedicinesStatement.cs new file mode 100644 index 0000000..4e8955c --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Entities/Enums/MedicinesStatement.cs @@ -0,0 +1,7 @@ +namespace ProjectPolyclinic.Entities.Enums; + +public enum MedicinesStatement +{ + Recieved = 1, + Decreased = 2 +} diff --git a/ProjectPolyclinic/ProjectPolyclinic/Entities/Enums/MedicinesType.cs b/ProjectPolyclinic/ProjectPolyclinic/Entities/Enums/MedicinesType.cs new file mode 100644 index 0000000..7c8cae5 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Entities/Enums/MedicinesType.cs @@ -0,0 +1,17 @@ +namespace ProjectPolyclinic.Entities.Enums; + +[Flags] +public enum MedicinesType +{ + None = 0, + + Antihypertensive = 1, + + Sedative = 2, + + Antihistamines = 4, + + Analgesics = 8, + + Antipyretics = 16 +} diff --git a/ProjectPolyclinic/ProjectPolyclinic/Entities/Medicines.cs b/ProjectPolyclinic/ProjectPolyclinic/Entities/Medicines.cs new file mode 100644 index 0000000..de8c739 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Entities/Medicines.cs @@ -0,0 +1,22 @@ +using ProjectPolyclinic.Entities.Enums; + +namespace ProjectPolyclinic.Entities; + +public class Medicines +{ + public int Id { get; private set; } + + public MedicinesType MedicinesType { get; private set; } + + public string Name { get; private set; } = string.Empty; + + public static Medicines CreateEntity(int id, MedicinesType medicinesType, string name) + { + return new Medicines + { + Id = id, + MedicinesType = medicinesType, + Name = name ?? string.Empty, + }; + } +} diff --git a/ProjectPolyclinic/ProjectPolyclinic/Entities/MedicinesMoving.cs b/ProjectPolyclinic/ProjectPolyclinic/Entities/MedicinesMoving.cs new file mode 100644 index 0000000..7166ae9 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Entities/MedicinesMoving.cs @@ -0,0 +1,25 @@ +using ProjectPolyclinic.Entities.Enums; + +namespace ProjectPolyclinic.Entities; + +public class MedicinesMoving +{ + public int Id { get; private set; } + + public int MedicinesId { get; private set; } + + public DateTime Date { get; private set; } + + public IEnumerable MedicinesStatement { get; private set; } = []; + + public static MedicinesMoving CreateOperation(int id, int medicinesId, DateTime date, IEnumerable medicinesStatement) + { + return new MedicinesMoving + { + Id = id, + MedicinesId = medicinesId, + Date = date, + MedicinesStatement = medicinesStatement + }; + } +} diff --git a/ProjectPolyclinic/ProjectPolyclinic/Entities/MedicinesVisit.cs b/ProjectPolyclinic/ProjectPolyclinic/Entities/MedicinesVisit.cs new file mode 100644 index 0000000..ac30de3 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Entities/MedicinesVisit.cs @@ -0,0 +1,23 @@ +namespace ProjectPolyclinic.Entities; + +public class MedicinesVisit +{ + public int Id { get; private set; } + + public int VisitId { get; private set; } + + public int MedicinesId { get; private set; } + + public int Quantity { get; private set; } + + public static MedicinesVisit CreateElement(int id, int visitId, int medicinesId, int quantity) + { + return new MedicinesVisit + { + Id = id, + VisitId = visitId, + MedicinesId = medicinesId, + Quantity = quantity + }; + } +} diff --git a/ProjectPolyclinic/ProjectPolyclinic/Entities/Patient.cs b/ProjectPolyclinic/ProjectPolyclinic/Entities/Patient.cs new file mode 100644 index 0000000..d47ecd4 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Entities/Patient.cs @@ -0,0 +1,24 @@ +namespace ProjectPolyclinic.Entities; + +public class Patient +{ + public int ID { get; private set; } + public string FirstName { get; private set; } + public string LastName { get; private set; } + public DateTime BirthDate { get; private set; } + public string Address { get; private set; } + public int MedicalCardNumber { get; private set; } + + public static Patient CreateEntity(int id, string firstName, string lastName, DateTime birthDate, string address, int medicalCardNumber) + { + return new Patient + { + ID = id, + FirstName = firstName, + LastName = lastName, + BirthDate = birthDate, + Address = address, + MedicalCardNumber = medicalCardNumber + }; + } +} diff --git a/ProjectPolyclinic/ProjectPolyclinic/Entities/Visit.cs b/ProjectPolyclinic/ProjectPolyclinic/Entities/Visit.cs new file mode 100644 index 0000000..42fe4a2 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Entities/Visit.cs @@ -0,0 +1,30 @@ +namespace ProjectPolyclinic.Entities; + +public class Visit +{ + public int Id { get; private set; } + + public DateTime Date { get; private set; } + + public int DiagnosisId { get; private set; } + + public int PatientId { get; private set; } + + public int DoctorId { get; private set; } + + public IEnumerable MedicinesVisits { get; private set; } = []; + + public static Visit CreateOperation(int id, DateTime date, int diagnosisId, int patientId, int doctorId, IEnumerable medicinesVisits) + { + return new Visit + { + Id = id, + Date = DateTime.Now, + DiagnosisId = diagnosisId, + PatientId = patientId, + DoctorId = doctorId, + MedicinesVisits = medicinesVisits + }; + } + +} diff --git a/ProjectPolyclinic/ProjectPolyclinic/Form1.Designer.cs b/ProjectPolyclinic/ProjectPolyclinic/Form1.Designer.cs deleted file mode 100644 index 9f1767d..0000000 --- a/ProjectPolyclinic/ProjectPolyclinic/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace ProjectPolyclinic -{ - partial class Form1 - { - /// - /// 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() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} diff --git a/ProjectPolyclinic/ProjectPolyclinic/FormPolyclinic.Designer.cs b/ProjectPolyclinic/ProjectPolyclinic/FormPolyclinic.Designer.cs new file mode 100644 index 0000000..4bedc5a --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/FormPolyclinic.Designer.cs @@ -0,0 +1,133 @@ +namespace ProjectPolyclinic +{ + partial class FormPolyclinic + { + /// + /// 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() + { + menuStrip1 = new MenuStrip(); + справочникиToolStripMenuItem = new ToolStripMenuItem(); + операцииToolStripMenuItem = new ToolStripMenuItem(); + отчетыToolStripMenuItem = new ToolStripMenuItem(); + врачиToolStripMenuItem = new ToolStripMenuItem(); + пациентыToolStripMenuItem = new ToolStripMenuItem(); + диагнозыToolStripMenuItem = new ToolStripMenuItem(); + медикаментыToolStripMenuItem = new ToolStripMenuItem(); + записьНаПриемToolStripMenuItem = new ToolStripMenuItem(); + menuStrip1.SuspendLayout(); + SuspendLayout(); + // + // menuStrip1 + // + menuStrip1.ImageScalingSize = new Size(20, 20); + menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, операцииToolStripMenuItem, отчетыToolStripMenuItem }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Size = new Size(782, 28); + menuStrip1.TabIndex = 0; + menuStrip1.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { врачиToolStripMenuItem, пациентыToolStripMenuItem, диагнозыToolStripMenuItem, медикаментыToolStripMenuItem }); + справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + справочникиToolStripMenuItem.Size = new Size(117, 24); + справочникиToolStripMenuItem.Text = "Справочники"; + // + // операцииToolStripMenuItem + // + операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { записьНаПриемToolStripMenuItem }); + операцииToolStripMenuItem.Name = "операцииToolStripMenuItem"; + операцииToolStripMenuItem.Size = new Size(95, 24); + операцииToolStripMenuItem.Text = "Операции"; + // + // отчетыToolStripMenuItem + // + отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; + отчетыToolStripMenuItem.Size = new Size(73, 24); + отчетыToolStripMenuItem.Text = "Отчеты"; + // + // врачиToolStripMenuItem + // + врачиToolStripMenuItem.Name = "врачиToolStripMenuItem"; + врачиToolStripMenuItem.Size = new Size(224, 26); + врачиToolStripMenuItem.Text = "Врачи"; + // + // пациентыToolStripMenuItem + // + пациентыToolStripMenuItem.Name = "пациентыToolStripMenuItem"; + пациентыToolStripMenuItem.Size = new Size(224, 26); + пациентыToolStripMenuItem.Text = "Пациенты"; + // + // диагнозыToolStripMenuItem + // + диагнозыToolStripMenuItem.Name = "диагнозыToolStripMenuItem"; + диагнозыToolStripMenuItem.Size = new Size(224, 26); + диагнозыToolStripMenuItem.Text = "Диагнозы"; + // + // медикаментыToolStripMenuItem + // + медикаментыToolStripMenuItem.Name = "медикаментыToolStripMenuItem"; + медикаментыToolStripMenuItem.Size = new Size(224, 26); + медикаментыToolStripMenuItem.Text = "Медикаменты"; + // + // записьНаПриемToolStripMenuItem + // + записьНаПриемToolStripMenuItem.Name = "записьНаПриемToolStripMenuItem"; + записьНаПриемToolStripMenuItem.Size = new Size(224, 26); + записьНаПриемToolStripMenuItem.Text = "Запись на прием"; + // + // FormPolyclinic + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + BackgroundImage = Properties.Resources.c516ff9163fefeaa5974fc7c8855cd02; + BackgroundImageLayout = ImageLayout.Stretch; + ClientSize = new Size(782, 403); + Controls.Add(menuStrip1); + MainMenuStrip = menuStrip1; + Name = "FormPolyclinic"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Поликлиника"; + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private MenuStrip menuStrip1; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem врачиToolStripMenuItem; + private ToolStripMenuItem пациентыToolStripMenuItem; + private ToolStripMenuItem диагнозыToolStripMenuItem; + private ToolStripMenuItem медикаментыToolStripMenuItem; + private ToolStripMenuItem операцииToolStripMenuItem; + private ToolStripMenuItem отчетыToolStripMenuItem; + private ToolStripMenuItem записьНаПриемToolStripMenuItem; + } +} diff --git a/ProjectPolyclinic/ProjectPolyclinic/Form1.cs b/ProjectPolyclinic/ProjectPolyclinic/FormPolyclinic.cs similarity index 55% rename from ProjectPolyclinic/ProjectPolyclinic/Form1.cs rename to ProjectPolyclinic/ProjectPolyclinic/FormPolyclinic.cs index f5c71a4..b42e1fc 100644 --- a/ProjectPolyclinic/ProjectPolyclinic/Form1.cs +++ b/ProjectPolyclinic/ProjectPolyclinic/FormPolyclinic.cs @@ -1,8 +1,8 @@ namespace ProjectPolyclinic { - public partial class Form1 : Form + public partial class FormPolyclinic : Form { - public Form1() + public FormPolyclinic() { InitializeComponent(); } diff --git a/ProjectPolyclinic/ProjectPolyclinic/FormPolyclinic.resx b/ProjectPolyclinic/ProjectPolyclinic/FormPolyclinic.resx new file mode 100644 index 0000000..a0623c8 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/FormPolyclinic.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 17, 17 + + \ No newline at end of file diff --git a/ProjectPolyclinic/ProjectPolyclinic/Forms/FormDiagnoses.Designer.cs b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormDiagnoses.Designer.cs new file mode 100644 index 0000000..38da5fe --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormDiagnoses.Designer.cs @@ -0,0 +1,119 @@ +namespace ProjectPolyclinic.Forms +{ + partial class FormDiagnoses + { + /// + /// 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() + { + panel1 = new Panel(); + buttonUpd = new Button(); + buttonDel = new Button(); + buttonAdd = new Button(); + dataGridViewDiagnoses = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewDiagnoses).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(buttonUpd); + panel1.Controls.Add(buttonDel); + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(590, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(210, 450); + panel1.TabIndex = 0; + // + // buttonUpd + // + buttonUpd.Location = new Point(56, 306); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(116, 85); + buttonUpd.TabIndex = 2; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += buttonUpd_Click; + // + // buttonDel + // + buttonDel.Location = new Point(56, 171); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(116, 86); + buttonDel.TabIndex = 1; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += buttonDel_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(56, 26); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(116, 91); + buttonAdd.TabIndex = 0; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // dataGridViewDiagnoses + // + dataGridViewDiagnoses.AllowUserToAddRows = false; + dataGridViewDiagnoses.AllowUserToDeleteRows = false; + dataGridViewDiagnoses.AllowUserToResizeColumns = false; + dataGridViewDiagnoses.AllowUserToResizeRows = false; + dataGridViewDiagnoses.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewDiagnoses.Dock = DockStyle.Fill; + dataGridViewDiagnoses.Location = new Point(0, 0); + dataGridViewDiagnoses.Name = "dataGridViewDiagnoses"; + dataGridViewDiagnoses.ReadOnly = true; + dataGridViewDiagnoses.RowHeadersWidth = 51; + dataGridViewDiagnoses.Size = new Size(590, 450); + dataGridViewDiagnoses.TabIndex = 1; + // + // FormDiagnoses + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridViewDiagnoses); + Controls.Add(panel1); + Name = "FormDiagnoses"; + Text = "Дигнозы"; + Load += FormDiagnoses_Load; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewDiagnoses).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel1; + private Button buttonUpd; + private Button buttonDel; + private Button buttonAdd; + private DataGridView dataGridViewDiagnoses; + } +} \ No newline at end of file diff --git a/ProjectPolyclinic/ProjectPolyclinic/Forms/FormDiagnoses.cs b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormDiagnoses.cs new file mode 100644 index 0000000..1e49830 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormDiagnoses.cs @@ -0,0 +1,107 @@ +using ProjectPolyclinic.Repositories; +using Unity; + +namespace ProjectPolyclinic.Forms +{ + public partial class FormDiagnoses : Form + { + private readonly IUnityContainer _container; + private readonly IDiagnosisRepository _diagnosisRepository; + + public FormDiagnoses(IUnityContainer container, IDiagnosisRepository diagnosisRepository) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + _diagnosisRepository = diagnosisRepository ?? throw new ArgumentNullException(nameof(diagnosisRepository)); + } + + private void FormDiagnoses_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonUpd_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + try + { + var form = _container.Resolve(); + form.Id = findId; + form.ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonDel_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) + { + return; + } + try + { + _diagnosisRepository.DeleteDiagnosis(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() + { + try + { + dataGridViewDiagnoses.DataSource = _diagnosisRepository.ReadDiagnosis(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке списка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridViewDiagnoses.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + id = Convert.ToInt32(dataGridViewDiagnoses.SelectedRows[0].Cells["Id"].Value); + return true; + } + } +} diff --git a/ProjectPolyclinic/ProjectPolyclinic/Form1.resx b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormDiagnoses.resx similarity index 93% rename from ProjectPolyclinic/ProjectPolyclinic/Form1.resx rename to ProjectPolyclinic/ProjectPolyclinic/Forms/FormDiagnoses.resx index 1af7de1..af32865 100644 --- a/ProjectPolyclinic/ProjectPolyclinic/Form1.resx +++ b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormDiagnoses.resx @@ -1,17 +1,17 @@  - diff --git a/ProjectPolyclinic/ProjectPolyclinic/Forms/FormDiagnosis.Designer.cs b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormDiagnosis.Designer.cs new file mode 100644 index 0000000..aff8ae8 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormDiagnosis.Designer.cs @@ -0,0 +1,95 @@ +namespace ProjectPolyclinic.Forms +{ + partial class FormDiagnosis + { + /// + /// 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() + { + buttonSave = new Button(); + buttonCancel = new Button(); + textBoxName = new TextBox(); + label1 = new Label(); + SuspendLayout(); + // + // buttonSave + // + buttonSave.Location = new Point(21, 166); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(139, 64); + buttonSave.TabIndex = 0; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(182, 166); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(150, 64); + buttonCancel.TabIndex = 1; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // textBoxName + // + textBoxName.Location = new Point(21, 75); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(311, 27); + textBoxName.TabIndex = 2; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(104, 35); + label1.Name = "label1"; + label1.Size = new Size(148, 20); + label1.TabIndex = 3; + label1.Text = "Название диагноза:"; + // + // FormDiagnosis + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(344, 289); + Controls.Add(label1); + Controls.Add(textBoxName); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Name = "FormDiagnosis"; + Text = "Диагноз"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonSave; + private Button buttonCancel; + private TextBox textBoxName; + private Label label1; + } +} \ No newline at end of file diff --git a/ProjectPolyclinic/ProjectPolyclinic/Forms/FormDiagnosis.cs b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormDiagnosis.cs new file mode 100644 index 0000000..8120741 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormDiagnosis.cs @@ -0,0 +1,68 @@ +using ProjectPolyclinic.Entities; +using ProjectPolyclinic.Repositories; + +namespace ProjectPolyclinic.Forms +{ + public partial class FormDiagnosis : Form + { + private readonly IDiagnosisRepository _diagnosisRepository; + private int? _diagnosisId; + + public int Id + { + set + { + try + { + var diagnosis = _diagnosisRepository.ReadDiagnosisById(value); + if (diagnosis == null) + { + throw new InvalidDataException(nameof(diagnosis)); + } + + textBoxName.Text = diagnosis.Name; + _diagnosisId = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + + public FormDiagnosis(IDiagnosisRepository diagnosisRepository) + { + InitializeComponent(); + _diagnosisRepository = diagnosisRepository ?? throw new ArgumentNullException(nameof(diagnosisRepository)); + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(textBoxName.Text)) + { + throw new Exception("Поле 'Название диагноза' должно быть заполнено."); + } + else + { + _diagnosisRepository.CreateDiagnosis(CreateDiagnosis(0)); + } + + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + + private Diagnosis CreateDiagnosis(int id) + { + return Diagnosis.CreateDiagnosis(id, textBoxName.Text); + } + } +} diff --git a/ProjectPolyclinic/ProjectPolyclinic/Forms/FormDiagnosis.resx b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormDiagnosis.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormDiagnosis.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/ProjectPolyclinic/ProjectPolyclinic/Forms/FormDoctor.Designer.cs b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormDoctor.Designer.cs new file mode 100644 index 0000000..eea5d8c --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormDoctor.Designer.cs @@ -0,0 +1,144 @@ +namespace ProjectPolyclinic.Forms +{ + partial class FormDoctor + { + /// + /// 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() + { + comboBoxSpecialty = new ComboBox(); + label1 = new Label(); + label2 = new Label(); + label3 = new Label(); + textBoxFirstName = new TextBox(); + textBoxLastName = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // comboBoxSpecialty + // + comboBoxSpecialty.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxSpecialty.FormattingEnabled = true; + comboBoxSpecialty.Location = new Point(137, 157); + comboBoxSpecialty.Name = "comboBoxSpecialty"; + comboBoxSpecialty.Size = new Size(196, 28); + comboBoxSpecialty.TabIndex = 0; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(12, 20); + label1.Name = "label1"; + label1.Size = new Size(42, 20); + label1.TabIndex = 1; + label1.Text = "Имя:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(12, 89); + label2.Name = "label2"; + label2.Size = new Size(76, 20); + label2.TabIndex = 2; + label2.Text = "Фамилия:"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(12, 157); + label3.Name = "label3"; + label3.Size = new Size(119, 20); + label3.TabIndex = 3; + label3.Text = "Специальность:"; + // + // textBoxFirstName + // + textBoxFirstName.Location = new Point(115, 20); + textBoxFirstName.Name = "textBoxFirstName"; + textBoxFirstName.Size = new Size(218, 27); + textBoxFirstName.TabIndex = 4; + // + // textBoxLastName + // + textBoxLastName.Location = new Point(115, 89); + textBoxLastName.Name = "textBoxLastName"; + textBoxLastName.Size = new Size(218, 27); + textBoxLastName.TabIndex = 5; + // + // buttonSave + // + buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonSave.Location = new Point(12, 211); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(141, 48); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonCancel.Location = new Point(183, 211); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(150, 48); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormDoctor + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(362, 290); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxLastName); + Controls.Add(textBoxFirstName); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(comboBoxSpecialty); + Name = "FormDoctor"; + StartPosition = FormStartPosition.CenterParent; + Text = "Доктор"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox comboBoxSpecialty; + private Label label1; + private Label label2; + private Label label3; + private TextBox textBoxFirstName; + private TextBox textBoxLastName; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/ProjectPolyclinic/ProjectPolyclinic/Forms/FormDoctor.cs b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormDoctor.cs new file mode 100644 index 0000000..86d20f9 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormDoctor.cs @@ -0,0 +1,76 @@ +using ProjectPolyclinic.Entities; +using ProjectPolyclinic.Entities.Enums; +using ProjectPolyclinic.Repositories; + +namespace ProjectPolyclinic.Forms +{ + public partial class FormDoctor : Form + { + private readonly IDoctorRepository _doctorRepository; + private int? _doctorId; + + public int Id + { + set + { + try + { + var doctor = _doctorRepository.ReadDoctorById(value); + if (doctor == null) + { + throw new InvalidDataException(nameof(doctor)); + } + textBoxFirstName.Text = doctor.FirstName; + textBoxLastName.Text = doctor.LastName; + comboBoxSpecialty.SelectedItem = doctor.DoctorSpeciality; + _doctorId = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + + public FormDoctor(IDoctorRepository doctorRepository) + { + InitializeComponent(); + _doctorRepository = doctorRepository ?? throw new ArgumentNullException(nameof(doctorRepository)); + comboBoxSpecialty.DataSource = Enum.GetValues(typeof(DoctorSpeciality)); + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(textBoxFirstName.Text) || + string.IsNullOrWhiteSpace(textBoxLastName.Text) || + comboBoxSpecialty.SelectedIndex < 0) + { + throw new Exception("Имеются незаполненные поля"); + } + + if (_doctorId.HasValue) + { + _doctorRepository.UpdateDoctor(CreateDoctor(_doctorId.Value)); + } + else + { + _doctorRepository.CreateDoctor(CreateDoctor(0)); + } + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + + private Doctor CreateDoctor(int id) => + Doctor.CreateEntity(id, textBoxFirstName.Text, textBoxLastName.Text, (DoctorSpeciality)comboBoxSpecialty.SelectedItem!); + } + +} diff --git a/ProjectPolyclinic/ProjectPolyclinic/Forms/FormDoctor.resx b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormDoctor.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormDoctor.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/ProjectPolyclinic/ProjectPolyclinic/Forms/FormDoctors.Designer.cs b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormDoctors.Designer.cs new file mode 100644 index 0000000..45dbb44 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormDoctors.Designer.cs @@ -0,0 +1,127 @@ +namespace ProjectPolyclinic.Forms +{ + partial class FormDoctors + { + /// + /// 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() + { + panel1 = new Panel(); + buttonUpd = new Button(); + buttonDel = new Button(); + buttonAdd = new Button(); + dataGridViewDoctors = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewDoctors).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(buttonUpd); + panel1.Controls.Add(buttonDel); + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(603, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(197, 450); + panel1.TabIndex = 0; + // + // buttonUpd + // + buttonUpd.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonUpd.Location = new Point(38, 257); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(119, 85); + buttonUpd.TabIndex = 2; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += buttonUpd_Click; + // + // buttonDel + // + buttonDel.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonDel.Location = new Point(38, 135); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(119, 88); + buttonDel.TabIndex = 1; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += buttonDel_Click; + // + // buttonAdd + // + buttonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAdd.Location = new Point(38, 12); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(119, 85); + buttonAdd.TabIndex = 0; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // dataGridViewDoctors + // + dataGridViewDoctors.AllowUserToAddRows = false; + dataGridViewDoctors.AllowUserToDeleteRows = false; + dataGridViewDoctors.AllowUserToResizeColumns = false; + dataGridViewDoctors.AllowUserToResizeRows = false; + dataGridViewDoctors.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewDoctors.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewDoctors.Dock = DockStyle.Fill; + dataGridViewDoctors.Location = new Point(0, 0); + dataGridViewDoctors.MultiSelect = false; + dataGridViewDoctors.Name = "dataGridViewDoctors"; + dataGridViewDoctors.ReadOnly = true; + dataGridViewDoctors.RowHeadersVisible = false; + dataGridViewDoctors.RowHeadersWidth = 51; + dataGridViewDoctors.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewDoctors.Size = new Size(603, 450); + dataGridViewDoctors.TabIndex = 1; + // + // FormDoctors + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridViewDoctors); + Controls.Add(panel1); + Name = "FormDoctors"; + StartPosition = FormStartPosition.CenterParent; + Text = "Доктора"; + Load += FormDoctors_Load; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewDoctors).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel1; + private DataGridView dataGridViewDoctors; + private Button buttonUpd; + private Button buttonDel; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/ProjectPolyclinic/ProjectPolyclinic/Forms/FormDoctors.cs b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormDoctors.cs new file mode 100644 index 0000000..0dad5a3 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormDoctors.cs @@ -0,0 +1,107 @@ +using ProjectPolyclinic.Repositories; +using Unity; + +namespace ProjectPolyclinic.Forms +{ + public partial class FormDoctors : Form + { + private readonly IUnityContainer _container; + private readonly IDoctorRepository _doctorRepository; + + public FormDoctors(IUnityContainer container, IDoctorRepository doctorRepository) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + _doctorRepository = doctorRepository ?? throw new ArgumentNullException(nameof(doctorRepository)); + } + + private void FormDoctors_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonUpd_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + try + { + var form = _container.Resolve(); + form.Id = findId; + form.ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonDel_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) + { + return; + } + try + { + _doctorRepository.DeleteDoctor(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() + { + try + { + dataGridViewDoctors.DataSource = _doctorRepository.ReadDoctor(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке списка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridViewDoctors.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + id = Convert.ToInt32(dataGridViewDoctors.SelectedRows[0].Cells["Id"].Value); + return true; + } + } +} diff --git a/ProjectPolyclinic/ProjectPolyclinic/Forms/FormDoctors.resx b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormDoctors.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormDoctors.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/ProjectPolyclinic/ProjectPolyclinic/Forms/FormMedicine.Designer.cs b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormMedicine.Designer.cs new file mode 100644 index 0000000..ef7d5c4 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormMedicine.Designer.cs @@ -0,0 +1,121 @@ +namespace ProjectPolyclinic.Forms +{ + partial class FormMedicine + { + /// + /// 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() + { + buttonSave = new Button(); + buttonCancel = new Button(); + checkedListBoxMedicinesType = new CheckedListBox(); + label1 = new Label(); + label2 = new Label(); + textBoxName = new TextBox(); + SuspendLayout(); + // + // buttonSave + // + buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonSave.Location = new Point(17, 237); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(130, 87); + buttonSave.TabIndex = 0; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonCancel.Location = new Point(236, 237); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(141, 87); + buttonCancel.TabIndex = 1; + buttonCancel.Text = "Отменить"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // checkedListBoxMedicinesType + // + checkedListBoxMedicinesType.FormattingEnabled = true; + checkedListBoxMedicinesType.Location = new Point(155, 30); + checkedListBoxMedicinesType.Name = "checkedListBoxMedicinesType"; + checkedListBoxMedicinesType.Size = new Size(233, 114); + checkedListBoxMedicinesType.TabIndex = 2; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(17, 30); + label1.Name = "label1"; + label1.Size = new Size(111, 20); + label1.TabIndex = 3; + label1.Text = "Вид лекарства:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(17, 181); + label2.Name = "label2"; + label2.Size = new Size(80, 20); + label2.TabIndex = 4; + label2.Text = "Название:"; + // + // textBoxName + // + textBoxName.Location = new Point(155, 181); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(233, 27); + textBoxName.TabIndex = 5; + // + // FormMedicine + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(398, 346); + Controls.Add(textBoxName); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(checkedListBoxMedicinesType); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Name = "FormMedicine"; + StartPosition = FormStartPosition.CenterParent; + Text = "Лекарство"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonSave; + private Button buttonCancel; + private CheckedListBox checkedListBoxMedicinesType; + private Label label1; + private Label label2; + private TextBox textBoxName; + } +} \ No newline at end of file diff --git a/ProjectPolyclinic/ProjectPolyclinic/Forms/FormMedicine.cs b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormMedicine.cs new file mode 100644 index 0000000..8a44224 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormMedicine.cs @@ -0,0 +1,97 @@ +using ProjectPolyclinic.Entities.Enums; +using ProjectPolyclinic.Entities; +using ProjectPolyclinic.Repositories; + +namespace ProjectPolyclinic.Forms +{ + public partial class FormMedicine : Form + { + private readonly IMedicinesRepository _medicinesRepository; + private int? _medicineId; + + public int Id + { + set + { + try + { + var medicine = _medicinesRepository.ReadMedicinesById(value); + if (medicine == null) + { + throw new InvalidDataException(nameof(medicine)); + } + + foreach (MedicinesType elem in Enum.GetValues(typeof(MedicinesType))) + { + if ((elem & medicine.MedicinesType) != 0) + { + checkedListBoxMedicinesType.SetItemChecked( + checkedListBoxMedicinesType.Items.IndexOf(elem), true); + } + } + + textBoxName.Text = medicine.Name; + _medicineId = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + + public FormMedicine(IMedicinesRepository medicinesRepository) + { + InitializeComponent(); + _medicinesRepository = medicinesRepository ?? throw new ArgumentNullException(nameof(medicinesRepository)); + + foreach (var elem in Enum.GetValues(typeof(MedicinesType))) + { + checkedListBoxMedicinesType.Items.Add(elem); + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(textBoxName.Text) || + checkedListBoxMedicinesType.CheckedItems.Count == 0) + { + throw new Exception("Имеются незаполненные поля"); + } + + if (_medicineId.HasValue) + { + _medicinesRepository.UpdateMedicines(CreateMedicine(_medicineId.Value)); + } + else + { + _medicinesRepository.CreateMedicines(CreateMedicine(0)); + } + + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + + private Medicines CreateMedicine(int id) + { + MedicinesType medicineType = MedicinesType.None; + + foreach (var elem in checkedListBoxMedicinesType.CheckedItems) + { + medicineType |= (MedicinesType)elem; + } + + return Medicines.CreateEntity(id, medicineType, textBoxName.Text); + } + } +} + diff --git a/ProjectPolyclinic/ProjectPolyclinic/Forms/FormMedicine.resx b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormMedicine.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormMedicine.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/ProjectPolyclinic/ProjectPolyclinic/Forms/FormMedicines.Designer.cs b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormMedicines.Designer.cs new file mode 100644 index 0000000..2c87ced --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormMedicines.Designer.cs @@ -0,0 +1,123 @@ +namespace ProjectPolyclinic.Forms +{ + partial class FormMedicines + { + /// + /// 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() + { + panel1 = new Panel(); + buttonUpd = new Button(); + buttonDel = new Button(); + buttonAdd = new Button(); + dataGridViewMedicines = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewMedicines).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(buttonUpd); + panel1.Controls.Add(buttonDel); + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(565, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(181, 424); + panel1.TabIndex = 0; + // + // buttonUpd + // + buttonUpd.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonUpd.Location = new Point(30, 277); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(118, 83); + buttonUpd.TabIndex = 2; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += buttonUpd_Click; + // + // buttonDel + // + buttonDel.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonDel.Location = new Point(30, 155); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(118, 85); + buttonDel.TabIndex = 1; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += buttonDel_Click; + // + // buttonAdd + // + buttonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAdd.Location = new Point(30, 34); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(118, 86); + buttonAdd.TabIndex = 0; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // dataGridViewMedicines + // + dataGridViewMedicines.AllowUserToAddRows = false; + dataGridViewMedicines.AllowUserToDeleteRows = false; + dataGridViewMedicines.AllowUserToResizeColumns = false; + dataGridViewMedicines.AllowUserToResizeRows = false; + dataGridViewMedicines.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewMedicines.Dock = DockStyle.Fill; + dataGridViewMedicines.Location = new Point(0, 0); + dataGridViewMedicines.Name = "dataGridViewMedicines"; + dataGridViewMedicines.ReadOnly = true; + dataGridViewMedicines.RowHeadersWidth = 51; + dataGridViewMedicines.Size = new Size(565, 424); + dataGridViewMedicines.TabIndex = 1; + // + // FormMedicines + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(746, 424); + Controls.Add(dataGridViewMedicines); + Controls.Add(panel1); + Name = "FormMedicines"; + StartPosition = FormStartPosition.CenterParent; + Text = "Лекарства"; + Load += FormMedicines_Load; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewMedicines).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel1; + private DataGridView dataGridViewMedicines; + private Button buttonUpd; + private Button buttonDel; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/ProjectPolyclinic/ProjectPolyclinic/Forms/FormMedicines.cs b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormMedicines.cs new file mode 100644 index 0000000..5f59079 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormMedicines.cs @@ -0,0 +1,107 @@ +using ProjectPolyclinic.Repositories; +using Unity; + +namespace ProjectPolyclinic.Forms +{ + public partial class FormMedicines : Form + { + private readonly IUnityContainer _container; + private readonly IMedicinesRepository _medicinesRepository; + + public FormMedicines(IUnityContainer container, IMedicinesRepository medicinesRepository) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + _medicinesRepository = medicinesRepository ?? throw new ArgumentNullException(nameof(medicinesRepository)); + } + + private void FormMedicines_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonUpd_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + try + { + var form = _container.Resolve(); + form.Id = findId; + form.ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonDel_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) + { + return; + } + try + { + _medicinesRepository.DeleteMedicines(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() + { + try + { + dataGridViewMedicines.DataSource = _medicinesRepository.ReadMedicines(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке списка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridViewMedicines.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + id = Convert.ToInt32(dataGridViewMedicines.SelectedRows[0].Cells["Id"].Value); + return true; + } + } +} diff --git a/ProjectPolyclinic/ProjectPolyclinic/Forms/FormMedicines.resx b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormMedicines.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormMedicines.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/ProjectPolyclinic/ProjectPolyclinic/Forms/FormMedicinesMoving.Designer.cs b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormMedicinesMoving.Designer.cs new file mode 100644 index 0000000..b0bd260 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormMedicinesMoving.Designer.cs @@ -0,0 +1,144 @@ +namespace ProjectPolyclinic.Forms +{ + partial class FormMedicinesMoving + { + /// + /// 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() + { + dateTimePickerData = new DateTimePicker(); + label1 = new Label(); + buttonSave = new Button(); + buttonCancel = new Button(); + comboBoxName = new ComboBox(); + label2 = new Label(); + label3 = new Label(); + comboBoxMedicinesStatement = new ComboBox(); + SuspendLayout(); + // + // dateTimePickerData + // + dateTimePickerData.Location = new Point(164, 24); + dateTimePickerData.Name = "dateTimePickerData"; + dateTimePickerData.Size = new Size(245, 27); + dateTimePickerData.TabIndex = 0; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(12, 24); + label1.Name = "label1"; + label1.Size = new Size(44, 20); + label1.TabIndex = 1; + label1.Text = "Дата:"; + // + // buttonSave + // + buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonSave.Location = new Point(18, 239); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(119, 53); + buttonSave.TabIndex = 2; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonCancel.Location = new Point(282, 239); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(127, 53); + buttonCancel.TabIndex = 3; + buttonCancel.Text = "Отменить"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // comboBoxName + // + comboBoxName.FormattingEnabled = true; + comboBoxName.Location = new Point(164, 88); + comboBoxName.Name = "comboBoxName"; + comboBoxName.Size = new Size(245, 28); + comboBoxName.TabIndex = 4; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(5, 91); + label2.Name = "label2"; + label2.Size = new Size(153, 20); + label2.TabIndex = 5; + label2.Text = "Название лекарства:"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(5, 170); + label3.Name = "label3"; + label3.Size = new Size(83, 20); + label3.TabIndex = 6; + label3.Text = "Операция:"; + // + // comboBoxMedicinesStatement + // + comboBoxMedicinesStatement.FormattingEnabled = true; + comboBoxMedicinesStatement.Location = new Point(164, 170); + comboBoxMedicinesStatement.Name = "comboBoxMedicinesStatement"; + comboBoxMedicinesStatement.Size = new Size(245, 28); + comboBoxMedicinesStatement.TabIndex = 7; + // + // FormMedicinesMoving + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(421, 320); + Controls.Add(comboBoxMedicinesStatement); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(comboBoxName); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(label1); + Controls.Add(dateTimePickerData); + Name = "FormMedicinesMoving"; + StartPosition = FormStartPosition.CenterParent; + Text = "Перемещение лекарств"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private DateTimePicker dateTimePickerData; + private Label label1; + private Button buttonSave; + private Button buttonCancel; + private ComboBox comboBoxName; + private Label label2; + private Label label3; + private ComboBox comboBoxMedicinesStatement; + } +} \ No newline at end of file diff --git a/ProjectPolyclinic/ProjectPolyclinic/Forms/FormMedicinesMoving.cs b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormMedicinesMoving.cs new file mode 100644 index 0000000..9890820 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormMedicinesMoving.cs @@ -0,0 +1,96 @@ +using ProjectPolyclinic.Entities.Enums; +using ProjectPolyclinic.Entities; +using ProjectPolyclinic.Repositories; + +namespace ProjectPolyclinic.Forms +{ + public partial class FormMedicinesMoving : Form + { + private readonly IMedicinesMovingRepository _medicinesMovingRepository; + private readonly IMedicinesRepository _medicinesRepository; + + private int? _operationId; + + public int Id + { + set + { + try + { + var medicinesMoving = _medicinesMovingRepository + .ReadMedicinesMovings() + .FirstOrDefault(m => m.Id == value); + + if (medicinesMoving == null) + { + throw new InvalidOperationException("Операция с указанным идентификатором не найдена."); + } + + dateTimePickerData.Value = medicinesMoving.Date; + comboBoxName.SelectedValue = medicinesMoving.MedicinesId; + comboBoxMedicinesStatement.SelectedValue = medicinesMoving.MedicinesStatement.FirstOrDefault(); + + _operationId = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + public FormMedicinesMoving( + IMedicinesMovingRepository medicinesMovingRepository, + IMedicinesRepository medicinesRepository) + { + InitializeComponent(); + + _medicinesMovingRepository = medicinesMovingRepository ?? throw new ArgumentNullException(nameof(medicinesMovingRepository)); + _medicinesRepository = medicinesRepository ?? throw new ArgumentNullException(nameof(medicinesRepository)); + + comboBoxName.DataSource = _medicinesRepository.ReadMedicines(); + comboBoxName.DisplayMember = "Name"; + comboBoxName.ValueMember = "Id"; + + comboBoxMedicinesStatement.DataSource = Enum.GetValues(typeof(MedicinesStatement)); + } + + private void buttonSave_Click(object sender, EventArgs e) + { + try + { + if (comboBoxName.SelectedIndex < 0 || comboBoxMedicinesStatement.SelectedIndex < 0) + { + throw new Exception("Имеются незаполненные поля."); + } + + if (!DateTime.TryParse(dateTimePickerData.Text, out var operationDate)) + { + throw new Exception("Неверный формат даты."); + } + + if (_operationId.HasValue) + { + _medicinesMovingRepository.DeleteMedicinesMoving(_operationId.Value); + } + + _medicinesMovingRepository.CreateMedicinesMoving(MedicinesMoving.CreateOperation( + _operationId ?? 0, + (int)comboBoxName.SelectedValue!, + operationDate, + new List { (MedicinesStatement)comboBoxMedicinesStatement.SelectedItem! } + )); + + MessageBox.Show("Операция успешно сохранена!", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) => Close(); + } +} diff --git a/ProjectPolyclinic/ProjectPolyclinic/Forms/FormMedicinesMoving.resx b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormMedicinesMoving.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormMedicinesMoving.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/ProjectPolyclinic/ProjectPolyclinic/Forms/FormMedicinesMovings.Designer.cs b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormMedicinesMovings.Designer.cs new file mode 100644 index 0000000..11f1338 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormMedicinesMovings.Designer.cs @@ -0,0 +1,122 @@ +namespace ProjectPolyclinic.Forms +{ + partial class FormMedicinesMovings + { + /// + /// 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() + { + panel1 = new Panel(); + buttonUpd = new Button(); + buttonDel = new Button(); + buttonAdd = new Button(); + dataGridViewMedicinesMovings = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewMedicinesMovings).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(buttonUpd); + panel1.Controls.Add(buttonDel); + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(466, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(186, 356); + panel1.TabIndex = 0; + // + // buttonUpd + // + buttonUpd.Location = new Point(24, 214); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(133, 78); + buttonUpd.TabIndex = 2; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonDel + // + buttonDel.Location = new Point(24, 114); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(133, 72); + buttonDel.TabIndex = 1; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(24, 12); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(133, 76); + buttonAdd.TabIndex = 0; + buttonAdd.Text = "Создать"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridViewMedicinesMovings + // + dataGridViewMedicinesMovings.AllowUserToAddRows = false; + dataGridViewMedicinesMovings.AllowUserToDeleteRows = false; + dataGridViewMedicinesMovings.AllowUserToResizeColumns = false; + dataGridViewMedicinesMovings.AllowUserToResizeRows = false; + dataGridViewMedicinesMovings.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewMedicinesMovings.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewMedicinesMovings.Dock = DockStyle.Fill; + dataGridViewMedicinesMovings.Location = new Point(0, 0); + dataGridViewMedicinesMovings.MultiSelect = false; + dataGridViewMedicinesMovings.Name = "dataGridViewMedicinesMovings"; + dataGridViewMedicinesMovings.ReadOnly = true; + dataGridViewMedicinesMovings.RowHeadersWidth = 51; + dataGridViewMedicinesMovings.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewMedicinesMovings.Size = new Size(466, 356); + dataGridViewMedicinesMovings.TabIndex = 1; + dataGridViewMedicinesMovings.Click += FormMedicinesMovings_Load; + // + // FormMedicinesMovings + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(652, 356); + Controls.Add(dataGridViewMedicinesMovings); + Controls.Add(panel1); + Name = "FormMedicinesMovings"; + Text = "Перемещения лекарств"; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewMedicinesMovings).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel1; + private DataGridView dataGridViewMedicinesMovings; + private Button buttonUpd; + private Button buttonDel; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/ProjectPolyclinic/ProjectPolyclinic/Forms/FormMedicinesMovings.cs b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormMedicinesMovings.cs new file mode 100644 index 0000000..7e67091 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormMedicinesMovings.cs @@ -0,0 +1,107 @@ +using ProjectPolyclinic.Repositories; +using Unity; + +namespace ProjectPolyclinic.Forms +{ + public partial class FormMedicinesMovings : Form + { + private readonly IUnityContainer _container; + private readonly IMedicinesMovingRepository _medicinesMovingRepository; + + public FormMedicinesMovings(IUnityContainer container, IMedicinesMovingRepository medicinesMovingRepository) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + _medicinesMovingRepository = medicinesMovingRepository ?? throw new ArgumentNullException(nameof(medicinesMovingRepository)); + } + + private void FormMedicinesMovings_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var movingId)) + { + return; + } + try + { + var form = _container.Resolve(); + form.Id = movingId; + form.ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var movingId)) + { + return; + } + if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) + { + return; + } + try + { + _medicinesMovingRepository.DeleteMedicinesMoving(movingId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() + { + try + { + dataGridViewMedicinesMovings.DataSource = _medicinesMovingRepository.ReadMedicinesMovings(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке списка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridViewMedicinesMovings.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + id = Convert.ToInt32(dataGridViewMedicinesMovings.SelectedRows[0].Cells["Id"].Value); + return true; + } + } +} diff --git a/ProjectPolyclinic/ProjectPolyclinic/Forms/FormMedicinesMovings.resx b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormMedicinesMovings.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormMedicinesMovings.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/ProjectPolyclinic/ProjectPolyclinic/Forms/FormPatient.Designer.cs b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormPatient.Designer.cs new file mode 100644 index 0000000..d94d73c --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormPatient.Designer.cs @@ -0,0 +1,189 @@ +namespace ProjectPolyclinic.Forms +{ + partial class FormPatient + { + /// + /// 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() + { + label1 = new Label(); + textBoxFirstName = new TextBox(); + label2 = new Label(); + textBoxLastName = new TextBox(); + label3 = new Label(); + textBoxAddress = new TextBox(); + label4 = new Label(); + label5 = new Label(); + textBoxMedicalCardNumber = new MaskedTextBox(); + button1 = new Button(); + button2 = new Button(); + dateTimePicker1 = new DateTimePicker(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(30, 33); + label1.Name = "label1"; + label1.Size = new Size(42, 20); + label1.TabIndex = 0; + label1.Text = "Имя:"; + // + // textBoxFirstName + // + textBoxFirstName.Location = new Point(103, 30); + textBoxFirstName.Name = "textBoxFirstName"; + textBoxFirstName.Size = new Size(235, 27); + textBoxFirstName.TabIndex = 1; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(18, 119); + label2.Name = "label2"; + label2.Size = new Size(76, 20); + label2.TabIndex = 2; + label2.Text = "Фамилия:"; + // + // textBoxLastName + // + textBoxLastName.Location = new Point(125, 116); + textBoxLastName.Name = "textBoxLastName"; + textBoxLastName.Size = new Size(213, 27); + textBoxLastName.TabIndex = 3; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(12, 199); + label3.Name = "label3"; + label3.Size = new Size(119, 20); + label3.TabIndex = 4; + label3.Text = "Дата рождения:"; + // + // textBoxAddress + // + textBoxAddress.Location = new Point(75, 270); + textBoxAddress.Name = "textBoxAddress"; + textBoxAddress.Size = new Size(263, 27); + textBoxAddress.TabIndex = 6; + // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(18, 273); + label4.Name = "label4"; + label4.Size = new Size(51, 20); + label4.TabIndex = 7; + label4.Text = "Адрес"; + // + // label5 + // + label5.AutoSize = true; + label5.Location = new Point(18, 345); + label5.Name = "label5"; + label5.Size = new Size(135, 20); + label5.TabIndex = 8; + label5.Text = "Номер мед.карты:"; + // + // textBoxMedicalCardNumber + // + textBoxMedicalCardNumber.Location = new Point(171, 338); + textBoxMedicalCardNumber.Mask = "00000"; + textBoxMedicalCardNumber.Name = "textBoxMedicalCardNumber"; + textBoxMedicalCardNumber.Size = new Size(104, 27); + textBoxMedicalCardNumber.TabIndex = 10; + textBoxMedicalCardNumber.ValidatingType = typeof(int); + // + // button1 + // + button1.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + button1.Location = new Point(18, 397); + button1.Name = "button1"; + button1.Size = new Size(114, 41); + button1.TabIndex = 11; + button1.Text = "Сохранить"; + button1.UseVisualStyleBackColor = true; + button1.Click += ButtonSave_Click; + // + // button2 + // + button2.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + button2.Location = new Point(221, 397); + button2.Name = "button2"; + button2.Size = new Size(117, 41); + button2.TabIndex = 12; + button2.Text = "Отмена"; + button2.UseVisualStyleBackColor = true; + button2.Click += ButtonCancel_Click; + // + // dateTimePicker1 + // + dateTimePicker1.Location = new Point(137, 194); + dateTimePicker1.Name = "dateTimePicker1"; + dateTimePicker1.Size = new Size(201, 27); + dateTimePicker1.TabIndex = 13; + // + // FormPatient + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(350, 463); + Controls.Add(dateTimePicker1); + Controls.Add(button2); + Controls.Add(button1); + Controls.Add(textBoxMedicalCardNumber); + Controls.Add(label5); + Controls.Add(label4); + Controls.Add(textBoxAddress); + Controls.Add(label3); + Controls.Add(textBoxLastName); + Controls.Add(label2); + Controls.Add(textBoxFirstName); + Controls.Add(label1); + Name = "FormPatient"; + StartPosition = FormStartPosition.CenterParent; + Text = "Пациент"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private TextBox textBoxFirstName; + private Label label2; + private TextBox textBoxLastName; + private Label label3; + private MaskedTextBox dateTimePickerBirthDate; + private TextBox textBoxAddress; + private Label label4; + private Label label5; + private MaskedTextBox textBoxMedicalCardNumber; + private Button button1; + private Button button2; + private DateTimePicker dateTimePicker1; + } +} \ No newline at end of file diff --git a/ProjectPolyclinic/ProjectPolyclinic/Forms/FormPatient.cs b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormPatient.cs new file mode 100644 index 0000000..9359004 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormPatient.cs @@ -0,0 +1,87 @@ +using ProjectPolyclinic.Entities; +using ProjectPolyclinic.Repositories; + +namespace ProjectPolyclinic.Forms +{ + public partial class FormPatient : Form + { + private readonly IPatientRepository _patientRepository; + private int? _patientId; + + public int Id + { + set + { + try + { + var patient = _patientRepository.ReadPatientById(value); + if (patient == null) + { + throw new InvalidDataException(nameof(patient)); + } + textBoxFirstName.Text = patient.FirstName; + textBoxLastName.Text = patient.LastName; + dateTimePicker1.Value = patient.BirthDate; + textBoxAddress.Text = patient.Address; + textBoxMedicalCardNumber.Text = patient.MedicalCardNumber.ToString(); + _patientId = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + + public FormPatient(IPatientRepository patientRepository) + { + InitializeComponent(); + _patientRepository = patientRepository ?? throw new ArgumentNullException(nameof(patientRepository)); + + dateTimePicker1.MaxDate = DateTime.Today; + dateTimePicker1.MinDate = new DateTime(1900, 1, 1); + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(textBoxFirstName.Text) || + string.IsNullOrWhiteSpace(textBoxLastName.Text) || + string.IsNullOrWhiteSpace(textBoxAddress.Text) || + string.IsNullOrWhiteSpace(textBoxMedicalCardNumber.Text)) + { + throw new Exception("Имеются незаполненные поля"); + } + + var birthDate = dateTimePicker1.Value; + + if (_patientId.HasValue) + { + _patientRepository.UpdatePatient(CreatePatient(_patientId.Value, birthDate)); + } + else + { + _patientRepository.CreatePatient(CreatePatient(0, birthDate)); + } + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + + private Patient CreatePatient(int id, DateTime birthDate) => Patient.CreateEntity( + id, + textBoxFirstName.Text, + textBoxLastName.Text, + birthDate, + textBoxAddress.Text, + int.Parse(textBoxMedicalCardNumber.Text) + ); + } +} diff --git a/ProjectPolyclinic/ProjectPolyclinic/Forms/FormPatient.resx b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormPatient.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormPatient.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/ProjectPolyclinic/ProjectPolyclinic/Forms/FormPatients.Designer.cs b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormPatients.Designer.cs new file mode 100644 index 0000000..02092b3 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormPatients.Designer.cs @@ -0,0 +1,152 @@ +namespace ProjectPolyclinic.Forms +{ + partial class FormPatients + { + /// + /// 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() + { + panel1 = new Panel(); + ButtonUpd = new Button(); + ButtonDel = new Button(); + ButtonAdd = new Button(); + dataGridViewData = new DataGridView(); + dataGridView1 = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit(); + ((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(ButtonUpd); + panel1.Controls.Add(ButtonDel); + panel1.Controls.Add(ButtonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(564, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(178, 450); + panel1.TabIndex = 0; + // + // ButtonUpd + // + ButtonUpd.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + ButtonUpd.Location = new Point(29, 283); + ButtonUpd.Name = "ButtonUpd"; + ButtonUpd.Size = new Size(124, 78); + ButtonUpd.TabIndex = 2; + ButtonUpd.Text = "Изменить"; + ButtonUpd.UseVisualStyleBackColor = true; + ButtonUpd.Click += ButtonUpd_Click; + // + // ButtonDel + // + ButtonDel.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + ButtonDel.Location = new Point(29, 160); + ButtonDel.Name = "ButtonDel"; + ButtonDel.Size = new Size(124, 81); + ButtonDel.TabIndex = 1; + ButtonDel.Text = "Удалить"; + ButtonDel.UseVisualStyleBackColor = true; + ButtonDel.Click += ButtonDel_Click; + // + // ButtonAdd + // + ButtonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + ButtonAdd.BackgroundImageLayout = ImageLayout.Center; + ButtonAdd.Location = new Point(29, 40); + ButtonAdd.Name = "ButtonAdd"; + ButtonAdd.Size = new Size(124, 75); + ButtonAdd.TabIndex = 0; + ButtonAdd.Text = "Добавить"; + ButtonAdd.UseVisualStyleBackColor = true; + ButtonAdd.Click += ButtonAdd_Click; + // + // dataGridViewData + // + dataGridViewData.AllowUserToAddRows = false; + dataGridViewData.AllowUserToDeleteRows = false; + dataGridViewData.AllowUserToResizeColumns = false; + dataGridViewData.AllowUserToResizeRows = false; + dataGridViewData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewData.Dock = DockStyle.Fill; + dataGridViewData.Location = new Point(0, 0); + dataGridViewData.MultiSelect = false; + dataGridViewData.Name = "dataGridViewData"; + dataGridViewData.ReadOnly = true; + dataGridViewData.RowHeadersVisible = false; + dataGridViewData.RowHeadersWidth = 51; + dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewData.Size = new Size(564, 450); + dataGridViewData.TabIndex = 1; + // + // dataGridView1 + // + dataGridView1.AllowUserToAddRows = false; + dataGridView1.AllowUserToDeleteRows = false; + dataGridView1.AllowUserToResizeColumns = false; + dataGridView1.AllowUserToResizeRows = false; + dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView1.Dock = DockStyle.Fill; + dataGridView1.Location = new Point(0, 0); + dataGridView1.MultiSelect = false; + dataGridView1.Name = "dataGridView1"; + dataGridView1.ReadOnly = true; + dataGridView1.RowHeadersVisible = false; + dataGridView1.RowHeadersWidth = 51; + dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView1.Size = new Size(564, 450); + dataGridView1.TabIndex = 2; + // + // FormPatients + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(742, 450); + Controls.Add(dataGridView1); + Controls.Add(dataGridViewData); + Controls.Add(panel1); + Name = "FormPatients"; + StartPosition = FormStartPosition.CenterParent; + Text = "Пациенты"; + Load += FormPatients_Load; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit(); + ((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel1; + private Button ButtonUpd; + private Button ButtonDel; + private Button ButtonAdd; + private DataGridView dataGridViewData; + private DataGridView dataGridView1; + } +} \ No newline at end of file diff --git a/ProjectPolyclinic/ProjectPolyclinic/Forms/FormPatients.cs b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormPatients.cs new file mode 100644 index 0000000..f22ddc0 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormPatients.cs @@ -0,0 +1,108 @@ +using ProjectPolyclinic.Repositories; +using Unity; + +namespace ProjectPolyclinic.Forms +{ + public partial class FormPatients : Form + { + private readonly IUnityContainer _container; + private readonly IPatientRepository _patientRepository; + + public FormPatients(IUnityContainer container, IPatientRepository patientRepository) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + _patientRepository = patientRepository ?? throw new ArgumentNullException(nameof(patientRepository)); + } + + private void FormPatients_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + try + { + var form = _container.Resolve(); + form.Id = findId; + form.ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) + { + return; + } + try + { + _patientRepository.DeletePatient(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() + { + try + { + dataGridViewData.DataSource = _patientRepository.ReadPatient(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке списка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridViewData.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + id = Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["Id"].Value); + return true; + } + } + +} diff --git a/ProjectPolyclinic/ProjectPolyclinic/Forms/FormPatients.resx b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormPatients.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormPatients.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/ProjectPolyclinic/ProjectPolyclinic/Forms/FormVisit.Designer.cs b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormVisit.Designer.cs new file mode 100644 index 0000000..5a929e3 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormVisit.Designer.cs @@ -0,0 +1,221 @@ +namespace ProjectPolyclinic.Forms +{ + partial class FormVisit + { + /// + /// 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() + { + dateTimePicker1 = new DateTimePicker(); + label1 = new Label(); + label2 = new Label(); + label3 = new Label(); + comboBoxDiagnosis = new ComboBox(); + comboBoxPatient = new ComboBox(); + comboBoxDoctor = new ComboBox(); + label4 = new Label(); + buttonSave = new Button(); + buttonCancel = new Button(); + groupBoxMedicines = new GroupBox(); + dataGridViewMedicines = new DataGridView(); + ColumnMedicine = new DataGridViewComboBoxColumn(); + ColumnQuantity = new DataGridViewTextBoxColumn(); + groupBoxMedicines.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewMedicines).BeginInit(); + SuspendLayout(); + // + // dateTimePicker1 + // + dateTimePicker1.Location = new Point(132, 24); + dateTimePicker1.Name = "dateTimePicker1"; + dateTimePicker1.Size = new Size(250, 27); + dateTimePicker1.TabIndex = 0; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(12, 24); + label1.Name = "label1"; + label1.Size = new Size(41, 20); + label1.TabIndex = 1; + label1.Text = "Дата"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(12, 103); + label2.Name = "label2"; + label2.Size = new Size(67, 20); + label2.TabIndex = 2; + label2.Text = "Диагноз"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(12, 186); + label3.Name = "label3"; + label3.Size = new Size(69, 20); + label3.TabIndex = 3; + label3.Text = "Пациент"; + // + // comboBoxDiagnosis + // + comboBoxDiagnosis.FormattingEnabled = true; + comboBoxDiagnosis.Location = new Point(132, 103); + comboBoxDiagnosis.Name = "comboBoxDiagnosis"; + comboBoxDiagnosis.Size = new Size(250, 28); + comboBoxDiagnosis.TabIndex = 4; + // + // comboBoxPatient + // + comboBoxPatient.FormattingEnabled = true; + comboBoxPatient.Location = new Point(132, 186); + comboBoxPatient.Name = "comboBoxPatient"; + comboBoxPatient.Size = new Size(250, 28); + comboBoxPatient.TabIndex = 5; + // + // comboBoxDoctor + // + comboBoxDoctor.FormattingEnabled = true; + comboBoxDoctor.Location = new Point(132, 271); + comboBoxDoctor.Name = "comboBoxDoctor"; + comboBoxDoctor.Size = new Size(250, 28); + comboBoxDoctor.TabIndex = 6; + // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(12, 279); + label4.Name = "label4"; + label4.Size = new Size(43, 20); + label4.TabIndex = 7; + label4.Text = "Врач"; + // + // buttonSave + // + buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonSave.Location = new Point(12, 580); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(156, 52); + buttonSave.TabIndex = 8; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonCancel.Location = new Point(220, 580); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(162, 52); + buttonCancel.TabIndex = 9; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // groupBoxMedicines + // + groupBoxMedicines.Controls.Add(dataGridViewMedicines); + groupBoxMedicines.Location = new Point(12, 358); + groupBoxMedicines.Name = "groupBoxMedicines"; + groupBoxMedicines.Size = new Size(370, 197); + groupBoxMedicines.TabIndex = 10; + groupBoxMedicines.TabStop = false; + groupBoxMedicines.Text = "Лекарства"; + // + // dataGridViewMedicines + // + dataGridViewMedicines.AllowUserToResizeColumns = false; + dataGridViewMedicines.AllowUserToResizeRows = false; + dataGridViewMedicines.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + dataGridViewMedicines.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewMedicines.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewMedicines.Columns.AddRange(new DataGridViewColumn[] { ColumnMedicine, ColumnQuantity }); + dataGridViewMedicines.Location = new Point(3, 23); + dataGridViewMedicines.MultiSelect = false; + dataGridViewMedicines.Name = "dataGridViewMedicines"; + dataGridViewMedicines.RowHeadersVisible = false; + dataGridViewMedicines.RowHeadersWidth = 51; + dataGridViewMedicines.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewMedicines.Size = new Size(364, 171); + dataGridViewMedicines.TabIndex = 0; + // + // ColumnMedicine + // + ColumnMedicine.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnMedicine.HeaderText = "Лекарство"; + ColumnMedicine.MinimumWidth = 6; + ColumnMedicine.Name = "ColumnMedicine"; + // + // ColumnQuantity + // + ColumnQuantity.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnQuantity.HeaderText = "Количество"; + ColumnQuantity.MinimumWidth = 6; + ColumnQuantity.Name = "ColumnQuantity"; + // + // FormVisit + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(410, 660); + Controls.Add(groupBoxMedicines); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(label4); + Controls.Add(comboBoxDoctor); + Controls.Add(comboBoxPatient); + Controls.Add(comboBoxDiagnosis); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(dateTimePicker1); + Name = "FormVisit"; + StartPosition = FormStartPosition.CenterParent; + Text = "Запись на прием"; + groupBoxMedicines.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewMedicines).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private DateTimePicker dateTimePicker1; + private Label label1; + private Label label2; + private Label label3; + private ComboBox comboBoxDiagnosis; + private ComboBox comboBoxPatient; + private ComboBox comboBoxDoctor; + private Label label4; + private Button buttonSave; + private Button buttonCancel; + private GroupBox groupBoxMedicines; + private DataGridView dataGridViewMedicines; + private DataGridViewComboBoxColumn ColumnMedicine; + private DataGridViewTextBoxColumn ColumnQuantity; + } +} \ No newline at end of file diff --git a/ProjectPolyclinic/ProjectPolyclinic/Forms/FormVisit.cs b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormVisit.cs new file mode 100644 index 0000000..7ff2bef --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormVisit.cs @@ -0,0 +1,152 @@ +using ProjectPolyclinic.Entities; +using ProjectPolyclinic.Repositories; +using System.Data; + +namespace ProjectPolyclinic.Forms +{ + public partial class FormVisit : Form + { + private readonly IVisitRepository _visitRepository; + private readonly IDiagnosisRepository _diagnosisRepository; + private readonly IPatientRepository _patientRepository; + private readonly IDoctorRepository _doctorRepository; + private readonly IMedicinesRepository _medicinesRepository; + + private int? _visitId; + + public int Id + { + set + { + try + { + var visitList = _visitRepository.ReadVisit(date: null, diagnosisId: null, patientId: null, doctorId: null) + .Where(v => v.Id == value).ToList(); + + var visit = visitList.FirstOrDefault(); + + if (visit == null) + { + throw new InvalidOperationException("Визит с указанным идентификатором не найден."); + } + + dateTimePicker1.Value = visit.Date; + comboBoxDiagnosis.SelectedValue = visit.DiagnosisId; + comboBoxPatient.SelectedValue = visit.PatientId; + comboBoxDoctor.SelectedValue = visit.DoctorId; + + dataGridViewMedicines.Rows.Clear(); + foreach (var medicineVisit in visit.MedicinesVisits) + { + dataGridViewMedicines.Rows.Add( + medicineVisit.MedicinesId, + medicineVisit.Quantity + ); + } + + _visitId = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + public FormVisit( + IVisitRepository visitRepository, + IDiagnosisRepository diagnosisRepository, + IPatientRepository patientRepository, + IDoctorRepository doctorRepository, + IMedicinesRepository medicinesRepository) + { + InitializeComponent(); + + _visitRepository = visitRepository ?? throw new ArgumentNullException(nameof(visitRepository)); + _diagnosisRepository = diagnosisRepository ?? throw new ArgumentNullException(nameof(diagnosisRepository)); + _patientRepository = patientRepository ?? throw new ArgumentNullException(nameof(patientRepository)); + _doctorRepository = doctorRepository ?? throw new ArgumentNullException(nameof(doctorRepository)); + _medicinesRepository = medicinesRepository ?? throw new ArgumentNullException(nameof(medicinesRepository)); + + comboBoxDiagnosis.DataSource = _diagnosisRepository.ReadDiagnosis(); + comboBoxDiagnosis.DisplayMember = "Name"; + comboBoxDiagnosis.ValueMember = "Id"; + + comboBoxPatient.DataSource = _patientRepository.ReadPatient(); + comboBoxPatient.DisplayMember = "Name"; + comboBoxPatient.ValueMember = "Id"; + + comboBoxDoctor.DataSource = _doctorRepository.ReadDoctor(); + comboBoxDoctor.DisplayMember = "Name"; + comboBoxDoctor.ValueMember = "Id"; + + ColumnMedicine.DataSource = _medicinesRepository.ReadMedicines(); + ColumnMedicine.DisplayMember = "Name"; + ColumnMedicine.ValueMember = "Id"; + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (comboBoxDiagnosis.SelectedIndex < 0 || + comboBoxPatient.SelectedIndex < 0 || + comboBoxDoctor.SelectedIndex < 0 || + dataGridViewMedicines.RowCount < 1) + { + throw new Exception("Имеются незаполненные поля."); + } + + if (!DateTime.TryParse(dateTimePicker1.Text, out var visitDate)) + { + throw new Exception("Неверный формат даты."); + } + + if (_visitId.HasValue) + { + _visitRepository.DeleteVisit(_visitId.Value); + } + + _visitRepository.CreateVisit(Visit.CreateOperation( + _visitId ?? 0, + visitDate, + (int)comboBoxDiagnosis.SelectedValue!, + (int)comboBoxPatient.SelectedValue!, + (int)comboBoxDoctor.SelectedValue!, + CreateListMedicinesVisitsFromDataGrid() + )); + + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + + private List CreateListMedicinesVisitsFromDataGrid() + { + var list = new List(); + + foreach (DataGridViewRow row in dataGridViewMedicines.Rows) + { + if (row.Cells["ColumnMedicine"].Value == null || + row.Cells["ColumnQuantity"].Value == null) + { + continue; + } + + list.Add(MedicinesVisit.CreateElement( + 0, + _visitId ?? 0, + Convert.ToInt32(row.Cells["ColumnMedicine"].Value), + Convert.ToInt32(row.Cells["ColumnQuantity"].Value) + )); + } + + return list; + } + } +} diff --git a/ProjectPolyclinic/ProjectPolyclinic/Forms/FormVisit.resx b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormVisit.resx new file mode 100644 index 0000000..a1bf26f --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormVisit.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + True + + + True + + \ No newline at end of file diff --git a/ProjectPolyclinic/ProjectPolyclinic/Forms/FormVisits.Designer.cs b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormVisits.Designer.cs new file mode 100644 index 0000000..f79fa5f --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormVisits.Designer.cs @@ -0,0 +1,123 @@ +namespace ProjectPolyclinic.Forms +{ + partial class FormVisits + { + /// + /// 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() + { + panel1 = new Panel(); + buttonUpd = new Button(); + buttonDel = new Button(); + buttonAdd = new Button(); + dataGridView1 = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(buttonUpd); + panel1.Controls.Add(buttonDel); + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(513, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(201, 443); + panel1.TabIndex = 0; + // + // buttonUpd + // + buttonUpd.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonUpd.Location = new Point(31, 266); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(146, 102); + buttonUpd.TabIndex = 2; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonDel + // + buttonDel.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonDel.Location = new Point(31, 140); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(146, 91); + buttonDel.TabIndex = 1; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonAdd + // + buttonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAdd.Location = new Point(31, 22); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(146, 86); + buttonAdd.TabIndex = 0; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridView1 + // + dataGridView1.AllowUserToAddRows = false; + dataGridView1.AllowUserToDeleteRows = false; + dataGridView1.AllowUserToResizeColumns = false; + dataGridView1.AllowUserToResizeRows = false; + dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView1.Dock = DockStyle.Fill; + dataGridView1.Location = new Point(0, 0); + dataGridView1.Name = "dataGridView1"; + dataGridView1.ReadOnly = true; + dataGridView1.RowHeadersWidth = 51; + dataGridView1.Size = new Size(513, 443); + dataGridView1.TabIndex = 1; + // + // FormVisits + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(714, 443); + Controls.Add(dataGridView1); + Controls.Add(panel1); + Name = "FormVisits"; + StartPosition = FormStartPosition.CenterParent; + Text = "Записи на прием"; + Load += FormVisits_Load; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel1; + private Button buttonUpd; + private Button buttonDel; + private Button buttonAdd; + private DataGridView dataGridView1; + } +} \ No newline at end of file diff --git a/ProjectPolyclinic/ProjectPolyclinic/Forms/FormVisits.cs b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormVisits.cs new file mode 100644 index 0000000..910605a --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormVisits.cs @@ -0,0 +1,107 @@ +using ProjectPolyclinic.Repositories; +using Unity; + +namespace ProjectPolyclinic.Forms +{ + public partial class FormVisits : Form + { + private readonly IUnityContainer _container; + private readonly IVisitRepository _visitRepository; + + public FormVisits(IUnityContainer container, IVisitRepository visitRepository) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + _visitRepository = visitRepository ?? throw new ArgumentNullException(nameof(visitRepository)); + } + + private void FormVisits_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var visitId)) + { + return; + } + try + { + var form = _container.Resolve(); + form.Id = visitId; + form.ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var visitId)) + { + return; + } + if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) + { + return; + } + try + { + _visitRepository.DeleteVisit(visitId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() + { + try + { + dataGridView1.DataSource = _visitRepository.ReadVisit(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке списка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridView1.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value); + return true; + } + } +} diff --git a/ProjectPolyclinic/ProjectPolyclinic/Forms/FormVisits.resx b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormVisits.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Forms/FormVisits.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/ProjectPolyclinic/ProjectPolyclinic/Program.cs b/ProjectPolyclinic/ProjectPolyclinic/Program.cs index 86d17b9..d51215e 100644 --- a/ProjectPolyclinic/ProjectPolyclinic/Program.cs +++ b/ProjectPolyclinic/ProjectPolyclinic/Program.cs @@ -1,3 +1,7 @@ +using ProjectPolyclinic.Repositories; +using ProjectPolyclinic.Repositories.Implementations; +using Unity; + namespace ProjectPolyclinic { internal static class Program @@ -11,7 +15,21 @@ namespace ProjectPolyclinic // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + Application.Run(CreateContainer().Resolve()); + } + + private static IUnityContainer CreateContainer() + { + var container = new UnityContainer(); + + container.RegisterType(); + container.RegisterType(); + container.RegisterType(); + container.RegisterType(); + container.RegisterType(); + container.RegisterType(); + + return container; } } } \ No newline at end of file diff --git a/ProjectPolyclinic/ProjectPolyclinic/ProjectPolyclinic.csproj b/ProjectPolyclinic/ProjectPolyclinic/ProjectPolyclinic.csproj index 663fdb8..accbdf0 100644 --- a/ProjectPolyclinic/ProjectPolyclinic/ProjectPolyclinic.csproj +++ b/ProjectPolyclinic/ProjectPolyclinic/ProjectPolyclinic.csproj @@ -8,4 +8,23 @@ enable + + + + + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + \ No newline at end of file diff --git a/ProjectPolyclinic/ProjectPolyclinic/Properties/Resources.Designer.cs b/ProjectPolyclinic/ProjectPolyclinic/Properties/Resources.Designer.cs new file mode 100644 index 0000000..0036aeb --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Properties/Resources.Designer.cs @@ -0,0 +1,93 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace ProjectPolyclinic.Properties { + using System; + + + /// + /// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д. + /// + // Этот класс создан автоматически классом StronglyTypedResourceBuilder + // с помощью такого средства, как ResGen или Visual Studio. + // Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen + // с параметром /str или перестройте свой проект VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ProjectPolyclinic.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Перезаписывает свойство CurrentUICulture текущего потока для всех + /// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap c516ff9163fefeaa5974fc7c8855cd02 { + get { + object obj = ResourceManager.GetObject("c516ff9163fefeaa5974fc7c8855cd02", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap Fairytale_button_add_svg { + get { + object obj = ResourceManager.GetObject("Fairytale_button_add.svg", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap Fairytale_button_add1 { + get { + object obj = ResourceManager.GetObject("Fairytale_button_add1", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/ProjectPolyclinic/ProjectPolyclinic/Properties/Resources.resx b/ProjectPolyclinic/ProjectPolyclinic/Properties/Resources.resx new file mode 100644 index 0000000..181f258 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Properties/Resources.resx @@ -0,0 +1,136 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + + ..\Resources\c516ff9163fefeaa5974fc7c8855cd02.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\unnamed1.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\Fairytale_button_add.svg.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\Fairytale_button_add.svg.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\195-1956806_abort-delete-cancel-icon-cross-no-access-denied.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file diff --git a/ProjectPolyclinic/ProjectPolyclinic/Repositories/IDiagnosisRepository.cs b/ProjectPolyclinic/ProjectPolyclinic/Repositories/IDiagnosisRepository.cs new file mode 100644 index 0000000..af52153 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Repositories/IDiagnosisRepository.cs @@ -0,0 +1,16 @@ +using ProjectPolyclinic.Entities; + +namespace ProjectPolyclinic.Repositories; + +public interface IDiagnosisRepository +{ + IEnumerable ReadDiagnosis(); + + Diagnosis ReadDiagnosisById(int id); + + void CreateDiagnosis(Diagnosis diagnosis); + + void UpdaterDiagnosis(Diagnosis diagnosis); + + void DeleteDiagnosis(int id); +} diff --git a/ProjectPolyclinic/ProjectPolyclinic/Repositories/IDoctorRepository.cs b/ProjectPolyclinic/ProjectPolyclinic/Repositories/IDoctorRepository.cs new file mode 100644 index 0000000..6b24de0 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Repositories/IDoctorRepository.cs @@ -0,0 +1,16 @@ +using ProjectPolyclinic.Entities; + +namespace ProjectPolyclinic.Repositories; + +public interface IDoctorRepository +{ + IEnumerable ReadDoctor(); + + Doctor ReadDoctorById(int id); + + void CreateDoctor(Doctor doctor); + + void UpdateDoctor(Doctor doctor); + + void DeleteDoctor(int id); +} diff --git a/ProjectPolyclinic/ProjectPolyclinic/Repositories/IMedicinesMovingRepository.cs b/ProjectPolyclinic/ProjectPolyclinic/Repositories/IMedicinesMovingRepository.cs new file mode 100644 index 0000000..73615c1 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Repositories/IMedicinesMovingRepository.cs @@ -0,0 +1,14 @@ +using ProjectPolyclinic.Entities; + +namespace ProjectPolyclinic.Repositories; + +public interface IMedicinesMovingRepository +{ + void CreateMedicinesMoving(MedicinesMoving medicinesMoving); + + IEnumerable ReadMedicinesMovings(int? medicinesId = null, DateTime? date = null); + + void UpdateMedicinesMoving(MedicinesMoving medicinesMoving); + + void DeleteMedicinesMoving(int id); +} diff --git a/ProjectPolyclinic/ProjectPolyclinic/Repositories/IMedicinesRepository.cs b/ProjectPolyclinic/ProjectPolyclinic/Repositories/IMedicinesRepository.cs new file mode 100644 index 0000000..3feebff --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Repositories/IMedicinesRepository.cs @@ -0,0 +1,16 @@ +using ProjectPolyclinic.Entities; + +namespace ProjectPolyclinic.Repositories; + +public interface IMedicinesRepository +{ + IEnumerable ReadMedicines(); + + Medicines ReadMedicinesById(int id); + + void CreateMedicines(Medicines medicines); + + void UpdateMedicines(Medicines medicines); + + void DeleteMedicines(int id); +} diff --git a/ProjectPolyclinic/ProjectPolyclinic/Repositories/IPatientRepository.cs b/ProjectPolyclinic/ProjectPolyclinic/Repositories/IPatientRepository.cs new file mode 100644 index 0000000..013fc52 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Repositories/IPatientRepository.cs @@ -0,0 +1,16 @@ +using ProjectPolyclinic.Entities; + +namespace ProjectPolyclinic.Repositories; + +public interface IPatientRepository +{ + IEnumerable ReadPatient(); + + Patient ReadPatientById(int id); + + void CreatePatient(Patient patient); + + void UpdatePatient(Patient patient); + + void DeletePatient(int id); +} diff --git a/ProjectPolyclinic/ProjectPolyclinic/Repositories/IVisitRepository.cs b/ProjectPolyclinic/ProjectPolyclinic/Repositories/IVisitRepository.cs new file mode 100644 index 0000000..55daa74 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Repositories/IVisitRepository.cs @@ -0,0 +1,12 @@ +using ProjectPolyclinic.Entities; + +namespace ProjectPolyclinic.Repositories; + +public interface IVisitRepository +{ + IEnumerable ReadVisit(DateTime? date = null, int? diagnosisId = null, int? patientId = null, int? doctorId = null); + + void CreateVisit(Visit visit); + + void DeleteVisit(int id); +} diff --git a/ProjectPolyclinic/ProjectPolyclinic/Repositories/Implementations/DiagnosisRepository.cs b/ProjectPolyclinic/ProjectPolyclinic/Repositories/Implementations/DiagnosisRepository.cs new file mode 100644 index 0000000..04d3ec8 --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Repositories/Implementations/DiagnosisRepository.cs @@ -0,0 +1,28 @@ +using ProjectPolyclinic.Entities; + +namespace ProjectPolyclinic.Repositories.Implementations; + +public class DiagnosisRepository : IDiagnosisRepository +{ + public void CreateDiagnosis(Diagnosis diagnosis) + { + } + + public void DeleteDiagnosis(int id) + { + } + + public IEnumerable ReadDiagnosis() + { + return []; + } + + public Diagnosis ReadDiagnosisById(int id) + { + return Diagnosis.CreateDiagnosis(0, string.Empty); + } + + public void UpdaterDiagnosis(Diagnosis diagnosis) + { + } +} diff --git a/ProjectPolyclinic/ProjectPolyclinic/Repositories/Implementations/DoctorRepository.cs b/ProjectPolyclinic/ProjectPolyclinic/Repositories/Implementations/DoctorRepository.cs new file mode 100644 index 0000000..e14129a --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Repositories/Implementations/DoctorRepository.cs @@ -0,0 +1,29 @@ +using ProjectPolyclinic.Entities; +using ProjectPolyclinic.Entities.Enums; + +namespace ProjectPolyclinic.Repositories.Implementations; + +public class DoctorRepository : IDoctorRepository +{ + public void CreateDoctor(Doctor doctor) + { + } + + public void DeleteDoctor(int id) + { + } + + public IEnumerable ReadDoctor() + { + return []; + } + + public Doctor ReadDoctorById(int id) + { + return Doctor.CreateEntity(0, string.Empty, string.Empty, DoctorSpeciality.None); + } + + public void UpdateDoctor(Doctor doctor) + { + } +} diff --git a/ProjectPolyclinic/ProjectPolyclinic/Repositories/Implementations/MedicinesMovingRepository.cs b/ProjectPolyclinic/ProjectPolyclinic/Repositories/Implementations/MedicinesMovingRepository.cs new file mode 100644 index 0000000..373c00a --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Repositories/Implementations/MedicinesMovingRepository.cs @@ -0,0 +1,23 @@ +using ProjectPolyclinic.Entities; + +namespace ProjectPolyclinic.Repositories.Implementations; + + public class MedicinesMovingRepository : IMedicinesMovingRepository +{ + public void CreateMedicinesMoving(MedicinesMoving medicinesMoving) + { + } + + public IEnumerable ReadMedicinesMovings(int? medicinesId = null, DateTime? date = null) + { + return []; + } + + public void UpdateMedicinesMoving(MedicinesMoving medicinesMoving) + { + } + + public void DeleteMedicinesMoving(int id) + { + } +} diff --git a/ProjectPolyclinic/ProjectPolyclinic/Repositories/Implementations/MedicinesRepository.cs b/ProjectPolyclinic/ProjectPolyclinic/Repositories/Implementations/MedicinesRepository.cs new file mode 100644 index 0000000..922c01a --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Repositories/Implementations/MedicinesRepository.cs @@ -0,0 +1,29 @@ +using ProjectPolyclinic.Entities; +using ProjectPolyclinic.Entities.Enums; + +namespace ProjectPolyclinic.Repositories.Implementations; + +public class MedicinesRepository : IMedicinesRepository +{ + public void CreateMedicines(Medicines medicines) + { + } + + public void DeleteMedicines(int id) + { + } + + public IEnumerable ReadMedicines() + { + return []; + } + + public Medicines ReadMedicinesById(int id) + { + return Medicines.CreateEntity(0, MedicinesType.None, string.Empty); + } + + public void UpdateMedicines(Medicines medicines) + { + } +} diff --git a/ProjectPolyclinic/ProjectPolyclinic/Repositories/Implementations/PatientRepository.cs b/ProjectPolyclinic/ProjectPolyclinic/Repositories/Implementations/PatientRepository.cs new file mode 100644 index 0000000..214afea --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Repositories/Implementations/PatientRepository.cs @@ -0,0 +1,28 @@ +using ProjectPolyclinic.Entities; + +namespace ProjectPolyclinic.Repositories.Implementations; + +public class PatientRepository : IPatientRepository +{ + public void CreatePatient(Patient patient) + { + } + + public void DeletePatient(int id) + { + } + + public IEnumerable ReadPatient() + { + return []; + } + + public Patient ReadPatientById(int id) + { + return Patient.CreateEntity(0, string.Empty, string.Empty, DateTime.Now, string.Empty, 0); + } + + public void UpdatePatient(Patient patient) + { + } +} diff --git a/ProjectPolyclinic/ProjectPolyclinic/Repositories/Implementations/VisitRepository.cs b/ProjectPolyclinic/ProjectPolyclinic/Repositories/Implementations/VisitRepository.cs new file mode 100644 index 0000000..606c20d --- /dev/null +++ b/ProjectPolyclinic/ProjectPolyclinic/Repositories/Implementations/VisitRepository.cs @@ -0,0 +1,19 @@ +using ProjectPolyclinic.Entities; + +namespace ProjectPolyclinic.Repositories.Implementations; + +public class VisitRepository : IVisitRepository +{ + public void CreateVisit(Visit visit) + { + } + + public void DeleteVisit(int id) + { + } + + public IEnumerable ReadVisit(DateTime? date = null, int? diagnosisId = null, int? patientId = null, int? doctorId = null) + { + return []; + } +} diff --git a/ProjectPolyclinic/ProjectPolyclinic/Resources/c516ff9163fefeaa5974fc7c8855cd02.jpg b/ProjectPolyclinic/ProjectPolyclinic/Resources/c516ff9163fefeaa5974fc7c8855cd02.jpg new file mode 100644 index 0000000..144fe6d Binary files /dev/null and b/ProjectPolyclinic/ProjectPolyclinic/Resources/c516ff9163fefeaa5974fc7c8855cd02.jpg differ diff --git a/README.md b/README.md deleted file mode 100644 index c4544c7..0000000 --- a/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# PIbd-22_Smolin_D.S._Polyclinic - diff --git a/c516ff9163fefeaa5974fc7c8855cd02.jpg b/c516ff9163fefeaa5974fc7c8855cd02.jpg new file mode 100644 index 0000000..144fe6d Binary files /dev/null and b/c516ff9163fefeaa5974fc7c8855cd02.jpg differ