conflict fix

This commit is contained in:
Danil Markov 2023-04-25 03:10:47 +04:00
commit f0249f4a02
29 changed files with 2275 additions and 157 deletions

View File

@ -12,10 +12,17 @@ namespace LawFirmBusinessLogic.BusinessLogics
{
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
private readonly IShopLogic _shopLogic;
private readonly IDocumentStorage _documentStorage;
public OrderLogic(ILogger<OrderLogic> logger,
IOrderStorage orderStorage,
IShopLogic shopLogic,
IDocumentStorage documentStorage)
{
_logger = logger;
_orderStorage = orderStorage;
_shopLogic = shopLogic;
_documentStorage = documentStorage;
}
public bool CreateOrder(OrderBindingModel model)
{
@ -47,7 +54,20 @@ namespace LawFirmBusinessLogic.BusinessLogics
return false;
}
model.Status = newStatus;
if (model.Status == OrderStatus.Готов) model.DateImplement = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
if (model.Status == OrderStatus.Готов)
{
model.DateImplement = DateTime.Now;
var document = _documentStorage.GetElement(new() { Id = viewModel.DocumentId });
if (document == null)
{
throw new ArgumentNullException(nameof(document));
}
if (!_shopLogic.AddDocuments(document, viewModel.Count))
{
throw new Exception($"AddDocuments operation failed - нет места");
}
}
else
{
model.DateImplement = viewModel.DateImplement;
@ -56,7 +76,7 @@ namespace LawFirmBusinessLogic.BusinessLogics
if (_orderStorage.Update(model) == null)
{
model.Status--;
_logger.LogWarning("Update operation failed");
_logger.LogWarning("Change status operation failed");
return false;
}
return true;

View File

@ -0,0 +1,211 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.BusinessLogicsContracts;
using LawFirmContracts.SearchModels;
using LawFirmContracts.StoragesContracts;
using LawFirmContracts.ViewModels;
using LawFirmDataModels.Models;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmBusinessLogic.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;
}
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));
}
_logger.LogInformation("Shop. ShopName:{0}. Address:{1}. Id:{2}",
model.ShopName, model.Address, model.Id);
var element = _shopStorage.GetElement(new ShopSearchModel
{
ShopName = model.ShopName
});
if (element != null && element.Id != model.Id && element.ShopName == model.ShopName)
{
throw new InvalidOperationException("Магазин с таким названием уже есть");
}
}
public bool AddDocument(ShopSearchModel model, IDocumentModel document, int count)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (count <= 0)
{
return false;
throw new ArgumentException("Количество поездок должно быть больше 0", nameof(count));
}
_logger.LogInformation("AddDocument. ShopName:{ShopName}. Id:{Id}", model.ShopName, model.Id);
var element = _shopStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("AddDocument element not found");
return false;
}
if (element.Capacity - element.ShopDocuments.Select(x => x.Value.Item2).Sum() < count)
{
throw new ArgumentNullException("В магазине не хватает места", nameof(count));
}
if (element.ShopDocuments.TryGetValue(document.Id, out var pair))
{
element.ShopDocuments[document.Id] = (document, count + pair.Item2);
_logger.LogInformation("AddDocument. Added {count} {document} to '{ShopName}' shop",
count, document.DocumentName, element.ShopName);
}
else
{
element.ShopDocuments[document.Id] = (document, count);
_logger.LogInformation("AddDocument. Added {count} new document {document} to '{ShopName}' shop",
count, document.DocumentName, element.ShopName);
}
_shopStorage.Update(new()
{
Id = element.Id,
Address = element.Address,
ShopName = element.ShopName,
DateOpen = element.DateOpen,
Capacity = element.Capacity,
ShopDocuments = element.ShopDocuments
});
return true;
}
public bool AddDocuments(IDocumentModel model, int count)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (count <= 0)
{
throw new ArgumentException("Количество документов должно быть больше 0", nameof(count));
}
_logger.LogInformation("AddDocuments. ShopName:{ShopName}. Id:{Id}", model.DocumentName, model.Id);
var allFreeQuantity = _shopStorage.GetFullList().Select(x => x.Capacity - x.ShopDocuments.Select(x => x.Value.Item2).Sum()).Sum();
if (allFreeQuantity < count)
{
_logger.LogWarning("AddTravels operation failed.");
return false;
}
foreach (var shop in _shopStorage.GetFullList())
{
int freeQuantity = shop.Capacity - shop.ShopDocuments.Select(x => x.Value.Item2).Sum();
if (freeQuantity <= 0)
{
continue;
}
if (freeQuantity < count)
{
if (!AddDocument(new() { Id = shop.Id }, model, freeQuantity))
{
_logger.LogWarning("AddDocuments operation failed.");
return false;
}
count -= freeQuantity;
}
else
{
if (!AddDocument(new() { Id = shop.Id }, model, count))
{
_logger.LogWarning("AddDocuments operation failed.");
return false;
}
count = 0;
}
if (count == 0)
{
return true;
}
}
_logger.LogWarning("AddDocuments operation failed.");
return false;
}
public bool SellDocuments(IDocumentModel model, int count)
{
return _shopStorage.SellDocuments(model, count);
}
}
}

View File

@ -0,0 +1,19 @@
using LawFirmDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmContracts.BindingModels
{
public class ShopBindingModel : IShopModel
{
public string ShopName { get; set; } = string.Empty;
public string Address { get; set; } = string.Empty;
public DateTime DateOpen { get; set; } = DateTime.Now;
public int Capacity { get; set; }
public Dictionary<int, (IDocumentModel, int)> ShopDocuments { get; set; } = new();
public int Id { get; set; }
}
}

View File

@ -0,0 +1,24 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.SearchModels;
using LawFirmContracts.ViewModels;
using LawFirmDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmContracts.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 AddDocuments(IDocumentModel model, int count);
bool SellDocuments(IDocumentModel model, int count);
bool AddDocument(ShopSearchModel model, IDocumentModel document, int count);
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmContracts.SearchModels
{
public class ShopSearchModel
{
public int? Id { get; set; }
public string? ShopName { get; set; }
}
}

View File

@ -0,0 +1,23 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.SearchModels;
using LawFirmContracts.ViewModels;
using LawFirmDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmContracts.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);
bool SellDocuments(IDocumentModel model, int count);
}
}

View File

@ -0,0 +1,26 @@
using LawFirmDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmContracts.ViewModels
{
public class ShopViewModel : IShopModel
{
[DisplayName("Название магазина")]
public string ShopName { get; set; } = string.Empty;
[DisplayName("Адрес магазина")]
public string Address { get; set; } = string.Empty;
[DisplayName("Дата открытия")]
public DateTime DateOpen { get; set; } = DateTime.Now;
[DisplayName("Вместимость магазина")]
public int Capacity { get; set; }
public Dictionary<int, (IDocumentModel, int)> ShopDocuments { get; set; } = new();
public int Id { get; set; }
}
}

View File

@ -0,0 +1,14 @@
using LawFirmDataModels;
using LawFirmDataModels.Models;
namespace LawFirmDataModels.Models
{
public interface IShopModel : IId
{
string ShopName { get; }
string Address { get; }
DateTime DateOpen { get; }
public int Capacity { get; }
Dictionary<int, (IDocumentModel, int)> ShopDocuments { get; }
}
}

View File

@ -9,10 +9,14 @@ namespace LawFirmFileImplement
private readonly string BlankFileName = "Blank.xml";
private readonly string OrderFileName = "Order.xml";
private readonly string DocumentFileName = "Document.xml";
public List<Blank> Blanks { get; private set; }
private readonly string ShopFileName = "Shop.xml";
public List<Blank> Blanks { get; private set; }
public List<Order> Orders { get; private set; }
public List<Document> Documents { get; private set; }
public static DataFileSingleton GetInstance()
public List<Shop> Shops { get; private set; }
public static DataFileSingleton GetInstance()
{
if (instance == null)
{
@ -23,22 +27,22 @@ namespace LawFirmFileImplement
public void SaveBlanks() => SaveData(Blanks, BlankFileName, "Blanks", x => x.GetXElement);
public void SaveDocuments() => SaveData(Documents, DocumentFileName, "Documents", x => x.GetXElement);
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
private DataFileSingleton()
public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement);
private DataFileSingleton()
{
Blanks = LoadData(BlankFileName, "Blank", x => Blank.Create(x)!)!;
Documents = LoadData(DocumentFileName, "Document", x => Document.Create(x)!)!;
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
}
private static List<T>? LoadData<T>(string filename, string xmlNodeName,
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!;
}
private static List<T>? LoadData<T>(string filename, string xmlNodeName,
Func<XElement, T> selectFunction)
{
if (File.Exists(filename))
{
return XDocument.Load(filename)?.
Root?.
Elements(xmlNodeName)?.
Select(selectFunction)?.
ToList();
return
XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList();
}
return new List<T>();
}

View File

@ -0,0 +1,129 @@

using LawFirmContracts.BindingModels;
using LawFirmContracts.SearchModels;
using LawFirmContracts.StoragesContracts;
using LawFirmContracts.ViewModels;
using LawFirmDataModels.Models;
using LawFirmFileImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmFileImplement.Implements
{
public class ShopStorage : IShopStorage
{
private readonly DataFileSingleton source;
public ShopStorage()
{
source = DataFileSingleton.GetInstance();
}
public ShopViewModel? GetElement(ShopSearchModel model)
{
if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue)
{
return null;
}
return source.Shops
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
{
if (string.IsNullOrEmpty(model.ShopName))
{
return new();
}
/*return source.Shops
.Where(x => x.ShopName.Contains(model.ShopName))
.Select(x => x.GetViewModel)
.ToList();*/
return source.Shops
.Where(x => x.ShopName.Contains(model.ShopName))
.Select(x => x.GetViewModel)
.ToList();
}
public List<ShopViewModel> GetFullList()
{
return source.Shops.Select(x => x.GetViewModel).ToList();
}
public ShopViewModel? Insert(ShopBindingModel model)
{
model.Id = source.Shops.Count > 0 ? source.Shops.Max(x => x.Id) + 1 : 1;
var newShop = Shop.Create(model);
if (newShop == null)
{
return null;
}
source.Shops.Add(newShop);
source.SaveShops();
return newShop.GetViewModel;
}
public ShopViewModel? Update(ShopBindingModel model)
{
var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id);
if (shop == null)
{
return null;
}
shop.Update(model);
source.SaveShops();
return shop.GetViewModel;
}
public ShopViewModel? Delete(ShopBindingModel model)
{
var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id);
if (shop != null)
{
source.Shops.Remove(shop);
source.SaveShops();
return shop.GetViewModel;
}
return null;
}
public bool SellDocuments(IDocumentModel model, int count)
{
int availableQuantity = source.Shops.Select(x => x.ShopDocuments.FirstOrDefault(y => y.Key == model.Id).Value.Item2).Sum();
if (availableQuantity < count)
{
return false;
}
var shops = source.Shops.Where(x => x.ShopDocuments.ContainsKey(model.Id));
foreach (var shop in shops)
{
int countInCurrentShop = shop.ShopDocuments[model.Id].Item2;
if (countInCurrentShop <= count)
{
shop.ShopDocuments[model.Id] = (shop.ShopDocuments[model.Id].Item1, 0);
count -= countInCurrentShop;
}
else
{
shop.ShopDocuments[model.Id] = (shop.ShopDocuments[model.Id].Item1, countInCurrentShop - count);
count = 0;
}
Update(new ShopBindingModel
{
Id = shop.Id,
ShopName = shop.ShopName,
Address = shop.Address,
DateOpen = shop.DateOpen,
ShopDocuments = shop.ShopDocuments,
Capacity = shop.Capacity
});
if (count == 0)
{
return true;
}
}
return false;
}
}
}

View File

@ -0,0 +1,108 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.ViewModels;
using LawFirmDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace LawFirmFileImplement.Models
{
public class Shop : IShopModel
{
public int Id { get; private set; }
public string ShopName { get; private set; } = string.Empty;
public string Address { get; private set; } = string.Empty;
public DateTime DateOpen { get; private set; }
public int Capacity { get; private set; }
public Dictionary<int, int> DocumentsCount = new();
public Dictionary<int, (IDocumentModel, int)>? _documents = null;
public Dictionary<int, (IDocumentModel, int)> ShopDocuments
{
get
{
if (_documents == null)
{
var source = DataFileSingleton.GetInstance();
_documents = DocumentsCount.ToDictionary(
x => x.Key,
y => ((source.Documents.FirstOrDefault(z => z.Id == y.Key) as IDocumentModel)!,
y.Value)
);
}
return _documents;
}
}
public static Shop? Create(ShopBindingModel? model)
{
if (model == null)
{
return null;
}
return new Shop()
{
Id = model.Id,
ShopName = model.ShopName,
Address = model.Address,
DateOpen = model.DateOpen,
Capacity = model.Capacity,
DocumentsCount = model.ShopDocuments.ToDictionary(x => x.Key, x => x.Value.Item2)
};
}
public static Shop? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Shop()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
ShopName = element.Element("ShopName")!.Value,
Address = element.Element("Address")!.Value,
DateOpen = Convert.ToDateTime(element.Element("DateOpening")!.Value),
Capacity = Convert.ToInt32(element.Element("Capacity")!.Value),
DocumentsCount = element.Element("Documents")!.Elements("Document")
.ToDictionary(
x => Convert.ToInt32(x.Element("Key")?.Value),
x => Convert.ToInt32(x.Element("Value")?.Value))
};
}
public void Update(ShopBindingModel? model)
{
if (model == null)
{
return;
}
ShopName = model.ShopName;
Address = model.Address;
DateOpen = model.DateOpen;
Capacity = model.Capacity;
DocumentsCount = model.ShopDocuments.ToDictionary(x => x.Key, x => x.Value.Item2);
_documents = null;
}
public ShopViewModel GetViewModel => new()
{
Id = Id,
ShopName = ShopName,
Address = Address,
DateOpen = DateOpen,
Capacity = Capacity,
ShopDocuments = ShopDocuments
};
public XElement GetXElement => new("Shop",
new XAttribute("Id", Id),
new XElement("ShopName", ShopName),
new XElement("Address", Address),
new XElement("DateOpening", DateOpen.ToString()),
new XElement("Capacity", Capacity.ToString()),
new XElement("Documents", DocumentsCount.Select(x =>
new XElement("Document",
new XElement("Key", x.Key),
new XElement("Value", x.Value)))
.ToArray()));
}
}

View File

@ -8,11 +8,14 @@ namespace LawFirmListImplement
public List<Blank> Blanks { get; set; }
public List<Order> Orders { get; set; }
public List<Document> Documents { get; set; }
public List<Shop> Shops { get; set; }
private DataListSingleton()
{
Blanks = new List<Blank>();
Orders = new List<Order>();
Documents = new List<Document>();
Shops = new List<Shop>();
}
public static DataListSingleton GetInstance()
{

View File

@ -0,0 +1,118 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.SearchModels;
using LawFirmContracts.StoragesContracts;
using LawFirmContracts.ViewModels;
using LawFirmDataModels.Models;
using LawFirmListImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmListImplement.Implements
{
public class ShopStorage : IShopStorage
{
private readonly DataListSingleton _source;
public ShopStorage()
{
_source = DataListSingleton.GetInstance();
}
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 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 List<ShopViewModel> GetFullList()
{
var result = new List<ShopViewModel>();
foreach (var shop in _source.Shops)
{
result.Add(shop.GetViewModel);
}
return result;
}
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;
}
public bool SellDocuments(IDocumentModel model, int count)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,59 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.ViewModels;
using LawFirmDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmListImplement.Models
{
public class Shop : IShopModel
{
public string ShopName { get; set; } = string.Empty;
public string Address { get; set; } = string.Empty;
public DateTime DateOpen { get; set; }
public int Capacity { get; private set; }
public int Id { get; set; }
public Dictionary<int, (IDocumentModel, int)> ShopDocuments { get; private set; } = new Dictionary<int, (IDocumentModel, int)>();
public static Shop? Create(ShopBindingModel? model)
{
if (model == null)
{
return null;
}
return new Shop()
{
Id = model.Id,
ShopName = model.ShopName,
Address = model.Address,
DateOpen = model.DateOpen,
ShopDocuments = model.ShopDocuments
};
}
public void Update(ShopBindingModel? model)
{
if (model == null)
{
return;
}
ShopName = model.ShopName;
Address = model.Address;
DateOpen = model.DateOpen;
ShopDocuments = model.ShopDocuments;
}
public ShopViewModel GetViewModel => new()
{
Id = Id,
ShopName = ShopName,
Address = Address,
DateOpen = DateOpen,
ShopDocuments = ShopDocuments
};
}
}

View File

@ -0,0 +1,151 @@
namespace LawFirmView
{
partial class FormAddDocument
{
/// <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.labelShop = new System.Windows.Forms.Label();
this.labelDocument = new System.Windows.Forms.Label();
this.labelCount = new System.Windows.Forms.Label();
this.comboBoxShop = new System.Windows.Forms.ComboBox();
this.comboBoxDocument = new System.Windows.Forms.ComboBox();
this.numericUpDownCount = new System.Windows.Forms.NumericUpDown();
this.ButtonSave = new System.Windows.Forms.Button();
this.ButtonCancel = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).BeginInit();
this.SuspendLayout();
//
// labelShop
//
this.labelShop.AutoSize = true;
this.labelShop.Location = new System.Drawing.Point(10, 23);
this.labelShop.Name = "labelShop";
this.labelShop.Size = new System.Drawing.Size(54, 15);
this.labelShop.TabIndex = 0;
this.labelShop.Text = "Магазин";
//
// labelDocument
//
this.labelDocument.AutoSize = true;
this.labelDocument.Location = new System.Drawing.Point(10, 57);
this.labelDocument.Name = "labelDocument";
this.labelDocument.Size = new System.Drawing.Size(61, 15);
this.labelDocument.TabIndex = 1;
this.labelDocument.Text = "Документ";
//
// labelCount
//
this.labelCount.AutoSize = true;
this.labelCount.Location = new System.Drawing.Point(10, 95);
this.labelCount.Name = "labelCount";
this.labelCount.Size = new System.Drawing.Size(72, 15);
this.labelCount.TabIndex = 2;
this.labelCount.Text = "Количество";
//
// comboBoxShop
//
this.comboBoxShop.FormattingEnabled = true;
this.comboBoxShop.Location = new System.Drawing.Point(97, 23);
this.comboBoxShop.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.comboBoxShop.Name = "comboBoxShop";
this.comboBoxShop.Size = new System.Drawing.Size(323, 23);
this.comboBoxShop.TabIndex = 3;
//
// comboBoxDocument
//
this.comboBoxDocument.FormattingEnabled = true;
this.comboBoxDocument.Location = new System.Drawing.Point(97, 57);
this.comboBoxDocument.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.comboBoxDocument.Name = "comboBoxDocument";
this.comboBoxDocument.Size = new System.Drawing.Size(323, 23);
this.comboBoxDocument.TabIndex = 4;
//
// numericUpDownCount
//
this.numericUpDownCount.Location = new System.Drawing.Point(97, 90);
this.numericUpDownCount.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.numericUpDownCount.Name = "numericUpDownCount";
this.numericUpDownCount.Size = new System.Drawing.Size(323, 23);
this.numericUpDownCount.TabIndex = 5;
//
// ButtonSave
//
this.ButtonSave.Location = new System.Drawing.Point(244, 125);
this.ButtonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.ButtonSave.Name = "ButtonSave";
this.ButtonSave.Size = new System.Drawing.Size(82, 22);
this.ButtonSave.TabIndex = 6;
this.ButtonSave.Text = "Сохранить";
this.ButtonSave.UseVisualStyleBackColor = true;
this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
// ButtonCancel
//
this.ButtonCancel.Location = new System.Drawing.Point(338, 125);
this.ButtonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.ButtonCancel.Name = "ButtonCancel";
this.ButtonCancel.Size = new System.Drawing.Size(82, 22);
this.ButtonCancel.TabIndex = 7;
this.ButtonCancel.Text = "Отмена";
this.ButtonCancel.UseVisualStyleBackColor = true;
this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// FormAddDocument
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(430, 155);
this.Controls.Add(this.ButtonCancel);
this.Controls.Add(this.ButtonSave);
this.Controls.Add(this.numericUpDownCount);
this.Controls.Add(this.comboBoxDocument);
this.Controls.Add(this.comboBoxShop);
this.Controls.Add(this.labelCount);
this.Controls.Add(this.labelDocument);
this.Controls.Add(this.labelShop);
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.Name = "FormAddDocument";
this.Text = "Добавление документа";
this.Load += new System.EventHandler(this.FormAddDocument_Load);
((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Label labelShop;
private Label labelDocument;
private Label labelCount;
private ComboBox comboBoxShop;
private ComboBox comboBoxDocument;
private NumericUpDown numericUpDownCount;
private Button ButtonSave;
private Button ButtonCancel;
}
}

View File

@ -0,0 +1,108 @@
using Microsoft.Extensions.Logging;
using LawFirmContracts.BusinessLogicsContracts;
using LawFirmContracts.SearchModels;
namespace LawFirmView
{
public partial class FormAddDocument : Form
{
private readonly ILogger _logger;
private readonly IDocumentLogic _logicDocument;
private readonly IShopLogic _logicShop;
public FormAddDocument(ILogger<FormAddDocument> logger, IDocumentLogic logicDocument, IShopLogic logicShop)
{
InitializeComponent();
_logger = logger;
_logicDocument = logicDocument;
_logicShop = logicShop;
}
private void FormAddDocument_Load(object sender, EventArgs e)
{
_logger.LogInformation("Загрузка списка документов для пополнения");
try
{
var list = _logicDocument.ReadList(null);
if (list != null)
{
comboBoxDocument.DisplayMember = "DocumentName";
comboBoxDocument.ValueMember = "Id";
comboBoxDocument.DataSource = list;
comboBoxDocument.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки списка документов");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
_logger.LogInformation("Загрузка списка магазинов для пополнения");
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, "Ошибка загрузки списка магазинов");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(numericUpDownCount.Text))
{
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxDocument.SelectedValue == null)
{
MessageBox.Show("Выберите документ", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxShop.SelectedValue == null)
{
MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Пополнение магазина");
try
{
var operationResult = _logicShop.AddDocument(new ShopSearchModel
{
Id = Convert.ToInt32(comboBoxShop.SelectedValue)
},
_logicDocument.ReadElement(new DocumentSearchModel()
{
Id = Convert.ToInt32(comboBoxDocument.SelectedValue)
})!, Convert.ToInt32(numericUpDownCount.Text));
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

@ -28,136 +28,170 @@
/// </summary>
private void InitializeComponent()
{
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.бланкиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.документыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonCreateOrder = new System.Windows.Forms.Button();
this.buttonTakeOrderInWork = new System.Windows.Forms.Button();
this.buttonOrderReady = new System.Windows.Forms.Button();
this.buttonIssuedOrder = new System.Windows.Forms.Button();
this.buttonUpdate = new System.Windows.Forms.Button();
this.menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// menuStrip1
//
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.бланкиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.документыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonCreateOrder = new System.Windows.Forms.Button();
this.buttonTakeOrderInWork = new System.Windows.Forms.Button();
this.buttonOrderReady = new System.Windows.Forms.Button();
this.buttonIssuedOrder = new System.Windows.Forms.Button();
this.buttonUpdate = new System.Windows.Forms.Button();
this.buttonAddDocument = new System.Windows.Forms.Button();
this.buttonSellDocument = new System.Windows.Forms.Button();
this.menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// menuStrip1
//
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.справочникиToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(800, 24);
this.menuStrip1.TabIndex = 0;
this.menuStrip1.Text = "menuStrip1";
//
// справочникиToolStripMenuItem
//
this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(800, 24);
this.menuStrip1.TabIndex = 0;
this.menuStrip1.Text = "menuStrip1";
//
// справочникиToolStripMenuItem
//
this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.бланкиToolStripMenuItem,
this.документыToolStripMenuItem});
this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20);
this.справочникиToolStripMenuItem.Text = "Справочники";
//
// бланкиToolStripMenuItem
//
this.бланкиToolStripMenuItem.Name = "бланкиToolStripMenuItem";
this.бланкиToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.бланкиToolStripMenuItem.Text = "Бланки";
this.бланкиToolStripMenuItem.Click += new System.EventHandler(this.BlanksToolStripMenuItem_Click);
//
// документыToolStripMenuItem
//
this.документыToolStripMenuItem.Name = окументыToolStripMenuItem";
this.документыToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.документыToolStripMenuItem.Text = "Документы";
this.документыToolStripMenuItem.Click += new System.EventHandler(this.DocumentsToolStripMenuItem_Click);
//
// dataGridView
//
this.dataGridView.AllowUserToAddRows = false;
this.dataGridView.AllowUserToDeleteRows = false;
this.dataGridView.BackgroundColor = System.Drawing.Color.White;
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(12, 27);
this.dataGridView.Name = "dataGridView";
this.dataGridView.ReadOnly = true;
this.dataGridView.RowTemplate.Height = 25;
this.dataGridView.Size = new System.Drawing.Size(566, 411);
this.dataGridView.TabIndex = 1;
//
// buttonCreateOrder
//
this.buttonCreateOrder.Location = new System.Drawing.Point(605, 27);
this.buttonCreateOrder.Name = "buttonCreateOrder";
this.buttonCreateOrder.Size = new System.Drawing.Size(168, 23);
this.buttonCreateOrder.TabIndex = 2;
this.buttonCreateOrder.Text = "Создать заказ";
this.buttonCreateOrder.UseVisualStyleBackColor = true;
this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click);
//
// buttonTakeOrderInWork
//
this.buttonTakeOrderInWork.Location = new System.Drawing.Point(605, 56);
this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
this.buttonTakeOrderInWork.Size = new System.Drawing.Size(168, 23);
this.buttonTakeOrderInWork.TabIndex = 3;
this.buttonTakeOrderInWork.Text = "Отдать на выполнение";
this.buttonTakeOrderInWork.UseVisualStyleBackColor = true;
this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click);
//
// buttonOrderReady
//
this.buttonOrderReady.Location = new System.Drawing.Point(605, 85);
this.buttonOrderReady.Name = "buttonOrderReady";
this.buttonOrderReady.Size = new System.Drawing.Size(168, 23);
this.buttonOrderReady.TabIndex = 4;
this.buttonOrderReady.Text = "Заказ готов";
this.buttonOrderReady.UseVisualStyleBackColor = true;
this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click);
//
// buttonIssuedOrder
//
this.buttonIssuedOrder.Location = new System.Drawing.Point(605, 114);
this.buttonIssuedOrder.Name = "buttonIssuedOrder";
this.buttonIssuedOrder.Size = new System.Drawing.Size(168, 23);
this.buttonIssuedOrder.TabIndex = 5;
this.buttonIssuedOrder.Text = "Заказ выдан";
this.buttonIssuedOrder.UseVisualStyleBackColor = true;
this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click);
//
// buttonUpdate
//
this.buttonUpdate.Location = new System.Drawing.Point(605, 143);
this.buttonUpdate.Name = "buttonUpdate";
this.buttonUpdate.Size = new System.Drawing.Size(168, 23);
this.buttonUpdate.TabIndex = 6;
this.buttonUpdate.Text = "Обновить список";
this.buttonUpdate.UseVisualStyleBackColor = true;
this.buttonUpdate.Click += new System.EventHandler(this.ButtonRef_Click);
//
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.buttonUpdate);
this.Controls.Add(this.buttonIssuedOrder);
this.Controls.Add(this.buttonOrderReady);
this.Controls.Add(this.buttonTakeOrderInWork);
this.Controls.Add(this.buttonCreateOrder);
this.Controls.Add(this.dataGridView);
this.Controls.Add(this.menuStrip1);
this.MainMenuStrip = this.menuStrip1;
this.Name = "FormMain";
this.Text = "Юридическая фирма";
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
this.документыToolStripMenuItem,
this.магазиныToolStripMenuItem});
this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20);
this.справочникиToolStripMenuItem.Text = "Справочники";
//
// бланкиToolStripMenuItem
//
this.бланкиToolStripMenuItem.Name = "бланкиToolStripMenuItem";
this.бланкиToolStripMenuItem.Size = new System.Drawing.Size(137, 22);
this.бланкиToolStripMenuItem.Text = "Бланки";
this.бланкиToolStripMenuItem.Click += new System.EventHandler(this.BlanksToolStripMenuItem_Click);
//
// документыToolStripMenuItem
//
this.документыToolStripMenuItem.Name = окументыToolStripMenuItem";
this.документыToolStripMenuItem.Size = new System.Drawing.Size(137, 22);
this.документыToolStripMenuItem.Text = "Документы";
this.документыToolStripMenuItem.Click += new System.EventHandler(this.DocumentsToolStripMenuItem_Click);
//
// магазиныToolStripMenuItem
//
this.магазиныToolStripMenuItem.Name = агазиныToolStripMenuItem";
this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(137, 22);
this.магазиныToolStripMenuItem.Text = "Магазины";
this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.ShopToolStripMenuItem_Click);
//
// dataGridView
//
this.dataGridView.AllowUserToAddRows = false;
this.dataGridView.AllowUserToDeleteRows = false;
this.dataGridView.BackgroundColor = System.Drawing.Color.White;
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(12, 27);
this.dataGridView.Name = "dataGridView";
this.dataGridView.ReadOnly = true;
this.dataGridView.RowTemplate.Height = 25;
this.dataGridView.Size = new System.Drawing.Size(566, 411);
this.dataGridView.TabIndex = 1;
//
// buttonCreateOrder
//
this.buttonCreateOrder.Location = new System.Drawing.Point(605, 27);
this.buttonCreateOrder.Name = "buttonCreateOrder";
this.buttonCreateOrder.Size = new System.Drawing.Size(168, 23);
this.buttonCreateOrder.TabIndex = 2;
this.buttonCreateOrder.Text = "Создать заказ";
this.buttonCreateOrder.UseVisualStyleBackColor = true;
this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click);
//
// buttonTakeOrderInWork
//
this.buttonTakeOrderInWork.Location = new System.Drawing.Point(605, 56);
this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
this.buttonTakeOrderInWork.Size = new System.Drawing.Size(168, 23);
this.buttonTakeOrderInWork.TabIndex = 3;
this.buttonTakeOrderInWork.Text = "Отдать на выполнение";
this.buttonTakeOrderInWork.UseVisualStyleBackColor = true;
this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click);
//
// buttonOrderReady
//
this.buttonOrderReady.Location = new System.Drawing.Point(605, 85);
this.buttonOrderReady.Name = "buttonOrderReady";
this.buttonOrderReady.Size = new System.Drawing.Size(168, 23);
this.buttonOrderReady.TabIndex = 4;
this.buttonOrderReady.Text = "Заказ готов";
this.buttonOrderReady.UseVisualStyleBackColor = true;
this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click);
//
// buttonIssuedOrder
//
this.buttonIssuedOrder.Location = new System.Drawing.Point(605, 114);
this.buttonIssuedOrder.Name = "buttonIssuedOrder";
this.buttonIssuedOrder.Size = new System.Drawing.Size(168, 23);
this.buttonIssuedOrder.TabIndex = 5;
this.buttonIssuedOrder.Text = "Заказ выдан";
this.buttonIssuedOrder.UseVisualStyleBackColor = true;
this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click);
//
// buttonUpdate
//
this.buttonUpdate.Location = new System.Drawing.Point(605, 143);
this.buttonUpdate.Name = "buttonUpdate";
this.buttonUpdate.Size = new System.Drawing.Size(168, 23);
this.buttonUpdate.TabIndex = 6;
this.buttonUpdate.Text = "Обновить список";
this.buttonUpdate.UseVisualStyleBackColor = true;
this.buttonUpdate.Click += new System.EventHandler(this.ButtonRef_Click);
//
// buttonAddDocument
//
this.buttonAddDocument.Location = new System.Drawing.Point(605, 172);
this.buttonAddDocument.Name = "buttonAddDocument";
this.buttonAddDocument.Size = new System.Drawing.Size(168, 23);
this.buttonAddDocument.TabIndex = 7;
this.buttonAddDocument.Text = "Добавить документ";
this.buttonAddDocument.UseVisualStyleBackColor = true;
this.buttonAddDocument.Click += new System.EventHandler(this.ButtonAddDocument_Click);
//
// buttonSellDocument
//
this.buttonSellDocument.Location = new System.Drawing.Point(605, 201);
this.buttonSellDocument.Name = "buttonSellDocument";
this.buttonSellDocument.Size = new System.Drawing.Size(168, 23);
this.buttonSellDocument.TabIndex = 8;
this.buttonSellDocument.Text = "Продать документ";
this.buttonSellDocument.UseVisualStyleBackColor = true;
this.buttonSellDocument.Click += new System.EventHandler(this.ButtonSellDocument_Click);
//
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.buttonSellDocument);
this.Controls.Add(this.buttonAddDocument);
this.Controls.Add(this.buttonUpdate);
this.Controls.Add(this.buttonIssuedOrder);
this.Controls.Add(this.buttonOrderReady);
this.Controls.Add(this.buttonTakeOrderInWork);
this.Controls.Add(this.buttonCreateOrder);
this.Controls.Add(this.dataGridView);
this.Controls.Add(this.menuStrip1);
this.MainMenuStrip = this.menuStrip1;
this.Name = "FormMain";
this.Text = "Юридическая фирма";
this.Load += new System.EventHandler(this.FormMain_Load);
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
@ -173,5 +207,8 @@
private Button buttonUpdate;
private ToolStripMenuItem бланкиToolStripMenuItem;
private ToolStripMenuItem документыToolStripMenuItem;
}
private ToolStripMenuItem магазиныToolStripMenuItem;
private Button buttonAddDocument;
private Button buttonSellDocument;
}
}

View File

@ -88,12 +88,7 @@ namespace LawFirmView
{
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel
{
Id = id,
DocumentId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["DocumentId"].Value),
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())
Id = id
});
if (!operationResult)
{
@ -120,12 +115,7 @@ namespace LawFirmView
var operationResult = _orderLogic.DeliveryOrder(new
OrderBindingModel
{
Id = id,
DocumentId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["DocumentId"].Value),
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())
Id = id
});
if (!operationResult)
{
@ -162,5 +152,34 @@ namespace LawFirmView
form.ShowDialog();
}
}
}
private void ShopToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShops));
if (service is FormShops form)
{
form.ShowDialog();
}
}
private void ButtonAddDocument_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormAddDocument));
if (service is FormAddDocument form)
{
form.ShowDialog();
LoadData();
}
}
private void ButtonSellDocument_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSellDocuments));
if (service is FormSellDocuments form)
{
form.ShowDialog();
LoadData();
}
}
}
}

View File

@ -0,0 +1,120 @@
namespace LawFirmView
{
partial class FormSellDocuments
{
/// <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.ButtonCancel = new System.Windows.Forms.Button();
this.comboBoxDocuments = new System.Windows.Forms.ComboBox();
this.numericUpDownCount = new System.Windows.Forms.NumericUpDown();
this.labelDocument = new System.Windows.Forms.Label();
this.labelCount = new System.Windows.Forms.Label();
this.ButtonSave = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).BeginInit();
this.SuspendLayout();
//
// ButtonCancel
//
this.ButtonCancel.Location = new System.Drawing.Point(266, 153);
this.ButtonCancel.Name = "ButtonCancel";
this.ButtonCancel.Size = new System.Drawing.Size(94, 29);
this.ButtonCancel.TabIndex = 1;
this.ButtonCancel.Text = "Отмена";
this.ButtonCancel.UseVisualStyleBackColor = true;
this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// comboBoxDocuments
//
this.comboBoxDocuments.FormattingEnabled = true;
this.comboBoxDocuments.Location = new System.Drawing.Point(144, 38);
this.comboBoxDocuments.Name = "comboBoxDocuments";
this.comboBoxDocuments.Size = new System.Drawing.Size(216, 28);
this.comboBoxDocuments.TabIndex = 2;
//
// numericUpDownCount
//
this.numericUpDownCount.Location = new System.Drawing.Point(144, 102);
this.numericUpDownCount.Name = "numericUpDownCount";
this.numericUpDownCount.Size = new System.Drawing.Size(216, 27);
this.numericUpDownCount.TabIndex = 3;
//
// labelDocument
//
this.labelDocument.AutoSize = true;
this.labelDocument.Location = new System.Drawing.Point(34, 38);
this.labelDocument.Name = "labelDocument";
this.labelDocument.Size = new System.Drawing.Size(69, 20);
this.labelDocument.TabIndex = 4;
this.labelDocument.Text = "Корабль";
//
// labelCount
//
this.labelCount.AutoSize = true;
this.labelCount.Location = new System.Drawing.Point(34, 109);
this.labelCount.Name = "labelCount";
this.labelCount.Size = new System.Drawing.Size(90, 20);
this.labelCount.TabIndex = 5;
this.labelCount.Text = "Количество";
//
// ButtonSave
//
this.ButtonSave.Location = new System.Drawing.Point(144, 153);
this.ButtonSave.Name = "ButtonSave";
this.ButtonSave.Size = new System.Drawing.Size(94, 29);
this.ButtonSave.TabIndex = 6;
this.ButtonSave.Text = "Сохранить";
this.ButtonSave.UseVisualStyleBackColor = true;
this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
// FormSellDocuments
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(373, 194);
this.Controls.Add(this.ButtonSave);
this.Controls.Add(this.labelCount);
this.Controls.Add(this.labelDocument);
this.Controls.Add(this.numericUpDownCount);
this.Controls.Add(this.comboBoxDocuments);
this.Controls.Add(this.ButtonCancel);
this.Name = "FormSellDocuments";
this.Text = "Продажа документов";
((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Button ButtonCancel;
private ComboBox comboBoxDocuments;
private NumericUpDown numericUpDownCount;
private Label labelDocument;
private Label labelCount;
private Button ButtonSave;
}
}

View File

@ -0,0 +1,86 @@
using Microsoft.Extensions.Logging;
using LawFirmContracts.BusinessLogicsContracts;
using LawFirmContracts.ViewModels;
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 LawFirmView
{
public partial class FormSellDocuments : Form
{
private readonly ILogger _logger;
private readonly IShopLogic _shopLogic;
private readonly IDocumentLogic _documentLogic;
private readonly List<DocumentViewModel>? _listDocument;
public FormSellDocuments(ILogger<FormSellDocuments> logger, IShopLogic shopLogic, IDocumentLogic documentLogic)
{
InitializeComponent();
_logger = logger;
_shopLogic = shopLogic;
_documentLogic = documentLogic;
_listDocument = documentLogic.ReadList(null);
if (_listDocument != null)
{
comboBoxDocuments.DisplayMember = "DocumentName";
comboBoxDocuments.ValueMember = "Id";
comboBoxDocuments.DataSource=_listDocument;
comboBoxDocuments.SelectedItem = null;
}
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (comboBoxDocuments.SelectedValue == null)
{
MessageBox.Show("Выберите корабль", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(numericUpDownCount.Text))
{
MessageBox.Show("Заполните количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Продажа поездок");
try
{
var document = _documentLogic.ReadElement(new()
{
Id = (int)comboBoxDocuments.SelectedValue
});
if (document == null)
{
throw new Exception("Корабль не найден. Дополнительная информация в логах.");
}
var operationResult = _shopLogic.SellDocuments(
model: document,
count: (int)numericUpDownCount.Value
);
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>

219
LawFirm/LawFirmView/FormShop.Designer.cs generated Normal file
View File

@ -0,0 +1,219 @@
namespace LawFirmView
{
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.labelShop = new System.Windows.Forms.Label();
this.labelAddress = new System.Windows.Forms.Label();
this.labelDate = new System.Windows.Forms.Label();
this.textBoxName = new System.Windows.Forms.TextBox();
this.textBoxAddress = new System.Windows.Forms.TextBox();
this.dateTimePickerDateOpen = new System.Windows.Forms.DateTimePicker();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.DocumentName = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ButtonSave = new System.Windows.Forms.Button();
this.ButtonCancel = new System.Windows.Forms.Button();
this.numericUpDownCapacity = new System.Windows.Forms.NumericUpDown();
this.labelCapacity = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownCapacity)).BeginInit();
this.SuspendLayout();
//
// labelShop
//
this.labelShop.AutoSize = true;
this.labelShop.Location = new System.Drawing.Point(10, 16);
this.labelShop.Name = "labelShop";
this.labelShop.Size = new System.Drawing.Size(54, 15);
this.labelShop.TabIndex = 0;
this.labelShop.Text = "Магазин";
//
// labelAddress
//
this.labelAddress.AutoSize = true;
this.labelAddress.Location = new System.Drawing.Point(156, 16);
this.labelAddress.Name = "labelAddress";
this.labelAddress.Size = new System.Drawing.Size(40, 15);
this.labelAddress.TabIndex = 1;
this.labelAddress.Text = "Адрес";
//
// labelDate
//
this.labelDate.AutoSize = true;
this.labelDate.Location = new System.Drawing.Point(375, 16);
this.labelDate.Name = "labelDate";
this.labelDate.Size = new System.Drawing.Size(87, 15);
this.labelDate.TabIndex = 2;
this.labelDate.Text = "Дата открытия";
//
// textBoxName
//
this.textBoxName.Location = new System.Drawing.Point(10, 33);
this.textBoxName.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.textBoxName.Name = "textBoxName";
this.textBoxName.Size = new System.Drawing.Size(140, 23);
this.textBoxName.TabIndex = 3;
//
// textBoxAddress
//
this.textBoxAddress.Location = new System.Drawing.Point(156, 33);
this.textBoxAddress.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.textBoxAddress.Name = "textBoxAddress";
this.textBoxAddress.Size = new System.Drawing.Size(216, 23);
this.textBoxAddress.TabIndex = 4;
//
// dateTimePickerDateOpen
//
this.dateTimePickerDateOpen.Location = new System.Drawing.Point(375, 33);
this.dateTimePickerDateOpen.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.dateTimePickerDateOpen.Name = "dateTimePickerDateOpen";
this.dateTimePickerDateOpen.Size = new System.Drawing.Size(123, 23);
this.dateTimePickerDateOpen.TabIndex = 5;
//
// dataGridView
//
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.ID,
this.DocumentName,
this.Count});
this.dataGridView.Location = new System.Drawing.Point(10, 58);
this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 29;
this.dataGridView.Size = new System.Drawing.Size(623, 248);
this.dataGridView.TabIndex = 6;
//
// ID
//
this.ID.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.ID.HeaderText = "ID";
this.ID.MinimumWidth = 6;
this.ID.Name = "ID";
this.ID.Visible = false;
//
// DocumentName
//
this.DocumentName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.DocumentName.HeaderText = "DocumentName";
this.DocumentName.MinimumWidth = 6;
this.DocumentName.Name = "DocumentName";
//
// Count
//
this.Count.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.Count.HeaderText = "Count";
this.Count.MinimumWidth = 6;
this.Count.Name = "Count";
//
// ButtonSave
//
this.ButtonSave.Location = new System.Drawing.Point(429, 310);
this.ButtonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.ButtonSave.Name = "ButtonSave";
this.ButtonSave.Size = new System.Drawing.Size(97, 22);
this.ButtonSave.TabIndex = 7;
this.ButtonSave.Text = "Сохранить";
this.ButtonSave.UseVisualStyleBackColor = true;
this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
// ButtonCancel
//
this.ButtonCancel.Location = new System.Drawing.Point(551, 310);
this.ButtonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.ButtonCancel.Name = "ButtonCancel";
this.ButtonCancel.Size = new System.Drawing.Size(82, 22);
this.ButtonCancel.TabIndex = 8;
this.ButtonCancel.Text = "Отмена";
this.ButtonCancel.UseVisualStyleBackColor = true;
this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// numericUpDownCapacity
//
this.numericUpDownCapacity.Location = new System.Drawing.Point(504, 33);
this.numericUpDownCapacity.Name = "numericUpDownCapacity";
this.numericUpDownCapacity.Size = new System.Drawing.Size(120, 23);
this.numericUpDownCapacity.TabIndex = 9;
//
// labelCapacity
//
this.labelCapacity.AutoSize = true;
this.labelCapacity.Location = new System.Drawing.Point(504, 16);
this.labelCapacity.Name = "labelCapacity";
this.labelCapacity.Size = new System.Drawing.Size(134, 15);
this.labelCapacity.TabIndex = 10;
this.labelCapacity.Text = "Вместимость магазина";
//
// FormShop
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(648, 338);
this.Controls.Add(this.labelCapacity);
this.Controls.Add(this.numericUpDownCapacity);
this.Controls.Add(this.ButtonCancel);
this.Controls.Add(this.ButtonSave);
this.Controls.Add(this.dataGridView);
this.Controls.Add(this.dateTimePickerDateOpen);
this.Controls.Add(this.textBoxAddress);
this.Controls.Add(this.textBoxName);
this.Controls.Add(this.labelDate);
this.Controls.Add(this.labelAddress);
this.Controls.Add(this.labelShop);
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.Name = "FormShop";
this.Text = "Магазин";
this.Load += new System.EventHandler(this.FormShop_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownCapacity)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Label labelShop;
private Label labelAddress;
private Label labelDate;
private TextBox textBoxName;
private TextBox textBoxAddress;
private DateTimePicker dateTimePickerDateOpen;
private DataGridView dataGridView;
private Button ButtonSave;
private Button ButtonCancel;
private DataGridViewTextBoxColumn ID;
private DataGridViewTextBoxColumn DocumentName;
private DataGridViewTextBoxColumn Count;
private NumericUpDown numericUpDownCapacity;
private Label labelCapacity;
}
}

View File

@ -0,0 +1,124 @@
using LawFirmContracts.BusinessLogicsContracts;
using LawFirmContracts.SearchModels;
using LawFirmDataModels.Models;
using Microsoft.Extensions.Logging;
using LawFirmContracts.BindingModels;
namespace LawFirmView
{
public partial class FormShop : Form
{
private readonly ILogger _logger;
private readonly IShopLogic _logic;
private int? _id;
private Dictionary<int, (IDocumentModel, int)> _shopDocuments;
public int Id { set { _id = value; } }
public FormShop(ILogger<FormShop> logger, IShopLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
_shopDocuments = new Dictionary<int, (IDocumentModel, 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.ToString();
dateTimePickerDateOpen.Text = view.DateOpen.ToString();
numericUpDownCapacity.Value = view.Capacity;
_shopDocuments = view.ShopDocuments ?? new Dictionary<int, (IDocumentModel, int)>();
LoadData();
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки магазина");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void LoadData()
{
_logger.LogInformation("Загрузка документов магазина");
try
{
if (_shopDocuments != null)
{
dataGridView.Rows.Clear();
foreach (var element in _shopDocuments)
{
dataGridView.Rows.Add(new object[] { element.Key, element.Value.Item1.DocumentName, element.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(dateTimePickerDateOpen.Text))
{
MessageBox.Show("Заполните дату", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение магазина");
try
{
var model = new ShopBindingModel
{
Id = _id ?? 0,
ShopName = textBoxName.Text,
Address = textBoxAddress.Text,
DateOpen = DateTime.Parse(dateTimePickerDateOpen.Text),
Capacity = (int)numericUpDownCapacity.Value,
ShopDocuments = _shopDocuments
};
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,69 @@
<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>
<metadata name="ID.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="DocumentName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Count.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

123
LawFirm/LawFirmView/FormShops.Designer.cs generated Normal file
View File

@ -0,0 +1,123 @@
namespace LawFirmView
{
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.dataGridView = new System.Windows.Forms.DataGridView();
this.ButtonAdd = new System.Windows.Forms.Button();
this.ButtonUpd = new System.Windows.Forms.Button();
this.ButtonDel = new System.Windows.Forms.Button();
this.ButtonRef = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// dataGridView
//
this.dataGridView.BackgroundColor = System.Drawing.Color.White;
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(3, 2, 3, 2);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 29;
this.dataGridView.Size = new System.Drawing.Size(552, 338);
this.dataGridView.TabIndex = 0;
//
// ButtonAdd
//
this.ButtonAdd.Location = new System.Drawing.Point(586, 25);
this.ButtonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.ButtonAdd.Name = "ButtonAdd";
this.ButtonAdd.Size = new System.Drawing.Size(93, 36);
this.ButtonAdd.TabIndex = 1;
this.ButtonAdd.Text = "Создать";
this.ButtonAdd.UseVisualStyleBackColor = true;
this.ButtonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
//
// ButtonUpd
//
this.ButtonUpd.Location = new System.Drawing.Point(586, 76);
this.ButtonUpd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.ButtonUpd.Name = "ButtonUpd";
this.ButtonUpd.Size = new System.Drawing.Size(93, 36);
this.ButtonUpd.TabIndex = 2;
this.ButtonUpd.Text = "Изменить";
this.ButtonUpd.UseVisualStyleBackColor = true;
this.ButtonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
//
// ButtonDel
//
this.ButtonDel.Location = new System.Drawing.Point(586, 124);
this.ButtonDel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.ButtonDel.Name = "ButtonDel";
this.ButtonDel.Size = new System.Drawing.Size(93, 36);
this.ButtonDel.TabIndex = 3;
this.ButtonDel.Text = "Удалить";
this.ButtonDel.UseVisualStyleBackColor = true;
this.ButtonDel.Click += new System.EventHandler(this.ButtonDel_Click);
//
// ButtonRef
//
this.ButtonRef.Location = new System.Drawing.Point(586, 172);
this.ButtonRef.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.ButtonRef.Name = "ButtonRef";
this.ButtonRef.Size = new System.Drawing.Size(93, 36);
this.ButtonRef.TabIndex = 4;
this.ButtonRef.Text = "Обновить";
this.ButtonRef.UseVisualStyleBackColor = true;
this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click);
//
// FormShops
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(700, 338);
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.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.Name = "FormShops";
this.Text = "Магазины";
this.Load += new System.EventHandler(this.FormShops_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private DataGridView dataGridView;
private Button ButtonAdd;
private Button ButtonUpd;
private Button ButtonDel;
private Button ButtonRef;
}
}

View File

@ -0,0 +1,104 @@
using Microsoft.Extensions.Logging;
using LawFirmContracts.BindingModels;
using LawFirmContracts.BusinessLogicsContracts;
namespace LawFirmView
{
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 FormShops_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["ShopDocuments"].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

@ -36,10 +36,12 @@ namespace LawFirmView
services.AddTransient<IBlankStorage, BlankStorage>();
services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<IDocumentStorage, DocumentStorage>();
services.AddTransient<IShopStorage, ShopStorage>();
services.AddTransient<IBlankLogic, BlankLogic>();
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<IDocumentLogic, DocumentLogic>();
services.AddTransient<IShopLogic, ShopLogic>();
services.AddTransient<FormMain>();
services.AddTransient<FormBlank>();
@ -48,6 +50,10 @@ namespace LawFirmView
services.AddTransient<FormDocument>();
services.AddTransient<FormDocumentBlank>();
services.AddTransient<FormDocuments>();
}
services.AddTransient<FormShop>();
services.AddTransient<FormShops>();
services.AddTransient<FormAddDocument>();
services.AddTransient<FormSellDocuments>();
}
}
}