PIbd-11 ShtyrkinE.D. LabWork07 Simple #7
@ -40,7 +40,7 @@ public abstract class AbstractCompany
|
||||
/// <summary>
|
||||
/// Вычисление максимального количества элементов, которых можно разместить в окне
|
||||
/// </summary>
|
||||
private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);
|
||||
private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight) - 6;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
@ -101,8 +101,12 @@ public abstract class AbstractCompany
|
||||
SetObjectPosition();
|
||||
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
|
||||
{
|
||||
DrawningWarship? obj = _collection?.Get(i);
|
||||
obj?.DrawTransport(graphics);
|
||||
try
|
||||
{
|
||||
DrawningWarship? obj = _collection?.Get(i);
|
||||
obj?.DrawTransport(graphics);
|
||||
}
|
||||
catch (Exception) { }
|
||||
}
|
||||
|
||||
return bitmap;
|
||||
|
@ -1,4 +1,6 @@
|
||||
namespace ProjectAircraftCarrier.CollectionGenericObjects;
|
||||
using ProjectAircraftCarrier.Exceptions;
|
||||
|
||||
namespace ProjectAircraftCarrier.CollectionGenericObjects;
|
||||
|
||||
public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
where T : class
|
||||
@ -42,36 +44,28 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
|
||||
public T? Get(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
if (position >= Count || position < 0) return null;
|
||||
if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
public int Insert(T obj)
|
||||
{
|
||||
// TODO проверка, что не превышено максимальное количество элементов
|
||||
// TODO вставка в конец набора
|
||||
if (Count == _maxCount) return -1;
|
||||
if (Count == _maxCount) throw new CollectionOverflowException(Count);
|
||||
_collection.Add(obj);
|
||||
return Count;
|
||||
}
|
||||
|
||||
public int Insert(T obj, int position)
|
||||
{
|
||||
// TODO проверка, что не превышено максимальное количество элементов
|
||||
// TODO проверка позиции
|
||||
// TODO вставка по позиции
|
||||
if (Count == _maxCount) return -1;
|
||||
if (position >= Count || position < 0) return -1;
|
||||
if (Count == _maxCount) throw new CollectionOverflowException(Count);
|
||||
if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
|
||||
_collection.Insert(position, obj);
|
||||
return position;
|
||||
}
|
||||
|
||||
public T Remove(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO удаление объекта из списка
|
||||
if (position >= Count || position < 0) return null;
|
||||
if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
|
||||
T obj = _collection[position];
|
||||
_collection.RemoveAt(position);
|
||||
return obj;
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using ProjectAircraftCarrier.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@ -54,29 +55,29 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
|
||||
public T? Get(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
if (position >= _collection.Length || position < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (position >= _collection.Length || position < 0) throw new PositionOutOfCollectionException(position);
|
||||
if (_collection[position] == null) throw new ObjectNotFoundException(position);
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
public int Insert(T obj)
|
||||
{
|
||||
// TODO вставка в свободное место набора
|
||||
return Insert(obj, 0);
|
||||
int index = 0;
|
||||
while (index < _collection.Length)
|
||||
{
|
||||
if (_collection[index] == null)
|
||||
{
|
||||
_collection[index] = obj;
|
||||
return index;
|
||||
}
|
||||
++index;
|
||||
}
|
||||
throw new CollectionOverflowException(Count);
|
||||
}
|
||||
|
||||
public int Insert(T obj, int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
|
||||
// ищется свободное место после этой позиции и идёт вставка туда
|
||||
// если нет после, ищем до
|
||||
// TODO вставка
|
||||
if (position >= _collection.Length || position < 0)
|
||||
return -1;
|
||||
if (position >= _collection.Length || position < 0) throw new PositionOutOfCollectionException(position);
|
||||
if (_collection[position] == null)
|
||||
{
|
||||
_collection[position] = obj;
|
||||
@ -102,15 +103,13 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
}
|
||||
--index;
|
||||
}
|
||||
return -1;
|
||||
throw new CollectionOverflowException(Count);
|
||||
}
|
||||
|
||||
public T? Remove(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO удаление объекта из массива, присвоив элементу массива значение null
|
||||
if (position >= _collection.Length || position < 0)
|
||||
return null;
|
||||
if (position >= _collection.Length || position < 0) throw new PositionOutOfCollectionException(position);
|
||||
if (_collection[position] == null) throw new ObjectNotFoundException(position);
|
||||
T obj = _collection[position];
|
||||
_collection[position] = null;
|
||||
return obj;
|
||||
|
@ -1,4 +1,5 @@
|
||||
using ProjectAircraftCarrier.Drawnings;
|
||||
using ProjectAircraftCarrier.Exceptions;
|
||||
using System.Text;
|
||||
|
||||
namespace ProjectAircraftCarrier.CollectionGenericObjects;
|
||||
@ -31,8 +32,6 @@ public class StorageCollection<T>
|
||||
/// <param name="collectionType">тип коллекции</param>
|
||||
public void AddCollection(string name, CollectionType collectionType)
|
||||
{
|
||||
// TODO проверка, что name не пустой и нет в словаре записи с таким ключом
|
||||
// TODO Прописать логику для добавления
|
||||
if (_storages.ContainsKey(name)) return;
|
||||
if (collectionType == CollectionType.None) return;
|
||||
else if (collectionType == CollectionType.Massive)
|
||||
@ -47,7 +46,6 @@ public class StorageCollection<T>
|
||||
/// <param name="name">Название коллекции</param>
|
||||
public void DelCollection(string name)
|
||||
{
|
||||
// TODO Прописать логику для удаления коллекции
|
||||
if (_storages.ContainsKey(name))
|
||||
_storages.Remove(name);
|
||||
}
|
||||
@ -61,7 +59,6 @@ public class StorageCollection<T>
|
||||
{
|
||||
get
|
||||
{
|
||||
// TODO Продумать логику получения объекта
|
||||
if (_storages.ContainsKey(name))
|
||||
return _storages[name];
|
||||
return null;
|
||||
@ -88,11 +85,11 @@ public class StorageCollection<T>
|
||||
/// </summary>
|
||||
/// <param name="filename">Путь и имя файла</param>
|
||||
/// <returns>true - сохранение прошло успешно, false - ошибка при сохранении данных</returns>
|
||||
public bool SaveData(string filename)
|
||||
public void SaveData(string filename)
|
||||
{
|
||||
if (_storages.Count == 0)
|
||||
{
|
||||
return false;
|
||||
throw new ArgumentException("В хранилище отсутствуют коллекции для сохранения");
|
||||
}
|
||||
|
||||
if (File.Exists(filename))
|
||||
@ -106,7 +103,6 @@ public class StorageCollection<T>
|
||||
foreach (KeyValuePair<string, ICollectionGenericObjects<T>> value in _storages)
|
||||
{
|
||||
writer.Write(Environment.NewLine);
|
||||
// не сохраняем пустые коллекции
|
||||
if (value.Value.Count == 0)
|
||||
{
|
||||
continue;
|
||||
@ -132,7 +128,6 @@ public class StorageCollection<T>
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -140,11 +135,11 @@ public class StorageCollection<T>
|
||||
/// </summary>
|
||||
/// <param name="filename">Путь и имя файла</param>
|
||||
/// <returns>true - загрузка прошла успешно, false - ошибка при загрузке данных</returns>
|
||||
public bool LoadData(string filename)
|
||||
public void LoadData(string filename)
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
return false;
|
||||
throw new FileNotFoundException("Файл не существует");
|
||||
}
|
||||
|
||||
using (StreamReader fs = File.OpenText(filename))
|
||||
@ -152,12 +147,12 @@ public class StorageCollection<T>
|
||||
string str = fs.ReadLine();
|
||||
if (str == null || str.Length == 0)
|
||||
{
|
||||
return false;
|
||||
throw new Exception("В файле нет данных");
|
||||
}
|
||||
|
||||
if (!str.StartsWith(_collectionKey))
|
||||
{
|
||||
return false;
|
||||
throw new FormatException("В файле неверные данные");
|
||||
}
|
||||
|
||||
_storages.Clear();
|
||||
@ -174,7 +169,7 @@ public class StorageCollection<T>
|
||||
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionType);
|
||||
if (collection == null)
|
||||
{
|
||||
return false;
|
||||
throw new Exception("Не удалось создать коллекцию");
|
||||
}
|
||||
|
||||
collection.MaxCount = Convert.ToInt32(record[2]);
|
||||
@ -183,15 +178,21 @@ public class StorageCollection<T>
|
||||
{
|
||||
if (elem?.CreateDrawningWarship() is T warship)
|
||||
{
|
||||
if (collection.Insert(warship) == -1)
|
||||
try
|
||||
{
|
||||
return false;
|
||||
if (collection.Insert(warship) == -1)
|
||||
{
|
||||
throw new InvalidOperationException("Объект не удалось добавить в коллекцию: " + record[3]);
|
||||
}
|
||||
}
|
||||
catch (CollectionOverflowException ex)
|
||||
{
|
||||
throw new CollectionOverflowException("Коллекция переполнена", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
_storages.Add(record[0], collection);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,11 +39,12 @@ public class WarshipDockService : AbstractCompany
|
||||
|
||||
for (int i = 0; i < (_collection?.Count ?? 0); i++)
|
||||
{
|
||||
if (_collection.Get(i) != null)
|
||||
try
|
||||
{
|
||||
_collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight);
|
||||
_collection.Get(i).SetPosition(_placeSizeWidth * posWidth + 5, posHeight * _placeSizeHeight + 10);
|
||||
}
|
||||
catch (Exception) { }
|
||||
if (posWidth < width - 1)
|
||||
{
|
||||
posWidth++;
|
||||
|
@ -0,0 +1,20 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace ProjectAircraftCarrier.Exceptions;
|
||||
|
||||
/// <summary>
|
||||
/// Класс, описывающий ошибку переполнения коллекции
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
internal class CollectionOverflowException : ApplicationException
|
||||
{
|
||||
public CollectionOverflowException(int count) : base("В коллекции превышено допустимое количество: " + count) { }
|
||||
|
||||
public CollectionOverflowException() : base() { }
|
||||
|
||||
public CollectionOverflowException(string message) : base(message) { }
|
||||
|
||||
public CollectionOverflowException(string message, Exception exception) : base(message, exception) { }
|
||||
|
||||
protected CollectionOverflowException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace ProjectAircraftCarrier.Exceptions;
|
||||
|
||||
/// <summary>
|
||||
/// Класс, описывающий ошибку, что по указанной позиции нет элемента
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
internal class ObjectNotFoundException : ApplicationException
|
||||
{
|
||||
public ObjectNotFoundException(int i) : base("Не найден объект по позиции " + i) { }
|
||||
|
||||
public ObjectNotFoundException() : base() { }
|
||||
|
||||
public ObjectNotFoundException(string message) : base(message) { }
|
||||
|
||||
public ObjectNotFoundException(string message, Exception exception) : base(message, exception) { }
|
||||
|
||||
protected ObjectNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace ProjectAircraftCarrier.Exceptions;
|
||||
|
||||
/// <summary>
|
||||
/// Класс, описывающий ошибку выхода за границы коллекции
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
internal class PositionOutOfCollectionException : ApplicationException
|
||||
{
|
||||
public PositionOutOfCollectionException(int i) : base("Выход за границы коллекции.Позиция " + i) { }
|
||||
|
||||
public PositionOutOfCollectionException() : base() { }
|
||||
|
||||
public PositionOutOfCollectionException(string message) : base(message) { }
|
||||
|
||||
public PositionOutOfCollectionException(string message, Exception exception) : base(message, exception) { }
|
||||
|
||||
protected PositionOutOfCollectionException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
using ProjectAircraftCarrier.CollectionGenericObjects;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ProjectAircraftCarrier.CollectionGenericObjects;
|
||||
using ProjectAircraftCarrier.Drawnings;
|
||||
using ProjectAircraftCarrier.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -24,13 +26,18 @@ public partial class FormWarshipCollection : Form
|
||||
/// </summary>
|
||||
private AbstractCompany? _company = null;
|
||||
|
||||
|
||||
private readonly ILogger _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormWarshipCollection()
|
||||
public FormWarshipCollection(ILogger<FormWarshipCollection> logger)
|
||||
{
|
||||
InitializeComponent();
|
||||
_storageCollection = new();
|
||||
_logger = logger;
|
||||
_logger.LogInformation("Форма загрузилась");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -46,25 +53,30 @@ public partial class FormWarshipCollection : Form
|
||||
private void ButtonAddWarship_Click(object sender, EventArgs e)
|
||||
{
|
||||
FormWarshipConfig form = new();
|
||||
// TODO передать метод
|
||||
form.Show();
|
||||
form.AddEvent(SetWarship);
|
||||
}
|
||||
|
||||
private void SetWarship(DrawningWarship? warship)
|
||||
{
|
||||
if (_company == null || warship == null)
|
||||
try
|
||||
{
|
||||
return;
|
||||
if (_company == null || warship == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (_company + warship != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _company.Show();
|
||||
_logger.LogInformation("Добавлен объект: " + warship.GetDataForSave());
|
||||
}
|
||||
}
|
||||
if (_company + warship != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
else
|
||||
catch (ObjectNotFoundException) { }
|
||||
catch (CollectionOverflowException ex)
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,21 +86,24 @@ public partial class FormWarshipCollection : Form
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int pos = Convert.ToInt32(maskedTextBox.Text);
|
||||
if (_company - pos != null)
|
||||
try
|
||||
{
|
||||
MessageBox.Show("Объект удалён");
|
||||
pictureBox.Image = _company.Show();
|
||||
if (_company - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBox.Image = _company.Show();
|
||||
_logger.LogInformation("Удален объект по позиции " + pos);
|
||||
}
|
||||
}
|
||||
else
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -98,29 +113,29 @@ public partial class FormWarshipCollection : Form
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DrawningWarship? warship = null;
|
||||
int counter = 100;
|
||||
while (warship == null)
|
||||
try
|
||||
{
|
||||
warship = _company.GetRandomObject();
|
||||
counter--;
|
||||
if (counter <= 0)
|
||||
while (warship == null)
|
||||
{
|
||||
break;
|
||||
warship = _company.GetRandomObject();
|
||||
counter--;
|
||||
if (counter <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
FormAircraftCarrier form = new()
|
||||
{
|
||||
SetWarship = warship
|
||||
};
|
||||
form.ShowDialog();
|
||||
}
|
||||
|
||||
if (warship == null)
|
||||
catch (Exception ex)
|
||||
{
|
||||
return;
|
||||
MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
FormAircraftCarrier form = new()
|
||||
{
|
||||
SetWarship = warship
|
||||
};
|
||||
form.ShowDialog();
|
||||
}
|
||||
|
||||
private void ButtonRefresh_Click(object sender, EventArgs e)
|
||||
@ -150,43 +165,52 @@ public partial class FormWarshipCollection : Form
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonList.Checked && !radioButtonMassive.Checked))
|
||||
{
|
||||
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
CollectionType collectionType = CollectionType.None;
|
||||
if (radioButtonMassive.Checked)
|
||||
try
|
||||
{
|
||||
collectionType = CollectionType.Massive;
|
||||
CollectionType collectionType = CollectionType.None;
|
||||
if (radioButtonMassive.Checked)
|
||||
{
|
||||
collectionType = CollectionType.Massive;
|
||||
}
|
||||
else if (radioButtonList.Checked)
|
||||
{
|
||||
collectionType = CollectionType.List;
|
||||
}
|
||||
_storageCollection.AddCollection(textBoxCollectionName.Text, collectionType);
|
||||
RerfreshListBoxItems();
|
||||
_logger.LogInformation("Коллекция добавлена " + textBoxCollectionName.Text);
|
||||
}
|
||||
else if (radioButtonList.Checked)
|
||||
catch (Exception ex)
|
||||
{
|
||||
collectionType = CollectionType.List;
|
||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||
}
|
||||
|
||||
_storageCollection.AddCollection(textBoxCollectionName.Text, collectionType);
|
||||
RerfreshListBoxItems();
|
||||
}
|
||||
|
||||
private void ButtonCollectionDel_Click(object sender, EventArgs e)
|
||||
{
|
||||
// TODO прописать логику удаления элемента из коллекции
|
||||
// нужно убедиться, что есть выбранная коллекция
|
||||
// спросить у пользователя через MessageBox, что он подтверждает, что хочет удалить запись
|
||||
// удалить и обновить ListBox
|
||||
if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
|
||||
{
|
||||
MessageBox.Show("Коллекция не выбрана");
|
||||
return;
|
||||
}
|
||||
|
||||
if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
try
|
||||
{
|
||||
return;
|
||||
if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
|
||||
RerfreshListBoxItems();
|
||||
_logger.LogInformation("Коллекция: " + listBoxCollection.SelectedItem.ToString() + " удалена");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||
}
|
||||
|
||||
_storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
|
||||
RerfreshListBoxItems();
|
||||
}
|
||||
|
||||
private void ButtonCreateCompany_Click(object sender, EventArgs e)
|
||||
@ -196,21 +220,19 @@ public partial class FormWarshipCollection : Form
|
||||
MessageBox.Show("Коллекция не выбрана");
|
||||
return;
|
||||
}
|
||||
|
||||
ICollectionGenericObjects<DrawningWarship>? collection = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
|
||||
ICollectionGenericObjects<DrawningWarship>? collection =
|
||||
_storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
|
||||
if (collection == null)
|
||||
{
|
||||
MessageBox.Show("Коллекция не проинициализирована");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (comboBoxSelectorCompany.Text)
|
||||
{
|
||||
case "Хранилище":
|
||||
_company = new WarshipDockService(pictureBox.Width, pictureBox.Height, collection);
|
||||
break;
|
||||
}
|
||||
|
||||
panelCompanyTools.Enabled = true;
|
||||
RerfreshListBoxItems();
|
||||
}
|
||||
@ -219,15 +241,16 @@ public partial class FormWarshipCollection : Form
|
||||
{
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_storageCollection.SaveData(saveFileDialog.FileName))
|
||||
try
|
||||
{
|
||||
MessageBox.Show("Сохранение прошло успешно",
|
||||
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
_storageCollection.SaveData(saveFileDialog.FileName);
|
||||
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
_logger.LogInformation("Сохранение в файл: {filename}", saveFileDialog.FileName);
|
||||
}
|
||||
else
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Не сохранилось", "Результат",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -236,16 +259,17 @@ public partial class FormWarshipCollection : Form
|
||||
{
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_storageCollection.LoadData(openFileDialog.FileName))
|
||||
try
|
||||
{
|
||||
MessageBox.Show("Загрузка прошла успешно",
|
||||
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
_storageCollection.LoadData(openFileDialog.FileName);
|
||||
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
RerfreshListBoxItems();
|
||||
_logger.LogInformation("Загрузка из файла: {filename}", openFileDialog.FileName);
|
||||
}
|
||||
else
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Не сохранилось", "Результат",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -73,8 +73,10 @@
|
||||
groupBoxConfig.Controls.Add(labelSimpleObject);
|
||||
groupBoxConfig.Dock = DockStyle.Left;
|
||||
groupBoxConfig.Location = new Point(0, 0);
|
||||
groupBoxConfig.Margin = new Padding(3, 2, 3, 2);
|
||||
groupBoxConfig.Name = "groupBoxConfig";
|
||||
groupBoxConfig.Size = new Size(686, 215);
|
||||
groupBoxConfig.Padding = new Padding(3, 2, 3, 2);
|
||||
groupBoxConfig.Size = new Size(600, 161);
|
||||
groupBoxConfig.TabIndex = 0;
|
||||
groupBoxConfig.TabStop = false;
|
||||
groupBoxConfig.Text = "Параметры";
|
||||
@ -89,9 +91,11 @@
|
||||
groupBoxColors.Controls.Add(panelWhite);
|
||||
groupBoxColors.Controls.Add(panelGreen);
|
||||
groupBoxColors.Controls.Add(panelRed);
|
||||
groupBoxColors.Location = new Point(386, 20);
|
||||
groupBoxColors.Location = new Point(338, 15);
|
||||
groupBoxColors.Margin = new Padding(3, 2, 3, 2);
|
||||
groupBoxColors.Name = "groupBoxColors";
|
||||
groupBoxColors.Size = new Size(271, 134);
|
||||
groupBoxColors.Padding = new Padding(3, 2, 3, 2);
|
||||
groupBoxColors.Size = new Size(237, 100);
|
||||
groupBoxColors.TabIndex = 8;
|
||||
groupBoxColors.TabStop = false;
|
||||
groupBoxColors.Text = "Цвета";
|
||||
@ -99,73 +103,82 @@
|
||||
// panelPurple
|
||||
//
|
||||
panelPurple.BackColor = Color.Purple;
|
||||
panelPurple.Location = new Point(212, 77);
|
||||
panelPurple.Location = new Point(186, 58);
|
||||
panelPurple.Margin = new Padding(3, 2, 3, 2);
|
||||
panelPurple.Name = "panelPurple";
|
||||
panelPurple.Size = new Size(40, 40);
|
||||
panelPurple.Size = new Size(35, 30);
|
||||
panelPurple.TabIndex = 3;
|
||||
//
|
||||
// panelYellow
|
||||
//
|
||||
panelYellow.BackColor = Color.Yellow;
|
||||
panelYellow.Location = new Point(212, 26);
|
||||
panelYellow.Location = new Point(186, 20);
|
||||
panelYellow.Margin = new Padding(3, 2, 3, 2);
|
||||
panelYellow.Name = "panelYellow";
|
||||
panelYellow.Size = new Size(40, 40);
|
||||
panelYellow.Size = new Size(35, 30);
|
||||
panelYellow.TabIndex = 1;
|
||||
//
|
||||
// panelBlack
|
||||
//
|
||||
panelBlack.BackColor = Color.Black;
|
||||
panelBlack.Location = new Point(148, 77);
|
||||
panelBlack.Location = new Point(130, 58);
|
||||
panelBlack.Margin = new Padding(3, 2, 3, 2);
|
||||
panelBlack.Name = "panelBlack";
|
||||
panelBlack.Size = new Size(40, 40);
|
||||
panelBlack.Size = new Size(35, 30);
|
||||
panelBlack.TabIndex = 4;
|
||||
//
|
||||
// panelBlue
|
||||
//
|
||||
panelBlue.BackColor = Color.Blue;
|
||||
panelBlue.Location = new Point(148, 26);
|
||||
panelBlue.Location = new Point(130, 20);
|
||||
panelBlue.Margin = new Padding(3, 2, 3, 2);
|
||||
panelBlue.Name = "panelBlue";
|
||||
panelBlue.Size = new Size(40, 40);
|
||||
panelBlue.Size = new Size(35, 30);
|
||||
panelBlue.TabIndex = 1;
|
||||
//
|
||||
// panelGray
|
||||
//
|
||||
panelGray.BackColor = Color.Gray;
|
||||
panelGray.Location = new Point(84, 77);
|
||||
panelGray.Location = new Point(74, 58);
|
||||
panelGray.Margin = new Padding(3, 2, 3, 2);
|
||||
panelGray.Name = "panelGray";
|
||||
panelGray.Size = new Size(40, 40);
|
||||
panelGray.Size = new Size(35, 30);
|
||||
panelGray.TabIndex = 5;
|
||||
//
|
||||
// panelWhite
|
||||
//
|
||||
panelWhite.BackColor = Color.White;
|
||||
panelWhite.Location = new Point(20, 77);
|
||||
panelWhite.Location = new Point(18, 58);
|
||||
panelWhite.Margin = new Padding(3, 2, 3, 2);
|
||||
panelWhite.Name = "panelWhite";
|
||||
panelWhite.Size = new Size(40, 40);
|
||||
panelWhite.Size = new Size(35, 30);
|
||||
panelWhite.TabIndex = 2;
|
||||
//
|
||||
// panelGreen
|
||||
//
|
||||
panelGreen.BackColor = Color.Green;
|
||||
panelGreen.Location = new Point(84, 26);
|
||||
panelGreen.Location = new Point(74, 20);
|
||||
panelGreen.Margin = new Padding(3, 2, 3, 2);
|
||||
panelGreen.Name = "panelGreen";
|
||||
panelGreen.Size = new Size(40, 40);
|
||||
panelGreen.Size = new Size(35, 30);
|
||||
panelGreen.TabIndex = 1;
|
||||
//
|
||||
// panelRed
|
||||
//
|
||||
panelRed.BackColor = Color.Red;
|
||||
panelRed.Location = new Point(20, 26);
|
||||
panelRed.Location = new Point(18, 20);
|
||||
panelRed.Margin = new Padding(3, 2, 3, 2);
|
||||
panelRed.Name = "panelRed";
|
||||
panelRed.Size = new Size(40, 40);
|
||||
panelRed.Size = new Size(35, 30);
|
||||
panelRed.TabIndex = 0;
|
||||
//
|
||||
// checkBoxControlRoom
|
||||
//
|
||||
checkBoxControlRoom.AutoSize = true;
|
||||
checkBoxControlRoom.Location = new Point(6, 130);
|
||||
checkBoxControlRoom.Location = new Point(5, 98);
|
||||
checkBoxControlRoom.Margin = new Padding(3, 2, 3, 2);
|
||||
checkBoxControlRoom.Name = "checkBoxControlRoom";
|
||||
checkBoxControlRoom.Size = new Size(286, 24);
|
||||
checkBoxControlRoom.Size = new Size(227, 19);
|
||||
checkBoxControlRoom.TabIndex = 7;
|
||||
checkBoxControlRoom.Text = "Признак наличия рубки управления";
|
||||
checkBoxControlRoom.UseVisualStyleBackColor = true;
|
||||
@ -173,57 +186,60 @@
|
||||
// checkBoxAircraftDeck
|
||||
//
|
||||
checkBoxAircraftDeck.AutoSize = true;
|
||||
checkBoxAircraftDeck.Location = new Point(6, 172);
|
||||
checkBoxAircraftDeck.Location = new Point(5, 129);
|
||||
checkBoxAircraftDeck.Margin = new Padding(3, 2, 3, 2);
|
||||
checkBoxAircraftDeck.Name = "checkBoxAircraftDeck";
|
||||
checkBoxAircraftDeck.Size = new Size(361, 24);
|
||||
checkBoxAircraftDeck.Size = new Size(287, 19);
|
||||
checkBoxAircraftDeck.TabIndex = 6;
|
||||
checkBoxAircraftDeck.Text = "Признак наличия взлётно-посадочной полосы";
|
||||
checkBoxAircraftDeck.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// numericUpDownWeight
|
||||
//
|
||||
numericUpDownWeight.Location = new Point(94, 76);
|
||||
numericUpDownWeight.Location = new Point(82, 57);
|
||||
numericUpDownWeight.Margin = new Padding(3, 2, 3, 2);
|
||||
numericUpDownWeight.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
|
||||
numericUpDownWeight.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
numericUpDownWeight.Name = "numericUpDownWeight";
|
||||
numericUpDownWeight.Size = new Size(122, 27);
|
||||
numericUpDownWeight.Size = new Size(107, 23);
|
||||
numericUpDownWeight.TabIndex = 5;
|
||||
numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
//
|
||||
// labelWeight
|
||||
//
|
||||
labelWeight.AutoSize = true;
|
||||
labelWeight.Location = new Point(12, 78);
|
||||
labelWeight.Location = new Point(10, 58);
|
||||
labelWeight.Name = "labelWeight";
|
||||
labelWeight.Size = new Size(36, 20);
|
||||
labelWeight.Size = new Size(29, 15);
|
||||
labelWeight.TabIndex = 4;
|
||||
labelWeight.Text = "Вес:";
|
||||
//
|
||||
// numericUpDownSpeed
|
||||
//
|
||||
numericUpDownSpeed.Location = new Point(94, 39);
|
||||
numericUpDownSpeed.Location = new Point(82, 29);
|
||||
numericUpDownSpeed.Margin = new Padding(3, 2, 3, 2);
|
||||
numericUpDownSpeed.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
|
||||
numericUpDownSpeed.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
numericUpDownSpeed.Name = "numericUpDownSpeed";
|
||||
numericUpDownSpeed.Size = new Size(122, 27);
|
||||
numericUpDownSpeed.Size = new Size(107, 23);
|
||||
numericUpDownSpeed.TabIndex = 3;
|
||||
numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
//
|
||||
// labelSpeed
|
||||
//
|
||||
labelSpeed.AutoSize = true;
|
||||
labelSpeed.Location = new Point(12, 41);
|
||||
labelSpeed.Location = new Point(10, 31);
|
||||
labelSpeed.Name = "labelSpeed";
|
||||
labelSpeed.Size = new Size(76, 20);
|
||||
labelSpeed.Size = new Size(62, 15);
|
||||
labelSpeed.TabIndex = 2;
|
||||
labelSpeed.Text = "Скорость:";
|
||||
//
|
||||
// labelModifiedObject
|
||||
//
|
||||
labelModifiedObject.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelModifiedObject.Location = new Point(538, 162);
|
||||
labelModifiedObject.Location = new Point(471, 122);
|
||||
labelModifiedObject.Name = "labelModifiedObject";
|
||||
labelModifiedObject.Size = new Size(119, 43);
|
||||
labelModifiedObject.Size = new Size(104, 33);
|
||||
labelModifiedObject.TabIndex = 1;
|
||||
labelModifiedObject.Text = "Продвинутый";
|
||||
labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter;
|
||||
@ -232,9 +248,9 @@
|
||||
// labelSimpleObject
|
||||
//
|
||||
labelSimpleObject.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelSimpleObject.Location = new Point(386, 162);
|
||||
labelSimpleObject.Location = new Point(338, 122);
|
||||
labelSimpleObject.Name = "labelSimpleObject";
|
||||
labelSimpleObject.Size = new Size(119, 43);
|
||||
labelSimpleObject.Size = new Size(104, 33);
|
||||
labelSimpleObject.TabIndex = 0;
|
||||
labelSimpleObject.Text = "Простой";
|
||||
labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter;
|
||||
@ -242,17 +258,19 @@
|
||||
//
|
||||
// pictureBoxObject
|
||||
//
|
||||
pictureBoxObject.Location = new Point(48, 65);
|
||||
pictureBoxObject.Location = new Point(8, 42);
|
||||
pictureBoxObject.Margin = new Padding(3, 2, 3, 2);
|
||||
pictureBoxObject.Name = "pictureBoxObject";
|
||||
pictureBoxObject.Size = new Size(154, 102);
|
||||
pictureBoxObject.Size = new Size(189, 83);
|
||||
pictureBoxObject.TabIndex = 1;
|
||||
pictureBoxObject.TabStop = false;
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
buttonAdd.Location = new Point(703, 176);
|
||||
buttonAdd.Location = new Point(615, 132);
|
||||
buttonAdd.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonAdd.Name = "buttonAdd";
|
||||
buttonAdd.Size = new Size(94, 29);
|
||||
buttonAdd.Size = new Size(82, 22);
|
||||
buttonAdd.TabIndex = 2;
|
||||
buttonAdd.Text = "Добавить";
|
||||
buttonAdd.UseVisualStyleBackColor = true;
|
||||
@ -260,9 +278,10 @@
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Location = new Point(814, 176);
|
||||
buttonCancel.Location = new Point(712, 132);
|
||||
buttonCancel.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(94, 29);
|
||||
buttonCancel.Size = new Size(82, 22);
|
||||
buttonCancel.TabIndex = 3;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
@ -273,9 +292,10 @@
|
||||
panelObject.Controls.Add(labelAdditionalColor);
|
||||
panelObject.Controls.Add(labelBodyColor);
|
||||
panelObject.Controls.Add(pictureBoxObject);
|
||||
panelObject.Location = new Point(683, 0);
|
||||
panelObject.Location = new Point(598, 0);
|
||||
panelObject.Margin = new Padding(3, 2, 3, 2);
|
||||
panelObject.Name = "panelObject";
|
||||
panelObject.Size = new Size(239, 170);
|
||||
panelObject.Size = new Size(209, 128);
|
||||
panelObject.TabIndex = 4;
|
||||
panelObject.DragDrop += PanelObject_DragDrop;
|
||||
panelObject.DragEnter += PanelObject_DragEnter;
|
||||
@ -284,9 +304,9 @@
|
||||
//
|
||||
labelAdditionalColor.AllowDrop = true;
|
||||
labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelAdditionalColor.Location = new Point(131, 9);
|
||||
labelAdditionalColor.Location = new Point(115, 7);
|
||||
labelAdditionalColor.Name = "labelAdditionalColor";
|
||||
labelAdditionalColor.Size = new Size(94, 43);
|
||||
labelAdditionalColor.Size = new Size(82, 33);
|
||||
labelAdditionalColor.TabIndex = 3;
|
||||
labelAdditionalColor.Text = "Доп. цвет";
|
||||
labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter;
|
||||
@ -297,9 +317,9 @@
|
||||
//
|
||||
labelBodyColor.AllowDrop = true;
|
||||
labelBodyColor.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelBodyColor.Location = new Point(20, 9);
|
||||
labelBodyColor.Location = new Point(18, 7);
|
||||
labelBodyColor.Name = "labelBodyColor";
|
||||
labelBodyColor.Size = new Size(94, 43);
|
||||
labelBodyColor.Size = new Size(82, 33);
|
||||
labelBodyColor.TabIndex = 2;
|
||||
labelBodyColor.Text = "Цвет";
|
||||
labelBodyColor.TextAlign = ContentAlignment.MiddleCenter;
|
||||
@ -308,13 +328,14 @@
|
||||
//
|
||||
// FormWarshipConfig
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(923, 215);
|
||||
ClientSize = new Size(808, 161);
|
||||
Controls.Add(panelObject);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonAdd);
|
||||
Controls.Add(groupBoxConfig);
|
||||
Margin = new Padding(3, 2, 3, 2);
|
||||
Name = "FormWarshipConfig";
|
||||
Text = "Создание объекта";
|
||||
groupBoxConfig.ResumeLayout(false);
|
||||
|
@ -1,3 +1,8 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Serilog;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace ProjectAircraftCarrier
|
||||
{
|
||||
internal static class Program
|
||||
@ -11,7 +16,31 @@ namespace ProjectAircraftCarrier
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormWarshipCollection());
|
||||
|
||||
ServiceCollection services = new();
|
||||
ConfigureServices(services);
|
||||
using ServiceProvider serviceProvider = services.BuildServiceProvider();
|
||||
Application.Run(serviceProvider.GetRequiredService<FormWarshipCollection>());
|
||||
|
||||
}
|
||||
private static void ConfigureServices(ServiceCollection services)
|
||||
{
|
||||
string[] path = Directory.GetCurrentDirectory().Split('\\');
|
||||
string pathNeed = "";
|
||||
for (int i = 0; i < path.Length - 3; i++)
|
||||
{
|
||||
pathNeed += path[i] + "\\";
|
||||
}
|
||||
services.AddSingleton<FormWarshipCollection>()
|
||||
.AddLogging(option =>
|
||||
{
|
||||
option.SetMinimumLevel(LogLevel.Information);
|
||||
option.AddSerilog(new LoggerConfiguration()
|
||||
.ReadFrom.Configuration(new ConfigurationBuilder()
|
||||
.AddJsonFile($"{pathNeed}serilog.json")
|
||||
.Build())
|
||||
.CreateLogger());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -8,6 +8,18 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</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="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.11" />
|
||||
<PackageReference Include="Serilog" Version="4.0.0" />
|
||||
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.1" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
|
15
ProjectAircraftCarrier/ProjectAircraftCarrier/serilog.json
Normal file
15
ProjectAircraftCarrier/ProjectAircraftCarrier/serilog.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"Serilog": {
|
||||
"Using": [ "Serilog.Sinks.File" ],
|
||||
"MinimumLevel": "Debug",
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": { "path": "log.log" }
|
||||
}
|
||||
],
|
||||
"Properties": {
|
||||
"Application": "Sample"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user