Lab8(Exception)
This commit is contained in:
parent
c2e139d3e3
commit
0ae3e3887e
@ -31,7 +31,7 @@ public abstract class AbstractCompany
|
|||||||
|
|
||||||
public static int operator +(AbstractCompany company, DrawingBase sau)
|
public static int operator +(AbstractCompany company, DrawingBase sau)
|
||||||
{
|
{
|
||||||
return company._collection.Insert(sau);
|
return company._collection.Insert(sau, new DrawingSAUEqutables());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DrawingBase operator -(AbstractCompany company, int position)
|
public static DrawingBase operator -(AbstractCompany company, int position)
|
||||||
@ -66,4 +66,5 @@ public abstract class AbstractCompany
|
|||||||
|
|
||||||
protected abstract void SetObjectPosition(int position, int MaxPos, DrawingBase? sau);
|
protected abstract void SetObjectPosition(int position, int MaxPos, DrawingBase? sau);
|
||||||
|
|
||||||
|
public void Sort(IComparer<DrawingBase?> comparer) => _collection?.CollectionSort(comparer);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,58 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Project_SelfPropelledArtilleryUnit.CollectionGenericObjects;
|
||||||
|
|
||||||
|
internal class CollectionInfo : IEquatable<CollectionInfo>
|
||||||
|
{
|
||||||
|
public string Name { get; private set; }
|
||||||
|
|
||||||
|
|
||||||
|
public CollectionType CollectionType { get; private set; }
|
||||||
|
|
||||||
|
public string Description { get; private set; }
|
||||||
|
|
||||||
|
private static readonly string _separator = "-";
|
||||||
|
|
||||||
|
|
||||||
|
public CollectionInfo(string name, CollectionType collectionType, string description)
|
||||||
|
{
|
||||||
|
Name = name;
|
||||||
|
CollectionType = collectionType;
|
||||||
|
Description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CollectionInfo? GetCollectionInfo(string data)
|
||||||
|
{
|
||||||
|
string[] strs = data.Split(_separator, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
if (strs.Length < 1 || strs.Length > 3)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new CollectionInfo(strs[0], (CollectionType)Enum.Parse(typeof(CollectionType), strs[1]), strs.Length > 2 ? strs[2] : string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return Name + _separator + CollectionType + _separator + Description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Equals(CollectionInfo? other)
|
||||||
|
{
|
||||||
|
return Name == other?.Name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object? obj)
|
||||||
|
{
|
||||||
|
return Equals(obj as CollectionInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return Name.GetHashCode();
|
||||||
|
}
|
||||||
|
}
|
@ -11,11 +11,12 @@ public interface ICollectionGenericObjects<T>
|
|||||||
{
|
{
|
||||||
int Count { get; }
|
int Count { get; }
|
||||||
int MaxCount { get; set; }
|
int MaxCount { get; set; }
|
||||||
int Insert(T obj);
|
int Insert(T obj, IEqualityComparer<T?>? comparer = null);
|
||||||
int Insert(T obj, int position);
|
int Insert(T obj, int position, IEqualityComparer<T?>? comparer = null);
|
||||||
T? Remove(int position);
|
T? Remove(int position);
|
||||||
T? Get(int position);
|
T? Get(int position);
|
||||||
|
|
||||||
CollectionType GetCollectionType { get; }
|
CollectionType GetCollectionType { get; }
|
||||||
IEnumerable<T?> GetItems();
|
IEnumerable<T?> GetItems();
|
||||||
|
void CollectionSort(IComparer<T?> comparer);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using Project_SelfPropelledArtilleryUnit.Exceptions;
|
using Project_SelfPropelledArtilleryUnit.Exceptions;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -44,8 +45,15 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
return _collection[position];
|
return _collection[position];
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Insert(T obj)
|
public int Insert(T obj, IEqualityComparer<T?>? comparer = null)
|
||||||
{
|
{
|
||||||
|
if (comparer != null)
|
||||||
|
{
|
||||||
|
if (_collection.Contains(obj, comparer))
|
||||||
|
{
|
||||||
|
throw new ObjectNotUniqueException();
|
||||||
|
}
|
||||||
|
}
|
||||||
if (Count == _maxCount)
|
if (Count == _maxCount)
|
||||||
{
|
{
|
||||||
throw new CollectionOverflowException(Count);
|
throw new CollectionOverflowException(Count);
|
||||||
@ -54,8 +62,15 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
return Count;
|
return Count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Insert(T obj, int position)
|
public int Insert(T obj, int position, IEqualityComparer<T?>? comparer = null)
|
||||||
{
|
{
|
||||||
|
if (comparer != null)
|
||||||
|
{
|
||||||
|
if (_collection.Contains(obj, comparer))
|
||||||
|
{
|
||||||
|
throw new ObjectNotUniqueException();
|
||||||
|
}
|
||||||
|
}
|
||||||
if (Count == _maxCount)
|
if (Count == _maxCount)
|
||||||
{
|
{
|
||||||
throw new CollectionOverflowException(Count);
|
throw new CollectionOverflowException(Count);
|
||||||
@ -86,4 +101,8 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
yield return _collection[i];
|
yield return _collection[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void ICollectionGenericObjects<T>.CollectionSort(IComparer<T?> comparer)
|
||||||
|
{
|
||||||
|
_collection.Sort(comparer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,8 +52,18 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
return _collection[position];
|
return _collection[position];
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Insert(T obj)
|
public int Insert(T obj, IEqualityComparer<T?>? comparer = null)
|
||||||
{
|
{
|
||||||
|
if (comparer != null)
|
||||||
|
{
|
||||||
|
foreach (T? item in _collection)
|
||||||
|
{
|
||||||
|
if ((comparer as IEqualityComparer<DrawingBase>).Equals(obj as DrawingBase, item as DrawingBase))
|
||||||
|
{
|
||||||
|
throw new ObjectNotUniqueException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
for (int i = 0; i < Count; i++)
|
for (int i = 0; i < Count; i++)
|
||||||
{
|
{
|
||||||
if (_collection[i] == null)
|
if (_collection[i] == null)
|
||||||
@ -66,7 +76,7 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
throw new CollectionOverflowException(Count);
|
throw new CollectionOverflowException(Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Insert(T obj, int position)
|
public int Insert(T obj, int position, IEqualityComparer<T?>? comparer = null)
|
||||||
{
|
{
|
||||||
if (position < 0 || position >= Count)
|
if (position < 0 || position >= Count)
|
||||||
{
|
{
|
||||||
@ -126,4 +136,8 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
yield return _collection[i];
|
yield return _collection[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void ICollectionGenericObjects<T>.CollectionSort(IComparer<T?> comparer)
|
||||||
|
{
|
||||||
|
Array.Sort(_collection, comparer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,9 +11,8 @@ namespace Project_SelfPropelledArtilleryUnit.CollectionGenericObjects;
|
|||||||
internal class StorageCollection<T>
|
internal class StorageCollection<T>
|
||||||
where T : DrawingBase
|
where T : DrawingBase
|
||||||
{
|
{
|
||||||
private Dictionary<string, ICollectionGenericObjects<T>> _storages;
|
readonly Dictionary<CollectionInfo, ICollectionGenericObjects<T>> _storages;
|
||||||
|
public List<CollectionInfo> Keys => _storages.Keys.ToList();
|
||||||
public List<string> Keys => _storages.Keys.ToList();
|
|
||||||
|
|
||||||
private readonly string _collectionKey = "CollectionsStorage";
|
private readonly string _collectionKey = "CollectionsStorage";
|
||||||
|
|
||||||
@ -23,36 +22,47 @@ internal class StorageCollection<T>
|
|||||||
|
|
||||||
public StorageCollection()
|
public StorageCollection()
|
||||||
{
|
{
|
||||||
_storages = new Dictionary<string, ICollectionGenericObjects<T>>();
|
_storages = new Dictionary<CollectionInfo, ICollectionGenericObjects<T>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddCollection(string name, CollectionType collectionType)
|
public void AddCollection(string name, CollectionType collectionType)
|
||||||
{
|
{
|
||||||
if (_storages.ContainsKey(name) || name == "") return;
|
CollectionInfo collectionInfo = new CollectionInfo(name, collectionType, string.Empty);
|
||||||
|
|
||||||
if (collectionType == CollectionType.Massive)
|
if (_storages.ContainsKey(collectionInfo) || collectionInfo.CollectionType == CollectionType.None)
|
||||||
{
|
{
|
||||||
_storages[name] = new MassiveGenericObjects<T>();
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
switch (collectionInfo.CollectionType)
|
||||||
{
|
{
|
||||||
_storages[name] = new ListGenericObjects<T>();
|
case CollectionType.Massive:
|
||||||
|
_storages[collectionInfo] = new MassiveGenericObjects<T>();
|
||||||
|
break;
|
||||||
|
case CollectionType.List:
|
||||||
|
_storages[collectionInfo] = new ListGenericObjects<T>();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void DelCollection(string name)
|
public void DelCollection(string name)
|
||||||
{
|
{
|
||||||
_storages.Remove(name);
|
CollectionInfo collectionInfo = new CollectionInfo(name, CollectionType.None, string.Empty);
|
||||||
|
if (_storages.ContainsKey(collectionInfo) && collectionInfo != null)
|
||||||
|
{
|
||||||
|
_storages.Remove(collectionInfo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICollectionGenericObjects<T>? this[string name]
|
public ICollectionGenericObjects<T>? this[string name]
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (name == "")
|
CollectionInfo collectionInfo = new CollectionInfo(name, CollectionType.None, string.Empty);
|
||||||
|
if (_storages.ContainsKey(collectionInfo))
|
||||||
{
|
{
|
||||||
return null;
|
return _storages[collectionInfo];
|
||||||
}
|
}
|
||||||
return _storages[name];
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,23 +78,24 @@ internal class StorageCollection<T>
|
|||||||
File.Delete(filename);
|
File.Delete(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
using (StreamWriter writer = new(filename))
|
using (StreamWriter writer = new StreamWriter(filename))
|
||||||
{
|
{
|
||||||
writer.Write(_collectionKey);
|
writer.Write(_collectionKey);
|
||||||
foreach (KeyValuePair<string, ICollectionGenericObjects<T>> value in _storages)
|
foreach (KeyValuePair<CollectionInfo, ICollectionGenericObjects<T>> value in _storages)
|
||||||
{
|
{
|
||||||
writer.Write(Environment.NewLine);
|
StringBuilder sb = new();
|
||||||
|
|
||||||
|
sb.Append(Environment.NewLine);
|
||||||
// не сохраняем пустые коллекции
|
// не сохраняем пустые коллекции
|
||||||
if (value.Value.Count == 0)
|
if (value.Value.Count == 0)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
writer.Write(value.Key);
|
|
||||||
writer.Write(_separatorForKeyValue);
|
sb.Append(value.Key);
|
||||||
writer.Write(value.Value.GetCollectionType);
|
sb.Append(_separatorForKeyValue);
|
||||||
writer.Write(_separatorForKeyValue);
|
sb.Append(value.Value.MaxCount);
|
||||||
writer.Write(value.Value.MaxCount);
|
sb.Append(_separatorForKeyValue);
|
||||||
writer.Write(_separatorForKeyValue);
|
|
||||||
|
|
||||||
foreach (T? item in value.Value.GetItems())
|
foreach (T? item in value.Value.GetItems())
|
||||||
{
|
{
|
||||||
@ -93,9 +104,12 @@ internal class StorageCollection<T>
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
writer.Write(data);
|
|
||||||
writer.Write(_separatorItems);
|
sb.Append(data);
|
||||||
|
sb.Append(_separatorItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
writer.Write(sb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -106,43 +120,44 @@ internal class StorageCollection<T>
|
|||||||
{
|
{
|
||||||
throw new FileNotFoundException("Файл не существует");
|
throw new FileNotFoundException("Файл не существует");
|
||||||
}
|
}
|
||||||
using (StreamReader reader = new(filename))
|
using (StreamReader fs = File.OpenText(filename))
|
||||||
{
|
{
|
||||||
string line = reader.ReadLine();
|
string str = fs.ReadLine();
|
||||||
if (line == null || line.Length == 0)
|
|
||||||
|
if (str == null || str.Length == 0)
|
||||||
{
|
{
|
||||||
throw new IOException("В файле нет данных");
|
throw new IOException("В файле нет данных");
|
||||||
}
|
}
|
||||||
if (!line.Equals(_collectionKey))
|
|
||||||
|
if (!str.StartsWith(_collectionKey))
|
||||||
{
|
{
|
||||||
throw new IOException("В файле неверные данные");
|
throw new IOException("В файле неверные данные");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_storages.Clear();
|
_storages.Clear();
|
||||||
while ((line = reader.ReadLine()) != null)
|
string strs = "";
|
||||||
|
while ((strs = fs.ReadLine()) != null)
|
||||||
{
|
{
|
||||||
string[] record = line.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||||
if (record.Length != 4)
|
if (record.Length != 3)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
|
|
||||||
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionType);
|
CollectionInfo? collectionInfo = CollectionInfo.GetCollectionInfo(record[0]) ??
|
||||||
if (collection == null)
|
throw new Exception("Не удалось определить информацию коллекции:" + record[0]);
|
||||||
{
|
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionInfo.CollectionType) ??
|
||||||
throw new IOException("В файле нет данных");
|
throw new Exception("Не удалось определить тип коллекции: " + record[1]);
|
||||||
}
|
collection.MaxCount = Convert.ToInt32(record[1]);
|
||||||
collection.MaxCount = Convert.ToInt32(record[2]);
|
|
||||||
string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
|
string[] set = record[2].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
|
||||||
foreach (string elem in set)
|
foreach (string elem in set)
|
||||||
{
|
{
|
||||||
if (elem?.CreateDrawningBase() is T truck)
|
if (elem?.CreateDrawningBase() is T airbus)
|
||||||
{
|
|
||||||
if (collection.Insert(truck) == -1)
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (collection.Insert(truck) == -1)
|
if (collection.Insert(airbus) == -1)
|
||||||
{
|
{
|
||||||
throw new Exception("Объект не удалось добавить в коллекцию: " + record[3]);
|
throw new Exception("Объект не удалось добавить в коллекцию: " + record[3]);
|
||||||
}
|
}
|
||||||
@ -153,21 +168,20 @@ internal class StorageCollection<T>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
_storages.Add(collectionInfo, collection);
|
||||||
_storages.Add(record[0], collection);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static ICollectionGenericObjects<T>?
|
private static ICollectionGenericObjects<T>? CreateCollection(CollectionType collectionType)
|
||||||
CreateCollection(CollectionType collectionType)
|
|
||||||
{
|
{
|
||||||
return collectionType switch
|
return collectionType switch
|
||||||
{
|
{
|
||||||
CollectionType.Massive => new MassiveGenericObjects<T>(),
|
CollectionType.Massive => new MassiveGenericObjects<T>(),
|
||||||
CollectionType.List => new ListGenericObjects<T>(),
|
CollectionType.List => new ListGenericObjects<T>(),
|
||||||
_ => null,
|
_ => null
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,45 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Project_SelfPropelledArtilleryUnit.Entity;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
|
||||||
|
namespace Project_SelfPropelledArtilleryUnit.Drawings;
|
||||||
|
|
||||||
|
public class DrawingSAUEqutables : IEqualityComparer<DrawingBase?>
|
||||||
|
{
|
||||||
|
public bool Equals(DrawingBase? x, DrawingBase? y)
|
||||||
|
{
|
||||||
|
if (x == null || x.BaseSAU == null) return false;
|
||||||
|
|
||||||
|
if (y == null || y.BaseSAU == null) return false;
|
||||||
|
|
||||||
|
if (x.GetType().Name != y.GetType().Name) return false;
|
||||||
|
|
||||||
|
if (x.BaseSAU.Speed != y.BaseSAU.Speed) return false;
|
||||||
|
|
||||||
|
if (x.BaseSAU.Weight != y.BaseSAU.Weight) return false;
|
||||||
|
|
||||||
|
if (x.BaseSAU.BodyColor != y.BaseSAU.BodyColor) return false;
|
||||||
|
|
||||||
|
if (x is DrawingSAU bigX && y is DrawingSAU bigY)
|
||||||
|
{
|
||||||
|
|
||||||
|
EntitySAU _x = (EntitySAU)x.BaseSAU;
|
||||||
|
EntitySAU _y = (EntitySAU)y.BaseSAU;
|
||||||
|
|
||||||
|
if (_x.Tracks != _y.Tracks) return false;
|
||||||
|
if (_x.Guns != _y.Guns) return false;
|
||||||
|
if (_x.AdditionalColor != _y.AdditionalColor) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetHashCode([DisallowNull] DrawingBase obj)
|
||||||
|
{
|
||||||
|
return obj.GetHashCode();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Project_SelfPropelledArtilleryUnit.Drawings;
|
||||||
|
|
||||||
|
public class SAUCompareByColor : IComparer<DrawingBase?>
|
||||||
|
{
|
||||||
|
public int Compare(DrawingBase? x, DrawingBase? y)
|
||||||
|
{
|
||||||
|
if (x == null || x.BaseSAU == null) return 1;
|
||||||
|
|
||||||
|
if (y == null || y.BaseSAU == null) return -1;
|
||||||
|
|
||||||
|
var bodycolorCompare = x.BaseSAU.BodyColor.Name.CompareTo(y.BaseSAU.BodyColor.Name);
|
||||||
|
if (bodycolorCompare != 0) return bodycolorCompare;
|
||||||
|
|
||||||
|
var speedCompare = x.BaseSAU.Speed.CompareTo(y.BaseSAU.Speed);
|
||||||
|
if (speedCompare != 0) return speedCompare;
|
||||||
|
|
||||||
|
return x.BaseSAU.Weight.CompareTo(y.BaseSAU.Weight);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Project_SelfPropelledArtilleryUnit.Drawings;
|
||||||
|
|
||||||
|
public class SAUCompareByType : IComparer<DrawingBase?>
|
||||||
|
{
|
||||||
|
public int Compare(DrawingBase? x, DrawingBase? y)
|
||||||
|
{
|
||||||
|
if (x == null || x.BaseSAU == null) return 1;
|
||||||
|
|
||||||
|
if (y == null || y.BaseSAU == null) return -1;
|
||||||
|
|
||||||
|
if (x.GetType().Name != y.GetType().Name) return x.GetType().Name.CompareTo(y.GetType().Name);
|
||||||
|
|
||||||
|
var speedCompare = x.BaseSAU.Speed.CompareTo(y.BaseSAU.Speed);
|
||||||
|
if (speedCompare != 0) return speedCompare;
|
||||||
|
|
||||||
|
return x.BaseSAU.Weight.CompareTo(y.BaseSAU.Weight);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
|
|
||||||
|
namespace Project_SelfPropelledArtilleryUnit.Exceptions;
|
||||||
|
[Serializable]
|
||||||
|
|
||||||
|
internal class ObjectNotUniqueException: ApplicationException
|
||||||
|
{
|
||||||
|
public ObjectNotUniqueException(object i) : base("В коллекции уже есть такой элемент " + i) { }
|
||||||
|
public ObjectNotUniqueException() : base() { }
|
||||||
|
public ObjectNotUniqueException(string message) : base(message) { }
|
||||||
|
public ObjectNotUniqueException(string message, Exception exception) : base(message, exception)
|
||||||
|
{ }
|
||||||
|
protected ObjectNotUniqueException(SerializationInfo info, StreamingContext context) : base(info, context) { }
|
||||||
|
}
|
@ -52,6 +52,8 @@
|
|||||||
loadToolStripMenuItem = new ToolStripMenuItem();
|
loadToolStripMenuItem = new ToolStripMenuItem();
|
||||||
saveFileDialog = new SaveFileDialog();
|
saveFileDialog = new SaveFileDialog();
|
||||||
openFileDialog = new OpenFileDialog();
|
openFileDialog = new OpenFileDialog();
|
||||||
|
buttonSortByType = new Button();
|
||||||
|
buttonSortByColor = new Button();
|
||||||
groupBoxTools.SuspendLayout();
|
groupBoxTools.SuspendLayout();
|
||||||
panelCompanyTools.SuspendLayout();
|
panelCompanyTools.SuspendLayout();
|
||||||
panelStorage.SuspendLayout();
|
panelStorage.SuspendLayout();
|
||||||
@ -66,13 +68,15 @@
|
|||||||
groupBoxTools.Dock = DockStyle.Right;
|
groupBoxTools.Dock = DockStyle.Right;
|
||||||
groupBoxTools.Location = new Point(1123, 28);
|
groupBoxTools.Location = new Point(1123, 28);
|
||||||
groupBoxTools.Name = "groupBoxTools";
|
groupBoxTools.Name = "groupBoxTools";
|
||||||
groupBoxTools.Size = new Size(218, 639);
|
groupBoxTools.Size = new Size(218, 669);
|
||||||
groupBoxTools.TabIndex = 0;
|
groupBoxTools.TabIndex = 0;
|
||||||
groupBoxTools.TabStop = false;
|
groupBoxTools.TabStop = false;
|
||||||
groupBoxTools.Text = "Инструменты";
|
groupBoxTools.Text = "Инструменты";
|
||||||
//
|
//
|
||||||
// panelCompanyTools
|
// panelCompanyTools
|
||||||
//
|
//
|
||||||
|
panelCompanyTools.Controls.Add(buttonSortByColor);
|
||||||
|
panelCompanyTools.Controls.Add(buttonSortByType);
|
||||||
panelCompanyTools.Controls.Add(buttonAddBaseSAU);
|
panelCompanyTools.Controls.Add(buttonAddBaseSAU);
|
||||||
panelCompanyTools.Controls.Add(buttonUpdate);
|
panelCompanyTools.Controls.Add(buttonUpdate);
|
||||||
panelCompanyTools.Controls.Add(buttonGoToCheck);
|
panelCompanyTools.Controls.Add(buttonGoToCheck);
|
||||||
@ -80,9 +84,9 @@
|
|||||||
panelCompanyTools.Controls.Add(buttonRemoveSAU);
|
panelCompanyTools.Controls.Add(buttonRemoveSAU);
|
||||||
panelCompanyTools.Dock = DockStyle.Bottom;
|
panelCompanyTools.Dock = DockStyle.Bottom;
|
||||||
panelCompanyTools.Enabled = false;
|
panelCompanyTools.Enabled = false;
|
||||||
panelCompanyTools.Location = new Point(3, 367);
|
panelCompanyTools.Location = new Point(3, 370);
|
||||||
panelCompanyTools.Name = "panelCompanyTools";
|
panelCompanyTools.Name = "panelCompanyTools";
|
||||||
panelCompanyTools.Size = new Size(212, 269);
|
panelCompanyTools.Size = new Size(212, 296);
|
||||||
panelCompanyTools.TabIndex = 10;
|
panelCompanyTools.TabIndex = 10;
|
||||||
//
|
//
|
||||||
// buttonAddBaseSAU
|
// buttonAddBaseSAU
|
||||||
@ -97,7 +101,7 @@
|
|||||||
//
|
//
|
||||||
// buttonUpdate
|
// buttonUpdate
|
||||||
//
|
//
|
||||||
buttonUpdate.Location = new Point(3, 224);
|
buttonUpdate.Location = new Point(3, 246);
|
||||||
buttonUpdate.Name = "buttonUpdate";
|
buttonUpdate.Name = "buttonUpdate";
|
||||||
buttonUpdate.Size = new Size(203, 41);
|
buttonUpdate.Size = new Size(203, 41);
|
||||||
buttonUpdate.TabIndex = 8;
|
buttonUpdate.TabIndex = 8;
|
||||||
@ -107,7 +111,7 @@
|
|||||||
//
|
//
|
||||||
// buttonGoToCheck
|
// buttonGoToCheck
|
||||||
//
|
//
|
||||||
buttonGoToCheck.Location = new Point(3, 177);
|
buttonGoToCheck.Location = new Point(3, 133);
|
||||||
buttonGoToCheck.Name = "buttonGoToCheck";
|
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||||
buttonGoToCheck.Size = new Size(203, 41);
|
buttonGoToCheck.Size = new Size(203, 41);
|
||||||
buttonGoToCheck.TabIndex = 7;
|
buttonGoToCheck.TabIndex = 7;
|
||||||
@ -117,7 +121,7 @@
|
|||||||
//
|
//
|
||||||
// maskedTextBox
|
// maskedTextBox
|
||||||
//
|
//
|
||||||
maskedTextBox.Location = new Point(3, 97);
|
maskedTextBox.Location = new Point(3, 53);
|
||||||
maskedTextBox.Mask = "00";
|
maskedTextBox.Mask = "00";
|
||||||
maskedTextBox.Name = "maskedTextBox";
|
maskedTextBox.Name = "maskedTextBox";
|
||||||
maskedTextBox.Size = new Size(203, 27);
|
maskedTextBox.Size = new Size(203, 27);
|
||||||
@ -126,7 +130,7 @@
|
|||||||
//
|
//
|
||||||
// buttonRemoveSAU
|
// buttonRemoveSAU
|
||||||
//
|
//
|
||||||
buttonRemoveSAU.Location = new Point(3, 130);
|
buttonRemoveSAU.Location = new Point(3, 86);
|
||||||
buttonRemoveSAU.Name = "buttonRemoveSAU";
|
buttonRemoveSAU.Name = "buttonRemoveSAU";
|
||||||
buttonRemoveSAU.Size = new Size(203, 41);
|
buttonRemoveSAU.Size = new Size(203, 41);
|
||||||
buttonRemoveSAU.TabIndex = 6;
|
buttonRemoveSAU.TabIndex = 6;
|
||||||
@ -243,7 +247,7 @@
|
|||||||
pictureBox.Dock = DockStyle.Fill;
|
pictureBox.Dock = DockStyle.Fill;
|
||||||
pictureBox.Location = new Point(0, 28);
|
pictureBox.Location = new Point(0, 28);
|
||||||
pictureBox.Name = "pictureBox";
|
pictureBox.Name = "pictureBox";
|
||||||
pictureBox.Size = new Size(1123, 639);
|
pictureBox.Size = new Size(1123, 669);
|
||||||
pictureBox.TabIndex = 4;
|
pictureBox.TabIndex = 4;
|
||||||
pictureBox.TabStop = false;
|
pictureBox.TabStop = false;
|
||||||
//
|
//
|
||||||
@ -288,11 +292,31 @@
|
|||||||
//
|
//
|
||||||
openFileDialog.Filter = "txt file | *.txt";
|
openFileDialog.Filter = "txt file | *.txt";
|
||||||
//
|
//
|
||||||
|
// buttonSortByType
|
||||||
|
//
|
||||||
|
buttonSortByType.Location = new Point(3, 177);
|
||||||
|
buttonSortByType.Name = "buttonSortByType";
|
||||||
|
buttonSortByType.Size = new Size(97, 63);
|
||||||
|
buttonSortByType.TabIndex = 9;
|
||||||
|
buttonSortByType.Text = "Сортировка по типу";
|
||||||
|
buttonSortByType.UseVisualStyleBackColor = true;
|
||||||
|
buttonSortByType.Click += buttonSortByType_Click;
|
||||||
|
//
|
||||||
|
// buttonSortByColor
|
||||||
|
//
|
||||||
|
buttonSortByColor.Location = new Point(106, 177);
|
||||||
|
buttonSortByColor.Name = "buttonSortByColor";
|
||||||
|
buttonSortByColor.Size = new Size(97, 63);
|
||||||
|
buttonSortByColor.TabIndex = 10;
|
||||||
|
buttonSortByColor.Text = "Сортировка по цвету";
|
||||||
|
buttonSortByColor.UseVisualStyleBackColor = true;
|
||||||
|
buttonSortByColor.Click += buttonSortByColor_Click;
|
||||||
|
//
|
||||||
// FormSAUCollection
|
// FormSAUCollection
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(1341, 667);
|
ClientSize = new Size(1341, 697);
|
||||||
Controls.Add(pictureBox);
|
Controls.Add(pictureBox);
|
||||||
Controls.Add(groupBoxTools);
|
Controls.Add(groupBoxTools);
|
||||||
Controls.Add(menuStrip);
|
Controls.Add(menuStrip);
|
||||||
@ -337,5 +361,7 @@
|
|||||||
private ToolStripMenuItem loadToolStripMenuItem;
|
private ToolStripMenuItem loadToolStripMenuItem;
|
||||||
private SaveFileDialog saveFileDialog;
|
private SaveFileDialog saveFileDialog;
|
||||||
private OpenFileDialog openFileDialog;
|
private OpenFileDialog openFileDialog;
|
||||||
|
private Button buttonSortByColor;
|
||||||
|
private Button buttonSortByType;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -165,7 +165,7 @@ public partial class FormSAUCollection : Form
|
|||||||
listBoxCollection.Items.Clear();
|
listBoxCollection.Items.Clear();
|
||||||
for (int i = 0; i < _storageCollection.Keys?.Count; ++i)
|
for (int i = 0; i < _storageCollection.Keys?.Count; ++i)
|
||||||
{
|
{
|
||||||
string? colName = _storageCollection.Keys?[i];
|
string? colName = _storageCollection.Keys?[i].Name;
|
||||||
if (!string.IsNullOrEmpty(colName))
|
if (!string.IsNullOrEmpty(colName))
|
||||||
{
|
{
|
||||||
listBoxCollection.Items.Add(colName);
|
listBoxCollection.Items.Add(colName);
|
||||||
@ -262,4 +262,24 @@ public partial class FormSAUCollection : Form
|
|||||||
}
|
}
|
||||||
UpdateListBoxItems();
|
UpdateListBoxItems();
|
||||||
}
|
}
|
||||||
|
private void CompareSAU(IComparer<DrawingBase?> comparer)
|
||||||
|
{
|
||||||
|
if (_company == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_company.Sort(comparer);
|
||||||
|
pictureBox.Image = _company.Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonSortByType_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
CompareSAU(new SAUCompareByType());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonSortByColor_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
CompareSAU(new SAUCompareByColor());
|
||||||
|
}
|
||||||
}
|
}
|
@ -29,6 +29,7 @@
|
|||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
groupBoxConfig = new GroupBox();
|
groupBoxConfig = new GroupBox();
|
||||||
|
checkBoxTracks = new CheckBox();
|
||||||
groupBoxColors = new GroupBox();
|
groupBoxColors = new GroupBox();
|
||||||
panelPurple = new Panel();
|
panelPurple = new Panel();
|
||||||
panelBlack = new Panel();
|
panelBlack = new Panel();
|
||||||
@ -51,7 +52,6 @@
|
|||||||
panelObject = new Panel();
|
panelObject = new Panel();
|
||||||
labelAdditionalColor = new Label();
|
labelAdditionalColor = new Label();
|
||||||
labelBodyColor = new Label();
|
labelBodyColor = new Label();
|
||||||
checkBoxTracks = new CheckBox();
|
|
||||||
groupBoxConfig.SuspendLayout();
|
groupBoxConfig.SuspendLayout();
|
||||||
groupBoxColors.SuspendLayout();
|
groupBoxColors.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit();
|
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit();
|
||||||
@ -79,6 +79,16 @@
|
|||||||
groupBoxConfig.TabStop = false;
|
groupBoxConfig.TabStop = false;
|
||||||
groupBoxConfig.Text = "Параметры";
|
groupBoxConfig.Text = "Параметры";
|
||||||
//
|
//
|
||||||
|
// checkBoxTracks
|
||||||
|
//
|
||||||
|
checkBoxTracks.AutoSize = true;
|
||||||
|
checkBoxTracks.Location = new Point(12, 135);
|
||||||
|
checkBoxTracks.Name = "checkBoxTracks";
|
||||||
|
checkBoxTracks.Size = new Size(213, 24);
|
||||||
|
checkBoxTracks.TabIndex = 9;
|
||||||
|
checkBoxTracks.Text = "Признак наличия гусениц";
|
||||||
|
checkBoxTracks.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
// groupBoxColors
|
// groupBoxColors
|
||||||
//
|
//
|
||||||
groupBoxColors.Controls.Add(panelPurple);
|
groupBoxColors.Controls.Add(panelPurple);
|
||||||
@ -312,16 +322,6 @@
|
|||||||
labelBodyColor.DragDrop += labelBodyColor_DragDrop;
|
labelBodyColor.DragDrop += labelBodyColor_DragDrop;
|
||||||
labelBodyColor.DragEnter += labelBodyColor_DragEnter;
|
labelBodyColor.DragEnter += labelBodyColor_DragEnter;
|
||||||
//
|
//
|
||||||
// checkBoxTracks
|
|
||||||
//
|
|
||||||
checkBoxTracks.AutoSize = true;
|
|
||||||
checkBoxTracks.Location = new Point(12, 135);
|
|
||||||
checkBoxTracks.Name = "checkBoxTracks";
|
|
||||||
checkBoxTracks.Size = new Size(232, 24);
|
|
||||||
checkBoxTracks.TabIndex = 9;
|
|
||||||
checkBoxTracks.Text = "Признак наличия пулеметов";
|
|
||||||
checkBoxTracks.UseVisualStyleBackColor = true;
|
|
||||||
//
|
|
||||||
// FormSAUConfig
|
// FormSAUConfig
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user