TractorGeneriStorage ready
This commit is contained in:
parent
a0a018477f
commit
8f30dca90b
@ -261,6 +261,8 @@ namespace ProjectTractor
|
||||
{
|
||||
this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
|
||||
this.groupBox = new System.Windows.Forms.GroupBox();
|
||||
this.ButtonSortByColor = new System.Windows.Forms.Button();
|
||||
this.ButtonSortByType = new System.Windows.Forms.Button();
|
||||
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
this.ButtonDelObject = new System.Windows.Forms.Button();
|
||||
this.listBoxStorages = new System.Windows.Forms.ListBox();
|
||||
@ -292,6 +294,8 @@ namespace ProjectTractor
|
||||
//
|
||||
// groupBox
|
||||
//
|
||||
this.groupBox.Controls.Add(this.ButtonSortByColor);
|
||||
this.groupBox.Controls.Add(this.ButtonSortByType);
|
||||
this.groupBox.Controls.Add(this.groupBox1);
|
||||
this.groupBox.Controls.Add(this.ButtonRefreshCollection);
|
||||
this.groupBox.Controls.Add(this.ButtonRemoveTractor);
|
||||
@ -305,6 +309,26 @@ namespace ProjectTractor
|
||||
this.groupBox.TabStop = false;
|
||||
this.groupBox.Text = "Инструменты";
|
||||
//
|
||||
// ButtonSortByColor
|
||||
//
|
||||
this.ButtonSortByColor.Location = new System.Drawing.Point(28, 326);
|
||||
this.ButtonSortByColor.Name = "ButtonSortByColor";
|
||||
this.ButtonSortByColor.Size = new System.Drawing.Size(203, 29);
|
||||
this.ButtonSortByColor.TabIndex = 12;
|
||||
this.ButtonSortByColor.Text = "Сортировка по цвету";
|
||||
this.ButtonSortByColor.UseVisualStyleBackColor = true;
|
||||
this.ButtonSortByColor.Click += new System.EventHandler(this.ButtonSortByColor_Click);
|
||||
//
|
||||
// ButtonSortByType
|
||||
//
|
||||
this.ButtonSortByType.Location = new System.Drawing.Point(28, 289);
|
||||
this.ButtonSortByType.Name = "ButtonSortByType";
|
||||
this.ButtonSortByType.Size = new System.Drawing.Size(203, 29);
|
||||
this.ButtonSortByType.TabIndex = 11;
|
||||
this.ButtonSortByType.Text = "Сортировка по типу";
|
||||
this.ButtonSortByType.UseVisualStyleBackColor = true;
|
||||
this.ButtonSortByType.Click += new System.EventHandler(this.ButtonSortByType_Click);
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
this.groupBox1.Controls.Add(this.ButtonDelObject);
|
||||
@ -313,14 +337,14 @@ namespace ProjectTractor
|
||||
this.groupBox1.Controls.Add(this.textBoxStorageName);
|
||||
this.groupBox1.Location = new System.Drawing.Point(16, 54);
|
||||
this.groupBox1.Name = "groupBox1";
|
||||
this.groupBox1.Size = new System.Drawing.Size(224, 279);
|
||||
this.groupBox1.Size = new System.Drawing.Size(224, 229);
|
||||
this.groupBox1.TabIndex = 9;
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "Наборы";
|
||||
//
|
||||
// ButtonDelObject
|
||||
//
|
||||
this.ButtonDelObject.Location = new System.Drawing.Point(12, 227);
|
||||
this.ButtonDelObject.Location = new System.Drawing.Point(12, 184);
|
||||
this.ButtonDelObject.Name = "ButtonDelObject";
|
||||
this.ButtonDelObject.Size = new System.Drawing.Size(203, 35);
|
||||
this.ButtonDelObject.TabIndex = 3;
|
||||
@ -332,7 +356,7 @@ namespace ProjectTractor
|
||||
//
|
||||
this.listBoxStorages.FormattingEnabled = true;
|
||||
this.listBoxStorages.ItemHeight = 20;
|
||||
this.listBoxStorages.Location = new System.Drawing.Point(12, 116);
|
||||
this.listBoxStorages.Location = new System.Drawing.Point(12, 94);
|
||||
this.listBoxStorages.Name = "listBoxStorages";
|
||||
this.listBoxStorages.Size = new System.Drawing.Size(203, 84);
|
||||
this.listBoxStorages.TabIndex = 2;
|
||||
@ -357,7 +381,7 @@ namespace ProjectTractor
|
||||
//
|
||||
// ButtonRefreshCollection
|
||||
//
|
||||
this.ButtonRefreshCollection.Location = new System.Drawing.Point(28, 463);
|
||||
this.ButtonRefreshCollection.Location = new System.Drawing.Point(28, 473);
|
||||
this.ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||
this.ButtonRefreshCollection.Size = new System.Drawing.Size(203, 35);
|
||||
this.ButtonRefreshCollection.TabIndex = 8;
|
||||
@ -367,7 +391,7 @@ namespace ProjectTractor
|
||||
//
|
||||
// ButtonRemoveTractor
|
||||
//
|
||||
this.ButtonRemoveTractor.Location = new System.Drawing.Point(28, 410);
|
||||
this.ButtonRemoveTractor.Location = new System.Drawing.Point(28, 434);
|
||||
this.ButtonRemoveTractor.Name = "ButtonRemoveTractor";
|
||||
this.ButtonRemoveTractor.Size = new System.Drawing.Size(203, 33);
|
||||
this.ButtonRemoveTractor.TabIndex = 7;
|
||||
@ -377,7 +401,7 @@ namespace ProjectTractor
|
||||
//
|
||||
// ButtonAddTractor
|
||||
//
|
||||
this.ButtonAddTractor.Location = new System.Drawing.Point(28, 337);
|
||||
this.ButtonAddTractor.Location = new System.Drawing.Point(28, 361);
|
||||
this.ButtonAddTractor.Name = "ButtonAddTractor";
|
||||
this.ButtonAddTractor.Size = new System.Drawing.Size(203, 34);
|
||||
this.ButtonAddTractor.TabIndex = 6;
|
||||
@ -387,7 +411,7 @@ namespace ProjectTractor
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
this.maskedTextBoxNumber.Location = new System.Drawing.Point(28, 377);
|
||||
this.maskedTextBoxNumber.Location = new System.Drawing.Point(28, 401);
|
||||
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
this.maskedTextBoxNumber.Size = new System.Drawing.Size(203, 27);
|
||||
this.maskedTextBoxNumber.TabIndex = 5;
|
||||
@ -463,6 +487,28 @@ namespace ProjectTractor
|
||||
private ToolStripMenuItem toolStripMenuItemload;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private Button ButtonSortByColor;
|
||||
private Button ButtonSortByType;
|
||||
private PictureBox pictureBoxCollection;
|
||||
|
||||
private void ButtonSortByType_Click(object sender, EventArgs e) => CompareTractors(new TractorCompareByType());
|
||||
|
||||
private void ButtonSortByColor_Click(object sender, EventArgs e) => CompareTractors(new TractorCompareByColor());
|
||||
|
||||
private void CompareTractors(IComparer<DrawningTractor?> comparer)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||
string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
obj.Sort(comparer);
|
||||
pictureBoxCollection.Image = obj.ShowTractors();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectTractor.Generics
|
||||
{
|
||||
internal class TractorsCollectionInfo : IEquatable<TractorsCollectionInfo?>
|
||||
{
|
||||
public string Name { get; private set; }
|
||||
public string Description { get; private set; }
|
||||
public TractorsCollectionInfo(string name, string description)
|
||||
{
|
||||
Name = name;
|
||||
Description = description;
|
||||
}
|
||||
public bool Equals(TractorsCollectionInfo? other)
|
||||
{
|
||||
if (other == null || other.Name == null)
|
||||
throw new ArgumentNullException(nameof(other));
|
||||
return Name == other.Name;
|
||||
}
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return this.Name.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
@ -17,11 +17,11 @@ namespace ProjectTractor
|
||||
/// <summary>
|
||||
/// Словарь (хранилище)
|
||||
/// </summary>
|
||||
readonly Dictionary<string, TractorsGenericCollection<DrawningTractor, DrawningObjectTractor>> _tractorStorages;
|
||||
readonly Dictionary<TractorsCollectionInfo, TractorsGenericCollection<DrawningTractor, DrawningObjectTractor>> _tractorStorages;
|
||||
/// <summary>
|
||||
/// Возвращение списка названий наборов
|
||||
/// </summary>
|
||||
public List<string> Keys => _tractorStorages.Keys.ToList();
|
||||
public List<TractorsCollectionInfo> Keys => _tractorStorages.Keys.ToList();
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
@ -49,8 +49,8 @@ namespace ProjectTractor
|
||||
/// <param name="pictureHeight"></param>
|
||||
public TractorsGenericStorage(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_tractorStorages = new Dictionary<string,
|
||||
TractorsGenericCollection<DrawningTractor, DrawningObjectTractor>>();
|
||||
_tractorStorages = new Dictionary<TractorsCollectionInfo,
|
||||
TractorsGenericCollection<DrawningTractor, DrawningObjectTractor>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
@ -60,7 +60,7 @@ namespace ProjectTractor
|
||||
/// <param name="name">Название набора</param>
|
||||
public void AddSet(string name)
|
||||
{
|
||||
_tractorStorages.Add(name,
|
||||
_tractorStorages.Add(new TractorsCollectionInfo(name, string.Empty),
|
||||
new TractorsGenericCollection<DrawningTractor,
|
||||
DrawningObjectTractor>(_pictureWidth, _pictureHeight));
|
||||
}
|
||||
@ -70,22 +70,22 @@ namespace ProjectTractor
|
||||
/// <param name="name">Название набора</param>
|
||||
public void DelSet(string name)
|
||||
{
|
||||
if (!_tractorStorages.ContainsKey(name))
|
||||
if (!_tractorStorages.ContainsKey(new TractorsCollectionInfo(name, string.Empty)))
|
||||
return;
|
||||
_tractorStorages.Remove(name);
|
||||
_tractorStorages.Remove(new TractorsCollectionInfo(name, string.Empty));
|
||||
}
|
||||
/// <summary>
|
||||
/// Доступ к набору
|
||||
/// </summary>
|
||||
/// <param name="ind"></param>
|
||||
/// <returns></returns>
|
||||
public TractorsGenericCollection<DrawningTractor, DrawningObjectTractor>?
|
||||
this[string ind]
|
||||
public TractorsGenericCollection<DrawningTractor, DrawningObjectTractor>?this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_tractorStorages.ContainsKey(ind))
|
||||
return _tractorStorages[ind];
|
||||
TractorsCollectionInfo indObj = new TractorsCollectionInfo(ind, string.Empty);
|
||||
if (_tractorStorages.ContainsKey(indObj))
|
||||
return _tractorStorages[indObj];
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -102,15 +102,14 @@ namespace ProjectTractor
|
||||
File.Delete(filename);
|
||||
}
|
||||
StringBuilder data = new();
|
||||
foreach (KeyValuePair<string,
|
||||
TractorsGenericCollection<DrawningTractor, DrawningObjectTractor>> record in _tractorStorages)
|
||||
foreach (KeyValuePair<TractorsCollectionInfo, TractorsGenericCollection<DrawningTractor, DrawningObjectTractor>> record in _tractorStorages)
|
||||
{
|
||||
StringBuilder records = new();
|
||||
foreach (DrawningTractor? elem in record.Value.GetTractors)
|
||||
{
|
||||
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
|
||||
}
|
||||
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}");
|
||||
data.AppendLine($"{record.Key.Name}{_separatorForKeyValue}{records}");
|
||||
}
|
||||
if (data.Length == 0)
|
||||
{
|
||||
@ -136,14 +135,13 @@ namespace ProjectTractor
|
||||
using (StreamReader streamReader = new(filename))
|
||||
{
|
||||
string str = streamReader.ReadLine();
|
||||
string[] strings = str.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (strings == null || strings.Length == 0)
|
||||
var strs = str.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (strs == null || strs.Length == 0)
|
||||
{
|
||||
throw new IOException("Нет данных для загрузки");
|
||||
}
|
||||
if (!strings[0].StartsWith("TractorStorage"))
|
||||
if (!strs[0].StartsWith("PlaneStorage"))
|
||||
{
|
||||
//если нет такой записи, то это не те данные
|
||||
throw new IOException("Неверный формат данных");
|
||||
}
|
||||
_tractorStorages.Clear();
|
||||
@ -156,7 +154,8 @@ namespace ProjectTractor
|
||||
continue;
|
||||
}
|
||||
TractorsGenericCollection<DrawningTractor, DrawningObjectTractor> collection = new(_pictureWidth, _pictureHeight);
|
||||
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] set = record[1].Split(_separatorRecords,
|
||||
StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string elem in set)
|
||||
{
|
||||
DrawningTractor? tractor = elem?.CreateDrawningTractor(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||
@ -168,7 +167,7 @@ namespace ProjectTractor
|
||||
}
|
||||
}
|
||||
}
|
||||
_tractorStorages.Add(record[0], collection);
|
||||
_tractorStorages.Add(new TractorsCollectionInfo(record[0], string.Empty), collection);
|
||||
str = streamReader.ReadLine();
|
||||
} while (str != null);
|
||||
}
|
||||
|
@ -0,0 +1,4 @@
|
||||
TractorStorage
|
||||
первый|100:100:Yellow:Red:True:True;100:100:Green;
|
||||
второй|100:100:Purple:Red:True:False;100:100:Yellow:Blue:False:True;
|
||||
|
Loading…
Reference in New Issue
Block a user