Compare commits

..

3 Commits

Author SHA1 Message Date
sqdselo
052b9929c1 Готовая 4 лабораторная работа 2024-04-28 00:20:54 +04:00
sqdselo
f57496c459 доделать 2024-04-22 19:10:26 +04:00
ff1e1066b6 доделаю 2024-04-15 14:25:51 +04:00
5 changed files with 51 additions and 58 deletions

View File

@ -48,7 +48,7 @@ namespace HoistingCrane.CollectionGenericObjects
} }
public static DrawningTrackedVehicle operator -(AbstractCompany company, int position) public static DrawningTrackedVehicle operator -(AbstractCompany company, int position)
{ {
return company.arr?.Remove(position) ?? null; return company.arr?.Remove(position);
} }
public DrawningTrackedVehicle? GetRandomObject() public DrawningTrackedVehicle? GetRandomObject()

View File

@ -11,14 +11,21 @@ namespace HoistingCrane.CollectionGenericObjects
public int Count public int Count
{ {
get { return arr.Length; } get { return arr.Length; }
} }
public int SetMaxCount public int SetMaxCount
{ {
set set
{ {
if (value > 0) if (value > 0)
{ {
arr = new T?[value]; if (arr.Length > 0)
{
Array.Resize(ref arr, value);
}
else
{
arr = new T?[value];
}
} }
} }
} }
@ -33,14 +40,7 @@ namespace HoistingCrane.CollectionGenericObjects
public int Insert(T obj) public int Insert(T obj)
{ {
for (int i = 0; i < Count; i++) return Insert(obj, 0);
{
if (arr[i] == null)
{
return Insert(obj, 0);
}
}
return -1;
} }
public int Insert(T obj, int position) public int Insert(T obj, int position)

View File

@ -27,17 +27,12 @@ namespace HoistingCrane.CollectionGenericObjects
{ {
// TODO проверка, что name не пустой и нет в словаре записи с таким ключом // TODO проверка, что name не пустой и нет в словаре записи с таким ключом
// TODO Прописать логику для добавления // TODO Прописать логику для добавления
if (!string.IsNullOrEmpty(name) && !Keys.Contains(name)) if (dict.ContainsKey(name)) return;
{ if (collectionType == CollectionType.None) return;
if(collectionType == CollectionType.Massive) else if (collectionType == CollectionType.Massive)
{ dict[name] = new MassivGenericObjects<T>();
dict.Add(name, new MassivGenericObjects<T> ()); else if (collectionType == CollectionType.List)
} dict[name] = new ListGenericObjects<T>();
if(collectionType == CollectionType.List)
{
dict.Add(name, new ListGenericObjects<T> ());
}
}
} }
/// <summary> /// <summary>
/// Удаление коллекции /// Удаление коллекции
@ -62,10 +57,8 @@ namespace HoistingCrane.CollectionGenericObjects
get get
{ {
// TODO Продумать логику получения объекта // TODO Продумать логику получения объекта
if (dict.TryGetValue(name, out ICollectionGenericObjects<T>? result)) if (dict.ContainsKey(name))
{ return dict[name];
return result;
}
return null; return null;
} }
} }

View File

@ -29,8 +29,8 @@
private void InitializeComponent() private void InitializeComponent()
{ {
groupBoxTools = new GroupBox(); groupBoxTools = new GroupBox();
panelCompanyTool = new Panel();
buttonCreateCompany = new Button(); buttonCreateCompany = new Button();
panelCompanyTool = new Panel();
buttonRefresh = new Button(); buttonRefresh = new Button();
buttonGoToChek = new Button(); buttonGoToChek = new Button();
buttonCreateHoistingCrane = new Button(); buttonCreateHoistingCrane = new Button();
@ -67,20 +67,6 @@
groupBoxTools.TabStop = false; groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты"; groupBoxTools.Text = "Инструменты";
// //
// panelCompanyTool
//
panelCompanyTool.Anchor = AnchorStyles.None;
panelCompanyTool.Controls.Add(buttonRefresh);
panelCompanyTool.Controls.Add(buttonGoToChek);
panelCompanyTool.Controls.Add(buttonCreateHoistingCrane);
panelCompanyTool.Controls.Add(buttonCreateTrackedVehicle);
panelCompanyTool.Controls.Add(buttonDeleteCar);
panelCompanyTool.Controls.Add(maskedTextBox);
panelCompanyTool.Location = new Point(3, 317);
panelCompanyTool.Name = "panelCompanyTool";
panelCompanyTool.Size = new Size(208, 238);
panelCompanyTool.TabIndex = 8;
//
// buttonCreateCompany // buttonCreateCompany
// //
buttonCreateCompany.Location = new Point(12, 288); buttonCreateCompany.Location = new Point(12, 288);
@ -91,6 +77,21 @@
buttonCreateCompany.UseVisualStyleBackColor = true; buttonCreateCompany.UseVisualStyleBackColor = true;
buttonCreateCompany.Click += buttonCreateCompany_Click; buttonCreateCompany.Click += buttonCreateCompany_Click;
// //
// panelCompanyTool
//
panelCompanyTool.Anchor = AnchorStyles.None;
panelCompanyTool.Controls.Add(buttonRefresh);
panelCompanyTool.Controls.Add(buttonGoToChek);
panelCompanyTool.Controls.Add(buttonCreateHoistingCrane);
panelCompanyTool.Controls.Add(buttonCreateTrackedVehicle);
panelCompanyTool.Controls.Add(buttonDeleteCar);
panelCompanyTool.Controls.Add(maskedTextBox);
panelCompanyTool.Enabled = false;
panelCompanyTool.Location = new Point(3, 317);
panelCompanyTool.Name = "panelCompanyTool";
panelCompanyTool.Size = new Size(208, 238);
panelCompanyTool.TabIndex = 8;
//
// buttonRefresh // buttonRefresh
// //
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
@ -204,7 +205,7 @@
radioButtonList.AutoSize = true; radioButtonList.AutoSize = true;
radioButtonList.Location = new Point(128, 56); radioButtonList.Location = new Point(128, 56);
radioButtonList.Name = "radioButtonList"; radioButtonList.Name = "radioButtonList";
radioButtonList.Size = new Size(67, 19); radioButtonList.Size = new Size(66, 19);
radioButtonList.TabIndex = 3; radioButtonList.TabIndex = 3;
radioButtonList.TabStop = true; radioButtonList.TabStop = true;
radioButtonList.Text = "Список"; radioButtonList.Text = "Список";
@ -215,7 +216,7 @@
radioButtonMassive.AutoSize = true; radioButtonMassive.AutoSize = true;
radioButtonMassive.Location = new Point(18, 56); radioButtonMassive.Location = new Point(18, 56);
radioButtonMassive.Name = "radioButtonMassive"; radioButtonMassive.Name = "radioButtonMassive";
radioButtonMassive.Size = new Size(69, 19); radioButtonMassive.Size = new Size(67, 19);
radioButtonMassive.TabIndex = 2; radioButtonMassive.TabIndex = 2;
radioButtonMassive.TabStop = true; radioButtonMassive.TabStop = true;
radioButtonMassive.Text = "Массив"; radioButtonMassive.Text = "Массив";
@ -233,7 +234,7 @@
labelCollectionName.AutoSize = true; labelCollectionName.AutoSize = true;
labelCollectionName.Location = new Point(35, 0); labelCollectionName.Location = new Point(35, 0);
labelCollectionName.Name = "labelCollectionName"; labelCollectionName.Name = "labelCollectionName";
labelCollectionName.Size = new Size(135, 15); labelCollectionName.Size = new Size(125, 15);
labelCollectionName.TabIndex = 0; labelCollectionName.TabIndex = 0;
labelCollectionName.Text = "Название коллекции:"; labelCollectionName.Text = "Название коллекции:";
// //

View File

@ -1,32 +1,24 @@
using HoistingCrane.CollectionGenericObjects; using HoistingCrane.CollectionGenericObjects;
using HoistingCrane.Drawning; using HoistingCrane.Drawning;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace HoistingCrane namespace HoistingCrane
{ {
public partial class FormCarCollection : Form public partial class FormCarCollection : Form
{ {
private AbstractCompany? _company; private AbstractCompany? _company = null;
private readonly StorageCollection<DrawningTrackedVehicle> _storageCollection; private readonly StorageCollection<DrawningTrackedVehicle> _storageCollection;
public FormCarCollection() public FormCarCollection()
{ {
InitializeComponent(); InitializeComponent();
_storageCollection = new(); _storageCollection = new();
panelCompanyTool.Enabled = false;
} }
private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{ {
panelCompanyTool.Enabled = false; panelCompanyTool.Enabled = false;
} }
private void CreateObject(string type) private void CreateObject(string type)
{ {
DrawningTrackedVehicle drawning; DrawningTrackedVehicle drawning;
@ -146,19 +138,26 @@ namespace HoistingCrane
{ {
collectionType = CollectionType.List; collectionType = CollectionType.List;
} }
_storageCollection.AddCollection(textBoxCollectionName.Text, _storageCollection.AddCollection(textBoxCollectionName.Text, collectionType);
collectionType);
RerfreshListBoxItems(); RerfreshListBoxItems();
} }
private void buttonDeleteCollection_Click(object sender, EventArgs e) private void buttonDeleteCollection_Click(object sender, EventArgs e)
{ {
// TODO прописать логику удаления элемента из коллекции
// нужно убедиться, что есть выбранная коллекция
// спросить у пользователя через MessageBox, что он подтверждает, что хочет удалить запись
// удалить и обновить ListBox
if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null) if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
{ {
MessageBox.Show("Коллекция не выбрана"); MessageBox.Show("Коллекция не выбрана");
return; return;
} }
if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return; return;
}
_storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString()); _storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
RerfreshListBoxItems(); RerfreshListBoxItems();
} }