ISEbd-22 Alimova M.S. Lab Work 01 base #1

Closed
malimova wants to merge 13 commits from Lab1_base into main
13 changed files with 187 additions and 43 deletions
Showing only changes of commit 0e9c54c487 - Show all commits

View File

@ -85,7 +85,7 @@ namespace ConfectioneryBusinessLogic
{
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);
}

View File

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

View File

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

View File

@ -38,6 +38,7 @@
//
// dataGridView
//
dataGridView.BackgroundColor = Color.AliceBlue;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(12, 12);
dataGridView.Name = "dataGridView";

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -79,15 +79,32 @@ namespace ConfectioneryView
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)
{
_logger.LogInformation("Загрузка изделия");
_logger.LogInformation("Загрузка суши");
try
{
var view = _logic.ReadElement(new PastrySearchModel
{
Id =
_id.Value
Id = _id.Value
});
if (view != null)
{
@ -100,7 +117,7 @@ namespace ConfectioneryView
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки изделия");
_logger.LogError(ex, "Ошибка загрузки суши");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}

View File

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

View File

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

View File

@ -7,14 +7,108 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Extensions.Logging;
using ConfectioneryContracts.BindingModels;
using ConfectioneryContracts.BusinessLogicsContracts;
namespace ConfectioneryView
{
public partial class FormPastrys : Form
{
public FormPastrys()
private readonly ILogger _logger;
private readonly IPastryLogic _logic;
public FormPastrys(ILogger<FormPastrys> logger, IPastryLogic logic)
{
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();
}
}
}