PIbd-22. Stroev V.M. Lab Work 02 #2
@ -40,7 +40,7 @@
|
|||||||
//
|
//
|
||||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
dataGridView.Location = new Point(10, 8);
|
dataGridView.Location = new Point(10, 8);
|
||||||
dataGridView.Margin = new Padding(2, 2, 2, 2);
|
dataGridView.Margin = new Padding(2);
|
||||||
dataGridView.Name = "dataGridView";
|
dataGridView.Name = "dataGridView";
|
||||||
dataGridView.RowHeadersWidth = 62;
|
dataGridView.RowHeadersWidth = 62;
|
||||||
dataGridView.RowTemplate.Height = 33;
|
dataGridView.RowTemplate.Height = 33;
|
||||||
@ -50,7 +50,7 @@
|
|||||||
// buttonAdd
|
// buttonAdd
|
||||||
//
|
//
|
||||||
buttonAdd.Location = new Point(547, 33);
|
buttonAdd.Location = new Point(547, 33);
|
||||||
buttonAdd.Margin = new Padding(2, 2, 2, 2);
|
buttonAdd.Margin = new Padding(2);
|
||||||
buttonAdd.Name = "buttonAdd";
|
buttonAdd.Name = "buttonAdd";
|
||||||
buttonAdd.Size = new Size(108, 27);
|
buttonAdd.Size = new Size(108, 27);
|
||||||
buttonAdd.TabIndex = 1;
|
buttonAdd.TabIndex = 1;
|
||||||
@ -61,7 +61,7 @@
|
|||||||
// buttonDel
|
// buttonDel
|
||||||
//
|
//
|
||||||
buttonDel.Location = new Point(547, 85);
|
buttonDel.Location = new Point(547, 85);
|
||||||
buttonDel.Margin = new Padding(2, 2, 2, 2);
|
buttonDel.Margin = new Padding(2);
|
||||||
buttonDel.Name = "buttonDel";
|
buttonDel.Name = "buttonDel";
|
||||||
buttonDel.Size = new Size(108, 27);
|
buttonDel.Size = new Size(108, 27);
|
||||||
buttonDel.TabIndex = 2;
|
buttonDel.TabIndex = 2;
|
||||||
@ -72,7 +72,7 @@
|
|||||||
// buttonChange
|
// buttonChange
|
||||||
//
|
//
|
||||||
buttonChange.Location = new Point(547, 147);
|
buttonChange.Location = new Point(547, 147);
|
||||||
buttonChange.Margin = new Padding(2, 2, 2, 2);
|
buttonChange.Margin = new Padding(2);
|
||||||
buttonChange.Name = "buttonChange";
|
buttonChange.Name = "buttonChange";
|
||||||
buttonChange.Size = new Size(108, 27);
|
buttonChange.Size = new Size(108, 27);
|
||||||
buttonChange.TabIndex = 3;
|
buttonChange.TabIndex = 3;
|
||||||
@ -83,7 +83,7 @@
|
|||||||
// buttonRef
|
// buttonRef
|
||||||
//
|
//
|
||||||
buttonRef.Location = new Point(547, 209);
|
buttonRef.Location = new Point(547, 209);
|
||||||
buttonRef.Margin = new Padding(2, 2, 2, 2);
|
buttonRef.Margin = new Padding(2);
|
||||||
buttonRef.Name = "buttonRef";
|
buttonRef.Name = "buttonRef";
|
||||||
buttonRef.Size = new Size(108, 27);
|
buttonRef.Size = new Size(108, 27);
|
||||||
buttonRef.TabIndex = 4;
|
buttonRef.TabIndex = 4;
|
||||||
@ -101,9 +101,10 @@
|
|||||||
Controls.Add(buttonDel);
|
Controls.Add(buttonDel);
|
||||||
Controls.Add(buttonAdd);
|
Controls.Add(buttonAdd);
|
||||||
Controls.Add(dataGridView);
|
Controls.Add(dataGridView);
|
||||||
Margin = new Padding(2, 2, 2, 2);
|
Margin = new Padding(2);
|
||||||
Name = "FormComponents";
|
Name = "FormComponents";
|
||||||
Text = "Компоненты";
|
Text = "Компоненты";
|
||||||
|
Load += FormComponents_Load;
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@
|
|||||||
//
|
//
|
||||||
buttonTakeOrderInWork.Location = new Point(608, 132);
|
buttonTakeOrderInWork.Location = new Point(608, 132);
|
||||||
buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
|
buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
|
||||||
buttonTakeOrderInWork.Size = new Size(170, 29);
|
buttonTakeOrderInWork.Size = new Size(170, 50);
|
||||||
buttonTakeOrderInWork.TabIndex = 3;
|
buttonTakeOrderInWork.TabIndex = 3;
|
||||||
buttonTakeOrderInWork.Text = "Отдать на выполнение";
|
buttonTakeOrderInWork.Text = "Отдать на выполнение";
|
||||||
buttonTakeOrderInWork.UseVisualStyleBackColor = true;
|
buttonTakeOrderInWork.UseVisualStyleBackColor = true;
|
||||||
|
110
PlumbingRepair/PlumbingRepair/FormWorks.Designer.cs
generated
110
PlumbingRepair/PlumbingRepair/FormWorks.Designer.cs
generated
@ -28,79 +28,79 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
this.dataGridView = new System.Windows.Forms.DataGridView();
|
dataGridView = new DataGridView();
|
||||||
this.buttonAdd = new System.Windows.Forms.Button();
|
buttonAdd = new Button();
|
||||||
this.buttonUpd = new System.Windows.Forms.Button();
|
buttonUpd = new Button();
|
||||||
this.buttonDel = new System.Windows.Forms.Button();
|
buttonDel = new Button();
|
||||||
this.buttonRef = new System.Windows.Forms.Button();
|
buttonRef = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||||
this.SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// dataGridView
|
// dataGridView
|
||||||
//
|
//
|
||||||
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
this.dataGridView.Location = new System.Drawing.Point(1, 0);
|
dataGridView.Location = new Point(1, 0);
|
||||||
this.dataGridView.Name = "dataGridView";
|
dataGridView.Name = "dataGridView";
|
||||||
this.dataGridView.RowHeadersWidth = 51;
|
dataGridView.RowHeadersWidth = 51;
|
||||||
this.dataGridView.RowTemplate.Height = 29;
|
dataGridView.RowTemplate.Height = 29;
|
||||||
this.dataGridView.Size = new System.Drawing.Size(611, 449);
|
dataGridView.Size = new Size(611, 449);
|
||||||
this.dataGridView.TabIndex = 0;
|
dataGridView.TabIndex = 0;
|
||||||
//
|
//
|
||||||
// buttonAdd
|
// buttonAdd
|
||||||
//
|
//
|
||||||
this.buttonAdd.Location = new System.Drawing.Point(670, 23);
|
buttonAdd.Location = new Point(670, 23);
|
||||||
this.buttonAdd.Name = "buttonAdd";
|
buttonAdd.Name = "buttonAdd";
|
||||||
this.buttonAdd.Size = new System.Drawing.Size(94, 29);
|
buttonAdd.Size = new Size(94, 29);
|
||||||
this.buttonAdd.TabIndex = 1;
|
buttonAdd.TabIndex = 1;
|
||||||
this.buttonAdd.Text = "Добавить";
|
buttonAdd.Text = "Добавить";
|
||||||
this.buttonAdd.UseVisualStyleBackColor = true;
|
buttonAdd.UseVisualStyleBackColor = true;
|
||||||
this.buttonAdd.Click += new System.EventHandler(this.AddButton_Click);
|
buttonAdd.Click += AddButton_Click;
|
||||||
//
|
//
|
||||||
// buttonUpd
|
// buttonUpd
|
||||||
//
|
//
|
||||||
this.buttonUpd.Location = new System.Drawing.Point(670, 75);
|
buttonUpd.Location = new Point(670, 75);
|
||||||
this.buttonUpd.Name = "buttonUpd";
|
buttonUpd.Name = "buttonUpd";
|
||||||
this.buttonUpd.Size = new System.Drawing.Size(94, 29);
|
buttonUpd.Size = new Size(94, 29);
|
||||||
this.buttonUpd.TabIndex = 2;
|
buttonUpd.TabIndex = 2;
|
||||||
this.buttonUpd.Text = "Изменить";
|
buttonUpd.Text = "Изменить";
|
||||||
this.buttonUpd.UseVisualStyleBackColor = true;
|
buttonUpd.UseVisualStyleBackColor = true;
|
||||||
this.buttonUpd.Click += new System.EventHandler(this.ChangeButton_Click);
|
buttonUpd.Click += ChangeButton_Click;
|
||||||
//
|
//
|
||||||
// buttonDel
|
// buttonDel
|
||||||
//
|
//
|
||||||
this.buttonDel.Location = new System.Drawing.Point(670, 132);
|
buttonDel.Location = new Point(670, 132);
|
||||||
this.buttonDel.Name = "buttonDel";
|
buttonDel.Name = "buttonDel";
|
||||||
this.buttonDel.Size = new System.Drawing.Size(94, 29);
|
buttonDel.Size = new Size(94, 29);
|
||||||
this.buttonDel.TabIndex = 3;
|
buttonDel.TabIndex = 3;
|
||||||
this.buttonDel.Text = "Удалить";
|
buttonDel.Text = "Удалить";
|
||||||
this.buttonDel.UseVisualStyleBackColor = true;
|
buttonDel.UseVisualStyleBackColor = true;
|
||||||
this.buttonDel.Click += new System.EventHandler(this.DeleteButton_Click);
|
buttonDel.Click += DeleteButton_Click;
|
||||||
//
|
//
|
||||||
// buttonRef
|
// buttonRef
|
||||||
//
|
//
|
||||||
this.buttonRef.Location = new System.Drawing.Point(670, 188);
|
buttonRef.Location = new Point(670, 188);
|
||||||
this.buttonRef.Name = "buttonRef";
|
buttonRef.Name = "buttonRef";
|
||||||
this.buttonRef.Size = new System.Drawing.Size(94, 29);
|
buttonRef.Size = new Size(94, 29);
|
||||||
this.buttonRef.TabIndex = 4;
|
buttonRef.TabIndex = 4;
|
||||||
this.buttonRef.Text = "Обновить";
|
buttonRef.Text = "Обновить";
|
||||||
this.buttonRef.UseVisualStyleBackColor = true;
|
buttonRef.UseVisualStyleBackColor = true;
|
||||||
this.buttonRef.Click += new System.EventHandler(this.UpdateButton_Click);
|
buttonRef.Click += UpdateButton_Click;
|
||||||
//
|
//
|
||||||
// FormWorks
|
// FormWorks
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
ClientSize = new Size(800, 450);
|
||||||
this.Controls.Add(this.buttonRef);
|
Controls.Add(buttonRef);
|
||||||
this.Controls.Add(this.buttonDel);
|
Controls.Add(buttonDel);
|
||||||
this.Controls.Add(this.buttonUpd);
|
Controls.Add(buttonUpd);
|
||||||
this.Controls.Add(this.buttonAdd);
|
Controls.Add(buttonAdd);
|
||||||
this.Controls.Add(this.dataGridView);
|
Controls.Add(dataGridView);
|
||||||
this.Name = "FormWorks";
|
Name = "FormWorks";
|
||||||
this.Text = "Работы";
|
Text = "Работы";
|
||||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
Load += FormComponents_Load;
|
||||||
this.ResumeLayout(false);
|
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
<data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data>
|
||||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
</data>
|
</data>
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\PlumbingRepairBusinessLogic\PlumbingRepairBusinessLogic.csproj" />
|
<ProjectReference Include="..\PlumbingRepairBusinessLogic\PlumbingRepairBusinessLogic.csproj" />
|
||||||
<ProjectReference Include="..\PlumbingRepairContracts\PlumbingRepairContracts.csproj" />
|
<ProjectReference Include="..\PlumbingRepairContracts\PlumbingRepairContracts.csproj" />
|
||||||
|
<ProjectReference Include="..\PlumbingRepairFileImplement\PlumbingRepairFileImplement.csproj" />
|
||||||
<ProjectReference Include="..\PlumbingRepairListImplement\PlumbingRepairListImplement.csproj" />
|
<ProjectReference Include="..\PlumbingRepairListImplement\PlumbingRepairListImplement.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using PlumbingRepairContracts.BusinessLogicsContracts;
|
using PlumbingRepairContracts.BusinessLogicsContracts;
|
||||||
using PlumbingRepairContracts.StoragesContracts;
|
using PlumbingRepairContracts.StoragesContracts;
|
||||||
using PlumbingRepairListImplement.Implements;
|
using PlumbingRepairFileImplement.Implements;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using NLog.Extensions.Logging;
|
using NLog.Extensions.Logging;
|
||||||
|
@ -0,0 +1,62 @@
|
|||||||
|
using PlumbingRepairFileImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace PlumbingRepairFileImplement
|
||||||
|
{
|
||||||
|
internal class DataFileSingleton
|
||||||
|
{
|
||||||
|
private static DataFileSingleton? instance;
|
||||||
|
private readonly string ComponentFileName = "Component.xml";
|
||||||
|
private readonly string OrderFileName = "Order.xml";
|
||||||
|
private readonly string WorkFileName = "Work.xml";
|
||||||
|
public List<Component> Components { get; private set; }
|
||||||
|
public List<Order> Orders { get; private set; }
|
||||||
|
public List<Work> Works { get; private set; }
|
||||||
|
public static DataFileSingleton GetInstance()
|
||||||
|
{
|
||||||
|
if (instance == null)
|
||||||
|
{
|
||||||
|
instance = new DataFileSingleton();
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
public void SaveComponents() => SaveData(Components, ComponentFileName,
|
||||||
|
"Components", x => x.GetXElement);
|
||||||
|
public void SaveWorks() => SaveData(Works, WorkFileName,
|
||||||
|
"Works", x => x.GetXElement);
|
||||||
|
public void SaveOrders() => SaveData(Orders, OrderFileName,
|
||||||
|
"Orders", x => x.GetXElement);
|
||||||
|
private DataFileSingleton()
|
||||||
|
{
|
||||||
|
Components = LoadData(ComponentFileName, "Component", x =>
|
||||||
|
Component.Create(x)!)!;
|
||||||
|
Works = LoadData(WorkFileName, "Work", x =>
|
||||||
|
Work.Create(x)!)!;
|
||||||
|
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||||
|
}
|
||||||
|
private static List<T>? LoadData<T>(string filename, string xmlNodeName,
|
||||||
|
Func<XElement, T> selectFunction)
|
||||||
|
{
|
||||||
|
if (File.Exists(filename))
|
||||||
|
{
|
||||||
|
return XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?
|
||||||
|
.Select(selectFunction)?.ToList();
|
||||||
|
}
|
||||||
|
return new List<T>();
|
||||||
|
}
|
||||||
|
private static void SaveData<T>(List<T> data, string filename, string
|
||||||
|
xmlNodeName, Func<T, XElement> selectFunction)
|
||||||
|
{
|
||||||
|
if (data != null)
|
||||||
|
{
|
||||||
|
new XDocument(new XElement(xmlNodeName,
|
||||||
|
data.Select(selectFunction).ToArray())).Save(filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,90 @@
|
|||||||
|
using PlumbingRepairContracts.BindingModels;
|
||||||
|
using PlumbingRepairContracts.SearchModels;
|
||||||
|
using PlumbingRepairContracts.StoragesContracts;
|
||||||
|
using PlumbingRepairContracts.ViewModels;
|
||||||
|
using PlumbingRepairFileImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PlumbingRepairFileImplement.Implements
|
||||||
|
{
|
||||||
|
public class ComponentStorage : IComponentStorage
|
||||||
|
{
|
||||||
|
private readonly DataFileSingleton source;
|
||||||
|
public ComponentStorage()
|
||||||
|
{
|
||||||
|
source = DataFileSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
public List<ComponentViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
return source.Components
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel
|
||||||
|
model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ComponentName))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
return source.Components
|
||||||
|
.Where(x => x.ComponentName.Contains(model.ComponentName))
|
||||||
|
.Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
public ComponentViewModel? GetElement(ComponentSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return source.Components
|
||||||
|
.FirstOrDefault(x =>
|
||||||
|
(!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName ==
|
||||||
|
model.ComponentName) ||
|
||||||
|
(model.Id.HasValue && x.Id == model.Id))
|
||||||
|
?.GetViewModel;
|
||||||
|
}
|
||||||
|
public ComponentViewModel? Insert(ComponentBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = source.Components.Count > 0 ? source.Components.Max(x =>
|
||||||
|
x.Id) + 1 : 1;
|
||||||
|
var newComponent = Component.Create(model);
|
||||||
|
if (newComponent == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
source.Components.Add(newComponent);
|
||||||
|
source.SaveComponents();
|
||||||
|
return newComponent.GetViewModel;
|
||||||
|
}
|
||||||
|
public ComponentViewModel? Update(ComponentBindingModel model)
|
||||||
|
{
|
||||||
|
var component = source.Components.FirstOrDefault(x => x.Id ==
|
||||||
|
model.Id);
|
||||||
|
if (component == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
component.Update(model);
|
||||||
|
source.SaveComponents();
|
||||||
|
return component.GetViewModel;
|
||||||
|
}
|
||||||
|
public ComponentViewModel? Delete(ComponentBindingModel model)
|
||||||
|
{
|
||||||
|
var element = source.Components.FirstOrDefault(x => x.Id ==
|
||||||
|
model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
source.Components.Remove(element);
|
||||||
|
source.SaveComponents();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,93 @@
|
|||||||
|
using PlumbingRepairContracts.BindingModels;
|
||||||
|
using PlumbingRepairContracts.SearchModels;
|
||||||
|
using PlumbingRepairContracts.StoragesContracts;
|
||||||
|
using PlumbingRepairContracts.ViewModels;
|
||||||
|
using PlumbingRepairFileImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PlumbingRepairFileImplement.Implements
|
||||||
|
{
|
||||||
|
public class OrderStorage : IOrderStorage
|
||||||
|
{
|
||||||
|
private readonly DataFileSingleton source;
|
||||||
|
|
||||||
|
public OrderStorage()
|
||||||
|
{
|
||||||
|
source = DataFileSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<OrderViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
return source.Orders.Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
return source.Orders.Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return source.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? Insert(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1;
|
||||||
|
var newOrder = Order.Create(model);
|
||||||
|
|
||||||
|
if (newOrder == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
source.Orders.Add(newOrder);
|
||||||
|
source.SaveOrders();
|
||||||
|
|
||||||
|
return newOrder.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
|
||||||
|
if (order == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
order.Update(model);
|
||||||
|
source.SaveOrders();
|
||||||
|
|
||||||
|
return order.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? Delete(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
var element = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
source.Orders.Remove(element);
|
||||||
|
source.SaveOrders();
|
||||||
|
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,94 @@
|
|||||||
|
using PlumbingRepairContracts.BindingModels;
|
||||||
|
using PlumbingRepairContracts.SearchModels;
|
||||||
|
using PlumbingRepairContracts.StoragesContracts;
|
||||||
|
using PlumbingRepairContracts.ViewModels;
|
||||||
|
using PlumbingRepairFileImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PlumbingRepairFileImplement.Implements
|
||||||
|
{
|
||||||
|
public class WorkStorage : IWorkStorage
|
||||||
|
{
|
||||||
|
private readonly DataFileSingleton source;
|
||||||
|
|
||||||
|
public WorkStorage()
|
||||||
|
{
|
||||||
|
source = DataFileSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<WorkViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
return source.Works.Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<WorkViewModel> GetFilteredList(WorkSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.WorkName))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
|
||||||
|
return source.Works.Where(x => x.WorkName.Contains(model.WorkName)).Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public WorkViewModel? GetElement(WorkSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.WorkName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return source.Works.FirstOrDefault(x => (!string.IsNullOrEmpty(model.WorkName) && x.WorkName == model.WorkName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public WorkViewModel? Insert(WorkBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = source.Works.Count > 0 ? source.Works.Max(x => x.Id) + 1 : 1;
|
||||||
|
var newWork = Work.Create(model);
|
||||||
|
|
||||||
|
if (newWork == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
source.Works.Add(newWork);
|
||||||
|
source.SaveWorks();
|
||||||
|
|
||||||
|
return newWork.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public WorkViewModel? Update(WorkBindingModel model)
|
||||||
|
{
|
||||||
|
var work = source.Works.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
|
||||||
|
if (work == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
work.Update(model);
|
||||||
|
source.SaveWorks();
|
||||||
|
|
||||||
|
return work.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public WorkViewModel? Delete(WorkBindingModel model)
|
||||||
|
{
|
||||||
|
var element = source.Works.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
source.Works.Remove(element);
|
||||||
|
source.SaveWorks();
|
||||||
|
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -18,9 +18,10 @@ namespace PlumbingRepairFileImplement.Models
|
|||||||
public String WorkName { get; private set; } = string.Empty;
|
public String WorkName { get; private set; } = string.Empty;
|
||||||
|
|||||||
public int Count { get; private set; }
|
public int Count { get; private set; }
|
||||||
public double Sum { get; private set; }
|
public double Sum { get; private set; }
|
||||||
public OrderStatus Status { get; private set; }
|
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
||||||
public DateTime DateCreate { get; private set; }
|
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||||
public DateTime? DateImplement { get; private set; }
|
public DateTime? DateImplement { get; private set; }
|
||||||
|
|
||||||
public static Order? Create(OrderBindingModel? model)
|
public static Order? Create(OrderBindingModel? model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
@ -48,13 +49,14 @@ namespace PlumbingRepairFileImplement.Models
|
|||||||
return new Order()
|
return new Order()
|
||||||
{
|
{
|
||||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||||
WorkId = Convert.ToInt32(element.Attribute("WorkId")!.Value),
|
WorkId = Convert.ToInt32(element.Element("WorkId")!.Value),
|
||||||
WorkName = element.Element("WorkName")!.Value,
|
WorkName = element.Element("WorkName")!.Value,
|
||||||
Count = Convert.ToInt32(element.Attribute("Count")!.Value),
|
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
||||||
Sum = Convert.ToInt32(element.Attribute("Sum")!.Value),
|
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
|
||||||
Status = model.Status,
|
Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
|
||||||
DateCreate = model.DateCreate,
|
DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value),
|
||||||
DateImplement = model.DateImplement,
|
DateImplement = string.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null
|
||||||
|
: Convert.ToDateTime(element.Element("DateImplement")!.Value)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public void Update(OrderBindingModel? model)
|
public void Update(OrderBindingModel? model)
|
||||||
@ -80,5 +82,14 @@ namespace PlumbingRepairFileImplement.Models
|
|||||||
DateCreate = DateCreate,
|
DateCreate = DateCreate,
|
||||||
DateImplement = DateImplement,
|
DateImplement = DateImplement,
|
||||||
};
|
};
|
||||||
|
public XElement GetXElement => new("Order",
|
||||||
|
new XAttribute("Id", Id),
|
||||||
|
new XElement("WorkName", WorkName),
|
||||||
|
new XElement("WorkId", WorkId.ToString()),
|
||||||
|
new XElement("Count", Count.ToString()),
|
||||||
|
new XElement("Sum", Sum.ToString()),
|
||||||
|
new XElement("Status", Status.ToString()),
|
||||||
|
new XElement("DateCreate", DateCreate.ToString()),
|
||||||
|
new XElement("DateImplement", DateImplement.ToString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,10 @@ namespace PlumbingRepairFileImplement.Models
|
|||||||
{
|
{
|
||||||
if(_workComponents == null)
|
if(_workComponents == null)
|
||||||
{
|
{
|
||||||
// to later
|
var source = DataFileSingleton.GetInstance();
|
||||||
|
_workComponents = Components.ToDictionary(x => x.Key, y =>
|
||||||
|
((source.Components.FirstOrDefault(z => z.Id == y.Key)
|
||||||
|
as IComponentModel)!, y.Value));
|
||||||
}
|
}
|
||||||
return _workComponents;
|
return _workComponents;
|
||||||
}
|
}
|
||||||
@ -75,7 +78,7 @@ namespace PlumbingRepairFileImplement.Models
|
|||||||
Price = Price,
|
Price = Price,
|
||||||
WorkComponents = WorkComponents
|
WorkComponents = WorkComponents
|
||||||
};
|
};
|
||||||
public XElement GetXElement => new("Product",
|
public XElement GetXElement => new("Work",
|
||||||
new XAttribute("Id", Id),
|
new XAttribute("Id", Id),
|
||||||
new XElement("WorkName", WorkName),
|
new XElement("WorkName", WorkName),
|
||||||
new XElement("Price", Price.ToString()),
|
new XElement("Price", Price.ToString()),
|
||||||
|
Loading…
Reference in New Issue
Block a user
Вычисляемое поле, не хранится в хранилище