Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cc3bc5bf34 | |||
| d1b29031d2 | |||
| d95866ee89 | |||
| 4b53ad808a | |||
| 6018455bd6 |
50
Airbus/Drawnings/ExtentionDrawningAirbus.cs
Normal file
50
Airbus/Drawnings/ExtentionDrawningAirbus.cs
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ProjectAirbus.Entities;
|
||||||
|
|
||||||
|
namespace ProjectAirbus.Drawnings
|
||||||
|
{
|
||||||
|
public static class ExtentionDrawningAirbus
|
||||||
|
{
|
||||||
|
// создание объекта из строки
|
||||||
|
public static DrawningAirbus? CreateDrawningAirbus(this string info, char separatorForObject, int width, int height)
|
||||||
|
{
|
||||||
|
string[] strs = info.Split(separatorForObject);
|
||||||
|
if (strs.Length == 3)
|
||||||
|
{
|
||||||
|
return new DrawningAirbus(
|
||||||
|
Convert.ToInt32(strs[0]),
|
||||||
|
Convert.ToInt32(strs[1]),
|
||||||
|
Color.FromName(strs[2]), width, height);
|
||||||
|
}
|
||||||
|
if (strs.Length == 6)
|
||||||
|
{
|
||||||
|
return new DrawningPlane(
|
||||||
|
Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]),
|
||||||
|
Color.FromName(strs[2]), Color.FromName(strs[3]),
|
||||||
|
Convert.ToBoolean(strs[4]), Convert.ToBoolean(strs[5]),
|
||||||
|
width, height);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Получение данных для сохранения в файл
|
||||||
|
public static string GetDataForSave(this DrawningAirbus drawningAirbus, char separatorForObject)
|
||||||
|
{
|
||||||
|
var airbus = drawningAirbus.EntityAirbus;
|
||||||
|
if (airbus == null)
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
var str = $"{airbus.Speed}{separatorForObject}{airbus.Weight}{separatorForObject}{airbus.BodyColor.Name}";
|
||||||
|
if (airbus is not EntityPlane plane)
|
||||||
|
{
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
return $"{str}{separatorForObject}{plane.AdditionalColor.Name}{separatorForObject}{plane.IsCompartment}{separatorForObject}{plane.IsAdditionalEngine}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
19
Airbus/Exceptions/AirbusNotFoundException.cs
Normal file
19
Airbus/Exceptions/AirbusNotFoundException.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
|
namespace ProjectAirbus.Exceptions
|
||||||
|
{
|
||||||
|
[Serializable]
|
||||||
|
internal class AirbusNotFoundException : ApplicationException
|
||||||
|
{
|
||||||
|
public AirbusNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
|
||||||
|
public AirbusNotFoundException() : base() { }
|
||||||
|
public AirbusNotFoundException(string message) : base(message) { }
|
||||||
|
public AirbusNotFoundException(string message, Exception exception) : base(message, exception) { }
|
||||||
|
protected AirbusNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
19
Airbus/Exceptions/StorageOverflowException.cs
Normal file
19
Airbus/Exceptions/StorageOverflowException.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
|
namespace ProjectAirbus.Exceptions
|
||||||
|
{
|
||||||
|
[Serializable]
|
||||||
|
internal class StorageOverflowException : ApplicationException
|
||||||
|
{
|
||||||
|
public StorageOverflowException(int count) : base($"В наборе превышено допустимое количество: {count}") { }
|
||||||
|
public StorageOverflowException() : base() { }
|
||||||
|
public StorageOverflowException (string message) : base(message) { }
|
||||||
|
public StorageOverflowException (string message, Exception exception) : base(message, exception) { }
|
||||||
|
protected StorageOverflowException(SerializationInfo info, StreamingContext context) : base(info, context) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
143
Airbus/FormAirbusCollection.Designer.cs
generated
143
Airbus/FormAirbusCollection.Designer.cs
generated
@@ -40,15 +40,25 @@
|
|||||||
buttonAddStorage = new Button();
|
buttonAddStorage = new Button();
|
||||||
buttonDeleteStorage = new Button();
|
buttonDeleteStorage = new Button();
|
||||||
textBoxStorageName = new TextBox();
|
textBoxStorageName = new TextBox();
|
||||||
|
menuStrip = new MenuStrip();
|
||||||
|
ToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
SaveToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
LoadToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
openFileDialog = new OpenFileDialog();
|
||||||
|
saveFileDialog = new SaveFileDialog();
|
||||||
|
buttonSortByType = new Button();
|
||||||
|
buttonSortByColor = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||||
|
menuStrip.SuspendLayout();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// buttonAddAirbus
|
// buttonAddAirbus
|
||||||
//
|
//
|
||||||
buttonAddAirbus.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
buttonAddAirbus.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
buttonAddAirbus.Location = new Point(572, 332);
|
buttonAddAirbus.Location = new Point(638, 458);
|
||||||
|
buttonAddAirbus.Margin = new Padding(3, 4, 3, 4);
|
||||||
buttonAddAirbus.Name = "buttonAddAirbus";
|
buttonAddAirbus.Name = "buttonAddAirbus";
|
||||||
buttonAddAirbus.Size = new Size(137, 28);
|
buttonAddAirbus.Size = new Size(173, 37);
|
||||||
buttonAddAirbus.TabIndex = 0;
|
buttonAddAirbus.TabIndex = 0;
|
||||||
buttonAddAirbus.Text = "Добавить самолёт";
|
buttonAddAirbus.Text = "Добавить самолёт";
|
||||||
buttonAddAirbus.UseVisualStyleBackColor = true;
|
buttonAddAirbus.UseVisualStyleBackColor = true;
|
||||||
@@ -56,9 +66,10 @@
|
|||||||
//
|
//
|
||||||
// pictureBoxCollection
|
// pictureBoxCollection
|
||||||
//
|
//
|
||||||
pictureBoxCollection.Location = new Point(0, 0);
|
pictureBoxCollection.Location = new Point(0, 28);
|
||||||
|
pictureBoxCollection.Margin = new Padding(3, 4, 3, 4);
|
||||||
pictureBoxCollection.Name = "pictureBoxCollection";
|
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||||
pictureBoxCollection.Size = new Size(552, 436);
|
pictureBoxCollection.Size = new Size(620, 545);
|
||||||
pictureBoxCollection.TabIndex = 1;
|
pictureBoxCollection.TabIndex = 1;
|
||||||
pictureBoxCollection.TabStop = false;
|
pictureBoxCollection.TabStop = false;
|
||||||
//
|
//
|
||||||
@@ -67,18 +78,19 @@
|
|||||||
labelInstruments.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
labelInstruments.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
labelInstruments.AutoSize = true;
|
labelInstruments.AutoSize = true;
|
||||||
labelInstruments.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
|
labelInstruments.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
|
||||||
labelInstruments.Location = new Point(580, 0);
|
labelInstruments.Location = new Point(638, 28);
|
||||||
labelInstruments.Name = "labelInstruments";
|
labelInstruments.Name = "labelInstruments";
|
||||||
labelInstruments.Size = new Size(108, 21);
|
labelInstruments.Size = new Size(136, 28);
|
||||||
labelInstruments.TabIndex = 2;
|
labelInstruments.TabIndex = 2;
|
||||||
labelInstruments.Text = "Инструменты";
|
labelInstruments.Text = "Инструменты";
|
||||||
//
|
//
|
||||||
// buttonUpdate
|
// buttonUpdate
|
||||||
//
|
//
|
||||||
buttonUpdate.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
buttonUpdate.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
buttonUpdate.Location = new Point(572, 130);
|
buttonUpdate.Location = new Point(638, 160);
|
||||||
|
buttonUpdate.Margin = new Padding(3, 4, 3, 4);
|
||||||
buttonUpdate.Name = "buttonUpdate";
|
buttonUpdate.Name = "buttonUpdate";
|
||||||
buttonUpdate.Size = new Size(131, 25);
|
buttonUpdate.Size = new Size(166, 33);
|
||||||
buttonUpdate.TabIndex = 3;
|
buttonUpdate.TabIndex = 3;
|
||||||
buttonUpdate.Text = "Обновить набор";
|
buttonUpdate.Text = "Обновить набор";
|
||||||
buttonUpdate.UseVisualStyleBackColor = true;
|
buttonUpdate.UseVisualStyleBackColor = true;
|
||||||
@@ -87,9 +99,10 @@
|
|||||||
// buttonDeleteAirbus
|
// buttonDeleteAirbus
|
||||||
//
|
//
|
||||||
buttonDeleteAirbus.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
buttonDeleteAirbus.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
buttonDeleteAirbus.Location = new Point(572, 392);
|
buttonDeleteAirbus.Location = new Point(638, 537);
|
||||||
|
buttonDeleteAirbus.Margin = new Padding(3, 4, 3, 4);
|
||||||
buttonDeleteAirbus.Name = "buttonDeleteAirbus";
|
buttonDeleteAirbus.Name = "buttonDeleteAirbus";
|
||||||
buttonDeleteAirbus.Size = new Size(137, 28);
|
buttonDeleteAirbus.Size = new Size(173, 37);
|
||||||
buttonDeleteAirbus.TabIndex = 4;
|
buttonDeleteAirbus.TabIndex = 4;
|
||||||
buttonDeleteAirbus.Text = "Удалить самолёт";
|
buttonDeleteAirbus.Text = "Удалить самолёт";
|
||||||
buttonDeleteAirbus.UseVisualStyleBackColor = true;
|
buttonDeleteAirbus.UseVisualStyleBackColor = true;
|
||||||
@@ -98,10 +111,11 @@
|
|||||||
// maskedTextBoxNumber
|
// maskedTextBoxNumber
|
||||||
//
|
//
|
||||||
maskedTextBoxNumber.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
maskedTextBoxNumber.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
maskedTextBoxNumber.Location = new Point(572, 365);
|
maskedTextBoxNumber.Location = new Point(638, 502);
|
||||||
|
maskedTextBoxNumber.Margin = new Padding(3, 4, 3, 4);
|
||||||
maskedTextBoxNumber.Mask = "00";
|
maskedTextBoxNumber.Mask = "00";
|
||||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||||
maskedTextBoxNumber.Size = new Size(138, 23);
|
maskedTextBoxNumber.Size = new Size(173, 27);
|
||||||
maskedTextBoxNumber.TabIndex = 5;
|
maskedTextBoxNumber.TabIndex = 5;
|
||||||
maskedTextBoxNumber.ValidatingType = typeof(int);
|
maskedTextBoxNumber.ValidatingType = typeof(int);
|
||||||
//
|
//
|
||||||
@@ -109,29 +123,27 @@
|
|||||||
//
|
//
|
||||||
label1.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
label1.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
label1.AutoSize = true;
|
label1.AutoSize = true;
|
||||||
label1.Location = new Point(572, 38);
|
label1.Location = new Point(638, 65);
|
||||||
label1.Name = "label1";
|
label1.Name = "label1";
|
||||||
label1.Size = new Size(52, 15);
|
label1.Size = new Size(66, 20);
|
||||||
label1.TabIndex = 7;
|
label1.TabIndex = 7;
|
||||||
label1.Text = "Наборы";
|
label1.Text = "Наборы";
|
||||||
//
|
//
|
||||||
// listBoxStorages
|
// listBoxStorages
|
||||||
//
|
//
|
||||||
listBoxStorages.FormattingEnabled = true;
|
listBoxStorages.FormattingEnabled = true;
|
||||||
listBoxStorages.ItemHeight = 15;
|
listBoxStorages.ItemHeight = 20;
|
||||||
listBoxStorages.Location = new Point(572, 160);
|
listBoxStorages.Location = new Point(638, 196);
|
||||||
listBoxStorages.Margin = new Padding(3, 2, 3, 2);
|
|
||||||
listBoxStorages.Name = "listBoxStorages";
|
listBoxStorages.Name = "listBoxStorages";
|
||||||
listBoxStorages.Size = new Size(132, 109);
|
listBoxStorages.Size = new Size(166, 124);
|
||||||
listBoxStorages.TabIndex = 8;
|
listBoxStorages.TabIndex = 8;
|
||||||
listBoxStorages.SelectedIndexChanged += listBoxObjects_SelectedIndexChanged;
|
listBoxStorages.SelectedIndexChanged += listBoxObjects_SelectedIndexChanged;
|
||||||
//
|
//
|
||||||
// buttonAddStorage
|
// buttonAddStorage
|
||||||
//
|
//
|
||||||
buttonAddStorage.Location = new Point(572, 102);
|
buttonAddStorage.Location = new Point(638, 124);
|
||||||
buttonAddStorage.Margin = new Padding(3, 2, 3, 2);
|
|
||||||
buttonAddStorage.Name = "buttonAddStorage";
|
buttonAddStorage.Name = "buttonAddStorage";
|
||||||
buttonAddStorage.Size = new Size(131, 25);
|
buttonAddStorage.Size = new Size(166, 33);
|
||||||
buttonAddStorage.TabIndex = 9;
|
buttonAddStorage.TabIndex = 9;
|
||||||
buttonAddStorage.Text = "Добавить набор";
|
buttonAddStorage.Text = "Добавить набор";
|
||||||
buttonAddStorage.UseVisualStyleBackColor = true;
|
buttonAddStorage.UseVisualStyleBackColor = true;
|
||||||
@@ -139,10 +151,9 @@
|
|||||||
//
|
//
|
||||||
// buttonDeleteStorage
|
// buttonDeleteStorage
|
||||||
//
|
//
|
||||||
buttonDeleteStorage.Location = new Point(572, 273);
|
buttonDeleteStorage.Location = new Point(638, 324);
|
||||||
buttonDeleteStorage.Margin = new Padding(3, 2, 3, 2);
|
|
||||||
buttonDeleteStorage.Name = "buttonDeleteStorage";
|
buttonDeleteStorage.Name = "buttonDeleteStorage";
|
||||||
buttonDeleteStorage.Size = new Size(131, 25);
|
buttonDeleteStorage.Size = new Size(166, 33);
|
||||||
buttonDeleteStorage.TabIndex = 10;
|
buttonDeleteStorage.TabIndex = 10;
|
||||||
buttonDeleteStorage.Text = "Удалить набор";
|
buttonDeleteStorage.Text = "Удалить набор";
|
||||||
buttonDeleteStorage.UseVisualStyleBackColor = true;
|
buttonDeleteStorage.UseVisualStyleBackColor = true;
|
||||||
@@ -150,17 +161,78 @@
|
|||||||
//
|
//
|
||||||
// textBoxStorageName
|
// textBoxStorageName
|
||||||
//
|
//
|
||||||
textBoxStorageName.Location = new Point(572, 77);
|
textBoxStorageName.Location = new Point(638, 93);
|
||||||
textBoxStorageName.Margin = new Padding(3, 2, 3, 2);
|
|
||||||
textBoxStorageName.Name = "textBoxStorageName";
|
textBoxStorageName.Name = "textBoxStorageName";
|
||||||
textBoxStorageName.Size = new Size(132, 23);
|
textBoxStorageName.Size = new Size(166, 27);
|
||||||
textBoxStorageName.TabIndex = 11;
|
textBoxStorageName.TabIndex = 11;
|
||||||
//
|
//
|
||||||
|
// menuStrip
|
||||||
|
//
|
||||||
|
menuStrip.ImageScalingSize = new Size(20, 20);
|
||||||
|
menuStrip.Items.AddRange(new ToolStripItem[] { ToolStripMenuItem });
|
||||||
|
menuStrip.Location = new Point(0, 0);
|
||||||
|
menuStrip.Name = "menuStrip";
|
||||||
|
menuStrip.Size = new Size(827, 28);
|
||||||
|
menuStrip.TabIndex = 12;
|
||||||
|
menuStrip.Text = "menuStrip1";
|
||||||
|
//
|
||||||
|
// ToolStripMenuItem
|
||||||
|
//
|
||||||
|
ToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { SaveToolStripMenuItem, LoadToolStripMenuItem });
|
||||||
|
ToolStripMenuItem.Name = "ToolStripMenuItem";
|
||||||
|
ToolStripMenuItem.Size = new Size(59, 24);
|
||||||
|
ToolStripMenuItem.Text = "Файл";
|
||||||
|
//
|
||||||
|
// SaveToolStripMenuItem
|
||||||
|
//
|
||||||
|
SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
|
||||||
|
SaveToolStripMenuItem.Size = new Size(166, 26);
|
||||||
|
SaveToolStripMenuItem.Text = "Сохранить";
|
||||||
|
SaveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// LoadToolStripMenuItem
|
||||||
|
//
|
||||||
|
LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
|
||||||
|
LoadToolStripMenuItem.Size = new Size(166, 26);
|
||||||
|
LoadToolStripMenuItem.Text = "Загрузить";
|
||||||
|
LoadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// openFileDialog
|
||||||
|
//
|
||||||
|
openFileDialog.Filter = "txt file | *.txt";
|
||||||
|
//
|
||||||
|
// saveFileDialog
|
||||||
|
//
|
||||||
|
saveFileDialog.Filter = "txt file | *.txt";
|
||||||
|
saveFileDialog.OverwritePrompt = false;
|
||||||
|
//
|
||||||
|
// buttonSortByType
|
||||||
|
//
|
||||||
|
buttonSortByType.Location = new Point(638, 372);
|
||||||
|
buttonSortByType.Name = "buttonSortByType";
|
||||||
|
buttonSortByType.Size = new Size(166, 33);
|
||||||
|
buttonSortByType.TabIndex = 13;
|
||||||
|
buttonSortByType.Text = "Сортировка по типу";
|
||||||
|
buttonSortByType.UseVisualStyleBackColor = true;
|
||||||
|
buttonSortByType.Click += buttonSortByType_Click;
|
||||||
|
//
|
||||||
|
// buttonSortByColor
|
||||||
|
//
|
||||||
|
buttonSortByColor.Location = new Point(638, 408);
|
||||||
|
buttonSortByColor.Name = "buttonSortByColor";
|
||||||
|
buttonSortByColor.Size = new Size(166, 31);
|
||||||
|
buttonSortByColor.TabIndex = 14;
|
||||||
|
buttonSortByColor.Text = "Сортировка по цвету";
|
||||||
|
buttonSortByColor.UseVisualStyleBackColor = true;
|
||||||
|
buttonSortByColor.Click += buttonSortByColor_Click;
|
||||||
|
//
|
||||||
// FormAirbusCollection
|
// FormAirbusCollection
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(724, 443);
|
ClientSize = new Size(827, 585);
|
||||||
|
Controls.Add(buttonSortByColor);
|
||||||
|
Controls.Add(buttonSortByType);
|
||||||
Controls.Add(textBoxStorageName);
|
Controls.Add(textBoxStorageName);
|
||||||
Controls.Add(buttonDeleteStorage);
|
Controls.Add(buttonDeleteStorage);
|
||||||
Controls.Add(buttonAddStorage);
|
Controls.Add(buttonAddStorage);
|
||||||
@@ -172,9 +244,14 @@
|
|||||||
Controls.Add(buttonUpdate);
|
Controls.Add(buttonUpdate);
|
||||||
Controls.Add(labelInstruments);
|
Controls.Add(labelInstruments);
|
||||||
Controls.Add(pictureBoxCollection);
|
Controls.Add(pictureBoxCollection);
|
||||||
|
Controls.Add(menuStrip);
|
||||||
|
MainMenuStrip = menuStrip;
|
||||||
|
Margin = new Padding(3, 4, 3, 4);
|
||||||
Name = "FormAirbusCollection";
|
Name = "FormAirbusCollection";
|
||||||
Text = "Набор самолётов";
|
Text = "Набор самолётов";
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||||
|
menuStrip.ResumeLayout(false);
|
||||||
|
menuStrip.PerformLayout();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
PerformLayout();
|
PerformLayout();
|
||||||
}
|
}
|
||||||
@@ -193,5 +270,13 @@
|
|||||||
private Button buttonAddStorage;
|
private Button buttonAddStorage;
|
||||||
private Button buttonDeleteStorage;
|
private Button buttonDeleteStorage;
|
||||||
private TextBox textBoxStorageName;
|
private TextBox textBoxStorageName;
|
||||||
|
private MenuStrip menuStrip;
|
||||||
|
private ToolStripMenuItem ToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem SaveToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem LoadToolStripMenuItem;
|
||||||
|
private OpenFileDialog openFileDialog;
|
||||||
|
private SaveFileDialog saveFileDialog;
|
||||||
|
private Button buttonSortByType;
|
||||||
|
private Button buttonSortByColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,9 +7,11 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using ProjectAirbus.Generics;
|
using ProjectAirbus.Generics;
|
||||||
using ProjectAirbus.Drawnings;
|
using ProjectAirbus.Drawnings;
|
||||||
using ProjectAirbus.MovementStrategy;
|
using ProjectAirbus.Exceptions;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
namespace ProjectAirbus
|
namespace ProjectAirbus
|
||||||
{
|
{
|
||||||
@@ -17,11 +19,73 @@ namespace ProjectAirbus
|
|||||||
{
|
{
|
||||||
// Набор объектов
|
// Набор объектов
|
||||||
private readonly AirbusGenericStorage _storage;
|
private readonly AirbusGenericStorage _storage;
|
||||||
|
// Логер
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
public FormAirbusCollection()
|
public FormAirbusCollection(ILogger<FormAirbusCollection> logger)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_storage = new AirbusGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
_storage = new AirbusGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonSortByType_Click(object sender, EventArgs e) => CompareAirbus(new AirbusCompareByType());
|
||||||
|
|
||||||
|
private void buttonSortByColor_Click(object sender, EventArgs e) => CompareAirbus(new AirbusCompareByColor());
|
||||||
|
|
||||||
|
// Сортировка по сравнителю
|
||||||
|
private void CompareAirbus(IComparer<DrawningAirbus?> comparer)
|
||||||
|
{
|
||||||
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
obj.Sort(comparer);
|
||||||
|
pictureBoxCollection.Image = obj.ShowAirbus();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Обработка нажатия "Сохранение"
|
||||||
|
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_storage.SaveData(saveFileDialog.FileName);
|
||||||
|
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
_logger.LogInformation($"Файл сохранён по пути: {saveFileDialog.FileName}");
|
||||||
|
}
|
||||||
|
catch (InvalidOperationException ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
_logger.LogWarning(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Обработка нажатия "Загрузка"
|
||||||
|
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_storage.LoadData(openFileDialog.FileName);
|
||||||
|
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
_logger.LogInformation($"Файл загружен по пути: {openFileDialog.FileName}");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
_logger.LogWarning(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ReloadObjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
// заполнение лист бокс
|
// заполнение лист бокс
|
||||||
@@ -31,7 +95,7 @@ namespace ProjectAirbus
|
|||||||
listBoxStorages.Items.Clear();
|
listBoxStorages.Items.Clear();
|
||||||
for (int i = 0; i < _storage.Keys.Count; i++)
|
for (int i = 0; i < _storage.Keys.Count; i++)
|
||||||
{
|
{
|
||||||
listBoxStorages.Items.Add(_storage.Keys[i]);
|
listBoxStorages.Items.Add(_storage.Keys[i].Name);
|
||||||
}
|
}
|
||||||
if (listBoxStorages.Items.Count > 0 && (index == -1 || index >= listBoxStorages.Items.Count))
|
if (listBoxStorages.Items.Count > 0 && (index == -1 || index >= listBoxStorages.Items.Count))
|
||||||
{
|
{
|
||||||
@@ -54,6 +118,7 @@ namespace ProjectAirbus
|
|||||||
}
|
}
|
||||||
_storage.AddSet(textBoxStorageName.Text);
|
_storage.AddSet(textBoxStorageName.Text);
|
||||||
ReloadObjects();
|
ReloadObjects();
|
||||||
|
_logger.LogInformation($"Добавлен набор: {textBoxStorageName.Text}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// выбрать набор
|
// выбрать набор
|
||||||
@@ -69,10 +134,12 @@ namespace ProjectAirbus
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
string name = listBoxStorages.SelectedItem.ToString() ?? string.Empty;
|
||||||
if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
{
|
{
|
||||||
_storage.DelSet(listBoxStorages.SelectedItem.ToString() ?? string.Empty);
|
_storage.DelSet(name);
|
||||||
ReloadObjects();
|
ReloadObjects();
|
||||||
|
_logger.LogInformation($"Удалён набор: {name}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,14 +165,28 @@ namespace ProjectAirbus
|
|||||||
}
|
}
|
||||||
// меняем границы после закрытия конфига
|
// меняем границы после закрытия конфига
|
||||||
_airbus.ChangeBordersPicture(Width, Height);
|
_airbus.ChangeBordersPicture(Width, Height);
|
||||||
if (obj + _airbus != -1)
|
try
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект добавлен");
|
if (obj + _airbus != -1)
|
||||||
pictureBoxCollection.Image = obj.ShowAirbus();
|
{
|
||||||
|
MessageBox.Show("Объект добавлен");
|
||||||
|
pictureBoxCollection.Image = obj.ShowAirbus();
|
||||||
|
_logger.LogInformation($"Добавлен объект: {_airbus.EntityAirbus.BodyColor}");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
catch (StorageOverflowException ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Не удалось добавить объект");
|
MessageBox.Show(ex.Message);
|
||||||
|
_logger.LogWarning(ex.Message);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message);
|
||||||
|
_logger.LogWarning(ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,24 +206,29 @@ namespace ProjectAirbus
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int pos = 0;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||||
|
if (obj - pos)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект удален");
|
||||||
|
pictureBoxCollection.Image = obj.ShowAirbus();
|
||||||
|
_logger.LogInformation($"Удалён объект по позиции : {pos}");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch (FormatException ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show("Неверный формат ввода");
|
||||||
return;
|
_logger.LogWarning("Неверный формат ввода");
|
||||||
}
|
}
|
||||||
if (obj - pos)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект удален");
|
MessageBox.Show(ex.Message);
|
||||||
pictureBoxCollection.Image = obj.ShowAirbus();
|
_logger.LogWarning(ex.Message);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MessageBox.Show("Не удалось удалить объект");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -120,7 +120,16 @@
|
|||||||
<metadata name="colorDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
<metadata name="colorDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
<value>17, 17</value>
|
<value>17, 17</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
|
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>156, 17</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>292, 17</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>462, 17</value>
|
||||||
|
</metadata>
|
||||||
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>36</value>
|
<value>25</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
</root>
|
</root>
|
||||||
4
Airbus/FormPlane.Designer.cs
generated
4
Airbus/FormPlane.Designer.cs
generated
@@ -1,6 +1,6 @@
|
|||||||
namespace ProjectAirbus
|
namespace ProjectAirbus
|
||||||
{
|
{
|
||||||
partial class FormPlane
|
partial class FormAirbus
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required designer variable.
|
/// Required designer variable.
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormPlane));
|
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormAirbus));
|
||||||
pictureAirBus = new PictureBox();
|
pictureAirBus = new PictureBox();
|
||||||
buttonUp = new Button();
|
buttonUp = new Button();
|
||||||
buttonLeft = new Button();
|
buttonLeft = new Button();
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ using ProjectAirbus.Entities;
|
|||||||
|
|
||||||
namespace ProjectAirbus
|
namespace ProjectAirbus
|
||||||
{
|
{
|
||||||
public partial class FormPlane : Form
|
public partial class FormAirbus : Form
|
||||||
{
|
{
|
||||||
private DrawningAirbus? _drawningAirbus;
|
private DrawningAirbus? _drawningAirbus;
|
||||||
private AbstractStrategy? _abstractStrategy;
|
private AbstractStrategy? _abstractStrategy;
|
||||||
@@ -12,7 +12,7 @@ namespace ProjectAirbus
|
|||||||
// Выбранный автомобиль
|
// Выбранный автомобиль
|
||||||
public DrawningAirbus? SelectedAirbus { get; private set; }
|
public DrawningAirbus? SelectedAirbus { get; private set; }
|
||||||
|
|
||||||
public FormPlane()
|
public FormAirbus()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_abstractStrategy = null;
|
_abstractStrategy = null;
|
||||||
|
|||||||
27
Airbus/Generics/AirbusCollectionInfo.cs
Normal file
27
Airbus/Generics/AirbusCollectionInfo.cs
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectAirbus.Generics
|
||||||
|
{
|
||||||
|
internal class AirbusCollectionInfo : IEquatable<AirbusCollectionInfo>
|
||||||
|
{
|
||||||
|
public string Name { get; private set; }
|
||||||
|
public string Description { get; private set; }
|
||||||
|
public AirbusCollectionInfo(string name, string description)
|
||||||
|
{
|
||||||
|
Name = name;
|
||||||
|
Description = description;
|
||||||
|
}
|
||||||
|
public bool Equals(AirbusCollectionInfo? other)
|
||||||
|
{
|
||||||
|
if (ReferenceEquals(other, null))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return Name.Equals(other.Name);
|
||||||
|
}
|
||||||
|
public override int GetHashCode() => Name.GetHashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
34
Airbus/Generics/AirbusCompareByColor.cs
Normal file
34
Airbus/Generics/AirbusCompareByColor.cs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ProjectAirbus.Drawnings;
|
||||||
|
using ProjectAirbus.Entities;
|
||||||
|
|
||||||
|
namespace ProjectAirbus.Generics
|
||||||
|
{
|
||||||
|
internal class AirbusCompareByColor : IComparer<DrawningAirbus>
|
||||||
|
{
|
||||||
|
public int Compare(DrawningAirbus? x, DrawningAirbus? y)
|
||||||
|
{
|
||||||
|
if (x == null || x.EntityAirbus == null)
|
||||||
|
throw new ArgumentNullException(nameof(x));
|
||||||
|
|
||||||
|
if (y == null || y.EntityAirbus == null)
|
||||||
|
throw new ArgumentNullException(nameof(y));
|
||||||
|
|
||||||
|
var xPlane = x.EntityAirbus;
|
||||||
|
var yPlane = y.EntityAirbus;
|
||||||
|
|
||||||
|
if (xPlane.BodyColor != yPlane.BodyColor)
|
||||||
|
return xPlane.BodyColor.Name.CompareTo(yPlane.BodyColor.Name);
|
||||||
|
|
||||||
|
var speedCompare = x.EntityAirbus.Speed.CompareTo(y.EntityAirbus.Speed);
|
||||||
|
if (speedCompare != 0)
|
||||||
|
return speedCompare;
|
||||||
|
|
||||||
|
return x.EntityAirbus.Weight.CompareTo(y.EntityAirbus.Weight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
30
Airbus/Generics/AirbusCompareByType.cs
Normal file
30
Airbus/Generics/AirbusCompareByType.cs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ProjectAirbus.Drawnings;
|
||||||
|
|
||||||
|
namespace ProjectAirbus.Generics
|
||||||
|
{
|
||||||
|
internal class AirbusCompareByType : IComparer<DrawningAirbus>
|
||||||
|
{
|
||||||
|
public int Compare(DrawningAirbus? x, DrawningAirbus? y)
|
||||||
|
{
|
||||||
|
if (x == null || x.EntityAirbus == null)
|
||||||
|
throw new ArgumentNullException(nameof(x));
|
||||||
|
|
||||||
|
if (y == null || y.EntityAirbus == null)
|
||||||
|
throw new ArgumentNullException(nameof(y));
|
||||||
|
|
||||||
|
if (x.GetType().Name != y.GetType().Name)
|
||||||
|
return x.GetType().Name.CompareTo(y.GetType().Name);
|
||||||
|
|
||||||
|
var speedCompare = x.EntityAirbus.Speed.CompareTo(y.EntityAirbus.Speed);
|
||||||
|
if (speedCompare != 0)
|
||||||
|
return speedCompare;
|
||||||
|
|
||||||
|
return x.EntityAirbus.Weight.CompareTo(y.EntityAirbus.Weight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,9 +12,10 @@ namespace ProjectAirbus.Generics
|
|||||||
where T : DrawningAirbus
|
where T : DrawningAirbus
|
||||||
where U : IMoveableObject
|
where U : IMoveableObject
|
||||||
{
|
{
|
||||||
|
public int count => _collection.Count;
|
||||||
private readonly int _pictureWidth;
|
private readonly int _pictureWidth;
|
||||||
private readonly int _pictureHeight;
|
private readonly int _pictureHeight;
|
||||||
// Размер занимаемого места
|
// Размер занимаемого места 89х34
|
||||||
private readonly int _placeSizeWidth = 89;
|
private readonly int _placeSizeWidth = 89;
|
||||||
private readonly int _placeSizeHeight = 34;
|
private readonly int _placeSizeHeight = 34;
|
||||||
// коллекция
|
// коллекция
|
||||||
@@ -29,11 +30,15 @@ namespace ProjectAirbus.Generics
|
|||||||
|
|
||||||
_collection = new SetGeneric<T>(width * height);
|
_collection = new SetGeneric<T>(width * height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Сортировка
|
||||||
|
public void Sort(IComparer<T?> comparer) => _collection.SortSet(comparer);
|
||||||
|
|
||||||
public static int operator +(AirbusGenericCollection<T, U> collect, T? obj)
|
public static int operator +(AirbusGenericCollection<T, U> collect, T? obj)
|
||||||
{
|
{
|
||||||
if (obj != null)
|
if (obj != null)
|
||||||
{
|
{
|
||||||
return collect._collection.Insert(obj);
|
return collect._collection.Insert(obj, new DrawningAirbusEqutables());
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -46,6 +51,9 @@ namespace ProjectAirbus.Generics
|
|||||||
return collect?._collection.Remove(pos) ?? false;
|
return collect?._collection.Remove(pos) ?? false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// получение объектов коллекции
|
||||||
|
public IEnumerable<T?> GetAirbus => _collection.GetAirbus();
|
||||||
|
|
||||||
// получение объекта IMoveableObjecr
|
// получение объекта IMoveableObjecr
|
||||||
public U? GetU(int pos)
|
public U? GetU(int pos)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,17 +13,24 @@ namespace ProjectAirbus.Generics
|
|||||||
internal class AirbusGenericStorage
|
internal class AirbusGenericStorage
|
||||||
{
|
{
|
||||||
//Словарь (хранилище)
|
//Словарь (хранилище)
|
||||||
readonly Dictionary<string, AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus>> _airbusStorages;
|
readonly Dictionary<AirbusCollectionInfo, AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus>> _airbusStorages;
|
||||||
//Возвращение списка названий наборов
|
//Возвращение списка названий наборов
|
||||||
public List<string> Keys => _airbusStorages.Keys.ToList();
|
public List<AirbusCollectionInfo> Keys => _airbusStorages.Keys.ToList();
|
||||||
//Ширина окна отрисовки
|
//Ширина окна отрисовки
|
||||||
private readonly int _pictureWidth;
|
private readonly int _pictureWidth;
|
||||||
//Высота окна отрисовки
|
//Высота окна отрисовки
|
||||||
private readonly int _pictureHeight;
|
private readonly int _pictureHeight;
|
||||||
|
|
||||||
|
// Разделитель для записи ключа и значения элемента словаря
|
||||||
|
private static readonly char _separatorForKeyValue = '|';
|
||||||
|
// Разделитель для записей коллекции данных в файл
|
||||||
|
private readonly char _separatorRecords = ';';
|
||||||
|
// Разделитель для записи информации по объекту в файл
|
||||||
|
private static readonly char _separatorForObject = ':';
|
||||||
|
|
||||||
public AirbusGenericStorage(int pictureWidth, int pictureHeight)
|
public AirbusGenericStorage(int pictureWidth, int pictureHeight)
|
||||||
{
|
{
|
||||||
_airbusStorages = new Dictionary<string, AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus>>();
|
_airbusStorages = new Dictionary<AirbusCollectionInfo, AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus>>();
|
||||||
_pictureWidth = pictureWidth;
|
_pictureWidth = pictureWidth;
|
||||||
_pictureHeight = pictureHeight;
|
_pictureHeight = pictureHeight;
|
||||||
}
|
}
|
||||||
@@ -31,25 +38,24 @@ namespace ProjectAirbus.Generics
|
|||||||
// Добавление набора
|
// Добавление набора
|
||||||
public void AddSet(string name)
|
public void AddSet(string name)
|
||||||
{
|
{
|
||||||
// проверка, что нет набора с таким именем
|
AirbusCollectionInfo set = new AirbusCollectionInfo(name, string.Empty);
|
||||||
foreach (string nameStorage in Keys)
|
|
||||||
{
|
if (_airbusStorages.ContainsKey(set))
|
||||||
if (nameStorage == name)
|
return;
|
||||||
{
|
|
||||||
return;
|
_airbusStorages.Add(set, new AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus>(_pictureWidth, _pictureHeight));
|
||||||
}
|
|
||||||
}
|
|
||||||
_airbusStorages.Add(name, new AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus>(_pictureWidth, _pictureHeight));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Удаление набора
|
// Удаление набора
|
||||||
public void DelSet(string name)
|
public void DelSet(string name)
|
||||||
{
|
{
|
||||||
if ( _airbusStorages.ContainsKey(name))
|
AirbusCollectionInfo set = new AirbusCollectionInfo(name, string.Empty);
|
||||||
{
|
|
||||||
_airbusStorages.Remove(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// проверка, что нет набора с таким именем
|
||||||
|
if (!_airbusStorages.ContainsKey(set))
|
||||||
|
return;
|
||||||
|
|
||||||
|
_airbusStorages.Remove(set);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Доступ к набору
|
// Доступ к набору
|
||||||
@@ -57,12 +63,110 @@ namespace ProjectAirbus.Generics
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (_airbusStorages.ContainsKey(ind))
|
AirbusCollectionInfo set = new AirbusCollectionInfo(ind, string.Empty);
|
||||||
|
|
||||||
|
if (!_airbusStorages.ContainsKey(set))
|
||||||
{
|
{
|
||||||
return _airbusStorages[ind];
|
return null;
|
||||||
}
|
}
|
||||||
return null;
|
return _airbusStorages[set];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Сохранение информации по автомобилям в хранилище в файл
|
||||||
|
public bool SaveData(string filename)
|
||||||
|
{
|
||||||
|
if (_airbusStorages.Count == 0)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Невалидная операция, нет данных для сохранения");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (File.Exists(filename))
|
||||||
|
{
|
||||||
|
File.Delete(filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
using (StreamWriter sw = File.CreateText(filename))
|
||||||
|
{
|
||||||
|
sw.WriteLine($"AirbusStorage");
|
||||||
|
|
||||||
|
foreach (var record in _airbusStorages)
|
||||||
|
{
|
||||||
|
StringBuilder records = new();
|
||||||
|
|
||||||
|
if (record.Value.count <= 0)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Невалидная операция, нет данных для сохранения");
|
||||||
|
}
|
||||||
|
foreach (DrawningAirbus? elem in record.Value.GetAirbus)
|
||||||
|
{
|
||||||
|
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
|
||||||
|
}
|
||||||
|
sw.WriteLine($"{record.Key}{_separatorForKeyValue}{records}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Загрузка информации по автомобилям в хранилище из файла
|
||||||
|
public bool LoadData(string filename)
|
||||||
|
{
|
||||||
|
if (!File.Exists(filename))
|
||||||
|
{
|
||||||
|
throw new FileNotFoundException($"Файл {filename} не найден");
|
||||||
|
}
|
||||||
|
|
||||||
|
using (StreamReader sr = File.OpenText(filename))
|
||||||
|
{
|
||||||
|
// 1-ая строка
|
||||||
|
string? curLine = sr.ReadLine();
|
||||||
|
// пустая или не те данные
|
||||||
|
if (curLine == null || curLine.Length == 0 || !curLine.StartsWith("AirbusStorage"))
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Неверный формат данных");
|
||||||
|
}
|
||||||
|
// очищаем
|
||||||
|
_airbusStorages.Clear();
|
||||||
|
|
||||||
|
// загружаем данные построчно
|
||||||
|
curLine = sr.ReadLine();
|
||||||
|
if (curLine == null || curLine.Length == 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Нет данных");
|
||||||
|
}
|
||||||
|
while (curLine != null)
|
||||||
|
{
|
||||||
|
// загружаем запись
|
||||||
|
if (!curLine.Contains(_separatorRecords))
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Коллекция пуста");
|
||||||
|
}
|
||||||
|
|
||||||
|
string[] record = curLine.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
|
||||||
|
// загружаем набор
|
||||||
|
AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus> collection = new(_pictureWidth, _pictureHeight);
|
||||||
|
// record[0] - название набора, record[1] - куча объектов
|
||||||
|
|
||||||
|
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
|
||||||
|
foreach (string elem in set)
|
||||||
|
{
|
||||||
|
DrawningAirbus? airbus = elem?.CreateDrawningAirbus(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||||
|
// проверяем, не переполнится ли коллекция
|
||||||
|
if (airbus != null)
|
||||||
|
{
|
||||||
|
if (collection + airbus == -1)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Невалидная операция, ошибка добавления в коллекцию");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_airbusStorages.Add(new AirbusCollectionInfo(record[0], string.Empty), collection);
|
||||||
|
curLine = sr.ReadLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
57
Airbus/Generics/DrawningAirbusEqutables.cs
Normal file
57
Airbus/Generics/DrawningAirbusEqutables.cs
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using ProjectAirbus.Drawnings;
|
||||||
|
using ProjectAirbus.Entities;
|
||||||
|
|
||||||
|
namespace ProjectAirbus.Generics
|
||||||
|
{
|
||||||
|
internal class DrawningAirbusEqutables : IEqualityComparer<DrawningAirbus?>
|
||||||
|
{
|
||||||
|
public bool Equals(DrawningAirbus? x, DrawningAirbus? y)
|
||||||
|
{
|
||||||
|
if (x == null && x.EntityAirbus == null)
|
||||||
|
throw new ArgumentNullException(nameof(x));
|
||||||
|
|
||||||
|
if (y == null && y.EntityAirbus == null)
|
||||||
|
throw new ArgumentNullException(nameof(y));
|
||||||
|
|
||||||
|
if ((x.GetType().Name != y.GetType().Name))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (x.EntityAirbus.Speed != y.EntityAirbus.Speed)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (x.EntityAirbus.Weight != y.EntityAirbus.Weight)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (x.EntityAirbus.BodyColor != y.EntityAirbus.BodyColor)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (x is DrawningPlane && y is DrawningPlane)
|
||||||
|
{
|
||||||
|
var xPlane = (EntityPlane)x.EntityAirbus;
|
||||||
|
var yPlane = (EntityPlane)y.EntityAirbus;
|
||||||
|
|
||||||
|
if (xPlane.AdditionalColor != yPlane.AdditionalColor)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (xPlane.IsAdditionalEngine != yPlane.IsAdditionalEngine)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (xPlane.IsCompartment != yPlane.IsCompartment)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetHashCode([DisallowNull] DrawningAirbus? obj)
|
||||||
|
{
|
||||||
|
return obj.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using ProjectAirbus.Exceptions;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -22,28 +23,33 @@ namespace ProjectAirbus.Generics
|
|||||||
_places = new List<T?>(count);
|
_places = new List<T?>(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Добавление объекта в начало набора
|
// сортировка набора
|
||||||
public int Insert(T airbus)
|
public void SortSet(IComparer<T?> comparer) => _places.Sort(comparer);
|
||||||
{
|
|
||||||
if (_places.Count >= _maxCount)
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
_places.Insert(0, airbus);
|
// Добавление объекта в начало набора
|
||||||
return 0;
|
public int Insert(T airbus, IEqualityComparer<T?>? equal = null)
|
||||||
|
{
|
||||||
|
return Insert(airbus, 0, equal);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Добавление объекта в набор на конкретную позицию
|
// Добавление объекта в набор на конкретную позицию
|
||||||
public bool Insert(T airbus, int position)
|
public int Insert(T airbus, int position, IEqualityComparer<T?>? equal = null)
|
||||||
{
|
{
|
||||||
if (Count >= _maxCount || position < 0 || position >= Count)
|
if (Count >= _maxCount)
|
||||||
{
|
{
|
||||||
return false;
|
throw new StorageOverflowException(_maxCount);
|
||||||
|
}
|
||||||
|
if (position < 0 || position >= _maxCount)
|
||||||
|
{
|
||||||
|
throw new IndexOutOfRangeException("Индекс вне границ коллекции");
|
||||||
|
}
|
||||||
|
if (equal != null && _places.Contains(airbus,equal))
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Данный объект уже есть в коллекции");
|
||||||
}
|
}
|
||||||
|
|
||||||
_places.Insert(position, airbus);
|
_places.Insert(position, airbus);
|
||||||
return true;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Удаление объекта из набора с конкретной позиции
|
// Удаление объекта из набора с конкретной позиции
|
||||||
@@ -51,34 +57,33 @@ namespace ProjectAirbus.Generics
|
|||||||
{
|
{
|
||||||
if (position < 0 || position >= Count)
|
if (position < 0 || position >= Count)
|
||||||
{
|
{
|
||||||
return false;
|
throw new AirbusNotFoundException(position);
|
||||||
}
|
}
|
||||||
_places.RemoveAt(position);
|
_places.RemoveAt(position);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Получение объекта из набора по позиции
|
// Получение объекта из набора по позиции
|
||||||
public T? this[int position]
|
public T? this[int position]
|
||||||
|
{
|
||||||
|
get
|
||||||
{
|
{
|
||||||
get
|
if (position < 0 || position >= Count)
|
||||||
{
|
{
|
||||||
if (position < 0 || position >= Count)
|
return null;
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return _places[position];
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (position < 0 || Count >= _maxCount)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_places.Insert(position, value);
|
|
||||||
}
|
}
|
||||||
|
return _places[position];
|
||||||
}
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (position < 0 || Count >= _maxCount)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_places.Insert(position, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Проход по списку
|
// Проход по списку
|
||||||
public IEnumerable<T?> GetAirbus(int? maxAirbus = null)
|
public IEnumerable<T?> GetAirbus(int? maxAirbus = null)
|
||||||
@@ -92,6 +97,5 @@ namespace ProjectAirbus.Generics
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Serilog;
|
||||||
|
|
||||||
namespace ProjectAirbus
|
namespace ProjectAirbus
|
||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
@@ -11,7 +16,30 @@ namespace ProjectAirbus
|
|||||||
// To customize application configuration such as set high DPI settings or default font,
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
// see https://aka.ms/applicationconfiguration.
|
// see https://aka.ms/applicationconfiguration.
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new FormAirbusCollection());
|
var services = new ServiceCollection();
|
||||||
|
ConfigureServices(services);
|
||||||
|
using (ServiceProvider serviceProvider = services.BuildServiceProvider())
|
||||||
|
{
|
||||||
|
Application.Run(serviceProvider.GetRequiredService<FormAirbusCollection>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ConfigureServices(ServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddSingleton<FormAirbusCollection>().AddLogging(option =>
|
||||||
|
{
|
||||||
|
string[] path = Directory.GetCurrentDirectory().Split('\\');
|
||||||
|
string pathNeed = "";
|
||||||
|
for (int i = 0; i < path.Length - 3; i++)
|
||||||
|
{
|
||||||
|
pathNeed += path[i] + "\\";
|
||||||
|
}
|
||||||
|
var configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile(path: $"{pathNeed}serilog.json", optional: false, reloadOnChange: true).Build();
|
||||||
|
var logger = new LoggerConfiguration().ReadFrom.Configuration(configuration).CreateLogger();
|
||||||
|
|
||||||
|
option.SetMinimumLevel(LogLevel.Information);
|
||||||
|
option.AddSerilog(logger);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -23,4 +23,24 @@
|
|||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||||
|
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.7" />
|
||||||
|
<PackageReference Include="Serilog" Version="3.1.1" />
|
||||||
|
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="serilog.json">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ProjectExtensions><VisualStudio><UserProperties /></VisualStudio></ProjectExtensions>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
20
Airbus/serilog.json
Normal file
20
Airbus/serilog.json
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"Serilog": {
|
||||||
|
"Using": [ "Serilog.Sinks.File" ],
|
||||||
|
"MinimumLevel": "Information",
|
||||||
|
"WriteTo": [
|
||||||
|
{
|
||||||
|
"Name": "File",
|
||||||
|
"Args": {
|
||||||
|
"path": "Logs/carlog.log",
|
||||||
|
"rollingInterval": "Day",
|
||||||
|
"outputTemplate": "[{Timestamp:HH:mm:ss.fff}]{Level:u4}: {Message:lj}{NewLine}{Exception}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
|
||||||
|
"Properties": {
|
||||||
|
"Application": "ProjectAirbus"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user