Revert "Lab 4 done"

This reverts commit 7397095a66.
This commit is contained in:
strwbrry1 2024-04-03 12:45:00 +04:00
parent 7397095a66
commit fdf88350d6
6 changed files with 46 additions and 396 deletions

View File

@ -25,7 +25,7 @@ namespace Catamaran.CollectionGenericObjects
} }
else else
{ {
_collection = new T?[value]; _collection = new T[value];
} }
} }
} }
@ -38,11 +38,7 @@ namespace Catamaran.CollectionGenericObjects
public T? Get(int position) public T? Get(int position)
{ {
if (position >= 0 && position < Count) return _collection[position];
{
return _collection[position];
}
return null;
} }
public int Insert(T obj) public int Insert(T obj)

View File

@ -1,17 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Catamaran.CollectionGenericObjects
{
public enum CollectionType
{
None = 0,
Array = 1,
List = 2
}
}

View File

@ -1,66 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Catamaran.CollectionGenericObjects
{
public class ListGenericObjects<T> : ICollectionGenericObjects<T>
where T : class
{
private readonly List<T?> _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 < 0 || position >= Count)
{
return null;
}
return _collection[position];
}
public int Insert(T obj)
{
if (Count + 1 > _maxCount)
{
return -1;
}
_collection.Add(obj);
return 1;
}
public int Insert(T obj, int position)
{
if (position < 0 || position > Count || Count + 1 > _maxCount)
{
return -1;
}
_collection.Insert(position, obj);
return 1;
}
public T? Remove(int position)
{
if (position < 0 || position > Count)
{
return null;
}
T? obj = _collection[position];
_collection.RemoveAt(position);
return obj;
}
}
}

View File

@ -1,62 +0,0 @@
using Catamaran.Drawings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Catamaran.CollectionGenericObjects
{
public class StorageCollection<T>
where T : class
{
readonly Dictionary<string, ICollectionGenericObjects<T>> _storages;
public List<string> Keys => _storages.Keys.ToList();
public StorageCollection()
{
_storages = new Dictionary<string, ICollectionGenericObjects<T>>();
}
public void AddCollection(string name, CollectionType collectionType)
{
if (!string.IsNullOrEmpty(name) && !_storages.ContainsKey(name))
{
switch (collectionType)
{
case CollectionType.None:
return;
case CollectionType.Array:
_storages[name] = new ArrayGenericObjects<T>();
return;
case CollectionType.List:
_storages[name] = new ListGenericObjects<T>();
return;
}
}
}
public void DelCollection(string name)
{
if (string.IsNullOrEmpty(name) || !_storages.ContainsKey(name))
{
return;
}
_storages.Remove(name);
}
public ICollectionGenericObjects<T>? this[string name]
{
get
{
if (!_storages.ContainsKey(name) || string.IsNullOrEmpty(name))
{
return null;
}
return _storages[name];
}
}
}
}

View File

@ -29,36 +29,27 @@
private void InitializeComponent() private void InitializeComponent()
{ {
groupBox1 = new GroupBox(); groupBox1 = new GroupBox();
buttonCompanyCreate = new Button();
panelCollection = new Panel();
buttonCollectionDelete = new Button();
listBoxCollection = new ListBox();
buttonCollectionAdd = new Button();
radioButtonList = new RadioButton();
radioButtonArray = new RadioButton();
textBoxCollectionName = new TextBox();
labelCollectionName = new Label();
UpdateButton = new Button(); UpdateButton = new Button();
GoToTestButton = new Button(); GoToTestButton = new Button();
DeleteButton = new Button(); DeleteButton = new Button();
maskedTextBox = new MaskedTextBox(); maskedTextBox = new MaskedTextBox();
AddCatamaranButton = new Button(); AddCatamaranButton = new Button();
AddBoatButton = new Button(); AddBoatButton = new Button();
comboBoxSelectorCompany = new ComboBox(); InstrumentBox = new ComboBox();
pictureBox = new PictureBox(); pictureBox = new PictureBox();
panelCompanyTools = new Panel();
groupBox1.SuspendLayout(); groupBox1.SuspendLayout();
panelCollection.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
panelCompanyTools.SuspendLayout();
SuspendLayout(); SuspendLayout();
// //
// groupBox1 // groupBox1
// //
groupBox1.Controls.Add(panelCompanyTools); groupBox1.Controls.Add(UpdateButton);
groupBox1.Controls.Add(buttonCompanyCreate); groupBox1.Controls.Add(GoToTestButton);
groupBox1.Controls.Add(panelCollection); groupBox1.Controls.Add(DeleteButton);
groupBox1.Controls.Add(comboBoxSelectorCompany); groupBox1.Controls.Add(maskedTextBox);
groupBox1.Controls.Add(AddCatamaranButton);
groupBox1.Controls.Add(AddBoatButton);
groupBox1.Controls.Add(InstrumentBox);
groupBox1.Dock = DockStyle.Right; groupBox1.Dock = DockStyle.Right;
groupBox1.Location = new Point(809, 0); groupBox1.Location = new Point(809, 0);
groupBox1.Name = "groupBox1"; groupBox1.Name = "groupBox1";
@ -67,101 +58,11 @@
groupBox1.TabStop = false; groupBox1.TabStop = false;
groupBox1.Text = "Инструменты"; groupBox1.Text = "Инструменты";
// //
// buttonCompanyCreate
//
buttonCompanyCreate.Location = new Point(6, 366);
buttonCompanyCreate.Name = "buttonCompanyCreate";
buttonCompanyCreate.Size = new Size(225, 29);
buttonCompanyCreate.TabIndex = 8;
buttonCompanyCreate.Text = "Создать компанию";
buttonCompanyCreate.UseVisualStyleBackColor = true;
buttonCompanyCreate.Click += buttonCompanyCreate_Click;
//
// panelCollection
//
panelCollection.Controls.Add(buttonCollectionDelete);
panelCollection.Controls.Add(listBoxCollection);
panelCollection.Controls.Add(buttonCollectionAdd);
panelCollection.Controls.Add(radioButtonList);
panelCollection.Controls.Add(radioButtonArray);
panelCollection.Controls.Add(textBoxCollectionName);
panelCollection.Controls.Add(labelCollectionName);
panelCollection.Location = new Point(6, 26);
panelCollection.Name = "panelCollection";
panelCollection.Size = new Size(225, 298);
panelCollection.TabIndex = 7;
//
// buttonCollectionDelete
//
buttonCollectionDelete.Location = new Point(3, 265);
buttonCollectionDelete.Name = "buttonCollectionDelete";
buttonCollectionDelete.Size = new Size(219, 29);
buttonCollectionDelete.TabIndex = 6;
buttonCollectionDelete.Text = "Удалить коллекцию";
buttonCollectionDelete.UseVisualStyleBackColor = true;
buttonCollectionDelete.Click += buttonCollectionDelete_Click;
//
// listBoxCollection
//
listBoxCollection.FormattingEnabled = true;
listBoxCollection.Location = new Point(3, 155);
listBoxCollection.Name = "listBoxCollection";
listBoxCollection.Size = new Size(216, 104);
listBoxCollection.TabIndex = 5;
//
// buttonCollectionAdd
//
buttonCollectionAdd.Location = new Point(3, 114);
buttonCollectionAdd.Name = "buttonCollectionAdd";
buttonCollectionAdd.Size = new Size(219, 29);
buttonCollectionAdd.TabIndex = 4;
buttonCollectionAdd.Text = "Добавить коллекцию";
buttonCollectionAdd.UseVisualStyleBackColor = true;
buttonCollectionAdd.Click += buttonCollectionAdd_Click;
//
// radioButtonList
//
radioButtonList.AutoSize = true;
radioButtonList.Location = new Point(91, 76);
radioButtonList.Name = "radioButtonList";
radioButtonList.Size = new Size(80, 24);
radioButtonList.TabIndex = 3;
radioButtonList.TabStop = true;
radioButtonList.Text = "Список";
radioButtonList.UseVisualStyleBackColor = true;
//
// radioButtonArray
//
radioButtonArray.AutoSize = true;
radioButtonArray.Location = new Point(3, 76);
radioButtonArray.Name = "radioButtonArray";
radioButtonArray.Size = new Size(82, 24);
radioButtonArray.TabIndex = 2;
radioButtonArray.TabStop = true;
radioButtonArray.Text = "Массив";
radioButtonArray.UseVisualStyleBackColor = true;
//
// textBoxCollectionName
//
textBoxCollectionName.Location = new Point(3, 37);
textBoxCollectionName.Name = "textBoxCollectionName";
textBoxCollectionName.Size = new Size(219, 27);
textBoxCollectionName.TabIndex = 1;
//
// labelCollectionName
//
labelCollectionName.AutoSize = true;
labelCollectionName.Location = new Point(36, 5);
labelCollectionName.Name = "labelCollectionName";
labelCollectionName.Size = new Size(158, 20);
labelCollectionName.TabIndex = 0;
labelCollectionName.Text = "Название коллекции:";
//
// UpdateButton // UpdateButton
// //
UpdateButton.Location = new Point(3, 202); UpdateButton.Location = new Point(6, 565);
UpdateButton.Name = "UpdateButton"; UpdateButton.Name = "UpdateButton";
UpdateButton.Size = new Size(222, 38); UpdateButton.Size = new Size(225, 38);
UpdateButton.TabIndex = 6; UpdateButton.TabIndex = 6;
UpdateButton.Text = "Обновить"; UpdateButton.Text = "Обновить";
UpdateButton.UseVisualStyleBackColor = true; UpdateButton.UseVisualStyleBackColor = true;
@ -169,9 +70,9 @@
// //
// GoToTestButton // GoToTestButton
// //
GoToTestButton.Location = new Point(3, 158); GoToTestButton.Location = new Point(12, 355);
GoToTestButton.Name = "GoToTestButton"; GoToTestButton.Name = "GoToTestButton";
GoToTestButton.Size = new Size(222, 38); GoToTestButton.Size = new Size(225, 38);
GoToTestButton.TabIndex = 5; GoToTestButton.TabIndex = 5;
GoToTestButton.Text = "Передать на тесты"; GoToTestButton.Text = "Передать на тесты";
GoToTestButton.UseVisualStyleBackColor = true; GoToTestButton.UseVisualStyleBackColor = true;
@ -179,9 +80,9 @@
// //
// DeleteButton // DeleteButton
// //
DeleteButton.Location = new Point(3, 113); DeleteButton.Location = new Point(6, 238);
DeleteButton.Name = "DeleteButton"; DeleteButton.Name = "DeleteButton";
DeleteButton.Size = new Size(222, 38); DeleteButton.Size = new Size(225, 38);
DeleteButton.TabIndex = 4; DeleteButton.TabIndex = 4;
DeleteButton.Text = "Удалить лодку"; DeleteButton.Text = "Удалить лодку";
DeleteButton.UseVisualStyleBackColor = true; DeleteButton.UseVisualStyleBackColor = true;
@ -189,18 +90,18 @@
// //
// maskedTextBox // maskedTextBox
// //
maskedTextBox.Location = new Point(3, 80); maskedTextBox.Location = new Point(6, 205);
maskedTextBox.Mask = "00"; maskedTextBox.Mask = "00";
maskedTextBox.Name = "maskedTextBox"; maskedTextBox.Name = "maskedTextBox";
maskedTextBox.Size = new Size(222, 27); maskedTextBox.Size = new Size(225, 27);
maskedTextBox.TabIndex = 3; maskedTextBox.TabIndex = 3;
maskedTextBox.ValidatingType = typeof(int); maskedTextBox.ValidatingType = typeof(int);
// //
// AddCatamaranButton // AddCatamaranButton
// //
AddCatamaranButton.Location = new Point(3, 41); AddCatamaranButton.Location = new Point(6, 104);
AddCatamaranButton.Name = "AddCatamaranButton"; AddCatamaranButton.Name = "AddCatamaranButton";
AddCatamaranButton.Size = new Size(222, 33); AddCatamaranButton.Size = new Size(225, 38);
AddCatamaranButton.TabIndex = 2; AddCatamaranButton.TabIndex = 2;
AddCatamaranButton.Text = "Добавить катамаран"; AddCatamaranButton.Text = "Добавить катамаран";
AddCatamaranButton.UseVisualStyleBackColor = true; AddCatamaranButton.UseVisualStyleBackColor = true;
@ -208,26 +109,26 @@
// //
// AddBoatButton // AddBoatButton
// //
AddBoatButton.Location = new Point(3, 3); AddBoatButton.Location = new Point(6, 60);
AddBoatButton.Name = "AddBoatButton"; AddBoatButton.Name = "AddBoatButton";
AddBoatButton.Size = new Size(222, 32); AddBoatButton.Size = new Size(225, 38);
AddBoatButton.TabIndex = 1; AddBoatButton.TabIndex = 1;
AddBoatButton.Text = "Добавить лодку"; AddBoatButton.Text = "Добавить лодку";
AddBoatButton.UseVisualStyleBackColor = true; AddBoatButton.UseVisualStyleBackColor = true;
AddBoatButton.Click += AddBoatButton_Click; AddBoatButton.Click += AddBoatButton_Click;
// //
// comboBoxSelectorCompany // InstrumentBox
// //
comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; InstrumentBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
comboBoxSelectorCompany.AutoCompleteCustomSource.AddRange(new string[] { "Хранилище" }); InstrumentBox.AutoCompleteCustomSource.AddRange(new string[] { "Хранилище" });
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; InstrumentBox.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectorCompany.FormattingEnabled = true; InstrumentBox.FormattingEnabled = true;
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); InstrumentBox.Items.AddRange(new object[] { "Хранилище" });
comboBoxSelectorCompany.Location = new Point(6, 330); InstrumentBox.Location = new Point(6, 26);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; InstrumentBox.Name = "InstrumentBox";
comboBoxSelectorCompany.Size = new Size(225, 28); InstrumentBox.Size = new Size(225, 28);
comboBoxSelectorCompany.TabIndex = 0; InstrumentBox.TabIndex = 0;
comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged; InstrumentBox.SelectedIndexChanged += InstrumentBox_SelectedIndexChanged;
// //
// pictureBox // pictureBox
// //
@ -238,21 +139,6 @@
pictureBox.TabIndex = 1; pictureBox.TabIndex = 1;
pictureBox.TabStop = false; pictureBox.TabStop = false;
// //
// panelCompanyTools
//
panelCompanyTools.Controls.Add(AddCatamaranButton);
panelCompanyTools.Controls.Add(AddBoatButton);
panelCompanyTools.Controls.Add(UpdateButton);
panelCompanyTools.Controls.Add(maskedTextBox);
panelCompanyTools.Controls.Add(GoToTestButton);
panelCompanyTools.Controls.Add(DeleteButton);
panelCompanyTools.Dock = DockStyle.Bottom;
panelCompanyTools.Enabled = false;
panelCompanyTools.Location = new Point(3, 398);
panelCompanyTools.Name = "panelCompanyTools";
panelCompanyTools.Size = new Size(231, 241);
panelCompanyTools.TabIndex = 9;
//
// FormBoatColletion // FormBoatColletion
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(8F, 20F);
@ -263,18 +149,15 @@
Name = "FormBoatColletion"; Name = "FormBoatColletion";
Text = "Коллекция лодок"; Text = "Коллекция лодок";
groupBox1.ResumeLayout(false); groupBox1.ResumeLayout(false);
panelCollection.ResumeLayout(false); groupBox1.PerformLayout();
panelCollection.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
panelCompanyTools.ResumeLayout(false);
panelCompanyTools.PerformLayout();
ResumeLayout(false); ResumeLayout(false);
} }
#endregion #endregion
private GroupBox groupBox1; private GroupBox groupBox1;
private ComboBox comboBoxSelectorCompany; private ComboBox InstrumentBox;
private Button AddBoatButton; private Button AddBoatButton;
private Button AddCatamaranButton; private Button AddCatamaranButton;
private PictureBox pictureBox; private PictureBox pictureBox;
@ -282,15 +165,5 @@
private Button DeleteButton; private Button DeleteButton;
private Button GoToTestButton; private Button GoToTestButton;
private Button UpdateButton; private Button UpdateButton;
private Panel panelCollection;
private RadioButton radioButtonList;
private RadioButton radioButtonArray;
private TextBox textBoxCollectionName;
private Label labelCollectionName;
private Button buttonCompanyCreate;
private Button buttonCollectionDelete;
private ListBox listBoxCollection;
private Button buttonCollectionAdd;
private Panel panelCompanyTools;
} }
} }

View File

@ -17,17 +17,21 @@ namespace Catamaran
private AbstractCompany? _company = null; private AbstractCompany? _company = null;
private readonly StorageCollection<DrawingBoat> _storageCollection;
public FormBoatColletion() public FormBoatColletion()
{ {
InitializeComponent(); InitializeComponent();
_storageCollection = new();
} }
private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) private void InstrumentBox_SelectedIndexChanged(object sender, EventArgs e)
{ {
panelCompanyTools.Enabled = false; switch (InstrumentBox.Text)
{
case "Хранилище":
_company = new Harbor(pictureBox.Width, pictureBox.Height, new ArrayGenericObjects<DrawingBoat>());
break;
}
} }
private void CreateObject(string type) private void CreateObject(string type)
@ -129,10 +133,10 @@ namespace Catamaran
DrawingBoat? boat = null; DrawingBoat? boat = null;
int counter = 100; int counter = 100;
while (boat == null) while (boat == null)
{ {
boat = _company.GetRandomObject(); boat = _company.GetRandomObject();
counter--; counter--;
if (counter <= 0) break; if (counter <= 0) break;
} }
@ -148,83 +152,5 @@ namespace Catamaran
}; };
form.ShowDialog(); form.ShowDialog();
} }
private void RefreshListBoxItems()
{
listBoxCollection.Items.Clear();
for (int i = 0; i < _storageCollection.Keys?.Count; ++i)
{
string? colName = _storageCollection.Keys?[i];
if (!string.IsNullOrEmpty(colName) )
{
listBoxCollection.Items.Add(colName);
}
}
}
private void buttonCollectionAdd_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonArray.Checked && !radioButtonList.Checked))
{
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
CollectionType collectionType = CollectionType.None;
if (radioButtonArray.Checked)
{
collectionType = CollectionType.Array;
}
else if (radioButtonList.Checked)
{
collectionType = CollectionType.List;
}
_storageCollection.AddCollection(textBoxCollectionName.Text, collectionType);
RefreshListBoxItems();
}
private void buttonCollectionDelete_Click(object sender, EventArgs e)
{
if (listBoxCollection.SelectedItem == null || listBoxCollection.SelectedIndex < 0)
{
MessageBox.Show("Не выбрана коллекция");
return;
}
if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
_storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
RefreshListBoxItems();
}
private void buttonCompanyCreate_Click(object sender, EventArgs e)
{
if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
{
MessageBox.Show("Коллекция не выбрана");
return;
}
ICollectionGenericObjects<DrawingBoat>? collection = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
if (collection == null)
{
MessageBox.Show("Коллекция не инициализирована");
return;
}
switch (comboBoxSelectorCompany.Text)
{
case "Хранилище":
_company = new Harbor(pictureBox.Width, pictureBox.Height, collection);
break;
}
panelCompanyTools.Enabled = true;
RefreshListBoxItems();
}
} }
} }