Lab8_DONE

This commit is contained in:
Itos 2024-10-03 00:46:41 +03:00
parent f4861308df
commit ff0f9a1a2a
18 changed files with 276 additions and 67 deletions

View File

@ -46,6 +46,8 @@
this.loadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.loadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog(); this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
this.openFileDialog = new System.Windows.Forms.OpenFileDialog(); this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
this.sort_type_button = new System.Windows.Forms.Button();
this.sort_color_button = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
this.menuStrip.SuspendLayout(); this.menuStrip.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
@ -53,7 +55,7 @@
// buttonAddTruck // buttonAddTruck
// //
this.buttonAddTruck.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.buttonAddTruck.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonAddTruck.Location = new System.Drawing.Point(642, 315); this.buttonAddTruck.Location = new System.Drawing.Point(660, 315);
this.buttonAddTruck.Name = "buttonAddTruck"; this.buttonAddTruck.Name = "buttonAddTruck";
this.buttonAddTruck.Size = new System.Drawing.Size(137, 28); this.buttonAddTruck.Size = new System.Drawing.Size(137, 28);
this.buttonAddTruck.TabIndex = 0; this.buttonAddTruck.TabIndex = 0;
@ -74,7 +76,7 @@
this.labelInstruments.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.labelInstruments.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.labelInstruments.AutoSize = true; this.labelInstruments.AutoSize = true;
this.labelInstruments.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); this.labelInstruments.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.labelInstruments.Location = new System.Drawing.Point(659, 9); this.labelInstruments.Location = new System.Drawing.Point(677, 9);
this.labelInstruments.Name = "labelInstruments"; this.labelInstruments.Name = "labelInstruments";
this.labelInstruments.Size = new System.Drawing.Size(108, 21); this.labelInstruments.Size = new System.Drawing.Size(108, 21);
this.labelInstruments.TabIndex = 2; this.labelInstruments.TabIndex = 2;
@ -83,7 +85,7 @@
// buttonUpdate // buttonUpdate
// //
this.buttonUpdate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.buttonUpdate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUpdate.Location = new System.Drawing.Point(648, 129); this.buttonUpdate.Location = new System.Drawing.Point(666, 129);
this.buttonUpdate.Name = "buttonUpdate"; this.buttonUpdate.Name = "buttonUpdate";
this.buttonUpdate.Size = new System.Drawing.Size(131, 25); this.buttonUpdate.Size = new System.Drawing.Size(131, 25);
this.buttonUpdate.TabIndex = 3; this.buttonUpdate.TabIndex = 3;
@ -94,7 +96,7 @@
// buttonDeleteTruck // buttonDeleteTruck
// //
this.buttonDeleteTruck.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.buttonDeleteTruck.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDeleteTruck.Location = new System.Drawing.Point(642, 403); this.buttonDeleteTruck.Location = new System.Drawing.Point(660, 403);
this.buttonDeleteTruck.Name = "buttonDeleteTruck"; this.buttonDeleteTruck.Name = "buttonDeleteTruck";
this.buttonDeleteTruck.Size = new System.Drawing.Size(137, 28); this.buttonDeleteTruck.Size = new System.Drawing.Size(137, 28);
this.buttonDeleteTruck.TabIndex = 4; this.buttonDeleteTruck.TabIndex = 4;
@ -105,7 +107,7 @@
// maskedTextBoxNumber // maskedTextBoxNumber
// //
this.maskedTextBoxNumber.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.maskedTextBoxNumber.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.maskedTextBoxNumber.Location = new System.Drawing.Point(642, 360); this.maskedTextBoxNumber.Location = new System.Drawing.Point(660, 360);
this.maskedTextBoxNumber.Mask = "00"; this.maskedTextBoxNumber.Mask = "00";
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber"; this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
this.maskedTextBoxNumber.Size = new System.Drawing.Size(138, 23); this.maskedTextBoxNumber.Size = new System.Drawing.Size(138, 23);
@ -116,7 +118,7 @@
// //
this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.label1.AutoSize = true; this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(648, 47); this.label1.Location = new System.Drawing.Point(666, 47);
this.label1.Name = "label1"; this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(52, 15); this.label1.Size = new System.Drawing.Size(52, 15);
this.label1.TabIndex = 7; this.label1.TabIndex = 7;
@ -129,7 +131,7 @@
this.listBoxStorages.Location = new System.Drawing.Point(648, 157); this.listBoxStorages.Location = new System.Drawing.Point(648, 157);
this.listBoxStorages.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.listBoxStorages.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.listBoxStorages.Name = "listBoxStorages"; this.listBoxStorages.Name = "listBoxStorages";
this.listBoxStorages.Size = new System.Drawing.Size(132, 109); this.listBoxStorages.Size = new System.Drawing.Size(132, 49);
this.listBoxStorages.TabIndex = 8; this.listBoxStorages.TabIndex = 8;
this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.listBoxObjects_SelectedIndexChanged); this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.listBoxObjects_SelectedIndexChanged);
// //
@ -169,7 +171,7 @@
this.toolStripMenuItem1}); this.toolStripMenuItem1});
this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Location = new System.Drawing.Point(0, 0);
this.menuStrip.Name = "menuStrip"; this.menuStrip.Name = "menuStrip";
this.menuStrip.Size = new System.Drawing.Size(797, 24); this.menuStrip.Size = new System.Drawing.Size(815, 24);
this.menuStrip.TabIndex = 12; this.menuStrip.TabIndex = 12;
this.menuStrip.Text = "menuStrip1"; this.menuStrip.Text = "menuStrip1";
// //
@ -185,14 +187,14 @@
// saveToolStripMenuItem // saveToolStripMenuItem
// //
this.saveToolStripMenuItem.Name = "saveToolStripMenuItem"; this.saveToolStripMenuItem.Name = "saveToolStripMenuItem";
this.saveToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.saveToolStripMenuItem.Size = new System.Drawing.Size(133, 22);
this.saveToolStripMenuItem.Text = "Сохранить"; this.saveToolStripMenuItem.Text = "Сохранить";
this.saveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click); this.saveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click);
// //
// loadToolStripMenuItem // loadToolStripMenuItem
// //
this.loadToolStripMenuItem.Name = "loadToolStripMenuItem"; this.loadToolStripMenuItem.Name = "loadToolStripMenuItem";
this.loadToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.loadToolStripMenuItem.Size = new System.Drawing.Size(133, 22);
this.loadToolStripMenuItem.Text = "Загрузить"; this.loadToolStripMenuItem.Text = "Загрузить";
this.loadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click); this.loadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click);
// //
@ -205,11 +207,33 @@
this.openFileDialog.FileName = "openFileDialog1"; this.openFileDialog.FileName = "openFileDialog1";
this.openFileDialog.Filter = "txt file | *.txt"; this.openFileDialog.Filter = "txt file | *.txt";
// //
// sort_type_button
//
this.sort_type_button.Location = new System.Drawing.Point(649, 213);
this.sort_type_button.Name = "sort_type_button";
this.sort_type_button.Size = new System.Drawing.Size(130, 23);
this.sort_type_button.TabIndex = 13;
this.sort_type_button.Text = "Сортировка по типу";
this.sort_type_button.UseVisualStyleBackColor = true;
this.sort_type_button.Click += new System.EventHandler(this.buttonSortByType_Click);
//
// sort_color_button
//
this.sort_color_button.Location = new System.Drawing.Point(649, 242);
this.sort_color_button.Name = "sort_color_button";
this.sort_color_button.Size = new System.Drawing.Size(131, 23);
this.sort_color_button.TabIndex = 14;
this.sort_color_button.Text = "Сортировка по цвету";
this.sort_color_button.UseVisualStyleBackColor = true;
this.sort_color_button.Click += new System.EventHandler(this.Sort_Color_button_Click);
//
// FormTruckCollection // FormTruckCollection
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(797, 465); this.ClientSize = new System.Drawing.Size(815, 465);
this.Controls.Add(this.sort_color_button);
this.Controls.Add(this.sort_type_button);
this.Controls.Add(this.textBoxStorageName); this.Controls.Add(this.textBoxStorageName);
this.Controls.Add(this.buttonDeleteStorage); this.Controls.Add(this.buttonDeleteStorage);
this.Controls.Add(this.buttonAddStorage); this.Controls.Add(this.buttonAddStorage);
@ -253,5 +277,7 @@
private ToolStripMenuItem loadToolStripMenuItem; private ToolStripMenuItem loadToolStripMenuItem;
private SaveFileDialog saveFileDialog; private SaveFileDialog saveFileDialog;
private OpenFileDialog openFileDialog; private OpenFileDialog openFileDialog;
private Button sort_type_button;
private Button sort_color_button;
} }
} }

View File

@ -15,6 +15,7 @@ using ProjectGasolineTanker.MovementStratg;
using ProjectGasolineTanker.Exceptions; using ProjectGasolineTanker.Exceptions;
using ProjectGasolineTanker; using ProjectGasolineTanker;
using System.Xml.Linq; using System.Xml.Linq;
using ProjectGasolineTanker.Generics;
namespace ProjectGasolineTanker namespace ProjectGasolineTanker
{ {
@ -32,6 +33,27 @@ namespace ProjectGasolineTanker
_logger = logger; _logger = logger;
} }
private void buttonSortByType_Click(object sender, EventArgs e) => CompareTruck(new TruckCompareByType());
private void Sort_Color_button_Click(object sender, EventArgs e) => CompareTruck(new TruckCompareByColor());
// Сортировка по сравнителю
private void CompareTruck(IComparer<DrawingTruck?> comparer)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
if (obj == null)
{
return;
}
obj.Sort(comparer);
pictureBoxCollection.Image = obj.ShowTruck();
}
// заполнение лист бокс // заполнение лист бокс
private void ReloadObjects() private void ReloadObjects()
{ {
@ -39,7 +61,7 @@ namespace ProjectGasolineTanker
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))
{ {
@ -127,6 +149,11 @@ namespace ProjectGasolineTanker
MessageBox.Show(ex.Message); MessageBox.Show(ex.Message);
_logger.LogWarning(ex.Message); _logger.LogWarning(ex.Message);
} }
catch (Exception ex)
{
MessageBox.Show(ex.Message);
_logger.LogWarning(ex.Message);
}
} }
@ -225,5 +252,6 @@ namespace ProjectGasolineTanker
ReloadObjects(); ReloadObjects();
} }
} }
} }

View 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 ProjectGasolineTanker.Drawings;
using ProjectGasolineTanker.Entities;
namespace ProjectGasolineTanker.Generics
{
internal class DrawingTruckEqutables : IEqualityComparer<DrawingTruck?>
{
public bool Equals(DrawingTruck? x, DrawingTruck? y)
{
if (x == null && x.EntityTruck == null)
throw new ArgumentNullException(nameof(x));
if (y == null && y.EntityTruck == null)
throw new ArgumentNullException(nameof(y));
if ((x.GetType().Name != y.GetType().Name))
return false;
if (x.EntityTruck.Speed != y.EntityTruck.Speed)
return false;
if (x.EntityTruck.Weight != y.EntityTruck.Weight)
return false;
if (x.EntityTruck.BodyColor != y.EntityTruck.BodyColor)
return false;
if (x is DrawingGasolineTanker && y is DrawingGasolineTanker)
{
var xGasTruck = (EntityGasolineTanker)x.EntityTruck;
var yGasTruck = (EntityGasolineTanker)y.EntityTruck;
if (xGasTruck.Add_Color != yGasTruck.Add_Color)
return false;
if (xGasTruck.IsTank != yGasTruck.IsTank)
return false;
if (xGasTruck.IsWheel != yGasTruck.IsWheel)
return false;
}
return true;
}
public int GetHashCode([DisallowNull] DrawingTruck? obj)
{
return obj.GetHashCode();
}
}
}

View File

@ -23,13 +23,15 @@ namespace ProjectGasolineTanker.Generic
} }
// Добавление объекта в начало // Добавление объекта в начало
public int Insert(T truck) public int Insert(T truck, IEqualityComparer<T?>? equal = null)
{ {
return Insert(truck, 0); return Insert(truck, 0, equal);
} }
public void SortSet(IComparer<T?> comparer) => _places.Sort(comparer);
// Добавление объекта в набор на конкретную позицию // Добавление объекта в набор на конкретную позицию
public int Insert(T truck, int position) public int Insert(T truck, int position, IEqualityComparer<T?>? equal = null)
{ {
if (Count >= _maxCount) if (Count >= _maxCount)
{ {
@ -39,6 +41,10 @@ namespace ProjectGasolineTanker.Generic
{ {
throw new IndexOutOfRangeException("Индекс вне границ коллекции"); throw new IndexOutOfRangeException("Индекс вне границ коллекции");
} }
if (equal != null && _places.Contains(truck, equal))
{
throw new ArgumentException("Данный объект уже есть в коллекции");
}
_places.Insert(position, truck); _places.Insert(position, truck);
return 0; return 0;
} }

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectGasolineTanker.Generics
{
internal class TruckCollectionInfo : IEquatable<TruckCollectionInfo>
{
public string Name { get; private set; }
public string Description { get; private set; }
public TruckCollectionInfo(string name, string description)
{
Name = name;
Description = description;
}
public bool Equals(TruckCollectionInfo? other)
{
if (ReferenceEquals(other, null))
return false;
return Name.Equals(other.Name);
}
public override int GetHashCode() => Name.GetHashCode();
}
}

View File

@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectGasolineTanker.Drawings;
using ProjectGasolineTanker.Entities;
namespace ProjectGasolineTanker.Generics
{
internal class TruckCompareByColor : IComparer<DrawingTruck>
{
public int Compare(DrawingTruck? x, DrawingTruck? y)
{
if (x == null || x.EntityTruck == null)
throw new ArgumentNullException(nameof(x));
if (y == null || y.EntityTruck == null)
throw new ArgumentNullException(nameof(y));
var xTruck = x.EntityTruck;
var yTruck = y.EntityTruck;
if (xTruck.BodyColor != yTruck.BodyColor)
return xTruck.BodyColor.Name.CompareTo(yTruck.BodyColor.Name);
var speedCompare = x.EntityTruck.Speed.CompareTo(y.EntityTruck.Speed);
if (speedCompare != 0)
return speedCompare;
return x.EntityTruck.Weight.CompareTo(y.EntityTruck.Weight);
}
}
}

View File

@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectGasolineTanker.Drawings;
namespace ProjectGasolineTanker.Generics
{
internal class TruckCompareByType : IComparer<DrawingTruck>
{
public int Compare(DrawingTruck? x, DrawingTruck? y)
{
if (x == null || x.EntityTruck == null)
throw new ArgumentNullException(nameof(x));
if (y == null || y.EntityTruck == null)
throw new ArgumentNullException(nameof(y));
if (x.GetType().Name != y.GetType().Name)
return x.GetType().Name.CompareTo(y.GetType().Name);
var speedCompare = x.EntityTruck.Speed.CompareTo(y.EntityTruck.Speed);
if (speedCompare != 0)
return speedCompare;
return x.EntityTruck.Weight.CompareTo(y.EntityTruck.Weight);
}
}
}

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using ProjectGasolineTanker.Drawings; using ProjectGasolineTanker.Drawings;
using ProjectGasolineTanker.Generics;
using ProjectGasolineTanker.MovementStratg; using ProjectGasolineTanker.MovementStratg;
namespace ProjectGasolineTanker.Generic namespace ProjectGasolineTanker.Generic
@ -29,13 +30,17 @@ namespace ProjectGasolineTanker.Generic
_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 +(TruckGenericCollection<T, U> collect, T? obj) public static int operator +(TruckGenericCollection<T, U> collect, T? obj)
{ {
if (obj != null) if (obj != null)
{ {
return collect._collection.Insert(obj); return collect._collection.Insert(obj, new DrawingTruckEqutables());
} }
return -1; return -1;
} }
public static bool operator -(TruckGenericCollection<T, U> collect, int pos) public static bool operator -(TruckGenericCollection<T, U> collect, int pos)
{ {
@ -46,14 +51,16 @@ namespace ProjectGasolineTanker.Generic
return collect?._collection.Remove(pos) ?? false; return collect?._collection.Remove(pos) ?? false;
} }
// получение объектов коллекции
public IEnumerable<T?> GetTruck => _collection.GetTruck(); public IEnumerable<T?> GetTruck => _collection.GetTruck();
// получение объекта IMoveableObjecr
public U? GetU(int pos) public U? GetU(int pos)
{ {
return (U?)_collection[pos]?.GetMoveableObject; return (U?)_collection[pos]?.GetMoveableObject;
} }
// вывод всего набора
public Bitmap ShowTruck() public Bitmap ShowTruck()
{ {
Bitmap bmp = new(_pictureWidth, _pictureHeight); Bitmap bmp = new(_pictureWidth, _pictureHeight);
@ -63,6 +70,7 @@ namespace ProjectGasolineTanker.Generic
return bmp; return bmp;
} }
// прорисовка фона
private void DrawBackground(Graphics gr) private void DrawBackground(Graphics gr)
{ {
Pen pen = new(Color.Black, 3); Pen pen = new(Color.Black, 3);
@ -77,7 +85,6 @@ namespace ProjectGasolineTanker.Generic
} }
} }
private void DrawObjects(Graphics g) private void DrawObjects(Graphics g)
{ {
// координаты // координаты
@ -88,15 +95,15 @@ namespace ProjectGasolineTanker.Generic
{ {
if (truck != null) if (truck != null)
{ {
// TODO получение объекта
if (x > _pictureWidth / _placeSizeWidth - 1) if (x > _pictureWidth / _placeSizeWidth - 1)
{ {
x = 0; x = 0;
--y; --y;
} }
// TODO установка позиции
truck.SetPosition(_placeSizeWidth * x, _placeSizeHeight * y); truck.SetPosition(_placeSizeWidth * x, _placeSizeHeight * y);
// TODO прорисовка объекта
truck.DrawTransport(g); truck.DrawTransport(g);
++x; ++x;
} }

View File

@ -3,7 +3,9 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Linq;
using ProjectGasolineTanker.Drawings; using ProjectGasolineTanker.Drawings;
using ProjectGasolineTanker.Generics;
using ProjectGasolineTanker.MovementStratg; using ProjectGasolineTanker.MovementStratg;
namespace ProjectGasolineTanker.Generic namespace ProjectGasolineTanker.Generic
@ -11,9 +13,9 @@ namespace ProjectGasolineTanker.Generic
internal class TruckGenericStorage internal class TruckGenericStorage
{ {
//Словарь (хранилище) //Словарь (хранилище)
readonly Dictionary<string, TruckGenericCollection<DrawingTruck, DrawingObjectTruck>> _TruckStorages; readonly Dictionary<TruckCollectionInfo, TruckGenericCollection<DrawingTruck, DrawingObjectTruck>> _TruckStorages;
//Возвращение списка названий наборов //Возвращение списка названий наборов
public List<string> Keys => _TruckStorages.Keys.ToList(); public List<TruckCollectionInfo> Keys => _TruckStorages.Keys.ToList();
//Ширина окна отрисовки //Ширина окна отрисовки
private readonly int _pictureWidth; private readonly int _pictureWidth;
//Высота окна отрисовки //Высота окна отрисовки
@ -28,34 +30,30 @@ namespace ProjectGasolineTanker.Generic
public TruckGenericStorage(int pictureWidth, int pictureHeight) public TruckGenericStorage(int pictureWidth, int pictureHeight)
{ {
_TruckStorages = new Dictionary<string, TruckGenericCollection<DrawingTruck, DrawingObjectTruck>>(); _TruckStorages = new Dictionary<TruckCollectionInfo, TruckGenericCollection<DrawingTruck, DrawingObjectTruck>>();
_pictureWidth = pictureWidth; _pictureWidth = pictureWidth;
_pictureHeight = pictureHeight; _pictureHeight = pictureHeight;
} }
// Добавление набора
public void AddSet(string name) public void AddSet(string name)
{ {
TruckCollectionInfo set = new TruckCollectionInfo(name, string.Empty);
foreach (string nameStorage in Keys) if (_TruckStorages.ContainsKey(set))
{
if (nameStorage == name)
{
MessageBox.Show("Набор с заданным именем уже занят", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} _TruckStorages.Add(set, new TruckGenericCollection<DrawingTruck, DrawingObjectTruck>(_pictureWidth, _pictureHeight));
}
_TruckStorages.Add(name, new TruckGenericCollection<DrawingTruck, DrawingObjectTruck>(_pictureWidth, _pictureHeight));
} }
// Удаление набора // Удаление набора
public void DelSet(string name) public void DelSet(string name)
{ {
TruckCollectionInfo set = new TruckCollectionInfo(name, string.Empty);
// TODO Прописать логику для удаления // TODO Прописать логику для удаления
if (_TruckStorages.ContainsKey(name)) if (!_TruckStorages.ContainsKey(set))
{ {
_TruckStorages.Remove(name); return;
} }
_TruckStorages.Remove(set);
} }
// Доступ к набору // Доступ к набору
@ -63,13 +61,14 @@ namespace ProjectGasolineTanker.Generic
{ {
get get
{ {
TruckCollectionInfo set = new TruckCollectionInfo(ind, string.Empty);
// TODO Продумать логику получения набора // TODO Продумать логику получения набора
if (_TruckStorages.ContainsKey(ind)) if (!_TruckStorages.ContainsKey(set))
{ {
return _TruckStorages[ind];
}
return null; return null;
} }
return _TruckStorages[set];
}
} }
public void SaveData(string filename) public void SaveData(string filename)
@ -79,7 +78,7 @@ namespace ProjectGasolineTanker.Generic
File.Delete(filename); File.Delete(filename);
} }
StringBuilder data = new(); StringBuilder data = new();
foreach (KeyValuePair<string, foreach (KeyValuePair<TruckCollectionInfo,
TruckGenericCollection<DrawingTruck, DrawingObjectTruck>> record in _TruckStorages) TruckGenericCollection<DrawingTruck, DrawingObjectTruck>> record in _TruckStorages)
{ {
StringBuilder records = new(); StringBuilder records = new();
@ -87,7 +86,7 @@ namespace ProjectGasolineTanker.Generic
{ {
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}"); records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
} }
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}"); data.AppendLine($"{record.Key.Name}{_separatorForKeyValue}{records}");
} }
if (data.Length == 0) if (data.Length == 0)
{ {
@ -95,14 +94,11 @@ namespace ProjectGasolineTanker.Generic
} }
using FileStream fs = new(filename, FileMode.Create); using FileStream fs = new(filename, FileMode.Create);
byte[] info = new byte[] info = new
UTF8Encoding(true).GetBytes($"TruckStorage{Environment.NewLine}{data}"); UTF8Encoding(true).GetBytes($"CarStorage{Environment.NewLine}{data}");
fs.Write(info, 0, info.Length); fs.Write(info, 0, info.Length);
return; return;
} }
public void LoadData(string filename) public void LoadData(string filename)
{ {
if (!File.Exists(filename)) if (!File.Exists(filename))
@ -145,19 +141,19 @@ namespace ProjectGasolineTanker.Generic
StringSplitOptions.RemoveEmptyEntries); StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set) foreach (string elem in set)
{ {
DrawingTruck? truck = DrawingTruck? Truck =
elem?.CreateDrawingTruck(_separatorForObject, _pictureWidth, _pictureHeight); elem?.CreateDrawingTruck(_separatorForObject, _pictureWidth, _pictureHeight);
if (truck != null) if (Truck != null)
{ {
if ((collection + truck) == -1) if ((collection + Truck)==-1)
{ {
throw new Exception("Ошибка добавления в коллекцию"); throw new Exception("Ошибка добавления в коллекцию");
} }
} }
} }
_TruckStorages.Add(record[0], collection); _TruckStorages.Add(new TruckCollectionInfo(record[0],
string.Empty), collection);
} }
} }
} }
} }

View File

@ -9,7 +9,9 @@ using ProjectGasolineTanker.Entities;
namespace ProjectGasolineTanker.MovementStratg namespace ProjectGasolineTanker.MovementStratg
{ {
/// <summary>
/// Реализация интерфейса
/// </summary>
public class DrawingObjectTruck : IMoveableObject public class DrawingObjectTruck : IMoveableObject
{ {
private readonly DrawingTruck? _drawingTruck = null; private readonly DrawingTruck? _drawingTruck = null;

View File

@ -6,9 +6,7 @@ using System.Threading.Tasks;
namespace ProjectGasolineTanker.MovementStratg namespace ProjectGasolineTanker.MovementStratg
{ {
/// <summary>
/// Стратегия перемещения объекта в центр экрана
/// </summary>
public class MoveToCenter : AbstractStrategy public class MoveToCenter : AbstractStrategy
{ {
protected override bool IsTargetDestinaion() protected override bool IsTargetDestinaion()

View File

@ -8,7 +8,6 @@
"Args": { "Args": {
"path": "Logs/trucklog.log", "path": "Logs/trucklog.log",
"rollingInterval": "Day", "rollingInterval": "Day",
"outputTemplate": null,
"outputTemplate": "[{Timestamp:HH:mm:ss.fff}]{Level:u4}: {Message:lj}{NewLine}{Exception}" "outputTemplate": "[{Timestamp:HH:mm:ss.fff}]{Level:u4}: {Message:lj}{NewLine}{Exception}"
} }
} }