PIbd-13 BelkinaM.I. LabWork04 Simple #4

Closed
BelkinaMaria wants to merge 3 commits from Lab4 into Lab3
9 changed files with 570 additions and 121 deletions

View File

@ -63,9 +63,9 @@ public abstract class AbstractCompany
/// <param name="company">Компания</param>
/// <param name="dozer">Добавляемый объект</param>
/// <returns></returns>
public static bool operator +(AbstractCompany company, DrawningDozer dozer)
public static int operator +(AbstractCompany company, DrawningDozer dozer)
{
return company._collection?.Insert(dozer) ?? false;
return company._collection.Insert(dozer);
}
/// <summary>
@ -74,9 +74,9 @@ public abstract class AbstractCompany
/// <param name="company">Компания</param>
/// <param name="position">Номер удаляемого объекта</param>
/// <returns></returns>
public static bool operator -(AbstractCompany company, int position)
public static DrawningDozer? operator -(AbstractCompany company, int position)
{
return company._collection?.Remove(position) ?? false;
return company._collection.Remove(position);
}
/// <summary>
@ -100,7 +100,8 @@ public abstract class AbstractCompany
DrawBackground(graphics);
SetObjectsPosition();
for (int i = 0; i < (_collection?.Count ?? 0); i++) {
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
{
DrawningDozer? obj = _collection?.Get(i);
obj?.DrawTransport(graphics);
}

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectBulldozer.CollectionGenericObjects;
/// <summary>
/// Тип коллекции
/// </summary>
public enum CollectionType
{
/// <summary>
/// Неопределено
/// </summary>
None = 0,
/// <summary>
/// Массив
/// </summary>
Massive = 1,
/// <summary>
/// Список
/// </summary>
List = 2
}

View File

@ -31,8 +31,10 @@ public class Garage : AbstractCompany
{
int cntVertically = _pictureHeight / _placeSizeHeight; //Колличество мест по вертикали
int cntHorizontally = _pictureWidth / _placeSizeWidth; //Колличество мест по горизонтали
Pen pen = new Pen(Color.FromArgb(185, 140, 0));
pen.Width = 3;
Pen pen = new(Color.FromArgb(185, 140, 0))
{
Width = 3
};
for (int i = 0; i < cntHorizontally; i++)
{
@ -78,7 +80,5 @@ public class Garage : AbstractCompany
placeVertically--;
}
}
//throw new NotImplementedException();
}
}

View File

@ -28,7 +28,7 @@ public interface ICollectoinGenericObjects<T>
/// </summary>
/// <param name="obj">Добавляемый объект</param>
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
bool Insert(T obj);
int Insert(T obj);
/// <summary>
/// Добавление объекта в коллекцию на конкретную позицию
@ -36,14 +36,14 @@ public interface ICollectoinGenericObjects<T>
/// <param name="obj">Добавляемый объект</param>
/// <param name="position">Позиция</param>
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
bool Insert(T obj, int position);
int Insert(T obj, int position);
/// <summary>
/// Удаление объекта из коллекции на конкретной позиции
/// </summary>
/// <param name="position">Позиция</param>
/// <returns></returns>
bool Remove(int position);
T? Remove(int position);
/// <summary>
/// Получение объекта по позиции

View File

@ -0,0 +1,93 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectBulldozer.CollectionGenericObjects;
/// <summary>
/// Параметрезированный набор объектов
/// </summary>
/// <typeparam name="T">Параметр: ограничение - ссылочный тип</typeparam>
public class ListGenericObjects<T> : ICollectoinGenericObjects<T>
where T : class
{
/// <summary>
/// Список объектов, которые храним
/// </summary>
private readonly List<T?> _collection;
/// <summary>
/// Максимально допустимое число объектов в списке
/// </summary>
private int _maxCount;
public int Count => _collection.Count;
public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } }
/// <summary>
/// Конструктор
/// </summary>
public ListGenericObjects()
{
_collection = new();
}
public T? Get(int position)
{
// Проверка позиции.
if (position < 0 || position >= _collection.Count || _collection == null || _collection.Count == 0)
{
return null;
}
return _collection[position];
}
public int Insert(T obj)
{
// Проверка, что не привышено максимальное колличество элементов.
if (Count == _maxCount)
{
return -1;
}
// Вставка в конец набора.
_collection.Add(obj);
return _collection.Count;
}
public int Insert(T obj, int position)
{
// Проверка, что не превышено максимальное колличество элементов.
if (Count == _maxCount)
{
return -1;
}
// Проверка позиции.
if (position < 0 || position >= _collection.Count || _collection == null || _collection.Count == 0) //TODO проверить, что если заменить _Collection.Count на Count
{
return -1;
}
// Вставка по позиции.
_collection.Insert(position, obj);
return position;
}
public T? Remove(int position)
{
// Проверка позиции.
if (position < 0 || position >= _collection.Count || _collection == null || _collection.Count == 0)
{
return null;
}
// Удаление объекта из списка.
T? obj = _collection[position];
_collection[position] = null;
return obj;
}
}

View File

@ -22,11 +22,14 @@ public class MassiveGenericObject<T> : ICollectoinGenericObjects<T>
{
if (value > 0)
{
Array.Resize(ref _collection, value);
}
else
{
_collection =new T?[value];
if (_collection.Length > 0)
{
Array.Resize(ref _collection, value);
}
else
{
_collection = new T[value];
}
}
}
}
@ -52,7 +55,7 @@ public class MassiveGenericObject<T> : ICollectoinGenericObjects<T>
}
}
public bool Insert(T obj)
public int Insert(T obj)
{
//Вставка в свободное место набора
for (int i = 0; i < Count; i++)
@ -60,19 +63,19 @@ public class MassiveGenericObject<T> : ICollectoinGenericObjects<T>
if (_collection[i] == null)
{
_collection[i] = obj;
return true;
return i;
}
}
return false;
return -1;
}
public bool Insert(T obj, int position)
public int Insert(T obj, int position)
{
//Проверка позиции
if ((position < 0) || (position >= Count))
{
return false;
return -1;
}
//Проверка, что элемент массива по этой позиции пустой, если нет, то ищется свободное место после этой
@ -105,25 +108,26 @@ public class MassiveGenericObject<T> : ICollectoinGenericObjects<T>
if (placed == false)
{
return false;
return -1;
}
}
//Вставка
_collection[position] = obj;
return true;
return position;
}
public bool Remove(int position)
public T? Remove(int position)
{
//Проверка позиции
if ((position < 0) || (position >= Count) || (_collection[position] == null))
{
return false;
return null;
}
//Удаление объекта из массива, присвоив элементу массива значение null
T? elem = _collection[position];
_collection[position] = null;
return true;
return elem;
}
}

View File

@ -0,0 +1,87 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectBulldozer.CollectionGenericObjects;
/// <summary>
/// Класс-хранилище коллекций
/// </summary>
/// <typeparam name="T"></typeparam>
public class StorageCollection<T>
where T : class
{
/// <summary>
/// Словарь (хранилище) с коллекциями
/// </summary>
readonly Dictionary<string, ICollectoinGenericObjects<T>> _storages;
/// <summary>
/// Вщзвращение списка названий коллекций
/// </summary>
public List<string> Keys => _storages.Keys.ToList();
/// <summary>
/// Конструктор
/// </summary>
public StorageCollection()
{
_storages = new Dictionary<string, ICollectoinGenericObjects<T>>();
}
/// <summary>
/// Добавление коллекции в хранилище
/// </summary>
/// <param name="name">название коллекции</param>
/// <param name="collectionType">тип коллекции</param>
public void AddCollection(string name, CollectionType collectionType)
{
// Проверка, что name не пустой и нет в словаре записи с таким ключом.
if (_storages.ContainsKey(name) && name == "")
{
return;
}
// Логика для добавления.
if (collectionType == CollectionType.Massive)
{
_storages[name] = new MassiveGenericObject<T>();
}
else
{
_storages[name] = new ListGenericObjects<T>();
}
}
/// <summary>
/// Удаление коллекции
/// </summary>
/// <param name="name">Название коллекции</param>
public void DelCollection(string name)
{
// Логика для удаления коллекции.
if (_storages.ContainsKey(name))
{
_storages.Remove(name);
}
}
/// <summary>
/// Доступ к коллекции
/// </summary>
/// <param name="name">Название коллекции</param>
/// <returns></returns>
public ICollectoinGenericObjects<T>? this[string name]
{
get
{
// Логика получения объекта.
if (_storages.ContainsKey(name))
{
return _storages[name];
}
return null;
}
}
}

View File

@ -29,96 +29,64 @@
private void InitializeComponent()
{
groupBoxTools = new GroupBox();
maskedTextBox = new MaskedTextBox();
buttonRefresh = new Button();
buttonGoToCheck = new Button();
buttonDelBulldozer = new Button();
buttonAddBulldozer = new Button();
panelCompanyTools = new Panel();
buttonAddDozer = new Button();
buttonAddBulldozer = new Button();
buttonDelBulldozer = new Button();
maskedTextBox = new MaskedTextBox();
buttonGoToCheck = new Button();
buttonRefresh = new Button();
panelStorage = new Panel();
listBoxCollection = new ListBox();
buttonCollectionDel = new Button();
buttonCollectionAdd = new Button();
radioButtonList = new RadioButton();
radioButtonMassive = new RadioButton();
textBoxCollectionName = new TextBox();
labelCollectionName = new Label();
buttonCreateCompany = new Button();
comboBoxSelectorCompany = new ComboBox();
pictureBox = new PictureBox();
groupBoxTools.SuspendLayout();
panelCompanyTools.SuspendLayout();
panelStorage.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
SuspendLayout();
//
// groupBoxTools
//
groupBoxTools.Controls.Add(maskedTextBox);
groupBoxTools.Controls.Add(buttonRefresh);
groupBoxTools.Controls.Add(buttonGoToCheck);
groupBoxTools.Controls.Add(buttonDelBulldozer);
groupBoxTools.Controls.Add(buttonAddBulldozer);
groupBoxTools.Controls.Add(buttonAddDozer);
groupBoxTools.Controls.Add(panelCompanyTools);
groupBoxTools.Controls.Add(panelStorage);
groupBoxTools.Controls.Add(buttonCreateCompany);
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point);
groupBoxTools.Location = new Point(1290, 0);
groupBoxTools.Name = "groupBoxTools";
groupBoxTools.Size = new Size(358, 914);
groupBoxTools.Size = new Size(358, 1051);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
// maskedTextBox
// panelCompanyTools
//
maskedTextBox.Location = new Point(14, 340);
maskedTextBox.Name = "maskedTextBox";
maskedTextBox.Size = new Size(332, 39);
maskedTextBox.TabIndex = 5;
maskedTextBox.ValidatingType = typeof(int);
//
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRefresh.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point);
buttonRefresh.Location = new Point(14, 719);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(332, 63);
buttonRefresh.TabIndex = 3;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += ButtonRefresh_Click;
//
// buttonGoToCheck
//
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonGoToCheck.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point);
buttonGoToCheck.Location = new Point(14, 520);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(332, 63);
buttonGoToCheck.TabIndex = 3;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
buttonGoToCheck.Click += ButtonGoToCheck_Click;
//
// buttonDelBulldozer
//
buttonDelBulldozer.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonDelBulldozer.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point);
buttonDelBulldozer.Location = new Point(14, 385);
buttonDelBulldozer.Name = "buttonDelBulldozer";
buttonDelBulldozer.Size = new Size(332, 63);
buttonDelBulldozer.TabIndex = 3;
buttonDelBulldozer.Text = "Удаленить бульдозер";
buttonDelBulldozer.UseVisualStyleBackColor = true;
buttonDelBulldozer.Click += ButtonDelBulldozer_Click;
//
// buttonAddBulldozer
//
buttonAddBulldozer.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddBulldozer.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point);
buttonAddBulldozer.Location = new Point(14, 210);
buttonAddBulldozer.Name = "buttonAddBulldozer";
buttonAddBulldozer.Size = new Size(332, 79);
buttonAddBulldozer.TabIndex = 3;
buttonAddBulldozer.Text = "Добавление крутого бульдозера";
buttonAddBulldozer.UseVisualStyleBackColor = true;
buttonAddBulldozer.Click += ButtonAddBulldozer_Click;
panelCompanyTools.Controls.Add(buttonAddDozer);
panelCompanyTools.Controls.Add(buttonAddBulldozer);
panelCompanyTools.Controls.Add(buttonDelBulldozer);
panelCompanyTools.Controls.Add(maskedTextBox);
panelCompanyTools.Controls.Add(buttonGoToCheck);
panelCompanyTools.Controls.Add(buttonRefresh);
panelCompanyTools.Enabled = false;
panelCompanyTools.Location = new Point(3, 624);
panelCompanyTools.Name = "panelCompanyTools";
panelCompanyTools.Size = new Size(400, 449);
panelCompanyTools.TabIndex = 7;
//
// buttonAddDozer
//
buttonAddDozer.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddDozer.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
buttonAddDozer.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point);
buttonAddDozer.Location = new Point(14, 140);
buttonAddDozer.Location = new Point(11, 14);
buttonAddDozer.Name = "buttonAddDozer";
buttonAddDozer.Size = new Size(332, 64);
buttonAddDozer.TabIndex = 2;
@ -126,24 +94,174 @@
buttonAddDozer.UseVisualStyleBackColor = true;
buttonAddDozer.Click += ButtonAddDozer_Click;
//
// buttonAddBulldozer
//
buttonAddBulldozer.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
buttonAddBulldozer.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point);
buttonAddBulldozer.Location = new Point(11, 84);
buttonAddBulldozer.Name = "buttonAddBulldozer";
buttonAddBulldozer.Size = new Size(332, 79);
buttonAddBulldozer.TabIndex = 3;
buttonAddBulldozer.Text = "Добавление крутого бульдозера";
buttonAddBulldozer.UseVisualStyleBackColor = true;
buttonAddBulldozer.Click += ButtonAddBulldozer_Click;
//
// buttonDelBulldozer
//
buttonDelBulldozer.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
buttonDelBulldozer.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point);
buttonDelBulldozer.Location = new Point(11, 216);
buttonDelBulldozer.Name = "buttonDelBulldozer";
buttonDelBulldozer.Size = new Size(332, 63);
buttonDelBulldozer.TabIndex = 3;
buttonDelBulldozer.Text = "Удаленить бульдозер";
buttonDelBulldozer.UseVisualStyleBackColor = true;
buttonDelBulldozer.Click += ButtonDelBulldozer_Click;
//
// maskedTextBox
//
maskedTextBox.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
maskedTextBox.Location = new Point(11, 169);
maskedTextBox.Name = "maskedTextBox";
maskedTextBox.Size = new Size(332, 41);
maskedTextBox.TabIndex = 5;
maskedTextBox.ValidatingType = typeof(int);
//
// buttonGoToCheck
//
buttonGoToCheck.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
buttonGoToCheck.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point);
buttonGoToCheck.Location = new Point(11, 285);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(332, 63);
buttonGoToCheck.TabIndex = 3;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
buttonGoToCheck.Click += ButtonGoToCheck_Click;
//
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
buttonRefresh.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point);
buttonRefresh.Location = new Point(11, 354);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(332, 63);
buttonRefresh.TabIndex = 3;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += ButtonRefresh_Click;
//
// panelStorage
//
panelStorage.Controls.Add(listBoxCollection);
panelStorage.Controls.Add(buttonCollectionDel);
panelStorage.Controls.Add(buttonCollectionAdd);
panelStorage.Controls.Add(radioButtonList);
panelStorage.Controls.Add(radioButtonMassive);
panelStorage.Controls.Add(textBoxCollectionName);
panelStorage.Controls.Add(labelCollectionName);
panelStorage.Dock = DockStyle.Top;
panelStorage.Location = new Point(3, 37);
panelStorage.Name = "panelStorage";
panelStorage.Size = new Size(352, 465);
panelStorage.TabIndex = 6;
//
// listBoxCollection
//
listBoxCollection.FormattingEnabled = true;
listBoxCollection.ItemHeight = 33;
listBoxCollection.Location = new Point(11, 219);
listBoxCollection.Name = "listBoxCollection";
listBoxCollection.Size = new Size(332, 169);
listBoxCollection.TabIndex = 5;
//
// buttonCollectionDel
//
buttonCollectionDel.Location = new Point(11, 407);
buttonCollectionDel.Name = "buttonCollectionDel";
buttonCollectionDel.Size = new Size(332, 46);
buttonCollectionDel.TabIndex = 4;
buttonCollectionDel.Text = "Удалить коллекцию";
buttonCollectionDel.UseVisualStyleBackColor = true;
buttonCollectionDel.Click += ButtonCollectionDel_Click;
//
// buttonCollectionAdd
//
buttonCollectionAdd.Location = new Point(11, 157);
buttonCollectionAdd.Name = "buttonCollectionAdd";
buttonCollectionAdd.Size = new Size(332, 46);
buttonCollectionAdd.TabIndex = 4;
buttonCollectionAdd.Text = "Добавить коллекцию";
buttonCollectionAdd.UseVisualStyleBackColor = true;
buttonCollectionAdd.Click += ButtonCollectionAdd_Click;
//
// radioButtonList
//
radioButtonList.AutoSize = true;
radioButtonList.Location = new Point(183, 115);
radioButtonList.Name = "radioButtonList";
radioButtonList.Size = new Size(129, 37);
radioButtonList.TabIndex = 3;
radioButtonList.TabStop = true;
radioButtonList.Text = "Список";
radioButtonList.UseVisualStyleBackColor = true;
//
// radioButtonMassive
//
radioButtonMassive.AutoSize = true;
radioButtonMassive.Location = new Point(38, 115);
radioButtonMassive.Name = "radioButtonMassive";
radioButtonMassive.Size = new Size(130, 37);
radioButtonMassive.TabIndex = 2;
radioButtonMassive.TabStop = true;
radioButtonMassive.Text = "Массив";
radioButtonMassive.UseVisualStyleBackColor = true;
//
// textBoxCollectionName
//
textBoxCollectionName.Location = new Point(11, 59);
textBoxCollectionName.Name = "textBoxCollectionName";
textBoxCollectionName.Size = new Size(332, 41);
textBoxCollectionName.TabIndex = 1;
//
// labelCollectionName
//
labelCollectionName.AutoSize = true;
labelCollectionName.Location = new Point(57, 13);
labelCollectionName.Name = "labelCollectionName";
labelCollectionName.Size = new Size(263, 33);
labelCollectionName.TabIndex = 0;
labelCollectionName.Text = "Название коллекции:";
//
// buttonCreateCompany
//
buttonCreateCompany.Location = new Point(14, 572);
buttonCreateCompany.Name = "buttonCreateCompany";
buttonCreateCompany.Size = new Size(332, 46);
buttonCreateCompany.TabIndex = 4;
buttonCreateCompany.Text = "Создать компанию";
buttonCreateCompany.UseVisualStyleBackColor = true;
buttonCreateCompany.Click += ButtonCreateCompany_Click;
//
// comboBoxSelectorCompany
//
comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
comboBoxSelectorCompany.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectorCompany.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point);
comboBoxSelectorCompany.FormattingEnabled = true;
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
comboBoxSelectorCompany.Location = new Point(14, 52);
comboBoxSelectorCompany.Location = new Point(14, 525);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(332, 41);
comboBoxSelectorCompany.TabIndex = 1;
comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged;
comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
//
// pictureBox
//
pictureBox.Location = new Point(12, 12);
pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 0);
pictureBox.Name = "pictureBox";
pictureBox.Size = new Size(1272, 890);
pictureBox.Size = new Size(1290, 1051);
pictureBox.TabIndex = 4;
pictureBox.TabStop = false;
//
@ -151,13 +269,16 @@
//
AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1648, 914);
ClientSize = new Size(1648, 1051);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Name = "FormBulldozerCollection";
Text = "Коллекция бульдозеров";
groupBoxTools.ResumeLayout(false);
groupBoxTools.PerformLayout();
panelCompanyTools.ResumeLayout(false);
panelCompanyTools.PerformLayout();
panelStorage.ResumeLayout(false);
panelStorage.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
ResumeLayout(false);
}
@ -173,5 +294,15 @@
private Button buttonDelBulldozer;
private Button buttonRefresh;
private Button buttonGoToCheck;
private Panel panelStorage;
private Label labelCollectionName;
private RadioButton radioButtonList;
private RadioButton radioButtonMassive;
private TextBox textBoxCollectionName;
private Button buttonCollectionAdd;
private ListBox listBoxCollection;
private Button buttonCollectionDel;
private Button buttonCreateCompany;
private Panel panelCompanyTools;
}
}

View File

@ -18,6 +18,11 @@ namespace ProjectBulldozer;
/// </summary>
public partial class FormBulldozerCollection : Form
{
/// <summary>
/// Хранилище коллекций
/// </summary>
private readonly StorageCollection<DrawningDozer> _storageCollection;
/// <summary>
/// Компания
/// </summary>
@ -29,6 +34,7 @@ public partial class FormBulldozerCollection : Form
public FormBulldozerCollection()
{
InitializeComponent();
_storageCollection = new();
}
/// <summary>
@ -36,25 +42,11 @@ public partial class FormBulldozerCollection : Form
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBoxSelectorCompany.Text)
{
case "Хранилище":
_company = new Garage(pictureBox.Width, pictureBox.Height, new MassiveGenericObject<DrawningDozer>());
break;
}
panelCompanyTools.Enabled = false;
}
/* private void ComboBoxSelectorCompany_SelectedIndexChanget(object sender, EventArgs e)
{
switch (comboBoxSelectorCompany.Text)
{
case "Хранилище":
_company = new CarSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObject<DrawningDozer>());
break;
}
}*/
/// <summary>
/// Добавление обычного бульдозера
@ -94,14 +86,14 @@ public partial class FormBulldozerCollection : Form
case nameof(DrawningBulldozer):
//Вызов диалогового окна для выбора цвета
drawningDozer = new DrawningBulldozer(random.Next(100, 300), random.Next(1000, 3000),
GetBodyColor(random), GetWheelsColor(random),
GetBodyColor(random), GetWheelsColor(random),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
break;
default:
return;
}
if (_company + drawningDozer)
if (_company + drawningDozer != -1)
{
MessageBox.Show("Объект добавлен.");
pictureBox.Image = _company.Show();
@ -162,7 +154,7 @@ public partial class FormBulldozerCollection : Form
}
int pos = Convert.ToInt32(maskedTextBox.Text);
if (_company - pos)
if (_company - pos != null)
{
MessageBox.Show("Объект удалён.");
pictureBox.Image = _company.Show();
@ -223,4 +215,117 @@ public partial class FormBulldozerCollection : Form
pictureBox.Image = _company.Show();
}
/// <summary>
/// Добавление коллекции
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCollectionAdd_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonList.Checked && !radioButtonMassive.Checked))
{
MessageBox.Show("Не все данные заполнены!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
CollectionType collectionType = CollectionType.None;
if (radioButtonMassive.Checked)
{
collectionType = CollectionType.Massive;
}
else if (radioButtonList.Checked)
{
collectionType = CollectionType.List;
}
_storageCollection.AddCollection(textBoxCollectionName.Text, collectionType);
RefreshListBoxItems();
}
/*private ListBox GetListBoxCollection()
{
return listBoxCollection;
}*/
/// <summary>
/// Удаление коллекции
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCollectionDel_Click(object sender, EventArgs e)
{
// Прописать логику удаления элемента из коллекции.
// Нужно убедиться, что есть выбранная коллекция
if (listBoxCollection.SelectedItem == null || listBoxCollection.SelectedIndex < 0)
{
MessageBox.Show("Коллекция не выбрана!");
return;
}
else
{
// Спросить у пользователя через MessageBox, что он подтверждает, что хочет удалить запись
if (MessageBox.Show("Удалить коллекцию?", "Удаление...", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
MessageBox.Show("Коллекция не выбрана!");
return;
}
else
{
// Удалить и обновить ListBox
_storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
RefreshListBoxItems();
}
}
}
/// <summary>
/// Обновление списка в ListBoxCollection
/// </summary>
private void RefreshListBoxItems()
{
listBoxCollection.Items.Clear();
for (int i = 0; i < _storageCollection.Keys?.Count; ++i)
{
string? colName = _storageCollection.Keys?[i];
if (!string.IsNullOrEmpty(colName))
{
listBoxCollection.Items.Add(colName);
}
}
}
/// <summary>
/// Создание компании
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreateCompany_Click(object sender, EventArgs e)
{
if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
{
MessageBox.Show("Коллекция не выбрана!");
return;
}
ICollectoinGenericObjects<DrawningDozer>? collection = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
if (collection == null)
{
MessageBox.Show("Коллекция не проинициализирована!");
return;
}
switch (comboBoxSelectorCompany.Text)
{
case "Хранилище":
_company = new Garage(pictureBox.Width, pictureBox.Height, collection);
break;
}
panelCompanyTools.Enabled = true;
RefreshListBoxItems();
}
}