diff --git a/ContainerShip/ContainerShip/AbstractStrategy.cs b/ContainerShip/ContainerShip/AbstractStrategy.cs
index 503523a..927a3b5 100644
--- a/ContainerShip/ContainerShip/AbstractStrategy.cs
+++ b/ContainerShip/ContainerShip/AbstractStrategy.cs
@@ -7,10 +7,9 @@ using static ProjectContainerShip.Direction;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace ProjectContainerShip.MovementStrategy
-{
- ///
- /// Класс-стратегия перемещения объекта
- ///
+{///
+ /// Класс-стратегия перемещения объекта
+ ///
public abstract class AbstractStrategy
{
///
diff --git a/ContainerShip/ContainerShip/ContainerGenericCollection.cs b/ContainerShip/ContainerShip/ContainerGenericCollection.cs
index 191f18c..bf103c3 100644
--- a/ContainerShip/ContainerShip/ContainerGenericCollection.cs
+++ b/ContainerShip/ContainerShip/ContainerGenericCollection.cs
@@ -4,7 +4,6 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectContainerShip.DrawningObjects;
-using ProjectContainerShip.Generics;
using ProjectContainerShip.MovementStrategy;
namespace ProjectContainerShip.Generics
@@ -18,6 +17,10 @@ namespace ProjectContainerShip.Generics
where T : DrawningShip
where U : IMoveableObject
{
+ ///
+ /// Получение объектов коллекции
+ ///
+ public IEnumerable GetShip => _collection.GetShip();
///
/// Ширина окна прорисовки
///
@@ -57,14 +60,14 @@ namespace ProjectContainerShip.Generics
///
///
///
- public static bool operator +(ContainerGenericCollection collect, T?
+ public static int? operator +(ContainerGenericCollection collect, T?
obj)
{
if (obj == null)
{
- return false;
+ return -1;
}
- return collect?._collection.Insert(obj) ?? false;
+ return collect?._collection.Insert(obj);
}
///
/// Перегрузка оператора вычитания
@@ -72,14 +75,15 @@ namespace ProjectContainerShip.Generics
///
///
///
- public static T? operator -(ContainerGenericCollection collect, int pos)
+ public static bool operator -(ContainerGenericCollection collect, int
+ pos)
{
T? obj = collect._collection[pos];
if (obj != null)
{
- collect._collection.Remove(pos);
+ return collect._collection.Remove(pos);
}
- return obj;
+ return false;
}
///
/// Получение объекта IMoveableObject
diff --git a/ContainerShip/ContainerShip/ContainerGenericStorage.cs b/ContainerShip/ContainerShip/ContainerGenericStorage.cs
index 3a77585..a80c909 100644
--- a/ContainerShip/ContainerShip/ContainerGenericStorage.cs
+++ b/ContainerShip/ContainerShip/ContainerGenericStorage.cs
@@ -32,6 +32,18 @@ namespace ProjectContainerShip
///
private readonly int _pictureHeight;
///
+ /// Разделитель для записи ключа и значения элемента словаря
+ ///
+ private static readonly char _separatorForKeyValue = '|';
+ ///
+ /// Разделитель для записей коллекции данных в файл
+ ///
+ private readonly char _separatorRecords = ';';
+ ///
+ /// Разделитель для записи информации по объекту в файл
+ ///
+ private static readonly char _separatorForObject = ':';
+ ///
/// Конструктор
///
///
@@ -51,8 +63,8 @@ namespace ProjectContainerShip
{
if (!_shipStorages.ContainsKey(name))
{
- ContainerGenericCollection newSet = new ContainerGenericCollection(_pictureWidth, _pictureHeight);
- _shipStorages.Add(name, newSet);
+ var shipCollection = new ContainerGenericCollection(_pictureWidth, _pictureHeight);
+ _shipStorages.Add(name, shipCollection);
}
}
///
@@ -82,6 +94,95 @@ namespace ProjectContainerShip
return null;
}
}
+ ///
+ /// Сохранение информации в хранилище в файл
+ ///
+ /// Путь и имя файла
+ /// true - сохранение прошло успешно, false - ошибка при сохранении данных
+ public bool SaveData(string filename)
+ {
+ if (File.Exists(filename))
+ {
+ File.Delete(filename);
+ }
+ StringBuilder data = new();
+ foreach (KeyValuePair> record in _shipStorages)
+ {
+ StringBuilder records = new();
+ foreach (DrawningShip? elem in record.Value.GetShip)
+ {
+ records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
+ }
+ data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}");
+ }
+ if (data.Length == 0)
+ {
+ return false;
+ }
+ using (StreamWriter writer = new StreamWriter(filename))
+ {
+ writer.WriteLine("shipStorages");
+ writer.Write(data.ToString());
+ return true;
+ }
+ }
+ ///
+ /// Загрузка информации в хранилище из файла
+ ///
+ /// Путь и имя файла
+ /// true - загрузка прошла успешно, false - ошибка при загрузке данных
+ public bool LoadData(string filename)
+ {
+ if (!File.Exists(filename))
+ {
+ return false;
+ }
+ using (StreamReader reader = new StreamReader(filename))
+ {
+ string cheker = reader.ReadLine();
+ if (cheker == null)
+ {
+ return false;
+ }
+ if (!cheker.StartsWith("shipStorages"))
+ {
+ return false;
+ }
+ _shipStorages.Clear();
+ string strs;
+ bool firstinit = true;
+ while ((strs = reader.ReadLine()) != null)
+ {
+ if (strs == null && firstinit)
+ {
+ return false;
+ }
+ if (strs == null)
+ {
+ return false;
+ }
+ firstinit = false;
+ string name = strs.Split(_separatorForKeyValue)[0];
+ ContainerGenericCollection collection = new(_pictureWidth, _pictureHeight);
+ foreach (string data in strs.Split(_separatorForKeyValue)[1].Split(_separatorRecords))
+ {
+ DrawningShip? ship =
+ data?.CreateDrawningShip(_separatorForObject, _pictureWidth, _pictureHeight);
+ if (ship != null)
+ {
+ int? result = collection + ship;
+ if (result == null || result.Value == -1)
+ {
+ return false;
+ }
+ }
+ }
+ _shipStorages.Add(name, collection);
+ }
+ return true;
+ }
+ }
}
}
diff --git a/ContainerShip/ContainerShip/ContainerShip.csproj b/ContainerShip/ContainerShip/ContainerShip.csproj
index 13ee123..ce86fc6 100644
--- a/ContainerShip/ContainerShip/ContainerShip.csproj
+++ b/ContainerShip/ContainerShip/ContainerShip.csproj
@@ -23,4 +23,8 @@
+
+
+
+
\ No newline at end of file
diff --git a/ContainerShip/ContainerShip/DrawingContainerShip.cs b/ContainerShip/ContainerShip/DrawingContainerShip.cs
index 56de59e..ddf14d1 100644
--- a/ContainerShip/ContainerShip/DrawingContainerShip.cs
+++ b/ContainerShip/ContainerShip/DrawingContainerShip.cs
@@ -37,7 +37,7 @@ namespace ProjectContainerShip.DrawningObjects
{
return;
}
- Brush additionalBrush = new SolidBrush(containerShip.AdditionalColor);
+ Brush additionalBrush = new SolidBrush(containerShip.AdditionalColor);
if (containerShip.Container)
{
g.FillRectangle(additionalBrush, _startPosX + 55, _startPosY + 7, 35, 5);
diff --git a/ContainerShip/ContainerShip/DrawningObjectShip.cs b/ContainerShip/ContainerShip/DrawningObjectShip.cs
index a08e165..2c4df94 100644
--- a/ContainerShip/ContainerShip/DrawningObjectShip.cs
+++ b/ContainerShip/ContainerShip/DrawningObjectShip.cs
@@ -32,5 +32,19 @@ namespace ProjectContainerShip.MovementStrategy
public int GetStep => (int)(_drawningShip?.EntityShip?.Step ?? 0);
public bool CheckCanMove(DirectionType direction) => _drawningShip?.CanMove(direction) ?? false;
public void MoveObject(DirectionType direction) => _drawningShip?.MoveTransport(direction);
+ public void SetPosition(int x, int y)
+ {
+ if (_drawningShip != null)
+ {
+ _drawningShip.SetPosition(x, y);
+ }
+ }
+ public void Draw(Graphics g)
+ {
+ if (_drawningShip != null)
+ {
+ _drawningShip.DrawTransport(g);
+ }
+ }
}
}
diff --git a/ContainerShip/ContainerShip/DrawningShip.cs b/ContainerShip/ContainerShip/DrawningShip.cs
index d3e7487..1dcff4e 100644
--- a/ContainerShip/ContainerShip/DrawningShip.cs
+++ b/ContainerShip/ContainerShip/DrawningShip.cs
@@ -57,12 +57,9 @@ namespace ProjectContainerShip.DrawningObjects
/// Высота картинки
public DrawningShip(int speed, double weight, Color bodyColor, int width, int height)
{
- if (width > _shipWidth && height > _shipHeight)
- {
_pictureWidth = width;
_pictureHeight = height;
EntityShip = new EntityShip(speed, weight, bodyColor);
- }
}
///
/// Конструктор
@@ -97,7 +94,6 @@ namespace ProjectContainerShip.DrawningObjects
else _startPosX = 0;
if ((y > 0) && (y < _pictureHeight))
_startPosY = y;
-
else _startPosY = 0;
_startPosX = x;
_startPosY = y;
@@ -118,7 +114,6 @@ namespace ProjectContainerShip.DrawningObjects
/// Высота объекта
///
public int GetHeight => _shipHeight;
- public object GetObjectPosition { get; internal set; }
///
/// Проверка, что объект может переместится по указанному направлению
///
@@ -157,19 +152,19 @@ namespace ProjectContainerShip.DrawningObjects
//влево
case DirectionType.Left:
_startPosX -= (int)EntityShip.Step;
- break;
+ break;
//вверх
case DirectionType.Up:
_startPosY -= (int)EntityShip.Step;
- break;
+ break;
// вправо
case DirectionType.Right:
_startPosX += (int)EntityShip.Step;
- break;
+ break;
//вниз
case DirectionType.Down:
_startPosY += (int)EntityShip.Step;
- break;
+ break;
}
}
///
@@ -177,11 +172,11 @@ namespace ProjectContainerShip.DrawningObjects
///
///
public virtual void DrawTransport(Graphics g)
- {
+ {
if (EntityShip == null)
{
return;
- }
+ }
Brush bodyColor = new SolidBrush(EntityShip.BodyColor);
//границы корабля
Brush brRd = new SolidBrush(Color.Red);
diff --git a/ContainerShip/ContainerShip/EntityContainerShip.cs b/ContainerShip/ContainerShip/EntityContainerShip.cs
index 58d8842..08c9c55 100644
--- a/ContainerShip/ContainerShip/EntityContainerShip.cs
+++ b/ContainerShip/ContainerShip/EntityContainerShip.cs
@@ -21,7 +21,6 @@ namespace ProjectContainerShip.Entities
/// Признак (опция) наличия дополнительных контейнеров
///
public bool Container { get; private set; }
-
///
/// Инициализация полей объекта-класса контейнеровоза
///
@@ -29,8 +28,8 @@ namespace ProjectContainerShip.Entities
/// Вес
/// Основной цвет
/// Дополнительный цвет
- /// Признак наличия труб
- /// Признак наличия топлива
+ /// Признак наличия крана
+ /// Признак наличия контейнеров
public EntityContainerShip(int speed, double weight, Color bodyColor, Color additionalColor, bool crane, bool container) : base(speed, weight, bodyColor)
{
AdditionalColor = additionalColor;
diff --git a/ContainerShip/ContainerShip/ExtentionDrawningContainer.cs b/ContainerShip/ContainerShip/ExtentionDrawningContainer.cs
new file mode 100644
index 0000000..4b16863
--- /dev/null
+++ b/ContainerShip/ContainerShip/ExtentionDrawningContainer.cs
@@ -0,0 +1,64 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using ProjectContainerShip.Entities;
+
+namespace ProjectContainerShip.DrawningObjects
+{
+ ///
+ /// Расширение для класса EntityShip
+ ///
+ public static class ExtentionDrawningContainer
+ {
+ ///
+ /// Создание объекта из строки
+ ///
+ /// Строка с данными для создания объекта
+ /// Разделитель даннных
+ /// Ширина
+ /// Высота
+ /// Объект
+ public static DrawningShip? CreateDrawningShip(this string info, char
+ separatorForObject, int width, int height)
+ {
+ string[] strs = info.Split(separatorForObject);
+ if (strs.Length == 3)
+ {
+ return new DrawningShip(Convert.ToInt32(strs[0]),
+ Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height);
+ }
+ else if (strs.Length == 6)
+ {
+ return new DrawningContainerShip(Convert.ToInt32(strs[0]),
+ Convert.ToInt32(strs[1]),
+ Color.FromName(strs[2]),
+ Color.FromName(strs[3]),
+ Convert.ToBoolean(strs[4]),
+ Convert.ToBoolean(strs[5]), width, height);
+ }
+ return null;
+ }
+ ///
+ /// Получение данных для сохранения в файл
+ ///
+ /// Сохраняемый объект
+ /// Разделитель даннных
+ /// Строка с данными по объекту
+ public static string GetDataForSave(this DrawningShip drawningShip, char separatorForObject)
+ {
+ var ship = drawningShip.EntityShip;
+ if (ship == null)
+ {
+ return string.Empty;
+ }
+ var str = $"{ship.Speed}{separatorForObject}{ship.Weight}{separatorForObject}{ship.BodyColor.Name}";
+ if (ship is not EntityContainerShip dopShip)
+ {
+ return str;
+ }
+ return $"{str}{separatorForObject}{dopShip.AdditionalColor.Name}{separatorForObject}{dopShip.Crane}{separatorForObject}{dopShip.Container}";
+ }
+ }
+}
diff --git a/ContainerShip/ContainerShip/FormContainerCollection.Designer.cs b/ContainerShip/ContainerShip/FormContainerCollection.Designer.cs
index 9e579cb..6581615 100644
--- a/ContainerShip/ContainerShip/FormContainerCollection.Designer.cs
+++ b/ContainerShip/ContainerShip/FormContainerCollection.Designer.cs
@@ -34,13 +34,20 @@
buttonRemoveEx = new Button();
buttonRefreshCollection = new Button();
groupBox1 = new GroupBox();
+ menuStrip = new MenuStrip();
+ fileToolStripMenuItem = new ToolStripMenuItem();
+ SaveToolStripMenuItem = new ToolStripMenuItem();
+ LoadToolStripMenuItem = new ToolStripMenuItem();
groupBox2 = new GroupBox();
textBoxStorageName = new TextBox();
buttonDelObject = new Button();
listBoxStorages = new ListBox();
buttonAddObject = new Button();
+ saveFileDialog = new SaveFileDialog();
+ openFileDialog = new OpenFileDialog();
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
groupBox1.SuspendLayout();
+ menuStrip.SuspendLayout();
groupBox2.SuspendLayout();
SuspendLayout();
//
@@ -55,14 +62,14 @@
//
// maskedTextBoxNumber
//
- maskedTextBoxNumber.Location = new Point(21, 326);
+ maskedTextBoxNumber.Location = new Point(19, 404);
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
maskedTextBoxNumber.Size = new Size(95, 27);
maskedTextBoxNumber.TabIndex = 1;
//
// buttonAddEx
//
- buttonAddEx.Location = new Point(21, 282);
+ buttonAddEx.Location = new Point(19, 371);
buttonAddEx.Name = "buttonAddEx";
buttonAddEx.Size = new Size(95, 27);
buttonAddEx.TabIndex = 2;
@@ -72,7 +79,7 @@
//
// buttonRemoveEx
//
- buttonRemoveEx.Location = new Point(19, 359);
+ buttonRemoveEx.Location = new Point(19, 437);
buttonRemoveEx.Name = "buttonRemoveEx";
buttonRemoveEx.Size = new Size(95, 27);
buttonRemoveEx.TabIndex = 3;
@@ -82,7 +89,7 @@
//
// buttonRefreshCollection
//
- buttonRefreshCollection.Location = new Point(21, 405);
+ buttonRefreshCollection.Location = new Point(19, 470);
buttonRefreshCollection.Name = "buttonRefreshCollection";
buttonRefreshCollection.Size = new Size(95, 27);
buttonRefreshCollection.TabIndex = 4;
@@ -92,6 +99,7 @@
//
// groupBox1
//
+ groupBox1.Controls.Add(menuStrip);
groupBox1.Controls.Add(groupBox2);
groupBox1.Controls.Add(buttonAddEx);
groupBox1.Controls.Add(buttonRefreshCollection);
@@ -99,18 +107,50 @@
groupBox1.Controls.Add(buttonRemoveEx);
groupBox1.Location = new Point(812, 0);
groupBox1.Name = "groupBox1";
- groupBox1.Size = new Size(120, 461);
+ groupBox1.Size = new Size(120, 503);
groupBox1.TabIndex = 5;
groupBox1.TabStop = false;
groupBox1.Text = "Инструменты";
//
+ // menuStrip
+ //
+ menuStrip.ImageScalingSize = new Size(20, 20);
+ menuStrip.Items.AddRange(new ToolStripItem[] { fileToolStripMenuItem });
+ menuStrip.Location = new Point(3, 23);
+ menuStrip.Name = "menuStrip";
+ menuStrip.Padding = new Padding(7, 3, 0, 3);
+ menuStrip.Size = new Size(114, 30);
+ menuStrip.TabIndex = 8;
+ menuStrip.Text = "menuStrip1";
+ //
+ // fileToolStripMenuItem
+ //
+ fileToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { SaveToolStripMenuItem, LoadToolStripMenuItem });
+ fileToolStripMenuItem.Name = "fileToolStripMenuItem";
+ fileToolStripMenuItem.Size = new Size(59, 24);
+ fileToolStripMenuItem.Text = "Файл";
+ //
+ // SaveToolStripMenuItem
+ //
+ SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
+ SaveToolStripMenuItem.Size = new Size(224, 26);
+ SaveToolStripMenuItem.Text = "Сохранение";
+ SaveToolStripMenuItem.Click += SaveToolStripMenuItem_Click_1;
+ //
+ // LoadToolStripMenuItem
+ //
+ LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
+ LoadToolStripMenuItem.Size = new Size(224, 26);
+ LoadToolStripMenuItem.Text = "Загрузка";
+ LoadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
+ //
// groupBox2
//
groupBox2.Controls.Add(textBoxStorageName);
groupBox2.Controls.Add(buttonDelObject);
groupBox2.Controls.Add(listBoxStorages);
groupBox2.Controls.Add(buttonAddObject);
- groupBox2.Location = new Point(13, 28);
+ groupBox2.Location = new Point(6, 151);
groupBox2.Name = "groupBox2";
groupBox2.Size = new Size(116, 214);
groupBox2.TabIndex = 5;
@@ -119,15 +159,14 @@
//
// textBoxStorageName
//
- textBoxStorageName.Location = new Point(8, 26);
+ textBoxStorageName.Location = new Point(13, 26);
textBoxStorageName.Name = "textBoxStorageName";
textBoxStorageName.Size = new Size(95, 27);
textBoxStorageName.TabIndex = 6;
- textBoxStorageName.TextChanged += textBoxStorageName_TextChanged;
//
// buttonDelObject
//
- buttonDelObject.Location = new Point(8, 162);
+ buttonDelObject.Location = new Point(13, 162);
buttonDelObject.Name = "buttonDelObject";
buttonDelObject.Size = new Size(95, 27);
buttonDelObject.TabIndex = 8;
@@ -139,7 +178,7 @@
//
listBoxStorages.FormattingEnabled = true;
listBoxStorages.ItemHeight = 20;
- listBoxStorages.Location = new Point(8, 92);
+ listBoxStorages.Location = new Point(13, 92);
listBoxStorages.Name = "listBoxStorages";
listBoxStorages.Size = new Size(95, 64);
listBoxStorages.TabIndex = 6;
@@ -147,7 +186,7 @@
//
// buttonAddObject
//
- buttonAddObject.Location = new Point(8, 59);
+ buttonAddObject.Location = new Point(13, 59);
buttonAddObject.Name = "buttonAddObject";
buttonAddObject.Size = new Size(95, 27);
buttonAddObject.TabIndex = 7;
@@ -155,6 +194,17 @@
buttonAddObject.UseVisualStyleBackColor = true;
buttonAddObject.Click += ButtonAddObject_Click;
//
+ // saveFileDialog
+ //
+ saveFileDialog.Filter = "txt file | *.txt";
+ saveFileDialog.Title = "Выберите текстовый файл";
+ //
+ // openFileDialog
+ //
+ openFileDialog.FileName = "openFileDialog1";
+ openFileDialog.Filter = "txt file | *.txt";
+ openFileDialog.Title = "Сохранить текстовый файл";
+ //
// FormContainerCollection
//
ClientSize = new Size(932, 503);
@@ -164,6 +214,8 @@
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
groupBox1.ResumeLayout(false);
groupBox1.PerformLayout();
+ menuStrip.ResumeLayout(false);
+ menuStrip.PerformLayout();
groupBox2.ResumeLayout(false);
groupBox2.PerformLayout();
ResumeLayout(false);
@@ -182,5 +234,11 @@
private Button buttonDelObject;
private ListBox listBoxStorages;
private Button buttonAddObject;
+ private MenuStrip menuStrip;
+ private ToolStripMenuItem fileToolStripMenuItem;
+ private ToolStripMenuItem SaveToolStripMenuItem;
+ private ToolStripMenuItem LoadToolStripMenuItem;
+ private SaveFileDialog saveFileDialog;
+ private OpenFileDialog openFileDialog;
}
}
\ No newline at end of file
diff --git a/ContainerShip/ContainerShip/FormContainerCollection.cs b/ContainerShip/ContainerShip/FormContainerCollection.cs
index e79668f..850768a 100644
--- a/ContainerShip/ContainerShip/FormContainerCollection.cs
+++ b/ContainerShip/ContainerShip/FormContainerCollection.cs
@@ -108,24 +108,24 @@ namespace ProjectContainerShip
{
return;
}
- var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
- string.Empty];
- if (obj == null)
- {
- return;
- }
var form = new FormContainerConfig();
- form.AddEvent(deleg =>
+ form.AddEvent(ship =>
{
- bool SelectedShip = (obj + deleg);
- if (SelectedShip)
+ if (listBoxStorages.SelectedIndex != -1)
{
- MessageBox.Show("Объект добавлен");
- pictureBoxCollection.Image = obj.ShowContainer();
- }
- else
- {
- MessageBox.Show("Не удалось добавить объект");
+ var obj = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty];
+ if (obj != null)
+ {
+ if (obj + ship != 1)
+ {
+ MessageBox.Show("Объект добавлен");
+ pictureBoxCollection.Image = obj.ShowContainer();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось добавить объект");
+ }
+ }
}
});
form.Show();
@@ -182,8 +182,59 @@ namespace ProjectContainerShip
}
pictureBoxCollection.Image = obj.ShowContainer();
}
- private void textBoxStorageName_TextChanged(object sender, EventArgs e)
+ ///
+ /// Обработка нажатия "Сохранение"
+ ///
+ ///
+ ///
+ private void SaveToolStripMenuItem_Click_1(object sender, EventArgs e)
{
+ if (saveFileDialog.ShowDialog() == DialogResult.OK)
+ {
+ if (_storage.SaveData(saveFileDialog.FileName))
+ {
+ MessageBox.Show("Сохранение прошло успешно",
+ "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ }
+ else
+ {
+ MessageBox.Show("Не сохранилось", "Результат",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+ ///
+ /// Обработка нажатия "Загрузка"
+ ///
+ ///
+ ///
+ private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ if (openFileDialog.ShowDialog() == DialogResult.OK)
+ {
+ if (_storage.LoadData(openFileDialog.FileName))
+ {
+ MessageBox.Show("Загрузка прошла успешно",
+ "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ ReloadObjects();
+ if (listBoxStorages.SelectedIndex == -1)
+ {
+ return;
+ }
+ var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
+ string.Empty];
+ if (obj == null)
+ {
+ return;
+ }
+ pictureBoxCollection.Image = obj.ShowContainer();
+ }
+ else
+ {
+ MessageBox.Show("Не загрузилось", "Результат",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
}
}
}
diff --git a/ContainerShip/ContainerShip/FormContainerCollection.resx b/ContainerShip/ContainerShip/FormContainerCollection.resx
index af32865..4fcc49f 100644
--- a/ContainerShip/ContainerShip/FormContainerCollection.resx
+++ b/ContainerShip/ContainerShip/FormContainerCollection.resx
@@ -117,4 +117,13 @@
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ 17, 17
+
+
+ 259, 17
+
+
+ 126, 17
+
\ No newline at end of file
diff --git a/ContainerShip/ContainerShip/FormContainerConfig.Designer.cs b/ContainerShip/ContainerShip/FormContainerConfig.Designer.cs
index ea90887..777c97d 100644
--- a/ContainerShip/ContainerShip/FormContainerConfig.Designer.cs
+++ b/ContainerShip/ContainerShip/FormContainerConfig.Designer.cs
@@ -89,7 +89,6 @@
labelModifiedObject.TabIndex = 8;
labelModifiedObject.Text = "Продвинутый";
labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter;
- labelModifiedObject.Click += labelModifiedObject_Click;
labelModifiedObject.MouseDown += LabelObject_MouseDown;
//
// labelSimpleObject
@@ -212,7 +211,6 @@
checkBoxContainer.TabIndex = 5;
checkBoxContainer.Text = "Признак наличия крана";
checkBoxContainer.UseVisualStyleBackColor = true;
- checkBoxContainer.CheckedChanged += checkBoxBodyKit_CheckedChanged;
//
// checkBoxCrane
//
@@ -224,7 +222,6 @@
checkBoxCrane.TabIndex = 4;
checkBoxCrane.Text = "Признак наличия котнейнеров";
checkBoxCrane.UseVisualStyleBackColor = true;
- checkBoxCrane.CheckedChanged += checkBoxCrane_CheckedChanged;
//
// numericUpDownWeight
//
@@ -236,7 +233,6 @@
numericUpDownWeight.Size = new Size(83, 27);
numericUpDownWeight.TabIndex = 3;
numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 });
- numericUpDownWeight.ValueChanged += numericUpDownWeight_ValueChanged;
//
// numericUpDownSpeed
//
@@ -248,7 +244,6 @@
numericUpDownSpeed.Size = new Size(83, 27);
numericUpDownSpeed.TabIndex = 2;
numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 });
- numericUpDownSpeed.ValueChanged += numericUpDownSpeed_ValueChanged;
//
// label2
//
diff --git a/ContainerShip/ContainerShip/FormContainerConfig.cs b/ContainerShip/ContainerShip/FormContainerConfig.cs
index cf611f1..96dc3c4 100644
--- a/ContainerShip/ContainerShip/FormContainerConfig.cs
+++ b/ContainerShip/ContainerShip/FormContainerConfig.cs
@@ -32,6 +32,7 @@ namespace ProjectContainerShip
panelWhite.MouseDown += panelColor_MouseDown;
panelYellow.MouseDown += panelColor_MouseDown;
panelBlue.MouseDown += panelColor_MouseDown;
+ // TODO buttonCancel.Click with lambda
buttonCancel.Click += (sender, e) => Close();
}
///
@@ -123,7 +124,6 @@ namespace ProjectContainerShip
if (e.Data.GetDataPresent(typeof(Color)))
{
_ship.EntityShip.BodyColor = (Color)e.Data.GetData(typeof(Color));
-
}
DrawShip();
}
@@ -136,7 +136,6 @@ namespace ProjectContainerShip
}
else
labelDopColor.AllowDrop = false;
-
if (e.Data.GetDataPresent(typeof(Color)))
{
e.Effect = DragDropEffects.Copy;
@@ -167,25 +166,5 @@ namespace ProjectContainerShip
EventAddShip?.Invoke(_ship);
Close();
}
- private void checkBoxBodyKit_CheckedChanged(object sender, EventArgs e)
- {
-
- }
- private void labelModifiedObject_Click(object sender, EventArgs e)
- {
-
- }
- private void numericUpDownSpeed_ValueChanged(object sender, EventArgs e)
- {
-
- }
- private void numericUpDownWeight_ValueChanged(object sender, EventArgs e)
- {
-
- }
- private void checkBoxCrane_CheckedChanged(object sender, EventArgs e)
- {
-
- }
}
}
diff --git a/ContainerShip/ContainerShip/FormContainerShip.cs b/ContainerShip/ContainerShip/FormContainerShip.cs
index c31782f..06dd873 100644
--- a/ContainerShip/ContainerShip/FormContainerShip.cs
+++ b/ContainerShip/ContainerShip/FormContainerShip.cs
@@ -13,6 +13,7 @@ namespace ProjectContainerShip
/// -
///
private DrawningShip? _drawingContainerShip;
+
///
///
///
@@ -162,6 +163,7 @@ namespace ProjectContainerShip
}
private void FormContainerShip_Load(object sender, EventArgs e)
{
+
}
}
}
diff --git a/ContainerShip/ContainerShip/Program.cs b/ContainerShip/ContainerShip/Program.cs
index 7bf5e39..78ae352 100644
--- a/ContainerShip/ContainerShip/Program.cs
+++ b/ContainerShip/ContainerShip/Program.cs
@@ -14,7 +14,6 @@ namespace ProjectContainerShip
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new FormContainerCollection());
-
}
}
}
diff --git a/ContainerShip/ContainerShip/SetGeneric.cs b/ContainerShip/ContainerShip/SetGeneric.cs
index afdd0f3..bd65293 100644
--- a/ContainerShip/ContainerShip/SetGeneric.cs
+++ b/ContainerShip/ContainerShip/SetGeneric.cs
@@ -39,14 +39,18 @@ namespace ProjectContainerShip.Generics
///
/// Добавляемый контейнеровоз
///
- public bool Insert(T ship)
+ public int Insert(T ship)
{
- if (_places.Count >= _maxCount)
- {
- return false;
- }
- _places.Insert(0, ship);
- return true;
+ return Insert(ship, 0);
+ }
+ public int Insert(T ship, int position)
+ {
+ if (position < 0 || position >= _maxCount)
+ return -1;
+ if (Count >= _maxCount)
+ return -1;
+ _places.Insert(position, ship);
+ return position;
}
///
/// Удаление объекта из набора с конкретной позиции
@@ -71,23 +75,15 @@ namespace ProjectContainerShip.Generics
{
get
{
- if (position < 0 || position >= _places.Count)
- {
+ if (position < 0 || position > _maxCount)
return null;
- }
return _places[position];
}
set
{
- if (position < 0 || position >= _places.Count)
- {
+ if (position < 0 || position > _maxCount)
return;
- }
- if (_places.Count >= _maxCount)
- {
- return;
- }
- _places.Insert(position, value);
+ _places[position] = value;
}
}
///