сделана 8лаба

This commit is contained in:
goldfest 2024-05-16 22:45:15 +04:00
parent 53824dd988
commit 13b6659582
25 changed files with 513 additions and 122 deletions

2
.gitignore vendored
View File

@ -69,6 +69,8 @@ ScaffoldingReadMe.txt
# StyleCop # StyleCop
StyleCopReport.xml StyleCopReport.xml
/TravelCompany/ImplementationExtensions
# Files built by Visual Studio # Files built by Visual Studio
*_i.c *_i.c
*_p.c *_p.c

View File

@ -28,18 +28,7 @@ namespace TravelCompany.Forms
{ {
try try
{ {
var list = _logic.ReadList(null); DataGridView.FillAndConfigGrid(_logic.ReadList(null));
if (list != null)
{
DataGridView.DataSource = list;
DataGridView.Columns["Id"].Visible = false;
DataGridView.Columns["ClientFIO"].AutoSizeMode =
DataGridViewAutoSizeColumnMode.Fill;
DataGridView.Columns["Email"].AutoSizeMode =
DataGridViewAutoSizeColumnMode.Fill;
DataGridView.Columns["Password"].AutoSizeMode =
DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка клиентов"); _logger.LogInformation("Загрузка клиентов");
} }
catch (Exception ex) catch (Exception ex)

View File

@ -10,6 +10,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using TravelCompanyContracts.DI;
namespace TravelCompany.Forms namespace TravelCompany.Forms
{ {
@ -51,23 +52,19 @@ namespace TravelCompany.Forms
private void buttonAdd_Click(object sender, EventArgs e) private void buttonAdd_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); var form = DependencyManager.Instance.Resolve<FormComponent>();
if (service is FormComponent form)
{
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
LoadData(); LoadData();
} }
} }
}
private void buttonUpd_Click(object sender, EventArgs e) private void buttonUpd_Click(object sender, EventArgs e)
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); var form = DependencyManager.Instance.Resolve<FormComponent>();
if (service is FormComponent form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
@ -75,7 +72,6 @@ namespace TravelCompany.Forms
} }
} }
} }
}
private void buttonDel_Click(object sender, EventArgs e) private void buttonDel_Click(object sender, EventArgs e)
{ {

View File

@ -12,6 +12,8 @@ using System.Windows.Forms;
using TravelCompanyContracts.BusinessLogicsContracts; using TravelCompanyContracts.BusinessLogicsContracts;
using TravelCompanyContracts.SearchModels; using TravelCompanyContracts.SearchModels;
using TravelCompanyContracts.BindingModels; using TravelCompanyContracts.BindingModels;
using TravelCompanyContracts.DI;
using TravelCompanyDatabaseImplement.Models;
namespace TravelCompany.Forms namespace TravelCompany.Forms
{ {
@ -20,14 +22,14 @@ namespace TravelCompany.Forms
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly ITravelLogic _logic; private readonly ITravelLogic _logic;
private int? _id; private int? _id;
private Dictionary<int, (IComponentModel, int)> _productComponents; private Dictionary<int, (IComponentModel, int)> _travelComponents;
public int Id { set { _id = value; } } public int Id { set { _id = value; } }
public FormTravel(ILogger<FormTravel> logger, ITravelLogic logic) public FormTravel(ILogger<FormTravel> logger, ITravelLogic logic)
{ {
InitializeComponent(); InitializeComponent();
_logger = logger; _logger = logger;
_logic = logic; _logic = logic;
_productComponents = new Dictionary<int, (IComponentModel, int)>(); _travelComponents = new Dictionary<int, (IComponentModel, int)>();
} }
private void FormTravel_Load(object sender, EventArgs e) private void FormTravel_Load(object sender, EventArgs e)
{ {
@ -44,7 +46,7 @@ namespace TravelCompany.Forms
{ {
textBoxName.Text = view.TravelName; textBoxName.Text = view.TravelName;
textBoxPrice.Text = view.Price.ToString(); textBoxPrice.Text = view.Price.ToString();
_productComponents = view.TravelComponents ?? new Dictionary<int, (IComponentModel, int)>(); _travelComponents = view.TravelComponents ?? new Dictionary<int, (IComponentModel, int)>();
LoadData(); LoadData();
} }
} }
@ -59,10 +61,10 @@ namespace TravelCompany.Forms
_logger.LogInformation("Загрузка компонент изделия"); _logger.LogInformation("Загрузка компонент изделия");
try try
{ {
if (_productComponents != null) if (_travelComponents != null)
{ {
dataGridView.Rows.Clear(); dataGridView.Rows.Clear();
foreach (var pc in _productComponents) foreach (var pc in _travelComponents)
{ {
dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 });
} }
@ -76,51 +78,44 @@ namespace TravelCompany.Forms
} }
private void buttonAdd_Click(object sender, EventArgs e) private void buttonAdd_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormTravelComponent)); var form = DependencyManager.Instance.Resolve<FormTravelComponent>();
if (service is FormTravelComponent form)
{
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{
if (form.ComponentModel == null)
{ {
return; return;
} }
_logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count} ", form.ComponentModel.ComponentName, form.Count); _logger.LogInformation("Добавление нового ингридиента:{ ComponentName}-{ Count}", form.ComponentModel.ComponentName, form.Count);
if (_productComponents.ContainsKey(form.Id)) if (_travelComponents.ContainsKey(form.Id))
{ {
_productComponents[form.Id] = (form.ComponentModel, form.Count); _travelComponents[form.Id] = (form.ComponentModel,
form.Count);
} }
else else
{ {
_productComponents.Add(form.Id, (form.ComponentModel, form.Count)); _travelComponents.Add(form.Id, (form.ComponentModel,
form.Count));
} }
LoadData(); LoadData();
} }
}
}
private void buttonUpd_Click(object sender, EventArgs e) private void buttonUpd_Click(object sender, EventArgs e)
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormTravelComponent)); var form = DependencyManager.Instance.Resolve<FormTravelComponent>();
if (service is FormTravelComponent form)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
form.Id = id; form.Id = id;
form.Count = _productComponents[id].Item2; form.Count = _travelComponents[id].Item2;
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
if (form.ComponentModel == null) if (form.ComponentModel == null)
{ {
return; return;
} }
_logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); _logger.LogInformation("Изменение ингридиента:{ ComponentName}-{ Count}", form.ComponentModel.ComponentName, form.Count);
_productComponents[form.Id] = (form.ComponentModel, form.Count); _travelComponents[form.Id] = (form.ComponentModel, form.Count);
LoadData(); LoadData();
} }
} }
} }
}
private void buttonDel_Click(object sender, EventArgs e) private void buttonDel_Click(object sender, EventArgs e)
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
@ -130,7 +125,7 @@ namespace TravelCompany.Forms
try try
{ {
_logger.LogInformation("Удаление компонента: { ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value); _logger.LogInformation("Удаление компонента: { ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value);
_productComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); _travelComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value));
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -156,7 +151,7 @@ namespace TravelCompany.Forms
MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }
if (_productComponents == null || _productComponents.Count == 0) if (_travelComponents == null || _travelComponents.Count == 0)
{ {
MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
@ -169,7 +164,7 @@ namespace TravelCompany.Forms
Id = _id ?? 0, Id = _id ?? 0,
TravelName = textBoxName.Text, TravelName = textBoxName.Text,
Price = Convert.ToDouble(textBoxPrice.Text), Price = Convert.ToDouble(textBoxPrice.Text),
TravelComponents = _productComponents TravelComponents = _travelComponents
}; };
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
if (!operationResult) if (!operationResult)
@ -195,7 +190,7 @@ namespace TravelCompany.Forms
private double CalcPrice() private double CalcPrice()
{ {
double price = 0; double price = 0;
foreach (var elem in _productComponents) foreach (var elem in _travelComponents)
{ {
price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2);
} }

View File

@ -11,6 +11,7 @@ using TravelCompany;
using TravelCompanyContracts.BindingModels; using TravelCompanyContracts.BindingModels;
using TravelCompanyContracts.BusinessLogicsContracts; using TravelCompanyContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using TravelCompanyContracts.DI;
namespace TravelCompany.Forms namespace TravelCompany.Forms
{ {
@ -34,14 +35,7 @@ namespace TravelCompany.Forms
{ {
try try
{ {
var list = _logic.ReadList(null); dataGridView.FillAndConfigGrid(_logic.ReadList(null));
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["TravelComponents"].Visible = false;
dataGridView.Columns["TravelName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка путёвок"); _logger.LogInformation("Загрузка путёвок");
} }
catch (Exception ex) catch (Exception ex)
@ -52,23 +46,18 @@ namespace TravelCompany.Forms
private void buttonAdd_Click(object sender, EventArgs e) private void buttonAdd_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormTravel)); var form = DependencyManager.Instance.Resolve<FormTravel>();
if (service is FormTravel form)
{
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
LoadData(); LoadData();
} }
} }
}
private void buttonUpd_Click(object sender, EventArgs e) private void buttonUpd_Click(object sender, EventArgs e)
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormTravel)); var form = DependencyManager.Instance.Resolve<FormTravel>();
if (service is FormTravel form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
@ -76,7 +65,6 @@ namespace TravelCompany.Forms
} }
} }
} }
}
private void buttonDel_Click(object sender, EventArgs e) private void buttonDel_Click(object sender, EventArgs e)
{ {

View File

@ -27,14 +27,7 @@ namespace TravelCompany.Forms
{ {
try try
{ {
var list = _logic.ReadList(null); dataGridView.FillAndConfigGrid(_logic.ReadList(null));
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["ClientId"].Visible = false;
dataGridView.Columns["MessageId"].Visible = false;
dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка списка писем"); _logger.LogInformation("Загрузка списка писем");
} }
catch (Exception ex) catch (Exception ex)

View File

@ -33,21 +33,8 @@ namespace TravelCompany.Forms
{ {
try try
{ {
var list = _logic.ReadList(null); dataGridView1.FillAndConfigGrid(_logic.ReadList(null));
if (list != null) _logger.LogInformation("Загрузка исполнителей");
{
dataGridView1.DataSource = list;
dataGridView1.Columns["Id"].Visible = false;
dataGridView1.Columns["ImplementerFIO"].AutoSizeMode =
DataGridViewAutoSizeColumnMode.Fill;
dataGridView1.Columns["Password"].AutoSizeMode =
DataGridViewAutoSizeColumnMode.Fill;
dataGridView1.Columns["Qualification"].AutoSizeMode =
DataGridViewAutoSizeColumnMode.Fill;
dataGridView1.Columns["WorkExperience"].AutoSizeMode =
DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка компонентов");
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

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

View File

@ -16,12 +16,15 @@ namespace TravelCompanyFileImplement
private readonly string TravelFileName = "Travel.xml"; private readonly string TravelFileName = "Travel.xml";
private readonly string ClientFileName = "Client.xml"; private readonly string ClientFileName = "Client.xml";
private readonly string ImplementerFileName = "Implementer.xml"; private readonly string ImplementerFileName = "Implementer.xml";
private readonly string MessageInfoFileName = "MessageInfo.xml";
public List<Component> Components { get; private set; } public List<Component> Components { get; private set; }
public List<Order> Orders { get; private set; } public List<Order> Orders { get; private set; }
public List<Travel> Travels { get; private set; } public List<Travel> Travels { get; private set; }
public List<Client> Clients { get; private set; } public List<Client> Clients { get; private set; }
public List<Implementer> Implementers { get; private set; } public List<Implementer> Implementers { get; private set; }
public List<MessageInfo> Messages { get; private set; }
public static DataFileSingleton GetInstance() public static DataFileSingleton GetInstance()
{ {
@ -38,6 +41,8 @@ namespace TravelCompanyFileImplement
"Clients", x => x.GetXElement); "Clients", x => x.GetXElement);
public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, public void SaveImplementers() => SaveData(Implementers, ImplementerFileName,
"Implementers", x => x.GetXElement); "Implementers", x => x.GetXElement);
public void SaveMessages() => SaveData(Orders, ImplementerFileName, "Messages", x => x.GetXElement);
private DataFileSingleton() private DataFileSingleton()
{ {
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
@ -47,6 +52,8 @@ namespace TravelCompanyFileImplement
Client.Create(x)!)!; Client.Create(x)!)!;
Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementers = LoadData(ImplementerFileName, "Implementer", x =>
Implementer.Create(x)!)!; Implementer.Create(x)!)!;
Messages = LoadData(MessageInfoFileName, "MessageInfo", x => MessageInfo.Create(x)!)!;
} }
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction) private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
{ {

View File

@ -0,0 +1,22 @@
using TravelCompanyContracts.DI;
using TravelCompanyContracts.StoragesContracts;
using TravelCompanyFileImplement.Implements;
namespace TravelCompanyFileImplement
{
public class ImplementationExtension : IImplementationExtension
{
public int Priority => 1;
public void RegisterServices()
{
DependencyManager.Instance.RegisterType<IClientStorage, ClientStorage>();
DependencyManager.Instance.RegisterType<IComponentStorage, ComponentStorage>();
DependencyManager.Instance.RegisterType<IImplementerStorage, ImplementerStorage>();
DependencyManager.Instance.RegisterType<IMessageInfoStorage, MessageInfoStorage>();
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
DependencyManager.Instance.RegisterType<ITravelStorage, TravelStorage>();
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
}
}
}

View File

@ -0,0 +1,39 @@
using TravelCompanyContracts.StoragesContracts;
using System.Reflection;
namespace TravelCompanyFileImplement.Implements
{
public class BackUpInfo : IBackUpInfo
{
private readonly DataFileSingleton source;
private readonly PropertyInfo[] sourceProperties;
public BackUpInfo()
{
source = DataFileSingleton.GetInstance();
sourceProperties = source.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);
}
public List<T>? GetList<T>() where T : class, new()
{
var requredType = typeof(T);
return (List<T>?)sourceProperties.FirstOrDefault(x => x.PropertyType.IsGenericType && x.PropertyType.GetGenericArguments()[0] == requredType)
?.GetValue(source);
}
public Type? GetTypeByModelInterface(string modelInterfaceName)
{
var assembly = typeof(BackUpInfo).Assembly;
var types = assembly.GetTypes();
foreach (var type in types)
{
if (type.IsClass && type.GetInterface(modelInterfaceName) != null)
{
return type;
}
}
return null;
}
}
}

View File

@ -0,0 +1,58 @@
using TravelCompanyContracts.BindingModels;
using TravelCompanyContracts.SearchModels;
using TravelCompanyContracts.StoragesContracts;
using TravelCompanyContracts.ViewModels;
using TravelCompanyFileImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TravelCompanyFileImplement.Implements
{
public class MessageInfoStorage : IMessageInfoStorage
{
private readonly DataFileSingleton _source;
public MessageInfoStorage()
{
_source = DataFileSingleton.GetInstance();
}
public MessageInfoViewModel? GetElement(MessageInfoSearchModel model)
{
if (model.MessageId != null)
{
return _source.Messages.FirstOrDefault(x => x.MessageId == model.MessageId)?.GetViewModel;
}
return null;
}
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
{
return _source.Messages
.Where(x => x.ClientId == model.ClientId)
.Select(x => x.GetViewModel)
.ToList();
}
public List<MessageInfoViewModel> GetFullList()
{
return _source.Messages
.Select(x => x.GetViewModel)
.ToList();
}
public MessageInfoViewModel? Insert(MessageInfoBindingModel model)
{
var newMessage = MessageInfo.Create(model);
if (newMessage == null)
{
return null;
}
_source.Messages.Add(newMessage);
_source.SaveMessages();
return newMessage.GetViewModel;
}
}
}

View File

@ -9,14 +9,21 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Linq; using System.Xml.Linq;
using System.Runtime.Serialization;
namespace TravelCompanyFileImplement.Models namespace TravelCompanyFileImplement.Models
{ {
[DataContract]
public class Client : IClientModel public class Client : IClientModel
{ {
[DataMember]
public int Id { get; private set; } public int Id { get; private set; }
[DataMember]
public string ClientFIO { get; private set; } = string.Empty; public string ClientFIO { get; private set; } = string.Empty;
[DataMember]
public string Email { get; set; } = string.Empty; public string Email { get; set; } = string.Empty;
[DataMember]
public string Password { get; set; } = string.Empty; public string Password { get; set; } = string.Empty;
public static Client? Create(ClientBindingModel model) public static Client? Create(ClientBindingModel model)
{ {

View File

@ -7,13 +7,18 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Linq; using System.Xml.Linq;
using System.Runtime.Serialization;
namespace TravelCompanyFileImplement.Models namespace TravelCompanyFileImplement.Models
{ {
[DataContract]
public class Component : IComponentModel public class Component : IComponentModel
{ {
[DataMember]
public int Id { get; private set; } public int Id { get; private set; }
[DataMember]
public string ComponentName { get; private set; } = string.Empty; public string ComponentName { get; private set; } = string.Empty;
[DataMember]
public double Cost { get; set; } public double Cost { get; set; }
public static Component? Create(ComponentBindingModel model) public static Component? Create(ComponentBindingModel model)
{ {

View File

@ -7,15 +7,22 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Linq; using System.Xml.Linq;
using System.Runtime.Serialization;
namespace TravelCompanyFileImplement.Models namespace TravelCompanyFileImplement.Models
{ {
[DataContract]
public class Implementer : IImplementerModel public class Implementer : IImplementerModel
{ {
[DataMember]
public int Id { get; private set; } public int Id { get; private set; }
[DataMember]
public string ImplementerFIO { get; private set; } = string.Empty; public string ImplementerFIO { get; private set; } = string.Empty;
[DataMember]
public string Password { get; set; } = string.Empty; public string Password { get; set; } = string.Empty;
[DataMember]
public int Qualification { get; set; } = 0; public int Qualification { get; set; } = 0;
[DataMember]
public int WorkExperience { get; set; } = 0; public int WorkExperience { get; set; } = 0;
public static Implementer? Create(ImplementerBindingModel model) public static Implementer? Create(ImplementerBindingModel model)
{ {

View File

@ -0,0 +1,91 @@
using TravelCompanyContracts.BindingModels;
using TravelCompanyContracts.ViewModels;
using TravelCompanyDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace TravelCompanyFileImplement.Models
{
[DataContract]
public class MessageInfo : IMessageInfoModel
{
[DataMember]
public int Id { get; private set; }
[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;
public static MessageInfo? Create(MessageInfoBindingModel model)
{
if (model == null)
{
return null;
}
return new()
{
Body = model.Body,
Subject = model.Subject,
ClientId = model.ClientId,
MessageId = model.MessageId,
SenderName = model.SenderName,
DateDelivery = model.DateDelivery,
};
}
public static MessageInfo? Create(XElement element)
{
if (element == null)
{
return null;
}
return new()
{
Body = element.Attribute("Body")!.Value,
Subject = element.Attribute("Subject")!.Value,
ClientId = Convert.ToInt32(element.Attribute("ClientId")!.Value),
MessageId = element.Attribute("MessageId")!.Value,
SenderName = element.Attribute("SenderName")!.Value,
DateDelivery = Convert.ToDateTime(element.Attribute("DateDelivery")!.Value),
};
}
public MessageInfoViewModel GetViewModel => new()
{
Body = Body,
Subject = Subject,
ClientId = ClientId,
MessageId = MessageId,
SenderName = SenderName,
DateDelivery = DateDelivery,
};
public XElement GetXElement => new("MessageInfo",
new XAttribute("Body", Body),
new XAttribute("Subject", Subject),
new XAttribute("ClientId", ClientId),
new XAttribute("MessageId", MessageId),
new XAttribute("SenderName", SenderName),
new XAttribute("DateDelivery", DateDelivery)
);
}
}

View File

@ -8,23 +8,34 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Linq; using System.Xml.Linq;
using System.Runtime.Serialization;
namespace TravelCompanyFileImplement.Models namespace TravelCompanyFileImplement.Models
{ {
[DataContract]
public class Order : IOrderModel public class Order : IOrderModel
{ {
[DataMember]
public int TravelId { get; private set; } public int TravelId { get; private set; }
[DataMember]
public int ClientId { get; private set; } public int ClientId { get; private set; }
[DataMember]
public int? ImplementerId { get; private set; } = null; public int? ImplementerId { get; private set; } = null;
[DataMember]
public int Count { get; private set; } public int Count { get; private set; }
[DataMember]
public double Sum { get; private set; } public double Sum { get; private set; }
[DataMember]
public OrderStatus Status { get; private set; } public OrderStatus Status { get; private set; }
[DataMember]
public DateTime DateCreate { get; private set; } public DateTime DateCreate { get; private set; }
[DataMember]
public DateTime? DateImplement { get; private set; } public DateTime? DateImplement { get; private set; }
[DataMember]
public int Id { get; private set; } public int Id { get; private set; }

View File

@ -7,13 +7,18 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Linq; using System.Xml.Linq;
using System.Runtime.Serialization;
namespace TravelCompanyFileImplement.Models namespace TravelCompanyFileImplement.Models
{ {
[DataContract]
public class Travel : ITravelModel public class Travel : ITravelModel
{ {
[DataMember]
public int Id { get; private set; } public int Id { get; private set; }
[DataMember]
public string TravelName { get; private set; } = string.Empty; public string TravelName { get; private set; } = string.Empty;
[DataMember]
public double Price { get; private set; } public double Price { get; private set; }
public Dictionary<int, int> Components { get; private set; } = new(); public Dictionary<int, int> Components { get; private set; } = new();
private Dictionary<int, (IComponentModel, int)>? _TravelComponents = null; private Dictionary<int, (IComponentModel, int)>? _TravelComponents = null;

View File

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

View File

@ -15,6 +15,8 @@ namespace TravelCompanyListImplement
public List<Travel> Travels { get; set; } public List<Travel> Travels { get; set; }
public List<Client> Clients { get; set; } public List<Client> Clients { get; set; }
public List<Implementer> Implementers { get; set; } public List<Implementer> Implementers { get; set; }
public List<MessageInfo> Messages { get; set; }
private DataListSingleton() private DataListSingleton()
{ {
@ -23,6 +25,8 @@ namespace TravelCompanyListImplement
Travels = new List<Travel>(); Travels = new List<Travel>();
Clients = new List<Client>(); Clients = new List<Client>();
Implementers = new List<Implementer>(); Implementers = new List<Implementer>();
Messages = new List<MessageInfo>();
} }
public static DataListSingleton GetInstance() public static DataListSingleton GetInstance()

View File

@ -0,0 +1,27 @@
using TravelCompanyContracts.DI;
using TravelCompanyContracts.StoragesContracts;
using TravelCompanyListImplement.Implements;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TravelCompanyListImplement
{
internal class ImplementationExtension : IImplementationExtension
{
public int Priority => 0;
public void RegisterServices()
{
DependencyManager.Instance.RegisterType<IClientStorage, ClientStorage>();
DependencyManager.Instance.RegisterType<IComponentStorage, ComponentStorage>();
DependencyManager.Instance.RegisterType<IImplementerStorage, ImplementerStorage>();
DependencyManager.Instance.RegisterType<IMessageInfoStorage, MessageInfoStorage>();
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
DependencyManager.Instance.RegisterType<ITravelStorage, TravelStorage>();
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
}
}
}

View File

@ -0,0 +1,22 @@
using TravelCompanyContracts.StoragesContracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TravelCompanyListImplement.Implements
{
public class BackUpInfo : IBackUpInfo
{
public List<T>? GetList<T>() where T : class, new()
{
throw new NotImplementedException();
}
public Type? GetTypeByModelInterface(string modelInterfaceName)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,68 @@
using TravelCompanyContracts.BindingModels;
using TravelCompanyContracts.SearchModels;
using TravelCompanyContracts.StoragesContracts;
using TravelCompanyContracts.ViewModels;
using TravelCompanyListImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TravelCompanyListImplement.Implements
{
public class MessageInfoStorage : IMessageInfoStorage
{
private readonly DataListSingleton _source;
public MessageInfoStorage()
{
_source = DataListSingleton.GetInstance();
}
public List<MessageInfoViewModel> GetFullList()
{
List<MessageInfoViewModel> result = new();
foreach (var item in _source.Messages)
{
result.Add(item.GetViewModel);
}
return result;
}
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
{
List<MessageInfoViewModel> result = new();
foreach (var item in _source.Messages)
{
if (item.ClientId.HasValue && item.ClientId == model.ClientId)
{
result.Add(item.GetViewModel);
}
}
return result;
}
public MessageInfoViewModel? GetElement(MessageInfoSearchModel model)
{
foreach (var message in _source.Messages)
{
if (model.MessageId != null && model.MessageId.Equals(message.MessageId))
{
return message.GetViewModel;
}
}
return null;
}
public MessageInfoViewModel? Insert(MessageInfoBindingModel model)
{
var newMessage = MessageInfo.Create(model);
if (newMessage == null)
{
return null;
}
_source.Messages.Add(newMessage);
return newMessage.GetViewModel;
}
}
}

View File

@ -0,0 +1,55 @@
using TravelCompanyContracts.BindingModels;
using TravelCompanyContracts.ViewModels;
using TravelCompanyDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TravelCompanyListImplement.Models
{
public class MessageInfo : IMessageInfoModel
{
public string MessageId { get; private set; } = string.Empty;
public int? ClientId { get; private set; }
public string SenderName { get; private set; } = string.Empty;
public DateTime DateDelivery { get; private set; } = DateTime.Now;
public string Subject { get; private set; } = string.Empty;
public string Body { get; private set; } = string.Empty;
public int Id => throw new NotImplementedException();
public static MessageInfo? Create(MessageInfoBindingModel model)
{
if (model == null)
{
return null;
}
return new()
{
Body = model.Body,
Subject = model.Subject,
ClientId = model.ClientId,
MessageId = model.MessageId,
SenderName = model.SenderName,
DateDelivery = model.DateDelivery,
};
}
public MessageInfoViewModel GetViewModel => new()
{
Body = Body,
Subject = Subject,
ClientId = ClientId,
MessageId = MessageId,
SenderName = SenderName,
DateDelivery = DateDelivery,
};
}
}

View File

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