This commit is contained in:
Дмитрий Блохин 2023-12-22 13:54:48 +04:00
parent 1778910e97
commit 8a8a1e270a
16 changed files with 278 additions and 249 deletions

View File

@ -19,43 +19,44 @@ namespace RPP.Generics
private readonly int _pictureHeight; private readonly int _pictureHeight;
private static readonly char _separatorForKeyValue = '|';
private readonly char _separatorRecords = ';';
private static readonly char _separatorForObject = ':';
public AirbusGenericStorage(int pictureWidth, int pictureHeight) public AirbusGenericStorage(int pictureWidth, int pictureHeight)
{ {
_airbusStorages = new Dictionary<string, _airbusStorages = new Dictionary<string, AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus>>();
AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus>>();
_pictureWidth = pictureWidth; _pictureWidth = pictureWidth;
_pictureHeight = pictureHeight; _pictureHeight = pictureHeight;
} }
public void AddSet(string name) public void AddSet(string name)
{ {
// TODO Прописать логику для добавления if (_airbusStorages.ContainsKey(name))
if (_airbusStorages.ContainsKey(name)) return; return;
_airbusStorages[name] = new AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus>(_pictureWidth, _pictureHeight); _airbusStorages[name] = new AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus>(_pictureWidth, _pictureHeight);
} }
public void DelSet(string name) public void DelSet(string name)
{ {
// TODO Прописать логику для удаления if (!_airbusStorages.ContainsKey(name))
if (!_airbusStorages.ContainsKey(name)) return; return;
_airbusStorages.Remove(name); _airbusStorages.Remove(name);
} }
public AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus>? public AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus>
this[string ind] this[string ind]
{ {
get get
{ {
// TODO Продумать логику получения набора if (_airbusStorages.ContainsKey(ind))
if(_airbusStorages.ContainsKey(ind)) return _airbusStorages[ind]; return _airbusStorages[ind];
return null; return null;
} }
} }
public bool SaveData(string filename)
private static readonly char _separatorForKeyValue = '|';
private readonly char _separatorRecords = ';';
private static readonly char _separatorForObject = ':';
public void SaveData(string filename)
{ {
if (File.Exists(filename)) if (File.Exists(filename))
{ {
File.Delete(filename); File.Delete(filename);
@ -73,37 +74,35 @@ namespace RPP.Generics
} }
if (data.Length == 0) if (data.Length == 0)
{ {
return false; throw new InvalidOperationException("Невалидная операция, нет данных для сохранения");
} }
using (StreamWriter writer = new StreamWriter(filename)) using (StreamWriter writer = new StreamWriter(filename))
{ {
writer.WriteLine("AirbusStorage"); writer.WriteLine("AirbusStorage");
writer.Write(data.ToString()); writer.Write(data.ToString());
return true;
} }
} }
public bool LoadData(string filename) public void LoadData(string filename)
{ {
if (!File.Exists(filename)) if (!File.Exists(filename))
{ throw new FileNotFoundException("Файл не найден");
return false;
}
using (StreamReader reader = new StreamReader(filename)) using (StreamReader reader = new StreamReader(filename))
{ {
string checker = reader.ReadLine(); string checker = reader.ReadLine();
if (checker == null) if (checker == null || checker.Length == 0)
return false; throw new Exception("Нет данных для загрузки");
if (!checker.StartsWith("AirbusStorage")) if (!checker.StartsWith("AirbusStorage"))
return false; throw new Exception("Неверный формат ввода");
_airbusStorages.Clear(); _airbusStorages.Clear();
string strs; string strs;
bool firstinit = true; bool firstinit = true;
while ((strs = reader.ReadLine()) != null) while ((strs = reader.ReadLine()) != null)
{ {
if (strs == null && firstinit) if (strs == null && firstinit)
return false; throw new Exception("Нет данных для загрузки");
if (strs == null) if (strs == null)
break; break;
firstinit = false; firstinit = false;
@ -111,21 +110,23 @@ namespace RPP.Generics
AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus> collection = new(_pictureWidth, _pictureHeight); AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus> collection = new(_pictureWidth, _pictureHeight);
foreach (string data in strs.Split('|')[1].Split(';')) foreach (string data in strs.Split('|')[1].Split(';'))
{ {
DrawningAirbus? car = DrawningAirbus? airbus =
data?.CreateDrawningAirbus(_separatorForObject, _pictureWidth, _pictureHeight); data?.CreateDrawningAirbus(_separatorForObject, _pictureWidth, _pictureHeight);
if (car != null) if (airbus != null)
{ {
if (!(collection + car)) try { _ = collection + airbus; }
catch (AirbusNotFoundException e)
{ {
return false; throw e;
}
catch (StorageOverflowException e)
{
throw e;
} }
} }
} }
_airbusStorages.Add(name, collection); _airbusStorages.Add(name, collection);
} }
return true;
} }
} }
} }

View File

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

View File

@ -51,7 +51,6 @@
pictureBoxAirbus.SizeMode = PictureBoxSizeMode.AutoSize; pictureBoxAirbus.SizeMode = PictureBoxSizeMode.AutoSize;
pictureBoxAirbus.TabIndex = 0; pictureBoxAirbus.TabIndex = 0;
pictureBoxAirbus.TabStop = false; pictureBoxAirbus.TabStop = false;
pictureBoxAirbus.Click += buttonMove_Click;
// //
// buttonCreateAirbus // buttonCreateAirbus
// //
@ -120,7 +119,6 @@
comboBoxStrategy.Name = "comboBoxStrategy"; comboBoxStrategy.Name = "comboBoxStrategy";
comboBoxStrategy.Size = new Size(121, 23); comboBoxStrategy.Size = new Size(121, 23);
comboBoxStrategy.TabIndex = 6; comboBoxStrategy.TabIndex = 6;
comboBoxStrategy.SelectedIndexChanged += comboBoxStrategy_SelectedIndexChanged;
// //
// buttonCreateFlyAirbus // buttonCreateFlyAirbus
// //
@ -169,7 +167,6 @@
Controls.Add(pictureBoxAirbus); Controls.Add(pictureBoxAirbus);
Name = "FormAirbus"; Name = "FormAirbus";
Text = "Airbus"; Text = "Airbus";
Load += FormAirbus_Load;
((System.ComponentModel.ISupportInitialize)pictureBoxAirbus).EndInit(); ((System.ComponentModel.ISupportInitialize)pictureBoxAirbus).EndInit();
ResumeLayout(false); ResumeLayout(false);
PerformLayout(); PerformLayout();

View File

@ -140,20 +140,5 @@ namespace RPP
SelectedAirbus = _drawningAirbus; SelectedAirbus = _drawningAirbus;
DialogResult = DialogResult.OK; DialogResult = DialogResult.OK;
} }
private void pictureBoxAirbus_Click(object sender, EventArgs e)
{
}
private void FormAirbus_Load(object sender, EventArgs e)
{
}
private void comboBoxStrategy_SelectedIndexChanged(object sender, EventArgs e)
{
}
} }
} }

View File

@ -62,12 +62,10 @@
panel1.Controls.Add(AddAirbusButton); panel1.Controls.Add(AddAirbusButton);
panel1.Controls.Add(menuStrip); panel1.Controls.Add(menuStrip);
panel1.Dock = DockStyle.Right; panel1.Dock = DockStyle.Right;
panel1.Location = new Point(682, 0); panel1.Location = new Point(597, 0);
panel1.Margin = new Padding(3, 4, 3, 4);
panel1.Name = "panel1"; panel1.Name = "panel1";
panel1.Size = new Size(232, 600); panel1.Size = new Size(203, 450);
panel1.TabIndex = 0; panel1.TabIndex = 0;
panel1.Paint += panel1_Paint;
// //
// panel2 // panel2
// //
@ -77,19 +75,16 @@
panel2.Controls.Add(textBoxStorageName); panel2.Controls.Add(textBoxStorageName);
panel2.Controls.Add(label2); panel2.Controls.Add(label2);
panel2.Controls.Add(label1); panel2.Controls.Add(label1);
panel2.Location = new Point(3, 36); panel2.Location = new Point(3, 27);
panel2.Margin = new Padding(3, 4, 3, 4);
panel2.Name = "panel2"; panel2.Name = "panel2";
panel2.Size = new Size(219, 292); panel2.Size = new Size(192, 219);
panel2.TabIndex = 5; panel2.TabIndex = 5;
panel2.Paint += panel2_Paint;
// //
// buttonDelObject // buttonDelObject
// //
buttonDelObject.Location = new Point(15, 240); buttonDelObject.Location = new Point(13, 180);
buttonDelObject.Margin = new Padding(3, 4, 3, 4);
buttonDelObject.Name = "buttonDelObject"; buttonDelObject.Name = "buttonDelObject";
buttonDelObject.Size = new Size(197, 48); buttonDelObject.Size = new Size(172, 36);
buttonDelObject.TabIndex = 4; buttonDelObject.TabIndex = 4;
buttonDelObject.Text = "Удалить набор"; buttonDelObject.Text = "Удалить набор";
buttonDelObject.UseVisualStyleBackColor = true; buttonDelObject.UseVisualStyleBackColor = true;
@ -98,20 +93,18 @@
// listBoxStorages // listBoxStorages
// //
listBoxStorages.FormattingEnabled = true; listBoxStorages.FormattingEnabled = true;
listBoxStorages.ItemHeight = 20; listBoxStorages.ItemHeight = 15;
listBoxStorages.Location = new Point(15, 127); listBoxStorages.Location = new Point(13, 95);
listBoxStorages.Margin = new Padding(3, 4, 3, 4);
listBoxStorages.Name = "listBoxStorages"; listBoxStorages.Name = "listBoxStorages";
listBoxStorages.Size = new Size(196, 104); listBoxStorages.Size = new Size(172, 79);
listBoxStorages.TabIndex = 3; listBoxStorages.TabIndex = 3;
listBoxStorages.SelectedIndexChanged += ListBoxObjects_SelectedIndexChanged; listBoxStorages.SelectedIndexChanged += ListBoxObjects_SelectedIndexChanged;
// //
// buttonAddObject // buttonAddObject
// //
buttonAddObject.Location = new Point(15, 64); buttonAddObject.Location = new Point(13, 48);
buttonAddObject.Margin = new Padding(3, 4, 3, 4);
buttonAddObject.Name = "buttonAddObject"; buttonAddObject.Name = "buttonAddObject";
buttonAddObject.Size = new Size(197, 55); buttonAddObject.Size = new Size(172, 41);
buttonAddObject.TabIndex = 2; buttonAddObject.TabIndex = 2;
buttonAddObject.Text = "Добавить набор"; buttonAddObject.Text = "Добавить набор";
buttonAddObject.UseVisualStyleBackColor = true; buttonAddObject.UseVisualStyleBackColor = true;
@ -119,36 +112,33 @@
// //
// textBoxStorageName // textBoxStorageName
// //
textBoxStorageName.Location = new Point(15, 25); textBoxStorageName.Location = new Point(13, 19);
textBoxStorageName.Margin = new Padding(3, 4, 3, 4);
textBoxStorageName.Name = "textBoxStorageName"; textBoxStorageName.Name = "textBoxStorageName";
textBoxStorageName.Size = new Size(196, 27); textBoxStorageName.Size = new Size(172, 23);
textBoxStorageName.TabIndex = 1; textBoxStorageName.TabIndex = 1;
// //
// label2 // label2
// //
label2.AutoSize = true; label2.AutoSize = true;
label2.Location = new Point(17, 0); label2.Location = new Point(15, 0);
label2.Name = "label2"; label2.Name = "label2";
label2.Size = new Size(66, 20); label2.Size = new Size(52, 15);
label2.TabIndex = 0; label2.TabIndex = 0;
label2.Text = "Наборы"; label2.Text = "Наборы";
label2.Click += label2_Click;
// //
// label1 // label1
// //
label1.AutoSize = true; label1.AutoSize = true;
label1.Location = new Point(117, 1); label1.Location = new Point(102, 1);
label1.Name = "label1"; label1.Name = "label1";
label1.Size = new Size(0, 20); label1.Size = new Size(0, 15);
label1.TabIndex = 0; label1.TabIndex = 0;
// //
// ButtonRefreshCollection // ButtonRefreshCollection
// //
ButtonRefreshCollection.Location = new Point(8, 531); ButtonRefreshCollection.Location = new Point(7, 398);
ButtonRefreshCollection.Margin = new Padding(3, 4, 3, 4);
ButtonRefreshCollection.Name = "ButtonRefreshCollection"; ButtonRefreshCollection.Name = "ButtonRefreshCollection";
ButtonRefreshCollection.Size = new Size(217, 53); ButtonRefreshCollection.Size = new Size(190, 40);
ButtonRefreshCollection.TabIndex = 4; ButtonRefreshCollection.TabIndex = 4;
ButtonRefreshCollection.Text = "Обновить коллекцию"; ButtonRefreshCollection.Text = "Обновить коллекцию";
ButtonRefreshCollection.UseVisualStyleBackColor = true; ButtonRefreshCollection.UseVisualStyleBackColor = true;
@ -156,10 +146,9 @@
// //
// ButtonRemoveAirbus // ButtonRemoveAirbus
// //
ButtonRemoveAirbus.Location = new Point(6, 436); ButtonRemoveAirbus.Location = new Point(5, 327);
ButtonRemoveAirbus.Margin = new Padding(3, 4, 3, 4);
ButtonRemoveAirbus.Name = "ButtonRemoveAirbus"; ButtonRemoveAirbus.Name = "ButtonRemoveAirbus";
ButtonRemoveAirbus.Size = new Size(217, 53); ButtonRemoveAirbus.Size = new Size(190, 40);
ButtonRemoveAirbus.TabIndex = 3; ButtonRemoveAirbus.TabIndex = 3;
ButtonRemoveAirbus.Text = "Удалить аэробус"; ButtonRemoveAirbus.Text = "Удалить аэробус";
ButtonRemoveAirbus.UseVisualStyleBackColor = true; ButtonRemoveAirbus.UseVisualStyleBackColor = true;
@ -167,18 +156,16 @@
// //
// maskedTextBoxNumber // maskedTextBoxNumber
// //
maskedTextBoxNumber.Location = new Point(46, 397); maskedTextBoxNumber.Location = new Point(40, 298);
maskedTextBoxNumber.Margin = new Padding(3, 4, 3, 4);
maskedTextBoxNumber.Name = "maskedTextBoxNumber"; maskedTextBoxNumber.Name = "maskedTextBoxNumber";
maskedTextBoxNumber.Size = new Size(111, 27); maskedTextBoxNumber.Size = new Size(98, 23);
maskedTextBoxNumber.TabIndex = 2; maskedTextBoxNumber.TabIndex = 2;
// //
// AddAirbusButton // AddAirbusButton
// //
AddAirbusButton.Location = new Point(6, 336); AddAirbusButton.Location = new Point(5, 252);
AddAirbusButton.Margin = new Padding(3, 4, 3, 4);
AddAirbusButton.Name = "AddAirbusButton"; AddAirbusButton.Name = "AddAirbusButton";
AddAirbusButton.Size = new Size(217, 53); AddAirbusButton.Size = new Size(190, 40);
AddAirbusButton.TabIndex = 1; AddAirbusButton.TabIndex = 1;
AddAirbusButton.Text = "Добавить аэробус"; AddAirbusButton.Text = "Добавить аэробус";
AddAirbusButton.UseVisualStyleBackColor = true; AddAirbusButton.UseVisualStyleBackColor = true;
@ -190,8 +177,7 @@
menuStrip.Items.AddRange(new ToolStripItem[] { menuToolStripMenuItem }); menuStrip.Items.AddRange(new ToolStripItem[] { menuToolStripMenuItem });
menuStrip.Location = new Point(0, 0); menuStrip.Location = new Point(0, 0);
menuStrip.Name = "menuStrip"; menuStrip.Name = "menuStrip";
menuStrip.Padding = new Padding(7, 3, 0, 3); menuStrip.Size = new Size(203, 24);
menuStrip.Size = new Size(232, 30);
menuStrip.TabIndex = 6; menuStrip.TabIndex = 6;
menuStrip.Text = "menuStrip1"; menuStrip.Text = "menuStrip1";
// //
@ -199,20 +185,20 @@
// //
menuToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { SaveToolStripMenuItem, LoadToolStripMenuItem }); menuToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { SaveToolStripMenuItem, LoadToolStripMenuItem });
menuToolStripMenuItem.Name = "menuToolStripMenuItem"; menuToolStripMenuItem.Name = "menuToolStripMenuItem";
menuToolStripMenuItem.Size = new Size(65, 24); menuToolStripMenuItem.Size = new Size(53, 20);
menuToolStripMenuItem.Text = "Меню"; menuToolStripMenuItem.Text = "Меню";
// //
// SaveToolStripMenuItem // SaveToolStripMenuItem
// //
SaveToolStripMenuItem.Name = "SaveToolStripMenuItem"; SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
SaveToolStripMenuItem.Size = new Size(224, 26); SaveToolStripMenuItem.Size = new Size(133, 22);
SaveToolStripMenuItem.Text = "Сохранить"; SaveToolStripMenuItem.Text = "Сохранить";
SaveToolStripMenuItem.Click += SaveToolStripMenuItem_Click; SaveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
// //
// LoadToolStripMenuItem // LoadToolStripMenuItem
// //
LoadToolStripMenuItem.Name = "LoadToolStripMenuItem"; LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
LoadToolStripMenuItem.Size = new Size(224, 26); LoadToolStripMenuItem.Size = new Size(133, 22);
LoadToolStripMenuItem.Text = "Загрузить"; LoadToolStripMenuItem.Text = "Загрузить";
LoadToolStripMenuItem.Click += LoadToolStripMenuItem_Click; LoadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
// //
@ -220,9 +206,8 @@
// //
pictureBoxCollection.Dock = DockStyle.Fill; pictureBoxCollection.Dock = DockStyle.Fill;
pictureBoxCollection.Location = new Point(0, 0); pictureBoxCollection.Location = new Point(0, 0);
pictureBoxCollection.Margin = new Padding(3, 4, 3, 4);
pictureBoxCollection.Name = "pictureBoxCollection"; pictureBoxCollection.Name = "pictureBoxCollection";
pictureBoxCollection.Size = new Size(682, 600); pictureBoxCollection.Size = new Size(597, 450);
pictureBoxCollection.TabIndex = 1; pictureBoxCollection.TabIndex = 1;
pictureBoxCollection.TabStop = false; pictureBoxCollection.TabStop = false;
// //
@ -236,13 +221,12 @@
// //
// FormAirbusCollection // FormAirbusCollection
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(914, 600); ClientSize = new Size(800, 450);
Controls.Add(pictureBoxCollection); Controls.Add(pictureBoxCollection);
Controls.Add(panel1); Controls.Add(panel1);
MainMenuStrip = menuStrip; MainMenuStrip = menuStrip;
Margin = new Padding(3, 4, 3, 4);
Name = "FormAirbusCollection"; Name = "FormAirbusCollection";
Text = "FormFlyAirbus"; Text = "FormFlyAirbus";
Load += FormFlyAirbus_Load; Load += FormFlyAirbus_Load;

View File

@ -1,19 +1,18 @@
using RPP.DrawningObjects; using RPP.DrawningObjects;
using RPP.Generics; using RPP.Generics;
using System.Windows.Forms; using Microsoft.Extensions.Logging;
namespace RPP namespace RPP
{ {
public partial class FormAirbusCollection : Form public partial class FormAirbusCollection : Form
{ {
private readonly AirbusGenericStorage _storage; private readonly AirbusGenericStorage _storage;
private readonly ILogger _logger;
public FormAirbusCollection() public FormAirbusCollection(ILogger<FormAirbusCollection> logger)
{ {
InitializeComponent(); InitializeComponent();
_storage = new AirbusGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height); _storage = new AirbusGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
_logger = logger;
} }
private void FormFlyAirbus_Load(object sender, EventArgs e) private void FormFlyAirbus_Load(object sender, EventArgs e)
@ -29,16 +28,20 @@ namespace RPP
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
if (obj == null) if (obj == null)
{ {
_logger.LogWarning("Добавление пустого объекта");
return; return;
} }
if (obj + Airbus) try
{ {
_ = obj + Airbus;
MessageBox.Show("Объект добавлен"); MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = obj.ShowCars(); pictureBoxCollection.Image = obj.ShowCars();
_logger.LogInformation($"Добавлен объект в набор {listBoxStorages.SelectedItem.ToString()}");
} }
else catch (Exception ex)
{ {
MessageBox.Show("Не удалось добавить объект"); MessageBox.Show("Не удалось добавить объект");
_logger.LogWarning($"{ex.Message} в наборе {listBoxStorages.SelectedItem.ToString()}");
} }
} }
@ -83,10 +86,12 @@ namespace RPP
{ {
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBox.Show("Не все данные заполнены", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogWarning("Пустое название набора");
return; return;
} }
_storage.AddSet(textBoxStorageName.Text); _storage.AddSet(textBoxStorageName.Text);
ReloadObjects(); ReloadObjects();
_logger.LogInformation($"Добавлен набор: {textBoxStorageName.Text}");
} }
private void ListBoxObjects_SelectedIndexChanged(object sender, EventArgs e) private void ListBoxObjects_SelectedIndexChanged(object sender, EventArgs e)
{ {
@ -97,12 +102,15 @@ namespace RPP
{ {
if (listBoxStorages.SelectedIndex == -1) if (listBoxStorages.SelectedIndex == -1)
{ {
_logger.LogWarning("Удаление невыбранного набора");
return; return;
} }
if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) string name = listBoxStorages.SelectedItem.ToString() ?? string.Empty;
if (MessageBox.Show($"Удалить объект {name}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{ {
_storage.DelSet(listBoxStorages.SelectedItem.ToString() ?? string.Empty); _storage.DelSet(listBoxStorages.SelectedItem.ToString() ?? string.Empty);
ReloadObjects(); ReloadObjects();
_logger.LogInformation($"Удален набор: {name}");
} }
} }
@ -110,6 +118,7 @@ namespace RPP
{ {
if (listBoxStorages.SelectedIndex == -1) if (listBoxStorages.SelectedIndex == -1)
{ {
_logger.LogWarning("Удаление объекта из несуществующего набора");
return; return;
} }
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
@ -122,14 +131,24 @@ namespace RPP
return; return;
} }
int pos = Convert.ToInt32(maskedTextBoxNumber.Text); int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
if (obj - pos != null) try
{ {
MessageBox.Show("Объект удален"); if (obj - pos != null)
pictureBoxCollection.Image = obj.ShowCars(); {
MessageBox.Show("Объект удален");
pictureBoxCollection.Image = obj.ShowCars();
_logger.LogInformation($"Удален объект из набора {listBoxStorages.SelectedItem.ToString()}");
}
else
{
MessageBox.Show("Не удалось удалить объект");
_logger.LogWarning($"Не удалось удалить объект из набора {listBoxStorages.SelectedItem.ToString()}");
}
} }
else catch (AirbusNotFoundException ex)
{ {
MessageBox.Show("Не удалось удалить объект"); MessageBox.Show(ex.Message);
_logger.LogWarning($"{ex.Message} из набора {listBoxStorages.SelectedItem.ToString()}");
} }
} }
@ -150,13 +169,16 @@ namespace RPP
{ {
if (saveFileDialog.ShowDialog() == DialogResult.OK) if (saveFileDialog.ShowDialog() == DialogResult.OK)
{ {
if (_storage.SaveData(saveFileDialog.FileName)) try
{ {
_storage.SaveData(saveFileDialog.FileName);
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
_logger.LogInformation($"Сохранение наборов в файл {saveFileDialog.FileName}");
} }
else catch (Exception ex)
{ {
MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogWarning($"Не удалось сохранить наборы с ошибкой: {ex.Message}");
} }
} }
} }
@ -165,31 +187,19 @@ namespace RPP
if (openFileDialog.ShowDialog() == DialogResult.OK) if (openFileDialog.ShowDialog() == DialogResult.OK)
{ {
if (_storage.LoadData(openFileDialog.FileName)) try
{ {
_storage.LoadData(openFileDialog.FileName);
ReloadObjects(); ReloadObjects();
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
_logger.LogInformation($"Загрузились наборы из файла {openFileDialog.FileName}");
} }
else catch (Exception ex)
{ {
MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogWarning($"Не удалось сохранить наборы с ошибкой: {ex.Message}");
} }
} }
} }
private void panel2_Paint(object sender, PaintEventArgs e)
{
}
private void label2_Click(object sender, EventArgs e)
{
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
} }
} }

View File

@ -18,7 +18,7 @@
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, 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="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" 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"> <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value> <value>[base64 mime encoded serialized .NET Framework object]</value>
</data> </data>

View File

@ -71,11 +71,9 @@
groupBoxParameters.Controls.Add(label2); groupBoxParameters.Controls.Add(label2);
groupBoxParameters.Controls.Add(numericUpDownSpeed); groupBoxParameters.Controls.Add(numericUpDownSpeed);
groupBoxParameters.Controls.Add(label1); groupBoxParameters.Controls.Add(label1);
groupBoxParameters.Location = new Point(14, 16); groupBoxParameters.Location = new Point(12, 12);
groupBoxParameters.Margin = new Padding(3, 4, 3, 4);
groupBoxParameters.Name = "groupBoxParameters"; groupBoxParameters.Name = "groupBoxParameters";
groupBoxParameters.Padding = new Padding(3, 4, 3, 4); groupBoxParameters.Size = new Size(549, 276);
groupBoxParameters.Size = new Size(627, 368);
groupBoxParameters.TabIndex = 0; groupBoxParameters.TabIndex = 0;
groupBoxParameters.TabStop = false; groupBoxParameters.TabStop = false;
groupBoxParameters.Text = "Параметры"; groupBoxParameters.Text = "Параметры";
@ -83,9 +81,9 @@
// labelFly // labelFly
// //
labelFly.BorderStyle = BorderStyle.FixedSingle; labelFly.BorderStyle = BorderStyle.FixedSingle;
labelFly.Location = new Point(446, 292); labelFly.Location = new Point(390, 219);
labelFly.Name = "labelFly"; labelFly.Name = "labelFly";
labelFly.Size = new Size(135, 47); labelFly.Size = new Size(118, 36);
labelFly.TabIndex = 8; labelFly.TabIndex = 8;
labelFly.Text = "Продвинутый"; labelFly.Text = "Продвинутый";
labelFly.TextAlign = ContentAlignment.MiddleCenter; labelFly.TextAlign = ContentAlignment.MiddleCenter;
@ -94,9 +92,9 @@
// labelBase // labelBase
// //
labelBase.BorderStyle = BorderStyle.FixedSingle; labelBase.BorderStyle = BorderStyle.FixedSingle;
labelBase.Location = new Point(291, 292); labelBase.Location = new Point(255, 219);
labelBase.Name = "labelBase"; labelBase.Name = "labelBase";
labelBase.Size = new Size(129, 47); labelBase.Size = new Size(113, 36);
labelBase.TabIndex = 7; labelBase.TabIndex = 7;
labelBase.Text = "Простой"; labelBase.Text = "Простой";
labelBase.TextAlign = ContentAlignment.MiddleCenter; labelBase.TextAlign = ContentAlignment.MiddleCenter;
@ -112,11 +110,9 @@
groupBoxColor.Controls.Add(panelBlue); groupBoxColor.Controls.Add(panelBlue);
groupBoxColor.Controls.Add(panelGreen); groupBoxColor.Controls.Add(panelGreen);
groupBoxColor.Controls.Add(panelRed); groupBoxColor.Controls.Add(panelRed);
groupBoxColor.Location = new Point(272, 40); groupBoxColor.Location = new Point(238, 30);
groupBoxColor.Margin = new Padding(3, 4, 3, 4);
groupBoxColor.Name = "groupBoxColor"; groupBoxColor.Name = "groupBoxColor";
groupBoxColor.Padding = new Padding(3, 4, 3, 4); groupBoxColor.Size = new Size(286, 167);
groupBoxColor.Size = new Size(327, 223);
groupBoxColor.TabIndex = 6; groupBoxColor.TabIndex = 6;
groupBoxColor.TabStop = false; groupBoxColor.TabStop = false;
groupBoxColor.Text = "Цвета"; groupBoxColor.Text = "Цвета";
@ -124,82 +120,73 @@
// panelPurple // panelPurple
// //
panelPurple.BackColor = Color.Purple; panelPurple.BackColor = Color.Purple;
panelPurple.Location = new Point(255, 129); panelPurple.Location = new Point(223, 97);
panelPurple.Margin = new Padding(3, 4, 3, 4);
panelPurple.Name = "panelPurple"; panelPurple.Name = "panelPurple";
panelPurple.Size = new Size(54, 59); panelPurple.Size = new Size(47, 44);
panelPurple.TabIndex = 7; panelPurple.TabIndex = 7;
// //
// panelBlack // panelBlack
// //
panelBlack.BackColor = Color.Black; panelBlack.BackColor = Color.Black;
panelBlack.Location = new Point(174, 129); panelBlack.Location = new Point(152, 97);
panelBlack.Margin = new Padding(3, 4, 3, 4);
panelBlack.Name = "panelBlack"; panelBlack.Name = "panelBlack";
panelBlack.Size = new Size(54, 59); panelBlack.Size = new Size(47, 44);
panelBlack.TabIndex = 6; panelBlack.TabIndex = 6;
// //
// panelGray // panelGray
// //
panelGray.BackColor = Color.Gray; panelGray.BackColor = Color.Gray;
panelGray.Location = new Point(95, 129); panelGray.Location = new Point(83, 97);
panelGray.Margin = new Padding(3, 4, 3, 4);
panelGray.Name = "panelGray"; panelGray.Name = "panelGray";
panelGray.Size = new Size(54, 59); panelGray.Size = new Size(47, 44);
panelGray.TabIndex = 5; panelGray.TabIndex = 5;
// //
// panelWhite // panelWhite
// //
panelWhite.BackColor = Color.White; panelWhite.BackColor = Color.White;
panelWhite.Location = new Point(19, 129); panelWhite.Location = new Point(17, 97);
panelWhite.Margin = new Padding(3, 4, 3, 4);
panelWhite.Name = "panelWhite"; panelWhite.Name = "panelWhite";
panelWhite.Size = new Size(54, 59); panelWhite.Size = new Size(47, 44);
panelWhite.TabIndex = 4; panelWhite.TabIndex = 4;
// //
// panelYellow // panelYellow
// //
panelYellow.BackColor = Color.Yellow; panelYellow.BackColor = Color.Yellow;
panelYellow.Location = new Point(255, 43); panelYellow.Location = new Point(223, 32);
panelYellow.Margin = new Padding(3, 4, 3, 4);
panelYellow.Name = "panelYellow"; panelYellow.Name = "panelYellow";
panelYellow.Size = new Size(54, 60); panelYellow.Size = new Size(47, 45);
panelYellow.TabIndex = 3; panelYellow.TabIndex = 3;
// //
// panelBlue // panelBlue
// //
panelBlue.BackColor = Color.Blue; panelBlue.BackColor = Color.Blue;
panelBlue.Location = new Point(174, 43); panelBlue.Location = new Point(152, 32);
panelBlue.Margin = new Padding(3, 4, 3, 4);
panelBlue.Name = "panelBlue"; panelBlue.Name = "panelBlue";
panelBlue.Size = new Size(54, 60); panelBlue.Size = new Size(47, 45);
panelBlue.TabIndex = 2; panelBlue.TabIndex = 2;
// //
// panelGreen // panelGreen
// //
panelGreen.BackColor = Color.Green; panelGreen.BackColor = Color.Green;
panelGreen.Location = new Point(95, 43); panelGreen.Location = new Point(83, 32);
panelGreen.Margin = new Padding(3, 4, 3, 4);
panelGreen.Name = "panelGreen"; panelGreen.Name = "panelGreen";
panelGreen.Size = new Size(54, 60); panelGreen.Size = new Size(47, 45);
panelGreen.TabIndex = 1; panelGreen.TabIndex = 1;
// //
// panelRed // panelRed
// //
panelRed.BackColor = Color.Red; panelRed.BackColor = Color.Red;
panelRed.Location = new Point(19, 43); panelRed.Location = new Point(17, 32);
panelRed.Margin = new Padding(3, 4, 3, 4);
panelRed.Name = "panelRed"; panelRed.Name = "panelRed";
panelRed.Size = new Size(54, 59); panelRed.Size = new Size(47, 44);
panelRed.TabIndex = 0; panelRed.TabIndex = 0;
// //
// checkBoxEngine // checkBoxEngine
// //
checkBoxEngine.AutoSize = true; checkBoxEngine.AutoSize = true;
checkBoxEngine.Location = new Point(17, 264); checkBoxEngine.Location = new Point(15, 198);
checkBoxEngine.Margin = new Padding(3, 4, 3, 4);
checkBoxEngine.Name = "checkBoxEngine"; checkBoxEngine.Name = "checkBoxEngine";
checkBoxEngine.Size = new Size(269, 24); checkBoxEngine.Size = new Size(213, 19);
checkBoxEngine.TabIndex = 5; checkBoxEngine.TabIndex = 5;
checkBoxEngine.Text = "Признак наличия доп. двигателей"; checkBoxEngine.Text = "Признак наличия доп. двигателей";
checkBoxEngine.UseVisualStyleBackColor = true; checkBoxEngine.UseVisualStyleBackColor = true;
@ -207,51 +194,48 @@
// checkBoxCompartment // checkBoxCompartment
// //
checkBoxCompartment.AutoSize = true; checkBoxCompartment.AutoSize = true;
checkBoxCompartment.Location = new Point(17, 203); checkBoxCompartment.Location = new Point(15, 152);
checkBoxCompartment.Margin = new Padding(3, 4, 3, 4);
checkBoxCompartment.Name = "checkBoxCompartment"; checkBoxCompartment.Name = "checkBoxCompartment";
checkBoxCompartment.Size = new Size(236, 24); checkBoxCompartment.Size = new Size(188, 19);
checkBoxCompartment.TabIndex = 4; checkBoxCompartment.TabIndex = 4;
checkBoxCompartment.Text = "Признак наличия доп. отсека"; checkBoxCompartment.Text = "Признак наличия доп. отсека";
checkBoxCompartment.UseVisualStyleBackColor = true; checkBoxCompartment.UseVisualStyleBackColor = true;
// //
// numericUpDownWeight // numericUpDownWeight
// //
numericUpDownWeight.Location = new Point(95, 89); numericUpDownWeight.Location = new Point(83, 67);
numericUpDownWeight.Margin = new Padding(3, 4, 3, 4);
numericUpDownWeight.Maximum = new decimal(new int[] { 1000, 0, 0, 0 }); numericUpDownWeight.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
numericUpDownWeight.Minimum = new decimal(new int[] { 100, 0, 0, 0 }); numericUpDownWeight.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
numericUpDownWeight.Name = "numericUpDownWeight"; numericUpDownWeight.Name = "numericUpDownWeight";
numericUpDownWeight.Size = new Size(79, 27); numericUpDownWeight.Size = new Size(69, 23);
numericUpDownWeight.TabIndex = 3; numericUpDownWeight.TabIndex = 3;
numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 }); numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 });
// //
// label2 // label2
// //
label2.AutoSize = true; label2.AutoSize = true;
label2.Location = new Point(17, 89); label2.Location = new Point(15, 67);
label2.Name = "label2"; label2.Name = "label2";
label2.Size = new Size(36, 20); label2.Size = new Size(29, 15);
label2.TabIndex = 2; label2.TabIndex = 2;
label2.Text = "Вес:"; label2.Text = "Вес:";
// //
// numericUpDownSpeed // numericUpDownSpeed
// //
numericUpDownSpeed.Location = new Point(95, 36); numericUpDownSpeed.Location = new Point(83, 27);
numericUpDownSpeed.Margin = new Padding(3, 4, 3, 4);
numericUpDownSpeed.Maximum = new decimal(new int[] { 1000, 0, 0, 0 }); numericUpDownSpeed.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
numericUpDownSpeed.Minimum = new decimal(new int[] { 100, 0, 0, 0 }); numericUpDownSpeed.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
numericUpDownSpeed.Name = "numericUpDownSpeed"; numericUpDownSpeed.Name = "numericUpDownSpeed";
numericUpDownSpeed.Size = new Size(79, 27); numericUpDownSpeed.Size = new Size(69, 23);
numericUpDownSpeed.TabIndex = 1; numericUpDownSpeed.TabIndex = 1;
numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 }); numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 });
// //
// label1 // label1
// //
label1.AutoSize = true; label1.AutoSize = true;
label1.Location = new Point(17, 39); label1.Location = new Point(15, 29);
label1.Name = "label1"; label1.Name = "label1";
label1.Size = new Size(76, 20); label1.Size = new Size(62, 15);
label1.TabIndex = 0; label1.TabIndex = 0;
label1.Text = "Скорость:"; label1.Text = "Скорость:";
// //
@ -259,20 +243,18 @@
// //
panel9.AllowDrop = true; panel9.AllowDrop = true;
panel9.Controls.Add(pictureBoxObject); panel9.Controls.Add(pictureBoxObject);
panel9.Location = new Point(675, 87); panel9.Location = new Point(591, 65);
panel9.Margin = new Padding(3, 4, 3, 4);
panel9.Name = "panel9"; panel9.Name = "panel9";
panel9.Size = new Size(354, 244); panel9.Size = new Size(310, 183);
panel9.TabIndex = 1; panel9.TabIndex = 1;
panel9.DragDrop += PanelObject_DragDrop; panel9.DragDrop += PanelObject_DragDrop;
panel9.DragEnter += PanelObject_DragEnter; panel9.DragEnter += PanelObject_DragEnter;
// //
// pictureBoxObject // pictureBoxObject
// //
pictureBoxObject.Location = new Point(27, 4); pictureBoxObject.Location = new Point(24, 3);
pictureBoxObject.Margin = new Padding(3, 4, 3, 4);
pictureBoxObject.Name = "pictureBoxObject"; pictureBoxObject.Name = "pictureBoxObject";
pictureBoxObject.Size = new Size(323, 236); pictureBoxObject.Size = new Size(283, 177);
pictureBoxObject.TabIndex = 2; pictureBoxObject.TabIndex = 2;
pictureBoxObject.TabStop = false; pictureBoxObject.TabStop = false;
// //
@ -280,9 +262,9 @@
// //
labelAdditionalColor.AllowDrop = true; labelAdditionalColor.AllowDrop = true;
labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle; labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle;
labelAdditionalColor.Location = new Point(870, 35); labelAdditionalColor.Location = new Point(761, 26);
labelAdditionalColor.Name = "labelAdditionalColor"; labelAdditionalColor.Name = "labelAdditionalColor";
labelAdditionalColor.Size = new Size(133, 47); labelAdditionalColor.Size = new Size(117, 36);
labelAdditionalColor.TabIndex = 1; labelAdditionalColor.TabIndex = 1;
labelAdditionalColor.Text = "Доп. цвет"; labelAdditionalColor.Text = "Доп. цвет";
labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter; labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter;
@ -293,9 +275,9 @@
// //
labelColor.AllowDrop = true; labelColor.AllowDrop = true;
labelColor.BorderStyle = BorderStyle.FixedSingle; labelColor.BorderStyle = BorderStyle.FixedSingle;
labelColor.Location = new Point(703, 35); labelColor.Location = new Point(615, 26);
labelColor.Name = "labelColor"; labelColor.Name = "labelColor";
labelColor.Size = new Size(133, 47); labelColor.Size = new Size(117, 36);
labelColor.TabIndex = 0; labelColor.TabIndex = 0;
labelColor.Text = "Цвет"; labelColor.Text = "Цвет";
labelColor.TextAlign = ContentAlignment.MiddleCenter; labelColor.TextAlign = ContentAlignment.MiddleCenter;
@ -304,10 +286,9 @@
// //
// buttonAdd // buttonAdd
// //
buttonAdd.Location = new Point(703, 339); buttonAdd.Location = new Point(615, 254);
buttonAdd.Margin = new Padding(3, 4, 3, 4);
buttonAdd.Name = "buttonAdd"; buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(134, 45); buttonAdd.Size = new Size(117, 34);
buttonAdd.TabIndex = 2; buttonAdd.TabIndex = 2;
buttonAdd.Text = "Добавить"; buttonAdd.Text = "Добавить";
buttonAdd.UseVisualStyleBackColor = true; buttonAdd.UseVisualStyleBackColor = true;
@ -315,26 +296,24 @@
// //
// buttonCancel // buttonCancel
// //
buttonCancel.Location = new Point(870, 339); buttonCancel.Location = new Point(761, 254);
buttonCancel.Margin = new Padding(3, 4, 3, 4);
buttonCancel.Name = "buttonCancel"; buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(134, 45); buttonCancel.Size = new Size(117, 34);
buttonCancel.TabIndex = 3; buttonCancel.TabIndex = 3;
buttonCancel.Text = "Отмена"; buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true; buttonCancel.UseVisualStyleBackColor = true;
// //
// FormAirbusConfig // FormAirbusConfig
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1057, 400); ClientSize = new Size(925, 300);
Controls.Add(buttonCancel); Controls.Add(buttonCancel);
Controls.Add(labelAdditionalColor); Controls.Add(labelAdditionalColor);
Controls.Add(labelColor); Controls.Add(labelColor);
Controls.Add(buttonAdd); Controls.Add(buttonAdd);
Controls.Add(panel9); Controls.Add(panel9);
Controls.Add(groupBoxParameters); Controls.Add(groupBoxParameters);
Margin = new Padding(3, 4, 3, 4);
Name = "FormAirbusConfig"; Name = "FormAirbusConfig";
Text = "FormAirbusConfig"; Text = "FormAirbusConfig";
Load += FormAirbusConfig_Load; Load += FormAirbusConfig_Load;

View File

@ -16,9 +16,7 @@ namespace RPP
public partial class FormAirbusConfig : Form public partial class FormAirbusConfig : Form
{ {
DrawningAirbus? _airbus = null; DrawningAirbus? _airbus = null;
/// <summary>
/// Событие
/// </summary>
private event Action<DrawningAirbus>? EventAddAirbus; private event Action<DrawningAirbus>? EventAddAirbus;
public FormAirbusConfig() public FormAirbusConfig()
@ -42,9 +40,6 @@ namespace RPP
} }
/// <summary>
/// Отрисовать машину
/// </summary>
private void DrawAirbus() private void DrawAirbus()
{ {
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
@ -56,21 +51,13 @@ namespace RPP
_airbus?.DrawTransport(gr); _airbus?.DrawTransport(gr);
pictureBoxObject.Image = bmp; pictureBoxObject.Image = bmp;
} }
/// <summary>
/// Передаем информацию при нажатии на Label
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LabelObject_MouseDown(object sender, MouseEventArgs e) private void LabelObject_MouseDown(object sender, MouseEventArgs e)
{ {
(sender as Label)?.DoDragDrop((sender as Label)?.Name, (sender as Label)?.DoDragDrop((sender as Label)?.Name,
DragDropEffects.Move | DragDropEffects.Copy); DragDropEffects.Move | DragDropEffects.Copy);
} }
/// <summary>
/// Проверка получаемой информации (ее типа на соответствие требуемому)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PanelObject_DragEnter(object sender, DragEventArgs e) private void PanelObject_DragEnter(object sender, DragEventArgs e)
{ {
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false) if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
@ -82,11 +69,7 @@ namespace RPP
e.Effect = DragDropEffects.None; e.Effect = DragDropEffects.None;
} }
} }
/// <summary>
/// Действия при приеме перетаскиваемой информации
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PanelObject_DragDrop(object sender, DragEventArgs e) private void PanelObject_DragDrop(object sender, DragEventArgs e)
{ {
switch (e.Data?.GetData(DataFormats.Text).ToString()) switch (e.Data?.GetData(DataFormats.Text).ToString())
@ -105,9 +88,6 @@ namespace RPP
} }
DrawAirbus(); DrawAirbus();
} }
/// Добавление события
/// </summary>
/// <param name="ev">Привязанный метод</param>
public void AddEvent(Action<DrawningAirbus> ev) public void AddEvent(Action<DrawningAirbus> ev)
{ {
if (EventAddAirbus == null) if (EventAddAirbus == null)
@ -119,11 +99,6 @@ namespace RPP
EventAddAirbus += ev; EventAddAirbus += ev;
} }
} }
/// <summary>
/// Добавление машины
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonOk_Click(object sender, EventArgs e) private void ButtonOk_Click(object sender, EventArgs e)
{ {
EventAddAirbus?.Invoke(_airbus); EventAddAirbus?.Invoke(_airbus);

View File

@ -18,7 +18,7 @@
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, 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="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" 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"> <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value> <value>[base64 mime encoded serialized .NET Framework object]</value>
</data> </data>

View File

@ -1,18 +1,42 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Serilog;
using System;
namespace RPP namespace RPP
{ {
internal static class Program internal static class Program
{ {
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread] [STAThread]
static void Main() static void Main()
{ {
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
Application.Run(new FormAirbusCollection()); var services = new ServiceCollection();
ConfigureServices(services);
using (ServiceProvider serviceProvider = services.BuildServiceProvider())
{
Application.Run(serviceProvider.GetRequiredService<FormAirbusCollection>());
}
}
private static void ConfigureServices(ServiceCollection services)
{
services.AddSingleton<FormAirbusCollection>().AddLogging(option =>
{
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();
var logger = new LoggerConfiguration().ReadFrom.Configuration(configuration).CreateLogger();
option.SetMinimumLevel(LogLevel.Information);
option.AddSerilog(logger);
});
} }
} }
} }

View File

@ -8,6 +8,17 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" 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="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="8.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> <ItemGroup>
<Compile Update="Properties\Resources.Designer.cs"> <Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime> <DesignTime>True</DesignTime>

View File

@ -29,11 +29,11 @@ namespace RPP.Generics
if (position < 0 || position >= _maxCount) if (position < 0 || position >= _maxCount)
{ {
return false; throw new AirbusNotFoundException(position);
} }
if (Count >= _maxCount) if (Count >= _maxCount)
{ {
return false; throw new StorageOverflowException(position);
} }
_places.Insert(0, airbus); _places.Insert(0, airbus);
@ -43,14 +43,8 @@ namespace RPP.Generics
public bool Remove(int position) public bool Remove(int position)
{ {
if (position < 0 || position > _maxCount) if (position < 0 || position > _maxCount || position >= Count)
{ throw new AirbusNotFoundException(position);
return false;
}
if (position >= Count)
{
return false;
}
_places.RemoveAt(position); _places.RemoveAt(position);
return true; return true;
} }

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace RPP
{
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 contex) : base(info, contex) { }
}
}

20
RPP/RPP/appsettings.json Normal file
View File

@ -0,0 +1,20 @@
{
"Serilog": {
"Using": [ "Serilog.Sinks.File" ],
"MinimumLevel": "Information",
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "Logs/log_.log",
"rollingInterval": "Day",
"outputTemplate": "[{Timestamp:HH:mm:ss.fff}]{Level:u4}: {Message:lj}{NewLine}{Exception}"
}
}
],
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
"Properties": {
"Application": "GasolineTanker"
}
}
}

13
RPP/RPP/nlog.config Normal file
View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true" internalLogLevel="Info">
<targets>
<target xsi:type="File" name="tofile" fileName="carlog-${shortdate}.log" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="tofile" />
</rules>
</nlog>
</configuration>