Лаба 4 без TODO.

This commit is contained in:
MariaBelkina 2024-04-22 19:42:45 +04:00
parent 34d5daf3b1
commit 5e7a5b684d
5 changed files with 407 additions and 41 deletions

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

@ -0,0 +1,64 @@
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)
{
//TODO проверка позиции
return _collection[position];
}
public bool Insert(T obj)
{
//TODO проверка, что не привышено максимальное колличество элементов
//TODO вставка в конец набора
return true;
}
public bool Insert(T obj, int position)
{
//TODO проверка, что не превышено максимальное колличество элементов
//TODO проверка позиции
//TODO вставка по позиции
return true;
}
public bool Remove(int position)
{
//TODO проверка позиции
//TODO удаление объекта из спписка
return true;
}
}

View File

@ -0,0 +1,66 @@
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)
{
// TODO проверка, что name не пустой и нет в словаре записи с таким ключом
// TODO прописать логику для добавления
}
/// <summary>
/// Удаление коллекции
/// </summary>
/// <param name="name">Название коллекции</param>
public void DelCollection(string name)
{
// TODO Прописать логику для удаления коллекции
}
/// <summary>
/// Доступ к коллекции
/// </summary>
/// <param name="name">Название коллекции</param>
/// <returns></returns>
public ICollectoinGenericObjects<T>? this[string name]
{
get
{
// TODO Продумать логику получения объекта
return null;
}
}
}

View File

@ -29,6 +29,15 @@
private void InitializeComponent()
{
groupBoxTools = new GroupBox();
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();
maskedTextBox = new MaskedTextBox();
buttonRefresh = new Button();
buttonGoToCheck = new Button();
@ -37,40 +46,135 @@
buttonAddDozer = new Button();
comboBoxSelectorCompany = new ComboBox();
pictureBox = new PictureBox();
panelCompanyTools = new Panel();
groupBoxTools.SuspendLayout();
panelStorage.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
panelCompanyTools.SuspendLayout();
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 = "Инструменты";
//
// 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;
textBoxCollectionName.Text = " ";
//
// 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;
//
// maskedTextBox
//
maskedTextBox.Location = new Point(14, 340);
maskedTextBox.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
maskedTextBox.Location = new Point(11, 169);
maskedTextBox.Name = "maskedTextBox";
maskedTextBox.Size = new Size(332, 39);
maskedTextBox.Size = new Size(332, 41);
maskedTextBox.TabIndex = 5;
maskedTextBox.ValidatingType = typeof(int);
//
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRefresh.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
buttonRefresh.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point);
buttonRefresh.Location = new Point(14, 719);
buttonRefresh.Location = new Point(11, 354);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(332, 63);
buttonRefresh.TabIndex = 3;
@ -80,9 +184,9 @@
//
// buttonGoToCheck
//
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonGoToCheck.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
buttonGoToCheck.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point);
buttonGoToCheck.Location = new Point(14, 520);
buttonGoToCheck.Location = new Point(11, 285);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(332, 63);
buttonGoToCheck.TabIndex = 3;
@ -92,9 +196,9 @@
//
// buttonDelBulldozer
//
buttonDelBulldozer.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonDelBulldozer.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
buttonDelBulldozer.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point);
buttonDelBulldozer.Location = new Point(14, 385);
buttonDelBulldozer.Location = new Point(11, 216);
buttonDelBulldozer.Name = "buttonDelBulldozer";
buttonDelBulldozer.Size = new Size(332, 63);
buttonDelBulldozer.TabIndex = 3;
@ -104,9 +208,9 @@
//
// buttonAddBulldozer
//
buttonAddBulldozer.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddBulldozer.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
buttonAddBulldozer.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point);
buttonAddBulldozer.Location = new Point(14, 210);
buttonAddBulldozer.Location = new Point(11, 84);
buttonAddBulldozer.Name = "buttonAddBulldozer";
buttonAddBulldozer.Size = new Size(332, 79);
buttonAddBulldozer.TabIndex = 3;
@ -116,9 +220,9 @@
//
// 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;
@ -128,12 +232,12 @@
//
// 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;
@ -141,24 +245,42 @@
//
// 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;
//
// panelCompanyTools
//
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;
//
// FormBulldozerCollection
//
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();
panelStorage.ResumeLayout(false);
panelStorage.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
panelCompanyTools.ResumeLayout(false);
panelCompanyTools.PerformLayout();
ResumeLayout(false);
}
@ -173,5 +295,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,9 @@ namespace ProjectBulldozer;
/// </summary>
public partial class FormBulldozerCollection : Form
{
private readonly StorageCollection<DrawningDozer> _storageCollection;
/// <summary>
/// Компания
/// </summary>
@ -29,6 +32,7 @@ public partial class FormBulldozerCollection : Form
public FormBulldozerCollection()
{
InitializeComponent();
_storageCollection = new();
}
/// <summary>
@ -38,23 +42,9 @@ public partial class FormBulldozerCollection : Form
/// <param name="e"></param>
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,7 +84,7 @@ 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:
@ -223,4 +213,90 @@ 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();
}
/// <summary>
/// Удаление коллекции
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCollectionDel_Click(object sender, EventArgs e)
{
// TODO Прописать логику удаления элемента из коллекции
//нужно убедиться, что есть выбранная коллекция
//спросить у пользователя через MessageBox, что он подтверждает, что хочет удалить запись
//удалить и обновить ListBox
}
/// <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)
{
MessageBox.Show("Коллекция не выбрана!");
return;
}
ICollectoinGenericObjects<DrawningDozer>? collectoin = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
if (collectoin == null)
{
MessageBox.Show("Коллекция не проинициализирована!");
return;
}
switch (comboBoxSelectorCompany.Text)
{
case "Хранилище":
_company = new Garage(pictureBox.Width, pictureBox.Height, new MassiveGenericObject<DrawningDozer>());
break;
}
panelCompanyTools.Enabled = true;
}
}