From 4a7084fdb5308e7c49a365c794f9fb5f5216d5ab Mon Sep 17 00:00:00 2001 From: MorozovDanil Date: Sun, 14 Apr 2024 15:17:56 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B2=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=BD=D0=BE=20=D0=B4=D0=BE=D0=BF=20=D0=B7=D0=B0=D0=B4?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=B5(=D0=BF=D0=BE=D1=82=D0=BE=D0=BC=20?= =?UTF-8?q?=D1=83=D0=B4=D0=B0=D0=BB=D0=B8=D1=82=D1=8C=20=D0=B2=20ListGener?= =?UTF-8?q?icObjects)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 8 +- .../CollectionType.cs | 28 ++ .../ICollectionGenericObjects.cs | 6 +- .../ListGenericObjects.cs | 121 ++++++++ .../MassiveGenericObjects.cs | 24 +- .../ShipSharingService.cs | 5 - .../StorageCollection.cs | 87 ++++++ .../FormShipCollection.Designer.cs | 265 +++++++++++++----- .../FormShipCollection.cs | 108 ++++++- .../FormShipCollection.resx | 3 - 10 files changed, 552 insertions(+), 103 deletions(-) create mode 100644 ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/CollectionType.cs create mode 100644 ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/ListGenericObjects.cs create mode 100644 ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/StorageCollection.cs diff --git a/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/AbstractCompany.cs b/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/AbstractCompany.cs index 4a20e8c..73ad088 100644 --- a/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/AbstractCompany.cs @@ -56,9 +56,9 @@ public abstract class AbstractCompany /// Компания /// Добавляемый объект /// - public static int operator +(AbstractCompany company, DrawningShip boat) + public static bool operator +(AbstractCompany company, DrawningShip boat) { - return company._collection?.Insert(boat) ?? -1; + return company._collection?.Insert(boat) ?? false; } /// @@ -67,9 +67,9 @@ public abstract class AbstractCompany /// Компания /// Номер удаляемого объекта /// - public static DrawningShip operator -(AbstractCompany company, int position) + public static bool operator -(AbstractCompany company, int position) { - return company._collection?.Remove(position) ?? null; + return company._collection?.Remove(position) ?? false; } /// diff --git a/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/CollectionType.cs b/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/CollectionType.cs new file mode 100644 index 0000000..25e72ce --- /dev/null +++ b/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/CollectionType.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectContainerShip.CollectionGenericObjects; + +/// +/// Тип коллекции +/// +public enum CollectionType +{ + /// + /// Неопределено + /// + None = 0, + + /// + /// Масссив + /// + Massive = 1, + + /// + /// Список + /// + List = 2 +} diff --git a/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/ICollectionGenericObjects.cs index 2dc17b3..6c3cb97 100644 --- a/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -19,7 +19,7 @@ public interface ICollectionGenericObjects /// /// Добавляемый объект /// true - вставка прошла удачно, false - вставка не удалась - int Insert (T obj); + bool Insert (T obj); /// /// Добавление объекта в коллекцию на конкретную позицию @@ -27,14 +27,14 @@ public interface ICollectionGenericObjects /// /// Добавляемый объект /// /// Позиция /// true - вставка прошла удачно, false - вставка не удалась - int Insert (T obj, int position); + bool Insert (T obj, int position); /// /// Удаление объекта из коллекции с конктретной позиции /// /// /// Добавляемый объект /// true - удаление прошло удачно, false - удаление не удалось - T Remove (int position); + bool Remove (int position); /// /// Получение объекта по позиции diff --git a/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/ListGenericObjects.cs b/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/ListGenericObjects.cs new file mode 100644 index 0000000..83765fe --- /dev/null +++ b/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/ListGenericObjects.cs @@ -0,0 +1,121 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectContainerShip.CollectionGenericObjects; + +/// +/// Параметризованный набор объектов +/// +/// Параметр: ограничение - ссылочный тип +public class ListGenericObjects : ICollectionGenericObjects + where T : class +{ + /// + /// Список объектов, которые храним + /// + //private readonly List _collection; + private readonly Dictionary _collection; + + /// + /// Максимально допустимое число объектов в списке + /// + private int _maxCount; + + public int Count => _collection.Count; + + public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } } + + /// + /// Конструктор + /// + public ListGenericObjects() + { + //_collection = new(); + _collection = new Dictionary(); + } + + public T? Get(int position) + { + if (position >= 0 && position < Count) + { + return _collection[position]; + } + else + { + return null; + } + + } + public bool Insert(T obj) + { + if (Count == _maxCount) { return false; } + //_collection.Add(obj); + //return true; + + //допка + int position = FindFirstNullPosition(); + if (position == -1) + { + return false; + } + + _collection[position] = obj; + return true; + } + + public bool Insert(T obj, int position) + { + //if (position < 0 || position >= Count || Count == _maxCount) + //{ + // return false; + //} + //_collection.Insert(position, obj); + + //return false; + + //допка + if (position < 0 || position >= _maxCount || Count == _maxCount || _collection.ContainsKey(position)) + { + return false; + } + + _collection[position] = obj; + return true; + } + + public bool Remove(int position) + { + // if (position < 0 || position >= Count) + // { + // return false; + // } + // _collection.RemoveAt(position); + // return true; + if (!_collection.ContainsKey(position)) + { + return false; + } + + _collection.Remove(position); + return true; + } + /// + /// Находит первую пустую позицию в словаре + /// + /// Индекс первой пустой позиции или -1, если такой не найдено + private int FindFirstNullPosition() + { + for (int i = 0; i < _maxCount; i++) + { + if (!_collection.ContainsKey(i) || _collection[i] == null) + { + return i; + } + } + return -1; + } + +} diff --git a/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/MassiveGenericObjects.cs index abe67dc..12404ff 100644 --- a/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/MassiveGenericObjects.cs @@ -50,29 +50,29 @@ public class MassiveGenericObjects : ICollectionGenericObjects return null; } - public int Insert(T obj) + public bool Insert(T obj) { for (int i = 0; i < Count; i++) { if (_collection[i] == null) { _collection[i] = obj; - return i; + return true; } } - return -1; + return false; } - public int Insert(T obj, int position) + public bool Insert(T obj, int position) { if (position < 0 || position >= Count) { - return -1; + return false; } if (_collection[position] == null) { _collection[position] = obj; - return position; + return true; } for (int i = position + 1; i < Count; i++) @@ -80,7 +80,7 @@ public class MassiveGenericObjects : ICollectionGenericObjects if (_collection[i] == null) { _collection[i] = obj; - return i; + return true; } } for (int i = position - 1; i >= 0; i--) @@ -88,21 +88,21 @@ public class MassiveGenericObjects : ICollectionGenericObjects if (_collection[i] == null) { _collection[i] = obj; - return i; + return true; } } - return -1; + return false; } - public T Remove(int position) + public bool Remove(int position) { if (position < 0 || position >= Count) { - return null; + return false; } T obj = _collection[position]; _collection[position] = null; - return obj; + return true; } } \ No newline at end of file diff --git a/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/ShipSharingService.cs b/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/ShipSharingService.cs index d2e7c60..cee3398 100644 --- a/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/ShipSharingService.cs +++ b/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/ShipSharingService.cs @@ -18,11 +18,6 @@ public class ShipSharingService : AbstractCompany protected override void DrawBackground(Graphics g) { - //Color backgroundColor = Color.SkyBlue; - //using (Brush brush = new SolidBrush(backgroundColor)) - //{ - // g.FillRectangle(brush, new Rectangle(0, 0, _pictureWidth, _pictureHeight)); - //} Pen pen = new Pen(Color.Brown, 3); int offsetX = 10, offsetY = -12; int x = 1 + offsetX, y = _pictureHeight - _placeSizeHeight + offsetY; diff --git a/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/StorageCollection.cs b/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/StorageCollection.cs new file mode 100644 index 0000000..4452313 --- /dev/null +++ b/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/StorageCollection.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectContainerShip.CollectionGenericObjects; + +/// +/// Класс - хранилище коллекций +/// +/// +public class StorageCollection + where T : class +{ + /// + /// Словарь (хранилище) с коллекциями + /// + readonly Dictionary> _storages; + + /// + /// Возвращение списка названий коллекций + /// + public List Keys => _storages.Keys.ToList(); + + /// + /// Конструктор + /// + public StorageCollection() + { + _storages = new Dictionary>(); + } + + /// + /// Добавление коллекции в хранилище + /// + /// Название коллекции + /// тип коллекции + public void AddCollection(string name, CollectionType collectionType) + { + if (string.IsNullOrEmpty(name) || _storages.ContainsKey(name)) + { + return; + } + switch (collectionType) + { + case CollectionType.Massive: + _storages[name] = new MassiveGenericObjects(); + break; + case CollectionType.List: + _storages[name] = new ListGenericObjects(); + break; + default: + return; + } + } + + /// + /// Удаление коллекции + /// + /// Название коллекции + public void DelCollection(string name) + { + if (_storages.ContainsKey(name)) + { + _storages.Remove(name); + } + + } + + /// + /// Доступ к коллекции + /// + /// Название коллекции + /// + public ICollectionGenericObjects? this[string name] + { + get + { + if (_storages.ContainsKey(name)) + { + return _storages[name]; + } + return null; + } + } +} diff --git a/ProjectContainerShip/ProjectContainerShip/FormShipCollection.Designer.cs b/ProjectContainerShip/ProjectContainerShip/FormShipCollection.Designer.cs index cf8986e..babf245 100644 --- a/ProjectContainerShip/ProjectContainerShip/FormShipCollection.Designer.cs +++ b/ProjectContainerShip/ProjectContainerShip/FormShipCollection.Designer.cs @@ -29,101 +29,216 @@ private void InitializeComponent() { groupBoxTools = new GroupBox(); - buttonRefresh = new Button(); - buttonGoToCheck = new Button(); - buttonDelShip = new Button(); - maskedTextBoxPosition = new MaskedTextBox(); - buttonAddContainerShip = new Button(); + panelCompanyTools = new Panel(); buttonAddShip = new Button(); + buttonAddContainerShip = new Button(); + maskedTextBoxPosition = new MaskedTextBox(); + buttonRefresh = new Button(); + buttonDelShip = new Button(); + buttonGoToCheck = new Button(); + buttonCreateCompany = 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(); pictureBox = new PictureBox(); - colorDialog = new ColorDialog(); groupBoxTools.SuspendLayout(); + panelCompanyTools.SuspendLayout(); + panelStorage.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); SuspendLayout(); // // groupBoxTools // - groupBoxTools.Controls.Add(buttonRefresh); - groupBoxTools.Controls.Add(buttonGoToCheck); - groupBoxTools.Controls.Add(buttonDelShip); - groupBoxTools.Controls.Add(maskedTextBoxPosition); - groupBoxTools.Controls.Add(buttonAddContainerShip); - groupBoxTools.Controls.Add(buttonAddShip); + groupBoxTools.Controls.Add(panelCompanyTools); + groupBoxTools.Controls.Add(buttonCreateCompany); + groupBoxTools.Controls.Add(panelStorage); groupBoxTools.Controls.Add(comboBoxSelectorCompany); groupBoxTools.Dock = DockStyle.Right; groupBoxTools.Location = new Point(930, 0); groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(206, 617); + groupBoxTools.Size = new Size(206, 638); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; // - // buttonRefresh + // panelCompanyTools // - buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRefresh.Location = new Point(6, 482); - buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.RightToLeft = RightToLeft.No; - buttonRefresh.Size = new Size(194, 34); - buttonRefresh.TabIndex = 6; - buttonRefresh.Text = "Обновить"; - buttonRefresh.UseVisualStyleBackColor = true; + panelCompanyTools.Controls.Add(buttonAddShip); + panelCompanyTools.Controls.Add(buttonAddContainerShip); + panelCompanyTools.Controls.Add(maskedTextBoxPosition); + panelCompanyTools.Controls.Add(buttonRefresh); + panelCompanyTools.Controls.Add(buttonDelShip); + panelCompanyTools.Controls.Add(buttonGoToCheck); + panelCompanyTools.Enabled = false; + panelCompanyTools.Location = new Point(6, 386); + panelCompanyTools.Name = "panelCompanyTools"; + panelCompanyTools.Size = new Size(197, 246); + panelCompanyTools.TabIndex = 9; // - // buttonGoToCheck + // buttonAddShip // - buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonGoToCheck.Location = new Point(6, 367); - buttonGoToCheck.Name = "buttonGoToCheck"; - buttonGoToCheck.RightToLeft = RightToLeft.No; - buttonGoToCheck.Size = new Size(194, 34); - buttonGoToCheck.TabIndex = 5; - buttonGoToCheck.Text = "Передать на тесты"; - buttonGoToCheck.UseVisualStyleBackColor = true; - buttonGoToCheck.Click += ButtonGoToCheck_Click; - // - // buttonDelShip - // - buttonDelShip.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonDelShip.Location = new Point(6, 234); - buttonDelShip.Name = "buttonDelShip"; - buttonDelShip.RightToLeft = RightToLeft.No; - buttonDelShip.Size = new Size(194, 34); - buttonDelShip.TabIndex = 4; - buttonDelShip.Text = "Удалить"; - buttonDelShip.UseVisualStyleBackColor = true; - buttonDelShip.Click += ButtonDelShip_Click; - // - // maskedTextBoxPosition - // - maskedTextBoxPosition.Location = new Point(6, 203); - maskedTextBoxPosition.Mask = "00"; - maskedTextBoxPosition.Name = "maskedTextBoxPosition"; - maskedTextBoxPosition.Size = new Size(188, 25); - maskedTextBoxPosition.TabIndex = 3; - maskedTextBoxPosition.ValidatingType = typeof(int); + buttonAddShip.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddShip.Location = new Point(3, 12); + buttonAddShip.Name = "buttonAddShip"; + buttonAddShip.Size = new Size(191, 34); + buttonAddShip.TabIndex = 1; + buttonAddShip.Text = "Добавление корабля"; + buttonAddShip.UseVisualStyleBackColor = true; + buttonAddShip.Click += ButtonAddShip_Click; // // buttonAddContainerShip // buttonAddContainerShip.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddContainerShip.Location = new Point(6, 134); + buttonAddContainerShip.Location = new Point(3, 52); buttonAddContainerShip.Name = "buttonAddContainerShip"; - buttonAddContainerShip.Size = new Size(194, 34); + buttonAddContainerShip.Size = new Size(191, 34); buttonAddContainerShip.TabIndex = 2; buttonAddContainerShip.Text = "Добавление контейнеровоза"; buttonAddContainerShip.UseVisualStyleBackColor = true; buttonAddContainerShip.Click += ButtonAddContainerShip_Click; // - // buttonAddShip + // maskedTextBoxPosition // - buttonAddShip.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddShip.Location = new Point(6, 94); - buttonAddShip.Name = "buttonAddShip"; - buttonAddShip.Size = new Size(194, 34); - buttonAddShip.TabIndex = 1; - buttonAddShip.Text = "Добавление корабля"; - buttonAddShip.UseVisualStyleBackColor = true; - buttonAddShip.Click += ButtonAddShip_Click; + maskedTextBoxPosition.Location = new Point(3, 92); + maskedTextBoxPosition.Mask = "00"; + maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + maskedTextBoxPosition.Size = new Size(194, 25); + maskedTextBoxPosition.TabIndex = 3; + maskedTextBoxPosition.ValidatingType = typeof(int); + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Location = new Point(3, 206); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.RightToLeft = RightToLeft.No; + buttonRefresh.Size = new Size(191, 34); + buttonRefresh.TabIndex = 6; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; + // + // buttonDelShip + // + buttonDelShip.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonDelShip.Location = new Point(3, 123); + buttonDelShip.Name = "buttonDelShip"; + buttonDelShip.RightToLeft = RightToLeft.No; + buttonDelShip.Size = new Size(191, 34); + buttonDelShip.TabIndex = 4; + buttonDelShip.Text = "Удалить"; + buttonDelShip.UseVisualStyleBackColor = true; + buttonDelShip.Click += ButtonDelShip_Click; + // + // buttonGoToCheck + // + buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonGoToCheck.Location = new Point(3, 163); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.RightToLeft = RightToLeft.No; + buttonGoToCheck.Size = new Size(191, 34); + buttonGoToCheck.TabIndex = 5; + buttonGoToCheck.Text = "Передать на тесты"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += ButtonGoToCheck_Click; + // + // buttonCreateCompany + // + buttonCreateCompany.Location = new Point(6, 357); + buttonCreateCompany.Name = "buttonCreateCompany"; + buttonCreateCompany.Size = new Size(194, 23); + buttonCreateCompany.TabIndex = 8; + buttonCreateCompany.Text = "Создать компанию"; + buttonCreateCompany.UseVisualStyleBackColor = true; + buttonCreateCompany.Click += ButtonCreateCompany_Click; + // + // panelStorage + // + panelStorage.Controls.Add(buttonCollectionDel); + 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, 21); + panelStorage.Name = "panelStorage"; + panelStorage.Size = new Size(200, 297); + panelStorage.TabIndex = 7; + // + // buttonCollectionDel + // + buttonCollectionDel.Location = new Point(3, 272); + buttonCollectionDel.Name = "buttonCollectionDel"; + buttonCollectionDel.Size = new Size(194, 23); + buttonCollectionDel.TabIndex = 6; + buttonCollectionDel.Text = "Удалить коллекцию"; + buttonCollectionDel.UseVisualStyleBackColor = true; + buttonCollectionDel.Click += ButtonCollectionDel_Click; + // + // listBoxCollection + // + listBoxCollection.FormattingEnabled = true; + listBoxCollection.ItemHeight = 17; + listBoxCollection.Location = new Point(3, 126); + listBoxCollection.Name = "listBoxCollection"; + listBoxCollection.Size = new Size(194, 140); + listBoxCollection.TabIndex = 5; + // + // buttonCollectionAdd + // + buttonCollectionAdd.Location = new Point(3, 89); + buttonCollectionAdd.Name = "buttonCollectionAdd"; + buttonCollectionAdd.Size = new Size(194, 31); + buttonCollectionAdd.TabIndex = 4; + buttonCollectionAdd.Text = "Добавить коллекцию"; + buttonCollectionAdd.UseVisualStyleBackColor = true; + buttonCollectionAdd.Click += ButtonCollectionAdd_Click; + // + // radioButtonList + // + radioButtonList.AutoSize = true; + radioButtonList.Location = new Point(120, 70); + radioButtonList.Name = "radioButtonList"; + radioButtonList.Size = new Size(68, 21); + radioButtonList.TabIndex = 3; + radioButtonList.TabStop = true; + radioButtonList.Text = "Список"; + radioButtonList.UseVisualStyleBackColor = true; + // + // radioButtonMassive + // + radioButtonMassive.AutoSize = true; + radioButtonMassive.Location = new Point(25, 70); + radioButtonMassive.Name = "radioButtonMassive"; + radioButtonMassive.Size = new Size(71, 21); + radioButtonMassive.TabIndex = 2; + radioButtonMassive.TabStop = true; + radioButtonMassive.Text = "Массив"; + radioButtonMassive.UseVisualStyleBackColor = true; + // + // textBoxCollectionName + // + textBoxCollectionName.Location = new Point(3, 39); + textBoxCollectionName.Name = "textBoxCollectionName"; + textBoxCollectionName.Size = new Size(194, 25); + textBoxCollectionName.TabIndex = 1; + // + // labelCollectionName + // + labelCollectionName.AutoSize = true; + labelCollectionName.Location = new Point(39, 9); + labelCollectionName.Name = "labelCollectionName"; + labelCollectionName.Size = new Size(134, 17); + labelCollectionName.TabIndex = 0; + labelCollectionName.Text = "Название коллекции:"; // // comboBoxSelectorCompany // @@ -131,7 +246,7 @@ comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxSelectorCompany.FormattingEnabled = true; comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); - comboBoxSelectorCompany.Location = new Point(6, 24); + comboBoxSelectorCompany.Location = new Point(6, 322); comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; comboBoxSelectorCompany.Size = new Size(194, 25); comboBoxSelectorCompany.TabIndex = 0; @@ -142,7 +257,7 @@ pictureBox.Dock = DockStyle.Fill; pictureBox.Location = new Point(0, 0); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(930, 617); + pictureBox.Size = new Size(930, 638); pictureBox.TabIndex = 1; pictureBox.TabStop = false; // @@ -150,13 +265,16 @@ // AutoScaleDimensions = new SizeF(7F, 17F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1136, 617); + ClientSize = new Size(1136, 638); Controls.Add(pictureBox); Controls.Add(groupBoxTools); Name = "FormShipCollection"; Text = "Коллекция кораблей"; groupBoxTools.ResumeLayout(false); - groupBoxTools.PerformLayout(); + panelCompanyTools.ResumeLayout(false); + panelCompanyTools.PerformLayout(); + panelStorage.ResumeLayout(false); + panelStorage.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); ResumeLayout(false); } @@ -172,6 +290,15 @@ private Button buttonDelShip; private Button buttonRefresh; private Button buttonGoToCheck; - private ColorDialog colorDialog; + private Panel panelStorage; + private RadioButton radioButtonList; + private RadioButton radioButtonMassive; + private TextBox textBoxCollectionName; + private Label labelCollectionName; + private Button buttonCreateCompany; + private Button buttonCollectionDel; + private ListBox listBoxCollection; + private Button buttonCollectionAdd; + private Panel panelCompanyTools; } } \ No newline at end of file diff --git a/ProjectContainerShip/ProjectContainerShip/FormShipCollection.cs b/ProjectContainerShip/ProjectContainerShip/FormShipCollection.cs index 66fc54f..f8bf5aa 100644 --- a/ProjectContainerShip/ProjectContainerShip/FormShipCollection.cs +++ b/ProjectContainerShip/ProjectContainerShip/FormShipCollection.cs @@ -14,12 +14,18 @@ namespace ProjectContainerShip /// private AbstractCompany? _company; + /// + /// Хранилище коллекций + /// + private readonly StorageCollection _storageCollection; + /// /// Конструктор /// public FormShipCollection() { InitializeComponent(); + _storageCollection = new(); } /// @@ -29,12 +35,7 @@ namespace ProjectContainerShip /// private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) { - switch (comboBoxSelectorCompany.Text) - { - case "Хранилище": - _company = new ShipSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); - break; - } + panelCompanyTools.Enabled = false; } /// @@ -64,7 +65,7 @@ namespace ProjectContainerShip return; } - if (_company + _drawningShip != -1) + if (_company + _drawningShip) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _company.Show(); @@ -185,5 +186,98 @@ namespace ProjectContainerShip 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(); + } + + /// + /// Обновление списка в listBoxCollection + /// + 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? 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(); + } } } diff --git a/ProjectContainerShip/ProjectContainerShip/FormShipCollection.resx b/ProjectContainerShip/ProjectContainerShip/FormShipCollection.resx index 3bec0d5..8c82215 100644 --- a/ProjectContainerShip/ProjectContainerShip/FormShipCollection.resx +++ b/ProjectContainerShip/ProjectContainerShip/FormShipCollection.resx @@ -117,9 +117,6 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 17, 17 - 79