From 6a2d498da855b0de0a99883ce053c4be4669d584 Mon Sep 17 00:00:00 2001 From: DyCTaTOR <125912249+DyCTaTOR@users.noreply.github.com> Date: Tue, 12 Mar 2024 23:36:19 +0400 Subject: [PATCH 1/2] =?UTF-8?q?=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=D0=BE=20lab2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PlumbingRepair/PlumbingRepair.sln | 6 ++ .../Models/Component.cs | 59 +++++++++++++ .../Models/Order.cs | 84 ++++++++++++++++++ .../Models/Work.cs | 87 +++++++++++++++++++ .../PlumbingRepairFileImplement.csproj | 14 +++ 5 files changed, 250 insertions(+) create mode 100644 PlumbingRepair/PlumbingRepairFileImplement/Models/Component.cs create mode 100644 PlumbingRepair/PlumbingRepairFileImplement/Models/Order.cs create mode 100644 PlumbingRepair/PlumbingRepairFileImplement/Models/Work.cs create mode 100644 PlumbingRepair/PlumbingRepairFileImplement/PlumbingRepairFileImplement.csproj diff --git a/PlumbingRepair/PlumbingRepair.sln b/PlumbingRepair/PlumbingRepair.sln index 52166b3..9ede061 100644 --- a/PlumbingRepair/PlumbingRepair.sln +++ b/PlumbingRepair/PlumbingRepair.sln @@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairBusinessLogic EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairListImplement", "PlumbingRepairListImplement\PlumbingRepairListImplement.csproj", "{E89CA82F-2FEA-4235-93A2-E5A412D0116F}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlumbingRepairFileImplement", "PlumbingRepairFileImplement\PlumbingRepairFileImplement.csproj", "{CF58BB85-A6FB-4581-940D-BB7D1AB815CD}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -39,6 +41,10 @@ Global {E89CA82F-2FEA-4235-93A2-E5A412D0116F}.Debug|Any CPU.Build.0 = Debug|Any CPU {E89CA82F-2FEA-4235-93A2-E5A412D0116F}.Release|Any CPU.ActiveCfg = Release|Any CPU {E89CA82F-2FEA-4235-93A2-E5A412D0116F}.Release|Any CPU.Build.0 = Release|Any CPU + {CF58BB85-A6FB-4581-940D-BB7D1AB815CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CF58BB85-A6FB-4581-940D-BB7D1AB815CD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CF58BB85-A6FB-4581-940D-BB7D1AB815CD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CF58BB85-A6FB-4581-940D-BB7D1AB815CD}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/PlumbingRepair/PlumbingRepairFileImplement/Models/Component.cs b/PlumbingRepair/PlumbingRepairFileImplement/Models/Component.cs new file mode 100644 index 0000000..7206698 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairFileImplement/Models/Component.cs @@ -0,0 +1,59 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.ViewModels; +using PlumbingRepairDataModels.Models; +using System.Xml.Linq; + +namespace PlumbingRepairFileImplement.Models +{ + public class Component : IComponentModel + { + public int Id { get; private set; } + public string ComponentName { get; private set; } = string.Empty; + public double Cost { get; set; } + public static Component? Create(ComponentBindingModel model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + public static Component? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Component() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ComponentName = element.Element("ComponentName")!.Value, + Cost = Convert.ToDouble(element.Element("Cost")!.Value) + }; + } + public void Update(ComponentBindingModel? model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + public XElement GetXElement => new("Component", + new XAttribute("Id", Id), + new XElement("ComponentName", ComponentName), + new XElement("Cost", Cost.ToString())); + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairFileImplement/Models/Order.cs b/PlumbingRepair/PlumbingRepairFileImplement/Models/Order.cs new file mode 100644 index 0000000..c094ebd --- /dev/null +++ b/PlumbingRepair/PlumbingRepairFileImplement/Models/Order.cs @@ -0,0 +1,84 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.ViewModels; +using PlumbingRepairDataModels.Enums; +using PlumbingRepairDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace PlumbingRepairFileImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + public int WorkId { get; private set; } + public String WorkName { get; private set; } = string.Empty; + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } + public DateTime DateCreate { get; private set; } + public DateTime? DateImplement { get; private set; } + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + WorkId = model.WorkId, + WorkName = model.WorkName, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + }; + } + public static Order? Create(XElement? element) + { + if (element == null) + { + return null; + } + return new Order() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + WorkId = Convert.ToInt32(element.Attribute("WorkId")!.Value), + WorkName = element.Element("WorkName")!.Value, + Count = Convert.ToInt32(element.Attribute("Count")!.Value), + Sum = Convert.ToInt32(element.Attribute("Sum")!.Value), + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + }; + } + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateCreate = model.DateCreate; + DateImplement = model.DateImplement; + } + public OrderViewModel GetViewModel => new() + { + Id = Id, + WorkId = WorkId, + WorkName = WorkName, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement, + }; + } +} diff --git a/PlumbingRepair/PlumbingRepairFileImplement/Models/Work.cs b/PlumbingRepair/PlumbingRepairFileImplement/Models/Work.cs new file mode 100644 index 0000000..4bf87b1 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairFileImplement/Models/Work.cs @@ -0,0 +1,87 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.ViewModels; +using PlumbingRepairDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace PlumbingRepairFileImplement.Models +{ + public class Work : IWorkModel + { + public int Id { get; private set; } + public string WorkName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary Components { get; private set; } = new(); + private Dictionary? _workComponents = null; + public Dictionary WorkComponents + { + get + { + if(_workComponents == null) + { + // to later + } + return _workComponents; + } + } + public static Work? Create(WorkBindingModel? model) + { + if (model == null) + { + return null; + } + return new Work() + { + Id = model.Id, + WorkName = model.WorkName, + Price = model.Price, + Components = model.WorkComponents.ToDictionary(x => x.Key, x => x.Value.Item2) + }; + } + public static Work? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Work() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + WorkName = element.Element("WorkName")!.Value, + Price = Convert.ToDouble(element.Element("Price")!.Value), + Components = element.Element("WorkComponents")!.Elements("WorkComponent") + .ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value)) + }; + } + public void Update(WorkBindingModel? model) + { + if (model == null) + { + return; + } + WorkName = model.WorkName; + Price = model.Price; + Components = model.WorkComponents.ToDictionary(x => x.Key, x => x.Value.Item2); + _workComponents = null; + } + public WorkViewModel GetViewModel => new() + { + Id = Id, + WorkName = WorkName, + Price = Price, + WorkComponents = WorkComponents + }; + public XElement GetXElement => new("Product", + new XAttribute("Id", Id), + new XElement("WorkName", WorkName), + new XElement("Price", Price.ToString()), + new XElement("WorkComponents", Components.Select(x => + new XElement("WorkComponent", + new XElement("Key", x.Key), + new XElement("Value", x.Value))).ToArray())); + } +} diff --git a/PlumbingRepair/PlumbingRepairFileImplement/PlumbingRepairFileImplement.csproj b/PlumbingRepair/PlumbingRepairFileImplement/PlumbingRepairFileImplement.csproj new file mode 100644 index 0000000..05f8377 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairFileImplement/PlumbingRepairFileImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + -- 2.25.1 From 4cdaf389a580086b00f027c31fb783026af878e1 Mon Sep 17 00:00:00 2001 From: DyCTaTOR <125912249+DyCTaTOR@users.noreply.github.com> Date: Wed, 13 Mar 2024 10:28:19 +0400 Subject: [PATCH 2/2] =?UTF-8?q?Lab2=20=D1=81=D0=B4=D0=B0=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PlumbingRepair/FormComponents.Designer.cs | 13 +- .../PlumbingRepair/FormMain.Designer.cs | 2 +- .../PlumbingRepair/FormWorks.Designer.cs | 156 ++++++------ PlumbingRepair/PlumbingRepair/FormWorks.resx | 238 +++++++++--------- .../PlumbingRepair/PlumbingRepairView.csproj | 1 + PlumbingRepair/PlumbingRepair/Program.cs | 100 ++++---- .../DataFileSingleton.cs | 62 +++++ .../Implements/ComponentStorage.cs | 90 +++++++ .../Implements/OrderStorage.cs | 93 +++++++ .../Implements/WorkStorage.cs | 94 +++++++ .../Models/Order.cs | 179 ++++++------- .../Models/Work.cs | 7 +- 12 files changed, 695 insertions(+), 340 deletions(-) create mode 100644 PlumbingRepair/PlumbingRepairFileImplement/DataFileSingleton.cs create mode 100644 PlumbingRepair/PlumbingRepairFileImplement/Implements/ComponentStorage.cs create mode 100644 PlumbingRepair/PlumbingRepairFileImplement/Implements/OrderStorage.cs create mode 100644 PlumbingRepair/PlumbingRepairFileImplement/Implements/WorkStorage.cs diff --git a/PlumbingRepair/PlumbingRepair/FormComponents.Designer.cs b/PlumbingRepair/PlumbingRepair/FormComponents.Designer.cs index 5e091c0..3a2b842 100644 --- a/PlumbingRepair/PlumbingRepair/FormComponents.Designer.cs +++ b/PlumbingRepair/PlumbingRepair/FormComponents.Designer.cs @@ -40,7 +40,7 @@ // dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.Location = new Point(10, 8); - dataGridView.Margin = new Padding(2, 2, 2, 2); + dataGridView.Margin = new Padding(2); dataGridView.Name = "dataGridView"; dataGridView.RowHeadersWidth = 62; dataGridView.RowTemplate.Height = 33; @@ -50,7 +50,7 @@ // buttonAdd // buttonAdd.Location = new Point(547, 33); - buttonAdd.Margin = new Padding(2, 2, 2, 2); + buttonAdd.Margin = new Padding(2); buttonAdd.Name = "buttonAdd"; buttonAdd.Size = new Size(108, 27); buttonAdd.TabIndex = 1; @@ -61,7 +61,7 @@ // buttonDel // buttonDel.Location = new Point(547, 85); - buttonDel.Margin = new Padding(2, 2, 2, 2); + buttonDel.Margin = new Padding(2); buttonDel.Name = "buttonDel"; buttonDel.Size = new Size(108, 27); buttonDel.TabIndex = 2; @@ -72,7 +72,7 @@ // buttonChange // buttonChange.Location = new Point(547, 147); - buttonChange.Margin = new Padding(2, 2, 2, 2); + buttonChange.Margin = new Padding(2); buttonChange.Name = "buttonChange"; buttonChange.Size = new Size(108, 27); buttonChange.TabIndex = 3; @@ -83,7 +83,7 @@ // buttonRef // buttonRef.Location = new Point(547, 209); - buttonRef.Margin = new Padding(2, 2, 2, 2); + buttonRef.Margin = new Padding(2); buttonRef.Name = "buttonRef"; buttonRef.Size = new Size(108, 27); buttonRef.TabIndex = 4; @@ -101,9 +101,10 @@ Controls.Add(buttonDel); Controls.Add(buttonAdd); Controls.Add(dataGridView); - Margin = new Padding(2, 2, 2, 2); + Margin = new Padding(2); Name = "FormComponents"; Text = "Компоненты"; + Load += FormComponents_Load; ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ResumeLayout(false); } diff --git a/PlumbingRepair/PlumbingRepair/FormMain.Designer.cs b/PlumbingRepair/PlumbingRepair/FormMain.Designer.cs index d0970cd..5471e44 100644 --- a/PlumbingRepair/PlumbingRepair/FormMain.Designer.cs +++ b/PlumbingRepair/PlumbingRepair/FormMain.Designer.cs @@ -97,7 +97,7 @@ // buttonTakeOrderInWork.Location = new Point(608, 132); buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - buttonTakeOrderInWork.Size = new Size(170, 29); + buttonTakeOrderInWork.Size = new Size(170, 50); buttonTakeOrderInWork.TabIndex = 3; buttonTakeOrderInWork.Text = "Отдать на выполнение"; buttonTakeOrderInWork.UseVisualStyleBackColor = true; diff --git a/PlumbingRepair/PlumbingRepair/FormWorks.Designer.cs b/PlumbingRepair/PlumbingRepair/FormWorks.Designer.cs index 5231cdb..f8f1e5a 100644 --- a/PlumbingRepair/PlumbingRepair/FormWorks.Designer.cs +++ b/PlumbingRepair/PlumbingRepair/FormWorks.Designer.cs @@ -26,85 +26,85 @@ /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// - private void InitializeComponent() - { - this.dataGridView = new System.Windows.Forms.DataGridView(); - this.buttonAdd = new System.Windows.Forms.Button(); - this.buttonUpd = new System.Windows.Forms.Button(); - this.buttonDel = new System.Windows.Forms.Button(); - this.buttonRef = new System.Windows.Forms.Button(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); - this.SuspendLayout(); - // - // dataGridView - // - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Location = new System.Drawing.Point(1, 0); - this.dataGridView.Name = "dataGridView"; - this.dataGridView.RowHeadersWidth = 51; - this.dataGridView.RowTemplate.Height = 29; - this.dataGridView.Size = new System.Drawing.Size(611, 449); - this.dataGridView.TabIndex = 0; - // - // buttonAdd - // - this.buttonAdd.Location = new System.Drawing.Point(670, 23); - this.buttonAdd.Name = "buttonAdd"; - this.buttonAdd.Size = new System.Drawing.Size(94, 29); - this.buttonAdd.TabIndex = 1; - this.buttonAdd.Text = "Добавить"; - this.buttonAdd.UseVisualStyleBackColor = true; - this.buttonAdd.Click += new System.EventHandler(this.AddButton_Click); - // - // buttonUpd - // - this.buttonUpd.Location = new System.Drawing.Point(670, 75); - this.buttonUpd.Name = "buttonUpd"; - this.buttonUpd.Size = new System.Drawing.Size(94, 29); - this.buttonUpd.TabIndex = 2; - this.buttonUpd.Text = "Изменить"; - this.buttonUpd.UseVisualStyleBackColor = true; - this.buttonUpd.Click += new System.EventHandler(this.ChangeButton_Click); - // - // buttonDel - // - this.buttonDel.Location = new System.Drawing.Point(670, 132); - this.buttonDel.Name = "buttonDel"; - this.buttonDel.Size = new System.Drawing.Size(94, 29); - this.buttonDel.TabIndex = 3; - this.buttonDel.Text = "Удалить"; - this.buttonDel.UseVisualStyleBackColor = true; - this.buttonDel.Click += new System.EventHandler(this.DeleteButton_Click); - // - // buttonRef - // - this.buttonRef.Location = new System.Drawing.Point(670, 188); - this.buttonRef.Name = "buttonRef"; - this.buttonRef.Size = new System.Drawing.Size(94, 29); - this.buttonRef.TabIndex = 4; - this.buttonRef.Text = "Обновить"; - this.buttonRef.UseVisualStyleBackColor = true; - this.buttonRef.Click += new System.EventHandler(this.UpdateButton_Click); - // - // FormWorks - // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Controls.Add(this.buttonRef); - this.Controls.Add(this.buttonDel); - this.Controls.Add(this.buttonUpd); - this.Controls.Add(this.buttonAdd); - this.Controls.Add(this.dataGridView); - this.Name = "FormWorks"; - this.Text = "Работы"; - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); - this.ResumeLayout(false); - - } - + private void InitializeComponent() + { + dataGridView = new DataGridView(); + buttonAdd = new Button(); + buttonUpd = new Button(); + buttonDel = new Button(); + buttonRef = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(1, 0); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(611, 449); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(670, 23); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(94, 29); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += AddButton_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(670, 75); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(94, 29); + buttonUpd.TabIndex = 2; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ChangeButton_Click; + // + // buttonDel + // + buttonDel.Location = new Point(670, 132); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(94, 29); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += DeleteButton_Click; + // + // buttonRef + // + buttonRef.Location = new Point(670, 188); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(94, 29); + buttonRef.TabIndex = 4; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += UpdateButton_Click; + // + // FormWorks + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonRef); + Controls.Add(buttonDel); + Controls.Add(buttonUpd); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormWorks"; + Text = "Работы"; + Load += FormComponents_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + #endregion - + private DataGridView dataGridView; private Button buttonAdd; private Button buttonUpd; diff --git a/PlumbingRepair/PlumbingRepair/FormWorks.resx b/PlumbingRepair/PlumbingRepair/FormWorks.resx index 1af7de1..0f362c9 100644 --- a/PlumbingRepair/PlumbingRepair/FormWorks.resx +++ b/PlumbingRepair/PlumbingRepair/FormWorks.resx @@ -1,120 +1,120 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepair/PlumbingRepairView.csproj b/PlumbingRepair/PlumbingRepair/PlumbingRepairView.csproj index 777ae54..e735055 100644 --- a/PlumbingRepair/PlumbingRepair/PlumbingRepairView.csproj +++ b/PlumbingRepair/PlumbingRepair/PlumbingRepairView.csproj @@ -15,6 +15,7 @@ + diff --git a/PlumbingRepair/PlumbingRepair/Program.cs b/PlumbingRepair/PlumbingRepair/Program.cs index e7dd925..4f61236 100644 --- a/PlumbingRepair/PlumbingRepair/Program.cs +++ b/PlumbingRepair/PlumbingRepair/Program.cs @@ -1,53 +1,53 @@ -using PlumbingRepairContracts.BusinessLogicsContracts; -using PlumbingRepairContracts.StoragesContracts; -using PlumbingRepairListImplement.Implements; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using NLog.Extensions.Logging; +using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.StoragesContracts; +using PlumbingRepairFileImplement.Implements; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; using PlumbingRepairBusinessLogic.BusinessLogics; -namespace PlumbingRepairView -{ - internal static class Program - { - private static ServiceProvider? _serviceProvider; - public static ServiceProvider? ServiceProvider => _serviceProvider; - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - // To customize application configuration such as set high DPI settings or default font, - // see https://aka.ms/applicationconfiguration. - ApplicationConfiguration.Initialize(); - var services = new ServiceCollection(); - ConfigureServices(services); - _serviceProvider = services.BuildServiceProvider(); - Application.Run(_serviceProvider.GetRequiredService()); - } - private static void ConfigureServices(ServiceCollection services) - { - services.AddLogging(option => - { - option.SetMinimumLevel(LogLevel.Information); - option.AddNLog("nlog.config"); - }); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - } - } +namespace PlumbingRepairView +{ + internal static class Program + { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + Application.Run(_serviceProvider.GetRequiredService()); + } + private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + } + } } \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairFileImplement/DataFileSingleton.cs b/PlumbingRepair/PlumbingRepairFileImplement/DataFileSingleton.cs new file mode 100644 index 0000000..3fbf29f --- /dev/null +++ b/PlumbingRepair/PlumbingRepairFileImplement/DataFileSingleton.cs @@ -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 Components { get; private set; } + public List Orders { get; private set; } + public List 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? LoadData(string filename, string xmlNodeName, + Func selectFunction) + { + if (File.Exists(filename)) + { + return XDocument.Load(filename)?.Root?.Elements(xmlNodeName)? + .Select(selectFunction)?.ToList(); + } + return new List(); + } + private static void SaveData(List data, string filename, string + xmlNodeName, Func selectFunction) + { + if (data != null) + { + new XDocument(new XElement(xmlNodeName, + data.Select(selectFunction).ToArray())).Save(filename); + } + } + } +} diff --git a/PlumbingRepair/PlumbingRepairFileImplement/Implements/ComponentStorage.cs b/PlumbingRepair/PlumbingRepairFileImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..999f1f3 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairFileImplement/Implements/ComponentStorage.cs @@ -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 GetFullList() + { + return source.Components + .Select(x => x.GetViewModel) + .ToList(); + } + public List 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; + } + + } +} diff --git a/PlumbingRepair/PlumbingRepairFileImplement/Implements/OrderStorage.cs b/PlumbingRepair/PlumbingRepairFileImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..1a375b3 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairFileImplement/Implements/OrderStorage.cs @@ -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 GetFullList() + { + return source.Orders.Select(x => x.GetViewModel).ToList(); + } + + public List 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; + } + } +} diff --git a/PlumbingRepair/PlumbingRepairFileImplement/Implements/WorkStorage.cs b/PlumbingRepair/PlumbingRepairFileImplement/Implements/WorkStorage.cs new file mode 100644 index 0000000..b2a047c --- /dev/null +++ b/PlumbingRepair/PlumbingRepairFileImplement/Implements/WorkStorage.cs @@ -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 GetFullList() + { + return source.Works.Select(x => x.GetViewModel).ToList(); + } + + public List 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; + } + } +} diff --git a/PlumbingRepair/PlumbingRepairFileImplement/Models/Order.cs b/PlumbingRepair/PlumbingRepairFileImplement/Models/Order.cs index c094ebd..c065257 100644 --- a/PlumbingRepair/PlumbingRepairFileImplement/Models/Order.cs +++ b/PlumbingRepair/PlumbingRepairFileImplement/Models/Order.cs @@ -1,84 +1,95 @@ -using PlumbingRepairContracts.BindingModels; -using PlumbingRepairContracts.ViewModels; -using PlumbingRepairDataModels.Enums; -using PlumbingRepairDataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Xml.Linq; - -namespace PlumbingRepairFileImplement.Models -{ - public class Order : IOrderModel - { - public int Id { get; private set; } - public int WorkId { get; private set; } - public String WorkName { get; private set; } = string.Empty; - public int Count { get; private set; } - public double Sum { get; private set; } - public OrderStatus Status { get; private set; } - public DateTime DateCreate { get; private set; } - public DateTime? DateImplement { get; private set; } - public static Order? Create(OrderBindingModel? model) - { - if (model == null) - { - return null; - } - return new Order() - { - Id = model.Id, - WorkId = model.WorkId, - WorkName = model.WorkName, - Count = model.Count, - Sum = model.Sum, - Status = model.Status, - DateCreate = model.DateCreate, - DateImplement = model.DateImplement, - }; - } - public static Order? Create(XElement? element) - { - if (element == null) - { - return null; - } - return new Order() - { - Id = Convert.ToInt32(element.Attribute("Id")!.Value), - WorkId = Convert.ToInt32(element.Attribute("WorkId")!.Value), - WorkName = element.Element("WorkName")!.Value, - Count = Convert.ToInt32(element.Attribute("Count")!.Value), - Sum = Convert.ToInt32(element.Attribute("Sum")!.Value), - Status = model.Status, - DateCreate = model.DateCreate, - DateImplement = model.DateImplement, - }; - } - public void Update(OrderBindingModel? model) - { - if (model == null) - { - return; - } - Count = model.Count; - Sum = model.Sum; - Status = model.Status; - DateCreate = model.DateCreate; - DateImplement = model.DateImplement; - } - public OrderViewModel GetViewModel => new() - { - Id = Id, - WorkId = WorkId, - WorkName = WorkName, - Count = Count, - Sum = Sum, - Status = Status, - DateCreate = DateCreate, - DateImplement = DateImplement, - }; - } -} +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.ViewModels; +using PlumbingRepairDataModels.Enums; +using PlumbingRepairDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace PlumbingRepairFileImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + public int WorkId { get; private set; } + public String WorkName { get; private set; } = string.Empty; + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; private set; } = DateTime.Now; + public DateTime? DateImplement { get; private set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + WorkId = model.WorkId, + WorkName = model.WorkName, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + }; + } + public static Order? Create(XElement? element) + { + if (element == null) + { + return null; + } + return new Order() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + WorkId = Convert.ToInt32(element.Element("WorkId")!.Value), + WorkName = element.Element("WorkName")!.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), + DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value), + DateImplement = string.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null + : Convert.ToDateTime(element.Element("DateImplement")!.Value) + }; + } + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateCreate = model.DateCreate; + DateImplement = model.DateImplement; + } + public OrderViewModel GetViewModel => new() + { + Id = Id, + WorkId = WorkId, + WorkName = WorkName, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + 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())); + } +} diff --git a/PlumbingRepair/PlumbingRepairFileImplement/Models/Work.cs b/PlumbingRepair/PlumbingRepairFileImplement/Models/Work.cs index 4bf87b1..54be2d7 100644 --- a/PlumbingRepair/PlumbingRepairFileImplement/Models/Work.cs +++ b/PlumbingRepair/PlumbingRepairFileImplement/Models/Work.cs @@ -23,7 +23,10 @@ namespace PlumbingRepairFileImplement.Models { 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; } @@ -75,7 +78,7 @@ namespace PlumbingRepairFileImplement.Models Price = Price, WorkComponents = WorkComponents }; - public XElement GetXElement => new("Product", + public XElement GetXElement => new("Work", new XAttribute("Id", Id), new XElement("WorkName", WorkName), new XElement("Price", Price.ToString()), -- 2.25.1