4 лаба

This commit is contained in:
123 2024-04-23 10:19:03 +04:00
parent 10a65bacae
commit e0295b4b65
7 changed files with 486 additions and 127 deletions

View File

@ -47,7 +47,7 @@ public class CarPark : AbstractCompany
return; return;
} }
int row = numRows - 1, col = numCols; int row = numRows - 1, col = numCols;
for (int i = 0; i < _collection?.Count-4; i++, col--) for (int i = 0; i < _collection?.Count; i++, col--)
{ {
_collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight); _collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight);
_collection?.Get(i)?.SetPosition(locCoord[row * numCols - col].Item1 + 5, locCoord[row * numCols - col].Item2 + 9); _collection?.Get(i)?.SetPosition(locCoord[row * numCols - col].Item1 + 5, locCoord[row * numCols - col].Item2 + 9);

View File

@ -0,0 +1,23 @@

namespace ProjectGasolineTanker.CollectionGenericObjects;
/// <summary>
/// Тип коллекции
/// </summary>
public enum CollectionType
{
/// <summary>
/// Неопределено
/// </summary>
None = 0,
/// <summary>
/// Массив
/// </summary>
Massive = 1,
/// <summary>
/// Список
/// </summary>
List = 2
}

View File

@ -0,0 +1,58 @@

namespace ProjectGasolineTanker.CollectionGenericObjects;
public class ListGenericObjects<T> : ICollectionGenericObjects<T>
where T : class
{
private readonly List<T?> _collection;
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 < Count)
{
return _collection[position];
}
else
{
return null;
}
}
public int Insert(T obj)
{
if (Count == _maxCount) { return -1; }
_collection.Add(obj);
return Count;
}
public int Insert(T obj, int position)
{
if (position < 0 || position >= Count || Count == _maxCount)
{
return -1;
}
_collection.Insert(position, obj);
return position;
}
public T Remove(int position)
{
if (position >= Count || position < 0) return null;
T obj = _collection[position];
_collection.RemoveAt(position);
return obj;
}
}

View File

@ -0,0 +1,77 @@

namespace ProjectGasolineTanker.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)
{
if (string.IsNullOrEmpty(name) || _storages.ContainsKey(name))
{
return;
}
switch (collectionType)
{
case CollectionType.Massive:
_storages[name] = new MassiveGenericObjects<T>();
break;
case CollectionType.List:
_storages[name] = new ListGenericObjects<T>();
break;
default:
return;
}
}
/// <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

@ -30,54 +30,97 @@ namespace ProjectGasolineTanker
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
groupBoxTools = new GroupBox(); Инструменты = new GroupBox();
buttonRefresh = new Button(); panelCompanyTools = new Panel();
buttonAddTanker = new Button();
buttonAddGasolineTanker = new Button();
maskedTextBoxPosition = new MaskedTextBox();
buttonGoToCheck = new Button(); buttonGoToCheck = new Button();
buttonRemoveTanker = new Button(); buttonRemoveTanker = new Button();
maskedTextBoxPosition = new MaskedTextBox(); buttonRefresh = new Button();
buttonAddGasolineTanker = new Button(); buttonCreateCompany = new Button();
buttonAddTanker = new Button(); panelStorage = new Panel();
buttonCollectionDel = new Button();
listBoxCollection = new ListBox();
buttonCollectionAdd = new Button();
radioButtonList = new RadioButton();
radioButtonMassive = new RadioButton();
textBoxCollectionName = new TextBox();
labelCollectionName = new Label();
comboBoxSelectorCompany = new ComboBox(); comboBoxSelectorCompany = new ComboBox();
pictureBox = new PictureBox(); pictureBox = new PictureBox();
groupBoxTools.SuspendLayout(); Инструменты.SuspendLayout();
panelCompanyTools.SuspendLayout();
panelStorage.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
SuspendLayout(); SuspendLayout();
// //
// groupBoxTools // Инструменты
// //
groupBoxTools.Controls.Add(buttonRefresh); Инструменты.Controls.Add(panelCompanyTools);
groupBoxTools.Controls.Add(buttonGoToCheck); Инструменты.Controls.Add(buttonCreateCompany);
groupBoxTools.Controls.Add(buttonRemoveTanker); Инструменты.Controls.Add(panelStorage);
groupBoxTools.Controls.Add(maskedTextBoxPosition); Инструменты.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Controls.Add(buttonAddGasolineTanker); Инструменты.Dock = DockStyle.Right;
groupBoxTools.Controls.Add(buttonAddTanker); Инструменты.Location = new Point(861, 0);
groupBoxTools.Controls.Add(comboBoxSelectorCompany); Инструменты.Name = "Инструменты";
groupBoxTools.Dock = DockStyle.Right; Инструменты.Size = new Size(225, 651);
groupBoxTools.Location = new Point(783, 0); Инструменты.TabIndex = 0;
groupBoxTools.Name = "groupBoxTools"; Инструменты.TabStop = false;
groupBoxTools.Size = new Size(179, 616); Инструменты.Text = "Инструменты";
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
// //
// buttonRefresh // panelCompanyTools
// //
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; panelCompanyTools.Controls.Add(buttonAddTanker);
buttonRefresh.Location = new Point(6, 499); panelCompanyTools.Controls.Add(buttonAddGasolineTanker);
buttonRefresh.Name = "buttonRefresh"; panelCompanyTools.Controls.Add(maskedTextBoxPosition);
buttonRefresh.Size = new Size(167, 40); panelCompanyTools.Controls.Add(buttonGoToCheck);
buttonRefresh.TabIndex = 6; panelCompanyTools.Controls.Add(buttonRemoveTanker);
buttonRefresh.Text = "Обновить"; panelCompanyTools.Controls.Add(buttonRefresh);
buttonRefresh.UseVisualStyleBackColor = true; panelCompanyTools.Dock = DockStyle.Bottom;
buttonRefresh.Click += ButtonRefresh_Click; panelCompanyTools.Location = new Point(3, 383);
panelCompanyTools.Name = "panelCompanyTools";
panelCompanyTools.Size = new Size(219, 265);
panelCompanyTools.TabIndex = 8;
//
// buttonAddTanker
//
buttonAddTanker.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddTanker.Location = new Point(3, 3);
buttonAddTanker.Name = "buttonAddTanker";
buttonAddTanker.Size = new Size(213, 37);
buttonAddTanker.TabIndex = 1;
buttonAddTanker.Text = "Добавление грузовика";
buttonAddTanker.UseVisualStyleBackColor = true;
buttonAddTanker.Click += buttonAddTanker_Click;
//
// buttonAddGasolineTanker
//
buttonAddGasolineTanker.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddGasolineTanker.Location = new Point(3, 43);
buttonAddGasolineTanker.Name = "buttonAddGasolineTanker";
buttonAddGasolineTanker.Size = new Size(213, 37);
buttonAddGasolineTanker.TabIndex = 2;
buttonAddGasolineTanker.Text = "Добавление бензовоза\r\n";
buttonAddGasolineTanker.UseVisualStyleBackColor = true;
buttonAddGasolineTanker.Click += buttonAddGasolineTanker_Click;
//
// maskedTextBoxPosition
//
maskedTextBoxPosition.Location = new Point(3, 86);
maskedTextBoxPosition.Mask = "00";
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
maskedTextBoxPosition.Size = new Size(213, 23);
maskedTextBoxPosition.TabIndex = 3;
maskedTextBoxPosition.ValidatingType = typeof(int);
// //
// buttonGoToCheck // buttonGoToCheck
// //
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonGoToCheck.Location = new Point(6, 361); buttonGoToCheck.Location = new Point(3, 161);
buttonGoToCheck.Name = "buttonGoToCheck"; buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(167, 40); buttonGoToCheck.Size = new Size(213, 40);
buttonGoToCheck.TabIndex = 5; buttonGoToCheck.TabIndex = 6;
buttonGoToCheck.Text = "Передать на тесты"; buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true; buttonGoToCheck.UseVisualStyleBackColor = true;
buttonGoToCheck.Click += ButtonGoToCheck_Click; buttonGoToCheck.Click += ButtonGoToCheck_Click;
@ -85,44 +128,116 @@ namespace ProjectGasolineTanker
// buttonRemoveTanker // buttonRemoveTanker
// //
buttonRemoveTanker.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; buttonRemoveTanker.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRemoveTanker.Location = new Point(6, 251); buttonRemoveTanker.Location = new Point(3, 115);
buttonRemoveTanker.Name = "buttonRemoveTanker"; buttonRemoveTanker.Name = "buttonRemoveTanker";
buttonRemoveTanker.Size = new Size(167, 40); buttonRemoveTanker.Size = new Size(213, 40);
buttonRemoveTanker.TabIndex = 4; buttonRemoveTanker.TabIndex = 4;
buttonRemoveTanker.Text = "Удалить автомобиль"; buttonRemoveTanker.Text = "Удаление машины";
buttonRemoveTanker.UseVisualStyleBackColor = true; buttonRemoveTanker.UseVisualStyleBackColor = true;
buttonRemoveTanker.Click += ButtonRemoveTanker_Click; buttonRemoveTanker.Click += ButtonRemoveTanker_Click;
// //
// maskedTextBoxPosition // buttonRefresh
// //
maskedTextBoxPosition.Location = new Point(6, 222); buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
maskedTextBoxPosition.Mask = "00"; buttonRefresh.Location = new Point(3, 207);
maskedTextBoxPosition.Name = "maskedTextBoxPosition"; buttonRefresh.Name = "buttonRefresh";
maskedTextBoxPosition.Size = new Size(167, 23); buttonRefresh.Size = new Size(213, 40);
maskedTextBoxPosition.TabIndex = 3; buttonRefresh.TabIndex = 5;
maskedTextBoxPosition.ValidatingType = typeof(int); buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += ButtonRefresh_Click;
// //
// buttonAddGaslineTanker // buttonCreateCompany
// //
buttonAddGasolineTanker.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; buttonCreateCompany.Location = new Point(6, 350);
buttonAddGasolineTanker.Location = new Point(6, 137); buttonCreateCompany.Name = "buttonCreateCompany";
buttonAddGasolineTanker.Name = "buttonAddGasolineTanker"; buttonCreateCompany.Size = new Size(213, 24);
buttonAddGasolineTanker.Size = new Size(167, 40); buttonCreateCompany.TabIndex = 7;
buttonAddGasolineTanker.TabIndex = 2; buttonCreateCompany.Text = "Создать компанию";
buttonAddGasolineTanker.Text = "Добавление бензовоза"; buttonCreateCompany.UseVisualStyleBackColor = true;
buttonAddGasolineTanker.UseVisualStyleBackColor = true; buttonCreateCompany.Click += ButtonCreateCompany_Click;
buttonAddGasolineTanker.Click += ButtonAddGasolineTanker_Click;
// //
// buttonAddTanker // panelStorage
// //
buttonAddTanker.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; panelStorage.Controls.Add(buttonCollectionDel);
buttonAddTanker.Location = new Point(6, 91); panelStorage.Controls.Add(listBoxCollection);
buttonAddTanker.Name = "buttonAddTanker"; panelStorage.Controls.Add(buttonCollectionAdd);
buttonAddTanker.Size = new Size(167, 40); panelStorage.Controls.Add(radioButtonList);
buttonAddTanker.TabIndex = 1; panelStorage.Controls.Add(radioButtonMassive);
buttonAddTanker.Text = "Добавление грузовика"; panelStorage.Controls.Add(textBoxCollectionName);
buttonAddTanker.UseVisualStyleBackColor = true; panelStorage.Controls.Add(labelCollectionName);
buttonAddTanker.Click += ButtonAddTanker_Click; panelStorage.Dock = DockStyle.Top;
panelStorage.Location = new Point(3, 19);
panelStorage.Name = "panelStorage";
panelStorage.Size = new Size(219, 296);
panelStorage.TabIndex = 7;
//
// buttonCollectionDel
//
buttonCollectionDel.Location = new Point(3, 267);
buttonCollectionDel.Name = "buttonCollectionDel";
buttonCollectionDel.Size = new Size(213, 24);
buttonCollectionDel.TabIndex = 6;
buttonCollectionDel.Text = "Удалить коллекцию";
buttonCollectionDel.UseVisualStyleBackColor = true;
buttonCollectionDel.Click += ButtonCollectionDel_Click;
//
// listBoxCollection
//
listBoxCollection.FormattingEnabled = true;
listBoxCollection.ItemHeight = 15;
listBoxCollection.Location = new Point(3, 122);
listBoxCollection.Name = "listBoxCollection";
listBoxCollection.Size = new Size(213, 139);
listBoxCollection.TabIndex = 5;
//
// buttonCollectionAdd
//
buttonCollectionAdd.Location = new Point(3, 85);
buttonCollectionAdd.Name = "buttonCollectionAdd";
buttonCollectionAdd.Size = new Size(213, 24);
buttonCollectionAdd.TabIndex = 4;
buttonCollectionAdd.Text = "Добавить коллекцию";
buttonCollectionAdd.UseVisualStyleBackColor = true;
buttonCollectionAdd.Click += ButtonCollectionAdd_Click;
//
// radioButtonList
//
radioButtonList.AutoSize = true;
radioButtonList.Location = new Point(139, 60);
radioButtonList.Name = "radioButtonList";
radioButtonList.Size = new Size(66, 19);
radioButtonList.TabIndex = 3;
radioButtonList.TabStop = true;
radioButtonList.Text = "Список";
radioButtonList.UseVisualStyleBackColor = true;
//
// radioButtonMassive
//
radioButtonMassive.AutoSize = true;
radioButtonMassive.Location = new Point(19, 60);
radioButtonMassive.Name = "radioButtonMassive";
radioButtonMassive.Size = new Size(67, 19);
radioButtonMassive.TabIndex = 2;
radioButtonMassive.TabStop = true;
radioButtonMassive.Text = "Массив";
radioButtonMassive.UseVisualStyleBackColor = true;
//
// textBoxCollectionName
//
textBoxCollectionName.Location = new Point(3, 31);
textBoxCollectionName.Name = "textBoxCollectionName";
textBoxCollectionName.Size = new Size(213, 23);
textBoxCollectionName.TabIndex = 1;
//
// labelCollectionName
//
labelCollectionName.AutoSize = true;
labelCollectionName.Location = new Point(47, 13);
labelCollectionName.Name = "labelCollectionName";
labelCollectionName.Size = new Size(125, 15);
labelCollectionName.TabIndex = 0;
labelCollectionName.Text = "Название коллекции:";
// //
// comboBoxSelectorCompany // comboBoxSelectorCompany
// //
@ -130,9 +245,9 @@ namespace ProjectGasolineTanker
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectorCompany.FormattingEnabled = true; comboBoxSelectorCompany.FormattingEnabled = true;
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
comboBoxSelectorCompany.Location = new Point(6, 22); comboBoxSelectorCompany.Location = new Point(6, 321);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(167, 23); comboBoxSelectorCompany.Size = new Size(213, 23);
comboBoxSelectorCompany.TabIndex = 0; comboBoxSelectorCompany.TabIndex = 0;
comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged; comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
// //
@ -141,7 +256,7 @@ namespace ProjectGasolineTanker
pictureBox.Dock = DockStyle.Fill; pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 0); pictureBox.Location = new Point(0, 0);
pictureBox.Name = "pictureBox"; pictureBox.Name = "pictureBox";
pictureBox.Size = new Size(783, 616); pictureBox.Size = new Size(861, 651);
pictureBox.TabIndex = 1; pictureBox.TabIndex = 1;
pictureBox.TabStop = false; pictureBox.TabStop = false;
// //
@ -149,28 +264,40 @@ namespace ProjectGasolineTanker
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(962, 616); ClientSize = new Size(1086, 651);
Controls.Add(pictureBox); Controls.Add(pictureBox);
Controls.Add(groupBoxTools); Controls.Add(Инструменты);
Name = "FormTankerCollection"; Name = "FormTankerCollection";
Text = "Коллекция автомобилей"; Text = "Коллекция лодок";
groupBoxTools.ResumeLayout(false); Инструменты.ResumeLayout(false);
groupBoxTools.PerformLayout(); panelCompanyTools.ResumeLayout(false);
panelCompanyTools.PerformLayout();
panelStorage.ResumeLayout(false);
panelStorage.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
ResumeLayout(false); ResumeLayout(false);
} }
#endregion #endregion
private GroupBox groupBoxTools; private GroupBox Инструменты;
private Button buttonAddTanker;
private ComboBox comboBoxSelectorCompany; private ComboBox comboBoxSelectorCompany;
private Button buttonAddGasolineTanker; private Button buttonAddGasolineTanker;
private Button buttonAddTanker;
private Button buttonRemoveTanker;
private MaskedTextBox maskedTextBoxPosition; private MaskedTextBox maskedTextBoxPosition;
private PictureBox pictureBox; private PictureBox pictureBox;
private Button buttonGoToCheck;
private Button buttonRefresh; private Button buttonRefresh;
private Button buttonRemoveTanker;
private Button buttonGoToCheck;
private Panel panelStorage;
private Label labelCollectionName;
private RadioButton radioButtonMassive;
private TextBox textBoxCollectionName;
private Button buttonCollectionDel;
private ListBox listBoxCollection;
private Button buttonCollectionAdd;
private RadioButton radioButtonList;
private Button buttonCreateCompany;
private Panel panelCompanyTools;
} }
} }

View File

@ -8,7 +8,12 @@ namespace ProjectGasolineTanker;
/// Форма работы с компанией и ее коллекцией /// Форма работы с компанией и ее коллекцией
/// </summary> /// </summary>
public partial class FormTankerCollection : Form public partial class FormTankerCollection : Form
{ {
/// <summary>
/// Хранилише коллекций
/// </summary>
private readonly StorageCollection<DrawningTanker> _storageCollection;
/// <summary> /// <summary>
/// Компания /// Компания
/// </summary> /// </summary>
@ -20,6 +25,7 @@ public partial class FormTankerCollection : Form
public FormTankerCollection() public FormTankerCollection()
{ {
InitializeComponent(); InitializeComponent();
_storageCollection = new();
} }
/// <summary> /// <summary>
@ -37,24 +43,6 @@ public partial class FormTankerCollection : Form
} }
} }
/// <summary>
/// Добавление обычного автомобиля
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddTanker_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTanker));
/// <summary>
/// Добавление спортивного автомобиля
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddGasolineTanker_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningGasolineTanker));
/// <summary>
/// Создание объекта класса-перемещения
/// </summary>
/// <param name="type">Тип создаваемого объекта</param>
private void CreateObject(string type) private void CreateObject(string type)
{ {
if (_company == null) if (_company == null)
@ -90,6 +78,20 @@ public partial class FormTankerCollection : Form
} }
} }
/// <summary>
/// Добавление обычного автомобиля
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonAddTanker_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTanker));
/// <summary>
/// Добавление спортивного автомобиля
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonAddGasolineTanker_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningGasolineTanker));
/// <summary> /// <summary>
/// Получение цвета /// Получение цвета
/// </summary> /// </summary>
@ -107,11 +109,6 @@ public partial class FormTankerCollection : Form
return color; return color;
} }
/// <summary>
/// Удаление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRemoveTanker_Click(object sender, EventArgs e) private void ButtonRemoveTanker_Click(object sender, EventArgs e)
{ {
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null) if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null)
@ -186,4 +183,81 @@ public partial class FormTankerCollection : Form
pictureBox.Image = _company.Show(); pictureBox.Image = _company.Show();
} }
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);
RefreshListBoxItems();
}
/// <summary>
/// Обновление списка в listBoxCollection
/// </summary>
private void RefreshListBoxItems()
{
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);
}
}
}
private void ButtonCollectionDel_Click(object sender, EventArgs e)
{
if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItems == null)
{
MessageBox.Show("Коллекция не выбрана");
return;
}
if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
_storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
RefreshListBoxItems();
}
private void ButtonCreateCompany_Click(object sender, EventArgs e)
{
if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
{
MessageBox.Show("Коллекция не выбрана");
return;
}
ICollectionGenericObjects<DrawningTanker>? collection = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
if (collection == null)
{
MessageBox.Show("Коллекция не проинициализирована");
return;
}
switch (comboBoxSelectorCompany.Text)
{
case "Хранилище":
_company = new CarPark(pictureBox.Width, pictureBox.Height, collection);
break;
}
panelCompanyTools.Enabled = true;
RefreshListBoxItems();
}
} }