изменение на колекции
This commit is contained in:
parent
74ad587062
commit
0d25d56f0f
@ -32,14 +32,14 @@
|
||||
pictureBoxCollection = new PictureBox();
|
||||
groupBox1 = new GroupBox();
|
||||
groupBox2 = new GroupBox();
|
||||
buttonDelObject = new Button();
|
||||
listBoxStorages = new ListBox();
|
||||
button1 = new Button();
|
||||
buttonAddObject = new Button();
|
||||
textBoxStorageName = new TextBox();
|
||||
maskedTextBoxNumber = new MaskedTextBox();
|
||||
buttonRefreshCollection = new Button();
|
||||
buttonRemoveLocomotive = new Button();
|
||||
buttonAddLocomotive = new Button();
|
||||
button2 = new Button();
|
||||
tableLayoutPanel1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||
groupBox1.SuspendLayout();
|
||||
@ -91,9 +91,9 @@
|
||||
//
|
||||
// groupBox2
|
||||
//
|
||||
groupBox2.Controls.Add(button2);
|
||||
groupBox2.Controls.Add(buttonDelObject);
|
||||
groupBox2.Controls.Add(listBoxStorages);
|
||||
groupBox2.Controls.Add(button1);
|
||||
groupBox2.Controls.Add(buttonAddObject);
|
||||
groupBox2.Controls.Add(textBoxStorageName);
|
||||
groupBox2.Location = new Point(6, 26);
|
||||
groupBox2.Name = "groupBox2";
|
||||
@ -102,6 +102,16 @@
|
||||
groupBox2.TabStop = false;
|
||||
groupBox2.Text = "Наборы";
|
||||
//
|
||||
// buttonDelObject
|
||||
//
|
||||
buttonDelObject.Location = new Point(4, 204);
|
||||
buttonDelObject.Name = "buttonDelObject";
|
||||
buttonDelObject.Size = new Size(176, 29);
|
||||
buttonDelObject.TabIndex = 3;
|
||||
buttonDelObject.Text = "Удалить набор";
|
||||
buttonDelObject.UseVisualStyleBackColor = true;
|
||||
buttonDelObject.Click += buttonDelObject_Click;
|
||||
//
|
||||
// listBoxStorages
|
||||
//
|
||||
listBoxStorages.FormattingEnabled = true;
|
||||
@ -110,15 +120,17 @@
|
||||
listBoxStorages.Name = "listBoxStorages";
|
||||
listBoxStorages.Size = new Size(174, 104);
|
||||
listBoxStorages.TabIndex = 2;
|
||||
listBoxStorages.SelectedIndexChanged += listBoxStorages_SelectedIndexChanged;
|
||||
//
|
||||
// button1
|
||||
// buttonAddObject
|
||||
//
|
||||
button1.Location = new Point(4, 59);
|
||||
button1.Name = "button1";
|
||||
button1.Size = new Size(176, 29);
|
||||
button1.TabIndex = 1;
|
||||
button1.Text = "Добавить набор";
|
||||
button1.UseVisualStyleBackColor = true;
|
||||
buttonAddObject.Location = new Point(4, 59);
|
||||
buttonAddObject.Name = "buttonAddObject";
|
||||
buttonAddObject.Size = new Size(176, 29);
|
||||
buttonAddObject.TabIndex = 1;
|
||||
buttonAddObject.Text = "Добавить набор";
|
||||
buttonAddObject.UseVisualStyleBackColor = true;
|
||||
buttonAddObject.Click += buttonAddObject_Click;
|
||||
//
|
||||
// textBoxStorageName
|
||||
//
|
||||
@ -165,15 +177,6 @@
|
||||
buttonAddLocomotive.Text = "Добавить локомотив";
|
||||
buttonAddLocomotive.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// button2
|
||||
//
|
||||
button2.Location = new Point(4, 204);
|
||||
button2.Name = "button2";
|
||||
button2.Size = new Size(176, 29);
|
||||
button2.TabIndex = 3;
|
||||
button2.Text = "Добавить набор";
|
||||
button2.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// FormLocomotiveCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
@ -204,8 +207,8 @@
|
||||
private MaskedTextBox maskedTextBoxNumber;
|
||||
private GroupBox groupBox2;
|
||||
private TextBox textBoxStorageName;
|
||||
private Button button1;
|
||||
private Button buttonAddObject;
|
||||
private ListBox listBoxStorages;
|
||||
private Button button2;
|
||||
private Button buttonDelObject;
|
||||
}
|
||||
}
|
@ -12,10 +12,7 @@ namespace ProjectElectricLocomotive
|
||||
{
|
||||
public partial class FormLocomotiveCollection
|
||||
{
|
||||
private void buttonAddLocomotive_Click(object sender, EventArgs e)
|
||||
{
|
||||
ButtonAddLocomotive_Click(sender, e);
|
||||
}
|
||||
|
||||
|
||||
private void buttonRemoveLocomotive_Click(object sender, EventArgs e)
|
||||
{
|
||||
@ -26,5 +23,20 @@ namespace ProjectElectricLocomotive
|
||||
{
|
||||
ButtonRefreshCollection_Click(sender, e);
|
||||
}
|
||||
|
||||
private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
ListBoxObjects_SelectedIndexChanged(sender, e);
|
||||
}
|
||||
|
||||
private void buttonAddObject_Click(object sender, EventArgs e)
|
||||
{
|
||||
ButtonAddObject_Click(sender, e);
|
||||
}
|
||||
|
||||
private void buttonDelObject_Click(object sender, EventArgs e)
|
||||
{
|
||||
ButtonDelObject_Click(sender, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ namespace ProjectElectricLocomotive.Generics
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (collect?._collection.Insert(obj) ?? false)
|
||||
if (collect?._collection.Insert(obj) ?? false)
|
||||
{
|
||||
return collect._collection.Count;
|
||||
}
|
||||
@ -77,7 +77,7 @@ namespace ProjectElectricLocomotive.Generics
|
||||
public static int operator -(LocomotivesGenericCollection<T, U> collect, int
|
||||
pos)
|
||||
{
|
||||
T? obj = collect._collection.Get(pos);
|
||||
T? obj = collect._collection[pos];
|
||||
if (obj != null && collect._collection.Remove(pos))
|
||||
{
|
||||
return collect._collection.Count;
|
||||
@ -133,19 +133,19 @@ namespace ProjectElectricLocomotive.Generics
|
||||
/// <param name="g"></param>
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
int ColumnCount = _pictureWidth / _placeSizeWidth;
|
||||
int RowsCount = _pictureHeight / _placeSizeHeight;
|
||||
int pos = 0;
|
||||
foreach (var locomotive in _collection.GetLocomotives())
|
||||
{
|
||||
if (locomotive != null)
|
||||
{
|
||||
//int widthCount = _pictureHeight / _placeSizeHeight;
|
||||
//locomotive.SetPosition((i / widthCount) * _placeSizeWidth, (i % widthCount) * _placeSizeHeight);
|
||||
locomotive.SetPosition((pos % ColumnCount) * _placeSizeWidth, ((RowsCount - pos / ColumnCount - 1) * _placeSizeHeight));
|
||||
locomotive.DrawTransport(g);
|
||||
}
|
||||
|
||||
int ColumnCount = _pictureWidth / _placeSizeWidth;
|
||||
int RowsCount = _pictureHeight / _placeSizeHeight;
|
||||
drawningLocomotive.SetPosition((i % ColumnCount) * _placeSizeWidth, ((RowsCount - i / ColumnCount - 1) * _placeSizeHeight));
|
||||
drawningLocomotive.DrawTransport(g);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
83
ElectricLocomotive/Generics/LocomotivesGenericStorage.cs
Normal file
83
ElectricLocomotive/Generics/LocomotivesGenericStorage.cs
Normal file
@ -0,0 +1,83 @@
|
||||
using ProjectElectricLocomotive.DrawningObjects;
|
||||
using ProjectElectricLocomotive.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectElectricLocomotive.Generics
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс для хранения коллекции
|
||||
/// </summary>
|
||||
internal class LocomotivesGenericStorage
|
||||
{
|
||||
/// <summary>
|
||||
/// Словарь (хранилище)
|
||||
/// </summary>
|
||||
readonly Dictionary<string, LocomotivesGenericCollection<
|
||||
DrawningLocomotive, DrawningObjectLocomotive>
|
||||
> _locomotiveStorage;
|
||||
|
||||
/// <summary>
|
||||
/// Возвращение списка названий наборов
|
||||
/// </summary>
|
||||
public List<string> Keys => _locomotiveStorage.Keys.ToList();
|
||||
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="pictureWidth"></param>
|
||||
/// <param name="pictureHeight"></param>
|
||||
public LocomotivesGenericStorage(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_locomotiveStorage = new Dictionary<string,
|
||||
LocomotivesGenericCollection<DrawningLocomotive,
|
||||
DrawningObjectLocomotive>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавление набора
|
||||
/// </summary>
|
||||
/// <param name="name">Название набора</param>
|
||||
public void AddSet(string name)
|
||||
{
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление набора
|
||||
/// </summary>
|
||||
/// <param name="name">Название набора</param>
|
||||
public void DelSet(string name)
|
||||
{
|
||||
// TODO Прописать логику для удаления
|
||||
}
|
||||
/// <summary>
|
||||
/// Доступ к набору
|
||||
/// </summary>
|
||||
/// <param name="ind"></param>
|
||||
/// <returns></returns>
|
||||
public LocomotivesGenericCollection<DrawningLocomotive,
|
||||
DrawningObjectLocomotive>? this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
// TODO Продумать логику получения набора
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -35,19 +35,6 @@ namespace ProjectElectricLocomotive.Generics
|
||||
_places = new List<T?>(count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// обмен двух элементов
|
||||
/// </summary>
|
||||
/// <param name="first">Первый элемент</param>
|
||||
/// <param name="second">Второй элемент</param>
|
||||
/// <returns></returns>
|
||||
private void swap(int index1, int index2)
|
||||
{
|
||||
T temp = _places[index1];
|
||||
_places[index1] = _places[index2];
|
||||
_places[index2] = temp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
@ -55,24 +42,10 @@ namespace ProjectElectricLocomotive.Generics
|
||||
/// <returns></returns>
|
||||
public bool Insert(T locomotive)
|
||||
{
|
||||
int end = Count;
|
||||
for (int i = 0; i < Count; ++i)
|
||||
{
|
||||
if (_places[i] == null)
|
||||
{
|
||||
end = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (end == Count)
|
||||
{
|
||||
if (_places.Count >= _maxCount) {
|
||||
return false;
|
||||
}
|
||||
for (int i = end; i >= 1; --i)
|
||||
{
|
||||
_places[i] = _places[i - 1];
|
||||
}
|
||||
_places[0] = locomotive;
|
||||
_places.Insert(0, locomotive);
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
@ -83,33 +56,11 @@ namespace ProjectElectricLocomotive.Generics
|
||||
/// <returns></returns>
|
||||
public bool Insert(T locomotive, int position)
|
||||
{
|
||||
if (position >= Count || position < 0)
|
||||
if (_places.Count >= _maxCount || position >= 0 || position <= _places.Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_places[position] == null)
|
||||
{
|
||||
_places[position] = locomotive;
|
||||
return true;
|
||||
}
|
||||
int end = Count;
|
||||
for (int i = position; i < Count; ++i)
|
||||
{
|
||||
if (_places[i] == null)
|
||||
{
|
||||
end = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (end == Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_places[end] = locomotive;
|
||||
for (int i = position; i < end; ++i)
|
||||
{
|
||||
swap(i, end);
|
||||
}
|
||||
_places.Insert(position, locomotive);
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
@ -124,7 +75,7 @@ namespace ProjectElectricLocomotive.Generics
|
||||
return false;
|
||||
}
|
||||
|
||||
_places[position] = null;
|
||||
_places.RemoveAt(position);
|
||||
return true;
|
||||
|
||||
}
|
||||
@ -145,9 +96,10 @@ namespace ProjectElectricLocomotive.Generics
|
||||
}
|
||||
set
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO проверка свободных мест в списке
|
||||
// TODO вставка в список по позиции
|
||||
if (position < Count || position >= 0)
|
||||
{
|
||||
_places[position] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,13 +42,11 @@ namespace ProjectElectricLocomotive
|
||||
{
|
||||
listBoxStorages.Items.Add(_storage.Keys[i]);
|
||||
}
|
||||
if (listBoxStorages.Items.Count > 0 && (index == -1 || index
|
||||
>= listBoxStorages.Items.Count))
|
||||
if (listBoxStorages.Items.Count > 0 && (index == -1 || index >= listBoxStorages.Items.Count))
|
||||
{
|
||||
listBoxStorages.SelectedIndex = 0;
|
||||
}
|
||||
else if (listBoxStorages.Items.Count > 0 && index > -1 &&
|
||||
index < listBoxStorages.Items.Count)
|
||||
else if (listBoxStorages.Items.Count > 0 && index > -1 && index < listBoxStorages.Items.Count)
|
||||
{
|
||||
listBoxStorages.SelectedIndex = index;
|
||||
}
|
||||
@ -120,7 +118,7 @@ namespace ProjectElectricLocomotive
|
||||
FormLocomotive form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_locomotives + form.SelectedLocomotive > 0)
|
||||
if (obj + form.SelectedLocomotive > 0)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = obj.ShowLocomotives();
|
||||
@ -154,7 +152,7 @@ namespace ProjectElectricLocomotive
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||
if (_locomotives - pos != -1)
|
||||
if (obj - pos != -1)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxCollection.Image = obj.ShowLocomotives();
|
||||
|
Loading…
Reference in New Issue
Block a user