diff --git a/ProjectLiner/ProjectLiner/CollectionGenericObjects/AbstractCompany.cs b/ProjectLiner/ProjectLiner/CollectionGenericObjects/AbstractCompany.cs index 5076923..b5cc584 100644 --- a/ProjectLiner/ProjectLiner/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectLiner/ProjectLiner/CollectionGenericObjects/AbstractCompany.cs @@ -71,7 +71,7 @@ namespace ProjectLiner.CollectionGenericObjects /// public static DrawningCommonLiner operator -(AbstractCompany company, int position) { - return company._collection.Remove(position); + return company._collection.Remove(position) ; } /// diff --git a/ProjectLiner/ProjectLiner/CollectionGenericObjects/CollectionType.cs b/ProjectLiner/ProjectLiner/CollectionGenericObjects/CollectionType.cs new file mode 100644 index 0000000..d5b8c2c --- /dev/null +++ b/ProjectLiner/ProjectLiner/CollectionGenericObjects/CollectionType.cs @@ -0,0 +1,24 @@ + +namespace ProjectLiner.CollectionGenericObjects; + + +/// +/// Тип коллекции +/// +public enum CollectionType +{ + /// + /// Неопределено + /// + None = 0, + + /// + /// Массив + /// + Massive = 1, + + /// + /// Список + /// + List = 2, +} diff --git a/ProjectLiner/ProjectLiner/CollectionGenericObjects/ListGenericObjects.cs b/ProjectLiner/ProjectLiner/CollectionGenericObjects/ListGenericObjects.cs new file mode 100644 index 0000000..dc81bc1 --- /dev/null +++ b/ProjectLiner/ProjectLiner/CollectionGenericObjects/ListGenericObjects.cs @@ -0,0 +1,52 @@ +using ProjectLiner.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 + 1 > _maxCount) return -1; + _collection.Add(obj); + return Count; + } + public int Insert(T obj, int position) + { + if (Count + 1 > _maxCount) return -1; + if (position < 0 || position > Count) return -1; + _collection.Insert(position, obj); + return 1; + } + public T? Remove(int position) + { + if (position < 0 || position > Count) return null; + T? temp = _collection[position]; + _collection.RemoveAt(position); + return temp; + } +} \ No newline at end of file diff --git a/ProjectLiner/ProjectLiner/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectLiner/ProjectLiner/CollectionGenericObjects/MassiveGenericObjects.cs index f668f85..661b751 100644 --- a/ProjectLiner/ProjectLiner/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/ProjectLiner/ProjectLiner/CollectionGenericObjects/MassiveGenericObjects.cs @@ -63,45 +63,33 @@ namespace ProjectLiner.CollectionGenericObjects public int Insert(T obj, int position) { - if (position < 0 || position >= Count) + if (position >= Count || position < 0) return -1; + if (_collection[position] == null) { - return -1; + _collection[position] = obj; + return position; } - - if (_collection[position] != null) + int temp = position + 1; + while (temp < Count) { - bool pushed = false; - for (int index = position + 1; index < Count; index++) + if (_collection[temp] == null) { - if (_collection[index] == null) - { - position = index; - pushed = true; - break; - } - } - - if (!pushed) - { - for (int index = position - 1; index >= 0; index--) - { - if (_collection[index] == null) - { - position = index; - pushed = true; - break; - } - } - } - - if (!pushed) - { - return position; + _collection[temp] = obj; + return temp; } + ++temp; } - - _collection[position] = obj; - return position; + temp = position - 1; + while (temp >= 0) + { + if (_collection[temp] == null) + { + _collection[temp] = obj; + return temp; + } + --temp; + } + return -1; } public T? Remove(int position) @@ -111,7 +99,7 @@ namespace ProjectLiner.CollectionGenericObjects return null; } - if (_collection[position] == null) return null; + //if (_collection[position] == null) return null; T? temp = _collection[position]; _collection[position] = null; diff --git a/ProjectLiner/ProjectLiner/CollectionGenericObjects/StorageCollection.cs b/ProjectLiner/ProjectLiner/CollectionGenericObjects/StorageCollection.cs new file mode 100644 index 0000000..6e2ed1a --- /dev/null +++ b/ProjectLiner/ProjectLiner/CollectionGenericObjects/StorageCollection.cs @@ -0,0 +1,68 @@ +using ProjectLiner.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; + } + } + /// + /// Удаление коллекции + /// + /// Название коллекции + public void DelCollection(string name) + { + if (_storages.ContainsKey(name)) + _storages.Remove(name); + } + /// + /// Доступ к коллекции + /// + /// Название коллекции + /// + public ICollectionGenericObjects? this[string name] + { + get + { + if (name == null || !_storages.ContainsKey(name)) { return null; } + return _storages[name]; + } + } +} \ No newline at end of file diff --git a/ProjectLiner/ProjectLiner/FormLinerCollection.Designer.cs b/ProjectLiner/ProjectLiner/FormLinerCollection.Designer.cs index 1aeb63b..50e79a9 100644 --- a/ProjectLiner/ProjectLiner/FormLinerCollection.Designer.cs +++ b/ProjectLiner/ProjectLiner/FormLinerCollection.Designer.cs @@ -29,98 +29,149 @@ private void InitializeComponent() { groupBoxTools = new GroupBox(); - buttonRefresh = new Button(); - buttonGoToCheck = new Button(); - buttonRemoveLiner = new Button(); - maskedTextBoxPosition = new MaskedTextBox(); - buttonAddCommonLiner = new Button(); - buttonAddLiner = 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(); + panelCompanyTools = new Panel(); + button1 = new Button(); + button2 = new Button(); + maskedTextBox1 = new MaskedTextBox(); + button3 = new Button(); + button4 = new Button(); + button5 = new Button(); groupBoxTools.SuspendLayout(); + panelStorage.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); + panelCompanyTools.SuspendLayout(); SuspendLayout(); // // groupBoxTools // - groupBoxTools.Controls.Add(buttonRefresh); - groupBoxTools.Controls.Add(buttonGoToCheck); - groupBoxTools.Controls.Add(buttonRemoveLiner); - groupBoxTools.Controls.Add(maskedTextBoxPosition); - groupBoxTools.Controls.Add(buttonAddCommonLiner); - groupBoxTools.Controls.Add(buttonAddLiner); + groupBoxTools.Controls.Add(buttonCreateCompany); + groupBoxTools.Controls.Add(panelStorage); groupBoxTools.Controls.Add(comboBoxSelectorCompany); groupBoxTools.Dock = DockStyle.Right; - groupBoxTools.Location = new Point(1053, 0); + groupBoxTools.Location = new Point(681, 0); + groupBoxTools.Margin = new Padding(2); groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(272, 845); + groupBoxTools.Padding = new Padding(2); + groupBoxTools.Size = new Size(176, 648); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; // - // buttonRefresh + // buttonCreateCompany // - buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRefresh.Location = new Point(33, 683); - buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(217, 76); - buttonRefresh.TabIndex = 6; - buttonRefresh.Text = "Обновить"; - buttonRefresh.UseVisualStyleBackColor = true; - buttonRefresh.Click += ButtonRefresh_Click; + buttonCreateCompany.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point); + buttonCreateCompany.Location = new Point(5, 317); + buttonCreateCompany.Name = "buttonCreateCompany"; + buttonCreateCompany.Size = new Size(166, 23); + buttonCreateCompany.TabIndex = 8; + buttonCreateCompany.Text = "Создать компанию"; + buttonCreateCompany.UseVisualStyleBackColor = true; + buttonCreateCompany.Click += ButtonCreateCompany_Click; // - // buttonGoToCheck + // panelStorage // - buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonGoToCheck.Location = new Point(33, 562); - buttonGoToCheck.Name = "buttonGoToCheck"; - buttonGoToCheck.Size = new Size(217, 76); - 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(textBoxCollectionName); + panelStorage.Controls.Add(labelCollectionName); + panelStorage.Dock = DockStyle.Top; + panelStorage.Location = new Point(2, 28); + panelStorage.Margin = new Padding(2); + panelStorage.Name = "panelStorage"; + panelStorage.Size = new Size(172, 247); + panelStorage.TabIndex = 7; // - // buttonRemoveLiner + // buttonCollectionDel // - buttonRemoveLiner.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRemoveLiner.Location = new Point(33, 416); - buttonRemoveLiner.Name = "buttonRemoveLiner"; - buttonRemoveLiner.Size = new Size(217, 76); - buttonRemoveLiner.TabIndex = 4; - buttonRemoveLiner.Text = "Удаление Лайнера"; - buttonRemoveLiner.UseVisualStyleBackColor = true; - buttonRemoveLiner.Click += ButtonRemoveLiner_Click; + buttonCollectionDel.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point); + buttonCollectionDel.Location = new Point(3, 212); + buttonCollectionDel.Name = "buttonCollectionDel"; + buttonCollectionDel.Size = new Size(166, 23); + buttonCollectionDel.TabIndex = 6; + buttonCollectionDel.Text = "Удалить Коллекцию"; + buttonCollectionDel.UseVisualStyleBackColor = true; + buttonCollectionDel.Click += ButtonCollectionDel_Click; // - // maskedTextBoxPosition + // listBoxCollection // - maskedTextBoxPosition.Location = new Point(33, 363); - maskedTextBoxPosition.Mask = "00"; - maskedTextBoxPosition.Name = "maskedTextBoxPosition"; - maskedTextBoxPosition.Size = new Size(217, 47); - maskedTextBoxPosition.TabIndex = 3; - maskedTextBoxPosition.ValidatingType = typeof(int); + listBoxCollection.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point); + listBoxCollection.FormattingEnabled = true; + listBoxCollection.ItemHeight = 17; + listBoxCollection.Location = new Point(3, 110); + listBoxCollection.Name = "listBoxCollection"; + listBoxCollection.Size = new Size(166, 89); + listBoxCollection.TabIndex = 5; // - // buttonAddCommonLiner + // buttonCollectionAdd // - buttonAddCommonLiner.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddCommonLiner.Location = new Point(33, 236); - buttonAddCommonLiner.Name = "buttonAddCommonLiner"; - buttonAddCommonLiner.Size = new Size(217, 76); - buttonAddCommonLiner.TabIndex = 2; - buttonAddCommonLiner.Text = "Добавление Обычного Лайнера"; - buttonAddCommonLiner.UseVisualStyleBackColor = true; - buttonAddCommonLiner.Click += ButtonAddCommonLiner_Click; + buttonCollectionAdd.Font = new Font("Segoe UI", 7.948052F, FontStyle.Regular, GraphicsUnit.Point); + buttonCollectionAdd.Location = new Point(2, 82); + buttonCollectionAdd.Margin = new Padding(2); + buttonCollectionAdd.Name = "buttonCollectionAdd"; + buttonCollectionAdd.Size = new Size(170, 23); + buttonCollectionAdd.TabIndex = 4; + buttonCollectionAdd.Text = "Добавить коллекцию"; + buttonCollectionAdd.UseVisualStyleBackColor = true; + buttonCollectionAdd.Click += ButtonCollectionAdd_Click; // - // buttonAddLiner + // radioButtonList // - buttonAddLiner.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddLiner.Location = new Point(33, 126); - buttonAddLiner.Name = "buttonAddLiner"; - buttonAddLiner.Size = new Size(217, 76); - buttonAddLiner.TabIndex = 1; - buttonAddLiner.Text = "Добавление Лайнера"; - buttonAddLiner.UseVisualStyleBackColor = true; - buttonAddLiner.Click += ButtonAddLiner_Click; + radioButtonList.AutoSize = true; + radioButtonList.Font = new Font("Segoe UI", 9.818182F, FontStyle.Regular, GraphicsUnit.Point); + radioButtonList.Location = new Point(89, 58); + radioButtonList.Margin = new Padding(2); + radioButtonList.Name = "radioButtonList"; + radioButtonList.Size = new Size(73, 23); + radioButtonList.TabIndex = 3; + radioButtonList.TabStop = true; + radioButtonList.Text = "Список"; + radioButtonList.UseVisualStyleBackColor = true; + // + // radioButtonMassive + // + radioButtonMassive.AutoSize = true; + radioButtonMassive.Font = new Font("Segoe UI", 9.818182F, FontStyle.Regular, GraphicsUnit.Point); + radioButtonMassive.Location = new Point(2, 58); + radioButtonMassive.Margin = new Padding(2); + radioButtonMassive.Name = "radioButtonMassive"; + radioButtonMassive.Size = new Size(71, 23); + radioButtonMassive.TabIndex = 2; + radioButtonMassive.TabStop = true; + radioButtonMassive.Text = "массив"; + radioButtonMassive.UseVisualStyleBackColor = true; + // + // textBoxCollectionName + // + textBoxCollectionName.Location = new Point(0, 26); + textBoxCollectionName.Margin = new Padding(2); + textBoxCollectionName.Name = "textBoxCollectionName"; + textBoxCollectionName.Size = new Size(172, 33); + textBoxCollectionName.TabIndex = 1; + // + // labelCollectionName + // + labelCollectionName.AutoSize = true; + labelCollectionName.Font = new Font("Segoe UI", 9.818182F, FontStyle.Regular, GraphicsUnit.Point); + labelCollectionName.Location = new Point(14, 5); + labelCollectionName.Margin = new Padding(2, 0, 2, 0); + labelCollectionName.Name = "labelCollectionName"; + labelCollectionName.Size = new Size(140, 19); + labelCollectionName.TabIndex = 0; + labelCollectionName.Text = "Название коллекции"; // // comboBoxSelectorCompany // @@ -128,33 +179,125 @@ comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxSelectorCompany.FormattingEnabled = true; comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); - comboBoxSelectorCompany.Location = new Point(18, 46); + comboBoxSelectorCompany.Location = new Point(13, 279); + comboBoxSelectorCompany.Margin = new Padding(2); comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; - comboBoxSelectorCompany.Size = new Size(242, 49); + comboBoxSelectorCompany.Size = new Size(158, 33); comboBoxSelectorCompany.TabIndex = 0; comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged; // // pictureBox // - pictureBox.Dock = DockStyle.Fill; + pictureBox.Dock = DockStyle.Bottom; + pictureBox.Enabled = false; pictureBox.Location = new Point(0, 0); + pictureBox.Margin = new Padding(2); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(1053, 845); + pictureBox.Size = new Size(681, 648); pictureBox.TabIndex = 1; pictureBox.TabStop = false; // + // panelCompanyTools + // + panelCompanyTools.BackColor = SystemColors.Window; + panelCompanyTools.Controls.Add(button1); + panelCompanyTools.Controls.Add(button2); + panelCompanyTools.Controls.Add(maskedTextBox1); + panelCompanyTools.Controls.Add(button5); + panelCompanyTools.Controls.Add(button3); + panelCompanyTools.Controls.Add(button4); + panelCompanyTools.Location = new Point(681, 346); + panelCompanyTools.Name = "panelCompanyTools"; + panelCompanyTools.Size = new Size(176, 302); + panelCompanyTools.TabIndex = 9; + // + // button1 + // + button1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + button1.Location = new Point(4, 2); + button1.Margin = new Padding(2); + button1.Name = "button1"; + button1.Size = new Size(140, 46); + button1.TabIndex = 1; + button1.Text = "Добавление Лайнера"; + button1.UseVisualStyleBackColor = true; + button1.Click += ButtonAddLiner_Click; + // + // button2 + // + button2.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + button2.Location = new Point(2, 52); + button2.Margin = new Padding(2); + button2.Name = "button2"; + button2.Size = new Size(140, 46); + button2.TabIndex = 2; + button2.Text = "Добавление Обычного Лайнера"; + button2.UseVisualStyleBackColor = true; + button2.Click += ButtonAddCommonLiner_Click; + // + // maskedTextBox1 + // + maskedTextBox1.Location = new Point(2, 102); + maskedTextBox1.Margin = new Padding(2); + maskedTextBox1.Mask = "00"; + maskedTextBox1.Name = "maskedTextBox1"; + maskedTextBox1.Size = new Size(142, 33); + maskedTextBox1.TabIndex = 3; + maskedTextBox1.ValidatingType = typeof(int); + // + // button3 + // + button3.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + button3.Location = new Point(2, 134); + button3.Margin = new Padding(2); + button3.Name = "button3"; + button3.Size = new Size(140, 46); + button3.TabIndex = 4; + button3.Text = "Удаление Лайнера"; + button3.UseVisualStyleBackColor = true; + button3.Click += ButtonRemoveLiner_Click; + // + // button4 + // + button4.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + button4.Location = new Point(2, 184); + button4.Margin = new Padding(2); + button4.Name = "button4"; + button4.Size = new Size(140, 46); + button4.TabIndex = 5; + button4.Text = "Передать на тесты"; + button4.UseVisualStyleBackColor = true; + button4.Click += ButtonGoToCheck_Click; + // + // button5 + // + button5.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + button5.Location = new Point(2, 234); + button5.Margin = new Padding(2); + button5.Name = "button5"; + button5.Size = new Size(140, 46); + button5.TabIndex = 6; + button5.Text = "Обновить"; + button5.UseVisualStyleBackColor = true; + button5.Click += ButtonRefresh_Click; + // // FormLinerCollection // - AutoScaleDimensions = new SizeF(17F, 41F); + AutoScaleDimensions = new SizeF(11F, 25F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1325, 845); + ClientSize = new Size(857, 648); + Controls.Add(panelCompanyTools); Controls.Add(pictureBox); Controls.Add(groupBoxTools); + Margin = new Padding(2); Name = "FormLinerCollection"; Text = "Коллекция автомобилей"; groupBoxTools.ResumeLayout(false); - groupBoxTools.PerformLayout(); + panelStorage.ResumeLayout(false); + panelStorage.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + panelCompanyTools.ResumeLayout(false); + panelCompanyTools.PerformLayout(); ResumeLayout(false); } @@ -169,5 +312,21 @@ private Button buttonRemoveLiner; private MaskedTextBox maskedTextBoxPosition; private Button buttonRefresh; + private Panel panelStorage; + private Label labelCollectionName; + private RadioButton radioButtonMassive; + private TextBox textBoxCollectionName; + private Button buttonCollectionAdd; + private RadioButton radioButtonList; + private Button buttonCollectionDel; + private ListBox listBoxCollection; + private Button buttonCreateCompany; + private Panel panelCompanyTools; + private Button button1; + private Button button2; + private MaskedTextBox maskedTextBox1; + private Button button5; + private Button button3; + private Button button4; } } \ No newline at end of file diff --git a/ProjectLiner/ProjectLiner/FormLinerCollection.cs b/ProjectLiner/ProjectLiner/FormLinerCollection.cs index 3e759f4..67b99b3 100644 --- a/ProjectLiner/ProjectLiner/FormLinerCollection.cs +++ b/ProjectLiner/ProjectLiner/FormLinerCollection.cs @@ -1,188 +1,256 @@ -using ProjectLiner.CollectionGenericObjects; + +using ProjectLiner.CollectionGenericObjects; using ProjectLiner.Drawnings; -using System.Windows.Forms; -namespace ProjectLiner +namespace ProjectLiner; +/// +/// Форма работы с компанией и ее коллекцией +/// +public partial class FormLinerCollection : Form { /// - /// Форма работы с компанией и ее коллекцией + /// Хранилише коллекций /// - public partial class FormLinerCollection : Form + private readonly StorageCollection _storageCollection; + /// + /// Компания + /// + private AbstractCompany? _company = null; + /// + /// Конструктор + /// + public FormLinerCollection() { - /// - /// Компания - /// - private AbstractCompany? _company = null; - - /// - /// Конструктор - /// - public FormLinerCollection() + InitializeComponent(); + _storageCollection = new(); + } + /// + /// Выбор компании + /// + /// + /// + private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) + { + panelCompanyTools.Enabled = false; + } + /// + /// Добавление грузовика + /// + /// + /// + private void ButtonAddCommonLiner_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningCommonLiner)); + /// + /// Добавление подметательно-уборочной машины + /// + /// + /// + private void ButtonAddLiner_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningLiner)); + /// + /// Создание объекта класса-перемещенияв + /// + /// + private void CreateObject(string type) + { + if (_company == null) { - InitializeComponent(); + return; } - - /// - /// Выбор компании - /// - /// - /// - private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) + Random random = new(); + DrawningCommonLiner drawningCommonLiner; + switch (type) { - switch (comboBoxSelectorCompany.Text) - { - case "Хранилище": - _company = new LinerSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); - break; - } + case nameof(DrawningCommonLiner): + drawningCommonLiner = new DrawningCommonLiner(random.Next(100, 300), + random.Next(1000, 3000), GetColor(random)); + break; + case nameof(DrawningLiner): + drawningCommonLiner = new DrawningLiner(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))); + break; + default: + return; } - - /// - /// Создание объекта класса-перемещения - /// - /// Тип создаваемого объекта - private void CreateObject(string type) + if (_company + drawningCommonLiner != -1) { - if (_company == null) - { - return; - } - - Random random = new(); - DrawningCommonLiner drawingLiner; - switch (type) - { - case nameof(DrawningCommonLiner): - drawingLiner = new DrawningCommonLiner(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); - break; - case nameof(DrawningLiner): - drawingLiner = new DrawningLiner(random.Next(100, 300), random.Next(1000, 3000), GetColor(random), GetColor(random), - Convert.ToBoolean(random.Next(1, 2)), Convert.ToBoolean(random.Next(1, 2)), Convert.ToBoolean(random.Next(1, 2))); - break; - default: - return; - } - - if (_company + drawingLiner != -1) - { - MessageBox.Show("Объект добавлен"); - pictureBox.Image = _company.Show(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } - } - - /// - /// Получение цвета - /// - /// Генератор случайных чисел - /// - private static Color GetColor(Random random) - { - Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); - ColorDialog dialog = new(); - if (dialog.ShowDialog() == DialogResult.OK) - { - color = dialog.Color; - } - - return color; - } - - /// - /// Добавление обычного лайнер - /// - /// - /// - private void ButtonAddCommonLiner_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningCommonLiner)); - - /// - /// Добавление лайнера - /// - /// - /// - private void ButtonAddLiner_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningLiner)); - - /// - /// Удаление объекта - /// - /// - /// - private void ButtonRemoveLiner_Click(object sender, EventArgs e) - { - if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null) - { - return; - } - - if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) - { - return; - } - - int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_company - pos != null) - { - MessageBox.Show("Объект удален"); - pictureBox.Image = _company.Show(); - } - else - { - MessageBox.Show("Не удалось удалить объект"); - } - } - - /// - /// Передача объекта в другую форму - /// - /// - /// - private void ButtonGoToCheck_Click(object sender, EventArgs e) - { - if (_company == null) - { - return; - } - - DrawningCommonLiner? liner = null; - int counter = 100; - while (liner == null) - { - liner = _company.GetRandomObject(); - counter--; - if (counter <= 0) - { - break; - } - } - - if (liner == null) - { - return; - } - - FormLiner form = new() - { - SetLiner = liner - }; - form.ShowDialog(); - } - - /// - /// Перерисовка коллекции - /// - /// - /// - private void ButtonRefresh_Click(object sender, EventArgs e) - { - if (_company == null) - { - return; - } - + MessageBox.Show("Объект добавлен"); pictureBox.Image = _company.Show(); } + else + { + MessageBox.Show("Не удалось добавить объект"); + } } -} + /// + /// Получение цвета + /// + /// Генератор случайных чисел + /// + private static Color GetColor(Random random) + { + Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, + 256), random.Next(0, 256)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + return color; + } + /// + /// Удаление объекта + /// + /// + /// + private void ButtonRemoveLiner_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null) + { + return; + } + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) + { + return; + } + int pos = Convert.ToInt32(maskedTextBoxPosition.Text); + if (_company - pos != null) + { + MessageBox.Show("Объект удален"); + pictureBox.Image = _company.Show(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + + } + /// + /// Передача объекта в другую форму + /// + /// + /// + private void ButtonGoToCheck_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + DrawningCommonLiner? liner = null; + int counter = 100; + while (liner == null) + { + liner = _company.GetRandomObject(); + counter--; + if (counter <= 0) break; + } + if (liner == null) + { + return; + } + FormLiner form = new FormLiner(); + form.SetLiner = liner; + form.ShowDialog(); + } + /// + /// Перерисовка коллекции + /// + /// + /// + private void ButtonRefresh_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + 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); + 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 LinerSharingService(pictureBox.Width, pictureBox.Height, collection); + break; + } + panelCompanyTools.Enabled = true; + RerfreshListBoxItems(); + } +} \ No newline at end of file