pibd-12 Tangatarov.I.A. LabWork04 Base #17
@ -0,0 +1,8 @@
|
||||
using System;
|
||||
namespace HoistingCrane.CollectionGenericObjects
|
||||
{
|
||||
public enum CollectionType
|
||||
{
|
||||
None = 0, Massive = 1, List = 2
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
using System;
|
||||
namespace HoistingCrane.CollectionGenericObjects
|
||||
{
|
||||
public class ListGenericObjects<T> : ICollectionGenericObjects<T> where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Список объектов, которые храним
|
||||
/// </summary>
|
||||
readonly List<T> list;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public ListGenericObjects()
|
||||
{
|
||||
list = new List<T>();
|
||||
}
|
||||
/// <summary>
|
||||
/// Максимально допустимое число объектов в списке
|
||||
/// </summary>
|
||||
private int _maxCount;
|
||||
public int Count
|
||||
{
|
||||
get { return list.Count; }
|
||||
}
|
||||
|
||||
public int SetMaxCount
|
||||
{
|
||||
set
|
||||
{
|
||||
if(value > 0)
|
||||
{
|
||||
_maxCount = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public T? Get(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
if(position >= 0 && position < list.Count)
|
||||
{
|
||||
return list[position];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public bool Insert(T obj)
|
||||
{
|
||||
// TODO проверка, что не превышено максимальное количество элементов
|
||||
// TODO вставка в конец набора
|
||||
if(list.Count < _maxCount)
|
||||
{
|
||||
list.Add(obj);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Insert(T obj, int position)
|
||||
{
|
||||
// TODO проверка, что не превышено максимальное количество элементов
|
||||
// TODO проверка позиции
|
||||
// TODO вставка по позиции
|
||||
if(list.Count < _maxCount && position >= 0 && position < list.Count)
|
||||
{
|
||||
if (list[position] == null)
|
||||
{
|
||||
list[position] = obj;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
public bool Remove(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO удаление объекта из списка
|
||||
if(position >= 0 && position < list.Count)
|
||||
{
|
||||
list.RemoveAt(position);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
using System;
|
||||
namespace HoistingCrane.CollectionGenericObjects
|
||||
{
|
||||
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 (!string.IsNullOrEmpty(name) && !Keys.Contains(name))
|
||||
{
|
||||
if(collectionType == CollectionType.Massive)
|
||||
{
|
||||
_storages.Add(name, new MassivGenericObjects<T> ());
|
||||
}
|
||||
if(collectionType == CollectionType.List)
|
||||
{
|
||||
_storages.Add(name, new ListGenericObjects<T> ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление коллекции
|
||||
/// </summary>
|
||||
/// <param name="name">Название коллекции</param>
|
||||
public void DelCollection(string name)
|
||||
{
|
||||
// TODO Прописать логику для удаления коллекции
|
||||
if(Keys.Contains(name))
|
||||
{
|
||||
_storages.Remove(name);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Доступ к коллекции
|
||||
/// </summary>
|
||||
/// <param name="name">Название коллекции</param>
|
||||
/// <returns></returns>
|
||||
public ICollectionGenericObjects<T>? this[string name]
|
||||
{
|
||||
get
|
||||
{
|
||||
// TODO Продумать логику получения объекта
|
||||
if (Keys.Contains(name))
|
||||
{
|
||||
return _storages[name];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -37,12 +37,24 @@
|
||||
buttonCreateTrackedVehicle = new Button();
|
||||
buttonCreateHoistingCrane = new Button();
|
||||
pictureBox = new PictureBox();
|
||||
panelStorage = new Panel();
|
||||
labelCollectionName = new Label();
|
||||
textBoxCollectionName = new TextBox();
|
||||
radioButtonMassive = new RadioButton();
|
||||
radioButtonList = new RadioButton();
|
||||
buttonCollectionAdd = new Button();
|
||||
listBoxCollection = new ListBox();
|
||||
buttonDeleteCollection = new Button();
|
||||
buttonCreateCompany = new Button();
|
||||
groupBoxTools.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||
panelStorage.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBoxTools
|
||||
//
|
||||
groupBoxTools.Controls.Add(buttonCreateCompany);
|
||||
groupBoxTools.Controls.Add(panelStorage);
|
||||
groupBoxTools.Controls.Add(buttonGoToChek);
|
||||
groupBoxTools.Controls.Add(buttonRefresh);
|
||||
groupBoxTools.Controls.Add(buttonDeleteCar);
|
||||
@ -51,9 +63,9 @@
|
||||
groupBoxTools.Controls.Add(buttonCreateTrackedVehicle);
|
||||
groupBoxTools.Controls.Add(buttonCreateHoistingCrane);
|
||||
groupBoxTools.Dock = DockStyle.Right;
|
||||
groupBoxTools.Location = new Point(716, 0);
|
||||
groupBoxTools.Location = new Point(763, 0);
|
||||
groupBoxTools.Name = "groupBoxTools";
|
||||
groupBoxTools.Size = new Size(210, 450);
|
||||
groupBoxTools.Size = new Size(210, 509);
|
||||
groupBoxTools.TabIndex = 0;
|
||||
groupBoxTools.TabStop = false;
|
||||
groupBoxTools.Text = "Инструменты";
|
||||
@ -61,9 +73,9 @@
|
||||
// buttonGoToChek
|
||||
//
|
||||
buttonGoToChek.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonGoToChek.Location = new Point(12, 298);
|
||||
buttonGoToChek.Location = new Point(12, 440);
|
||||
buttonGoToChek.Name = "buttonGoToChek";
|
||||
buttonGoToChek.Size = new Size(192, 34);
|
||||
buttonGoToChek.Size = new Size(192, 24);
|
||||
buttonGoToChek.TabIndex = 6;
|
||||
buttonGoToChek.Text = "Передать на тесты";
|
||||
buttonGoToChek.UseVisualStyleBackColor = true;
|
||||
@ -72,9 +84,9 @@
|
||||
// buttonRefresh
|
||||
//
|
||||
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRefresh.Location = new Point(12, 375);
|
||||
buttonRefresh.Location = new Point(12, 470);
|
||||
buttonRefresh.Name = "buttonRefresh";
|
||||
buttonRefresh.Size = new Size(192, 34);
|
||||
buttonRefresh.Size = new Size(192, 27);
|
||||
buttonRefresh.TabIndex = 5;
|
||||
buttonRefresh.Text = "Обновить";
|
||||
buttonRefresh.UseVisualStyleBackColor = true;
|
||||
@ -83,9 +95,9 @@
|
||||
// buttonDeleteCar
|
||||
//
|
||||
buttonDeleteCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonDeleteCar.Location = new Point(12, 233);
|
||||
buttonDeleteCar.Location = new Point(12, 411);
|
||||
buttonDeleteCar.Name = "buttonDeleteCar";
|
||||
buttonDeleteCar.Size = new Size(192, 34);
|
||||
buttonDeleteCar.Size = new Size(192, 23);
|
||||
buttonDeleteCar.TabIndex = 4;
|
||||
buttonDeleteCar.Text = "Удалить автомобиль";
|
||||
buttonDeleteCar.UseVisualStyleBackColor = true;
|
||||
@ -94,7 +106,7 @@
|
||||
// maskedTextBox
|
||||
//
|
||||
maskedTextBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
maskedTextBox.Location = new Point(12, 204);
|
||||
maskedTextBox.Location = new Point(12, 382);
|
||||
maskedTextBox.Mask = "00";
|
||||
maskedTextBox.Name = "maskedTextBox";
|
||||
maskedTextBox.Size = new Size(192, 23);
|
||||
@ -106,7 +118,7 @@
|
||||
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxSelectorCompany.FormattingEnabled = true;
|
||||
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
|
||||
comboBoxSelectorCompany.Location = new Point(12, 28);
|
||||
comboBoxSelectorCompany.Location = new Point(12, 266);
|
||||
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
||||
comboBoxSelectorCompany.Size = new Size(192, 23);
|
||||
comboBoxSelectorCompany.TabIndex = 2;
|
||||
@ -115,9 +127,9 @@
|
||||
// buttonCreateTrackedVehicle
|
||||
//
|
||||
buttonCreateTrackedVehicle.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonCreateTrackedVehicle.Location = new Point(12, 129);
|
||||
buttonCreateTrackedVehicle.Location = new Point(12, 352);
|
||||
buttonCreateTrackedVehicle.Name = "buttonCreateTrackedVehicle";
|
||||
buttonCreateTrackedVehicle.Size = new Size(192, 34);
|
||||
buttonCreateTrackedVehicle.Size = new Size(192, 24);
|
||||
buttonCreateTrackedVehicle.TabIndex = 1;
|
||||
buttonCreateTrackedVehicle.Text = "Добавить гусеничную машину";
|
||||
buttonCreateTrackedVehicle.UseVisualStyleBackColor = true;
|
||||
@ -126,9 +138,9 @@
|
||||
// buttonCreateHoistingCrane
|
||||
//
|
||||
buttonCreateHoistingCrane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonCreateHoistingCrane.Location = new Point(12, 89);
|
||||
buttonCreateHoistingCrane.Location = new Point(12, 324);
|
||||
buttonCreateHoistingCrane.Name = "buttonCreateHoistingCrane";
|
||||
buttonCreateHoistingCrane.Size = new Size(192, 34);
|
||||
buttonCreateHoistingCrane.Size = new Size(192, 22);
|
||||
buttonCreateHoistingCrane.TabIndex = 0;
|
||||
buttonCreateHoistingCrane.Text = "Добавить подъемный кран";
|
||||
buttonCreateHoistingCrane.UseVisualStyleBackColor = true;
|
||||
@ -139,15 +151,107 @@
|
||||
pictureBox.Dock = DockStyle.Fill;
|
||||
pictureBox.Location = new Point(0, 0);
|
||||
pictureBox.Name = "pictureBox";
|
||||
pictureBox.Size = new Size(716, 450);
|
||||
pictureBox.Size = new Size(763, 509);
|
||||
pictureBox.TabIndex = 1;
|
||||
pictureBox.TabStop = false;
|
||||
//
|
||||
// panelStorage
|
||||
//
|
||||
panelStorage.Controls.Add(buttonDeleteCollection);
|
||||
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, 19);
|
||||
panelStorage.Name = "panelStorage";
|
||||
panelStorage.Size = new Size(204, 229);
|
||||
panelStorage.TabIndex = 7;
|
||||
//
|
||||
// labelCollectionName
|
||||
//
|
||||
labelCollectionName.AutoSize = true;
|
||||
labelCollectionName.Location = new Point(35, 0);
|
||||
labelCollectionName.Name = "labelCollectionName";
|
||||
labelCollectionName.Size = new Size(135, 15);
|
||||
labelCollectionName.TabIndex = 0;
|
||||
labelCollectionName.Text = "Название коллекции:";
|
||||
//
|
||||
// textBoxCollectionName
|
||||
//
|
||||
textBoxCollectionName.Location = new Point(9, 18);
|
||||
textBoxCollectionName.Name = "textBoxCollectionName";
|
||||
textBoxCollectionName.Size = new Size(192, 23);
|
||||
textBoxCollectionName.TabIndex = 1;
|
||||
//
|
||||
// radioButtonMassive
|
||||
//
|
||||
radioButtonMassive.AutoSize = true;
|
||||
radioButtonMassive.Location = new Point(18, 56);
|
||||
radioButtonMassive.Name = "radioButtonMassive";
|
||||
radioButtonMassive.Size = new Size(69, 19);
|
||||
radioButtonMassive.TabIndex = 2;
|
||||
radioButtonMassive.TabStop = true;
|
||||
radioButtonMassive.Text = "Массив";
|
||||
radioButtonMassive.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// radioButtonList
|
||||
//
|
||||
radioButtonList.AutoSize = true;
|
||||
radioButtonList.Location = new Point(128, 56);
|
||||
radioButtonList.Name = "radioButtonList";
|
||||
radioButtonList.Size = new Size(67, 19);
|
||||
radioButtonList.TabIndex = 3;
|
||||
radioButtonList.TabStop = true;
|
||||
radioButtonList.Text = "Список";
|
||||
radioButtonList.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// buttonCollectionAdd
|
||||
//
|
||||
buttonCollectionAdd.Location = new Point(9, 81);
|
||||
buttonCollectionAdd.Name = "buttonCollectionAdd";
|
||||
buttonCollectionAdd.Size = new Size(192, 23);
|
||||
buttonCollectionAdd.TabIndex = 4;
|
||||
buttonCollectionAdd.Text = "Добавить коллекцию";
|
||||
buttonCollectionAdd.UseVisualStyleBackColor = true;
|
||||
buttonCollectionAdd.Click += buttonCollectionAdd_Click;
|
||||
//
|
||||
// listBoxCollection
|
||||
//
|
||||
listBoxCollection.FormattingEnabled = true;
|
||||
listBoxCollection.ItemHeight = 15;
|
||||
listBoxCollection.Location = new Point(9, 118);
|
||||
listBoxCollection.Name = "listBoxCollection";
|
||||
listBoxCollection.Size = new Size(192, 79);
|
||||
listBoxCollection.TabIndex = 5;
|
||||
//
|
||||
// buttonDeleteCollection
|
||||
//
|
||||
buttonDeleteCollection.Location = new Point(9, 199);
|
||||
buttonDeleteCollection.Name = "buttonDeleteCollection";
|
||||
buttonDeleteCollection.Size = new Size(192, 27);
|
||||
buttonDeleteCollection.TabIndex = 6;
|
||||
buttonDeleteCollection.Text = "Удалить коллекцию";
|
||||
buttonDeleteCollection.UseVisualStyleBackColor = true;
|
||||
buttonDeleteCollection.Click += buttonDeleteCollection_Click;
|
||||
//
|
||||
// buttonCreateCompany
|
||||
//
|
||||
buttonCreateCompany.Location = new Point(12, 295);
|
||||
buttonCreateCompany.Name = "buttonCreateCompany";
|
||||
buttonCreateCompany.Size = new Size(192, 23);
|
||||
buttonCreateCompany.TabIndex = 7;
|
||||
buttonCreateCompany.Text = "Создать компанию";
|
||||
buttonCreateCompany.UseVisualStyleBackColor = true;
|
||||
buttonCreateCompany.Click += buttonCreateCompany_Click;
|
||||
//
|
||||
// FormCarCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(926, 450);
|
||||
ClientSize = new Size(973, 509);
|
||||
Controls.Add(pictureBox);
|
||||
Controls.Add(groupBoxTools);
|
||||
Name = "FormCarCollection";
|
||||
@ -155,6 +259,8 @@
|
||||
groupBoxTools.ResumeLayout(false);
|
||||
groupBoxTools.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||
panelStorage.ResumeLayout(false);
|
||||
panelStorage.PerformLayout();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
@ -169,5 +275,14 @@
|
||||
private MaskedTextBox maskedTextBox;
|
||||
private PictureBox pictureBox;
|
||||
private Button buttonGoToChek;
|
||||
private Panel panelStorage;
|
||||
private RadioButton radioButtonList;
|
||||
private RadioButton radioButtonMassive;
|
||||
private TextBox textBoxCollectionName;
|
||||
private Label labelCollectionName;
|
||||
private Button buttonCreateCompany;
|
||||
private Button buttonDeleteCollection;
|
||||
private ListBox listBoxCollection;
|
||||
private Button buttonCollectionAdd;
|
||||
}
|
||||
}
|
@ -77,7 +77,7 @@ namespace HoistingCrane
|
||||
|
||||
|
||||
private void buttonCreateTrackedVehicle_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTrackedVehicle));
|
||||
|
||||
|
||||
|
||||
private void buttonDeleteCar_Click(object sender, EventArgs e)
|
||||
{
|
||||
@ -120,12 +120,27 @@ namespace HoistingCrane
|
||||
if (count <= 0) break;
|
||||
}
|
||||
if (car == null) return;
|
||||
FormHoistingCrane form = new()
|
||||
FormHoistingCrane form = new()
|
||||
{
|
||||
SetCar = car
|
||||
};
|
||||
form.ShowDialog();
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void buttonCollectionAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void buttonDeleteCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void buttonCreateCompany_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user
У словаря есть метод проверки наличия ключа