ISEbd-12_Frolova.A.S._LabWork04_Simple #6

Closed
Fr_Alyona wants to merge 1 commits from LabWork04 into LabWork03
9 changed files with 442 additions and 62 deletions

View File

@ -54,7 +54,7 @@ private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _
/// <returns></returns>
public static int operator +(AbstractCompany company, DrawningBoat boat)
{
return company._collection?.Insert(boat) ?? 0;
return company._collection?.Insert(boat) ?? -1;
}
/// <summary>
/// Перегрузка оператора удаления для класса
@ -84,6 +84,7 @@ private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _
Bitmap bitmap = new(_pictureWidth, _pictureHeight);
Graphics graphics = Graphics.FromImage(bitmap);
DrawBackgound(graphics);
SetObjectsPosition();
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
{

View File

@ -12,6 +12,7 @@ namespace ProjectCatamaran.CollectiongGenericObjects;
/// </summary>
public class BoatHarborService : AbstractCompany
{
/// <summary>
///
/// </summary>

View File

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

View File

@ -17,19 +17,16 @@ public interface ICollectionGenericObjects<T>
/// Количество объектов в коллекции
/// </summary>
int Count { get; }
/// <summary>
/// Установка максимального количества элементов
/// </summary>
int SetMaxCount { set; }
/// <summary>
/// Добавление объекта в коллекцию
/// </summary>
/// <param name="obj">Добавляемый объект</param>
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
int Insert(T obj);
/// <summary>
/// Добавление объекта в коллекцию на конкретную позицию
/// </summary>
@ -37,14 +34,12 @@ public interface ICollectionGenericObjects<T>
/// <param name="position">Позиция</param>
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
int Insert(T obj, int position);
/// <summary>
/// Удаление объекта из коллекции с конкретной позиции
/// </summary>
/// <param name="position">Позиция</param>
/// <returns>true - удаление прошло удачно, false - удаление не удалось</returns>
T? Remove(int position);
/// <summary>
/// Получение объекта по позиции
/// </summary>

View File

@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectCatamaran.CollectiongGenericObjects;
public class ListGenericObjects<T> : ICollectionGenericObjects<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 проверка позиции
if (position >= 0 && position < Count)
{
return _collection[position];
}
return null;
}
public int Insert(T obj)
{
if (Count <= _maxCount)
{
_collection.Add(obj);
return Count;
}
return -1;
}
public int Insert(T obj, int position)
{
if (Count < _maxCount && position >= 0 && position < _maxCount)
{
_collection.Insert(position, obj);
return position;
}
return -1;
}
public T Remove(int position)
{
T temp = _collection[position];
if (position >= 0 && position < _maxCount)
{
_collection.RemoveAt(position);
return temp;
}
return null;
}
}

View File

@ -18,38 +18,43 @@ namespace ProjectCatamaran.CollectiongGenericObjects;
/// </summary>
private T?[] _collection;
public int Count => _collection.Length;
public int SetMaxCount { set { if (value > 0) { _collection = new T?[value]; } } }
public int SetMaxCount
{
set
{
if (value > 0)
{
if (_collection.Length > 0)
{
Array.Resize(ref _collection, value);
}
else
{
_collection = new T?[value];
}
}
}
}
/// <summary>
/// Конструктор
/// </summary>
public MassiveGenericObjects()
{
_collection = Array.Empty<T>();
_collection = Array.Empty<T?>();
}
/// <summary>
/// проверка позиции
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public T? Get(int position)
{
// проверка позиции
if (position >= _collection.Length || position < 0)
{
return null;
}
return _collection[position];
}
/// <summary>
/// вставка в свободное место набора
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public int Insert(T obj)
{
// вставка в свободное место набора
int index = 0;
while (index < _collection.Length)
{
@ -62,15 +67,9 @@ namespace ProjectCatamaran.CollectiongGenericObjects;
}
return -1;
}
/// <summary>
/// проверка позиции
/// </summary>
/// <param name="obj"></param>
/// <param name="position"></param>
/// <returns></returns>
public int Insert(T obj, int position)
{
if (position >= _collection.Length || position < 0)
{ return -1; }
@ -100,15 +99,12 @@ namespace ProjectCatamaran.CollectiongGenericObjects;
}
return -1;
}
public T? Remove(int position)
public T Remove(int position)
{
if (position >= _collection.Length || position < 0)
{
return null;
}
T drawningBoat = _collection[position];
{ return null; }
T DrawningAircraft = _collection[position];
_collection[position] = null;
return drawningBoat;
return DrawningAircraft;
}
}

View File

@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectCatamaran.CollectiongGenericObjects;
/// <summary>
/// Класс-хранилище коллекций
/// </summary>
/// <typeparam name="T"></typeparam>
public class StorageCollection<T>
where T : class
{
/// <summary>
/// Словарь (хранилище) с коллекциями
/// </summary>
readonly Dictionary<string, ICollectionGenericObjects<T>> _storages;
/// <summary>
/// Возвращение списка названий коллекций
/// </summary>
public List<string> Keys => _storages.Keys.ToList();
/// <summary>
/// Конструктор
/// </summary>
public StorageCollection()
{
_storages = new Dictionary<string, ICollectionGenericObjects<T>>();
}
/// <summary>
/// Добавление коллекции в хранилище
/// </summary>
/// <param name="name">Название коллекции</param>
/// <param name="collectionType">тип коллекции</param>
public void AddCollection(string name, CollectionType collectionType)
{
if (!(collectionType == CollectionType.None) && !_storages.ContainsKey(name))
{
if (collectionType == CollectionType.List)
{
_storages.Add(name, new ListGenericObjects<T>());
}
else if (collectionType == CollectionType.Massive)
{
_storages.Add(name, new MassiveGenericObjects<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 ICollectionGenericObjects<T>? this[string name]
{
get
{
if (_storages.ContainsKey(name))
{
return _storages[name];
}
return null;
}
}
}

View File

@ -29,6 +29,15 @@
private void InitializeComponent()
{
groupBoxTools = new GroupBox();
buttonCreateCompany = new Button();
panelStorage = new Panel();
radioButtonList = new RadioButton();
radioButtonMassive = new RadioButton();
buttonCollectionaDel = new Button();
listBoxCollection = new ListBox();
buttonCollectionaAdd = new Button();
textBoxCollectionName = new TextBox();
labelCollectionName = new Label();
buttonRefresh = new Button();
buttonGoToCheck = new Button();
buttonRemoveBoat = new Button();
@ -37,18 +46,18 @@
buttonAddBoat = new Button();
comboBoxSelectorCompany = new ComboBox();
pictureBoxBoat = new PictureBox();
panelCompanyTools = new Panel();
groupBoxTools.SuspendLayout();
panelStorage.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxBoat).BeginInit();
panelCompanyTools.SuspendLayout();
SuspendLayout();
//
// groupBoxTools
//
groupBoxTools.Controls.Add(buttonRefresh);
groupBoxTools.Controls.Add(buttonGoToCheck);
groupBoxTools.Controls.Add(buttonRemoveBoat);
groupBoxTools.Controls.Add(maskedTextBoxPosition);
groupBoxTools.Controls.Add(buttonAddCatamaran);
groupBoxTools.Controls.Add(buttonAddBoat);
groupBoxTools.Controls.Add(panelCompanyTools);
groupBoxTools.Controls.Add(buttonCreateCompany);
groupBoxTools.Controls.Add(panelStorage);
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(849, 0);
@ -58,12 +67,103 @@
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
// buttonCreateCompany
//
buttonCreateCompany.Location = new Point(16, 353);
buttonCreateCompany.Name = "buttonCreateCompany";
buttonCreateCompany.Size = new Size(251, 29);
buttonCreateCompany.TabIndex = 7;
buttonCreateCompany.Text = "Создать компанию";
buttonCreateCompany.UseVisualStyleBackColor = true;
buttonCreateCompany.Click += ButtonCreateCompany_Click;
//
// panelStorage
//
panelStorage.Controls.Add(radioButtonList);
panelStorage.Controls.Add(radioButtonMassive);
panelStorage.Controls.Add(buttonCollectionaDel);
panelStorage.Controls.Add(listBoxCollection);
panelStorage.Controls.Add(buttonCollectionaAdd);
panelStorage.Controls.Add(textBoxCollectionName);
panelStorage.Controls.Add(labelCollectionName);
panelStorage.Dock = DockStyle.Top;
panelStorage.Location = new Point(3, 23);
panelStorage.Name = "panelStorage";
panelStorage.Size = new Size(273, 276);
panelStorage.TabIndex = 7;
//
// radioButtonList
//
radioButtonList.AutoSize = true;
radioButtonList.Location = new Point(158, 65);
radioButtonList.Name = "radioButtonList";
radioButtonList.Size = new Size(80, 24);
radioButtonList.TabIndex = 9;
radioButtonList.TabStop = true;
radioButtonList.Text = "Список";
radioButtonList.UseVisualStyleBackColor = true;
//
// radioButtonMassive
//
radioButtonMassive.AutoSize = true;
radioButtonMassive.Location = new Point(29, 65);
radioButtonMassive.Name = "radioButtonMassive";
radioButtonMassive.Size = new Size(82, 24);
radioButtonMassive.TabIndex = 8;
radioButtonMassive.TabStop = true;
radioButtonMassive.Text = "Массив";
radioButtonMassive.UseVisualStyleBackColor = true;
//
// buttonCollectionaDel
//
buttonCollectionaDel.Location = new Point(12, 240);
buttonCollectionaDel.Name = "buttonCollectionaDel";
buttonCollectionaDel.Size = new Size(251, 29);
buttonCollectionaDel.TabIndex = 6;
buttonCollectionaDel.Text = "Удалить коллекцию";
buttonCollectionaDel.UseVisualStyleBackColor = true;
buttonCollectionaDel.Click += ButtonCollectionDel_Click;
//
// listBoxCollection
//
listBoxCollection.ItemHeight = 20;
listBoxCollection.Location = new Point(3, 130);
listBoxCollection.Name = "listBoxCollection";
listBoxCollection.Size = new Size(267, 104);
listBoxCollection.TabIndex = 7;
//
// buttonCollectionaAdd
//
buttonCollectionaAdd.Location = new Point(13, 95);
buttonCollectionaAdd.Name = "buttonCollectionaAdd";
buttonCollectionaAdd.Size = new Size(251, 29);
buttonCollectionaAdd.TabIndex = 4;
buttonCollectionaAdd.Text = "Добавить коллекцию";
buttonCollectionaAdd.UseVisualStyleBackColor = true;
buttonCollectionaAdd.Click += ButtonCollectionAdd_Click;
//
// textBoxCollectionName
//
textBoxCollectionName.Location = new Point(3, 32);
textBoxCollectionName.Name = "textBoxCollectionName";
textBoxCollectionName.Size = new Size(267, 27);
textBoxCollectionName.TabIndex = 1;
//
// labelCollectionName
//
labelCollectionName.AutoSize = true;
labelCollectionName.Location = new Point(57, 9);
labelCollectionName.Name = "labelCollectionName";
labelCollectionName.Size = new Size(158, 20);
labelCollectionName.TabIndex = 0;
labelCollectionName.Text = "Название коллекции:";
//
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRefresh.Location = new Point(16, 522);
buttonRefresh.Location = new Point(3, 181);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(250, 51);
buttonRefresh.Size = new Size(267, 31);
buttonRefresh.TabIndex = 6;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
@ -72,9 +172,9 @@
// buttonGoToCheck
//
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonGoToCheck.Location = new Point(16, 408);
buttonGoToCheck.Location = new Point(4, 146);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(250, 51);
buttonGoToCheck.Size = new Size(266, 29);
buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
@ -83,9 +183,9 @@
// buttonRemoveBoat
//
buttonRemoveBoat.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRemoveBoat.Location = new Point(16, 301);
buttonRemoveBoat.Location = new Point(3, 113);
buttonRemoveBoat.Name = "buttonRemoveBoat";
buttonRemoveBoat.Size = new Size(250, 51);
buttonRemoveBoat.Size = new Size(267, 27);
buttonRemoveBoat.TabIndex = 4;
buttonRemoveBoat.Text = "Удалить лодку";
buttonRemoveBoat.UseVisualStyleBackColor = true;
@ -94,19 +194,19 @@
// maskedTextBoxPosition
//
maskedTextBoxPosition.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
maskedTextBoxPosition.Location = new Point(16, 258);
maskedTextBoxPosition.Location = new Point(3, 80);
maskedTextBoxPosition.Mask = "00";
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
maskedTextBoxPosition.Size = new Size(250, 27);
maskedTextBoxPosition.Size = new Size(267, 27);
maskedTextBoxPosition.TabIndex = 3;
maskedTextBoxPosition.ValidatingType = typeof(int);
//
// buttonAddCatamaran
//
buttonAddCatamaran.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddCatamaran.Location = new Point(16, 174);
buttonAddCatamaran.Location = new Point(3, 41);
buttonAddCatamaran.Name = "buttonAddCatamaran";
buttonAddCatamaran.Size = new Size(250, 51);
buttonAddCatamaran.Size = new Size(267, 33);
buttonAddCatamaran.TabIndex = 2;
buttonAddCatamaran.Text = "Добавление катамарана";
buttonAddCatamaran.UseVisualStyleBackColor = true;
@ -115,9 +215,9 @@
// buttonAddBoat
//
buttonAddBoat.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddBoat.Location = new Point(16, 117);
buttonAddBoat.Location = new Point(3, 3);
buttonAddBoat.Name = "buttonAddBoat";
buttonAddBoat.Size = new Size(250, 51);
buttonAddBoat.Size = new Size(267, 32);
buttonAddBoat.TabIndex = 1;
buttonAddBoat.Text = "Добавление лодки";
buttonAddBoat.UseVisualStyleBackColor = true;
@ -129,7 +229,7 @@
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectorCompany.FormattingEnabled = true;
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
comboBoxSelectorCompany.Location = new Point(16, 30);
comboBoxSelectorCompany.Location = new Point(17, 305);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(250, 28);
comboBoxSelectorCompany.TabIndex = 0;
@ -144,6 +244,21 @@
pictureBoxBoat.TabIndex = 1;
pictureBoxBoat.TabStop = false;
//
// panelCompanyTools
//
panelCompanyTools.Controls.Add(buttonAddCatamaran);
panelCompanyTools.Controls.Add(buttonAddBoat);
panelCompanyTools.Controls.Add(maskedTextBoxPosition);
panelCompanyTools.Controls.Add(buttonRefresh);
panelCompanyTools.Controls.Add(buttonRemoveBoat);
panelCompanyTools.Controls.Add(buttonGoToCheck);
panelCompanyTools.Dock = DockStyle.Bottom;
panelCompanyTools.Enabled = false;
panelCompanyTools.Location = new Point(3, 397);
panelCompanyTools.Name = "panelCompanyTools";
panelCompanyTools.Size = new Size(273, 229);
panelCompanyTools.TabIndex = 8;
//
// FormBoatCollection
//
AutoScaleDimensions = new SizeF(8F, 20F);
@ -154,8 +269,11 @@
Name = "FormBoatCollection";
Text = "Коллекция лодок";
groupBoxTools.ResumeLayout(false);
groupBoxTools.PerformLayout();
panelStorage.ResumeLayout(false);
panelStorage.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxBoat).EndInit();
panelCompanyTools.ResumeLayout(false);
panelCompanyTools.PerformLayout();
ResumeLayout(false);
}
@ -170,5 +288,15 @@
private Button buttonRemoveBoat;
private MaskedTextBox maskedTextBoxPosition;
private PictureBox pictureBoxBoat;
private Panel panelStorage;
private Label labelCollectionName;
private TextBox textBoxCollectionName;
private Button buttonCollectionaAdd;
private Button buttonCreateCompany;
private Button buttonCollectionaDel;
private ListBox listBoxCollection;
private RadioButton radioButtonList;
private RadioButton radioButtonMassive;
private Panel panelCompanyTools;
}
}

View File

@ -17,6 +17,8 @@ namespace ProjectCatamaran;
/// </summary>
public partial class FormBoatCollection : Form
{
private readonly StorageCollection<DrawningBoat> _storageCollection;
/// <summary>
/// Компания
/// </summary>
@ -25,6 +27,7 @@ public partial class FormBoatCollection : Form
public FormBoatCollection()
{
InitializeComponent();
_storageCollection = new();
}
/// <summary>
@ -34,13 +37,7 @@ public partial class FormBoatCollection : Form
/// <param name="e"></param>
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBoxSelectorCompany.Text)
{
case "Хранилище":
_company = new BoatHarborService(pictureBoxBoat.Width,
pictureBoxBoat.Height, new MassiveGenericObjects<DrawningBoat>());
break;
}
panelCompanyTools.Enabled = false;
}
@ -189,4 +186,100 @@ public partial class FormBoatCollection : Form
pictureBoxBoat.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);
RerfreshListBoxItems();
}
/// <summary>
/// Удаление коллекции
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCollectionDel_Click(object sender, EventArgs e)
{
if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
{
MessageBox.Show("Коллекция не выбрана");
return;
}
if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
_storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
RerfreshListBoxItems();
}
/// <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;
}
ICollectionGenericObjects<DrawningBoat>? collection = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
if (collection == null)
{
MessageBox.Show("Коллекция не проинициализирована");
return;
}
switch (comboBoxSelectorCompany.Text)
{
case "Хранилище":
_company = new BoatHarborService(pictureBoxBoat.Width, pictureBoxBoat.Height, collection);
break;
}
panelCompanyTools.Enabled = true;
RerfreshListBoxItems();
}
/// <summary>
/// Обновление списка в listBoxCollection
/// </summary>
private void RerfreshListBoxItems()
{
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);
}
}
}
}