Compare commits
No commits in common. "fa6661bfceb71cc6efeb22f81f7cccc46c0efa6c" and "86aefff19974d44c20a5b3f6fe9557b2af19dff3" have entirely different histories.
fa6661bfce
...
86aefff199
@ -21,7 +21,7 @@ public abstract class AbstractCompany
|
|||||||
|
|
||||||
protected ICollectionGenericObjects<DrawningBus?> _collection = null;
|
protected ICollectionGenericObjects<DrawningBus?> _collection = null;
|
||||||
|
|
||||||
private int GetMaxCount => _pictureWidth / _placeSizeWidth * (_pictureHeight / _placeSizeHeight / 2 * 3);
|
private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);
|
||||||
|
|
||||||
public AbstractCompany(int picWidth, int picHeigth, ICollectionGenericObjects<DrawningBus> collection)
|
public AbstractCompany(int picWidth, int picHeigth, ICollectionGenericObjects<DrawningBus> collection)
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using ProjectAccordionBus.Exceptions;
|
using System;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -36,30 +35,39 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
|
|
||||||
public T Get(int position)
|
public T Get(int position)
|
||||||
{
|
{
|
||||||
if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
|
if (position < 0 || position >= _collection.Count || _collection == null || _collection.Count == 0) return null;
|
||||||
|
|
||||||
return _collection[position];
|
return _collection[position];
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Insert(T obj)
|
public int Insert(T obj)
|
||||||
{
|
{
|
||||||
if (Count == _maxCount) throw new CollectionOverflowException(Count);
|
if (Count == _maxCount)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
_collection.Add(obj);
|
_collection.Add(obj);
|
||||||
return Count;
|
return Count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Insert(T obj, int position)
|
public int Insert(T obj, int position)
|
||||||
{
|
{
|
||||||
if (Count == _maxCount) throw new CollectionOverflowException(Count);
|
if (Count == _maxCount || position < 0 || position > Count)
|
||||||
if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
_collection.Insert(position, obj);
|
_collection.Insert(position, obj);
|
||||||
return position;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T? Remove(int position)
|
public T? Remove(int position)
|
||||||
{
|
{
|
||||||
if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
|
if (_collection == null || position < 0 || position >= _collection.Count) return null;
|
||||||
T obj = _collection[position];
|
|
||||||
_collection.RemoveAt(position);
|
T? obj = _collection[position];
|
||||||
|
_collection[position] = null;
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using ProjectAccordionBus.Exceptions;
|
using System;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -56,60 +55,70 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
|
|
||||||
public T? Get(int position)
|
public T? Get(int position)
|
||||||
{
|
{
|
||||||
if (position < 0 || position >= Count) throw new PositionOutOfCollectionException(position);
|
if (position >= _collection.Length || position < 0)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return _collection[position];
|
return _collection[position];
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Insert(T obj)
|
public int Insert(T obj)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < Count; i++)
|
int index = 0;
|
||||||
{
|
|
||||||
if (_collection[i] == null)
|
|
||||||
{
|
|
||||||
_collection[i] = obj;
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new CollectionOverflowException(Count);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int Insert(T obj, int position)
|
|
||||||
{
|
|
||||||
if (position >= _collection.Length || position < 0) throw new PositionOutOfCollectionException(position);
|
|
||||||
if (_collection[position] == null)
|
|
||||||
{
|
|
||||||
_collection[position] = obj;
|
|
||||||
return position;
|
|
||||||
}
|
|
||||||
int index = position + 1;
|
|
||||||
while (index < _collection.Length)
|
while (index < _collection.Length)
|
||||||
{
|
{
|
||||||
if (_collection[index] == null)
|
if (_collection[index] == null)
|
||||||
{
|
{
|
||||||
_collection[index] = obj;
|
_collection[index] = obj;
|
||||||
return index;
|
return 1;
|
||||||
}
|
}
|
||||||
++index;
|
index++;
|
||||||
}
|
}
|
||||||
index = position - 1;
|
return -1;
|
||||||
while (index >= 0)
|
}
|
||||||
|
|
||||||
|
public int Insert(T obj, int position)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (position >= _collection.Length || position < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
|
||||||
|
if (_collection[position] != null)
|
||||||
{
|
{
|
||||||
if (_collection[index] == null)
|
// проверка, что после вставляемого элемента в массиве есть пустой элемент
|
||||||
|
int nullIndex = -1;
|
||||||
|
for (int i = position + 1; i < Count; i++)
|
||||||
{
|
{
|
||||||
_collection[index] = obj;
|
if (_collection[i] == null)
|
||||||
return index;
|
{
|
||||||
|
nullIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Если пустого элемента нет, то выходим
|
||||||
|
if (nullIndex < 0)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
||||||
|
int j = nullIndex - 1;
|
||||||
|
while (j >= position)
|
||||||
|
{
|
||||||
|
_collection[j + 1] = _collection[j];
|
||||||
|
j--;
|
||||||
}
|
}
|
||||||
--index;
|
|
||||||
}
|
}
|
||||||
throw new CollectionOverflowException(Count);
|
_collection[position] = obj;
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T? Remove(int position)
|
public T? Remove(int position)
|
||||||
{
|
{
|
||||||
if (position < 0 || position >= Count) throw new PositionOutOfCollectionException(position);
|
if (position >= _collection.Length || position < 0)
|
||||||
if (_collection[position] == null) throw new ObjectNotFoundException(position);
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
T? temp = _collection[position];
|
T? temp = _collection[position];
|
||||||
_collection[position] = null;
|
_collection[position] = null;
|
||||||
return temp;
|
return temp;
|
||||||
|
@ -5,7 +5,6 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using ProjectAccordionBus.Exceptions;
|
|
||||||
|
|
||||||
namespace ProjectAccordionBus.CollectionGenericObjects;
|
namespace ProjectAccordionBus.CollectionGenericObjects;
|
||||||
|
|
||||||
@ -51,19 +50,15 @@ public class StorageCollection<T>
|
|||||||
/// <param name="collectionType">тип коллекции</param>
|
/// <param name="collectionType">тип коллекции</param>
|
||||||
public void AddCollection(string name, CollectionType collectionType)
|
public void AddCollection(string name, CollectionType collectionType)
|
||||||
{
|
{
|
||||||
if (name == null || _storages.ContainsKey(name))
|
if (_storages.ContainsKey(name) || name == "") return;
|
||||||
return;
|
|
||||||
switch (collectionType)
|
if (collectionType == CollectionType.Massive)
|
||||||
{
|
{
|
||||||
case CollectionType.None:
|
_storages[name] = new MassiveGenericObjects<T>();
|
||||||
return;
|
}
|
||||||
case CollectionType.Massive:
|
else
|
||||||
_storages[name] = new MassiveGenericObjects<T>();
|
{
|
||||||
return;
|
_storages[name] = new ListGenericObjects<T>();
|
||||||
case CollectionType.List:
|
|
||||||
_storages[name] = new ListGenericObjects<T>();
|
|
||||||
return;
|
|
||||||
default: break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -72,8 +67,7 @@ public class StorageCollection<T>
|
|||||||
/// <param name="name">Название коллекции</param>
|
/// <param name="name">Название коллекции</param>
|
||||||
public void DelCollection(string name)
|
public void DelCollection(string name)
|
||||||
{
|
{
|
||||||
if (_storages.ContainsKey(name))
|
_storages.Remove(name);
|
||||||
_storages.Remove(name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -93,11 +87,11 @@ public class StorageCollection<T>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SaveData(string filename)
|
public bool SaveData(string filename)
|
||||||
{
|
{
|
||||||
if (_storages.Count == 0)
|
if (_storages.Count == 0)
|
||||||
{
|
{
|
||||||
throw new ArgumentException("В хранилище отсутствуют коллекции для сохранения");
|
return false;
|
||||||
}
|
}
|
||||||
if (File.Exists(filename))
|
if (File.Exists(filename))
|
||||||
{
|
{
|
||||||
@ -133,25 +127,25 @@ public class StorageCollection<T>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadData(string filename)
|
public bool LoadData(string filename)
|
||||||
{
|
{
|
||||||
if (!File.Exists(filename))
|
if (!File.Exists(filename))
|
||||||
{
|
{
|
||||||
throw new FileNotFoundException($"{filename} не существует");
|
return false;
|
||||||
}
|
}
|
||||||
using (StreamReader reader = new(filename))
|
using (StreamReader reader = new(filename))
|
||||||
{
|
{
|
||||||
string line = reader.ReadLine();
|
string line = reader.ReadLine();
|
||||||
if (line == null || line.Length == 0)
|
if (line == null || line.Length == 0)
|
||||||
{
|
{
|
||||||
throw new IOException("Файл не подходит");
|
return false;
|
||||||
}
|
}
|
||||||
if (!line.Equals(_collectionKey))
|
if (!line.Equals(_collectionKey))
|
||||||
{
|
{
|
||||||
|
return false;
|
||||||
throw new IOException("В файле неверные данные");
|
|
||||||
}
|
}
|
||||||
_storages.Clear();
|
_storages.Clear();
|
||||||
while ((line = reader.ReadLine()) != null)
|
while ((line = reader.ReadLine()) != null)
|
||||||
@ -166,31 +160,25 @@ public class StorageCollection<T>
|
|||||||
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionType);
|
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionType);
|
||||||
if (collection == null)
|
if (collection == null)
|
||||||
{
|
{
|
||||||
throw new Exception("Не удалось создать коллекцию");
|
return false;
|
||||||
}
|
}
|
||||||
collection.MaxCount = Convert.ToInt32(record[2]);
|
collection.MaxCount = Convert.ToInt32(record[2]);
|
||||||
string[] set = record[3].Split(_separatorItems,
|
string[] set = record[3].Split(_separatorItems,
|
||||||
StringSplitOptions.RemoveEmptyEntries);
|
StringSplitOptions.RemoveEmptyEntries);
|
||||||
foreach (string elem in set)
|
foreach (string elem in set)
|
||||||
{
|
{
|
||||||
if (elem?.CreateDrawningBus() is T armoredCar)
|
if (elem?.CreateDrawningBus() is T truck)
|
||||||
{
|
{
|
||||||
try
|
if (collection.Insert(truck) == -1)
|
||||||
{
|
{
|
||||||
if (collection.Insert(armoredCar) == -1)
|
return false;
|
||||||
{
|
|
||||||
throw new Exception("Объект не удалось добавить в коллекцию: " + record[3]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (CollectionOverflowException ex)
|
|
||||||
{
|
|
||||||
throw new Exception("Коллекция переполнена", ex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_storages.Add(record[0], collection);
|
_storages.Add(record[0], collection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Runtime.Serialization;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ProjectAccordionBus.Exceptions;
|
|
||||||
|
|
||||||
[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) { }
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Runtime.Serialization;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ProjectAccordionBus.Exceptions;
|
|
||||||
|
|
||||||
[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) { }
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Runtime.Serialization;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ProjectAccordionBus.Exceptions;
|
|
||||||
|
|
||||||
[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,7 +1,5 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using ProjectAccordionBus.CollectionGenericObjects;
|
||||||
using ProjectAccordionBus.CollectionGenericObjects;
|
|
||||||
using ProjectAccordionBus.Drawnings;
|
using ProjectAccordionBus.Drawnings;
|
||||||
using ProjectAccordionBus.Exceptions;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
@ -29,28 +27,20 @@ public partial class FormBusCollection : Form
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private AbstractCompany? _company = null;
|
private AbstractCompany? _company = null;
|
||||||
|
|
||||||
private readonly ILogger _logger;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public FormBusCollection(ILogger<FormBusCollection> logger)
|
public FormBusCollection()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_storageCollection = new();
|
_storageCollection = new();
|
||||||
_logger = logger;
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление улучшенного троллейбуса
|
/// Добавление улучшенного троллейбуса
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender"></param>
|
/// <param name="sender"></param>
|
||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void ButtonAddAccordionBus_Click(object sender, EventArgs e)
|
private void ButtonAddAccordionBus_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAccordionBus));
|
||||||
{
|
|
||||||
FormBusConfig form = new FormBusConfig();
|
|
||||||
form.Show();
|
|
||||||
form.AddEvent(SetBus);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Создание объекта класса-перемещения
|
/// Создание объекта класса-перемещения
|
||||||
@ -116,24 +106,18 @@ public partial class FormBusCollection : Form
|
|||||||
|
|
||||||
private void SetBus(DrawningBus bus)
|
private void SetBus(DrawningBus bus)
|
||||||
{
|
{
|
||||||
try
|
if (_company == null || bus == null) return;
|
||||||
{
|
|
||||||
if (_company == null || bus == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (_company + bus != -1)
|
|
||||||
{
|
|
||||||
MessageBox.Show("Объект добавлен");
|
|
||||||
pictureBox.Image = _company.Show();
|
|
||||||
_logger.LogInformation("Добавлен объект: {0}", bus.GetDataForSave());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
bus.SetPictureSize(pictureBox.Width, pictureBox.Height);
|
||||||
catch (CollectionOverflowException ex)
|
|
||||||
|
if (_company + bus != -1)
|
||||||
{
|
{
|
||||||
MessageBox.Show(ex.Message);
|
MessageBox.Show("Объект добавлен");
|
||||||
_logger.LogError($"Ошибка: {ex.Message}");
|
pictureBox.Image = _company.Show();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект не удалось добавить");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,60 +128,37 @@ public partial class FormBusCollection : Form
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
|
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int pos = Convert.ToInt32(maskedTextBox.Text);
|
int pos = Convert.ToInt32(maskedTextBox.Text);
|
||||||
try
|
if (_company - pos != null)
|
||||||
{
|
{
|
||||||
if (_company - pos != null)
|
MessageBox.Show("Объект удалён");
|
||||||
{
|
pictureBox.Image = _company.Show();
|
||||||
MessageBox.Show("Объект удален");
|
|
||||||
pictureBox.Image = _company.Show();
|
|
||||||
_logger.LogInformation("Удален объект по позиции " + pos);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MessageBox.Show($"Не удалось удалить объект");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
else
|
||||||
{
|
{
|
||||||
MessageBox.Show(ex.Message);
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonGoToCheck_Click(object sender, EventArgs e)
|
private void buttonGoToCheck_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_company == null)
|
if (_company == null) return;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
DrawningBus? bus = null;
|
DrawningBus? bus = null;
|
||||||
int counter = 100;
|
int counter = 100;
|
||||||
while (bus == null)
|
while (bus == null || counter > 0)
|
||||||
{
|
{
|
||||||
try
|
bus = _company.GetRandomObject();
|
||||||
{
|
counter--;
|
||||||
bus = _company.GetRandomObject();
|
|
||||||
}
|
|
||||||
catch (ObjectNotFoundException)
|
|
||||||
{
|
|
||||||
counter--;
|
|
||||||
if (counter <= 0)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (bus == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (bus == null) return;
|
||||||
|
|
||||||
FormAccordionBus form = new()
|
FormAccordionBus form = new()
|
||||||
{
|
{
|
||||||
SetBus = bus
|
SetBus = bus
|
||||||
@ -232,12 +193,10 @@ public partial class FormBusCollection : Form
|
|||||||
|
|
||||||
private void buttonCollectionAdd_Click(object sender, EventArgs e)
|
private void buttonCollectionAdd_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(textBoxCollectionName.Text) ||
|
if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonList.Checked && !radioButtonMassive.Checked))
|
||||||
(!radioButtonList.Checked && !radioButtonMassive.Checked))
|
|
||||||
{
|
{
|
||||||
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
_logger.LogWarning("Не заполненная коллекция");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
CollectionType collectionType = CollectionType.None;
|
CollectionType collectionType = CollectionType.None;
|
||||||
@ -249,8 +208,8 @@ public partial class FormBusCollection : Form
|
|||||||
{
|
{
|
||||||
collectionType = CollectionType.List;
|
collectionType = CollectionType.List;
|
||||||
}
|
}
|
||||||
_storageCollection.AddCollection(textBoxCollectionName.Text, collectionType);
|
_storageCollection.AddCollection(textBoxCollectionName.Text,
|
||||||
_logger.LogInformation($"Добавлена коллекция: {textBoxCollectionName.Text}");
|
collectionType);
|
||||||
RefreshListBoxItems();
|
RefreshListBoxItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,45 +229,43 @@ public partial class FormBusCollection : Form
|
|||||||
|
|
||||||
private void buttonCollectionDel_Click(object sender, EventArgs e)
|
private void buttonCollectionDel_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
|
if (listBoxCollection.SelectedItem == null) return;
|
||||||
|
|
||||||
|
if (MessageBox.Show("Вы действительно хотите удалить выбранный элемент?",
|
||||||
|
"Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Коллекция не выбрана");
|
_storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
|
||||||
_logger.LogWarning("Удаление невыбранной коллекции");
|
RefreshListBoxItems();
|
||||||
return;
|
MessageBox.Show("Компания удалена");
|
||||||
}
|
}
|
||||||
string name = listBoxCollection.SelectedItem.ToString() ?? string.Empty;
|
else
|
||||||
if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
|
||||||
{
|
{
|
||||||
return;
|
MessageBox.Show("Не удалось удалить компанию");
|
||||||
}
|
}
|
||||||
_storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
|
|
||||||
_logger.LogInformation($"Удалена коллекция: {name}");
|
|
||||||
RefreshListBoxItems();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonCreateCompany_Click(object sender, EventArgs e)
|
private void buttonCreateCompany_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
|
if (listBoxCollection.SelectedIndex < 0)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Коллекция не выбрана");
|
MessageBox.Show("Компания не выбрана");
|
||||||
_logger.LogWarning("Создание компании невыбранной коллекции");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ICollectionGenericObjects<DrawningBus>? collection =
|
|
||||||
_storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
|
ICollectionGenericObjects<DrawningBus?> collection = _storageCollection[listBoxCollection.SelectedItem?.ToString() ?? string.Empty];
|
||||||
if (collection == null)
|
if (collection == null)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Коллекция не проинициализирована");
|
MessageBox.Show("Компания не инициализирована");
|
||||||
_logger.LogWarning("Не удалось инициализировать коллекцию");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (comboBoxSelectorCompany.Text)
|
switch (comboBoxSelectorCompany.Text)
|
||||||
{
|
{
|
||||||
case "Хранилище":
|
case "Хранилище":
|
||||||
_company = new BusSharingService(pictureBox.Width,
|
_company = new BusSharingService(pictureBox.Width, pictureBox.Height, collection);
|
||||||
pictureBox.Height, collection);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
panelCompanyTools.Enabled = true;
|
panelCompanyTools.Enabled = true;
|
||||||
RefreshListBoxItems();
|
RefreshListBoxItems();
|
||||||
}
|
}
|
||||||
@ -317,16 +274,13 @@ public partial class FormBusCollection : Form
|
|||||||
{
|
{
|
||||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
try
|
if (_storageCollection.SaveData(saveFileDialog.FileName))
|
||||||
{
|
{
|
||||||
_storageCollection.SaveData(saveFileDialog.FileName);
|
|
||||||
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
_logger.LogInformation("Сохранение в файл: {filename}", saveFileDialog.FileName);
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
else
|
||||||
{
|
{
|
||||||
MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -335,17 +289,14 @@ public partial class FormBusCollection : Form
|
|||||||
{
|
{
|
||||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
try
|
if (_storageCollection.LoadData(openFileDialog.FileName))
|
||||||
{
|
{
|
||||||
_storageCollection.LoadData(openFileDialog.FileName);
|
MessageBox.Show("Загрузка прошла успешно", "Реузльтат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
||||||
_logger.LogInformation("Загрузка из файла: {filename}", saveFileDialog.FileName);
|
|
||||||
RefreshListBoxItems();
|
RefreshListBoxItems();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
else
|
||||||
{
|
{
|
||||||
MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,40 +1,17 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
namespace ProjectAccordionBus
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Serilog;
|
|
||||||
|
|
||||||
namespace ProjectAccordionBus;
|
|
||||||
|
|
||||||
internal static class Program
|
|
||||||
{
|
{
|
||||||
/// <summary>
|
internal static class Program
|
||||||
/// The main entry point for the application.
|
|
||||||
/// </summary>
|
|
||||||
[STAThread]
|
|
||||||
static void Main()
|
|
||||||
{
|
{
|
||||||
// To customize application configuration such as set high DPI settings or default font,
|
/// <summary>
|
||||||
// see https://aka.ms/applicationconfiguration.
|
/// The main entry point for the application.
|
||||||
ApplicationConfiguration.Initialize();
|
/// </summary>
|
||||||
|
[STAThread]
|
||||||
ServiceCollection services = new();
|
static void Main()
|
||||||
ConfigureServices(services);
|
{
|
||||||
using ServiceProvider serviceProvider = services.BuildServiceProvider();
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
Application.Run(serviceProvider.GetRequiredService<FormBusCollection>());
|
// see https://aka.ms/applicationconfiguration.
|
||||||
|
ApplicationConfiguration.Initialize();
|
||||||
|
Application.Run(new FormBusCollection());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
private static void ConfigureServices(ServiceCollection services)
|
|
||||||
{
|
|
||||||
services
|
|
||||||
.AddSingleton<FormBusCollection>()
|
|
||||||
.AddLogging(option =>
|
|
||||||
{
|
|
||||||
option.SetMinimumLevel(LogLevel.Information);
|
|
||||||
var config = new ConfigurationBuilder()
|
|
||||||
.AddJsonFile("serilogConfig.json", optional: false, reloadOnChange: true)
|
|
||||||
.Build();
|
|
||||||
option.AddSerilog(Log.Logger = new LoggerConfiguration()
|
|
||||||
.ReadFrom.Configuration(config)
|
|
||||||
.CreateLogger());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -8,20 +8,6 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.0" />
|
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
|
||||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.11" />
|
|
||||||
<PackageReference Include="Serilog" Version="3.1.1" />
|
|
||||||
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" />
|
|
||||||
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
|
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Update="Properties\Resources.Designer.cs">
|
<Compile Update="Properties\Resources.Designer.cs">
|
||||||
<DesignTime>True</DesignTime>
|
<DesignTime>True</DesignTime>
|
||||||
@ -37,13 +23,4 @@
|
|||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<None Update="nlog.config">
|
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
<None Update="serilogConfig.json">
|
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
@ -1,15 +0,0 @@
|
|||||||
<?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>
|
|
@ -1,20 +0,0 @@
|
|||||||
{
|
|
||||||
"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": "Linkor"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user