че а ниче

This commit is contained in:
dasha 2023-05-02 21:20:10 +04:00
parent e38f6cc36f
commit 1c7becb81c
26 changed files with 193 additions and 87 deletions

1
.gitignore vendored
View File

@ -14,6 +14,7 @@
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
ImplementationExtensions
BusinessLogicExtensions
# Mono auto generated files
mono_crash.*

View File

@ -39,6 +39,7 @@ namespace SushiBarView
{
column.Width = columnAttr.Width;
}
column.DefaultCellStyle.Format = columnAttr.Format;
}
}
}

View File

@ -1,5 +1,6 @@
using Microsoft.Extensions.Logging;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.DI;
namespace SushiBarView
{
@ -40,13 +41,7 @@ namespace SushiBarView
CurrentPage = currentPage
});
}
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["ClientId"].Visible = false;
dataGridView.Columns["MessageId"].Visible = false;
dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
dataGridView.FillAndConfigGrid(list);
labelPage.Text = "c. " + currentPage;
_logger.LogInformation("Загрузка писем");
}
@ -75,7 +70,7 @@ namespace SushiBarView
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormMail));
var service = DependencyManager.Instance.Resolve<FormMail>();
if (service is FormMail form)
{
form.MessageId = Convert.ToString(dataGridView.SelectedRows[0].Cells["MessageId"].Value);

View File

@ -175,7 +175,7 @@ namespace SushiBarView
private void ShopSushiToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormReportShopListSushi));
var service = DependencyManager.Instance.Resolve<FormReportShopListSushi>();
if (service is FormReportShopListSushi form)
{
form.ShowDialog();
@ -193,7 +193,7 @@ namespace SushiBarView
private void OrdersGroupedByDateToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormReportOrdersGroupedByDate));
var service = DependencyManager.Instance.Resolve<FormReportOrdersGroupedByDate>();
if (service is FormReportOrdersGroupedByDate form)
{
form.ShowDialog();
@ -202,7 +202,7 @@ namespace SushiBarView
private void ShopsToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShops));
var service = DependencyManager.Instance.Resolve<FormShops>();
if (service is FormShops form)
{
form.ShowDialog();
@ -211,7 +211,7 @@ namespace SushiBarView
private void ButtonAddSushiInShop_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShopSushi));
var service = DependencyManager.Instance.Resolve<FormShopSushi>();
if (service is FormShopSushi form)
{
form.ShowDialog();
@ -220,7 +220,7 @@ namespace SushiBarView
private void ButtonSellSushi_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSellSushi));
var service = DependencyManager.Instance.Resolve<FormSellSushi>();
if (service is FormSellSushi form)
{
form.ShowDialog();

View File

@ -1,6 +1,7 @@
using Microsoft.Extensions.Logging;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.DI;
namespace SushiBarView
{
@ -22,14 +23,7 @@ namespace SushiBarView
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["ListSushi"].Visible = false;
dataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
dataGridView.FillAndConfigGrid(_logic.ReadList(null));
_logger.LogInformation("Загрузка магазинов");
}
catch (Exception ex)
@ -41,7 +35,7 @@ namespace SushiBarView
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShop));
var service = DependencyManager.Instance.Resolve<FormShop>();
if (service is FormShop form)
{
if (form.ShowDialog() == DialogResult.OK)
@ -54,7 +48,7 @@ namespace SushiBarView
{
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);

View File

@ -59,22 +59,6 @@ namespace SushiBarView
option.SetMinimumLevel(LogLevel.Information);
option.AddNLog("nlog.config");
});
;
DependencyManager.Instance.RegisterType<IClientLogic, ClientLogic>();
DependencyManager.Instance.RegisterType<IIngredientLogic, IngredientLogic>();
DependencyManager.Instance.RegisterType<IOrderLogic, OrderLogic>();
DependencyManager.Instance.RegisterType<ISushiLogic, SushiLogic>();
DependencyManager.Instance.RegisterType<IReportLogic, ReportLogic>();
DependencyManager.Instance.RegisterType<IImplementerLogic, ImplementerLogic>();
DependencyManager.Instance.RegisterType<IMessageInfoLogic, MessageInfoLogic>();
DependencyManager.Instance.RegisterType<IBackUpLogic, BackUpLogic>();
DependencyManager.Instance.RegisterType<IWorkProcess, WorkModeling>();
DependencyManager.Instance.RegisterType<AbstractMailWorker, MailKitWorker>(true);
DependencyManager.Instance.RegisterType<AbstractSaveToExcel, SaveToExcel>();
DependencyManager.Instance.RegisterType<AbstractSaveToWord, SaveToWord>();
DependencyManager.Instance.RegisterType<AbstractSaveToPdf, SaveToPdf>();
DependencyManager.Instance.RegisterType<FormMain>();
DependencyManager.Instance.RegisterType<FormClients>();
@ -89,6 +73,7 @@ namespace SushiBarView
DependencyManager.Instance.RegisterType<FormImplementers>();
DependencyManager.Instance.RegisterType<FormImplementer>();
DependencyManager.Instance.RegisterType<FormMails>();
DependencyManager.Instance.RegisterType<FormMail>();
}
private static void MailCheck(object obj) => DependencyManager.Instance.Resolve<AbstractMailWorker>()?.MailCheck();

View File

@ -0,0 +1,34 @@
using SushiBarBusinessLogic.BusinessLogics;
using SushiBarBusinessLogic.MailWorker;
using SushiBarBusinessLogic.OfficePackage.Implements;
using SushiBarBusinessLogic.OfficePackage;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.DI;
namespace SushiBarBusinessLogic
{
public class BusinessLogicExtension : IBusinessLogicExtension
{
public int Priority => 0;
public void RegisterServices()
{
DependencyManager.Instance.RegisterType<IClientLogic, ClientLogic>();
DependencyManager.Instance.RegisterType<IIngredientLogic, IngredientLogic>();
DependencyManager.Instance.RegisterType<IOrderLogic, OrderLogic>();
DependencyManager.Instance.RegisterType<ISushiLogic, SushiLogic>();
DependencyManager.Instance.RegisterType<IReportLogic, ReportLogic>();
DependencyManager.Instance.RegisterType<IImplementerLogic, ImplementerLogic>();
DependencyManager.Instance.RegisterType<IMessageInfoLogic, MessageInfoLogic>();
DependencyManager.Instance.RegisterType<IBackUpLogic, BackUpLogic>();
DependencyManager.Instance.RegisterType<IShopLogic, ShopLogic>();
DependencyManager.Instance.RegisterType<IWorkProcess, WorkModeling>();
DependencyManager.Instance.RegisterType<AbstractMailWorker, MailKitWorker>(true);
DependencyManager.Instance.RegisterType<AbstractSaveToExcel, SaveToExcel>();
DependencyManager.Instance.RegisterType<AbstractSaveToWord, SaveToWord>();
DependencyManager.Instance.RegisterType<AbstractSaveToPdf, SaveToPdf>();
}
}
}

View File

@ -23,4 +23,8 @@
<ProjectReference Include="..\SushiBarContracts\SushiBarContracts.csproj" />
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="copy /Y &quot;$(TargetDir)*.dll&quot; &quot;$(SolutionDir)BusinessLogicExtensions\*.dll&quot;" />
</Target>
</Project>

View File

@ -13,13 +13,16 @@
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;
}
}
}

View File

@ -23,12 +23,14 @@ namespace SushiBarContracts.DI
public static void InitDependency()
{
var ext = ServiceProviderLoader.GetImplementationExtensions();
if (ext == null)
var extLogic = ServiceProviderLoader.GetBusinessLogicExtensions();
if (ext == null || extLogic == null)
{
throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям");
}
// регистрируем зависимости
ext.RegisterServices();
extLogic.RegisterServices();
}
/// <summary>

View File

@ -0,0 +1,11 @@
namespace SushiBarContracts.DI
{
public interface IBusinessLogicExtension
{
public int Priority { get; }
/// <summary>
/// Регистрация сервисов
/// </summary>
public void RegisterServices();
}
}

View File

@ -37,6 +37,39 @@ namespace SushiBarContracts.DI
return source;
}
/// <summary>
/// Загрузка всех классов-реализаций IBusinessLogicExtension
/// </summary>
/// <returns></returns>
public static IBusinessLogicExtension? GetBusinessLogicExtensions()
{
IBusinessLogicExtension? source = null;
var files = Directory.GetFiles(TryGetBusinessLogicExtensionsFolder(), "*.dll", SearchOption.AllDirectories);
foreach (var file in files.Distinct())
{
Assembly asm = Assembly.LoadFrom(file);
foreach (var t in asm.GetExportedTypes())
{
if (t.IsClass && typeof(IBusinessLogicExtension).IsAssignableFrom(t))
{
if (source == null)
{
source = (IBusinessLogicExtension)Activator.CreateInstance(t)!;
}
else
{
var newSource = (IBusinessLogicExtension)Activator.CreateInstance(t)!;
if (newSource.Priority > source.Priority)
{
source = newSource;
}
}
}
}
}
return source;
}
private static string TryGetImplementationExtensionsFolder()
{
var directory = new DirectoryInfo(Directory.GetCurrentDirectory());
@ -46,5 +79,15 @@ namespace SushiBarContracts.DI
}
return $"{directory?.FullName}\\ImplementationExtensions";
}
private static string TryGetBusinessLogicExtensionsFolder()
{
var directory = new DirectoryInfo(Directory.GetCurrentDirectory());
while (directory != null && !directory.GetDirectories("BusinessLogicExtensions", SearchOption.AllDirectories).Any(x => x.Name == "BusinessLogicExtensions"))
{
directory = directory.Parent;
}
return $"{directory?.FullName}\\BusinessLogicExtensions";
}
}
}

View File

@ -9,7 +9,7 @@ namespace SushiBarContracts.ViewModels
public int Id { get; set; }
[Column(title: "Ингредиент", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string IngredientName { get; set; } = string.Empty;
[Column(title: "Цена", width: 150)]
[Column(title: "Цена", width: 150, format: "c2")]
public double Cost { get; set; }
}
}

View File

@ -1,6 +1,5 @@
using SushiBarContracts.Attributes;
using SushiBarDataModels.Models;
using System.ComponentModel;
namespace SushiBarContracts.ViewModels
{
@ -15,7 +14,7 @@ namespace SushiBarContracts.ViewModels
[Column(title: "Отправитель", width: 150)]
public string SenderName { get; set; } = string.Empty;
[Column(title: "Дата письма", width: 150)]
[Column(title: "Дата письма", width: 150, format: "g")]
public DateTime DateDelivery { get; set; }
[Column(title: "Заголовок", width: 150)]
@ -26,10 +25,10 @@ namespace SushiBarContracts.ViewModels
[Column(visible: false)]
public int Id => throw new NotImplementedException();
[DisplayName("Прочитано")]
[Column(title: "Прочитано", width: 100)]
public bool HasRead { get; set; }
[DisplayName("Ответ")]
[Column(title: "Ответ", width: 150)]
public string? Answer { get; set; }
}
}

View File

@ -22,13 +22,13 @@ namespace SushiBarContracts.ViewModels
public string ImplementerFIO { get; set; } = string.Empty;
[Column(title: "Количество", width: 100)]
public int Count { get; set; }
[Column(title: "Сумма", width: 50)]
[Column(title: "Сумма", width: 80, format: "c2")]
public double Sum { get; set; }
[Column(title: "Статус", width: 50)]
[Column(title: "Статус", width: 100)]
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
[Column(title: "Дата создания", width: 100)]
[Column(title: "Дата создания", width: 100, format: "g")]
public DateTime DateCreate { get; set; } = DateTime.Now;
[Column(title: "Дата выполнения", width: 100)]
[Column(title: "Дата выполнения", width: 100, format: "g")]
public DateTime? DateImplement { get; set; }
}
}

View File

@ -1,22 +1,21 @@
using SushiBarDataModels.Models;
using System.ComponentModel;
using SushiBarContracts.Attributes;
using SushiBarDataModels.Models;
namespace SushiBarContracts.ViewModels
{
public class ShopViewModel : IShopModel
{
[Column(visible: false)]
public int Id { get; set; }
[DisplayName("Название магазина")]
[Column(title: "Магазин", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string ShopName { get; set; } = string.Empty;
[DisplayName("Адрес магазина")]
[Column(title: "Адрес", width: 80)]
public string Address { get; set; } = string.Empty;
[DisplayName("Дата открытия")]
[Column(title: "Дата открытия", width: 80, format: "d")]
public DateTime DateOpening { get; set; } = DateTime.Now;
[DisplayName("Максимальное количество суши")]
[Column(title: "Максимальное количество суши", width: 80)]
public int MaxCountSushi { get; set; }
[Column(visible: false)]
public Dictionary<int, (ISushiModel, int)> ListSushi
{
get;

View File

@ -1,6 +1,5 @@
using SushiBarContracts.Attributes;
using SushiBarDataModels.Models;
using System.ComponentModel;
namespace SushiBarContracts.ViewModels
{
@ -10,7 +9,7 @@ namespace SushiBarContracts.ViewModels
public int Id { get; set; }
[Column(title: "Суши", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string SushiName { get; set; } = string.Empty;
[Column(title: "Цена", width: 150)]
[Column(title: "Цена", width: 150, format: "c2")]
public double Price { get; set; }
[Column(visible: false)]
public Dictionary<int, (IIngredientModel, int)> SushiIngredients

View File

@ -16,6 +16,7 @@ namespace SushiBarDatabaseImplement
DependencyManager.Instance.RegisterType<IMessageInfoStorage, MessageInfoStorage>();
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
DependencyManager.Instance.RegisterType<ISushiStorage, SushiStorage>();
DependencyManager.Instance.RegisterType<IShopStorage, ShopStorage>();
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
}
}

View File

@ -26,8 +26,10 @@ namespace SushiBarDatabaseImplement.Models
[DataMember]
[Required]
public string Body { get; private set; } = string.Empty;
[DataMember]
[Required]
public bool HasRead { get; set; }
[DataMember]
public string? Answer { get; set; }
public static Message? Create(MessageInfoBindingModel model)

View File

@ -3,24 +3,30 @@ using SushiBarContracts.ViewModels;
using SushiBarDataModels.Models;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Xml.Linq;
using System.Runtime.Serialization;
namespace SushiBarDatabaseImplement.Models
{
[DataContract]
public class Shop : IShopModel
{
[DataMember]
public int Id { get; private set; }
[DataMember]
[Required]
public string ShopName { get; private set; } = string.Empty;
[DataMember]
[Required]
public string Address { get; private set; } = string.Empty;
[DataMember]
[Required]
public DateTime DateOpening { get; private set; }
[DataMember]
[Required]
public int MaxCountSushi { get; private set; }
private Dictionary<int, (ISushiModel, int)>? _shopSushi = null;
[DataMember]
[NotMapped]
public Dictionary<int, (ISushiModel, int)> ListSushi
{
@ -33,11 +39,11 @@ namespace SushiBarDatabaseImplement.Models
{
if (_shopSushi.ContainsKey(x.SushiId))
{
_shopSushi[x.SushiId] = (x.Sushi as ISushiModel, _shopSushi[x.SushiId].Item2 + x.Count);
_shopSushi[x.SushiId] = (x.Sushi, _shopSushi[x.SushiId].Item2 + x.Count);
}
else
{
_shopSushi[x.SushiId] = (x.Sushi as ISushiModel, x.Count);
_shopSushi[x.SushiId] = (x.Sushi, x.Count);
}
});
}

View File

@ -17,6 +17,7 @@ namespace SushiBarFileImplement
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
DependencyManager.Instance.RegisterType<ISushiStorage, SushiStorage>();
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
DependencyManager.Instance.RegisterType<IShopStorage, ShopStorage>();
}
}
}

View File

@ -22,9 +22,9 @@ namespace SushiBarFileImplement.Models
public string Subject { get; private set; } = string.Empty;
[DataMember]
public string Body { get; private set; } = string.Empty;
[DataMember]
public bool HasRead { get; set; }
[DataMember]
public string? Answer { get; set; }
public static Message? Create(MessageInfoBindingModel model)
@ -40,6 +40,9 @@ namespace SushiBarFileImplement.Models
DateDelivery = model.DateDelivery,
SenderName = model.SenderName,
ClientId = model.ClientId,
MessageId = model.MessageId,
HasRead = model.HasRead,
Answer = model.Answer
};
}
@ -79,6 +82,9 @@ namespace SushiBarFileImplement.Models
DateDelivery = DateDelivery,
SenderName = SenderName,
ClientId = ClientId,
MessageId = MessageId,
HasRead = HasRead,
Answer = Answer
};
public XElement GetXElement => new("MessageInfo",
@ -87,6 +93,9 @@ namespace SushiBarFileImplement.Models
new XAttribute("ClientId", ClientId),
new XAttribute("MessageId", MessageId),
new XAttribute("SenderName", SenderName),
new XAttribute("DateDelivery", DateDelivery),
new XAttribute("HasRead", HasRead),
new XAttribute("Answer", Answer)
);
public int Id => throw new NotImplementedException();

View File

@ -2,17 +2,23 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.ViewModels;
using SushiBarDataModels.Models;
using System.Reflection.Metadata;
using System.Runtime.Serialization;
using System.Xml.Linq;
namespace SushiBarFileImplement.Models
{
[DataContract]
public class Shop : IShopModel
{
[DataMember]
public int Id { get; private set; }
[DataMember]
public string ShopName { get; private set; } = string.Empty;
[DataMember]
public string Address { get; private set; } = string.Empty;
[DataMember]
public DateTime DateOpening { get; private set; }
[DataMember]
public int MaxCountSushi { get; private set; }
public Dictionary<int, int> CountSushi
{
@ -21,6 +27,7 @@ namespace SushiBarFileImplement.Models
} = new();
private Dictionary<int, (ISushiModel, int)>? _shopSushi = null;
[DataMember]
public Dictionary<int, (ISushiModel, int)> ListSushi
{
get

View File

@ -17,6 +17,7 @@ namespace SushiBarListImplement
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
DependencyManager.Instance.RegisterType<ISushiStorage, SushiStorage>();
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
DependencyManager.Instance.RegisterType<IShopStorage, ShopStorage>();
}
}
}

View File

@ -1,26 +1,28 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.ViewModels;
using SushiBarDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
namespace SushiBarListImplement.Models
{
[DataContract]
public class Message : IMessageInfoModel
{
[DataMember]
public string MessageId { get; private set; } = string.Empty;
[DataMember]
public int? ClientId { get; private set; }
[DataMember]
public string SenderName { get; private set; } = string.Empty;
[DataMember]
public DateTime DateDelivery { get; private set; } = DateTime.Now;
[DataMember]
public string Subject { get; private set; } = string.Empty;
[DataMember]
public string Body { get; private set; } = string.Empty;
[DataMember]
public bool HasRead { get; set; }
[DataMember]
public string? Answer { get; set; }
public static Message? Create(MessageInfoBindingModel model)

View File

@ -1,15 +1,22 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.ViewModels;
using SushiBarDataModels.Models;
using System.Runtime.Serialization;
namespace SushiBarListImplement.Models
{
[DataContract]
public class Shop : IShopModel
{
[DataMember]
public int Id { get; private set; }
[DataMember]
public string ShopName { get; private set; } = string.Empty;
[DataMember]
public string Address { get; private set; } = string.Empty;
[DataMember]
public DateTime DateOpening { get; private set; }
[DataMember]
public Dictionary<int, (ISushiModel, int)> ListSushi
{
get;