hard lab2 complete
This commit is contained in:
parent
06be024b14
commit
157df090c8
212
FlowerShop/FlowerShop/FormFlowers.Designer.cs
generated
212
FlowerShop/FlowerShop/FormFlowers.Designer.cs
generated
@ -1,114 +1,114 @@
|
|||||||
namespace FlowerShopView
|
namespace FlowerShopView
|
||||||
{
|
{
|
||||||
partial class FormFlowers
|
partial class FormFlowers
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required designer variable.
|
/// Required designer variable.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private System.ComponentModel.IContainer components = null;
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Clean up any resources being used.
|
/// Clean up any resources being used.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing && (components != null))
|
if (disposing && (components != null))
|
||||||
{
|
{
|
||||||
components.Dispose();
|
components.Dispose();
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Windows Form Designer generated code
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required method for Designer support - do not modify
|
/// Required method for Designer support - do not modify
|
||||||
/// the contents of this method with the code editor.
|
/// the contents of this method with the code editor.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
buttonRef = new Button();
|
buttonRef = new Button();
|
||||||
buttonDel = new Button();
|
buttonDel = new Button();
|
||||||
buttonUpd = new Button();
|
buttonUpd = new Button();
|
||||||
buttonAdd = new Button();
|
buttonAdd = new Button();
|
||||||
dataGridView = new DataGridView();
|
dataGridView = new DataGridView();
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// buttonRef
|
// buttonRef
|
||||||
//
|
//
|
||||||
buttonRef.Location = new Point(283, 126);
|
buttonRef.Location = new Point(283, 126);
|
||||||
buttonRef.Name = "buttonRef";
|
buttonRef.Name = "buttonRef";
|
||||||
buttonRef.Size = new Size(103, 28);
|
buttonRef.Size = new Size(103, 28);
|
||||||
buttonRef.TabIndex = 9;
|
buttonRef.TabIndex = 9;
|
||||||
buttonRef.Text = "Обновить";
|
buttonRef.Text = "Обновить";
|
||||||
buttonRef.UseVisualStyleBackColor = true;
|
buttonRef.UseVisualStyleBackColor = true;
|
||||||
buttonRef.Click += buttonRef_Click;
|
buttonRef.Click += buttonRef_Click;
|
||||||
//
|
//
|
||||||
// buttonDel
|
// buttonDel
|
||||||
//
|
//
|
||||||
buttonDel.Location = new Point(283, 92);
|
buttonDel.Location = new Point(283, 92);
|
||||||
buttonDel.Name = "buttonDel";
|
buttonDel.Name = "buttonDel";
|
||||||
buttonDel.Size = new Size(103, 28);
|
buttonDel.Size = new Size(103, 28);
|
||||||
buttonDel.TabIndex = 8;
|
buttonDel.TabIndex = 8;
|
||||||
buttonDel.Text = "Удалить";
|
buttonDel.Text = "Удалить";
|
||||||
buttonDel.UseVisualStyleBackColor = true;
|
buttonDel.UseVisualStyleBackColor = true;
|
||||||
buttonDel.Click += buttonDel_Click;
|
buttonDel.Click += buttonDel_Click;
|
||||||
//
|
//
|
||||||
// buttonUpd
|
// buttonUpd
|
||||||
//
|
//
|
||||||
buttonUpd.Location = new Point(283, 58);
|
buttonUpd.Location = new Point(283, 58);
|
||||||
buttonUpd.Name = "buttonUpd";
|
buttonUpd.Name = "buttonUpd";
|
||||||
buttonUpd.Size = new Size(103, 28);
|
buttonUpd.Size = new Size(103, 28);
|
||||||
buttonUpd.TabIndex = 7;
|
buttonUpd.TabIndex = 7;
|
||||||
buttonUpd.Text = "Изменить";
|
buttonUpd.Text = "Изменить";
|
||||||
buttonUpd.UseVisualStyleBackColor = true;
|
buttonUpd.UseVisualStyleBackColor = true;
|
||||||
buttonUpd.Click += buttonUpd_Click;
|
buttonUpd.Click += buttonUpd_Click;
|
||||||
//
|
//
|
||||||
// buttonAdd
|
// buttonAdd
|
||||||
//
|
//
|
||||||
buttonAdd.Location = new Point(283, 24);
|
buttonAdd.Location = new Point(283, 24);
|
||||||
buttonAdd.Name = "buttonAdd";
|
buttonAdd.Name = "buttonAdd";
|
||||||
buttonAdd.Size = new Size(103, 28);
|
buttonAdd.Size = new Size(103, 28);
|
||||||
buttonAdd.TabIndex = 6;
|
buttonAdd.TabIndex = 6;
|
||||||
buttonAdd.Text = "Добавить";
|
buttonAdd.Text = "Добавить";
|
||||||
buttonAdd.UseVisualStyleBackColor = true;
|
buttonAdd.UseVisualStyleBackColor = true;
|
||||||
buttonAdd.Click += buttonAdd_Click;
|
buttonAdd.Click += buttonAdd_Click;
|
||||||
//
|
//
|
||||||
// dataGridView
|
// dataGridView
|
||||||
//
|
//
|
||||||
dataGridView.BackgroundColor = Color.White;
|
dataGridView.BackgroundColor = Color.White;
|
||||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
dataGridView.Location = new Point(12, 12);
|
dataGridView.Location = new Point(12, 12);
|
||||||
dataGridView.Name = "dataGridView";
|
dataGridView.Name = "dataGridView";
|
||||||
dataGridView.RowTemplate.Height = 25;
|
dataGridView.RowTemplate.Height = 25;
|
||||||
dataGridView.Size = new Size(240, 426);
|
dataGridView.Size = new Size(240, 426);
|
||||||
dataGridView.TabIndex = 5;
|
dataGridView.TabIndex = 5;
|
||||||
//
|
//
|
||||||
// FormFlowers
|
// FormFlowers
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(407, 450);
|
ClientSize = new Size(407, 450);
|
||||||
Controls.Add(buttonRef);
|
Controls.Add(buttonRef);
|
||||||
Controls.Add(buttonDel);
|
Controls.Add(buttonDel);
|
||||||
Controls.Add(buttonUpd);
|
Controls.Add(buttonUpd);
|
||||||
Controls.Add(buttonAdd);
|
Controls.Add(buttonAdd);
|
||||||
Controls.Add(dataGridView);
|
Controls.Add(dataGridView);
|
||||||
Name = "FormFlowers";
|
Name = "FormFlowers";
|
||||||
Text = "FormFlowers";
|
Text = "Цветы";
|
||||||
Load += FormFlowers_Load;
|
Load += FormFlowers_Load;
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private Button buttonRef;
|
private Button buttonRef;
|
||||||
private Button buttonDel;
|
private Button buttonDel;
|
||||||
private Button buttonUpd;
|
private Button buttonUpd;
|
||||||
private Button buttonAdd;
|
private Button buttonAdd;
|
||||||
private DataGridView dataGridView;
|
private DataGridView dataGridView;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,102 +4,102 @@ using FlowerShopContracts.BusinessLogicsContracts;
|
|||||||
|
|
||||||
namespace FlowerShopView
|
namespace FlowerShopView
|
||||||
{
|
{
|
||||||
public partial class FormFlowers : Form
|
public partial class FormFlowers : Form
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IFlowerLogic _logic;
|
private readonly IFlowerLogic _logic;
|
||||||
public FormFlowers(ILogger<FormFlowers> logger, IFlowerLogic logic)
|
public FormFlowers(ILogger<FormFlowers> logger, IFlowerLogic logic)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_logic = logic;
|
_logic = logic;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FormFlowers_Load(object sender, EventArgs e)
|
private void FormFlowers_Load(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
LoadData();
|
LoadData();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadData()
|
private void LoadData()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var list = _logic.ReadList(null);
|
var list = _logic.ReadList(null);
|
||||||
if (list != null)
|
if (list != null)
|
||||||
{
|
{
|
||||||
dataGridView.DataSource = list;
|
dataGridView.DataSource = list;
|
||||||
dataGridView.Columns["Id"].Visible = false;
|
dataGridView.Columns["Id"].Visible = false;
|
||||||
dataGridView.Columns["FlowerComponents"].Visible = false;
|
dataGridView.Columns["FlowerComponents"].Visible = false;
|
||||||
dataGridView.Columns["FlowerName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
dataGridView.Columns["FlowerName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
}
|
}
|
||||||
_logger.LogInformation("Загрузка компонентов");
|
_logger.LogInformation("Загрузка компонентов");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Ошибка загрузки компонентов");
|
_logger.LogError(ex, "Ошибка загрузки компонентов");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonAdd_Click(object sender, EventArgs e)
|
private void buttonAdd_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormFlower));
|
var service = Program.ServiceProvider?.GetService(typeof(FormFlower));
|
||||||
if (service is FormFlower form)
|
if (service is FormFlower form)
|
||||||
{
|
{
|
||||||
if (form.ShowDialog() == DialogResult.OK)
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
LoadData();
|
LoadData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonUpd_Click(object sender, EventArgs e)
|
private void buttonUpd_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (dataGridView.SelectedRows.Count == 1)
|
if (dataGridView.SelectedRows.Count == 1)
|
||||||
{
|
{
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormFlower));
|
var service = Program.ServiceProvider?.GetService(typeof(FormFlower));
|
||||||
if (service is FormFlower form)
|
if (service is FormFlower form)
|
||||||
{
|
{
|
||||||
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
if (form.ShowDialog() == DialogResult.OK)
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
LoadData();
|
LoadData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonDel_Click(object sender, EventArgs e)
|
private void buttonDel_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (dataGridView.SelectedRows.Count == 1)
|
if (dataGridView.SelectedRows.Count == 1)
|
||||||
{
|
{
|
||||||
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
{
|
{
|
||||||
int id =
|
int id =
|
||||||
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
_logger.LogInformation("Удаление записи");
|
_logger.LogInformation("Удаление записи");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!_logic.Delete(new FlowerBindingModel
|
if (!_logic.Delete(new FlowerBindingModel
|
||||||
{
|
{
|
||||||
Id = id
|
Id = id
|
||||||
}))
|
}))
|
||||||
{
|
{
|
||||||
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
|
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
|
||||||
}
|
}
|
||||||
LoadData();
|
LoadData();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Ошибка удаления записи");
|
_logger.LogError(ex, "Ошибка удаления записи");
|
||||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonRef_Click(object sender, EventArgs e)
|
private void buttonRef_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
LoadData();
|
LoadData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
<data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data>
|
||||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
</data>
|
</data>
|
||||||
|
371
FlowerShop/FlowerShop/FormMain.Designer.cs
generated
371
FlowerShop/FlowerShop/FormMain.Designer.cs
generated
@ -1,189 +1,198 @@
|
|||||||
namespace FlowerShopView
|
namespace FlowerShopView
|
||||||
{
|
{
|
||||||
partial class FormMain
|
partial class FormMain
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required designer variable.
|
/// Required designer variable.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private System.ComponentModel.IContainer components = null;
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Clean up any resources being used.
|
/// Clean up any resources being used.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing && (components != null))
|
if (disposing && (components != null))
|
||||||
{
|
{
|
||||||
components.Dispose();
|
components.Dispose();
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Windows Form Designer generated code
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required method for Designer support - do not modify
|
/// Required method for Designer support - do not modify
|
||||||
/// the contents of this method with the code editor.
|
/// the contents of this method with the code editor.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
menuStrip1 = new MenuStrip();
|
menuStrip1 = new MenuStrip();
|
||||||
справочникиToolStripMenuItem = new ToolStripMenuItem();
|
справочникиToolStripMenuItem = new ToolStripMenuItem();
|
||||||
ЦветыToolStripMenuItem = new ToolStripMenuItem();
|
ЦветыToolStripMenuItem = new ToolStripMenuItem();
|
||||||
КомпонентыToolStripMenuItem = new ToolStripMenuItem();
|
КомпонентыToolStripMenuItem = new ToolStripMenuItem();
|
||||||
магазиныToolStripMenuItem = new ToolStripMenuItem();
|
магазиныToolStripMenuItem = new ToolStripMenuItem();
|
||||||
dataGridView = new DataGridView();
|
продажаЦветовToolStripMenuItem = new ToolStripMenuItem();
|
||||||
buttonCreateOrder = new Button();
|
dataGridView = new DataGridView();
|
||||||
buttonTakeOrderInWork = new Button();
|
buttonCreateOrder = new Button();
|
||||||
buttonOrderReady = new Button();
|
buttonTakeOrderInWork = new Button();
|
||||||
buttonIssuedOrder = new Button();
|
buttonOrderReady = new Button();
|
||||||
buttonRef = new Button();
|
buttonIssuedOrder = new Button();
|
||||||
пополнениеМагазинаToolStripMenuItem = new ToolStripMenuItem();
|
buttonRef = new Button();
|
||||||
menuStrip1.SuspendLayout();
|
пополениеМагазинаToolStripMenuItem = new ToolStripMenuItem();
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
menuStrip1.SuspendLayout();
|
||||||
SuspendLayout();
|
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||||
//
|
SuspendLayout();
|
||||||
// menuStrip1
|
//
|
||||||
//
|
// menuStrip1
|
||||||
menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem });
|
//
|
||||||
menuStrip1.Location = new Point(0, 0);
|
menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, пополениеМагазинаToolStripMenuItem, продажаЦветовToolStripMenuItem });
|
||||||
menuStrip1.Name = "menuStrip1";
|
menuStrip1.Location = new Point(0, 0);
|
||||||
menuStrip1.Size = new Size(964, 24);
|
menuStrip1.Name = "menuStrip1";
|
||||||
menuStrip1.TabIndex = 0;
|
menuStrip1.Size = new Size(964, 24);
|
||||||
menuStrip1.Text = "menuStrip1";
|
menuStrip1.TabIndex = 0;
|
||||||
//
|
menuStrip1.Text = "menuStrip1";
|
||||||
// справочникиToolStripMenuItem
|
//
|
||||||
//
|
// справочникиToolStripMenuItem
|
||||||
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ЦветыToolStripMenuItem, КомпонентыToolStripMenuItem, магазиныToolStripMenuItem, пополнениеМагазинаToolStripMenuItem });
|
//
|
||||||
справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
|
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ЦветыToolStripMenuItem, КомпонентыToolStripMenuItem, магазиныToolStripMenuItem });
|
||||||
справочникиToolStripMenuItem.Size = new Size(94, 20);
|
справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
|
||||||
справочникиToolStripMenuItem.Text = "Справочники";
|
справочникиToolStripMenuItem.Size = new Size(94, 20);
|
||||||
//
|
справочникиToolStripMenuItem.Text = "Справочники";
|
||||||
// ЦветыToolStripMenuItem
|
//
|
||||||
//
|
// ЦветыToolStripMenuItem
|
||||||
ЦветыToolStripMenuItem.Name = "ЦветыToolStripMenuItem";
|
//
|
||||||
ЦветыToolStripMenuItem.Size = new Size(198, 22);
|
ЦветыToolStripMenuItem.Name = "ЦветыToolStripMenuItem";
|
||||||
ЦветыToolStripMenuItem.Text = "Цветы";
|
ЦветыToolStripMenuItem.Size = new Size(180, 22);
|
||||||
ЦветыToolStripMenuItem.Click += ЦветыToolStripMenuItem_Click;
|
ЦветыToolStripMenuItem.Text = "Цветы";
|
||||||
//
|
ЦветыToolStripMenuItem.Click += ЦветыToolStripMenuItem_Click;
|
||||||
// КомпонентыToolStripMenuItem
|
//
|
||||||
//
|
// КомпонентыToolStripMenuItem
|
||||||
КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem";
|
//
|
||||||
КомпонентыToolStripMenuItem.Size = new Size(198, 22);
|
КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem";
|
||||||
КомпонентыToolStripMenuItem.Text = "Компоненты";
|
КомпонентыToolStripMenuItem.Size = new Size(180, 22);
|
||||||
КомпонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click;
|
КомпонентыToolStripMenuItem.Text = "Компоненты";
|
||||||
//
|
КомпонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click;
|
||||||
// магазиныToolStripMenuItem
|
//
|
||||||
//
|
// магазиныToolStripMenuItem
|
||||||
магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem";
|
//
|
||||||
магазиныToolStripMenuItem.Size = new Size(198, 22);
|
магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem";
|
||||||
магазиныToolStripMenuItem.Text = "Магазины";
|
магазиныToolStripMenuItem.Size = new Size(180, 22);
|
||||||
магазиныToolStripMenuItem.Click += магазиныToolStripMenuItem_Click;
|
магазиныToolStripMenuItem.Text = "Магазины";
|
||||||
//
|
магазиныToolStripMenuItem.Click += магазиныToolStripMenuItem_Click;
|
||||||
// dataGridView
|
//
|
||||||
//
|
// продажаЦветовToolStripMenuItem
|
||||||
dataGridView.BackgroundColor = Color.White;
|
//
|
||||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
продажаЦветовToolStripMenuItem.Name = "продажаЦветовToolStripMenuItem";
|
||||||
dataGridView.Location = new Point(12, 27);
|
продажаЦветовToolStripMenuItem.Size = new Size(109, 20);
|
||||||
dataGridView.Name = "dataGridView";
|
продажаЦветовToolStripMenuItem.Text = "Продажа цветов";
|
||||||
dataGridView.RowTemplate.Height = 25;
|
продажаЦветовToolStripMenuItem.Click += продажаЦветовToolStripMenuItem_Click;
|
||||||
dataGridView.Size = new Size(739, 411);
|
//
|
||||||
dataGridView.TabIndex = 1;
|
// dataGridView
|
||||||
//
|
//
|
||||||
// buttonCreateOrder
|
dataGridView.BackgroundColor = Color.White;
|
||||||
//
|
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
buttonCreateOrder.Location = new Point(775, 55);
|
dataGridView.Location = new Point(12, 27);
|
||||||
buttonCreateOrder.Name = "buttonCreateOrder";
|
dataGridView.Name = "dataGridView";
|
||||||
buttonCreateOrder.Size = new Size(158, 32);
|
dataGridView.RowTemplate.Height = 25;
|
||||||
buttonCreateOrder.TabIndex = 2;
|
dataGridView.Size = new Size(739, 411);
|
||||||
buttonCreateOrder.Text = "Создать заказ";
|
dataGridView.TabIndex = 1;
|
||||||
buttonCreateOrder.UseVisualStyleBackColor = true;
|
//
|
||||||
buttonCreateOrder.Click += ButtonCreateOrder_Click;
|
// buttonCreateOrder
|
||||||
//
|
//
|
||||||
// buttonTakeOrderInWork
|
buttonCreateOrder.Location = new Point(775, 55);
|
||||||
//
|
buttonCreateOrder.Name = "buttonCreateOrder";
|
||||||
buttonTakeOrderInWork.Location = new Point(775, 110);
|
buttonCreateOrder.Size = new Size(158, 32);
|
||||||
buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
|
buttonCreateOrder.TabIndex = 2;
|
||||||
buttonTakeOrderInWork.Size = new Size(158, 34);
|
buttonCreateOrder.Text = "Создать заказ";
|
||||||
buttonTakeOrderInWork.TabIndex = 3;
|
buttonCreateOrder.UseVisualStyleBackColor = true;
|
||||||
buttonTakeOrderInWork.Text = "Отдать на выполнение";
|
buttonCreateOrder.Click += ButtonCreateOrder_Click;
|
||||||
buttonTakeOrderInWork.UseVisualStyleBackColor = true;
|
//
|
||||||
buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click;
|
// buttonTakeOrderInWork
|
||||||
//
|
//
|
||||||
// buttonOrderReady
|
buttonTakeOrderInWork.Location = new Point(775, 110);
|
||||||
//
|
buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
|
||||||
buttonOrderReady.Location = new Point(775, 168);
|
buttonTakeOrderInWork.Size = new Size(158, 34);
|
||||||
buttonOrderReady.Name = "buttonOrderReady";
|
buttonTakeOrderInWork.TabIndex = 3;
|
||||||
buttonOrderReady.Size = new Size(158, 34);
|
buttonTakeOrderInWork.Text = "Отдать на выполнение";
|
||||||
buttonOrderReady.TabIndex = 4;
|
buttonTakeOrderInWork.UseVisualStyleBackColor = true;
|
||||||
buttonOrderReady.Text = "Заказ готов";
|
buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click;
|
||||||
buttonOrderReady.UseVisualStyleBackColor = true;
|
//
|
||||||
buttonOrderReady.Click += ButtonOrderReady_Click;
|
// buttonOrderReady
|
||||||
//
|
//
|
||||||
// buttonIssuedOrder
|
buttonOrderReady.Location = new Point(775, 168);
|
||||||
//
|
buttonOrderReady.Name = "buttonOrderReady";
|
||||||
buttonIssuedOrder.Location = new Point(775, 230);
|
buttonOrderReady.Size = new Size(158, 34);
|
||||||
buttonIssuedOrder.Name = "buttonIssuedOrder";
|
buttonOrderReady.TabIndex = 4;
|
||||||
buttonIssuedOrder.Size = new Size(158, 34);
|
buttonOrderReady.Text = "Заказ готов";
|
||||||
buttonIssuedOrder.TabIndex = 5;
|
buttonOrderReady.UseVisualStyleBackColor = true;
|
||||||
buttonIssuedOrder.Text = "Заказ выдан";
|
buttonOrderReady.Click += ButtonOrderReady_Click;
|
||||||
buttonIssuedOrder.UseVisualStyleBackColor = true;
|
//
|
||||||
buttonIssuedOrder.Click += ButtonIssuedOrder_Click;
|
// buttonIssuedOrder
|
||||||
//
|
//
|
||||||
// buttonRef
|
buttonIssuedOrder.Location = new Point(775, 230);
|
||||||
//
|
buttonIssuedOrder.Name = "buttonIssuedOrder";
|
||||||
buttonRef.Location = new Point(775, 289);
|
buttonIssuedOrder.Size = new Size(158, 34);
|
||||||
buttonRef.Name = "buttonRef";
|
buttonIssuedOrder.TabIndex = 5;
|
||||||
buttonRef.Size = new Size(158, 34);
|
buttonIssuedOrder.Text = "Заказ выдан";
|
||||||
buttonRef.TabIndex = 6;
|
buttonIssuedOrder.UseVisualStyleBackColor = true;
|
||||||
buttonRef.Text = "Обновить список";
|
buttonIssuedOrder.Click += ButtonIssuedOrder_Click;
|
||||||
buttonRef.UseVisualStyleBackColor = true;
|
//
|
||||||
buttonRef.Click += ButtonRef_Click;
|
// buttonRef
|
||||||
//
|
//
|
||||||
// пополнениеМагазинаToolStripMenuItem
|
buttonRef.Location = new Point(775, 289);
|
||||||
//
|
buttonRef.Name = "buttonRef";
|
||||||
пополнениеМагазинаToolStripMenuItem.Name = "пополнениеМагазинаToolStripMenuItem";
|
buttonRef.Size = new Size(158, 34);
|
||||||
пополнениеМагазинаToolStripMenuItem.Size = new Size(198, 22);
|
buttonRef.TabIndex = 6;
|
||||||
пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина";
|
buttonRef.Text = "Обновить список";
|
||||||
пополнениеМагазинаToolStripMenuItem.Click += пополнениеМагазинаToolStripMenuItem_Click;
|
buttonRef.UseVisualStyleBackColor = true;
|
||||||
//
|
buttonRef.Click += ButtonRef_Click;
|
||||||
// FormMain
|
//
|
||||||
//
|
// пополениеМагазинаToolStripMenuItem
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
//
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
пополениеМагазинаToolStripMenuItem.Name = "пополениеМагазинаToolStripMenuItem";
|
||||||
ClientSize = new Size(964, 450);
|
пополениеМагазинаToolStripMenuItem.Size = new Size(136, 20);
|
||||||
Controls.Add(buttonRef);
|
пополениеМагазинаToolStripMenuItem.Text = "Пополение магазина";
|
||||||
Controls.Add(buttonIssuedOrder);
|
пополениеМагазинаToolStripMenuItem.Click += пополениеМагазинаToolStripMenuItem_Click;
|
||||||
Controls.Add(buttonOrderReady);
|
//
|
||||||
Controls.Add(buttonTakeOrderInWork);
|
// FormMain
|
||||||
Controls.Add(buttonCreateOrder);
|
//
|
||||||
Controls.Add(dataGridView);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
Controls.Add(menuStrip1);
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
MainMenuStrip = menuStrip1;
|
ClientSize = new Size(964, 450);
|
||||||
Name = "FormMain";
|
Controls.Add(buttonRef);
|
||||||
Text = "Цветочный магазин";
|
Controls.Add(buttonIssuedOrder);
|
||||||
Load += FormMain_Load;
|
Controls.Add(buttonOrderReady);
|
||||||
menuStrip1.ResumeLayout(false);
|
Controls.Add(buttonTakeOrderInWork);
|
||||||
menuStrip1.PerformLayout();
|
Controls.Add(buttonCreateOrder);
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
Controls.Add(dataGridView);
|
||||||
ResumeLayout(false);
|
Controls.Add(menuStrip1);
|
||||||
PerformLayout();
|
MainMenuStrip = menuStrip1;
|
||||||
}
|
Name = "FormMain";
|
||||||
|
Text = "Цветочный магазин";
|
||||||
|
Load += FormMain_Load;
|
||||||
|
menuStrip1.ResumeLayout(false);
|
||||||
|
menuStrip1.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private MenuStrip menuStrip1;
|
private MenuStrip menuStrip1;
|
||||||
private ToolStripMenuItem справочникиToolStripMenuItem;
|
private ToolStripMenuItem справочникиToolStripMenuItem;
|
||||||
private ToolStripMenuItem ЦветыToolStripMenuItem;
|
private ToolStripMenuItem ЦветыToolStripMenuItem;
|
||||||
private ToolStripMenuItem КомпонентыToolStripMenuItem;
|
private ToolStripMenuItem КомпонентыToolStripMenuItem;
|
||||||
private DataGridView dataGridView;
|
private DataGridView dataGridView;
|
||||||
private Button buttonCreateOrder;
|
private Button buttonCreateOrder;
|
||||||
private Button buttonTakeOrderInWork;
|
private Button buttonTakeOrderInWork;
|
||||||
private Button buttonOrderReady;
|
private Button buttonOrderReady;
|
||||||
private Button buttonIssuedOrder;
|
private Button buttonIssuedOrder;
|
||||||
private Button buttonRef;
|
private Button buttonRef;
|
||||||
private ToolStripMenuItem магазиныToolStripMenuItem;
|
private ToolStripMenuItem магазиныToolStripMenuItem;
|
||||||
private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem;
|
private ToolStripMenuItem продажаЦветовToolStripMenuItem;
|
||||||
}
|
private ToolStripMenuItem пополениеМагазинаToolStripMenuItem;
|
||||||
|
}
|
||||||
}
|
}
|
@ -4,157 +4,164 @@ using Microsoft.Extensions.Logging;
|
|||||||
|
|
||||||
namespace FlowerShopView
|
namespace FlowerShopView
|
||||||
{
|
{
|
||||||
public partial class FormMain : Form
|
public partial class FormMain : Form
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IOrderLogic _orderLogic;
|
private readonly IOrderLogic _orderLogic;
|
||||||
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic)
|
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_orderLogic = orderLogic;
|
_orderLogic = orderLogic;
|
||||||
}
|
}
|
||||||
private void FormMain_Load(object sender, EventArgs e)
|
private void FormMain_Load(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
LoadData();
|
LoadData();
|
||||||
}
|
}
|
||||||
private void LoadData()
|
private void LoadData()
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Загрузка заказов");
|
_logger.LogInformation("Загрузка заказов");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var list = _orderLogic.ReadList(null);
|
var list = _orderLogic.ReadList(null);
|
||||||
if (list != null)
|
if (list != null)
|
||||||
{
|
{
|
||||||
dataGridView.DataSource = list;
|
dataGridView.DataSource = list;
|
||||||
dataGridView.Columns["FlowerId"].Visible = false;
|
dataGridView.Columns["FlowerId"].Visible = false;
|
||||||
dataGridView.Columns["FlowerName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
dataGridView.Columns["FlowerName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Ошибка загрузки заказов");
|
_logger.LogError(ex, "Ошибка загрузки заказов");
|
||||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e)
|
private void ButtonCreateOrder_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
|
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
|
||||||
if (service is FormComponents form)
|
if (service is FormCreateOrder form)
|
||||||
{
|
{
|
||||||
form.ShowDialog();
|
form.ShowDialog();
|
||||||
}
|
LoadData();
|
||||||
}
|
}
|
||||||
private void ЦветыToolStripMenuItem_Click(object sender, EventArgs e)
|
}
|
||||||
{
|
private void ButtonTakeOrderInWork_Click(object sender, EventArgs e)
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormFlowers));
|
{
|
||||||
if (service is FormFlowers form)
|
if (dataGridView.SelectedRows.Count == 1)
|
||||||
{
|
{
|
||||||
form.ShowDialog();
|
int id =
|
||||||
}
|
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
}
|
_logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id);
|
||||||
private void магазиныToolStripMenuItem_Click(object sender, EventArgs e)
|
try
|
||||||
{
|
{
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormShops));
|
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id });
|
||||||
if (service is FormShops form)
|
if (!operationResult)
|
||||||
{
|
{
|
||||||
form.ShowDialog();
|
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||||
}
|
}
|
||||||
}
|
LoadData();
|
||||||
private void пополнениеМагазинаToolStripMenuItem_Click(object sender, EventArgs e)
|
}
|
||||||
{
|
catch (Exception ex)
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormMakeSupply));
|
{
|
||||||
if (service is FormMakeSupply form)
|
_logger.LogError(ex, "Ошибка передачи заказа в работу");
|
||||||
{
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
form.ShowDialog();
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void ButtonCreateOrder_Click(object sender, EventArgs e)
|
private void ButtonOrderReady_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
|
if (dataGridView.SelectedRows.Count == 1)
|
||||||
if (service is FormCreateOrder form)
|
{
|
||||||
{
|
int id =
|
||||||
form.ShowDialog();
|
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
LoadData();
|
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'",
|
||||||
}
|
id);
|
||||||
}
|
try
|
||||||
private void ButtonTakeOrderInWork_Click(object sender, EventArgs e)
|
{
|
||||||
{
|
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id });
|
||||||
if (dataGridView.SelectedRows.Count == 1)
|
if (!operationResult)
|
||||||
{
|
{
|
||||||
int id =
|
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||||
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
}
|
||||||
_logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id);
|
LoadData();
|
||||||
try
|
}
|
||||||
{
|
catch (Exception ex)
|
||||||
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id });
|
{
|
||||||
if (!operationResult)
|
_logger.LogError(ex, "Ошибка отметки о готовности заказа");
|
||||||
{
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
}
|
||||||
}
|
}
|
||||||
LoadData();
|
}
|
||||||
}
|
private void ButtonIssuedOrder_Click(object sender, EventArgs e)
|
||||||
catch (Exception ex)
|
{
|
||||||
{
|
if (dataGridView.SelectedRows.Count == 1)
|
||||||
_logger.LogError(ex, "Ошибка передачи заказа в работу");
|
{
|
||||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
}
|
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id);
|
||||||
}
|
try
|
||||||
}
|
{
|
||||||
private void ButtonOrderReady_Click(object sender, EventArgs e)
|
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id });
|
||||||
{
|
if (!operationResult)
|
||||||
if (dataGridView.SelectedRows.Count == 1)
|
{
|
||||||
{
|
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||||
int id =
|
}
|
||||||
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
_logger.LogInformation("Заказ №{id} выдан", id);
|
||||||
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'",
|
LoadData();
|
||||||
id);
|
}
|
||||||
try
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var operationResult = _orderLogic.FinishOrder(new
|
_logger.LogError(ex, "Ошибка отметки о выдачи заказа");
|
||||||
OrderBindingModel
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||||
{ Id = id });
|
MessageBoxIcon.Error);
|
||||||
if (!operationResult)
|
}
|
||||||
{
|
}
|
||||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
}
|
||||||
}
|
private void ButtonRef_Click(object sender, EventArgs e)
|
||||||
LoadData();
|
{
|
||||||
}
|
LoadData();
|
||||||
catch (Exception ex)
|
}
|
||||||
{
|
|
||||||
_logger.LogError(ex, "Ошибка отметки о готовности заказа");
|
private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
{
|
||||||
}
|
var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
|
||||||
}
|
if (service is FormComponents form)
|
||||||
}
|
{
|
||||||
private void ButtonIssuedOrder_Click(object sender, EventArgs e)
|
form.ShowDialog();
|
||||||
{
|
}
|
||||||
if (dataGridView.SelectedRows.Count == 1)
|
}
|
||||||
{
|
private void ЦветыToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
int id =
|
{
|
||||||
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
var service = Program.ServiceProvider?.GetService(typeof(FormFlowers));
|
||||||
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id);
|
if (service is FormFlowers form)
|
||||||
try
|
{
|
||||||
{
|
form.ShowDialog();
|
||||||
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id });
|
}
|
||||||
if (!operationResult)
|
}
|
||||||
{
|
private void магазиныToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
{
|
||||||
}
|
var service = Program.ServiceProvider?.GetService(typeof(FormShops));
|
||||||
_logger.LogInformation("Заказ №{id} выдан", id);
|
if (service is FormShops form)
|
||||||
LoadData();
|
{
|
||||||
}
|
form.ShowDialog();
|
||||||
catch (Exception ex)
|
}
|
||||||
{
|
}
|
||||||
_logger.LogError(ex, "Ошибка отметки о выдачи заказа");
|
private void продажаЦветовToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
{
|
||||||
MessageBoxIcon.Error);
|
var service = Program.ServiceProvider?.GetService(typeof(FormMakeSale));
|
||||||
}
|
if (service is FormMakeSale form)
|
||||||
}
|
{
|
||||||
}
|
form.ShowDialog();
|
||||||
private void ButtonRef_Click(object sender, EventArgs e)
|
}
|
||||||
{
|
}
|
||||||
LoadData();
|
|
||||||
}
|
private void пополениеМагазинаToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
}
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormMakeSupply));
|
||||||
|
if (service is FormMakeSupply form)
|
||||||
|
{
|
||||||
|
form.ShowDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
127
FlowerShop/FlowerShop/FormMakeSale.Designer.cs
generated
Normal file
127
FlowerShop/FlowerShop/FormMakeSale.Designer.cs
generated
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
namespace FlowerShopView
|
||||||
|
{
|
||||||
|
partial class FormMakeSale
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
buttonCancel = new Button();
|
||||||
|
buttonSale = new Button();
|
||||||
|
textBoxCount = new TextBox();
|
||||||
|
labelCount = new Label();
|
||||||
|
comboBoxFlower = new ComboBox();
|
||||||
|
labelFlower = new Label();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
buttonCancel.Location = new Point(253, 83);
|
||||||
|
buttonCancel.Margin = new Padding(4, 3, 4, 3);
|
||||||
|
buttonCancel.Name = "buttonCancel";
|
||||||
|
buttonCancel.Size = new Size(88, 27);
|
||||||
|
buttonCancel.TabIndex = 17;
|
||||||
|
buttonCancel.Text = "Отмена";
|
||||||
|
buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
buttonCancel.Click += ButtonCancel_Click;
|
||||||
|
//
|
||||||
|
// buttonSale
|
||||||
|
//
|
||||||
|
buttonSale.Location = new Point(159, 83);
|
||||||
|
buttonSale.Margin = new Padding(4, 3, 4, 3);
|
||||||
|
buttonSale.Name = "buttonSale";
|
||||||
|
buttonSale.Size = new Size(88, 27);
|
||||||
|
buttonSale.TabIndex = 16;
|
||||||
|
buttonSale.Text = "Продать";
|
||||||
|
buttonSale.UseVisualStyleBackColor = true;
|
||||||
|
buttonSale.Click += ButtonSale_Click;
|
||||||
|
//
|
||||||
|
// textBoxCount
|
||||||
|
//
|
||||||
|
textBoxCount.Location = new Point(101, 51);
|
||||||
|
textBoxCount.Margin = new Padding(4, 3, 4, 3);
|
||||||
|
textBoxCount.Name = "textBoxCount";
|
||||||
|
textBoxCount.Size = new Size(252, 23);
|
||||||
|
textBoxCount.TabIndex = 15;
|
||||||
|
//
|
||||||
|
// labelCount
|
||||||
|
//
|
||||||
|
labelCount.AutoSize = true;
|
||||||
|
labelCount.Location = new Point(13, 54);
|
||||||
|
labelCount.Margin = new Padding(4, 0, 4, 0);
|
||||||
|
labelCount.Name = "labelCount";
|
||||||
|
labelCount.Size = new Size(75, 15);
|
||||||
|
labelCount.TabIndex = 14;
|
||||||
|
labelCount.Text = "Количество:";
|
||||||
|
//
|
||||||
|
// comboBoxFlower
|
||||||
|
//
|
||||||
|
comboBoxFlower.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
|
comboBoxFlower.FormattingEnabled = true;
|
||||||
|
comboBoxFlower.Location = new Point(101, 15);
|
||||||
|
comboBoxFlower.Margin = new Padding(4, 3, 4, 3);
|
||||||
|
comboBoxFlower.Name = "comboBoxFlower";
|
||||||
|
comboBoxFlower.Size = new Size(252, 23);
|
||||||
|
comboBoxFlower.TabIndex = 13;
|
||||||
|
//
|
||||||
|
// labelFlower
|
||||||
|
//
|
||||||
|
labelFlower.AutoSize = true;
|
||||||
|
labelFlower.Location = new Point(13, 19);
|
||||||
|
labelFlower.Margin = new Padding(4, 0, 4, 0);
|
||||||
|
labelFlower.Name = "labelFlower";
|
||||||
|
labelFlower.Size = new Size(45, 15);
|
||||||
|
labelFlower.TabIndex = 12;
|
||||||
|
labelFlower.Text = "Цветы:";
|
||||||
|
//
|
||||||
|
// FormMakeSale
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(373, 123);
|
||||||
|
Controls.Add(buttonCancel);
|
||||||
|
Controls.Add(buttonSale);
|
||||||
|
Controls.Add(textBoxCount);
|
||||||
|
Controls.Add(labelCount);
|
||||||
|
Controls.Add(comboBoxFlower);
|
||||||
|
Controls.Add(labelFlower);
|
||||||
|
Name = "FormMakeSale";
|
||||||
|
StartPosition = FormStartPosition.CenterScreen;
|
||||||
|
Text = "Продажа цветов";
|
||||||
|
Load += FormMakeSale_Load;
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Button buttonCancel;
|
||||||
|
private Button buttonSale;
|
||||||
|
private TextBox textBoxCount;
|
||||||
|
private Label labelCount;
|
||||||
|
private ComboBox comboBoxFlower;
|
||||||
|
private Label labelFlower;
|
||||||
|
}
|
||||||
|
}
|
85
FlowerShop/FlowerShop/FormMakeSale.cs
Normal file
85
FlowerShop/FlowerShop/FormMakeSale.cs
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
using FlowerShopContracts.BindingModels;
|
||||||
|
using FlowerShopContracts.BusinessLogicsContracts;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace FlowerShopView
|
||||||
|
{
|
||||||
|
public partial class FormMakeSale : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger<FormMakeSale> _logger;
|
||||||
|
|
||||||
|
private readonly IFlowerLogic _logicFlower;
|
||||||
|
|
||||||
|
private readonly IShopLogic _logicShop;
|
||||||
|
public FormMakeSale(ILogger<FormMakeSale> logger, IFlowerLogic logicFlower, IShopLogic logicShop)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logicFlower = logicFlower;
|
||||||
|
_logicShop = logicShop;
|
||||||
|
}
|
||||||
|
private void FormMakeSale_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Flowers loading");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var list = _logicFlower.ReadList(null);
|
||||||
|
if (list != null)
|
||||||
|
{
|
||||||
|
comboBoxFlower.DisplayMember = "FlowerName";
|
||||||
|
comboBoxFlower.ValueMember = "Id";
|
||||||
|
comboBoxFlower.DataSource = list;
|
||||||
|
comboBoxFlower.SelectedItem = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Flowers loading error");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonSale_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (comboBoxFlower.SelectedValue == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Выберите цветы", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(textBoxCount.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Flowers sale");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var operationResult = _logicShop.MakeSale(
|
||||||
|
new FlowerBindingModel
|
||||||
|
{
|
||||||
|
Id = Convert.ToInt32(comboBoxFlower.SelectedValue)
|
||||||
|
},
|
||||||
|
Convert.ToInt32(textBoxCount.Text)
|
||||||
|
);
|
||||||
|
if (!operationResult)
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка при продаже.");
|
||||||
|
}
|
||||||
|
MessageBox.Show("Продажа прошла успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Flowers sale error");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
DialogResult = DialogResult.Cancel;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
FlowerShop/FlowerShop/FormMakeSale.resx
Normal file
120
FlowerShop/FlowerShop/FormMakeSale.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
@ -91,14 +91,13 @@ namespace FlowerShopView
|
|||||||
{ Id = Convert.ToInt32(comboBoxFlower.SelectedValue) });
|
{ Id = Convert.ToInt32(comboBoxFlower.SelectedValue) });
|
||||||
if (iceCream == null)
|
if (iceCream == null)
|
||||||
{
|
{
|
||||||
throw new Exception("Мороженое не найдено.");
|
throw new Exception("Цветок не найден.");
|
||||||
}
|
}
|
||||||
var operationResult = _logicShop.MakeSupply(new ShopSearchModel
|
var operationResult = _logicShop.MakeSupply(new ShopSearchModel
|
||||||
{
|
{
|
||||||
Id = Convert.ToInt32(comboBoxShop.SelectedValue)
|
Id = Convert.ToInt32(comboBoxShop.SelectedValue)
|
||||||
},
|
},
|
||||||
iceCream,
|
iceCream, Convert.ToInt32(textBoxCount.Text));
|
||||||
Convert.ToInt32(textBoxCount.Text));
|
|
||||||
if (!operationResult)
|
if (!operationResult)
|
||||||
{
|
{
|
||||||
throw new Exception("Ошибка при проведении поставки.");
|
throw new Exception("Ошибка при проведении поставки.");
|
||||||
|
433
FlowerShop/FlowerShop/FormShop.Designer.cs
generated
433
FlowerShop/FlowerShop/FormShop.Designer.cs
generated
@ -1,213 +1,236 @@
|
|||||||
namespace FlowerShopView
|
namespace FlowerShopView
|
||||||
{
|
{
|
||||||
partial class FormShop
|
partial class FormShop
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required designer variable.
|
/// Required designer variable.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private System.ComponentModel.IContainer components = null;
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Clean up any resources being used.
|
/// Clean up any resources being used.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing && (components != null))
|
if (disposing && (components != null))
|
||||||
{
|
{
|
||||||
components.Dispose();
|
components.Dispose();
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Windows Form Designer generated code
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required method for Designer support - do not modify
|
/// Required method for Designer support - do not modify
|
||||||
/// the contents of this method with the code editor.
|
/// the contents of this method with the code editor.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
labelName = new Label();
|
labelName = new Label();
|
||||||
textBoxName = new TextBox();
|
textBoxName = new TextBox();
|
||||||
labelAddress = new Label();
|
labelAddress = new Label();
|
||||||
textBoxAddress = new TextBox();
|
textBoxAddress = new TextBox();
|
||||||
dateTimePicker = new DateTimePicker();
|
dateTimePicker = new DateTimePicker();
|
||||||
labelOpeningDate = new Label();
|
labelOpeningDate = new Label();
|
||||||
groupBoxFlowers = new GroupBox();
|
groupBoxFlowers = new GroupBox();
|
||||||
dataGridView = new DataGridView();
|
dataGridView = new DataGridView();
|
||||||
ColumnId = new DataGridViewTextBoxColumn();
|
ColumnId = new DataGridViewTextBoxColumn();
|
||||||
ColumnName = new DataGridViewTextBoxColumn();
|
ColumnName = new DataGridViewTextBoxColumn();
|
||||||
ColumnCount = new DataGridViewTextBoxColumn();
|
ColumnCount = new DataGridViewTextBoxColumn();
|
||||||
buttonSave = new Button();
|
buttonSave = new Button();
|
||||||
buttonCancel = new Button();
|
buttonCancel = new Button();
|
||||||
groupBoxFlowers.SuspendLayout();
|
textBoxMaximum = new TextBox();
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
label1 = new Label();
|
||||||
SuspendLayout();
|
groupBoxFlowers.SuspendLayout();
|
||||||
//
|
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||||
// labelName
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
labelName.AutoSize = true;
|
// labelName
|
||||||
labelName.Location = new Point(14, 10);
|
//
|
||||||
labelName.Margin = new Padding(4, 0, 4, 0);
|
labelName.AutoSize = true;
|
||||||
labelName.Name = "labelName";
|
labelName.Location = new Point(14, 10);
|
||||||
labelName.Size = new Size(62, 15);
|
labelName.Margin = new Padding(4, 0, 4, 0);
|
||||||
labelName.TabIndex = 1;
|
labelName.Name = "labelName";
|
||||||
labelName.Text = "Название:";
|
labelName.Size = new Size(62, 15);
|
||||||
//
|
labelName.TabIndex = 1;
|
||||||
// textBoxName
|
labelName.Text = "Название:";
|
||||||
//
|
//
|
||||||
textBoxName.Location = new Point(92, 7);
|
// textBoxName
|
||||||
textBoxName.Margin = new Padding(4, 3, 4, 3);
|
//
|
||||||
textBoxName.Name = "textBoxName";
|
textBoxName.Location = new Point(175, 7);
|
||||||
textBoxName.Size = new Size(252, 23);
|
textBoxName.Margin = new Padding(4, 3, 4, 3);
|
||||||
textBoxName.TabIndex = 2;
|
textBoxName.Name = "textBoxName";
|
||||||
//
|
textBoxName.Size = new Size(252, 23);
|
||||||
// labelAddress
|
textBoxName.TabIndex = 2;
|
||||||
//
|
//
|
||||||
labelAddress.AutoSize = true;
|
// labelAddress
|
||||||
labelAddress.Location = new Point(14, 40);
|
//
|
||||||
labelAddress.Margin = new Padding(4, 0, 4, 0);
|
labelAddress.AutoSize = true;
|
||||||
labelAddress.Name = "labelAddress";
|
labelAddress.Location = new Point(14, 40);
|
||||||
labelAddress.Size = new Size(43, 15);
|
labelAddress.Margin = new Padding(4, 0, 4, 0);
|
||||||
labelAddress.TabIndex = 3;
|
labelAddress.Name = "labelAddress";
|
||||||
labelAddress.Text = "Адрес:";
|
labelAddress.Size = new Size(43, 15);
|
||||||
//
|
labelAddress.TabIndex = 3;
|
||||||
// textBoxAddress
|
labelAddress.Text = "Адрес:";
|
||||||
//
|
//
|
||||||
textBoxAddress.Location = new Point(92, 37);
|
// textBoxAddress
|
||||||
textBoxAddress.Margin = new Padding(4, 3, 4, 3);
|
//
|
||||||
textBoxAddress.Name = "textBoxAddress";
|
textBoxAddress.Location = new Point(175, 37);
|
||||||
textBoxAddress.Size = new Size(252, 23);
|
textBoxAddress.Margin = new Padding(4, 3, 4, 3);
|
||||||
textBoxAddress.TabIndex = 4;
|
textBoxAddress.Name = "textBoxAddress";
|
||||||
//
|
textBoxAddress.Size = new Size(252, 23);
|
||||||
// dateTimePicker
|
textBoxAddress.TabIndex = 4;
|
||||||
//
|
//
|
||||||
dateTimePicker.Location = new Point(126, 66);
|
// dateTimePicker
|
||||||
dateTimePicker.Name = "dateTimePicker";
|
//
|
||||||
dateTimePicker.Size = new Size(218, 23);
|
dateTimePicker.Location = new Point(209, 98);
|
||||||
dateTimePicker.TabIndex = 5;
|
dateTimePicker.Name = "dateTimePicker";
|
||||||
//
|
dateTimePicker.Size = new Size(218, 23);
|
||||||
// labelOpeningDate
|
dateTimePicker.TabIndex = 5;
|
||||||
//
|
//
|
||||||
labelOpeningDate.AutoSize = true;
|
// labelOpeningDate
|
||||||
labelOpeningDate.Location = new Point(14, 69);
|
//
|
||||||
labelOpeningDate.Margin = new Padding(4, 0, 4, 0);
|
labelOpeningDate.AutoSize = true;
|
||||||
labelOpeningDate.Name = "labelOpeningDate";
|
labelOpeningDate.Location = new Point(14, 104);
|
||||||
labelOpeningDate.Size = new Size(90, 15);
|
labelOpeningDate.Margin = new Padding(4, 0, 4, 0);
|
||||||
labelOpeningDate.TabIndex = 6;
|
labelOpeningDate.Name = "labelOpeningDate";
|
||||||
labelOpeningDate.Text = "Дата открытия:";
|
labelOpeningDate.Size = new Size(90, 15);
|
||||||
//
|
labelOpeningDate.TabIndex = 6;
|
||||||
// groupBoxFlowers
|
labelOpeningDate.Text = "Дата открытия:";
|
||||||
//
|
//
|
||||||
groupBoxFlowers.Controls.Add(dataGridView);
|
// groupBoxFlowers
|
||||||
groupBoxFlowers.Location = new Point(4, 100);
|
//
|
||||||
groupBoxFlowers.Margin = new Padding(4, 3, 4, 3);
|
groupBoxFlowers.Controls.Add(dataGridView);
|
||||||
groupBoxFlowers.Name = "groupBoxFlowers";
|
groupBoxFlowers.Location = new Point(4, 135);
|
||||||
groupBoxFlowers.Padding = new Padding(4, 3, 4, 3);
|
groupBoxFlowers.Margin = new Padding(4, 3, 4, 3);
|
||||||
groupBoxFlowers.Size = new Size(469, 288);
|
groupBoxFlowers.Name = "groupBoxFlowers";
|
||||||
groupBoxFlowers.TabIndex = 7;
|
groupBoxFlowers.Padding = new Padding(4, 3, 4, 3);
|
||||||
groupBoxFlowers.TabStop = false;
|
groupBoxFlowers.Size = new Size(469, 288);
|
||||||
groupBoxFlowers.Text = "Цветы";
|
groupBoxFlowers.TabIndex = 7;
|
||||||
//
|
groupBoxFlowers.TabStop = false;
|
||||||
// dataGridView
|
groupBoxFlowers.Text = "Цветы";
|
||||||
//
|
//
|
||||||
dataGridView.AllowUserToAddRows = false;
|
// dataGridView
|
||||||
dataGridView.AllowUserToDeleteRows = false;
|
//
|
||||||
dataGridView.BackgroundColor = SystemColors.ControlLightLight;
|
dataGridView.AllowUserToAddRows = false;
|
||||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
dataGridView.AllowUserToDeleteRows = false;
|
||||||
dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnName, ColumnCount });
|
dataGridView.BackgroundColor = SystemColors.ControlLightLight;
|
||||||
dataGridView.Dock = DockStyle.Left;
|
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
dataGridView.Location = new Point(4, 19);
|
dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnName, ColumnCount });
|
||||||
dataGridView.Margin = new Padding(4, 3, 4, 3);
|
dataGridView.Dock = DockStyle.Left;
|
||||||
dataGridView.MultiSelect = false;
|
dataGridView.Location = new Point(4, 19);
|
||||||
dataGridView.Name = "dataGridView";
|
dataGridView.Margin = new Padding(4, 3, 4, 3);
|
||||||
dataGridView.ReadOnly = true;
|
dataGridView.MultiSelect = false;
|
||||||
dataGridView.RowHeadersVisible = false;
|
dataGridView.Name = "dataGridView";
|
||||||
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
dataGridView.ReadOnly = true;
|
||||||
dataGridView.Size = new Size(457, 266);
|
dataGridView.RowHeadersVisible = false;
|
||||||
dataGridView.TabIndex = 0;
|
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||||
//
|
dataGridView.Size = new Size(457, 266);
|
||||||
// ColumnId
|
dataGridView.TabIndex = 0;
|
||||||
//
|
//
|
||||||
ColumnId.HeaderText = "Id";
|
// ColumnId
|
||||||
ColumnId.Name = "ColumnId";
|
//
|
||||||
ColumnId.ReadOnly = true;
|
ColumnId.HeaderText = "Id";
|
||||||
ColumnId.Visible = false;
|
ColumnId.Name = "ColumnId";
|
||||||
//
|
ColumnId.ReadOnly = true;
|
||||||
// ColumnName
|
ColumnId.Visible = false;
|
||||||
//
|
//
|
||||||
ColumnName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
// ColumnName
|
||||||
ColumnName.HeaderText = "Название цветка";
|
//
|
||||||
ColumnName.Name = "ColumnName";
|
ColumnName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
ColumnName.ReadOnly = true;
|
ColumnName.HeaderText = "Название цветка";
|
||||||
//
|
ColumnName.Name = "ColumnName";
|
||||||
// ColumnCount
|
ColumnName.ReadOnly = true;
|
||||||
//
|
//
|
||||||
ColumnCount.HeaderText = "Количество";
|
// ColumnCount
|
||||||
ColumnCount.Name = "ColumnCount";
|
//
|
||||||
ColumnCount.ReadOnly = true;
|
ColumnCount.HeaderText = "Количество";
|
||||||
//
|
ColumnCount.Name = "ColumnCount";
|
||||||
// buttonSave
|
ColumnCount.ReadOnly = true;
|
||||||
//
|
//
|
||||||
buttonSave.Location = new Point(255, 394);
|
// buttonSave
|
||||||
buttonSave.Margin = new Padding(4, 3, 4, 3);
|
//
|
||||||
buttonSave.Name = "buttonSave";
|
buttonSave.Location = new Point(255, 429);
|
||||||
buttonSave.Size = new Size(88, 27);
|
buttonSave.Margin = new Padding(4, 3, 4, 3);
|
||||||
buttonSave.TabIndex = 8;
|
buttonSave.Name = "buttonSave";
|
||||||
buttonSave.Text = "Сохранить";
|
buttonSave.Size = new Size(88, 27);
|
||||||
buttonSave.UseVisualStyleBackColor = true;
|
buttonSave.TabIndex = 8;
|
||||||
buttonSave.Click += ButtonSave_Click;
|
buttonSave.Text = "Сохранить";
|
||||||
//
|
buttonSave.UseVisualStyleBackColor = true;
|
||||||
// buttonCancel
|
buttonSave.Click += ButtonSave_Click;
|
||||||
//
|
//
|
||||||
buttonCancel.Location = new Point(359, 394);
|
// buttonCancel
|
||||||
buttonCancel.Margin = new Padding(4, 3, 4, 3);
|
//
|
||||||
buttonCancel.Name = "buttonCancel";
|
buttonCancel.Location = new Point(359, 429);
|
||||||
buttonCancel.Size = new Size(88, 27);
|
buttonCancel.Margin = new Padding(4, 3, 4, 3);
|
||||||
buttonCancel.TabIndex = 9;
|
buttonCancel.Name = "buttonCancel";
|
||||||
buttonCancel.Text = "Отмена";
|
buttonCancel.Size = new Size(88, 27);
|
||||||
buttonCancel.UseVisualStyleBackColor = true;
|
buttonCancel.TabIndex = 9;
|
||||||
buttonCancel.Click += ButtonCancel_Click;
|
buttonCancel.Text = "Отмена";
|
||||||
//
|
buttonCancel.UseVisualStyleBackColor = true;
|
||||||
// FormShop
|
buttonCancel.Click += ButtonCancel_Click;
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
// textBoxMaximum
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
//
|
||||||
ClientSize = new Size(478, 432);
|
textBoxMaximum.Location = new Point(175, 68);
|
||||||
Controls.Add(buttonCancel);
|
textBoxMaximum.Margin = new Padding(4, 3, 4, 3);
|
||||||
Controls.Add(buttonSave);
|
textBoxMaximum.Name = "textBoxMaximum";
|
||||||
Controls.Add(groupBoxFlowers);
|
textBoxMaximum.Size = new Size(252, 23);
|
||||||
Controls.Add(labelOpeningDate);
|
textBoxMaximum.TabIndex = 11;
|
||||||
Controls.Add(dateTimePicker);
|
//
|
||||||
Controls.Add(textBoxAddress);
|
// label1
|
||||||
Controls.Add(labelAddress);
|
//
|
||||||
Controls.Add(textBoxName);
|
label1.Location = new Point(14, 68);
|
||||||
Controls.Add(labelName);
|
label1.Margin = new Padding(4, 0, 4, 0);
|
||||||
Name = "FormShop";
|
label1.Name = "label1";
|
||||||
StartPosition = FormStartPosition.CenterScreen;
|
label1.Size = new Size(153, 33);
|
||||||
Text = "Магазин";
|
label1.TabIndex = 10;
|
||||||
Load += FormShop_Load;
|
label1.Text = "Максимальное количество цветков:";
|
||||||
groupBoxFlowers.ResumeLayout(false);
|
//
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
// FormShop
|
||||||
ResumeLayout(false);
|
//
|
||||||
PerformLayout();
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
}
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(478, 465);
|
||||||
|
Controls.Add(textBoxMaximum);
|
||||||
|
Controls.Add(label1);
|
||||||
|
Controls.Add(buttonCancel);
|
||||||
|
Controls.Add(buttonSave);
|
||||||
|
Controls.Add(groupBoxFlowers);
|
||||||
|
Controls.Add(labelOpeningDate);
|
||||||
|
Controls.Add(dateTimePicker);
|
||||||
|
Controls.Add(textBoxAddress);
|
||||||
|
Controls.Add(labelAddress);
|
||||||
|
Controls.Add(textBoxName);
|
||||||
|
Controls.Add(labelName);
|
||||||
|
Name = "FormShop";
|
||||||
|
StartPosition = FormStartPosition.CenterScreen;
|
||||||
|
Text = "Магазин";
|
||||||
|
Load += FormShop_Load;
|
||||||
|
groupBoxFlowers.ResumeLayout(false);
|
||||||
|
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private Label labelName;
|
private Label labelName;
|
||||||
private TextBox textBoxName;
|
private TextBox textBoxName;
|
||||||
private Label labelAddress;
|
private Label labelAddress;
|
||||||
private TextBox textBoxAddress;
|
private TextBox textBoxAddress;
|
||||||
private DateTimePicker dateTimePicker;
|
private DateTimePicker dateTimePicker;
|
||||||
private Label labelOpeningDate;
|
private Label labelOpeningDate;
|
||||||
private GroupBox groupBoxFlowers;
|
private GroupBox groupBoxFlowers;
|
||||||
private DataGridView dataGridView;
|
private DataGridView dataGridView;
|
||||||
private DataGridViewTextBoxColumn ColumnId;
|
private DataGridViewTextBoxColumn ColumnId;
|
||||||
private DataGridViewTextBoxColumn ColumnName;
|
private DataGridViewTextBoxColumn ColumnName;
|
||||||
private DataGridViewTextBoxColumn ColumnCount;
|
private DataGridViewTextBoxColumn ColumnCount;
|
||||||
private Button buttonSave;
|
private Button buttonSave;
|
||||||
private Button buttonCancel;
|
private Button buttonCancel;
|
||||||
}
|
private TextBox textBoxMaximum;
|
||||||
|
private Label label1;
|
||||||
|
}
|
||||||
}
|
}
|
@ -6,120 +6,121 @@ using Microsoft.Extensions.Logging;
|
|||||||
|
|
||||||
namespace FlowerShopView
|
namespace FlowerShopView
|
||||||
{
|
{
|
||||||
public partial class FormShop : Form
|
public partial class FormShop : Form
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
private readonly IShopLogic _logic;
|
private readonly IShopLogic _logic;
|
||||||
|
|
||||||
private int? _id;
|
private int? _id;
|
||||||
|
|
||||||
private Dictionary<int, (IFlowerModel, int)> _shopFlowers;
|
private Dictionary<int, (IFlowerModel, int)> _shopFlowers;
|
||||||
|
|
||||||
public int Id { set { _id = value; } }
|
public int Id { set { _id = value; } }
|
||||||
|
|
||||||
public FormShop(ILogger<FormShop> logger, IShopLogic logic)
|
public FormShop(ILogger<FormShop> logger, IShopLogic logic)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_logic = logic;
|
_logic = logic;
|
||||||
_shopFlowers = new Dictionary<int, (IFlowerModel, int)>();
|
_shopFlowers = new Dictionary<int, (IFlowerModel, int)>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FormShop_Load(object sender, EventArgs e)
|
private void FormShop_Load(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_id.HasValue)
|
if (_id.HasValue)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Shop loading");
|
_logger.LogInformation("Shop loading");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var view = _logic.ReadElement(new ShopSearchModel { Id = _id.Value });
|
var view = _logic.ReadElement(new ShopSearchModel { Id = _id.Value });
|
||||||
if (view != null)
|
if (view != null)
|
||||||
{
|
{
|
||||||
textBoxName.Text = view.ShopName;
|
textBoxName.Text = view.ShopName;
|
||||||
textBoxAddress.Text = view.Address;
|
textBoxAddress.Text = view.Address;
|
||||||
dateTimePicker.Value = view.DateOpening;
|
dateTimePicker.Value = view.DateOpening;
|
||||||
_shopFlowers = view.Flowers ?? new Dictionary<int, (IFlowerModel, int)>();
|
_shopFlowers = view.ShopFlowers ?? new Dictionary<int, (IFlowerModel, int)>();
|
||||||
LoadData();
|
LoadData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Shop loading error");
|
_logger.LogError(ex, "Shop loading error");
|
||||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadData()
|
private void LoadData()
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Shop flowers loading");
|
_logger.LogInformation("Shop flowers loading");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (_shopFlowers != null)
|
if (_shopFlowers != null)
|
||||||
{
|
{
|
||||||
dataGridView.Rows.Clear();
|
dataGridView.Rows.Clear();
|
||||||
foreach (var iceCream in _shopFlowers)
|
foreach (var iceCream in _shopFlowers)
|
||||||
{
|
{
|
||||||
dataGridView.Rows.Add(new object[] { iceCream.Key, iceCream.Value.Item1.FlowerName, iceCream.Value.Item2 });
|
dataGridView.Rows.Add(new object[] { iceCream.Key, iceCream.Value.Item1.FlowerName, iceCream.Value.Item2 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Shop flowers loading error");
|
_logger.LogError(ex, "Shop flowers loading error");
|
||||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ButtonSave_Click(object sender, EventArgs e)
|
private void ButtonSave_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(textBoxName.Text))
|
if (string.IsNullOrEmpty(textBoxName.Text))
|
||||||
{
|
{
|
||||||
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (string.IsNullOrEmpty(textBoxAddress.Text))
|
if (string.IsNullOrEmpty(textBoxAddress.Text))
|
||||||
{
|
{
|
||||||
MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (string.IsNullOrEmpty(dateTimePicker.Text))
|
if (string.IsNullOrEmpty(dateTimePicker.Text))
|
||||||
{
|
{
|
||||||
MessageBox.Show("Заполните дату", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show("Заполните дату", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_logger.LogInformation("Shop saving");
|
_logger.LogInformation("Shop saving");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var model = new ShopBindingModel
|
var model = new ShopBindingModel
|
||||||
{
|
{
|
||||||
Id = _id ?? 0,
|
Id = _id ?? 0,
|
||||||
ShopName = textBoxName.Text,
|
ShopName = textBoxName.Text,
|
||||||
Address = textBoxAddress.Text,
|
Address = textBoxAddress.Text,
|
||||||
DateOpening = dateTimePicker.Value,
|
DateOpening = dateTimePicker.Value,
|
||||||
Flowers = _shopFlowers
|
ShopFlowers = _shopFlowers,
|
||||||
};
|
MaximumFlowers = Convert.ToInt32(textBoxMaximum.Text),
|
||||||
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
|
};
|
||||||
if (!operationResult)
|
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
|
||||||
{
|
if (!operationResult)
|
||||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
{
|
||||||
}
|
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||||
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
}
|
||||||
DialogResult = DialogResult.OK;
|
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
Close();
|
DialogResult = DialogResult.OK;
|
||||||
}
|
Close();
|
||||||
catch (Exception ex)
|
}
|
||||||
{
|
catch (Exception ex)
|
||||||
_logger.LogError(ex, "Shop saving error");
|
{
|
||||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
_logger.LogError(ex, "Shop saving error");
|
||||||
}
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void ButtonCancel_Click(object sender, EventArgs e)
|
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
DialogResult = DialogResult.Cancel;
|
DialogResult = DialogResult.Cancel;
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ namespace FlowerShopView
|
|||||||
dataGridView.DataSource = list;
|
dataGridView.DataSource = list;
|
||||||
dataGridView.Columns["Id"].Visible = false;
|
dataGridView.Columns["Id"].Visible = false;
|
||||||
dataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
dataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
dataGridView.Columns["Flowers"].Visible = false;
|
dataGridView.Columns["ShopFlowers"].Visible = false;
|
||||||
}
|
}
|
||||||
_logger.LogInformation("Shops loading");
|
_logger.LogInformation("Shops loading");
|
||||||
}
|
}
|
||||||
|
@ -36,10 +36,12 @@ namespace FlowerShopView
|
|||||||
services.AddTransient<IComponentStorage, ComponentStorage>();
|
services.AddTransient<IComponentStorage, ComponentStorage>();
|
||||||
services.AddTransient<IOrderStorage, OrderStorage>();
|
services.AddTransient<IOrderStorage, OrderStorage>();
|
||||||
services.AddTransient<IFlowerStorage, FlowerStorage>();
|
services.AddTransient<IFlowerStorage, FlowerStorage>();
|
||||||
|
services.AddTransient<IShopStorage, ShopStorage>();
|
||||||
|
|
||||||
services.AddTransient<IComponentLogic, ComponentLogic>();
|
services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||||
services.AddTransient<IOrderLogic, OrderLogic>();
|
services.AddTransient<IOrderLogic, OrderLogic>();
|
||||||
services.AddTransient<IFlowerLogic, FlowerLogic>();
|
services.AddTransient<IFlowerLogic, FlowerLogic>();
|
||||||
|
services.AddTransient<IShopLogic, ShopLogic>();
|
||||||
|
|
||||||
services.AddTransient<FormMain>();
|
services.AddTransient<FormMain>();
|
||||||
services.AddTransient<FormComponent>();
|
services.AddTransient<FormComponent>();
|
||||||
@ -48,6 +50,10 @@ namespace FlowerShopView
|
|||||||
services.AddTransient<FormFlower>();
|
services.AddTransient<FormFlower>();
|
||||||
services.AddTransient<FormFlowerComponent>();
|
services.AddTransient<FormFlowerComponent>();
|
||||||
services.AddTransient<FormFlowers>();
|
services.AddTransient<FormFlowers>();
|
||||||
}
|
services.AddTransient<FormShop>();
|
||||||
|
services.AddTransient<FormShops>();
|
||||||
|
services.AddTransient<FormMakeSupply>();
|
||||||
|
services.AddTransient<FormMakeSale>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,6 +4,7 @@ using FlowerShopContracts.SearchModels;
|
|||||||
using FlowerShopContracts.StoragesContracts;
|
using FlowerShopContracts.StoragesContracts;
|
||||||
using FlowerShopContracts.ViewModels;
|
using FlowerShopContracts.ViewModels;
|
||||||
using FlowerShopDataModels.Enums;
|
using FlowerShopDataModels.Enums;
|
||||||
|
using FlowerShopDataModels.Models;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace FlowerShopBusinessLogic.BusinessLogics
|
namespace FlowerShopBusinessLogic.BusinessLogics
|
||||||
@ -12,10 +13,16 @@ namespace FlowerShopBusinessLogic.BusinessLogics
|
|||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IOrderStorage _orderStorage;
|
private readonly IOrderStorage _orderStorage;
|
||||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
|
private readonly IFlowerStorage _flowerStorage;
|
||||||
|
private readonly IShopStorage _shopStorage;
|
||||||
|
private readonly IShopLogic _shopLogic;
|
||||||
|
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IFlowerStorage flowerStorage, IShopStorage shopStorage, IShopLogic shopLogic)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_orderStorage = orderStorage;
|
_orderStorage = orderStorage;
|
||||||
|
_flowerStorage = flowerStorage;
|
||||||
|
_shopStorage = shopStorage;
|
||||||
|
_shopLogic = shopLogic;
|
||||||
}
|
}
|
||||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||||
{
|
{
|
||||||
@ -80,17 +87,32 @@ namespace FlowerShopBusinessLogic.BusinessLogics
|
|||||||
_logger.LogWarning("Status update to " + orderStatus + " operation failed");
|
_logger.LogWarning("Status update to " + orderStatus + " operation failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (orderStatus == OrderStatus.Выдан)
|
||||||
|
{
|
||||||
|
var flower = _flowerStorage.GetElement(new FlowerSearchModel() { Id = model.FlowerId } );
|
||||||
|
if (flower == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!SupplyFlowers(flower, model.Count))
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Change status operation failed. Flowers delivery operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
model.Status = orderStatus;
|
model.Status = orderStatus;
|
||||||
|
if (model.Status == OrderStatus.Готов)
|
||||||
if (model.Status == OrderStatus.Выдан)
|
|
||||||
{
|
{
|
||||||
model.DateImplement = DateTime.Now;
|
model.DateImplement = DateTime.Now;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
model.DateImplement = element.DateImplement;
|
||||||
|
}
|
||||||
if (_orderStorage.Update(model) == null)
|
if (_orderStorage.Update(model) == null)
|
||||||
{
|
{
|
||||||
model.Status--;
|
model.Status--;
|
||||||
_logger.LogWarning("Changing status operation faled");
|
_logger.LogWarning("Changing status operation failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -119,5 +141,62 @@ namespace FlowerShopBusinessLogic.BusinessLogics
|
|||||||
}
|
}
|
||||||
_logger.LogInformation("Order. FlowerId:{EngineId}.Count:{Count}.Sum:{Sum}Id:{Id}", model.FlowerId, model.Count, model.Sum, model.Id);
|
_logger.LogInformation("Order. FlowerId:{EngineId}.Count:{Count}.Sum:{Sum}Id:{Id}", model.FlowerId, model.Count, model.Sum, model.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool SupplyFlowers(IFlowerModel flower, int count)
|
||||||
|
{
|
||||||
|
if (count < 0)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Flower supply operation failed. Count <= 0");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var shopList = _shopStorage.GetFullList();
|
||||||
|
var shopsCapacity = shopList.Sum(x => x.MaximumFlowers);
|
||||||
|
int currentFlowers = shopList.Select(x => x.ShopFlowers.Sum(y => y.Value.Item2)).Sum();
|
||||||
|
int freeSpace = shopsCapacity - currentFlowers;
|
||||||
|
|
||||||
|
if (freeSpace < count)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Flower supply operation failed. No free space for new flowers");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var shop in shopList)
|
||||||
|
{
|
||||||
|
freeSpace = shop.MaximumFlowers - shop.ShopFlowers.Sum(x => x.Value.Item2);
|
||||||
|
if (freeSpace == 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (freeSpace >= count)
|
||||||
|
{
|
||||||
|
if (_shopLogic.MakeSupply(new ShopSearchModel() { Id = shop.Id }, flower, count))
|
||||||
|
{
|
||||||
|
count = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Flowers delivery operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (_shopLogic.MakeSupply(new ShopSearchModel() { Id = shop.Id }, flower, freeSpace))
|
||||||
|
{
|
||||||
|
count -= freeSpace;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Flowers delivery operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (count == 0)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,16 +100,16 @@ namespace FlowerShopBusinessLogic.BusinessLogics
|
|||||||
_logger.LogWarning("MakeSupply(GetElement). Element not found");
|
_logger.LogWarning("MakeSupply(GetElement). Element not found");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (shop.Flowers.ContainsKey(flower.Id))
|
if (shop.ShopFlowers.ContainsKey(flower.Id))
|
||||||
{
|
{
|
||||||
var shopFlower = shop.Flowers[flower.Id];
|
var shopFlower = shop.ShopFlowers[flower.Id];
|
||||||
shopFlower.Item2 += count;
|
shopFlower.Item2 += count;
|
||||||
shop.Flowers[flower.Id] = shopFlower;
|
shop.ShopFlowers[flower.Id] = shopFlower;
|
||||||
_logger.LogInformation("MakeSupply. Added {count} '{flower}' to '{ShopName}' shop", count, flower.FlowerName, shop.ShopName);
|
_logger.LogInformation("MakeSupply. Added {count} '{flower}' to '{ShopName}' shop", count, flower.FlowerName, shop.ShopName);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
shop.Flowers.Add(flower.Id, (flower, count));
|
shop.ShopFlowers.Add(flower.Id, (flower, count));
|
||||||
_logger.LogInformation("MakeSupply. Added {count} new '{flower}' to '{ShopName}' shop", count, flower.FlowerName, shop.ShopName);
|
_logger.LogInformation("MakeSupply. Added {count} new '{flower}' to '{ShopName}' shop", count, flower.FlowerName, shop.ShopName);
|
||||||
}
|
}
|
||||||
if (_shopStorage.Update(new ShopBindingModel()
|
if (_shopStorage.Update(new ShopBindingModel()
|
||||||
@ -118,7 +118,8 @@ namespace FlowerShopBusinessLogic.BusinessLogics
|
|||||||
ShopName = shop.ShopName,
|
ShopName = shop.ShopName,
|
||||||
Address = shop.Address,
|
Address = shop.Address,
|
||||||
DateOpening = shop.DateOpening,
|
DateOpening = shop.DateOpening,
|
||||||
Flowers = shop.Flowers,
|
ShopFlowers = shop.ShopFlowers,
|
||||||
|
MaximumFlowers = shop.MaximumFlowers,
|
||||||
}) == null)
|
}) == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("MakeSupply. Update operation failed");
|
_logger.LogWarning("MakeSupply. Update operation failed");
|
||||||
@ -154,5 +155,10 @@ namespace FlowerShopBusinessLogic.BusinessLogics
|
|||||||
throw new InvalidOperationException("Магазин с таким названием уже есть");
|
throw new InvalidOperationException("Магазин с таким названием уже есть");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public bool MakeSale(IFlowerModel model, int count)
|
||||||
|
{
|
||||||
|
return _shopStorage.MakeSale(model, count);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,10 +8,12 @@ namespace FlowerShopContracts.BindingModels
|
|||||||
public string ShopName { get; set; } = string.Empty;
|
public string ShopName { get; set; } = string.Empty;
|
||||||
public string Address { get; set; } = string.Empty;
|
public string Address { get; set; } = string.Empty;
|
||||||
public DateTime DateOpening { get; set; } = DateTime.Now;
|
public DateTime DateOpening { get; set; } = DateTime.Now;
|
||||||
public Dictionary<int, (IFlowerModel, int)> Flowers
|
public Dictionary<int, (IFlowerModel, int)> ShopFlowers
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
} = new();
|
} = new();
|
||||||
|
|
||||||
|
public int MaximumFlowers { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,5 +13,6 @@ namespace FlowerShopContracts.BusinessLogicsContracts
|
|||||||
bool Update(ShopBindingModel model);
|
bool Update(ShopBindingModel model);
|
||||||
bool Delete(ShopBindingModel model);
|
bool Delete(ShopBindingModel model);
|
||||||
bool MakeSupply(ShopSearchModel shopModel, IFlowerModel flower, int count);
|
bool MakeSupply(ShopSearchModel shopModel, IFlowerModel flower, int count);
|
||||||
}
|
bool MakeSale(IFlowerModel model, int count);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using FlowerShopContracts.BindingModels;
|
using FlowerShopContracts.BindingModels;
|
||||||
using FlowerShopContracts.SearchModels;
|
using FlowerShopContracts.SearchModels;
|
||||||
using FlowerShopContracts.ViewModels;
|
using FlowerShopContracts.ViewModels;
|
||||||
|
using FlowerShopDataModels.Models;
|
||||||
|
|
||||||
namespace FlowerShopContracts.StoragesContracts
|
namespace FlowerShopContracts.StoragesContracts
|
||||||
{
|
{
|
||||||
@ -12,5 +13,6 @@ namespace FlowerShopContracts.StoragesContracts
|
|||||||
ShopViewModel? Insert(ShopBindingModel model);
|
ShopViewModel? Insert(ShopBindingModel model);
|
||||||
ShopViewModel? Update(ShopBindingModel model);
|
ShopViewModel? Update(ShopBindingModel model);
|
||||||
ShopViewModel? Delete(ShopBindingModel model);
|
ShopViewModel? Delete(ShopBindingModel model);
|
||||||
|
bool MakeSale(IFlowerModel model, int count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,10 +12,12 @@ namespace FlowerShopContracts.ViewModels
|
|||||||
public string Address { get; set; } = string.Empty;
|
public string Address { get; set; } = string.Empty;
|
||||||
[DisplayName("Дата открытия")]
|
[DisplayName("Дата открытия")]
|
||||||
public DateTime DateOpening { get; set; } = DateTime.Now;
|
public DateTime DateOpening { get; set; } = DateTime.Now;
|
||||||
public Dictionary<int, (IFlowerModel, int)> Flowers
|
public Dictionary<int, (IFlowerModel, int)> ShopFlowers
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
} = new();
|
} = new();
|
||||||
}
|
[DisplayName("Максимальное количество цветков")]
|
||||||
|
public int MaximumFlowers { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,8 @@
|
|||||||
{
|
{
|
||||||
string ShopName { get; }
|
string ShopName { get; }
|
||||||
string Address { get; }
|
string Address { get; }
|
||||||
Dictionary<int, (IFlowerModel, int)> Flowers { get; }
|
Dictionary<int, (IFlowerModel, int)> ShopFlowers { get; }
|
||||||
DateTime DateOpening { get; }
|
DateTime DateOpening { get; }
|
||||||
|
int MaximumFlowers { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,9 +9,11 @@ namespace FlowerShopFileImplement
|
|||||||
private readonly string ComponentFileName = "Component.xml";
|
private readonly string ComponentFileName = "Component.xml";
|
||||||
private readonly string OrderFileName = "Order.xml";
|
private readonly string OrderFileName = "Order.xml";
|
||||||
private readonly string FlowerFileName = "Flower.xml";
|
private readonly string FlowerFileName = "Flower.xml";
|
||||||
public List<Component> Components { get; private set; }
|
private readonly string ShopFileName = "Shop.xml";
|
||||||
|
public List<Component> Components { get; private set; }
|
||||||
public List<Order> Orders { get; private set; }
|
public List<Order> Orders { get; private set; }
|
||||||
public List<Flower> Flowers { get; private set; }
|
public List<Flower> Flowers { get; private set; }
|
||||||
|
public List<Shop> Shops { get; private set; }
|
||||||
public static DataFileSingleton GetInstance()
|
public static DataFileSingleton GetInstance()
|
||||||
{
|
{
|
||||||
if (instance == null)
|
if (instance == null)
|
||||||
@ -23,12 +25,14 @@ namespace FlowerShopFileImplement
|
|||||||
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
|
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
|
||||||
public void SaveFlowers() => SaveData(Flowers, FlowerFileName, "Flowers", x => x.GetXElement);
|
public void SaveFlowers() => SaveData(Flowers, FlowerFileName, "Flowers", x => x.GetXElement);
|
||||||
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
||||||
private DataFileSingleton()
|
public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement);
|
||||||
|
private DataFileSingleton()
|
||||||
{
|
{
|
||||||
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
||||||
Flowers = LoadData(FlowerFileName, "Flower", x => Flower.Create(x)!)!;
|
Flowers = LoadData(FlowerFileName, "Flower", x => Flower.Create(x)!)!;
|
||||||
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||||
}
|
Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!;
|
||||||
|
}
|
||||||
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
||||||
{
|
{
|
||||||
if (File.Exists(filename))
|
if (File.Exists(filename))
|
||||||
|
134
FlowerShop/FlowerShopFileImplement/Implements/ShopStorage.cs
Normal file
134
FlowerShop/FlowerShopFileImplement/Implements/ShopStorage.cs
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
|
||||||
|
using FlowerShopContracts.BindingModels;
|
||||||
|
using FlowerShopContracts.SearchModels;
|
||||||
|
using FlowerShopContracts.StoragesContracts;
|
||||||
|
using FlowerShopContracts.ViewModels;
|
||||||
|
using FlowerShopDataModels.Models;
|
||||||
|
using FlowerShopFileImplement.Models;
|
||||||
|
|
||||||
|
namespace FlowerShopFileImplement.Implements
|
||||||
|
{
|
||||||
|
public class ShopStorage : IShopStorage
|
||||||
|
{
|
||||||
|
private readonly DataFileSingleton source;
|
||||||
|
|
||||||
|
public ShopStorage()
|
||||||
|
{
|
||||||
|
source = DataFileSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ShopViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
return source.Shops
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ShopName))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
return source.Shops
|
||||||
|
.Where(x => x.ShopName.Contains(model.ShopName))
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel? GetElement(ShopSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return source.Shops
|
||||||
|
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName) ||
|
||||||
|
(model.Id.HasValue && x.Id == model.Id))
|
||||||
|
?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel? Insert(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = source.Shops.Count > 0 ? source.Shops.Max(x => x.Id) + 1 : 1;
|
||||||
|
var newShop = Shop.Create(model);
|
||||||
|
if (newShop == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
source.Shops.Add(newShop);
|
||||||
|
source.SaveShops();
|
||||||
|
return newShop.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel? Update(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (shop == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
shop.Update(model);
|
||||||
|
source.SaveShops();
|
||||||
|
return shop.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel? Delete(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
var element = source.Shops.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
source.Shops.Remove(element);
|
||||||
|
source.SaveShops();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool MakeSale(IFlowerModel model, int count)
|
||||||
|
{
|
||||||
|
// TODO: разобраться
|
||||||
|
var flower = source.Flowers.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
int countInShops = source.Shops.SelectMany(x => x.ShopFlowers).Sum(y => y.Key == model.Id ? y.Value.Item2 : 0);
|
||||||
|
|
||||||
|
if (flower == null || countInShops < count)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var shop in source.Shops)
|
||||||
|
{
|
||||||
|
var shopFlowers = shop.ShopFlowers.Where(x => x.Key == model.Id);
|
||||||
|
if (shopFlowers.Any())
|
||||||
|
{
|
||||||
|
var shopFlower = shopFlowers.First();
|
||||||
|
int min = Math.Min(shopFlower.Value.Item2, count);
|
||||||
|
if (min == shopFlower.Value.Item2)
|
||||||
|
{
|
||||||
|
shop.ShopFlowers.Remove(shopFlower.Key);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
shop.ShopFlowers[shopFlower.Key] = (shopFlower.Value.Item1, shopFlower.Value.Item2 - min);
|
||||||
|
}
|
||||||
|
shop.Update(new ShopBindingModel
|
||||||
|
{
|
||||||
|
Id = shop.Id,
|
||||||
|
ShopName = shop.ShopName,
|
||||||
|
Address = shop.Address,
|
||||||
|
DateOpening = shop.DateOpening,
|
||||||
|
ShopFlowers = shop.ShopFlowers,
|
||||||
|
MaximumFlowers = shop.MaximumFlowers
|
||||||
|
});
|
||||||
|
count -= min;
|
||||||
|
if (count <= 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
source.SaveShops();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
88
FlowerShop/FlowerShopFileImplement/Models/Shop.cs
Normal file
88
FlowerShop/FlowerShopFileImplement/Models/Shop.cs
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
using FlowerShopContracts.BindingModels;
|
||||||
|
using FlowerShopContracts.ViewModels;
|
||||||
|
using FlowerShopDataModels.Models;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace FlowerShopFileImplement.Models
|
||||||
|
{
|
||||||
|
public class Shop : IShopModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public string ShopName { get; private set; } = string.Empty;
|
||||||
|
public string Address { get; private set; } = string.Empty;
|
||||||
|
public DateTime DateOpening { get; private set; }
|
||||||
|
public Dictionary<int, int> Flowers { get; private set; } = new();
|
||||||
|
private Dictionary<int, (IFlowerModel, int)> _shopFlowers = null;
|
||||||
|
public Dictionary<int, (IFlowerModel, int)> ShopFlowers
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_shopFlowers == null)
|
||||||
|
{
|
||||||
|
var source = DataFileSingleton.GetInstance();
|
||||||
|
_shopFlowers = Flowers.ToDictionary(x => x.Key,
|
||||||
|
y => ((source.Flowers.FirstOrDefault(z => z.Id == y.Key) as IFlowerModel)!, y.Value));
|
||||||
|
}
|
||||||
|
return _shopFlowers;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public int MaximumFlowers { get; private set; }
|
||||||
|
public static Shop? Create(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null) return null;
|
||||||
|
return new Shop()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
ShopName = model.ShopName,
|
||||||
|
Address = model.Address,
|
||||||
|
DateOpening = model.DateOpening,
|
||||||
|
Flowers = model.ShopFlowers.ToDictionary(x => x.Key, x => x.Value.Item2),
|
||||||
|
MaximumFlowers = model.MaximumFlowers,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public static Shop? Create(XElement element)
|
||||||
|
{
|
||||||
|
if (element == null) return null;
|
||||||
|
return new Shop()
|
||||||
|
{
|
||||||
|
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||||
|
ShopName = element.Element("ShopName")!.Value,
|
||||||
|
Address = element.Element("Address")!.Value,
|
||||||
|
DateOpening = Convert.ToDateTime(element.Element("DateOpening")!.Value),
|
||||||
|
MaximumFlowers = Convert.ToInt32(element.Element("MaximumFlowers")!.Value),
|
||||||
|
Flowers = element.Element("ShopFlowers")!.Elements("ShopFlower")
|
||||||
|
.ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(ShopBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null) return;
|
||||||
|
ShopName = model.ShopName;
|
||||||
|
Address = model.Address;
|
||||||
|
DateOpening = model.DateOpening;
|
||||||
|
MaximumFlowers = model.MaximumFlowers;
|
||||||
|
Flowers = model.ShopFlowers.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||||
|
_shopFlowers = null;
|
||||||
|
}
|
||||||
|
public ShopViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
ShopName = ShopName,
|
||||||
|
Address = Address,
|
||||||
|
DateOpening = DateOpening,
|
||||||
|
MaximumFlowers = MaximumFlowers,
|
||||||
|
ShopFlowers = ShopFlowers,
|
||||||
|
};
|
||||||
|
|
||||||
|
public XElement GetXElement => new("Shop",
|
||||||
|
new XAttribute("Id", Id),
|
||||||
|
new XElement("ShopName", ShopName),
|
||||||
|
new XElement("Address", Address),
|
||||||
|
new XElement("DateOpening", DateOpening.ToString()),
|
||||||
|
new XElement("MaximumFlowers", MaximumFlowers.ToString()),
|
||||||
|
new XElement("ShopFlowers",
|
||||||
|
Flowers.Select(x => new XElement("ShopFlower",
|
||||||
|
new XElement("Key", x.Key),
|
||||||
|
new XElement("Value", x.Value))).ToArray()));
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,7 @@
|
|||||||
using FlowerShopContracts.SearchModels;
|
using FlowerShopContracts.SearchModels;
|
||||||
using FlowerShopContracts.StoragesContracts;
|
using FlowerShopContracts.StoragesContracts;
|
||||||
using FlowerShopContracts.ViewModels;
|
using FlowerShopContracts.ViewModels;
|
||||||
|
using FlowerShopDataModels.Models;
|
||||||
using FlowerShopListImplement.Models;
|
using FlowerShopListImplement.Models;
|
||||||
|
|
||||||
namespace FlowerShopListImplement.Implements
|
namespace FlowerShopListImplement.Implements
|
||||||
@ -105,5 +106,9 @@ namespace FlowerShopListImplement.Implements
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
public bool MakeSale(IFlowerModel model, int count)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,9 +10,10 @@ namespace FlowerShopListImplement.Models
|
|||||||
public string ShopName { get; private set; } = string.Empty;
|
public string ShopName { get; private set; } = string.Empty;
|
||||||
public string Address { get; private set; } = string.Empty;
|
public string Address { get; private set; } = string.Empty;
|
||||||
public DateTime DateOpening { get; private set; }
|
public DateTime DateOpening { get; private set; }
|
||||||
public Dictionary<int, (IFlowerModel, int)> Flowers { get; private set; } = new();
|
public Dictionary<int, (IFlowerModel, int)> ShopFlowers { get; private set; } = new();
|
||||||
|
public int MaximumFlowers { get; private set; }
|
||||||
|
|
||||||
public static Shop? Create(ShopBindingModel? model)
|
public static Shop? Create(ShopBindingModel? model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
{
|
{
|
||||||
@ -23,7 +24,9 @@ namespace FlowerShopListImplement.Models
|
|||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
ShopName = model.ShopName,
|
ShopName = model.ShopName,
|
||||||
Address = model.Address,
|
Address = model.Address,
|
||||||
DateOpening = model.DateOpening
|
DateOpening = model.DateOpening,
|
||||||
|
ShopFlowers = model.ShopFlowers,
|
||||||
|
MaximumFlowers = model.MaximumFlowers,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,6 +39,8 @@ namespace FlowerShopListImplement.Models
|
|||||||
ShopName = model.ShopName;
|
ShopName = model.ShopName;
|
||||||
Address = model.Address;
|
Address = model.Address;
|
||||||
DateOpening = model.DateOpening;
|
DateOpening = model.DateOpening;
|
||||||
|
ShopFlowers = model.ShopFlowers;
|
||||||
|
MaximumFlowers = model.MaximumFlowers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ShopViewModel GetViewModel => new()
|
public ShopViewModel GetViewModel => new()
|
||||||
@ -44,7 +49,8 @@ namespace FlowerShopListImplement.Models
|
|||||||
ShopName = ShopName,
|
ShopName = ShopName,
|
||||||
Address = Address,
|
Address = Address,
|
||||||
DateOpening = DateOpening,
|
DateOpening = DateOpening,
|
||||||
Flowers = Flowers
|
ShopFlowers = ShopFlowers,
|
||||||
|
MaximumFlowers = MaximumFlowers,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user