PIbd-12_Bugrov_D.A._Simple LabWork08 #8
@ -63,7 +63,7 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
|
||||
public int Insert(T obj, IEqualityComparer<DrawningLocomotive?>? comparer = null)
|
||||
{
|
||||
|
||||
if (_collection.Contains(obj, comparer)) throw new AlreadyExistingObject(obj.GetDataForSave());
|
||||
if (Count == _maxCount) throw new CollectionOwerflowException(Count);
|
||||
_collection.Add(obj);
|
||||
return Count;
|
||||
@ -110,4 +110,10 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
yield return _collection[i];
|
||||
}
|
||||
}
|
||||
|
||||
public void CollectionSort(IComparer<T?> comparer)
|
||||
{
|
||||
_collection.Sort(comparer);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -70,6 +70,7 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
public int Insert(T obj, IEqualityComparer<DrawningLocomotive?>? comparer = null)
|
||||
{
|
||||
// вставка в свободное место набора
|
||||
if (_collection.Contains(obj, comparer)) throw new AlreadyExistingObject(obj.GetDataForSave());
|
||||
for (int i = 0; i < Count; ++i)
|
||||
{
|
||||
if (_collection[i] == null)
|
||||
|
@ -181,7 +181,7 @@ public class StorageCollection<T>
|
||||
{
|
||||
try
|
||||
{
|
||||
collection.Insert(locomotive);
|
||||
collection.Insert(locomotive, new DrawningLocomotiveEqutables());
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
|
@ -53,6 +53,8 @@
|
||||
loadToolStripMenuItem = new ToolStripMenuItem();
|
||||
saveFileDialog = new SaveFileDialog();
|
||||
openFileDialog = new OpenFileDialog();
|
||||
buttonSortByColor = new Button();
|
||||
buttonSortByType = new Button();
|
||||
groupBoxTools.SuspendLayout();
|
||||
panelCompanyTools.SuspendLayout();
|
||||
panelStorage.SuspendLayout();
|
||||
@ -69,7 +71,7 @@
|
||||
groupBoxTools.Dock = DockStyle.Right;
|
||||
groupBoxTools.Location = new Point(640, 24);
|
||||
groupBoxTools.Name = "groupBoxTools";
|
||||
groupBoxTools.Size = new Size(200, 569);
|
||||
groupBoxTools.Size = new Size(200, 678);
|
||||
groupBoxTools.TabIndex = 0;
|
||||
groupBoxTools.TabStop = false;
|
||||
groupBoxTools.Text = "Инструменты";
|
||||
@ -98,6 +100,8 @@
|
||||
//
|
||||
// panelCompanyTools
|
||||
//
|
||||
panelCompanyTools.Controls.Add(buttonSortByColor);
|
||||
panelCompanyTools.Controls.Add(buttonSortByType);
|
||||
panelCompanyTools.Controls.Add(buttonAddLocomotive);
|
||||
panelCompanyTools.Controls.Add(buttonRefresh);
|
||||
panelCompanyTools.Controls.Add(maskedTextBoxPosition);
|
||||
@ -105,9 +109,9 @@
|
||||
panelCompanyTools.Controls.Add(buttonRemoveLocomotive);
|
||||
panelCompanyTools.Dock = DockStyle.Bottom;
|
||||
panelCompanyTools.Enabled = false;
|
||||
panelCompanyTools.Location = new Point(3, 340);
|
||||
panelCompanyTools.Location = new Point(3, 364);
|
||||
panelCompanyTools.Name = "panelCompanyTools";
|
||||
panelCompanyTools.Size = new Size(194, 226);
|
||||
panelCompanyTools.Size = new Size(194, 311);
|
||||
panelCompanyTools.TabIndex = 8;
|
||||
//
|
||||
// buttonAddLocomotive
|
||||
@ -246,7 +250,7 @@
|
||||
pictureBox.Dock = DockStyle.Fill;
|
||||
pictureBox.Location = new Point(0, 24);
|
||||
pictureBox.Name = "pictureBox";
|
||||
pictureBox.Size = new Size(640, 569);
|
||||
pictureBox.Size = new Size(640, 678);
|
||||
pictureBox.TabIndex = 1;
|
||||
pictureBox.TabStop = false;
|
||||
//
|
||||
@ -290,11 +294,31 @@
|
||||
//
|
||||
openFileDialog.Filter = "txt file|*.txt";
|
||||
//
|
||||
// buttonSortByColor
|
||||
//
|
||||
buttonSortByColor.Location = new Point(3, 260);
|
||||
buttonSortByColor.Name = "buttonSortByColor";
|
||||
buttonSortByColor.Size = new Size(188, 31);
|
||||
buttonSortByColor.TabIndex = 8;
|
||||
buttonSortByColor.Text = "Сортировка по цвету";
|
||||
buttonSortByColor.UseVisualStyleBackColor = true;
|
||||
buttonSortByColor.Click += ButtonSortByColor_Click;
|
||||
//
|
||||
// buttonSortByType
|
||||
//
|
||||
buttonSortByType.Location = new Point(3, 223);
|
||||
buttonSortByType.Name = "buttonSortByType";
|
||||
buttonSortByType.Size = new Size(188, 31);
|
||||
buttonSortByType.TabIndex = 7;
|
||||
buttonSortByType.Text = "Сортировка по типу";
|
||||
buttonSortByType.UseVisualStyleBackColor = true;
|
||||
buttonSortByType.Click += ButtonSortByType_Click;
|
||||
//
|
||||
// FormLocomotiveCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(840, 593);
|
||||
ClientSize = new Size(840, 702);
|
||||
Controls.Add(pictureBox);
|
||||
Controls.Add(groupBoxTools);
|
||||
Controls.Add(menuStrip);
|
||||
@ -340,5 +364,7 @@
|
||||
private ToolStripMenuItem loadToolStripMenuItem;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private Button buttonSortByColor;
|
||||
private Button buttonSortByType;
|
||||
}
|
||||
}
|
@ -78,19 +78,19 @@ public partial class FormLocomotiveCollection : Form
|
||||
|
||||
try
|
||||
{
|
||||
if((_company + locomotive) != -1)
|
||||
if ((_company + locomotive) != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
_logger.LogInformation("Добавлен объект: {entity}", locomotive.GetDataForSave());
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Объект не был добавлен");
|
||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -228,11 +228,11 @@ public partial class FormLocomotiveCollection : Form
|
||||
private void RefreshListBoxItems()
|
||||
{
|
||||
listBoxCollection.Items.Clear();
|
||||
foreach(string colName in _storageCollection.Keys)
|
||||
foreach (var colName in _storageCollection.Keys)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(colName))
|
||||
if (!string.IsNullOrEmpty(colName.Name))
|
||||
{
|
||||
listBoxCollection.Items.Add(colName);
|
||||
listBoxCollection.Items.Add(colName.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -284,7 +284,7 @@ public partial class FormLocomotiveCollection : Form
|
||||
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
_logger.LogInformation("Сохранение в файл {filename}", saveFileDialog.FileName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogError("Ошибка {Message}", ex.Message);
|
||||
@ -307,7 +307,7 @@ public partial class FormLocomotiveCollection : Form
|
||||
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
_logger.LogInformation("Загрузка прошла успешно из файла, {filename}", openFileDialog.FileName);
|
||||
}
|
||||
catch(Exception ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogError("Ошибка {Message}", ex.Message);
|
||||
@ -315,4 +315,36 @@ public partial class FormLocomotiveCollection : Form
|
||||
RefreshListBoxItems();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Сортировка по типу
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonSortByType_Click(object sender, EventArgs e)
|
||||
{
|
||||
CompareCars(new DrawningLocomotiveCompareByType());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Сортировка по цвету
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonSortByColor_Click(object sender, EventArgs e)
|
||||
{
|
||||
CompareCars(new DrawningLocomotiveCompareByColor());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Сортировка по сравнителю
|
||||
/// </summary>
|
||||
/// <param name="comparer">Сравнитель объектов</param>
|
||||
private void CompareCars(IComparer<DrawningLocomotive?> comparer)
|
||||
{
|
||||
if (_company == null) return;
|
||||
|
||||
_company.Sort(comparer);
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user