LabWork4
This commit is contained in:
parent
3d664c461e
commit
e37875f510
@ -49,19 +49,21 @@ public abstract class AbstractCompany
|
||||
/// <param name="company">Компания</param>
|
||||
/// <param name="gun">Добавляемый объект</param>
|
||||
/// <returns></returns>
|
||||
public static int operator +(AbstractCompany company, DrawningGun gun)
|
||||
public static bool operator +(AbstractCompany company, DrawningGun gun)
|
||||
{
|
||||
return company._collection.Insert(gun);
|
||||
return company._collection?.Insert(gun) ?? false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перегрузка оператора удаления для класса
|
||||
/// </summary>
|
||||
/// <param name="company">Компания</param>
|
||||
/// <param name="position">Номер удаляемого объекта</param>
|
||||
/// <returns></returns>
|
||||
public static DrawningGun? operator -(AbstractCompany company, int position)
|
||||
public static bool operator -(AbstractCompany company, int position)
|
||||
{
|
||||
return company._collection?.Remove(position);
|
||||
return company._collection?.Remove(position) ?? false;
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение случайного объекта из коллекции
|
||||
|
@ -0,0 +1,19 @@
|
||||
namespace AntiAircraftGun.CollectionGenericObjects;
|
||||
/// <summary>
|
||||
/// Тип коллекции
|
||||
/// </summary>
|
||||
public enum CollectionType
|
||||
{
|
||||
/// <summary>
|
||||
/// Неопределено
|
||||
/// </summary>
|
||||
None = 0,
|
||||
/// <summary>
|
||||
/// Массив
|
||||
/// </summary>
|
||||
Massive = 1,
|
||||
/// <summary>
|
||||
/// Список
|
||||
/// </summary>
|
||||
List = 2
|
||||
}
|
@ -48,13 +48,15 @@ public class GunSharingService : AbstractCompany
|
||||
|
||||
for (int j = 0; j < maxCountY; j++)
|
||||
{
|
||||
for (int i = 0; i < maxCountX; i++)
|
||||
for (int i = 0; i < maxCountX; i++)
|
||||
{
|
||||
currentIndex++;
|
||||
if (_collection.Get(currentIndex) == null) continue;
|
||||
if (_collection.Get(currentIndex) != null)
|
||||
{
|
||||
|
||||
_collection.Get(currentIndex).SetPictureSize(_pictureWidth, _pictureHeight);
|
||||
_collection.Get(currentIndex).SetPosition(boarderOffsetX + i * _placeSizeWidth + i * offsetX, boarderOffsetY + j * _placeSizeHeight);
|
||||
_collection.Get(currentIndex).SetPictureSize(_pictureWidth, _pictureHeight);
|
||||
_collection.Get(currentIndex).SetPosition(boarderOffsetX + i * _placeSizeWidth + i * offsetX, boarderOffsetY + j * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,20 +21,20 @@ public interface ICollectionGenericObjects<T>
|
||||
/// </summary>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||
int Insert(T obj);
|
||||
bool Insert(T obj);
|
||||
/// <summary>
|
||||
/// Добавление объекта в коллекцию на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||
int Insert(T obj, int position);
|
||||
bool Insert(T obj, int position);
|
||||
/// <summary>
|
||||
/// Удаление объекта из коллекции с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>true - удаление прошло удачно, false - удаление не удалось</returns>
|
||||
T? Remove(int position);
|
||||
bool Remove(int position);
|
||||
/// <summary>
|
||||
/// Получение объекта по позиции
|
||||
/// </summary>
|
||||
|
@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AntiAircraftGun.CollectionGenericObjects;
|
||||
/// <summary>
|
||||
/// Параметризованный набор объектов
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Параметр: ограничение - ссылочный тип</typeparam>
|
||||
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 (!_collection.Any()) { return null; }
|
||||
if (_collection.Count <= position || position < 0 || position >= _maxCount) { return null; }
|
||||
return _collection[position];
|
||||
}
|
||||
public bool Insert(T obj)
|
||||
{
|
||||
// TODO проверка, что не превышено максимальное количество элементов
|
||||
// TODO вставка в конец набора
|
||||
if (_collection.Count>=_maxCount) return false;
|
||||
_collection.Add(obj);
|
||||
return true;
|
||||
}
|
||||
public bool Insert(T obj, int position)
|
||||
{
|
||||
// TODO проверка, что не превышено максимальное количество элементов
|
||||
// TODO проверка позиции
|
||||
// TODO вставка по позиции
|
||||
if (_collection.Count >= _maxCount || _collection[position] == null || position < 0) { return false; }
|
||||
_collection.Insert(position, obj);
|
||||
return true;
|
||||
}
|
||||
public bool Remove(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO удаление объекта из списка
|
||||
if (_collection[position] == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_collection.RemoveAt(position);
|
||||
return true;
|
||||
}
|
||||
}
|
@ -44,46 +44,44 @@ internal class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
return null;
|
||||
return _collection[position];
|
||||
}
|
||||
public int Insert(T obj)
|
||||
public bool Insert(T obj)
|
||||
{
|
||||
// TODO вставка в свободное место набора
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
if (InsertingElementCollection(i, obj)) return i;
|
||||
if (InsertingElementCollection(i, obj)) return true;
|
||||
}
|
||||
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
public int Insert(T obj, int position)
|
||||
public bool Insert(T obj, int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
|
||||
// ищется свободное место после этой позиции и идет вставка туда
|
||||
// если нет после, ищем до
|
||||
// TODO вставка
|
||||
if (InsertingElementCollection(position, obj)) return position;
|
||||
if (InsertingElementCollection(position, obj)) return true;
|
||||
|
||||
for (int i = position + 1; i < Count; i++)
|
||||
{
|
||||
if (InsertingElementCollection(i, obj)) return position;
|
||||
if (InsertingElementCollection(i, obj)) return true;
|
||||
}
|
||||
|
||||
for (int i = position - 1; i >= 0; i--)
|
||||
{
|
||||
if (InsertingElementCollection(i, obj)) return position;
|
||||
if (InsertingElementCollection(i, obj)) return true;
|
||||
}
|
||||
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
public T? Remove(int position)
|
||||
public bool Remove(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO удаление объекта из массива, присвоив элементу массива значение null
|
||||
if (_collection[position] == null) return null;
|
||||
|
||||
T? temp = _collection[position];
|
||||
if (_collection[position] == null) return false;
|
||||
_collection[position] = null;
|
||||
return temp;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,73 @@
|
||||
namespace AntiAircraftGun.CollectionGenericObjects;
|
||||
/// <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)
|
||||
{
|
||||
// TODO проверка, что name не пустой и нет в словаре записи с таким ключом
|
||||
// TODO Прописать логику для добавления
|
||||
if (name.Length<=0 || _storages.ContainsKey(name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
switch(collectionType)
|
||||
{
|
||||
case CollectionType.List:
|
||||
_storages.Add(name, new ListGenericObjects<T>());
|
||||
break;
|
||||
case CollectionType.Massive:
|
||||
_storages.Add(name, new MassiveGenericObjects<T>());
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление коллекции
|
||||
/// </summary>
|
||||
/// <param name="name">Название коллекции</param>
|
||||
public void DelCollection(string name)
|
||||
{
|
||||
// TODO Прописать логику для удаления коллекции
|
||||
if(!_storages.ContainsKey(name)) { return; }
|
||||
_storages.Remove(name);
|
||||
}
|
||||
/// <summary>
|
||||
/// Доступ к коллекции
|
||||
/// </summary>
|
||||
/// <param name="name">Название коллекции</param>
|
||||
/// <returns></returns>
|
||||
public ICollectionGenericObjects<T>? this[string name]
|
||||
{
|
||||
get
|
||||
{
|
||||
// TODO Продумать логику получения объекта
|
||||
if (!_storages.ContainsKey(name)) { return null; }
|
||||
return _storages[name];
|
||||
}
|
||||
}
|
||||
}
|
@ -29,98 +29,67 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
groupBox1 = new GroupBox();
|
||||
buttonRefresh = new Button();
|
||||
buttonGoToCheck = new Button();
|
||||
buttonRemoveGun = new Button();
|
||||
maskedTextBox = new MaskedTextBox();
|
||||
buttonAddAntiAircraftGun = new Button();
|
||||
buttonAddGun = new Button();
|
||||
panelCompanyTools = new Panel();
|
||||
buttonCreateCompany = new Button();
|
||||
comboBoxSelectorCompany = new ComboBox();
|
||||
buttonAddGun = new Button();
|
||||
buttonRefresh = new Button();
|
||||
buttonAddAntiAircraftGun = new Button();
|
||||
buttonGoToCheck = new Button();
|
||||
maskedTextBox = new MaskedTextBox();
|
||||
buttonRemoveGun = new Button();
|
||||
panelStorage = new Panel();
|
||||
buttonCollectionDel = new Button();
|
||||
listBoxCollection = new ListBox();
|
||||
buttonCollectionAdd = new Button();
|
||||
textBoxCollectionName = new TextBox();
|
||||
radioButtonList = new RadioButton();
|
||||
radioButtonMassive = new RadioButton();
|
||||
labelNameCollection = new Label();
|
||||
pictureBox = new PictureBox();
|
||||
groupBox1.SuspendLayout();
|
||||
panelCompanyTools.SuspendLayout();
|
||||
panelStorage.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
groupBox1.Controls.Add(buttonRefresh);
|
||||
groupBox1.Controls.Add(buttonGoToCheck);
|
||||
groupBox1.Controls.Add(buttonRemoveGun);
|
||||
groupBox1.Controls.Add(maskedTextBox);
|
||||
groupBox1.Controls.Add(buttonAddAntiAircraftGun);
|
||||
groupBox1.Controls.Add(buttonAddGun);
|
||||
groupBox1.Controls.Add(comboBoxSelectorCompany);
|
||||
groupBox1.Controls.Add(panelCompanyTools);
|
||||
groupBox1.Controls.Add(panelStorage);
|
||||
groupBox1.Dock = DockStyle.Right;
|
||||
groupBox1.Location = new Point(940, 0);
|
||||
groupBox1.Location = new Point(981, 0);
|
||||
groupBox1.Name = "groupBox1";
|
||||
groupBox1.Size = new Size(235, 669);
|
||||
groupBox1.Size = new Size(235, 772);
|
||||
groupBox1.TabIndex = 0;
|
||||
groupBox1.TabStop = false;
|
||||
groupBox1.Text = "Инструменты";
|
||||
//
|
||||
// buttonRefresh
|
||||
// panelCompanyTools
|
||||
//
|
||||
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRefresh.Location = new Point(32, 578);
|
||||
buttonRefresh.Name = "buttonRefresh";
|
||||
buttonRefresh.Size = new Size(171, 70);
|
||||
buttonRefresh.TabIndex = 6;
|
||||
buttonRefresh.Text = "Обновить";
|
||||
buttonRefresh.UseVisualStyleBackColor = true;
|
||||
buttonRefresh.Click += ButtonRefresh_Click;
|
||||
panelCompanyTools.Controls.Add(buttonCreateCompany);
|
||||
panelCompanyTools.Controls.Add(comboBoxSelectorCompany);
|
||||
panelCompanyTools.Controls.Add(buttonAddGun);
|
||||
panelCompanyTools.Controls.Add(buttonRefresh);
|
||||
panelCompanyTools.Controls.Add(buttonAddAntiAircraftGun);
|
||||
panelCompanyTools.Controls.Add(buttonGoToCheck);
|
||||
panelCompanyTools.Controls.Add(maskedTextBox);
|
||||
panelCompanyTools.Controls.Add(buttonRemoveGun);
|
||||
panelCompanyTools.Dock = DockStyle.Bottom;
|
||||
panelCompanyTools.Location = new Point(3, 395);
|
||||
panelCompanyTools.Name = "panelCompanyTools";
|
||||
panelCompanyTools.Size = new Size(229, 374);
|
||||
panelCompanyTools.TabIndex = 9;
|
||||
//
|
||||
// buttonGoToCheck
|
||||
// buttonCreateCompany
|
||||
//
|
||||
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonGoToCheck.Location = new Point(32, 465);
|
||||
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||
buttonGoToCheck.Size = new Size(171, 70);
|
||||
buttonGoToCheck.TabIndex = 5;
|
||||
buttonGoToCheck.Text = "Передать на тесты";
|
||||
buttonGoToCheck.UseVisualStyleBackColor = true;
|
||||
buttonGoToCheck.Click += ButtonGoToCheck_Click;
|
||||
//
|
||||
// buttonRemoveGun
|
||||
//
|
||||
buttonRemoveGun.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRemoveGun.Location = new Point(32, 364);
|
||||
buttonRemoveGun.Name = "buttonRemoveGun";
|
||||
buttonRemoveGun.Size = new Size(171, 70);
|
||||
buttonRemoveGun.TabIndex = 4;
|
||||
buttonRemoveGun.Text = "Удалить установку";
|
||||
buttonRemoveGun.UseVisualStyleBackColor = true;
|
||||
buttonRemoveGun.Click += ButtonRemoveGun_Click;
|
||||
//
|
||||
// maskedTextBox
|
||||
//
|
||||
maskedTextBox.Location = new Point(32, 292);
|
||||
maskedTextBox.Mask = "00";
|
||||
maskedTextBox.Name = "maskedTextBox";
|
||||
maskedTextBox.Size = new Size(171, 27);
|
||||
maskedTextBox.TabIndex = 3;
|
||||
maskedTextBox.ValidatingType = typeof(int);
|
||||
//
|
||||
// buttonAddAntiAircraftGun
|
||||
//
|
||||
buttonAddAntiAircraftGun.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddAntiAircraftGun.Location = new Point(33, 191);
|
||||
buttonAddAntiAircraftGun.Name = "buttonAddAntiAircraftGun";
|
||||
buttonAddAntiAircraftGun.Size = new Size(171, 70);
|
||||
buttonAddAntiAircraftGun.TabIndex = 2;
|
||||
buttonAddAntiAircraftGun.Text = "Добавление зенитной установки";
|
||||
buttonAddAntiAircraftGun.UseVisualStyleBackColor = true;
|
||||
buttonAddAntiAircraftGun.Click += ButtonAddAntiAircraftGun_Click;
|
||||
//
|
||||
// buttonAddGun
|
||||
//
|
||||
buttonAddGun.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddGun.Location = new Point(32, 106);
|
||||
buttonAddGun.Name = "buttonAddGun";
|
||||
buttonAddGun.Size = new Size(171, 70);
|
||||
buttonAddGun.TabIndex = 1;
|
||||
buttonAddGun.Text = "Добавление установки";
|
||||
buttonAddGun.UseVisualStyleBackColor = true;
|
||||
buttonAddGun.Click += ButtonAddGun_Click;
|
||||
buttonCreateCompany.Location = new Point(9, 40);
|
||||
buttonCreateCompany.Name = "buttonCreateCompany";
|
||||
buttonCreateCompany.Size = new Size(217, 29);
|
||||
buttonCreateCompany.TabIndex = 8;
|
||||
buttonCreateCompany.Text = "Создать компанию";
|
||||
buttonCreateCompany.UseVisualStyleBackColor = true;
|
||||
buttonCreateCompany.Click += ButtonCreateCompany_Click;
|
||||
//
|
||||
// comboBoxSelectorCompany
|
||||
//
|
||||
@ -128,18 +97,164 @@
|
||||
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxSelectorCompany.FormattingEnabled = true;
|
||||
comboBoxSelectorCompany.Items.AddRange(new object[] { "База" });
|
||||
comboBoxSelectorCompany.Location = new Point(33, 43);
|
||||
comboBoxSelectorCompany.Location = new Point(9, 6);
|
||||
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
||||
comboBoxSelectorCompany.Size = new Size(171, 28);
|
||||
comboBoxSelectorCompany.Size = new Size(214, 28);
|
||||
comboBoxSelectorCompany.TabIndex = 0;
|
||||
comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged;
|
||||
comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
|
||||
//
|
||||
// buttonAddGun
|
||||
//
|
||||
buttonAddGun.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddGun.Location = new Point(9, 87);
|
||||
buttonAddGun.Name = "buttonAddGun";
|
||||
buttonAddGun.Size = new Size(214, 52);
|
||||
buttonAddGun.TabIndex = 1;
|
||||
buttonAddGun.Text = "Добавление установки";
|
||||
buttonAddGun.UseVisualStyleBackColor = true;
|
||||
buttonAddGun.Click += ButtonAddGun_Click;
|
||||
//
|
||||
// buttonRefresh
|
||||
//
|
||||
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRefresh.Location = new Point(9, 313);
|
||||
buttonRefresh.Name = "buttonRefresh";
|
||||
buttonRefresh.Size = new Size(214, 39);
|
||||
buttonRefresh.TabIndex = 6;
|
||||
buttonRefresh.Text = "Обновить";
|
||||
buttonRefresh.UseVisualStyleBackColor = true;
|
||||
buttonRefresh.Click += ButtonRefresh_Click;
|
||||
//
|
||||
// buttonAddAntiAircraftGun
|
||||
//
|
||||
buttonAddAntiAircraftGun.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddAntiAircraftGun.Location = new Point(9, 145);
|
||||
buttonAddAntiAircraftGun.Name = "buttonAddAntiAircraftGun";
|
||||
buttonAddAntiAircraftGun.Size = new Size(214, 52);
|
||||
buttonAddAntiAircraftGun.TabIndex = 2;
|
||||
buttonAddAntiAircraftGun.Text = "Добавление зенитной установки";
|
||||
buttonAddAntiAircraftGun.UseVisualStyleBackColor = true;
|
||||
buttonAddAntiAircraftGun.Click += ButtonAddAntiAircraftGun_Click;
|
||||
//
|
||||
// buttonGoToCheck
|
||||
//
|
||||
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonGoToCheck.Location = new Point(9, 274);
|
||||
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||
buttonGoToCheck.Size = new Size(214, 33);
|
||||
buttonGoToCheck.TabIndex = 5;
|
||||
buttonGoToCheck.Text = "Передать на тесты";
|
||||
buttonGoToCheck.UseVisualStyleBackColor = true;
|
||||
buttonGoToCheck.Click += ButtonGoToCheck_Click;
|
||||
//
|
||||
// maskedTextBox
|
||||
//
|
||||
maskedTextBox.Location = new Point(9, 203);
|
||||
maskedTextBox.Mask = "00";
|
||||
maskedTextBox.Name = "maskedTextBox";
|
||||
maskedTextBox.Size = new Size(217, 27);
|
||||
maskedTextBox.TabIndex = 3;
|
||||
maskedTextBox.ValidatingType = typeof(int);
|
||||
//
|
||||
// buttonRemoveGun
|
||||
//
|
||||
buttonRemoveGun.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRemoveGun.Location = new Point(9, 236);
|
||||
buttonRemoveGun.Name = "buttonRemoveGun";
|
||||
buttonRemoveGun.Size = new Size(214, 32);
|
||||
buttonRemoveGun.TabIndex = 4;
|
||||
buttonRemoveGun.Text = "Удалить установку";
|
||||
buttonRemoveGun.UseVisualStyleBackColor = true;
|
||||
buttonRemoveGun.Click += ButtonRemoveGun_Click;
|
||||
//
|
||||
// panelStorage
|
||||
//
|
||||
panelStorage.Controls.Add(buttonCollectionDel);
|
||||
panelStorage.Controls.Add(listBoxCollection);
|
||||
panelStorage.Controls.Add(buttonCollectionAdd);
|
||||
panelStorage.Controls.Add(textBoxCollectionName);
|
||||
panelStorage.Controls.Add(radioButtonList);
|
||||
panelStorage.Controls.Add(radioButtonMassive);
|
||||
panelStorage.Controls.Add(labelNameCollection);
|
||||
panelStorage.Dock = DockStyle.Top;
|
||||
panelStorage.Location = new Point(3, 23);
|
||||
panelStorage.Name = "panelStorage";
|
||||
panelStorage.Size = new Size(229, 366);
|
||||
panelStorage.TabIndex = 7;
|
||||
//
|
||||
// buttonCollectionDel
|
||||
//
|
||||
buttonCollectionDel.Location = new Point(9, 326);
|
||||
buttonCollectionDel.Name = "buttonCollectionDel";
|
||||
buttonCollectionDel.Size = new Size(217, 29);
|
||||
buttonCollectionDel.TabIndex = 6;
|
||||
buttonCollectionDel.Text = "Удалить коллекцию";
|
||||
buttonCollectionDel.UseVisualStyleBackColor = true;
|
||||
buttonCollectionDel.Click += ButtonCollectionDel_Click;
|
||||
//
|
||||
// listBoxCollection
|
||||
//
|
||||
listBoxCollection.FormattingEnabled = true;
|
||||
listBoxCollection.ItemHeight = 20;
|
||||
listBoxCollection.Location = new Point(9, 164);
|
||||
listBoxCollection.Name = "listBoxCollection";
|
||||
listBoxCollection.Size = new Size(217, 144);
|
||||
listBoxCollection.TabIndex = 5;
|
||||
//
|
||||
// buttonCollectionAdd
|
||||
//
|
||||
buttonCollectionAdd.Location = new Point(9, 120);
|
||||
buttonCollectionAdd.Name = "buttonCollectionAdd";
|
||||
buttonCollectionAdd.Size = new Size(217, 29);
|
||||
buttonCollectionAdd.TabIndex = 4;
|
||||
buttonCollectionAdd.Text = "Добаваить коллекцию";
|
||||
buttonCollectionAdd.UseVisualStyleBackColor = true;
|
||||
buttonCollectionAdd.Click += ButtonCollectionAdd_Click;
|
||||
//
|
||||
// textBoxCollectionName
|
||||
//
|
||||
textBoxCollectionName.Location = new Point(9, 41);
|
||||
textBoxCollectionName.Name = "textBoxCollectionName";
|
||||
textBoxCollectionName.Size = new Size(217, 27);
|
||||
textBoxCollectionName.TabIndex = 3;
|
||||
//
|
||||
// radioButtonList
|
||||
//
|
||||
radioButtonList.AutoSize = true;
|
||||
radioButtonList.Location = new Point(146, 74);
|
||||
radioButtonList.Name = "radioButtonList";
|
||||
radioButtonList.Size = new Size(80, 24);
|
||||
radioButtonList.TabIndex = 2;
|
||||
radioButtonList.TabStop = true;
|
||||
radioButtonList.Text = "Список";
|
||||
radioButtonList.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// radioButtonMassive
|
||||
//
|
||||
radioButtonMassive.AutoSize = true;
|
||||
radioButtonMassive.Location = new Point(9, 74);
|
||||
radioButtonMassive.Name = "radioButtonMassive";
|
||||
radioButtonMassive.Size = new Size(82, 24);
|
||||
radioButtonMassive.TabIndex = 1;
|
||||
radioButtonMassive.TabStop = true;
|
||||
radioButtonMassive.Text = "Массив";
|
||||
radioButtonMassive.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// labelNameCollection
|
||||
//
|
||||
labelNameCollection.AutoSize = true;
|
||||
labelNameCollection.Location = new Point(41, 11);
|
||||
labelNameCollection.Name = "labelNameCollection";
|
||||
labelNameCollection.Size = new Size(155, 20);
|
||||
labelNameCollection.TabIndex = 0;
|
||||
labelNameCollection.Text = "Название коллекции";
|
||||
//
|
||||
// pictureBox
|
||||
//
|
||||
pictureBox.Dock = DockStyle.Fill;
|
||||
pictureBox.Location = new Point(0, 0);
|
||||
pictureBox.Name = "pictureBox";
|
||||
pictureBox.Size = new Size(940, 669);
|
||||
pictureBox.Size = new Size(981, 772);
|
||||
pictureBox.TabIndex = 1;
|
||||
pictureBox.TabStop = false;
|
||||
//
|
||||
@ -147,13 +262,16 @@
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1175, 669);
|
||||
ClientSize = new Size(1216, 772);
|
||||
Controls.Add(pictureBox);
|
||||
Controls.Add(groupBox1);
|
||||
Name = "FormGunCollections";
|
||||
Text = "Коллекция установок";
|
||||
groupBox1.ResumeLayout(false);
|
||||
groupBox1.PerformLayout();
|
||||
panelCompanyTools.ResumeLayout(false);
|
||||
panelCompanyTools.PerformLayout();
|
||||
panelStorage.ResumeLayout(false);
|
||||
panelStorage.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
@ -169,5 +287,15 @@
|
||||
private Button buttonRemoveGun;
|
||||
private Button buttonRefresh;
|
||||
private Button buttonGoToCheck;
|
||||
private Panel panelStorage;
|
||||
private ListBox listBoxCollection;
|
||||
private Button buttonCollectionAdd;
|
||||
private TextBox textBoxCollectionName;
|
||||
private RadioButton radioButtonList;
|
||||
private RadioButton radioButtonMassive;
|
||||
private Label labelNameCollection;
|
||||
private Button buttonCreateCompany;
|
||||
private Button buttonCollectionDel;
|
||||
private Panel panelCompanyTools;
|
||||
}
|
||||
}
|
@ -5,8 +5,10 @@ namespace AntiAircraftGun;
|
||||
|
||||
public partial class FormGunCollections : Form
|
||||
{
|
||||
|
||||
private readonly StorageCollection<DrawningGun> _storageCollection;
|
||||
/// <summary>
|
||||
///
|
||||
/// Компания
|
||||
/// </summary>
|
||||
private AbstractCompany? _company = null;
|
||||
/// <summary>
|
||||
@ -15,20 +17,16 @@ public partial class FormGunCollections : Form
|
||||
public FormGunCollections()
|
||||
{
|
||||
InitializeComponent();
|
||||
_storageCollection = new();
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </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 GunSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningGun>());
|
||||
break;
|
||||
}
|
||||
panelCompanyTools.Enabled = true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Создание объекта класса перемещения
|
||||
@ -61,7 +59,7 @@ public partial class FormGunCollections : Form
|
||||
default:
|
||||
return;
|
||||
}
|
||||
if (_company + _drawningGun!=-1)
|
||||
if (_company + _drawningGun)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _company.Show();
|
||||
@ -83,17 +81,29 @@ public partial class FormGunCollections : Form
|
||||
if (dialog.ShowDialog() == DialogResult.OK) { color = dialog.Color; }
|
||||
return color;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавление установки
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddGun_Click(object sender, EventArgs e)
|
||||
{
|
||||
CreateObj(nameof(DrawningGun));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавление зенитной устновки
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddAntiAircraftGun_Click(object sender, EventArgs e)
|
||||
{
|
||||
CreateObj(nameof(DrawningAntiAircraftGun));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление установки
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRemoveGun_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_company == null)
|
||||
@ -106,7 +116,7 @@ public partial class FormGunCollections : Form
|
||||
}
|
||||
if (MessageBox.Show("Удалить объект", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; }
|
||||
int pos = Convert.ToInt32(maskedTextBox.Text);
|
||||
if (_company - pos is DrawningGun)
|
||||
if (_company - pos)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBox.Image = _company.Show();
|
||||
@ -117,7 +127,11 @@ public partial class FormGunCollections : Form
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Передача объекта на тесты
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonGoToCheck_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_company == null)
|
||||
@ -148,7 +162,11 @@ public partial class FormGunCollections : Form
|
||||
form.ShowDialog();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обновление экрана
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRefresh_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_company == null)
|
||||
@ -157,4 +175,90 @@ public partial class FormGunCollections : 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);
|
||||
RerfreshListBoxItems();
|
||||
}
|
||||
/// <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;
|
||||
}
|
||||
_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<DrawningGun>? collection =
|
||||
_storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
|
||||
if (collection == null)
|
||||
{
|
||||
MessageBox.Show("Коллекция не проинициализирована");
|
||||
return;
|
||||
}
|
||||
switch (comboBoxSelectorCompany.Text)
|
||||
{
|
||||
case "База":
|
||||
_company = new GunSharingService(pictureBox.Width,
|
||||
pictureBox.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user