добавила клиентов форму

This commit is contained in:
Елена Бакальская 2024-05-08 13:18:47 +04:00
parent 2026569f00
commit 2a009156e1
7 changed files with 347 additions and 87 deletions

View File

@ -28,12 +28,93 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.components = new System.ComponentModel.Container(); labelName = new Label();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; buttonCancel = new Button();
this.ClientSize = new System.Drawing.Size(800, 450); textBoxFIO = new TextBox();
this.Text = "FormClient"; buttonSave = new Button();
numericUpDownAge = new NumericUpDown();
label = new Label();
((System.ComponentModel.ISupportInitialize)numericUpDownAge).BeginInit();
SuspendLayout();
//
// labelName
//
labelName.AutoSize = true;
labelName.Location = new Point(23, 62);
labelName.Name = "labelName";
labelName.Size = new Size(42, 20);
labelName.TabIndex = 7;
labelName.Text = "ФИО";
//
// buttonCancel
//
buttonCancel.Location = new Point(164, 202);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(133, 44);
buttonCancel.TabIndex = 6;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += buttonCancel_Click;
//
// textBoxFIO
//
textBoxFIO.Location = new Point(23, 23);
textBoxFIO.Name = "textBoxFIO";
textBoxFIO.Size = new Size(274, 27);
textBoxFIO.TabIndex = 5;
//
// buttonSave
//
buttonSave.Location = new Point(23, 202);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(133, 44);
buttonSave.TabIndex = 4;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += buttonSave_Click;
//
// numericUpDownAge
//
numericUpDownAge.Location = new Point(23, 108);
numericUpDownAge.Name = "numericUpDownAge";
numericUpDownAge.Size = new Size(274, 27);
numericUpDownAge.TabIndex = 8;
//
// label
//
label.AutoSize = true;
label.Location = new Point(23, 156);
label.Name = "label";
label.Size = new Size(64, 20);
label.TabIndex = 9;
label.Text = "Возраст";
//
// FormClient
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(338, 282);
Controls.Add(label);
Controls.Add(numericUpDownAge);
Controls.Add(labelName);
Controls.Add(buttonCancel);
Controls.Add(textBoxFIO);
Controls.Add(buttonSave);
Name = "FormClient";
Text = "Клиент";
Load += FormClient_Load;
((System.ComponentModel.ISupportInitialize)numericUpDownAge).EndInit();
ResumeLayout(false);
PerformLayout();
} }
#endregion #endregion
private Label labelName;
private Button buttonCancel;
private TextBox textBoxFIO;
private Button buttonSave;
private NumericUpDown numericUpDownAge;
private Label label;
} }
} }

View File

@ -1,20 +1,83 @@
using System; using BeautySalonDBModels;
using System.Collections.Generic; using BeautySalonDBModels.Models;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace BeautySalon namespace BeautySalon
{ {
public partial class FormClient : Form public partial class FormClient : Form
{ {
public FormClient()
private int? _id;
public int Id
{ {
set { _id = value; }
}
private readonly AbstractWorkWithStorage<Client> clientStorage;
public FormClient(AbstractWorkWithStorage<Client> clientStorage)
{
this.clientStorage = clientStorage;
InitializeComponent(); InitializeComponent();
} }
private void buttonSave_Click(object sender, EventArgs e)
{
try
{
if (_id != null)
{
var newClient = new Client
{
ClientId = _id ?? 0,
FIO = textBoxFIO.Text,
Age = (int)numericUpDownAge.Value,
};
clientStorage.Update(newClient);
}
else
{
var newClient = new Client
{
FIO = textBoxFIO.Text,
Age = (int)numericUpDownAge.Value,
};
clientStorage.Add(newClient);
}
DialogResult = DialogResult.OK;
Close();
}
catch (Exception)
{
throw;
}
}
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel; Close();
}
private void FormClient_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
try
{
var client = clientStorage.GetObject(_id.Value);
if (client != null)
{
textBoxFIO.Text = client.FIO.ToString();
numericUpDownAge.Value = (decimal)client.Age;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
} }
} }

View File

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

View File

@ -28,12 +28,78 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.components = new System.ComponentModel.Container(); buttonDelete = new Button();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; buttonUpdate = new Button();
this.ClientSize = new System.Drawing.Size(800, 450); buttonCreate = new Button();
this.Text = "FormClients"; dataGridView = new DataGridView();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// buttonDelete
//
buttonDelete.Location = new Point(480, 356);
buttonDelete.Name = "buttonDelete";
buttonDelete.Size = new Size(147, 56);
buttonDelete.TabIndex = 7;
buttonDelete.Text = "Уничтожить...";
buttonDelete.UseVisualStyleBackColor = true;
buttonDelete.Click += buttonDelete_Click;
//
// buttonUpdate
//
buttonUpdate.Location = new Point(480, 186);
buttonUpdate.Name = "buttonUpdate";
buttonUpdate.Size = new Size(147, 56);
buttonUpdate.TabIndex = 6;
buttonUpdate.Text = "Корректровать";
buttonUpdate.UseVisualStyleBackColor = true;
buttonUpdate.Click += buttonUpdate_Click;
//
// buttonCreate
//
buttonCreate.Location = new Point(480, 25);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(147, 56);
buttonCreate.TabIndex = 5;
buttonCreate.Text = "Добавить";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += buttonCreate_Click;
//
// dataGridView
//
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridView.BackgroundColor = SystemColors.ActiveCaption;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Dock = DockStyle.Left;
dataGridView.Location = new Point(0, 0);
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersVisible = false;
dataGridView.RowHeadersWidth = 51;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(417, 450);
dataGridView.TabIndex = 4;
//
// FormClients
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(683, 450);
Controls.Add(buttonDelete);
Controls.Add(buttonUpdate);
Controls.Add(buttonCreate);
Controls.Add(dataGridView);
Name = "FormClients";
Text = "Клиенты";
Load += FormClients_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
} }
#endregion #endregion
private Button buttonDelete;
private Button buttonUpdate;
private Button buttonCreate;
private DataGridView dataGridView;
} }
} }

View File

@ -1,20 +1,79 @@
using System; using BeautySalonDBModels;
using System.Collections.Generic; using BeautySalonDBModels.Models;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace BeautySalon namespace BeautySalon
{ {
public partial class FormClients : Form public partial class FormClients : Form
{ {
public FormClients()
private int? _id;
public int Id
{ {
set { _id = value; }
}
private readonly AbstractWorkWithStorage<Client> clientStorage;
public FormClients(AbstractWorkWithStorage<Client> clientStorage)
{
this.clientStorage = clientStorage;
InitializeComponent(); InitializeComponent();
} }
private void LoadData()
{
var list = clientStorage.GetObjects();
if (list != null)
{
dataGridView.DataSource = list;
}
}
private void FormClients_Load(object sender, EventArgs e)
{
LoadData();
}
private void buttonCreate_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormClient));
if (service is FormClient 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(FormClient));
if (service is FormClient form)
{
int index = dataGridView.CurrentCell.RowIndex;
form.Id = (int)dataGridView.Rows[index].Cells["ClientId"].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["ClientId"].Value);
clientStorage.Remove(id);
LoadData();
}
}
} }
} }

View File

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

View File

@ -1,14 +1,5 @@
using BeautySalonDBModels; using BeautySalonDBModels;
using BeautySalonDBModels.Models; using BeautySalonDBModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace BeautySalon namespace BeautySalon
{ {