переименовала до конца классы хранилища, добавила (внедрила :)) ) зависимости - абстрактный класс и его реализации, делаю формы для мастеров

This commit is contained in:
Елена Бакальская 2024-05-07 22:33:37 +04:00
parent 8f68e44d08
commit 975b5f9463
10 changed files with 203 additions and 42 deletions

View File

@ -28,12 +28,91 @@
/// </summary>
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 = "FormMaster";
textBoxFIO = new TextBox();
FIO = new Label();
comboBoxSpecialisation = new ComboBox();
labelSpecialisation = new Label();
buttonCancel = new Button();
buttonSave = new Button();
SuspendLayout();
//
// textBoxFIO
//
textBoxFIO.Location = new Point(163, 21);
textBoxFIO.Name = "textBoxFIO";
textBoxFIO.Size = new Size(290, 27);
textBoxFIO.TabIndex = 0;
//
// FIO
//
FIO.AutoSize = true;
FIO.Location = new Point(12, 28);
FIO.Name = "FIO";
FIO.Size = new Size(103, 20);
FIO.TabIndex = 1;
FIO.Text = "ФИО мастера";
//
// comboBoxSpecialisation
//
comboBoxSpecialisation.FormattingEnabled = true;
comboBoxSpecialisation.Location = new Point(163, 80);
comboBoxSpecialisation.Name = "comboBoxSpecialisation";
comboBoxSpecialisation.Size = new Size(290, 28);
comboBoxSpecialisation.TabIndex = 2;
//
// labelSpecialisation
//
labelSpecialisation.AutoSize = true;
labelSpecialisation.Location = new Point(12, 83);
labelSpecialisation.Name = "labelSpecialisation";
labelSpecialisation.Size = new Size(122, 20);
labelSpecialisation.TabIndex = 3;
labelSpecialisation.Text = "Специализация:";
//
// buttonCancel
//
buttonCancel.Location = new Point(320, 142);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(133, 44);
buttonCancel.TabIndex = 5;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += buttonCancel_Click;
//
// buttonSave
//
buttonSave.Location = new Point(12, 142);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(133, 44);
buttonSave.TabIndex = 4;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += buttonSave_Click;
//
// FormMaster
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(482, 216);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(labelSpecialisation);
Controls.Add(comboBoxSpecialisation);
Controls.Add(FIO);
Controls.Add(textBoxFIO);
Name = "FormMaster";
Text = "Мастер";
ResumeLayout(false);
PerformLayout();
}
#endregion
private TextBox textBoxFIO;
private Label FIO;
private ComboBox comboBoxSpecialisation;
private Label labelSpecialisation;
private Button buttonCancel;
private Button buttonSave;
}
}

View File

@ -1,4 +1,6 @@
using System;
using BeautySalonDBModels;
using BeautySalonDBModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
@ -12,9 +14,43 @@ namespace BeautySalon
{
public partial class FormMaster : Form
{
public FormMaster()
private int? _id;
public int Id
{
set { _id = value; }
}
private readonly AbstractWorkWithStorage<Master> storage;
public FormMaster(AbstractWorkWithStorage<Master> storage)
{
this.storage = storage;
InitializeComponent();
}
private void buttonSave_Click(object sender, EventArgs e)
{
try
{
if (_id != null)
{
}
else
{
}
}
catch(Exception ex)
{
}
}
private void buttonCancel_Click(object sender, EventArgs e)
{
}
}
}

View File

@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
@ -26,36 +26,36 @@
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->

View File

@ -39,17 +39,41 @@ namespace BeautySalon
private void buttonCreate_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormMaster));
if (service is FormMaster form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void buttonUpdate_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormMaster));
if (service is FormMaster form)
{
int rowIndex = dataGridView.CurrentCell.RowIndex;
form.Id = (int)dataGridView.Rows[rowIndex].Cells["MasterId"].Value;
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void buttonDelete_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["MasterId"].Value);
masterDb.Remove(id);
LoadData();
}
}
private void FormMasters_Load(object sender, EventArgs e)

View File

@ -31,11 +31,12 @@
buttonSave = new Button();
textBoxNameSpecialisation = new TextBox();
buttonCancel = new Button();
labelName = new Label();
SuspendLayout();
//
// buttonSave
//
buttonSave.Location = new Point(37, 86);
buttonSave.Location = new Point(37, 159);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(133, 44);
buttonSave.TabIndex = 0;
@ -52,7 +53,7 @@
//
// buttonCancel
//
buttonCancel.Location = new Point(178, 86);
buttonCancel.Location = new Point(178, 159);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(133, 44);
buttonCancel.TabIndex = 2;
@ -60,11 +61,21 @@
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += buttonCancel_Click;
//
// labelName
//
labelName.AutoSize = true;
labelName.Location = new Point(133, 76);
labelName.Name = "labelName";
labelName.Size = new Size(77, 20);
labelName.TabIndex = 3;
labelName.Text = "Название";
//
// FormSpecialisation
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(345, 170);
ClientSize = new Size(345, 236);
Controls.Add(labelName);
Controls.Add(buttonCancel);
Controls.Add(textBoxNameSpecialisation);
Controls.Add(buttonSave);
@ -80,5 +91,6 @@
private Button buttonSave;
private TextBox textBoxNameSpecialisation;
private Button buttonCancel;
private Label labelName;
}
}

View File

@ -63,7 +63,7 @@ namespace BeautySalon
if (service is FormSpecialisation form)
{
int rowIndex = dataGridView.CurrentCell.RowIndex;
form.Id = (int)dataGridView.Rows[rowIndex].Cells["SpecialisationId"].Value; ;
form.Id = (int)dataGridView.Rows[rowIndex].Cells["SpecialisationId"].Value;
if (form.ShowDialog() == DialogResult.OK)
{

View File

@ -39,10 +39,20 @@ namespace BeautySalon
});
////services.AddTransient<IComponentStorage, ComponentStorage>();
services.AddSingleton<AbstractWorkWithStorage<Specialisation>, SpecialisationDB>();
services.AddSingleton<AbstractWorkWithStorage<Master>, MasterDatabase>();
services.AddSingleton<AbstractWorkWithStorage<Cheque>, ChequeDatabase>();
services.AddSingleton<AbstractWorkWithStorage<Client>, ClientDatabase>();
services.AddSingleton<AbstractWorkWithStorage<Reception>, ReceptionDatabase>();
services.AddSingleton<AbstractWorkWithStorage<Service>, ServiceDatabase>();
services.AddTransient<FormMain>();
services.AddTransient<FormHello>();
services.AddTransient<FormSpecialisations>();
services.AddTransient<FormSpecialisation>();
services.AddTransient<FormMasters>();
services.AddTransient<FormMaster>();
}
}
}

View File

@ -9,13 +9,13 @@ using System.Threading.Tasks;
namespace BeautySalonDBModels.Implements
{
public class MasterDB : AbstractWorkWithStorage<Master>
public class MasterDatabase : AbstractWorkWithStorage<Master>
{
public override void Add(Master master)
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand("INSERT INTO masters (specialisation_id, fio) VALUES ((nextval('seq_master'), @SpecialisationId, @FIO)", conn);
using var cmd = new NpgsqlCommand("INSERT INTO masters (master_id, specialisation_id, fio) VALUES ((nextval('seq_master'), @SpecialisationId, @FIO)", conn);
cmd.Parameters.AddWithValue("@SpecialisationId", master.SpecialisationId);
cmd.Parameters.AddWithValue("@FIO", master.FIO);
cmd.ExecuteNonQuery();

View File

@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace BeautySalonDBModels.Implements
{
public class ReceptionBD : AbstractWorkWithStorage<Reception>
public class ReceptionDatabase : AbstractWorkWithStorage<Reception>
{
public override void Add(Reception reception)
{

View File

@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace BeautySalonDBModels.Implements
{
public class ServiceDB : AbstractWorkWithStorage<Service>
public class ServiceDatabase : AbstractWorkWithStorage<Service>
{
public override void Add(Service service)
{