Итоговый вариант + добавлен файл nlog.config.

This commit is contained in:
Anastasia 2023-03-01 10:48:21 +04:00
parent f29a279a08
commit 63ae753b2a
26 changed files with 248 additions and 265 deletions

View File

@ -7,5 +7,4 @@ namespace JewelryStoreDataModels.Models
string ComponentName { get; } string ComponentName { get; }
double Cost { get; } double Cost { get; }
} }
} }

View File

@ -20,13 +20,14 @@ namespace JewelryStore
private readonly IComponentLogic _logic; private readonly IComponentLogic _logic;
private int? _id; private int? _id;
public int Id { set { _id = value; } } public int Id { set { _id = value; } }
public FormComponent(ILogger<FormComponent> logger, IComponentLogic
logic) public FormComponent(ILogger<FormComponent> logger, IComponentLogic logic)
{ {
InitializeComponent(); InitializeComponent();
_logger = logger; _logger = logger;
_logic = logic; _logic = logic;
} }
private void FormComponent_Load(object sender, EventArgs e) private void FormComponent_Load(object sender, EventArgs e)
{ {
if (_id.HasValue) if (_id.HasValue)
@ -36,8 +37,7 @@ namespace JewelryStore
_logger.LogInformation("Получение компонента"); _logger.LogInformation("Получение компонента");
var view = _logic.ReadElement(new ComponentSearchModel var view = _logic.ReadElement(new ComponentSearchModel
{ {
Id = Id = _id.Value
_id.Value
}); });
if (view != null) if (view != null)
{ {
@ -48,17 +48,16 @@ namespace JewelryStore
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);
} }
} }
} }
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("Заполните название", "Ошибка", MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }
_logger.LogInformation("Сохранение компонента"); _logger.LogInformation("Сохранение компонента");
@ -70,24 +69,22 @@ namespace JewelryStore
ComponentName = textBoxName.Text, ComponentName = textBoxName.Text,
Cost = Convert.ToDouble(textBoxCost.Text) Cost = Convert.ToDouble(textBoxCost.Text)
}; };
var operationResult = _id.HasValue ? _logic.Update(model) : var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
_logic.Create(model);
if (!operationResult) if (!operationResult)
{ {
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
} }
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK; DialogResult = DialogResult.OK;
Close(); Close();
} }
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);
} }
} }
private void ButtonCancel_Click(object sender, EventArgs e) private void ButtonCancel_Click(object sender, EventArgs e)
{ {
DialogResult = DialogResult.Cancel; DialogResult = DialogResult.Cancel;

View File

@ -30,7 +30,7 @@
{ {
this.dataGridView = new System.Windows.Forms.DataGridView(); this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonAdd = new System.Windows.Forms.Button(); this.buttonAdd = new System.Windows.Forms.Button();
this.buttonRef = new System.Windows.Forms.Button(); this.buttonRefresh = new System.Windows.Forms.Button();
this.buttonDelete = new System.Windows.Forms.Button(); this.buttonDelete = new System.Windows.Forms.Button();
this.buttonUpdate = new System.Windows.Forms.Button(); this.buttonUpdate = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
@ -46,7 +46,6 @@
this.dataGridView.RowTemplate.Height = 33; this.dataGridView.RowTemplate.Height = 33;
this.dataGridView.Size = new System.Drawing.Size(525, 427); this.dataGridView.Size = new System.Drawing.Size(525, 427);
this.dataGridView.TabIndex = 0; this.dataGridView.TabIndex = 0;
this.dataGridView.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView_CellContentClick);
// //
// buttonAdd // buttonAdd
// //
@ -58,15 +57,15 @@
this.buttonAdd.UseVisualStyleBackColor = true; this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
// //
// buttonRef // buttonRefresh
// //
this.buttonRef.Location = new System.Drawing.Point(569, 107); this.buttonRefresh.Location = new System.Drawing.Point(569, 107);
this.buttonRef.Name = "buttonRef"; this.buttonRefresh.Name = "buttonRefresh";
this.buttonRef.Size = new System.Drawing.Size(164, 34); this.buttonRefresh.Size = new System.Drawing.Size(164, 34);
this.buttonRef.TabIndex = 2; this.buttonRefresh.TabIndex = 2;
this.buttonRef.Text = "Изменить"; this.buttonRefresh.Text = "Изменить";
this.buttonRef.UseVisualStyleBackColor = true; this.buttonRefresh.UseVisualStyleBackColor = true;
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); this.buttonRefresh.Click += new System.EventHandler(this.ButtonRefresh_Click);
// //
// buttonDelete // buttonDelete
// //
@ -95,12 +94,11 @@
this.ClientSize = new System.Drawing.Size(756, 450); this.ClientSize = new System.Drawing.Size(756, 450);
this.Controls.Add(this.buttonUpdate); this.Controls.Add(this.buttonUpdate);
this.Controls.Add(this.buttonDelete); this.Controls.Add(this.buttonDelete);
this.Controls.Add(this.buttonRef); this.Controls.Add(this.buttonRefresh);
this.Controls.Add(this.buttonAdd); this.Controls.Add(this.buttonAdd);
this.Controls.Add(this.dataGridView); this.Controls.Add(this.dataGridView);
this.Name = "FormComponents"; this.Name = "FormComponents";
this.Text = "Компоненты"; this.Text = "Компоненты";
this.Load += new System.EventHandler(this.FormComponents_Load_1);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
@ -110,7 +108,7 @@
private DataGridView dataGridView; private DataGridView dataGridView;
private Button buttonAdd; private Button buttonAdd;
private Button buttonRef; private Button buttonRefresh;
private Button buttonDelete; private Button buttonDelete;
private Button buttonUpdate; private Button buttonUpdate;
} }

View File

@ -9,6 +9,7 @@ namespace JewelryStore
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IComponentLogic _logic; private readonly IComponentLogic _logic;
public FormComponents(ILogger<FormComponents> logger, IComponentLogic logic) public FormComponents(ILogger<FormComponents> logger, IComponentLogic logic)
{ {
InitializeComponent(); InitializeComponent();
@ -20,6 +21,7 @@ namespace JewelryStore
{ {
LoadData(); LoadData();
} }
private void LoadData() private void LoadData()
{ {
try try
@ -29,16 +31,14 @@ namespace JewelryStore
{ {
dataGridView.DataSource = list; dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false; dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["ComponentName"].AutoSizeMode = dataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
DataGridViewAutoSizeColumnMode.Fill;
} }
_logger.LogInformation("Загрузка компонентов"); _logger.LogInformation("Загрузка компонентов");
} }
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);
} }
} }
@ -63,11 +63,9 @@ namespace JewelryStore
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
if (MessageBox.Show("Удалить запись?", "Вопрос", if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
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
{ {
@ -83,20 +81,17 @@ namespace JewelryStore
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка удаления компонента"); _logger.LogError(ex, "Ошибка удаления компонента");
MessageBox.Show(ex.Message, "Ошибка", MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
} }
} }
} }
private void ButtonRef_Click(object sender, EventArgs e) private void ButtonRefresh_Click(object sender, EventArgs e)
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
var service = var service = Program.ServiceProvider?.GetService(typeof(FormComponent));
Program.ServiceProvider?.GetService(typeof(FormComponent));
if (service is FormComponent form) if (service is FormComponent form)
{ {
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
@ -107,15 +102,5 @@ namespace JewelryStore
} }
} }
} }
private void FormComponents_Load_1(object sender, EventArgs e)
{
}
private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
} }
} }

View File

@ -29,8 +29,8 @@
private void InitializeComponent() private void InitializeComponent()
{ {
this.labelJewel = new System.Windows.Forms.Label(); this.labelJewel = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label(); this.labelCount = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label(); this.labelSum = new System.Windows.Forms.Label();
this.comboBoxJewel = new System.Windows.Forms.ComboBox(); this.comboBoxJewel = new System.Windows.Forms.ComboBox();
this.textBoxCount = new System.Windows.Forms.TextBox(); this.textBoxCount = new System.Windows.Forms.TextBox();
this.textBoxSum = new System.Windows.Forms.TextBox(); this.textBoxSum = new System.Windows.Forms.TextBox();
@ -47,23 +47,23 @@
this.labelJewel.TabIndex = 0; this.labelJewel.TabIndex = 0;
this.labelJewel.Text = "Изделие:"; this.labelJewel.Text = "Изделие:";
// //
// label2 // labelCount
// //
this.label2.AutoSize = true; this.labelCount.AutoSize = true;
this.label2.Location = new System.Drawing.Point(17, 62); this.labelCount.Location = new System.Drawing.Point(17, 62);
this.label2.Name = "label2"; this.labelCount.Name = "labelCount";
this.label2.Size = new System.Drawing.Size(111, 25); this.labelCount.Size = new System.Drawing.Size(111, 25);
this.label2.TabIndex = 1; this.labelCount.TabIndex = 1;
this.label2.Text = "Количество:"; this.labelCount.Text = "Количество:";
// //
// label3 // labelSum
// //
this.label3.AutoSize = true; this.labelSum.AutoSize = true;
this.label3.Location = new System.Drawing.Point(17, 107); this.labelSum.Location = new System.Drawing.Point(17, 107);
this.label3.Name = "label3"; this.labelSum.Name = "labelSum";
this.label3.Size = new System.Drawing.Size(71, 25); this.labelSum.Size = new System.Drawing.Size(71, 25);
this.label3.TabIndex = 2; this.labelSum.TabIndex = 2;
this.label3.Text = "Сумма:"; this.labelSum.Text = "Сумма:";
// //
// comboBoxJewel // comboBoxJewel
// //
@ -120,8 +120,8 @@
this.Controls.Add(this.textBoxSum); this.Controls.Add(this.textBoxSum);
this.Controls.Add(this.textBoxCount); this.Controls.Add(this.textBoxCount);
this.Controls.Add(this.comboBoxJewel); this.Controls.Add(this.comboBoxJewel);
this.Controls.Add(this.label3); this.Controls.Add(this.labelSum);
this.Controls.Add(this.label2); this.Controls.Add(this.labelCount);
this.Controls.Add(this.labelJewel); this.Controls.Add(this.labelJewel);
this.Name = "FormCreateOrder"; this.Name = "FormCreateOrder";
this.Text = "Заказ"; this.Text = "Заказ";
@ -134,8 +134,8 @@
#endregion #endregion
private Label labelJewel; private Label labelJewel;
private Label label2; private Label labelCount;
private Label label3; private Label labelSum;
private ComboBox comboBoxJewel; private ComboBox comboBoxJewel;
private TextBox textBoxCount; private TextBox textBoxCount;
private TextBox textBoxSum; private TextBox textBoxSum;

View File

@ -12,7 +12,6 @@ namespace JewelryStore
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IJewelLogic _logicJ; private readonly IJewelLogic _logicJ;
private readonly IOrderLogic _logicO; private readonly IOrderLogic _logicO;
private List<JewelViewModel>? _list; private List<JewelViewModel>? _list;
public FormCreateOrder(ILogger<FormCreateOrder> logger, IJewelLogic logicJ, IOrderLogic logicO) public FormCreateOrder(ILogger<FormCreateOrder> logger, IJewelLogic logicJ, IOrderLogic logicO)
@ -89,14 +88,12 @@ namespace JewelryStore
{ {
if (string.IsNullOrEmpty(textBoxCount.Text)) if (string.IsNullOrEmpty(textBoxCount.Text))
{ {
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }
if (comboBoxJewel.SelectedValue == null) if (comboBoxJewel.SelectedValue == null)
{ {
MessageBox.Show("Выберите драгоценность", "Ошибка", MessageBox.Show("Выберите драгоценность", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }
_logger.LogInformation("Создание заказа"); _logger.LogInformation("Создание заказа");
@ -119,10 +116,8 @@ namespace JewelryStore
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);
} }
} }
private void ComboBoxJewel_SelectedIndexChanged(object sender, EventArgs e) private void ComboBoxJewel_SelectedIndexChanged(object sender, EventArgs e)
@ -130,7 +125,6 @@ namespace JewelryStore
CalcSum(); CalcSum();
} }
private void ButtonCancel_Click(object sender, EventArgs e) private void ButtonCancel_Click(object sender, EventArgs e)
{ {
DialogResult = DialogResult.Cancel; DialogResult = DialogResult.Cancel;

View File

@ -29,6 +29,9 @@
private void InitializeComponent() private void InitializeComponent()
{ {
this.dataGridView = new System.Windows.Forms.DataGridView(); this.dataGridView = new System.Windows.Forms.DataGridView();
this.JewelId = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ComponentName = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.labelName = new System.Windows.Forms.Label(); this.labelName = new System.Windows.Forms.Label();
this.labelPrice = new System.Windows.Forms.Label(); this.labelPrice = new System.Windows.Forms.Label();
this.textBoxName = new System.Windows.Forms.TextBox(); this.textBoxName = new System.Windows.Forms.TextBox();
@ -36,13 +39,10 @@
this.groupBox = new System.Windows.Forms.GroupBox(); this.groupBox = new System.Windows.Forms.GroupBox();
this.buttonUpdate = new System.Windows.Forms.Button(); this.buttonUpdate = new System.Windows.Forms.Button();
this.buttonDelete = new System.Windows.Forms.Button(); this.buttonDelete = new System.Windows.Forms.Button();
this.buttonChange = new System.Windows.Forms.Button(); this.buttonRefresh = new System.Windows.Forms.Button();
this.buttonAdd = new System.Windows.Forms.Button(); this.buttonAdd = new System.Windows.Forms.Button();
this.buttonSave = new System.Windows.Forms.Button(); this.buttonSave = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button(); this.buttonCancel = new System.Windows.Forms.Button();
this.JewelId = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ComponentName = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.groupBox.SuspendLayout(); this.groupBox.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
@ -61,7 +61,29 @@
this.dataGridView.RowTemplate.Height = 33; this.dataGridView.RowTemplate.Height = 33;
this.dataGridView.Size = new System.Drawing.Size(468, 325); this.dataGridView.Size = new System.Drawing.Size(468, 325);
this.dataGridView.TabIndex = 0; this.dataGridView.TabIndex = 0;
this.dataGridView.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView_CellContentClick); //
// JewelId
//
this.JewelId.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.None;
this.JewelId.HeaderText = "Id";
this.JewelId.MinimumWidth = 8;
this.JewelId.Name = "JewelId";
this.JewelId.Visible = false;
this.JewelId.Width = 8;
//
// ComponentName
//
this.ComponentName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.ComponentName.HeaderText = "Компонент";
this.ComponentName.MinimumWidth = 8;
this.ComponentName.Name = "ComponentName";
//
// Count
//
this.Count.HeaderText = "Количество";
this.Count.MinimumWidth = 8;
this.Count.Name = "Count";
this.Count.Width = 150;
// //
// labelName // labelName
// //
@ -99,7 +121,7 @@
// //
this.groupBox.Controls.Add(this.buttonUpdate); this.groupBox.Controls.Add(this.buttonUpdate);
this.groupBox.Controls.Add(this.buttonDelete); this.groupBox.Controls.Add(this.buttonDelete);
this.groupBox.Controls.Add(this.buttonChange); this.groupBox.Controls.Add(this.buttonRefresh);
this.groupBox.Controls.Add(this.buttonAdd); this.groupBox.Controls.Add(this.buttonAdd);
this.groupBox.Controls.Add(this.dataGridView); this.groupBox.Controls.Add(this.dataGridView);
this.groupBox.Location = new System.Drawing.Point(15, 94); this.groupBox.Location = new System.Drawing.Point(15, 94);
@ -129,15 +151,15 @@
this.buttonDelete.UseVisualStyleBackColor = true; this.buttonDelete.UseVisualStyleBackColor = true;
this.buttonDelete.Click += new System.EventHandler(this.ButtonDelete_Click); this.buttonDelete.Click += new System.EventHandler(this.ButtonDelete_Click);
// //
// buttonChange // buttonRefresh
// //
this.buttonChange.Location = new System.Drawing.Point(505, 118); this.buttonRefresh.Location = new System.Drawing.Point(505, 118);
this.buttonChange.Name = "buttonChange"; this.buttonRefresh.Name = "buttonRefresh";
this.buttonChange.Size = new System.Drawing.Size(141, 34); this.buttonRefresh.Size = new System.Drawing.Size(141, 34);
this.buttonChange.TabIndex = 2; this.buttonRefresh.TabIndex = 2;
this.buttonChange.Text = "Изменить"; this.buttonRefresh.Text = "Изменить";
this.buttonChange.UseVisualStyleBackColor = true; this.buttonRefresh.UseVisualStyleBackColor = true;
this.buttonChange.Click += new System.EventHandler(this.ButtonChange_Click); this.buttonRefresh.Click += new System.EventHandler(this.ButtonRefresh_Click);
// //
// buttonAdd // buttonAdd
// //
@ -169,29 +191,6 @@
this.buttonCancel.UseVisualStyleBackColor = true; this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
// //
// JewelId
//
this.JewelId.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.None;
this.JewelId.HeaderText = "Id";
this.JewelId.MinimumWidth = 8;
this.JewelId.Name = "JewelId";
this.JewelId.Visible = false;
this.JewelId.Width = 8;
//
// ComponentName
//
this.ComponentName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.ComponentName.HeaderText = "Компонент";
this.ComponentName.MinimumWidth = 8;
this.ComponentName.Name = "ComponentName";
//
// Count
//
this.Count.HeaderText = "Количество";
this.Count.MinimumWidth = 8;
this.Count.Name = "Count";
this.Count.Width = 150;
//
// FormJewel // FormJewel
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
@ -223,7 +222,7 @@
private GroupBox groupBox; private GroupBox groupBox;
private Button buttonUpdate; private Button buttonUpdate;
private Button buttonDelete; private Button buttonDelete;
private Button buttonChange; private Button buttonRefresh;
private Button buttonAdd; private Button buttonAdd;
private Button buttonSave; private Button buttonSave;
private Button buttonCancel; private Button buttonCancel;

View File

@ -14,6 +14,7 @@ namespace JewelryStore
private int? _id; private int? _id;
private Dictionary<int, (IComponentModel, int)> _JewelComponents; private Dictionary<int, (IComponentModel, int)> _JewelComponents;
public int Id { set { _id = value; } } public int Id { set { _id = value; } }
public FormJewel(ILogger<FormJewel> logger, IJewelLogic logic) public FormJewel(ILogger<FormJewel> logger, IJewelLogic logic)
{ {
InitializeComponent(); InitializeComponent();
@ -26,7 +27,7 @@ namespace JewelryStore
{ {
if (_id.HasValue) if (_id.HasValue)
{ {
_logger.LogInformation("Загрузка драгоценности"); _logger.LogInformation("Загрузка изделия");
try try
{ {
var view = _logic.ReadElement(new JewelSearchModel var view = _logic.ReadElement(new JewelSearchModel
@ -37,40 +38,37 @@ namespace JewelryStore
{ {
textBoxName.Text = view.JewelName; textBoxName.Text = view.JewelName;
textBoxPrice.Text = view.Price.ToString(); textBoxPrice.Text = view.Price.ToString();
_JewelComponents = view.JewelComponents ?? new _JewelComponents = view.JewelComponents ?? new Dictionary<int, (IComponentModel, int)>();
Dictionary<int, (IComponentModel, int)>();
LoadData(); LoadData();
} }
} }
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);
} }
} }
} }
private void LoadData() private void LoadData()
{ {
_logger.LogInformation("Загрузка компонент драгоценности"); _logger.LogInformation("Загрузка компонентов изделия");
try try
{ {
if (_JewelComponents != null) if (_JewelComponents != null)
{ {
dataGridView.Rows.Clear(); dataGridView.Rows.Clear();
foreach (var pc in _JewelComponents) foreach (var jc in _JewelComponents)
{ {
dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); dataGridView.Rows.Add(new object[] { jc.Key, jc.Value.Item1.ComponentName, jc.Value.Item2 });
} }
textBoxPrice.Text = CalcPrice().ToString(); textBoxPrice.Text = CalcPrice().ToString();
} }
} }
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);
} }
} }
@ -97,10 +95,9 @@ namespace JewelryStore
LoadData(); LoadData();
} }
} }
} }
private void ButtonChange_Click(object sender, EventArgs e) private void ButtonRefresh_Click(object sender, EventArgs e)
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
@ -122,15 +119,13 @@ namespace JewelryStore
} }
} }
} }
} }
private void ButtonDelete_Click(object sender, EventArgs e) private void ButtonDelete_Click(object sender, EventArgs e)
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
if (MessageBox.Show("Удалить запись?", "Вопрос", if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{ {
try try
{ {
@ -139,8 +134,7 @@ namespace JewelryStore
} }
catch (Exception ex) catch (Exception ex)
{ {
MessageBox.Show(ex.Message, "Ошибка", MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
LoadData(); LoadData();
} }
@ -156,23 +150,20 @@ namespace JewelryStore
{ {
if (string.IsNullOrEmpty(textBoxName.Text)) if (string.IsNullOrEmpty(textBoxName.Text))
{ {
MessageBox.Show("Заполните название", "Ошибка", MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }
if (string.IsNullOrEmpty(textBoxPrice.Text)) if (string.IsNullOrEmpty(textBoxPrice.Text))
{ {
MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBoxIcon.Error);
return; return;
} }
if (_JewelComponents == null || _JewelComponents.Count == 0) if (_JewelComponents == null || _JewelComponents.Count == 0)
{ {
MessageBox.Show("Заполните компоненты", "Ошибка", MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }
_logger.LogInformation("Сохранение драгоценности"); _logger.LogInformation("Сохранение изделия");
try try
{ {
var model = new JewelBindingModel var model = new JewelBindingModel
@ -182,23 +173,20 @@ namespace JewelryStore
Price = Convert.ToDouble(textBoxPrice.Text), Price = Convert.ToDouble(textBoxPrice.Text),
JewelComponents = _JewelComponents JewelComponents = _JewelComponents
}; };
var operationResult = _id.HasValue ? _logic.Update(model) : var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
_logic.Create(model);
if (!operationResult) if (!operationResult)
{ {
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
} }
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK; DialogResult = DialogResult.OK;
Close(); Close();
} }
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 ButtonCancel_Click(object sender, EventArgs e) private void ButtonCancel_Click(object sender, EventArgs e)
@ -206,6 +194,7 @@ namespace JewelryStore
DialogResult = DialogResult.Cancel; DialogResult = DialogResult.Cancel;
Close(); Close();
} }
private double CalcPrice() private double CalcPrice()
{ {
double price = 0; double price = 0;
@ -215,10 +204,5 @@ namespace JewelryStore
} }
return Math.Round(price * 1.1, 2); return Math.Round(price * 1.1, 2);
} }
private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
} }
} }

View File

@ -66,4 +66,13 @@
<metadata name="Count.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <metadata name="Count.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value> <value>True</value>
</metadata> </metadata>
<metadata name="JewelId.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ComponentName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Count.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root> </root>

View File

@ -77,7 +77,7 @@
this.buttonSave.TabIndex = 4; this.buttonSave.TabIndex = 4;
this.buttonSave.Text = "Сохранить"; this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true; this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
// //
// buttonCancel // buttonCancel
// //
@ -87,7 +87,7 @@
this.buttonCancel.TabIndex = 5; this.buttonCancel.TabIndex = 5;
this.buttonCancel.Text = "Отмена"; this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true; this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
// //
// FormJewelComponent // FormJewelComponent
// //

View File

@ -7,6 +7,7 @@ namespace JewelryStore
public partial class FormJewelComponent : Form public partial class FormJewelComponent : Form
{ {
private readonly List<ComponentViewModel>? _list; private readonly List<ComponentViewModel>? _list;
public int Id public int Id
{ {
get get
@ -18,6 +19,7 @@ namespace JewelryStore
comboBoxComponent.SelectedValue = value; comboBoxComponent.SelectedValue = value;
} }
} }
public IComponentModel? ComponentModel public IComponentModel? ComponentModel
{ {
get get
@ -36,6 +38,7 @@ namespace JewelryStore
return null; return null;
} }
} }
public int Count public int Count
{ {
get { return Convert.ToInt32(textBoxCount.Text); } get { return Convert.ToInt32(textBoxCount.Text); }
@ -55,18 +58,16 @@ namespace JewelryStore
} }
} }
private void buttonSave_Click(object sender, EventArgs e) private void ButtonSave_Click(object sender, EventArgs e)
{ {
if (string.IsNullOrEmpty(textBoxCount.Text)) if (string.IsNullOrEmpty(textBoxCount.Text))
{ {
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }
if (comboBoxComponent.SelectedValue == null) if (comboBoxComponent.SelectedValue == null)
{ {
MessageBox.Show("Выберите компонент", "Ошибка", MessageBox.Show("Выберите компонент", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }
DialogResult = DialogResult.OK; DialogResult = DialogResult.OK;
@ -74,7 +75,7 @@ namespace JewelryStore
} }
private void buttonCancel_Click(object sender, EventArgs e) private void ButtonCancel_Click(object sender, EventArgs e)
{ {
DialogResult = DialogResult.Cancel; DialogResult = DialogResult.Cancel;
Close(); Close();

View File

@ -31,7 +31,7 @@
this.dataGridView = new System.Windows.Forms.DataGridView(); this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonUpdate = new System.Windows.Forms.Button(); this.buttonUpdate = new System.Windows.Forms.Button();
this.buttonDelete = new System.Windows.Forms.Button(); this.buttonDelete = new System.Windows.Forms.Button();
this.buttonRef = new System.Windows.Forms.Button(); this.buttonRefresh = new System.Windows.Forms.Button();
this.buttonAdd = new System.Windows.Forms.Button(); this.buttonAdd = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
@ -47,7 +47,6 @@
this.dataGridView.RowTemplate.Height = 33; this.dataGridView.RowTemplate.Height = 33;
this.dataGridView.Size = new System.Drawing.Size(467, 333); this.dataGridView.Size = new System.Drawing.Size(467, 333);
this.dataGridView.TabIndex = 0; this.dataGridView.TabIndex = 0;
this.dataGridView.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView_CellContentClick);
// //
// buttonUpdate // buttonUpdate
// //
@ -69,15 +68,15 @@
this.buttonDelete.UseVisualStyleBackColor = true; this.buttonDelete.UseVisualStyleBackColor = true;
this.buttonDelete.Click += new System.EventHandler(this.ButtonDelete_Click); this.buttonDelete.Click += new System.EventHandler(this.ButtonDelete_Click);
// //
// buttonRef // buttonRefresh
// //
this.buttonRef.Location = new System.Drawing.Point(516, 120); this.buttonRefresh.Location = new System.Drawing.Point(516, 120);
this.buttonRef.Name = "buttonRef"; this.buttonRefresh.Name = "buttonRefresh";
this.buttonRef.Size = new System.Drawing.Size(164, 34); this.buttonRefresh.Size = new System.Drawing.Size(164, 34);
this.buttonRef.TabIndex = 6; this.buttonRefresh.TabIndex = 6;
this.buttonRef.Text = "Изменить"; this.buttonRefresh.Text = "Изменить";
this.buttonRef.UseVisualStyleBackColor = true; this.buttonRefresh.UseVisualStyleBackColor = true;
this.buttonRef.Click += new System.EventHandler(this.ButtonChange_Click); this.buttonRefresh.Click += new System.EventHandler(this.ButtonRefresh_Click);
// //
// buttonAdd // buttonAdd
// //
@ -96,7 +95,7 @@
this.ClientSize = new System.Drawing.Size(709, 364); this.ClientSize = new System.Drawing.Size(709, 364);
this.Controls.Add(this.buttonUpdate); this.Controls.Add(this.buttonUpdate);
this.Controls.Add(this.buttonDelete); this.Controls.Add(this.buttonDelete);
this.Controls.Add(this.buttonRef); this.Controls.Add(this.buttonRefresh);
this.Controls.Add(this.buttonAdd); this.Controls.Add(this.buttonAdd);
this.Controls.Add(this.dataGridView); this.Controls.Add(this.dataGridView);
this.Name = "FormJewels"; this.Name = "FormJewels";
@ -111,7 +110,7 @@
private DataGridView dataGridView; private DataGridView dataGridView;
private Button buttonUpdate; private Button buttonUpdate;
private Button buttonDelete; private Button buttonDelete;
private Button buttonRef; private Button buttonRefresh;
private Button buttonAdd; private Button buttonAdd;
} }
} }

View File

@ -4,7 +4,7 @@ using Microsoft.Extensions.Logging;
namespace JewelryStore namespace JewelryStore
{ {
public partial class FormJewels : Form //TODO public partial class FormJewels : Form
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IJewelLogic _logic; private readonly IJewelLogic _logic;
@ -25,16 +25,14 @@ namespace JewelryStore
{ {
dataGridView.DataSource = list; dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false; dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["JewelName"].AutoSizeMode = dataGridView.Columns["JewelName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
DataGridViewAutoSizeColumnMode.Fill;
} }
_logger.LogInformation("Загрузка изделий"); _logger.LogInformation("Загрузка изделий");
} }
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);
} }
} }
@ -50,16 +48,14 @@ namespace JewelryStore
} }
} }
private void ButtonChange_Click(object sender, EventArgs e) private void ButtonRefresh_Click(object sender, EventArgs e)
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
var service = var service = Program.ServiceProvider?.GetService(typeof(FormJewel));
Program.ServiceProvider?.GetService(typeof(FormJewel));
if (service is FormJewel form) if (service is FormJewel form)
{ {
form.Id = form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
LoadData(); LoadData();
@ -72,11 +68,9 @@ namespace JewelryStore
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
if (MessageBox.Show("Удалить запись?", "Вопрос", if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
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
{ {
@ -92,8 +86,7 @@ namespace JewelryStore
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка удаления изделия"); _logger.LogError(ex, "Ошибка удаления изделия");
MessageBox.Show(ex.Message, "Ошибка", MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
} }
} }
@ -108,10 +101,5 @@ namespace JewelryStore
{ {
LoadData(); LoadData();
} }
private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
} }
} }

View File

@ -33,10 +33,10 @@
this.КомпонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.КомпонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ИзделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ИзделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.dataGridView = new System.Windows.Forms.DataGridView(); this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonCreate = new System.Windows.Forms.Button(); this.buttonCreateOrder = new System.Windows.Forms.Button();
this.buttonToWork = new System.Windows.Forms.Button(); this.buttonTakeOrderInWork = new System.Windows.Forms.Button();
this.buttonReady = new System.Windows.Forms.Button(); this.buttonOrderReady = new System.Windows.Forms.Button();
this.buttonPut = new System.Windows.Forms.Button(); this.buttonIssuedOrder = new System.Windows.Forms.Button();
this.buttonRefresh = new System.Windows.Forms.Button(); this.buttonRefresh = new System.Windows.Forms.Button();
this.menuStrip.SuspendLayout(); this.menuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
@ -87,45 +87,45 @@
this.dataGridView.Size = new System.Drawing.Size(851, 402); this.dataGridView.Size = new System.Drawing.Size(851, 402);
this.dataGridView.TabIndex = 1; this.dataGridView.TabIndex = 1;
// //
// buttonCreate // buttonCreateOrder
// //
this.buttonCreate.Location = new System.Drawing.Point(884, 78); this.buttonCreateOrder.Location = new System.Drawing.Point(884, 78);
this.buttonCreate.Name = "buttonCreate"; this.buttonCreateOrder.Name = "buttonCreateOrder";
this.buttonCreate.Size = new System.Drawing.Size(210, 34); this.buttonCreateOrder.Size = new System.Drawing.Size(210, 34);
this.buttonCreate.TabIndex = 2; this.buttonCreateOrder.TabIndex = 2;
this.buttonCreate.Text = "Создать заказ"; this.buttonCreateOrder.Text = "Создать заказ";
this.buttonCreate.UseVisualStyleBackColor = true; this.buttonCreateOrder.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.ButtonCreateOrder_Click); this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click);
// //
// buttonToWork // buttonTakeOrderInWork
// //
this.buttonToWork.Location = new System.Drawing.Point(884, 150); this.buttonTakeOrderInWork.Location = new System.Drawing.Point(884, 150);
this.buttonToWork.Name = "buttonToWork"; this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
this.buttonToWork.Size = new System.Drawing.Size(210, 34); this.buttonTakeOrderInWork.Size = new System.Drawing.Size(210, 34);
this.buttonToWork.TabIndex = 3; this.buttonTakeOrderInWork.TabIndex = 3;
this.buttonToWork.Text = "Отдать на выполнение"; this.buttonTakeOrderInWork.Text = "Отдать на выполнение";
this.buttonToWork.UseVisualStyleBackColor = true; this.buttonTakeOrderInWork.UseVisualStyleBackColor = true;
this.buttonToWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click);
// //
// buttonReady // buttonOrderReady
// //
this.buttonReady.Location = new System.Drawing.Point(884, 221); this.buttonOrderReady.Location = new System.Drawing.Point(884, 221);
this.buttonReady.Name = "buttonReady"; this.buttonOrderReady.Name = "buttonOrderReady";
this.buttonReady.Size = new System.Drawing.Size(210, 34); this.buttonOrderReady.Size = new System.Drawing.Size(210, 34);
this.buttonReady.TabIndex = 4; this.buttonOrderReady.TabIndex = 4;
this.buttonReady.Text = "Заказ готов"; this.buttonOrderReady.Text = "Заказ готов";
this.buttonReady.UseVisualStyleBackColor = true; this.buttonOrderReady.UseVisualStyleBackColor = true;
this.buttonReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click);
// //
// buttonPut // buttonIssuedOrder
// //
this.buttonPut.Location = new System.Drawing.Point(884, 292); this.buttonIssuedOrder.Location = new System.Drawing.Point(884, 292);
this.buttonPut.Name = "buttonPut"; this.buttonIssuedOrder.Name = "buttonIssuedOrder";
this.buttonPut.Size = new System.Drawing.Size(210, 34); this.buttonIssuedOrder.Size = new System.Drawing.Size(210, 34);
this.buttonPut.TabIndex = 5; this.buttonIssuedOrder.TabIndex = 5;
this.buttonPut.Text = "Заказ выдан"; this.buttonIssuedOrder.Text = "Заказ выдан";
this.buttonPut.UseVisualStyleBackColor = true; this.buttonIssuedOrder.UseVisualStyleBackColor = true;
this.buttonPut.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click);
// //
// buttonRefresh // buttonRefresh
// //
@ -135,7 +135,7 @@
this.buttonRefresh.TabIndex = 6; this.buttonRefresh.TabIndex = 6;
this.buttonRefresh.Text = "Обновить список"; this.buttonRefresh.Text = "Обновить список";
this.buttonRefresh.UseVisualStyleBackColor = true; this.buttonRefresh.UseVisualStyleBackColor = true;
this.buttonRefresh.Click += new System.EventHandler(this.ButtonRef_Click); this.buttonRefresh.Click += new System.EventHandler(this.ButtonRefresh_Click);
// //
// FormMain // FormMain
// //
@ -143,10 +143,10 @@
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1121, 450); this.ClientSize = new System.Drawing.Size(1121, 450);
this.Controls.Add(this.buttonRefresh); this.Controls.Add(this.buttonRefresh);
this.Controls.Add(this.buttonPut); this.Controls.Add(this.buttonIssuedOrder);
this.Controls.Add(this.buttonReady); this.Controls.Add(this.buttonOrderReady);
this.Controls.Add(this.buttonToWork); this.Controls.Add(this.buttonTakeOrderInWork);
this.Controls.Add(this.buttonCreate); this.Controls.Add(this.buttonCreateOrder);
this.Controls.Add(this.dataGridView); this.Controls.Add(this.dataGridView);
this.Controls.Add(this.menuStrip); this.Controls.Add(this.menuStrip);
this.MainMenuStrip = this.menuStrip; this.MainMenuStrip = this.menuStrip;
@ -167,10 +167,10 @@
private ToolStripMenuItem КомпонентыToolStripMenuItem; private ToolStripMenuItem КомпонентыToolStripMenuItem;
private ToolStripMenuItem ИзделияToolStripMenuItem; private ToolStripMenuItem ИзделияToolStripMenuItem;
private DataGridView dataGridView; private DataGridView dataGridView;
private Button buttonCreate; private Button buttonCreateOrder;
private Button buttonToWork; private Button buttonTakeOrderInWork;
private Button buttonReady; private Button buttonOrderReady;
private Button buttonPut; private Button buttonIssuedOrder;
private Button buttonRefresh; private Button buttonRefresh;
} }
} }

View File

@ -10,16 +10,19 @@ namespace JewelryStore
{ {
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()
{ {
try try
@ -35,14 +38,13 @@ namespace JewelryStore
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);
} }
} }
private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e) private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
Program.ServiceProvider?.GetService(typeof(FormComponents));
if (service is FormComponents form) if (service is FormComponents form)
{ {
form.ShowDialog(); form.ShowDialog();
@ -51,8 +53,7 @@ namespace JewelryStore
private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e) private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = var service = Program.ServiceProvider?.GetService(typeof(FormJewels));
Program.ServiceProvider?.GetService(typeof(FormJewels));
if (service is FormJewels form) if (service is FormJewels form)
{ {
form.ShowDialog(); form.ShowDialog();
@ -68,6 +69,7 @@ namespace JewelryStore
LoadData(); LoadData();
} }
} }
private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) private void ButtonTakeOrderInWork_Click(object sender, EventArgs e)
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
@ -96,8 +98,7 @@ namespace JewelryStore
if (dataGridView.SelectedRows.Count == 1) 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}. Меняется статус на 'Готов'", _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id);
id);
try try
{ {
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id });
@ -121,8 +122,7 @@ namespace JewelryStore
if (dataGridView.SelectedRows.Count == 1) 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}. Меняется статус на 'Выдан'", _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id);
id);
try try
{ {
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id });
@ -141,7 +141,7 @@ namespace JewelryStore
} }
} }
} }
private void ButtonRef_Click(object sender, EventArgs e) private void ButtonRefresh_Click(object sender, EventArgs e)
{ {
LoadData(); LoadData();
} }

View File

@ -8,6 +8,10 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<None Remove="C:\Users\Black\.nuget\packages\nlog.config\4.7.15\contentFiles\any\any\NLog.config" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" /> <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true" internalLogLevel="Info">
<targets>
<target xsi:type="File" name="tofile" fileName="log-${shortdate}.log" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="tofile" />
</rules>
</nlog>
</configuration>

View File

@ -7,7 +7,7 @@ using Microsoft.Extensions.Logging;
namespace JewelryStoreBusinessLogic.BusinessLogics namespace JewelryStoreBusinessLogic.BusinessLogics
{ {
public class JewelLogic : IJewelLogic // TODO реализовать интерфейс идентично componentLogic public class JewelLogic : IJewelLogic
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IJewelStorage _jewelStorage; private readonly IJewelStorage _jewelStorage;
@ -69,6 +69,7 @@ namespace JewelryStoreBusinessLogic.BusinessLogics
} }
return true; return true;
} }
public bool Delete(JewelBindingModel model) public bool Delete(JewelBindingModel model)
{ {
CheckModel(model, false); CheckModel(model, false);

View File

@ -8,7 +8,7 @@ using Microsoft.Extensions.Logging;
namespace JewelryStoreBusinessLogic.BusinessLogics namespace JewelryStoreBusinessLogic.BusinessLogics
{ {
public class OrderLogic : IOrderLogic //TODO реализовать интерфейс public class OrderLogic : IOrderLogic
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage; private readonly IOrderStorage _orderStorage;

View File

@ -8,12 +8,14 @@ namespace JewelryStoreListImplement
public List<Component> Components { get; set; } public List<Component> Components { get; set; }
public List<Order> Orders { get; set; } public List<Order> Orders { get; set; }
public List<Jewel> Jewels { get; set; } public List<Jewel> Jewels { get; set; }
private DataListSingleton() private DataListSingleton()
{ {
Components = new List<Component>(); Components = new List<Component>();
Orders = new List<Order>(); Orders = new List<Order>();
Jewels = new List<Jewel>(); Jewels = new List<Jewel>();
} }
public static DataListSingleton GetInstance() public static DataListSingleton GetInstance()
{ {
if (_instance == null) if (_instance == null)

View File

@ -14,6 +14,7 @@ namespace JewelryStoreListImplement.Implements
{ {
_source = DataListSingleton.GetInstance(); _source = DataListSingleton.GetInstance();
} }
public List<ComponentViewModel> GetFullList() public List<ComponentViewModel> GetFullList()
{ {
var result = new List<ComponentViewModel>(); var result = new List<ComponentViewModel>();
@ -23,6 +24,7 @@ namespace JewelryStoreListImplement.Implements
} }
return result; return result;
} }
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model) public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
{ {
var result = new List<ComponentViewModel>(); var result = new List<ComponentViewModel>();
@ -39,6 +41,7 @@ namespace JewelryStoreListImplement.Implements
} }
return result; return result;
} }
public ComponentViewModel? GetElement(ComponentSearchModel model) public ComponentViewModel? GetElement(ComponentSearchModel model)
{ {
if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
@ -56,6 +59,7 @@ namespace JewelryStoreListImplement.Implements
} }
return null; return null;
} }
public ComponentViewModel? Insert(ComponentBindingModel model) public ComponentViewModel? Insert(ComponentBindingModel model)
{ {
model.Id = 1; model.Id = 1;
@ -74,6 +78,7 @@ namespace JewelryStoreListImplement.Implements
_source.Components.Add(newComponent); _source.Components.Add(newComponent);
return newComponent.GetViewModel; return newComponent.GetViewModel;
} }
public ComponentViewModel? Update(ComponentBindingModel model) public ComponentViewModel? Update(ComponentBindingModel model)
{ {
foreach (var component in _source.Components) foreach (var component in _source.Components)
@ -86,6 +91,7 @@ namespace JewelryStoreListImplement.Implements
} }
return null; return null;
} }
public ComponentViewModel? Delete(ComponentBindingModel model) public ComponentViewModel? Delete(ComponentBindingModel model)
{ {
for (int i = 0; i < _source.Components.Count; ++i) for (int i = 0; i < _source.Components.Count; ++i)

View File

@ -6,7 +6,7 @@ using JewelryStoreListImplement.Models;
namespace JewelryStoreListImplement.Implements namespace JewelryStoreListImplement.Implements
{ {
public class JewelStorage : IJewelStorage // TODO реализовать интерфейс public class JewelStorage : IJewelStorage
{ {
private readonly DataListSingleton _source; private readonly DataListSingleton _source;
@ -14,6 +14,7 @@ namespace JewelryStoreListImplement.Implements
{ {
_source = DataListSingleton.GetInstance(); _source = DataListSingleton.GetInstance();
} }
public List<JewelViewModel> GetFullList() public List<JewelViewModel> GetFullList()
{ {
var result = new List<JewelViewModel>(); var result = new List<JewelViewModel>();

View File

@ -6,7 +6,7 @@ using JewelryStoreListImplement.Models;
namespace JewelryStoreListImplement.Implements namespace JewelryStoreListImplement.Implements
{ {
public class OrderStorage : IOrderStorage // TODO реализовать интерфейс public class OrderStorage : IOrderStorage
{ {
private readonly DataListSingleton _source; private readonly DataListSingleton _source;
@ -14,6 +14,7 @@ namespace JewelryStoreListImplement.Implements
{ {
_source = DataListSingleton.GetInstance(); _source = DataListSingleton.GetInstance();
} }
public List<OrderViewModel> GetFullList() public List<OrderViewModel> GetFullList()
{ {
var result = new List<OrderViewModel>(); var result = new List<OrderViewModel>();

View File

@ -23,6 +23,7 @@ namespace JewelryStoreListImplement.Models
Cost = model.Cost Cost = model.Cost
}; };
} }
public void Update(ComponentBindingModel? model) public void Update(ComponentBindingModel? model)
{ {
if (model == null) if (model == null)
@ -32,6 +33,7 @@ namespace JewelryStoreListImplement.Models
ComponentName = model.ComponentName; ComponentName = model.ComponentName;
Cost = model.Cost; Cost = model.Cost;
} }
public ComponentViewModel GetViewModel => new() public ComponentViewModel GetViewModel => new()
{ {
Id = Id, Id = Id,

View File

@ -29,6 +29,7 @@ namespace JewelryStoreListImplement.Models
JewelComponents = model.JewelComponents JewelComponents = model.JewelComponents
}; };
} }
public void Update(JewelBindingModel? model) public void Update(JewelBindingModel? model)
{ {
if (model == null) if (model == null)
@ -39,6 +40,7 @@ namespace JewelryStoreListImplement.Models
Price = model.Price; Price = model.Price;
JewelComponents = model.JewelComponents; JewelComponents = model.JewelComponents;
} }
public JewelViewModel GetViewModel => new() public JewelViewModel GetViewModel => new()
{ {
Id = Id, Id = Id,

View File

@ -5,20 +5,14 @@ using JewelryStoreDataModels.Models;
namespace JewelryStoreListImplement.Models namespace JewelryStoreListImplement.Models
{ {
public class Order : IOrderModel // TODO Класс для модели сущности «Заказ» разработать самостоятельно public class Order : IOrderModel
{ {
public int Id { get; private set; } public int Id { get; private set; }
public int JewelId { get; private set; } public int JewelId { get; private set; }
public int Count { get; private set; } public int Count { get; private set; }
public double Sum { get; private set; } public double Sum { get; private set; }
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
public DateTime DateCreate { get; private set; } = DateTime.Now; public DateTime DateCreate { get; private set; } = DateTime.Now;
public DateTime? DateImplement { get; private set; } public DateTime? DateImplement { get; private set; }
public static Order? Create(OrderBindingModel? model) public static Order? Create(OrderBindingModel? model)
@ -38,6 +32,7 @@ namespace JewelryStoreListImplement.Models
DateImplement = model.DateImplement DateImplement = model.DateImplement
}; };
} }
public void Update(OrderBindingModel? model) public void Update(OrderBindingModel? model)
{ {
if (model == null) if (model == null)
@ -50,6 +45,7 @@ namespace JewelryStoreListImplement.Models
DateImplement = model.DateImplement; DateImplement = model.DateImplement;
} }
} }
public OrderViewModel GetViewModel => new() public OrderViewModel GetViewModel => new()
{ {
Id = Id, Id = Id,