collections
This commit is contained in:
parent
b822f2ef79
commit
0498d0da74
@ -1,5 +1,5 @@
|
|||||||
using ProjectCruiser.DrawningSamples;
|
using ProjectCruiser.DrawningSamples;
|
||||||
namespace ProjectCruiser;
|
namespace ProjectCruiser.CollectionGenericObj;
|
||||||
|
|
||||||
/// Абстракция компании, хранящий коллекцию автомобилей
|
/// Абстракция компании, хранящий коллекцию автомобилей
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -31,12 +31,12 @@ public abstract class AbstractCompany
|
|||||||
|
|
||||||
// Перегрузка оператора сложения для класса
|
// Перегрузка оператора сложения для класса
|
||||||
// [ ! ] insted of bool:
|
// [ ! ] insted of bool:
|
||||||
public static int operator +(AbstractCompany cmp,
|
public static int operator +(AbstractCompany company,
|
||||||
DrawningBase trasport) => (cmp._collection.Insert(trasport));
|
DrawningBase trasport) => company._collection.Insert(trasport);
|
||||||
|
|
||||||
// Перегрузка оператора удаления для класса
|
// Перегрузка оператора удаления для класса
|
||||||
public static DrawningBase operator -(AbstractCompany cmp,
|
public static DrawningBase operator -(AbstractCompany company,
|
||||||
int pos) => (cmp._collection.Remove(pos));
|
int pos) => company._collection.Remove(pos);
|
||||||
|
|
||||||
// Получение случайного объекта из коллекции
|
// Получение случайного объекта из коллекции
|
||||||
public DrawningBase? GetRandomObject()
|
public DrawningBase? GetRandomObject()
|
@ -1,4 +1,4 @@
|
|||||||
namespace ProjectCruiser;
|
namespace ProjectCruiser.CollectionGenericObj;
|
||||||
|
|
||||||
public class ArrayGenObj<T> : ICollectionGenObj<T>
|
public class ArrayGenObj<T> : ICollectionGenObj<T>
|
||||||
where T : class
|
where T : class
|
||||||
@ -8,7 +8,7 @@ public class ArrayGenObj<T> : ICollectionGenObj<T>
|
|||||||
public int Count => _collection.Length;
|
public int Count => _collection.Length;
|
||||||
public int SetMaxCount
|
public int SetMaxCount
|
||||||
{
|
{
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value > 0)
|
if (value > 0)
|
||||||
{
|
{
|
||||||
@ -64,7 +64,7 @@ public class ArrayGenObj<T> : ICollectionGenObj<T>
|
|||||||
|
|
||||||
for (int i = 0; i < Count; i++)
|
for (int i = 0; i < Count; i++)
|
||||||
{
|
{
|
||||||
if (_collection[i] == null
|
if (_collection[i] == null
|
||||||
&& min_diff > Math.Abs(index - i))
|
&& min_diff > Math.Abs(index - i))
|
||||||
{
|
{
|
||||||
min_diff = Math.Abs(index - i);
|
min_diff = Math.Abs(index - i);
|
8
ProjectCruiser/CollectionGenericObj/CollectionType.cs
Normal file
8
ProjectCruiser/CollectionGenericObj/CollectionType.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
namespace ProjectCruiser.CollectionGenericObj;
|
||||||
|
|
||||||
|
public enum CollectionType
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
Array = 1,
|
||||||
|
List = 2
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
namespace ProjectCruiser;
|
namespace ProjectCruiser.CollectionGenericObj;
|
||||||
|
|
||||||
public interface ICollectionGenObj<T> where T : class
|
public interface ICollectionGenObj<T> where T : class
|
||||||
{
|
{
|
@ -1,10 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
namespace ProjectCruiser;
|
namespace ProjectCruiser.CollectionGenericObj;
|
||||||
|
|
||||||
// Параметризованный набор объектов
|
// Параметризованный набор объектов
|
||||||
public class ListGenericObjects<T> : ICollectionGenObj<T>
|
public class ListGenObj<T> : ICollectionGenObj<T>
|
||||||
where T : class
|
where T : class
|
||||||
{
|
{
|
||||||
// Список объектов, которые храним
|
// Список объектов, которые храним
|
||||||
@ -16,14 +16,14 @@ public class ListGenericObjects<T> : ICollectionGenObj<T>
|
|||||||
|
|
||||||
public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } }
|
public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } }
|
||||||
|
|
||||||
public ListGenericObjects()
|
public ListGenObj()
|
||||||
{
|
{
|
||||||
_collection = new();
|
_collection = new();
|
||||||
}
|
}
|
||||||
|
|
||||||
public T? GetItem(int position)
|
public T? GetItem(int position)
|
||||||
{
|
{
|
||||||
if (position > _maxCount - 1 || position < 0)
|
if (position >= Count || position < 0)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -33,18 +33,20 @@ public class ListGenericObjects<T> : ICollectionGenObj<T>
|
|||||||
|
|
||||||
public int Insert(T obj)
|
public int Insert(T obj)
|
||||||
{
|
{
|
||||||
if (Count + 1 < _maxCount || obj == null)
|
if (Count >= _maxCount || obj == null)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
_collection.Add(obj);
|
_collection.Add(obj);
|
||||||
return Count;
|
return Count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Insert(T obj, int position)
|
public int Insert(T obj, int position)
|
||||||
{
|
{
|
||||||
if (position >= _maxCount || position < 0 ||
|
if (position >= _maxCount || Count >= _maxCount ||
|
||||||
_collection[position] != null)
|
position < 0 || _collection[position] != null
|
||||||
|
|| obj == null)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -56,7 +58,7 @@ public class ListGenericObjects<T> : ICollectionGenObj<T>
|
|||||||
public T? Remove(int position)
|
public T? Remove(int position)
|
||||||
{
|
{
|
||||||
if (position >= Count || position < 0)
|
if (position >= Count || position < 0)
|
||||||
// on the other positions items don't exist
|
// on the other positions items don't exist
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
@ -1,5 +1,5 @@
|
|||||||
using ProjectCruiser.DrawningSamples;
|
using ProjectCruiser.DrawningSamples;
|
||||||
namespace ProjectCruiser;
|
namespace ProjectCruiser.CollectionGenericObj;
|
||||||
|
|
||||||
public class ShipSharingService : AbstractCompany
|
public class ShipSharingService : AbstractCompany
|
||||||
{
|
{
|
57
ProjectCruiser/CollectionGenericObj/StorageCollection.cs
Normal file
57
ProjectCruiser/CollectionGenericObj/StorageCollection.cs
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
namespace ProjectCruiser.CollectionGenericObj;
|
||||||
|
|
||||||
|
public class StorageCollection<T>
|
||||||
|
where T : class
|
||||||
|
{
|
||||||
|
// Словарь (хранилище) с коллекциями < name, type (class) >
|
||||||
|
readonly Dictionary<string, ICollectionGenObj<T>> _storages;
|
||||||
|
|
||||||
|
// Возвращение списка названий коллекций
|
||||||
|
public List<string> Keys => _storages.Keys.ToList();
|
||||||
|
|
||||||
|
public StorageCollection()
|
||||||
|
{
|
||||||
|
_storages = new Dictionary<string, ICollectionGenObj<T>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Добавление коллекции в хранилище
|
||||||
|
/// <param name="name">Название коллекции</param>
|
||||||
|
/// <param name="collectionType">тип коллекции</param>
|
||||||
|
public void AddCollection(string name, CollectionType collType)
|
||||||
|
{
|
||||||
|
if (name == null || _storages.ContainsKey(name)
|
||||||
|
|| collType == CollectionType.None)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (collType)
|
||||||
|
{
|
||||||
|
case CollectionType.List: _storages.Add(name, new ListGenObj<T>()); break;
|
||||||
|
// _storages[name] = new ListGenericObjects<T>(); break; [*]
|
||||||
|
|
||||||
|
case CollectionType.Array: _storages.Add(name, new ArrayGenObj<T>()); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Удаление коллекции ( по ключу-строке - её имени )
|
||||||
|
/// <param name="name">Название коллекции</param>
|
||||||
|
public void DelCollection(string name)
|
||||||
|
{
|
||||||
|
if (_storages.ContainsKey(name)) _storages.Remove(name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Доступ к коллекции ( по ключу-строке - её имени )
|
||||||
|
public ICollectionGenObj<T>? this[string name]
|
||||||
|
{
|
||||||
|
get => _storages.ContainsKey(name) ? _storages[name] : null;
|
||||||
|
/* ^^^
|
||||||
|
{
|
||||||
|
if (_storages.ContainsKey(name)) return _storages[name];
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,10 +1,4 @@
|
|||||||
using System;
|
namespace ProjectCruiser.MoveStrategy;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ProjectCruiser.MoveStrategy;
|
|
||||||
|
|
||||||
public class MoveToBorder : AbstractStrategy
|
public class MoveToBorder : AbstractStrategy
|
||||||
{
|
{
|
||||||
|
198
ProjectCruiser/ServiceForm2.Designer.cs
generated
198
ProjectCruiser/ServiceForm2.Designer.cs
generated
@ -31,26 +31,26 @@
|
|||||||
comboBoxArrList = new ComboBox();
|
comboBoxArrList = new ComboBox();
|
||||||
btnAddBase = new Button();
|
btnAddBase = new Button();
|
||||||
groupBox = new GroupBox();
|
groupBox = new GroupBox();
|
||||||
|
toolPanel = new Panel();
|
||||||
btnUpdate = new Button();
|
btnUpdate = new Button();
|
||||||
btnTest = new Button();
|
btnTest = new Button();
|
||||||
btnDelete = new Button();
|
|
||||||
maskedTextBoxPosition = new MaskedTextBox();
|
maskedTextBoxPosition = new MaskedTextBox();
|
||||||
|
btnDelete = new Button();
|
||||||
btnAddCruiser = new Button();
|
btnAddCruiser = new Button();
|
||||||
|
btnCreateCompany = new Button();
|
||||||
pictureBox = new PictureBox();
|
pictureBox = new PictureBox();
|
||||||
companyPanel = new Panel();
|
companyPanel = new Panel();
|
||||||
label = new Label();
|
|
||||||
maskedTxtBoxCName = new MaskedTextBox();
|
|
||||||
rBtnArray = new RadioButton();
|
|
||||||
rBtnList = new RadioButton();
|
|
||||||
btnAddCollection = new Button();
|
|
||||||
listBox = new ListBox();
|
|
||||||
btnDeleteCollection = new Button();
|
btnDeleteCollection = new Button();
|
||||||
btnCreateCompany = new Button();
|
listBox = new ListBox();
|
||||||
toolPanel = new Panel();
|
btnAddCollection = new Button();
|
||||||
|
rBtnList = new RadioButton();
|
||||||
|
rBtnArray = new RadioButton();
|
||||||
|
maskedTxtBoxCName = new MaskedTextBox();
|
||||||
|
label = new Label();
|
||||||
groupBox.SuspendLayout();
|
groupBox.SuspendLayout();
|
||||||
|
toolPanel.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||||
companyPanel.SuspendLayout();
|
companyPanel.SuspendLayout();
|
||||||
toolPanel.SuspendLayout();
|
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// comboBoxArrList
|
// comboBoxArrList
|
||||||
@ -60,7 +60,7 @@
|
|||||||
comboBoxArrList.Items.AddRange(new object[] { "Storage" });
|
comboBoxArrList.Items.AddRange(new object[] { "Storage" });
|
||||||
comboBoxArrList.Location = new Point(17, 41);
|
comboBoxArrList.Location = new Point(17, 41);
|
||||||
comboBoxArrList.Name = "comboBoxArrList";
|
comboBoxArrList.Name = "comboBoxArrList";
|
||||||
comboBoxArrList.Size = new Size(243, 40);
|
comboBoxArrList.Size = new Size(241, 40);
|
||||||
comboBoxArrList.TabIndex = 0;
|
comboBoxArrList.TabIndex = 0;
|
||||||
comboBoxArrList.SelectedIndexChanged += SelectorCompany_SelectedIndexChanged;
|
comboBoxArrList.SelectedIndexChanged += SelectorCompany_SelectedIndexChanged;
|
||||||
//
|
//
|
||||||
@ -78,16 +78,31 @@
|
|||||||
// groupBox
|
// groupBox
|
||||||
//
|
//
|
||||||
groupBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
groupBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
groupBox.Controls.Add(companyPanel);
|
||||||
groupBox.Controls.Add(toolPanel);
|
groupBox.Controls.Add(toolPanel);
|
||||||
groupBox.Controls.Add(btnCreateCompany);
|
groupBox.Controls.Add(btnCreateCompany);
|
||||||
groupBox.Controls.Add(comboBoxArrList);
|
groupBox.Controls.Add(comboBoxArrList);
|
||||||
groupBox.Location = new Point(1402, 12);
|
groupBox.Location = new Point(1421, 10);
|
||||||
groupBox.Name = "groupBox";
|
groupBox.Name = "groupBox";
|
||||||
groupBox.Size = new Size(275, 986);
|
groupBox.Size = new Size(273, 986);
|
||||||
groupBox.TabIndex = 2;
|
groupBox.TabIndex = 2;
|
||||||
groupBox.TabStop = false;
|
groupBox.TabStop = false;
|
||||||
groupBox.Text = "Tool panel";
|
groupBox.Text = "Tool panel";
|
||||||
//
|
//
|
||||||
|
// toolPanel
|
||||||
|
//
|
||||||
|
toolPanel.Controls.Add(btnUpdate);
|
||||||
|
toolPanel.Controls.Add(btnTest);
|
||||||
|
toolPanel.Controls.Add(maskedTextBoxPosition);
|
||||||
|
toolPanel.Controls.Add(btnDelete);
|
||||||
|
toolPanel.Controls.Add(btnAddCruiser);
|
||||||
|
toolPanel.Controls.Add(btnAddBase);
|
||||||
|
toolPanel.Enabled = false;
|
||||||
|
toolPanel.Location = new Point(26, 593);
|
||||||
|
toolPanel.Name = "toolPanel";
|
||||||
|
toolPanel.Size = new Size(226, 377);
|
||||||
|
toolPanel.TabIndex = 13;
|
||||||
|
//
|
||||||
// btnUpdate
|
// btnUpdate
|
||||||
//
|
//
|
||||||
btnUpdate.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
btnUpdate.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
@ -110,6 +125,16 @@
|
|||||||
btnTest.UseVisualStyleBackColor = true;
|
btnTest.UseVisualStyleBackColor = true;
|
||||||
btnTest.Click += btnChooseforTest_Click;
|
btnTest.Click += btnChooseforTest_Click;
|
||||||
//
|
//
|
||||||
|
// maskedTextBoxPosition
|
||||||
|
//
|
||||||
|
maskedTextBoxPosition.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
maskedTextBoxPosition.Location = new Point(17, 119);
|
||||||
|
maskedTextBoxPosition.Mask = "00";
|
||||||
|
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||||
|
maskedTextBoxPosition.Size = new Size(192, 39);
|
||||||
|
maskedTextBoxPosition.TabIndex = 3;
|
||||||
|
maskedTextBoxPosition.ValidatingType = typeof(int);
|
||||||
|
//
|
||||||
// btnDelete
|
// btnDelete
|
||||||
//
|
//
|
||||||
btnDelete.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
btnDelete.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
@ -121,16 +146,6 @@
|
|||||||
btnDelete.UseVisualStyleBackColor = true;
|
btnDelete.UseVisualStyleBackColor = true;
|
||||||
btnDelete.Click += btnRemoveCar_Click;
|
btnDelete.Click += btnRemoveCar_Click;
|
||||||
//
|
//
|
||||||
// maskedTextBoxPosition
|
|
||||||
//
|
|
||||||
maskedTextBoxPosition.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
|
||||||
maskedTextBoxPosition.Location = new Point(17, 119);
|
|
||||||
maskedTextBoxPosition.Mask = "00";
|
|
||||||
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
|
||||||
maskedTextBoxPosition.Size = new Size(192, 39);
|
|
||||||
maskedTextBoxPosition.TabIndex = 3;
|
|
||||||
maskedTextBoxPosition.ValidatingType = typeof(int);
|
|
||||||
//
|
|
||||||
// btnAddCruiser
|
// btnAddCruiser
|
||||||
//
|
//
|
||||||
btnAddCruiser.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
btnAddCruiser.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
@ -142,12 +157,23 @@
|
|||||||
btnAddCruiser.UseVisualStyleBackColor = true;
|
btnAddCruiser.UseVisualStyleBackColor = true;
|
||||||
btnAddCruiser.Click += btnAddAdvanced_Click;
|
btnAddCruiser.Click += btnAddAdvanced_Click;
|
||||||
//
|
//
|
||||||
|
// btnCreateCompany
|
||||||
|
//
|
||||||
|
btnCreateCompany.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
btnCreateCompany.Location = new Point(17, 526);
|
||||||
|
btnCreateCompany.Name = "btnCreateCompany";
|
||||||
|
btnCreateCompany.Size = new Size(243, 61);
|
||||||
|
btnCreateCompany.TabIndex = 12;
|
||||||
|
btnCreateCompany.Text = "Create Company";
|
||||||
|
btnCreateCompany.UseVisualStyleBackColor = true;
|
||||||
|
btnCreateCompany.Click += btnCreateCompany_Click;
|
||||||
|
//
|
||||||
// pictureBox
|
// pictureBox
|
||||||
//
|
//
|
||||||
pictureBox.Dock = DockStyle.Left;
|
pictureBox.Dock = DockStyle.Left;
|
||||||
pictureBox.Location = new Point(0, 0);
|
pictureBox.Location = new Point(0, 0);
|
||||||
pictureBox.Name = "pictureBox";
|
pictureBox.Name = "pictureBox";
|
||||||
pictureBox.Size = new Size(1385, 1007);
|
pictureBox.Size = new Size(1415, 1007);
|
||||||
pictureBox.TabIndex = 3;
|
pictureBox.TabIndex = 3;
|
||||||
pictureBox.TabStop = false;
|
pictureBox.TabStop = false;
|
||||||
//
|
//
|
||||||
@ -160,38 +186,40 @@
|
|||||||
companyPanel.Controls.Add(rBtnArray);
|
companyPanel.Controls.Add(rBtnArray);
|
||||||
companyPanel.Controls.Add(maskedTxtBoxCName);
|
companyPanel.Controls.Add(maskedTxtBoxCName);
|
||||||
companyPanel.Controls.Add(label);
|
companyPanel.Controls.Add(label);
|
||||||
companyPanel.Location = new Point(1419, 101);
|
companyPanel.Location = new Point(17, 91);
|
||||||
companyPanel.Name = "panel1";
|
companyPanel.Name = "companyPanel";
|
||||||
companyPanel.Size = new Size(243, 429);
|
companyPanel.Size = new Size(243, 429);
|
||||||
companyPanel.TabIndex = 7;
|
companyPanel.TabIndex = 7;
|
||||||
//
|
//
|
||||||
// label
|
// btnDeleteCollection
|
||||||
//
|
//
|
||||||
label.AutoSize = true;
|
btnDeleteCollection.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
label.Location = new Point(29, 6);
|
btnDeleteCollection.Location = new Point(15, 371);
|
||||||
label.Name = "label";
|
btnDeleteCollection.Name = "btnDeleteCollection";
|
||||||
label.Size = new Size(188, 32);
|
btnDeleteCollection.Size = new Size(214, 43);
|
||||||
label.TabIndex = 0;
|
btnDeleteCollection.TabIndex = 11;
|
||||||
label.Text = "Collection name";
|
btnDeleteCollection.Text = "Remove Collection";
|
||||||
|
btnDeleteCollection.UseVisualStyleBackColor = true;
|
||||||
|
btnDeleteCollection.Click += btnCollectionDel_Click;
|
||||||
//
|
//
|
||||||
// maskedTxtBoxCName
|
// listBox
|
||||||
//
|
//
|
||||||
maskedTxtBoxCName.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
listBox.FormattingEnabled = true;
|
||||||
maskedTxtBoxCName.Location = new Point(16, 43);
|
listBox.Location = new Point(16, 199);
|
||||||
maskedTxtBoxCName.Name = "maskedTextBox1";
|
listBox.Name = "listBox";
|
||||||
maskedTxtBoxCName.Size = new Size(214, 39);
|
listBox.Size = new Size(214, 164);
|
||||||
maskedTxtBoxCName.TabIndex = 7;
|
listBox.TabIndex = 10;
|
||||||
//
|
//
|
||||||
// rBtnArray
|
// btnAddCollection
|
||||||
//
|
//
|
||||||
rBtnArray.AutoSize = true;
|
btnAddCollection.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
rBtnArray.Location = new Point(16, 88);
|
btnAddCollection.Location = new Point(15, 130);
|
||||||
rBtnArray.Name = "rBtnArray";
|
btnAddCollection.Name = "btnAddCollection";
|
||||||
rBtnArray.Size = new Size(100, 36);
|
btnAddCollection.Size = new Size(214, 61);
|
||||||
rBtnArray.TabIndex = 8;
|
btnAddCollection.TabIndex = 7;
|
||||||
rBtnArray.TabStop = true;
|
btnAddCollection.Text = "Add Collection";
|
||||||
rBtnArray.Text = "Array";
|
btnAddCollection.UseVisualStyleBackColor = true;
|
||||||
rBtnArray.UseVisualStyleBackColor = true;
|
btnAddCollection.Click += btnCollectionAdd_Click;
|
||||||
//
|
//
|
||||||
// rBtnList
|
// rBtnList
|
||||||
//
|
//
|
||||||
@ -204,73 +232,49 @@
|
|||||||
rBtnList.Text = "List";
|
rBtnList.Text = "List";
|
||||||
rBtnList.UseVisualStyleBackColor = true;
|
rBtnList.UseVisualStyleBackColor = true;
|
||||||
//
|
//
|
||||||
// btnAddCollection
|
// rBtnArray
|
||||||
//
|
//
|
||||||
btnAddCollection.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
rBtnArray.AutoSize = true;
|
||||||
btnAddCollection.Location = new Point(15, 130);
|
rBtnArray.Location = new Point(16, 88);
|
||||||
btnAddCollection.Name = "btnAddCollection";
|
rBtnArray.Name = "rBtnArray";
|
||||||
btnAddCollection.Size = new Size(214, 61);
|
rBtnArray.Size = new Size(100, 36);
|
||||||
btnAddCollection.TabIndex = 7;
|
rBtnArray.TabIndex = 8;
|
||||||
btnAddCollection.Text = "Add Collection";
|
rBtnArray.TabStop = true;
|
||||||
btnAddCollection.UseVisualStyleBackColor = true;
|
rBtnArray.Text = "Array";
|
||||||
|
rBtnArray.UseVisualStyleBackColor = true;
|
||||||
//
|
//
|
||||||
// listBox1
|
// maskedTxtBoxCName
|
||||||
//
|
//
|
||||||
listBox.FormattingEnabled = true;
|
maskedTxtBoxCName.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
listBox.Location = new Point(16, 199);
|
maskedTxtBoxCName.Location = new Point(16, 43);
|
||||||
listBox.Name = "listBox1";
|
maskedTxtBoxCName.Name = "maskedTxtBoxCName";
|
||||||
listBox.Size = new Size(214, 164);
|
maskedTxtBoxCName.Size = new Size(214, 39);
|
||||||
listBox.TabIndex = 10;
|
maskedTxtBoxCName.TabIndex = 7;
|
||||||
//
|
//
|
||||||
// btnDeleteCollection
|
// label
|
||||||
//
|
//
|
||||||
btnDeleteCollection.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
label.AutoSize = true;
|
||||||
btnDeleteCollection.Location = new Point(15, 371);
|
label.Location = new Point(29, 6);
|
||||||
btnDeleteCollection.Name = "btnDeleteCollection";
|
label.Name = "label";
|
||||||
btnDeleteCollection.Size = new Size(214, 43);
|
label.Size = new Size(188, 32);
|
||||||
btnDeleteCollection.TabIndex = 11;
|
label.TabIndex = 0;
|
||||||
btnDeleteCollection.Text = "Remove Collection";
|
label.Text = "Collection name";
|
||||||
btnDeleteCollection.UseVisualStyleBackColor = true;
|
|
||||||
//
|
|
||||||
// btnCreateCompany
|
|
||||||
//
|
|
||||||
btnCreateCompany.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
|
||||||
btnCreateCompany.Location = new Point(17, 526);
|
|
||||||
btnCreateCompany.Name = "btnCreateCompany";
|
|
||||||
btnCreateCompany.Size = new Size(243, 61);
|
|
||||||
btnCreateCompany.TabIndex = 12;
|
|
||||||
btnCreateCompany.Text = "Create Company";
|
|
||||||
btnCreateCompany.UseVisualStyleBackColor = true;
|
|
||||||
//
|
|
||||||
// toolPanel
|
|
||||||
//
|
|
||||||
toolPanel.Controls.Add(btnUpdate);
|
|
||||||
toolPanel.Controls.Add(btnTest);
|
|
||||||
toolPanel.Controls.Add(maskedTextBoxPosition);
|
|
||||||
toolPanel.Controls.Add(btnDelete);
|
|
||||||
toolPanel.Controls.Add(btnAddCruiser);
|
|
||||||
toolPanel.Controls.Add(btnAddBase);
|
|
||||||
toolPanel.Location = new Point(26, 596);
|
|
||||||
toolPanel.Name = "panel2";
|
|
||||||
toolPanel.Size = new Size(226, 377);
|
|
||||||
toolPanel.TabIndex = 13;
|
|
||||||
//
|
//
|
||||||
// ServiceForm2
|
// ServiceForm2
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(13F, 32F);
|
AutoScaleDimensions = new SizeF(13F, 32F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(1689, 1007);
|
ClientSize = new Size(1700, 1007);
|
||||||
Controls.Add(companyPanel);
|
|
||||||
Controls.Add(pictureBox);
|
Controls.Add(pictureBox);
|
||||||
Controls.Add(groupBox);
|
Controls.Add(groupBox);
|
||||||
Name = "ServiceForm2";
|
Name = "ServiceForm2";
|
||||||
Text = "ServiceForm2";
|
Text = "ServiceForm2";
|
||||||
groupBox.ResumeLayout(false);
|
groupBox.ResumeLayout(false);
|
||||||
|
toolPanel.ResumeLayout(false);
|
||||||
|
toolPanel.PerformLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||||
companyPanel.ResumeLayout(false);
|
companyPanel.ResumeLayout(false);
|
||||||
companyPanel.PerformLayout();
|
companyPanel.PerformLayout();
|
||||||
toolPanel.ResumeLayout(false);
|
|
||||||
toolPanel.PerformLayout();
|
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,20 +1,28 @@
|
|||||||
using System.Windows.Forms;
|
using System.Collections.Generic;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
using ProjectCruiser.CollectionGenericObj;
|
||||||
using ProjectCruiser.DrawningSamples;
|
using ProjectCruiser.DrawningSamples;
|
||||||
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||||
namespace ProjectCruiser;
|
namespace ProjectCruiser;
|
||||||
|
|
||||||
public partial class ServiceForm2 : Form
|
public partial class ServiceForm2 : Form
|
||||||
{
|
{
|
||||||
// Компания
|
// Компания
|
||||||
private AbstractCompany? _company;
|
private AbstractCompany? _company = null;
|
||||||
|
|
||||||
|
private readonly StorageCollection<DrawningBase> _storageCollection;
|
||||||
|
|
||||||
public ServiceForm2()
|
public ServiceForm2()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_company = null;
|
_storageCollection = new();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Выбор компании
|
// Выбор компании
|
||||||
private void SelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
|
private void SelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
switch (comboBoxArrList.Text)
|
switch (comboBoxArrList.Text)
|
||||||
{
|
{
|
||||||
case "Storage":
|
case "Storage":
|
||||||
@ -22,6 +30,9 @@ public partial class ServiceForm2 : Form
|
|||||||
new ArrayGenObj<DrawningBase>());
|
new ArrayGenObj<DrawningBase>());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
toolPanel.Enabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Color picker (default : random)
|
// Color picker (default : random)
|
||||||
@ -62,7 +73,6 @@ public partial class ServiceForm2 : Form
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case nameof(DrawningCruiser):
|
case nameof(DrawningCruiser):
|
||||||
// (TODO) вызов диалогового окна для выбора цвета >>>
|
|
||||||
drawningCar = new DrawningCruiser(random.Next(100, 300),
|
drawningCar = new DrawningCruiser(random.Next(100, 300),
|
||||||
random.Next(1000, 3000), pickColor(random), pickColor(random),
|
random.Next(1000, 3000), pickColor(random), pickColor(random),
|
||||||
Convert.ToBoolean(random.Next(0, 2)));
|
Convert.ToBoolean(random.Next(0, 2)));
|
||||||
@ -136,5 +146,83 @@ public partial class ServiceForm2 : Form
|
|||||||
pictureBox.Image = _company.Show();
|
pictureBox.Image = _company.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
// continue
|
private void btnCollectionAdd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(maskedTxtBoxCName.Text) || (!rBtnList.Checked && !rBtnArray.Checked))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Enter correct data or choose an option", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CollectionType collType = CollectionType.None;
|
||||||
|
|
||||||
|
if (rBtnArray.Checked)
|
||||||
|
{
|
||||||
|
collType = CollectionType.Array;
|
||||||
|
}
|
||||||
|
else if (rBtnList.Checked)
|
||||||
|
{
|
||||||
|
collType = CollectionType.List;
|
||||||
|
}
|
||||||
|
|
||||||
|
_storageCollection.AddCollection(maskedTxtBoxCName.Text, collType);
|
||||||
|
RefreshListBoxItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void btnCollectionDel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBox.SelectedItem == null || listBox.SelectedIndex < 0)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Collection was not choosed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show("Are you sure?", "Removing", MessageBoxButtons.OK, MessageBoxIcon.Question) != DialogResult.OK)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_storageCollection.DelCollection(listBox.SelectedItem.ToString());
|
||||||
|
RefreshListBoxItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RefreshListBoxItems()
|
||||||
|
{
|
||||||
|
listBox.Items.Clear();
|
||||||
|
for (int i = 0; i < _storageCollection.Keys?.Count; ++i)
|
||||||
|
{
|
||||||
|
string? collName = _storageCollection.Keys?[i];
|
||||||
|
if (!string.IsNullOrEmpty(collName))
|
||||||
|
{
|
||||||
|
listBox.Items.Add(collName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void btnCreateCompany_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBox.SelectedIndex < 0 || listBox.SelectedItem == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Collection wasn't choosed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ICollectionGenObj<DrawningBase>? collection =
|
||||||
|
_storageCollection[listBox.SelectedItem.ToString() ?? string.Empty];
|
||||||
|
|
||||||
|
if (collection == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Collection wasn't initialized");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (comboBoxArrList.Text)
|
||||||
|
{
|
||||||
|
case "Storage":
|
||||||
|
_company = new ShipSharingService(pictureBox.Width,
|
||||||
|
pictureBox.Height, collection);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
toolPanel.Enabled = true; // block of buttons at the right bottom
|
||||||
|
RefreshListBoxItems();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user