PIBD-14_Lavrova_K.I._LabWork04_Simple #4
15
solution/lab1/CollectionGenericObjects/ClassForDop.cs
Normal file
15
solution/lab1/CollectionGenericObjects/ClassForDop.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using lab1.Drawnings;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace lab1.CollectionGenericObjects
|
||||
{
|
||||
internal class ClassForDoppublic<T>
|
||||
where T : DrawningTrackedVehicle
|
||||
{
|
||||
|
||||
}
|
||||
}
|
23
solution/lab1/CollectionGenericObjects/CollectionType.cs
Normal file
23
solution/lab1/CollectionGenericObjects/CollectionType.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace lab1.CollectionGenericObjects;
|
||||
|
||||
public enum CollectionType
|
||||
{
|
||||
/// <summary>
|
||||
/// Неопределено
|
||||
/// </summary>
|
||||
None = 0,
|
||||
/// <summary>
|
||||
/// Массив
|
||||
/// </summary>
|
||||
Massive = 1,
|
||||
/// <summary>
|
||||
/// Список
|
||||
/// </summary>
|
||||
List = 2
|
||||
}
|
79
solution/lab1/CollectionGenericObjects/ListGenericObjects.cs
Normal file
79
solution/lab1/CollectionGenericObjects/ListGenericObjects.cs
Normal file
@ -0,0 +1,79 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace lab1.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)
|
||||
{
|
||||
if (position >= 0 && position < _collection.Count)
|
||||
{
|
||||
return _collection[position];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int Insert(T obj)
|
||||
{
|
||||
// TODO проверка, что не превышено максимальное количество элементов
|
||||
// TODO вставка в конец набора
|
||||
if (_collection.Count <= _maxCount)
|
||||
{
|
||||
_collection.Add(obj);
|
||||
return _collection.Count;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int Insert(T obj, int position)
|
||||
{
|
||||
// TODO проверка, что не превышено максимальное количество элементов
|
||||
// TODO проверка позиции
|
||||
// TODO вставка по позиции
|
||||
if (position >= 0 && position < _maxCount && _collection.Count <= _maxCount)
|
||||
{
|
||||
_collection.Insert(position, obj);
|
||||
return position;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public T? Remove(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO удаление объекта из списка
|
||||
if (position < 0 || position > _maxCount)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
T temp = _collection[position];
|
||||
_collection.RemoveAt(position);
|
||||
return temp;
|
||||
}
|
||||
}
|
@ -15,10 +15,25 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
private T?[] _collection;
|
||||
public int Count => _collection.Length;
|
||||
|
||||
public int SetMaxCount { set { if (value > 0) { _collection = new T?[value]; } } }
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
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?>();
|
||||
|
73
solution/lab1/CollectionGenericObjects/StorageCollection.cs
Normal file
73
solution/lab1/CollectionGenericObjects/StorageCollection.cs
Normal file
@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace lab1.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)
|
||||
{
|
||||
|
||||
if (_storages.ContainsKey(name)) return;
|
||||
if (collectionType == CollectionType.None) return;
|
||||
else if (collectionType == CollectionType.Massive)
|
||||
_storages[name] = new MassiveGenericObjects<T>();
|
||||
else if (collectionType == CollectionType.List)
|
||||
_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 ICollectionGenericObjects<T>? this[string name]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_storages.ContainsKey(name))
|
||||
return _storages[name];
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -31,24 +31,24 @@ public class DrawningEntityFighter : DrawningTrackedVehicle
|
||||
Brush CraneBrush = new SolidBrush(fighter.AdditionalColor);
|
||||
|
||||
|
||||
|
||||
base.DrawTransport(g);
|
||||
|
||||
|
||||
if (fighter.Kovsh)
|
||||
{
|
||||
|
||||
//ковш
|
||||
g.DrawRectangle(pen, _startPosX.Value - 2, _startPosY.Value + 37, 8, 15);
|
||||
g.FillRectangle(CraneBrush, _startPosX.Value - 2, _startPosY.Value + 37, 8, 15);
|
||||
g.DrawRectangle(pen, _startPosX.Value - -6, _startPosY.Value + 37, 4, 1);
|
||||
///ковш
|
||||
g.DrawRectangle(pen, _startPosX.Value - 17, _startPosY.Value + 12, 8, 15);
|
||||
g.FillRectangle(CraneBrush, _startPosX.Value - 17, _startPosY.Value + 12, 8, 15);
|
||||
g.DrawRectangle(pen, _startPosX.Value - 8, _startPosY.Value + 17, 5, 1);
|
||||
|
||||
}
|
||||
|
||||
//противовес
|
||||
///противовес
|
||||
if (fighter.Otval)
|
||||
{
|
||||
g.DrawRectangle(pen, _startPosX.Value + 73, _startPosY.Value + 37, 17, 1);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value + 37, 1, 17);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 63, _startPosY.Value + 17, 17, 1);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 80, _startPosY.Value + 17, 1, 16);
|
||||
|
||||
|
||||
}
|
||||
|
224
solution/lab1/FormTrackedVehicleCollection.Designer.cs
generated
224
solution/lab1/FormTrackedVehicleCollection.Designer.cs
generated
@ -29,52 +29,117 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
groupBoxTools = new GroupBox();
|
||||
buttonCollectionDel = new Button();
|
||||
panelCompanyTools = new Panel();
|
||||
buttonAddFighter = new Button();
|
||||
buttonAddTrackedVehicle = new Button();
|
||||
buttonRefresh = new Button();
|
||||
maskedTextBox = new MaskedTextBox();
|
||||
buttonGoToCheck = new Button();
|
||||
buttonRemoveTrackedVehicle = new Button();
|
||||
maskedTextBox = new MaskedTextBox();
|
||||
buttonAddTrackedVehicle = new Button();
|
||||
buttonAddFighter = new Button();
|
||||
button1CreateCompany = new Button();
|
||||
panelStorage = new Panel();
|
||||
listBoxCollection = new ListBox();
|
||||
buttonCollectionAdd = new Button();
|
||||
radioButtonList = new RadioButton();
|
||||
radioButtonMassive = new RadioButton();
|
||||
textBoxCollectionName = new TextBox();
|
||||
labelCollectionName = new Label();
|
||||
comboBoxSelectorCompany = new ComboBox();
|
||||
pictureBox = new PictureBox();
|
||||
groupBoxTools.SuspendLayout();
|
||||
panelCompanyTools.SuspendLayout();
|
||||
panelStorage.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBoxTools
|
||||
//
|
||||
groupBoxTools.Controls.Add(buttonRefresh);
|
||||
groupBoxTools.Controls.Add(buttonGoToCheck);
|
||||
groupBoxTools.Controls.Add(buttonRemoveTrackedVehicle);
|
||||
groupBoxTools.Controls.Add(maskedTextBox);
|
||||
groupBoxTools.Controls.Add(buttonAddTrackedVehicle);
|
||||
groupBoxTools.Controls.Add(buttonAddFighter);
|
||||
groupBoxTools.Controls.Add(buttonCollectionDel);
|
||||
groupBoxTools.Controls.Add(panelCompanyTools);
|
||||
groupBoxTools.Controls.Add(button1CreateCompany);
|
||||
groupBoxTools.Controls.Add(panelStorage);
|
||||
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
|
||||
groupBoxTools.Dock = DockStyle.Right;
|
||||
groupBoxTools.Location = new Point(886, 0);
|
||||
groupBoxTools.Location = new Point(677, 0);
|
||||
groupBoxTools.Name = "groupBoxTools";
|
||||
groupBoxTools.Size = new Size(297, 617);
|
||||
groupBoxTools.Size = new Size(297, 710);
|
||||
groupBoxTools.TabIndex = 0;
|
||||
groupBoxTools.TabStop = false;
|
||||
groupBoxTools.Text = "Инструменты";
|
||||
//
|
||||
// buttonCollectionDel
|
||||
//
|
||||
buttonCollectionDel.Location = new Point(3, 284);
|
||||
buttonCollectionDel.Name = "buttonCollectionDel";
|
||||
buttonCollectionDel.Size = new Size(276, 34);
|
||||
buttonCollectionDel.TabIndex = 6;
|
||||
buttonCollectionDel.Text = "Удалить коллекцию";
|
||||
buttonCollectionDel.UseVisualStyleBackColor = true;
|
||||
buttonCollectionDel.Click += buttonCollectionDel_Click;
|
||||
//
|
||||
// panelCompanyTools
|
||||
//
|
||||
panelCompanyTools.Controls.Add(buttonAddFighter);
|
||||
panelCompanyTools.Controls.Add(buttonAddTrackedVehicle);
|
||||
panelCompanyTools.Controls.Add(buttonRefresh);
|
||||
panelCompanyTools.Controls.Add(maskedTextBox);
|
||||
panelCompanyTools.Controls.Add(buttonGoToCheck);
|
||||
panelCompanyTools.Controls.Add(buttonRemoveTrackedVehicle);
|
||||
panelCompanyTools.Enabled = false;
|
||||
panelCompanyTools.Location = new Point(3, 431);
|
||||
panelCompanyTools.Name = "panelCompanyTools";
|
||||
panelCompanyTools.Size = new Size(282, 273);
|
||||
panelCompanyTools.TabIndex = 10;
|
||||
//
|
||||
// buttonAddFighter
|
||||
//
|
||||
buttonAddFighter.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddFighter.Location = new Point(6, 59);
|
||||
buttonAddFighter.Name = "buttonAddFighter";
|
||||
buttonAddFighter.Size = new Size(273, 59);
|
||||
buttonAddFighter.TabIndex = 2;
|
||||
buttonAddFighter.Text = "Добавление гусеничной машины с оборудованием";
|
||||
buttonAddFighter.UseVisualStyleBackColor = true;
|
||||
buttonAddFighter.Click += ButtonAddFighter_Click;
|
||||
//
|
||||
// buttonAddTrackedVehicle
|
||||
//
|
||||
buttonAddTrackedVehicle.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddTrackedVehicle.Location = new Point(6, 0);
|
||||
buttonAddTrackedVehicle.Name = "buttonAddTrackedVehicle";
|
||||
buttonAddTrackedVehicle.Size = new Size(273, 63);
|
||||
buttonAddTrackedVehicle.TabIndex = 3;
|
||||
buttonAddTrackedVehicle.Text = "Добавление гусеничной машины";
|
||||
buttonAddTrackedVehicle.UseVisualStyleBackColor = true;
|
||||
buttonAddTrackedVehicle.Click += ButtonAddTrackedVehicle_Click;
|
||||
//
|
||||
// buttonRefresh
|
||||
//
|
||||
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRefresh.Location = new Point(7, 516);
|
||||
buttonRefresh.Location = new Point(7, 239);
|
||||
buttonRefresh.Name = "buttonRefresh";
|
||||
buttonRefresh.Size = new Size(284, 53);
|
||||
buttonRefresh.Size = new Size(272, 31);
|
||||
buttonRefresh.TabIndex = 7;
|
||||
buttonRefresh.Text = "Обновить";
|
||||
buttonRefresh.UseVisualStyleBackColor = true;
|
||||
buttonRefresh.Click += ButtonRefresh_Click_1;
|
||||
//
|
||||
// maskedTextBox
|
||||
//
|
||||
maskedTextBox.Location = new Point(3, 124);
|
||||
maskedTextBox.Mask = "00";
|
||||
maskedTextBox.Name = "maskedTextBox";
|
||||
maskedTextBox.Size = new Size(284, 31);
|
||||
maskedTextBox.TabIndex = 4;
|
||||
maskedTextBox.ValidatingType = typeof(int);
|
||||
//
|
||||
// buttonGoToCheck
|
||||
//
|
||||
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonGoToCheck.Location = new Point(5, 457);
|
||||
buttonGoToCheck.Location = new Point(7, 205);
|
||||
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||
buttonGoToCheck.Size = new Size(286, 53);
|
||||
buttonGoToCheck.Size = new Size(274, 33);
|
||||
buttonGoToCheck.TabIndex = 6;
|
||||
buttonGoToCheck.Text = "Передать на тесты";
|
||||
buttonGoToCheck.UseVisualStyleBackColor = true;
|
||||
@ -83,45 +148,94 @@
|
||||
// buttonRemoveTrackedVehicle
|
||||
//
|
||||
buttonRemoveTrackedVehicle.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRemoveTrackedVehicle.Location = new Point(5, 342);
|
||||
buttonRemoveTrackedVehicle.Location = new Point(7, 161);
|
||||
buttonRemoveTrackedVehicle.Name = "buttonRemoveTrackedVehicle";
|
||||
buttonRemoveTrackedVehicle.Size = new Size(286, 82);
|
||||
buttonRemoveTrackedVehicle.Size = new Size(274, 38);
|
||||
buttonRemoveTrackedVehicle.TabIndex = 5;
|
||||
buttonRemoveTrackedVehicle.Text = "Удаление гусеничной машины";
|
||||
buttonRemoveTrackedVehicle.UseVisualStyleBackColor = true;
|
||||
buttonRemoveTrackedVehicle.Click += ButtonRemoveTrackedVehicle_Click;
|
||||
//
|
||||
// maskedTextBox
|
||||
// button1CreateCompany
|
||||
//
|
||||
maskedTextBox.Location = new Point(7, 305);
|
||||
maskedTextBox.Mask = "00";
|
||||
maskedTextBox.Name = "maskedTextBox";
|
||||
maskedTextBox.Size = new Size(284, 31);
|
||||
maskedTextBox.TabIndex = 4;
|
||||
maskedTextBox.ValidatingType = typeof(int);
|
||||
maskedTextBox.MaskInputRejected += maskedTextBox1_MaskInputRejected;
|
||||
button1CreateCompany.Location = new Point(6, 376);
|
||||
button1CreateCompany.Name = "button1CreateCompany";
|
||||
button1CreateCompany.Size = new Size(276, 34);
|
||||
button1CreateCompany.TabIndex = 9;
|
||||
button1CreateCompany.Text = "Создать компанию";
|
||||
button1CreateCompany.UseVisualStyleBackColor = true;
|
||||
button1CreateCompany.Click += button1CreateCompany_Click;
|
||||
//
|
||||
// buttonAddTrackedVehicle
|
||||
// panelStorage
|
||||
//
|
||||
buttonAddTrackedVehicle.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddTrackedVehicle.Location = new Point(12, 181);
|
||||
buttonAddTrackedVehicle.Name = "buttonAddTrackedVehicle";
|
||||
buttonAddTrackedVehicle.Size = new Size(279, 82);
|
||||
buttonAddTrackedVehicle.TabIndex = 3;
|
||||
buttonAddTrackedVehicle.Text = "Добавление гусеничной машины";
|
||||
buttonAddTrackedVehicle.UseVisualStyleBackColor = true;
|
||||
buttonAddTrackedVehicle.Click += ButtonAddTrackedVehicle_Click;
|
||||
panelStorage.Controls.Add(listBoxCollection);
|
||||
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, 27);
|
||||
panelStorage.Name = "panelStorage";
|
||||
panelStorage.Size = new Size(291, 226);
|
||||
panelStorage.TabIndex = 8;
|
||||
//
|
||||
// buttonAddFighter
|
||||
// listBoxCollection
|
||||
//
|
||||
buttonAddFighter.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddFighter.Location = new Point(0, 98);
|
||||
buttonAddFighter.Name = "buttonAddFighter";
|
||||
buttonAddFighter.Size = new Size(291, 77);
|
||||
buttonAddFighter.TabIndex = 2;
|
||||
buttonAddFighter.Text = "Добавление истребителя";
|
||||
buttonAddFighter.UseVisualStyleBackColor = true;
|
||||
buttonAddFighter.Click += ButtonAddTrackedVehicle_Click;
|
||||
listBoxCollection.FormattingEnabled = true;
|
||||
listBoxCollection.ItemHeight = 25;
|
||||
listBoxCollection.Location = new Point(6, 154);
|
||||
listBoxCollection.Name = "listBoxCollection";
|
||||
listBoxCollection.Size = new Size(276, 104);
|
||||
listBoxCollection.TabIndex = 5;
|
||||
//
|
||||
// buttonCollectionAdd
|
||||
//
|
||||
buttonCollectionAdd.Location = new Point(6, 114);
|
||||
buttonCollectionAdd.Name = "buttonCollectionAdd";
|
||||
buttonCollectionAdd.Size = new Size(276, 34);
|
||||
buttonCollectionAdd.TabIndex = 4;
|
||||
buttonCollectionAdd.Text = "Добавить коллекцию";
|
||||
buttonCollectionAdd.UseVisualStyleBackColor = true;
|
||||
buttonCollectionAdd.Click += buttonCollectionAdd_Click;
|
||||
//
|
||||
// radioButtonList
|
||||
//
|
||||
radioButtonList.AutoSize = true;
|
||||
radioButtonList.Location = new Point(153, 79);
|
||||
radioButtonList.Name = "radioButtonList";
|
||||
radioButtonList.Size = new Size(96, 29);
|
||||
radioButtonList.TabIndex = 3;
|
||||
radioButtonList.TabStop = true;
|
||||
radioButtonList.Text = "Список";
|
||||
radioButtonList.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// radioButtonMassive
|
||||
//
|
||||
radioButtonMassive.AutoSize = true;
|
||||
radioButtonMassive.Location = new Point(41, 79);
|
||||
radioButtonMassive.Name = "radioButtonMassive";
|
||||
radioButtonMassive.Size = new Size(98, 29);
|
||||
radioButtonMassive.TabIndex = 2;
|
||||
radioButtonMassive.TabStop = true;
|
||||
radioButtonMassive.Text = "Массив";
|
||||
radioButtonMassive.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// textBoxCollectionName
|
||||
//
|
||||
textBoxCollectionName.Location = new Point(4, 42);
|
||||
textBoxCollectionName.Name = "textBoxCollectionName";
|
||||
textBoxCollectionName.Size = new Size(278, 31);
|
||||
textBoxCollectionName.TabIndex = 1;
|
||||
//
|
||||
// labelCollectionName
|
||||
//
|
||||
labelCollectionName.AutoSize = true;
|
||||
labelCollectionName.Location = new Point(41, 14);
|
||||
labelCollectionName.Name = "labelCollectionName";
|
||||
labelCollectionName.Size = new Size(186, 25);
|
||||
labelCollectionName.TabIndex = 0;
|
||||
labelCollectionName.Text = "Название коллекции:";
|
||||
//
|
||||
// comboBoxSelectorCompany
|
||||
//
|
||||
@ -129,34 +243,34 @@
|
||||
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxSelectorCompany.FormattingEnabled = true;
|
||||
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
|
||||
comboBoxSelectorCompany.Location = new Point(7, 30);
|
||||
comboBoxSelectorCompany.Location = new Point(1, 324);
|
||||
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
||||
comboBoxSelectorCompany.Size = new Size(284, 33);
|
||||
comboBoxSelectorCompany.TabIndex = 1;
|
||||
comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged;
|
||||
//
|
||||
// pictureBox
|
||||
//
|
||||
pictureBox.Dock = DockStyle.Fill;
|
||||
pictureBox.Location = new Point(0, 0);
|
||||
pictureBox.Name = "pictureBox";
|
||||
pictureBox.Size = new Size(886, 617);
|
||||
pictureBox.Size = new Size(677, 710);
|
||||
pictureBox.TabIndex = 1;
|
||||
pictureBox.TabStop = false;
|
||||
pictureBox.Click += pictureBox1_Click;
|
||||
//
|
||||
// FormTrackedVehicleCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(10F, 25F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1183, 617);
|
||||
ClientSize = new Size(974, 710);
|
||||
Controls.Add(pictureBox);
|
||||
Controls.Add(groupBoxTools);
|
||||
Name = "FormTrackedVehicleCollection";
|
||||
Text = "Коллекция гусеничных машин";
|
||||
Load += FormTrackedVehicleCollection_Load;
|
||||
groupBoxTools.ResumeLayout(false);
|
||||
groupBoxTools.PerformLayout();
|
||||
panelCompanyTools.ResumeLayout(false);
|
||||
panelCompanyTools.PerformLayout();
|
||||
panelStorage.ResumeLayout(false);
|
||||
panelStorage.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
@ -172,5 +286,15 @@
|
||||
private MaskedTextBox maskedTextBox;
|
||||
private Button buttonGoToCheck;
|
||||
private Button buttonRefresh;
|
||||
private Panel panelStorage;
|
||||
private TextBox textBoxCollectionName;
|
||||
private Label labelCollectionName;
|
||||
private RadioButton radioButtonList;
|
||||
private RadioButton radioButtonMassive;
|
||||
private ListBox listBoxCollection;
|
||||
private Button buttonCollectionAdd;
|
||||
private Button button1CreateCompany;
|
||||
private Button buttonCollectionDel;
|
||||
private Panel panelCompanyTools;
|
||||
}
|
||||
}
|
@ -1,12 +1,18 @@
|
||||
using lab1.CollectionGenericObjects;
|
||||
using lab1.Drawnings;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace lab1;
|
||||
|
||||
/// <summary>
|
||||
///Форма работы с компанией и её коллекцией
|
||||
/// Форма работы с компанией и ее коллекцией
|
||||
/// </summary>
|
||||
public partial class FormTrackedVehicleCollection : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Хранилише коллекций
|
||||
/// </summary>
|
||||
private readonly StorageCollection<DrawningTrackedVehicle> _storageCollection;
|
||||
/// <summary>
|
||||
/// Компания
|
||||
/// </summary>
|
||||
@ -18,14 +24,15 @@ public partial class FormTrackedVehicleCollection : Form
|
||||
public FormTrackedVehicleCollection()
|
||||
{
|
||||
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)
|
||||
{
|
||||
@ -36,63 +43,64 @@ public partial class FormTrackedVehicleCollection : Form
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавление гусеничной машины
|
||||
/// Добавление обычного автомобиля
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddTrackedVehicle_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTrackedVehicle));
|
||||
|
||||
/// <summary>
|
||||
/// Добавление истребителя
|
||||
/// Добавление спортивного автомобиля
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddEntityFighter_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningEntityFighter));
|
||||
private void ButtonAddFighter_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningEntityFighter));
|
||||
|
||||
/// <summary>
|
||||
/// Создание объекта класса-перемещения
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="type">Тип создаваемого объекта</param>
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Random random = new();
|
||||
DrawningTrackedVehicle drawningTrackedVehicle;
|
||||
DrawningTrackedVehicle drawingTrans;
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningTrackedVehicle):
|
||||
drawningTrackedVehicle = new DrawningTrackedVehicle(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
|
||||
drawingTrans = new DrawningTrackedVehicle(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
|
||||
break;
|
||||
case nameof(DrawningEntityFighter):
|
||||
drawningTrackedVehicle = new DrawningEntityFighter(random.Next(100, 300), random.Next(1000, 3000),
|
||||
GetColor(random),
|
||||
GetColor(random),
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||
// вызов диалогового окна для выбора цвета
|
||||
drawingTrans = new DrawningEntityFighter(random.Next(100, 300), random.Next(1000, 3000),
|
||||
GetColor(random),
|
||||
GetColor(random),
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
|
||||
}
|
||||
if (_company + drawningTrackedVehicle != -1)
|
||||
|
||||
if (_company + drawingTrans != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
_ = MessageBox.Show(drawingTrans.ToString());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение цвета
|
||||
/// </summary>
|
||||
/// <param name="random">Генератор случайных чисел</param>
|
||||
/// <returns></returns>
|
||||
/// Получение цвета
|
||||
/// </summary>
|
||||
/// <param name="random">Генератор случайных чисел</param>
|
||||
/// <returns></returns>
|
||||
private static Color GetColor(Random random)
|
||||
{
|
||||
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
@ -101,28 +109,27 @@ public partial class FormTrackedVehicleCollection : Form
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Удаление объекта
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRemoveTrackedVehicle_Click(object sender, EventArgs e)
|
||||
private void buttonCollectionDel_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int pos = Convert.ToInt32(maskedTextBox.Text);
|
||||
if (_company - pos != null)
|
||||
{
|
||||
@ -134,42 +141,43 @@ public partial class FormTrackedVehicleCollection : Form
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Передача объекта в другую форму
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
|
||||
private void button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
DrawningTrackedVehicle? fighter = null;
|
||||
|
||||
DrawningTrackedVehicle? car = null;
|
||||
int counter = 100;
|
||||
while (fighter == null)
|
||||
while (car == null)
|
||||
{
|
||||
fighter = _company.GetRandomObject();
|
||||
car = _company.GetRandomObject();
|
||||
counter--;
|
||||
if (counter <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (fighter == null)
|
||||
|
||||
if (car == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
FormFighter form = new()
|
||||
{
|
||||
SetTrackedVehicle = fighter
|
||||
SetTrackedVehicle = car
|
||||
};
|
||||
form.ShowDialog();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Перерисовка коллекции
|
||||
/// </summary>
|
||||
@ -181,24 +189,103 @@ public partial class FormTrackedVehicleCollection : Form
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
private void pictureBox1_Click(object sender, EventArgs e)
|
||||
|
||||
/// <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();
|
||||
}
|
||||
|
||||
private void maskedTextBox1_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
|
||||
/// <summary>
|
||||
/// Удаление коллекции
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRemoveTrackedVehicle_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
|
||||
{
|
||||
MessageBox.Show("Коллекция не выбрана");
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
|
||||
RerfreshListBoxItems();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обновление списка в listBoxCollection
|
||||
/// </summary>
|
||||
private void RerfreshListBoxItems()
|
||||
{
|
||||
listBoxCollection.Items.Clear();
|
||||
foreach (var key in _storageCollection.Keys ?? Enumerable.Empty<string>())
|
||||
{
|
||||
if (!string.IsNullOrEmpty(key))
|
||||
{
|
||||
listBoxCollection.Items.Add(key);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создание компании
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void button1CreateCompany_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
|
||||
{
|
||||
MessageBox.Show("Коллекция не выбрана");
|
||||
return;
|
||||
}
|
||||
|
||||
ICollectionGenericObjects<DrawningTrackedVehicle>? collection = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
|
||||
if (collection == null)
|
||||
{
|
||||
MessageBox.Show("Коллекция не проинициализирована");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (comboBoxSelectorCompany.Text)
|
||||
{
|
||||
case "Хранилище":
|
||||
_company = new TrackedVehicleSharingService(pictureBox.Width, pictureBox.Height, collection);
|
||||
break;
|
||||
}
|
||||
|
||||
panelCompanyTools.Enabled = true;
|
||||
RerfreshListBoxItems();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void FormTrackedVehicleCollection_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user