4 Commits
lab5 ... lab_7

Author SHA1 Message Date
Alenka
76bed1f328 Done 2023-12-22 20:10:32 +04:00
Alenka
e898da222c Начинать всегда стоит с того, что сеет сомнения 2023-12-22 20:04:42 +04:00
Alenka
d8ad99c6fa Done 2023-12-14 18:17:09 +04:00
Alenka
bd31bcb20c Done 2023-12-08 22:08:43 +04:00
15 changed files with 551 additions and 175 deletions

View File

@@ -8,6 +8,18 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.7" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>

View File

@@ -11,14 +11,33 @@ using Cruiser.MovementStrategy;
namespace Cruiser.Generics
{
internal class CruiserGenericCollection<T, U>
where T : DrawningCruiser
where U : IMoveableObject
{
/// <summary>
/// Ширина окна прорисовки
/// </summary>
private readonly int _pictureWidth;
/// <summary>
/// Высота окна прорисовки
/// </summary>
private readonly int _pictureHeight;
private readonly int _placeSizeWidth = 210;
private readonly int _placeSizeHeight = 90;
/// <summary>
private readonly int _placeSizeWidth = 170;
/// <summary>
/// Размер занимаемого объектом места (высота)
/// </summary>
private readonly int _placeSizeHeight = 124;
/// <summary>
/// Набор объектов
/// </summary>
private readonly SetGeneric<T> _collection;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="picWidth"></param>
/// <param name="picHeight"></param>
public CruiserGenericCollection(int picWidth, int picHeight)
{
int width = picWidth / _placeSizeWidth;
@@ -27,30 +46,44 @@ namespace Cruiser.Generics
_pictureHeight = picHeight;
_collection = new SetGeneric<T>(width * height);
}
public static bool operator +(CruiserGenericCollection<T, U> collect, T? obj)
/// <summary>
/// Перегрузка оператора сложения
/// </summary>
/// <param name="collect"></param>
/// <param name="obj"></param>
/// <returns></returns>
public static bool operator +(CruiserGenericCollection<T, U>? collect, T? obj)
{
if (obj == null)
{
if (obj == null || collect == null)
return false;
}
return collect?._collection.Insert(obj) ?? false;
collect?._collection.Insert(obj);
return true;
}
/// <summary>
/// Перегрузка оператора вычитания
/// </summary>
/// <param name="collect"></param>
/// <param name="pos"></param>
/// <returns></returns>
public static T? operator -(CruiserGenericCollection<T, U> collect, int pos)
{
T? obj = collect._collection[pos];
if (obj != null)
{
collect._collection.Remove(pos);
}
collect._collection.Remove(pos);
return obj;
}
/// <summary>
/// Получение объекта IMoveableObject
/// </summary>
/// <param name="pos"></param>
/// <returns></returns>
public U? GetU(int pos)
{
return (U?)_collection[pos]?.GetMoveableObject;
}
/// <summary>
/// Вывод всего набора объектов
/// </summary>
/// <returns></returns>
public Bitmap ShowCruisers()
{
Bitmap bmp = new(_pictureWidth, _pictureHeight);
@@ -59,6 +92,10 @@ namespace Cruiser.Generics
DrawObjects(gr);
return bmp;
}
/// <summary>
/// Метод отрисовки фона
/// </summary>
/// <param name="g"></param>
private void DrawBackground(Graphics g)
{
Pen pen = new(Color.Black, 3);
@@ -66,7 +103,7 @@ namespace Cruiser.Generics
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight +
1; ++j)
{
{//линия разметки места
g.DrawLine(pen, i * _placeSizeWidth, j *
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
_placeSizeHeight);
@@ -75,6 +112,10 @@ namespace Cruiser.Generics
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
}
}
/// <summary>
/// Метод прорисовки объектов
/// </summary>
/// <param name="g"></param>
private void DrawObjects(Graphics g)
{
int i = 0;
@@ -83,11 +124,12 @@ namespace Cruiser.Generics
if (cruiser != null)
{
int inRow = _pictureWidth / _placeSizeWidth;
cruiser.SetPosition((i % inRow) * _placeSizeWidth + _placeSizeWidth / 20, _placeSizeHeight * (i / inRow) + _placeSizeHeight / 10);
cruiser.SetPosition(_placeSizeWidth * (inRow - 1) - (i % inRow * _placeSizeWidth), i / inRow * _placeSizeHeight);
cruiser.DrawTransport(g);
}
i++;
}
}
public IEnumerable<T?> GetCruisers => _collection.GetCruiser();
}
}

View File

@@ -15,6 +15,9 @@ namespace Cruiser.Generics
public List<string> Keys => _cruiserStorages.Keys.ToList();
private readonly int _pictureWidth;
private readonly int _pictureHeight;
private static readonly char _separatorForKeyValue = '|';
private readonly char _separatorRecords = ';';
private static readonly char _separatorForObject = ':';
public CruiserGenericStorage(int pictureWidth, int pictureHeight)
{
_cruiserStorages = new Dictionary<string, CruiserGenericCollection<DrawningCruiser, DrawningObjectCruiser>>();
@@ -45,6 +48,78 @@ namespace Cruiser.Generics
return null;
}
}
public void SaveData(string filename)
{
if (File.Exists(filename))
{
File.Delete(filename);
}
StringBuilder data = new();
foreach (KeyValuePair<string, CruiserGenericCollection<DrawningCruiser, DrawningObjectCruiser>> record in _cruiserStorages)
{
StringBuilder records = new();
foreach (DrawningCruiser? elem in record.Value.GetCruisers)
{
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
}
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}");
}
if (data.Length == 0)
{
throw new IOException("Невалидная операция, нет данных для сохранения");
}
using (StreamWriter sw = new(filename))
{
sw.WriteLine($"CruiserStorage{Environment.NewLine}{data}");
}
return;
}
public void LoadData(string filename)
{
if (!File.Exists(filename))
{
throw new IOException("Файл не найден");
}
using (StreamReader sr = new(filename))
{
string str = sr.ReadLine();
var strs = str.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
if (strs == null || strs.Length == 0)
{
throw new IOException("Нет данных для загрузки");
}
if (!strs[0].StartsWith("CruiserStorage"))
{
throw new IOException("Неверный формат данных");
}
_cruiserStorages.Clear();
do
{
string[] record = str.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
if (record.Length != 2)
{
str = sr.ReadLine();
continue;
}
CruiserGenericCollection<DrawningCruiser, DrawningObjectCruiser> collection = new(_pictureWidth, _pictureHeight);
string[] set = record[1].Split(_separatorRecords,
StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set)
{
DrawningCruiser? cruiser = elem?.CreateDrawningCruiser(_separatorForObject, _pictureWidth, _pictureHeight);
if (cruiser != null)
{
if (!(collection + cruiser))
{
throw new ArgumentNullException("Ошибка добавления в коллекцию");
}
}
}
_cruiserStorages.Add(record[0], collection);
str = sr.ReadLine();
} while (str != null);
}
return;
}
}
}
}

View File

@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;
namespace Cruiser.Exceptions
{
[Serializable]
internal class CruiserNotFoundException : ApplicationException
{
public CruiserNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
public CruiserNotFoundException() : base() { }
public CruiserNotFoundException(string message) : base(message) { }
public CruiserNotFoundException(string message, Exception exception) : base(message, exception) { }
protected CruiserNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context) { }
}
}

View File

@@ -119,7 +119,7 @@ width, int height, int cruiserWidth, int cruiserHeight)
g.FillRectangle(br, _startPosX + 10, _startPosY + 15, 10, 30);
g.FillRectangle(br, _startPosX + 90, _startPosY + 15, 10, 30);
g.FillRectangle(br, _startPosX + 20, _startPosY + 5, 70, 50);
Point[] points = new Point[3];
Point[] points = new Point[3];//
points[0] = new Point(_startPosX + 100, _startPosY + 5);
points[1] = new Point(_startPosX + 100, _startPosY + 55);
points[2] = new Point(_startPosX + 100 + 50, _startPosY + 50 / 2);
@@ -132,4 +132,5 @@ width, int height, int cruiserWidth, int cruiserHeight)
_startPosY + 19, 30, 25);
}
}
}

View File

@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cruiser.Entities;
namespace Cruiser.DrawningObjects
{
public static class ExtentionDrawingCruiser
{
public static DrawningCruiser? CreateDrawningCruiser(this string info, char separatorForObject, int width, int height)
{
string[] strs = info.Split(separatorForObject);
if (strs.Length == 3)
{
return new DrawningCruiser(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height);
}
if (strs.Length == 7)
{
return new DrawningAdvancedCruiser(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 DrawningCruiser drawningcruiser, char separatorForObject)
{
var cruiser = drawningcruiser.EntityCruiser;
if (cruiser == null)
{
return string.Empty;
}
var str = $"{cruiser.Speed}{separatorForObject}{cruiser.Weight}{separatorForObject}{cruiser.BodyColor.Name}";
if (cruiser is not EntityAdvancedCruiser advancedCruiser)
{
return str;
}
return
$"{str}{separatorForObject}{advancedCruiser.AdditionalColor.Name}{separatorForObject}" +
$"{separatorForObject}{advancedCruiser.HelicopterPad}{separatorForObject}{advancedCruiser.Coating}";
}
}
}

View File

@@ -17,26 +17,33 @@
{
this.pictureBoxCruiser = new System.Windows.Forms.PictureBox();
this.panelCruiser = new System.Windows.Forms.Panel();
this.panelSet = new System.Windows.Forms.Panel();
this.textBoxSet = new System.Windows.Forms.TextBox();
this.ButtonAddObject = new System.Windows.Forms.Button();
this.listBoxStorages = new System.Windows.Forms.ListBox();
this.ButtonDelObject = new System.Windows.Forms.Button();
this.ButtonAddCruiser = new System.Windows.Forms.Button();
this.textBoxCruiser = new System.Windows.Forms.TextBox();
this.ButtonRemoveCruiser = new System.Windows.Forms.Button();
this.ButtonRefreshCollection = new System.Windows.Forms.Button();
this.ButtonRemoveCruiser = new System.Windows.Forms.Button();
this.textBoxCruiser = new System.Windows.Forms.TextBox();
this.ButtonAddCruiser = new System.Windows.Forms.Button();
this.panelSet = new System.Windows.Forms.Panel();
this.ButtonDelObject = new System.Windows.Forms.Button();
this.listBoxStorages = new System.Windows.Forms.ListBox();
this.ButtonAddObject = new System.Windows.Forms.Button();
this.textBoxSet = new System.Windows.Forms.TextBox();
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
this.menuStrip = new System.Windows.Forms.MenuStrip();
this.FileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.SaveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.LoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCruiser)).BeginInit();
this.panelCruiser.SuspendLayout();
this.panelSet.SuspendLayout();
this.menuStrip.SuspendLayout();
this.SuspendLayout();
//
// pictureBoxCruiser
//
this.pictureBoxCruiser.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxCruiser.Location = new System.Drawing.Point(0, 0);
this.pictureBoxCruiser.Location = new System.Drawing.Point(0, 33);
this.pictureBoxCruiser.Name = "pictureBoxCruiser";
this.pictureBoxCruiser.Size = new System.Drawing.Size(904, 510);
this.pictureBoxCruiser.Size = new System.Drawing.Size(904, 477);
this.pictureBoxCruiser.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxCruiser.TabIndex = 0;
this.pictureBoxCruiser.TabStop = false;
@@ -53,70 +60,15 @@
this.panelCruiser.Size = new System.Drawing.Size(221, 486);
this.panelCruiser.TabIndex = 1;
//
// panelSet
// ButtonRefreshCollection
//
this.panelSet.Controls.Add(this.ButtonDelObject);
this.panelSet.Controls.Add(this.listBoxStorages);
this.panelSet.Controls.Add(this.ButtonAddObject);
this.panelSet.Controls.Add(this.textBoxSet);
this.panelSet.Location = new System.Drawing.Point(22, 19);
this.panelSet.Name = "panelSet";
this.panelSet.Size = new System.Drawing.Size(185, 241);
this.panelSet.TabIndex = 0;
//
// textBoxSet
//
this.textBoxSet.Location = new System.Drawing.Point(38, 21);
this.textBoxSet.Name = "textBoxSet";
this.textBoxSet.Size = new System.Drawing.Size(118, 31);
this.textBoxSet.TabIndex = 0;
//
// ButtonAddObject
//
this.ButtonAddObject.Location = new System.Drawing.Point(18, 58);
this.ButtonAddObject.Name = "ButtonAddObject";
this.ButtonAddObject.Size = new System.Drawing.Size(153, 51);
this.ButtonAddObject.TabIndex = 2;
this.ButtonAddObject.Text = "Создать набор";
this.ButtonAddObject.UseVisualStyleBackColor = true;
this.ButtonAddObject.Click += new System.EventHandler(this.ButtonAddObject_Click);
//
// listBoxStorages
//
this.listBoxStorages.FormattingEnabled = true;
this.listBoxStorages.ItemHeight = 25;
this.listBoxStorages.Location = new System.Drawing.Point(49, 115);
this.listBoxStorages.Name = "listBoxStorages";
this.listBoxStorages.Size = new System.Drawing.Size(97, 54);
this.listBoxStorages.TabIndex = 3;
this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.listBoxObjects_SelectedIndexChanged);
//
// ButtonDelObject
//
this.ButtonDelObject.Location = new System.Drawing.Point(18, 175);
this.ButtonDelObject.Name = "ButtonDelObject";
this.ButtonDelObject.Size = new System.Drawing.Size(153, 47);
this.ButtonDelObject.TabIndex = 2;
this.ButtonDelObject.Text = "Удалить набор";
this.ButtonDelObject.UseVisualStyleBackColor = true;
this.ButtonDelObject.Click += new System.EventHandler(this.ButtonDelObject_Click);
//
// ButtonAddCruiser
//
this.ButtonAddCruiser.Location = new System.Drawing.Point(45, 266);
this.ButtonAddCruiser.Name = "ButtonAddCruiser";
this.ButtonAddCruiser.Size = new System.Drawing.Size(133, 38);
this.ButtonAddCruiser.TabIndex = 2;
this.ButtonAddCruiser.Text = "Добавить";
this.ButtonAddCruiser.UseVisualStyleBackColor = true;
this.ButtonAddCruiser.Click += new System.EventHandler(this.ButtonAddCruiser_Click);
//
// textBoxCruiser
//
this.textBoxCruiser.Location = new System.Drawing.Point(45, 330);
this.textBoxCruiser.Name = "textBoxCruiser";
this.textBoxCruiser.Size = new System.Drawing.Size(133, 31);
this.textBoxCruiser.TabIndex = 3;
this.ButtonRefreshCollection.Location = new System.Drawing.Point(45, 435);
this.ButtonRefreshCollection.Name = "ButtonRefreshCollection";
this.ButtonRefreshCollection.Size = new System.Drawing.Size(138, 41);
this.ButtonRefreshCollection.TabIndex = 2;
this.ButtonRefreshCollection.Text = "Обновить";
this.ButtonRefreshCollection.UseVisualStyleBackColor = true;
this.ButtonRefreshCollection.Click += new System.EventHandler(this.ButtonRefreshCollection_Click);
//
// ButtonRemoveCruiser
//
@@ -128,15 +80,113 @@
this.ButtonRemoveCruiser.UseVisualStyleBackColor = true;
this.ButtonRemoveCruiser.Click += new System.EventHandler(this.ButtonRemoveCruiser_Click);
//
// ButtonRefreshCollection
// textBoxCruiser
//
this.ButtonRefreshCollection.Location = new System.Drawing.Point(45, 435);
this.ButtonRefreshCollection.Name = "ButtonRefreshCollection";
this.ButtonRefreshCollection.Size = new System.Drawing.Size(138, 41);
this.ButtonRefreshCollection.TabIndex = 2;
this.ButtonRefreshCollection.Text = "Обновить";
this.ButtonRefreshCollection.UseVisualStyleBackColor = true;
this.ButtonRefreshCollection.Click += new System.EventHandler(this.ButtonRefreshCollection_Click);
this.textBoxCruiser.Location = new System.Drawing.Point(45, 330);
this.textBoxCruiser.Name = "textBoxCruiser";
this.textBoxCruiser.Size = new System.Drawing.Size(133, 31);
this.textBoxCruiser.TabIndex = 3;
//
// ButtonAddCruiser
//
this.ButtonAddCruiser.Location = new System.Drawing.Point(45, 266);
this.ButtonAddCruiser.Name = "ButtonAddCruiser";
this.ButtonAddCruiser.Size = new System.Drawing.Size(133, 38);
this.ButtonAddCruiser.TabIndex = 2;
this.ButtonAddCruiser.Text = "Добавить";
this.ButtonAddCruiser.UseVisualStyleBackColor = true;
this.ButtonAddCruiser.Click += new System.EventHandler(this.ButtonAddCruiser_Click);
//
// panelSet
//
this.panelSet.Controls.Add(this.ButtonDelObject);
this.panelSet.Controls.Add(this.listBoxStorages);
this.panelSet.Controls.Add(this.ButtonAddObject);
this.panelSet.Controls.Add(this.textBoxSet);
this.panelSet.Location = new System.Drawing.Point(22, 19);
this.panelSet.Name = "panelSet";
this.panelSet.Size = new System.Drawing.Size(185, 241);
this.panelSet.TabIndex = 0;
//
// ButtonDelObject
//
this.ButtonDelObject.Location = new System.Drawing.Point(18, 175);
this.ButtonDelObject.Name = "ButtonDelObject";
this.ButtonDelObject.Size = new System.Drawing.Size(153, 47);
this.ButtonDelObject.TabIndex = 2;
this.ButtonDelObject.Text = "Удалить набор";
this.ButtonDelObject.UseVisualStyleBackColor = true;
this.ButtonDelObject.Click += new System.EventHandler(this.ButtonDelObject_Click);
//
// listBoxStorages
//
this.listBoxStorages.FormattingEnabled = true;
this.listBoxStorages.ItemHeight = 25;
this.listBoxStorages.Location = new System.Drawing.Point(49, 115);
this.listBoxStorages.Name = "listBoxStorages";
this.listBoxStorages.Size = new System.Drawing.Size(97, 54);
this.listBoxStorages.TabIndex = 3;
this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.listBoxObjects_SelectedIndexChanged);
//
// ButtonAddObject
//
this.ButtonAddObject.Location = new System.Drawing.Point(18, 58);
this.ButtonAddObject.Name = "ButtonAddObject";
this.ButtonAddObject.Size = new System.Drawing.Size(153, 51);
this.ButtonAddObject.TabIndex = 2;
this.ButtonAddObject.Text = "Создать набор";
this.ButtonAddObject.UseVisualStyleBackColor = true;
this.ButtonAddObject.Click += new System.EventHandler(this.ButtonAddObject_Click);
//
// textBoxSet
//
this.textBoxSet.Location = new System.Drawing.Point(38, 21);
this.textBoxSet.Name = "textBoxSet";
this.textBoxSet.Size = new System.Drawing.Size(118, 31);
this.textBoxSet.TabIndex = 0;
//
// openFileDialog
//
this.openFileDialog.FileName = "openFileDialog";
this.openFileDialog.Filter = "txt file | *.txt";
//
// saveFileDialog
//
this.saveFileDialog.Filter = "txt file | *.txt";
//
// menuStrip
//
this.menuStrip.ImageScalingSize = new System.Drawing.Size(24, 24);
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.FileToolStripMenuItem});
this.menuStrip.Location = new System.Drawing.Point(0, 0);
this.menuStrip.Name = "menuStrip";
this.menuStrip.Size = new System.Drawing.Size(904, 33);
this.menuStrip.TabIndex = 2;
this.menuStrip.Text = "menuStrip";
//
// FileToolStripMenuItem
//
this.FileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.SaveToolStripMenuItem,
this.LoadToolStripMenuItem});
this.FileToolStripMenuItem.Name = "FileToolStripMenuItem";
this.FileToolStripMenuItem.Size = new System.Drawing.Size(69, 29);
this.FileToolStripMenuItem.Text = "Файл";
//
// SaveToolStripMenuItem
//
this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
this.SaveToolStripMenuItem.Size = new System.Drawing.Size(270, 34);
this.SaveToolStripMenuItem.Text = "Сохранить";
this.SaveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click);
//
// LoadToolStripMenuItem
//
this.LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
this.LoadToolStripMenuItem.Size = new System.Drawing.Size(270, 34);
this.LoadToolStripMenuItem.Text = "Загрузить";
this.LoadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click);
//
// FormCruiserCollection
//
@@ -145,6 +195,8 @@
this.ClientSize = new System.Drawing.Size(904, 510);
this.Controls.Add(this.panelCruiser);
this.Controls.Add(this.pictureBoxCruiser);
this.Controls.Add(this.menuStrip);
this.MainMenuStrip = this.menuStrip;
this.Name = "FormCruiserCollection";
this.Text = "FormCruiserCollection";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCruiser)).EndInit();
@@ -152,6 +204,8 @@
this.panelCruiser.PerformLayout();
this.panelSet.ResumeLayout(false);
this.panelSet.PerformLayout();
this.menuStrip.ResumeLayout(false);
this.menuStrip.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
@@ -169,5 +223,11 @@
private Button ButtonRemoveCruiser;
private TextBox textBoxCruiser;
private Button ButtonRefreshCollection;
private OpenFileDialog openFileDialog;
private SaveFileDialog saveFileDialog;
private MenuStrip menuStrip;
private ToolStripMenuItem FileToolStripMenuItem;
private ToolStripMenuItem SaveToolStripMenuItem;
private ToolStripMenuItem LoadToolStripMenuItem;
}
}

View File

@@ -9,6 +9,10 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Cruiser.Exceptions;
using System.Xml.Linq;
using Serilog;
using System.Numerics;
namespace Cruiser
{
@@ -50,6 +54,7 @@ namespace Cruiser
}
_storage.AddSet(textBoxSet.Text);
ReloadObjects();
Log.Information($"Добавлен набор: {textBoxSet.Text}");
}
private void listBoxObjects_SelectedIndexChanged(object sender, EventArgs e)
{
@@ -64,9 +69,10 @@ namespace Cruiser
if (MessageBox.Show($"Удалить объект{listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo,
MessageBoxIcon.Question) == DialogResult.Yes)
{
_storage.DelSet(listBoxStorages.SelectedItem.ToString()
?? string.Empty);
string name = listBoxStorages.SelectedItem.ToString() ?? string.Empty;
_storage.DelSet(name);
ReloadObjects();
Log.Information($"Удален набор: {name}");
}
}
private void ButtonAddCruiser_Click(object sender, EventArgs e)
@@ -84,16 +90,17 @@ namespace Cruiser
form.Show();
Action<DrawningCruiser>? cruiserDelegate = new((m) =>
{
bool isAdditionSuccessful = (obj + m);
if (isAdditionSuccessful)
try
{
bool q = obj + m;
MessageBox.Show("Объект добавлен");
m.ChangePictureBoxSize(pictureBoxCruiser.Width, pictureBoxCruiser.Height);
pictureBoxCruiser.Image = obj.ShowCruisers();
Log.Information($"Добавлен объект в коллекцию {listBoxStorages.SelectedItem.ToString() ?? string.Empty}");
}
else
catch (StorageOverflowException ex)
{
MessageBox.Show("Не удалось добавить объект");
Log.Warning($"Коллекция {listBoxStorages.SelectedItem.ToString() ?? string.Empty} переполнена");
MessageBox.Show(ex.Message);
}
});
form.AddEvent(cruiserDelegate);
@@ -115,16 +122,25 @@ namespace Cruiser
{
return;
}
int pos = Convert.ToInt32(textBoxCruiser.Text);
if (obj - pos != null)
try
{
int pos = Convert.ToInt32(textBoxCruiser.Text);
var q = obj - pos;
MessageBox.Show("Объект удален");
Log.Information($"Удален объект из коллекции {listBoxStorages.SelectedItem.ToString() ?? string.Empty} по номеру {pos}");
pictureBoxCruiser.Image = obj.ShowCruisers();
}
else
catch (CruiserNotFoundException ex)
{
MessageBox.Show("Не удалось удалить объект");
Log.Warning($"Не получилось удалить объект из коллекции {listBoxStorages.SelectedItem.ToString() ?? string.Empty}");
MessageBox.Show(ex.Message);
}
catch (FormatException)
{
Log.Warning($"Было введено не число");
MessageBox.Show("Введите число");
}
}
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
{
@@ -140,5 +156,47 @@ namespace Cruiser
}
pictureBoxCruiser.Image = obj.ShowCruisers();
}
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
{
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
try
{
_storage.SaveData(saveFileDialog.FileName);
MessageBox.Show("Сохранение прошло успешно",
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
Log.Information($"Файл {saveFileDialog.FileName} успешно сохранен");
}
catch (Exception ex)
{
Log.Warning("Не удалось сохранить");
MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
{
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
try
{
_storage.LoadData(openFileDialog.FileName);
MessageBox.Show("Загрузка прошла успешно",
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
Log.Information($"Файл {openFileDialog.FileName} успешно загружен");
foreach (var collection in _storage.Keys)
{
listBoxStorages.Items.Add(collection);
}
ReloadObjects();
}
catch (Exception ex)
{
Log.Warning("Не удалось загрузить");
MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
}
}

View File

@@ -57,4 +57,13 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="openFileDialog.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>201, 17</value>
</metadata>
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>379, 17</value>
</metadata>
</root>

View File

@@ -32,14 +32,14 @@
this.checkBoxMissileSilos = new System.Windows.Forms.CheckBox();
this.buttonCancel = new System.Windows.Forms.Button();
this.buttonAdd = new System.Windows.Forms.Button();
this.panelColor = new System.Windows.Forms.Panel();
this.panelOrchid = new System.Windows.Forms.Panel();
this.label_addit_color = new System.Windows.Forms.Label();
this.label_color = new System.Windows.Forms.Label();
this.pictureBoxCruiser = new System.Windows.Forms.PictureBox();
this.labelAdvanced = new System.Windows.Forms.Label();
this.labelBasic = new System.Windows.Forms.Label();
this.groupBoxColor = new System.Windows.Forms.GroupBox();
this.panelOrchid = new System.Windows.Forms.Panel();
this.panelColor = new System.Windows.Forms.Panel();
this.panelPink = new System.Windows.Forms.Panel();
this.panelViolet = new System.Windows.Forms.Panel();
this.panelBlue = new System.Windows.Forms.Panel();
@@ -53,7 +53,7 @@
this.labelWeight = new System.Windows.Forms.Label();
this.labelSpeed = new System.Windows.Forms.Label();
this.groupBoxCruiser.SuspendLayout();
this.panelColor.SuspendLayout();
this.panelOrchid.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCruiser)).BeginInit();
this.groupBoxColor.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
@@ -65,7 +65,7 @@
this.groupBoxCruiser.Controls.Add(this.checkBoxMissileSilos);
this.groupBoxCruiser.Controls.Add(this.buttonCancel);
this.groupBoxCruiser.Controls.Add(this.buttonAdd);
this.groupBoxCruiser.Controls.Add(this.panelColor);
this.groupBoxCruiser.Controls.Add(this.panelOrchid);
this.groupBoxCruiser.Controls.Add(this.labelAdvanced);
this.groupBoxCruiser.Controls.Add(this.labelBasic);
this.groupBoxCruiser.Controls.Add(this.groupBoxColor);
@@ -110,18 +110,18 @@
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
//
// panelColor
// panelOrchid
//
this.panelColor.AllowDrop = true;
this.panelColor.Controls.Add(this.label_addit_color);
this.panelColor.Controls.Add(this.label_color);
this.panelColor.Controls.Add(this.pictureBoxCruiser);
this.panelColor.Location = new System.Drawing.Point(822, 45);
this.panelColor.Name = "panelColor";
this.panelColor.Size = new System.Drawing.Size(312, 261);
this.panelColor.TabIndex = 9;
this.panelColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop);
this.panelColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter);
this.panelOrchid.AllowDrop = true;
this.panelOrchid.Controls.Add(this.label_addit_color);
this.panelOrchid.Controls.Add(this.label_color);
this.panelOrchid.Controls.Add(this.pictureBoxCruiser);
this.panelOrchid.Location = new System.Drawing.Point(822, 45);
this.panelOrchid.Name = "panelOrchid";
this.panelOrchid.Size = new System.Drawing.Size(312, 261);
this.panelOrchid.TabIndex = 9;
this.panelOrchid.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop);
this.panelOrchid.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter);
//
// label_addit_color
//
@@ -181,7 +181,7 @@
//
// groupBoxColor
//
this.groupBoxColor.Controls.Add(this.panelOrchid);
this.groupBoxColor.Controls.Add(this.panelColor);
this.groupBoxColor.Controls.Add(this.panelPink);
this.groupBoxColor.Controls.Add(this.panelViolet);
this.groupBoxColor.Controls.Add(this.panelBlue);
@@ -196,17 +196,17 @@
this.groupBoxColor.TabStop = false;
this.groupBoxColor.Text = "Цвета";
//
// panelOrchid
// panelColor
//
this.panelOrchid.BackColor = System.Drawing.Color.Fuchsia;
this.panelOrchid.Location = new System.Drawing.Point(264, 153);
this.panelOrchid.Name = "panelOrchid";
this.panelOrchid.Size = new System.Drawing.Size(53, 49);
this.panelOrchid.TabIndex = 7;
this.panelColor.BackColor = System.Drawing.Color.Fuchsia;
this.panelColor.Location = new System.Drawing.Point(264, 153);
this.panelColor.Name = "panelColor";
this.panelColor.Size = new System.Drawing.Size(53, 49);
this.panelColor.TabIndex = 7;
//
// panelPink
//
this.panelPink.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(255)))));
this.panelPink.BackColor = System.Drawing.Color.Violet;
this.panelPink.Location = new System.Drawing.Point(180, 153);
this.panelPink.Name = "panelPink";
this.panelPink.Size = new System.Drawing.Size(53, 49);
@@ -214,7 +214,7 @@
//
// panelViolet
//
this.panelViolet.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(128)))), ((int)(((byte)(255)))));
this.panelViolet.BackColor = System.Drawing.Color.DarkTurquoise;
this.panelViolet.Location = new System.Drawing.Point(108, 153);
this.panelViolet.Name = "panelViolet";
this.panelViolet.Size = new System.Drawing.Size(53, 49);
@@ -222,7 +222,7 @@
//
// panelBlue
//
this.panelBlue.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(192)))), ((int)(((byte)(255)))));
this.panelBlue.BackColor = System.Drawing.Color.PaleTurquoise;
this.panelBlue.Location = new System.Drawing.Point(34, 153);
this.panelBlue.Name = "panelBlue";
this.panelBlue.Size = new System.Drawing.Size(53, 49);
@@ -342,7 +342,7 @@
this.Text = "Создание объекта";
this.groupBoxCruiser.ResumeLayout(false);
this.groupBoxCruiser.PerformLayout();
this.panelColor.ResumeLayout(false);
this.panelOrchid.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCruiser)).EndInit();
this.groupBoxColor.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit();
@@ -356,7 +356,7 @@
private GroupBox groupBoxCruiser;
private Button buttonCancel;
private Button buttonAdd;
private Panel panelColor;
private Panel panelOrchid;
private Label label_addit_color;
private Label label_color;
private PictureBox pictureBoxCruiser;
@@ -371,7 +371,7 @@
private Label labelWeight;
private Label labelSpeed;
private CheckBox checkBoxMissileSilos;
private Panel panelOrchid;
private Panel panelColor;
private Panel panelPink;
private Panel panelViolet;
private Panel panelBlue;

View File

@@ -27,7 +27,7 @@ namespace Cruiser
panelPink.MouseDown += PanelColor_MouseDown;
panelViolet.MouseDown += PanelColor_MouseDown;
panelPurple.MouseDown += PanelColor_MouseDown;
panelColor.MouseDown += PanelColor_MouseDown;
panelOrchid.MouseDown += PanelColor_MouseDown;
buttonCancel.Click += (s, e) => Close();
}

View File

@@ -1,3 +1,15 @@
using Serilog;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Events;
using Serilog.Formatting.Json;
using Serilog.Configuration;
using Microsoft.Extensions.Configuration;
namespace Cruiser
{
internal static class Program
@@ -8,9 +20,24 @@ namespace Cruiser
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
string[] path = Directory.GetCurrentDirectory().Split('\\');
string pathNeed = "";
for (int i = 0; i < path.Length - 3; i++)
{
pathNeed += path[i] + "\\";
}
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile(path: $"{pathNeed}appsettings.json", optional: false, reloadOnChange: true)
.Build();
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.CreateLogger();
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FormCruiserCollection());
}
}

View File

@@ -1,69 +1,65 @@
using System;
using Cruiser.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cruiser.Exceptions;
namespace Cruiser.Generics
{
internal class SetGeneric<T>
where T : class
{
private readonly List<T?> _places;
public int Count => _places.Count;
private readonly int _maxCount;
public int Count => _places.Count;
public SetGeneric(int count)
{
_maxCount = count;
_places = new List<T?>(count);
}
public bool Insert(T cruiser)
public void Insert(T cruiser)
{
if (_places.Count == _maxCount)
{
return false;
}
throw new StorageOverflowException(_maxCount);
Insert(cruiser, 0);
return true;
}
public bool Insert(T cruiser, int position)
{
if (!(position >= 0 && position <= Count && _places.Count < _maxCount))
{
return false;
}
_places.Insert(position, cruiser);
return true;
}
public bool Remove(int position)
{
if (position < 0 || position >= Count)
{
return false;
}
_places.RemoveAt(position);
return true;
public void Insert(T cruiser, int position)
{
if (_places.Count == _maxCount)
throw new StorageOverflowException(_maxCount);
if (!(position >= 0 && position <= Count))
throw new Exception("Неверная позиция для вставки");
_places.Insert(position, cruiser);
}
public void Remove(int position)
{
if (!(position >= 0 && position < Count))
throw new CruiserNotFoundException(position);
_places.RemoveAt(position);
}
public T? this[int position]
{
get
{
if (position < 0 || position >= _maxCount)
{
if (!(position >= 0 && position < Count))
return null;
}
return _places[position];
}
set
{
if (!(position >= 0 && position < Count && _places.Count < _maxCount))
{
return;
}
_places.Insert(position, value);
return;
}
}
public IEnumerable<T?> GetCruiser(int? maxCruisers = null)
@@ -78,4 +74,4 @@ namespace Cruiser.Generics
}
}
}
}
}

View File

@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace Cruiser.Exceptions
{
[Serializable]
internal class StorageOverflowException : ApplicationException
{
public StorageOverflowException(int count) : base($"В наборе превышено допустимое количество: {count}") { }
public StorageOverflowException() : base() { }
public StorageOverflowException(string message) : base(message) { }
public StorageOverflowException(string message, Exception exception) : base(message, exception) { }
protected StorageOverflowException(SerializationInfo info, StreamingContext context) : base(info, context) { }
}
}

View File

@@ -0,0 +1,15 @@
{
"Serilog": {
"Using": [ "Serilog.Sinks.File" ],
"MinimumLevel": "Debug",
"WriteTo": [
{
"Name": "File",
"Args": { "path": "log.log" }
}
],
"Properties": {
"Application": "Sample"
}
}
}