лр6 коммит
This commit is contained in:
parent
bf3a4908ef
commit
c6d13da0f3
@ -15,10 +15,12 @@ namespace PrecastConcretePlantFileImplement
|
||||
private readonly string OrderFileName = "Order.xml";
|
||||
private readonly string ReinforcedFileName = "Reinforced.xml";
|
||||
private readonly string ClientFileName = "Client.xml";
|
||||
private readonly string ImplementerFileName = "Implementer.xml";
|
||||
public List<Component> Components { get; private set; }
|
||||
public List<Order> Orders { get; private set; }
|
||||
public List<Reinforced> Reinforceds { get; private set; }
|
||||
public List<Client> Clients { get; private set; }
|
||||
public List<Implementer> Implementers { get; private set; }
|
||||
public static DataFileSingleton GetInstance()
|
||||
{
|
||||
if (instance == null)
|
||||
@ -35,6 +37,8 @@ namespace PrecastConcretePlantFileImplement
|
||||
=> x.GetXElement);
|
||||
public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x
|
||||
=> x.GetXElement);
|
||||
public void SaveImplementers() => SaveData(Implementers, OrderFileName, "Implementers", x
|
||||
=> x.GetXElement);
|
||||
private DataFileSingleton()
|
||||
{
|
||||
Components = LoadData(ComponentFileName, "Component", x =>
|
||||
@ -43,6 +47,7 @@ namespace PrecastConcretePlantFileImplement
|
||||
Reinforced.Create(x)!)!;
|
||||
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||
Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!;
|
||||
Implementers=LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!;
|
||||
}
|
||||
private static List<T>? LoadData<T>(string filename, string xmlNodeName,
|
||||
Func<XElement, T> selectFunction)
|
||||
|
103
PrecastConcreteFileImplement/Implements/ImplementerStorage.cs
Normal file
103
PrecastConcreteFileImplement/Implements/ImplementerStorage.cs
Normal file
@ -0,0 +1,103 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PrecastConcretePlantFileImplement.Implements
|
||||
{
|
||||
public class ImplementerStorage : IImplementerStorage
|
||||
{
|
||||
private readonly DataFileSingleton _source;
|
||||
public ImplementerStorage()
|
||||
{
|
||||
_source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
public ImplementerViewModel? Delete(ImplementerBindingModel model)
|
||||
{
|
||||
var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (res != null)
|
||||
{
|
||||
_source.Implementers.Remove(res);
|
||||
_source.SaveImplementers();
|
||||
}
|
||||
return res?.GetViewModel;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? GetElement(ImplementerSearchModel model)
|
||||
{
|
||||
if (model.Id.HasValue)
|
||||
return _source.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||
|
||||
if (model.ImplementerFIO != null && model.Password != null)
|
||||
return _source.Implementers
|
||||
.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO)
|
||||
&& x.Password.Equals(model.Password))
|
||||
?.GetViewModel;
|
||||
|
||||
if (model.ImplementerFIO != null)
|
||||
return _source.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))?.GetViewModel;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
var res = GetElement(model);
|
||||
|
||||
return res != null ? new() { res } : new();
|
||||
}
|
||||
|
||||
if (model.ImplementerFIO != null)
|
||||
{
|
||||
return _source.Implementers
|
||||
.Where(x => x.ImplementerFIO.Equals(model.ImplementerFIO))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return new();
|
||||
}
|
||||
|
||||
public List<ImplementerViewModel> GetFullList()
|
||||
{
|
||||
return _source.Implementers.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Insert(ImplementerBindingModel model)
|
||||
{
|
||||
model.Id = _source.Implementers.Count > 0 ? _source.Implementers.Max(x => x.Id) + 1 : 1;
|
||||
|
||||
var res = Implementer.Create(model);
|
||||
|
||||
if (res != null)
|
||||
{
|
||||
_source.Implementers.Add(res);
|
||||
_source.SaveImplementers();
|
||||
}
|
||||
|
||||
return res?.GetViewModel;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Update(ImplementerBindingModel model)
|
||||
{
|
||||
var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (res != null)
|
||||
{
|
||||
res.Update(model);
|
||||
_source.SaveImplementers();
|
||||
}
|
||||
|
||||
return res?.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -37,6 +37,20 @@ namespace PrecastConcretePlantFileImplement.Implements
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (model.ImplementerId.HasValue && model.Statuses != null)
|
||||
{
|
||||
return source.Orders
|
||||
.FirstOrDefault(x => x.ImplementerId == model.ImplementerId &&
|
||||
model.Statuses.Contains(x.Status))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
if (model.ImplementerId.HasValue)
|
||||
{
|
||||
return source.Orders
|
||||
.FirstOrDefault(x => x.ImplementerId == model.ImplementerId)
|
||||
?.GetViewModel;
|
||||
}
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
|
82
PrecastConcreteFileImplement/Models/Implementer.cs
Normal file
82
PrecastConcreteFileImplement/Models/Implementer.cs
Normal file
@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PrecastConcretePlantFileImplement.Models
|
||||
{
|
||||
public class Implementer : IImplementerModel
|
||||
{
|
||||
public string ImplementerFIO { get; private set; } = string.Empty;
|
||||
|
||||
public string Password { get; private set; } = string.Empty;
|
||||
|
||||
public int WorkExperience { get; private set; }
|
||||
|
||||
public int Qualification { get; private set; }
|
||||
|
||||
public int Id { get; private set; }
|
||||
|
||||
public static Implementer? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new()
|
||||
{
|
||||
ImplementerFIO = element.Element("FIO")!.Value,
|
||||
Password = element.Element("Password")!.Value,
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
Qualification = Convert.ToInt32(element.Element("Qualification")!.Value),
|
||||
WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value),
|
||||
};
|
||||
}
|
||||
|
||||
public static Implementer? Create(ImplementerBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new()
|
||||
{
|
||||
Id = model.Id,
|
||||
Password = model.Password,
|
||||
Qualification = model.Qualification,
|
||||
ImplementerFIO = model.ImplementerFIO,
|
||||
WorkExperience = model.WorkExperience,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ImplementerBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Password = model.Password;
|
||||
Qualification = model.Qualification;
|
||||
ImplementerFIO = model.ImplementerFIO;
|
||||
WorkExperience = model.WorkExperience;
|
||||
}
|
||||
|
||||
public ImplementerViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Password = Password,
|
||||
Qualification = Qualification,
|
||||
ImplementerFIO = ImplementerFIO,
|
||||
WorkExperience = WorkExperience
|
||||
};
|
||||
|
||||
public XElement GetXElement => new("Client",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("Password", Password),
|
||||
new XElement("FIO", ImplementerFIO),
|
||||
new XElement("Qualification", Qualification),
|
||||
new XElement("WorkExperience", WorkExperience)
|
||||
);
|
||||
}
|
||||
}
|
@ -13,6 +13,7 @@ namespace PrecastConcretePlantFileImplement.Models
|
||||
{
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int? ImplementerId { get; set; }
|
||||
public int ClientId { get; private set; }
|
||||
public int ReinforcedId { get; private set; }
|
||||
public int Count { get; private set; }
|
||||
@ -36,6 +37,7 @@ namespace PrecastConcretePlantFileImplement.Models
|
||||
return new Order()
|
||||
{
|
||||
Id = model.Id,
|
||||
ImplementerId = model.ImplementerId,
|
||||
ClientId = model.ClientId,
|
||||
ReinforcedId = model.ReinforcedId,
|
||||
Count = model.Count,
|
||||
@ -56,8 +58,9 @@ namespace PrecastConcretePlantFileImplement.Models
|
||||
var order = new Order()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value)
|
||||
ReinforcedId = Convert.ToInt32(element.Element("ReinforcedId")!.Value),
|
||||
ClientId=Convert.ToInt32(element.Element("ClientId")!.Value),
|
||||
ClientId = Convert.ToInt32(element.Element("ClientId")!.Value),
|
||||
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
||||
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
|
||||
Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
|
||||
@ -85,6 +88,7 @@ namespace PrecastConcretePlantFileImplement.Models
|
||||
{
|
||||
Id = Id,
|
||||
ClientId = ClientId,
|
||||
ImplementerId = ImplementerId,
|
||||
ReinforcedId = ReinforcedId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
@ -95,7 +99,8 @@ namespace PrecastConcretePlantFileImplement.Models
|
||||
|
||||
public XElement GetXElement => new("Order",
|
||||
new XAttribute("Id", Id),
|
||||
new XAttribute("ClientId",ClientId.ToString()),
|
||||
new XAttribute("ClientId", ClientId.ToString()),
|
||||
new XElement("ImplementerId", ImplementerId.ToString()),
|
||||
new XElement("ReinforcedId", ReinforcedId.ToString()),
|
||||
new XElement("Count", Count.ToString()),
|
||||
new XElement("Sum", Sum.ToString()),
|
||||
|
@ -19,7 +19,6 @@ namespace PrecastConcretePlantContracts.ViewModels
|
||||
public int? ImplementerId { get; set; }
|
||||
[DisplayName("ФИО исполнителя")]
|
||||
public string? ImplementerFIO { get; set; } = string.Empty;
|
||||
[DisplayName("Количество")]
|
||||
public int ReinforcedId { get; set; }
|
||||
[DisplayName("ЖБИ")]
|
||||
public string ReinforcedName { get; set; } = string.Empty;
|
||||
|
@ -24,52 +24,80 @@ namespace PrecastConcretePlantDatabaseImplement.Implements
|
||||
|
||||
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model)
|
||||
{
|
||||
using var context = new PrecastConcretePlantDatabase();
|
||||
return context.Implementers
|
||||
if (model == null)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
var implementer = GetElement(model);
|
||||
|
||||
return implementer != null ? new() { implementer } : new();
|
||||
}
|
||||
|
||||
if (model.ImplementerFIO != null)
|
||||
{
|
||||
using var context = new SoftwareInstallationDataBase();
|
||||
|
||||
return context.Implementers
|
||||
.Where(x => x.ImplementerFIO.Equals(model.ImplementerFIO))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return new();
|
||||
}
|
||||
|
||||
public ImplementerViewModel? GetElement(ImplementerSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new PrecastConcretePlantDatabase();
|
||||
return context.Implementers
|
||||
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
||||
if (model.Id.HasValue)
|
||||
return context.Implementers
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
|
||||
if (model.ImplementerFIO != null && model.Password != null)
|
||||
return context.Implementers
|
||||
.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO)
|
||||
&& x.Password.Equals(model.Password))
|
||||
?.GetViewModel;
|
||||
|
||||
if (model.ImplementerFIO != null)
|
||||
return context.Implementers
|
||||
.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))
|
||||
?.GetViewModel;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Insert(ImplementerBindingModel model)
|
||||
{
|
||||
var newImplementer = Implementer.Create(model);
|
||||
if (newImplementer == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new PrecastConcretePlantDatabase();
|
||||
context.Implementers.Add(newImplementer);
|
||||
context.SaveChanges();
|
||||
return context.Implementers
|
||||
.FirstOrDefault(x => x.Id == newImplementer.Id)
|
||||
?.GetViewModel;
|
||||
var implementer = Implementer.Create(model);
|
||||
|
||||
if (implementer != null)
|
||||
{
|
||||
context.Implementers.Add(implementer);
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
return implementer?.GetViewModel;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Update(ImplementerBindingModel model)
|
||||
{
|
||||
using var context = new PrecastConcretePlantDatabase();
|
||||
var implementer = context.Implementers.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (implementer == null)
|
||||
var implementer = context.Implementers
|
||||
.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (implementer != null)
|
||||
{
|
||||
return null;
|
||||
implementer.Update(model);
|
||||
context.SaveChanges();
|
||||
}
|
||||
implementer.Update(model);
|
||||
context.SaveChanges();
|
||||
return context.Implementers
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
|
||||
return implementer?.GetViewModel;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Delete(ImplementerBindingModel model)
|
||||
@ -81,9 +109,8 @@ namespace PrecastConcretePlantDatabaseImplement.Implements
|
||||
{
|
||||
context.Implementers.Remove(implementer);
|
||||
context.SaveChanges();
|
||||
return implementer.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
return implementer?.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -48,6 +48,10 @@ namespace PrecastConcretePlantDatabaseImplement.Models
|
||||
|
||||
public void Update(ImplementerBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ImplementerFIO = model.ImplementerFIO;
|
||||
Password = model.Password;
|
||||
WorkExperience = model.WorkExperience;
|
||||
|
@ -60,10 +60,7 @@ namespace PrecastConcretePlantDatabaseImplement.Models
|
||||
}
|
||||
Status = model.Status;
|
||||
DateImplement = model.DateImplement;
|
||||
if (model.ImplementerId.HasValue)
|
||||
{
|
||||
ImplementerId = model.ImplementerId;
|
||||
}
|
||||
ImplementerId = model.ImplementerId;
|
||||
}
|
||||
|
||||
public OrderViewModel GetViewModel
|
||||
|
@ -14,12 +14,14 @@ namespace PrecastConcretePlantListImplement
|
||||
public List<Order> Orders { get; set; }
|
||||
public List<Reinforced> Reinforceds { get; set; }
|
||||
public List<Client> Clients { get; set; }
|
||||
public List<Implementer> Implementers { get; set; }
|
||||
private DataListSingleton()
|
||||
{
|
||||
Components = new List<Component>();
|
||||
Orders = new List<Order>();
|
||||
Reinforceds = new List<Reinforced>();
|
||||
Clients = new List<Client>();
|
||||
Implementers = new List<Implementer>();
|
||||
}
|
||||
public static DataListSingleton GetInstance()
|
||||
{
|
||||
|
@ -0,0 +1,130 @@
|
||||
using PrecastConcretePlantContracts.BindingModels;
|
||||
using PrecastConcretePlantContracts.SearchModels;
|
||||
using PrecastConcretePlantContracts.StoragesContracts;
|
||||
using PrecastConcretePlantContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PrecastConcretePlantListImplement.Implements
|
||||
{
|
||||
public class ImplementerStorage : IImplementerStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
public ImplementerStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Delete(ImplementerBindingModel model)
|
||||
{
|
||||
for (int i = 0; i < _source.Implementers.Count; ++i)
|
||||
{
|
||||
if (_source.Implementers[i].Id == model.Id)
|
||||
{
|
||||
var element = _source.Implementers[i];
|
||||
_source.Implementers.RemoveAt(i);
|
||||
|
||||
return element.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? GetElement(ImplementerSearchModel model)
|
||||
{
|
||||
foreach (var x in _source.Implementers)
|
||||
{
|
||||
if (model.Id.HasValue && x.Id == model.Id)
|
||||
return x.GetViewModel;
|
||||
|
||||
if (model.ImplementerFIO != null && model.Password != null &&
|
||||
x.ImplementerFIO.Equals(model.ImplementerFIO) &&
|
||||
x.Password.Equals(model.Password))
|
||||
return x.GetViewModel;
|
||||
|
||||
if (model.ImplementerFIO != null && x.ImplementerFIO.Equals(model.ImplementerFIO))
|
||||
return x.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
var res = GetElement(model);
|
||||
|
||||
return res != null ? new() { res } : new();
|
||||
}
|
||||
|
||||
List<ImplementerViewModel> result = new();
|
||||
|
||||
if (model.ImplementerFIO != null)
|
||||
{
|
||||
foreach (var implementer in _source.Implementers)
|
||||
{
|
||||
if (implementer.ImplementerFIO.Equals(model.ImplementerFIO))
|
||||
{
|
||||
result.Add(implementer.GetViewModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<ImplementerViewModel> GetFullList()
|
||||
{
|
||||
var result = new List<ImplementerViewModel>();
|
||||
|
||||
foreach (var implementer in _source.Implementers)
|
||||
{
|
||||
result.Add(implementer.GetViewModel);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Insert(ImplementerBindingModel model)
|
||||
{
|
||||
model.Id = 1;
|
||||
|
||||
foreach (var implementer in _source.Implementers)
|
||||
{
|
||||
if (model.Id <= implementer.Id)
|
||||
{
|
||||
model.Id = implementer.Id + 1;
|
||||
}
|
||||
}
|
||||
|
||||
var res = Implementer.Create(model);
|
||||
|
||||
if (res != null)
|
||||
{
|
||||
_source.Implementers.Add(res);
|
||||
}
|
||||
return res?.GetViewModel;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Update(ImplementerBindingModel model)
|
||||
{
|
||||
foreach (var implementer in _source.Implementers)
|
||||
{
|
||||
if (implementer.Id == model.Id)
|
||||
{
|
||||
implementer.Update(model);
|
||||
|
||||
return implementer.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -47,6 +47,18 @@ namespace PrecastConcretePlantListImplement.Implements
|
||||
{
|
||||
return order.GetViewModel;
|
||||
}
|
||||
else if (model.ImplementerId.HasValue && model.Statuses != null &&
|
||||
order.ImplementerId == model.ImplementerId &&
|
||||
model.Statuses.Contains(order.Status))
|
||||
{
|
||||
return GetViewModel(order);
|
||||
}
|
||||
|
||||
else if (model.ImplementerId.HasValue &&
|
||||
model.ImplementerId == order.ImplementerId)
|
||||
{
|
||||
return GetViewModel(order);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
@ -69,6 +81,15 @@ namespace PrecastConcretePlantListImplement.Implements
|
||||
{
|
||||
result.Add(order.GetViewModel);
|
||||
}
|
||||
else if (model.ImplementerId.HasValue && order.ImplementerId == model.ImplementerId)
|
||||
{
|
||||
result.Add(order.GetViewModel);
|
||||
}
|
||||
|
||||
else if (model.Status != null && model.Status.Contains(order.Status))
|
||||
{
|
||||
result.Add(order.GetViewModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (model.DateFrom != null && model.DateTo != null)
|
||||
|
Loading…
Reference in New Issue
Block a user