Создание хранилища, работа с формой
This commit is contained in:
parent
1c549bb586
commit
dbd1e73375
@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectCleaningCar.CollectionGenericObjects;
|
||||
/// <summary>
|
||||
/// Тип коллекции
|
||||
/// </summary>
|
||||
public enum CollectionType
|
||||
{
|
||||
/// <summary>
|
||||
/// Неопределено
|
||||
/// </summary>
|
||||
None = 0,
|
||||
/// <summary>
|
||||
/// Массив
|
||||
/// </summary>
|
||||
Massive = 1,
|
||||
/// <summary>
|
||||
/// Список
|
||||
/// </summary>
|
||||
List = 2
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectCleaningCar.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)
|
||||
{
|
||||
throw new IndexOutOfRangeException("Недопустимая позиция");
|
||||
}
|
||||
return _collection[position];
|
||||
}
|
||||
public bool Insert(T obj)
|
||||
{
|
||||
if (_collection.Count >= _maxCount)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_collection.Add(obj);
|
||||
return true;
|
||||
}
|
||||
public bool Insert(T obj, int position)
|
||||
{
|
||||
if (_collection.Count >= _maxCount || position < 0 || position > _collection.Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_collection.Insert(position, obj);
|
||||
return true;
|
||||
}
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (position < 0 || position >= _collection.Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_collection.RemoveAt(position);
|
||||
return true;
|
||||
}
|
||||
|
||||
int ICollectionGenericObjects<T>.Insert(T obj)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
int ICollectionGenericObjects<T>.Insert(T obj, int position)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
T ICollectionGenericObjects<T>.Remove(int position)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectCleaningCar.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 (string.IsNullOrEmpty(name))
|
||||
{
|
||||
throw new ArgumentException("Название коллекции не может быть пустым или null", nameof(name));
|
||||
}
|
||||
|
||||
if (_storages.ContainsKey(name))
|
||||
{
|
||||
throw new ArgumentException($"Коллекция с именем {name} уже существует", nameof(name));
|
||||
}
|
||||
|
||||
ICollectionGenericObjects<T> collection;
|
||||
switch (collectionType)
|
||||
{
|
||||
case CollectionType.List:
|
||||
collection = new ListGenericObjects<T>();
|
||||
break;
|
||||
case CollectionType.Massive:
|
||||
collection = new MassiveGenericObjects<T>();
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException($"Неизвестный тип коллекции: {collectionType}", nameof(collectionType));
|
||||
}
|
||||
|
||||
_storages.Add(name, collection);
|
||||
}
|
||||
|
||||
/// <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.TryGetValue(name, out ICollectionGenericObjects<T>? collection))
|
||||
{
|
||||
return collection;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -62,9 +62,9 @@ namespace ProjectCleaningCar
|
||||
// buttonRefresh
|
||||
//
|
||||
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRefresh.Location = new Point(12, 470);
|
||||
buttonRefresh.Location = new Point(12, 589);
|
||||
buttonRefresh.Name = "buttonRefresh";
|
||||
buttonRefresh.Size = new Size(226, 69);
|
||||
buttonRefresh.Size = new Size(226, 35);
|
||||
buttonRefresh.TabIndex = 6;
|
||||
buttonRefresh.Text = "Обновить";
|
||||
buttonRefresh.UseVisualStyleBackColor = true;
|
||||
@ -73,9 +73,9 @@ namespace ProjectCleaningCar
|
||||
// buttonGoToCheck
|
||||
//
|
||||
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonGoToCheck.Location = new Point(12, 378);
|
||||
buttonGoToCheck.Location = new Point(12, 552);
|
||||
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||
buttonGoToCheck.Size = new Size(226, 69);
|
||||
buttonGoToCheck.Size = new Size(226, 31);
|
||||
buttonGoToCheck.TabIndex = 5;
|
||||
buttonGoToCheck.Text = "Передать на тесты";
|
||||
buttonGoToCheck.UseVisualStyleBackColor = true;
|
||||
@ -84,9 +84,9 @@ namespace ProjectCleaningCar
|
||||
// buttonRemoveTruck
|
||||
//
|
||||
buttonRemoveTruck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRemoveTruck.Location = new Point(12, 284);
|
||||
buttonRemoveTruck.Location = new Point(12, 515);
|
||||
buttonRemoveTruck.Name = "buttonRemoveTruck";
|
||||
buttonRemoveTruck.Size = new Size(226, 69);
|
||||
buttonRemoveTruck.Size = new Size(226, 31);
|
||||
buttonRemoveTruck.TabIndex = 4;
|
||||
buttonRemoveTruck.Text = "Удаление грузовика";
|
||||
buttonRemoveTruck.UseVisualStyleBackColor = true;
|
||||
@ -94,7 +94,7 @@ namespace ProjectCleaningCar
|
||||
//
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
maskedTextBoxPosition.Location = new Point(12, 228);
|
||||
maskedTextBoxPosition.Location = new Point(12, 482);
|
||||
maskedTextBoxPosition.Mask = "00";
|
||||
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
maskedTextBoxPosition.Size = new Size(226, 27);
|
||||
@ -105,9 +105,9 @@ namespace ProjectCleaningCar
|
||||
// buttonAddCleaningCar
|
||||
//
|
||||
buttonAddCleaningCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddCleaningCar.Location = new Point(12, 129);
|
||||
buttonAddCleaningCar.Location = new Point(12, 423);
|
||||
buttonAddCleaningCar.Name = "buttonAddCleaningCar";
|
||||
buttonAddCleaningCar.Size = new Size(226, 69);
|
||||
buttonAddCleaningCar.Size = new Size(226, 53);
|
||||
buttonAddCleaningCar.TabIndex = 2;
|
||||
buttonAddCleaningCar.Text = "Добавление подметально-уборочной машины";
|
||||
buttonAddCleaningCar.UseVisualStyleBackColor = true;
|
||||
@ -116,9 +116,9 @@ namespace ProjectCleaningCar
|
||||
// buttonAddTruck
|
||||
//
|
||||
buttonAddTruck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddTruck.Location = new Point(12, 69);
|
||||
buttonAddTruck.Location = new Point(12, 384);
|
||||
buttonAddTruck.Name = "buttonAddTruck";
|
||||
buttonAddTruck.Size = new Size(226, 54);
|
||||
buttonAddTruck.Size = new Size(226, 33);
|
||||
buttonAddTruck.TabIndex = 1;
|
||||
buttonAddTruck.Text = "Добавление грузовика";
|
||||
buttonAddTruck.UseVisualStyleBackColor = true;
|
||||
@ -130,9 +130,9 @@ namespace ProjectCleaningCar
|
||||
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxSelectorCompany.FormattingEnabled = true;
|
||||
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
|
||||
comboBoxSelectorCompany.Location = new Point(12, 26);
|
||||
comboBoxSelectorCompany.Location = new Point(12, 350);
|
||||
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
||||
comboBoxSelectorCompany.Size = new Size(232, 28);
|
||||
comboBoxSelectorCompany.Size = new Size(226, 28);
|
||||
comboBoxSelectorCompany.TabIndex = 0;
|
||||
comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged;
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user