From 77a1def62ef41795e27fab34281f5b8d905d13e4 Mon Sep 17 00:00:00 2001
From: sqdselo <147947144+sqdselo@users.noreply.github.com>
Date: Sun, 28 Apr 2024 11:50:50 +0400
Subject: [PATCH 01/17] =?UTF-8?q?=D0=9E=D1=81=D1=82=D0=B0=D0=BB=D0=BE?=
=?UTF-8?q?=D1=81=D1=8C=20=D0=B4=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0?=
=?UTF-8?q?=D1=82=D1=8C?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../AbstractCompany.cs | 2 +-
.../ICollectionGenericObjects.cs | 15 +-
.../ListGenericObjects.cs | 16 +-
.../MassivGenericObjects.cs | 18 +-
.../StorageCollection.cs | 142 +++++++++++-
.../Drawning/DrawningHoistingCrane.cs | 11 +-
.../Drawning/DrawningTrackedVehicle.cs | 10 +
.../Drawning/ExtentionDrawningCrane.cs | 55 +++++
.../Entities/EntityHoistingCrane.cs | 25 ++-
.../Entities/EntityTrackedVehicle.cs | 25 ++-
.../FormCarCollection.Designer.cs | 212 +++++++++++-------
.../HoistingCrane/FormCarCollection.cs | 41 ++++
.../HoistingCrane/FormCarCollection.resx | 12 +
13 files changed, 496 insertions(+), 88 deletions(-)
create mode 100644 HoistingCrane/HoistingCrane/Drawning/ExtentionDrawningCrane.cs
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs
index 3f787d3..98a10dc 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs
@@ -39,7 +39,7 @@ namespace HoistingCrane.CollectionGenericObjects
pictureWidth = picWidth;
pictureHeight = picHeight;
arr = array;
- arr.SetMaxCount = GetMaxCount;
+ arr.MaxCount = GetMaxCount;
}
public static int operator +(AbstractCompany company, DrawningTrackedVehicle car)
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs
index adc295a..04b8de7 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -8,10 +8,10 @@ namespace HoistingCrane.CollectionGenericObjects
/// Кол-во объектов в коллекции
///
int Count { get; }
- ///
- /// Максимальное количество элементов
+ /// ///
+ /// Установка максимального количества элементов
///
- int SetMaxCount { set; }
+ int MaxCount { get; set; }
///
/// Добавление элемента в коллекцию
///
@@ -37,5 +37,14 @@ namespace HoistingCrane.CollectionGenericObjects
///
///
T? Get(int position);
+ ///
+ /// Получение типа коллекции
+ ///
+ CollectionType GetCollectionType { get; }
+ ///
+ /// Получение объектов коллекции по одному
+ ///
+ ///
+ IEnumerable GetItems();
}
}
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs
index 48bb52d..acb044f 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs
@@ -25,8 +25,12 @@ namespace HoistingCrane.CollectionGenericObjects
get { return list.Count; }
}
- public int SetMaxCount
+ public int MaxCount
{
+ get
+ {
+ return list.Count;
+ }
set
{
if (value > 0)
@@ -36,6 +40,8 @@ namespace HoistingCrane.CollectionGenericObjects
}
}
+ public CollectionType GetCollectionType => CollectionType.List;
+
public T? Get(int position)
{
// TODO проверка позиции
@@ -80,5 +86,13 @@ namespace HoistingCrane.CollectionGenericObjects
}
return null;
}
+
+ public IEnumerable GetItems()
+ {
+ for(int i = 0; i < list.Count; i++)
+ {
+ yield return list[i];
+ }
+ }
}
}
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs
index 39d6839..afe3a36 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs
@@ -1,4 +1,5 @@
using System;
+
namespace HoistingCrane.CollectionGenericObjects
{
public class MassivGenericObjects : ICollectionGenericObjects where T : class
@@ -12,8 +13,12 @@ namespace HoistingCrane.CollectionGenericObjects
{
get { return arr.Length; }
}
- public int SetMaxCount
+ public int MaxCount
{
+ get
+ {
+ return arr.Length;
+ }
set
{
if (value > 0)
@@ -29,6 +34,9 @@ namespace HoistingCrane.CollectionGenericObjects
}
}
}
+
+ public CollectionType GetCollectionType => CollectionType.Massive;
+
public T? Get(int position)
{
if (position >= 0 && position < arr.Length)
@@ -38,6 +46,14 @@ namespace HoistingCrane.CollectionGenericObjects
return null;
}
+ public IEnumerable GetItems()
+ {
+ for(int i = 0; i < arr.Length; i++)
+ {
+ yield return arr[i];
+ }
+ }
+
public int Insert(T obj)
{
return Insert(obj, 0);
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs
index d1e5183..d696adb 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs
@@ -1,7 +1,10 @@
-using System;
+using HoistingCrane.Drawning;
+using System;
+using System.Text;
+
namespace HoistingCrane.CollectionGenericObjects
{
- public class StorageCollection where T : class
+ public class StorageCollection where T : DrawningTrackedVehicle
{
///
/// Словарь (хранилище) с коллекциями
@@ -12,6 +15,18 @@ namespace HoistingCrane.CollectionGenericObjects
///
public List Keys => dict.Keys.ToList();
///
+ /// Ключевое слово, с которого должен начинаться файл
+ ///
+ private readonly string _collectionKey = "CollectionsStorage";
+ ///
+ /// Разделитель для записи ключа и значения элемента словаря
+ ///
+ private readonly string _separatorForKeyValue = "|";
+ ///
+ /// Разделитель для записей коллекции данных в файл
+ ///
+ private readonly string _separatorItems = ";";
+ ///
/// Конструктор
///
public StorageCollection()
@@ -59,5 +74,128 @@ namespace HoistingCrane.CollectionGenericObjects
return dict[name];
}
}
+ ///
+ /// Сохранение информации по автомобилям в хранилище в файл
+ ///
+ /// Путь и имя файла
+ /// true - сохранение прошло успешно, false - ошибка при сохранении данных
+ public bool SaveData(string filename)
+ {
+ if (dict.Count == 0)
+ {
+ return false;
+ }
+
+ if (File.Exists(filename))
+ {
+ File.Delete(filename);
+ }
+
+ using (StreamWriter writer = new StreamWriter(filename))
+ {
+ writer.Write(_collectionKey);
+ foreach (KeyValuePair> value in dict)
+ {
+ StringBuilder sb = new();
+ sb.Append(Environment.NewLine);
+
+ // не сохраняем пустые коллекции
+ if (value.Value.Count == 0)
+ {
+ continue;
+ }
+
+ sb.Append(value.Key);
+ sb.Append(_separatorForKeyValue);
+ sb.Append(value.Value.GetCollectionType);
+ sb.Append(_separatorForKeyValue);
+ sb.Append(value.Value.MaxCount);
+ sb.Append(_separatorForKeyValue);
+ foreach (T? item in value.Value.GetItems())
+ {
+ string data = item?.GetDataForSave() ?? string.Empty;
+ if (string.IsNullOrEmpty(data))
+ {
+ continue;
+ }
+ sb.Append(data);
+ sb.Append(_separatorItems);
+ }
+ writer.Write(sb);
+ }
+
+ }
+ return true;
+
+ }
+
+ ///
+ // /// Загрузка информации по грузовикам в хранилище из файла
+ // ///
+ // /// Путь и имя файла
+ // /// true - загрузка прошла успешно, false - ошибка при загрузке данных
+ public bool LoadData(string filename)
+ {
+ if (!File.Exists(filename))
+ {
+ return false;
+ }
+ using (StreamReader fs = File.OpenText(filename))
+ {
+ string str = fs.ReadLine();
+ if (str == null || str.Length == 0)
+ {
+ return false;
+ }
+ if (!str.StartsWith(_collectionKey))
+ {
+ return false;
+ }
+ dict.Clear();
+ string strs = "";
+ while ((strs = fs.ReadLine()) != null)
+ {
+ string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
+ if (record.Length != 4)
+ {
+ continue;
+ }
+ CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
+ ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionType);
+ if (collection == null)
+ {
+ return false;
+ }
+ collection.MaxCount = Convert.ToInt32(record[2]);
+ string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
+ foreach (string elem in set)
+ {
+ if (elem?.CreateDrawningTrackedVehicle() is T truck)
+ {
+ if (collection.Insert(truck) == -1)
+ {
+ return false;
+ }
+ }
+ }
+ dict.Add(record[0], collection);
+ }
+ return true;
+ }
+ }
+ ///
+ /// Создание коллекции по типу
+ ///
+ ///
+ ///
+ private static ICollectionGenericObjects? CreateCollection(CollectionType collectionType)
+ {
+ return collectionType switch
+ {
+ CollectionType.Massive => new MassivGenericObjects(),
+ CollectionType.List => new ListGenericObjects(),
+ _ => null,
+ };
+ }
}
}
diff --git a/HoistingCrane/HoistingCrane/Drawning/DrawningHoistingCrane.cs b/HoistingCrane/HoistingCrane/Drawning/DrawningHoistingCrane.cs
index 2023b34..b52830c 100644
--- a/HoistingCrane/HoistingCrane/Drawning/DrawningHoistingCrane.cs
+++ b/HoistingCrane/HoistingCrane/Drawning/DrawningHoistingCrane.cs
@@ -1,5 +1,6 @@
using HoistingCrane.Entities;
using System.Configuration;
+using System.Reflection.PortableExecutable;
namespace HoistingCrane.Drawning;
@@ -39,6 +40,15 @@ public class DrawningHoistingCrane : DrawningTrackedVehicle
EntityTrackedVehicle = new EntityHoistingCrane(speed, weight, bodyColor, additionalColor, counterweight, platform);
}
+ ///
+ /// Конструктор для Extention
+ ///
+ ///
+ public DrawningHoistingCrane(EntityHoistingCrane entityHoistingCrane) : base(115, 63)
+ {
+ EntityTrackedVehicle = new EntityHoistingCrane(entityHoistingCrane.Speed, entityHoistingCrane.Weight, entityHoistingCrane.BodyColor, entityHoistingCrane.AdditionalColor, entityHoistingCrane.Counterweight, entityHoistingCrane.Platform);
+ }
+
///
/// Метод отрисовки объекта
///
@@ -49,7 +59,6 @@ public class DrawningHoistingCrane : DrawningTrackedVehicle
{
return;
}
-
base.DrawTransport(gr);
Brush b = new SolidBrush(EntityHoistingCrane.AdditionalColor);
Pen pen = new Pen(EntityHoistingCrane.AdditionalColor);
diff --git a/HoistingCrane/HoistingCrane/Drawning/DrawningTrackedVehicle.cs b/HoistingCrane/HoistingCrane/Drawning/DrawningTrackedVehicle.cs
index 29846b3..be19768 100644
--- a/HoistingCrane/HoistingCrane/Drawning/DrawningTrackedVehicle.cs
+++ b/HoistingCrane/HoistingCrane/Drawning/DrawningTrackedVehicle.cs
@@ -1,4 +1,5 @@
using HoistingCrane.Entities;
+using System.Reflection.PortableExecutable;
namespace HoistingCrane.Drawning
{
@@ -80,6 +81,15 @@ namespace HoistingCrane.Drawning
_startPosY = null;
}
+ ///
+ /// Конструктор для Extention
+ ///
+ ///
+ public DrawningTrackedVehicle(EntityTrackedVehicle entityTrackedVehicle) : this()
+ {
+ EntityTrackedVehicle = new EntityTrackedVehicle(entityTrackedVehicle.Speed, entityTrackedVehicle.Weight, entityTrackedVehicle.BodyColor);
+ }
+
///
/// Метод отрисовки игрового поля
diff --git a/HoistingCrane/HoistingCrane/Drawning/ExtentionDrawningCrane.cs b/HoistingCrane/HoistingCrane/Drawning/ExtentionDrawningCrane.cs
new file mode 100644
index 0000000..ada1b71
--- /dev/null
+++ b/HoistingCrane/HoistingCrane/Drawning/ExtentionDrawningCrane.cs
@@ -0,0 +1,55 @@
+using HoistingCrane.Entities;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace HoistingCrane.Drawning
+{
+ public static class ExtentionDrawningCrane
+ {
+ ///
+ /// Разделитель для записи информации по объекту в файл
+ ///
+ private static readonly string _separatorForObject = ":";
+
+ ///
+ /// Создание объекта из строки
+ ///
+ /// Строка с данными для создания объекта
+ /// Объект
+ public static DrawningTrackedVehicle? CreateDrawningTrackedVehicle(this string info)
+ {
+ string[] strs = info.Split(_separatorForObject);
+ EntityTrackedVehicle? trackedVehicle = EntityHoistingCrane.CreateEntityHoistingCrane(strs);
+ if (trackedVehicle != null)
+ {
+ return new DrawningHoistingCrane((EntityHoistingCrane)trackedVehicle);
+ }
+ trackedVehicle = EntityTrackedVehicle.CreateEntityTrackedVehicle(strs);
+ if (trackedVehicle != null)
+ {
+ return new DrawningTrackedVehicle(trackedVehicle);
+ }
+ return null;
+ }
+
+ ///
+ /// Получение данных для сохранения в файл
+ ///
+ /// Сохраняемый объект
+ /// Строка с данными по объекту
+ public static string GetDataForSave(this DrawningTrackedVehicle drawningTrackedVehicle)
+ {
+ string[]? array = drawningTrackedVehicle?.EntityTrackedVehicle?.GetStringRepresentation();
+
+ if (array == null)
+ {
+ return string.Empty;
+
+ }
+ return string.Join(_separatorForObject, array);
+ }
+ }
+}
diff --git a/HoistingCrane/HoistingCrane/Entities/EntityHoistingCrane.cs b/HoistingCrane/HoistingCrane/Entities/EntityHoistingCrane.cs
index 3c6c8f9..ea0f5de 100644
--- a/HoistingCrane/HoistingCrane/Entities/EntityHoistingCrane.cs
+++ b/HoistingCrane/HoistingCrane/Entities/EntityHoistingCrane.cs
@@ -30,7 +30,7 @@ public class EntityHoistingCrane : EntityTrackedVehicle
// .
- public EntityHoistingCrane(int Speed, int Weight, Color BodyColor, Color AdditionalColor, bool Counterweight, bool Platform) : base(Speed, Weight, BodyColor)
+ public EntityHoistingCrane(int Speed, double Weight, Color BodyColor, Color AdditionalColor, bool Counterweight, bool Platform) : base(Speed, Weight, BodyColor)
{
this.AdditionalColor = AdditionalColor;
this.Counterweight = Counterweight;
@@ -42,4 +42,27 @@ public class EntityHoistingCrane : EntityTrackedVehicle
{
AdditionalColor = newColor;
}
+
+ ///
+ /// -
+ ///
+ ///
+ public override string[] GetStringRepresentation()
+ {
+ return new[] { nameof(EntityHoistingCrane), Speed.ToString(), Weight.ToString(), BodyColor.Name, AdditionalColor.Name, Counterweight.ToString(), Platform.ToString()};
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static EntityHoistingCrane? CreateEntityHoistingCrane(string[] strs)
+ {
+ if (strs.Length != 7 || strs[0] != nameof(EntityHoistingCrane))
+ {
+ return null;
+ }
+ return new EntityHoistingCrane(Convert.ToInt32(strs[1]), Convert.ToInt32(strs[2]), Color.FromName(strs[3]), Color.FromName(strs[4]), Convert.ToBoolean(strs[5]), Convert.ToBoolean(strs[6]));
+ }
}
\ No newline at end of file
diff --git a/HoistingCrane/HoistingCrane/Entities/EntityTrackedVehicle.cs b/HoistingCrane/HoistingCrane/Entities/EntityTrackedVehicle.cs
index caef6bc..409e6e4 100644
--- a/HoistingCrane/HoistingCrane/Entities/EntityTrackedVehicle.cs
+++ b/HoistingCrane/HoistingCrane/Entities/EntityTrackedVehicle.cs
@@ -43,11 +43,34 @@
this.Weight = Weight;
this.BodyColor = BodyColor;
}
-
+
public void SetBodyColor(Color newBodyColor)
{
BodyColor = newBodyColor;
}
+ ///
+ /// Получуеин строк со значениями свойств объекта класса-сущности
+ ///
+ ///
+ public virtual string[] GetStringRepresentation()
+ {
+ return new[] { nameof(EntityTrackedVehicle), Speed.ToString(), Weight.ToString(), BodyColor.Name };
+ }
+
+ ///
+ /// Создание объекта из массива строк
+ ///
+ ///
+ ///
+ public static EntityTrackedVehicle? CreateEntityTrackedVehicle(string[] strs)
+ {
+ if(strs.Length != 4 || strs[0] != nameof(EntityTrackedVehicle))
+ {
+ return null;
+ }
+ return new EntityTrackedVehicle(Convert.ToInt32(strs[1]), Convert.ToDouble(strs[2]), Color.FromName(strs[3]));
+ }
+
}
}
diff --git a/HoistingCrane/HoistingCrane/FormCarCollection.Designer.cs b/HoistingCrane/HoistingCrane/FormCarCollection.Designer.cs
index 0977933..4991414 100644
--- a/HoistingCrane/HoistingCrane/FormCarCollection.Designer.cs
+++ b/HoistingCrane/HoistingCrane/FormCarCollection.Designer.cs
@@ -29,6 +29,12 @@
private void InitializeComponent()
{
groupBoxTools = new GroupBox();
+ panelCompanyTool = new Panel();
+ buttonCreateHoistingCrane = new Button();
+ maskedTextBox = new MaskedTextBox();
+ buttonRefresh = new Button();
+ buttonGoToChek = new Button();
+ buttonDeleteCar = new Button();
buttonCreateCompany = new Button();
panelStorage = new Panel();
buttonDeleteCollection = new Button();
@@ -38,18 +44,19 @@
radioButtonMassive = new RadioButton();
textBoxCollectionName = new TextBox();
labelCollectionName = new Label();
- buttonGoToChek = new Button();
- buttonRefresh = new Button();
- buttonDeleteCar = new Button();
- maskedTextBox = new MaskedTextBox();
comboBoxSelectorCompany = new ComboBox();
- buttonCreateHoistingCrane = new Button();
pictureBox = new PictureBox();
- panelCompanyTool = new Panel();
+ menuStrip = new MenuStrip();
+ файлToolStripMenuItem = new ToolStripMenuItem();
+ saveToolStripMenuItem = new ToolStripMenuItem();
+ loadToolStripMenuItem = new ToolStripMenuItem();
+ saveFileDialog = new SaveFileDialog();
+ openFileDialog = new OpenFileDialog();
groupBoxTools.SuspendLayout();
+ panelCompanyTool.SuspendLayout();
panelStorage.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
- panelCompanyTool.SuspendLayout();
+ menuStrip.SuspendLayout();
SuspendLayout();
//
// groupBoxTools
@@ -59,13 +66,79 @@
groupBoxTools.Controls.Add(panelStorage);
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right;
- groupBoxTools.Location = new Point(763, 0);
+ groupBoxTools.Location = new Point(763, 24);
groupBoxTools.Name = "groupBoxTools";
- groupBoxTools.Size = new Size(210, 509);
+ groupBoxTools.Size = new Size(210, 485);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
+ // panelCompanyTool
+ //
+ panelCompanyTool.Anchor = AnchorStyles.None;
+ panelCompanyTool.Controls.Add(buttonCreateHoistingCrane);
+ panelCompanyTool.Controls.Add(maskedTextBox);
+ panelCompanyTool.Controls.Add(buttonRefresh);
+ panelCompanyTool.Controls.Add(buttonGoToChek);
+ panelCompanyTool.Controls.Add(buttonDeleteCar);
+ panelCompanyTool.Location = new Point(6, 312);
+ panelCompanyTool.Name = "panelCompanyTool";
+ panelCompanyTool.Size = new Size(204, 185);
+ panelCompanyTool.TabIndex = 8;
+ //
+ // buttonCreateHoistingCrane
+ //
+ buttonCreateHoistingCrane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonCreateHoistingCrane.Location = new Point(9, 13);
+ buttonCreateHoistingCrane.Name = "buttonCreateHoistingCrane";
+ buttonCreateHoistingCrane.Size = new Size(192, 22);
+ buttonCreateHoistingCrane.TabIndex = 0;
+ buttonCreateHoistingCrane.Text = "Добавить транспорт";
+ buttonCreateHoistingCrane.UseVisualStyleBackColor = true;
+ buttonCreateHoistingCrane.Click += buttonCreateHoistingCrane_Click;
+ //
+ // maskedTextBox
+ //
+ maskedTextBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ maskedTextBox.Location = new Point(9, 41);
+ maskedTextBox.Mask = "00";
+ maskedTextBox.Name = "maskedTextBox";
+ maskedTextBox.Size = new Size(192, 23);
+ maskedTextBox.TabIndex = 3;
+ //
+ // buttonRefresh
+ //
+ buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonRefresh.Location = new Point(9, 129);
+ buttonRefresh.Name = "buttonRefresh";
+ buttonRefresh.Size = new Size(192, 27);
+ buttonRefresh.TabIndex = 5;
+ buttonRefresh.Text = "Обновить";
+ buttonRefresh.UseVisualStyleBackColor = true;
+ buttonRefresh.Click += buttonRefresh_Click;
+ //
+ // buttonGoToChek
+ //
+ buttonGoToChek.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonGoToChek.Location = new Point(9, 99);
+ buttonGoToChek.Name = "buttonGoToChek";
+ buttonGoToChek.Size = new Size(192, 24);
+ buttonGoToChek.TabIndex = 6;
+ buttonGoToChek.Text = "Передать на тесты";
+ buttonGoToChek.UseVisualStyleBackColor = true;
+ buttonGoToChek.Click += buttonGoToChek_Click;
+ //
+ // buttonDeleteCar
+ //
+ buttonDeleteCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonDeleteCar.Location = new Point(9, 70);
+ buttonDeleteCar.Name = "buttonDeleteCar";
+ buttonDeleteCar.Size = new Size(192, 23);
+ buttonDeleteCar.TabIndex = 4;
+ buttonDeleteCar.Text = "Удалить автомобиль";
+ buttonDeleteCar.UseVisualStyleBackColor = true;
+ buttonDeleteCar.Click += buttonDeleteCar_Click;
+ //
// buttonCreateCompany
//
buttonCreateCompany.Location = new Point(12, 295);
@@ -158,48 +231,6 @@
labelCollectionName.TabIndex = 0;
labelCollectionName.Text = "Название коллекции:";
//
- // buttonGoToChek
- //
- buttonGoToChek.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonGoToChek.Location = new Point(9, 99);
- buttonGoToChek.Name = "buttonGoToChek";
- buttonGoToChek.Size = new Size(192, 24);
- buttonGoToChek.TabIndex = 6;
- buttonGoToChek.Text = "Передать на тесты";
- buttonGoToChek.UseVisualStyleBackColor = true;
- buttonGoToChek.Click += buttonGoToChek_Click;
- //
- // buttonRefresh
- //
- buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonRefresh.Location = new Point(9, 129);
- buttonRefresh.Name = "buttonRefresh";
- buttonRefresh.Size = new Size(192, 27);
- buttonRefresh.TabIndex = 5;
- buttonRefresh.Text = "Обновить";
- buttonRefresh.UseVisualStyleBackColor = true;
- buttonRefresh.Click += buttonRefresh_Click;
- //
- // buttonDeleteCar
- //
- buttonDeleteCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonDeleteCar.Location = new Point(9, 70);
- buttonDeleteCar.Name = "buttonDeleteCar";
- buttonDeleteCar.Size = new Size(192, 23);
- buttonDeleteCar.TabIndex = 4;
- buttonDeleteCar.Text = "Удалить автомобиль";
- buttonDeleteCar.UseVisualStyleBackColor = true;
- buttonDeleteCar.Click += buttonDeleteCar_Click;
- //
- // maskedTextBox
- //
- maskedTextBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- maskedTextBox.Location = new Point(9, 41);
- maskedTextBox.Mask = "00";
- maskedTextBox.Name = "maskedTextBox";
- maskedTextBox.Size = new Size(192, 23);
- maskedTextBox.TabIndex = 3;
- //
// comboBoxSelectorCompany
//
comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
@@ -212,38 +243,54 @@
comboBoxSelectorCompany.TabIndex = 2;
comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged;
//
- // buttonCreateHoistingCrane
- //
- buttonCreateHoistingCrane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonCreateHoistingCrane.Location = new Point(9, 13);
- buttonCreateHoistingCrane.Name = "buttonCreateHoistingCrane";
- buttonCreateHoistingCrane.Size = new Size(192, 22);
- buttonCreateHoistingCrane.TabIndex = 0;
- buttonCreateHoistingCrane.Text = "Добавить транспорт";
- buttonCreateHoistingCrane.UseVisualStyleBackColor = true;
- buttonCreateHoistingCrane.Click += buttonCreateHoistingCrane_Click;
- //
// pictureBox
//
pictureBox.Dock = DockStyle.Fill;
- pictureBox.Location = new Point(0, 0);
+ pictureBox.Location = new Point(0, 24);
pictureBox.Name = "pictureBox";
- pictureBox.Size = new Size(763, 509);
+ pictureBox.Size = new Size(763, 485);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
- // panelCompanyTool
+ // menuStrip
//
- panelCompanyTool.Anchor = AnchorStyles.None;
- panelCompanyTool.Controls.Add(buttonCreateHoistingCrane);
- panelCompanyTool.Controls.Add(maskedTextBox);
- panelCompanyTool.Controls.Add(buttonRefresh);
- panelCompanyTool.Controls.Add(buttonGoToChek);
- panelCompanyTool.Controls.Add(buttonDeleteCar);
- panelCompanyTool.Location = new Point(6, 324);
- panelCompanyTool.Name = "panelCompanyTool";
- panelCompanyTool.Size = new Size(204, 185);
- panelCompanyTool.TabIndex = 8;
+ menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem });
+ menuStrip.Location = new Point(0, 0);
+ menuStrip.Name = "menuStrip";
+ menuStrip.Size = new Size(973, 24);
+ menuStrip.TabIndex = 2;
+ menuStrip.Text = "menuStrip1";
+ //
+ // файлToolStripMenuItem
+ //
+ файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { saveToolStripMenuItem, loadToolStripMenuItem });
+ файлToolStripMenuItem.Name = "файлToolStripMenuItem";
+ файлToolStripMenuItem.Size = new Size(50, 20);
+ файлToolStripMenuItem.Text = "Файл";
+ //
+ // saveToolStripMenuItem
+ //
+ saveToolStripMenuItem.Name = "saveToolStripMenuItem";
+ saveToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S;
+ saveToolStripMenuItem.Size = new Size(186, 22);
+ saveToolStripMenuItem.Text = "Сохранение";
+ saveToolStripMenuItem.Click += saveToolStripMenuItem_Click;
+ //
+ // loadToolStripMenuItem
+ //
+ loadToolStripMenuItem.Name = "loadToolStripMenuItem";
+ loadToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.L;
+ loadToolStripMenuItem.Size = new Size(186, 22);
+ loadToolStripMenuItem.Text = "Загрузка";
+ loadToolStripMenuItem.Click += loadToolStripMenuItem_Click;
+ //
+ // saveFileDialog
+ //
+ saveFileDialog.Filter = "txt file | *.txt";
+ //
+ // openFileDialog
+ //
+ openFileDialog.Filter = "txt file | *.txt";
//
// FormCarCollection
//
@@ -252,15 +299,20 @@
ClientSize = new Size(973, 509);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
+ Controls.Add(menuStrip);
+ MainMenuStrip = menuStrip;
Name = "FormCarCollection";
Text = "FormCarCollections";
groupBoxTools.ResumeLayout(false);
+ panelCompanyTool.ResumeLayout(false);
+ panelCompanyTool.PerformLayout();
panelStorage.ResumeLayout(false);
panelStorage.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
- panelCompanyTool.ResumeLayout(false);
- panelCompanyTool.PerformLayout();
+ menuStrip.ResumeLayout(false);
+ menuStrip.PerformLayout();
ResumeLayout(false);
+ PerformLayout();
}
#endregion
@@ -283,5 +335,11 @@
private ListBox listBoxCollection;
private Button buttonCollectionAdd;
private Panel panelCompanyTool;
+ private MenuStrip menuStrip;
+ private ToolStripMenuItem файлToolStripMenuItem;
+ private ToolStripMenuItem saveToolStripMenuItem;
+ private ToolStripMenuItem loadToolStripMenuItem;
+ private SaveFileDialog saveFileDialog;
+ private OpenFileDialog openFileDialog;
}
}
\ No newline at end of file
diff --git a/HoistingCrane/HoistingCrane/FormCarCollection.cs b/HoistingCrane/HoistingCrane/FormCarCollection.cs
index bd42830..978fbe7 100644
--- a/HoistingCrane/HoistingCrane/FormCarCollection.cs
+++ b/HoistingCrane/HoistingCrane/FormCarCollection.cs
@@ -204,6 +204,47 @@ namespace HoistingCrane
panelCompanyTool.Enabled = true;
RerfreshListBoxItems();
}
+
+ ///
+ /// Обработка нажатия "Сохранение"
+ ///
+ ///
+ ///
+ private void saveToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ if (saveFileDialog.ShowDialog() == DialogResult.OK)
+ {
+ if (_storageCollection.SaveData(saveFileDialog.FileName))
+ {
+ MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ }
+ else
+ {
+ MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+
+ ///
+ /// Обработка нажатия "Загразка"
+ ///
+ ///
+ ///
+ private void loadToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ if(openFileDialog.ShowDialog() == DialogResult.OK)
+ {
+ if (_storageCollection.LoadData(openFileDialog.FileName))
+ {
+ MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ RerfreshListBoxItems();
+ }
+ else
+ {
+ MessageBox.Show("Не сохранилось", "Результат",MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
}
}
diff --git a/HoistingCrane/HoistingCrane/FormCarCollection.resx b/HoistingCrane/HoistingCrane/FormCarCollection.resx
index af32865..0430c52 100644
--- a/HoistingCrane/HoistingCrane/FormCarCollection.resx
+++ b/HoistingCrane/HoistingCrane/FormCarCollection.resx
@@ -117,4 +117,16 @@
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ 17, 5
+
+
+ 130, 5
+
+
+ 270, 5
+
+
+ 25
+
\ No newline at end of file
--
2.25.1
From d83972988a3f0d9162e839322172e9f5bc91b96f Mon Sep 17 00:00:00 2001
From: sqdselo <147947144+sqdselo@users.noreply.github.com>
Date: Sun, 28 Apr 2024 13:04:05 +0400
Subject: [PATCH 02/17] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0?=
=?UTF-8?q?=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80?=
=?UTF-8?q?=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=206?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../CollectionGenericObjects/ListGenericObjects.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs
index acb044f..c92ca52 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs
@@ -7,7 +7,7 @@ namespace HoistingCrane.CollectionGenericObjects
{
///
/// Список объектов, которые храним
- ///
+ ///
readonly List list;
///
/// Конструктор
--
2.25.1
From 3cae6dc2f4344e8fb3fa467e7d7e879a063fc6c4 Mon Sep 17 00:00:00 2001
From: sqdselo <147947144+sqdselo@users.noreply.github.com>
Date: Sun, 28 Apr 2024 23:17:48 +0400
Subject: [PATCH 03/17] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0?=
=?UTF-8?q?=D1=82=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE?=
=?UTF-8?q?=D1=82=D0=B0=207=20(=D0=B2=D1=81=D0=B5=20=D0=BA=D1=80=D0=BE?=
=?UTF-8?q?=D0=BC=D0=B5=20=D0=BB=D0=BE=D0=B3=D0=B8=D1=80=D0=BE=D0=B2=D0=B0?=
=?UTF-8?q?=D0=BD=D0=B8=D1=8F)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../AbstractCompany.cs | 2 +-
.../CollectionGenericObjects/Garage.cs | 4 +-
.../ListGenericObjects.cs | 68 +++++++++-----
.../MassivGenericObjects.cs | 88 +++++++++++++------
.../StorageCollection.cs | 31 ++++---
.../Exceptions/CollectionOverflowException.cs | 19 ++++
.../Exceptions/ObjectNotFoundException.cs | 19 ++++
.../PositionOutOfCollectionException.cs | 19 ++++
.../HoistingCrane/FormCarCollection.cs | 49 ++++++++---
9 files changed, 222 insertions(+), 77 deletions(-)
create mode 100644 HoistingCrane/HoistingCrane/Exceptions/CollectionOverflowException.cs
create mode 100644 HoistingCrane/HoistingCrane/Exceptions/ObjectNotFoundException.cs
create mode 100644 HoistingCrane/HoistingCrane/Exceptions/PositionOutOfCollectionException.cs
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs
index 98a10dc..1c50f33 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs
@@ -31,7 +31,7 @@ namespace HoistingCrane.CollectionGenericObjects
{
get
{
- return (pictureWidth * pictureHeight) / (_placeSizeHeight * _placeSizeWidth)-3;
+ return (pictureWidth * pictureHeight) / (_placeSizeHeight * _placeSizeWidth)-2;
}
}
public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects array)
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/Garage.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/Garage.cs
index e2da629..0cf29d7 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/Garage.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/Garage.cs
@@ -38,8 +38,9 @@ namespace HoistingCrane.CollectionGenericObjects
{
arr?.Get(i)?.SetPictureSize(pictureWidth, pictureHeight);
arr?.Get(i)?.SetPosition(_placeSizeWidth * currentPosWidth + 25, _placeSizeHeight * currentPosHeight + 15);
+
}
-
+
if (currentPosWidth > 0)
currentPosWidth--;
else
@@ -51,7 +52,6 @@ namespace HoistingCrane.CollectionGenericObjects
{
break;
}
-
}
}
}
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs
index c92ca52..73f740c 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs
@@ -1,4 +1,5 @@
-using System;
+using HoistingCrane.Exceptions;
+using System;
using System.CodeDom.Compiler;
namespace HoistingCrane.CollectionGenericObjects
@@ -44,47 +45,72 @@ namespace HoistingCrane.CollectionGenericObjects
public T? Get(int position)
{
- // TODO проверка позиции
- if (position >= Count || position < 0) return null;
- return list[position];
+ try
+ {
+ if (position >= Count || position < 0)
+ {
+ throw new PositionOutOfCollectionException(position);
+ }
+ return list[position];
+ }
+ catch (PositionOutOfCollectionException ex)
+ {
+ MessageBox.Show(ex.Message);
+ return null;
+ }
}
-
-
+
public int Insert(T obj)
{
- // TODO проверка, что не превышено максимальное количество элементов
- // TODO вставка в конец набора
- if (Count == _maxCount)
+ try
{
+ if (Count == _maxCount) throw new CollectionOverflowException(Count);
+ list.Add(obj);
+ return Count;
+ }
+ catch(CollectionOverflowException ex)
+ {
+ MessageBox.Show(ex.Message);
return -1;
}
- list.Add(obj);
- return Count;
}
public int Insert(T obj, int position)
{
- // TODO проверка, что не превышено максимальное количество элементов
- // TODO проверка позиции
- // TODO вставка по позиции
- if (position < 0 || position >= Count || Count == _maxCount)
+ try
{
+ if (position < 0 || position >= _maxCount) throw new PositionOutOfCollectionException(position);
+ if (Count == _maxCount) throw new CollectionOverflowException(Count);
+ list.Insert(position, obj);
+ return position;
+ }
+ catch (CollectionOverflowException ex)
+ {
+ MessageBox.Show(ex.Message);
return -1;
}
- list.Insert(position, obj);
- return position;
+ catch (PositionOutOfCollectionException ex)
+ {
+ MessageBox.Show(ex.Message);
+ return -1;
+ }
+
}
+
public T? Remove(int position)
{
- // TODO проверка позиции
- // TODO удаление объекта из списка
- if (position >= 0 && position < list.Count)
+ try
{
+ if (position < 0 || position >= Count) throw new PositionOutOfCollectionException(position);
T? temp = list[position];
list.RemoveAt(position);
return temp;
}
- return null;
+ catch (PositionOutOfCollectionException ex)
+ {
+ MessageBox.Show(ex.Message);
+ return null;
+ }
}
public IEnumerable GetItems()
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs
index afe3a36..7680ae0 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs
@@ -1,4 +1,5 @@
-using System;
+using HoistingCrane.Exceptions;
+using System;
namespace HoistingCrane.CollectionGenericObjects
{
@@ -39,11 +40,22 @@ namespace HoistingCrane.CollectionGenericObjects
public T? Get(int position)
{
- if (position >= 0 && position < arr.Length)
+ try
{
+ if (position < 0 || position >= Count) throw new PositionOutOfCollectionException(position);
+ //if (arr[position] == null) throw new ObjectNotFoundException(position);
return arr[position];
}
- return null;
+ catch (PositionOutOfCollectionException ex)
+ {
+ MessageBox.Show(ex.Message);
+ return null;
+ }
+ //catch (ObjectNotFoundException ex)
+ //{
+ // MessageBox.Show(ex.Message);
+ // return null;
+ //}
}
public IEnumerable GetItems()
@@ -56,45 +68,69 @@ namespace HoistingCrane.CollectionGenericObjects
public int Insert(T obj)
{
- return Insert(obj, 0);
+ try
+ {
+ if (arr.Count(x => x != null) == MaxCount) throw new CollectionOverflowException(Count);
+ return Insert(obj, 0);
+ }
+ catch(CollectionOverflowException ex)
+ {
+ MessageBox.Show(ex.Message);
+ return -1;
+ }
}
public int Insert(T obj, int position)
{
- //todo Проверка позиции
- if (position < 0 || position > Count)
+ try
{
+ if (position < 0 || position > Count) throw new PositionOutOfCollectionException(position);
+
+ if (arr[position] == null)
+ {
+ arr[position] = obj;
+ return position;
+ }
+ else
+ {
+ if (Insert(obj, position + 1) != -1)
+ {
+ return position;
+ }
+ if (Insert(obj, position - 1) != -1)
+ {
+ return position;
+ }
+ return -1;
+ }
+ }
+ catch (PositionOutOfCollectionException ex)
+ {
+ MessageBox.Show(ex.Message);
return -1;
}
-
- if (arr[position] == null)
- {
- arr[position] = obj;
- return position;
- }
- else
- {
- if (Insert(obj, position + 1) != -1)
- {
- return position;
- }
- if (Insert(obj, position - 1) != -1)
- {
- return position;
- }
- }
- return -1;
}
public T? Remove(int position)
{
- if (position >= 0 && position < Count)
+ try
{
+ if (position < 0 || position >= MaxCount) throw new PositionOutOfCollectionException(position);
+ if (arr[position] == null) throw new ObjectNotFoundException(position);
T? temp = arr[position];
arr[position] = null;
return temp;
}
- return null;
+ catch (ObjectNotFoundException ex)
+ {
+ MessageBox.Show(ex.Message);
+ return null;
+ }
+ catch (PositionOutOfCollectionException ex)
+ {
+ MessageBox.Show(ex.Message);
+ return null;
+ }
}
}
}
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs
index d696adb..cb6a3f0 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs
@@ -1,4 +1,5 @@
using HoistingCrane.Drawning;
+using HoistingCrane.Exceptions;
using System;
using System.Text;
@@ -79,11 +80,11 @@ namespace HoistingCrane.CollectionGenericObjects
///
/// Путь и имя файла
/// true - сохранение прошло успешно, false - ошибка при сохранении данных
- public bool SaveData(string filename)
+ public void SaveData(string filename)
{
if (dict.Count == 0)
{
- return false;
+ throw new Exception("В хранилище отсутствуют коллекции для сохранения");
}
if (File.Exists(filename))
@@ -125,8 +126,6 @@ namespace HoistingCrane.CollectionGenericObjects
}
}
- return true;
-
}
///
@@ -134,22 +133,22 @@ namespace HoistingCrane.CollectionGenericObjects
// ///
// /// Путь и имя файла
// /// true - загрузка прошла успешно, false - ошибка при загрузке данных
- public bool LoadData(string filename)
+ public void LoadData(string filename)
{
if (!File.Exists(filename))
{
- return false;
+ throw new Exception("Файл не существует");
}
using (StreamReader fs = File.OpenText(filename))
{
string str = fs.ReadLine();
if (str == null || str.Length == 0)
{
- return false;
+ throw new Exception("В файле не присутствуют данные");
}
if (!str.StartsWith(_collectionKey))
{
- return false;
+ throw new Exception("В файле неверные данные");
}
dict.Clear();
string strs = "";
@@ -164,23 +163,29 @@ namespace HoistingCrane.CollectionGenericObjects
ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionType);
if (collection == null)
{
- return false;
+ throw new Exception("Не удалось создать коллекцию");
}
collection.MaxCount = Convert.ToInt32(record[2]);
string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set)
{
- if (elem?.CreateDrawningTrackedVehicle() is T truck)
+ if (elem?.CreateDrawningTrackedVehicle() is T crane)
{
- if (collection.Insert(truck) == -1)
+ try
{
- return false;
+ if (collection.Insert(crane) == -1)
+ {
+ throw new Exception("Объект не удалось добавить в коллекцию: " + record[3]);
+ }
+ }
+ catch(CollectionOverflowException ex)
+ {
+ throw new Exception("Коллекция переполнена");
}
}
}
dict.Add(record[0], collection);
}
- return true;
}
}
///
diff --git a/HoistingCrane/HoistingCrane/Exceptions/CollectionOverflowException.cs b/HoistingCrane/HoistingCrane/Exceptions/CollectionOverflowException.cs
new file mode 100644
index 0000000..da3c19f
--- /dev/null
+++ b/HoistingCrane/HoistingCrane/Exceptions/CollectionOverflowException.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace HoistingCrane.Exceptions
+{
+ [Serializable]
+ public class CollectionOverflowException : ApplicationException
+ {
+ public CollectionOverflowException(int count) : base("В коллекции превышено допустимое количество: count" + count) { }
+ public CollectionOverflowException() : base(){ }
+ public CollectionOverflowException(string message) : base(message) { }
+ public CollectionOverflowException(string message, Exception exception) : base(message, exception) { }
+ protected CollectionOverflowException(SerializationInfo info, StreamingContext context) : base(info, context) { }
+ }
+}
diff --git a/HoistingCrane/HoistingCrane/Exceptions/ObjectNotFoundException.cs b/HoistingCrane/HoistingCrane/Exceptions/ObjectNotFoundException.cs
new file mode 100644
index 0000000..c833095
--- /dev/null
+++ b/HoistingCrane/HoistingCrane/Exceptions/ObjectNotFoundException.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace HoistingCrane.Exceptions
+{
+ [Serializable]
+ public class ObjectNotFoundException : ApplicationException
+ {
+ public ObjectNotFoundException(int i) :base("Не найден объект по позиции " + i){ }
+ public ObjectNotFoundException() : base() { }
+ public ObjectNotFoundException(string message) : base(message) { }
+ public ObjectNotFoundException(string message, Exception exception) : base(message, exception) { }
+ protected ObjectNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context) { }
+ }
+}
diff --git a/HoistingCrane/HoistingCrane/Exceptions/PositionOutOfCollectionException.cs b/HoistingCrane/HoistingCrane/Exceptions/PositionOutOfCollectionException.cs
new file mode 100644
index 0000000..e35263d
--- /dev/null
+++ b/HoistingCrane/HoistingCrane/Exceptions/PositionOutOfCollectionException.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace HoistingCrane.Exceptions
+{
+ [Serializable]
+ public class PositionOutOfCollectionException : ApplicationException
+ {
+ public PositionOutOfCollectionException(int i) : base("Выход за границы коллекции. Позиция " + i) { }
+ public PositionOutOfCollectionException() : base(){ }
+ public PositionOutOfCollectionException(string message) : base(message) { }
+ public PositionOutOfCollectionException(string message, Exception exception) : base(message, exception) { }
+ protected PositionOutOfCollectionException(SerializationInfo info, StreamingContext context) : base(info, context){ }
+ }
+}
diff --git a/HoistingCrane/HoistingCrane/FormCarCollection.cs b/HoistingCrane/HoistingCrane/FormCarCollection.cs
index 978fbe7..7fb63e8 100644
--- a/HoistingCrane/HoistingCrane/FormCarCollection.cs
+++ b/HoistingCrane/HoistingCrane/FormCarCollection.cs
@@ -49,10 +49,10 @@ namespace HoistingCrane
MessageBox.Show("Объект добавлен");
pictureBox.Image = _company.Show();
}
- else
- {
- MessageBox.Show("Не удалось добавить объект");
- }
+ //else
+ //{
+ // MessageBox.Show("Не удалось добавить объект");
+ //}
}
private static Color GetColor(Random random)
{
@@ -82,10 +82,10 @@ namespace HoistingCrane
MessageBox.Show("Объект добавлен");
pictureBox.Image = _company.Show();
}
- else
- {
- MessageBox.Show("Не удалось добавить объект");
- }
+ //else
+ //{
+ // MessageBox.Show("Не удалось добавить объект");
+ //}
}
private void buttonDeleteCar_Click(object sender, EventArgs e)
@@ -105,10 +105,10 @@ namespace HoistingCrane
MessageBox.Show("Объект удален!");
pictureBox.Image = _company.Show();
}
- else
- {
- MessageBox.Show("Не удалось удалить объект");
- }
+ //else
+ //{
+ // MessageBox.Show("Не удалось удалить объект");
+ //}
}
private void buttonRefresh_Click(object sender, EventArgs e)
{
@@ -214,7 +214,17 @@ namespace HoistingCrane
{
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
- if (_storageCollection.SaveData(saveFileDialog.FileName))
+ bool saveSuccessful = false;
+ try
+ {
+ _storageCollection.SaveData(saveFileDialog.FileName);
+ saveSuccessful = true;
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show("Ошибка при сохранении данных: " + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ if (saveSuccessful)
{
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
@@ -234,7 +244,18 @@ namespace HoistingCrane
{
if(openFileDialog.ShowDialog() == DialogResult.OK)
{
- if (_storageCollection.LoadData(openFileDialog.FileName))
+ bool loadSuccessful = false;
+ try
+ {
+ _storageCollection.LoadData(openFileDialog.FileName);
+ loadSuccessful = true;
+ }
+
+ catch(Exception ex)
+ {
+ MessageBox.Show("Ошибка при загрузке данных: " + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ if(loadSuccessful)
{
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
RerfreshListBoxItems();
--
2.25.1
From 4fc0549d2efe03c4dd886ea8d169fea677c9efd4 Mon Sep 17 00:00:00 2001
From: sqdselo <147947144+sqdselo@users.noreply.github.com>
Date: Mon, 29 Apr 2024 00:51:57 +0400
Subject: [PATCH 04/17] =?UTF-8?q?=D0=B4=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0?=
=?UTF-8?q?=D1=8E?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../HoistingCrane/FormCarCollection.cs | 112 +++++++++---------
HoistingCrane/HoistingCrane/FormCarConfig.cs | 1 +
.../HoistingCrane/HoistingCrane.csproj | 11 ++
HoistingCrane/HoistingCrane/Program.cs | 23 +++-
HoistingCrane/HoistingCrane/nlog.config | 13 ++
5 files changed, 100 insertions(+), 60 deletions(-)
create mode 100644 HoistingCrane/HoistingCrane/nlog.config
diff --git a/HoistingCrane/HoistingCrane/FormCarCollection.cs b/HoistingCrane/HoistingCrane/FormCarCollection.cs
index 7fb63e8..acd8ebf 100644
--- a/HoistingCrane/HoistingCrane/FormCarCollection.cs
+++ b/HoistingCrane/HoistingCrane/FormCarCollection.cs
@@ -1,5 +1,7 @@
using HoistingCrane.CollectionGenericObjects;
using HoistingCrane.Drawning;
+using HoistingCrane.Entities;
+using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@@ -17,11 +19,16 @@ namespace HoistingCrane
private AbstractCompany? _company;
private readonly StorageCollection _storageCollection;
- public FormCarCollection()
+ ///
+ /// Логгер
+ ///
+ private readonly ILogger logger;
+ public FormCarCollection(ILogger logger)
{
InitializeComponent();
_storageCollection = new();
panelCompanyTool.Enabled = false;
+ this.logger = logger;
}
private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{
@@ -49,10 +56,6 @@ namespace HoistingCrane
MessageBox.Show("Объект добавлен");
pictureBox.Image = _company.Show();
}
- //else
- //{
- // MessageBox.Show("Не удалось добавить объект");
- //}
}
private static Color GetColor(Random random)
{
@@ -72,43 +75,47 @@ namespace HoistingCrane
}
private void SetCar(DrawningTrackedVehicle drawningTrackedVehicle)
{
- if (_company == null || drawningTrackedVehicle == null)
+
+ try
{
+ if (_company + drawningTrackedVehicle != -1)
+ {
+ MessageBox.Show("Объект добавлен");
+ pictureBox.Image = _company.Show();
+ logger.LogInformation("Добавлен объект DrawningTrackedVehicle");
+ }
+ else
+ {
+ throw new Exception();
+ }
+ }
+ catch (Exception ex)
+ {
+ logger.LogError("Не удалось добавить объект");
return;
}
-
- if (_company + drawningTrackedVehicle != -1)
- {
- MessageBox.Show("Объект добавлен");
- pictureBox.Image = _company.Show();
- }
- //else
- //{
- // MessageBox.Show("Не удалось добавить объект");
- //}
+
}
private void buttonDeleteCar_Click(object sender, EventArgs e)
{
-
- if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
+ try
{
+ if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) throw new Exception();
+ if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null) throw new Exception();
+ int pos = Convert.ToInt32(maskedTextBox.Text);
+ if ((_company - pos) != null)
+ {
+ MessageBox.Show("Объект удален!");
+ pictureBox.Image = _company.Show();
+ logger.LogInformation("удален объект по позиции: {pos}", pos);
+ }
+ }
+ catch(Exception ex)
+ {
+ logger.LogError("Не удалось удалить объект по позиции: {pos}", Convert.ToInt32(maskedTextBox.Text));
return;
}
- if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
- {
- return;
- }
- int pos = Convert.ToInt32(maskedTextBox.Text);
- if ((_company - pos) != null)
- {
- MessageBox.Show("Объект удален!");
- pictureBox.Image = _company.Show();
- }
- //else
- //{
- // MessageBox.Show("Не удалось удалить объект");
- //}
}
private void buttonRefresh_Click(object sender, EventArgs e)
{
@@ -148,6 +155,7 @@ namespace HoistingCrane
listBoxCollection.Items.Add(colName);
}
}
+ logger.LogInformation("Коллекция успешно обновлена");
}
private void buttonCollectionAdd_Click(object sender, EventArgs e)
{
@@ -184,17 +192,18 @@ namespace HoistingCrane
}
private void buttonCreateCompany_Click(object sender, EventArgs e)
{
- if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
+
+ if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
{
MessageBox.Show("Коллекция не выбрана");
return;
}
ICollectionGenericObjects? collection = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
- if (collection == null)
+ if (collection == null)
{
MessageBox.Show("Коллекция не проинициализирована");
return;
- }
+ };
switch (comboBoxSelectorCompany.Text)
{
case "Хранилище":
@@ -203,6 +212,8 @@ namespace HoistingCrane
}
panelCompanyTool.Enabled = true;
RerfreshListBoxItems();
+
+
}
///
@@ -214,23 +225,16 @@ namespace HoistingCrane
{
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
- bool saveSuccessful = false;
try
{
_storageCollection.SaveData(saveFileDialog.FileName);
- saveSuccessful = true;
+ MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ logger.LogInformation("Сохранение в файл: {filename}", saveFileDialog.FileName);
}
catch (Exception ex)
{
- MessageBox.Show("Ошибка при сохранении данных: " + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- if (saveSuccessful)
- {
- MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- else
- {
- MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ logger.LogError("Ошибка: {Message}", ex.Message);
}
}
}
@@ -244,25 +248,17 @@ namespace HoistingCrane
{
if(openFileDialog.ShowDialog() == DialogResult.OK)
{
- bool loadSuccessful = false;
try
{
_storageCollection.LoadData(openFileDialog.FileName);
- loadSuccessful = true;
- }
-
- catch(Exception ex)
- {
- MessageBox.Show("Ошибка при загрузке данных: " + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- if(loadSuccessful)
- {
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
RerfreshListBoxItems();
+ logger.LogInformation("Загрузка в файл: {filename}", saveFileDialog.FileName);
}
- else
+ catch(Exception ex)
{
- MessageBox.Show("Не сохранилось", "Результат",MessageBoxButtons.OK, MessageBoxIcon.Error);
+ MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ logger.LogError("Ошибка: {Message}", ex.Message);
}
}
}
diff --git a/HoistingCrane/HoistingCrane/FormCarConfig.cs b/HoistingCrane/HoistingCrane/FormCarConfig.cs
index 1908fc4..96a2990 100644
--- a/HoistingCrane/HoistingCrane/FormCarConfig.cs
+++ b/HoistingCrane/HoistingCrane/FormCarConfig.cs
@@ -31,6 +31,7 @@ namespace HoistingCrane
panelColorPurple.MouseDown += panel_MouseDown;
buttonCancel.Click += (sender, e) => Close();
}
+
///
/// Привязка метода к событию
///
diff --git a/HoistingCrane/HoistingCrane/HoistingCrane.csproj b/HoistingCrane/HoistingCrane/HoistingCrane.csproj
index 69ac652..5f40a60 100644
--- a/HoistingCrane/HoistingCrane/HoistingCrane.csproj
+++ b/HoistingCrane/HoistingCrane/HoistingCrane.csproj
@@ -12,6 +12,11 @@
+
+
+
+
+
True
@@ -27,4 +32,10 @@
+
+
+ Always
+
+
+
\ No newline at end of file
diff --git a/HoistingCrane/HoistingCrane/Program.cs b/HoistingCrane/HoistingCrane/Program.cs
index 79d96ff..c5abf19 100644
--- a/HoistingCrane/HoistingCrane/Program.cs
+++ b/HoistingCrane/HoistingCrane/Program.cs
@@ -1,3 +1,7 @@
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
+using NLog.Extensions.Logging;
+
namespace HoistingCrane
{
internal static class Program
@@ -11,8 +15,23 @@ namespace HoistingCrane
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new FormCarCollection());
-
+ ServiceCollection services = new();
+ ConfigureServices(services);
+ using ServiceProvider serviceProvider = services.BuildServiceProvider();
+ Application.Run(serviceProvider.GetRequiredService());
+
+ }
+ ///
+ /// DI
+ ///
+ ///
+ private static void ConfigureServices(ServiceCollection services)
+ {
+ services.AddSingleton().AddLogging(option =>
+ {
+ option.SetMinimumLevel(LogLevel.Information);
+ option.AddNLog("nlog.config");
+ });
}
}
}
\ No newline at end of file
diff --git a/HoistingCrane/HoistingCrane/nlog.config b/HoistingCrane/HoistingCrane/nlog.config
new file mode 100644
index 0000000..3a13aee
--- /dev/null
+++ b/HoistingCrane/HoistingCrane/nlog.config
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
--
2.25.1
From d7cbb7356716c512c78730fd3e2e6e1ce6ed7915 Mon Sep 17 00:00:00 2001
From: sqdselo <147947144+sqdselo@users.noreply.github.com>
Date: Mon, 29 Apr 2024 01:40:45 +0400
Subject: [PATCH 05/17] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0?=
=?UTF-8?q?=D1=82=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE?=
=?UTF-8?q?=D1=82=D0=B0=207?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../HoistingCrane/FormCarCollection.cs | 26 ++++++++++---------
1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/HoistingCrane/HoistingCrane/FormCarCollection.cs b/HoistingCrane/HoistingCrane/FormCarCollection.cs
index acd8ebf..cc3db0d 100644
--- a/HoistingCrane/HoistingCrane/FormCarCollection.cs
+++ b/HoistingCrane/HoistingCrane/FormCarCollection.cs
@@ -75,23 +75,23 @@ namespace HoistingCrane
}
private void SetCar(DrawningTrackedVehicle drawningTrackedVehicle)
{
-
+ if (_company == null || drawningTrackedVehicle == null) return;
try
{
if (_company + drawningTrackedVehicle != -1)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _company.Show();
- logger.LogInformation("Добавлен объект DrawningTrackedVehicle");
+ logger.LogInformation("Добавлен объект {nameObject}", drawningTrackedVehicle.GetType().Name);
}
else
{
- throw new Exception();
+ throw new Exception("Не удалось добавить объект. Заполнено максимальное количество ячеек");
}
}
catch (Exception ex)
{
- logger.LogError("Не удалось добавить объект");
+ logger.LogInformation(ex.Message);
return;
}
@@ -99,21 +99,22 @@ namespace HoistingCrane
private void buttonDeleteCar_Click(object sender, EventArgs e)
{
+ if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return;
+ if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null) return;
try
{
- if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) throw new Exception();
- if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null) throw new Exception();
int pos = Convert.ToInt32(maskedTextBox.Text);
if ((_company - pos) != null)
{
MessageBox.Show("Объект удален!");
pictureBox.Image = _company.Show();
- logger.LogInformation("удален объект по позиции: {pos}", pos);
+ logger.LogInformation("Удален объект по позиции: {pos} ", pos);
}
+ else throw new Exception();
}
catch(Exception ex)
{
- logger.LogError("Не удалось удалить объект по позиции: {pos}", Convert.ToInt32(maskedTextBox.Text));
+ logger.LogInformation("Не удалось удалить объект по позиции: {pos}", Convert.ToInt32(maskedTextBox.Text));
return;
}
}
@@ -169,14 +170,14 @@ namespace HoistingCrane
if (radioButtonMassive.Checked)
{
collectionType = CollectionType.Massive;
+ logger.LogInformation("Создана коллекция типа: {name}", collectionType);
}
else if (radioButtonList.Checked)
{
collectionType = CollectionType.List;
+ logger.LogInformation("Создана коллекция типа: {name}", collectionType);
}
- _storageCollection.AddCollection(textBoxCollectionName.Text,
- collectionType);
- RerfreshListBoxItems();
+ _storageCollection.AddCollection(textBoxCollectionName.Text,collectionType);RerfreshListBoxItems();
}
private void buttonDeleteCollection_Click(object sender, EventArgs e)
{
@@ -189,6 +190,7 @@ namespace HoistingCrane
return;
_storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
RerfreshListBoxItems();
+ logger.LogInformation("Коллекция успешно удалена");
}
private void buttonCreateCompany_Click(object sender, EventArgs e)
{
@@ -212,7 +214,7 @@ namespace HoistingCrane
}
panelCompanyTool.Enabled = true;
RerfreshListBoxItems();
-
+ logger.LogInformation("Создана компания");
}
--
2.25.1
From 5ae896d09f1986968baeeb9ed94570f1d0b2ab27 Mon Sep 17 00:00:00 2001
From: sqdselo
Date: Mon, 29 Apr 2024 11:30:11 +0400
Subject: [PATCH 06/17] =?UTF-8?q?=D0=B2=20=D0=BF=D1=80=D0=BE=D1=86=D0=B5?=
=?UTF-8?q?=D1=81=D1=81=D0=B5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
HoistingCrane/HoistingCrane/nlog.config | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/HoistingCrane/HoistingCrane/nlog.config b/HoistingCrane/HoistingCrane/nlog.config
index 3a13aee..0c93951 100644
--- a/HoistingCrane/HoistingCrane/nlog.config
+++ b/HoistingCrane/HoistingCrane/nlog.config
@@ -4,7 +4,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true" internalLogLevel="Info">
-
+
--
2.25.1
From f520564545663b4c5e7bc984b0793948d096b24f Mon Sep 17 00:00:00 2001
From: sqdselo
Date: Mon, 29 Apr 2024 11:38:35 +0400
Subject: [PATCH 07/17] =?UTF-8?q?=D0=B4=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0?=
=?UTF-8?q?=D1=8E?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../HoistingCrane/CollectionGenericObjects/AbstractCompany.cs | 2 +-
Файл_с_машинами.txt | 2 ++
2 files changed, 3 insertions(+), 1 deletion(-)
create mode 100644 Файл_с_машинами.txt
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs
index 98a10dc..1c50f33 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs
@@ -31,7 +31,7 @@ namespace HoistingCrane.CollectionGenericObjects
{
get
{
- return (pictureWidth * pictureHeight) / (_placeSizeHeight * _placeSizeWidth)-3;
+ return (pictureWidth * pictureHeight) / (_placeSizeHeight * _placeSizeWidth)-2;
}
}
public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects array)
diff --git a/Файл_с_машинами.txt b/Файл_с_машинами.txt
new file mode 100644
index 0000000..ec76705
--- /dev/null
+++ b/Файл_с_машинами.txt
@@ -0,0 +1,2 @@
+CollectionsStorage
+массив|Massive|24|EntityTrackedVehicle:100:100:Gray;EntityTrackedVehicle:100:100:Red;EntityTrackedVehicle:100:100:Blue;EntityTrackedVehicle:100:100:Yellow;EntityTrackedVehicle:100:100:Green;EntityTrackedVehicle:100:100:Black;EntityTrackedVehicle:100:100:White;EntityTrackedVehicle:100:100:Purple;EntityHoistingCrane:100:100:Green:Black:False:False;EntityHoistingCrane:100:100:Yellow:Gray:False:True;EntityHoistingCrane:100:100:Purple:Black:True:True;EntityTrackedVehicle:100:100:White;EntityHoistingCrane:100:100:White:Black:False:True;EntityTrackedVehicle:100:100:Green;EntityTrackedVehicle:100:100:White;EntityTrackedVehicle:100:100:White;EntityTrackedVehicle:100:100:White;EntityTrackedVehicle:100:100:White;EntityHoistingCrane:100:100:White:Black:False:False;EntityTrackedVehicle:100:100:White;EntityTrackedVehicle:100:100:Yellow;EntityTrackedVehicle:100:100:White;EntityHoistingCrane:100:100:Gray:Black:False:False;EntityTrackedVehicle:100:100:Black;
\ No newline at end of file
--
2.25.1
From 0b15e5c7d02e885050643f23aa57d77ef1a458e7 Mon Sep 17 00:00:00 2001
From: sqdselo
Date: Mon, 29 Apr 2024 13:26:18 +0400
Subject: [PATCH 08/17] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0?=
=?UTF-8?q?=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80?=
=?UTF-8?q?=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=206?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../StorageCollection.cs | 6 +++---
.../FormCarCollection.Designer.cs | 20 +++++++++----------
...йл_для_лабораторной_6.txt | 3 +++
допка3.txt | 3 +++
4 files changed, 19 insertions(+), 13 deletions(-)
create mode 100644 Файл_для_лабораторной_6.txt
create mode 100644 допка3.txt
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs
index d696adb..637b638 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs
@@ -1,5 +1,6 @@
using HoistingCrane.Drawning;
using System;
+using System.Configuration;
using System.Text;
namespace HoistingCrane.CollectionGenericObjects
@@ -94,6 +95,7 @@ namespace HoistingCrane.CollectionGenericObjects
using (StreamWriter writer = new StreamWriter(filename))
{
writer.Write(_collectionKey);
+
foreach (KeyValuePair> value in dict)
{
StringBuilder sb = new();
@@ -123,10 +125,8 @@ namespace HoistingCrane.CollectionGenericObjects
}
writer.Write(sb);
}
-
}
return true;
-
}
///
@@ -156,7 +156,7 @@ namespace HoistingCrane.CollectionGenericObjects
while ((strs = fs.ReadLine()) != null)
{
string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
- if (record.Length != 4)
+ if (record.Length != 2)
{
continue;
}
diff --git a/HoistingCrane/HoistingCrane/FormCarCollection.Designer.cs b/HoistingCrane/HoistingCrane/FormCarCollection.Designer.cs
index 4991414..47d3972 100644
--- a/HoistingCrane/HoistingCrane/FormCarCollection.Designer.cs
+++ b/HoistingCrane/HoistingCrane/FormCarCollection.Designer.cs
@@ -68,7 +68,7 @@
groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(763, 24);
groupBoxTools.Name = "groupBoxTools";
- groupBoxTools.Size = new Size(210, 485);
+ groupBoxTools.Size = new Size(210, 499);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
@@ -81,7 +81,7 @@
panelCompanyTool.Controls.Add(buttonRefresh);
panelCompanyTool.Controls.Add(buttonGoToChek);
panelCompanyTool.Controls.Add(buttonDeleteCar);
- panelCompanyTool.Location = new Point(6, 312);
+ panelCompanyTool.Location = new Point(6, 319);
panelCompanyTool.Name = "panelCompanyTool";
panelCompanyTool.Size = new Size(204, 185);
panelCompanyTool.TabIndex = 8;
@@ -198,7 +198,7 @@
radioButtonList.AutoSize = true;
radioButtonList.Location = new Point(128, 56);
radioButtonList.Name = "radioButtonList";
- radioButtonList.Size = new Size(67, 19);
+ radioButtonList.Size = new Size(66, 19);
radioButtonList.TabIndex = 3;
radioButtonList.TabStop = true;
radioButtonList.Text = "Список";
@@ -209,7 +209,7 @@
radioButtonMassive.AutoSize = true;
radioButtonMassive.Location = new Point(18, 56);
radioButtonMassive.Name = "radioButtonMassive";
- radioButtonMassive.Size = new Size(69, 19);
+ radioButtonMassive.Size = new Size(67, 19);
radioButtonMassive.TabIndex = 2;
radioButtonMassive.TabStop = true;
radioButtonMassive.Text = "Массив";
@@ -227,7 +227,7 @@
labelCollectionName.AutoSize = true;
labelCollectionName.Location = new Point(35, 0);
labelCollectionName.Name = "labelCollectionName";
- labelCollectionName.Size = new Size(135, 15);
+ labelCollectionName.Size = new Size(125, 15);
labelCollectionName.TabIndex = 0;
labelCollectionName.Text = "Название коллекции:";
//
@@ -248,7 +248,7 @@
pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 24);
pictureBox.Name = "pictureBox";
- pictureBox.Size = new Size(763, 485);
+ pictureBox.Size = new Size(763, 499);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
@@ -265,14 +265,14 @@
//
файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { saveToolStripMenuItem, loadToolStripMenuItem });
файлToolStripMenuItem.Name = "файлToolStripMenuItem";
- файлToolStripMenuItem.Size = new Size(50, 20);
+ файлToolStripMenuItem.Size = new Size(48, 20);
файлToolStripMenuItem.Text = "Файл";
//
// saveToolStripMenuItem
//
saveToolStripMenuItem.Name = "saveToolStripMenuItem";
saveToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S;
- saveToolStripMenuItem.Size = new Size(186, 22);
+ saveToolStripMenuItem.Size = new Size(181, 22);
saveToolStripMenuItem.Text = "Сохранение";
saveToolStripMenuItem.Click += saveToolStripMenuItem_Click;
//
@@ -280,7 +280,7 @@
//
loadToolStripMenuItem.Name = "loadToolStripMenuItem";
loadToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.L;
- loadToolStripMenuItem.Size = new Size(186, 22);
+ loadToolStripMenuItem.Size = new Size(181, 22);
loadToolStripMenuItem.Text = "Загрузка";
loadToolStripMenuItem.Click += loadToolStripMenuItem_Click;
//
@@ -296,7 +296,7 @@
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(973, 509);
+ ClientSize = new Size(973, 523);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Controls.Add(menuStrip);
diff --git a/Файл_для_лабораторной_6.txt b/Файл_для_лабораторной_6.txt
new file mode 100644
index 0000000..9ad6433
--- /dev/null
+++ b/Файл_для_лабораторной_6.txt
@@ -0,0 +1,3 @@
+CollectionsStorage
+массив|Massive|25|EntityTrackedVehicle:100:100:Green;EntityHoistingCrane:100:100:Yellow:Black:False:False;EntityTrackedVehicle:100:100:Gray;
+список|List|2|EntityTrackedVehicle:100:100:Blue;EntityHoistingCrane:100:100:Gray:Black:True:True;
\ No newline at end of file
diff --git a/допка3.txt b/допка3.txt
new file mode 100644
index 0000000..24b0dfa
--- /dev/null
+++ b/допка3.txt
@@ -0,0 +1,3 @@
+CollectionsStorage
+массив|Massive
+список|List
\ No newline at end of file
--
2.25.1
From 2015e638fe64a0b258138a2e788b9f21828ce410 Mon Sep 17 00:00:00 2001
From: sqdselo <147947144+sqdselo@users.noreply.github.com>
Date: Sat, 4 May 2024 15:57:24 +0400
Subject: [PATCH 09/17] 1
---
.../HoistingCrane/FormCarCollection.cs | 40 +++++++++----------
1 file changed, 20 insertions(+), 20 deletions(-)
diff --git a/HoistingCrane/HoistingCrane/FormCarCollection.cs b/HoistingCrane/HoistingCrane/FormCarCollection.cs
index cc3db0d..8fb3fa7 100644
--- a/HoistingCrane/HoistingCrane/FormCarCollection.cs
+++ b/HoistingCrane/HoistingCrane/FormCarCollection.cs
@@ -99,24 +99,24 @@ namespace HoistingCrane
private void buttonDeleteCar_Click(object sender, EventArgs e)
{
- if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return;
- if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null) return;
- try
- {
- int pos = Convert.ToInt32(maskedTextBox.Text);
- if ((_company - pos) != null)
- {
- MessageBox.Show("Объект удален!");
- pictureBox.Image = _company.Show();
- logger.LogInformation("Удален объект по позиции: {pos} ", pos);
- }
- else throw new Exception();
- }
- catch(Exception ex)
- {
- logger.LogInformation("Не удалось удалить объект по позиции: {pos}", Convert.ToInt32(maskedTextBox.Text));
- return;
- }
+ //if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return;
+ //if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null) return;
+ //try
+ //{
+ // int pos = Convert.ToInt32(maskedTextBox.Text);
+ // if ((_company - pos) != null)
+ // {
+ // MessageBox.Show("Объект удален!");
+ // pictureBox.Image = _company.Show();
+ // logger.LogInformation("Удален объект по позиции: {pos} ", pos);
+ // }
+ // else throw new Exception();
+ //}
+ //catch(Exception ex)
+ //{
+ // logger.LogInformation("Не удалось удалить объект по позиции: {pos}", Convert.ToInt32(maskedTextBox.Text));
+ // return;
+ //}
}
private void buttonRefresh_Click(object sender, EventArgs e)
{
@@ -233,7 +233,7 @@ namespace HoistingCrane
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
logger.LogInformation("Сохранение в файл: {filename}", saveFileDialog.FileName);
}
- catch (Exception ex)
+ catch (FileNotFoundException ex)
{
MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
logger.LogError("Ошибка: {Message}", ex.Message);
@@ -257,7 +257,7 @@ namespace HoistingCrane
RerfreshListBoxItems();
logger.LogInformation("Загрузка в файл: {filename}", saveFileDialog.FileName);
}
- catch(Exception ex)
+ catch(FileNotFoundException ex)
{
MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
logger.LogError("Ошибка: {Message}", ex.Message);
--
2.25.1
From 58d5e959c7ca9513f1032dafc5771f2bd2363d00 Mon Sep 17 00:00:00 2001
From: sqdselo <147947144+sqdselo@users.noreply.github.com>
Date: Sat, 4 May 2024 16:01:40 +0400
Subject: [PATCH 10/17] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0?=
=?UTF-8?q?=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80?=
=?UTF-8?q?=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=206?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../HoistingCrane/CollectionGenericObjects/AbstractCompany.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs
index 1c50f33..6b7102b 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs
@@ -31,7 +31,7 @@ namespace HoistingCrane.CollectionGenericObjects
{
get
{
- return (pictureWidth * pictureHeight) / (_placeSizeHeight * _placeSizeWidth)-2;
+ return (pictureWidth * pictureHeight) / (_placeSizeHeight * _placeSizeWidth);
}
}
public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects array)
--
2.25.1
From 21e126ef09a3ba040b44a812338171509fea9a2e Mon Sep 17 00:00:00 2001
From: sqdselo <147947144+sqdselo@users.noreply.github.com>
Date: Sat, 4 May 2024 16:09:17 +0400
Subject: [PATCH 11/17] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0?=
=?UTF-8?q?=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80?=
=?UTF-8?q?=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=206?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../HoistingCrane/CollectionGenericObjects/StorageCollection.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs
index 637b638..ae9901b 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs
@@ -156,7 +156,7 @@ namespace HoistingCrane.CollectionGenericObjects
while ((strs = fs.ReadLine()) != null)
{
string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
- if (record.Length != 2)
+ if (record.Length != 4)
{
continue;
}
--
2.25.1
From 170e4abff07453aa496eb11adeef619cb873b0bf Mon Sep 17 00:00:00 2001
From: sqdselo <147947144+sqdselo@users.noreply.github.com>
Date: Mon, 6 May 2024 17:35:33 +0400
Subject: [PATCH 12/17] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D0=BB=20=D0=BB?=
=?UTF-8?q?=D0=B8=D1=88=D0=BD=D0=B8=D0=B5=20=D1=8E=D0=B7=D0=B8=D0=BD=D0=B3?=
=?UTF-8?q?=D0=B8,=20=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20=D0=B8=D1=81?=
=?UTF-8?q?=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BD=D0=B0?=
=?UTF-8?q?=20=D0=BE=D0=BF=D0=B5=D1=80=D0=B0=D1=86=D0=B8=D0=B8=20(=D0=B4?=
=?UTF-8?q?=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D1=82=D1=8C,=20=D1=83=D0=B4?=
=?UTF-8?q?=D0=B0=D0=BB=D0=B8=D1=82=D1=8C,=20=D0=BF=D0=BE=D0=BB=D1=83?=
=?UTF-8?q?=D1=87=D0=B8=D1=82=D1=8C)=20=D0=B8=20=D1=81=D0=B4=D0=B5=D0=BB?=
=?UTF-8?q?=D0=B0=D0=BB=20=D0=B8=D1=81=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD?=
=?UTF-8?q?=D0=B8=D1=8F=20=D0=BD=D0=B0=20=D0=B7=D0=B0=D0=B3=D1=80=D1=83?=
=?UTF-8?q?=D0=B7=D0=BA=D1=83=20=D0=B8=20=D0=B2=D1=8B=D0=B3=D1=80=D1=83?=
=?UTF-8?q?=D0=B7=D0=BA=D1=83=20=D1=84=D0=B0=D0=B9=D0=BB=D0=BE=D0=B2?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../AbstractCompany.cs | 1 -
.../CollectionType.cs | 3 +-
.../CollectionGenericObjects/Garage.cs | 12 +-
.../ICollectionGenericObjects.cs | 3 +-
.../ListGenericObjects.cs | 71 +++-------
.../MassivGenericObjects.cs | 101 +++++---------
.../StorageCollection.cs | 27 ++--
.../Exceptions/CollectionOverflowException.cs | 8 +-
.../Exceptions/ObjectNotFoundException.cs | 8 +-
.../PositionOutOfCollectionException.cs | 8 +-
.../HoistingCrane/FormCarCollection.cs | 125 +++++++-----------
11 files changed, 121 insertions(+), 246 deletions(-)
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs
index 1c50f33..e56d990 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs
@@ -1,5 +1,4 @@
using HoistingCrane.Drawning;
-using System;
namespace HoistingCrane.CollectionGenericObjects
{
public abstract class AbstractCompany
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/CollectionType.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/CollectionType.cs
index 22ffa84..93433c2 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/CollectionType.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/CollectionType.cs
@@ -1,5 +1,4 @@
-using System;
-namespace HoistingCrane.CollectionGenericObjects
+namespace HoistingCrane.CollectionGenericObjects
{
public enum CollectionType
{
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/Garage.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/Garage.cs
index 0cf29d7..4927dd5 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/Garage.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/Garage.cs
@@ -1,6 +1,5 @@
using HoistingCrane.Drawning;
-using System;
-using System.Collections.Specialized;
+using HoistingCrane.Exceptions;
namespace HoistingCrane.CollectionGenericObjects
{
@@ -36,9 +35,12 @@ namespace HoistingCrane.CollectionGenericObjects
{
if (arr?.Get(i) != null)
{
- arr?.Get(i)?.SetPictureSize(pictureWidth, pictureHeight);
- arr?.Get(i)?.SetPosition(_placeSizeWidth * currentPosWidth + 25, _placeSizeHeight * currentPosHeight + 15);
-
+ try
+ {
+ arr?.Get(i)?.SetPictureSize(pictureWidth, pictureHeight);
+ arr?.Get(i)?.SetPosition(_placeSizeWidth * currentPosWidth + 25, _placeSizeHeight * currentPosHeight + 15);
+ }
+ catch (ObjectNotFoundException) { }
}
if (currentPosWidth > 0)
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs
index 04b8de7..ae99e89 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -1,5 +1,4 @@
-using System;
-namespace HoistingCrane.CollectionGenericObjects
+namespace HoistingCrane.CollectionGenericObjects
{
public interface ICollectionGenericObjects
where T: class
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs
index 73f740c..7503bb0 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs
@@ -1,7 +1,4 @@
using HoistingCrane.Exceptions;
-using System;
-using System.CodeDom.Compiler;
-
namespace HoistingCrane.CollectionGenericObjects
{
public class ListGenericObjects : ICollectionGenericObjects where T : class
@@ -45,72 +42,34 @@ namespace HoistingCrane.CollectionGenericObjects
public T? Get(int position)
{
- try
- {
- if (position >= Count || position < 0)
- {
- throw new PositionOutOfCollectionException(position);
- }
- return list[position];
- }
- catch (PositionOutOfCollectionException ex)
- {
- MessageBox.Show(ex.Message);
- return null;
- }
+ if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
+ return list[position];
}
-
+
public int Insert(T obj)
{
- try
+ if (Count == _maxCount)
{
- if (Count == _maxCount) throw new CollectionOverflowException(Count);
- list.Add(obj);
- return Count;
- }
- catch(CollectionOverflowException ex)
- {
- MessageBox.Show(ex.Message);
- return -1;
+ throw new CollectionOverflowException(Count);
}
+ list.Add(obj);
+ return Count;
}
public int Insert(T obj, int position)
{
- try
- {
- if (position < 0 || position >= _maxCount) throw new PositionOutOfCollectionException(position);
- if (Count == _maxCount) throw new CollectionOverflowException(Count);
- list.Insert(position, obj);
- return position;
- }
- catch (CollectionOverflowException ex)
- {
- MessageBox.Show(ex.Message);
- return -1;
- }
- catch (PositionOutOfCollectionException ex)
- {
- MessageBox.Show(ex.Message);
- return -1;
- }
-
+ if (position < 0 || position >= Count) throw new PositionOutOfCollectionException(position);
+ if (Count == _maxCount) throw new CollectionOverflowException(Count);
+ list.Insert(position, obj);
+ return position;
}
public T? Remove(int position)
{
- try
- {
- if (position < 0 || position >= Count) throw new PositionOutOfCollectionException(position);
- T? temp = list[position];
- list.RemoveAt(position);
- return temp;
- }
- catch (PositionOutOfCollectionException ex)
- {
- MessageBox.Show(ex.Message);
- return null;
- }
+ if (position < 0 || position >= list.Count) throw new PositionOutOfCollectionException(position);
+ T? temp = list[position];
+ list.RemoveAt(position);
+ return temp;
}
public IEnumerable GetItems()
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs
index 7680ae0..43df118 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs
@@ -1,6 +1,4 @@
using HoistingCrane.Exceptions;
-using System;
-
namespace HoistingCrane.CollectionGenericObjects
{
public class MassivGenericObjects : ICollectionGenericObjects where T : class
@@ -40,96 +38,63 @@ namespace HoistingCrane.CollectionGenericObjects
public T? Get(int position)
{
- try
- {
- if (position < 0 || position >= Count) throw new PositionOutOfCollectionException(position);
- //if (arr[position] == null) throw new ObjectNotFoundException(position);
- return arr[position];
- }
- catch (PositionOutOfCollectionException ex)
- {
- MessageBox.Show(ex.Message);
- return null;
- }
- //catch (ObjectNotFoundException ex)
- //{
- // MessageBox.Show(ex.Message);
- // return null;
- //}
- }
-
- public IEnumerable GetItems()
- {
- for(int i = 0; i < arr.Length; i++)
- {
- yield return arr[i];
- }
+ if (position < 0 || position >= Count) throw new PositionOutOfCollectionException(position);
+ return arr[position];
}
public int Insert(T obj)
{
- try
+ int countObjectNotNull = 0;
+ for(int i = 0; i < Count; i++)
{
- if (arr.Count(x => x != null) == MaxCount) throw new CollectionOverflowException(Count);
- return Insert(obj, 0);
- }
- catch(CollectionOverflowException ex)
- {
- MessageBox.Show(ex.Message);
- return -1;
+ if (arr[i] != null) countObjectNotNull += 1;
}
+ if(countObjectNotNull == MaxCount) throw new CollectionOverflowException(Count);
+ return Insert(obj, 0);
}
-
public int Insert(T obj, int position)
{
- try
+ if (position < 0 || position >= Count)
{
- if (position < 0 || position > Count) throw new PositionOutOfCollectionException(position);
+ throw new PositionOutOfCollectionException(position);
+ }
+ int copyPos = position - 1;
+ while (position < Count)
+ {
if (arr[position] == null)
{
arr[position] = obj;
return position;
}
- else
- {
- if (Insert(obj, position + 1) != -1)
- {
- return position;
- }
- if (Insert(obj, position - 1) != -1)
- {
- return position;
- }
- return -1;
- }
+ position++;
}
- catch (PositionOutOfCollectionException ex)
+ while (copyPos > 0)
{
- MessageBox.Show(ex.Message);
- return -1;
+ if (arr[copyPos] == null)
+ {
+ arr[copyPos] = obj;
+ return copyPos;
+ }
+ copyPos--;
}
+ throw new CollectionOverflowException(Count);
}
public T? Remove(int position)
{
- try
+ if (position < 0 || position >= Count) throw new PositionOutOfCollectionException(position);
+ if (arr[position] == null) throw new ObjectNotFoundException(position);
+ T? temp = arr[position];
+ arr[position] = null;
+ return temp;
+ }
+
+ public IEnumerable GetItems()
+ {
+ for (int i = 0; i < arr.Length; i++)
{
- if (position < 0 || position >= MaxCount) throw new PositionOutOfCollectionException(position);
- if (arr[position] == null) throw new ObjectNotFoundException(position);
- T? temp = arr[position];
- arr[position] = null;
- return temp;
- }
- catch (ObjectNotFoundException ex)
- {
- MessageBox.Show(ex.Message);
- return null;
- }
- catch (PositionOutOfCollectionException ex)
- {
- MessageBox.Show(ex.Message);
- return null;
+ yield return arr[i];
}
}
}
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs
index cb6a3f0..7ac7b49 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs
@@ -1,8 +1,6 @@
using HoistingCrane.Drawning;
using HoistingCrane.Exceptions;
-using System;
using System.Text;
-
namespace HoistingCrane.CollectionGenericObjects
{
public class StorageCollection where T : DrawningTrackedVehicle
@@ -84,7 +82,7 @@ namespace HoistingCrane.CollectionGenericObjects
{
if (dict.Count == 0)
{
- throw new Exception("В хранилище отсутствуют коллекции для сохранения");
+ throw new InvalidOperationException("В хранилище отсутствуют коллекции для сохранения");
}
if (File.Exists(filename))
@@ -95,6 +93,7 @@ namespace HoistingCrane.CollectionGenericObjects
using (StreamWriter writer = new StreamWriter(filename))
{
writer.Write(_collectionKey);
+
foreach (KeyValuePair> value in dict)
{
StringBuilder sb = new();
@@ -105,7 +104,6 @@ namespace HoistingCrane.CollectionGenericObjects
{
continue;
}
-
sb.Append(value.Key);
sb.Append(_separatorForKeyValue);
sb.Append(value.Value.GetCollectionType);
@@ -124,31 +122,30 @@ namespace HoistingCrane.CollectionGenericObjects
}
writer.Write(sb);
}
-
}
}
///
- // /// Загрузка информации по грузовикам в хранилище из файла
- // ///
- // /// Путь и имя файла
- // /// true - загрузка прошла успешно, false - ошибка при загрузке данных
+ /// Загрузка информации по грузовикам в хранилище из файла
+ ///
+ ///
+ ///
public void LoadData(string filename)
{
if (!File.Exists(filename))
{
- throw new Exception("Файл не существует");
+ throw new FileNotFoundException("Файл не существует");
}
using (StreamReader fs = File.OpenText(filename))
{
string str = fs.ReadLine();
if (str == null || str.Length == 0)
{
- throw new Exception("В файле не присутствуют данные");
+ throw new InvalidOperationException("В файле не присутствуют данные");
}
if (!str.StartsWith(_collectionKey))
{
- throw new Exception("В файле неверные данные");
+ throw new FormatException("В файле неверные данные");
}
dict.Clear();
string strs = "";
@@ -163,7 +160,7 @@ namespace HoistingCrane.CollectionGenericObjects
ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionType);
if (collection == null)
{
- throw new Exception("Не удалось создать коллекцию");
+ throw new InvalidOperationException("Не удалось определить тип коллекции:" + record[1]);
}
collection.MaxCount = Convert.ToInt32(record[2]);
string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
@@ -175,12 +172,12 @@ namespace HoistingCrane.CollectionGenericObjects
{
if (collection.Insert(crane) == -1)
{
- throw new Exception("Объект не удалось добавить в коллекцию: " + record[3]);
+ throw new InvalidOperationException("Объект не удалось добавить в коллекцию: " + record[3]);
}
}
catch(CollectionOverflowException ex)
{
- throw new Exception("Коллекция переполнена");
+ throw new CollectionOverflowException("Коллекция переполнена", ex);
}
}
}
diff --git a/HoistingCrane/HoistingCrane/Exceptions/CollectionOverflowException.cs b/HoistingCrane/HoistingCrane/Exceptions/CollectionOverflowException.cs
index da3c19f..44eaf0a 100644
--- a/HoistingCrane/HoistingCrane/Exceptions/CollectionOverflowException.cs
+++ b/HoistingCrane/HoistingCrane/Exceptions/CollectionOverflowException.cs
@@ -1,10 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Runtime.Serialization;
-using System.Text;
-using System.Threading.Tasks;
-
+using System.Runtime.Serialization;
namespace HoistingCrane.Exceptions
{
[Serializable]
diff --git a/HoistingCrane/HoistingCrane/Exceptions/ObjectNotFoundException.cs b/HoistingCrane/HoistingCrane/Exceptions/ObjectNotFoundException.cs
index c833095..bd43581 100644
--- a/HoistingCrane/HoistingCrane/Exceptions/ObjectNotFoundException.cs
+++ b/HoistingCrane/HoistingCrane/Exceptions/ObjectNotFoundException.cs
@@ -1,10 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Runtime.Serialization;
-using System.Text;
-using System.Threading.Tasks;
-
+using System.Runtime.Serialization;
namespace HoistingCrane.Exceptions
{
[Serializable]
diff --git a/HoistingCrane/HoistingCrane/Exceptions/PositionOutOfCollectionException.cs b/HoistingCrane/HoistingCrane/Exceptions/PositionOutOfCollectionException.cs
index e35263d..15796e2 100644
--- a/HoistingCrane/HoistingCrane/Exceptions/PositionOutOfCollectionException.cs
+++ b/HoistingCrane/HoistingCrane/Exceptions/PositionOutOfCollectionException.cs
@@ -1,10 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Runtime.Serialization;
-using System.Text;
-using System.Threading.Tasks;
-
+using System.Runtime.Serialization;
namespace HoistingCrane.Exceptions
{
[Serializable]
diff --git a/HoistingCrane/HoistingCrane/FormCarCollection.cs b/HoistingCrane/HoistingCrane/FormCarCollection.cs
index 8fb3fa7..623ad8f 100644
--- a/HoistingCrane/HoistingCrane/FormCarCollection.cs
+++ b/HoistingCrane/HoistingCrane/FormCarCollection.cs
@@ -1,17 +1,7 @@
using HoistingCrane.CollectionGenericObjects;
using HoistingCrane.Drawning;
-using HoistingCrane.Entities;
+using HoistingCrane.Exceptions;
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 HoistingCrane
{
public partial class FormCarCollection : Form
@@ -34,46 +24,13 @@ namespace HoistingCrane
{
panelCompanyTool.Enabled = false;
}
- private void CreateObject(string type)
- {
- DrawningTrackedVehicle drawning;
- if (_company == null) return;
- Random rand = new();
- switch (type)
- {
- case nameof(DrawningHoistingCrane):
- drawning = new DrawningHoistingCrane(rand.Next(100, 300), rand.Next(1000, 3000), GetColor(rand), GetColor(rand), true, true);
- break;
-
- case nameof(DrawningTrackedVehicle):
- drawning = new DrawningTrackedVehicle(rand.Next(100, 300), rand.Next(1000, 3000), GetColor(rand));
- break;
- default:
- return;
- }
- if ((_company + drawning) != -1)
- {
- MessageBox.Show("Объект добавлен");
- pictureBox.Image = _company.Show();
- }
- }
- private static Color GetColor(Random random)
- {
- Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
- ColorDialog dialog = new();
- if (dialog.ShowDialog() == DialogResult.OK)
- {
- color = dialog.Color;
- }
- return color;
- }
private void buttonCreateHoistingCrane_Click(object sender, EventArgs e)
{
FormCarConfig form = new();
form.Show();
- form.AddEvent(SetCar);
+ form.AddEvent(SetCrane);
}
- private void SetCar(DrawningTrackedVehicle drawningTrackedVehicle)
+ private void SetCrane(DrawningTrackedVehicle drawningTrackedVehicle)
{
if (_company == null || drawningTrackedVehicle == null) return;
try
@@ -86,37 +43,53 @@ namespace HoistingCrane
}
else
{
- throw new Exception("Не удалось добавить объект. Заполнено максимальное количество ячеек");
+ MessageBox.Show("Не удалось добавить объект");
+ logger.LogInformation("Не удалось добавить корабль {ship} в коллекцию", drawningTrackedVehicle.GetType().Name);
}
}
- catch (Exception ex)
+ catch (CollectionOverflowException ex)
{
- logger.LogInformation(ex.Message);
- return;
+ MessageBox.Show("Ошибка переполнения коллекции");
+ logger.LogError("Ошибка: {Message}", ex.Message);
}
}
private void buttonDeleteCar_Click(object sender, EventArgs e)
{
- //if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return;
- //if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null) return;
- //try
- //{
- // int pos = Convert.ToInt32(maskedTextBox.Text);
- // if ((_company - pos) != null)
- // {
- // MessageBox.Show("Объект удален!");
- // pictureBox.Image = _company.Show();
- // logger.LogInformation("Удален объект по позиции: {pos} ", pos);
- // }
- // else throw new Exception();
- //}
- //catch(Exception ex)
- //{
- // logger.LogInformation("Не удалось удалить объект по позиции: {pos}", Convert.ToInt32(maskedTextBox.Text));
- // return;
- //}
+ if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
+ {
+ return;
+ }
+ if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
+ {
+ return;
+ }
+ try
+ {
+ int pos = Convert.ToInt32(maskedTextBox.Text);
+ if ((_company - pos) != null)
+ {
+ MessageBox.Show("Объект удален!");
+ pictureBox.Image = _company.Show();
+ logger.LogInformation("Удаление авто по индексу {pos}", pos);
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ logger.LogInformation("Не удалось удалить авто из коллекции по индексу {pos}", pos);
+ }
+ }
+ catch (ObjectNotFoundException ex)
+ {
+ MessageBox.Show("Ошибка: отсутствует объект");
+ logger.LogError("Ошибка: {Message}", ex.Message);
+ }
+ catch (PositionOutOfCollectionException ex)
+ {
+ MessageBox.Show("Ошибка: неправильная позиция");
+ logger.LogError("Ошибка: {Message}", ex.Message);
+ }
}
private void buttonRefresh_Click(object sender, EventArgs e)
{
@@ -162,20 +135,20 @@ namespace HoistingCrane
{
if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonList.Checked && !radioButtonMassive.Checked))
{
- MessageBox.Show("Не все данные заполнены", "Ошибка",
- MessageBoxButtons.OK, MessageBoxIcon.Error);
+ MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ logger.LogInformation("Не удалось добавить коллекцию: не все данные заполнены");
return;
}
CollectionType collectionType = CollectionType.None;
if (radioButtonMassive.Checked)
{
collectionType = CollectionType.Massive;
- logger.LogInformation("Создана коллекция типа: {name}", collectionType);
+ logger.LogInformation("Создана коллекция типа: {name}, название: {name}", collectionType, textBoxCollectionName.Text);
}
else if (radioButtonList.Checked)
{
collectionType = CollectionType.List;
- logger.LogInformation("Создана коллекция типа: {name}", collectionType);
+ logger.LogInformation("Создана коллекция типа: {name}, название: {name}", collectionType, textBoxCollectionName.Text);
}
_storageCollection.AddCollection(textBoxCollectionName.Text,collectionType);RerfreshListBoxItems();
}
@@ -190,7 +163,7 @@ namespace HoistingCrane
return;
_storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
RerfreshListBoxItems();
- logger.LogInformation("Коллекция успешно удалена");
+ logger.LogInformation("Коллекция {name} успешно удалена", listBoxCollection.SelectedItem.ToString());
}
private void buttonCreateCompany_Click(object sender, EventArgs e)
{
@@ -233,7 +206,7 @@ namespace HoistingCrane
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
logger.LogInformation("Сохранение в файл: {filename}", saveFileDialog.FileName);
}
- catch (FileNotFoundException ex)
+ catch (Exception ex)
{
MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
logger.LogError("Ошибка: {Message}", ex.Message);
@@ -253,11 +226,11 @@ namespace HoistingCrane
try
{
_storageCollection.LoadData(openFileDialog.FileName);
- MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
RerfreshListBoxItems();
+ MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
logger.LogInformation("Загрузка в файл: {filename}", saveFileDialog.FileName);
}
- catch(FileNotFoundException ex)
+ catch(Exception ex)
{
MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
logger.LogError("Ошибка: {Message}", ex.Message);
--
2.25.1
From ea555cc89719b619e6234fee39543348883c3344 Mon Sep 17 00:00:00 2001
From: sqdselo <147947144+sqdselo@users.noreply.github.com>
Date: Mon, 6 May 2024 23:02:05 +0400
Subject: [PATCH 13/17] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0?=
=?UTF-8?q?=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80?=
=?UTF-8?q?=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=207?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../AbstractCompany.cs | 1 -
.../HoistingCrane/FormCarCollection.cs | 13 ++++++-----
.../HoistingCrane/HoistingCrane.csproj | 10 ++++-----
HoistingCrane/HoistingCrane/Program.cs | 22 ++++++-------------
HoistingCrane/HoistingCrane/nlog.config | 13 -----------
5 files changed, 18 insertions(+), 41 deletions(-)
delete mode 100644 HoistingCrane/HoistingCrane/nlog.config
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs
index e56d990..fb26d02 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs
@@ -40,7 +40,6 @@ namespace HoistingCrane.CollectionGenericObjects
arr = array;
arr.MaxCount = GetMaxCount;
}
-
public static int operator +(AbstractCompany company, DrawningTrackedVehicle car)
{
return company.arr?.Insert(car) ?? -1;
diff --git a/HoistingCrane/HoistingCrane/FormCarCollection.cs b/HoistingCrane/HoistingCrane/FormCarCollection.cs
index 623ad8f..318a373 100644
--- a/HoistingCrane/HoistingCrane/FormCarCollection.cs
+++ b/HoistingCrane/HoistingCrane/FormCarCollection.cs
@@ -129,7 +129,6 @@ namespace HoistingCrane
listBoxCollection.Items.Add(colName);
}
}
- logger.LogInformation("Коллекция успешно обновлена");
}
private void buttonCollectionAdd_Click(object sender, EventArgs e)
{
@@ -143,12 +142,12 @@ namespace HoistingCrane
if (radioButtonMassive.Checked)
{
collectionType = CollectionType.Massive;
- logger.LogInformation("Создана коллекция типа: {name}, название: {name}", collectionType, textBoxCollectionName.Text);
+ logger.LogInformation("Создана коллекция '{nameCol}' , название: {name}", collectionType, textBoxCollectionName.Text);
}
else if (radioButtonList.Checked)
{
collectionType = CollectionType.List;
- logger.LogInformation("Создана коллекция типа: {name}, название: {name}", collectionType, textBoxCollectionName.Text);
+ logger.LogInformation("Создана коллекция '{nameCol}' , название: {name}", collectionType, textBoxCollectionName.Text);
}
_storageCollection.AddCollection(textBoxCollectionName.Text,collectionType);RerfreshListBoxItems();
}
@@ -161,9 +160,13 @@ namespace HoistingCrane
}
if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
return;
+ if (listBoxCollection.SelectedItem != null)
+ {
+ logger.LogInformation("Коллекция '{name}' успешно удалена", listBoxCollection.SelectedItem.ToString());
+ }
_storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
RerfreshListBoxItems();
- logger.LogInformation("Коллекция {name} успешно удалена", listBoxCollection.SelectedItem.ToString());
+
}
private void buttonCreateCompany_Click(object sender, EventArgs e)
{
@@ -187,8 +190,6 @@ namespace HoistingCrane
}
panelCompanyTool.Enabled = true;
RerfreshListBoxItems();
- logger.LogInformation("Создана компания");
-
}
///
diff --git a/HoistingCrane/HoistingCrane/HoistingCrane.csproj b/HoistingCrane/HoistingCrane/HoistingCrane.csproj
index 5f40a60..9b3b27e 100644
--- a/HoistingCrane/HoistingCrane/HoistingCrane.csproj
+++ b/HoistingCrane/HoistingCrane/HoistingCrane.csproj
@@ -15,6 +15,10 @@
+
+
+
+
@@ -32,10 +36,4 @@
-
-
- Always
-
-
-
\ No newline at end of file
diff --git a/HoistingCrane/HoistingCrane/Program.cs b/HoistingCrane/HoistingCrane/Program.cs
index c5abf19..562ee2d 100644
--- a/HoistingCrane/HoistingCrane/Program.cs
+++ b/HoistingCrane/HoistingCrane/Program.cs
@@ -1,37 +1,29 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
-using NLog.Extensions.Logging;
+using Serilog;
+using Serilog.Extensions.Logging;
namespace HoistingCrane
{
internal static class Program
{
- ///
- /// The main entry point for the application.
- ///
[STAThread]
static void Main()
{
- // To customize application configuration such as set high DPI settings or default font,
- // see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
ServiceCollection services = new();
ConfigureServices(services);
using ServiceProvider serviceProvider = services.BuildServiceProvider();
Application.Run(serviceProvider.GetRequiredService());
-
}
- ///
- /// DI
- ///
- ///
private static void ConfigureServices(ServiceCollection services)
{
- services.AddSingleton().AddLogging(option =>
+ // Serilog
+ Log.Logger = new LoggerConfiguration().WriteTo.File("E:\\myLog.log").CreateLogger();
+ services.AddSingleton().AddLogging(builder =>
{
- option.SetMinimumLevel(LogLevel.Information);
- option.AddNLog("nlog.config");
+ builder.AddSerilog();
});
}
}
-}
\ No newline at end of file
+}
diff --git a/HoistingCrane/HoistingCrane/nlog.config b/HoistingCrane/HoistingCrane/nlog.config
deleted file mode 100644
index 0c93951..0000000
--- a/HoistingCrane/HoistingCrane/nlog.config
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
--
2.25.1
From f655c6b4bb852fa5b02864912673503c66c9b9e8 Mon Sep 17 00:00:00 2001
From: Timur_Sharafutdinov
Date: Mon, 13 May 2024 11:43:03 +0400
Subject: [PATCH 14/17] =?UTF-8?q?=D0=B4=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0?=
=?UTF-8?q?=D1=8E?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../AbstractCompany.cs | 7 +-
.../CollectionInfo.cs | 66 ++++++++++++++++
.../ICollectionGenericObjects.cs | 15 +++-
.../ListGenericObjects.cs | 35 +++++++--
.../MassivGenericObjects.cs | 77 +++++++++++++------
.../StorageCollection.cs | 51 ++++++------
.../Drawning/DrawningCraneCompareByColor.cs | 19 +++++
.../Drawning/DrawningCraneCompareByType.cs | 21 +++++
.../Drawning/DrawningCraneEqutables.cs | 32 ++++++++
...ObjectIsPresentInTheCollectionException.cs | 18 +++++
.../FormCarCollection.Designer.cs | 64 ++++++++++-----
.../HoistingCrane/FormCarCollection.cs | 36 ++++++---
12 files changed, 352 insertions(+), 89 deletions(-)
create mode 100644 HoistingCrane/HoistingCrane/CollectionGenericObjects/CollectionInfo.cs
create mode 100644 HoistingCrane/HoistingCrane/Drawning/DrawningCraneCompareByColor.cs
create mode 100644 HoistingCrane/HoistingCrane/Drawning/DrawningCraneCompareByType.cs
create mode 100644 HoistingCrane/HoistingCrane/Drawning/DrawningCraneEqutables.cs
create mode 100644 HoistingCrane/HoistingCrane/Exceptions/ObjectIsPresentInTheCollectionException.cs
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs
index fb26d02..94b5609 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs
@@ -42,7 +42,7 @@ namespace HoistingCrane.CollectionGenericObjects
}
public static int operator +(AbstractCompany company, DrawningTrackedVehicle car)
{
- return company.arr?.Insert(car) ?? -1;
+ return company.arr?.Insert(car, new DrawningCraneEqutables()) ?? -1;
}
public static DrawningTrackedVehicle operator -(AbstractCompany company, int position)
{
@@ -84,5 +84,10 @@ namespace HoistingCrane.CollectionGenericObjects
/// Расстановка объектов
///
protected abstract void SetObjectsPosition();
+ ///
+ /// Сортировка
+ ///
+ ///
+ public void Sort(IComparer comparer) => arr?.CollectionSort(comparer);
}
}
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/CollectionInfo.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/CollectionInfo.cs
new file mode 100644
index 0000000..5762d92
--- /dev/null
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/CollectionInfo.cs
@@ -0,0 +1,66 @@
+using System.Diagnostics.CodeAnalysis;
+
+namespace HoistingCrane.CollectionGenericObjects
+{
+ public class CollectionInfo : IEquatable
+ {
+ ///
+ /// Название
+ ///
+ public string name { get; private set; }
+ ///
+ /// Тип
+ ///
+ public CollectionType collectionType { get; private set; }
+ ///
+ /// Описание
+ ///
+ public string description { get; private set; }
+ ///
+ /// Разделитель
+ ///
+ public static readonly string _separator = "-";
+
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ ///
+ public CollectionInfo(string name, CollectionType collectionType, string description)
+ {
+ this.name = name;
+ this.collectionType = collectionType;
+ this.description = description;
+ }
+
+ public static CollectionInfo? GetCollectionInfo(string data)
+ {
+ string[] strs = data.Split(_separator, StringSplitOptions.RemoveEmptyEntries);
+ if (strs.Length < 1 || strs.Length > 3) return null;
+ return new CollectionInfo(strs[0], (CollectionType)Enum.Parse(typeof(CollectionType), strs[1]), strs.Length > 2 ? strs[2] : string.Empty);
+ }
+
+ public override string ToString()
+ {
+ return name + _separator + collectionType + _separator + description;
+ }
+
+ public bool Equals(CollectionInfo? other)
+ {
+ if(other == null) return false;
+ if (name != other.name) return false;
+ return true;
+ }
+
+ public override bool Equals(object? obj)
+ {
+ return Equals(obj as CollectionInfo);
+ }
+
+ public override int GetHashCode()
+ {
+ return name.GetHashCode();
+ }
+ }
+}
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs
index ae99e89..1fb465a 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -1,4 +1,6 @@
-namespace HoistingCrane.CollectionGenericObjects
+using HoistingCrane.Drawning;
+
+namespace HoistingCrane.CollectionGenericObjects
{
public interface ICollectionGenericObjects
where T: class
@@ -15,15 +17,17 @@
/// Добавление элемента в коллекцию
///
///
+ /// /// Сравнение двух объектов
///
- int Insert(T obj);
+ int Insert(T obj, IEqualityComparer? comparer = null);
///
/// Добавление элемента в коллекцию на определенную позицию
///
///
///
+ /// Сравнение двух объектов
///
- int Insert(T obj, int position);
+ int Insert(T obj, int position, IEqualityComparer? comparer = null);
///
/// Удаление элемента из коллекции по его позиции
///
@@ -45,5 +49,10 @@
///
///
IEnumerable GetItems();
+ ///
+ /// Сортировка коллекции
+ ///
+ ///
+ void CollectionSort(IComparer comparer);
}
}
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs
index 7503bb0..66feeeb 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs
@@ -1,4 +1,5 @@
-using HoistingCrane.Exceptions;
+using HoistingCrane.Drawning;
+using HoistingCrane.Exceptions;
namespace HoistingCrane.CollectionGenericObjects
{
public class ListGenericObjects : ICollectionGenericObjects where T : class
@@ -46,20 +47,33 @@ namespace HoistingCrane.CollectionGenericObjects
return list[position];
}
- public int Insert(T obj)
+ public int Insert(T obj, IEqualityComparer? comparer = null)
{
- if (Count == _maxCount)
+ // TODO выброс ошибки, если такой объект есть в коллекции
+ if (comparer != null && list.Contains(obj))
{
- throw new CollectionOverflowException(Count);
+ throw new ObjectIsPresentInTheCollectionException(obj);
+ }
+ if (list.Count >= _maxCount)
+ {
+ throw new CollectionOverflowException(_maxCount);
}
list.Add(obj);
- return Count;
+ return _maxCount;
}
- public int Insert(T obj, int position)
+ public int Insert(T obj, int position, IEqualityComparer? comparer = null)
{
- if (position < 0 || position >= Count) throw new PositionOutOfCollectionException(position);
- if (Count == _maxCount) throw new CollectionOverflowException(Count);
+ if (comparer != null && list.Contains(obj))
+ {
+ throw new ObjectIsPresentInTheCollectionException();
+ }
+ if (Count >= _maxCount)
+ throw new CollectionOverflowException(_maxCount);
+
+ if (position < 0 || position >= _maxCount)
+ throw new PositionOutOfCollectionException(position);
+
list.Insert(position, obj);
return position;
}
@@ -79,5 +93,10 @@ namespace HoistingCrane.CollectionGenericObjects
yield return list[i];
}
}
+
+ public void CollectionSort(IComparer comparer)
+ {
+ list.Sort(comparer);
+ }
}
}
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs
index 43df118..f96e396 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs
@@ -1,4 +1,6 @@
-using HoistingCrane.Exceptions;
+using HoistingCrane.Drawning;
+using HoistingCrane.Exceptions;
+
namespace HoistingCrane.CollectionGenericObjects
{
public class MassivGenericObjects : ICollectionGenericObjects where T : class
@@ -42,41 +44,65 @@ namespace HoistingCrane.CollectionGenericObjects
return arr[position];
}
- public int Insert(T obj)
+ public int Insert(T obj, IEqualityComparer? comparer = null)
{
- int countObjectNotNull = 0;
- for(int i = 0; i < Count; i++)
+ if (comparer != null)
{
- if (arr[i] != null) countObjectNotNull += 1;
+ foreach (T? item in arr)
+ {
+ if ((comparer as IEqualityComparer).Equals(obj as DrawningTrackedVehicle, item as DrawningTrackedVehicle))
+ throw new ObjectIsPresentInTheCollectionException();
+ }
}
- if(countObjectNotNull == MaxCount) throw new CollectionOverflowException(Count);
- return Insert(obj, 0);
+ int index = 0;
+ while (index < arr.Length)
+ {
+ if (arr[index] == null)
+ {
+ arr[index] = obj;
+ return index;
+ }
+ index++;
+ }
+ throw new CollectionOverflowException(Count);
}
- public int Insert(T obj, int position)
+ public int Insert(T obj, int position, IEqualityComparer? comparer = null)
{
- if (position < 0 || position >= Count)
+ if (comparer != null)
{
- throw new PositionOutOfCollectionException(position);
+ foreach (T? item in arr)
+ {
+ if ((comparer as IEqualityComparer).Equals(obj as DrawningTrackedVehicle, item as DrawningTrackedVehicle))
+ throw new ObjectIsPresentInTheCollectionException();
+ }
}
- int copyPos = position - 1;
- while (position < Count)
+ if (position >= arr.Length || position < 0) throw new PositionOutOfCollectionException(position);
+
+ if (arr[position] == null)
{
- if (arr[position] == null)
- {
- arr[position] = obj;
- return position;
- }
- position++;
+ arr[position] = obj;
+ return position;
}
- while (copyPos > 0)
+ int index = position + 1;
+ while (index < arr.Length)
{
- if (arr[copyPos] == null)
+ if (arr[index] == null)
{
- arr[copyPos] = obj;
- return copyPos;
+ arr[index] = obj;
+ return index;
}
- copyPos--;
+ index++;
+ }
+ index = position - 1;
+ while (index >= 0)
+ {
+ if (arr[index] == null)
+ {
+ arr[index] = obj;
+ return index;
+ }
+ index--;
}
throw new CollectionOverflowException(Count);
}
@@ -97,5 +123,10 @@ namespace HoistingCrane.CollectionGenericObjects
yield return arr[i];
}
}
+ public void CollectionSort(IComparer comparer)
+ {
+ T[] notNullArr = arr.OfType().ToArray();
+ Array.Sort(notNullArr, comparer);
+ }
}
}
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs
index 7ac7b49..07ea4c1 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs
@@ -8,11 +8,11 @@ namespace HoistingCrane.CollectionGenericObjects
///
/// Словарь (хранилище) с коллекциями
///
- readonly Dictionary> dict;
+ readonly Dictionary> dict;
///
/// Возвращение списка названий коллекций
///
- public List Keys => dict.Keys.ToList();
+ public List Keys => dict.Keys.ToList();
///
/// Ключевое слово, с которого должен начинаться файл
///
@@ -30,7 +30,7 @@ namespace HoistingCrane.CollectionGenericObjects
///
public StorageCollection()
{
- dict = new Dictionary>();
+ dict = new Dictionary>();
}
///
/// Добавление коллекции в хранилище
@@ -39,15 +39,16 @@ namespace HoistingCrane.CollectionGenericObjects
/// тип коллекции
public void AddCollection(string name, CollectionType collectionType)
{
- if (!string.IsNullOrEmpty(name) && !Keys.Contains(name))
+ var collectionInfo = new CollectionInfo(name, collectionType, " ");
+ if (!string.IsNullOrEmpty(name) && !Keys.Contains(collectionInfo))
{
- if(collectionType == CollectionType.Massive)
+ if (collectionType == CollectionType.Massive)
{
- dict.Add(name, new MassivGenericObjects ());
+ dict.Add(collectionInfo, new MassivGenericObjects ());
}
if(collectionType == CollectionType.List)
{
- dict.Add(name, new ListGenericObjects ());
+ dict.Add(collectionInfo, new ListGenericObjects ());
}
}
}
@@ -57,8 +58,11 @@ namespace HoistingCrane.CollectionGenericObjects
/// Название коллекции
public void DelCollection(string name)
{
- if (dict.ContainsKey(name))
- dict.Remove(name);
+ var key = dict.Keys.FirstOrDefault(k => k.name == name);
+ if (key != null)
+ {
+ dict.Remove(key);
+ }
}
///
/// Доступ к коллекции
@@ -69,8 +73,9 @@ namespace HoistingCrane.CollectionGenericObjects
{
get
{
- if (name == null || !dict.ContainsKey(name)) { return null; }
- return dict[name];
+ var key = dict.Keys.FirstOrDefault(k => k.name == name);
+ if (key == null) { return null; }
+ return dict[key];
}
}
///
@@ -94,20 +99,16 @@ namespace HoistingCrane.CollectionGenericObjects
{
writer.Write(_collectionKey);
- foreach (KeyValuePair> value in dict)
+ foreach (KeyValuePair> value in dict)
{
StringBuilder sb = new();
sb.Append(Environment.NewLine);
-
- // не сохраняем пустые коллекции
if (value.Value.Count == 0)
{
continue;
}
sb.Append(value.Key);
sb.Append(_separatorForKeyValue);
- sb.Append(value.Value.GetCollectionType);
- sb.Append(_separatorForKeyValue);
sb.Append(value.Value.MaxCount);
sb.Append(_separatorForKeyValue);
foreach (T? item in value.Value.GetItems())
@@ -152,18 +153,14 @@ namespace HoistingCrane.CollectionGenericObjects
while ((strs = fs.ReadLine()) != null)
{
string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
- if (record.Length != 4)
+ if (record.Length != 3)
{
continue;
}
- CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
- ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionType);
- if (collection == null)
- {
- throw new InvalidOperationException("Не удалось определить тип коллекции:" + record[1]);
- }
- collection.MaxCount = Convert.ToInt32(record[2]);
- string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
+ CollectionInfo? collectionInfo = CollectionInfo.GetCollectionInfo(record[0]) ?? throw new InvalidOperationException("Не удалось определить информацию о коллекции: " + record[0]);
+ ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionInfo.collectionType) ?? throw new InvalidOperationException("Не удалось определить тип коллекции:" + record[1]);
+ collection.MaxCount = Convert.ToInt32(record[1]);
+ string[] set = record[2].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set)
{
if (elem?.CreateDrawningTrackedVehicle() is T crane)
@@ -172,7 +169,7 @@ namespace HoistingCrane.CollectionGenericObjects
{
if (collection.Insert(crane) == -1)
{
- throw new InvalidOperationException("Объект не удалось добавить в коллекцию: " + record[3]);
+ throw new InvalidOperationException("Объект не удалось добавить в коллекцию: " + record[2]);
}
}
catch(CollectionOverflowException ex)
@@ -181,7 +178,7 @@ namespace HoistingCrane.CollectionGenericObjects
}
}
}
- dict.Add(record[0], collection);
+ dict.Add(collectionInfo, collection);
}
}
}
diff --git a/HoistingCrane/HoistingCrane/Drawning/DrawningCraneCompareByColor.cs b/HoistingCrane/HoistingCrane/Drawning/DrawningCraneCompareByColor.cs
new file mode 100644
index 0000000..8e76d17
--- /dev/null
+++ b/HoistingCrane/HoistingCrane/Drawning/DrawningCraneCompareByColor.cs
@@ -0,0 +1,19 @@
+namespace HoistingCrane.Drawning
+{
+ public class DrawningCraneCompareByColor : IComparer
+ {
+ public int Compare(DrawningTrackedVehicle? x, DrawningTrackedVehicle? y)
+ {
+ //TODO: Прописать логику сравнения по цветам, скорости и весу
+ if (x == null || x.EntityTrackedVehicle == null) return -1;
+ if (y == null || y.EntityTrackedVehicle == null) return 1;
+ var colorCompare = x.EntityTrackedVehicle.BodyColor.ToArgb().CompareTo(y.EntityTrackedVehicle.BodyColor.ToArgb());
+ if (colorCompare != 0) return colorCompare;
+ var speedCompare = x.EntityTrackedVehicle.Speed.CompareTo(y.EntityTrackedVehicle.Speed);
+ if (speedCompare != 0) return speedCompare;
+ return x.EntityTrackedVehicle.Weight.CompareTo(y.EntityTrackedVehicle.Weight);
+ }
+ }
+}
+
+
diff --git a/HoistingCrane/HoistingCrane/Drawning/DrawningCraneCompareByType.cs b/HoistingCrane/HoistingCrane/Drawning/DrawningCraneCompareByType.cs
new file mode 100644
index 0000000..b2e59ef
--- /dev/null
+++ b/HoistingCrane/HoistingCrane/Drawning/DrawningCraneCompareByType.cs
@@ -0,0 +1,21 @@
+namespace HoistingCrane.Drawning
+{
+ public class DrawningCraneCompareByType : IComparer
+ {
+ ///
+ /// Сравнение по типу, скорости и весу
+ ///
+ ///
+ ///
+ ///
+ public int Compare(DrawningTrackedVehicle? x, DrawningTrackedVehicle? y)
+ {
+ if (x == null || x.EntityTrackedVehicle == null) return -1;
+ if (y == null || y.EntityTrackedVehicle == null) return 1;
+ if (x.GetType().Name != y.GetType().Name) return x.GetType().Name.CompareTo(y.GetType().Name);
+ var speedCompare = x.EntityTrackedVehicle.Speed.CompareTo(y.EntityTrackedVehicle.Speed);
+ if(speedCompare != 0) return speedCompare;
+ return x.EntityTrackedVehicle.Weight.CompareTo(y.EntityTrackedVehicle.Weight);
+ }
+ }
+}
diff --git a/HoistingCrane/HoistingCrane/Drawning/DrawningCraneEqutables.cs b/HoistingCrane/HoistingCrane/Drawning/DrawningCraneEqutables.cs
new file mode 100644
index 0000000..432dd15
--- /dev/null
+++ b/HoistingCrane/HoistingCrane/Drawning/DrawningCraneEqutables.cs
@@ -0,0 +1,32 @@
+using HoistingCrane.Entities;
+using System.Diagnostics.CodeAnalysis;
+
+namespace HoistingCrane.Drawning
+{
+ public class DrawningCraneEqutables : IEqualityComparer
+ {
+ public bool Equals(DrawningTrackedVehicle? x, DrawningTrackedVehicle? y)
+ {
+ if (x == null || x.EntityTrackedVehicle == null) return false;
+ if (y == null || y.EntityTrackedVehicle == null) return false;
+ if (x.GetType().Name != y.GetType().Name) return false;
+ if (x.EntityTrackedVehicle.Speed != y.EntityTrackedVehicle.Speed) return false;
+ if (x.EntityTrackedVehicle.Weight != y.EntityTrackedVehicle.Weight) return false;
+ if (x.EntityTrackedVehicle.BodyColor != y.EntityTrackedVehicle.BodyColor) return false;
+ if ((x.EntityTrackedVehicle as EntityHoistingCrane)!= null && (y.EntityTrackedVehicle as EntityHoistingCrane)!=null)
+ {
+ var newX = x.EntityTrackedVehicle as EntityHoistingCrane;
+ var newY = y.EntityTrackedVehicle as EntityHoistingCrane;
+ if (newX?.AdditionalColor != newY?.AdditionalColor) return false;
+ if (newX?.Platform != newY?.Platform) return false;
+ if (newX?.Counterweight != newY?.Counterweight) return false;
+ }
+ return true;
+ }
+
+ public int GetHashCode([DisallowNull] DrawningTrackedVehicle obj)
+ {
+ return obj.GetHashCode();
+ }
+ }
+}
diff --git a/HoistingCrane/HoistingCrane/Exceptions/ObjectIsPresentInTheCollectionException.cs b/HoistingCrane/HoistingCrane/Exceptions/ObjectIsPresentInTheCollectionException.cs
new file mode 100644
index 0000000..d659852
--- /dev/null
+++ b/HoistingCrane/HoistingCrane/Exceptions/ObjectIsPresentInTheCollectionException.cs
@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace HoistingCrane.Exceptions
+{
+ public class ObjectIsPresentInTheCollectionException : ApplicationException
+ {
+ public ObjectIsPresentInTheCollectionException(object obj) : base("В коллекции уже присустствует объект " + obj) { }
+ public ObjectIsPresentInTheCollectionException() : base() { }
+ public ObjectIsPresentInTheCollectionException(string message) : base(message) { }
+ public ObjectIsPresentInTheCollectionException(string message, Exception exception) : base(message, exception) { }
+ protected ObjectIsPresentInTheCollectionException(SerializationInfo info, StreamingContext context) : base(info, context) { }
+ }
+}
diff --git a/HoistingCrane/HoistingCrane/FormCarCollection.Designer.cs b/HoistingCrane/HoistingCrane/FormCarCollection.Designer.cs
index 4991414..2405784 100644
--- a/HoistingCrane/HoistingCrane/FormCarCollection.Designer.cs
+++ b/HoistingCrane/HoistingCrane/FormCarCollection.Designer.cs
@@ -52,6 +52,8 @@
loadToolStripMenuItem = new ToolStripMenuItem();
saveFileDialog = new SaveFileDialog();
openFileDialog = new OpenFileDialog();
+ buttonSortByType = new Button();
+ buttonSortByColor = new Button();
groupBoxTools.SuspendLayout();
panelCompanyTool.SuspendLayout();
panelStorage.SuspendLayout();
@@ -68,7 +70,7 @@
groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(763, 24);
groupBoxTools.Name = "groupBoxTools";
- groupBoxTools.Size = new Size(210, 485);
+ groupBoxTools.Size = new Size(210, 524);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
@@ -76,20 +78,22 @@
// panelCompanyTool
//
panelCompanyTool.Anchor = AnchorStyles.None;
+ panelCompanyTool.Controls.Add(buttonSortByColor);
+ panelCompanyTool.Controls.Add(buttonSortByType);
panelCompanyTool.Controls.Add(buttonCreateHoistingCrane);
panelCompanyTool.Controls.Add(maskedTextBox);
panelCompanyTool.Controls.Add(buttonRefresh);
panelCompanyTool.Controls.Add(buttonGoToChek);
panelCompanyTool.Controls.Add(buttonDeleteCar);
- panelCompanyTool.Location = new Point(6, 312);
+ panelCompanyTool.Location = new Point(6, 296);
panelCompanyTool.Name = "panelCompanyTool";
- panelCompanyTool.Size = new Size(204, 185);
+ panelCompanyTool.Size = new Size(204, 221);
panelCompanyTool.TabIndex = 8;
//
// buttonCreateHoistingCrane
//
buttonCreateHoistingCrane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonCreateHoistingCrane.Location = new Point(9, 13);
+ buttonCreateHoistingCrane.Location = new Point(6, 3);
buttonCreateHoistingCrane.Name = "buttonCreateHoistingCrane";
buttonCreateHoistingCrane.Size = new Size(192, 22);
buttonCreateHoistingCrane.TabIndex = 0;
@@ -100,7 +104,7 @@
// maskedTextBox
//
maskedTextBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- maskedTextBox.Location = new Point(9, 41);
+ maskedTextBox.Location = new Point(6, 31);
maskedTextBox.Mask = "00";
maskedTextBox.Name = "maskedTextBox";
maskedTextBox.Size = new Size(192, 23);
@@ -109,7 +113,7 @@
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonRefresh.Location = new Point(9, 129);
+ buttonRefresh.Location = new Point(6, 119);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(192, 27);
buttonRefresh.TabIndex = 5;
@@ -120,7 +124,7 @@
// buttonGoToChek
//
buttonGoToChek.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonGoToChek.Location = new Point(9, 99);
+ buttonGoToChek.Location = new Point(6, 89);
buttonGoToChek.Name = "buttonGoToChek";
buttonGoToChek.Size = new Size(192, 24);
buttonGoToChek.TabIndex = 6;
@@ -131,7 +135,7 @@
// buttonDeleteCar
//
buttonDeleteCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonDeleteCar.Location = new Point(9, 70);
+ buttonDeleteCar.Location = new Point(6, 60);
buttonDeleteCar.Name = "buttonDeleteCar";
buttonDeleteCar.Size = new Size(192, 23);
buttonDeleteCar.TabIndex = 4;
@@ -141,7 +145,7 @@
//
// buttonCreateCompany
//
- buttonCreateCompany.Location = new Point(12, 295);
+ buttonCreateCompany.Location = new Point(12, 267);
buttonCreateCompany.Name = "buttonCreateCompany";
buttonCreateCompany.Size = new Size(192, 23);
buttonCreateCompany.TabIndex = 7;
@@ -161,12 +165,12 @@
panelStorage.Dock = DockStyle.Top;
panelStorage.Location = new Point(3, 19);
panelStorage.Name = "panelStorage";
- panelStorage.Size = new Size(204, 229);
+ panelStorage.Size = new Size(204, 216);
panelStorage.TabIndex = 7;
//
// buttonDeleteCollection
//
- buttonDeleteCollection.Location = new Point(9, 199);
+ buttonDeleteCollection.Location = new Point(9, 186);
buttonDeleteCollection.Name = "buttonDeleteCollection";
buttonDeleteCollection.Size = new Size(192, 27);
buttonDeleteCollection.TabIndex = 6;
@@ -178,14 +182,14 @@
//
listBoxCollection.FormattingEnabled = true;
listBoxCollection.ItemHeight = 15;
- listBoxCollection.Location = new Point(9, 118);
+ listBoxCollection.Location = new Point(9, 101);
listBoxCollection.Name = "listBoxCollection";
listBoxCollection.Size = new Size(192, 79);
listBoxCollection.TabIndex = 5;
//
// buttonCollectionAdd
//
- buttonCollectionAdd.Location = new Point(9, 81);
+ buttonCollectionAdd.Location = new Point(9, 72);
buttonCollectionAdd.Name = "buttonCollectionAdd";
buttonCollectionAdd.Size = new Size(192, 23);
buttonCollectionAdd.TabIndex = 4;
@@ -196,7 +200,7 @@
// radioButtonList
//
radioButtonList.AutoSize = true;
- radioButtonList.Location = new Point(128, 56);
+ radioButtonList.Location = new Point(128, 47);
radioButtonList.Name = "radioButtonList";
radioButtonList.Size = new Size(67, 19);
radioButtonList.TabIndex = 3;
@@ -207,7 +211,7 @@
// radioButtonMassive
//
radioButtonMassive.AutoSize = true;
- radioButtonMassive.Location = new Point(18, 56);
+ radioButtonMassive.Location = new Point(12, 47);
radioButtonMassive.Name = "radioButtonMassive";
radioButtonMassive.Size = new Size(69, 19);
radioButtonMassive.TabIndex = 2;
@@ -237,7 +241,7 @@
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectorCompany.FormattingEnabled = true;
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
- comboBoxSelectorCompany.Location = new Point(12, 266);
+ comboBoxSelectorCompany.Location = new Point(12, 238);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(192, 23);
comboBoxSelectorCompany.TabIndex = 2;
@@ -248,7 +252,7 @@
pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 24);
pictureBox.Name = "pictureBox";
- pictureBox.Size = new Size(763, 485);
+ pictureBox.Size = new Size(763, 524);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
@@ -292,11 +296,33 @@
//
openFileDialog.Filter = "txt file | *.txt";
//
+ // buttonSortByType
+ //
+ buttonSortByType.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonSortByType.Location = new Point(6, 152);
+ buttonSortByType.Name = "buttonSortByType";
+ buttonSortByType.Size = new Size(192, 27);
+ buttonSortByType.TabIndex = 7;
+ buttonSortByType.Text = "Сортировка по типу";
+ buttonSortByType.UseVisualStyleBackColor = true;
+ buttonSortByType.Click += buttonSortByType_Click;
+ //
+ // buttonSortByColor
+ //
+ buttonSortByColor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonSortByColor.Location = new Point(6, 185);
+ buttonSortByColor.Name = "buttonSortByColor";
+ buttonSortByColor.Size = new Size(192, 27);
+ buttonSortByColor.TabIndex = 8;
+ buttonSortByColor.Text = "Сортировка по цвету";
+ buttonSortByColor.UseVisualStyleBackColor = true;
+ buttonSortByColor.Click += buttonSortByColor_Click;
+ //
// FormCarCollection
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(973, 509);
+ ClientSize = new Size(973, 548);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Controls.Add(menuStrip);
@@ -341,5 +367,7 @@
private ToolStripMenuItem loadToolStripMenuItem;
private SaveFileDialog saveFileDialog;
private OpenFileDialog openFileDialog;
+ private Button buttonSortByColor;
+ private Button buttonSortByType;
}
}
\ No newline at end of file
diff --git a/HoistingCrane/HoistingCrane/FormCarCollection.cs b/HoistingCrane/HoistingCrane/FormCarCollection.cs
index 318a373..b4cf3d6 100644
--- a/HoistingCrane/HoistingCrane/FormCarCollection.cs
+++ b/HoistingCrane/HoistingCrane/FormCarCollection.cs
@@ -52,7 +52,7 @@ namespace HoistingCrane
MessageBox.Show("Ошибка переполнения коллекции");
logger.LogError("Ошибка: {Message}", ex.Message);
}
-
+
}
private void buttonDeleteCar_Click(object sender, EventArgs e)
@@ -123,7 +123,7 @@ namespace HoistingCrane
listBoxCollection.Items.Clear();
for (int i = 0; i < _storageCollection.Keys?.Count; ++i)
{
- string? colName = _storageCollection.Keys?[i];
+ string? colName = _storageCollection.Keys?[i].name;
if (!string.IsNullOrEmpty(colName))
{
listBoxCollection.Items.Add(colName);
@@ -149,7 +149,8 @@ namespace HoistingCrane
collectionType = CollectionType.List;
logger.LogInformation("Создана коллекция '{nameCol}' , название: {name}", collectionType, textBoxCollectionName.Text);
}
- _storageCollection.AddCollection(textBoxCollectionName.Text,collectionType);RerfreshListBoxItems();
+ _storageCollection.AddCollection(textBoxCollectionName.Text, collectionType);
+ RerfreshListBoxItems();
}
private void buttonDeleteCollection_Click(object sender, EventArgs e)
{
@@ -166,18 +167,18 @@ namespace HoistingCrane
}
_storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
RerfreshListBoxItems();
-
+
}
private void buttonCreateCompany_Click(object sender, EventArgs e)
{
-
- if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
+
+ if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
{
MessageBox.Show("Коллекция не выбрана");
return;
}
ICollectionGenericObjects? collection = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
- if (collection == null)
+ if (collection == null)
{
MessageBox.Show("Коллекция не проинициализирована");
return;
@@ -222,7 +223,7 @@ namespace HoistingCrane
///
private void loadToolStripMenuItem_Click(object sender, EventArgs e)
{
- if(openFileDialog.ShowDialog() == DialogResult.OK)
+ if (openFileDialog.ShowDialog() == DialogResult.OK)
{
try
{
@@ -231,13 +232,30 @@ namespace HoistingCrane
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
logger.LogInformation("Загрузка в файл: {filename}", saveFileDialog.FileName);
}
- catch(Exception ex)
+ catch (Exception ex)
{
MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
logger.LogError("Ошибка: {Message}", ex.Message);
}
}
}
+
+ private void buttonSortByType_Click(object sender, EventArgs e)
+ {
+ compareCars(new DrawningCraneCompareByType());
+ }
+
+ private void buttonSortByColor_Click(object sender, EventArgs e)
+ {
+ compareCars(new DrawningCraneCompareByColor());
+ }
+
+ private void compareCars(IComparer comparer)
+ {
+ if (_company == null) return;
+ _company.Sort(comparer);
+ pictureBox.Image = _company.Show();
+ }
}
}
--
2.25.1
From 84b3e6f21e3ba4ea1febf7b8e096bd096cde82d5 Mon Sep 17 00:00:00 2001
From: sqdselo <147947144+sqdselo@users.noreply.github.com>
Date: Mon, 6 May 2024 23:02:05 +0400
Subject: [PATCH 15/17] =?UTF-8?q?=D0=B4=D0=BE=D0=BF=D0=BA=D0=B0=D0=93?=
=?UTF-8?q?=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=BE?=
=?UTF-8?q?=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0?=
=?UTF-8?q?=D0=B1=D0=BE=D1=82=D0=B0=207?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../AbstractCompany.cs | 2 +-
.../HoistingCrane/FormCarCollection.cs | 10 ++++----
.../HoistingCrane/HoistingCrane.csproj | 5 +++-
HoistingCrane/HoistingCrane/Program.cs | 24 ++++++++++++++-----
HoistingCrane/HoistingCrane/serilog.json | 18 ++++++++++++++
ФайлДляЛабы.txt | 2 ++
6 files changed, 48 insertions(+), 13 deletions(-)
create mode 100644 HoistingCrane/HoistingCrane/serilog.json
create mode 100644 ФайлДляЛабы.txt
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs
index fb26d02..10711a6 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs
@@ -30,7 +30,7 @@ namespace HoistingCrane.CollectionGenericObjects
{
get
{
- return (pictureWidth * pictureHeight) / (_placeSizeHeight * _placeSizeWidth)-2;
+ return (pictureWidth / _placeSizeWidth) * (pictureHeight / _placeSizeHeight);
}
}
public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects array)
diff --git a/HoistingCrane/HoistingCrane/FormCarCollection.cs b/HoistingCrane/HoistingCrane/FormCarCollection.cs
index 318a373..bde17ab 100644
--- a/HoistingCrane/HoistingCrane/FormCarCollection.cs
+++ b/HoistingCrane/HoistingCrane/FormCarCollection.cs
@@ -44,7 +44,7 @@ namespace HoistingCrane
else
{
MessageBox.Show("Не удалось добавить объект");
- logger.LogInformation("Не удалось добавить корабль {ship} в коллекцию", drawningTrackedVehicle.GetType().Name);
+ logger.LogInformation("Не удалось добавить кран {crane} в коллекцию", drawningTrackedVehicle.GetType().Name);
}
}
catch (CollectionOverflowException ex)
@@ -142,12 +142,12 @@ namespace HoistingCrane
if (radioButtonMassive.Checked)
{
collectionType = CollectionType.Massive;
- logger.LogInformation("Создана коллекция '{nameCol}' , название: {name}", collectionType, textBoxCollectionName.Text);
+ logger.LogInformation("Создана коллекция {nameCol} , название: {name}", collectionType, textBoxCollectionName.Text);
}
else if (radioButtonList.Checked)
{
collectionType = CollectionType.List;
- logger.LogInformation("Создана коллекция '{nameCol}' , название: {name}", collectionType, textBoxCollectionName.Text);
+ logger.LogInformation("Создана коллекция {nameCol} , название: {name}", collectionType, textBoxCollectionName.Text);
}
_storageCollection.AddCollection(textBoxCollectionName.Text,collectionType);RerfreshListBoxItems();
}
@@ -205,7 +205,7 @@ namespace HoistingCrane
{
_storageCollection.SaveData(saveFileDialog.FileName);
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
- logger.LogInformation("Сохранение в файл: {filename}", saveFileDialog.FileName);
+ logger.LogInformation("Сохранение в файл: {filename}", saveFileDialog.FileName.ToString());
}
catch (Exception ex)
{
@@ -229,7 +229,7 @@ namespace HoistingCrane
_storageCollection.LoadData(openFileDialog.FileName);
RerfreshListBoxItems();
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
- logger.LogInformation("Загрузка в файл: {filename}", saveFileDialog.FileName);
+ logger.LogInformation("Загрузка из файла: {filename}", saveFileDialog.FileName.ToString());
}
catch(Exception ex)
{
diff --git a/HoistingCrane/HoistingCrane/HoistingCrane.csproj b/HoistingCrane/HoistingCrane/HoistingCrane.csproj
index 9b3b27e..3f2e375 100644
--- a/HoistingCrane/HoistingCrane/HoistingCrane.csproj
+++ b/HoistingCrane/HoistingCrane/HoistingCrane.csproj
@@ -13,8 +13,11 @@
+
+
-
+
+
diff --git a/HoistingCrane/HoistingCrane/Program.cs b/HoistingCrane/HoistingCrane/Program.cs
index 562ee2d..48fac59 100644
--- a/HoistingCrane/HoistingCrane/Program.cs
+++ b/HoistingCrane/HoistingCrane/Program.cs
@@ -1,8 +1,7 @@
+using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Serilog;
-using Serilog.Extensions.Logging;
-
namespace HoistingCrane
{
internal static class Program
@@ -18,11 +17,24 @@ namespace HoistingCrane
}
private static void ConfigureServices(ServiceCollection services)
{
- // Serilog
- Log.Logger = new LoggerConfiguration().WriteTo.File("E:\\myLog.log").CreateLogger();
- services.AddSingleton().AddLogging(builder =>
+
+ string[] path = Directory.GetCurrentDirectory().Split('\\');
+ string pathNeed = "";
+ for (int i = 0; i < path.Length - 3; i++)
{
- builder.AddSerilog();
+ pathNeed += path[i] + "\\";
+ }
+
+
+ services.AddSingleton()
+ .AddLogging(option =>
+ {
+ option.SetMinimumLevel(LogLevel.Information);
+ option.AddSerilog(new LoggerConfiguration()
+ .ReadFrom.Configuration(new ConfigurationBuilder()
+ .AddJsonFile($"{pathNeed}serilog.json")
+ .Build())
+ .CreateLogger());
});
}
}
diff --git a/HoistingCrane/HoistingCrane/serilog.json b/HoistingCrane/HoistingCrane/serilog.json
new file mode 100644
index 0000000..a8648e8
--- /dev/null
+++ b/HoistingCrane/HoistingCrane/serilog.json
@@ -0,0 +1,18 @@
+
+{
+ "Serilog": {
+ "Using": [ "Serilog.Sinks.File" ],
+ "MinimumLevel": "Debug",
+ "WriteTo": [
+ {
+ "Name": "File",
+ "Args": {
+ "path": "log.log"
+ }
+ }
+ ],
+ "Properties": {
+ "Application": "Sample"
+ }
+ }
+}
diff --git a/ФайлДляЛабы.txt b/ФайлДляЛабы.txt
new file mode 100644
index 0000000..f37cd75
--- /dev/null
+++ b/ФайлДляЛабы.txt
@@ -0,0 +1,2 @@
+CollectionsStorage
+массив|Massive|25|EntityTrackedVehicle:100:100:White;EntityTrackedVehicle:100:100:Yellow;EntityTrackedVehicle:100:100:Purple;EntityHoistingCrane:100:100:Gray:Black:True:False;EntityTrackedVehicle:100:100:White;EntityTrackedVehicle:100:100:White;EntityHoistingCrane:100:100:Green:Black:False:False;EntityTrackedVehicle:100:100:Gray;EntityTrackedVehicle:100:100:Red;EntityHoistingCrane:100:100:White:Black:False:False;EntityHoistingCrane:100:100:Green:Blue:True:False;EntityHoistingCrane:100:100:Black:Black:True:True;EntityTrackedVehicle:100:100:White;EntityTrackedVehicle:100:100:Purple;EntityTrackedVehicle:100:100:Black;EntityTrackedVehicle:100:100:Blue;EntityTrackedVehicle:100:100:Gray;EntityTrackedVehicle:100:100:Red;EntityTrackedVehicle:100:100:Purple;EntityTrackedVehicle:100:100:Green;EntityTrackedVehicle:100:100:Purple;EntityTrackedVehicle:100:100:Yellow;EntityTrackedVehicle:100:100:Blue;EntityTrackedVehicle:100:100:Gray;
\ No newline at end of file
--
2.25.1
From e4d751e638c6e54565c8f4370dbc2e1579bd67dd Mon Sep 17 00:00:00 2001
From: Timur_Sharafutdinov
Date: Mon, 13 May 2024 13:45:27 +0400
Subject: [PATCH 16/17] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0?=
=?UTF-8?q?=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80?=
=?UTF-8?q?=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=207?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
HoistingCrane/HoistingCrane/serilog.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/HoistingCrane/HoistingCrane/serilog.json b/HoistingCrane/HoistingCrane/serilog.json
index a8648e8..e76e9c8 100644
--- a/HoistingCrane/HoistingCrane/serilog.json
+++ b/HoistingCrane/HoistingCrane/serilog.json
@@ -15,4 +15,4 @@
"Application": "Sample"
}
}
-}
+}
\ No newline at end of file
--
2.25.1
From 0d5ea4481fee4c7d720bfe71c8cfdaa1cd37ba62 Mon Sep 17 00:00:00 2001
From: sqdselo <147947144+sqdselo@users.noreply.github.com>
Date: Wed, 5 Jun 2024 06:51:03 +0400
Subject: [PATCH 17/17] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0?=
=?UTF-8?q?=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80?=
=?UTF-8?q?=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=208?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../AbstractCompany.cs | 6 +-
.../ICollectionGenericObjects.cs | 4 +-
.../ListGenericObjects.cs | 48 ++++----
.../MassivGenericObjects.cs | 107 ++++++++++--------
.../Drawning/DrawningCraneCompareByColor.cs | 5 +-
.../Drawning/StorageEqutables.cs | 12 ++
...ObjectIsPresentInTheCollectionException.cs | 12 +-
.../HoistingCrane/FormCarCollection.cs | 4 +-
.../HoistingCrane/HoistingCrane.csproj | 1 +
HoistingCrane/HoistingCrane/Program.cs | 26 +++--
HoistingCrane/HoistingCrane/serilog.json | 17 +++
11 files changed, 150 insertions(+), 92 deletions(-)
create mode 100644 HoistingCrane/HoistingCrane/Drawning/StorageEqutables.cs
create mode 100644 HoistingCrane/HoistingCrane/serilog.json
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs
index 94b5609..9608211 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs
@@ -30,7 +30,7 @@ namespace HoistingCrane.CollectionGenericObjects
{
get
{
- return (pictureWidth * pictureHeight) / (_placeSizeHeight * _placeSizeWidth)-2;
+ return (pictureWidth / _placeSizeWidth) * (pictureHeight * _placeSizeHeight);
}
}
public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects array)
@@ -42,11 +42,11 @@ namespace HoistingCrane.CollectionGenericObjects
}
public static int operator +(AbstractCompany company, DrawningTrackedVehicle car)
{
- return company.arr?.Insert(car, new DrawningCraneEqutables()) ?? -1;
+ return company.arr.Insert(car, new DrawningCraneEqutables());
}
public static DrawningTrackedVehicle operator -(AbstractCompany company, int position)
{
- return company.arr?.Remove(position) ?? null;
+ return company.arr?.Remove(position);
}
public DrawningTrackedVehicle? GetRandomObject()
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs
index 1fb465a..02a42a6 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -19,7 +19,7 @@ namespace HoistingCrane.CollectionGenericObjects
///
/// /// Сравнение двух объектов
///
- int Insert(T obj, IEqualityComparer? comparer = null);
+ int Insert(T obj, IEqualityComparer? comparer = null);
///
/// Добавление элемента в коллекцию на определенную позицию
///
@@ -27,7 +27,7 @@ namespace HoistingCrane.CollectionGenericObjects
///
/// Сравнение двух объектов
///
- int Insert(T obj, int position, IEqualityComparer? comparer = null);
+ int Insert(T obj, int position, IEqualityComparer? comparer = null);
///
/// Удаление элемента из коллекции по его позиции
///
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs
index 66feeeb..99d6afb 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs
@@ -46,36 +46,42 @@ namespace HoistingCrane.CollectionGenericObjects
if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
return list[position];
}
-
- public int Insert(T obj, IEqualityComparer? comparer = null)
+ public int Insert(T obj, IEqualityComparer? comparer = null)
{
- // TODO выброс ошибки, если такой объект есть в коллекции
- if (comparer != null && list.Contains(obj))
+ try
{
- throw new ObjectIsPresentInTheCollectionException(obj);
+ if (list.Contains(obj, comparer)) throw new ObjectIsPresentInTheCollectionException(Count);
+ if (Count == _maxCount) throw new CollectionOverflowException(Count);
+ list.Add(obj);
+ return Count - 1;
}
- if (list.Count >= _maxCount)
+ catch (ObjectIsPresentInTheCollectionException ex)
{
- throw new CollectionOverflowException(_maxCount);
+ MessageBox.Show(ex.Message);
+ return -1;
}
- list.Add(obj);
- return _maxCount;
}
-
- public int Insert(T obj, int position, IEqualityComparer? comparer = null)
+ public int Insert(T obj, int position, IEqualityComparer? comparer = null)
{
- if (comparer != null && list.Contains(obj))
+ try
{
- throw new ObjectIsPresentInTheCollectionException();
+ if (comparer != null && list.Contains(obj, comparer))
+ {
+ throw new ObjectIsPresentInTheCollectionException(Count);
+ }
+
+ if (Count == _maxCount) throw new CollectionOverflowException(Count);
+
+ if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
+
+ list.Insert(position, obj);
+ return position;
+ }
+ catch (ObjectIsPresentInTheCollectionException ex)
+ {
+ Console.WriteLine(ex.Message);
+ return -1;
}
- if (Count >= _maxCount)
- throw new CollectionOverflowException(_maxCount);
-
- if (position < 0 || position >= _maxCount)
- throw new PositionOutOfCollectionException(position);
-
- list.Insert(position, obj);
- return position;
}
public T? Remove(int position)
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs
index f96e396..316bd4c 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs
@@ -1,9 +1,10 @@
using HoistingCrane.Drawning;
using HoistingCrane.Exceptions;
+using System.Linq;
namespace HoistingCrane.CollectionGenericObjects
{
- public class MassivGenericObjects : ICollectionGenericObjects where T : class
+ public class MassivGenericObjects : ICollectionGenericObjects where T : DrawningTrackedVehicle
{
private T?[] arr;
public MassivGenericObjects()
@@ -43,68 +44,83 @@ namespace HoistingCrane.CollectionGenericObjects
if (position < 0 || position >= Count) throw new PositionOutOfCollectionException(position);
return arr[position];
}
-
- public int Insert(T obj, IEqualityComparer? comparer = null)
+ public int Insert(T obj, IEqualityComparer? comparer = null)
{
- if (comparer != null)
+ try
{
- foreach (T? item in arr)
+ if (arr.Contains(obj, comparer))
{
- if ((comparer as IEqualityComparer).Equals(obj as DrawningTrackedVehicle, item as DrawningTrackedVehicle))
- throw new ObjectIsPresentInTheCollectionException();
+ throw new ObjectIsPresentInTheCollectionException();
}
+ for (int i = 0; i < Count; ++i)
+ {
+ if (arr[i] == null)
+ {
+ arr[i] = obj;
+ return i;
+ }
+ }
+ throw new CollectionOverflowException(Count);
}
- int index = 0;
- while (index < arr.Length)
+ catch (ObjectIsPresentInTheCollectionException ex)
{
- if (arr[index] == null)
- {
- arr[index] = obj;
- return index;
- }
- index++;
+ MessageBox.Show(ex.Message);
+ return -1;
}
- throw new CollectionOverflowException(Count);
+
}
- public int Insert(T obj, int position, IEqualityComparer? comparer = null)
+ public int Insert(T obj, int position, IEqualityComparer? comparer = null)
{
- if (comparer != null)
+ try
{
- foreach (T? item in arr)
+ if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
+ if (comparer != null)
{
- if ((comparer as IEqualityComparer).Equals(obj as DrawningTrackedVehicle, item as DrawningTrackedVehicle))
- throw new ObjectIsPresentInTheCollectionException();
+ for (int i = 0; i < Count; i++)
+ {
+ if (comparer.Equals(arr[i], obj))
+ {
+ throw new ObjectIsPresentInTheCollectionException();
+ }
+ }
}
- }
- if (position >= arr.Length || position < 0) throw new PositionOutOfCollectionException(position);
-
- if (arr[position] == null)
- {
- arr[position] = obj;
- return position;
- }
- int index = position + 1;
- while (index < arr.Length)
- {
- if (arr[index] == null)
+ if (arr[position] == null)
{
- arr[index] = obj;
- return index;
+ arr[position] = obj;
+ return position;
}
- index++;
- }
- index = position - 1;
- while (index >= 0)
- {
- if (arr[index] == null)
+ else
{
- arr[index] = obj;
- return index;
+ for (int i = 1; i < Count; ++i)
+ {
+ if (arr[position + i] == null)
+ {
+ arr[position + i] = obj;
+ return position + i;
+ }
+ for (i = position - 1; i >= 0; i--)
+ {
+ if (arr[i] == null)
+ {
+ arr[i] = obj;
+ return i;
+ }
+ }
+ }
}
- index--;
+ throw new CollectionOverflowException(Count);
+ }
+ catch (PositionOutOfCollectionException ex)
+ {
+ MessageBox.Show(ex.Message);
+ return -1;
+ }
+ catch (ObjectIsPresentInTheCollectionException ex)
+ {
+ MessageBox.Show(ex.Message);
+ return -1;
}
- throw new CollectionOverflowException(Count);
}
public T? Remove(int position)
@@ -127,6 +143,7 @@ namespace HoistingCrane.CollectionGenericObjects
{
T[] notNullArr = arr.OfType().ToArray();
Array.Sort(notNullArr, comparer);
+ Array.Copy(notNullArr, 0, arr, 0, notNullArr.Length);
}
}
}
diff --git a/HoistingCrane/HoistingCrane/Drawning/DrawningCraneCompareByColor.cs b/HoistingCrane/HoistingCrane/Drawning/DrawningCraneCompareByColor.cs
index 8e76d17..9902054 100644
--- a/HoistingCrane/HoistingCrane/Drawning/DrawningCraneCompareByColor.cs
+++ b/HoistingCrane/HoistingCrane/Drawning/DrawningCraneCompareByColor.cs
@@ -4,11 +4,10 @@
{
public int Compare(DrawningTrackedVehicle? x, DrawningTrackedVehicle? y)
{
- //TODO: Прописать логику сравнения по цветам, скорости и весу
if (x == null || x.EntityTrackedVehicle == null) return -1;
if (y == null || y.EntityTrackedVehicle == null) return 1;
- var colorCompare = x.EntityTrackedVehicle.BodyColor.ToArgb().CompareTo(y.EntityTrackedVehicle.BodyColor.ToArgb());
- if (colorCompare != 0) return colorCompare;
+ if (x.EntityTrackedVehicle.BodyColor.Name != y.EntityTrackedVehicle.BodyColor.Name)
+ return x.EntityTrackedVehicle.BodyColor.Name.CompareTo(y.EntityTrackedVehicle.BodyColor.Name);
var speedCompare = x.EntityTrackedVehicle.Speed.CompareTo(y.EntityTrackedVehicle.Speed);
if (speedCompare != 0) return speedCompare;
return x.EntityTrackedVehicle.Weight.CompareTo(y.EntityTrackedVehicle.Weight);
diff --git a/HoistingCrane/HoistingCrane/Drawning/StorageEqutables.cs b/HoistingCrane/HoistingCrane/Drawning/StorageEqutables.cs
new file mode 100644
index 0000000..c4788f2
--- /dev/null
+++ b/HoistingCrane/HoistingCrane/Drawning/StorageEqutables.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace HoistingCrane.Drawning
+{
+ internal class StorageEqutables
+ {
+ }
+}
diff --git a/HoistingCrane/HoistingCrane/Exceptions/ObjectIsPresentInTheCollectionException.cs b/HoistingCrane/HoistingCrane/Exceptions/ObjectIsPresentInTheCollectionException.cs
index d659852..1175102 100644
--- a/HoistingCrane/HoistingCrane/Exceptions/ObjectIsPresentInTheCollectionException.cs
+++ b/HoistingCrane/HoistingCrane/Exceptions/ObjectIsPresentInTheCollectionException.cs
@@ -1,17 +1,11 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Runtime.Serialization;
-using System.Text;
-using System.Threading.Tasks;
-
+using System.Runtime.Serialization;
namespace HoistingCrane.Exceptions
{
+ [Serializable]
public class ObjectIsPresentInTheCollectionException : ApplicationException
{
- public ObjectIsPresentInTheCollectionException(object obj) : base("В коллекции уже присустствует объект " + obj) { }
+ public ObjectIsPresentInTheCollectionException(int objName) : base("В коллекции уже присустствует объект " + objName) { }
public ObjectIsPresentInTheCollectionException() : base() { }
- public ObjectIsPresentInTheCollectionException(string message) : base(message) { }
public ObjectIsPresentInTheCollectionException(string message, Exception exception) : base(message, exception) { }
protected ObjectIsPresentInTheCollectionException(SerializationInfo info, StreamingContext context) : base(info, context) { }
}
diff --git a/HoistingCrane/HoistingCrane/FormCarCollection.cs b/HoistingCrane/HoistingCrane/FormCarCollection.cs
index b4cf3d6..3287d4b 100644
--- a/HoistingCrane/HoistingCrane/FormCarCollection.cs
+++ b/HoistingCrane/HoistingCrane/FormCarCollection.cs
@@ -43,8 +43,8 @@ namespace HoistingCrane
}
else
{
- MessageBox.Show("Не удалось добавить объект");
- logger.LogInformation("Не удалось добавить корабль {ship} в коллекцию", drawningTrackedVehicle.GetType().Name);
+ //MessageBox.Show("Не удалось добавить объект");
+ logger.LogInformation("Не удалось добавить кран {crane} в коллекцию", drawningTrackedVehicle.GetType().Name);
}
}
catch (CollectionOverflowException ex)
diff --git a/HoistingCrane/HoistingCrane/HoistingCrane.csproj b/HoistingCrane/HoistingCrane/HoistingCrane.csproj
index 9b3b27e..780fadb 100644
--- a/HoistingCrane/HoistingCrane/HoistingCrane.csproj
+++ b/HoistingCrane/HoistingCrane/HoistingCrane.csproj
@@ -13,6 +13,7 @@
+
diff --git a/HoistingCrane/HoistingCrane/Program.cs b/HoistingCrane/HoistingCrane/Program.cs
index 562ee2d..b2baa34 100644
--- a/HoistingCrane/HoistingCrane/Program.cs
+++ b/HoistingCrane/HoistingCrane/Program.cs
@@ -1,8 +1,7 @@
+using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Serilog;
-using Serilog.Extensions.Logging;
-
namespace HoistingCrane
{
internal static class Program
@@ -18,12 +17,25 @@ namespace HoistingCrane
}
private static void ConfigureServices(ServiceCollection services)
{
- // Serilog
- Log.Logger = new LoggerConfiguration().WriteTo.File("E:\\myLog.log").CreateLogger();
- services.AddSingleton().AddLogging(builder =>
+
+ string[] path = Directory.GetCurrentDirectory().Split('\\');
+ string pathNeed = "";
+ for (int i = 0; i < path.Length - 3; i++)
{
- builder.AddSerilog();
+ pathNeed += path[i] + "\\";
+ }
+
+
+ services.AddSingleton()
+ .AddLogging(option =>
+ {
+ option.SetMinimumLevel(LogLevel.Information);
+ option.AddSerilog(new LoggerConfiguration()
+ .ReadFrom.Configuration(new ConfigurationBuilder()
+ .AddJsonFile($"{pathNeed}serilog.json")
+ .Build())
+ .CreateLogger());
});
}
}
-}
+}
\ No newline at end of file
diff --git a/HoistingCrane/HoistingCrane/serilog.json b/HoistingCrane/HoistingCrane/serilog.json
new file mode 100644
index 0000000..6660c8d
--- /dev/null
+++ b/HoistingCrane/HoistingCrane/serilog.json
@@ -0,0 +1,17 @@
+{
+ "Serilog": {
+ "Using": [ "Serilog.Sinks.File" ],
+ "MinimumLevel": "Debug",
+ "WriteTo": [
+ {
+ "Name": "File",
+ "Args": {
+ "path": "log.log"
+ }
+ }
+ ],
+ "Properties": {
+ "Application": "Sample"
+ }
+ }
+}
\ No newline at end of file
--
2.25.1