Compare commits

..

No commits in common. "0498d0da74fadd6ca3e48800dd2c87c8860f76ed" and "a6ff38c3e47c60c71aaf317598e191b5ecd70aa9" have entirely different histories.

10 changed files with 61 additions and 410 deletions

View File

@ -1,5 +1,5 @@
using ProjectCruiser.DrawningSamples;
namespace ProjectCruiser.CollectionGenericObj;
namespace ProjectCruiser;
/// Абстракция компании, хранящий коллекцию автомобилей
/// </summary>
@ -31,12 +31,12 @@ public abstract class AbstractCompany
// Перегрузка оператора сложения для класса
// [ ! ] insted of bool:
public static int operator +(AbstractCompany company,
DrawningBase trasport) => company._collection.Insert(trasport);
public static int operator +(AbstractCompany cmp,
DrawningBase trasport) => (cmp._collection.Insert(trasport));
// Перегрузка оператора удаления для класса
public static DrawningBase operator -(AbstractCompany company,
int pos) => company._collection.Remove(pos);
public static DrawningBase operator -(AbstractCompany cmp,
int pos) => (cmp._collection.Remove(pos));
// Получение случайного объекта из коллекции
public DrawningBase? GetRandomObject()

View File

@ -1,4 +1,4 @@
namespace ProjectCruiser.CollectionGenericObj;
namespace ProjectCruiser;
public class ArrayGenObj<T> : ICollectionGenObj<T>
where T : class
@ -8,7 +8,7 @@ public class ArrayGenObj<T> : ICollectionGenObj<T>
public int Count => _collection.Length;
public int SetMaxCount
{
set
set
{
if (value > 0)
{
@ -64,7 +64,7 @@ public class ArrayGenObj<T> : ICollectionGenObj<T>
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);

View File

@ -1,8 +0,0 @@
namespace ProjectCruiser.CollectionGenericObj;
public enum CollectionType
{
None = 0,
Array = 1,
List = 2
}

View File

@ -1,70 +0,0 @@
using System;
using System.Reflection;
namespace ProjectCruiser.CollectionGenericObj;
// Параметризованный набор объектов
public class ListGenObj<T> : ICollectionGenObj<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 ListGenObj()
{
_collection = new();
}
public T? GetItem(int position)
{
if (position >= Count || position < 0)
{
return null;
}
return _collection[position];
}
public int Insert(T obj)
{
if (Count >= _maxCount || obj == null)
{
return -1;
}
_collection.Add(obj);
return Count;
}
public int Insert(T obj, int position)
{
if (position >= _maxCount || Count >= _maxCount ||
position < 0 || _collection[position] != null
|| obj == null)
{
return -1;
}
_collection.Insert(position, obj);
return position;
}
public T? Remove(int position)
{
if (position >= Count || position < 0)
// on the other positions items don't exist
{
return null;
}
T? item = _collection[position];
_collection.RemoveAt(position);
return item;
}
}

View File

@ -1,57 +0,0 @@
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;
}
*/
}
}

View File

@ -1,4 +1,4 @@
namespace ProjectCruiser.CollectionGenericObj;
namespace ProjectCruiser;
public interface ICollectionGenObj<T> where T : class
{

View File

@ -1,4 +1,10 @@
namespace ProjectCruiser.MoveStrategy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectCruiser.MoveStrategy;
public class MoveToBorder : AbstractStrategy
{

View File

@ -31,26 +31,14 @@
comboBoxArrList = new ComboBox();
btnAddBase = new Button();
groupBox = new GroupBox();
toolPanel = new Panel();
btnUpdate = new Button();
btnTest = new Button();
maskedTextBoxPosition = new MaskedTextBox();
btnDelete = new Button();
maskedTextBoxPosition = new MaskedTextBox();
btnAddCruiser = new Button();
btnCreateCompany = new Button();
pictureBox = new PictureBox();
companyPanel = new Panel();
btnDeleteCollection = new Button();
listBox = new ListBox();
btnAddCollection = new Button();
rBtnList = new RadioButton();
rBtnArray = new RadioButton();
maskedTxtBoxCName = new MaskedTextBox();
label = new Label();
groupBox.SuspendLayout();
toolPanel.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
companyPanel.SuspendLayout();
SuspendLayout();
//
// comboBoxArrList
@ -58,18 +46,18 @@
comboBoxArrList.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
comboBoxArrList.FormattingEnabled = true;
comboBoxArrList.Items.AddRange(new object[] { "Storage" });
comboBoxArrList.Location = new Point(17, 41);
comboBoxArrList.Location = new Point(17, 54);
comboBoxArrList.Name = "comboBoxArrList";
comboBoxArrList.Size = new Size(241, 40);
comboBoxArrList.Size = new Size(268, 40);
comboBoxArrList.TabIndex = 0;
comboBoxArrList.SelectedIndexChanged += SelectorCompany_SelectedIndexChanged;
//
// btnAddBase
//
btnAddBase.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
btnAddBase.Location = new Point(17, 13);
btnAddBase.Location = new Point(17, 561);
btnAddBase.Name = "btnAddBase";
btnAddBase.Size = new Size(192, 43);
btnAddBase.Size = new Size(268, 46);
btnAddBase.TabIndex = 1;
btnAddBase.Text = "Add ship";
btnAddBase.UseVisualStyleBackColor = true;
@ -78,37 +66,26 @@
// groupBox
//
groupBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
groupBox.Controls.Add(companyPanel);
groupBox.Controls.Add(toolPanel);
groupBox.Controls.Add(btnCreateCompany);
groupBox.Controls.Add(btnUpdate);
groupBox.Controls.Add(btnTest);
groupBox.Controls.Add(btnDelete);
groupBox.Controls.Add(maskedTextBoxPosition);
groupBox.Controls.Add(btnAddCruiser);
groupBox.Controls.Add(btnAddBase);
groupBox.Controls.Add(comboBoxArrList);
groupBox.Location = new Point(1421, 10);
groupBox.Location = new Point(1437, 12);
groupBox.Name = "groupBox";
groupBox.Size = new Size(273, 986);
groupBox.Size = new Size(300, 938);
groupBox.TabIndex = 2;
groupBox.TabStop = false;
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.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
btnUpdate.Location = new Point(17, 315);
btnUpdate.Location = new Point(17, 865);
btnUpdate.Name = "btnUpdate";
btnUpdate.Size = new Size(192, 49);
btnUpdate.Size = new Size(268, 46);
btnUpdate.TabIndex = 6;
btnUpdate.Text = "Update";
btnUpdate.UseVisualStyleBackColor = true;
@ -117,164 +94,67 @@
// btnTest
//
btnTest.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
btnTest.Location = new Point(17, 224);
btnTest.Location = new Point(17, 795);
btnTest.Name = "btnTest";
btnTest.Size = new Size(192, 85);
btnTest.Size = new Size(268, 64);
btnTest.TabIndex = 5;
btnTest.Text = "Choose\r\nfor testing";
btnTest.Text = "Choose for testing";
btnTest.UseVisualStyleBackColor = true;
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.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
btnDelete.Location = new Point(17, 170);
btnDelete.Location = new Point(17, 732);
btnDelete.Name = "btnDelete";
btnDelete.Size = new Size(192, 48);
btnDelete.Size = new Size(268, 46);
btnDelete.TabIndex = 4;
btnDelete.Text = "Delete";
btnDelete.UseVisualStyleBackColor = true;
btnDelete.Click += btnRemoveCar_Click;
//
// maskedTextBoxPosition
//
maskedTextBoxPosition.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
maskedTextBoxPosition.Location = new Point(17, 682);
maskedTextBoxPosition.Mask = "00";
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
maskedTextBoxPosition.Size = new Size(268, 39);
maskedTextBoxPosition.TabIndex = 3;
maskedTextBoxPosition.ValidatingType = typeof(int);
//
// btnAddCruiser
//
btnAddCruiser.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
btnAddCruiser.Location = new Point(17, 62);
btnAddCruiser.Location = new Point(17, 613);
btnAddCruiser.Name = "btnAddCruiser";
btnAddCruiser.Size = new Size(192, 51);
btnAddCruiser.Size = new Size(268, 46);
btnAddCruiser.TabIndex = 2;
btnAddCruiser.Text = "Add cruiser";
btnAddCruiser.UseVisualStyleBackColor = true;
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.Dock = DockStyle.Left;
pictureBox.Location = new Point(0, 0);
pictureBox.Name = "pictureBox";
pictureBox.Size = new Size(1415, 1007);
pictureBox.Size = new Size(1417, 959);
pictureBox.TabIndex = 3;
pictureBox.TabStop = false;
//
// companyPanel
//
companyPanel.Controls.Add(btnDeleteCollection);
companyPanel.Controls.Add(listBox);
companyPanel.Controls.Add(btnAddCollection);
companyPanel.Controls.Add(rBtnList);
companyPanel.Controls.Add(rBtnArray);
companyPanel.Controls.Add(maskedTxtBoxCName);
companyPanel.Controls.Add(label);
companyPanel.Location = new Point(17, 91);
companyPanel.Name = "companyPanel";
companyPanel.Size = new Size(243, 429);
companyPanel.TabIndex = 7;
//
// btnDeleteCollection
//
btnDeleteCollection.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
btnDeleteCollection.Location = new Point(15, 371);
btnDeleteCollection.Name = "btnDeleteCollection";
btnDeleteCollection.Size = new Size(214, 43);
btnDeleteCollection.TabIndex = 11;
btnDeleteCollection.Text = "Remove Collection";
btnDeleteCollection.UseVisualStyleBackColor = true;
btnDeleteCollection.Click += btnCollectionDel_Click;
//
// listBox
//
listBox.FormattingEnabled = true;
listBox.Location = new Point(16, 199);
listBox.Name = "listBox";
listBox.Size = new Size(214, 164);
listBox.TabIndex = 10;
//
// btnAddCollection
//
btnAddCollection.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
btnAddCollection.Location = new Point(15, 130);
btnAddCollection.Name = "btnAddCollection";
btnAddCollection.Size = new Size(214, 61);
btnAddCollection.TabIndex = 7;
btnAddCollection.Text = "Add Collection";
btnAddCollection.UseVisualStyleBackColor = true;
btnAddCollection.Click += btnCollectionAdd_Click;
//
// rBtnList
//
rBtnList.AutoSize = true;
rBtnList.Location = new Point(150, 88);
rBtnList.Name = "rBtnList";
rBtnList.Size = new Size(80, 36);
rBtnList.TabIndex = 9;
rBtnList.TabStop = true;
rBtnList.Text = "List";
rBtnList.UseVisualStyleBackColor = true;
//
// rBtnArray
//
rBtnArray.AutoSize = true;
rBtnArray.Location = new Point(16, 88);
rBtnArray.Name = "rBtnArray";
rBtnArray.Size = new Size(100, 36);
rBtnArray.TabIndex = 8;
rBtnArray.TabStop = true;
rBtnArray.Text = "Array";
rBtnArray.UseVisualStyleBackColor = true;
//
// maskedTxtBoxCName
//
maskedTxtBoxCName.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
maskedTxtBoxCName.Location = new Point(16, 43);
maskedTxtBoxCName.Name = "maskedTxtBoxCName";
maskedTxtBoxCName.Size = new Size(214, 39);
maskedTxtBoxCName.TabIndex = 7;
//
// label
//
label.AutoSize = true;
label.Location = new Point(29, 6);
label.Name = "label";
label.Size = new Size(188, 32);
label.TabIndex = 0;
label.Text = "Collection name";
//
// ServiceForm2
//
AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1700, 1007);
ClientSize = new Size(1749, 959);
Controls.Add(pictureBox);
Controls.Add(groupBox);
Name = "ServiceForm2";
Text = "ServiceForm2";
groupBox.ResumeLayout(false);
toolPanel.ResumeLayout(false);
toolPanel.PerformLayout();
groupBox.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
companyPanel.ResumeLayout(false);
companyPanel.PerformLayout();
ResumeLayout(false);
}
@ -289,15 +169,5 @@
private Button btnDelete;
private MaskedTextBox maskedTextBoxPosition;
private PictureBox pictureBox;
private Panel companyPanel;
private RadioButton rBtnArray;
private MaskedTextBox maskedTxtBoxCName;
private Label label;
private RadioButton rBtnList;
private Button btnAddCollection;
private ListBox listBox;
private Button btnDeleteCollection;
private Button btnCreateCompany;
private Panel toolPanel;
}
}

View File

@ -1,28 +1,20 @@
using System.Collections.Generic;
using System.Windows.Forms;
using System.Xml.Linq;
using ProjectCruiser.CollectionGenericObj;
using System.Windows.Forms;
using ProjectCruiser.DrawningSamples;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace ProjectCruiser;
public partial class ServiceForm2 : Form
{
// Компания
private AbstractCompany? _company = null;
private readonly StorageCollection<DrawningBase> _storageCollection;
private AbstractCompany? _company;
public ServiceForm2()
{
InitializeComponent();
_storageCollection = new();
_company = null;
}
// Выбор компании
private void SelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{
/*
switch (comboBoxArrList.Text)
{
case "Storage":
@ -30,19 +22,16 @@ public partial class ServiceForm2 : Form
new ArrayGenObj<DrawningBase>());
break;
}
*/
toolPanel.Enabled = false;
}
// Color picker (default : random)
// Color picker
private static Color pickColor(Random r)
{
Color cl = new Color();
Color cl = Color.FromArgb(r.Next(0, 256), r.Next(0, 256), r.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK) cl = dialog.Color;
else Color.FromArgb(r.Next(0, 256), r.Next(0, 256), r.Next(0, 256));
if (dialog.ShowDialog() == DialogResult.OK)
{ cl = dialog.Color; }
return cl;
}
@ -73,6 +62,7 @@ public partial class ServiceForm2 : Form
break;
case nameof(DrawningCruiser):
// (TODO) вызов диалогового окна для выбора цвета >>>
drawningCar = new DrawningCruiser(random.Next(100, 300),
random.Next(1000, 3000), pickColor(random), pickColor(random),
Convert.ToBoolean(random.Next(0, 2)));
@ -94,7 +84,7 @@ public partial class ServiceForm2 : Form
// Удаление объекта
private void btnRemoveCar_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)
|| _company == null) return;
if (MessageBox.Show("[*] Remove object: Are you sure?", "Remove",
@ -145,84 +135,4 @@ public partial class ServiceForm2 : Form
}
pictureBox.Image = _company.Show();
}
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();
}
}

View File

@ -1,5 +1,5 @@
using ProjectCruiser.DrawningSamples;
namespace ProjectCruiser.CollectionGenericObj;
namespace ProjectCruiser;
public class ShipSharingService : AbstractCompany
{