Morozov V.S. LabWork2Hard #9

Closed
VoldemarProger wants to merge 5 commits from LabWork2Hard into LabWork1Hard
31 changed files with 1287 additions and 39 deletions

View File

@ -43,6 +43,14 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics
_logger.LogWarning("AddCarInShop element not found");
return false;
}
var quantityCars = 0;
foreach (var ShopCar in element.Cars)
quantityCars += ShopCar.Value.Item2;
if((quantityCars + quantity) > element.Fullness)
{
throw new ArgumentException("Превышена максимальная вместимость", nameof(quantity));
}
_logger.LogInformation("AddCarInShop find. Id:{Id}", element.Id);
@ -63,11 +71,56 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics
Adress = element.Adress,
ShopName = element.ShopName,
DateOpen = element.DateOpen,
Fullness = element.Fullness,
Cars = element.Cars
});
return true;
}
public bool AddCar(ICarModel car, int quantity)
{
if (CheckShops(quantity))
{
foreach(var shop in ReadList(null))
{
if(quantity==0) return true;
int OccupiedPlaces = 0;
foreach(var ShopCar in shop.Cars)
{
OccupiedPlaces += ShopCar.Value.Item2;
}
int EmptyPlaces = shop.Fullness - OccupiedPlaces;
if(EmptyPlaces > 0)
{
EmptyPlaces = EmptyPlaces > quantity ? quantity : EmptyPlaces;
AddCar(new CarShopSearchModel { Id = shop.Id}, car, EmptyPlaces);
quantity -= EmptyPlaces;
if (quantity == 0) return true;
}
}
}
return false;
}
public bool CheckShops( int quantity)
{
foreach(var shop in ReadList(null))
{
int OccupiedPlaces = 0;
foreach(var car in shop.Cars)
{
OccupiedPlaces += car.Value.Item2;
}
int EmptyPlaces = shop.Fullness - OccupiedPlaces;
quantity -= EmptyPlaces;
}
if(quantity <= 0)
return true;
else return false;
}
public bool Create(CarShopBindingModel model)
{
CheckModel(model);

View File

@ -18,10 +18,14 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics
{
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
public OrderLogic(ILogger<ComponentLogic> logger, IOrderStorage orderStorage)
private readonly ICarShopLogic _carShopLogic;
private readonly ICarStorage _carStorage;
public OrderLogic(ILogger<ComponentLogic> logger, IOrderStorage orderStorage, ICarShopLogic carShopLogic, ICarStorage carStorage)
{
_logger = logger;
_orderStorage = orderStorage;
_carShopLogic = carShopLogic;
_carStorage = carStorage;
}
public bool CreateOrder(OrderBindingModel model)
@ -58,7 +62,16 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics
model.Status = newStatus;
if (model.Status == OrderStatus.Выдан)
{
model.DateImplement = DateTime.Now;
if (!_carShopLogic.AddCar(_carStorage.GetElement(new CarSearchModel { Id = model.CarId }), model.Count))
{
model.Status--;
_logger.LogWarning("Small places in shops");
return false;
}
}
if (_orderStorage.Update(model) == null)
{

View File

@ -14,6 +14,7 @@ namespace AutomobilePlantContracts.BindingModels
public string Adress { get; set; } = String.Empty ;
public DateTime DateOpen { get; set; } = new();
public int Fullness { get; set; }
public Dictionary<int, (ICarModel, int)> Cars { get; set; } = new();

View File

@ -18,5 +18,7 @@ namespace AutomobilePlantContracts.BusinessLogicsContracts
bool Update(CarShopBindingModel model);
bool Delete(CarShopBindingModel model);
bool AddCar(CarShopSearchModel model, ICarModel car, int quantity);
bool CheckShops(int quantity);
bool AddCar(ICarModel car, int quantity);
}
}

View File

@ -1,6 +1,7 @@
using AutomobilePlantContracts.BindingModels;
using AutomobilePlantContracts.SearchModel;
using AutomobilePlantContracts.ViewModel;
using AutomobilePlantDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
@ -13,6 +14,7 @@ namespace AutomobilePlantContracts.StoragesContracts
{
List<CarShopViewModel> GetFullList();
List<CarShopViewModel> GetFilteredList(CarShopSearchModel model);
bool TrySell ( ICarModel car, int quantity);
CarShopViewModel? GetElement(CarShopSearchModel model);
CarShopViewModel? Insert(CarShopBindingModel model);
CarShopViewModel? Update(CarShopBindingModel model);

View File

@ -16,6 +16,8 @@ namespace AutomobilePlantContracts.ViewModel
public string Adress { get; set; } = String.Empty;
[DisplayName("Дата открытия")]
public DateTime DateOpen { get; set; } = new();
[DisplayName("Наполненность")]
public int Fullness { get; set; }
public Dictionary<int, (ICarModel, int)> Cars { get; set; } = new();

View File

@ -11,6 +11,7 @@ namespace AutomobilePlantDataModels.Models
string ShopName { get; }
string Adress { get; }
DateTime DateOpen { get; }
int Fullness { get; }
Dictionary<int, (ICarModel, int)> Cars { get; }
}
}

View File

@ -2,6 +2,7 @@
using AutomobilePlantContracts.SearchModel;
using AutomobilePlantContracts.StoragesContracts;
using AutomobilePlantContracts.ViewModel;
using AutomobilePlantDataModels.Models;
using AutomobilePlantListImplement.Models;
using System;
using System.Collections.Generic;
@ -117,5 +118,11 @@ namespace AutomobilePlantListImplement.Implements
return null;
}
public bool TrySell(ICarModel car, int quantity)
{
throw new NotImplementedException();
}
}
}

View File

@ -18,6 +18,7 @@ namespace AutomobilePlantListImplement.Models
public string Adress { get; private set; } = String.Empty;
public DateTime DateOpen { get; private set; }
public int Fullness { get; set; }
public Dictionary<int, (ICarModel, int)> Cars { get; private set; } = new ();

View File

@ -7,11 +7,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutomobilePlantDataModels",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutomobilePlantContracts", "AbstractAutoContracts\AutomobilePlantContracts.csproj", "{4B515980-8AD9-48F3-886E-3C2A6B1E9D90}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomobilePlantBusinessLogic", "AbstractAutoBusinessLogic\AutomobilePlantBusinessLogic.csproj", "{D57C726F-E5B4-4CB3-A754-D5F93295CE1E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutomobilePlantBusinessLogic", "AbstractAutoBusinessLogic\AutomobilePlantBusinessLogic.csproj", "{D57C726F-E5B4-4CB3-A754-D5F93295CE1E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomobilePlantListImplement", "AbstractAutoListImplement\AutomobilePlantListImplement.csproj", "{305978E5-BFB5-47B0-94C9-2C5D06748BD6}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutomobilePlantListImplement", "AbstractAutoListImplement\AutomobilePlantListImplement.csproj", "{305978E5-BFB5-47B0-94C9-2C5D06748BD6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomobilePlant", "AutomobilePlant\AutomobilePlant.csproj", "{8DB13E4F-D083-40DD-B1C2-F3CF74B762C2}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutomobilePlant", "AutomobilePlant\AutomobilePlant.csproj", "{8DB13E4F-D083-40DD-B1C2-F3CF74B762C2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomomilePlantFileImplement", "AutomomilePlantFileImplement\AutomomilePlantFileImplement.csproj", "{3EC099D5-0C5C-43F5-AC6D-09B4D7CE9D72}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -39,6 +41,10 @@ Global
{8DB13E4F-D083-40DD-B1C2-F3CF74B762C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8DB13E4F-D083-40DD-B1C2-F3CF74B762C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8DB13E4F-D083-40DD-B1C2-F3CF74B762C2}.Release|Any CPU.Build.0 = Release|Any CPU
{3EC099D5-0C5C-43F5-AC6D-09B4D7CE9D72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3EC099D5-0C5C-43F5-AC6D-09B4D7CE9D72}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3EC099D5-0C5C-43F5-AC6D-09B4D7CE9D72}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3EC099D5-0C5C-43F5-AC6D-09B4D7CE9D72}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -24,7 +24,7 @@
<ItemGroup>
<ProjectReference Include="..\AbstractAutoBusinessLogic\AutomobilePlantBusinessLogic.csproj" />
<ProjectReference Include="..\AbstractAutoListImplement\AutomobilePlantListImplement.csproj" />
<ProjectReference Include="..\AutomomilePlantFileImplement\AutomomilePlantFileImplement.csproj" />
</ItemGroup>
</Project>

View File

@ -40,6 +40,7 @@
this.IssuedOrderButton = new System.Windows.Forms.Button();
this.UpdateListButton = new System.Windows.Forms.Button();
this.AddShopCarButton = new System.Windows.Forms.Button();
this.Sellbutton = new System.Windows.Forms.Button();
this.MenuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit();
this.SuspendLayout();
@ -69,21 +70,21 @@
// ИзделияToolStripMenuItem
//
this.ИзделияToolStripMenuItem.Name = "ИзделияToolStripMenuItem";
this.ИзделияToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
this.ИзделияToolStripMenuItem.Size = new System.Drawing.Size(182, 26);
this.ИзделияToolStripMenuItem.Text = "Изделия";
this.ИзделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click);
//
// КомпонентыToolStripMenuItem
//
this.КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem";
this.КомпонентыToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
this.КомпонентыToolStripMenuItem.Size = new System.Drawing.Size(182, 26);
this.КомпонентыToolStripMenuItem.Text = "Компоненты";
this.КомпонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click);
//
// магазиныToolStripMenuItem
//
this.магазиныToolStripMenuItem.Name = агазиныToolStripMenuItem";
this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(182, 26);
this.магазиныToolStripMenuItem.Text = "Магазины";
this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.магазиныToolStripMenuItem_Click);
//
@ -163,11 +164,22 @@
this.AddShopCarButton.UseVisualStyleBackColor = true;
this.AddShopCarButton.Click += new System.EventHandler(this.AddShopCarButton_Click);
//
// Sellbutton
//
this.Sellbutton.Location = new System.Drawing.Point(832, 507);
this.Sellbutton.Name = "Sellbutton";
this.Sellbutton.Size = new System.Drawing.Size(143, 56);
this.Sellbutton.TabIndex = 8;
this.Sellbutton.Text = "Продать";
this.Sellbutton.UseVisualStyleBackColor = true;
this.Sellbutton.Click += new System.EventHandler(this.Sellbutton_Click);
//
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(989, 600);
this.Controls.Add(this.Sellbutton);
this.Controls.Add(this.AddShopCarButton);
this.Controls.Add(this.UpdateListButton);
this.Controls.Add(this.IssuedOrderButton);
@ -203,5 +215,6 @@
private Button UpdateListButton;
private ToolStripMenuItem магазиныToolStripMenuItem;
private Button AddShopCarButton;
private Button Sellbutton;
}
}

View File

@ -217,5 +217,16 @@ namespace AutomobilePlant
LoadData();
}
}
private void Sellbutton_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShopSell));
if (service is FormShopSell form)
{
form.ShowDialog();
LoadData();
}
}
}
}

View File

@ -46,6 +46,7 @@ namespace AutomobilePlant
_carComponents = view.Cars ?? new
Dictionary<int, (ICarModel, int)>();
LoadData();
}
}

View File

@ -75,7 +75,7 @@ namespace AutomobilePlant
var resultOperation = _shopLogic.AddCar(
model: new() { Id = (int)ShopNameComboBox.SelectedValue },
car: car,
car: car,
quantity: Convert.ToInt32(CountTextBox.Text)
);

View File

@ -28,9 +28,9 @@
/// </summary>
private void InitializeComponent()
{
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle6 = new System.Windows.Forms.DataGridViewCellStyle();
this.ShopNameLabel = new System.Windows.Forms.Label();
this.AdressLabel = new System.Windows.Forms.Label();
this.ShopNameTextBox = new System.Windows.Forms.TextBox();
@ -44,8 +44,11 @@
this.ComponentNameField = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.CountField = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.DateOpenPicker = new System.Windows.Forms.DateTimePicker();
this.FullnessnumericUpDown = new System.Windows.Forms.NumericUpDown();
this.Fullness = new System.Windows.Forms.Label();
this.ComponentsGroupBox.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.FullnessnumericUpDown)).BeginInit();
this.SuspendLayout();
//
// ShopNameLabel
@ -132,38 +135,38 @@
//
// DataGridView
//
dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control;
dataGridViewCellStyle1.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText;
dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.DataGridView.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle4.BackColor = System.Drawing.SystemColors.Control;
dataGridViewCellStyle4.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
dataGridViewCellStyle4.ForeColor = System.Drawing.SystemColors.WindowText;
dataGridViewCellStyle4.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle4.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle4.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.DataGridView.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle4;
this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.DataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.ID,
this.ComponentNameField,
this.CountField});
dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Window;
dataGridViewCellStyle2.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
dataGridViewCellStyle2.ForeColor = System.Drawing.SystemColors.ControlText;
dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
this.DataGridView.DefaultCellStyle = dataGridViewCellStyle2;
dataGridViewCellStyle5.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle5.BackColor = System.Drawing.SystemColors.Window;
dataGridViewCellStyle5.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
dataGridViewCellStyle5.ForeColor = System.Drawing.SystemColors.ControlText;
dataGridViewCellStyle5.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle5.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle5.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
this.DataGridView.DefaultCellStyle = dataGridViewCellStyle5;
this.DataGridView.Location = new System.Drawing.Point(7, 29);
this.DataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.DataGridView.Name = "DataGridView";
dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle3.BackColor = System.Drawing.SystemColors.Control;
dataGridViewCellStyle3.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
dataGridViewCellStyle3.ForeColor = System.Drawing.SystemColors.WindowText;
dataGridViewCellStyle3.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle3.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle3.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.DataGridView.RowHeadersDefaultCellStyle = dataGridViewCellStyle3;
dataGridViewCellStyle6.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle6.BackColor = System.Drawing.SystemColors.Control;
dataGridViewCellStyle6.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
dataGridViewCellStyle6.ForeColor = System.Drawing.SystemColors.WindowText;
dataGridViewCellStyle6.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle6.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle6.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.DataGridView.RowHeadersDefaultCellStyle = dataGridViewCellStyle6;
this.DataGridView.RowHeadersWidth = 51;
this.DataGridView.RowTemplate.Height = 25;
this.DataGridView.Size = new System.Drawing.Size(641, 429);
@ -193,16 +196,34 @@
//
// DateOpenPicker
//
this.DateOpenPicker.Location = new System.Drawing.Point(471, 8);
this.DateOpenPicker.Location = new System.Drawing.Point(495, 12);
this.DateOpenPicker.Name = "DateOpenPicker";
this.DateOpenPicker.Size = new System.Drawing.Size(250, 27);
this.DateOpenPicker.TabIndex = 6;
//
// FullnessnumericUpDown
//
this.FullnessnumericUpDown.Location = new System.Drawing.Point(595, 57);
this.FullnessnumericUpDown.Name = "FullnessnumericUpDown";
this.FullnessnumericUpDown.Size = new System.Drawing.Size(150, 27);
this.FullnessnumericUpDown.TabIndex = 7;
//
// Fullness
//
this.Fullness.AutoSize = true;
this.Fullness.Location = new System.Drawing.Point(469, 64);
this.Fullness.Name = "Fullness";
this.Fullness.Size = new System.Drawing.Size(103, 20);
this.Fullness.TabIndex = 8;
this.Fullness.Text = "Ограничение";
//
// FormShopCar
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(853, 664);
this.Controls.Add(this.Fullness);
this.Controls.Add(this.FullnessnumericUpDown);
this.Controls.Add(this.DateOpenPicker);
this.Controls.Add(this.ComponentsGroupBox);
this.Controls.Add(this.AdressTextBox);
@ -215,6 +236,7 @@
this.Load += new System.EventHandler(this.FormCar_Load);
this.ComponentsGroupBox.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.FullnessnumericUpDown)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
@ -235,5 +257,7 @@
private DataGridViewTextBoxColumn ComponentNameField;
private DataGridViewTextBoxColumn CountField;
private DateTimePicker DateOpenPicker;
private NumericUpDown FullnessnumericUpDown;
private Label Fullness;
}
}

View File

@ -46,6 +46,7 @@ namespace AutomobilePlant
ShopNameTextBox.Text = view.ShopName;
AdressTextBox.Text = view.Adress;
DateOpenPicker.Value = view.DateOpen;
FullnessnumericUpDown.Value = view.Fullness;
_cars = view.Cars ?? new
Dictionary<int, (ICarModel, int)>();
LoadData();
@ -110,6 +111,7 @@ namespace AutomobilePlant
ShopName = ShopNameTextBox.Text,
DateOpen = DateOpenPicker.Value,
Adress = AdressTextBox.Text,
Fullness = (int)FullnessnumericUpDown.Value,
Cars = _cars
};
var operationResult = _id.HasValue ? _logic.Update(model) :

View File

@ -0,0 +1,118 @@
namespace AutomobilePlant
{
partial class FormShopSell
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Carlabel = new System.Windows.Forms.Label();
this.Countlabel = new System.Windows.Forms.Label();
this.CarComboBox = new System.Windows.Forms.ComboBox();
this.CountnumericUpDown = new System.Windows.Forms.NumericUpDown();
this.Sellbutton = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.CountnumericUpDown)).BeginInit();
this.SuspendLayout();
//
// Carlabel
//
this.Carlabel.AutoSize = true;
this.Carlabel.Location = new System.Drawing.Point(42, 41);
this.Carlabel.Name = "Carlabel";
this.Carlabel.Size = new System.Drawing.Size(68, 20);
this.Carlabel.TabIndex = 0;
this.Carlabel.Text = "Машина";
//
// Countlabel
//
this.Countlabel.AutoSize = true;
this.Countlabel.Location = new System.Drawing.Point(42, 101);
this.Countlabel.Name = "Countlabel";
this.Countlabel.Size = new System.Drawing.Size(90, 20);
this.Countlabel.TabIndex = 1;
this.Countlabel.Text = "Количество";
//
// CarComboBox
//
this.CarComboBox.FormattingEnabled = true;
this.CarComboBox.Location = new System.Drawing.Point(161, 38);
this.CarComboBox.Name = "CarComboBox";
this.CarComboBox.Size = new System.Drawing.Size(151, 28);
this.CarComboBox.TabIndex = 2;
//
// CountnumericUpDown
//
this.CountnumericUpDown.Location = new System.Drawing.Point(175, 99);
this.CountnumericUpDown.Minimum = new decimal(new int[] {
1,
0,
0,
0});
this.CountnumericUpDown.Name = "CountnumericUpDown";
this.CountnumericUpDown.Size = new System.Drawing.Size(137, 27);
this.CountnumericUpDown.TabIndex = 3;
this.CountnumericUpDown.Value = new decimal(new int[] {
1,
0,
0,
0});
//
// Sellbutton
//
this.Sellbutton.Location = new System.Drawing.Point(123, 160);
this.Sellbutton.Name = "Sellbutton";
this.Sellbutton.Size = new System.Drawing.Size(94, 66);
this.Sellbutton.TabIndex = 4;
this.Sellbutton.Text = "Продать";
this.Sellbutton.UseVisualStyleBackColor = true;
this.Sellbutton.Click += new System.EventHandler(this.Sellbutton_Click);
//
// FormShopSell
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(362, 238);
this.Controls.Add(this.Sellbutton);
this.Controls.Add(this.CountnumericUpDown);
this.Controls.Add(this.CarComboBox);
this.Controls.Add(this.Countlabel);
this.Controls.Add(this.Carlabel);
this.Name = "FormShopSell";
this.Text = "FormShopSell";
((System.ComponentModel.ISupportInitialize)(this.CountnumericUpDown)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Label Carlabel;
private Label Countlabel;
private ComboBox CarComboBox;
private NumericUpDown CountnumericUpDown;
private Button Sellbutton;
}
}

View File

@ -0,0 +1,50 @@
using AutomobilePlantContracts.BusinessLogicsContracts;
using AutomobilePlantContracts.SearchModel;
using AutomobilePlantContracts.StoragesContracts;
using AutomobilePlantContracts.ViewModel;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AutomobilePlant
{
public partial class FormShopSell : Form
{
private readonly ILogger _logger;
private readonly ICarLogic _carLogic;
private readonly List<CarViewModel>? _listCars;
private readonly ICarShopStorage _carShopStorage;
public FormShopSell(ILogger<FormShopAdd> logger, ICarLogic carLogic, ICarShopStorage carShopStorage)
{
InitializeComponent();
_carLogic = carLogic;
_logger = logger;
_carShopStorage = carShopStorage;
_listCars = carLogic.ReadList(null);
if (_listCars != null)
{
CarComboBox.DisplayMember = "CarName";
CarComboBox.ValueMember = "Id";
CarComboBox.DataSource = _listCars;
CarComboBox.SelectedItem = null;
}
}
private void Sellbutton_Click(object sender, EventArgs e)
{
var car = _carLogic.ReadElement(new CarSearchModel { Id = (int)CarComboBox.SelectedValue });
var Faith = _carShopStorage.TrySell(car, (int)CountnumericUpDown.Value);
if (Faith)
MessageBox.Show("Продажа прошла успешно");
else
MessageBox.Show("Продажа прошла неудачно");
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -1,7 +1,7 @@
using AutomobilePlantBusinessLogic.BusinessLogics;
using AutomobilePlantContracts.BusinessLogicsContracts;
using AutomobilePlantContracts.StoragesContracts;
using AutomobilePlantListImplement.Implements;
using AutomomilePlantFileImplement.Implements;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
@ -37,7 +37,7 @@ namespace AutomobilePlant
services.AddTransient<IComponentStorage, ComponentStorage>();
services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<ICarStorage, CarStorage>();
services.AddTransient<ICarShopStorage, CarShopStorege>();
services.AddTransient<ICarShopStorage, CarShopStorage>();
services.AddTransient<IComponentLogic, ComponentLogic>();
services.AddTransient<IOrderLogic, OrderLogic>();
@ -56,6 +56,7 @@ namespace AutomobilePlant
services.AddTransient<FormShopCar>();
services.AddTransient<FormShopAdd>();
services.AddTransient<FormShopCreate>();
services.AddTransient<FormShopSell>();
}
}

View File

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\AbstractAutoContracts\AutomobilePlantContracts.csproj" />
<ProjectReference Include="..\AbstractAutoDataModels\AutomobilePlantDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,67 @@
using AutomomilePlantFileImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace AutomomilePlantFileImplement
{
public class DataFileSingleton
{
private static DataFileSingleton? instance;
private readonly string ComponentFileName = "Component.xml";
private readonly string OrderFileName = "Order.xml";
private readonly string CarFileName = "Car.xml";
private readonly string CarShopFileName = "CarShop.xml";
public List<Component> Components { get; private set; }
public List<Order> Orders { get; private set; }
public List<Car> Cars { get; private set; }
public List<CarShop> CarShops { 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 SaveCars() => SaveData(Cars, CarFileName,
"Cars", x => x.GetXElement);
public void SaveCarShops() => SaveData(CarShops, CarShopFileName,
"CarShops", x => x.GetXElement);
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x
=> x.GetXElement);
private DataFileSingleton()
{
Components = LoadData(ComponentFileName, "Component", x =>
Component.Create(x)!)!;
Cars = LoadData(CarFileName, "Car", x =>
Car.Create(x)!)!;
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
CarShops = LoadData(CarShopFileName, "CarShop", x => CarShop.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);
}
}
}
}

View File

@ -0,0 +1,141 @@
using AutomobilePlantContracts.BindingModels;
using AutomobilePlantContracts.SearchModel;
using AutomobilePlantContracts.StoragesContracts;
using AutomobilePlantContracts.ViewModel;
using AutomobilePlantDataModels.Models;
using AutomomilePlantFileImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace AutomomilePlantFileImplement.Implements
{
public class CarShopStorage : ICarShopStorage
{
private readonly DataFileSingleton source;
public CarShopStorage()
{
source = DataFileSingleton.GetInstance();
}
public CarShopViewModel? Delete(CarShopBindingModel model)
{
var element = source.CarShops.FirstOrDefault(x => x.Id ==
model.Id);
if (element != null)
{
source.CarShops.Remove(element);
source.SaveCarShops();
return element.GetViewModel;
}
return null;
}
public CarShopViewModel? GetElement(CarShopSearchModel model)
{
if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue)
{
return null;
}
return source.CarShops
.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.ShopName) && x.ShopName ==
model.ShopName) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public List<CarShopViewModel> GetFilteredList(CarShopSearchModel model)
{
if (string.IsNullOrEmpty(model.ShopName))
{
return new();
}
return source.CarShops
.Where(x => x.ShopName.Contains(model.ShopName))
.Select(x => x.GetViewModel)
.ToList();
}
public List<CarShopViewModel> GetFullList()
{
return source.CarShops
.Select(x => x.GetViewModel)
.ToList();
}
public CarShopViewModel? Insert(CarShopBindingModel model)
{
model.Id = source.CarShops.Count > 0 ? source.CarShops.Max(x =>
x.Id) + 1 : 1;
var newCarShop = CarShop.Create(model);
if (newCarShop == null)
{
return null;
}
source.CarShops.Add(newCarShop);
source.SaveCarShops();
return newCarShop.GetViewModel;
}
public bool TrySell(ICarModel car, int quantity)
{
List<CarShopViewModel> carShops = new List<CarShopViewModel>();
int fakeQuantity = quantity;
Review

Значение можно получить через LINQ-запрос

Значение можно получить через LINQ-запрос
foreach (var shop in GetFullList())
{
if (shop.Cars.ContainsKey(car.Id) )
{
carShops.Add(shop);
fakeQuantity -= shop.Cars[car.Id].Item2;
if(fakeQuantity < 0)
break;
}
}
if (fakeQuantity > 0)
return false;
foreach(var shop in carShops)
{
if(quantity-shop.Cars[car.Id].Item2 < 0)
{
shop.Cars[car.Id] = (shop.Cars[car.Id].Item1, shop.Cars[car.Id].Item2 - quantity);
}
else
{
quantity -= shop.Cars[car.Id].Item2;
shop.Cars.Remove(car.Id);
}
Update(new CarShopBindingModel
{
ShopName = shop.ShopName,
Adress = shop.Adress,
DateOpen = shop.DateOpen,
Fullness = shop.Fullness,
Id = shop.Id,
Cars = shop.Cars
});
}
; return true;
}
public CarShopViewModel? Update(CarShopBindingModel model)
{
var shop = source.CarShops.FirstOrDefault(x => x.Id ==
model.Id);
if (shop == null)
{
return null;
}
shop.Update(model);
source.SaveCarShops();
return shop.GetViewModel;
}
}
}

View File

@ -0,0 +1,94 @@
using AutomobilePlantContracts.BindingModels;
using AutomobilePlantContracts.SearchModel;
using AutomobilePlantContracts.StoragesContracts;
using AutomobilePlantContracts.ViewModel;
using AutomomilePlantFileImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AutomomilePlantFileImplement.Implements
{
public class CarStorage : ICarStorage
{
private readonly DataFileSingleton source;
public CarStorage()
{
source = DataFileSingleton.GetInstance();
}
public CarViewModel? Delete(CarBindingModel model)
{
var element = source.Cars.FirstOrDefault(x => x.Id ==
model.Id);
if (element != null)
{
source.Cars.Remove(element);
source.SaveCars();
return element.GetViewModel;
}
return null;
}
public CarViewModel? GetElement(CarSearchModel model)
{
if (string.IsNullOrEmpty(model.CarName) && !model.Id.HasValue)
{
return null;
}
return source.Cars
.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.CarName) && x.CarName ==
model.CarName) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public List<CarViewModel> GetFilteredList(CarSearchModel model)
{
if (string.IsNullOrEmpty(model.CarName))
{
return new();
}
return source.Cars
.Where(x => x.CarName.Contains(model.CarName))
.Select(x => x.GetViewModel)
.ToList();
}
public List<CarViewModel> GetFullList()
{
return source.Cars
.Select(x => x.GetViewModel)
.ToList();
}
public CarViewModel? Insert(CarBindingModel model)
{
model.Id = source.Cars.Count > 0 ? source.Cars.Max(x =>
x.Id) + 1 : 1;
var newCar = Car.Create(model);
if (newCar == null)
{
return null;
}
source.Cars.Add(newCar);
source.SaveCars();
return newCar.GetViewModel;
}
public CarViewModel? Update(CarBindingModel model)
{
var car = source.Cars.FirstOrDefault(x => x.Id ==
model.Id);
if (car == null)
{
return null;
}
car.Update(model);
source.SaveCars();
return car.GetViewModel;
}
}
}

View File

@ -0,0 +1,90 @@
using AutomobilePlantContracts.BindingModels;
using AutomobilePlantContracts.SearchModel;
using AutomobilePlantContracts.StoragesContracts;
using AutomobilePlantContracts.ViewModel;
using AutomomilePlantFileImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AutomomilePlantFileImplement.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;
}
}
}

View File

@ -0,0 +1,92 @@
using AutomobilePlantContracts.BindingModels;
using AutomobilePlantContracts.SearchModel;
using AutomobilePlantContracts.StoragesContracts;
using AutomobilePlantContracts.ViewModel;
using AutomomilePlantFileImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AutomomilePlantFileImplement.Implements
{
public class OrderStorage : IOrderStorage
{
private readonly DataFileSingleton source;
public OrderStorage()
{
source = DataFileSingleton.GetInstance();
}
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;
}
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 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 List<OrderViewModel> GetFullList()
{
return source.Orders
.Select(x => x.GetViewModel)
.ToList();
}
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;
}
}
}

View File

@ -0,0 +1,100 @@
using AutomobilePlantContracts.BindingModels;
using AutomobilePlantContracts.ViewModel;
using AutomobilePlantDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace AutomomilePlantFileImplement.Models
{
public class Car : ICarModel
{
public int Id { get; private set; }
public string CarName { get; private set; } = string.Empty;
public double Price { get; private set; }
public Dictionary<int, int> Components { get; private set; } = new();
private Dictionary<int, (IComponentModel, int)>? _carComponents =
null;
public Dictionary<int, (IComponentModel, int)> CarComponents
{
get
{
if (_carComponents == null)
{
var source = DataFileSingleton.GetInstance();
_carComponents = Components.ToDictionary(x => x.Key, y =>
((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!,
y.Value));
}
return _carComponents;
}
}
public static Car? Create(CarBindingModel model)
{
if (model == null)
{
return null;
}
return new Car()
{
Id = model.Id,
CarName = model.CarName,
Price = model.Price,
Components = model.CarComponents.ToDictionary(x => x.Key, x
=> x.Value.Item2)
};
}
public static Car? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Car()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
CarName = element.Element("CarName")!.Value,
Price = Convert.ToDouble(element.Element("Price")!.Value),
Components =
element.Element("CarComponents")!.Elements("CarComponent")
.ToDictionary(x =>
Convert.ToInt32(x.Element("Key")?.Value), x =>
Convert.ToInt32(x.Element("Value")?.Value))
};
}
public void Update(CarBindingModel model)
{
if (model == null)
{
return;
}
CarName = model.CarName;
Price = model.Price;
Components = model.CarComponents.ToDictionary(x => x.Key, x =>
x.Value.Item2);
_carComponents = null;
}
public CarViewModel GetViewModel => new()
{
Id = Id,
CarName = CarName,
Price = Price,
CarComponents = CarComponents
};
public XElement GetXElement => new("Car",
new XAttribute("Id", Id),
new XElement("CarName", CarName),
new XElement("Price", Price.ToString()),
new XElement("CarComponents", Components.Select(x =>
new XElement("CarComponent",
new XElement("Key", x.Key),
new XElement("Value", x.Value)))
.ToArray()));
}
}

View File

@ -0,0 +1,117 @@
using AutomobilePlantContracts.BindingModels;
using AutomobilePlantContracts.ViewModel;
using AutomobilePlantDataModels.Models;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace AutomomilePlantFileImplement.Models
{
public class CarShop : ICarShop
{
public string ShopName {get; set;} = String.Empty;
public string Adress { get; set; } = String.Empty;
public DateTime DateOpen { get; set; }
public int Fullness { get; set; }
public Dictionary<int, int> ShopCars { get; set; } = new();
private Dictionary<int, (ICarModel, int)> _cars = null;
public int Id { get; set; }
public Dictionary<int, (ICarModel, int)> Cars
{
get
{
if (_cars == null)
{
var source = DataFileSingleton.GetInstance();
_cars = ShopCars.ToDictionary(x => x.Key, y =>
((source.Cars.FirstOrDefault(z => z.Id == y.Key) as ICarModel)!,
y.Value));
}
return _cars;
}
}
public static CarShop? Create(CarShopBindingModel model)
{
if (model == null)
{
return null;
}
return new CarShop()
{
Id = model.Id,
ShopName = model.ShopName,
Fullness = model.Fullness,
Adress = model.Adress,
DateOpen = model.DateOpen,
ShopCars = model.Cars.ToDictionary(x => x.Key, x
=> x.Value.Item2)
};
}
public static CarShop? Create(XElement element)
{
if (element == null)
{
return null;
}
return new CarShop()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
ShopName = element.Element("ShopName")!.Value,
Adress = element.Element("Adress")!.Value,
DateOpen = DateTime.Parse(element.Element("DateOpen")!.Value),
Fullness = Convert.ToInt32(element.Element("Fullness")!.Value),
ShopCars =
element.Element("Cars")!.Elements("ShopCar")
.ToDictionary(x =>
Convert.ToInt32(x.Element("Key")?.Value), x =>
Convert.ToInt32(x.Element("Value")?.Value))
};
}
public void Update(CarShopBindingModel model)
{
if (model == null)
{
return;
}
ShopName = model.ShopName;
Adress = model.Adress;
Fullness = model.Fullness;
ShopCars = model.Cars.ToDictionary(x => x.Key, x =>
x.Value.Item2);
_cars = null;
}
public CarShopViewModel GetViewModel => new()
{
Id = Id,
ShopName = ShopName,
Adress = Adress,
DateOpen = DateOpen,
Fullness = Fullness,
Cars = Cars
};
public XElement GetXElement => new("CarShop",
new XAttribute("Id", Id),
new XElement("ShopName", ShopName),
new XElement("Adress", Adress),
new XElement("DateOpen", DateOpen.ToString()),
new XElement("Fullness", Fullness.ToString()),
new XElement("Cars", ShopCars.Select(x =>
new XElement("ShopCar",
new XElement("Key", x.Key),
new XElement("Value", x.Value)))
.ToArray()));
}
}

View File

@ -0,0 +1,65 @@
using AutomobilePlantContracts.BindingModels;
using AutomobilePlantContracts.ViewModel;
using AutomobilePlantDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace AutomomilePlantFileImplement.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())
);
}
}

View File

@ -0,0 +1,100 @@
using AutomobilePlantContracts.BindingModels;
using AutomobilePlantContracts.ViewModel;
using AutomobilePlantDataModels.Enums;
using AutomobilePlantDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace AutomomilePlantFileImplement.Models
{
public class Order : IOrderModel
{
public int CarId { get; private set; }
public string CarName { 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; } = null;
public int Id { get; private set; }
public static Order? Create(OrderBindingModel model)
{
if (model == null)
{
return null;
}
return new Order()
{
CarId = model.CarId,
CarName = model.CarName,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement,
Id = model.Id
};
}
public static Order? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Order()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
CarId = Convert.ToInt32(element.Element("CarId")!.Value),
CarName= element.Element("CarName")!.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=DateTime.Parse(element.Element("DateCreate")!.Value),
DateImplement= string.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null : DateTime.Parse(element.Element("DateImplement")!.Value)
};
}
public void Update(OrderBindingModel model)
{
if (model == null)
{
return;
}
Status = model.Status;
DateImplement = model.DateImplement;
}
public OrderViewModel GetViewModel => new()
{
Id = Id,
CarId = CarId,
CarName = CarName,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement
};
public XElement GetXElement => new("Order",
new XAttribute("Id", Id),
new XElement("CarId", CarId.ToString()),
new XElement("CarName", CarName),
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())
);
}
}