diff --git a/Excavator/Excavator/CollectionGenericObjects/CollectionType.cs b/Excavator/Excavator/CollectionGenericObjects/CollectionType.cs new file mode 100644 index 0000000..713eebb --- /dev/null +++ b/Excavator/Excavator/CollectionGenericObjects/CollectionType.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Excavator.CollectionGenericObjects; + +public enum CollectionType +{ + /// + /// Неопределено + /// + None = 0, + + /// + /// Массив + /// + Massive = 1, + + /// + /// Список + /// + List = 2 +} \ No newline at end of file diff --git a/Excavator/Excavator/CollectionGenericObjects/Garage.cs b/Excavator/Excavator/CollectionGenericObjects/Garage.cs index 6b35061..273f98b 100644 --- a/Excavator/Excavator/CollectionGenericObjects/Garage.cs +++ b/Excavator/Excavator/CollectionGenericObjects/Garage.cs @@ -7,6 +7,7 @@ namespace Excavator.CollectionGenericObjects; /// public class Garage : AbstractCompany { + /// /// Конструктор /// diff --git a/Excavator/Excavator/CollectionGenericObjects/ListGenericObjects.cs b/Excavator/Excavator/CollectionGenericObjects/ListGenericObjects.cs new file mode 100644 index 0000000..b2ea060 --- /dev/null +++ b/Excavator/Excavator/CollectionGenericObjects/ListGenericObjects.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Excavator.CollectionGenericObjects; + +public class ListGenericObjects : ICollectionGenericObjects + where T : class +{ + /// + /// Список объектов, которые храним + /// + private readonly List _collection; + + /// + /// Максимально допустимое число объектов в списке + /// + public 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 >= Count || position < 0) return null; + T temp = _collection[position]; + _collection.RemoveAt(position); + return temp; + } +} diff --git a/Excavator/Excavator/CollectionGenericObjects/StorageCollection.cs b/Excavator/Excavator/CollectionGenericObjects/StorageCollection.cs new file mode 100644 index 0000000..99091de --- /dev/null +++ b/Excavator/Excavator/CollectionGenericObjects/StorageCollection.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Excavator.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 (name == null || _storages.ContainsKey(name)) + return; + switch (collectionType) + { + case CollectionType.None: + return; + case CollectionType.Massive: + _storages[name] = new MassiveGenericObjects(); + return; + case CollectionType.List: + _storages[name] = new ListGenericObjects(); + return; + default: break; + } + } + + /// + /// Удаление коллекции + /// + /// Название коллекции + 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; + } + } +} \ No newline at end of file diff --git a/Excavator/Excavator/FormExcavatorCollection.Designer.cs b/Excavator/Excavator/FormExcavatorCollection.Designer.cs index 2314178..d5e5a1d 100644 --- a/Excavator/Excavator/FormExcavatorCollection.Designer.cs +++ b/Excavator/Excavator/FormExcavatorCollection.Designer.cs @@ -29,28 +29,37 @@ private void InitializeComponent() { groupBoxTools = new GroupBox(); - buttonRefresh = new Button(); - buttonGoToCheck = new Button(); - buttonRemoveExcavator = new Button(); - maskedTextBoxPosition = new MaskedTextBox(); - buttonAddExcavator = new Button(); - buttonAddSimpleExcavator = new Button(); + buttonCreateCompany = new Button(); + panelStorage = new Panel(); + buttonCollectionDel = new Button(); + listBoxCollection = new ListBox(); + buttonCollectionAdd = new Button(); + radioButtonList = new RadioButton(); + radioButtonMassive = new RadioButton(); + labelCollectionName = new Label(); + textBoxCollectionName = new TextBox(); comboBoxSelectorCompany = new ComboBox(); + panelCompanyTools = new Panel(); + buttonGoToCheck = new Button(); + buttonAddSimpleExcavator = new Button(); + buttonAddExcavator = new Button(); + maskedTextBoxPosition = new MaskedTextBox(); + buttonRemoveExcavator = new Button(); + buttonRefresh = new Button(); pictureBox = new PictureBox(); groupBoxTools.SuspendLayout(); + panelStorage.SuspendLayout(); + panelCompanyTools.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); SuspendLayout(); // // groupBoxTools // groupBoxTools.Anchor = AnchorStyles.Right; - groupBoxTools.Controls.Add(buttonRefresh); - groupBoxTools.Controls.Add(buttonGoToCheck); - groupBoxTools.Controls.Add(buttonRemoveExcavator); - groupBoxTools.Controls.Add(maskedTextBoxPosition); - groupBoxTools.Controls.Add(buttonAddExcavator); - groupBoxTools.Controls.Add(buttonAddSimpleExcavator); + groupBoxTools.Controls.Add(buttonCreateCompany); + groupBoxTools.Controls.Add(panelStorage); groupBoxTools.Controls.Add(comboBoxSelectorCompany); + groupBoxTools.Controls.Add(panelCompanyTools); groupBoxTools.Font = new Font("Microsoft Sans Serif", 8.25F, FontStyle.Regular, GraphicsUnit.Point); groupBoxTools.Location = new Point(855, 1); groupBoxTools.Name = "groupBoxTools"; @@ -59,64 +68,97 @@ groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; // - // buttonRefresh + // buttonCreateCompany // - buttonRefresh.Location = new Point(6, 473); - buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(200, 49); - buttonRefresh.TabIndex = 6; - buttonRefresh.Text = "Обновить"; - buttonRefresh.UseVisualStyleBackColor = true; - buttonRefresh.Click += ButtonRefresh_Click; + buttonCreateCompany.Location = new Point(9, 325); + buttonCreateCompany.Name = "buttonCreateCompany"; + buttonCreateCompany.Size = new Size(191, 34); + buttonCreateCompany.TabIndex = 7; + buttonCreateCompany.Text = "Создать компанию"; + buttonCreateCompany.UseVisualStyleBackColor = true; + buttonCreateCompany.Click += buttonCreateCompany_Click; // - // buttonGoToCheck + // panelStorage // - buttonGoToCheck.Location = new Point(6, 379); - buttonGoToCheck.Name = "buttonGoToCheck"; - buttonGoToCheck.Size = new Size(200, 49); - buttonGoToCheck.TabIndex = 5; - buttonGoToCheck.Text = "Передать на тесты"; - buttonGoToCheck.UseVisualStyleBackColor = true; - buttonGoToCheck.Click += ButtonGoToCheck_Click; + panelStorage.Controls.Add(buttonCollectionDel); + panelStorage.Controls.Add(listBoxCollection); + panelStorage.Controls.Add(buttonCollectionAdd); + panelStorage.Controls.Add(radioButtonList); + panelStorage.Controls.Add(radioButtonMassive); + panelStorage.Controls.Add(labelCollectionName); + panelStorage.Controls.Add(textBoxCollectionName); + panelStorage.Location = new Point(6, 23); + panelStorage.Name = "panelStorage"; + panelStorage.Size = new Size(200, 269); + panelStorage.TabIndex = 8; // - // buttonRemoveExcavator + // buttonCollectionDel // - buttonRemoveExcavator.Location = new Point(6, 273); - buttonRemoveExcavator.Name = "buttonRemoveExcavator"; - buttonRemoveExcavator.Size = new Size(200, 49); - buttonRemoveExcavator.TabIndex = 4; - buttonRemoveExcavator.Text = "Удалить экскаватор"; - buttonRemoveExcavator.UseVisualStyleBackColor = true; - buttonRemoveExcavator.Click += ButtonRemoveExcavator_Click; + buttonCollectionDel.Location = new Point(6, 231); + buttonCollectionDel.Name = "buttonCollectionDel"; + buttonCollectionDel.Size = new Size(191, 38); + buttonCollectionDel.TabIndex = 6; + buttonCollectionDel.Text = "Удалить коллекцию"; + buttonCollectionDel.UseVisualStyleBackColor = true; + buttonCollectionDel.Click += buttonCollectionDel_Click; // - // maskedTextBoxPosition + // listBoxCollection // - maskedTextBoxPosition.Location = new Point(12, 244); - maskedTextBoxPosition.Mask = "00"; - maskedTextBoxPosition.Name = "maskedTextBoxPosition"; - maskedTextBoxPosition.Size = new Size(194, 20); - maskedTextBoxPosition.TabIndex = 3; + listBoxCollection.FormattingEnabled = true; + listBoxCollection.Location = new Point(6, 121); + listBoxCollection.Name = "listBoxCollection"; + listBoxCollection.Size = new Size(191, 108); + listBoxCollection.TabIndex = 5; // - // buttonAddExcavator + // buttonCollectionAdd // - buttonAddExcavator.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddExcavator.Location = new Point(6, 145); - buttonAddExcavator.Name = "buttonAddExcavator"; - buttonAddExcavator.Size = new Size(200, 52); - buttonAddExcavator.TabIndex = 2; - buttonAddExcavator.Text = "Добавить экскаватор с обвесами"; - buttonAddExcavator.UseVisualStyleBackColor = true; - buttonAddExcavator.Click += ButtonAddExcavator_Click; + buttonCollectionAdd.Location = new Point(6, 72); + buttonCollectionAdd.Name = "buttonCollectionAdd"; + buttonCollectionAdd.Size = new Size(191, 38); + buttonCollectionAdd.TabIndex = 4; + buttonCollectionAdd.Text = "Добавить коллекцию"; + buttonCollectionAdd.UseVisualStyleBackColor = true; + buttonCollectionAdd.Click += buttonCollectionAdd_Click; // - // buttonAddSimpleExcavator + // radioButtonList // - buttonAddSimpleExcavator.Location = new Point(6, 87); - buttonAddSimpleExcavator.Name = "buttonAddSimpleExcavator"; - buttonAddSimpleExcavator.Size = new Size(200, 52); - buttonAddSimpleExcavator.TabIndex = 1; - buttonAddSimpleExcavator.Text = "Добавить экскаватор"; - buttonAddSimpleExcavator.UseVisualStyleBackColor = true; - buttonAddSimpleExcavator.Click += ButtonAddSimleExcavator_Click; + radioButtonList.AutoSize = true; + radioButtonList.Location = new Point(117, 49); + radioButtonList.Name = "radioButtonList"; + radioButtonList.Size = new Size(62, 17); + radioButtonList.TabIndex = 3; + radioButtonList.TabStop = true; + radioButtonList.Text = "Список"; + radioButtonList.UseVisualStyleBackColor = true; + // + // radioButtonMassive + // + radioButtonMassive.AutoSize = true; + radioButtonMassive.Location = new Point(19, 49); + radioButtonMassive.Name = "radioButtonMassive"; + radioButtonMassive.Size = new Size(64, 17); + radioButtonMassive.TabIndex = 2; + radioButtonMassive.TabStop = true; + radioButtonMassive.Text = "Массив"; + radioButtonMassive.UseVisualStyleBackColor = true; + // + // labelCollectionName + // + labelCollectionName.AutoSize = true; + labelCollectionName.Location = new Point(46, 7); + labelCollectionName.Name = "labelCollectionName"; + labelCollectionName.Size = new Size(117, 13); + labelCollectionName.TabIndex = 1; + labelCollectionName.Text = "Название коллекции:"; + labelCollectionName.Click += labelCollectionName_Click; + // + // textBoxCollectionName + // + textBoxCollectionName.Location = new Point(6, 23); + textBoxCollectionName.Name = "textBoxCollectionName"; + textBoxCollectionName.Size = new Size(191, 20); + textBoxCollectionName.TabIndex = 0; + textBoxCollectionName.TextChanged += textBoxCollectionName_TextChanged; // // comboBoxSelectorCompany // @@ -124,12 +166,84 @@ comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxSelectorCompany.FormattingEnabled = true; comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); - comboBoxSelectorCompany.Location = new Point(12, 22); + comboBoxSelectorCompany.Location = new Point(9, 298); comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; - comboBoxSelectorCompany.Size = new Size(194, 21); + comboBoxSelectorCompany.Size = new Size(191, 21); comboBoxSelectorCompany.TabIndex = 0; comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged; // + // panelCompanyTools + // + panelCompanyTools.Controls.Add(buttonGoToCheck); + panelCompanyTools.Controls.Add(buttonAddSimpleExcavator); + panelCompanyTools.Controls.Add(buttonAddExcavator); + panelCompanyTools.Controls.Add(maskedTextBoxPosition); + panelCompanyTools.Controls.Add(buttonRemoveExcavator); + panelCompanyTools.Controls.Add(buttonRefresh); + panelCompanyTools.Location = new Point(6, 365); + panelCompanyTools.Name = "panelCompanyTools"; + panelCompanyTools.Size = new Size(200, 263); + panelCompanyTools.TabIndex = 7; + // + // buttonGoToCheck + // + buttonGoToCheck.Location = new Point(6, 164); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(191, 42); + buttonGoToCheck.TabIndex = 5; + buttonGoToCheck.Text = "Передать на тесты"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += ButtonGoToCheck_Click; + // + // buttonAddSimpleExcavator + // + buttonAddSimpleExcavator.Location = new Point(3, 3); + buttonAddSimpleExcavator.Name = "buttonAddSimpleExcavator"; + buttonAddSimpleExcavator.Size = new Size(191, 35); + buttonAddSimpleExcavator.TabIndex = 1; + buttonAddSimpleExcavator.Text = "Добавить экскаватор"; + buttonAddSimpleExcavator.UseVisualStyleBackColor = true; + buttonAddSimpleExcavator.Click += ButtonAddSimleExcavator_Click; + // + // buttonAddExcavator + // + buttonAddExcavator.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddExcavator.Location = new Point(3, 44); + buttonAddExcavator.Name = "buttonAddExcavator"; + buttonAddExcavator.Size = new Size(191, 41); + buttonAddExcavator.TabIndex = 2; + buttonAddExcavator.Text = "Добавить экскаватор с обвесами"; + buttonAddExcavator.UseVisualStyleBackColor = true; + buttonAddExcavator.Click += ButtonAddExcavator_Click; + // + // maskedTextBoxPosition + // + maskedTextBoxPosition.Location = new Point(3, 91); + maskedTextBoxPosition.Mask = "00"; + maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + maskedTextBoxPosition.Size = new Size(191, 20); + maskedTextBoxPosition.TabIndex = 3; + // + // buttonRemoveExcavator + // + buttonRemoveExcavator.Location = new Point(6, 117); + buttonRemoveExcavator.Name = "buttonRemoveExcavator"; + buttonRemoveExcavator.Size = new Size(191, 41); + buttonRemoveExcavator.TabIndex = 4; + buttonRemoveExcavator.Text = "Удалить экскаватор"; + buttonRemoveExcavator.UseVisualStyleBackColor = true; + buttonRemoveExcavator.Click += ButtonRemoveExcavator_Click; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(6, 212); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(191, 41); + buttonRefresh.TabIndex = 6; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; + // // pictureBox // pictureBox.AccessibleRole = AccessibleRole.None; @@ -152,7 +266,10 @@ Name = "FormExcavatorCollection"; Text = "Коллекция экскаваторов"; groupBoxTools.ResumeLayout(false); - groupBoxTools.PerformLayout(); + panelStorage.ResumeLayout(false); + panelStorage.PerformLayout(); + panelCompanyTools.ResumeLayout(false); + panelCompanyTools.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); ResumeLayout(false); } @@ -168,5 +285,15 @@ private Button buttonRemoveExcavator; private MaskedTextBox maskedTextBoxPosition; private Button buttonRefresh; + private Panel panelStorage; + private Panel panelCompanyTools; + private TextBox textBoxCollectionName; + private Label labelCollectionName; + private Button buttonCollectionAdd; + private RadioButton radioButtonList; + private RadioButton radioButtonMassive; + private ListBox listBoxCollection; + private Button buttonCollectionDel; + private Button buttonCreateCompany; } } \ No newline at end of file diff --git a/Excavator/Excavator/FormExcavatorCollection.cs b/Excavator/Excavator/FormExcavatorCollection.cs index 4aaf62b..59775b1 100644 --- a/Excavator/Excavator/FormExcavatorCollection.cs +++ b/Excavator/Excavator/FormExcavatorCollection.cs @@ -1,25 +1,22 @@ using Excavator.CollectionGenericObjects; using Excavator.Drawnings; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; namespace Excavator; public partial class FormExcavatorCollection : Form { + /// + /// Хранилище коллекций + /// + private readonly StorageCollection _storageCollection; + private AbstractCompany? _company = null; public FormExcavatorCollection() { InitializeComponent(); + _storageCollection = new(); } private void pictureBox_Click(object sender, EventArgs e) @@ -28,12 +25,7 @@ public partial class FormExcavatorCollection : Form } private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) { - switch (comboBoxSelectorCompany.Text) - { - case "Хранилище": - _company = new Garage(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); - break; - } + panelCompanyTools.Enabled = false; } private void CreateObject(string type) { @@ -155,4 +147,99 @@ public partial class FormExcavatorCollection : Form pictureBox.Image = _company.Show(); } + + private void textBoxCollectionName_TextChanged(object sender, EventArgs e) + { + + } + + private void labelCollectionName_Click(object sender, EventArgs e) + { + + } + + /// + /// Обновление списка в 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 Garage(pictureBox.Width, pictureBox.Height, collection); + break; + } + + panelCompanyTools.Enabled = true; + RerfreshListBoxItems(); + } } \ No newline at end of file