PIbd-22. Stroev V.M. Lab Work 08 #10

Closed
StroevVladimir wants to merge 3 commits from Lab8 into Lab7
14 changed files with 324 additions and 510 deletions
Showing only changes of commit 112833ae68 - Show all commits

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)
}
private void LoadData()
{ {
try try
{ {
DataGridView.FillandConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Ïîëó÷åíèå êîìïîíåíòà");
_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) 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)
{
var form = DependencyManager.Instance.Resolve<FormComponent>();
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
} }
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxName.Text))
{
MessageBox.Show("Çàïîëíèòå íàçâàíèå", "Îøèáêà",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
} }
private void ChangeButton_Click(object sender, EventArgs e) _logger.LogInformation("Ñîõðàíåíèå êîìïîíåíòà");
{
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 try
{ {
if (!_logic.Delete(new ComponentBindingModel var model = new ComponentBindingModel
{ {
Id = id 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("Îøèáêà ïðè óäàëåíèè. Äîïîëíèòåëüíàÿ èíôîðìàöèÿ â ëîãàõ."); throw new Exception("Îøèáêà ïðè ñîõðàíåíèè. Äîïîëíèòåëüíàÿ èíôîðìàöèÿ â ëîãàõ.");
} }
MessageBox.Show("Ñîõðàíåíèå ïðîøëî óñïåøíî", "Ñîîáùåíèå",
LoadData(); 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)
}
private void UpdateButton_Click(object sender, EventArgs e)
{ {
LoadData(); DialogResult = DialogResult.Cancel;
Close();
} }
} }
} }

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) if (form.ShowDialog() == DialogResult.OK)
{ {
LoadData(); LoadData();
} }
} }
}
private void ButtonUpd_Click(object sender, EventArgs e) private void ButtonUpd_Click(object sender, EventArgs e)
{ {
if (dataGridView.SelectedRows.Count == 1) if (DataGridView.SelectedRows.Count == 1)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); var form = DependencyManager.Instance.Resolve<FormComponent>();
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);
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
LoadData(); LoadData();
} }
} }
} }
}
private void ButtonDel_Click(object sender, EventArgs e) private void ButtonDel_Click(object sender, EventArgs e)
{ {
if (dataGridView.SelectedRows.Count == 1) if (DataGridView.SelectedRows.Count == 1)
{ {
if (MessageBox.Show("Удалить запись?", "Вопрос", 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))
{
MessageBox.Show("Заполните фио", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
} }
_logger.LogInformation("Сохранение исполнителя");
private void ChangeButton_Click(object sender, EventArgs e)
{
if (DataGridView.SelectedRows.Count == 1)
{
var form = DependencyManager.Instance.Resolve<FormImplementer>();
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 try
{ {
if (!_logic.Delete(new ImplementerBindingModel var model = new ImplementerBindingModel
{ {
Id = id 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("Ошибка при удалении. Дополнительная информация в логах."); throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
} }
MessageBox.Show("Сохранение прошло успешно", "Сообщение",
LoadData(); 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 UpdateButton_Click(object sender, EventArgs e) private void ButtonCancel_Click(object sender, EventArgs e)
{ {
LoadData(); DialogResult = DialogResult.Cancel;
Close();
} }
private void FormImplementers_Load(object sender, EventArgs e) private void FormImplementer_Load(object sender, EventArgs e)
{ {
LoadData(); if (_id.HasValue)
}
private void LoadData()
{ {
try try
{ {
DataGridView.FillandConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Получение исполнителя");
var view = _logic.ReadElement(new ImplementerSearchModel
_logger.LogInformation("Загрузка исполнителей"); {
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) 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);
} }
} }
} }
}
} }

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,24 +28,18 @@ 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 (service is FormImplementer form)
{
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
LoadData(); LoadData();
} }
} }
}
private void ChangeButton_Click(object sender, EventArgs e) private void ChangeButton_Click(object sender, EventArgs e)
{ {
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); form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
@ -52,7 +47,6 @@ namespace PlumbingRepair
} }
} }
} }
}
private void DeleteButton_Click(object sender, EventArgs e) private void DeleteButton_Click(object sender, EventArgs e)
{ {

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>();
if (service is FormComponents 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(FormWorks)); var form = DependencyManager.Instance.Resolve<FormWorks>();
if (service is FormWorks form)
{
form.ShowDialog(); 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>();
if (service is FormCreateOrder form)
{
form.ShowDialog(); form.ShowDialog();
LoadData(); 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,21 +98,15 @@ 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,34 +124,47 @@ 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>();
if (service is FormImplementers 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(FormMails)); var form = DependencyManager.Instance.Resolve<FormMails>();
if (service is FormMails form)
{
form.ShowDialog(); form.ShowDialog();
} }
private void создатьБэкапToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
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,8 @@ 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.ShowDialog() == DialogResult.OK)
{ {
if (form.ComponentModel == null) if (form.ComponentModel == null)
@ -111,17 +110,13 @@ namespace PlumbingRepairView
LoadData(); LoadData();
} }
} }
}
private void ChangeButton_Click(object sender, EventArgs e) private void ChangeButton_Click(object sender, EventArgs e)
{ {
if (dataGridView.SelectedRows.Count == 1) if (DataGridView.SelectedRows.Count == 1)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormWorkComponent)); var form = DependencyManager.Instance.Resolve<FormWorkComponent>();
int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells[0].Value);
if (service is FormWorkComponent form)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
form.Id = id; form.Id = id;
form.Count = _workComponents[id].Item2; form.Count = _workComponents[id].Item2;
@ -138,18 +133,17 @@ namespace PlumbingRepairView
} }
} }
} }
}
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,25 +39,18 @@ 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 (service is FormWork form)
{
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
LoadData(); LoadData();
} }
} }
}
private void ChangeButton_Click(object sender, EventArgs e) private void ChangeButton_Click(object sender, EventArgs e)
{ {
if (dataGridView.SelectedRows.Count == 1) if (DataGridView.SelectedRows.Count == 1)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormWork)); var form = DependencyManager.Instance.Resolve<FormWork>();
form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
if (service is FormWork form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
@ -82,14 +58,13 @@ namespace PlumbingRepairView
} }
} }
} }
}
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