diff --git a/AntiAircraftGun/CollectionGenericObjects/CollectionType.cs b/AntiAircraftGun/CollectionGenericObjects/CollectionType.cs new file mode 100644 index 0000000..b5215af --- /dev/null +++ b/AntiAircraftGun/CollectionGenericObjects/CollectionType.cs @@ -0,0 +1,21 @@ +namespace AntiAircraftGun.CollectionGenericObjects; +/// +/// Тип коллекции +/// +public enum CollectionType +{ + /// + /// Неопределено + /// + None = 0, + + /// + /// Массив + /// + Massive = 1, + + /// + /// Список + /// + List = 2 +} diff --git a/AntiAircraftGun/CollectionGenericObjects/ListGenericObjects.cs b/AntiAircraftGun/CollectionGenericObjects/ListGenericObjects.cs new file mode 100644 index 0000000..f4a497b --- /dev/null +++ b/AntiAircraftGun/CollectionGenericObjects/ListGenericObjects.cs @@ -0,0 +1,61 @@ +using AntiAircraftGun.CollectionGenereticObject; + +namespace AntiAircraftGun.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) + { + if (position >= Count || position < 0) return null; + return _collection[position]; + } + + public int Insert(T obj) + { + if (Count == _maxCount) return -1; + _collection.Add(obj); + return Count; + } + + public int Insert(T obj, int position) + { + if (Count == _maxCount) return -1; + if (position >= Count || position < 0) return -1; + _collection.Insert(position, obj); + return position; + } + + public T Remove(int position) + { + if (position >= _collection.Count || position < 0) return null; + T obj = _collection[position]; + _collection.RemoveAt(position); + return obj; + } +} diff --git a/AntiAircraftGun/CollectionGenericObjects/StorageCollection.cs b/AntiAircraftGun/CollectionGenericObjects/StorageCollection.cs new file mode 100644 index 0000000..286a131 --- /dev/null +++ b/AntiAircraftGun/CollectionGenericObjects/StorageCollection.cs @@ -0,0 +1,70 @@ +using AntiAircraftGun.CollectionGenereticObject; + +namespace AntiAircraftGun.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 (_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) + { + 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/AntiAircraftGun/FormArmoredCarCollection.Designer.cs b/AntiAircraftGun/FormArmoredCarCollection.Designer.cs index c369d4c..8ef3957 100644 --- a/AntiAircraftGun/FormArmoredCarCollection.Designer.cs +++ b/AntiAircraftGun/FormArmoredCarCollection.Designer.cs @@ -29,6 +29,15 @@ private void InitializeComponent() { groupBoxToools = new GroupBox(); + 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(); buttonRefresh = new Button(); buttonGoToChek = new Button(); buttonRemoveArmoredCar = new Button(); @@ -37,18 +46,18 @@ buttonAddArmoredCar = new Button(); comboBoxSelectorCompany = new ComboBox(); pictureBox = new PictureBox(); + panelCompanyTools = new Panel(); groupBoxToools.SuspendLayout(); + panelStorage.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); + panelCompanyTools.SuspendLayout(); SuspendLayout(); // // groupBoxToools // - groupBoxToools.Controls.Add(buttonRefresh); - groupBoxToools.Controls.Add(buttonGoToChek); - groupBoxToools.Controls.Add(buttonRemoveArmoredCar); - groupBoxToools.Controls.Add(maskedTextBox); - groupBoxToools.Controls.Add(buttonAddAntiAircraftGun); - groupBoxToools.Controls.Add(buttonAddArmoredCar); + groupBoxToools.Controls.Add(panelCompanyTools); + groupBoxToools.Controls.Add(buttonCreateCompany); + groupBoxToools.Controls.Add(panelStorage); groupBoxToools.Controls.Add(comboBoxSelectorCompany); groupBoxToools.Dock = DockStyle.Right; groupBoxToools.Location = new Point(1057, 0); @@ -58,12 +67,104 @@ groupBoxToools.TabStop = false; groupBoxToools.Text = "Инструменты"; // + // buttonCreateCompany + // + buttonCreateCompany.Location = new Point(6, 290); + buttonCreateCompany.Name = "buttonCreateCompany"; + buttonCreateCompany.Size = new Size(198, 23); + buttonCreateCompany.TabIndex = 7; + 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, 19); + panelStorage.Name = "panelStorage"; + panelStorage.Size = new Size(204, 258); + panelStorage.TabIndex = 7; + // + // buttonCollectionDel + // + buttonCollectionDel.Location = new Point(3, 228); + buttonCollectionDel.Name = "buttonCollectionDel"; + buttonCollectionDel.Size = new Size(198, 23); + buttonCollectionDel.TabIndex = 6; + buttonCollectionDel.Text = "Удалить коллекцию"; + buttonCollectionDel.UseVisualStyleBackColor = true; + buttonCollectionDel.Click += buttonCollectionDel_Click; + // + // listBoxCollection + // + listBoxCollection.FormattingEnabled = true; + listBoxCollection.ItemHeight = 15; + listBoxCollection.Location = new Point(3, 113); + listBoxCollection.Name = "listBoxCollection"; + listBoxCollection.Size = new Size(198, 109); + listBoxCollection.TabIndex = 5; + // + // buttonCollectionAdd + // + buttonCollectionAdd.Location = new Point(3, 84); + buttonCollectionAdd.Name = "buttonCollectionAdd"; + buttonCollectionAdd.Size = new Size(198, 23); + buttonCollectionAdd.TabIndex = 4; + buttonCollectionAdd.Text = "Добавить коллекцию"; + buttonCollectionAdd.UseVisualStyleBackColor = true; + buttonCollectionAdd.Click += buttonCollectionAdd_Click; + // + // radioButtonList + // + radioButtonList.AutoSize = true; + radioButtonList.Location = new Point(115, 59); + 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, 59); + 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, 30); + textBoxCollectionName.Name = "textBoxCollectionName"; + textBoxCollectionName.Size = new Size(198, 23); + textBoxCollectionName.TabIndex = 1; + // + // labelCollectionName + // + labelCollectionName.AutoSize = true; + labelCollectionName.Location = new Point(39, 12); + labelCollectionName.Name = "labelCollectionName"; + labelCollectionName.Size = new Size(125, 15); + labelCollectionName.TabIndex = 0; + labelCollectionName.Text = "Название коллекции:"; + // // buttonRefresh // buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRefresh.Location = new Point(6, 527); + buttonRefresh.Location = new Point(6, 216); buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(198, 39); + buttonRefresh.Size = new Size(191, 39); buttonRefresh.TabIndex = 6; buttonRefresh.Text = "Обновить"; buttonRefresh.UseVisualStyleBackColor = true; @@ -72,9 +173,9 @@ // buttonGoToChek // buttonGoToChek.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonGoToChek.Location = new Point(6, 482); + buttonGoToChek.Location = new Point(6, 171); buttonGoToChek.Name = "buttonGoToChek"; - buttonGoToChek.Size = new Size(198, 39); + buttonGoToChek.Size = new Size(191, 39); buttonGoToChek.TabIndex = 5; buttonGoToChek.Text = "Передать на тесты"; buttonGoToChek.UseVisualStyleBackColor = true; @@ -83,9 +184,9 @@ // buttonRemoveArmoredCar // buttonRemoveArmoredCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRemoveArmoredCar.Location = new Point(6, 302); + buttonRemoveArmoredCar.Location = new Point(6, 123); buttonRemoveArmoredCar.Name = "buttonRemoveArmoredCar"; - buttonRemoveArmoredCar.Size = new Size(198, 60); + buttonRemoveArmoredCar.Size = new Size(191, 44); buttonRemoveArmoredCar.TabIndex = 4; buttonRemoveArmoredCar.Text = "Удалить бронемашину"; buttonRemoveArmoredCar.UseVisualStyleBackColor = true; @@ -93,19 +194,19 @@ // // maskedTextBox // - maskedTextBox.Location = new Point(6, 249); + maskedTextBox.Location = new Point(6, 94); maskedTextBox.Mask = "00"; maskedTextBox.Name = "maskedTextBox"; - maskedTextBox.Size = new Size(198, 23); + maskedTextBox.Size = new Size(194, 23); maskedTextBox.TabIndex = 3; maskedTextBox.ValidatingType = typeof(int); // // buttonAddAntiAircraftGun // buttonAddAntiAircraftGun.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddAntiAircraftGun.Location = new Point(6, 164); + buttonAddAntiAircraftGun.Location = new Point(6, 42); buttonAddAntiAircraftGun.Name = "buttonAddAntiAircraftGun"; - buttonAddAntiAircraftGun.Size = new Size(198, 60); + buttonAddAntiAircraftGun.Size = new Size(191, 46); buttonAddAntiAircraftGun.TabIndex = 2; buttonAddAntiAircraftGun.Text = "Добавление зениитной установки"; buttonAddAntiAircraftGun.UseVisualStyleBackColor = true; @@ -114,9 +215,9 @@ // buttonAddArmoredCar // buttonAddArmoredCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddArmoredCar.Location = new Point(6, 86); + buttonAddArmoredCar.Location = new Point(6, 3); buttonAddArmoredCar.Name = "buttonAddArmoredCar"; - buttonAddArmoredCar.Size = new Size(198, 60); + buttonAddArmoredCar.Size = new Size(191, 40); buttonAddArmoredCar.TabIndex = 1; buttonAddArmoredCar.Text = "Добавление бронемашины"; buttonAddArmoredCar.UseVisualStyleBackColor = true; @@ -128,7 +229,7 @@ comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxSelectorCompany.FormattingEnabled = true; comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); - comboBoxSelectorCompany.Location = new Point(6, 22); + comboBoxSelectorCompany.Location = new Point(6, 319); comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; comboBoxSelectorCompany.Size = new Size(198, 23); comboBoxSelectorCompany.TabIndex = 0; @@ -143,6 +244,20 @@ pictureBox.TabIndex = 1; pictureBox.TabStop = false; // + // panelCompanyTools + // + panelCompanyTools.Controls.Add(buttonAddAntiAircraftGun); + panelCompanyTools.Controls.Add(buttonAddArmoredCar); + panelCompanyTools.Controls.Add(maskedTextBox); + panelCompanyTools.Controls.Add(buttonRefresh); + panelCompanyTools.Controls.Add(buttonRemoveArmoredCar); + panelCompanyTools.Controls.Add(buttonGoToChek); + panelCompanyTools.Enabled = false; + panelCompanyTools.Location = new Point(6, 348); + panelCompanyTools.Name = "panelCompanyTools"; + panelCompanyTools.Size = new Size(200, 261); + panelCompanyTools.TabIndex = 8; + // // FormArmoredCarCollection // AutoScaleDimensions = new SizeF(7F, 15F); @@ -153,8 +268,11 @@ Name = "FormArmoredCarCollection"; Text = "Коллекция бронемашин"; groupBoxToools.ResumeLayout(false); - groupBoxToools.PerformLayout(); + panelStorage.ResumeLayout(false); + panelStorage.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + panelCompanyTools.ResumeLayout(false); + panelCompanyTools.PerformLayout(); ResumeLayout(false); } @@ -169,5 +287,15 @@ private MaskedTextBox maskedTextBox; private Button buttonRefresh; private Button buttonGoToChek; + private Panel panelStorage; + private Label labelCollectionName; + private TextBox textBoxCollectionName; + private RadioButton radioButtonMassive; + private RadioButton radioButtonList; + private Button buttonCollectionAdd; + private Button buttonCollectionDel; + private ListBox listBoxCollection; + private Button buttonCreateCompany; + private Panel panelCompanyTools; } } \ No newline at end of file diff --git a/AntiAircraftGun/FormArmoredCarCollection.cs b/AntiAircraftGun/FormArmoredCarCollection.cs index 5dd8927..c6f245e 100644 --- a/AntiAircraftGun/FormArmoredCarCollection.cs +++ b/AntiAircraftGun/FormArmoredCarCollection.cs @@ -1,5 +1,6 @@ using AntiAircraftGun.CollectionGenereticObject; using AntiAircraftGun.CollectionGenereticObjects; +using AntiAircraftGun.CollectionGenericObjects; using AntiAircraftGun.Drawnings; @@ -9,6 +10,10 @@ namespace AntiAircraftGun; /// public partial class FormArmoredCarCollection : Form { + /// + /// Хранилише коллекций + /// + private readonly StorageCollection _storageCollection; /// /// Компания /// @@ -20,6 +25,7 @@ public partial class FormArmoredCarCollection : Form public FormArmoredCarCollection() { InitializeComponent(); + _storageCollection = new(); } /// @@ -29,12 +35,7 @@ public partial class FormArmoredCarCollection : Form /// private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) { - switch (comboBoxSelectorCompany.Text) - { - case "Хранилище": - _company = new CarBase(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); - break; - } + panelCompanyTools.Enabled = false; } /// @@ -185,6 +186,97 @@ public partial class FormArmoredCarCollection : Form form.ShowDialog(); } + /// + /// Обновление списка в 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 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); + 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(); + } + /// + /// Создание комании + /// + /// + /// + 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 CarBase(pictureBox.Width, pictureBox.Height, collection); + break; + } + + panelCompanyTools.Enabled = true; + RerfreshListBoxItems(); + } } +