Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| caf208b305 | |||
| ec986c5a2c | |||
| 825ad3cdf5 | |||
| fce83f96d5 |
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) { }
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace ProjectBulldozer
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ProjectBulldozer
|
||||
{
|
||||
partial class FormTractorCollections
|
||||
{
|
||||
@@ -23,7 +25,9 @@
|
||||
сохранитьToolStripMenuItem = new ToolStripMenuItem();
|
||||
загрузитьToolStripMenuItem = new ToolStripMenuItem();
|
||||
toolStripMenuItem1 = new ToolStripMenuItem();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollections).BeginInit();
|
||||
ButtonSortByType = new Button();
|
||||
ButtonSortByColor = new Button();
|
||||
((ISupportInitialize)pictureBoxCollections).BeginInit();
|
||||
groupBox1.SuspendLayout();
|
||||
Instruments.SuspendLayout();
|
||||
menuStrip1.SuspendLayout();
|
||||
@@ -32,17 +36,17 @@
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
maskedTextBoxNumber.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
maskedTextBoxNumber.Location = new Point(33, 356);
|
||||
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);
|
||||
@@ -54,7 +58,7 @@
|
||||
// ButtonRemoveTractor
|
||||
//
|
||||
ButtonRemoveTractor.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
ButtonRemoveTractor.Location = new Point(33, 393);
|
||||
ButtonRemoveTractor.Location = new Point(35, 406);
|
||||
ButtonRemoveTractor.Margin = new Padding(3, 2, 3, 2);
|
||||
ButtonRemoveTractor.Name = "ButtonRemoveTractor";
|
||||
ButtonRemoveTractor.Size = new Size(131, 31);
|
||||
@@ -66,7 +70,7 @@
|
||||
// ButtonAddTractor
|
||||
//
|
||||
ButtonAddTractor.Anchor = AnchorStyles.Top;
|
||||
ButtonAddTractor.Location = new Point(33, 323);
|
||||
ButtonAddTractor.Location = new Point(35, 337);
|
||||
ButtonAddTractor.Margin = new Padding(3, 2, 3, 2);
|
||||
ButtonAddTractor.Name = "ButtonAddTractor";
|
||||
ButtonAddTractor.Size = new Size(131, 29);
|
||||
@@ -81,14 +85,14 @@
|
||||
pictureBoxCollections.Location = new Point(0, 26);
|
||||
pictureBoxCollections.Margin = new Padding(3, 2, 3, 2);
|
||||
pictureBoxCollections.Name = "pictureBoxCollections";
|
||||
pictureBoxCollections.Size = new Size(697, 404);
|
||||
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;
|
||||
@@ -101,7 +105,7 @@
|
||||
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 = "Наборы";
|
||||
@@ -110,7 +114,7 @@
|
||||
//
|
||||
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;
|
||||
@@ -119,7 +123,7 @@
|
||||
// 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);
|
||||
@@ -131,7 +135,7 @@
|
||||
// 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);
|
||||
@@ -142,14 +146,16 @@
|
||||
//
|
||||
// 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 = "Инструменты";
|
||||
@@ -205,11 +211,31 @@
|
||||
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, 439);
|
||||
ClientSize = new Size(904, 509);
|
||||
Controls.Add(Instruments);
|
||||
Controls.Add(pictureBoxCollections);
|
||||
Controls.Add(menuStrip1);
|
||||
@@ -217,7 +243,7 @@
|
||||
Margin = new Padding(3, 2, 3, 2);
|
||||
Name = "FormTractorCollections";
|
||||
Text = "Набор объектов";
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollections).EndInit();
|
||||
((ISupportInitialize)pictureBoxCollections).EndInit();
|
||||
groupBox1.ResumeLayout(false);
|
||||
groupBox1.PerformLayout();
|
||||
Instruments.ResumeLayout(false);
|
||||
@@ -227,6 +253,22 @@
|
||||
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();
|
||||
@@ -249,5 +291,7 @@
|
||||
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;
|
||||
private readonly TractorGenericCollection<DrawingTractor, DrawingObjectTractor> _tractors;
|
||||
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,13 +60,16 @@ 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)
|
||||
@@ -83,20 +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)
|
||||
@@ -111,15 +142,27 @@ namespace ProjectBulldozer
|
||||
{
|
||||
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)
|
||||
@@ -136,15 +179,16 @@ namespace ProjectBulldozer
|
||||
{
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_storage.SaveData(saveFileDialog.FileName))
|
||||
try
|
||||
{
|
||||
MessageBox.Show("Сохранение прошло успешно",
|
||||
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
_storage.SaveData(saveFileDialog.FileName);
|
||||
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
_logger.LogInformation("Сохранение");
|
||||
}
|
||||
else
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Не сохранилось", "Результат",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogWarning("Ошибка сохранения");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -152,21 +196,39 @@ namespace ProjectBulldozer
|
||||
{
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_storage.LoadData(openFileDialog.FileName))
|
||||
try
|
||||
{
|
||||
MessageBox.Show("Загрузка прошло успешно",
|
||||
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
_storage.LoadData(openFileDialog.FileName);
|
||||
ReloadObjects();
|
||||
MessageBox.Show("Загрузка произошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
_logger.LogInformation("Загрузка");
|
||||
}
|
||||
else
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Не загрузилось", "Результат",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogWarning("Ошибка загрузки");
|
||||
}
|
||||
ReloadObjects();
|
||||
}
|
||||
}
|
||||
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,8 +5,10 @@ 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;
|
||||
@@ -19,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)
|
||||
{
|
||||
@@ -36,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);
|
||||
@@ -51,7 +55,7 @@ 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);
|
||||
@@ -63,17 +67,21 @@ namespace ProjectBulldozer.Generics
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,38 +9,36 @@ namespace ProjectBulldozer.Generics
|
||||
private static readonly char _separatorForKeyValue = '|';
|
||||
private readonly char _separatorRecords = ';';
|
||||
private static readonly char _separatorForObject = ':';
|
||||
readonly Dictionary<string, TractorGenericCollection<DrawingTractor, DrawingObjectTractor>> _TractorsStorage;
|
||||
public List<string> Keys => _TractorsStorage.Keys.ToList();
|
||||
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]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_TractorsStorage.ContainsKey(ind))
|
||||
{
|
||||
return _TractorsStorage[ind];
|
||||
}
|
||||
var info = new TractorsCollectionInfo(ind, "");
|
||||
if (_TractorsStorage.ContainsKey(info)) return _TractorsStorage[info];
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -51,9 +49,7 @@ namespace ProjectBulldozer.Generics
|
||||
File.Delete(filename);
|
||||
}
|
||||
StringBuilder data = new();
|
||||
|
||||
foreach (KeyValuePair<string, TractorGenericCollection<DrawingTractor, DrawingObjectTractor>>
|
||||
record in _TractorsStorage)
|
||||
foreach (KeyValuePair<TractorsCollectionInfo, TractorGenericCollection<DrawingTractor, DrawingObjectTractor>> record in _TractorsStorage)
|
||||
{
|
||||
StringBuilder records = new();
|
||||
foreach (DrawingTractor? elem in record.Value.GetTractors)
|
||||
@@ -64,7 +60,7 @@ namespace ProjectBulldozer.Generics
|
||||
}
|
||||
if (data.Length == 0)
|
||||
{
|
||||
return false;
|
||||
throw new InvalidOperationException("Невалиданя операция, нет данных для сохранения");
|
||||
}
|
||||
using StreamWriter sw = new(filename);
|
||||
sw.Write($"TractorsStorage{Environment.NewLine}{data}");
|
||||
@@ -74,7 +70,7 @@ namespace ProjectBulldozer.Generics
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
return false;
|
||||
throw new FileNotFoundException("Файл не найден");
|
||||
}
|
||||
using (StreamReader sr = File.OpenText(filename))
|
||||
{
|
||||
@@ -85,7 +81,7 @@ namespace ProjectBulldozer.Generics
|
||||
}
|
||||
if (!str.StartsWith("TractorsStorage"))
|
||||
{
|
||||
return false;
|
||||
throw new FormatException("Неверный формат данных");
|
||||
}
|
||||
|
||||
_TractorsStorage.Clear();
|
||||
@@ -112,13 +108,13 @@ namespace ProjectBulldozer.Generics
|
||||
_pictureWidth, _pictureHeight);
|
||||
if (tractor != null)
|
||||
{
|
||||
if ((collection + tractor) == -1)
|
||||
if ((collection + tractor)==-1)
|
||||
{
|
||||
return false;
|
||||
throw new ApplicationException("Ошибка добавления в коллекцию");
|
||||
}
|
||||
}
|
||||
}
|
||||
_TractorsStorage.Add(record[0], collection);
|
||||
_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