Лабораторная работа №4

This commit is contained in:
Aidar 2024-05-03 21:39:13 +04:00
parent da9d37f184
commit eb1240b42d
6 changed files with 472 additions and 80 deletions

View File

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

View File

@ -0,0 +1,66 @@
namespace ProjectLiner.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 null;
}
return _collection[position];
}
public int Insert(T obj)
{
return Insert(obj, _collection.Count);
}
public int Insert(T obj, int position)
{
if (_maxCount == _collection.Count || position < 0 || position > _collection.Count)
{
return -1;
}
_collection.Insert(position, obj);
return _collection.Count;
}
public T? Remove(int position)
{
if (position < 0 || position > _collection.Count)
{
return null;
}
T? obj = _collection[position];
_collection.RemoveAt(position);
return obj;
}
}

View File

@ -0,0 +1,86 @@
namespace ProjectLiner.CollectionGenericObjects;
/// <summary>
/// Класс-хранилище коллекций
/// </summary>
/// <typeparam name="T"></typeparam>
public class StorageCollection<T>
where T : class
{
/// <summary>
/// Словарь (хранилище) с коллекциями
/// </summary>
readonly Dictionary<string, ICollectionGenericObjects<T>> _storage;
/// <summary>
/// Возвращение списка названий коллекций
/// </summary>
public List<string> Keys => _storage.Keys.ToList();
/// <summary>
/// Конструктор
/// </summary>
public StorageCollection()
{
_storage = 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) || _storage.ContainsKey(name))
{
return;
}
if (collectionType == CollectionType.None)
{
return;
}
if (collectionType == CollectionType.Massive)
{
_storage[name] = new MassiveGenericObjects<T>();
}
else if (collectionType == CollectionType.List)
{
_storage[name] = new ListGenericObjects<T>();
}
}
/// <summary>
/// Удаление коллекции
/// </summary>
/// <param name="name">Название коллекции</param>
public void DelCollection(string name)
{
if (name == null || !_storage.ContainsKey(name))
{
return;
}
_storage.Remove(name);
}
/// <summary>
/// Доступ к коллекции
/// </summary>
/// <param name="name">Название коллекции</param>
/// <returns></returns>
public ICollectionGenericObjects<T>? this[string name]
{
get
{
if (_storage.ContainsKey(name))
{
return _storage[name];
}
else
{
return null;
}
}
}
}

View File

@ -1,4 +1,8 @@
namespace ProjectLiner using static System.Net.Mime.MediaTypeNames;
using System.Windows.Forms;
using System.Xml.Linq;
namespace ProjectLiner
{ {
partial class FormShipCollection partial class FormShipCollection
{ {
@ -29,53 +33,103 @@
private void InitializeComponent() private void InitializeComponent()
{ {
groupBoxTools = new GroupBox(); groupBoxTools = new GroupBox();
panelCompanyTools = new Panel();
buttonAddShip = new Button();
buttonAddLiner = new Button();
buttonRefresh = new Button(); buttonRefresh = new Button();
maskedTextBoxPosition = new MaskedTextBox();
buttonGoToCheck = new Button(); buttonGoToCheck = new Button();
buttonRemoveShip = new Button(); buttonRemoveShip = new Button();
maskedTextBoxPosition = new MaskedTextBox(); buttonCreateCompany = new Button();
buttonAddLiner = new Button(); panelStorage = new Panel();
buttonAddShip = new Button(); buttonCollectionDel = new Button();
ComboBoxSelectorCompany = new ComboBox(); listBoxCollection = new ListBox();
buttonCollectionAdd = new Button();
radioButtonList = new RadioButton();
radioButtonMassive = new RadioButton();
textBoxCollectionName = new TextBox();
labelCollectionName = new Label();
comboBoxSelectorCompany = new ComboBox();
pictureBox = new PictureBox(); pictureBox = new PictureBox();
colorDialog1 = new ColorDialog();
groupBoxTools.SuspendLayout(); groupBoxTools.SuspendLayout();
panelCompanyTools.SuspendLayout();
panelStorage.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
SuspendLayout(); SuspendLayout();
// //
// groupBoxTools // groupBoxTools
// //
groupBoxTools.Controls.Add(buttonRefresh); groupBoxTools.Controls.Add(panelCompanyTools);
groupBoxTools.Controls.Add(buttonGoToCheck); groupBoxTools.Controls.Add(buttonCreateCompany);
groupBoxTools.Controls.Add(buttonRemoveShip); groupBoxTools.Controls.Add(panelStorage);
groupBoxTools.Controls.Add(maskedTextBoxPosition); groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Controls.Add(buttonAddLiner);
groupBoxTools.Controls.Add(buttonAddShip);
groupBoxTools.Controls.Add(ComboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right; groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(1006, 0); groupBoxTools.Location = new Point(793, 0);
groupBoxTools.Name = "groupBoxTools"; groupBoxTools.Name = "groupBoxTools";
groupBoxTools.Size = new Size(178, 561); groupBoxTools.Size = new Size(144, 571);
groupBoxTools.TabIndex = 0; groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false; groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты"; groupBoxTools.Text = "Инструменты";
// //
// panelCompanyTools
//
panelCompanyTools.Controls.Add(buttonAddShip);
panelCompanyTools.Controls.Add(buttonAddLiner);
panelCompanyTools.Controls.Add(buttonRefresh);
panelCompanyTools.Controls.Add(maskedTextBoxPosition);
panelCompanyTools.Controls.Add(buttonGoToCheck);
panelCompanyTools.Controls.Add(buttonRemoveShip);
panelCompanyTools.Dock = DockStyle.Bottom;
panelCompanyTools.Enabled = false;
panelCompanyTools.Location = new Point(3, 321);
panelCompanyTools.Name = "panelCompanyTools";
panelCompanyTools.Size = new Size(138, 247);
panelCompanyTools.TabIndex = 10;
//
// buttonAddLiner
//
buttonAddLiner.Location = new Point(3, 51);
buttonAddLiner.Name = "buttonAddLiner";
buttonAddLiner.Size = new Size(126, 44);
buttonAddLiner.TabIndex = 2;
buttonAddLiner.Text = "Добавление лайнера";
buttonAddLiner.UseVisualStyleBackColor = true;
buttonAddLiner.Click += ButtonAddLiner_Click;
//
// buttonAddShip
//
buttonAddShip.Location = new Point(4, 3);
buttonAddShip.Name = "buttonAddShip";
buttonAddShip.Size = new Size(126, 42);
buttonAddShip.TabIndex = 1;
buttonAddShip.Text = "Добавление корабля";
buttonAddShip.UseVisualStyleBackColor = true;
buttonAddShip.Click += ButtonAddShip_Click;
//
// buttonRefresh // buttonRefresh
// //
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; buttonRefresh.Location = new Point(3, 202);
buttonRefresh.Location = new Point(0, 302);
buttonRefresh.Name = "buttonRefresh"; buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(178, 40); buttonRefresh.Size = new Size(126, 42);
buttonRefresh.TabIndex = 6; buttonRefresh.TabIndex = 6;
buttonRefresh.Text = "Обновить"; buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true; buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += ButtonRefresh_Click; buttonRefresh.Click += ButtonRefresh_Click;
// //
// maskedTextBoxPosition
//
maskedTextBoxPosition.Location = new Point(4, 101);
maskedTextBoxPosition.Mask = "00";
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
maskedTextBoxPosition.Size = new Size(126, 23);
maskedTextBoxPosition.TabIndex = 3;
maskedTextBoxPosition.ValidatingType = typeof(int);
//
// buttonGoToCheck // buttonGoToCheck
// //
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; buttonGoToCheck.Location = new Point(4, 166);
buttonGoToCheck.Location = new Point(0, 256);
buttonGoToCheck.Name = "buttonGoToCheck"; buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(178, 40); buttonGoToCheck.Size = new Size(126, 30);
buttonGoToCheck.TabIndex = 5; buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Text = "Передать на тесты"; buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true; buttonGoToCheck.UseVisualStyleBackColor = true;
@ -83,64 +137,126 @@
// //
// buttonRemoveShip // buttonRemoveShip
// //
buttonRemoveShip.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; buttonRemoveShip.Location = new Point(4, 130);
buttonRemoveShip.Location = new Point(0, 191);
buttonRemoveShip.Name = "buttonRemoveShip"; buttonRemoveShip.Name = "buttonRemoveShip";
buttonRemoveShip.Size = new Size(178, 40); buttonRemoveShip.Size = new Size(126, 30);
buttonRemoveShip.TabIndex = 4; buttonRemoveShip.TabIndex = 4;
buttonRemoveShip.Text = "Удаление корабля"; buttonRemoveShip.Text = "Удалить корабль";
buttonRemoveShip.UseVisualStyleBackColor = true; buttonRemoveShip.UseVisualStyleBackColor = true;
buttonRemoveShip.Click += ButtonRemoveShip_Click; buttonRemoveShip.Click += ButtonRemoveShip_Click;
// //
// maskedTextBoxPosition // buttonCreateCompany
// //
maskedTextBoxPosition.Location = new Point(0, 162); buttonCreateCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
maskedTextBoxPosition.Mask = "00"; buttonCreateCompany.Location = new Point(7, 285);
maskedTextBoxPosition.Name = "maskedTextBoxPosition"; buttonCreateCompany.Name = "buttonCreateCompany";
maskedTextBoxPosition.Size = new Size(178, 23); buttonCreateCompany.Size = new Size(126, 30);
maskedTextBoxPosition.TabIndex = 3; buttonCreateCompany.TabIndex = 9;
maskedTextBoxPosition.ValidatingType = typeof(int); buttonCreateCompany.Text = "Создать компанию";
buttonCreateCompany.UseVisualStyleBackColor = true;
buttonCreateCompany.Click += ButtonCreateCompany_Click;
// //
// buttonAddLiner // panelStorage
// //
buttonAddLiner.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; panelStorage.Controls.Add(buttonCollectionDel);
buttonAddLiner.Location = new Point(0, 97); panelStorage.Controls.Add(listBoxCollection);
buttonAddLiner.Name = "buttonAddLiner"; panelStorage.Controls.Add(buttonCollectionAdd);
buttonAddLiner.Size = new Size(178, 40); panelStorage.Controls.Add(radioButtonList);
buttonAddLiner.TabIndex = 2; panelStorage.Controls.Add(radioButtonMassive);
buttonAddLiner.Text = "Добавление лайнера"; panelStorage.Controls.Add(textBoxCollectionName);
buttonAddLiner.UseVisualStyleBackColor = true; panelStorage.Controls.Add(labelCollectionName);
buttonAddLiner.Click += buttonAddLiner_Click; panelStorage.Dock = DockStyle.Top;
panelStorage.Location = new Point(3, 19);
panelStorage.Name = "panelStorage";
panelStorage.Size = new Size(138, 231);
panelStorage.TabIndex = 7;
// //
// buttonAddShip // buttonCollectionDel
// //
buttonAddShip.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; buttonCollectionDel.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddShip.Location = new Point(0, 51); buttonCollectionDel.Location = new Point(3, 196);
buttonAddShip.Name = "buttonAddShip"; buttonCollectionDel.Name = "buttonCollectionDel";
buttonAddShip.Size = new Size(178, 40); buttonCollectionDel.Size = new Size(126, 30);
buttonAddShip.TabIndex = 1; buttonCollectionDel.TabIndex = 8;
buttonAddShip.Text = "Добавление корабля"; buttonCollectionDel.Text = "Удалить коллекцию";
buttonAddShip.UseVisualStyleBackColor = true; buttonCollectionDel.UseVisualStyleBackColor = true;
buttonAddShip.Click += buttonAddShip_Click; buttonCollectionDel.Click += ButtonCollectionDel_Click;
// //
// ComboBoxSelectorCompany // listBoxCollection
// //
ComboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; listBoxCollection.FormattingEnabled = true;
ComboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; listBoxCollection.ItemHeight = 15;
ComboBoxSelectorCompany.FormattingEnabled = true; listBoxCollection.Location = new Point(3, 126);
ComboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); listBoxCollection.Name = "listBoxCollection";
ComboBoxSelectorCompany.Location = new Point(0, 22); listBoxCollection.Size = new Size(126, 64);
ComboBoxSelectorCompany.Name = "ComboBoxSelectorCompany"; listBoxCollection.TabIndex = 5;
ComboBoxSelectorCompany.Size = new Size(178, 23); //
ComboBoxSelectorCompany.TabIndex = 0; // buttonCollectionAdd
ComboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged; //
buttonCollectionAdd.Location = new Point(4, 81);
buttonCollectionAdd.Name = "buttonCollectionAdd";
buttonCollectionAdd.Size = new Size(125, 39);
buttonCollectionAdd.TabIndex = 4;
buttonCollectionAdd.Text = "Добавить коллекцию";
buttonCollectionAdd.UseVisualStyleBackColor = true;
buttonCollectionAdd.Click += ButtonCollectionAdd_Click;
//
// radioButtonList
//
radioButtonList.AutoSize = true;
radioButtonList.Location = new Point(69, 56);
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(4, 56);
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, 27);
textBoxCollectionName.Name = "textBoxCollectionName";
textBoxCollectionName.Size = new Size(126, 23);
textBoxCollectionName.TabIndex = 1;
//
// labelCollectionName
//
labelCollectionName.AutoSize = true;
labelCollectionName.Location = new Point(4, 9);
labelCollectionName.Name = "labelCollectionName";
labelCollectionName.Size = new Size(125, 15);
labelCollectionName.TabIndex = 0;
labelCollectionName.Text = "Название коллекции:";
//
// comboBoxSelectorCompany
//
comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectorCompany.FormattingEnabled = true;
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
comboBoxSelectorCompany.Location = new Point(6, 256);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(126, 23);
comboBoxSelectorCompany.TabIndex = 0;
comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
// //
// pictureBox // pictureBox
// //
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(1006, 561); pictureBox.Size = new Size(793, 571);
pictureBox.TabIndex = 1; pictureBox.TabIndex = 1;
pictureBox.TabStop = false; pictureBox.TabStop = false;
// //
@ -148,13 +264,16 @@
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1184, 561); ClientSize = new Size(937, 571);
Controls.Add(pictureBox); Controls.Add(pictureBox);
Controls.Add(groupBoxTools); Controls.Add(groupBoxTools);
Name = "FormShipCollection"; Name = "FormShipCollection";
Text = "Коллекция кораблей"; Text = "Коллекция самолётов";
groupBoxTools.ResumeLayout(false); groupBoxTools.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);
} }
@ -162,14 +281,23 @@
#endregion #endregion
private GroupBox groupBoxTools; private GroupBox groupBoxTools;
private ComboBox ComboBoxSelectorCompany; private ComboBox comboBoxSelectorCompany;
private Button buttonAddLiner;
private Button buttonAddShip; private Button buttonAddShip;
private Button buttonRefresh; private Button buttonAddLiner;
private Button buttonGoToCheck;
private Button buttonRemoveShip; private Button buttonRemoveShip;
private MaskedTextBox maskedTextBoxPosition; private MaskedTextBox maskedTextBoxPosition;
private PictureBox pictureBox; private PictureBox pictureBox;
private ColorDialog colorDialog1; private Button buttonRefresh;
private Button buttonGoToCheck;
private Panel panelStorage;
private Label labelCollectionName;
private RadioButton radioButtonMassive;
private TextBox textBoxCollectionName;
private Button buttonCollectionAdd;
private RadioButton radioButtonList;
private ListBox listBoxCollection;
private Button buttonCollectionDel;
private Button buttonCreateCompany;
private Panel panelCompanyTools;
} }
} }

View File

@ -8,6 +8,11 @@ namespace ProjectLiner;
/// </summary> /// </summary>
public partial class FormShipCollection : Form public partial class FormShipCollection : Form
{ {
/// <summary>
/// Хранилише коллекций
/// </summary>
private readonly StorageCollection<DrawningShip> _storageCollection;
/// <summary> /// <summary>
/// Компания /// Компания
/// </summary> /// </summary>
@ -19,6 +24,7 @@ public partial class FormShipCollection : Form
public FormShipCollection() public FormShipCollection()
{ {
InitializeComponent(); InitializeComponent();
_storageCollection = new();
} }
/// <summary> /// <summary>
@ -28,12 +34,7 @@ public partial class FormShipCollection : Form
/// <param name="e"></param> /// <param name="e"></param>
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{ {
switch (ComboBoxSelectorCompany.Text) panelCompanyTools.Enabled = false;
{
case "Хранилище":
_company = new ShipSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningShip>());
break;
}
} }
/// <summary> /// <summary>
@ -41,14 +42,14 @@ public partial class FormShipCollection : Form
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void buttonAddShip_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningShip)); private void ButtonAddShip_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningShip));
/// <summary> /// <summary>
/// Добавление лайнера /// Добавление лайнера
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void buttonAddLiner_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningLiner)); private void ButtonAddLiner_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningLiner));
/// <summary> /// <summary>
/// Создание объекта класса-перемещения /// Создание объекта класса-перемещения
@ -176,4 +177,96 @@ public partial class FormShipCollection : Form
} }
pictureBox.Image = _company.Show(); 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);
RefreshListBoxItems();
}
/// <summary>
/// Удаление коллекции
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCollectionDel_Click(object sender, EventArgs e)
{
if (listBoxCollection.SelectedIndex < 0)
{
MessageBox.Show("Сначала выберите коллекцию");
return;
}
if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
_storageCollection.DelCollection(listBoxCollection.SelectedItem?.ToString() ?? string.Empty);
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);
}
}
}
/// <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<DrawningShip>? collection = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
if (collection == null)
{
MessageBox.Show("Коллекция не проинициализирована");
return;
}
switch (comboBoxSelectorCompany.Text)
{
case "Хранилище":
_company = new ShipSharingService(pictureBox.Width, pictureBox.Height, collection);
break;
}
panelCompanyTools.Enabled = true;
RefreshListBoxItems();
}
} }

View File

@ -117,7 +117,4 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<metadata name="colorDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root> </root>