Правки
This commit is contained in:
parent
438b1653bc
commit
7624745b9d
@ -41,8 +41,8 @@ public abstract class AbstractCompany
|
||||
/// <summary>
|
||||
/// Вычисление максимального количества элементов, который можно разместить в окне
|
||||
/// </summary>
|
||||
private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);
|
||||
|
||||
//private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);
|
||||
private int GetMaxCount => 36;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
@ -97,10 +97,14 @@ public abstract class AbstractCompany
|
||||
DrawBackgound(graphics);
|
||||
SetObjectsPosition();
|
||||
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
|
||||
{
|
||||
try
|
||||
{
|
||||
DrawningBus? obj = _collection?.Get(i);
|
||||
obj?.DrawTransport(graphics);
|
||||
}
|
||||
catch (Exception) { }
|
||||
}
|
||||
return bitmap;
|
||||
}
|
||||
/// <summary>
|
||||
|
@ -36,23 +36,24 @@ public class BusSharingService : AbstractCompany
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
int height = _pictureHeight / _placeSizeHeight;
|
||||
|
||||
int BusWidth = width - 1;
|
||||
int BusHeight = height - 1;
|
||||
int BusWidth = 0;
|
||||
int BusHeight = 0;
|
||||
|
||||
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 * BusWidth + 20, BusHeight * _placeSizeHeight + 20);
|
||||
}
|
||||
catch (Exception) { }
|
||||
|
||||
if (BusWidth > 0)
|
||||
BusWidth--;
|
||||
if (BusWidth < width - 1)
|
||||
BusWidth++;
|
||||
else
|
||||
{
|
||||
BusWidth = width - 1;
|
||||
BusHeight--;
|
||||
BusWidth = 0;
|
||||
BusHeight++;
|
||||
}
|
||||
if (BusHeight > height)
|
||||
{
|
||||
|
@ -56,6 +56,10 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
{
|
||||
throw new PositionOutOfCollectionException(position);
|
||||
}
|
||||
if (_collection[position] == null)
|
||||
{
|
||||
throw new ObjectNotFoundException(position);
|
||||
}
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
|
@ -99,6 +99,7 @@ public class StorageCollection<T>
|
||||
/// <returns>true - сохранение прошло успешно, false - ошибка при сохранении данных</returns>
|
||||
public void SaveData(string filename)
|
||||
{
|
||||
|
||||
if (_storages.Count == 0)
|
||||
{
|
||||
throw new Exception("В хранилище отсутствуют коллекции для сохранения");
|
||||
@ -150,10 +151,13 @@ public class StorageCollection<T>
|
||||
{
|
||||
throw new Exception("Файл не существует");
|
||||
}
|
||||
using (StreamReader fs = File.OpenText(filename))
|
||||
{
|
||||
string str = fs.ReadLine();
|
||||
if (str == null || str.Length == 0)
|
||||
using StreamReader rd = new StreamReader(filename);
|
||||
|
||||
|
||||
UTF8Encoding temp = new(true);
|
||||
string str = rd.ReadLine();
|
||||
|
||||
if (str == null)
|
||||
{
|
||||
throw new Exception("В файле нет данных");
|
||||
}
|
||||
@ -161,9 +165,10 @@ public class StorageCollection<T>
|
||||
{
|
||||
throw new Exception("В файле неверные данные");
|
||||
}
|
||||
|
||||
_storages.Clear();
|
||||
string strs = "";
|
||||
while ((strs = fs.ReadLine()) != null)
|
||||
while ((strs = rd.ReadLine()) != null)
|
||||
{
|
||||
string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (record.Length != 4)
|
||||
@ -174,7 +179,7 @@ public class StorageCollection<T>
|
||||
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionType);
|
||||
if (collection == null)
|
||||
{
|
||||
throw new Exception("Не удалось определить тип коллекции:" + record[1]);
|
||||
throw new Exception("Не удалось создать коллекции");
|
||||
}
|
||||
collection.MaxCount = Convert.ToInt32(record[2]);
|
||||
string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
|
||||
@ -184,7 +189,7 @@ public class StorageCollection<T>
|
||||
{
|
||||
try
|
||||
{
|
||||
if (collection.Insert(bus) == -1)
|
||||
if (collection.Insert(bus) < 0)
|
||||
{
|
||||
throw new Exception("Объект не удалось добавить в коллекцию: " + record[3]);
|
||||
}
|
||||
@ -193,12 +198,12 @@ public class StorageCollection<T>
|
||||
{
|
||||
throw new Exception("Коллекция переполнена", ex);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
_storages.Add(record[0], collection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создание коллекции по типу
|
||||
@ -206,7 +211,7 @@ public class StorageCollection<T>
|
||||
/// <param name="collectionType"></param>
|
||||
/// <returns></returns>
|
||||
private static ICollectionGenericObjects<T>?
|
||||
CreateCollection(CollectionType collectionType)
|
||||
CreateCollection(CollectionType collectionType)
|
||||
{
|
||||
return collectionType switch
|
||||
{
|
||||
|
@ -38,6 +38,7 @@ namespace ProjectAirbus
|
||||
InitializeComponent();
|
||||
_storageCollection = new();
|
||||
_logger = logger;
|
||||
_logger.LogInformation("Форма загрузилась");
|
||||
}
|
||||
|
||||
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
|
||||
@ -53,6 +54,8 @@ namespace ProjectAirbus
|
||||
}
|
||||
|
||||
private void SetBus(DrawningBus? bus)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_company == null || bus == null)
|
||||
{
|
||||
@ -62,10 +65,14 @@ namespace ProjectAirbus
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _company.Show();
|
||||
_logger.LogInformation("Объект добавлен");
|
||||
}
|
||||
else
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
_logger.LogWarning($"Ошибка: {ex.Message}");
|
||||
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
@ -85,14 +92,19 @@ namespace ProjectAirbus
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
try
|
||||
{
|
||||
if (_company - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBox.Image = _company.Show();
|
||||
_logger.LogInformation("Объект удален");
|
||||
}
|
||||
else
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -165,6 +177,7 @@ namespace ProjectAirbus
|
||||
collectionType = CollectionType.List;
|
||||
}
|
||||
_storageCollection.AddCollection(textBoxCollectionName.Text, collectionType);
|
||||
_logger.LogInformation("Коллекция добавлена " + textBoxCollectionName.Text);
|
||||
RerfreshListBoxItems();
|
||||
}
|
||||
|
||||
@ -206,6 +219,7 @@ namespace ProjectAirbus
|
||||
return;
|
||||
}
|
||||
_storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
|
||||
_logger.LogInformation("Коллекция с название: " + listBoxCollection.SelectedItem.ToString() + " удалена");
|
||||
RerfreshListBoxItems();
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
autoReload="true" internalLogLevel="Info">
|
||||
|
||||
<targets>
|
||||
<target xsi:type="File" name="tofile" fileName="carlog-${shortdate}.log" />
|
||||
<target xsi:type="File" name="tofile" fileName="buslog-${shortdate}.log" />
|
||||
</targets>
|
||||
<rules>
|
||||
<logger name="*" minlevel="Debug" writeTo="tofile" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user