Много изменений...

This commit is contained in:
malimova 2024-02-28 21:24:29 +04:00
parent ccc910eb79
commit 0e9c54c487
13 changed files with 187 additions and 43 deletions

View File

@ -85,7 +85,7 @@ namespace ConfectioneryBusinessLogic
{ {
throw new ArithmeticException($"Дата выдачи заказа {model.DateImplement} не может быть раньше даты его создания {model.DateCreate}"); throw new ArithmeticException($"Дата выдачи заказа {model.DateImplement} не может быть раньше даты его создания {model.DateCreate}");
} }
_logger.LogInformation("Sushi. SushiId:{SushiId}.Count:{Count}.Sum:{Sum}Id:{Id}", _logger.LogInformation("Pastry. PastryId:{PastryId}.Count:{Count}.Sum:{Sum}Id:{Id}",
model.PastryId, model.Count, model.Sum, model.Id); model.PastryId, model.Count, model.Sum, model.Id);
} }

View File

@ -76,6 +76,7 @@
buttonCreate.TabIndex = 4; buttonCreate.TabIndex = 4;
buttonCreate.Text = "Создать"; buttonCreate.Text = "Создать";
buttonCreate.UseVisualStyleBackColor = true; buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += ButtonSave_Click;
// //
// buttonCancel // buttonCancel
// //
@ -85,6 +86,7 @@
buttonCancel.TabIndex = 5; buttonCancel.TabIndex = 5;
buttonCancel.Text = "Отмена"; buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true; buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
// //
// FormComponent // FormComponent
// //
@ -99,6 +101,7 @@
Controls.Add(label1); Controls.Add(label1);
Name = "FormComponent"; Name = "FormComponent";
Text = "Компонент"; Text = "Компонент";
Load += FormComponent_Load;
ResumeLayout(false); ResumeLayout(false);
PerformLayout(); PerformLayout();
} }

View File

@ -80,5 +80,7 @@ namespace ConfectioneryView
DialogResult = DialogResult.Cancel; DialogResult = DialogResult.Cancel;
Close(); Close();
} }
} }
} }

View File

@ -38,6 +38,7 @@
// //
// dataGridView // dataGridView
// //
dataGridView.BackgroundColor = Color.AliceBlue;
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";

View File

@ -72,7 +72,7 @@
comboBoxPastry.Name = "comboBoxPastry"; comboBoxPastry.Name = "comboBoxPastry";
comboBoxPastry.Size = new Size(434, 33); comboBoxPastry.Size = new Size(434, 33);
comboBoxPastry.TabIndex = 3; comboBoxPastry.TabIndex = 3;
comboBoxPastry.SelectedIndexChanged += comboBoxProduct_SelectedIndexChanged; comboBoxPastry.SelectedIndexChanged += comboBoxPastry_SelectedIndexChanged;
// //
// textBoxCount // textBoxCount
// //
@ -86,6 +86,7 @@
// //
textBoxSum.Location = new Point(192, 155); textBoxSum.Location = new Point(192, 155);
textBoxSum.Name = "textBoxSum"; textBoxSum.Name = "textBoxSum";
textBoxSum.ReadOnly = true;
textBoxSum.Size = new Size(434, 31); textBoxSum.Size = new Size(434, 31);
textBoxSum.TabIndex = 5; textBoxSum.TabIndex = 5;
// //
@ -123,7 +124,7 @@
Controls.Add(labelCount); Controls.Add(labelCount);
Controls.Add(labelName); Controls.Add(labelName);
Name = "FormCreateOrder"; Name = "FormCreateOrder";
Text = "FormCreateOrder"; Text = "Создание заказа";
Load += FormCreateOrder_Load; Load += FormCreateOrder_Load;
ResumeLayout(false); ResumeLayout(false);
PerformLayout(); PerformLayout();

View File

@ -73,15 +73,15 @@ namespace ConfectioneryView
private void FormCreateOrder_Load(object sender, EventArgs e) private void FormCreateOrder_Load(object sender, EventArgs e)
{ {
_logger.LogInformation("Загрузка суши для заказа"); _logger.LogInformation("Загрузка кондитерского изделия для заказа");
_list = _logicP.ReadList(null); _list = _logicP.ReadList(null);
if (_list != null) if (_list != null)
{ {
comboBoxPastry.DisplayMember = "SushiName"; comboBoxPastry.DisplayMember = "PastryName";
comboBoxPastry.ValueMember = "Id"; comboBoxPastry.ValueMember = "Id";
comboBoxPastry.DataSource = _list; comboBoxPastry.DataSource = _list;
comboBoxPastry.SelectedItem = null; comboBoxPastry.SelectedItem = null;
_logger.LogInformation("Загрузка суши для заказа"); _logger.LogInformation("Загрузка кондитерского изделия для заказа");
} }
} }
private void CalcSum() private void CalcSum()
@ -109,7 +109,7 @@ namespace ConfectioneryView
{ {
CalcSum(); CalcSum();
} }
private void comboBoxProduct_SelectedIndexChanged(object sender, EventArgs e) private void comboBoxPastry_SelectedIndexChanged(object sender, EventArgs e)
{ {
CalcSum(); CalcSum();
} }

View File

@ -44,6 +44,7 @@
// //
// dataGridView // dataGridView
// //
dataGridView.BackgroundColor = Color.AliceBlue;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(12, 60); dataGridView.Location = new Point(12, 60);
dataGridView.Name = "dataGridView"; dataGridView.Name = "dataGridView";
@ -74,12 +75,14 @@
componentsToolStripMenuItem.Name = "componentsToolStripMenuItem"; componentsToolStripMenuItem.Name = "componentsToolStripMenuItem";
componentsToolStripMenuItem.Size = new Size(298, 34); componentsToolStripMenuItem.Size = new Size(298, 34);
componentsToolStripMenuItem.Text = "Компоненты"; componentsToolStripMenuItem.Text = "Компоненты";
componentsToolStripMenuItem.Click += componentsToolStripMenuItem_Click;
// //
// pastryToolStripMenuItem // pastryToolStripMenuItem
// //
pastryToolStripMenuItem.Name = "pastryToolStripMenuItem"; pastryToolStripMenuItem.Name = "pastryToolStripMenuItem";
pastryToolStripMenuItem.Size = new Size(298, 34); pastryToolStripMenuItem.Size = new Size(298, 34);
pastryToolStripMenuItem.Text = "Кондитерские изделия"; pastryToolStripMenuItem.Text = "Кондитерские изделия";
pastryToolStripMenuItem.Click += pastryToolStripMenuItem_Click;
// //
// buttonCreateOrder // buttonCreateOrder
// //
@ -145,7 +148,8 @@
Controls.Add(menuStrip); Controls.Add(menuStrip);
MainMenuStrip = menuStrip; MainMenuStrip = menuStrip;
Name = "FormMain"; Name = "FormMain";
Text = "FormMain"; Text = "Кондитерская";
Load += FormMain_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
menuStrip.ResumeLayout(false); menuStrip.ResumeLayout(false);
menuStrip.PerformLayout(); menuStrip.PerformLayout();

View File

@ -30,10 +30,25 @@ namespace ConfectioneryView
private void LoadData() private void LoadData()
{ {
_logger.LogInformation("Загрузка заказов"); _logger.LogInformation("Загрузка заказов");
// прописать логику try
{
var list = _orderLogic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["PastryId"].Visible = false;
dataGridView.Columns["PastryName"].AutoSizeMode =
DataGridViewAutoSizeColumnMode.Fill;
} }
private void componentsToolStripMenuItem_Click(object sender, EventArgs _logger.LogInformation("Загрузка заказов");
e) }
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки заказов");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void componentsToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
if (service is FormComponents form) if (service is FormComponents form)
@ -43,7 +58,6 @@ e)
} }
private void pastryToolStripMenuItem_Click(object sender, EventArgs e) private void pastryToolStripMenuItem_Click(object sender, EventArgs e)
{ {
// прописать логику
var service = Program.ServiceProvider?.GetService(typeof(FormPastrys)); var service = Program.ServiceProvider?.GetService(typeof(FormPastrys));
if (service is FormPastrys form) if (service is FormPastrys form)
{ {
@ -65,8 +79,7 @@ e)
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
int id = int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id);
try try
{ {
@ -92,10 +105,8 @@ e)
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
int id = int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'",
id);
try try
{ {
var operationResult = _orderLogic.FinishOrder(new var operationResult = _orderLogic.FinishOrder(new

View File

@ -132,6 +132,7 @@
// //
// dataGridView // dataGridView
// //
dataGridView.BackgroundColor = Color.AliceBlue;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(10, 30); dataGridView.Location = new Point(10, 30);
dataGridView.Name = "dataGridView"; dataGridView.Name = "dataGridView";
@ -173,7 +174,7 @@
Controls.Add(label2); Controls.Add(label2);
Controls.Add(label1); Controls.Add(label1);
Name = "FormPastry"; Name = "FormPastry";
Text = "FormPastry"; Text = "Кондитерское изделие";
Load += FormPastry_Load; Load += FormPastry_Load;
groupBoxComponents.ResumeLayout(false); groupBoxComponents.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();

View File

@ -79,15 +79,32 @@ namespace ConfectioneryView
private void FormPastry_Load(object sender, EventArgs e) private void FormPastry_Load(object sender, EventArgs e)
{ {
var list = _logic.ReadList(null);
if (list != null)
{
dataGridView.AllowUserToAddRows = false;
DataGridViewTextBoxColumn Id = new DataGridViewTextBoxColumn();
DataGridViewTextBoxColumn Component = new DataGridViewTextBoxColumn();
DataGridViewTextBoxColumn Number = new DataGridViewTextBoxColumn();
Component.HeaderText = "Количество";
Number.HeaderText = "Компонент";
Number.Name = "Number";
Id.Name = "Id";
dataGridView.Columns.Add(Id);
dataGridView.Columns.Add(Number);
dataGridView.Columns.Add(Component);
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["Number"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
if (_id.HasValue) if (_id.HasValue)
{ {
_logger.LogInformation("Загрузка изделия"); _logger.LogInformation("Загрузка суши");
try try
{ {
var view = _logic.ReadElement(new PastrySearchModel var view = _logic.ReadElement(new PastrySearchModel
{ {
Id = Id = _id.Value
_id.Value
}); });
if (view != null) if (view != null)
{ {
@ -100,7 +117,7 @@ namespace ConfectioneryView
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка загрузки изделия"); _logger.LogError(ex, "Ошибка загрузки суши");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error); MessageBoxIcon.Error);
} }

View File

@ -101,7 +101,7 @@
Controls.Add(label2); Controls.Add(label2);
Controls.Add(label1); Controls.Add(label1);
Name = "FormPastryComponent"; Name = "FormPastryComponent";
Text = "FormPastryComponent"; Text = "Компонент изделия";
ResumeLayout(false); ResumeLayout(false);
PerformLayout(); PerformLayout();
} }

View File

@ -28,79 +28,89 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
dataGridView1 = new DataGridView(); dataGridView = new DataGridView();
buttonAdd = new Button(); buttonAdd = new Button();
buttonUpd = new Button(); buttonUpd = new Button();
buttonDel = new Button(); buttonDel = new Button();
buttonRef = new Button(); buttonRef = new Button();
((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout(); SuspendLayout();
// //
// dataGridView1 // dataGridView
// //
dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.BackgroundColor = Color.AliceBlue;
dataGridView1.Location = new Point(12, 12); dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView1.Name = "dataGridView1"; dataGridView.Location = new Point(12, 12);
dataGridView1.RowHeadersWidth = 62; dataGridView.Name = "dataGridView";
dataGridView1.RowTemplate.Height = 33; dataGridView.RowHeadersWidth = 62;
dataGridView1.Size = new Size(1075, 635); dataGridView.RowTemplate.Height = 33;
dataGridView1.TabIndex = 0; dataGridView.Size = new Size(916, 479);
dataGridView.TabIndex = 0;
// //
// buttonAdd // buttonAdd
// //
buttonAdd.Location = new Point(1161, 53); buttonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonAdd.Location = new Point(975, 53);
buttonAdd.Name = "buttonAdd"; buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(133, 46); buttonAdd.Size = new Size(133, 46);
buttonAdd.TabIndex = 1; buttonAdd.TabIndex = 1;
buttonAdd.Text = "Добавить"; buttonAdd.Text = "Добавить";
buttonAdd.UseVisualStyleBackColor = true; buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += buttonAdd_Click;
// //
// buttonUpd // buttonUpd
// //
buttonUpd.Location = new Point(1161, 119); buttonUpd.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonUpd.Location = new Point(975, 119);
buttonUpd.Name = "buttonUpd"; buttonUpd.Name = "buttonUpd";
buttonUpd.Size = new Size(133, 46); buttonUpd.Size = new Size(133, 46);
buttonUpd.TabIndex = 2; buttonUpd.TabIndex = 2;
buttonUpd.Text = "Изменить"; buttonUpd.Text = "Изменить";
buttonUpd.UseVisualStyleBackColor = true; buttonUpd.UseVisualStyleBackColor = true;
buttonUpd.Click += buttonUpd_Click;
// //
// buttonDel // buttonDel
// //
buttonDel.Location = new Point(1161, 185); buttonDel.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonDel.Location = new Point(975, 185);
buttonDel.Name = "buttonDel"; buttonDel.Name = "buttonDel";
buttonDel.Size = new Size(133, 45); buttonDel.Size = new Size(133, 45);
buttonDel.TabIndex = 3; buttonDel.TabIndex = 3;
buttonDel.Text = "Удалить"; buttonDel.Text = "Удалить";
buttonDel.UseVisualStyleBackColor = true; buttonDel.UseVisualStyleBackColor = true;
buttonDel.Click += buttonDel_Click;
// //
// buttonRef // buttonRef
// //
buttonRef.Location = new Point(1161, 251); buttonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonRef.Location = new Point(975, 251);
buttonRef.Name = "buttonRef"; buttonRef.Name = "buttonRef";
buttonRef.Size = new Size(133, 48); buttonRef.Size = new Size(133, 48);
buttonRef.TabIndex = 4; buttonRef.TabIndex = 4;
buttonRef.Text = "Обновить"; buttonRef.Text = "Обновить";
buttonRef.UseVisualStyleBackColor = true; buttonRef.UseVisualStyleBackColor = true;
buttonRef.Click += buttonRef_Click;
// //
// FormPastrys // FormPastrys
// //
AutoScaleDimensions = new SizeF(10F, 25F); AutoScaleDimensions = new SizeF(10F, 25F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1325, 659); ClientSize = new Size(1139, 518);
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(dataGridView1); Controls.Add(dataGridView);
Name = "FormPastrys"; Name = "FormPastrys";
Text = "Кондитерские изделия"; Text = "Кондитерские изделия";
((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit(); Load += FormPastrys_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false); ResumeLayout(false);
} }
#endregion #endregion
private DataGridView dataGridView1; private DataGridView dataGridView;
private Button buttonAdd; private Button buttonAdd;
private Button buttonUpd; private Button buttonUpd;
private Button buttonDel; private Button buttonDel;

View File

@ -7,14 +7,108 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using Microsoft.Extensions.Logging;
using ConfectioneryContracts.BindingModels;
using ConfectioneryContracts.BusinessLogicsContracts;
namespace ConfectioneryView namespace ConfectioneryView
{ {
public partial class FormPastrys : Form public partial class FormPastrys : Form
{ {
public FormPastrys() private readonly ILogger _logger;
private readonly IPastryLogic _logic;
public FormPastrys(ILogger<FormPastrys> logger, IPastryLogic logic)
{ {
InitializeComponent(); InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormPastrys_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["PastryComponents"].Visible = false;
dataGridView.Columns["PastryName"].AutoSizeMode =
DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка кондитерского изделия");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки кондитерского изделия");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormPastry));
if (service is FormPastry form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void buttonUpd_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormPastry));
if (service is FormPastry form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void buttonDel_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Удаление кондитерского изделия");
try
{
if (!_logic.Delete(new PastryBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления кондитерского изделия");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void buttonRef_Click(object sender, EventArgs e)
{
LoadData();
} }
} }
} }