Kashin M.I. Lab work 8 hard #17
@ -36,6 +36,7 @@ namespace PrecastConcretePlantView
|
||||
{
|
||||
column.HeaderText = columnAttr.Title;
|
||||
column.Visible = columnAttr.Visible;
|
||||
column.DefaultCellStyle.Format = columnAttr.Format;
|
||||
if (columnAttr.IsUseAutoSize)
|
||||
{
|
||||
column.AutoSizeMode = (DataGridViewAutoSizeColumnMode)Enum.Parse(typeof(DataGridViewAutoSizeColumnMode), columnAttr.GridViewAutoSize.ToString());
|
||||
|
@ -220,11 +220,8 @@ namespace PrecastConcretePlantView
|
||||
|
||||
private void МагазинtoolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormShops));
|
||||
if (service is FormShops form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
var form = DependencyManager.Instance.Resolve<FormShops>();
|
||||
form.ShowDialog();
|
||||
}
|
||||
|
||||
private void списокМагазиновToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
@ -239,20 +236,14 @@ namespace PrecastConcretePlantView
|
||||
|
||||
private void магазиныСИзделиямиToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormReportShopReinforcedies));
|
||||
if (service is FormReportShopReinforcedies form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
var form = DependencyManager.Instance.Resolve<FormReportShopReinforcedies>();
|
||||
form.ShowDialog();
|
||||
}
|
||||
|
||||
private void списокГруппЗаказовToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormReportGroupOrders));
|
||||
if (service is FormReportGroupOrders form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
var form = DependencyManager.Instance.Resolve<FormReportGroupOrders>();
|
||||
form.ShowDialog();
|
||||
}
|
||||
|
||||
private void письмаToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
@ -288,21 +279,15 @@ namespace PrecastConcretePlantView
|
||||
|
||||
private void buttonSellReinforced_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormSellReinforced));
|
||||
|
||||
if (service is FormSellReinforced form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
|
||||
var form = DependencyManager.Instance.Resolve<FormSellReinforced>();
|
||||
form.ShowDialog();
|
||||
}
|
||||
|
||||
private void buttonAddReinforcedInShop_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormReinforcedShop));
|
||||
if (service is FormReinforcedShop form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
var form = DependencyManager.Instance.Resolve<FormReinforcedShop>();
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PrecastConcretePlantContracts.BindingModels;
|
||||
using PrecastConcretePlantContracts.BusinessLogicsContracts;
|
||||
using PrecastConcretePlantContracts.DI;
|
||||
using PrecastConcretePlantView;
|
||||
|
||||
namespace PrecastConcretePlantView
|
||||
@ -23,16 +24,7 @@ namespace PrecastConcretePlantView
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = _logic.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
dataGridView.Columns["ShopReinforcedies"].Visible = false;
|
||||
dataGridView.Columns["Name"].AutoSizeMode =
|
||||
DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
dataGridView.FillAndConfigGrid(_logic.ReadList(null));
|
||||
_logger.LogInformation("Загрузка магазинов");
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -44,20 +36,17 @@ namespace PrecastConcretePlantView
|
||||
}
|
||||
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormShop));
|
||||
if (service is FormShop form)
|
||||
var form = DependencyManager.Instance.Resolve<FormComponent>();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
private void ButtonUpd_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormShop));
|
||||
var service = DependencyManager.Instance.Resolve<FormShop>();
|
||||
if (service is FormShop form)
|
||||
{
|
||||
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
|
@ -11,6 +11,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using PrecastConcretePlantContracts.ViewModels;
|
||||
using PrecastConcretePlantContracts.DI;
|
||||
|
||||
namespace PrecastConcretePlantView
|
||||
{
|
||||
@ -38,18 +39,11 @@ namespace PrecastConcretePlantView
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = _logic.ReadList(new()
|
||||
dataGridView.FillAndConfigGrid(_logic.ReadList(new()
|
||||
{
|
||||
Page = currentPage,
|
||||
PageSize = pageSize,
|
||||
});
|
||||
if (list != null)
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["ClientId"].Visible = false;
|
||||
dataGridView.Columns["MessageId"].Visible = false;
|
||||
dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
}));
|
||||
_logger.LogInformation("Загрузка списка писем");
|
||||
labelInfoPages.Text = $"{currentPage} страница";
|
||||
return true;
|
||||
@ -99,28 +93,12 @@ namespace PrecastConcretePlantView
|
||||
|
||||
private void dataGridView_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormReplyMail));
|
||||
if (service is FormReplyMail form)
|
||||
{
|
||||
form.MessageId = (string)dataGridView.Rows[e.RowIndex].Cells["MessageId"].Value;
|
||||
form.ShowDialog();
|
||||
MailLoad();
|
||||
}
|
||||
var form = DependencyManager.Instance.Resolve<FormReplyMail>();
|
||||
form.MessageId = (string)dataGridView.Rows[e.RowIndex].Cells["MessageId"].Value;
|
||||
form.ShowDialog();
|
||||
MailLoad();
|
||||
}
|
||||
|
||||
}
|
||||
private void FormViewMail_Load(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
dataGridView.FillAndConfigGrid(_logic.ReadList(null));
|
||||
_logger.LogInformation("Загрузка списка писем");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки писем");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,48 +54,6 @@ namespace PrecastConcretePlantView
|
||||
option.SetMinimumLevel(LogLevel.Information);
|
||||
option.AddNLog("nlog.config");
|
||||
});
|
||||
services.AddTransient<IClientStorage, ClientStorage>();
|
||||
services.AddTransient<IComponentStorage, ComponentStorage>();
|
||||
services.AddTransient<IOrderStorage, OrderStorage>();
|
||||
services.AddTransient<IReinforcedStorage, ReinforcedStorage>();
|
||||
services.AddTransient<IClientLogic, ClientLogic>();
|
||||
services.AddTransient<IShopStorage, ShopStorage>();
|
||||
services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||
services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
services.AddTransient<IReinforcedLogic, ReinforcedLogic>();
|
||||
services.AddTransient<IReportLogic, ReportLogic>();
|
||||
services.AddTransient<IImplementerStorage, ImplementerStorage>();
|
||||
services.AddTransient<IImplementerLogic, ImplementerLogic>();
|
||||
services.AddTransient<IWorkProcess, WorkModeling>();
|
||||
services.AddTransient<IShopLogic, ShopLogic>();
|
||||
|
||||
services.AddTransient<IMessageInfoStorage, MessageInfoStorage>();
|
||||
services.AddTransient<IMessageInfoLogic, MessageInfoLogic>();
|
||||
services.AddTransient<AbstractSaveToWord, SaveToWord>();
|
||||
services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
|
||||
services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
|
||||
|
||||
services.AddTransient<FormMain>();
|
||||
services.AddTransient<FormClients>();
|
||||
services.AddTransient<FormComponent>();
|
||||
services.AddTransient<FormComponents>();
|
||||
services.AddTransient<FormCreateOrder>();
|
||||
services.AddTransient<FormReinforced>();
|
||||
services.AddTransient<FormReinforcedComponent>();
|
||||
services.AddTransient<FormReinforceds>();
|
||||
services.AddTransient<FormReinforcedShop>();
|
||||
services.AddTransient<FormShops>();
|
||||
services.AddTransient<FormShop>();
|
||||
services.AddTransient<FormSellReinforced>();
|
||||
services.AddTransient<FormReportShopReinforcedies>();
|
||||
services.AddTransient<FormReportReinforcedComponents>();
|
||||
services.AddTransient<FormReportGroupOrders>();
|
||||
services.AddTransient<FormReportOrder>();
|
||||
services.AddTransient<FormViewImplementers>();
|
||||
services.AddTransient<FormImplementer>();
|
||||
services.AddTransient<FormViewMail>();
|
||||
services.AddTransient<FormReplyMail>();
|
||||
services.AddSingleton<AbstractMailWorker, MailKitWorker>();
|
||||
DependencyManager.Instance.RegisterType<IComponentLogic, ComponentLogic>();
|
||||
|
||||
DependencyManager.Instance.RegisterType<IOrderLogic, OrderLogic>();
|
||||
DependencyManager.Instance.RegisterType<IReinforcedLogic, ReinforcedLogic>();
|
||||
|
@ -25,7 +25,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic
|
||||
}
|
||||
public List<ShopViewModel>? ReadList(ShopSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Name:{Name}.Id:{ Id} ",
|
||||
_logger.LogInformation("ReadList. ShopName:{ShopName}.Id:{ Id} ",
|
||||
model?.Name, model?.Id);
|
||||
var list = (model == null) ? _shopStorage.GetFullList() :
|
||||
_shopStorage.GetFilteredList(model);
|
||||
@ -43,7 +43,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Name:{Name}.Id:{ Id}",
|
||||
_logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}",
|
||||
model.Name, model.Id);
|
||||
var element = _shopStorage.GetElement(model);
|
||||
if (element == null)
|
||||
@ -65,10 +65,6 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool SellReinforced(IReinforcedModel reinforced, int count)
|
||||
{
|
||||
return _shopStorage.SellReinforced(reinforced, count);
|
||||
}
|
||||
public bool Update(ShopBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
@ -77,7 +73,6 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic
|
||||
throw new ArgumentNullException("Нет названия магазина",
|
||||
nameof(model.Name));
|
||||
}
|
||||
|
||||
if (_shopStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
@ -113,9 +108,12 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic
|
||||
}
|
||||
if (model.ReinforcedMaxCount < 0)
|
||||
{
|
||||
throw new ArgumentException("Максимальное количество изделий в магазине не может быть меньше нуля", nameof(model.ReinforcedMaxCount));
|
||||
throw new ArgumentException(
|
||||
"Максимальное количество изделий в магазине не должно быть отрицательным",
|
||||
nameof(model.ReinforcedMaxCount));
|
||||
}
|
||||
_logger.LogInformation("Shop. Name:{0}.Address:{1}. Id: {2}",
|
||||
|
||||
_logger.LogInformation("Shop. ShopName:{0}.Address:{1}. Id: {2}",
|
||||
model.Name, model.Address, model.Id);
|
||||
var element = _shopStorage.GetElement(new ShopSearchModel
|
||||
{
|
||||
@ -133,38 +131,26 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
if (count <= 0)
|
||||
{
|
||||
throw new ArgumentException("Количество изделий должно быть больше 0", nameof(count));
|
||||
throw new ArgumentException("Количество добавляемого изделия должно быть больше 0", nameof(count));
|
||||
}
|
||||
|
||||
_logger.LogInformation("AddReinforced. Name:{Name}.Id:{ Id}", model.Name, model.Id);
|
||||
_logger.LogInformation("AddReinforcedInShop. ShopName:{ShopName}.Id:{ Id}",
|
||||
model.Name, model.Id);
|
||||
var element = _shopStorage.GetElement(model);
|
||||
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("AddReinforced element not found");
|
||||
_logger.LogWarning("AddReinforcedInShop element not found");
|
||||
return false;
|
||||
}
|
||||
_logger.LogInformation("AddReinforcedInShop find. Id:{Id}", element.Id);
|
||||
|
||||
if (element.ReinforcedMaxCount - element.ShopReinforcedies.Select(x => x.Value.Item2).Sum() < count)
|
||||
{
|
||||
throw new ArgumentNullException("Магазин переполнен", nameof(count));
|
||||
}
|
||||
|
||||
_logger.LogInformation("AddReinforced find. Id:{Id}", element.Id);
|
||||
|
||||
if (element.ShopReinforcedies.TryGetValue(reinforced.Id, out var pair))
|
||||
{
|
||||
element.ShopReinforcedies[reinforced.Id] = (reinforced, count + pair.Item2);
|
||||
_logger.LogInformation("AddReinforced. Added {count} {reinforced} to '{Name}' shop", count, reinforced.ReinforcedName, element.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
element.ShopReinforcedies[reinforced.Id] = (reinforced, count);
|
||||
_logger.LogInformation("AddReinforced. Added {count} new reinforced {reinforced} to '{Name}' shop", count, reinforced.ReinforcedName, element.Name);
|
||||
}
|
||||
var prevCount = element.ShopReinforcedies.GetValueOrDefault(reinforced.Id, (reinforced, 0)).Item2;
|
||||
element.ShopReinforcedies[reinforced.Id] = (reinforced, prevCount + count);
|
||||
_logger.LogInformation(
|
||||
"AddReinforcedInShop. Has been added {count} {reinforced} in {ShopName}",
|
||||
count, reinforced.ReinforcedName, element.Name);
|
||||
|
||||
_shopStorage.Update(new()
|
||||
{
|
||||
@ -172,51 +158,48 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic
|
||||
Address = element.Address,
|
||||
Name = element.Name,
|
||||
DateOpening = element.DateOpening,
|
||||
ReinforcedMaxCount = element.ReinforcedMaxCount,
|
||||
ShopReinforcedies = element.ShopReinforcedies,
|
||||
ShopReinforcedies = element.ShopReinforcedies
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public int GetFreePlacesWithReinfocrediesInShops(int countReinfocredies)
|
||||
{
|
||||
// Сумма разностей между максимальный кол-вом изделий и суммой всех изделий в магазине
|
||||
return _shopStorage.GetFullList()
|
||||
.Select(x => x.ReinforcedMaxCount - x.ShopReinforcedies
|
||||
.Select(p => p.Value.Item2).Sum())
|
||||
.Sum() - countReinfocredies;
|
||||
}
|
||||
|
||||
public bool AddReinforcediesInShops(IReinforcedModel reinforced, int count)
|
||||
{
|
||||
if (reinforced == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(reinforced));
|
||||
}
|
||||
|
||||
if (count <= 0)
|
||||
{
|
||||
throw new ArgumentException("Количество добавляемого изделия должно быть больше 0", nameof(count));
|
||||
}
|
||||
|
||||
var freePlaces = _shopStorage.GetFullList()
|
||||
.Select(x => x.ReinforcedMaxCount - x.ShopReinforcedies
|
||||
.Select(p => p.Value.Item2).Sum()).Sum() - count;
|
||||
|
||||
if (freePlaces < 0)
|
||||
{
|
||||
_logger.LogInformation("AddReinforced. Failed to add reinforced to shop. It's full.");
|
||||
_logger.LogWarning("AddReinfocrediesInShops. Количество добавляемых изделий должно быть больше 0. Количество - {count}", count);
|
||||
return false;
|
||||
}
|
||||
var freePlaces = GetFreePlacesWithReinfocrediesInShops(count);
|
||||
if (freePlaces < 0)
|
||||
{
|
||||
_logger.LogInformation("AddReinfocrediesInShops. Не удалось добавить изделия в магазины, поскольку они переполнены." +
|
||||
"Освободите магазины на {places} изделий", -freePlaces);
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var shop in _shopStorage.GetFullList())
|
||||
{
|
||||
var temp = Math.Min(count, shop.ReinforcedMaxCount - shop.ShopReinforcedies.Select(x => x.Value.Item2).Sum());
|
||||
|
||||
if (temp <= 0)
|
||||
var cnt = Math.Min(count, shop.ReinforcedMaxCount - shop.ShopReinforcedies.Select(x => x.Value.Item2).Sum());
|
||||
if (cnt <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!AddReinforced(new() { Id = shop.Id }, reinforced, temp))
|
||||
if (!AddReinforced(new() { Id = shop.Id }, reinforced, cnt))
|
||||
{
|
||||
_logger.LogWarning("An error occurred while adding reinforced to shops");
|
||||
_logger.LogWarning("При добавления изделий во все магазины произошла ошибка");
|
||||
return false;
|
||||
}
|
||||
|
||||
count -= temp;
|
||||
|
||||
count -= cnt;
|
||||
if (count == 0)
|
||||
{
|
||||
return true;
|
||||
@ -224,5 +207,11 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool SellReinforced(IReinforcedModel reinforced, int needCount)
|
||||
{
|
||||
return _shopStorage.SellReinforced(reinforced, needCount);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,39 @@
|
||||
using PrecastConcretePlantBusinessLogic.BusinessLogic;
|
||||
using PrecastConcretePlantBusinessLogic.MailWorker;
|
||||
using PrecastConcretePlantBusinessLogic.OfficePackage.Implements;
|
||||
using PrecastConcretePlantBusinessLogic.OfficePackage;
|
||||
using PrecastConcretePlantContracts.BusinessLogicsContracts;
|
||||
using PrecastConcretePlantContracts.DI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PrecastConcretePlantBusinessLogic
|
||||
{
|
||||
public class ImplementationBusinessLogicExtension : IImplementationBusinessLogicExtension
|
||||
{
|
||||
public int Priority => 0;
|
||||
|
||||
public void RegisterServices()
|
||||
{
|
||||
DependencyManager.Instance.RegisterType<IComponentLogic, ComponentLogic>();
|
||||
DependencyManager.Instance.RegisterType<IOrderLogic, OrderLogic>();
|
||||
DependencyManager.Instance.RegisterType<IReinforcedLogic, ReinforcedLogic>();
|
||||
DependencyManager.Instance.RegisterType<IReportLogic, ReportLogic>();
|
||||
DependencyManager.Instance.RegisterType<IClientLogic, ClientLogic>();
|
||||
DependencyManager.Instance.RegisterType<IImplementerLogic, ImplementerLogic>();
|
||||
DependencyManager.Instance.RegisterType<IMessageInfoLogic, MessageInfoLogic>();
|
||||
DependencyManager.Instance.RegisterType<IWorkProcess, WorkModeling>();
|
||||
DependencyManager.Instance.RegisterType<IBackUpLogic, BackUpLogic>();
|
||||
DependencyManager.Instance.RegisterType<IShopLogic, ShopLogic>();
|
||||
|
||||
DependencyManager.Instance.RegisterType<AbstractMailWorker, MailKitWorker>(true);
|
||||
|
||||
DependencyManager.Instance.RegisterType<AbstractSaveToExcel, SaveToExcel>();
|
||||
DependencyManager.Instance.RegisterType<AbstractSaveToWord, SaveToWord>();
|
||||
DependencyManager.Instance.RegisterType<AbstractSaveToPdf, SaveToPdf>();
|
||||
}
|
||||
}
|
||||
}
|
@ -17,4 +17,8 @@
|
||||
<ProjectReference Include="..\PrecastConcretePlantContracts\PrecastConcretePlantContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
<Exec Command="copy /Y "$(targetDir)*.dll" "$(solutionDir)ImplementationExtensions\*.dll"" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
@ -19,13 +19,16 @@ namespace PrecastConcretePlantContracts.Attributes
|
||||
|
||||
public bool IsUseAutoSize { get; private set; }
|
||||
|
||||
public ColumnAttribute(string title = "", bool visible = true, int width = 0, GridViewAutoSize gridViewAutoSize = GridViewAutoSize.None, bool isUseAutoSize = false)
|
||||
public string Format { get; private set; }
|
||||
|
||||
public ColumnAttribute(string title = "", bool visible = true, int width = 0, GridViewAutoSize gridViewAutoSize = GridViewAutoSize.None, bool isUseAutoSize = false, string format = "")
|
||||
{
|
||||
Title = title;
|
||||
Visible = visible;
|
||||
Width = width;
|
||||
GridViewAutoSize = gridViewAutoSize;
|
||||
IsUseAutoSize = isUseAutoSize;
|
||||
Format = format;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ namespace PrecastConcretePlantContracts.BindingModels
|
||||
public string Body { get; set; } = string.Empty;
|
||||
|
||||
public DateTime DateDelivery { get; set; }
|
||||
|
||||
public bool HasRead { get; set; }
|
||||
public string? Reply { get; set; }
|
||||
public int Id => throw new NotImplementedException();
|
||||
|
@ -22,20 +22,48 @@ namespace PrecastConcretePlantContracts.DI
|
||||
|
||||
public static DependencyManager Instance { get { if (_manager == null) { lock (_locjObject) { _manager = new DependencyManager(); } } return _manager; } }
|
||||
|
||||
/// <summary>
|
||||
/// Иницализация библиотек, в которых идут установки зависомстей
|
||||
/// </summary>
|
||||
public static void InitDependency()
|
||||
{
|
||||
var ext = ServiceProviderLoader.GetImplementationExtensions();
|
||||
if (ext == null)
|
||||
var extList = ServiceProviderLoader.GetImplementationExtensions();
|
||||
foreach (var ext in extList)
|
||||
{
|
||||
throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям");
|
||||
if (ext == null)
|
||||
{
|
||||
throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям");
|
||||
}
|
||||
// регистрируем зависимости
|
||||
ext.RegisterServices();
|
||||
}
|
||||
// регистрируем зависимости
|
||||
ext.RegisterServices();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Регистрация логгера
|
||||
/// </summary>
|
||||
/// <param name="configure"></param>
|
||||
public void AddLogging(Action<ILoggingBuilder> configure) => _dependencyManager.AddLogging(configure);
|
||||
|
||||
/// <summary>
|
||||
/// Добавление зависимости
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="U"></typeparam>
|
||||
public void RegisterType<T, U>(bool isSingle = false) where U : class, T where T : class => _dependencyManager.RegisterType<T, U>(isSingle);
|
||||
|
||||
/// <summary>
|
||||
/// Добавление зависимости
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="U"></typeparam>
|
||||
public void RegisterType<T>(bool isSingle = false) where T : class => _dependencyManager.RegisterType<T>(isSingle);
|
||||
|
||||
/// <summary>
|
||||
/// Получение класса со всеми зависмостями
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns></returns>
|
||||
public T Resolve<T>() => _dependencyManager.Resolve<T>();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PrecastConcretePlantContracts.DI
|
||||
{
|
||||
public interface IImplementationBusinessLogicExtension : IImplementationExtension { }
|
||||
}
|
@ -9,33 +9,41 @@ namespace PrecastConcretePlantContracts.DI
|
||||
{
|
||||
public class ServiceProviderLoader
|
||||
eegov
commented
Нет подгрузки зависимосетй по логике Нет подгрузки зависимосетй по логике
|
||||
{
|
||||
public static IImplementationExtension? GetImplementationExtensions()
|
||||
public static List<IImplementationExtension?> GetImplementationExtensions()
|
||||
{
|
||||
IImplementationExtension? source = null;
|
||||
Type[] handledTypes =
|
||||
{
|
||||
typeof(IImplementationBusinessLogicExtension),
|
||||
typeof(IImplementationExtension)
|
||||
};
|
||||
var result = handledTypes.Select(x => (IImplementationExtension?)null).ToList();
|
||||
var files = Directory.GetFiles(TryGetImplementationExtensionsFolder(), "*.dll", SearchOption.AllDirectories);
|
||||
foreach (var file in files.Distinct())
|
||||
{
|
||||
Assembly asm = Assembly.LoadFrom(file);
|
||||
foreach (var t in asm.GetExportedTypes())
|
||||
{
|
||||
if (t.IsClass && typeof(IImplementationExtension).IsAssignableFrom(t))
|
||||
for (var i = 0; i < handledTypes.Length; i++)
|
||||
{
|
||||
if (source == null)
|
||||
if (t.IsClass && handledTypes[i].IsAssignableFrom(t))
|
||||
{
|
||||
source = (IImplementationExtension)Activator.CreateInstance(t)!;
|
||||
}
|
||||
else
|
||||
{
|
||||
var newSource = (IImplementationExtension)Activator.CreateInstance(t)!;
|
||||
if (newSource.Priority > source.Priority)
|
||||
if (result[i] == null)
|
||||
{
|
||||
source = newSource;
|
||||
result[i] = (IImplementationExtension)Activator.CreateInstance(t)!;
|
||||
}
|
||||
else
|
||||
{
|
||||
var newSource = (IImplementationExtension)Activator.CreateInstance(t)!;
|
||||
if (newSource.Priority > result[i].Priority)
|
||||
{
|
||||
result[i] = newSource;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return source;
|
||||
return result;
|
||||
}
|
||||
|
||||
private static string TryGetImplementationExtensionsFolder()
|
||||
|
@ -13,13 +13,14 @@ namespace PrecastConcretePlantContracts.ViewModels
|
||||
{
|
||||
[Column(visible: false)]
|
||||
public string MessageId { get; set; } = string.Empty;
|
||||
|
||||
[Column(visible: false)]
|
||||
public int? ClientId { get; set; }
|
||||
|
||||
[Column("Отправитель", gridViewAutoSize: GridViewAutoSize.DisplayedCells, isUseAutoSize: true)]
|
||||
public string SenderName { get; set; } = string.Empty;
|
||||
|
||||
[Column("Дата письма", width: 100)]
|
||||
[Column("Дата письма", width: 100, format: "D")]
|
||||
public DateTime DateDelivery { get; set; }
|
||||
|
||||
[Column("Заголовок", width: 150)]
|
||||
@ -27,11 +28,15 @@ namespace PrecastConcretePlantContracts.ViewModels
|
||||
|
||||
[Column("Текст", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
|
||||
public string Body { get; set; } = string.Empty;
|
||||
[DisplayName("Прочитано")]
|
||||
public bool HasRead { get; set; }
|
||||
[DisplayName("Ответ")]
|
||||
public string? Reply { get; set; }
|
||||
|
||||
[Column(visible: false)]
|
||||
|
||||
public int Id => throw new NotImplementedException();
|
||||
|
||||
[Column("Прочитано", gridViewAutoSize: GridViewAutoSize.AllCellsExceptHeader, isUseAutoSize: true)]
|
||||
public bool HasRead { get; set; }
|
||||
|
||||
[Column("Ответ", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
|
||||
public string? Reply { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using PrecastConcretePlantDataModels.Models;
|
||||
using PrecastConcretePlantContracts.Attributes;
|
||||
using PrecastConcretePlantDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -10,21 +11,22 @@ namespace PrecastConcretePlantContracts.ViewModels
|
||||
{
|
||||
public class ShopViewModel : IShopModel
|
||||
{
|
||||
[DisplayName("Название магазина")]
|
||||
[Column("Название магазина", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Адрес магазина")]
|
||||
[Column("Адрес магазина", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
|
||||
public string Address { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Время открытия")]
|
||||
[Column("Время открытия", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true, format: "f")]
|
||||
public DateTime DateOpening { get; set; }
|
||||
|
||||
[DisplayName("Вместимость магазина")]
|
||||
public int ReinforcedMaxCount { get; set; }
|
||||
|
||||
[Column("Максимальное количество изделий в магазине", gridViewAutoSize: GridViewAutoSize.DisplayedCells, isUseAutoSize: true)]
|
||||
public int ReinforcedMaxCount { get; set; }
|
||||
|
||||
[Column(visible: false)]
|
||||
public Dictionary<int, (IReinforcedModel, int)> ShopReinforcedies { get; set; } = new();
|
||||
|
||||
|
||||
[Column(visible: false)]
|
||||
public int Id { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ namespace PrecastConcretePlantDatabaseImplement
|
||||
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
|
||||
DependencyManager.Instance.RegisterType<IReinforcedStorage, ReinforcedStorage>();
|
||||
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
|
||||
DependencyManager.Instance.RegisterType<IShopStorage, ShopStorage>();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,8 +12,8 @@ using PrecastConcretePlantDatabaseImplement;
|
||||
namespace PrecastConcretePlantDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(PrecastConcretePlantDataBase))]
|
||||
[Migration("20230503180531_Lab7Hard")]
|
||||
partial class Lab7Hard
|
||||
[Migration("20230505082651_LabWork08")]
|
||||
partial class LabWork08
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
|
||||
namespace PrecastConcretePlantDatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class Lab7Hard : Migration
|
||||
public partial class LabWork08 : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
@ -6,26 +6,34 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PrecastConcretePlantDatabaseImplement.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class Shop : IShopModel
|
||||
{
|
||||
[DataMember]
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
[DataMember]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[Required]
|
||||
[DataMember]
|
||||
public string Address { get; set; } = string.Empty;
|
||||
[Required]
|
||||
[DataMember]
|
||||
public DateTime DateOpening { get; set; }
|
||||
[Required]
|
||||
[DataMember]
|
||||
public int ReinforcedMaxCount { get; set; }
|
||||
|
||||
private Dictionary<int, (IReinforcedModel, int)>? _shopReinforcedies = null;
|
||||
|
||||
[NotMapped]
|
||||
[DataMember]
|
||||
public Dictionary<int, (IReinforcedModel, int)> ShopReinforcedies
|
||||
{
|
||||
get
|
||||
|
@ -22,6 +22,7 @@ namespace PrecastConcretePlantFileImplement
|
||||
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
|
||||
DependencyManager.Instance.RegisterType<IReinforcedStorage, ReinforcedStorage>();
|
||||
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
|
||||
DependencyManager.Instance.RegisterType<IShopStorage, ShopStorage>();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user
Регистрация зависимостей должна быть в библиотеках