PIbd-21. Razubaev SM Lab work 5 hard #13

Closed
Sergey wants to merge 13 commits from lab_5_hard into lab_5
23 changed files with 1504 additions and 2 deletions
Showing only changes of commit bf5eaae8a1 - Show all commits

View File

@ -0,0 +1,165 @@
using Microsoft.Extensions.Logging;
using PlumbingRepairContracts.BindingModels;
using PlumbingRepairContracts.BusinessLogicsContracts;
using PlumbingRepairContracts.SearchModels;
using PlumbingRepairContracts.StoragesContracts;
using PlumbingRepairContracts.ViewModels;
using PlumbingRepairDataModels.Models;
namespace PlumbingRepairBusinessLogic.BusinessLogics
{
public class ShopLogic :IShopLogic
{
private readonly ILogger _logger;
private readonly IShopStorage _shopStorage;
public ShopLogic(ILogger<ShopLogic> logger, IShopStorage shopStorage)
{
_logger = logger;
_shopStorage = shopStorage;
}
public List<ShopViewModel>? ReadList(ShopSearchModel? model)
{
_logger.LogInformation("ReadList. ShopName:{ShopName}. Id:{Id}", model?.ShopName, model?.Id);
var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public ShopViewModel? ReadElement(ShopSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. ShopName:{ShopName}. Id:{Id}", model.ShopName, model.Id);
var element = _shopStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public bool Create(ShopBindingModel model)
{
CheckModel(model);
if (_shopStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(ShopBindingModel model)
{
CheckModel(model);
if (_shopStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(ShopBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_shopStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public bool StoreReplenishment(ShopSearchModel shopModel, IWorkModel workModel, int count)
{
if (shopModel == null)
{
throw new ArgumentNullException(nameof(shopModel));
}
if (workModel == null)
{
throw new ArgumentNullException(nameof(workModel));
}
if (count <= 0)
{
throw new ArgumentNullException("Количество товаров должно быть больше 0", nameof(count));
}
_logger.LogInformation("StoreReplenishment. ShopName:{ShopName}. Id:{Id}", shopModel.ShopName, shopModel.Id);
var element = _shopStorage.GetElement(shopModel);
if (element == null)
{
throw new InvalidOperationException("StoreReplenishment. Element not found");
}
if(element.ShopWorks.ContainsKey(workModel.Id))
{
var oldWorks = element.ShopWorks[workModel.Id];
oldWorks.Item2 += count;
element.ShopWorks[workModel.Id] = oldWorks;
_logger.LogInformation("StoreReplenishment. Added {count} '{work}' to '{ShopName}' shop", count, workModel.WorkName,shopModel.ShopName);
}
else
{
element.ShopWorks.Add(workModel.Id,(workModel, count));
_logger.LogInformation("StoreReplenishment. Added {count} new '{work}' to '{ShopName}' shop", count, workModel.WorkName, shopModel.ShopName);
}
if(_shopStorage.Update(new ShopBindingModel()
{
Id = element.Id,
ShopName = element.ShopName,
Address = element.Address,
DateOpening = element.DateOpening,
ShopWorks= element.ShopWorks
}) == null)
{
_logger.LogInformation("StoreReplenishment. Update operation failed");
return false;
}
return true;
}
private void CheckModel(ShopBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.ShopName))
{
throw new ArgumentNullException("Нет названия магазина", nameof(model.ShopName));
}
if (string.IsNullOrEmpty(model.Address))
{
throw new ArgumentNullException("Нет адреса магазина", nameof(model.ShopName));
}
_logger.LogInformation("Shop. ShopName:{ShopName}. Address:{Address}. Id:{Id}", model.ShopName, model.Address, model.Id);
var element = _shopStorage.GetElement(new ShopSearchModel
{
ShopName = model.ShopName
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Компонент с таким названием уже есть");
}
}
}
}

View File

@ -0,0 +1,17 @@
using PlumbingRepairDataModels.Models;
namespace PlumbingRepairContracts.BindingModels
{
public class ShopBindingModel
{
public int Id { get; set; }
public string ShopName { get; set; } =string.Empty;
public string Address { get; set; } = string.Empty;
public DateTime DateOpening { get; set; } = DateTime.Now;
public Dictionary<int, (IWorkModel, int)> ShopWorks { get; set; } = new();
}
}

View File

@ -0,0 +1,22 @@
using PlumbingRepairContracts.BindingModels;
using PlumbingRepairContracts.SearchModels;
using PlumbingRepairContracts.ViewModels;
using PlumbingRepairDataModels.Models;
namespace PlumbingRepairContracts.BusinessLogicsContracts
{
public interface IShopLogic
{
List<ShopViewModel>? ReadList(ShopSearchModel? model);
ShopViewModel? ReadElement(ShopSearchModel model);
bool Create(ShopBindingModel model);
bool Update(ShopBindingModel model);
bool Delete(ShopBindingModel model);
bool StoreReplenishment(ShopSearchModel shopModel, IWorkModel workModel, int count);
}
}

View File

@ -0,0 +1,9 @@
namespace PlumbingRepairContracts.SearchModels
{
public class ShopSearchModel
{
public int? Id { get; set; }
public string? ShopName { get; set; }
}
}

View File

@ -0,0 +1,21 @@
using PlumbingRepairContracts.BindingModels;
using PlumbingRepairContracts.SearchModels;
using PlumbingRepairContracts.ViewModels;
namespace PlumbingRepairContracts.StoragesContracts
{
public interface IShopStorage
{
List<ShopViewModel> GetFullList();
List<ShopViewModel> GetFilteredList(ShopSearchModel model);
ShopViewModel? GetElement(ShopSearchModel model);
ShopViewModel? Insert(ShopBindingModel model);
ShopViewModel? Update(ShopBindingModel model);
ShopViewModel? Delete(ShopBindingModel model);
}
}

View File

@ -8,6 +8,7 @@ namespace PlumbingRepairContracts.ViewModels
{
[DisplayName("Номер")]
public int Id { get; set; }
[DisplayName("Номер работы")]
public int WorkId { get; set; }
[DisplayName("Работа")]

View File

@ -0,0 +1,20 @@
using PlumbingRepairDataModels.Models;
using System.ComponentModel;
namespace PlumbingRepairContracts.ViewModels
{
public class ShopViewModel
{
public int Id { get; set; }
[DisplayName("Название магазина")]
public string ShopName { get; set; } = string.Empty;
[DisplayName("Адрес")]
public string Address { get; set; } = string.Empty;
[DisplayName("Дата открытия")]
public DateTime DateOpening { get; set; }
public Dictionary<int, (IWorkModel, int)> ShopWorks { get; set; } = new();
}
}

View File

@ -0,0 +1,13 @@
namespace PlumbingRepairDataModels.Models
{
public class IShopModel
{
string ShopName { get; }
string Address { get; }
DateTime DateOpening { get; }
Dictionary<int, (IWorkModel, int)> ShopWorks { get; }
}
}

View File

@ -12,11 +12,14 @@ namespace PlumbingRepairListImplement
public List<Work> Works { get; set; }
public List<Shop> Shops { get; set; }
private DataListSingleton()
{
Components = new List<Component>();
Orders = new List<Order>();
Works = new List<Work>();
Shops = new List<Shop>();
}
public static DataListSingleton GetInstance()

View File

@ -0,0 +1,108 @@
using PlumbingRepairContracts.BindingModels;
using PlumbingRepairContracts.SearchModels;
using PlumbingRepairContracts.StoragesContracts;
using PlumbingRepairContracts.ViewModels;
using PlumbingRepairListImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PlumbingRepairListImplement.Implements
{
public class ShopStorage : IShopStorage
{
private readonly DataListSingleton _source;
public ShopStorage()
{
_source = DataListSingleton.GetInstance();
}
public List<ShopViewModel> GetFullList()
{
var result = new List<ShopViewModel>();
foreach (var shop in _source.Shops)
{
result.Add(shop.GetViewModel);
}
return result;
}
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
{
var result = new List<ShopViewModel>();
if (string.IsNullOrEmpty(model.ShopName))
{
return result;
}
foreach (var shop in _source.Shops)
{
if (shop.ShopName.Contains(model.ShopName))
{
result.Add(shop.GetViewModel);
}
}
return result;
}
public ShopViewModel? GetElement(ShopSearchModel model)
{
if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue)
{
return null;
}
foreach (var shop in _source.Shops)
{
if ((!string.IsNullOrEmpty(model.ShopName) && shop.ShopName == model.ShopName) || (model.Id.HasValue && shop.Id == model.Id))
{
return shop.GetViewModel;
}
}
return null;
}
public ShopViewModel? Insert(ShopBindingModel model)
{
model.Id = 1;
foreach (var shop in _source.Shops)
{
if (model.Id <= shop.Id)
{
model.Id = shop.Id + 1;
}
}
var newShop = Shop.Create(model);
if (newShop == null)
{
return null;
}
_source.Shops.Add(newShop);
return newShop.GetViewModel;
}
public ShopViewModel? Update(ShopBindingModel model)
{
foreach (var shop in _source.Shops)
{
if (shop.Id == model.Id)
{
shop.Update(model);
return shop.GetViewModel;
}
}
return null;
}
public ShopViewModel? Delete(ShopBindingModel model)
{
for (int i = 0; i < _source.Shops.Count; ++i)
{
if (_source.Shops[i].Id == model.Id)
{
var element = _source.Shops[i];
_source.Shops.RemoveAt(i);
return element.GetViewModel;
}
}
return null;
}
}
}

View File

@ -0,0 +1,54 @@
using PlumbingRepairContracts.BindingModels;
using PlumbingRepairContracts.ViewModels;
using PlumbingRepairDataModels.Models;
namespace PlumbingRepairListImplement.Models
{
public class Shop
{
public int Id { get; private set; }
public string ShopName { get; private set; } = string.Empty;
public string Address { get; private set; } = string.Empty;
public DateTime DateOpening { get; private set; }
public Dictionary<int, (IWorkModel, int)> ShopWorks { get; private set; } = new Dictionary<int, (IWorkModel, int)>();
public static Shop? Create(ShopBindingModel? model)
{
if (model == null)
{
return null;
}
return new Shop()
{
Id = model.Id,
ShopName = model.ShopName,
Address = model.Address,
DateOpening = model.DateOpening,
ShopWorks = model.ShopWorks
};
}
public void Update(ShopBindingModel? model)
{
if (model == null)
{
return;
}
ShopName = model.ShopName;
Address = model.Address;
DateOpening= model.DateOpening;
}
public ShopViewModel GetViewModel => new()
{
Id = Id,
ShopName = ShopName,
Address = Address,
DateOpening = DateOpening,
ShopWorks = ShopWorks
};
}
}

View File

@ -38,6 +38,8 @@
this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.РаботыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.пToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
@ -137,7 +139,9 @@
//
this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.компонентыToolStripMenuItem,
this.РаботыToolStripMenuItem});
this.РаботыToolStripMenuItem,
this.магазиныToolStripMenuItem,
this.пToolStripMenuItem});
this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(139, 29);
this.справочникиToolStripMenuItem.Text = "Справочники";
@ -156,6 +160,20 @@
this.РаботыToolStripMenuItem.Text = "Работы";
this.РаботыToolStripMenuItem.Click += new System.EventHandler(this.РаботыToolStripMenuItem_Click);
//
// магазиныToolStripMenuItem
//
this.магазиныToolStripMenuItem.Name = агазиныToolStripMenuItem";
this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(296, 34);
this.магазиныToolStripMenuItem.Text = "Магазины";
this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.магазиныToolStripMenuItem_Click);
//
// пToolStripMenuItem
//
this.пToolStripMenuItem.Name = "пToolStripMenuItem";
this.пToolStripMenuItem.Size = new System.Drawing.Size(296, 34);
this.пToolStripMenuItem.Text = "Пополнение магазина";
this.пToolStripMenuItem.Click += new System.EventHandler(this.пополнениеToolStripMenuItem_Click);
//
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
@ -192,5 +210,7 @@
private ToolStripMenuItem справочникиToolStripMenuItem;
private ToolStripMenuItem компонентыToolStripMenuItem;
private ToolStripMenuItem РаботыToolStripMenuItem;
private ToolStripMenuItem магазиныToolStripMenuItem;
private ToolStripMenuItem пToolStripMenuItem;
}
}

View File

@ -58,6 +58,22 @@ namespace PlumbingRepairView
form.ShowDialog();
}
}
private void магазиныToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShops));
if (service is FormShops form)
{
form.ShowDialog();
}
}
private void пополнениеToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormStoreReplenishment));
if (service is FormStoreReplenishment form)
{
form.ShowDialog();
}
}
private void ButtonCreateOrder_Click(object sender, EventArgs e)
{
@ -142,6 +158,6 @@ namespace PlumbingRepairView
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
}
}
}
}

View File

@ -0,0 +1,222 @@
namespace PlumbingRepairView
{
partial class FormShop
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.textBoxAddress = new System.Windows.Forms.TextBox();
this.labelAddress = new System.Windows.Forms.Label();
this.buttonCancel = new System.Windows.Forms.Button();
this.buttonSave = new System.Windows.Forms.Button();
this.textBoxName = new System.Windows.Forms.TextBox();
this.labelName = new System.Windows.Forms.Label();
this.dateTimePickerOpening = new System.Windows.Forms.DateTimePicker();
this.groupBoxComponents = new System.Windows.Forms.GroupBox();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.ColumnId = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ColumnName = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.labelDateOpening = new System.Windows.Forms.Label();
this.groupBoxComponents.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// textBoxAddress
//
this.textBoxAddress.Location = new System.Drawing.Point(152, 75);
this.textBoxAddress.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5);
this.textBoxAddress.Name = "textBoxAddress";
this.textBoxAddress.Size = new System.Drawing.Size(183, 31);
this.textBoxAddress.TabIndex = 15;
//
// labelAddress
//
this.labelAddress.AutoSize = true;
this.labelAddress.Location = new System.Drawing.Point(8, 78);
this.labelAddress.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
this.labelAddress.Name = "labelAddress";
this.labelAddress.Size = new System.Drawing.Size(66, 25);
this.labelAddress.TabIndex = 14;
this.labelAddress.Text = "Адрес:";
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(633, 149);
this.buttonCancel.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(126, 45);
this.buttonCancel.TabIndex = 17;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(633, 50);
this.buttonSave.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(126, 45);
this.buttonSave.TabIndex = 16;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
// textBoxName
//
this.textBoxName.Location = new System.Drawing.Point(152, 27);
this.textBoxName.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5);
this.textBoxName.Name = "textBoxName";
this.textBoxName.Size = new System.Drawing.Size(358, 31);
this.textBoxName.TabIndex = 13;
//
// labelName
//
this.labelName.AutoSize = true;
this.labelName.Location = new System.Drawing.Point(8, 30);
this.labelName.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
this.labelName.Name = "labelName";
this.labelName.Size = new System.Drawing.Size(94, 25);
this.labelName.TabIndex = 12;
this.labelName.Text = "Название:";
//
// dateTimePickerOpening
//
this.dateTimePickerOpening.Location = new System.Drawing.Point(152, 118);
this.dateTimePickerOpening.Name = "dateTimePickerOpening";
this.dateTimePickerOpening.Size = new System.Drawing.Size(300, 31);
this.dateTimePickerOpening.TabIndex = 18;
//
// groupBoxComponents
//
this.groupBoxComponents.Controls.Add(this.dataGridView);
this.groupBoxComponents.Controls.Add(this.buttonSave);
this.groupBoxComponents.Controls.Add(this.buttonCancel);
this.groupBoxComponents.Location = new System.Drawing.Point(8, 151);
this.groupBoxComponents.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5);
this.groupBoxComponents.Name = "groupBoxComponents";
this.groupBoxComponents.Padding = new System.Windows.Forms.Padding(6, 5, 6, 5);
this.groupBoxComponents.Size = new System.Drawing.Size(797, 379);
this.groupBoxComponents.TabIndex = 19;
this.groupBoxComponents.TabStop = false;
this.groupBoxComponents.Text = "Компоненты";
//
// dataGridView
//
this.dataGridView.AllowUserToAddRows = false;
this.dataGridView.AllowUserToDeleteRows = false;
this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.ColumnId,
this.ColumnName,
this.ColumnCount});
this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left;
this.dataGridView.Location = new System.Drawing.Point(6, 29);
this.dataGridView.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5);
this.dataGridView.MultiSelect = false;
this.dataGridView.Name = "dataGridView";
this.dataGridView.ReadOnly = true;
this.dataGridView.RowHeadersVisible = false;
this.dataGridView.RowHeadersWidth = 62;
this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
this.dataGridView.Size = new System.Drawing.Size(583, 345);
this.dataGridView.TabIndex = 0;
//
// ColumnId
//
this.ColumnId.HeaderText = "Id";
this.ColumnId.MinimumWidth = 8;
this.ColumnId.Name = "ColumnId";
this.ColumnId.ReadOnly = true;
this.ColumnId.Visible = false;
this.ColumnId.Width = 150;
//
// ColumnName
//
this.ColumnName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.ColumnName.HeaderText = "Работа";
this.ColumnName.MinimumWidth = 8;
this.ColumnName.Name = "ColumnName";
this.ColumnName.ReadOnly = true;
//
// ColumnCount
//
this.ColumnCount.HeaderText = "Количество";
this.ColumnCount.MinimumWidth = 8;
this.ColumnCount.Name = "ColumnCount";
this.ColumnCount.ReadOnly = true;
this.ColumnCount.Width = 150;
//
// labelDateOpening
//
this.labelDateOpening.AutoSize = true;
this.labelDateOpening.Location = new System.Drawing.Point(8, 118);
this.labelDateOpening.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
this.labelDateOpening.Name = "labelDateOpening";
this.labelDateOpening.Size = new System.Drawing.Size(135, 25);
this.labelDateOpening.TabIndex = 20;
this.labelDateOpening.Text = "Дата открытия:";
//
// FormShop
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(812, 543);
this.Controls.Add(this.labelDateOpening);
this.Controls.Add(this.groupBoxComponents);
this.Controls.Add(this.dateTimePickerOpening);
this.Controls.Add(this.textBoxAddress);
this.Controls.Add(this.labelAddress);
this.Controls.Add(this.textBoxName);
this.Controls.Add(this.labelName);
this.Name = "FormShop";
this.Text = "Магазин";
this.Load += new System.EventHandler(this.FormShop_Load);
this.groupBoxComponents.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private TextBox textBoxAddress;
private Label labelAddress;
private Button buttonCancel;
private Button buttonSave;
private TextBox textBoxName;
private Label labelName;
private DateTimePicker dateTimePickerOpening;
private GroupBox groupBoxComponents;
private DataGridView dataGridView;
private DataGridViewTextBoxColumn ColumnId;
private DataGridViewTextBoxColumn ColumnName;
private DataGridViewTextBoxColumn ColumnCount;
private Label labelDateOpening;
}
}

View File

@ -0,0 +1,124 @@
using Microsoft.Extensions.Logging;
using PlumbingRepairContracts.BindingModels;
using PlumbingRepairContracts.BusinessLogicsContracts;
using PlumbingRepairContracts.SearchModels;
using PlumbingRepairDataModels.Models;
namespace PlumbingRepairView
{
public partial class FormShop : Form
{
private readonly ILogger _logger;
private readonly IShopLogic _logic;
private int? _id;
private Dictionary<int, (IWorkModel, int)> _shopWorks;
public int Id { set { _id = value; } }
public FormShop(ILogger<FormShop> logger, IShopLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
_shopWorks = new Dictionary<int, (IWorkModel, int)>();
}
private void FormShop_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
_logger.LogInformation("Загрузка изделия");
try
{
var view = _logic.ReadElement(new ShopSearchModel { Id = _id.Value });
if (view != null)
{
textBoxName.Text = view.ShopName;
textBoxAddress.Text = view.Address;
dateTimePickerOpening.Value = view.DateOpening;
_shopWorks = view.ShopWorks ?? new Dictionary<int, (IWorkModel, int)>();
LoadData();
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки магазина");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void LoadData()
{
_logger.LogInformation("Загрузка изделий магазина");
try
{
if (_shopWorks != null)
{
dataGridView.Rows.Clear();
foreach (var pc in _shopWorks)
{
dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.WorkName, pc.Value.Item2 });
}
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки компонент изделия");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxName.Text))
{
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxAddress.Text))
{
MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(dateTimePickerOpening.Text))
{
MessageBox.Show("Заполните дату", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение магазина");
try
{
var model = new ShopBindingModel
{
Id = _id ?? 0,
ShopName = textBoxName.Text,
Address = textBoxAddress.Text,
DateOpening= dateTimePickerOpening.Value,
ShopWorks = _shopWorks
};
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)
{
_logger.LogError(ex, "Ошибка сохранения магазина");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,127 @@
namespace PlumbingRepairView
{
partial class FormShops
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.buttonRef = new System.Windows.Forms.Button();
this.buttonDel = new System.Windows.Forms.Button();
this.buttonUpd = new System.Windows.Forms.Button();
this.buttonAdd = new System.Windows.Forms.Button();
this.dataGridView = new System.Windows.Forms.DataGridView();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// buttonRef
//
this.buttonRef.Location = new System.Drawing.Point(786, 234);
this.buttonRef.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6);
this.buttonRef.Name = "buttonRef";
this.buttonRef.Size = new System.Drawing.Size(125, 44);
this.buttonRef.TabIndex = 19;
this.buttonRef.Text = "Обновить";
this.buttonRef.UseVisualStyleBackColor = true;
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
//
// buttonDel
//
this.buttonDel.Location = new System.Drawing.Point(786, 156);
this.buttonDel.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6);
this.buttonDel.Name = "buttonDel";
this.buttonDel.Size = new System.Drawing.Size(125, 44);
this.buttonDel.TabIndex = 18;
this.buttonDel.Text = "Удалить";
this.buttonDel.UseVisualStyleBackColor = true;
this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click);
//
// buttonUpd
//
this.buttonUpd.Location = new System.Drawing.Point(786, 77);
this.buttonUpd.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6);
this.buttonUpd.Name = "buttonUpd";
this.buttonUpd.Size = new System.Drawing.Size(125, 44);
this.buttonUpd.TabIndex = 17;
this.buttonUpd.Text = "Изменить";
this.buttonUpd.UseVisualStyleBackColor = true;
this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
//
// buttonAdd
//
this.buttonAdd.Location = new System.Drawing.Point(786, 4);
this.buttonAdd.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(125, 44);
this.buttonAdd.TabIndex = 16;
this.buttonAdd.Text = "Добавить";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
//
// dataGridView
//
this.dataGridView.AllowUserToAddRows = false;
this.dataGridView.AllowUserToDeleteRows = false;
this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left;
this.dataGridView.Location = new System.Drawing.Point(0, 0);
this.dataGridView.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6);
this.dataGridView.MultiSelect = false;
this.dataGridView.Name = "dataGridView";
this.dataGridView.ReadOnly = true;
this.dataGridView.RowHeadersVisible = false;
this.dataGridView.RowHeadersWidth = 62;
this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
this.dataGridView.Size = new System.Drawing.Size(767, 446);
this.dataGridView.TabIndex = 15;
//
// FormShops
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(926, 446);
this.Controls.Add(this.buttonRef);
this.Controls.Add(this.buttonDel);
this.Controls.Add(this.buttonUpd);
this.Controls.Add(this.buttonAdd);
this.Controls.Add(this.dataGridView);
this.Name = "FormShops";
this.Text = "Магазины";
this.Load += new System.EventHandler(this.FormShop_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private Button buttonRef;
private Button buttonDel;
private Button buttonUpd;
private Button buttonAdd;
private DataGridView dataGridView;
}
}

View File

@ -0,0 +1,105 @@
using Microsoft.Extensions.Logging;
using PlumbingRepairContracts.BindingModels;
using PlumbingRepairContracts.BusinessLogicsContracts;
namespace PlumbingRepairView
{
public partial class FormShops : Form
{
private readonly ILogger _logger;
private readonly IShopLogic _logic;
public FormShops(ILogger<FormShops> logger, IShopLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormShop_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["ShopWorks"].Visible = false;
dataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка магазинов");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки магазинов");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShop));
if (service is FormShop form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShop));
if (service is FormShop form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Удаление магазина");
try
{
if (!_logic.Delete(new ShopBindingModel { Id = id }))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления магазина");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,153 @@
namespace PlumbingRepairView
{
partial class FormStoreReplenishment
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.textBoxCount = new System.Windows.Forms.TextBox();
this.labelWorkName = new System.Windows.Forms.Label();
this.labelShopName = new System.Windows.Forms.Label();
this.labelCount = new System.Windows.Forms.Label();
this.comboBoxShop = new System.Windows.Forms.ComboBox();
this.comboBoxWork = new System.Windows.Forms.ComboBox();
this.buttonSave = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBoxCount
//
this.textBoxCount.Location = new System.Drawing.Point(128, 109);
this.textBoxCount.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5);
this.textBoxCount.Name = "textBoxCount";
this.textBoxCount.Size = new System.Drawing.Size(183, 31);
this.textBoxCount.TabIndex = 13;
//
// labelWorkName
//
this.labelWorkName.AutoSize = true;
this.labelWorkName.Location = new System.Drawing.Point(5, 67);
this.labelWorkName.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
this.labelWorkName.Name = "labelWorkName";
this.labelWorkName.Size = new System.Drawing.Size(72, 25);
this.labelWorkName.TabIndex = 12;
this.labelWorkName.Text = "Работа:";
//
// labelShopName
//
this.labelShopName.AutoSize = true;
this.labelShopName.Location = new System.Drawing.Point(5, 19);
this.labelShopName.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
this.labelShopName.Name = "labelShopName";
this.labelShopName.Size = new System.Drawing.Size(85, 25);
this.labelShopName.TabIndex = 10;
this.labelShopName.Text = "Магазин:";
//
// labelCount
//
this.labelCount.AutoSize = true;
this.labelCount.Location = new System.Drawing.Point(5, 115);
this.labelCount.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
this.labelCount.Name = "labelCount";
this.labelCount.Size = new System.Drawing.Size(111, 25);
this.labelCount.TabIndex = 14;
this.labelCount.Text = "Количество:";
//
// comboBoxShop
//
this.comboBoxShop.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxShop.FormattingEnabled = true;
this.comboBoxShop.Location = new System.Drawing.Point(128, 19);
this.comboBoxShop.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6);
this.comboBoxShop.Name = "comboBoxShop";
this.comboBoxShop.Size = new System.Drawing.Size(359, 33);
this.comboBoxShop.TabIndex = 15;
//
// comboBoxWork
//
this.comboBoxWork.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxWork.FormattingEnabled = true;
this.comboBoxWork.Location = new System.Drawing.Point(128, 59);
this.comboBoxWork.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6);
this.comboBoxWork.Name = "comboBoxWork";
this.comboBoxWork.Size = new System.Drawing.Size(359, 33);
this.comboBoxWork.TabIndex = 16;
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(15, 182);
this.buttonSave.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(126, 45);
this.buttonSave.TabIndex = 18;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(331, 182);
this.buttonCancel.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(126, 45);
this.buttonCancel.TabIndex = 19;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// FormStoreReplenishment
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(501, 239);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.comboBoxWork);
this.Controls.Add(this.comboBoxShop);
this.Controls.Add(this.labelCount);
this.Controls.Add(this.textBoxCount);
this.Controls.Add(this.labelWorkName);
this.Controls.Add(this.labelShopName);
this.Name = "FormStoreReplenishment";
this.Text = "FormStoreReplenishment";
this.Load += new System.EventHandler(this.FormStoreReplenishment_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private TextBox textBoxCount;
private Label labelWorkName;
private Label labelShopName;
private Label labelCount;
private ComboBox comboBoxShop;
private ComboBox comboBoxWork;
private Button buttonSave;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,117 @@
using Microsoft.Extensions.Logging;
using PlumbingRepairContracts.BusinessLogicsContracts;
using PlumbingRepairContracts.SearchModels;
namespace PlumbingRepairView
{
public partial class FormStoreReplenishment : Form
{
private readonly ILogger _logger;
private readonly IWorkLogic _workLogic;
private readonly IShopLogic _logicShop;
public FormStoreReplenishment(ILogger<FormStoreReplenishment> logger, IWorkLogic workLogic, IShopLogic logicShop)
{
InitializeComponent();
_logger = logger;
_workLogic = workLogic;
_logicShop = logicShop;
}
private void FormStoreReplenishment_Load(object sender, EventArgs e)
{
_logger.LogInformation("Works loading");
try
{
var list = _workLogic.ReadList(null);
if (list != null)
{
comboBoxWork.DisplayMember = "WorkName";
comboBoxWork.ValueMember = "Id";
comboBoxWork.DataSource = list;
comboBoxWork.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Works loading error");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
_logger.LogInformation("Shops loading");
try
{
var list = _logicShop.ReadList(null);
if (list != null)
{
comboBoxShop.DisplayMember = "ShopName";
comboBoxShop.ValueMember = "Id";
comboBoxShop.DataSource = list;
comboBoxShop.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Shops loading error");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (comboBoxShop.SelectedValue == null)
{
MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxWork.SelectedValue == null)
{
MessageBox.Show("Выберите работу", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxCount.Text))
{
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Shop replenishment");
try
{
var work = _workLogic.ReadElement(new WorkSearchModel
{ Id = Convert.ToInt32(comboBoxWork.SelectedValue) });
if (work == null)
{
throw new Exception("Работа не найдена.");
}
var operationResult = _logicShop.StoreReplenishment(new ShopSearchModel
{
Id = Convert.ToInt32(comboBoxShop.SelectedValue)
},
work,
Convert.ToInt32(textBoxCount.Text));
if (!operationResult)
{
throw new Exception("Ошибка при проведении поставки.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Shop replenishment error");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
DialogResult = DialogResult.OK;
Close();
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -38,10 +38,12 @@ namespace PlumbingRepairView
services.AddTransient<IComponentStorage, ComponentStorage>();
services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<IWorkStorage, WorkStorage>();
services.AddTransient<IShopStorage, ShopStorage>();
services.AddTransient<IComponentLogic, ComponentLogic>();
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<IWorkLogic, WorkLogic>();
services.AddTransient<IShopLogic, ShopLogic>();
services.AddTransient<FormMain>();
services.AddTransient<FormComponent>();
@ -49,7 +51,10 @@ namespace PlumbingRepairView
services.AddTransient<FormCreateOrder>();
services.AddTransient<FormWork>();
services.AddTransient<FormWorks>();
services.AddTransient<FormShop>();
services.AddTransient<FormShops>();
services.AddTransient<FormWorkComponent>();
services.AddTransient<FormStoreReplenishment>();
}
}
}