Лаба 6, гготовая.

This commit is contained in:
MariaBelkina 2024-06-08 20:58:52 +04:00
parent 5e1a479097
commit 21ea2ca455
11 changed files with 401 additions and 50 deletions

View File

@ -54,7 +54,7 @@ public abstract class AbstractCompany
_pictureWidth = picWidth; _pictureWidth = picWidth;
_pictureHeight = picHeight; _pictureHeight = picHeight;
_collection = collectoin; _collection = collectoin;
_collection.SetMaxCount = GetMaxCount; _collection.MaxCount = GetMaxCount;
} }
/// <summary> /// <summary>

View File

@ -21,7 +21,7 @@ public interface ICollectoinGenericObjects<T>
/// <summary> /// <summary>
/// Установка максимального колличества элементов /// Установка максимального колличества элементов
/// </summary> /// </summary>
int SetMaxCount { set; } int MaxCount { get; set; }
/// <summary> /// <summary>
/// Добавление элемента в коллекцию /// Добавление элемента в коллекцию
@ -55,10 +55,10 @@ public interface ICollectoinGenericObjects<T>
/// <summary> /// <summary>
/// Получение типа коллекции /// Получение типа коллекции
/// </summary> /// </summary>
CollectionType GetCollecctionType { get; } CollectionType GetCollectionType { get; }
/// <summary> /// <summary>
/// Получение объектов коллекции по одному. /// Получение объектов коллекции по одному
/// </summary> /// </summary>
/// <returns>Поэлементный вывод элементов коллекции</returns> /// <returns>Поэлементный вывод элементов коллекции</returns>
IEnumerable<T> GetItems(); IEnumerable<T> GetItems();

View File

@ -25,7 +25,22 @@ public class ListGenericObjects<T> : ICollectoinGenericObjects<T>
public int Count => _collection.Count; public int Count => _collection.Count;
public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } } public int MaxCount {
get
{
return _collection.Count;
}
set
{
if (value > 0)
{
_maxCount = value;
}
}
}
public CollectionType GetCollectionType => CollectionType.List;
/// <summary> /// <summary>
/// Конструктор /// Конструктор
@ -91,5 +106,11 @@ public class ListGenericObjects<T> : ICollectoinGenericObjects<T>
return obj; return obj;
} }
// TODO та же фигня, что и в MassiveGenericObject public IEnumerable<T?> GetItems()
{
for (int i = 0; i < _collection.Count; ++i)
{
yield return _collection[i];
}
}
} }

View File

@ -16,8 +16,12 @@ public class MassiveGenericObject<T> : ICollectoinGenericObjects<T>
public int Count => _collection.Length; public int Count => _collection.Length;
public int SetMaxCount public int MaxCount
{ {
get
{
return _collection.Length;
}
set set
{ {
if (value > 0) if (value > 0)
@ -34,6 +38,8 @@ public class MassiveGenericObject<T> : ICollectoinGenericObjects<T>
} }
} }
public CollectionType GetCollectionType => CollectionType.Massive;
/// <summary> /// <summary>
/// Конструктор /// Конструктор
/// </summary> /// </summary>

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using ProjectBulldozer.Drawnings;
namespace ProjectBulldozer.CollectionGenericObjects; namespace ProjectBulldozer.CollectionGenericObjects;
@ -11,7 +12,7 @@ namespace ProjectBulldozer.CollectionGenericObjects;
/// </summary> /// </summary>
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
public class StorageCollection<T> public class StorageCollection<T>
where T : class where T : DrawningDozer
{ {
/// <summary> /// <summary>
/// Словарь (хранилище) с коллекциями /// Словарь (хранилище) с коллекциями
@ -23,6 +24,21 @@ public class StorageCollection<T>
/// </summary> /// </summary>
public List<string> Keys => _storages.Keys.ToList(); public List<string> Keys => _storages.Keys.ToList();
/// <summary>
/// Ключевое слово, с которого должен начианться файл
/// </summary>
private readonly string _collectionKey = "CollectionStorage";
/// <summary>
/// Разделитель для записи ключа и значения элемента словаря
/// </summary>
private readonly string _separatorForKeyValue = "|";
/// <summary>
/// Разделительдля записи коллекций данных в файл
/// </summary>
private readonly string _separatorItems = ";";
/// <summary> /// <summary>
/// Конструктор /// Конструктор
/// </summary> /// </summary>
@ -84,4 +100,140 @@ public class StorageCollection<T>
return null; return null;
} }
} }
/// <summary>
/// Сохранение информации по бульдозерам в хранилище в файла
/// </summary>
/// <param name="filename">Путь и имя файла</param>
/// <returns>true - сохранение прошло успешно, false - ошибка при сохранении данных</returns>
public bool SaveData(string filename)
{
if (_storages.Count == 0)
{
return false;
}
if (File.Exists(filename))
{
File.Delete(filename);
}
StringBuilder stringBuilder = new();
stringBuilder.Append(_collectionKey);
foreach (KeyValuePair<string, ICollectoinGenericObjects<T>> value in _storages)
{
stringBuilder.Append(Environment.NewLine);
// не сохраняем пустые коллекции.
if (value.Value.Count == 0)
{
continue;
}
stringBuilder.Append(value.Key);
stringBuilder.Append(_separatorForKeyValue);
stringBuilder.Append(value.Value.GetCollectionType);
stringBuilder.Append(_separatorForKeyValue);
stringBuilder.Append(value.Value.MaxCount);
stringBuilder.Append(_separatorForKeyValue);
foreach (T? item in value.Value.GetItems())
{
string data = item?.GetDataForSave() ?? string.Empty;
if (string.IsNullOrEmpty(data))
{
continue;
}
stringBuilder.Append(data);
stringBuilder.Append(_separatorItems);
}
}
using FileStream fileStream = new(filename, FileMode.Create);
byte[] info = new UTF8Encoding(true).GetBytes(stringBuilder.ToString());
fileStream.Write(info, 0, info.Length);
return true;
}
/// <summary>
/// Загрузка информации по бульдозерам в хранилище из файла
/// </summary>
/// <param name="filename">Путь и имя файла</param>
/// <returns>true- загрузка прошла успешно, false - ошибка при загрузке данных</returns>
public bool LoadData(string filename)
{
if (!File.Exists(filename)) return false;
string bufferTextfromFile = "";
using (FileStream fileStream = new(filename, FileMode.Open))
{
byte[] bytes = new byte[fileStream.Length];
UTF8Encoding temp = new(true);
while (fileStream.Read(bytes, 0, bytes.Length) > 0)
{
bufferTextfromFile += temp.GetString(bytes);
}
}
string[] strs = bufferTextfromFile.Split(new char[] { '\r', '\n'},
StringSplitOptions.RemoveEmptyEntries);
if (strs == null || strs.Length == 0)
{
return false;
}
if (!strs[0].Equals(_collectionKey))
{
// если нет такой записи, то это не те данные.
return false;
}
_storages.Clear();
foreach (string data in strs)
{
string[] record = data.Split(_separatorForKeyValue,
StringSplitOptions.RemoveEmptyEntries);
if (record.Length != 4)
{
continue;
}
CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
ICollectoinGenericObjects<T>? collectoin = StorageCollection<T>.CreateCollection(collectionType);
if (collectoin == null)
{
return false;
}
collectoin.MaxCount = Convert.ToInt32(record[2]);
string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set)
{
if (elem?.CreateDrawningDozer() is T dozer)
{
if (collectoin.Insert(dozer) == -1)
{
return false;
}
}
}
_storages.Add(record[0], collectoin);
}
return true;
}
private static ICollectoinGenericObjects<T>? CreateCollection(CollectionType collectionType)
{
return collectionType switch
{
CollectionType.Massive => new MassiveGenericObject<T>(),
CollectionType.List => new ListGenericObjects<T>(),
_ => null,
};
}
} }

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Numerics;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using ProjectBulldozer.Entities; using ProjectBulldozer.Entities;
@ -12,6 +13,20 @@ namespace ProjectBulldozer.Drawnings;
/// </summary> /// </summary>
public class DrawningBulldozer : DrawningDozer public class DrawningBulldozer : DrawningDozer
{ {
private EntityDozer dozer;
/// <summary>
/// Другой конструктор.
/// </summary>
/// <param name="dozer"></param>
public DrawningBulldozer(EntityDozer? entityDozer) : base(150, 90)
{
if (entityDozer != null)
{
EntityDozer = entityDozer;
}
}
///<summary> ///<summary>
///Конструктор ///Конструктор
/// </summary> /// </summary>

View File

@ -36,6 +36,7 @@ public class DrawningDozer
/// Верхнаяя координата прорисовки бульдозера /// Верхнаяя координата прорисовки бульдозера
/// </summary> /// </summary>
protected int? _startPosY; protected int? _startPosY;
private EntityDozer dozer;
///<summary> ///<summary>
///Ширина прорисовки бульдозера ///Ширина прорисовки бульдозера
@ -102,6 +103,16 @@ public class DrawningDozer
_pictureHeight = drawningBulldozerHeigh; _pictureHeight = drawningBulldozerHeigh;
} }
/// <summary>
/// Другой конструктор.
/// </summary>
/// <param name="dozer"></param>
public DrawningDozer(EntityDozer? entityDozer)
{
if (entityDozer == null) return;
EntityDozer = entityDozer;
}
///<summary> ///<summary>
///Установка границ поля ///Установка границ поля
/// </summary> /// </summary>
@ -243,19 +254,19 @@ public class DrawningDozer
Pen pen = new(Color.Black); Pen pen = new(Color.Black);
Brush bodyBrush = new SolidBrush(EntityDozer.BodyColor); Brush bodyBrush = new SolidBrush(EntityDozer.BodyColor);
Brush wheelsBrush = new SolidBrush(Color.FromArgb(60, 60, 60)); Brush wheelstringBuilderrush = new SolidBrush(Color.FromArgb(60, 60, 60));
//BULDOZER //BULDOZER
//body //body
g.FillRectangle(bodyBrush, _startPosX.Value + 10, _startPosY.Value + 15, _drawningBulldozerWidth - 20, _drawningBulldozerHeight - 30); g.FillRectangle(bodyBrush, _startPosX.Value + 10, _startPosY.Value + 15, _drawningBulldozerWidth - 20, _drawningBulldozerHeight - 30);
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 15, _drawningBulldozerWidth - 20, _drawningBulldozerHeight - 30); g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 15, _drawningBulldozerWidth - 20, _drawningBulldozerHeight - 30);
//wheels //wheels
g.FillRectangle(wheelsBrush, _startPosX.Value, _startPosY.Value + _drawningBulldozerHeight - 15, 50, 15); g.FillRectangle(wheelstringBuilderrush, _startPosX.Value, _startPosY.Value + _drawningBulldozerHeight - 15, 50, 15);
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + _drawningBulldozerHeight - 15, 50, 15); g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + _drawningBulldozerHeight - 15, 50, 15);
g.FillRectangle(wheelsBrush, _startPosX.Value + _drawningBulldozerWidth - 50, _startPosY.Value + _drawningBulldozerHeight - 15, 50, 15); g.FillRectangle(wheelstringBuilderrush, _startPosX.Value + _drawningBulldozerWidth - 50, _startPosY.Value + _drawningBulldozerHeight - 15, 50, 15);
g.DrawRectangle(pen, _startPosX.Value + _drawningBulldozerWidth - 50, _startPosY.Value + _drawningBulldozerHeight - 15, 50, 15); g.DrawRectangle(pen, _startPosX.Value + _drawningBulldozerWidth - 50, _startPosY.Value + _drawningBulldozerHeight - 15, 50, 15);
g.FillRectangle(wheelsBrush, _startPosX.Value, _startPosY.Value, 50, 15); g.FillRectangle(wheelstringBuilderrush, _startPosX.Value, _startPosY.Value, 50, 15);
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value, 50, 15); g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value, 50, 15);
g.FillRectangle(wheelsBrush, _startPosX.Value + _drawningBulldozerWidth - 50, _startPosY.Value, 50, 15); g.FillRectangle(wheelstringBuilderrush, _startPosX.Value + _drawningBulldozerWidth - 50, _startPosY.Value, 50, 15);
g.DrawRectangle(pen, _startPosX.Value + _drawningBulldozerWidth - 50, _startPosY.Value, 50, 15); g.DrawRectangle(pen, _startPosX.Value + _drawningBulldozerWidth - 50, _startPosY.Value, 50, 15);
//strange rectangles //strange rectangles
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 25, 3, _drawningBulldozerHeight - 50); g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 25, 3, _drawningBulldozerHeight - 50);

View File

@ -50,5 +50,29 @@ public class EntityBulldozer : EntityDozer
Caterpillar = caterpillar; Caterpillar = caterpillar;
} }
// TODO то же, что и в EntityDozer.
/// <summary>
/// Получение строк со значениями свойств объекта класса-сущности.
/// </summary>
/// <returns></returns>
public override string[] GetStringRepresentation()
{
return new[] { nameof(EntityBulldozer), Speed.ToString(), Weight.ToString(), Weight.ToString(), BodyColor.Name,
AdditionalColor.Name, Blade.ToString(), Caterpillar.ToString() };
}
/// <summary>
/// Создание объекта из массива строк.
/// </summary>
/// <param name="strs"></param>
/// <returns></returns>
public static EntityBulldozer? CreateEntityBulldozer(string[] strs)
{
if (strs.Length != 7 || strs[0] != nameof(EntityBulldozer))
{
return null;
}
return new EntityBulldozer(Convert.ToInt32(strs[1]), Convert.ToDouble(strs[2]), Color.FromName(strs[3]),
Color.FromName(strs[4]), Convert.ToBoolean(strs[5]), Convert.ToBoolean(strs[6]));
}
} }

View File

@ -46,10 +46,17 @@
buttonCreateCompany = new Button(); buttonCreateCompany = new Button();
comboBoxSelectorCompany = new ComboBox(); comboBoxSelectorCompany = new ComboBox();
pictureBox = new PictureBox(); pictureBox = new PictureBox();
menuStrip = new MenuStrip();
fileToolStripMenuItem = new ToolStripMenuItem();
saveToolStripMenuItem = new ToolStripMenuItem();
loadToolStripMenuItem = new ToolStripMenuItem();
saveFileDialog = new SaveFileDialog();
openFileDialog = new OpenFileDialog();
groupBoxTools.SuspendLayout(); groupBoxTools.SuspendLayout();
panelCompanyTools.SuspendLayout(); panelCompanyTools.SuspendLayout();
panelStorage.SuspendLayout(); panelStorage.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
menuStrip.SuspendLayout();
SuspendLayout(); SuspendLayout();
// //
// groupBoxTools // groupBoxTools
@ -60,9 +67,9 @@
groupBoxTools.Controls.Add(comboBoxSelectorCompany); groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right; groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point); groupBoxTools.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point);
groupBoxTools.Location = new Point(1290, 0); groupBoxTools.Location = new Point(1489, 41);
groupBoxTools.Name = "groupBoxTools"; groupBoxTools.Name = "groupBoxTools";
groupBoxTools.Size = new Size(358, 968); groupBoxTools.Size = new Size(413, 963);
groupBoxTools.TabIndex = 0; groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false; groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты"; groupBoxTools.Text = "Инструменты";
@ -75,18 +82,18 @@
panelCompanyTools.Controls.Add(buttonGoToCheck); panelCompanyTools.Controls.Add(buttonGoToCheck);
panelCompanyTools.Controls.Add(buttonRefresh); panelCompanyTools.Controls.Add(buttonRefresh);
panelCompanyTools.Enabled = false; panelCompanyTools.Enabled = false;
panelCompanyTools.Location = new Point(3, 624); panelCompanyTools.Location = new Point(3, 602);
panelCompanyTools.Name = "panelCompanyTools"; panelCompanyTools.Name = "panelCompanyTools";
panelCompanyTools.Size = new Size(400, 345); panelCompanyTools.Size = new Size(406, 356);
panelCompanyTools.TabIndex = 7; panelCompanyTools.TabIndex = 7;
// //
// buttonAddDozer // buttonAddDozer
// //
buttonAddDozer.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; buttonAddDozer.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddDozer.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point); buttonAddDozer.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point);
buttonAddDozer.Location = new Point(11, 14); buttonAddDozer.Location = new Point(13, 14);
buttonAddDozer.Name = "buttonAddDozer"; buttonAddDozer.Name = "buttonAddDozer";
buttonAddDozer.Size = new Size(332, 64); buttonAddDozer.Size = new Size(383, 66);
buttonAddDozer.TabIndex = 2; buttonAddDozer.TabIndex = 2;
buttonAddDozer.Text = "Добавление бульдозера"; buttonAddDozer.Text = "Добавление бульдозера";
buttonAddDozer.UseVisualStyleBackColor = true; buttonAddDozer.UseVisualStyleBackColor = true;
@ -96,9 +103,9 @@
// //
buttonDelBulldozer.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; buttonDelBulldozer.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonDelBulldozer.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point); buttonDelBulldozer.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point);
buttonDelBulldozer.Location = new Point(11, 131); buttonDelBulldozer.Location = new Point(13, 135);
buttonDelBulldozer.Name = "buttonDelBulldozer"; buttonDelBulldozer.Name = "buttonDelBulldozer";
buttonDelBulldozer.Size = new Size(332, 63); buttonDelBulldozer.Size = new Size(383, 65);
buttonDelBulldozer.TabIndex = 3; buttonDelBulldozer.TabIndex = 3;
buttonDelBulldozer.Text = "Удаленить бульдозер"; buttonDelBulldozer.Text = "Удаленить бульдозер";
buttonDelBulldozer.UseVisualStyleBackColor = true; buttonDelBulldozer.UseVisualStyleBackColor = true;
@ -107,9 +114,10 @@
// maskedTextBox // maskedTextBox
// //
maskedTextBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; maskedTextBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
maskedTextBox.Location = new Point(11, 84); maskedTextBox.Location = new Point(13, 87);
maskedTextBox.Mask = "00";
maskedTextBox.Name = "maskedTextBox"; maskedTextBox.Name = "maskedTextBox";
maskedTextBox.Size = new Size(332, 41); maskedTextBox.Size = new Size(382, 41);
maskedTextBox.TabIndex = 5; maskedTextBox.TabIndex = 5;
maskedTextBox.ValidatingType = typeof(int); maskedTextBox.ValidatingType = typeof(int);
// //
@ -117,9 +125,9 @@
// //
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonGoToCheck.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point); buttonGoToCheck.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point);
buttonGoToCheck.Location = new Point(11, 200); buttonGoToCheck.Location = new Point(13, 206);
buttonGoToCheck.Name = "buttonGoToCheck"; buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(332, 63); buttonGoToCheck.Size = new Size(383, 65);
buttonGoToCheck.TabIndex = 3; buttonGoToCheck.TabIndex = 3;
buttonGoToCheck.Text = "Передать на тесты"; buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true; buttonGoToCheck.UseVisualStyleBackColor = true;
@ -129,9 +137,9 @@
// //
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRefresh.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point); buttonRefresh.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point);
buttonRefresh.Location = new Point(11, 269); buttonRefresh.Location = new Point(13, 277);
buttonRefresh.Name = "buttonRefresh"; buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(332, 63); buttonRefresh.Size = new Size(383, 65);
buttonRefresh.TabIndex = 3; buttonRefresh.TabIndex = 3;
buttonRefresh.Text = "Обновить"; buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true; buttonRefresh.UseVisualStyleBackColor = true;
@ -149,23 +157,23 @@
panelStorage.Dock = DockStyle.Top; panelStorage.Dock = DockStyle.Top;
panelStorage.Location = new Point(3, 37); panelStorage.Location = new Point(3, 37);
panelStorage.Name = "panelStorage"; panelStorage.Name = "panelStorage";
panelStorage.Size = new Size(352, 465); panelStorage.Size = new Size(407, 448);
panelStorage.TabIndex = 6; panelStorage.TabIndex = 6;
// //
// listBoxCollection // listBoxCollection
// //
listBoxCollection.FormattingEnabled = true; listBoxCollection.FormattingEnabled = true;
listBoxCollection.ItemHeight = 33; listBoxCollection.ItemHeight = 33;
listBoxCollection.Location = new Point(11, 219); listBoxCollection.Location = new Point(13, 209);
listBoxCollection.Name = "listBoxCollection"; listBoxCollection.Name = "listBoxCollection";
listBoxCollection.Size = new Size(332, 169); listBoxCollection.Size = new Size(382, 169);
listBoxCollection.TabIndex = 5; listBoxCollection.TabIndex = 5;
// //
// buttonCollectionDel // buttonCollectionDel
// //
buttonCollectionDel.Location = new Point(11, 407); buttonCollectionDel.Location = new Point(13, 394);
buttonCollectionDel.Name = "buttonCollectionDel"; buttonCollectionDel.Name = "buttonCollectionDel";
buttonCollectionDel.Size = new Size(332, 46); buttonCollectionDel.Size = new Size(383, 47);
buttonCollectionDel.TabIndex = 4; buttonCollectionDel.TabIndex = 4;
buttonCollectionDel.Text = "Удалить коллекцию"; buttonCollectionDel.Text = "Удалить коллекцию";
buttonCollectionDel.UseVisualStyleBackColor = true; buttonCollectionDel.UseVisualStyleBackColor = true;
@ -173,9 +181,9 @@
// //
// buttonCollectionAdd // buttonCollectionAdd
// //
buttonCollectionAdd.Location = new Point(11, 157); buttonCollectionAdd.Location = new Point(13, 144);
buttonCollectionAdd.Name = "buttonCollectionAdd"; buttonCollectionAdd.Name = "buttonCollectionAdd";
buttonCollectionAdd.Size = new Size(332, 46); buttonCollectionAdd.Size = new Size(383, 47);
buttonCollectionAdd.TabIndex = 4; buttonCollectionAdd.TabIndex = 4;
buttonCollectionAdd.Text = "Добавить коллекцию"; buttonCollectionAdd.Text = "Добавить коллекцию";
buttonCollectionAdd.UseVisualStyleBackColor = true; buttonCollectionAdd.UseVisualStyleBackColor = true;
@ -184,7 +192,7 @@
// radioButtonList // radioButtonList
// //
radioButtonList.AutoSize = true; radioButtonList.AutoSize = true;
radioButtonList.Location = new Point(183, 115); radioButtonList.Location = new Point(211, 99);
radioButtonList.Name = "radioButtonList"; radioButtonList.Name = "radioButtonList";
radioButtonList.Size = new Size(129, 37); radioButtonList.Size = new Size(129, 37);
radioButtonList.TabIndex = 3; radioButtonList.TabIndex = 3;
@ -195,7 +203,7 @@
// radioButtonMassive // radioButtonMassive
// //
radioButtonMassive.AutoSize = true; radioButtonMassive.AutoSize = true;
radioButtonMassive.Location = new Point(38, 115); radioButtonMassive.Location = new Point(44, 99);
radioButtonMassive.Name = "radioButtonMassive"; radioButtonMassive.Name = "radioButtonMassive";
radioButtonMassive.Size = new Size(130, 37); radioButtonMassive.Size = new Size(130, 37);
radioButtonMassive.TabIndex = 2; radioButtonMassive.TabIndex = 2;
@ -205,15 +213,15 @@
// //
// textBoxCollectionName // textBoxCollectionName
// //
textBoxCollectionName.Location = new Point(11, 59); textBoxCollectionName.Location = new Point(13, 48);
textBoxCollectionName.Name = "textBoxCollectionName"; textBoxCollectionName.Name = "textBoxCollectionName";
textBoxCollectionName.Size = new Size(332, 41); textBoxCollectionName.Size = new Size(382, 41);
textBoxCollectionName.TabIndex = 1; textBoxCollectionName.TabIndex = 1;
// //
// labelCollectionName // labelCollectionName
// //
labelCollectionName.AutoSize = true; labelCollectionName.AutoSize = true;
labelCollectionName.Location = new Point(57, 13); labelCollectionName.Location = new Point(54, 5);
labelCollectionName.Name = "labelCollectionName"; labelCollectionName.Name = "labelCollectionName";
labelCollectionName.Size = new Size(263, 33); labelCollectionName.Size = new Size(263, 33);
labelCollectionName.TabIndex = 0; labelCollectionName.TabIndex = 0;
@ -221,9 +229,9 @@
// //
// buttonCreateCompany // buttonCreateCompany
// //
buttonCreateCompany.Location = new Point(14, 572); buttonCreateCompany.Location = new Point(16, 547);
buttonCreateCompany.Name = "buttonCreateCompany"; buttonCreateCompany.Name = "buttonCreateCompany";
buttonCreateCompany.Size = new Size(332, 46); buttonCreateCompany.Size = new Size(383, 47);
buttonCreateCompany.TabIndex = 4; buttonCreateCompany.TabIndex = 4;
buttonCreateCompany.Text = "Создать компанию"; buttonCreateCompany.Text = "Создать компанию";
buttonCreateCompany.UseVisualStyleBackColor = true; buttonCreateCompany.UseVisualStyleBackColor = true;
@ -236,28 +244,76 @@
comboBoxSelectorCompany.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point); comboBoxSelectorCompany.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point);
comboBoxSelectorCompany.FormattingEnabled = true; comboBoxSelectorCompany.FormattingEnabled = true;
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
comboBoxSelectorCompany.Location = new Point(14, 525); comboBoxSelectorCompany.Location = new Point(16, 498);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(332, 41); comboBoxSelectorCompany.Size = new Size(382, 41);
comboBoxSelectorCompany.TabIndex = 1; comboBoxSelectorCompany.TabIndex = 1;
comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged; comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
// //
// pictureBox // pictureBox
// //
pictureBox.Dock = DockStyle.Fill; pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 0); pictureBox.Location = new Point(0, 41);
pictureBox.Name = "pictureBox"; pictureBox.Name = "pictureBox";
pictureBox.Size = new Size(1290, 968); pictureBox.Size = new Size(1489, 963);
pictureBox.TabIndex = 4; pictureBox.TabIndex = 4;
pictureBox.TabStop = false; pictureBox.TabStop = false;
// //
// menuStrip
//
menuStrip.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point);
menuStrip.ImageScalingSize = new Size(32, 32);
menuStrip.Items.AddRange(new ToolStripItem[] { fileToolStripMenuItem });
menuStrip.Location = new Point(0, 0);
menuStrip.Name = "menuStrip";
menuStrip.Padding = new Padding(7, 2, 0, 2);
menuStrip.Size = new Size(1902, 41);
menuStrip.TabIndex = 5;
menuStrip.Text = "menuStrip";
//
// fileToolStripMenuItem
//
fileToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { saveToolStripMenuItem, loadToolStripMenuItem });
fileToolStripMenuItem.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point);
fileToolStripMenuItem.Name = "fileToolStripMenuItem";
fileToolStripMenuItem.Size = new Size(93, 37);
fileToolStripMenuItem.Text = "Файл";
//
// saveToolStripMenuItem
//
saveToolStripMenuItem.Name = "saveToolStripMenuItem";
saveToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S;
saveToolStripMenuItem.Size = new Size(369, 44);
saveToolStripMenuItem.Text = "Сохранение";
saveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
//
// loadToolStripMenuItem
//
loadToolStripMenuItem.Name = "loadToolStripMenuItem";
loadToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.L;
loadToolStripMenuItem.Size = new Size(369, 44);
loadToolStripMenuItem.Text = "Загрузка";
loadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
//
// saveFileDialog
//
saveFileDialog.Filter = "txt file | *.txt";
//
// openFileDialog
//
openFileDialog.FileName = "openFileDialog";
openFileDialog.Filter = "txt file | *.txt";
//
// FormBulldozerCollection // FormBulldozerCollection
// //
AutoScaleDimensions = new SizeF(13F, 32F); AutoScaleDimensions = new SizeF(15F, 33F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1648, 968); ClientSize = new Size(1902, 1004);
Controls.Add(pictureBox); Controls.Add(pictureBox);
Controls.Add(groupBoxTools); Controls.Add(groupBoxTools);
Controls.Add(menuStrip);
Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point);
MainMenuStrip = menuStrip;
Name = "FormBulldozerCollection"; Name = "FormBulldozerCollection";
Text = "Коллекция бульдозеров"; Text = "Коллекция бульдозеров";
groupBoxTools.ResumeLayout(false); groupBoxTools.ResumeLayout(false);
@ -266,7 +322,10 @@
panelStorage.ResumeLayout(false); panelStorage.ResumeLayout(false);
panelStorage.PerformLayout(); panelStorage.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
menuStrip.ResumeLayout(false);
menuStrip.PerformLayout();
ResumeLayout(false); ResumeLayout(false);
PerformLayout();
} }
#endregion #endregion
@ -289,5 +348,11 @@
private Button buttonCollectionDel; private Button buttonCollectionDel;
private Button buttonCreateCompany; private Button buttonCreateCompany;
private Panel panelCompanyTools; private Panel panelCompanyTools;
private MenuStrip menuStrip;
private ToolStripMenuItem fileToolStripMenuItem;
private ToolStripMenuItem saveToolStripMenuItem;
private ToolStripMenuItem loadToolStripMenuItem;
private SaveFileDialog saveFileDialog;
private OpenFileDialog openFileDialog;
} }
} }

View File

@ -10,6 +10,8 @@ using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using ProjectBulldozer.CollectionGenericObjects;
using ProjectBulldozer.Drawnings;
namespace ProjectBulldozer; namespace ProjectBulldozer;
@ -359,4 +361,50 @@ public partial class FormBulldozerCollection : Form
panelCompanyTools.Enabled = true; panelCompanyTools.Enabled = true;
RefreshListBoxItems(); RefreshListBoxItems();
} }
/// <summary>
/// Обработка нажатия "Сохранить"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
{
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
if (_storageCollection.SaveData(saveFileDialog.FileName))
{
MessageBox.Show("Сохранение прошло успешно.", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Не сохранено!", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
/// <summary>
/// Обрработка нажати "Загрузка"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
{
// Логика
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
if (_storageCollection.LoadData(openFileDialog.FileName))
{
MessageBox.Show("Загрузка прошла успешно.", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Information);
RefreshListBoxItems();
}
else
{
MessageBox.Show("Загрузка не удалась!", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
} }

View File

@ -117,4 +117,13 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>204, 17</value>
</metadata>
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>447, 17</value>
</metadata>
</root> </root>