Доработка лабораторной №3
This commit is contained in:
parent
76698af8ac
commit
1c549bb586
@ -1,9 +1,4 @@
|
|||||||
using ProjectCleaningCar.Drawnings;
|
using ProjectCleaningCar.Drawnings;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ProjectCleaningCar.CollectionGenericObjects;
|
namespace ProjectCleaningCar.CollectionGenericObjects;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -54,9 +49,9 @@ public abstract class AbstractCompany
|
|||||||
/// <param name="company">Компания</param>
|
/// <param name="company">Компания</param>
|
||||||
/// <param name="truck">Добавляемый объект</param>
|
/// <param name="truck">Добавляемый объект</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static bool operator +(AbstractCompany company, DrawningTruck truck)
|
public static int operator +(AbstractCompany company, DrawningTruck truck)
|
||||||
{
|
{
|
||||||
return company._collection?.Insert(truck) ?? false;
|
return company._collection?.Insert(truck) ?? -1;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Перегрузка оператора удаления для класса
|
/// Перегрузка оператора удаления для класса
|
||||||
@ -64,9 +59,9 @@ public abstract class AbstractCompany
|
|||||||
/// <param name="company">Компания</param>
|
/// <param name="company">Компания</param>
|
||||||
/// <param name="position">Номер удаляемого объекта</param>
|
/// <param name="position">Номер удаляемого объекта</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static bool operator -(AbstractCompany company, int position)
|
public static DrawningTruck operator -(AbstractCompany company, int position)
|
||||||
{
|
{
|
||||||
return company._collection?.Remove(position) ?? false;
|
return company._collection?.Remove(position) ?? null;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получение случайного объекта из коллекции
|
/// Получение случайного объекта из коллекции
|
||||||
|
@ -25,20 +25,20 @@ public interface ICollectionGenericObjects<T>
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="obj">Добавляемый объект</param>
|
/// <param name="obj">Добавляемый объект</param>
|
||||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||||
bool Insert(T obj);
|
int Insert(T obj);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление объекта в коллекцию на конкретную позицию
|
/// Добавление объекта в коллекцию на конкретную позицию
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="obj">Добавляемый объект</param>
|
/// <param name="obj">Добавляемый объект</param>
|
||||||
/// <param name="position">Позиция</param>
|
/// <param name="position">Позиция</param>
|
||||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||||
bool Insert(T obj, int position);
|
int Insert(T obj, int position);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Удаление объекта из коллекции с конкретной позиции
|
/// Удаление объекта из коллекции с конкретной позиции
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="position">Позиция</param>
|
/// <param name="position">Позиция</param>
|
||||||
/// <returns>true - удаление прошло удачно, false - удаление не удалось</returns>
|
/// <returns>true - удаление прошло удачно, false - удаление не удалось</returns>
|
||||||
bool Remove(int position);
|
T Remove(int position);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получение объекта по позиции
|
/// Получение объекта по позиции
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -41,56 +41,70 @@ internal class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
{
|
{
|
||||||
_collection = Array.Empty<T?>();
|
_collection = Array.Empty<T?>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public T? Get(int position)
|
public T? Get(int position)
|
||||||
{
|
{
|
||||||
if (position < 0 || position >= _collection.Length)
|
if (position >= 0 && position < Count)
|
||||||
{
|
{
|
||||||
throw new IndexOutOfRangeException("Position is out of range.");
|
return _collection[position];
|
||||||
}
|
}
|
||||||
return _collection[position];
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
public bool Insert(T obj)
|
|
||||||
|
public int Insert(T obj)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < _collection.Length; i++)
|
for (int i = 0; i < Count; i++)
|
||||||
{
|
{
|
||||||
if (_collection[i] == null)
|
if (_collection[i] == null)
|
||||||
{
|
{
|
||||||
_collection[i] = obj;
|
_collection[i] = obj;
|
||||||
return true;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return -1;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
public bool Insert(T obj, int position)
|
|
||||||
{
|
|
||||||
if (position < 0 || position >= _collection.Length)
|
|
||||||
{
|
|
||||||
throw new IndexOutOfRangeException("Position is out of range.");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public int Insert(T obj, int position)
|
||||||
|
{
|
||||||
|
if (position < 0 || position >= Count)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
if (_collection[position] == null)
|
if (_collection[position] == null)
|
||||||
{
|
{
|
||||||
_collection[position] = obj;
|
_collection[position] = obj;
|
||||||
return true;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
for (int i = position + 1; i < Count; i++)
|
||||||
|
{
|
||||||
|
if (_collection[i] == null)
|
||||||
|
{
|
||||||
|
_collection[i] = obj;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i = position - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
if (_collection[i] == null)
|
||||||
|
{
|
||||||
|
_collection[i] = obj;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
public bool Remove(int position)
|
public T Remove(int position)
|
||||||
{
|
{
|
||||||
if (position < 0 || position >= _collection.Length)
|
if (position < 0 || position >= Count)
|
||||||
{
|
{
|
||||||
throw new IndexOutOfRangeException("Position is out of range.");
|
return null;
|
||||||
}
|
}
|
||||||
|
T obj = _collection[position];
|
||||||
if (_collection[position] != null)
|
_collection[position] = null;
|
||||||
{
|
return obj;
|
||||||
_collection[position] = null;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ namespace ProjectCleaningCar
|
|||||||
buttonRefresh.TabIndex = 6;
|
buttonRefresh.TabIndex = 6;
|
||||||
buttonRefresh.Text = "Обновить";
|
buttonRefresh.Text = "Обновить";
|
||||||
buttonRefresh.UseVisualStyleBackColor = true;
|
buttonRefresh.UseVisualStyleBackColor = true;
|
||||||
buttonRefresh.Click += buttonRefresh_Click;
|
buttonRefresh.Click += ButtonRefresh_Click;
|
||||||
//
|
//
|
||||||
// buttonGoToCheck
|
// buttonGoToCheck
|
||||||
//
|
//
|
||||||
@ -79,7 +79,7 @@ namespace ProjectCleaningCar
|
|||||||
buttonGoToCheck.TabIndex = 5;
|
buttonGoToCheck.TabIndex = 5;
|
||||||
buttonGoToCheck.Text = "Передать на тесты";
|
buttonGoToCheck.Text = "Передать на тесты";
|
||||||
buttonGoToCheck.UseVisualStyleBackColor = true;
|
buttonGoToCheck.UseVisualStyleBackColor = true;
|
||||||
buttonGoToCheck.Click += buttonGoToCheck_Click;
|
buttonGoToCheck.Click += ButtonGoToCheck_Click;
|
||||||
//
|
//
|
||||||
// buttonRemoveTruck
|
// buttonRemoveTruck
|
||||||
//
|
//
|
||||||
@ -90,7 +90,7 @@ namespace ProjectCleaningCar
|
|||||||
buttonRemoveTruck.TabIndex = 4;
|
buttonRemoveTruck.TabIndex = 4;
|
||||||
buttonRemoveTruck.Text = "Удаление грузовика";
|
buttonRemoveTruck.Text = "Удаление грузовика";
|
||||||
buttonRemoveTruck.UseVisualStyleBackColor = true;
|
buttonRemoveTruck.UseVisualStyleBackColor = true;
|
||||||
buttonRemoveTruck.Click += buttonRemoveTruck_Click;
|
buttonRemoveTruck.Click += ButtonRemoveTruck_Click;
|
||||||
//
|
//
|
||||||
// maskedTextBoxPosition
|
// maskedTextBoxPosition
|
||||||
//
|
//
|
||||||
@ -100,7 +100,7 @@ namespace ProjectCleaningCar
|
|||||||
maskedTextBoxPosition.Size = new Size(226, 27);
|
maskedTextBoxPosition.Size = new Size(226, 27);
|
||||||
maskedTextBoxPosition.TabIndex = 3;
|
maskedTextBoxPosition.TabIndex = 3;
|
||||||
maskedTextBoxPosition.ValidatingType = typeof(int);
|
maskedTextBoxPosition.ValidatingType = typeof(int);
|
||||||
maskedTextBoxPosition.MaskInputRejected += maskedTextBoxPosition_MaskInputRejected;
|
maskedTextBoxPosition.MaskInputRejected += MaskedTextBoxPosition_MaskInputRejected;
|
||||||
//
|
//
|
||||||
// buttonAddCleaningCar
|
// buttonAddCleaningCar
|
||||||
//
|
//
|
||||||
|
@ -67,55 +67,23 @@ public partial class FormTruckCollection : Form
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Random random = new();
|
Random random = new();
|
||||||
DrawningTruck drawningTruck;
|
DrawningTruck _drawningTruck;
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case nameof(DrawningTruck):
|
case nameof(DrawningTruck):
|
||||||
drawningTruck = new DrawningTruck(random.Next(100, 300),
|
_drawningTruck = new DrawningTruck(random.Next(100, 300),
|
||||||
random.Next(1000, 3000), GetColor(random));
|
random.Next(1000, 3000), GetColor(random));
|
||||||
break;
|
break;
|
||||||
case nameof(DrawningCleaningCar):
|
case nameof(DrawningCleaningCar):
|
||||||
// Вызываем диалоговое окно для выбора основного цвета машины
|
_drawningTruck = new DrawningCleaningCar(random.Next(1000, 3000), random.Next(100, 500),
|
||||||
Color bodyColor;
|
GetColor(random), GetColor(random),
|
||||||
using (ColorDialog dialogBody = new ColorDialog())
|
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||||
{
|
|
||||||
if (dialogBody.ShowDialog() == DialogResult.OK)
|
|
||||||
{
|
|
||||||
bodyColor = dialogBody.Color;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Если диалог был закрыт без выбора цвета, выходим из метода
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Вызываем диалоговое окно для выбора дополнительного цвета машины
|
|
||||||
Color additionalColor;
|
|
||||||
using (ColorDialog dialogAdditional = new ColorDialog())
|
|
||||||
{
|
|
||||||
if (dialogAdditional.ShowDialog() == DialogResult.OK)
|
|
||||||
{
|
|
||||||
additionalColor = dialogAdditional.Color;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Если диалог был закрыт без выбора цвета, выходим из метода
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Создаем объект класса DrawningCleaningCar с выбранными цветами
|
|
||||||
drawningTruck = new DrawningCleaningCar(
|
|
||||||
random.Next(100, 300),
|
|
||||||
random.Next(1000, 3000),
|
|
||||||
bodyColor,
|
|
||||||
additionalColor,
|
|
||||||
Convert.ToBoolean(random.Next(0, 2)),
|
|
||||||
Convert.ToBoolean(random.Next(0, 2)));
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (_company + drawningTruck)
|
|
||||||
|
if (_company + _drawningTruck != -1)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект добавлен");
|
MessageBox.Show("Объект добавлен");
|
||||||
pictureBox.Image = _company.Show();
|
pictureBox.Image = _company.Show();
|
||||||
@ -146,7 +114,7 @@ public partial class FormTruckCollection : Form
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender"></param>
|
/// <param name="sender"></param>
|
||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void buttonRemoveTruck_Click(object sender, EventArgs e)
|
private void ButtonRemoveTruck_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company ==
|
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company ==
|
||||||
null)
|
null)
|
||||||
@ -158,8 +126,9 @@ public partial class FormTruckCollection : Form
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||||
if (_company - pos)
|
if (_company - pos != null)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект удален");
|
MessageBox.Show("Объект удален");
|
||||||
pictureBox.Image = _company.Show();
|
pictureBox.Image = _company.Show();
|
||||||
@ -174,7 +143,7 @@ public partial class FormTruckCollection : Form
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender"></param>
|
/// <param name="sender"></param>
|
||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void buttonGoToCheck_Click(object sender, EventArgs e)
|
private void ButtonGoToCheck_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_company == null)
|
if (_company == null)
|
||||||
{
|
{
|
||||||
@ -206,7 +175,7 @@ public partial class FormTruckCollection : Form
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender"></param>
|
/// <param name="sender"></param>
|
||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void buttonRefresh_Click(object sender, EventArgs e)
|
private void ButtonRefresh_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_company == null)
|
if (_company == null)
|
||||||
{
|
{
|
||||||
@ -215,7 +184,7 @@ public partial class FormTruckCollection : Form
|
|||||||
pictureBox.Image = _company.Show();
|
pictureBox.Image = _company.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void maskedTextBoxPosition_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
|
private void MaskedTextBoxPosition_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>WinExe</OutputType>
|
<OutputType>WinExe</OutputType>
|
||||||
<TargetFramework>net7.0-windows</TargetFramework>
|
<TargetFramework>net7.0-windows7.0</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<UseWindowsForms>true</UseWindowsForms>
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user