diff --git a/ProjectTank/ProjectTank/CollectionGenericObjects/AbstractCompany.cs b/ProjectTank/ProjectTank/CollectionGenericObjects/AbstractCompany.cs index 68b1260..7c1535c 100644 --- a/ProjectTank/ProjectTank/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectTank/ProjectTank/CollectionGenericObjects/AbstractCompany.cs @@ -28,7 +28,7 @@ namespace ProjectTank.CollectionGenericObjects protected readonly int _pictureHeight; /// - /// Коллекция автомобилей + /// Коллекция танков /// protected ICollectionGenericObjects? _collection = null; diff --git a/ProjectTank/ProjectTank/CollectionGenericObjects/CollectionType.cs b/ProjectTank/ProjectTank/CollectionGenericObjects/CollectionType.cs new file mode 100644 index 0000000..7a39f1e --- /dev/null +++ b/ProjectTank/ProjectTank/CollectionGenericObjects/CollectionType.cs @@ -0,0 +1,18 @@ +namespace ProjectTank.CollectionGenericObjects +{ + public enum CollectionType + { + /// + /// Неопределено + /// + None = 0, + /// + /// Массив + /// + Massive = 1, + /// + /// Список + /// + List = 2 + } +} diff --git a/ProjectTank/ProjectTank/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectTank/ProjectTank/CollectionGenericObjects/ICollectionGenericObjects.cs index 8ff883f..2bb8a14 100644 --- a/ProjectTank/ProjectTank/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/ProjectTank/ProjectTank/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -11,16 +11,19 @@ /// Количество объектов в коллекции /// int Count { get; } + /// /// Установка максимального количества элементов /// int SetMaxCount { set; } + /// /// Добавление объекта в коллекцию /// /// Добавляемый объект /// true - вставка прошла удачно, false - вставка не удалась int Insert(T obj); + /// /// Добавление объекта в коллекцию на конкретную позицию /// @@ -28,12 +31,14 @@ /// Позиция /// true - вставка прошла удачно, false - вставка не удалась int Insert(T obj, int position); + /// /// Удаление объекта из коллекции с конкретной позиции /// /// Позиция /// true - удаление прошло удачно, false - удаление не удалось T? Remove(int position); + /// /// Получение объекта по позиции /// diff --git a/ProjectTank/ProjectTank/CollectionGenericObjects/ListGenericObjects.cs b/ProjectTank/ProjectTank/CollectionGenericObjects/ListGenericObjects.cs new file mode 100644 index 0000000..ea07c15 --- /dev/null +++ b/ProjectTank/ProjectTank/CollectionGenericObjects/ListGenericObjects.cs @@ -0,0 +1,65 @@ +namespace ProjectTank.CollectionGenericObjects +{ + /// + /// Параметризованный набор объектов + /// + /// Параметр: ограничение - ссылочный тип + public class ListGenericObjects : ICollectionGenericObjects + where T : class + { + /// + /// Список объектов, которые храним + /// + private readonly List _collection; + /// + /// Максимально допустимое число объектов в списке + /// + private int _maxCount; + public int Count => _collection.Count; + public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } } + /// + /// Конструктор + /// + public ListGenericObjects() + { + _collection = new(); + } + public T? Get(int position) + { + // TODO проверка позиции + if (position >= Count || position < 0) return null; + return _collection[position]; + } + + public int Insert(T obj) + { + // TODO проверка, что не превышено максимальное количество элементов + // TODO вставка в конец набора + if (Count == _maxCount) return -1; + _collection.Add(obj); + return Count; + } + + public int Insert(T obj, int position) + { + // TODO проверка, что не превышено максимальное количество элементов + // TODO проверка позиции + // TODO вставка по позиции + if (Count == _maxCount) return -1; + if (position >= Count || position < 0) return -1; + _collection.Insert(position, obj); + return position; + + } + + public T Remove(int position) + { + // TODO проверка позиции + // TODO удаление объекта из списка + if (position >= Count || position < 0) return null; + T obj = _collection[position]; + _collection.RemoveAt(position); + return obj; + } + } +} diff --git a/ProjectTank/ProjectTank/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectTank/ProjectTank/CollectionGenericObjects/MassiveGenericObjects.cs index 0da45f0..bf556ae 100644 --- a/ProjectTank/ProjectTank/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/ProjectTank/ProjectTank/CollectionGenericObjects/MassiveGenericObjects.cs @@ -14,7 +14,23 @@ namespace ProjectTank.CollectionGenericObjects /// private T?[] _collection; public int Count => _collection.Length; - public int SetMaxCount { set { if (value > 0) { _collection = new T?[value]; } } } + public int SetMaxCount + { + set + { + if (value > 0) + { + if (_collection.Length > 0) + { + Array.Resize(ref _collection, value); + } + else + { + _collection = new T?[value]; + } + } + } + } /// /// Конструктор @@ -27,11 +43,10 @@ namespace ProjectTank.CollectionGenericObjects { // TODO проверка позиции if (position >= _collection.Length || position < 0) - { - return null; - } + { return null; } return _collection[position]; } + public int Insert(T obj) { // TODO вставка в свободное место набора @@ -43,16 +58,18 @@ namespace ProjectTank.CollectionGenericObjects _collection[index] = obj; return index; } + index++; } return -1; } + public int Insert(T obj, int position) { // TODO проверка позиции // TODO проверка, что элемент массива по этой позиции пустой, если нет, то - // ищется свободное место после этой позиции и идет вставка туда - // если нет после, ищем до + // ищется свободное место после этой позиции и идет вставка туда + // если нет после, ищем до // TODO вставка if (position >= _collection.Length || position < 0) { return -1; } @@ -83,15 +100,16 @@ namespace ProjectTank.CollectionGenericObjects } return -1; } + public T Remove(int position) { // TODO проверка позиции // TODO удаление объекта из массива, присвоив элементу массива значение null if (position >= _collection.Length || position < 0) { return null; } - T drawningTank = _collection[position]; + T obj = _collection[position]; _collection[position] = null; - return drawningTank; + return obj; } } } diff --git a/ProjectTank/ProjectTank/CollectionGenericObjects/StorageCollection.cs b/ProjectTank/ProjectTank/CollectionGenericObjects/StorageCollection.cs new file mode 100644 index 0000000..da58c7a --- /dev/null +++ b/ProjectTank/ProjectTank/CollectionGenericObjects/StorageCollection.cs @@ -0,0 +1,73 @@ +namespace ProjectTank.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) + { + // TODO проверка, что name не пустой и нет в словаре записи с таким ключом + // TODO Прописать логику для добавления + + if (_storages.ContainsKey(name)) return; + + if (collectionType == CollectionType.None) return; + else if (collectionType == CollectionType.Massive) + _storages[name] = new MassiveGenericObjects(); + else if (collectionType == CollectionType.List) + _storages[name] = new ListGenericObjects(); + } + + /// + /// Удаление коллекции + /// + /// Название коллекции + public void DelCollection(string name) + { + // TODO Прописать логику для удаления коллекции + if (_storages.ContainsKey(name)) + _storages.Remove(name); + } + + /// + /// Доступ к коллекции + /// + /// Название коллекции + /// + public ICollectionGenericObjects? this[string name] + { + get + { + // TODO Продумать логику получения объекта + if (_storages.ContainsKey(name)) + return _storages[name]; + return null; + } + } + } +} diff --git a/ProjectTank/ProjectTank/CollectionGenericObjects/TankDockingService.cs b/ProjectTank/ProjectTank/CollectionGenericObjects/TankDockingService.cs index 02580c5..c6b6729 100644 --- a/ProjectTank/ProjectTank/CollectionGenericObjects/TankDockingService.cs +++ b/ProjectTank/ProjectTank/CollectionGenericObjects/TankDockingService.cs @@ -22,7 +22,7 @@ namespace ProjectTank.CollectionGenericObjects int width = _pictureWidth / _placeSizeWidth; int height = _pictureHeight / _placeSizeHeight; Pen pen = new(Color.Black, 2); - for (int i = 0; i < width; i++) + for (int i = 0; i < width + 1; i++) { for (int j = 0; j < height + 1; ++j) { @@ -47,7 +47,7 @@ namespace ProjectTank.CollectionGenericObjects _collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 10, curHeight * _placeSizeHeight + 10); } - if (curWidth < width - 1) + if (curWidth < width ) curWidth++; else { diff --git a/ProjectTank/ProjectTank/FormTanksCollection.Designer.cs b/ProjectTank/ProjectTank/FormTanksCollection.Designer.cs index 8d4f6a7..18d1f92 100644 --- a/ProjectTank/ProjectTank/FormTanksCollection.Designer.cs +++ b/ProjectTank/ProjectTank/FormTanksCollection.Designer.cs @@ -29,75 +29,214 @@ private void InitializeComponent() { groupBoxTools = new GroupBox(); - maskedTextBoxPosision = new MaskedTextBox(); - buttonRefresh = new Button(); - buttonGetToTest = new Button(); - ButtonRemoveTank = new Button(); - ButtonAddMilitaryTank = new Button(); - ButtonAddTank = new Button(); + buttonCreateCompany = new Button(); + panelStorage = new Panel(); + buttonCollectionDel = new Button(); + listBoxCollection = new ListBox(); + buttonCollecctionAdd = new Button(); + radioButtonList = new RadioButton(); + radioButtonMassive = new RadioButton(); + textBoxCollectionName = new TextBox(); + labelCollectionName = new Label(); comboBoxSelectorCompany = new ComboBox(); + panelCompanyTools = new Panel(); + ButtonAddTank = new Button(); + ButtonAddMilitaryTank = new Button(); + buttonRefresh = new Button(); + ButtonRemoveTank = new Button(); + maskedTextBoxPosision = new MaskedTextBox(); + buttonGetToTest = new Button(); pictureBoxTank = new PictureBox(); groupBoxTools.SuspendLayout(); + panelStorage.SuspendLayout(); + panelCompanyTools.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBoxTank).BeginInit(); SuspendLayout(); // // groupBoxTools // - groupBoxTools.Controls.Add(maskedTextBoxPosision); - groupBoxTools.Controls.Add(buttonRefresh); - groupBoxTools.Controls.Add(buttonGetToTest); - groupBoxTools.Controls.Add(ButtonRemoveTank); - groupBoxTools.Controls.Add(ButtonAddMilitaryTank); - groupBoxTools.Controls.Add(ButtonAddTank); + groupBoxTools.Controls.Add(buttonCreateCompany); + groupBoxTools.Controls.Add(panelStorage); groupBoxTools.Controls.Add(comboBoxSelectorCompany); + groupBoxTools.Controls.Add(panelCompanyTools); groupBoxTools.Dock = DockStyle.Right; - groupBoxTools.Location = new Point(522, 0); + groupBoxTools.Location = new Point(538, 0); groupBoxTools.Margin = new Padding(3, 2, 3, 2); groupBoxTools.Name = "groupBoxTools"; groupBoxTools.Padding = new Padding(3, 2, 3, 2); - groupBoxTools.Size = new Size(194, 430); + groupBoxTools.Size = new Size(187, 490); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "инструменты"; // - // maskedTextBoxPosision + // buttonCreateCompany // - maskedTextBoxPosision.Location = new Point(18, 172); - maskedTextBoxPosision.Margin = new Padding(3, 2, 3, 2); - maskedTextBoxPosision.Mask = "00"; - maskedTextBoxPosision.Name = "maskedTextBoxPosision"; - maskedTextBoxPosision.Size = new Size(163, 23); - maskedTextBoxPosision.TabIndex = 2; - maskedTextBoxPosision.ValidatingType = typeof(int); + buttonCreateCompany.Location = new Point(18, 259); + buttonCreateCompany.Margin = new Padding(3, 2, 3, 2); + buttonCreateCompany.Name = "buttonCreateCompany"; + buttonCreateCompany.Size = new Size(163, 20); + buttonCreateCompany.TabIndex = 7; + buttonCreateCompany.Text = "Создать компанию"; + buttonCreateCompany.UseVisualStyleBackColor = true; + buttonCreateCompany.Click += ButtonCreateCompany_Click; + // + // panelStorage + // + panelStorage.Controls.Add(buttonCollectionDel); + panelStorage.Controls.Add(listBoxCollection); + panelStorage.Controls.Add(buttonCollecctionAdd); + 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, 18); + panelStorage.Margin = new Padding(3, 2, 3, 2); + panelStorage.Name = "panelStorage"; + panelStorage.Size = new Size(181, 212); + panelStorage.TabIndex = 6; + // + // buttonCollectionDel + // + buttonCollectionDel.Location = new Point(15, 185); + buttonCollectionDel.Margin = new Padding(3, 2, 3, 2); + buttonCollectionDel.Name = "buttonCollectionDel"; + buttonCollectionDel.Size = new Size(163, 20); + buttonCollectionDel.TabIndex = 6; + buttonCollectionDel.Text = "Удалить коллекцию"; + buttonCollectionDel.UseVisualStyleBackColor = true; + buttonCollectionDel.Click += ButtonCollectionDel_Click; + // + // listBoxCollection + // + listBoxCollection.FormattingEnabled = true; + listBoxCollection.ItemHeight = 15; + listBoxCollection.Location = new Point(15, 103); + listBoxCollection.Margin = new Padding(3, 2, 3, 2); + listBoxCollection.Name = "listBoxCollection"; + listBoxCollection.Size = new Size(163, 79); + listBoxCollection.TabIndex = 5; + // + // buttonCollecctionAdd + // + buttonCollecctionAdd.Location = new Point(15, 78); + buttonCollecctionAdd.Margin = new Padding(3, 2, 3, 2); + buttonCollecctionAdd.Name = "buttonCollecctionAdd"; + buttonCollecctionAdd.Size = new Size(163, 20); + buttonCollecctionAdd.TabIndex = 4; + buttonCollecctionAdd.Text = "Добавить коллекцию"; + buttonCollecctionAdd.UseVisualStyleBackColor = true; + buttonCollecctionAdd.Click += ButtonCollecctionAdd_Click; + // + // radioButtonList + // + radioButtonList.AutoSize = true; + radioButtonList.Location = new Point(108, 56); + radioButtonList.Margin = new Padding(3, 2, 3, 2); + 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(15, 56); + radioButtonMassive.Margin = new Padding(3, 2, 3, 2); + 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(15, 24); + textBoxCollectionName.Margin = new Padding(3, 2, 3, 2); + textBoxCollectionName.Name = "textBoxCollectionName"; + textBoxCollectionName.Size = new Size(163, 23); + textBoxCollectionName.TabIndex = 1; + // + // labelCollectionName + // + labelCollectionName.AutoSize = true; + labelCollectionName.Location = new Point(23, 7); + labelCollectionName.Name = "labelCollectionName"; + labelCollectionName.Size = new Size(122, 15); + labelCollectionName.TabIndex = 0; + labelCollectionName.Text = "Название коллекции"; + // + // comboBoxSelectorCompany + // + comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxSelectorCompany.FormattingEnabled = true; + comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); + comboBoxSelectorCompany.Location = new Point(18, 233); + comboBoxSelectorCompany.Margin = new Padding(3, 2, 3, 2); + comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; + comboBoxSelectorCompany.Size = new Size(163, 23); + comboBoxSelectorCompany.TabIndex = 0; + comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged_1; + // + // panelCompanyTools + // + panelCompanyTools.Controls.Add(ButtonAddTank); + panelCompanyTools.Controls.Add(ButtonAddMilitaryTank); + panelCompanyTools.Controls.Add(buttonRefresh); + panelCompanyTools.Controls.Add(ButtonRemoveTank); + panelCompanyTools.Controls.Add(maskedTextBoxPosision); + panelCompanyTools.Controls.Add(buttonGetToTest); + panelCompanyTools.Enabled = false; + panelCompanyTools.Location = new Point(3, 284); + panelCompanyTools.Margin = new Padding(3, 2, 3, 2); + panelCompanyTools.Name = "panelCompanyTools"; + panelCompanyTools.Size = new Size(189, 206); + panelCompanyTools.TabIndex = 8; + // + // ButtonAddTank + // + ButtonAddTank.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + ButtonAddTank.BackgroundImageLayout = ImageLayout.Center; + ButtonAddTank.Location = new Point(16, 2); + ButtonAddTank.Margin = new Padding(3, 2, 3, 2); + ButtonAddTank.Name = "ButtonAddTank"; + ButtonAddTank.Size = new Size(163, 30); + ButtonAddTank.TabIndex = 1; + ButtonAddTank.Text = "добваление танка"; + ButtonAddTank.UseVisualStyleBackColor = true; + ButtonAddTank.Click += ButtonAddTank_Click; + // + // ButtonAddMilitaryTank + // + ButtonAddMilitaryTank.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + ButtonAddMilitaryTank.Location = new Point(16, 37); + ButtonAddMilitaryTank.Margin = new Padding(3, 2, 3, 2); + ButtonAddMilitaryTank.Name = "ButtonAddMilitaryTank"; + ButtonAddMilitaryTank.Size = new Size(163, 38); + ButtonAddMilitaryTank.TabIndex = 2; + ButtonAddMilitaryTank.Text = "добваление военного танка"; + ButtonAddMilitaryTank.UseVisualStyleBackColor = true; + ButtonAddMilitaryTank.Click += ButtonAddMilitaryTank_Click; // // buttonRefresh // buttonRefresh.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonRefresh.Location = new Point(18, 359); + buttonRefresh.Location = new Point(16, 170); buttonRefresh.Margin = new Padding(3, 2, 3, 2); buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(163, 30); + buttonRefresh.Size = new Size(163, 31); buttonRefresh.TabIndex = 5; buttonRefresh.Text = "обновить"; buttonRefresh.UseVisualStyleBackColor = true; buttonRefresh.Click += ButtonRefresh_Click; // - // buttonGetToTest - // - buttonGetToTest.Anchor = AnchorStyles.Right; - buttonGetToTest.Location = new Point(18, 274); - buttonGetToTest.Margin = new Padding(3, 2, 3, 2); - buttonGetToTest.Name = "buttonGetToTest"; - buttonGetToTest.Size = new Size(163, 30); - buttonGetToTest.TabIndex = 4; - buttonGetToTest.Text = "передать на тесты"; - buttonGetToTest.UseVisualStyleBackColor = true; - buttonGetToTest.Click += ButtonGetToTest_Click; - // // ButtonRemoveTank // ButtonRemoveTank.Anchor = AnchorStyles.Right; - ButtonRemoveTank.Location = new Point(18, 203); + ButtonRemoveTank.Location = new Point(16, 104); ButtonRemoveTank.Margin = new Padding(3, 2, 3, 2); ButtonRemoveTank.Name = "ButtonRemoveTank"; ButtonRemoveTank.Size = new Size(163, 30); @@ -106,42 +245,27 @@ ButtonRemoveTank.UseVisualStyleBackColor = true; ButtonRemoveTank.Click += ButtonRemoveTank_Click; // - // ButtonAddMilitaryTank + // maskedTextBoxPosision // - ButtonAddMilitaryTank.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - ButtonAddMilitaryTank.Location = new Point(18, 114); - ButtonAddMilitaryTank.Margin = new Padding(3, 2, 3, 2); - ButtonAddMilitaryTank.Name = "ButtonAddMilitaryTank"; - ButtonAddMilitaryTank.Size = new Size(163, 38); - ButtonAddMilitaryTank.TabIndex = 2; - ButtonAddMilitaryTank.Text = "добавлене военного танка"; - ButtonAddMilitaryTank.UseVisualStyleBackColor = true; - ButtonAddMilitaryTank.Click += ButtonAddMilitaryTank_Click; + maskedTextBoxPosision.Location = new Point(15, 79); + maskedTextBoxPosision.Margin = new Padding(3, 2, 3, 2); + maskedTextBoxPosision.Mask = "00"; + maskedTextBoxPosision.Name = "maskedTextBoxPosision"; + maskedTextBoxPosision.Size = new Size(164, 23); + maskedTextBoxPosision.TabIndex = 2; + maskedTextBoxPosision.ValidatingType = typeof(int); // - // ButtonAddTank + // buttonGetToTest // - ButtonAddTank.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - ButtonAddTank.BackgroundImageLayout = ImageLayout.Center; - ButtonAddTank.Location = new Point(18, 80); - ButtonAddTank.Margin = new Padding(3, 2, 3, 2); - ButtonAddTank.Name = "ButtonAddTank"; - ButtonAddTank.Size = new Size(163, 30); - ButtonAddTank.TabIndex = 1; - ButtonAddTank.Text = "добваление танк"; - ButtonAddTank.UseVisualStyleBackColor = true; - ButtonAddTank.Click += ButtonAddTank_Click; - // - // comboBoxSelectorCompany - // - comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; - comboBoxSelectorCompany.FormattingEnabled = true; - comboBoxSelectorCompany.Items.AddRange(new object[] { "хранилище" }); - comboBoxSelectorCompany.Location = new Point(18, 20); - comboBoxSelectorCompany.Margin = new Padding(3, 2, 3, 2); - comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; - comboBoxSelectorCompany.Size = new Size(163, 23); - comboBoxSelectorCompany.TabIndex = 0; - comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged_1; + buttonGetToTest.Anchor = AnchorStyles.Right; + buttonGetToTest.Location = new Point(16, 138); + buttonGetToTest.Margin = new Padding(3, 2, 3, 2); + buttonGetToTest.Name = "buttonGetToTest"; + buttonGetToTest.Size = new Size(163, 30); + buttonGetToTest.TabIndex = 4; + buttonGetToTest.Text = "передать на тесты"; + buttonGetToTest.UseVisualStyleBackColor = true; + buttonGetToTest.Click += ButtonGetToTest_Click; // // pictureBoxTank // @@ -149,7 +273,7 @@ pictureBoxTank.Location = new Point(0, 0); pictureBoxTank.Margin = new Padding(3, 2, 3, 2); pictureBoxTank.Name = "pictureBoxTank"; - pictureBoxTank.Size = new Size(522, 430); + pictureBoxTank.Size = new Size(538, 490); pictureBoxTank.TabIndex = 1; pictureBoxTank.TabStop = false; // @@ -157,14 +281,17 @@ // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(716, 430); + ClientSize = new Size(725, 490); Controls.Add(pictureBoxTank); Controls.Add(groupBoxTools); Margin = new Padding(3, 2, 3, 2); Name = "FormTanksCollection"; Text = "FormTanksCollection"; groupBoxTools.ResumeLayout(false); - groupBoxTools.PerformLayout(); + panelStorage.ResumeLayout(false); + panelStorage.PerformLayout(); + panelCompanyTools.ResumeLayout(false); + panelCompanyTools.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBoxTank).EndInit(); ResumeLayout(false); } @@ -180,5 +307,15 @@ private Button buttonGetToTest; private PictureBox pictureBoxTank; private MaskedTextBox maskedTextBoxPosision; + private Panel panelStorage; + private TextBox textBoxCollectionName; + private Label labelCollectionName; + private ListBox listBoxCollection; + private Button buttonCollecctionAdd; + private RadioButton radioButtonList; + private RadioButton radioButtonMassive; + private Button buttonCreateCompany; + private Button buttonCollectionDel; + private Panel panelCompanyTools; } } \ No newline at end of file diff --git a/ProjectTank/ProjectTank/FormTanksCollection.cs b/ProjectTank/ProjectTank/FormTanksCollection.cs index 52a91f2..9bc035b 100644 --- a/ProjectTank/ProjectTank/FormTanksCollection.cs +++ b/ProjectTank/ProjectTank/FormTanksCollection.cs @@ -5,16 +5,23 @@ namespace ProjectTank { public partial class FormTanksCollection : Form { + /// + /// Хранилише коллекций + /// + private readonly StorageCollection _storageCollection; + /// /// Компания /// private AbstractCompany? _company = null; + /// /// Конструктор /// public FormTanksCollection() { InitializeComponent(); + _storageCollection = new(); } /// @@ -24,13 +31,7 @@ namespace ProjectTank /// private void comboBoxSelectorCompany_SelectedIndexChanged_1(object sender, EventArgs e) { - switch (comboBoxSelectorCompany.Text) - { - case "хранилище": - _company = new TankDockingService(pictureBoxTank.Width, - pictureBoxTank.Height, new MassiveGenericObjects()); - break; - } + panelCompanyTools.Enabled = false; } /// @@ -51,23 +52,22 @@ namespace ProjectTank drawningTank = new DrawningTank(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); break; case nameof(DrawningMilitaryTank): + // TODO вызов диалогового окна для выбора цвета drawningTank = new DrawningMilitaryTank(random.Next(100, 300), random.Next(1000, 3000), - GetColor(random), - GetColor(random), - Convert.ToBoolean(random.Next(0, 2)), - Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); + GetColor(random), GetColor(random), + Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); break; default: return; } if (_company + drawningTank != -1) { - MessageBox.Show("объект добавлен"); + MessageBox.Show("Объект добавлен"); pictureBoxTank.Image = _company.Show(); } else { - MessageBox.Show("не удалось добавить объект"); + MessageBox.Show("Не удалось добавить объект"); } } @@ -164,6 +164,97 @@ namespace ProjectTank pictureBoxTank.Image = _company.Show(); } + /// + /// Добавление коллекции + /// + /// + /// + private void ButtonCollecctionAdd_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); + RerfreshListBoxItems(); + } + + /// + /// Удаленние коллекции + /// + /// + /// + private void ButtonCollectionDel_Click(object sender, EventArgs e) + { + if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null) + { + MessageBox.Show("Коллекция не выбрана"); + return; + } + if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + { + return; + } + _storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString()); + RerfreshListBoxItems(); + } + + /// + /// Обновление списка в listBoxCollection + /// + private void RerfreshListBoxItems() + { + 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 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 TankDockingService(pictureBoxTank.Width, pictureBoxTank.Height, collection); + break; + } + panelCompanyTools.Enabled = true; + + } + } }