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