Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| caf208b305 | |||
| ec986c5a2c | |||
| 825ad3cdf5 | |||
| fce83f96d5 | |||
| 5630e074f1 | |||
| 0027078048 | |||
| 9123f0442e |
48
ProjectBulldozer/Drawning/ExtentionDrawingTractor.cs
Normal file
48
ProjectBulldozer/Drawning/ExtentionDrawingTractor.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using ProjectBulldozer.Drawning;
|
||||
using ProjectBulldozer.Entities;
|
||||
namespace ProjectBulldozer.Drawing
|
||||
{
|
||||
public static class ExtentionDrawingTractor
|
||||
{
|
||||
public static DrawingTractor? CreateDrawingTractor(this string info,
|
||||
char separatorForObject, int width, int height)
|
||||
{
|
||||
string[] strs = info.Split(separatorForObject);
|
||||
if (strs.Length == 3)
|
||||
{
|
||||
return new DrawingTractor(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]),
|
||||
Color.FromName(strs[2]), width, height);
|
||||
}
|
||||
if (strs.Length == 7)
|
||||
{
|
||||
return new DrawingBulldozer(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 DrawingTractor drawingTractor,
|
||||
char separatorForObject)
|
||||
{
|
||||
var tractor = drawingTractor.EntityTractor;
|
||||
if (tractor == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
var str =
|
||||
$"{tractor.Speed}{separatorForObject}{tractor.Weight}{separatorForObject}{tractor.BodyColor.Name}";
|
||||
if (tractor is not EntityBulldozer bulldozer)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
return
|
||||
$"{str}{separatorForObject}{bulldozer.AdditionalColor.Name}{separatorForObject}" +
|
||||
$"{bulldozer.ThirdWheel}{separatorForObject}{bulldozer.Otval}{separatorForObject}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
17
ProjectBulldozer/Exceptions/BulldozerNotFoundException.cs
Normal file
17
ProjectBulldozer/Exceptions/BulldozerNotFoundException.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System.Runtime.Serialization;
|
||||
namespace ProjectBulldozer.Exceptions
|
||||
{
|
||||
[Serializable]
|
||||
internal class BulldozerNotFoundException : ApplicationException
|
||||
{
|
||||
public BulldozerNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
|
||||
|
||||
public BulldozerNotFoundException() : base() { }
|
||||
|
||||
public BulldozerNotFoundException(string message) : base(message) { }
|
||||
|
||||
public BulldozerNotFoundException(string message, Exception exception) : base(message, exception) { }
|
||||
|
||||
protected BulldozerNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context) { }
|
||||
}
|
||||
}
|
||||
17
ProjectBulldozer/Exceptions/StorageOverflowException.cs
Normal file
17
ProjectBulldozer/Exceptions/StorageOverflowException.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System.Runtime.Serialization;
|
||||
namespace ProjectBulldozer.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) { }
|
||||
}
|
||||
}
|
||||
174
ProjectBulldozer/FormBulldozerCollections.Designer.cs
generated
174
ProjectBulldozer/FormBulldozerCollections.Designer.cs
generated
@@ -1,61 +1,67 @@
|
||||
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ProjectBulldozer
|
||||
{
|
||||
partial class FormTractorCollections
|
||||
{
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
components = new System.ComponentModel.Container();
|
||||
maskedTextBoxNumber = new MaskedTextBox();
|
||||
ButtonRefreshCollection = new Button();
|
||||
ButtonRemoveTractor = new Button();
|
||||
ButtonAddTractor = new Button();
|
||||
pictureBoxCollections = new PictureBox();
|
||||
textBoxStorageName = new TextBox();
|
||||
bindingSource1 = new BindingSource(components);
|
||||
bindingSource2 = new BindingSource(components);
|
||||
groupBox1 = new GroupBox();
|
||||
listBoxStorage = new ListBox();
|
||||
ButtonAddObject = new Button();
|
||||
ButtonRemoveObject = new Button();
|
||||
Instruments = new GroupBox();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollections).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)bindingSource1).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)bindingSource2).BeginInit();
|
||||
openFileDialog = new OpenFileDialog();
|
||||
saveFileDialog = new SaveFileDialog();
|
||||
menuStrip1 = new MenuStrip();
|
||||
файлToolStripMenuItem = new ToolStripMenuItem();
|
||||
сохранитьToolStripMenuItem = new ToolStripMenuItem();
|
||||
загрузитьToolStripMenuItem = new ToolStripMenuItem();
|
||||
toolStripMenuItem1 = new ToolStripMenuItem();
|
||||
ButtonSortByType = new Button();
|
||||
ButtonSortByColor = new Button();
|
||||
((ISupportInitialize)pictureBoxCollections).BeginInit();
|
||||
groupBox1.SuspendLayout();
|
||||
Instruments.SuspendLayout();
|
||||
menuStrip1.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
maskedTextBoxNumber.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
maskedTextBoxNumber.Location = new Point(33, 399);
|
||||
maskedTextBoxNumber.Location = new Point(35, 379);
|
||||
maskedTextBoxNumber.Margin = new Padding(3, 2, 3, 2);
|
||||
maskedTextBoxNumber.Mask = "0";
|
||||
maskedTextBoxNumber.Mask = "00";
|
||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
maskedTextBoxNumber.Size = new Size(131, 23);
|
||||
maskedTextBoxNumber.Size = new Size(132, 23);
|
||||
maskedTextBoxNumber.TabIndex = 4;
|
||||
//
|
||||
// ButtonRefreshCollection
|
||||
//
|
||||
ButtonRefreshCollection.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
ButtonRefreshCollection.Location = new Point(33, 499);
|
||||
ButtonRefreshCollection.Location = new Point(33, 441);
|
||||
ButtonRefreshCollection.Margin = new Padding(3, 2, 3, 2);
|
||||
ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||
ButtonRefreshCollection.Size = new Size(131, 31);
|
||||
ButtonRefreshCollection.TabIndex = 2;
|
||||
ButtonRefreshCollection.Text = "Обновить все";
|
||||
ButtonRefreshCollection.UseVisualStyleBackColor = true;
|
||||
ButtonRefreshCollection.Click += ButtonRefreshCollection_Click;
|
||||
//
|
||||
// ButtonRemoveTractor
|
||||
//
|
||||
ButtonRemoveTractor.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
ButtonRemoveTractor.Location = new Point(33, 444);
|
||||
ButtonRemoveTractor.Location = new Point(35, 406);
|
||||
ButtonRemoveTractor.Margin = new Padding(3, 2, 3, 2);
|
||||
ButtonRemoveTractor.Name = "ButtonRemoveTractor";
|
||||
ButtonRemoveTractor.Size = new Size(131, 33);
|
||||
ButtonRemoveTractor.Size = new Size(131, 31);
|
||||
ButtonRemoveTractor.TabIndex = 1;
|
||||
ButtonRemoveTractor.Text = "Удалить объект";
|
||||
ButtonRemoveTractor.UseVisualStyleBackColor = true;
|
||||
@@ -64,7 +70,7 @@ namespace ProjectBulldozer
|
||||
// ButtonAddTractor
|
||||
//
|
||||
ButtonAddTractor.Anchor = AnchorStyles.Top;
|
||||
ButtonAddTractor.Location = new Point(33, 346);
|
||||
ButtonAddTractor.Location = new Point(35, 337);
|
||||
ButtonAddTractor.Margin = new Padding(3, 2, 3, 2);
|
||||
ButtonAddTractor.Name = "ButtonAddTractor";
|
||||
ButtonAddTractor.Size = new Size(131, 29);
|
||||
@@ -76,20 +82,20 @@ namespace ProjectBulldozer
|
||||
// pictureBoxCollections
|
||||
//
|
||||
pictureBoxCollections.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
pictureBoxCollections.Location = new Point(4, 4);
|
||||
pictureBoxCollections.Location = new Point(0, 26);
|
||||
pictureBoxCollections.Margin = new Padding(3, 2, 3, 2);
|
||||
pictureBoxCollections.Name = "pictureBoxCollections";
|
||||
pictureBoxCollections.Size = new Size(693, 541);
|
||||
pictureBoxCollections.Size = new Size(697, 474);
|
||||
pictureBoxCollections.TabIndex = 1;
|
||||
pictureBoxCollections.TabStop = false;
|
||||
pictureBoxCollections.Click += pictureBoxCollections_Click;
|
||||
//
|
||||
// textBoxStorageName
|
||||
//
|
||||
textBoxStorageName.Location = new Point(27, 32);
|
||||
textBoxStorageName.Location = new Point(27, 22);
|
||||
textBoxStorageName.Name = "textBoxStorageName";
|
||||
textBoxStorageName.Size = new Size(131, 23);
|
||||
textBoxStorageName.TabIndex = 5;
|
||||
textBoxStorageName.TextChanged += textBoxStorageName_TextChanged;
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
@@ -99,7 +105,7 @@ namespace ProjectBulldozer
|
||||
groupBox1.Controls.Add(textBoxStorageName);
|
||||
groupBox1.Location = new Point(6, 22);
|
||||
groupBox1.Name = "groupBox1";
|
||||
groupBox1.Size = new Size(189, 296);
|
||||
groupBox1.Size = new Size(189, 219);
|
||||
groupBox1.TabIndex = 5;
|
||||
groupBox1.TabStop = false;
|
||||
groupBox1.Text = "Наборы";
|
||||
@@ -108,7 +114,7 @@ namespace ProjectBulldozer
|
||||
//
|
||||
listBoxStorage.FormattingEnabled = true;
|
||||
listBoxStorage.ItemHeight = 15;
|
||||
listBoxStorage.Location = new Point(27, 122);
|
||||
listBoxStorage.Location = new Point(27, 84);
|
||||
listBoxStorage.Name = "listBoxStorage";
|
||||
listBoxStorage.Size = new Size(131, 94);
|
||||
listBoxStorage.TabIndex = 9;
|
||||
@@ -117,7 +123,7 @@ namespace ProjectBulldozer
|
||||
// ButtonAddObject
|
||||
//
|
||||
ButtonAddObject.Anchor = AnchorStyles.Top;
|
||||
ButtonAddObject.Location = new Point(27, 72);
|
||||
ButtonAddObject.Location = new Point(27, 50);
|
||||
ButtonAddObject.Margin = new Padding(3, 2, 3, 2);
|
||||
ButtonAddObject.Name = "ButtonAddObject";
|
||||
ButtonAddObject.Size = new Size(131, 29);
|
||||
@@ -129,7 +135,7 @@ namespace ProjectBulldozer
|
||||
// ButtonRemoveObject
|
||||
//
|
||||
ButtonRemoveObject.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
ButtonRemoveObject.Location = new Point(27, 244);
|
||||
ButtonRemoveObject.Location = new Point(27, 181);
|
||||
ButtonRemoveObject.Margin = new Padding(3, 2, 3, 2);
|
||||
ButtonRemoveObject.Name = "ButtonRemoveObject";
|
||||
ButtonRemoveObject.Size = new Size(131, 33);
|
||||
@@ -140,36 +146,132 @@ namespace ProjectBulldozer
|
||||
//
|
||||
// Instruments
|
||||
//
|
||||
Instruments.Controls.Add(ButtonSortByColor);
|
||||
Instruments.Controls.Add(ButtonSortByType);
|
||||
Instruments.Controls.Add(ButtonRefreshCollection);
|
||||
Instruments.Controls.Add(groupBox1);
|
||||
Instruments.Controls.Add(maskedTextBoxNumber);
|
||||
Instruments.Controls.Add(ButtonAddTractor);
|
||||
Instruments.Controls.Add(ButtonRemoveTractor);
|
||||
Instruments.Location = new Point(697, 4);
|
||||
Instruments.Location = new Point(703, 26);
|
||||
Instruments.Name = "Instruments";
|
||||
Instruments.Size = new Size(200, 541);
|
||||
Instruments.Size = new Size(201, 464);
|
||||
Instruments.TabIndex = 6;
|
||||
Instruments.TabStop = false;
|
||||
Instruments.Text = "Инструменты";
|
||||
//
|
||||
// openFileDialog
|
||||
//
|
||||
openFileDialog.FileName = "openFileDialog";
|
||||
openFileDialog.Filter = "txt file | *.txt";
|
||||
openFileDialog.FileOk += openFileDialog_FileOk;
|
||||
//
|
||||
// saveFileDialog
|
||||
//
|
||||
saveFileDialog.FileName = "saveFileDialog";
|
||||
saveFileDialog.Filter = "txt file | *.txt";
|
||||
saveFileDialog.FileOk += saveFileDialog_FileOk;
|
||||
//
|
||||
// menuStrip1
|
||||
//
|
||||
menuStrip1.ImageScalingSize = new Size(20, 20);
|
||||
menuStrip1.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem });
|
||||
menuStrip1.Location = new Point(0, 0);
|
||||
menuStrip1.Name = "menuStrip1";
|
||||
menuStrip1.Padding = new Padding(5, 2, 0, 2);
|
||||
menuStrip1.RenderMode = ToolStripRenderMode.System;
|
||||
menuStrip1.Size = new Size(904, 24);
|
||||
menuStrip1.TabIndex = 6;
|
||||
menuStrip1.Text = "menuStrip1";
|
||||
//
|
||||
// файлToolStripMenuItem
|
||||
//
|
||||
файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { сохранитьToolStripMenuItem, загрузитьToolStripMenuItem });
|
||||
файлToolStripMenuItem.Name = "файлToolStripMenuItem";
|
||||
файлToolStripMenuItem.Size = new Size(50, 20);
|
||||
файлToolStripMenuItem.Text = "Файл";
|
||||
файлToolStripMenuItem.Click += файлToolStripMenuItem_Click;
|
||||
//
|
||||
// сохранитьToolStripMenuItem
|
||||
//
|
||||
сохранитьToolStripMenuItem.Name = "сохранитьToolStripMenuItem";
|
||||
сохранитьToolStripMenuItem.Size = new Size(135, 22);
|
||||
сохранитьToolStripMenuItem.Text = "Сохранить";
|
||||
сохранитьToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
|
||||
//
|
||||
// загрузитьToolStripMenuItem
|
||||
//
|
||||
загрузитьToolStripMenuItem.Name = "загрузитьToolStripMenuItem";
|
||||
загрузитьToolStripMenuItem.Size = new Size(135, 22);
|
||||
загрузитьToolStripMenuItem.Text = "Загрузить";
|
||||
загрузитьToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
|
||||
//
|
||||
// toolStripMenuItem1
|
||||
//
|
||||
toolStripMenuItem1.Name = "toolStripMenuItem1";
|
||||
toolStripMenuItem1.Size = new Size(32, 19);
|
||||
//
|
||||
// ButtonSortByType
|
||||
//
|
||||
ButtonSortByType.Location = new Point(33, 247);
|
||||
ButtonSortByType.Name = "ButtonSortByType";
|
||||
ButtonSortByType.Size = new Size(131, 41);
|
||||
ButtonSortByType.TabIndex = 7;
|
||||
ButtonSortByType.Text = "Сортировать по типу";
|
||||
ButtonSortByType.UseVisualStyleBackColor = true;
|
||||
ButtonSortByType.Click += ButtonSortByType_Click;
|
||||
//
|
||||
// ButtonSortByColor
|
||||
//
|
||||
ButtonSortByColor.Location = new Point(33, 294);
|
||||
ButtonSortByColor.Name = "ButtonSortByColor";
|
||||
ButtonSortByColor.Size = new Size(131, 38);
|
||||
ButtonSortByColor.TabIndex = 8;
|
||||
ButtonSortByColor.Text = "Сортировать по цвету";
|
||||
ButtonSortByColor.UseVisualStyleBackColor = true;
|
||||
ButtonSortByColor.Click += ButtonSortByColor_Click;
|
||||
//
|
||||
// FormTractorCollections
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(904, 543);
|
||||
ClientSize = new Size(904, 509);
|
||||
Controls.Add(Instruments);
|
||||
Controls.Add(pictureBoxCollections);
|
||||
Controls.Add(menuStrip1);
|
||||
MainMenuStrip = menuStrip1;
|
||||
Margin = new Padding(3, 2, 3, 2);
|
||||
Name = "FormTractorCollections";
|
||||
Text = "Набор локомотивов";
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollections).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)bindingSource1).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)bindingSource2).EndInit();
|
||||
Text = "Набор объектов";
|
||||
((ISupportInitialize)pictureBoxCollections).EndInit();
|
||||
groupBox1.ResumeLayout(false);
|
||||
groupBox1.PerformLayout();
|
||||
Instruments.ResumeLayout(false);
|
||||
Instruments.PerformLayout();
|
||||
menuStrip1.ResumeLayout(false);
|
||||
menuStrip1.PerformLayout();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
private void файлToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private void saveFileDialog_FileOk(object sender, CancelEventArgs e)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private void openFileDialog_FileOk(object sender, CancelEventArgs e)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private void pictureBoxCollections_Click(object sender, EventArgs e)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
private Button ButtonRefreshCollection;
|
||||
private Button ButtonRemoveTractor;
|
||||
@@ -178,12 +280,18 @@ namespace ProjectBulldozer
|
||||
private MaskedTextBox maskedTextBoxNumber;
|
||||
private GroupBox groupBox1;
|
||||
private TextBox textBoxStorageName;
|
||||
private BindingSource bindingSource1;
|
||||
private BindingSource bindingSource2;
|
||||
private ListBox listBoxStorage;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private Button ButtonAddObject;
|
||||
private Button ButtonRemoveObject;
|
||||
private GroupBox Instruments;
|
||||
private EventHandler textBoxStorageName_TextChanged;
|
||||
private MenuStrip menuStrip1;
|
||||
private ToolStripMenuItem файлToolStripMenuItem;
|
||||
private ToolStripMenuItem сохранитьToolStripMenuItem;
|
||||
private ToolStripMenuItem загрузитьToolStripMenuItem;
|
||||
private ToolStripMenuItem toolStripMenuItem1;
|
||||
private Button ButtonSortByColor;
|
||||
private Button ButtonSortByType;
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,27 @@
|
||||
using Bulldozer;
|
||||
using ProjectBulldozer.Generics;
|
||||
using ProjectBulldozer.Drawning;
|
||||
|
||||
using ProjectBulldozer.Exceptions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
namespace ProjectBulldozer
|
||||
{
|
||||
public partial class FormTractorCollections : Form
|
||||
{
|
||||
private readonly TractorGenericStorage _storage;
|
||||
readonly int countPlace = 10;
|
||||
|
||||
private readonly ILogger _logger;
|
||||
readonly int countPlace = 12;
|
||||
public FormTractorCollections()
|
||||
{
|
||||
InitializeComponent();
|
||||
_storage = new TractorGenericStorage(pictureBoxCollections.Width, pictureBoxCollections.Height);
|
||||
}
|
||||
public FormTractorCollections(ILogger<FormTractorCollections> logger)
|
||||
{
|
||||
InitializeComponent();
|
||||
_storage = new TractorGenericStorage(pictureBoxCollections.Width, pictureBoxCollections.Height);
|
||||
_logger = logger;
|
||||
}
|
||||
private void ReloadObjects()
|
||||
{
|
||||
int index = listBoxStorage.SelectedIndex;
|
||||
@@ -36,10 +45,12 @@ namespace ProjectBulldozer
|
||||
if (string.IsNullOrEmpty(textBoxStorageName.Text))
|
||||
{
|
||||
MessageBox.Show("Не всё заполнено", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogWarning($"!!Ошибка!! Не все данные заполнены");
|
||||
return;
|
||||
}
|
||||
_storage.AddSet(textBoxStorageName.Text);
|
||||
ReloadObjects();
|
||||
_logger.LogInformation($"Добавлен набор: {textBoxStorageName.Text}");
|
||||
}
|
||||
private void listBoxStorage_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
@@ -49,22 +60,35 @@ namespace ProjectBulldozer
|
||||
{
|
||||
if (listBoxStorage.SelectedIndex == -1)
|
||||
{
|
||||
_logger.LogWarning($"Удаление не выбранного набора");
|
||||
return;
|
||||
}
|
||||
string name = listBoxStorage.SelectedItem.ToString() ?? string.Empty;
|
||||
if (MessageBox.Show($"Удалить объект {listBoxStorage.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
_storage.DelSet(listBoxStorage.SelectedItem.ToString() ?? string.Empty);
|
||||
ReloadObjects();
|
||||
_logger.LogInformation($"Удален набор: {name}");
|
||||
}
|
||||
}
|
||||
private void ButtonAddTractor_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorage.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var formBulldozerConfig = new FormBulldozerConfig();
|
||||
formBulldozerConfig.AddEvent(AddTractor);
|
||||
formBulldozerConfig.Show();
|
||||
}
|
||||
|
||||
private void AddTractor(DrawingTractor tractor)
|
||||
{
|
||||
tractor._pictureWidth = pictureBoxCollections.Width;
|
||||
@@ -73,22 +97,37 @@ namespace ProjectBulldozer
|
||||
if (listBoxStorage.SelectedIndex == -1) return;
|
||||
|
||||
var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? string.Empty];
|
||||
string name = listBoxStorage.SelectedItem.ToString() ?? string.Empty;
|
||||
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int addedIndex = obj + tractor;
|
||||
if (addedIndex != -1 && addedIndex < countPlace)
|
||||
try
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollections.Image = obj.ShowTractors();
|
||||
|
||||
int addedIndex = obj + tractor;
|
||||
if (addedIndex != -1 && addedIndex < countPlace)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollections.Image = obj.ShowTractors();
|
||||
_logger.LogInformation($"В набор {name} добавлен объект");
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
_logger.LogWarning("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
else
|
||||
catch (StorageOverflowException ex)
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
|
||||
|
||||
MessageBox.Show(ex.Message);
|
||||
_logger.LogWarning($"{ex.Message}. Не удалось добавить объект");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
_logger.LogWarning($"{ex.Message}. Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
private void ButtonRemoveTractor_Click(object sender, EventArgs e)
|
||||
@@ -99,21 +138,97 @@ namespace ProjectBulldozer
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (maskedTextBoxNumber.Text == "") { return; }
|
||||
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||
if (obj - pos != null)
|
||||
try
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxCollections.Image = obj.ShowTractors();
|
||||
string name = listBoxStorage.SelectedItem.ToString() ?? string.Empty;
|
||||
if (obj - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxCollections.Image = obj.ShowTractors();
|
||||
_logger.LogInformation($"Из набора {name} удален объект");
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
_logger.LogWarning("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
else
|
||||
catch (BulldozerNotFoundException ex)
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
MessageBox.Show(ex.Message);
|
||||
_logger.LogWarning($"{ex.Message}. Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorage.SelectedIndex == -1) return;
|
||||
var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBoxCollections.Image = obj.ShowTractors();
|
||||
}
|
||||
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
_storage.SaveData(saveFileDialog.FileName);
|
||||
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
_logger.LogInformation("Сохранение");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogWarning("Ошибка сохранения");
|
||||
}
|
||||
}
|
||||
}
|
||||
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
_storage.LoadData(openFileDialog.FileName);
|
||||
ReloadObjects();
|
||||
MessageBox.Show("Загрузка произошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
_logger.LogInformation("Загрузка");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogWarning("Ошибка загрузки");
|
||||
}
|
||||
}
|
||||
}
|
||||
private void ButtonSortByType_Click(object sender, EventArgs e) => CompareTractors(new TractorCompareByType());
|
||||
|
||||
private void ButtonSortByColor_Click(object sender, EventArgs e) => CompareTractors(new TractorCompareByColor());
|
||||
|
||||
private void CompareTractors(IComparer<DrawingTractor?> comparer)
|
||||
{
|
||||
if (listBoxStorage.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
obj.Sort(comparer);
|
||||
pictureBoxCollections.Image = obj.ShowTractors();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -18,9 +18,7 @@
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="
|
||||
|
||||
1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
@@ -119,4 +117,16 @@
|
||||
<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>153, 17</value>
|
||||
</metadata>
|
||||
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>286, 17</value>
|
||||
</metadata>
|
||||
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>25</value>
|
||||
</metadata>
|
||||
</root>
|
||||
@@ -5,11 +5,14 @@ namespace ProjectBulldozer.Generics
|
||||
{
|
||||
internal class TractorGenericCollection<T, U> where T : DrawingTractor where U : IMoveableObject
|
||||
{
|
||||
//ширина/высота окна
|
||||
private readonly int _pictureWidth;
|
||||
private readonly int _pictureHeight;
|
||||
//ширина/высота занимаемого места
|
||||
private readonly int _placeSizeWidth = 150;
|
||||
private readonly int _placeSizeHeight = 130;
|
||||
private readonly SetGeneric<T> _collection;
|
||||
public IEnumerable<T?> GetTractors => _collection.GetTractors();
|
||||
public TractorGenericCollection(int picWidth, int picHeight)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
@@ -18,13 +21,11 @@ namespace ProjectBulldozer.Generics
|
||||
_pictureHeight = picHeight;
|
||||
_collection = new SetGeneric<T>(width * height);
|
||||
}
|
||||
public static int operator +(TractorGenericCollection<T, U> collect, T? tract)
|
||||
public static int operator +(TractorGenericCollection<T, U> collect, T? tractor)
|
||||
{
|
||||
if (tract == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return collect._collection.Insert(tract);
|
||||
if (tractor == null) return -1;
|
||||
|
||||
return collect?._collection.Insert(tractor, new DrawingBulldozerEqutables())??-1;
|
||||
}
|
||||
public static T? operator -(TractorGenericCollection<T, U> collect, int pos)
|
||||
{
|
||||
@@ -35,6 +36,10 @@ namespace ProjectBulldozer.Generics
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
public U? GetU(int pos)
|
||||
{
|
||||
return (U?)_collection[pos]?.GetMoveableObject;
|
||||
}
|
||||
public Bitmap ShowTractors()
|
||||
{
|
||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||
@@ -50,30 +55,33 @@ namespace ProjectBulldozer.Generics
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||
{
|
||||
//линия рамзетки места
|
||||
//линия разметки места
|
||||
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 3, j * _placeSizeHeight);
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
int height = _pictureHeight / _placeSizeHeight;
|
||||
for (int i = 0; i < _collection.Count; i++)
|
||||
{
|
||||
// Получение объекта
|
||||
var obj = _collection[i];
|
||||
// Установка позиции
|
||||
obj?.SetPosition(
|
||||
(int)((width - 1) * _placeSizeWidth - (i % width * _placeSizeWidth)),
|
||||
(int)((height - 1) * _placeSizeHeight - (i / width * _placeSizeHeight))
|
||||
);
|
||||
// Прорисовка объекта
|
||||
obj?.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
|
||||
public void Sort(IComparer<T?> comparer) => _collection.SortSet(comparer);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
55
ProjectBulldozer/Generics/DrawingBulldozerEqutables.cs.cs
Normal file
55
ProjectBulldozer/Generics/DrawingBulldozerEqutables.cs.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using ProjectBulldozer.Drawning;
|
||||
using ProjectBulldozer.Entities;
|
||||
|
||||
namespace ProjectBulldozer.Generics
|
||||
{
|
||||
internal class DrawingBulldozerEqutables : IEqualityComparer<DrawingTractor?>
|
||||
{
|
||||
public bool Equals(DrawingTractor? x, DrawingTractor? y)
|
||||
{
|
||||
if (x == null || x.EntityTractor == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
}
|
||||
if (y == null || y.EntityTractor == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
}
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityTractor.Speed != y.EntityTractor.Speed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityTractor.Weight != y.EntityTractor.Weight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityTractor.BodyColor != y.EntityTractor.BodyColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x is DrawingBulldozer && y is DrawingBulldozer)
|
||||
{
|
||||
if ((x.EntityTractor as EntityBulldozer).Otval != (y.EntityTractor as EntityBulldozer).Otval)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ((x.EntityTractor as EntityBulldozer).ThirdWheel != (y.EntityTractor as EntityBulldozer).ThirdWheel)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] DrawingTractor obj)
|
||||
{
|
||||
return obj.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
namespace ProjectBulldozer.Generics
|
||||
using ProjectBulldozer.Exceptions;
|
||||
namespace ProjectBulldozer.Generics
|
||||
{
|
||||
internal class SetGeneric<T> where T : class
|
||||
{
|
||||
@@ -12,24 +13,48 @@
|
||||
_places = new List<T?>(count);
|
||||
}
|
||||
/// Добавление объекта в набор
|
||||
public int Insert(T tract)
|
||||
public int Insert(T tractor, IEqualityComparer<T?>? equal = null)
|
||||
{
|
||||
return Insert(tract, 0);
|
||||
if (_places.Count == _maxCount)
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
Insert(tractor, 0, equal);
|
||||
return 0;
|
||||
}
|
||||
public int Insert(T tract, int position)
|
||||
public bool Insert(T tractor, int position, IEqualityComparer<T?>? equal = null)
|
||||
{
|
||||
if (position < 0 || position >= _maxCount) return -1;
|
||||
_places.Insert(position, tract);
|
||||
return position;
|
||||
if (position < 0 || position >= _maxCount)
|
||||
{
|
||||
throw new BulldozerNotFoundException(position);
|
||||
}
|
||||
if (Count >= _maxCount)
|
||||
{
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
}
|
||||
if (equal != null)
|
||||
{
|
||||
foreach (var i in _places)
|
||||
{
|
||||
if (equal.Equals(i, tractor))
|
||||
{
|
||||
throw new ApplicationException($"Объект уже существует");
|
||||
}
|
||||
}
|
||||
}
|
||||
_places.Insert(position, tractor);
|
||||
return true;
|
||||
}
|
||||
public T? Remove(int position)
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (position >= Count || position < 0)
|
||||
return null;
|
||||
|
||||
T? tmp = _places[position];
|
||||
if (position < 0 || position >= _maxCount)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_places[position] == null)
|
||||
{
|
||||
throw new BulldozerNotFoundException(position);
|
||||
}
|
||||
_places[position] = null;
|
||||
return tmp;
|
||||
return true;
|
||||
}
|
||||
public T? this[int position]
|
||||
{
|
||||
@@ -55,5 +80,7 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SortSet(IComparer<T?> comparer) => _places.Sort(comparer);
|
||||
}
|
||||
}
|
||||
|
||||
38
ProjectBulldozer/Generics/TractorCompareByColor.cs
Normal file
38
ProjectBulldozer/Generics/TractorCompareByColor.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using ProjectBulldozer.Drawning;
|
||||
using ProjectBulldozer.Entities;
|
||||
|
||||
namespace ProjectBulldozer.Generics
|
||||
{
|
||||
internal class TractorCompareByColor : IComparer<DrawingTractor?>
|
||||
{
|
||||
public int Compare(DrawingTractor? x, DrawingTractor? y)
|
||||
{
|
||||
if (x == null || x.EntityTractor == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
}
|
||||
if (y == null || y.EntityTractor == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
}
|
||||
if (x.EntityTractor.BodyColor != y.EntityTractor.BodyColor)
|
||||
{
|
||||
return x.EntityTractor.BodyColor.Name.CompareTo(y.EntityTractor.BodyColor.Name);
|
||||
}
|
||||
if (x.EntityTractor is EntityBulldozer _BulldozerX && y.EntityTractor is EntityBulldozer _BulldozertY)
|
||||
{
|
||||
var ElementsColorCompare = _BulldozerX.AdditionalColor.Name.CompareTo(_BulldozertY.AdditionalColor.Name);
|
||||
if (ElementsColorCompare != 0)
|
||||
{
|
||||
return ElementsColorCompare;
|
||||
}
|
||||
}
|
||||
var speedCompare = x.EntityTractor.Speed.CompareTo(y.EntityTractor.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return x.EntityTractor.Weight.CompareTo(y.EntityTractor.Weight);
|
||||
}
|
||||
}
|
||||
}
|
||||
29
ProjectBulldozer/Generics/TractorCompareByType.cs
Normal file
29
ProjectBulldozer/Generics/TractorCompareByType.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using ProjectBulldozer.Drawning;
|
||||
|
||||
namespace ProjectBulldozer.Generics
|
||||
{
|
||||
internal class TractorCompareByType : IComparer<DrawingTractor?>
|
||||
{
|
||||
public int Compare(DrawingTractor? x, DrawingTractor? y)
|
||||
{
|
||||
if (x == null || x.EntityTractor == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
}
|
||||
if (y == null || y.EntityTractor == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
}
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return x.GetType().Name.CompareTo(y.GetType().Name);
|
||||
}
|
||||
var speedCompare = x.EntityTractor.Speed.CompareTo(y.EntityTractor.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return x.EntityTractor.Weight.CompareTo(y.EntityTractor.Weight);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,43 +1,123 @@
|
||||
using ProjectBulldozer.Drawning;
|
||||
using ProjectBulldozer.Drawing;
|
||||
using ProjectBulldozer.Drawning;
|
||||
using System.Text;
|
||||
|
||||
namespace ProjectBulldozer.Generics
|
||||
{
|
||||
internal class TractorGenericStorage
|
||||
{
|
||||
readonly Dictionary<string, TractorGenericCollection<DrawingTractor, DrawingObjectTractor>> _TractorsStorage;
|
||||
public List<string> Keys => _TractorsStorage.Keys.ToList();
|
||||
private static readonly char _separatorForKeyValue = '|';
|
||||
private readonly char _separatorRecords = ';';
|
||||
private static readonly char _separatorForObject = ':';
|
||||
readonly Dictionary<TractorsCollectionInfo, TractorGenericCollection<DrawingTractor, DrawingObjectTractor>> _TractorsStorage;
|
||||
public List<TractorsCollectionInfo> Keys => _TractorsStorage.Keys.ToList();
|
||||
private readonly int _pictureWidth;
|
||||
private readonly int _pictureHeight;
|
||||
public TractorGenericStorage(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_TractorsStorage = new Dictionary<string, TractorGenericCollection<DrawingTractor, DrawingObjectTractor>>();
|
||||
_TractorsStorage = new Dictionary<TractorsCollectionInfo, TractorGenericCollection<DrawingTractor, DrawingObjectTractor>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
public void AddSet(string name)
|
||||
{
|
||||
if (!_TractorsStorage.ContainsKey(name))
|
||||
if (!_TractorsStorage.ContainsKey(new TractorsCollectionInfo(name, "")))
|
||||
{
|
||||
_TractorsStorage.Add(name, new TractorGenericCollection<DrawingTractor, DrawingObjectTractor>(_pictureWidth, _pictureHeight));
|
||||
_TractorsStorage.Add(new TractorsCollectionInfo(name, ""), new TractorGenericCollection<DrawingTractor, DrawingObjectTractor>(_pictureWidth, _pictureHeight));
|
||||
}
|
||||
}
|
||||
public void DelSet(string name)
|
||||
{
|
||||
if (_TractorsStorage.ContainsKey(name))
|
||||
if (_TractorsStorage.ContainsKey(new TractorsCollectionInfo(name, "")))
|
||||
{
|
||||
_TractorsStorage.Remove(name);
|
||||
_TractorsStorage.Remove(new TractorsCollectionInfo(name, ""));
|
||||
}
|
||||
}
|
||||
public TractorGenericCollection<DrawingTractor, DrawingObjectTractor>?
|
||||
this[string ind]
|
||||
public TractorGenericCollection<DrawingTractor, DrawingObjectTractor>? this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_TractorsStorage.ContainsKey(ind))
|
||||
{
|
||||
return _TractorsStorage[ind];
|
||||
}
|
||||
var info = new TractorsCollectionInfo(ind, "");
|
||||
if (_TractorsStorage.ContainsKey(info)) return _TractorsStorage[info];
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public bool SaveData(string filename)
|
||||
{
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
File.Delete(filename);
|
||||
}
|
||||
StringBuilder data = new();
|
||||
foreach (KeyValuePair<TractorsCollectionInfo, TractorGenericCollection<DrawingTractor, DrawingObjectTractor>> record in _TractorsStorage)
|
||||
{
|
||||
StringBuilder records = new();
|
||||
foreach (DrawingTractor? elem in record.Value.GetTractors)
|
||||
{
|
||||
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
|
||||
}
|
||||
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}");
|
||||
}
|
||||
if (data.Length == 0)
|
||||
{
|
||||
throw new InvalidOperationException("Невалиданя операция, нет данных для сохранения");
|
||||
}
|
||||
using StreamWriter sw = new(filename);
|
||||
sw.Write($"TractorsStorage{Environment.NewLine}{data}");
|
||||
return true;
|
||||
}
|
||||
public bool LoadData(string filename)
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
throw new FileNotFoundException("Файл не найден");
|
||||
}
|
||||
using (StreamReader sr = File.OpenText(filename))
|
||||
{
|
||||
string str = sr.ReadLine();
|
||||
if (str == null || str.Length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!str.StartsWith("TractorsStorage"))
|
||||
{
|
||||
throw new FormatException("Неверный формат данных");
|
||||
}
|
||||
|
||||
_TractorsStorage.Clear();
|
||||
string strs = "";
|
||||
|
||||
while ((strs = sr.ReadLine()) != null)
|
||||
{
|
||||
if (strs == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (record.Length != 2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
TractorGenericCollection<DrawingTractor, DrawingObjectTractor> collection =
|
||||
new(_pictureWidth, _pictureHeight);
|
||||
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string elem in set)
|
||||
{
|
||||
DrawingTractor? tractor = elem?.CreateDrawingTractor(_separatorForObject,
|
||||
_pictureWidth, _pictureHeight);
|
||||
if (tractor != null)
|
||||
{
|
||||
if ((collection + tractor)==-1)
|
||||
{
|
||||
throw new ApplicationException("Ошибка добавления в коллекцию");
|
||||
}
|
||||
}
|
||||
}
|
||||
_TractorsStorage.Add(new TractorsCollectionInfo(record[0], string.Empty), collection);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
29
ProjectBulldozer/Generics/TractorsCollectionInfo.cs
Normal file
29
ProjectBulldozer/Generics/TractorsCollectionInfo.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
namespace ProjectBulldozer.Generics
|
||||
{
|
||||
internal class TractorsCollectionInfo : IEquatable<TractorsCollectionInfo>
|
||||
{
|
||||
public string Name { get; private set; }
|
||||
|
||||
public string Description { get; private set; }
|
||||
|
||||
public TractorsCollectionInfo(string name, string description)
|
||||
{
|
||||
Name = name;
|
||||
Description = description;
|
||||
}
|
||||
|
||||
public bool Equals(TractorsCollectionInfo? other)
|
||||
{
|
||||
return Name == other.Name;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Name.GetHashCode();
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,40 @@
|
||||
using ProjectBulldozer;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Serilog;
|
||||
namespace Bulldozer
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
private static Serilog.ILogger? logger;
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
https://aka.ms/applicationconfiguration.
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormTractorCollections());
|
||||
var services = new ServiceCollection();
|
||||
ConfigureServices(services);
|
||||
using (ServiceProvider serviceProvider = services.BuildServiceProvider())
|
||||
{
|
||||
Application.Run(serviceProvider.GetRequiredService<FormTractorCollections>());
|
||||
}
|
||||
}
|
||||
private static void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<FormTractorCollections>().AddLogging(option =>
|
||||
{
|
||||
string[] path = Directory.GetCurrentDirectory().Split('\\');
|
||||
string appPath = "";
|
||||
for (int i = 0; i < path.Length - 3; i++)
|
||||
{
|
||||
appPath += path[i] + "\\";
|
||||
}
|
||||
var configuration = new ConfigurationBuilder().AddJsonFile($"{appPath}appsettings.json").Build();
|
||||
var logger = new LoggerConfiguration().ReadFrom.Configuration(configuration).CreateLogger();
|
||||
option.SetMinimumLevel(LogLevel.Information);
|
||||
option.AddSerilog(logger);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,20 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
|
||||
<PackageReference Include="NLog" Version="5.2.7" />
|
||||
<PackageReference Include="NLog.Config" Version="4.7.15" />
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.7" />
|
||||
<PackageReference Include="NLog.Schema" Version="5.2.7" />
|
||||
<PackageReference Include="NLog.Web.AspNetCore" Version="5.3.7" />
|
||||
<PackageReference Include="Serilog.Extensions.Logging.File" Version="3.0.0" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
|
||||
20
ProjectBulldozer/appsettings.json
Normal file
20
ProjectBulldozer/appsettings.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"Serilog": {
|
||||
"Using": [ "Serilog.Sinks.File" ],
|
||||
"MinimumLevel": "Information",
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "logs/bulldozerlog-.log",
|
||||
"rollingInterval": "Day",
|
||||
"outputTemplate": "[{Timestamp:HH:mm:ss.fff}]{Level:u4}: {Message:lj}{NewLine}{Exception}"
|
||||
}
|
||||
}
|
||||
],
|
||||
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
|
||||
"Properties": {
|
||||
"Application": "Bulldozer"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user