Compare commits

...

2 Commits

52 changed files with 3005 additions and 115 deletions

View File

@ -13,6 +13,8 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NLog" Version="5.1.4" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.3" />
</ItemGroup>
<ItemGroup>

View File

@ -1,10 +0,0 @@
namespace BeautySalon
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

119
BeautySalon/FormClient.Designer.cs generated Normal file
View File

@ -0,0 +1,119 @@
namespace BeautySalon
{
partial class FormClient
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.buttonSave = new System.Windows.Forms.Button();
this.labelName = new System.Windows.Forms.Label();
this.textBoxName = new System.Windows.Forms.TextBox();
this.labelPhoneNumber = new System.Windows.Forms.Label();
this.textBoxPhoneNumber = new System.Windows.Forms.TextBox();
this.buttonCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(213, 76);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(75, 23);
this.buttonSave.TabIndex = 0;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
// labelName
//
this.labelName.AutoSize = true;
this.labelName.Location = new System.Drawing.Point(12, 22);
this.labelName.Name = "labelName";
this.labelName.Size = new System.Drawing.Size(37, 15);
this.labelName.TabIndex = 1;
this.labelName.Text = "ФИО:";
//
// textBoxName
//
this.textBoxName.Location = new System.Drawing.Point(122, 19);
this.textBoxName.Name = "textBoxName";
this.textBoxName.Size = new System.Drawing.Size(247, 23);
this.textBoxName.TabIndex = 2;
//
// labelPhoneNumber
//
this.labelPhoneNumber.AutoSize = true;
this.labelPhoneNumber.Location = new System.Drawing.Point(12, 50);
this.labelPhoneNumber.Name = "labelPhoneNumber";
this.labelPhoneNumber.Size = new System.Drawing.Size(104, 15);
this.labelPhoneNumber.TabIndex = 3;
this.labelPhoneNumber.Text = "Номер телефона:";
//
// textBoxPhoneNumber
//
this.textBoxPhoneNumber.Location = new System.Drawing.Point(122, 47);
this.textBoxPhoneNumber.Name = "textBoxPhoneNumber";
this.textBoxPhoneNumber.Size = new System.Drawing.Size(128, 23);
this.textBoxPhoneNumber.TabIndex = 4;
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(294, 76);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
this.buttonCancel.TabIndex = 5;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// FormClient
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(381, 107);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.textBoxPhoneNumber);
this.Controls.Add(this.labelPhoneNumber);
this.Controls.Add(this.textBoxName);
this.Controls.Add(this.labelName);
this.Controls.Add(this.buttonSave);
this.Name = "FormClient";
this.Text = "Клиент";
this.Load += new System.EventHandler(this.FormClient_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Button buttonSave;
private Label labelName;
private TextBox textBoxName;
private Label labelPhoneNumber;
private TextBox textBoxPhoneNumber;
private Button buttonCancel;
}
}

82
BeautySalon/FormClient.cs Normal file
View File

@ -0,0 +1,82 @@
using BeautySalonContracts.BindingModels;
using BeautySalonContracts.BusinessLogicsContracts;
using BeautySalonContracts.SearchModels;
using Microsoft.Extensions.Logging;
namespace BeautySalon
{
public partial class FormClient : Form
{
private readonly ILogger _logger;
private readonly IClientLogic _logic;
private int? _id;
public int Id { set { _id = value; } }
public FormClient(ILogger<FormClient> logger, IClientLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxName.Text))
{
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение клиента");
try
{
var model = new ClientBindingModel
{
Id = _id ?? 0,
ClientFIO = textBoxName.Text,
PhoneNumber = textBoxPhoneNumber.Text
};
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения клиента");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
private void FormClient_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
try
{
_logger.LogInformation("Получение клиента");
var view = _logic.ReadElement(new ClientSearchModel { Id = _id.Value });
if (view != null)
{
textBoxName.Text = view.ClientFIO;
textBoxPhoneNumber.Text = view.PhoneNumber.ToString();
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения клиента");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

113
BeautySalon/FormClients.Designer.cs generated Normal file
View File

@ -0,0 +1,113 @@
namespace BeautySalon
{
partial class FormClients
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonAdd = new System.Windows.Forms.Button();
this.buttonUpd = new System.Windows.Forms.Button();
this.buttonDel = new System.Windows.Forms.Button();
this.buttonRef = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// dataGridView
//
this.dataGridView.BackgroundColor = System.Drawing.SystemColors.Control;
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(12, 12);
this.dataGridView.Name = "dataGridView";
this.dataGridView.Size = new System.Drawing.Size(357, 426);
this.dataGridView.TabIndex = 0;
//
// buttonAdd
//
this.buttonAdd.Location = new System.Drawing.Point(411, 31);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(75, 23);
this.buttonAdd.TabIndex = 1;
this.buttonAdd.Text = "Добавить";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
//
// buttonUpd
//
this.buttonUpd.Location = new System.Drawing.Point(411, 79);
this.buttonUpd.Name = "buttonUpd";
this.buttonUpd.Size = new System.Drawing.Size(75, 23);
this.buttonUpd.TabIndex = 2;
this.buttonUpd.Text = "Изменить";
this.buttonUpd.UseVisualStyleBackColor = true;
this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
//
// buttonDel
//
this.buttonDel.Location = new System.Drawing.Point(411, 131);
this.buttonDel.Name = "buttonDel";
this.buttonDel.Size = new System.Drawing.Size(75, 23);
this.buttonDel.TabIndex = 3;
this.buttonDel.Text = "Удалить";
this.buttonDel.UseVisualStyleBackColor = true;
this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click);
//
// buttonRef
//
this.buttonRef.Location = new System.Drawing.Point(411, 187);
this.buttonRef.Name = "buttonRef";
this.buttonRef.Size = new System.Drawing.Size(75, 23);
this.buttonRef.TabIndex = 4;
this.buttonRef.Text = "Обновить";
this.buttonRef.UseVisualStyleBackColor = true;
//
// FormClients
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(520, 450);
this.Controls.Add(this.buttonRef);
this.Controls.Add(this.buttonDel);
this.Controls.Add(this.buttonUpd);
this.Controls.Add(this.buttonAdd);
this.Controls.Add(this.dataGridView);
this.Name = "FormClients";
this.Text = "Клиенты";
this.Load += new System.EventHandler(this.FormClients_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private DataGridView dataGridView;
private Button buttonAdd;
private Button buttonUpd;
private Button buttonDel;
private Button buttonRef;
}
}

View File

@ -0,0 +1,97 @@
using BeautySalonContracts.BindingModels;
using BeautySalonContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
namespace BeautySalon
{
public partial class FormClients : Form
{
private readonly ILogger _logger;
private readonly IClientLogic _logic;
public FormClients(ILogger<FormClients> logger, IClientLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void LoadData()
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["PhoneNumber"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка клиентов");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки клиентов");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonAdd_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 ButtonUpd_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormClient));
if (service is FormClient form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Удаление клиента");
try
{
if (!_logic.Delete(new ClientBindingModel { Id = id }))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления клиента");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void FormClients_Load(object sender, EventArgs e)
{
LoadData();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

198
BeautySalon/FormCreateVisit.Designer.cs generated Normal file
View File

@ -0,0 +1,198 @@
namespace BeautySalon
{
partial class FormCreateVisit
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.labelMaster = new System.Windows.Forms.Label();
this.labelSum = new System.Windows.Forms.Label();
this.comboBoxMaster = new System.Windows.Forms.ComboBox();
this.textBoxSum = new System.Windows.Forms.TextBox();
this.buttonSave = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.labelClient = new System.Windows.Forms.Label();
this.comboBoxClient = new System.Windows.Forms.ComboBox();
this.comboBoxService = new System.Windows.Forms.ComboBox();
this.labelService = new System.Windows.Forms.Label();
this.labelDate = new System.Windows.Forms.Label();
this.dateTimePicker = new System.Windows.Forms.DateTimePicker();
this.SuspendLayout();
//
// labelMaster
//
this.labelMaster.AutoSize = true;
this.labelMaster.Location = new System.Drawing.Point(12, 44);
this.labelMaster.Name = "labelMaster";
this.labelMaster.Size = new System.Drawing.Size(51, 15);
this.labelMaster.TabIndex = 0;
this.labelMaster.Text = "Мастер:";
//
// labelSum
//
this.labelSum.AutoSize = true;
this.labelSum.Location = new System.Drawing.Point(11, 102);
this.labelSum.Name = "labelSum";
this.labelSum.Size = new System.Drawing.Size(48, 15);
this.labelSum.TabIndex = 2;
this.labelSum.Text = "Сумма:";
//
// comboBoxMaster
//
this.comboBoxMaster.BackColor = System.Drawing.SystemColors.Window;
this.comboBoxMaster.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxMaster.FormattingEnabled = true;
this.comboBoxMaster.Location = new System.Drawing.Point(93, 41);
this.comboBoxMaster.Name = "comboBoxMaster";
this.comboBoxMaster.Size = new System.Drawing.Size(238, 23);
this.comboBoxMaster.TabIndex = 3;
this.comboBoxMaster.SelectedIndexChanged += new System.EventHandler(this.ComboBoxMaster_SelectedIndexChanged);
//
// textBoxSum
//
this.textBoxSum.Location = new System.Drawing.Point(93, 99);
this.textBoxSum.Name = "textBoxSum";
this.textBoxSum.ReadOnly = true;
this.textBoxSum.Size = new System.Drawing.Size(238, 23);
this.textBoxSum.TabIndex = 5;
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(175, 170);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(75, 23);
this.buttonSave.TabIndex = 6;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(256, 170);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
this.buttonCancel.TabIndex = 7;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// labelClient
//
this.labelClient.AutoSize = true;
this.labelClient.Location = new System.Drawing.Point(12, 15);
this.labelClient.Name = "labelClient";
this.labelClient.Size = new System.Drawing.Size(49, 15);
this.labelClient.TabIndex = 8;
this.labelClient.Text = "Клиент:";
//
// comboBoxClient
//
this.comboBoxClient.BackColor = System.Drawing.SystemColors.Window;
this.comboBoxClient.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxClient.FormattingEnabled = true;
this.comboBoxClient.Location = new System.Drawing.Point(93, 12);
this.comboBoxClient.Name = "comboBoxClient";
this.comboBoxClient.Size = new System.Drawing.Size(238, 23);
this.comboBoxClient.TabIndex = 9;
this.comboBoxClient.SelectedIndexChanged += new System.EventHandler(this.ComboBoxClient_SelectedIndexChanged);
//
// comboBoxService
//
this.comboBoxService.BackColor = System.Drawing.SystemColors.Window;
this.comboBoxService.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxService.FormattingEnabled = true;
this.comboBoxService.Location = new System.Drawing.Point(93, 70);
this.comboBoxService.Name = "comboBoxService";
this.comboBoxService.Size = new System.Drawing.Size(238, 23);
this.comboBoxService.TabIndex = 11;
this.comboBoxService.SelectedIndexChanged += new System.EventHandler(this.ComboBoxService_SelectedIndexChanged);
//
// labelService
//
this.labelService.AutoSize = true;
this.labelService.Location = new System.Drawing.Point(11, 73);
this.labelService.Name = "labelService";
this.labelService.Size = new System.Drawing.Size(47, 15);
this.labelService.TabIndex = 10;
this.labelService.Text = "Услуга:";
//
// labelDate
//
this.labelDate.AutoSize = true;
this.labelDate.Location = new System.Drawing.Point(12, 134);
this.labelDate.Name = "labelDate";
this.labelDate.Size = new System.Drawing.Size(35, 15);
this.labelDate.TabIndex = 12;
this.labelDate.Text = "Дата:";
//
// dateTimePicker
//
this.dateTimePicker.Location = new System.Drawing.Point(93, 128);
this.dateTimePicker.Name = "dateTimePicker";
this.dateTimePicker.Size = new System.Drawing.Size(238, 23);
this.dateTimePicker.TabIndex = 13;
//
// FormCreateVisit
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(346, 206);
this.Controls.Add(this.dateTimePicker);
this.Controls.Add(this.labelDate);
this.Controls.Add(this.comboBoxService);
this.Controls.Add(this.labelService);
this.Controls.Add(this.comboBoxClient);
this.Controls.Add(this.labelClient);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.textBoxSum);
this.Controls.Add(this.comboBoxMaster);
this.Controls.Add(this.labelSum);
this.Controls.Add(this.labelMaster);
this.Name = "FormCreateVisit";
this.Text = "Посещение";
this.Load += new System.EventHandler(this.FormCreateVisit_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Label labelMaster;
private Label labelSum;
private ComboBox comboBoxMaster;
private TextBox textBoxSum;
private Button buttonSave;
private Button buttonCancel;
private Label labelClient;
private ComboBox comboBoxClient;
private ComboBox comboBoxService;
private Label labelService;
private Label labelDate;
private DateTimePicker dateTimePicker;
}
}

View File

@ -0,0 +1,174 @@
using BeautySalonContracts.BindingModels;
using BeautySalonContracts.BusinessLogicsContracts;
using BeautySalonContracts.SearchModels;
using Microsoft.Extensions.Logging;
namespace BeautySalon
{
public partial class FormCreateVisit : Form
{
private readonly ILogger _logger;
private readonly IServiceLogic _logicS;
private readonly IClientLogic _logicC;
private readonly IMasterLogic _logicM;
private readonly IVisitLogic _logicV;
public FormCreateVisit(ILogger<FormCreateVisit> logger, IVisitLogic logicV, IServiceLogic logicS, IClientLogic logicC, IMasterLogic logicM)
{
InitializeComponent();
_logger = logger;
_logicS = logicS;
_logicV = logicV;
_logicC = logicC;
_logicM = logicM;
LoadData();
}
private void LoadData()
{
_logger.LogInformation("Загрузка услуг для посещения");
try
{
var list = _logicS.ReadList(null);
if (list != null)
{
comboBoxService.DisplayMember = "ServiceName";
comboBoxService.ValueMember = "Id";
comboBoxService.DataSource = list;
comboBoxService.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки списка услуг");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
_logger.LogInformation("Загрузка клиентов для заказа");
try
{
var list = _logicC.ReadList(null);
if (list != null)
{
comboBoxClient.DisplayMember = "ClientFIO";
comboBoxClient.ValueMember = "Id";
comboBoxClient.DataSource = list;
comboBoxClient.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки списка клиентов");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
_logger.LogInformation("Загрузка мастеров для заказа");
try
{
var list = _logicM.ReadList(null);
if (list != null)
{
comboBoxMaster.DisplayMember = "MasterFIO";
comboBoxMaster.ValueMember = "Id";
comboBoxMaster.DataSource = list;
comboBoxMaster.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки списка мастеров");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void FormCreateVisit_Load(object sender, EventArgs e)
{
_logger.LogInformation("Загрузка мастеров для посещения");
LoadData();
}
private void CalcSum()
{
if (comboBoxService.SelectedValue != null)
{
try
{
int id = Convert.ToInt32(comboBoxService.SelectedValue);
var service = _logicS.ReadElement(new ServiceSearchModel
{
Id = id
});
textBoxSum.Text = Math.Round((service?.Cost ?? 0), 2).ToString();
_logger.LogInformation("Расчет суммы посещения");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка расчета суммы посещения");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ComboBoxClient_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void ComboBoxMaster_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void ComboBoxService_SelectedIndexChanged(object sender, EventArgs e)
{
CalcSum();
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (comboBoxClient.SelectedValue == null)
{
MessageBox.Show("Выберите клиента", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxService.SelectedValue == null)
{
MessageBox.Show("Выберите услугу", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxMaster.SelectedValue == null)
{
MessageBox.Show("Выберите мастера", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Создание посещения");
try
{
var operationResult = _logicV.Create(new VisitBindingModel
{
MasterId = Convert.ToInt32(comboBoxMaster.SelectedValue),
MasterFIO = comboBoxMaster.Text,
ClientId = Convert.ToInt32(comboBoxClient.SelectedValue),
ClientFIO = comboBoxClient.Text,
ServiceId = Convert.ToInt32(comboBoxService.SelectedValue),
ServiceName = comboBoxService.Text,
DateOfVisit = dateTimePicker.Value,
Sum = Convert.ToDouble(textBoxSum.Text)
});
if (!operationResult)
{
throw new Exception("Ошибка при создании посещения. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания посещения");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

145
BeautySalon/FormMain.Designer.cs generated Normal file
View File

@ -0,0 +1,145 @@
namespace BeautySalon
{
partial class FormMain
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.услугиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.мастераToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonCreateVisit = new System.Windows.Forms.Button();
this.buttonRef = new System.Windows.Forms.Button();
this.menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// menuStrip1
//
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.справочникиToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(1078, 24);
this.menuStrip1.TabIndex = 0;
this.menuStrip1.Text = "menuStrip1";
//
// справочникиToolStripMenuItem
//
this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.услугиToolStripMenuItem,
this.мастераToolStripMenuItem,
this.клиентыToolStripMenuItem});
this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20);
this.справочникиToolStripMenuItem.Text = "Справочники";
//
// услугиToolStripMenuItem
//
this.услугиToolStripMenuItem.Name = "услугиToolStripMenuItem";
this.услугиToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.услугиToolStripMenuItem.Text = "Услуги";
this.услугиToolStripMenuItem.Click += new System.EventHandler(this.УслугиToolStripMenuItem_Click);
//
// мастераToolStripMenuItem
//
this.мастераToolStripMenuItem.Name = астераToolStripMenuItem";
this.мастераToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.мастераToolStripMenuItem.Text = "Мастера";
this.мастераToolStripMenuItem.Click += new System.EventHandler(this.МастераToolStripMenuItem_Click);
//
// клиентыToolStripMenuItem
//
this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem";
this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.клиентыToolStripMenuItem.Text = "Клиенты";
this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.КлиентыToolStripMenuItem_Click);
//
// dataGridView
//
this.dataGridView.BackgroundColor = System.Drawing.SystemColors.Control;
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(0, 27);
this.dataGridView.Name = "dataGridView";
this.dataGridView.Size = new System.Drawing.Size(889, 397);
this.dataGridView.TabIndex = 1;
//
// buttonCreateVisit
//
this.buttonCreateVisit.Location = new System.Drawing.Point(912, 60);
this.buttonCreateVisit.Name = "buttonCreateVisit";
this.buttonCreateVisit.Size = new System.Drawing.Size(145, 23);
this.buttonCreateVisit.TabIndex = 2;
this.buttonCreateVisit.Text = "Создать посещение";
this.buttonCreateVisit.UseVisualStyleBackColor = true;
this.buttonCreateVisit.Click += new System.EventHandler(this.ButtonCreateVisit_Click);
//
// buttonRef
//
this.buttonRef.Location = new System.Drawing.Point(912, 98);
this.buttonRef.Name = "buttonRef";
this.buttonRef.Size = new System.Drawing.Size(145, 23);
this.buttonRef.TabIndex = 3;
this.buttonRef.Text = "Обновить список";
this.buttonRef.UseVisualStyleBackColor = true;
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
//
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1078, 425);
this.Controls.Add(this.buttonRef);
this.Controls.Add(this.buttonCreateVisit);
this.Controls.Add(this.dataGridView);
this.Controls.Add(this.menuStrip1);
this.MainMenuStrip = this.menuStrip1;
this.Name = "FormMain";
this.Text = "Салон красоты";
this.Load += new System.EventHandler(this.FormMain_Load);
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private MenuStrip menuStrip1;
private ToolStripMenuItem справочникиToolStripMenuItem;
private ToolStripMenuItem услугиToolStripMenuItem;
private ToolStripMenuItem мастераToolStripMenuItem;
private ToolStripMenuItem клиентыToolStripMenuItem;
private DataGridView dataGridView;
private Button buttonCreateVisit;
private Button buttonRef;
}
}

91
BeautySalon/FormMain.cs Normal file
View File

@ -0,0 +1,91 @@
using BeautySalonContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
namespace BeautySalon
{
public partial class FormMain : Form
{
private readonly ILogger _logger;
private readonly IVisitLogic _visitLogic;
public FormMain(ILogger<FormMain> logger, IVisitLogic visitLogic)
{
InitializeComponent();
_logger = logger;
_visitLogic = visitLogic;
}
private void FormMain_Load(object sender, EventArgs e)
{
LoadData();
}
private void ButtonCreateVisit_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCreateVisit));
if (service is FormCreateVisit form)
{
form.ShowDialog();
LoadData();
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
}
private void УслугиToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormServices));
if (service is FormServices form)
{
form.ShowDialog();
}
}
private void МастераToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormMasters));
if (service is FormMasters form)
{
form.ShowDialog();
}
}
private void КлиентыToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormClients));
if (service is FormClients form)
{
form.ShowDialog();
}
}
private void LoadData()
{
_logger.LogInformation("Загрузка посещений");
try
{
var list = _visitLogic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["ClientId"].Visible = false;
dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["MasterId"].Visible = false;
dataGridView.Columns["MasterFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["ServiceId"].Visible = false;
dataGridView.Columns["ServiceName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["DateOfVisit"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["Sum"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка посещений");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки посещений");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

63
BeautySalon/FormMain.resx Normal file
View File

@ -0,0 +1,63 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

229
BeautySalon/FormMaster.Designer.cs generated Normal file
View File

@ -0,0 +1,229 @@
namespace BeautySalon
{
partial class FormMaster
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.labelName = new System.Windows.Forms.Label();
this.textBoxName = new System.Windows.Forms.TextBox();
this.groupBox = new System.Windows.Forms.GroupBox();
this.buttonRef = new System.Windows.Forms.Button();
this.buttonDel = new System.Windows.Forms.Button();
this.buttonUpd = new System.Windows.Forms.Button();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.NameService = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Time = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.buttonAdd = new System.Windows.Forms.Button();
this.labelWage = new System.Windows.Forms.Label();
this.buttonSave = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.textBoxWage = new System.Windows.Forms.TextBox();
this.groupBox.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// labelName
//
this.labelName.AutoSize = true;
this.labelName.Location = new System.Drawing.Point(24, 27);
this.labelName.Name = "labelName";
this.labelName.Size = new System.Drawing.Size(37, 15);
this.labelName.TabIndex = 0;
this.labelName.Text = "ФИО:";
//
// textBoxName
//
this.textBoxName.Location = new System.Drawing.Point(138, 24);
this.textBoxName.Name = "textBoxName";
this.textBoxName.Size = new System.Drawing.Size(301, 23);
this.textBoxName.TabIndex = 1;
//
// groupBox
//
this.groupBox.Controls.Add(this.buttonRef);
this.groupBox.Controls.Add(this.buttonDel);
this.groupBox.Controls.Add(this.buttonUpd);
this.groupBox.Controls.Add(this.dataGridView);
this.groupBox.Controls.Add(this.buttonAdd);
this.groupBox.Location = new System.Drawing.Point(12, 112);
this.groupBox.Name = "groupBox";
this.groupBox.Size = new System.Drawing.Size(551, 292);
this.groupBox.TabIndex = 2;
this.groupBox.TabStop = false;
this.groupBox.Text = "Услуги";
//
// buttonRef
//
this.buttonRef.Location = new System.Drawing.Point(438, 164);
this.buttonRef.Name = "buttonRef";
this.buttonRef.Size = new System.Drawing.Size(75, 23);
this.buttonRef.TabIndex = 4;
this.buttonRef.Text = "Обновить";
this.buttonRef.UseVisualStyleBackColor = true;
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
//
// buttonDel
//
this.buttonDel.Location = new System.Drawing.Point(438, 121);
this.buttonDel.Name = "buttonDel";
this.buttonDel.Size = new System.Drawing.Size(75, 23);
this.buttonDel.TabIndex = 3;
this.buttonDel.Text = "Удалить";
this.buttonDel.UseVisualStyleBackColor = true;
this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click);
//
// buttonUpd
//
this.buttonUpd.Location = new System.Drawing.Point(438, 78);
this.buttonUpd.Name = "buttonUpd";
this.buttonUpd.Size = new System.Drawing.Size(75, 23);
this.buttonUpd.TabIndex = 2;
this.buttonUpd.Text = "Изменить";
this.buttonUpd.UseVisualStyleBackColor = true;
this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
//
// dataGridView
//
this.dataGridView.BackgroundColor = System.Drawing.SystemColors.Control;
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.ID,
this.NameService,
this.Time});
this.dataGridView.GridColor = System.Drawing.SystemColors.Control;
this.dataGridView.Location = new System.Drawing.Point(6, 16);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowTemplate.Height = 25;
this.dataGridView.Size = new System.Drawing.Size(398, 270);
this.dataGridView.TabIndex = 1;
//
// ID
//
this.ID.HeaderText = "ID";
this.ID.Name = "ID";
this.ID.Visible = false;
//
// NameService
//
this.NameService.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.NameService.HeaderText = "Услуга";
this.NameService.Name = "NameService";
//
// Time
//
this.Time.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.Time.HeaderText = "Время на услугу, час(ов)";
this.Time.Name = "Time";
//
// buttonAdd
//
this.buttonAdd.Location = new System.Drawing.Point(438, 36);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(75, 23);
this.buttonAdd.TabIndex = 0;
this.buttonAdd.Text = "Добавить";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
//
// labelWage
//
this.labelWage.AutoSize = true;
this.labelWage.Location = new System.Drawing.Point(24, 59);
this.labelWage.Name = "labelWage";
this.labelWage.Size = new System.Drawing.Size(108, 15);
this.labelWage.TabIndex = 3;
this.labelWage.Text = "Заработная плата:";
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(369, 410);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(75, 23);
this.buttonSave.TabIndex = 5;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(450, 410);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
this.buttonCancel.TabIndex = 6;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// textBoxWage
//
this.textBoxWage.Location = new System.Drawing.Point(138, 56);
this.textBoxWage.Name = "textBoxWage";
this.textBoxWage.ReadOnly = true;
this.textBoxWage.Size = new System.Drawing.Size(152, 23);
this.textBoxWage.TabIndex = 7;
//
// FormMaster
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(575, 444);
this.Controls.Add(this.textBoxWage);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.labelWage);
this.Controls.Add(this.groupBox);
this.Controls.Add(this.textBoxName);
this.Controls.Add(this.labelName);
this.Name = "FormMaster";
this.Text = "Мастер";
this.groupBox.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Label labelName;
private TextBox textBoxName;
private GroupBox groupBox;
private Button buttonRef;
private Button buttonDel;
private Button buttonUpd;
private DataGridView dataGridView;
private Button buttonAdd;
private Label labelWage;
private Button buttonSave;
private Button buttonCancel;
private DataGridViewTextBoxColumn ID;
private DataGridViewTextBoxColumn NameService;
private DataGridViewTextBoxColumn Time;
private TextBox textBoxWage;
}
}

202
BeautySalon/FormMaster.cs Normal file
View File

@ -0,0 +1,202 @@
using BeautySalonContracts.BindingModels;
using BeautySalonContracts.BusinessLogicsContracts;
using BeautySalonContracts.SearchModels;
using BeautySalonDataModels.Models;
using Microsoft.Extensions.Logging;
namespace BeautySalon
{
public partial class FormMaster : Form
{
private readonly ILogger _logger;
private readonly IMasterLogic _logic;
private int? _id;
private Dictionary<int, (IServiceModel, double)> _masterServices;
public int Id { set { _id = value; } }
public FormMaster(ILogger<FormMaster> logger, IMasterLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
_masterServices = new Dictionary<int, (IServiceModel, double)>();
}
private void LoadData()
{
_logger.LogInformation("Загрузка услуг мастера");
try
{
if (_masterServices != null)
{
dataGridView.Rows.Clear();
foreach (var ec in _masterServices)
{
dataGridView.Rows.Add(new object[] { ec.Key, ec.Value.Item1.ServiceName, ec.Value.Item2 });
}
textBoxWage.Text = CalcWage().ToString();
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки услуг мастера");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormMasterService));
if (service is FormMasterService form)
{
if (form.ShowDialog() == DialogResult.OK)
{
if (form.ServiceModel == null)
{
return;
}
_logger.LogInformation("Добавление новой услуги: {ServiceName} - {Time}", form.ServiceModel.ServiceName, form.Time);
if (_masterServices.ContainsKey(form.Id))
{
_masterServices[form.Id] = (form.ServiceModel, form.Time);
}
else
{
_masterServices.Add(form.Id, (form.ServiceModel, form.Time));
}
LoadData();
}
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormMasterService));
if (service is FormMasterService form)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
form.Id = id;
form.Time = _masterServices[id].Item2;
if (form.ShowDialog() == DialogResult.OK)
{
if (form.ServiceModel == null)
{
return;
}
_logger.LogInformation("Изменение услуги: { ServiceName} - { Time}", form.ServiceModel.ServiceName, form.Time);
_masterServices[form.Id] = (form.ServiceModel, form.Time);
LoadData();
}
}
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
try
{
_logger.LogInformation("Удаление услуги: { ServiceName} - { Time}", dataGridView.SelectedRows[0].Cells[1].Value);
_masterServices?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
LoadData();
}
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxName.Text))
{
MessageBox.Show("Заполните ФИО", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (_masterServices == null || _masterServices.Count == 0)
{
MessageBox.Show("Заполните услуги", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxWage.Text))
{
MessageBox.Show("Заполните рабочее время", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение мастера");
try
{
var model = new MasterBindingModel
{
Id = _id ?? 0,
MasterFIO = textBoxName.Text,
Wage = Convert.ToDouble(textBoxWage.Text),
MasterServices = _masterServices
};
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения мастера");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
private void FormMaster_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
_logger.LogInformation("Загрузка мастера");
try
{
var view = _logic.ReadElement(new MasterSearchModel { Id = _id.Value });
if (view != null)
{
textBoxName.Text = view.MasterFIO;
textBoxWage.Text = view.Wage.ToString();
_masterServices = view.MasterServices ?? new Dictionary<int, (IServiceModel, double)>();
LoadData();
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки мастера");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private double CalcWage()
{
double price = 0;
foreach (var elem in _masterServices)
{
price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2);
}
return Math.Round(price * 1.1, 2);
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

120
BeautySalon/FormMasterService.Designer.cs generated Normal file
View File

@ -0,0 +1,120 @@
namespace BeautySalon
{
partial class FormMasterService
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.labelService = new System.Windows.Forms.Label();
this.labelTime = new System.Windows.Forms.Label();
this.comboBoxService = new System.Windows.Forms.ComboBox();
this.textBoxTime = new System.Windows.Forms.TextBox();
this.buttonSave = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// labelService
//
this.labelService.AutoSize = true;
this.labelService.Location = new System.Drawing.Point(23, 22);
this.labelService.Name = "labelService";
this.labelService.Size = new System.Drawing.Size(47, 15);
this.labelService.TabIndex = 0;
this.labelService.Text = "Услуга:";
//
// labelTime
//
this.labelTime.AutoSize = true;
this.labelTime.Location = new System.Drawing.Point(23, 51);
this.labelTime.Name = "labelTime";
this.labelTime.Size = new System.Drawing.Size(45, 15);
this.labelTime.TabIndex = 1;
this.labelTime.Text = "Время:";
//
// comboBoxService
//
this.comboBoxService.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxService.FormattingEnabled = true;
this.comboBoxService.Location = new System.Drawing.Point(76, 19);
this.comboBoxService.Name = "comboBoxService";
this.comboBoxService.Size = new System.Drawing.Size(248, 23);
this.comboBoxService.TabIndex = 2;
//
// textBoxTime
//
this.textBoxTime.Location = new System.Drawing.Point(76, 48);
this.textBoxTime.Name = "textBoxTime";
this.textBoxTime.Size = new System.Drawing.Size(248, 23);
this.textBoxTime.TabIndex = 3;
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(168, 82);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(75, 23);
this.buttonSave.TabIndex = 4;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(249, 82);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
this.buttonCancel.TabIndex = 5;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// FormMasterService
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(347, 117);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.textBoxTime);
this.Controls.Add(this.comboBoxService);
this.Controls.Add(this.labelTime);
this.Controls.Add(this.labelService);
this.Name = "FormMasterService";
this.Text = "Услуга мастера";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Label labelService;
private Label labelTime;
private ComboBox comboBoxService;
private TextBox textBoxTime;
private Button buttonSave;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,80 @@
using BeautySalonContracts.BusinessLogicsContracts;
using BeautySalonContracts.ViewModels;
using BeautySalonDataModels.Models;
namespace BeautySalon
{
public partial class FormMasterService : Form
{
private readonly List<ServiceViewModel>? _list;
public int Id
{
get
{
return Convert.ToInt32(comboBoxService.SelectedValue);
}
set
{
comboBoxService.SelectedValue = value;
}
}
public IServiceModel? ServiceModel
{
get
{
if (_list == null)
{
return null;
}
foreach (var elem in _list)
{
if (elem.Id == Id)
{
return elem;
}
}
return null;
}
}
public double Time
{
get { return Convert.ToDouble(textBoxTime.Text); }
set
{ textBoxTime.Text = value.ToString(); }
}
public FormMasterService(IServiceLogic logic)
{
InitializeComponent();
_list = logic.ReadList(null);
if (_list != null)
{
comboBoxService.DisplayMember = "ServiceName";
comboBoxService.ValueMember = "Id";
comboBoxService.DataSource = _list;
comboBoxService.SelectedItem = null;
}
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxTime.Text))
{
MessageBox.Show("Заполните поле время", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxService.SelectedValue == null)
{
MessageBox.Show("Выберите услугу", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
DialogResult = DialogResult.OK;
Close();
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

116
BeautySalon/FormMasters.Designer.cs generated Normal file
View File

@ -0,0 +1,116 @@
namespace BeautySalon
{
partial class FormMasters
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonAdd = new System.Windows.Forms.Button();
this.buttonUpd = new System.Windows.Forms.Button();
this.buttonDel = new System.Windows.Forms.Button();
this.buttonRef = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// dataGridView
//
this.dataGridView.BackgroundColor = System.Drawing.SystemColors.Control;
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.GridColor = System.Drawing.SystemColors.Control;
this.dataGridView.Location = new System.Drawing.Point(3, 3);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowTemplate.Height = 25;
this.dataGridView.Size = new System.Drawing.Size(382, 407);
this.dataGridView.TabIndex = 0;
//
// buttonAdd
//
this.buttonAdd.Location = new System.Drawing.Point(437, 61);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(75, 23);
this.buttonAdd.TabIndex = 1;
this.buttonAdd.Text = "Добавить";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
//
// buttonUpd
//
this.buttonUpd.Location = new System.Drawing.Point(437, 113);
this.buttonUpd.Name = "buttonUpd";
this.buttonUpd.Size = new System.Drawing.Size(75, 23);
this.buttonUpd.TabIndex = 2;
this.buttonUpd.Text = "Изменить";
this.buttonUpd.UseVisualStyleBackColor = true;
this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
//
// buttonDel
//
this.buttonDel.Location = new System.Drawing.Point(437, 162);
this.buttonDel.Name = "buttonDel";
this.buttonDel.Size = new System.Drawing.Size(75, 23);
this.buttonDel.TabIndex = 3;
this.buttonDel.Text = "Удалить";
this.buttonDel.UseVisualStyleBackColor = true;
this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click);
//
// buttonRef
//
this.buttonRef.Location = new System.Drawing.Point(437, 213);
this.buttonRef.Name = "buttonRef";
this.buttonRef.Size = new System.Drawing.Size(75, 23);
this.buttonRef.TabIndex = 4;
this.buttonRef.Text = "Обновить";
this.buttonRef.UseVisualStyleBackColor = true;
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
//
// FormMasters
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(558, 413);
this.Controls.Add(this.buttonRef);
this.Controls.Add(this.buttonDel);
this.Controls.Add(this.buttonUpd);
this.Controls.Add(this.buttonAdd);
this.Controls.Add(this.dataGridView);
this.Name = "FormMasters";
this.Text = "Мастера";
this.Load += new System.EventHandler(this.FormMasters_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private DataGridView dataGridView;
private Button buttonAdd;
private Button buttonUpd;
private Button buttonDel;
private Button buttonRef;
}
}

106
BeautySalon/FormMasters.cs Normal file
View File

@ -0,0 +1,106 @@
using BeautySalonContracts.BindingModels;
using BeautySalonContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
namespace BeautySalon
{
public partial class FormMasters : Form
{
private readonly ILogger _logger;
private readonly IMasterLogic _logic;
public FormMasters(ILogger<FormMasters> logger, IMasterLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void LoadData()
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["MasterFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["MasterServices"].Visible = false;
}
_logger.LogInformation("Загрузка мастеров");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки мастеров");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void FormMasters_Load(object sender, EventArgs e)
{
LoadData();
}
private void ButtonAdd_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 ButtonUpd_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormMaster));
if (service is FormMaster form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Удаление мастера");
try
{
if (!_logic.Delete(new MasterBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления мастера");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

119
BeautySalon/FormService.Designer.cs generated Normal file
View File

@ -0,0 +1,119 @@
namespace BeautySalon
{
partial class FormService
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.buttonSave = new System.Windows.Forms.Button();
this.labelName = new System.Windows.Forms.Label();
this.textBoxName = new System.Windows.Forms.TextBox();
this.labelCost = new System.Windows.Forms.Label();
this.textBoxCost = new System.Windows.Forms.TextBox();
this.buttonCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(170, 76);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(75, 23);
this.buttonSave.TabIndex = 0;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
// labelName
//
this.labelName.AutoSize = true;
this.labelName.Location = new System.Drawing.Point(12, 22);
this.labelName.Name = "labelName";
this.labelName.Size = new System.Drawing.Size(62, 15);
this.labelName.TabIndex = 1;
this.labelName.Text = "Название:";
//
// textBoxName
//
this.textBoxName.Location = new System.Drawing.Point(82, 19);
this.textBoxName.Name = "textBoxName";
this.textBoxName.Size = new System.Drawing.Size(247, 23);
this.textBoxName.TabIndex = 2;
//
// labelCost
//
this.labelCost.AutoSize = true;
this.labelCost.Location = new System.Drawing.Point(12, 50);
this.labelCost.Name = "labelCost";
this.labelCost.Size = new System.Drawing.Size(38, 15);
this.labelCost.TabIndex = 3;
this.labelCost.Text = "Цена:";
//
// textBoxCost
//
this.textBoxCost.Location = new System.Drawing.Point(82, 47);
this.textBoxCost.Name = "textBoxCost";
this.textBoxCost.Size = new System.Drawing.Size(128, 23);
this.textBoxCost.TabIndex = 4;
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(254, 76);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
this.buttonCancel.TabIndex = 5;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// FormService
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(341, 107);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.textBoxCost);
this.Controls.Add(this.labelCost);
this.Controls.Add(this.textBoxName);
this.Controls.Add(this.labelName);
this.Controls.Add(this.buttonSave);
this.Name = "FormService";
this.Text = "Услуга";
this.Load += new System.EventHandler(this.FormService_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Button buttonSave;
private Label labelName;
private TextBox textBoxName;
private Label labelCost;
private TextBox textBoxCost;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,82 @@
using BeautySalonContracts.BindingModels;
using BeautySalonContracts.BusinessLogicsContracts;
using BeautySalonContracts.SearchModels;
using Microsoft.Extensions.Logging;
namespace BeautySalon
{
public partial class FormService : Form
{
private readonly ILogger _logger;
private readonly IServiceLogic _logic;
private int? _id;
public int Id { set { _id = value; } }
public FormService(ILogger<FormService> logger, IServiceLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxName.Text))
{
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение услуги");
try
{
var model = new ServiceBindingModel
{
Id = _id ?? 0,
ServiceName = textBoxName.Text,
Cost = Convert.ToDouble(textBoxCost.Text)
};
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения услуги");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
private void FormService_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
try
{
_logger.LogInformation("Получение услуги");
var view = _logic.ReadElement(new ServiceSearchModel { Id = _id.Value });
if (view != null)
{
textBoxName.Text = view.ServiceName;
textBoxCost.Text = view.Cost.ToString();
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения услуги");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

114
BeautySalon/FormServices.Designer.cs generated Normal file
View File

@ -0,0 +1,114 @@
namespace BeautySalon
{
partial class FormServices
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonAdd = new System.Windows.Forms.Button();
this.buttonUpd = new System.Windows.Forms.Button();
this.buttonDel = new System.Windows.Forms.Button();
this.buttonRef = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// dataGridView
//
this.dataGridView.BackgroundColor = System.Drawing.SystemColors.Control;
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(12, 12);
this.dataGridView.Name = "dataGridView";
this.dataGridView.Size = new System.Drawing.Size(357, 426);
this.dataGridView.TabIndex = 0;
//
// buttonAdd
//
this.buttonAdd.Location = new System.Drawing.Point(411, 31);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(75, 23);
this.buttonAdd.TabIndex = 1;
this.buttonAdd.Text = "Добавить";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
//
// buttonUpd
//
this.buttonUpd.Location = new System.Drawing.Point(411, 79);
this.buttonUpd.Name = "buttonUpd";
this.buttonUpd.Size = new System.Drawing.Size(75, 23);
this.buttonUpd.TabIndex = 2;
this.buttonUpd.Text = "Изменить";
this.buttonUpd.UseVisualStyleBackColor = true;
this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
//
// buttonDel
//
this.buttonDel.Location = new System.Drawing.Point(411, 131);
this.buttonDel.Name = "buttonDel";
this.buttonDel.Size = new System.Drawing.Size(75, 23);
this.buttonDel.TabIndex = 3;
this.buttonDel.Text = "Удалить";
this.buttonDel.UseVisualStyleBackColor = true;
this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click);
//
// buttonRef
//
this.buttonRef.Location = new System.Drawing.Point(411, 187);
this.buttonRef.Name = "buttonRef";
this.buttonRef.Size = new System.Drawing.Size(75, 23);
this.buttonRef.TabIndex = 4;
this.buttonRef.Text = "Обновить";
this.buttonRef.UseVisualStyleBackColor = true;
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
//
// FormServices
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(520, 450);
this.Controls.Add(this.buttonRef);
this.Controls.Add(this.buttonDel);
this.Controls.Add(this.buttonUpd);
this.Controls.Add(this.buttonAdd);
this.Controls.Add(this.dataGridView);
this.Name = "FormServices";
this.Text = "Услуги";
this.Load += new System.EventHandler(this.FormServices_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private DataGridView dataGridView;
private Button buttonAdd;
private Button buttonUpd;
private Button buttonDel;
private Button buttonRef;
}
}

102
BeautySalon/FormServices.cs Normal file
View File

@ -0,0 +1,102 @@
using BeautySalonContracts.BindingModels;
using BeautySalonContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
namespace BeautySalon
{
public partial class FormServices : Form
{
private readonly ILogger _logger;
private readonly IServiceLogic _logic;
public FormServices(ILogger<FormServices> logger, IServiceLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormServices_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["ServiceName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["Cost"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка услуг");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки услуг");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormService));
if (service is FormService form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormService));
if (service is FormService form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Удаление услуги");
try
{
if (!_logic.Delete(new ServiceBindingModel { Id = id }))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления услуги");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -1,14 +1,14 @@
namespace BeautySalon
{
partial class Form1
partial class FormTests
{
/// <summary>
/// Required designer variable.
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
@ -23,15 +23,15 @@
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </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 = "Form1";
this.Text = "FormTests";
}
#endregion

20
BeautySalon/FormTests.cs Normal file
View File

@ -0,0 +1,20 @@
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
{
public partial class FormTests : Form
{
public FormTests()
{
InitializeComponent();
}
}
}

View File

@ -1,17 +1,53 @@
using BeautySalonBusinessLogic.BusinessLogics;
using BeautySalonContracts.BusinessLogicsContracts;
using BeautySalonContracts.StoragesContracts;
using BeautySalonDatabaseImplement.Implements;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
namespace BeautySalon
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
private static ServiceProvider? _serviceProvider;
public static ServiceProvider? ServiceProvider => _serviceProvider;
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
var services = new ServiceCollection();
ConfigureServices(services);
_serviceProvider = services.BuildServiceProvider();
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
}
private static void ConfigureServices(ServiceCollection services)
{
services.AddLogging(option =>
{
option.SetMinimumLevel(LogLevel.Information);
option.AddNLog("nlog.config");
});
services.AddTransient<IServiceStorage, ServiceStorage>();
services.AddTransient<IVisitStorage, VisitStorage>();
services.AddTransient<IMasterStorage, MasterStorage>();
services.AddTransient<IClientStorage, ClientStorage>();
services.AddTransient<IServiceLogic, ServiceLogic>();
services.AddTransient<IVisitLogic, VisitLogic>();
services.AddTransient<IMasterLogic, MasterLogic>();
services.AddTransient<IClientLogic, ClientLogic>();
services.AddTransient<FormMain>();
services.AddTransient<FormService>();
services.AddTransient<FormServices>();
services.AddTransient<FormCreateVisit>();
services.AddTransient<FormMaster>();
services.AddTransient<FormMasters>();
services.AddTransient<FormClient>();
services.AddTransient<FormClients>();
services.AddTransient<FormMasterService>();
}
}
}

View File

@ -89,11 +89,11 @@ namespace BeautySalonBusinessLogic.BusinessLogics
{
throw new ArgumentNullException("Нет ФИО мастера", nameof(model.MasterFIO));
}
if (string.IsNullOrEmpty(model.Specialization))
if (model.Wage <= 0)
{
throw new ArgumentNullException("Нет специализации мастера", nameof(model.MasterFIO));
throw new ArgumentNullException("Зарплата должна быть больше 0", nameof(model.Wage));
}
_logger.LogInformation("Master. MasterFIO:{MasterFIO}. Specialization:{ Specialization}. Id: { Id} ", model.MasterFIO, model.Specialization, model.Id);
_logger.LogInformation("Master. MasterFIO:{MasterFIO}. Wage:{ Wage}. Id: { Id} ", model.MasterFIO, model.Wage, model.Id);
var element = _masterStorage.GetElement(new MasterSearchModel
{
MasterFIO = model.MasterFIO

View File

@ -81,10 +81,6 @@ namespace BeautySalonBusinessLogic.BusinessLogics
{
throw new ArgumentNullException(nameof(model));
}
if (model.Count <= 0)
{
throw new ArgumentNullException("Количество услуг должно быть больше 0", nameof(model.Count));
}
if (model.Sum <= 0)
{
throw new ArgumentNullException("Суммарная стоимость должна быть больше 0", nameof(model.Sum));

View File

@ -3,7 +3,7 @@
public interface IMasterModel : IId
{
string MasterFIO { get; }
string Specialization { get; }
public Dictionary<int, (IServiceModel, int)> MasterServices { get; }
double Wage { get; }
public Dictionary<int, (IServiceModel, double)> MasterServices { get; }
}
}

View File

@ -7,6 +7,5 @@
int MasterId { get; }
int ServiceId { get; }
double Sum { get; }
int Count { get; }
}
}

View File

@ -12,7 +12,11 @@ namespace BeautySalonDatabaseImplement.Implements
public VisitViewModel? Delete(VisitBindingModel model)
{
using var context = new BeautySalonDatabase();
var element = context.Visits.FirstOrDefault(rec => rec.Id == model.Id);
var element = context.Visits
.Include(x => x.Master)
.Include(x => x.Client)
.Include(x => x.Service)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Visits.Remove(element);
@ -39,13 +43,21 @@ namespace BeautySalonDatabaseImplement.Implements
return new();
}
using var context = new BeautySalonDatabase();
return context.Visits.Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList();
return context.Visits
.Where(x => x.ClientId == model.ClientId)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public List<VisitViewModel> GetFullList()
{
using var context = new BeautySalonDatabase();
return context.Visits.Select(x => x.GetViewModel).ToList();
return context.Visits
.Include(x => x.Service)
.Include(x => x.Master)
.Include(x => x.Client)
.Select(x => x.GetViewModel).ToList();
}
public VisitViewModel? Insert(VisitBindingModel model)
@ -58,7 +70,12 @@ namespace BeautySalonDatabaseImplement.Implements
using var context = new BeautySalonDatabase();
context.Visits.Add(newVisit);
context.SaveChanges();
return newVisit.GetViewModel;
return context.Visits
.Include(x => x.Service)
.Include(x => x.Master)
.Include(x => x.Client)
.FirstOrDefault(x => x.Id == newVisit.Id)
?.GetViewModel;
}
public VisitViewModel? Update(VisitBindingModel model)

View File

@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace BeautySalonDatabaseImplement.Migrations
{
[DbContext(typeof(BeautySalonDatabase))]
[Migration("20230513120245_InitialCreate")]
[Migration("20230513191649_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
@ -58,9 +58,8 @@ namespace BeautySalonDatabaseImplement.Migrations
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Specialization")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Wage")
.HasColumnType("float");
b.HasKey("Id");
@ -75,15 +74,15 @@ namespace BeautySalonDatabaseImplement.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("MasterId")
.HasColumnType("int");
b.Property<int>("ServiceId")
.HasColumnType("int");
b.Property<double>("Wage")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("MasterId");
@ -108,6 +107,9 @@ namespace BeautySalonDatabaseImplement.Migrations
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Time")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Services");
@ -128,9 +130,6 @@ namespace BeautySalonDatabaseImplement.Migrations
b.Property<int>("ClientId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<DateTime>("DateOfVisit")
.HasColumnType("datetime2");

View File

@ -32,7 +32,7 @@ namespace BeautySalonDatabaseImplement.Migrations
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
MasterFIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
Specialization = table.Column<string>(type: "nvarchar(max)", nullable: false)
Wage = table.Column<double>(type: "float", nullable: false)
},
constraints: table =>
{
@ -46,7 +46,8 @@ namespace BeautySalonDatabaseImplement.Migrations
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ServiceName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Cost = table.Column<double>(type: "float", nullable: false)
Cost = table.Column<double>(type: "float", nullable: false),
Time = table.Column<double>(type: "float", nullable: false)
},
constraints: table =>
{
@ -61,7 +62,7 @@ namespace BeautySalonDatabaseImplement.Migrations
.Annotation("SqlServer:Identity", "1, 1"),
MasterId = table.Column<int>(type: "int", nullable: false),
ServiceId = table.Column<int>(type: "int", nullable: false),
Count = table.Column<int>(type: "int", nullable: false)
Wage = table.Column<double>(type: "float", nullable: false)
},
constraints: table =>
{
@ -93,8 +94,7 @@ namespace BeautySalonDatabaseImplement.Migrations
ClientFIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
MasterFIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
ServiceName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Sum = table.Column<double>(type: "float", nullable: false),
Count = table.Column<int>(type: "int", nullable: false)
Sum = table.Column<double>(type: "float", nullable: false)
},
constraints: table =>
{

View File

@ -55,9 +55,8 @@ namespace BeautySalonDatabaseImplement.Migrations
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Specialization")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Wage")
.HasColumnType("float");
b.HasKey("Id");
@ -72,15 +71,15 @@ namespace BeautySalonDatabaseImplement.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("MasterId")
.HasColumnType("int");
b.Property<int>("ServiceId")
.HasColumnType("int");
b.Property<double>("Wage")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("MasterId");
@ -105,6 +104,9 @@ namespace BeautySalonDatabaseImplement.Migrations
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Time")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Services");
@ -125,9 +127,6 @@ namespace BeautySalonDatabaseImplement.Migrations
b.Property<int>("ClientId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<DateTime>("DateOfVisit")
.HasColumnType("datetime2");

View File

@ -12,18 +12,18 @@ namespace BeautySalonDatabaseImplement.Models
[Required]
public string MasterFIO { get; set; } = string.Empty;
[Required]
public string Specialization { get; set; } = string.Empty;
private Dictionary<int, (IServiceModel, int)>? _masterServices = null;
public double Wage { get; set; }
private Dictionary<int, (IServiceModel, double)>? _masterServices = null;
[NotMapped]
public Dictionary<int, (IServiceModel, int)> MasterServices
public Dictionary<int, (IServiceModel, double)> MasterServices
{
get
{
if (_masterServices == null)
{
_masterServices = Services
.ToDictionary(recPC => recPC.MasterId, recPC =>
(recPC.Service as IServiceModel, recPC.Count));
.ToDictionary(recPC => recPC.ServiceId, recPC =>
(recPC.Service as IServiceModel, recPC.Wage));
}
return _masterServices;
}
@ -38,26 +38,33 @@ namespace BeautySalonDatabaseImplement.Models
{
Id = model.Id,
MasterFIO = model.MasterFIO,
Specialization = model.Specialization,
Wage = model.Wage,
Services = model.MasterServices.Select(x => new MasterService
{
Service = context.Services.First(y => y.Id == x.Key),
Count = x.Value.Item2
Wage = x.Value.Item2
}).ToList()
};
}
public void Update(MasterBindingModel model)
{
MasterFIO = model.MasterFIO;
Specialization = model.Specialization;
Wage = model.Wage;
}
public MasterViewModel GetViewModel => new()
public MasterViewModel GetViewModel
{
Id = Id,
MasterFIO = MasterFIO,
Specialization = Specialization,
MasterServices = MasterServices
};
get
{
using var context = new BeautySalonDatabase();
return new MasterViewModel
{
Id = Id,
MasterFIO = MasterFIO,
Wage = Wage,
MasterServices = MasterServices
};
}
}
public void UpdateServices(BeautySalonDatabase context, MasterBindingModel model)
{
var masterServices = context.MasterServices.Where(rec => rec.MasterId == model.Id).ToList();
@ -69,8 +76,7 @@ namespace BeautySalonDatabaseImplement.Models
// обновили количество у существующих записей
foreach (var updateService in masterServices)
{
updateService.Count =
model.MasterServices[updateService.ServiceId].Item2;
updateService.Wage = model.MasterServices[updateService.ServiceId].Item2;
model.MasterServices.Remove(updateService.ServiceId);
}
context.SaveChanges();
@ -82,7 +88,7 @@ namespace BeautySalonDatabaseImplement.Models
{
Master = master,
Service = context.Services.First(x => x.Id == pc.Key),
Count = pc.Value.Item2
Wage = pc.Value.Item2
});
context.SaveChanges();
}

View File

@ -10,7 +10,7 @@ namespace BeautySalonDatabaseImplement.Models
[Required]
public int ServiceId { get; set; }
[Required]
public int Count { get; set; }
public double Wage { get; set; }
public virtual Service Service { get; set; } = new();
public virtual Master Master { get; set; } = new();
}

View File

@ -13,6 +13,8 @@ namespace BeautySalonDatabaseImplement.Models
public string ServiceName { get; private set; } = string.Empty;
[Required]
public double Cost { get; set; }
[Required]
public double Time { get; set; }
[ForeignKey("ServiceId")]
public virtual List<MasterService> MasterServices { get; set; } = new();
public static Service? Create(ServiceBindingModel model)

View File

@ -10,7 +10,6 @@ namespace BeautySalonDatabaseImplement.Models
public int Id { get; private set; }
[Required]
public DateTime DateOfVisit { get; private set; }
[Required]
public int ClientId { get; private set; }
public int MasterId { get; private set; }
public int ServiceId { get; private set; }
@ -19,9 +18,7 @@ namespace BeautySalonDatabaseImplement.Models
public string ServiceName { get; set; } = string.Empty;
[Required]
public double Sum { get; private set; }
[Required]
public int Count { get; private set; }
public virtual Client Client { get; set; }
public Client Client { get; set; }
public virtual Master Master { get; set; }
public virtual Service Service { get; set; }
@ -41,7 +38,6 @@ namespace BeautySalonDatabaseImplement.Models
MasterFIO = model.MasterFIO,
ServiceId = model.ServiceId,
ServiceName = model.ServiceName,
Count = model.Count,
Sum = model.Sum,
DateOfVisit = model.DateOfVisit
};
@ -54,29 +50,28 @@ namespace BeautySalonDatabaseImplement.Models
return;
}
ClientId = model.ClientId;
ClientFIO = model.ClientFIO;
MasterId = model.MasterId;
MasterFIO = model.MasterFIO;
ServiceId = model.ServiceId;
ServiceName = model.ServiceName;
Count = model.Count;
Sum = model.Sum;
DateOfVisit = model.DateOfVisit;
}
public VisitViewModel GetViewModel => new()
public VisitViewModel GetViewModel
{
Id = Id,
ClientId = ClientId,
ClientFIO = ClientFIO,
MasterId = MasterId,
MasterFIO = MasterFIO,
ServiceId = ServiceId,
ServiceName = ServiceName,
Count = Count,
Sum = Sum,
DateOfVisit = DateOfVisit
};
get
{
using var context = new BeautySalonDatabase();
return new VisitViewModel
{
Id = Id,
ClientId = ClientId,
ClientFIO = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty,
MasterId = MasterId,
MasterFIO = context.Masters.FirstOrDefault(x => x.Id == MasterId)?.MasterFIO ?? string.Empty,
ServiceId = ServiceId,
ServiceName = context.Services.FirstOrDefault(x => x.Id == ServiceId)?.ServiceName ?? string.Empty,
Sum = Sum,
DateOfVisit = DateOfVisit
};
}
}
}
}

View File

@ -6,7 +6,7 @@ namespace BeautySalonContracts.BindingModels
{
public int Id { get; set; }
public string MasterFIO { get; set; } = string.Empty;
public string Specialization { get; set; } = string.Empty;
public Dictionary<int, (IServiceModel, int)> MasterServices { get; set; } = new();
public double Wage { get; set; }
public Dictionary<int, (IServiceModel, double)> MasterServices { get; set; } = new();
}
}

View File

@ -13,6 +13,5 @@ namespace BeautySalonContracts.BindingModels
public string MasterFIO { get; set; } = string.Empty;
public string ServiceName { get; set; } = string.Empty;
public double Sum { get; set; }
public int Count { get; set; }
}
}

View File

@ -4,6 +4,5 @@
{
public int? Id { get; set; }
public string? MasterFIO { get; set; }
public string? Specilization { get; set; }
}
}

View File

@ -3,5 +3,6 @@
public class VisitSearchModel
{
public int? Id { get; set; }
public int? ClientId { get; set; }
}
}

View File

@ -8,8 +8,8 @@ namespace BeautySalonContracts.ViewModels
public int Id { get; set; }
[DisplayName("ФИО мастера")]
public string MasterFIO { get; set; } = string.Empty;
[DisplayName("Специализация")]
public string Specialization { get; set; } = string.Empty;
public Dictionary<int, (IServiceModel, int)> MasterServices { get; set; } = new();
[DisplayName("Зарплата")]
public double Wage { get; set; }
public Dictionary<int, (IServiceModel, double)> MasterServices { get; set; } = new();
}
}

View File

@ -19,7 +19,5 @@ namespace BeautySalonContracts.ViewModels
public string ServiceName { get; set; } = string.Empty;
[DisplayName("Сумма")]
public double Sum { get; set; }
[DisplayName("Количество")]
public int Count { get; set; }
}
}