This commit is contained in:
Victoria_Isaeva 2024-04-17 12:19:09 +04:00
parent a8ae0ee97c
commit 9deaccb1e1
15 changed files with 628 additions and 324 deletions

View File

@ -48,7 +48,7 @@ public abstract class AbstractCompany
_pictureWidth = picWidth; _pictureWidth = picWidth;
_pictureHeight = picHeight; _pictureHeight = picHeight;
_collection = collection; _collection = collection;
_collection.SetMaxCount = GetMaxCount; _collection.MaxCount = GetMaxCount;
} }
/// <summary> /// <summary>

View File

@ -59,7 +59,7 @@ public class AerodromService : AbstractCompany
if (_collection.Get(i) != null) if (_collection.Get(i) != null)
{ {
_collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight); _collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight);
_collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 20, curHeight * _placeSizeHeight + 15); _collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 20, curHeight * _placeSizeHeight + 35);
} }
if (curWidth > 0) if (curWidth > 0)

View File

@ -11,10 +11,14 @@ public interface ICollectionGenericObjects<T>
where T : class where T : class
{ {
int Count { get; } int Count { get; }
int SetMaxCount { set; } int MaxCount{get;set;}
int Insert(T obj); int Insert(T obj);
int Insert(T obj, int position); int Insert(T obj, int position);
T Remove(int position); T Remove(int position);
T? Get(int position); T? Get(int position);
CollectionType GetCollectionType { get; }
IEnumerable<T> GetItems();
} }

View File

@ -23,6 +23,10 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } } public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } }
public CollectionType GetCollectionType => CollectionType.List;
public int MaxCount { get; set; }
/// <summary> /// <summary>
/// Конструктор /// Конструктор
/// </summary> /// </summary>
@ -67,4 +71,11 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
_collection.RemoveAt(position); _collection.RemoveAt(position);
return pos; return pos;
} }
public IEnumerable<T> GetItems()
{
for (int i = 0; i < _collection.Count; i++)
{
yield return _collection[i];
}
}
} }

View File

@ -1,8 +1,4 @@
using System; 
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectAirbus.CollectionGenericObjects; namespace ProjectAirbus.CollectionGenericObjects;
@ -18,8 +14,12 @@ internal class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
public int Count => _collection.Length; public int Count => _collection.Length;
public int SetMaxCount public int MaxCount
{ {
get
{
return _collection.Length;
}
set set
{ {
if (value > 0) if (value > 0)
@ -34,8 +34,10 @@ internal class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
} }
} }
} }
} }
public CollectionType GetCollectionType => CollectionType.Massive;
/// <summary> /// <summary>
/// Конструктор /// Конструктор
/// </summary> /// </summary>
@ -118,6 +120,13 @@ internal class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
_collection[position] = null; _collection[position] = null;
return obj; return obj;
} }
public IEnumerable<T> GetItems()
{
for (int i = 0; i < _collection.Length; i++)
{
yield return _collection[i];
}
}
} }

View File

@ -1,40 +1,34 @@
 
using ProjectAirbus.CollectionGenericObjects; using ProjectAirbus.CollectionGenericObjects;
using ProjectAirbus.Drawnings;
using System.Text;
namespace ProjectAirBus.CollectionGenericObjects; namespace ProjectAirBus.CollectionGenericObjects;
/// <summary>
/// Класс-хранилище коллекций
/// </summary>
/// <typeparam name="T"></typeparam>
public class StorageCollection<T> public class StorageCollection<T>
where T : class where T : DrawningBus
{ {
/// <summary>
/// Словарь (хранилище) с коллекциями
/// </summary>
readonly Dictionary<string, ICollectionGenericObjects<T>> _storages; readonly Dictionary<string, ICollectionGenericObjects<T>> _storages;
/// <summary>
/// Возвращение списка названий коллекций
/// </summary>
public List<string> Keys => _storages.Keys.ToList(); public List<string> Keys => _storages.Keys.ToList();
/// <summary> private readonly string _collectionKey = "CollectionStorage";
/// Конструктор
/// </summary> private readonly string _separatorForKeyValue = "|";
private readonly string _separatorItem = ";";
public StorageCollection() public StorageCollection()
{ {
_storages = new Dictionary<string, ICollectionGenericObjects<T>>(); _storages = new Dictionary<string, ICollectionGenericObjects<T>>();
} }
/// <summary>
/// Добавление коллекции в хранилище
/// </summary>
/// <param name="name">Название коллекции</param>
/// <param name="collectionType">тип коллекции</param>
public void AddCollection(string name, CollectionType collectionType) public void AddCollection(string name, CollectionType collectionType)
{ {
// TODO проверка, что name не пустой и нет в словаре записи с таким ключом // TODO проверка, что name не пустой и нет в словаре записи с таким ключом
@ -54,10 +48,7 @@ public class StorageCollection<T>
} }
} }
/// <summary>
/// Удаление коллекции
/// </summary>
/// <param name="name">Название коллекции</param>
public void DelCollection(string name) public void DelCollection(string name)
{ {
// TODO Прописать логику для удаления коллекции // TODO Прописать логику для удаления коллекции
@ -65,11 +56,7 @@ public class StorageCollection<T>
_storages.Remove(name); _storages.Remove(name);
} }
/// <summary>
/// Доступ к коллекции
/// </summary>
/// <param name="name">Название коллекции</param>
/// <returns></returns>
public ICollectionGenericObjects<T>? this[string name] public ICollectionGenericObjects<T>? this[string name]
{ {
get get
@ -79,4 +66,122 @@ public class StorageCollection<T>
return _storages[name]; return _storages[name];
} }
} }
public bool SaveData(string filename)
{
if (_storages.Count == 0)
{
return false;
}
if (File.Exists(filename))
{
File.Delete(filename);
}
StringBuilder sb = new();
sb.Append(_collectionKey);
foreach (KeyValuePair<string, ICollectionGenericObjects<T>> value in _storages)
{
sb.Append(Environment.NewLine);
if (value.Value.Count == 0)
{
continue;
}
sb.Append(value.Key);
sb.Append(_separatorForKeyValue);
sb.Append(value.Value.GetCollectionType);
sb.Append(_separatorForKeyValue);
sb.Append(value.Value.MaxCount);
sb.Append(_separatorForKeyValue);
foreach (T? item in value.Value.GetItems())
{
string data = item?.GetDataForSave() ?? string.Empty;
if (string.IsNullOrEmpty(data))
{
continue;
}
sb.Append(data);
sb.Append(_separatorItem);
}
}
using FileStream fs = new(filename, FileMode.Create);
byte[] info = new UTF8Encoding().GetBytes(sb.ToString());
fs.Write(info, 0, info.Length);
return true;
}
public bool LoadData(string filename)
{
if (!File.Exists(filename))
{
return false;
}
string bufferTextFromFile = "";
using (FileStream fs = new(filename, FileMode.Open))
{
byte[] b = new byte[fs.Length];
UTF8Encoding temp = new UTF8Encoding(true);
while (fs.Read(b, 0, b.Length) > 0)
{
bufferTextFromFile += temp.GetString(b);
}
}
string[] strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
if (strs.Length == 0 || strs == null)
{
return false;
}
if (!strs[0].Equals(_collectionKey))
{
return false;
}
_storages.Clear();
foreach (string data in strs)
{
string[] record = data.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
if (record.Length != 4)
{
continue;
}
CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionType);
if (collection == null)
{
return false;
}
collection.MaxCount = Convert.ToInt32(record[2]);
string[] set = record[3].Split(_separatorItem, StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set)
{
if (elem?.CreateDrawningBus() is T bus)
{
if (collection.Insert(bus) == -1)
{
return false;
}
}
}
_storages.Add(record[0], collection);
}
return true;
}
private static ICollectionGenericObjects<T>? CreateCollection(CollectionType collectionType)
{
return collectionType switch
{
CollectionType.Massive => new MassiveGenericObjects<T>(),
CollectionType.List => new ListGenericObjects<T>(),
_ => null,
};
}
} }

View File

@ -4,11 +4,17 @@ namespace ProjectAirbus.Drawnings;
public class DrawningAirbus : DrawningBus public class DrawningAirbus : DrawningBus
{ {
private EntityAirbus bus;
public DrawningAirbus(EntityBus bus) : base(bus)
{
}
public DrawningAirbus(int speed, double weight, Color bodyColor, Color additionalColor, bool compartment, bool engine) : base(140, 60) public DrawningAirbus(int speed, double weight, Color bodyColor, Color additionalColor, bool compartment, bool engine) : base(140, 60)
{ {
EntityBus = new EntityAirbus(speed, weight, bodyColor, additionalColor, compartment, engine); EntityBus = new EntityAirbus(speed, weight, bodyColor, additionalColor, compartment, engine);
} }
public override void DrawTransport(Graphics g) public override void DrawTransport(Graphics g)
{ {
if (EntityBus == null || EntityBus is not EntityAirbus airbus || !_startPosX.HasValue || !_startPosY.HasValue) if (EntityBus == null || EntityBus is not EntityAirbus airbus || !_startPosX.HasValue || !_startPosY.HasValue)

View File

@ -39,12 +39,11 @@ public class DrawningBus
_startPosY = null; _startPosY = null;
} }
public DrawningBus(int speed, double weight, Color bodyColor) : this() public DrawningBus(int speed, double weight, Color bodyColor) : this()
{ {
EntityBus = new EntityBus(speed, weight, bodyColor); EntityBus = new EntityBus(speed, weight, bodyColor);
} }
//конструктор для наследников //конструктор для наследников
protected DrawningBus(int drawningBusWidth, int drawningBusHeigh) : this() protected DrawningBus(int drawningBusWidth, int drawningBusHeigh) : this()
{ {
@ -52,6 +51,12 @@ public class DrawningBus
drawningBusHeigh = drawningBusHeigh; //высота drawningBusHeigh = drawningBusHeigh; //высота
} }
public DrawningBus(EntityBus bus)
{
EntityBus = bus;
}
public bool SetPictureSize(int width, int height) public bool SetPictureSize(int width, int height)
{ {
if (_drawningBusWidth < width && _drawningBusHeight < height) if (_drawningBusWidth < width && _drawningBusHeight < height)

View File

@ -0,0 +1,45 @@
using ProjectAirbus.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectAirbus.Drawnings;
public static class ExtentionDrawningBus
{
private static readonly string _separatorForObject = ":";
public static DrawningBus? CreateDrawningBus(this string info)
{
string[] strs = info.Split(_separatorForObject);
EntityBus? bus = EntityAirbus.CreateEntityAirbus(strs);
if (bus != null)
{
return new DrawningAirbus(bus);
}
bus = EntityBus.CreateEntityBus(strs);
if (bus != null)
{
return new DrawningBus(bus);
}
return null;
}
public static string GetDataForSave(this DrawningBus drawningBus)
{
string[]? array = drawningBus?.EntityBus?.GetStringRepresentation();
if (array == null)
{
return string.Empty;
}
return string.Join(_separatorForObject, array);
}
}

View File

@ -1,16 +1,13 @@
using System; namespace ProjectAirbus.Entities;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectAirbus.Entities;
public class EntityAirbus : EntityBus public class EntityAirbus : EntityBus
{ {
public Color AdditionalColor { get; private set; } public Color AdditionalColor { get; private set; }
public void SetAdditionalColor(Color color) { AdditionalColor = color; } public void SetAdditionalColor(Color color)
{
AdditionalColor = color;
}
public bool Compartment { get; private set; } public bool Compartment { get; private set; }
@ -23,5 +20,19 @@ public class EntityAirbus : EntityBus
Engine = engine; Engine = engine;
} }
public override string[] GetStringRepresentation()
{
return new[] { nameof(EntityAirbus), Speed.ToString(), Weight.ToString(), BodyColor.Name,AdditionalColor.Name, Compartment.ToString(), Engine.ToString() };
}
public static EntityAirbus? CreateEntityAirbus(string[] strs)
{
if (strs.Length != 7 || strs[0] != nameof(EntityAirbus))
{
return null;
}
return new EntityAirbus(Convert.ToInt32(strs[1]), Convert.ToDouble(strs[2]),
Color.FromName(strs[3]), Color.FromName(strs[4]), Convert.ToBoolean(strs[5]), Convert.ToBoolean(strs[6]));
}
} }

View File

@ -6,6 +6,7 @@ using System.Threading.Tasks;
namespace ProjectAirbus.Entities; namespace ProjectAirbus.Entities;
public class EntityBus public class EntityBus
{ {
public int Speed { get; set; } public int Speed { get; set; }
@ -15,11 +16,25 @@ public class EntityBus
public void SetBodyColor(Color color) { BodyColor = color; } public void SetBodyColor(Color color) { BodyColor = color; }
public double Step => Speed * 100 / Weight; public double Step => Speed * 100 / Weight;
public EntityBus(int speed, double weight, Color bodyColor) public EntityBus(int speed, double weight, Color bodyColor)
{ {
Speed = speed; Speed = speed;
Weight = weight; Weight = weight;
BodyColor = bodyColor; BodyColor = bodyColor;
} }
}
public virtual string[] GetStringRepresentation()
{
return new[] { nameof(EntityBus), Speed.ToString(), Weight.ToString(), BodyColor.Name };
}
public static EntityBus? CreateEntityBus(string[] strs)
{
if (strs.Length != 4 || strs[0] != nameof(EntityBus))
return null;
return new EntityBus(Convert.ToInt32(strs[1]), Convert.ToDouble(strs[2]), Color.FromName(strs[3]));
}
}

View File

@ -29,16 +29,15 @@
private void InitializeComponent() private void InitializeComponent()
{ {
groupBoxTools = new GroupBox(); groupBoxTools = new GroupBox();
buttonCreateCompany = new Button();
comboBoxSelectorCompany = new ComboBox();
panelCompanyTools = new Panel(); panelCompanyTools = new Panel();
buttonRefresh = new Button(); buttonRefresh = new Button();
comboBoxSelectorCompany = new ComboBox();
buttonGoToChek = new Button(); buttonGoToChek = new Button();
buttonAddBus = new Button(); buttonAddBus = new Button();
buttonDelBus = new Button(); buttonDelBus = new Button();
buttonAddAirBus = new Button();
maskedTextBox = new MaskedTextBox(); maskedTextBox = new MaskedTextBox();
panelStorage = new Panel(); panelStorage = new Panel();
buttonCreateCompany = new Button();
buttonCollectionDel = new Button(); buttonCollectionDel = new Button();
listBoxCollection = new ListBox(); listBoxCollection = new ListBox();
buttonCollectionAdd = new Button(); buttonCollectionAdd = new Button();
@ -47,67 +46,50 @@
textBoxCollectionName = new TextBox(); textBoxCollectionName = new TextBox();
labelCollectionName = new Label(); labelCollectionName = new Label();
pictureBox1 = new PictureBox(); pictureBox1 = new PictureBox();
menuStrip = new MenuStrip();
файлToolStripMenuItem = new ToolStripMenuItem();
saveToolStripMenuItem = new ToolStripMenuItem();
loadToolStripMenuItem = new ToolStripMenuItem();
saveFileDialog = new SaveFileDialog();
openFileDialog = new OpenFileDialog();
groupBoxTools.SuspendLayout(); groupBoxTools.SuspendLayout();
panelCompanyTools.SuspendLayout(); panelCompanyTools.SuspendLayout();
panelStorage.SuspendLayout(); panelStorage.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit(); ((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit();
menuStrip.SuspendLayout();
SuspendLayout(); SuspendLayout();
// //
// groupBoxTools // groupBoxTools
// //
groupBoxTools.Controls.Add(buttonCreateCompany);
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Controls.Add(panelCompanyTools); groupBoxTools.Controls.Add(panelCompanyTools);
groupBoxTools.Controls.Add(panelStorage); groupBoxTools.Controls.Add(panelStorage);
groupBoxTools.Dock = DockStyle.Right; groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(825, 0); groupBoxTools.Location = new Point(825, 28);
groupBoxTools.Name = "groupBoxTools"; groupBoxTools.Name = "groupBoxTools";
groupBoxTools.Size = new Size(303, 644); groupBoxTools.Size = new Size(303, 581);
groupBoxTools.TabIndex = 0; groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false; groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты"; groupBoxTools.Text = "Инструменты";
// //
// buttonCreateCompany
//
buttonCreateCompany.Location = new Point(15, 316);
buttonCreateCompany.Name = "buttonCreateCompany";
buttonCreateCompany.Size = new Size(270, 29);
buttonCreateCompany.TabIndex = 7;
buttonCreateCompany.Text = "Создать компанию ";
buttonCreateCompany.UseVisualStyleBackColor = true;
buttonCreateCompany.Click += buttonCreateCompany_Click;
//
// comboBoxSelectorCompany
//
comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectorCompany.FormattingEnabled = true;
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
comboBoxSelectorCompany.Location = new Point(18, 350);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(267, 28);
comboBoxSelectorCompany.TabIndex = 0;
comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged;
//
// panelCompanyTools // panelCompanyTools
// //
panelCompanyTools.Controls.Add(buttonRefresh); panelCompanyTools.Controls.Add(buttonRefresh);
panelCompanyTools.Controls.Add(comboBoxSelectorCompany);
panelCompanyTools.Controls.Add(buttonGoToChek); panelCompanyTools.Controls.Add(buttonGoToChek);
panelCompanyTools.Controls.Add(buttonAddBus); panelCompanyTools.Controls.Add(buttonAddBus);
panelCompanyTools.Controls.Add(buttonDelBus); panelCompanyTools.Controls.Add(buttonDelBus);
panelCompanyTools.Controls.Add(buttonAddAirBus);
panelCompanyTools.Controls.Add(maskedTextBox); panelCompanyTools.Controls.Add(maskedTextBox);
panelCompanyTools.Dock = DockStyle.Bottom; panelCompanyTools.Dock = DockStyle.Bottom;
panelCompanyTools.Enabled = false; panelCompanyTools.Enabled = false;
panelCompanyTools.Location = new Point(3, 384); panelCompanyTools.Location = new Point(3, 343);
panelCompanyTools.Name = "panelCompanyTools"; panelCompanyTools.Name = "panelCompanyTools";
panelCompanyTools.Size = new Size(297, 257); panelCompanyTools.Size = new Size(297, 235);
panelCompanyTools.TabIndex = 2; panelCompanyTools.TabIndex = 2;
// //
// buttonRefresh // buttonRefresh
// //
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRefresh.Location = new Point(12, 216); buttonRefresh.Location = new Point(10, 191);
buttonRefresh.Name = "buttonRefresh"; buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(275, 35); buttonRefresh.Size = new Size(275, 35);
buttonRefresh.TabIndex = 6; buttonRefresh.TabIndex = 6;
@ -115,10 +97,22 @@
buttonRefresh.UseVisualStyleBackColor = true; buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += buttonRefresh_Click; buttonRefresh.Click += buttonRefresh_Click;
// //
// comboBoxSelectorCompany
//
comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectorCompany.FormattingEnabled = true;
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
comboBoxSelectorCompany.Location = new Point(11, 3);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(267, 28);
comboBoxSelectorCompany.TabIndex = 0;
comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged;
//
// buttonGoToChek // buttonGoToChek
// //
buttonGoToChek.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; buttonGoToChek.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonGoToChek.Location = new Point(14, 173); buttonGoToChek.Location = new Point(12, 150);
buttonGoToChek.Name = "buttonGoToChek"; buttonGoToChek.Name = "buttonGoToChek";
buttonGoToChek.Size = new Size(273, 37); buttonGoToChek.Size = new Size(273, 37);
buttonGoToChek.TabIndex = 5; buttonGoToChek.TabIndex = 5;
@ -129,7 +123,7 @@
// buttonAddBus // buttonAddBus
// //
buttonAddBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; buttonAddBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddBus.Location = new Point(11, 17); buttonAddBus.Location = new Point(11, 37);
buttonAddBus.Name = "buttonAddBus"; buttonAddBus.Name = "buttonAddBus";
buttonAddBus.Size = new Size(270, 33); buttonAddBus.Size = new Size(270, 33);
buttonAddBus.TabIndex = 1; buttonAddBus.TabIndex = 1;
@ -140,27 +134,16 @@
// buttonDelBus // buttonDelBus
// //
buttonDelBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; buttonDelBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonDelBus.Location = new Point(15, 132); buttonDelBus.Location = new Point(11, 109);
buttonDelBus.Name = "buttonDelBus"; buttonDelBus.Name = "buttonDelBus";
buttonDelBus.Size = new Size(272, 35); buttonDelBus.Size = new Size(272, 35);
buttonDelBus.TabIndex = 4; buttonDelBus.TabIndex = 4;
buttonDelBus.Text = "Удалить самолет"; buttonDelBus.Text = "Удалить самолет";
buttonDelBus.UseVisualStyleBackColor = true; buttonDelBus.UseVisualStyleBackColor = true;
//
// buttonAddAirBus
//
buttonAddAirBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddAirBus.Location = new Point(12, 56);
buttonAddAirBus.Name = "buttonAddAirBus";
buttonAddAirBus.Size = new Size(270, 37);
buttonAddAirBus.TabIndex = 2;
buttonAddAirBus.Text = "Добавление аэробуса";
buttonAddAirBus.UseVisualStyleBackColor = true;
// //
// maskedTextBox // maskedTextBox
// //
maskedTextBox.Location = new Point(11, 99); maskedTextBox.Location = new Point(11, 76);
maskedTextBox.Mask = "00"; maskedTextBox.Mask = "00";
maskedTextBox.Name = "maskedTextBox"; maskedTextBox.Name = "maskedTextBox";
maskedTextBox.Size = new Size(276, 27); maskedTextBox.Size = new Size(276, 27);
@ -169,6 +152,7 @@
// //
// panelStorage // panelStorage
// //
panelStorage.Controls.Add(buttonCreateCompany);
panelStorage.Controls.Add(buttonCollectionDel); panelStorage.Controls.Add(buttonCollectionDel);
panelStorage.Controls.Add(listBoxCollection); panelStorage.Controls.Add(listBoxCollection);
panelStorage.Controls.Add(buttonCollectionAdd); panelStorage.Controls.Add(buttonCollectionAdd);
@ -179,9 +163,19 @@
panelStorage.Dock = DockStyle.Top; panelStorage.Dock = DockStyle.Top;
panelStorage.Location = new Point(3, 23); panelStorage.Location = new Point(3, 23);
panelStorage.Name = "panelStorage"; panelStorage.Name = "panelStorage";
panelStorage.Size = new Size(297, 287); panelStorage.Size = new Size(297, 317);
panelStorage.TabIndex = 2; panelStorage.TabIndex = 2;
// //
// buttonCreateCompany
//
buttonCreateCompany.Location = new Point(12, 288);
buttonCreateCompany.Name = "buttonCreateCompany";
buttonCreateCompany.Size = new Size(270, 29);
buttonCreateCompany.TabIndex = 7;
buttonCreateCompany.Text = "Создать компанию ";
buttonCreateCompany.UseVisualStyleBackColor = true;
buttonCreateCompany.Click += buttonCreateCompany_Click;
//
// buttonCollectionDel // buttonCollectionDel
// //
buttonCollectionDel.Location = new Point(12, 251); buttonCollectionDel.Location = new Point(12, 251);
@ -251,19 +245,63 @@
// pictureBox1 // pictureBox1
// //
pictureBox1.Dock = DockStyle.Fill; pictureBox1.Dock = DockStyle.Fill;
pictureBox1.Location = new Point(0, 0); pictureBox1.Location = new Point(0, 28);
pictureBox1.Name = "pictureBox1"; pictureBox1.Name = "pictureBox1";
pictureBox1.Size = new Size(825, 644); pictureBox1.Size = new Size(825, 581);
pictureBox1.TabIndex = 1; pictureBox1.TabIndex = 1;
pictureBox1.TabStop = false; pictureBox1.TabStop = false;
// //
// menuStrip
//
menuStrip.ImageScalingSize = new Size(20, 20);
menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem });
menuStrip.Location = new Point(0, 0);
menuStrip.Name = "menuStrip";
menuStrip.Size = new Size(1128, 28);
menuStrip.TabIndex = 2;
menuStrip.Text = "menuStrip1";
//
// файлToolStripMenuItem
//
файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { saveToolStripMenuItem, loadToolStripMenuItem });
файлToolStripMenuItem.Name = айлToolStripMenuItem";
файлToolStripMenuItem.Size = new Size(59, 24);
файлToolStripMenuItem.Text = "Файл";
//
// saveToolStripMenuItem
//
saveToolStripMenuItem.Name = "saveToolStripMenuItem";
saveToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S;
saveToolStripMenuItem.Size = new Size(231, 26);
saveToolStripMenuItem.Text = "Сохранение ";
saveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
//
// loadToolStripMenuItem
//
loadToolStripMenuItem.Name = "loadToolStripMenuItem";
loadToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.L;
loadToolStripMenuItem.Size = new Size(231, 26);
loadToolStripMenuItem.Text = "Загрузка";
loadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
//
// saveFileDialog
//
saveFileDialog.Filter = "txt file | *.txt";
//
// openFileDialog
//
openFileDialog.Filter = "txt file | *.txt";
//
// FormBusCollection // FormBusCollection
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1128, 644); ClientSize = new Size(1128, 609);
Controls.Add(pictureBox1); Controls.Add(pictureBox1);
Controls.Add(groupBoxTools); Controls.Add(groupBoxTools);
Controls.Add(menuStrip);
FormBorderStyle = FormBorderStyle.FixedSingle;
MainMenuStrip = menuStrip;
Name = "FormBusCollection"; Name = "FormBusCollection";
Text = "Коллекция самолетов "; Text = "Коллекция самолетов ";
groupBoxTools.ResumeLayout(false); groupBoxTools.ResumeLayout(false);
@ -272,14 +310,16 @@
panelStorage.ResumeLayout(false); panelStorage.ResumeLayout(false);
panelStorage.PerformLayout(); panelStorage.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit(); ((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit();
menuStrip.ResumeLayout(false);
menuStrip.PerformLayout();
ResumeLayout(false); ResumeLayout(false);
PerformLayout();
} }
#endregion #endregion
private GroupBox groupBoxTools; private GroupBox groupBoxTools;
private ComboBox comboBoxSelectorCompany; private ComboBox comboBoxSelectorCompany;
private Button buttonAddAirBus;
private Button buttonAddBus; private Button buttonAddBus;
private PictureBox pictureBox1; private PictureBox pictureBox1;
private Button buttonDelBus; private Button buttonDelBus;
@ -296,5 +336,12 @@
private Button buttonCreateCompany; private Button buttonCreateCompany;
private Button buttonCollectionDel; private Button buttonCollectionDel;
private Panel panelCompanyTools; private Panel panelCompanyTools;
private MenuStrip menuStrip;
private ToolStripMenuItem файлToolStripMenuItem;
private ToolStripMenuItem saveToolStripMenuItem;
private ToolStripMenuItem loadToolStripMenuItem;
private SaveFileDialog saveFileDialog;
private OpenFileDialog openFileDialog;
} }
} }

View File

@ -2,10 +2,10 @@
using ProjectAirbus.Drawnings; using ProjectAirbus.Drawnings;
using ProjectAirBus.CollectionGenericObjects; using ProjectAirBus.CollectionGenericObjects;
namespace ProjectAirbus namespace ProjectAirbus;
public partial class FormBusCollection : Form
{ {
public partial class FormBusCollection : Form
{
private readonly StorageCollection<DrawningBus> _storageCollection; private readonly StorageCollection<DrawningBus> _storageCollection;
private AbstractCompany? _company; private AbstractCompany? _company;
@ -218,7 +218,7 @@ namespace ProjectAirbus
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("Коллекция не проинициализирована");
@ -228,12 +228,45 @@ namespace ProjectAirbus
switch (comboBoxSelectorCompany.Text) switch (comboBoxSelectorCompany.Text)
{ {
case "Хранилище": case "Хранилище":
_company = new AerodromService(pictureBox1.Width, pictureBox1.Height,collection); _company = new AerodromService(pictureBox1.Width, pictureBox1.Height, collection);
break; break;
} }
panelCompanyTools.Enabled = true; panelCompanyTools.Enabled = true;
RerfreshListBoxItems(); RerfreshListBoxItems();
} }
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
{
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
if (_storageCollection.SaveData(saveFileDialog.FileName))
{
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
{
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
if (_storageCollection.LoadData(openFileDialog.FileName))
{
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
RerfreshListBoxItems();
}
else
{
MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
} }
} }

View File

@ -117,4 +117,16 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>145, 17</value>
</metadata>
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>310, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>25</value>
</metadata>
</root> </root>

View File

@ -256,6 +256,7 @@
buttonAdd.TabIndex = 2; buttonAdd.TabIndex = 2;
buttonAdd.Text = "Добавить "; buttonAdd.Text = "Добавить ";
buttonAdd.UseVisualStyleBackColor = true; buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += ButtonAddAirbus_Click;
// //
// buttonCancel // buttonCancel
// //