Почти все ошибки решены

This commit is contained in:
DyCTaTOR 2024-05-21 21:56:44 +04:00
parent 9f89c83852
commit 112833ae68
14 changed files with 324 additions and 510 deletions

View File

@ -1,10 +1,11 @@
using System; using PlumbingRepairContracts.Attributes;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace PlumbingRepairContracts.Attributes namespace PlumbingRepairContracts
{ {
public static class DataGridViewExtension public static class DataGridViewExtension
{ {
@ -14,33 +15,37 @@ namespace PlumbingRepairContracts.Attributes
{ {
return; return;
} }
grid.DataSource = data; grid.DataSource = data;
var type = typeof(T); var type = typeof(T);
var properties = type.GetProperties(); var properties = type.GetProperties();
foreach (DataGridViewColumn column in grid.Columns) foreach (DataGridViewColumn column in grid.Columns)
{ {
var property = properties.FirstOrDefault(x => x.Name == var property = properties.FirstOrDefault(x => x.Name == column.Name);
column.Name);
if (property == null) if (property == null)
{ {
throw new InvalidOperationException($"В типе {type.Name} не найдено свойство с именем { column.Name }"); throw new InvalidOperationException($"В типе {type.Name} не найдено свойство с именем {column.Name}");
} }
var attribute =
property.GetCustomAttributes(typeof(ColumnAttribute), true)?.SingleOrDefault(); var attribute = property.GetCustomAttributes(typeof(ColumnAttribute), true)?.SingleOrDefault();
if (attribute == null) if (attribute == null)
{ {
throw new InvalidOperationException($"Не найден атрибут типа ColumnAttribute для свойства { property.Name }"); throw new InvalidOperationException($"Не найден атрибут типа ColumnAttribute для свойства {property.Name}");
} }
// ищем нужный нам атрибут // ищем нужный нам атрибут
if (attribute is ColumnAttribute columnAttr) if (attribute is ColumnAttribute columnAttr)
{ {
column.HeaderText = columnAttr.Title; column.HeaderText = columnAttr.Title;
column.Visible = columnAttr.Visible; column.Visible = columnAttr.Visible;
if (columnAttr.IsUseAutoSize) if (columnAttr.IsUseAutoSize)
{ {
column.AutoSizeMode = column.AutoSizeMode = (DataGridViewAutoSizeColumnMode)Enum.Parse(typeof(DataGridViewAutoSizeColumnMode), columnAttr.GridViewAutoSize.ToString());
(DataGridViewAutoSizeColumnMode)Enum.Parse(typeof(DataGridViewAutoSizeColumnMode)
, columnAttr.GridViewAutoSize.ToString());
} }
else else
{ {
@ -49,6 +54,5 @@ namespace PlumbingRepairContracts.Attributes
} }
} }
} }
} }
} }

View File

@ -1,9 +1,6 @@
using PlumbingRepairContracts.BindingModels; using PlumbingRepairContracts.BindingModels;
using PlumbingRepairContracts.BusinessLogicsContracts; using PlumbingRepairContracts.BusinessLogicsContracts;
using PlumbingRepairContracts.SearchModels;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System.Windows.Forms;
using PlumbingRepairContracts.Attributes;
namespace PlumbingRepairView namespace PlumbingRepairView
{ {

View File

@ -1,7 +1,7 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using PlumbingRepairContracts.BusinessLogicsContracts; using PlumbingRepairContracts.BusinessLogicsContracts;
using PlumbingRepairContracts.BindingModels; using PlumbingRepairContracts.BindingModels;
using PlumbingRepairContracts.DI; using PlumbingRepairContracts.SearchModels;
using System.Windows.Forms; using System.Windows.Forms;
namespace PlumbingRepairView namespace PlumbingRepairView
@ -18,79 +18,70 @@ namespace PlumbingRepairView
_logger = logger; _logger = logger;
_logic = logic; _logic = logic;
} }
private void FormComponents_Load(object sender, EventArgs e) private void FormComponent_Load(object sender, EventArgs e)
{ {
LoadData(); if (_id.HasValue)
{
try
{
_logger.LogInformation("Ïîëó÷åíèå êîìïîíåíòà");
var view = _logic.ReadElement(new ComponentSearchModel
{
Id = _id.Value
});
if (view != null)
{
textBoxName.Text = view.ComponentName;
textBoxCost.Text = view.Cost.ToString();
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Îøèáêà ïîëó÷åíèÿ êîìïîíåíòà");
MessageBox.Show(ex.Message, "Îøèáêà", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
} }
private void ButtonSave_Click(object sender, EventArgs e)
private void LoadData()
{ {
if (string.IsNullOrEmpty(textBoxName.Text))
{
MessageBox.Show("Çàïîëíèòå íàçâàíèå", "Îøèáêà",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Ñîõðàíåíèå êîìïîíåíòà");
try try
{ {
DataGridView.FillandConfigGrid(_logic.ReadList(null)); var model = new ComponentBindingModel
_logger.LogInformation("Çàãðóçêà êîìïîíåíòîâ"); {
Id = _id ?? 0,
ComponentName = textBoxName.Text,
Cost = Convert.ToDouble(textBoxCost.Text)
};
var operationResult = _id.HasValue ? _logic.Update(model) :
_logic.Create(model);
if (!operationResult)
{
throw new Exception("Îøèáêà ïðè ñîõðàíåíèè. Äîïîëíèòåëüíàÿ èíôîðìàöèÿ â ëîãàõ.");
}
MessageBox.Show("Ñîõðàíåíèå ïðîøëî óñïåøíî", "Ñîîáùåíèå",
MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
} }
catch (Exception ex) 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 AddButton_Click(object sender, EventArgs e) private void ButtonCancel_Click(object sender, EventArgs e)
{ {
var form = DependencyManager.Instance.Resolve<FormComponent>(); DialogResult = DialogResult.Cancel;
Close();
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
private void ChangeButton_Click(object sender, EventArgs e)
{
if (DataGridView.SelectedRows.Count == 1)
{
var form = DependencyManager.Instance.Resolve<FormComponent>();
form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void DeleteButton_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 ComponentBindingModel
{
Id = id
}))
{
throw new Exception("Îøèáêà ïðè óäàëåíèè. Äîïîëíèòåëüíàÿ èíôîðìàöèÿ â ëîãàõ.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Îøèáêà óäàëåíèÿ êîìïîíåíòà");
MessageBox.Show(ex.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void UpdateButton_Click(object sender, EventArgs e)
{
LoadData();
} }
} }
} }

View File

@ -28,24 +28,24 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
dataGridView = new DataGridView(); DataGridView = new DataGridView();
buttonAdd = new Button(); buttonAdd = new Button();
buttonDel = new Button(); buttonDel = new Button();
buttonChange = new Button(); buttonChange = new Button();
buttonRef = new Button(); buttonRef = new Button();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); ((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit();
SuspendLayout(); SuspendLayout();
// //
// dataGridView // dataGridView
// //
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(10, 8); DataGridView.Location = new Point(10, 8);
dataGridView.Margin = new Padding(2); DataGridView.Margin = new Padding(2);
dataGridView.Name = "dataGridView"; DataGridView.Name = "dataGridView";
dataGridView.RowHeadersWidth = 62; DataGridView.RowHeadersWidth = 62;
dataGridView.RowTemplate.Height = 33; DataGridView.RowTemplate.Height = 33;
dataGridView.Size = new Size(512, 404); DataGridView.Size = new Size(512, 404);
dataGridView.TabIndex = 0; DataGridView.TabIndex = 0;
// //
// buttonAdd // buttonAdd
// //
@ -100,18 +100,18 @@
Controls.Add(buttonChange); Controls.Add(buttonChange);
Controls.Add(buttonDel); Controls.Add(buttonDel);
Controls.Add(buttonAdd); Controls.Add(buttonAdd);
Controls.Add(dataGridView); Controls.Add(DataGridView);
Margin = new Padding(2); Margin = new Padding(2);
Name = "FormComponents"; Name = "FormComponents";
Text = "Компоненты"; Text = "Компоненты";
Load += FormComponents_Load; Load += FormComponents_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ((System.ComponentModel.ISupportInitialize)DataGridView).EndInit();
ResumeLayout(false); ResumeLayout(false);
} }
#endregion #endregion
private DataGridView dataGridView; private DataGridView DataGridView;
private Button buttonAdd; private Button buttonAdd;
private Button buttonDel; private Button buttonDel;
private Button buttonChange; private Button buttonChange;

View File

@ -1,6 +1,8 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using PlumbingRepairContracts.Attributes;
using PlumbingRepairContracts.BindingModels; using PlumbingRepairContracts.BindingModels;
using PlumbingRepairContracts.BusinessLogicsContracts; using PlumbingRepairContracts.BusinessLogicsContracts;
using PlumbingRepairContracts.DI;
namespace PlumbingRepairView namespace PlumbingRepairView
{ {
@ -22,14 +24,7 @@ namespace PlumbingRepairView
{ {
try try
{ {
var list = _logic.ReadList(null); DataGridView.FillandConfigGrid(_logic.ReadList(null));
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["ComponentName"].AutoSizeMode =
DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка компонентов"); _logger.LogInformation("Загрузка компонентов");
} }
catch (Exception ex) catch (Exception ex)
@ -41,38 +36,32 @@ namespace PlumbingRepairView
} }
private void ButtonAdd_Click(object sender, EventArgs e) private void ButtonAdd_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); var form = DependencyManager.Instance.Resolve<FormComponent>();
if (service is FormComponent form) if (form.ShowDialog() == DialogResult.OK)
{ {
LoadData();
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (DataGridView.SelectedRows.Count == 1)
{
var form = DependencyManager.Instance.Resolve<FormComponent>();
form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
LoadData(); LoadData();
} }
} }
} }
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormComponent));
if (service is FormComponent 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) private void ButtonDel_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)
{ {
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Удаление компонента"); _logger.LogInformation("Удаление компонента");
try try
{ {

View File

@ -29,83 +29,79 @@ namespace PlumbingRepair
_logic = logic; _logic = logic;
} }
private void AddButton_Click(object sender, EventArgs e) private void ButtonSave_Click(object sender, EventArgs e)
{ {
var form = DependencyManager.Instance.Resolve<FormImplementer>(); if (string.IsNullOrEmpty(PasswordTextBox.Text))
if (form.ShowDialog() == DialogResult.OK)
{ {
LoadData(); MessageBox.Show("Заполните пароль", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
} }
} if (string.IsNullOrEmpty(FIOTextBox.Text))
private void ChangeButton_Click(object sender, EventArgs e)
{
if (DataGridView.SelectedRows.Count == 1)
{ {
var form = DependencyManager.Instance.Resolve<FormImplementer>(); MessageBox.Show("Заполните фио", "Ошибка",
form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); MessageBoxButtons.OK, MessageBoxIcon.Error);
if (form.ShowDialog() == DialogResult.OK) return;
{
LoadData();
}
} }
} _logger.LogInformation("Сохранение исполнителя");
private void DeleteButton_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 ImplementerBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления исполнителя");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void UpdateButton_Click(object sender, EventArgs e)
{
LoadData();
}
private void FormImplementers_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try try
{ {
DataGridView.FillandConfigGrid(_logic.ReadList(null)); var model = new ImplementerBindingModel
{
_logger.LogInformation("Загрузка исполнителей"); Id = _id ?? 0,
ImplementerFIO = FIOTextBox.Text,
Password = PasswordTextBox.Text,
Qualification = (int)QualificationNumericUpDown.Value,
WorkExperience = (int)WorkExpNumericUpDown.Value,
};
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение",
MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
} }
catch (Exception ex) 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)
{
DialogResult = DialogResult.Cancel;
Close();
}
private void FormImplementer_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
try
{
_logger.LogInformation("Получение исполнителя");
var view = _logic.ReadElement(new ImplementerSearchModel
{
Id = _id.Value
});
if (view != null)
{
FIOTextBox.Text = view.ImplementerFIO;
PasswordTextBox.Text = view.Password;
QualificationNumericUpDown.Value = view.Qualification;
WorkExpNumericUpDown.Value = view.WorkExperience;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения исполнителя");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
} }
} }

View File

@ -1,6 +1,7 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using PlumbingRepairContracts.BindingModels; using PlumbingRepairContracts.BindingModels;
using PlumbingRepairContracts.BusinessLogicsContracts; using PlumbingRepairContracts.BusinessLogicsContracts;
using PlumbingRepairContracts.DI;
using PlumbingRepairView; using PlumbingRepairView;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -27,14 +28,10 @@ namespace PlumbingRepair
private void AddButton_Click(object sender, EventArgs e) private void AddButton_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); var form = DependencyManager.Instance.Resolve<FormImplementer>();
if (form.ShowDialog() == DialogResult.OK)
if (service is FormImplementer form)
{ {
if (form.ShowDialog() == DialogResult.OK) LoadData();
{
LoadData();
}
} }
} }
@ -42,14 +39,11 @@ namespace PlumbingRepair
{ {
if (DataGridView.SelectedRows.Count == 1) if (DataGridView.SelectedRows.Count == 1)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); var form = DependencyManager.Instance.Resolve<FormImplementer>();
if (service is FormImplementer form) form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{ {
form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); LoadData();
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
} }
} }
} }

View File

@ -1,4 +1,5 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using PlumbingRepairContracts.Attributes;
using PlumbingRepairContracts.BusinessLogicsContracts; using PlumbingRepairContracts.BusinessLogicsContracts;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -29,14 +30,7 @@ namespace PlumbingRepairView
{ {
try try
{ {
var list = _logic.ReadList(null); DataGridView.FillandConfigGrid(_logic.ReadList(null));
if (list != null)
{
DataGridView.DataSource = list;
DataGridView.Columns["ClientId"].Visible = false;
DataGridView.Columns["MessageId"].Visible = false;
DataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка писем"); _logger.LogInformation("Загрузка писем");
} }
catch (Exception ex) catch (Exception ex)

View File

@ -40,20 +40,19 @@
исполнителиToolStripMenuItem = new ToolStripMenuItem(); исполнителиToolStripMenuItem = new ToolStripMenuItem();
запускРаботToolStripMenuItem = new ToolStripMenuItem(); запускРаботToolStripMenuItem = new ToolStripMenuItem();
письмаToolStripMenuItem = new ToolStripMenuItem(); письмаToolStripMenuItem = new ToolStripMenuItem();
dataGridView = new DataGridView(); создатьБэкапToolStripMenuItem = new ToolStripMenuItem();
DataGridView = new DataGridView();
buttonCreateOrder = new Button(); buttonCreateOrder = new Button();
buttonTakeOrderInWork = new Button();
buttonOrderReady = new Button();
buttonIssuedOrder = new Button(); buttonIssuedOrder = new Button();
buttonUpdateList = new Button(); buttonUpdateList = new Button();
menuStrip1.SuspendLayout(); menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); ((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit();
SuspendLayout(); SuspendLayout();
// //
// menuStrip1 // menuStrip1
// //
menuStrip1.ImageScalingSize = new Size(20, 20); menuStrip1.ImageScalingSize = new Size(20, 20);
menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчётыToolStripMenuItem, запускРаботToolStripMenuItem, письмаToolStripMenuItem }); menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчётыToolStripMenuItem, запускРаботToolStripMenuItem, письмаToolStripMenuItem, создатьБэкапToolStripMenuItem });
menuStrip1.Location = new Point(0, 0); menuStrip1.Location = new Point(0, 0);
menuStrip1.Name = "menuStrip1"; menuStrip1.Name = "menuStrip1";
menuStrip1.Padding = new Padding(8, 2, 0, 2); menuStrip1.Padding = new Padding(8, 2, 0, 2);
@ -133,14 +132,14 @@
// //
// dataGridView // dataGridView
// //
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(0, 39); DataGridView.Location = new Point(0, 39);
dataGridView.Margin = new Padding(4); DataGridView.Margin = new Padding(4);
dataGridView.Name = "dataGridView"; DataGridView.Name = "dataGridView";
dataGridView.RowHeadersWidth = 51; DataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 29; DataGridView.RowTemplate.Height = 29;
dataGridView.Size = new Size(1098, 525); DataGridView.Size = new Size(1098, 525);
dataGridView.TabIndex = 1; DataGridView.TabIndex = 1;
// //
// buttonCreateOrder // buttonCreateOrder
// //
@ -153,28 +152,6 @@
buttonCreateOrder.UseVisualStyleBackColor = true; buttonCreateOrder.UseVisualStyleBackColor = true;
buttonCreateOrder.Click += buttonCreateOrder_Click; buttonCreateOrder.Click += buttonCreateOrder_Click;
// //
// buttonTakeOrderInWork
//
buttonTakeOrderInWork.Location = new Point(1129, 178);
buttonTakeOrderInWork.Margin = new Padding(4);
buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
buttonTakeOrderInWork.Size = new Size(212, 62);
buttonTakeOrderInWork.TabIndex = 3;
buttonTakeOrderInWork.Text = "Отдать на выполнение";
buttonTakeOrderInWork.UseVisualStyleBackColor = true;
buttonTakeOrderInWork.Click += buttonTakeOrderInWork_Click;
//
// buttonOrderReady
//
buttonOrderReady.Location = new Point(1129, 291);
buttonOrderReady.Margin = new Padding(4);
buttonOrderReady.Name = "buttonOrderReady";
buttonOrderReady.Size = new Size(212, 36);
buttonOrderReady.TabIndex = 4;
buttonOrderReady.Text = "Заказ готов";
buttonOrderReady.UseVisualStyleBackColor = true;
buttonOrderReady.Click += buttonOrderReady_Click;
//
// buttonIssuedOrder // buttonIssuedOrder
// //
buttonIssuedOrder.Location = new Point(1129, 404); buttonIssuedOrder.Location = new Point(1129, 404);
@ -204,6 +181,13 @@
письмаToolStripMenuItem.Text = "Письма"; письмаToolStripMenuItem.Text = "Письма";
письмаToolStripMenuItem.Click += письмаToolStripMenuItem_Click; письмаToolStripMenuItem.Click += письмаToolStripMenuItem_Click;
// //
// создатьБэкапToolStripMenuItem
//
создатьБэкапToolStripMenuItem.Name = "создатьБэкапToolStripMenuItem";
создатьБэкапToolStripMenuItem.Size = new Size(122, 24);
создатьБэкапToolStripMenuItem.Text = "Создать бэкап";
создатьБэкапToolStripMenuItem.Click += создатьБэкапToolStripMenuItem_Click;
//
// FormMain // FormMain
// //
AutoScaleDimensions = new SizeF(10F, 25F); AutoScaleDimensions = new SizeF(10F, 25F);
@ -211,10 +195,8 @@
ClientSize = new Size(1379, 592); ClientSize = new Size(1379, 592);
Controls.Add(buttonUpdateList); Controls.Add(buttonUpdateList);
Controls.Add(buttonIssuedOrder); Controls.Add(buttonIssuedOrder);
Controls.Add(buttonOrderReady);
Controls.Add(buttonTakeOrderInWork);
Controls.Add(buttonCreateOrder); Controls.Add(buttonCreateOrder);
Controls.Add(dataGridView); Controls.Add(DataGridView);
Controls.Add(menuStrip1); Controls.Add(menuStrip1);
MainMenuStrip = menuStrip1; MainMenuStrip = menuStrip1;
Margin = new Padding(4); Margin = new Padding(4);
@ -223,7 +205,7 @@
Load += FormMain_Load; Load += FormMain_Load;
menuStrip1.ResumeLayout(false); menuStrip1.ResumeLayout(false);
menuStrip1.PerformLayout(); menuStrip1.PerformLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ((System.ComponentModel.ISupportInitialize)DataGridView).EndInit();
ResumeLayout(false); ResumeLayout(false);
PerformLayout(); PerformLayout();
} }
@ -232,10 +214,8 @@
private MenuStrip menuStrip1; private MenuStrip menuStrip1;
private ToolStripMenuItem справочникиToolStripMenuItem; private ToolStripMenuItem справочникиToolStripMenuItem;
private DataGridView dataGridView; private DataGridView DataGridView;
private Button buttonCreateOrder; private Button buttonCreateOrder;
private Button buttonTakeOrderInWork;
private Button buttonOrderReady;
private Button buttonIssuedOrder; private Button buttonIssuedOrder;
private Button buttonUpdateList; private Button buttonUpdateList;
private ToolStripMenuItem компонентыToolStripMenuItem; private ToolStripMenuItem компонентыToolStripMenuItem;
@ -248,5 +228,6 @@
private ToolStripMenuItem запускРаботToolStripMenuItem; private ToolStripMenuItem запускРаботToolStripMenuItem;
private ToolStripMenuItem КлиентыToolStripMenuItem; private ToolStripMenuItem КлиентыToolStripMenuItem;
private ToolStripMenuItem письмаToolStripMenuItem; private ToolStripMenuItem письмаToolStripMenuItem;
private ToolStripMenuItem создатьБэкапToolStripMenuItem;
} }
} }

View File

@ -1,18 +1,8 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using PlumbingRepair; using PlumbingRepair;
using PlumbingRepairBusinessLogic.BusinessLogics;
using PlumbingRepairContracts.BindingModels; using PlumbingRepairContracts.BindingModels;
using PlumbingRepairContracts.BusinessLogicsContracts; using PlumbingRepairContracts.BusinessLogicsContracts;
using PlumbingRepairDataModels.Enums; using PlumbingRepairContracts.DI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PlumbingRepairView namespace PlumbingRepairView
{ {
@ -22,14 +12,15 @@ namespace PlumbingRepairView
private readonly IOrderLogic _orderLogic; private readonly IOrderLogic _orderLogic;
private readonly IReportLogic _reportLogic; private readonly IReportLogic _reportLogic;
private readonly IWorkProcess _workProcess; private readonly IWorkProcess _workProcess;
private readonly IBackUpLogic _backUpLogic;
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess, IBackUpLogic backUpLogic)
{ {
InitializeComponent(); InitializeComponent();
_logger = logger; _logger = logger;
_orderLogic = orderLogic; _orderLogic = orderLogic;
_reportLogic = reportLogic; _reportLogic = reportLogic;
_workProcess = workProcess; _workProcess = workProcess;
_backUpLogic = backUpLogic;
} }
private void FormMain_Load(object sender, EventArgs e) private void FormMain_Load(object sender, EventArgs e)
@ -42,16 +33,7 @@ namespace PlumbingRepairView
try try
{ {
var list = _orderLogic.ReadList(null); DataGridView.FillandConfigGrid(_orderLogic.ReadList(null));
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["WorkId"].Visible = false;
dataGridView.Columns["ClientId"].Visible = false;
dataGridView.Columns["ImplementerId"].Visible = false;
}
_logger.LogInformation("Загрузка заказов"); _logger.LogInformation("Загрузка заказов");
} }
catch (Exception ex) catch (Exception ex)
@ -63,124 +45,34 @@ namespace PlumbingRepairView
private void компонентыToolStripMenuItem_Click(object sender, EventArgs e) private void компонентыToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); var form = DependencyManager.Instance.Resolve<FormComponents>();
form.ShowDialog();
if (service is FormComponents form)
{
form.ShowDialog();
}
} }
private void работыToolStripMenuItem_Click(object sender, EventArgs e) private void работыToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormWorks)); var form = DependencyManager.Instance.Resolve<FormWorks>();
form.ShowDialog();
if (service is FormWorks form)
{
form.ShowDialog();
}
} }
private void buttonCreateOrder_Click(object sender, EventArgs e) private void buttonCreateOrder_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); var form = DependencyManager.Instance.Resolve<FormCreateOrder>();
form.ShowDialog();
if (service is FormCreateOrder form) LoadData();
{
form.ShowDialog();
LoadData();
}
} }
private void buttonIssuedOrder_Click(object sender, EventArgs e)
private void buttonTakeOrderInWork_Click(object sender, EventArgs e)
{ {
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}. Меняется статус на 'В работе'", id); _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id);
try
{
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel
{
Id = id,
WorkId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["WorkId"].Value),
WorkName = dataGridView.SelectedRows[0].Cells["WorkName"].Value.ToString(),
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
});
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка передачи заказа в работу");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void buttonOrderReady_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id);
try try
{ {
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel
{ {
Id = id, Id = id
WorkId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["WorkId"].Value),
WorkName = dataGridView.SelectedRows[0].Cells["WorkName"].Value.ToString(),
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
});
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка отметки о готовности заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void buttonIssuedOrder_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id);
try
{
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel
{
Id = id,
WorkId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["WorkId"].Value),
WorkName = dataGridView.SelectedRows[0].Cells["WorkName"].Value.ToString(),
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
}); });
if (!operationResult) if (!operationResult)
@ -206,20 +98,14 @@ namespace PlumbingRepairView
private void списокЗаказовToolStripMenuItem_Click(object sender, EventArgs e) private void списокЗаказовToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); var form = DependencyManager.Instance.Resolve<FormReportOrders>();
if (service is FormReportOrders form) form.ShowDialog();
{
form.ShowDialog();
}
} }
private void компонентыПоРаботамToolStripMenuItem_Click(object sender, EventArgs e) private void компонентыПоРаботамToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormReportWorkComponents)); var form = DependencyManager.Instance.Resolve<FormReportWorkComponents>();
if (service is FormReportWorkComponents form) form.ShowDialog();
{
form.ShowDialog();
}
} }
private void списокРаботToolStripMenuItem_Click(object sender, EventArgs e) private void списокРаботToolStripMenuItem_Click(object sender, EventArgs e)
@ -238,33 +124,46 @@ namespace PlumbingRepairView
} }
private void КлиентыToolStripMenuItem_Click(object sender, EventArgs e) private void КлиентыToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormClients)); var form = DependencyManager.Instance.Resolve<FormClients>();
if (service is FormClients form) form.ShowDialog();
{
form.ShowDialog();
}
} }
private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e) private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e)
{ {
_workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); _workProcess.DoWork(DependencyManager.Instance.Resolve<IImplementerLogic>(), _orderLogic);
MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
} }
private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e) private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); var form = DependencyManager.Instance.Resolve<FormImplementers>();
form.ShowDialog();
if (service is FormImplementers form)
{
form.ShowDialog();
}
} }
private void письмаToolStripMenuItem_Click(object sender, EventArgs e) private void письмаToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormMails)); var form = DependencyManager.Instance.Resolve<FormMails>();
if (service is FormMails form) form.ShowDialog();
}
private void создатьБэкапToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{ {
form.ShowDialog(); if (_backUpLogic != null)
{
var fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == DialogResult.OK)
{
_backUpLogic.CreateBackUp(new BackUpSaveBindingModel
{
FolderName = fbd.SelectedPath
});
MessageBox.Show("Бекап создан", "Сообщение",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
} }
} }

View File

@ -35,7 +35,7 @@
buttonDel = new Button(); buttonDel = new Button();
buttonUpd = new Button(); buttonUpd = new Button();
buttonAdd = new Button(); buttonAdd = new Button();
dataGridView = new DataGridView(); DataGridView = new DataGridView();
ComponentId = new DataGridViewTextBoxColumn(); ComponentId = new DataGridViewTextBoxColumn();
ComponentName = new DataGridViewTextBoxColumn(); ComponentName = new DataGridViewTextBoxColumn();
Count = new DataGridViewTextBoxColumn(); Count = new DataGridViewTextBoxColumn();
@ -44,7 +44,7 @@
buttonCancel = new Button(); buttonCancel = new Button();
buttonSave = new Button(); buttonSave = new Button();
groupBox1.SuspendLayout(); groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); ((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit();
SuspendLayout(); SuspendLayout();
// //
// label1 // label1
@ -73,7 +73,7 @@
groupBox1.Controls.Add(buttonDel); groupBox1.Controls.Add(buttonDel);
groupBox1.Controls.Add(buttonUpd); groupBox1.Controls.Add(buttonUpd);
groupBox1.Controls.Add(buttonAdd); groupBox1.Controls.Add(buttonAdd);
groupBox1.Controls.Add(dataGridView); groupBox1.Controls.Add(DataGridView);
groupBox1.Location = new Point(40, 108); groupBox1.Location = new Point(40, 108);
groupBox1.Margin = new Padding(4, 4, 4, 4); groupBox1.Margin = new Padding(4, 4, 4, 4);
groupBox1.Name = "groupBox1"; groupBox1.Name = "groupBox1";
@ -129,15 +129,15 @@
// //
// dataGridView // dataGridView
// //
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Columns.AddRange(new DataGridViewColumn[] { ComponentId, ComponentName, Count }); DataGridView.Columns.AddRange(new DataGridViewColumn[] { ComponentId, ComponentName, Count });
dataGridView.Location = new Point(0, 32); DataGridView.Location = new Point(0, 32);
dataGridView.Margin = new Padding(4, 4, 4, 4); DataGridView.Margin = new Padding(4, 4, 4, 4);
dataGridView.Name = "dataGridView"; DataGridView.Name = "dataGridView";
dataGridView.RowHeadersWidth = 51; DataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 29; DataGridView.RowTemplate.Height = 29;
dataGridView.Size = new Size(668, 344); DataGridView.Size = new Size(668, 344);
dataGridView.TabIndex = 0; DataGridView.TabIndex = 0;
// //
// ComponentId // ComponentId
// //
@ -215,7 +215,7 @@
Name = "FormWork"; Name = "FormWork";
Text = "Работа"; Text = "Работа";
groupBox1.ResumeLayout(false); groupBox1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ((System.ComponentModel.ISupportInitialize)DataGridView).EndInit();
ResumeLayout(false); ResumeLayout(false);
PerformLayout(); PerformLayout();
} }
@ -225,7 +225,7 @@
private Label label1; private Label label1;
private Label label2; private Label label2;
private GroupBox groupBox1; private GroupBox groupBox1;
private DataGridView dataGridView; private DataGridView DataGridView;
private TextBox textBoxName; private TextBox textBoxName;
private TextBox textBoxCost; private TextBox textBoxCost;
private Button buttonRef; private Button buttonRef;

View File

@ -1,6 +1,7 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using PlumbingRepairContracts.BindingModels; using PlumbingRepairContracts.BindingModels;
using PlumbingRepairContracts.BusinessLogicsContracts; using PlumbingRepairContracts.BusinessLogicsContracts;
using PlumbingRepairContracts.DI;
using PlumbingRepairContracts.SearchModels; using PlumbingRepairContracts.SearchModels;
using PlumbingRepairDataModels.Models; using PlumbingRepairDataModels.Models;
using System; using System;
@ -69,10 +70,10 @@ namespace PlumbingRepairView
{ {
if (_workComponents != null) if (_workComponents != null)
{ {
dataGridView.Rows.Clear(); DataGridView.Rows.Clear();
foreach (var pc in _workComponents) foreach (var pc in _workComponents)
{ {
dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); DataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 });
} }
textBoxCost.Text = CalcPrice().ToString(); textBoxCost.Text = CalcPrice().ToString();
} }
@ -85,10 +86,40 @@ namespace PlumbingRepairView
} }
private void AddButton_Click(object sender, EventArgs e) private void AddButton_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormWorkComponent)); var form = DependencyManager.Instance.Resolve<FormWorkComponent>();
if (service is FormWorkComponent form) if (form.ShowDialog() == DialogResult.OK)
{ {
if (form.ComponentModel == null)
{
return;
}
_logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
if (_workComponents.ContainsKey(form.Id))
{
_workComponents[form.Id] = (form.ComponentModel, form.Count);
}
else
{
_workComponents.Add(form.Id, (form.ComponentModel, form.Count));
}
LoadData();
}
}
private void ChangeButton_Click(object sender, EventArgs e)
{
if (DataGridView.SelectedRows.Count == 1)
{
var form = DependencyManager.Instance.Resolve<FormWorkComponent>();
int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells[0].Value);
form.Id = id;
form.Count = _workComponents[id].Item2;
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
if (form.ComponentModel == null) if (form.ComponentModel == null)
@ -96,60 +127,23 @@ namespace PlumbingRepairView
return; return;
} }
_logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); _logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
_workComponents[form.Id] = (form.ComponentModel, form.Count);
if (_workComponents.ContainsKey(form.Id))
{
_workComponents[form.Id] = (form.ComponentModel, form.Count);
}
else
{
_workComponents.Add(form.Id, (form.ComponentModel, form.Count));
}
LoadData(); LoadData();
} }
} }
} }
private void ChangeButton_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormWorkComponent));
if (service is FormWorkComponent form)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
form.Id = id;
form.Count = _workComponents[id].Item2;
if (form.ShowDialog() == DialogResult.OK)
{
if (form.ComponentModel == null)
{
return;
}
_logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
_workComponents[form.Id] = (form.ComponentModel, form.Count);
LoadData();
}
}
}
}
private void DeleteButton_Click(object sender, EventArgs e) private void DeleteButton_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)
{ {
try try
{ {
_logger.LogInformation("Удаление компонента: { ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value); _logger.LogInformation("Удаление компонента: { ComponentName} - { Count}", DataGridView.SelectedRows[0].Cells[1].Value);
_workComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); _workComponents?.Remove(Convert.ToInt32(DataGridView.SelectedRows[0].Cells[0].Value));
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -28,23 +28,23 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
dataGridView = 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)dataGridView).BeginInit(); ((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit();
SuspendLayout(); SuspendLayout();
// //
// dataGridView // dataGridView
// //
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(1, 0); DataGridView.Location = new Point(1, 0);
dataGridView.Name = "dataGridView"; DataGridView.Name = "dataGridView";
dataGridView.RowHeadersWidth = 51; DataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 29; DataGridView.RowTemplate.Height = 29;
dataGridView.Size = new Size(611, 449); DataGridView.Size = new Size(611, 449);
dataGridView.TabIndex = 0; DataGridView.TabIndex = 0;
// //
// buttonAdd // buttonAdd
// //
@ -95,17 +95,17 @@
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 = "FormWorks"; Name = "FormWorks";
Text = "Работы"; Text = "Работы";
Load += FormComponents_Load; Load += FormComponents_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ((System.ComponentModel.ISupportInitialize)DataGridView).EndInit();
ResumeLayout(false); ResumeLayout(false);
} }
#endregion #endregion
private DataGridView dataGridView; private DataGridView DataGridView;
private Button buttonAdd; private Button buttonAdd;
private Button buttonUpd; private Button buttonUpd;
private Button buttonDel; private Button buttonDel;

View File

@ -1,15 +1,7 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using PlumbingRepairContracts.BindingModels; using PlumbingRepairContracts.BindingModels;
using PlumbingRepairContracts.BusinessLogicsContracts; using PlumbingRepairContracts.BusinessLogicsContracts;
using System; using PlumbingRepairContracts.DI;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PlumbingRepairView namespace PlumbingRepairView
{ {
@ -34,16 +26,7 @@ namespace PlumbingRepairView
{ {
try try
{ {
var list = _logic.ReadList(null); DataGridView.FillandConfigGrid(_logic.ReadList(null));
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["WorkName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["WorkComponents"].Visible = false;
}
_logger.LogInformation("Загрузка изделий"); _logger.LogInformation("Загрузка изделий");
} }
@ -56,40 +39,32 @@ namespace PlumbingRepairView
private void AddButton_Click(object sender, EventArgs e) private void AddButton_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormWork)); var form = DependencyManager.Instance.Resolve<FormWork>();
if (form.ShowDialog() == DialogResult.OK)
if (service is FormWork form)
{ {
LoadData();
}
}
private void ChangeButton_Click(object sender, EventArgs e)
{
if (DataGridView.SelectedRows.Count == 1)
{
var form = DependencyManager.Instance.Resolve<FormWork>();
form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
LoadData(); LoadData();
} }
} }
} }
private void ChangeButton_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormWork));
if (service is FormWork form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void DeleteButton_Click(object sender, EventArgs e) private void DeleteButton_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 = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Удаление изделия"); _logger.LogInformation("Удаление изделия");
try try