6 лабораторная работа

This commit is contained in:
cleverman1337 2024-10-08 15:33:26 +03:00
parent a7382f2382
commit 613d0daa2a
13 changed files with 520 additions and 150 deletions

View File

@ -45,7 +45,7 @@ public abstract class AbstractCompany
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = collection;
_collection.SetMaxCount = GetMaxCount;
_collection.MaxCount = GetMaxCount;
}
/// <summary>
@ -54,7 +54,7 @@ public abstract class AbstractCompany
/// <param name="company">Компания</param>
/// <param name="tank">Добавляемый объект</param>
/// <returns></returns>
public static int operator +(AbstractCompany company, DrawningTank tank)
public static bool operator +(AbstractCompany company, DrawningTank tank)
{
return company._collection.Insert(tank);
}
@ -65,11 +65,10 @@ public abstract class AbstractCompany
/// <param name="company">Компания</param>
/// <param name="position">Номер удаляемого объекта</param>
/// <returns></returns>
public static DrawningTank? operator -(AbstractCompany company, int position)
public static bool operator -(AbstractCompany company, int position)
{
return company._collection?.Remove(position);
return company._collection.Remove(position);
}
/// <summary>
/// Получение случайного объекта из коллекции
/// </summary>

View File

@ -21,29 +21,28 @@ public interface ICollectionGenericObjects<T>
/// <summary>
/// Установка максимального количества элементов
/// </summary>
int SetMaxCount { set; }
int MaxCount { get; set; }
/// <summary>
/// Добавление объекта в коллекцию
/// </summary>
/// <param name="obj">Добавляемый объект</param>
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
int Insert(T obj);
bool Insert(T obj);
/// <summary>
/// Добавление объекта в коллекцию на конкретную позицию
/// вставить по позиции
/// </summary>
/// <param name="obj">Добавляемый объект</param>
/// <param name="position">Позиция</param>
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
int Insert(T obj, int position);
/// <param name="obj">добавляемый объект</param>
/// <param name="position">индекс</param>
/// <returns></returns>
bool Insert(T obj, int position);
/// <summary>
/// Удаление объекта из коллекции с конкретной позиции
/// </summary>
/// <param name="position">Позиция</param>
/// <returns>true - удаление прошло удачно, false - удаление не удалось</returns>
T? Remove(int position);
bool Remove(int position);
/// <summary>
/// Получение объекта по позиции
@ -51,4 +50,15 @@ public interface ICollectionGenericObjects<T>
/// <param name="position">Позиция</param>
/// <returns>Объект</returns>
T? Get(int position);
/// <summary>
/// Получение типа коллекции
/// </summary>
CollectionType GetCollectionType { get; }
/// <summary>
/// Получение объектов коллекции по одному
/// </summary>
/// <returns></returns>
IEnumerable<T> GetItems();
}

View File

@ -19,10 +19,24 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
/// </summary>
private int _maxCount;
public int Count => _collection.Count;
public int Count { get { return _collection.Count; } }
public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } }
public CollectionType GetCollectionType => CollectionType.List;
public int MaxCount
{
get
{
return _maxCount;
}
set
{
if (value > 0) _maxCount = value;
}
}
/// <summary>
/// Конструктор
/// </summary>
@ -33,30 +47,41 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
public T? Get(int position)
{
if (position < 0 || position >= Count) return null;
if (position < 0 || position >= _collection.Count || _collection == null || _collection.Count == 0) return null;
return _collection[position];
}
public int Insert(T? obj)
public bool Insert(T obj)
{
if (Count == _maxCount) return -1;
if (_collection == null || _collection.Count == _maxCount) return false;
_collection.Add(obj);
return Count - 1;
return true;
}
public int Insert(T? obj, int position)
public bool Insert(T obj, int position)
{
if (Count == _maxCount) return -1;
if (position < 0 || position >= Count) return -1;
if (_collection == null || position < 0 || position > _maxCount) return false;
_collection.Insert(position, obj);
return position;
return true;
}
public T? Remove(int position)
public bool Remove(int position)
{
if (position < 0 || position >= Count) return null;
if (_collection == null || position < 0 || position >= _collection.Count) return false;
T? obj = _collection[position];
_collection.RemoveAt(position);
return obj;
_collection[position] = null;
return true;
}
public IEnumerable<T> GetItems()
{
for (int i = 0; i < _collection.Count; i++)
{
yield return _collection[i];
}
}
}

View File

@ -14,26 +14,28 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
/// </summary>
private T?[] _collection;
public int Count => _collection.Length;
public int Count { get { return _collection.Length; } }
public int SetMaxCount
public int MaxCount
{
get
{
return _collection.Length;
}
set
{
if (value > 0)
if (value > 0 && _collection.Length == 0)
{
if (_collection.Length > 0)
{
Array.Resize(ref _collection, value);
}
else
{
_collection = new T?[value];
}
_collection = new T?[value];
}
}
}
public CollectionType GetCollectionType => CollectionType.Massive;
public int SetMaxCount { set => throw new NotImplementedException(); }
/// <summary>
/// Конструктор
/// </summary>
@ -49,27 +51,27 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
return _collection[position];
}
public int Insert(T obj)
public bool Insert(T obj)
{
for (int i = 0; i < _collection.Length; i++)
{
if (_collection[i] == null)
{
_collection[i] = obj;
return i;
return true;
}
}
return -1;
return false;
}
public int Insert(T obj, int position)
public bool Insert(T obj, int position)
{
if (position < 0 || position >= _collection.Length) { return position; }
if (position < 0 || position >= _collection.Length) { return false; }
if (_collection[position] == null)
{
_collection[position] = obj;
return position;
return true;
}
else
{
@ -78,7 +80,7 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
if (_collection[i] == null)
{
_collection[i] = obj;
return i;
return true;
}
}
@ -87,21 +89,29 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
if (_collection[i] == null)
{
_collection[i] = obj;
return i;
return true;
}
}
}
return -1;
return false;
}
public T? Remove(int position)
public bool Remove(int position)
{
if (position < 0 || position >= _collection.Length || _collection[position] == null)
return null;
T? temp = _collection[position];
_collection[position] = null;
if (position < 0 || position >= _collection.Length) { return false; }
return temp;
T? obj = _collection[position];
_collection[position] = null;
return true;
}
public IEnumerable<T> GetItems()
{
for (int i = 0; i < _collection.Length; i++)
{
yield return _collection[i];
}
}
}

View File

@ -1,4 +1,5 @@
using System;
using SelfPropelledArtilleryUnit.Drawnings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -7,7 +8,7 @@ using System.Threading.Tasks;
namespace SelfPropelledArtilleryUnit.CollectionGenericObjects;
public class StorageCollection<T>
where T : class
where T : DrawningTank
{
/// <summary>
/// Словарь (хранилище) с коллекциями
@ -19,6 +20,11 @@ public class StorageCollection<T>
/// </summary>
public List<string> Keys => _storages.Keys.ToList();
private readonly string _collectionKey = "CollectionStorage";
private readonly string _separatorForKeyValue = "|";
private readonly string _separatorItem = ";";
/// <summary>
/// Конструктор
/// </summary>
@ -75,4 +81,106 @@ public class StorageCollection<T>
return null;
}
}
public bool SaveData(string filename)
{
if (_storages.Count == 0)
{
return false;
}
if (File.Exists(filename))
{
File.Delete(filename);
}
using (StreamWriter writer = new StreamWriter(filename))
{
writer.Write(_collectionKey);
foreach (KeyValuePair<string, ICollectionGenericObjects<T>> value in _storages)
{
StringBuilder sb = new();
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);
}
writer.Write(sb);
}
return true;
}
}
public bool LoadData(string filename)
{
if (!File.Exists(filename))
{
return false;
}
using (StreamReader reader = File.OpenText(filename))
{
string str = reader.ReadLine();
if (str == null || str.Length == 0)
{
return false;
}
if (!str.StartsWith(_collectionKey))
{
return false;
}
_storages.Clear();
string strs = "";
while ((strs = reader.ReadLine()) != null)
{
string[] record = strs.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?.CreateDrawningTank() is T tank)
{
if (!collection.Insert(tank))
{
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

@ -20,7 +20,10 @@ public class DrawningArtillery : DrawningTank
{
EntityTank = new EntityArtillery(speed, weight, bodyColor, additionalColor, cannon, rocket);
}
public DrawningArtillery(EntityArtillery tank) : base(130, 20)
{
EntityTank = tank;
}
public override void DrawTransport(Graphics g)
{

View File

@ -76,6 +76,10 @@ public class DrawningTank
_drawningTankWidth = drawningTankWidth;
_pictureHeight = drawningTankHeight;
}
public DrawningTank(EntityTank tank)
{
EntityTank = tank;
}
/// <summary>
/// Установка границ поля
/// </summary>

View File

@ -0,0 +1,51 @@
using SelfPropelledArtilleryUnit.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SelfPropelledArtilleryUnit.Drawnings;
public static class ExtentionDrawningTank
{
private static readonly string _separatorForObject = ":";
/// <summary>
/// Создание объекта из строк характеристик
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
public static DrawningTank? CreateDrawningTank(this string info)
{
string[] strs = info.Split(_separatorForObject);
EntityTank? tank = EntityArtillery.CreateEntityArtillery(strs);
if (tank != null && tank is EntityArtillery tankA)
{
return new DrawningArtillery(tankA);
}
tank = EntityTank.CreateEntityTank(strs);
if (tank != null)
{
return new DrawningTank(tank);
}
return null;
}
/// <summary>
/// Подготовка данных для сохранения в файл
/// </summary>
/// <param name="drawningTank"></param>
/// <returns></returns>
public static string GetDataForSave(this DrawningTank drawningTank)
{
string[]? array = drawningTank?.EntityTank?.GetStringRepresentation();
if (array == null) { return string.Empty; }
return string.Join(_separatorForObject, array);
}
}

View File

@ -38,6 +38,28 @@ public class EntityArtillery : EntityTank
Cannon = cannon;
Rocket = rocket;
}
/// <summary>
/// Получение строк характеристик
/// </summary>
/// <returns></returns>
public override string[] GetStringRepresentation()
{
return new[] { nameof(EntityArtillery), Speed.ToString(), Weight.ToString(), BodyColor.Name,
AdditionalColor.Name, Cannon.ToString(), Rocket.ToString() };
}
/// <summary>
/// Создание объекта по строкам характеристик
/// </summary>
/// <param name="strs"></param>
/// <returns></returns>
public static EntityArtillery? CreateEntityArtillery(string[] strs)
{
if (strs.Length != 7 || strs[0] != nameof(EntityArtillery)) { return null; }
return new EntityArtillery(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

@ -35,5 +35,22 @@ public class EntityTank
BodyColor = bodyColor;
}
public virtual string[] GetStringRepresentation()
{
return new[] { nameof(EntityTank), Speed.ToString(), Weight.ToString(), BodyColor.Name };
}
/// <summary>
/// Создание объекта по строкам характеристик
/// </summary>
/// <param name="strs"></param>
/// <returns></returns>
public static EntityTank? CreateEntityTank(string[] strs)
{
if (strs.Length != 4 || strs[0] != nameof(EntityTank)) { return null; }
return new EntityTank(Convert.ToInt32(strs[1]), Convert.ToDouble(strs[2]), Color.FromName(strs[3]));
}
}

View File

@ -29,6 +29,13 @@
private void InitializeComponent()
{
groupBoxTools = new GroupBox();
panelCompanyTools = new Panel();
buttonAddTank = new Button();
buttonAddArtillery = new Button();
buttonRefresh = new Button();
maskedTextBoxPosition = new MaskedTextBox();
buttonGoToCheak = new Button();
buttonRemoveTank = new Button();
buttonCreateCompany = new Button();
panelStorage = new Panel();
buttonCollectionDel = new Button();
@ -38,19 +45,19 @@
radioButtonMassive = new RadioButton();
textBoxCollectionName = new TextBox();
labelCollectionName = new Label();
buttonRefresh = new Button();
buttonGoToCheak = new Button();
buttonRemoveTank = new Button();
maskedTextBoxPosition = new MaskedTextBox();
buttonAddTank = new Button();
buttonAddArtillery = new Button();
comboBoxSelectorCompany = new ComboBox();
pictureBox = new PictureBox();
panelCompanyTools = new Panel();
menuStrip = new MenuStrip();
файлToolStripMenuItem = new ToolStripMenuItem();
saveToolStripMenuItem = new ToolStripMenuItem();
loadToolStripMenuItem = new ToolStripMenuItem();
saveFileDialog = new SaveFileDialog();
openFileDialog = new OpenFileDialog();
groupBoxTools.SuspendLayout();
panelCompanyTools.SuspendLayout();
panelStorage.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
panelCompanyTools.SuspendLayout();
menuStrip.SuspendLayout();
SuspendLayout();
//
// groupBoxTools
@ -60,13 +67,91 @@
groupBoxTools.Controls.Add(panelStorage);
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(715, 0);
groupBoxTools.Location = new Point(715, 24);
groupBoxTools.Name = "groupBoxTools";
groupBoxTools.Size = new Size(200, 508);
groupBoxTools.Size = new Size(200, 484);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
// panelCompanyTools
//
panelCompanyTools.Controls.Add(buttonAddTank);
panelCompanyTools.Controls.Add(buttonAddArtillery);
panelCompanyTools.Controls.Add(buttonRefresh);
panelCompanyTools.Controls.Add(maskedTextBoxPosition);
panelCompanyTools.Controls.Add(buttonGoToCheak);
panelCompanyTools.Controls.Add(buttonRemoveTank);
panelCompanyTools.Dock = DockStyle.Bottom;
panelCompanyTools.Enabled = false;
panelCompanyTools.Location = new Point(3, 276);
panelCompanyTools.Name = "panelCompanyTools";
panelCompanyTools.Size = new Size(194, 205);
panelCompanyTools.TabIndex = 9;
//
// buttonAddTank
//
buttonAddTank.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddTank.Location = new Point(12, 9);
buttonAddTank.Name = "buttonAddTank";
buttonAddTank.Size = new Size(170, 30);
buttonAddTank.TabIndex = 2;
buttonAddTank.Text = "Добавление танка";
buttonAddTank.UseVisualStyleBackColor = true;
buttonAddTank.Click += ButtonAddTank_Click;
//
// buttonAddArtillery
//
buttonAddArtillery.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddArtillery.Location = new Point(12, 45);
buttonAddArtillery.Name = "buttonAddArtillery";
buttonAddArtillery.Size = new Size(170, 31);
buttonAddArtillery.TabIndex = 1;
buttonAddArtillery.Text = "Добавление сау";
buttonAddArtillery.UseVisualStyleBackColor = true;
//
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRefresh.Location = new Point(12, 174);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(170, 23);
buttonRefresh.TabIndex = 6;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += ButtonRefresh_Click;
//
// maskedTextBoxPosition
//
maskedTextBoxPosition.Location = new Point(12, 82);
maskedTextBoxPosition.Mask = "00";
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
maskedTextBoxPosition.Size = new Size(176, 23);
maskedTextBoxPosition.TabIndex = 3;
maskedTextBoxPosition.ValidatingType = typeof(int);
//
// buttonGoToCheak
//
buttonGoToCheak.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonGoToCheak.Location = new Point(12, 143);
buttonGoToCheak.Name = "buttonGoToCheak";
buttonGoToCheak.Size = new Size(170, 25);
buttonGoToCheak.TabIndex = 5;
buttonGoToCheak.Text = "Передать на тесты";
buttonGoToCheak.UseVisualStyleBackColor = true;
buttonGoToCheak.Click += ButtonGoToCheak_Click;
//
// buttonRemoveTank
//
buttonRemoveTank.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRemoveTank.Location = new Point(12, 110);
buttonRemoveTank.Name = "buttonRemoveTank";
buttonRemoveTank.Size = new Size(170, 27);
buttonRemoveTank.TabIndex = 4;
buttonRemoveTank.Text = "Удалить танк";
buttonRemoveTank.UseVisualStyleBackColor = true;
buttonRemoveTank.Click += ButtonRemoveTank_Click;
//
// buttonCreateCompany
//
buttonCreateCompany.Location = new Point(5, 267);
@ -159,69 +244,6 @@
labelCollectionName.TabIndex = 0;
labelCollectionName.Text = "Название коллекции:";
//
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRefresh.Location = new Point(12, 174);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(170, 23);
buttonRefresh.TabIndex = 6;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += ButtonRefresh_Click;
//
// buttonGoToCheak
//
buttonGoToCheak.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonGoToCheak.Location = new Point(12, 143);
buttonGoToCheak.Name = "buttonGoToCheak";
buttonGoToCheak.Size = new Size(170, 25);
buttonGoToCheak.TabIndex = 5;
buttonGoToCheak.Text = "Передать на тесты";
buttonGoToCheak.UseVisualStyleBackColor = true;
buttonGoToCheak.Click += ButtonGoToCheak_Click;
//
// buttonRemoveTank
//
buttonRemoveTank.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRemoveTank.Location = new Point(12, 110);
buttonRemoveTank.Name = "buttonRemoveTank";
buttonRemoveTank.Size = new Size(170, 27);
buttonRemoveTank.TabIndex = 4;
buttonRemoveTank.Text = "Удалить танк";
buttonRemoveTank.UseVisualStyleBackColor = true;
buttonRemoveTank.Click += ButtonRemoveTank_Click;
//
// maskedTextBoxPosition
//
maskedTextBoxPosition.Location = new Point(12, 82);
maskedTextBoxPosition.Mask = "00";
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
maskedTextBoxPosition.Size = new Size(176, 23);
maskedTextBoxPosition.TabIndex = 3;
maskedTextBoxPosition.ValidatingType = typeof(int);
//
// buttonAddTank
//
buttonAddTank.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddTank.Location = new Point(12, 9);
buttonAddTank.Name = "buttonAddTank";
buttonAddTank.Size = new Size(170, 30);
buttonAddTank.TabIndex = 2;
buttonAddTank.Text = "Добавление танка";
buttonAddTank.UseVisualStyleBackColor = true;
buttonAddTank.Click += ButtonAddTank_Click;
//
// buttonAddArtillery
//
buttonAddArtillery.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddArtillery.Location = new Point(12, 45);
buttonAddArtillery.Name = "buttonAddArtillery";
buttonAddArtillery.Size = new Size(170, 31);
buttonAddArtillery.TabIndex = 1;
buttonAddArtillery.Text = "Добавление сау";
buttonAddArtillery.UseVisualStyleBackColor = true;
//
// comboBoxSelectorCompany
//
comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
@ -237,26 +259,53 @@
// pictureBox
//
pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 0);
pictureBox.Location = new Point(0, 24);
pictureBox.Name = "pictureBox";
pictureBox.Size = new Size(715, 508);
pictureBox.Size = new Size(715, 484);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
pictureBox.Click += pictureBox_Click;
//
// panelCompanyTools
// menuStrip
//
panelCompanyTools.Controls.Add(buttonAddTank);
panelCompanyTools.Controls.Add(buttonAddArtillery);
panelCompanyTools.Controls.Add(buttonRefresh);
panelCompanyTools.Controls.Add(maskedTextBoxPosition);
panelCompanyTools.Controls.Add(buttonGoToCheak);
panelCompanyTools.Controls.Add(buttonRemoveTank);
panelCompanyTools.Dock = DockStyle.Bottom;
panelCompanyTools.Enabled = false;
panelCompanyTools.Location = new Point(3, 300);
panelCompanyTools.Name = "panelCompanyTools";
panelCompanyTools.Size = new Size(194, 205);
panelCompanyTools.TabIndex = 9;
menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem });
menuStrip.Location = new Point(0, 0);
menuStrip.Name = "menuStrip";
menuStrip.Size = new Size(915, 24);
menuStrip.TabIndex = 2;
menuStrip.Text = "menuStrip1";
//
// файлToolStripMenuItem
//
файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { saveToolStripMenuItem, loadToolStripMenuItem });
файлToolStripMenuItem.Name = айлToolStripMenuItem";
файлToolStripMenuItem.Size = new Size(48, 20);
файлToolStripMenuItem.Text = "Файл";
//
// saveToolStripMenuItem
//
saveToolStripMenuItem.Name = "saveToolStripMenuItem";
saveToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S;
saveToolStripMenuItem.Size = new Size(181, 22);
saveToolStripMenuItem.Text = "Сохранение";
saveToolStripMenuItem.Click += saveToolStripMenuItem_Click;
//
// loadToolStripMenuItem
//
loadToolStripMenuItem.Name = "loadToolStripMenuItem";
loadToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.L;
loadToolStripMenuItem.Size = new Size(181, 22);
loadToolStripMenuItem.Text = "Загрузка";
loadToolStripMenuItem.Click += loadToolStripMenuItem_Click;
//
// saveFileDialog
//
saveFileDialog.Filter = "txt file | *.txt";
//
// openFileDialog
//
openFileDialog.FileName = "openFileDialog1";
openFileDialog.Filter = "txt file | *.txt";
//
// FormTankCollection
//
@ -265,15 +314,20 @@
ClientSize = new Size(915, 508);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Controls.Add(menuStrip);
MainMenuStrip = menuStrip;
Name = "FormTankCollection";
Text = "Коллекция сау";
groupBoxTools.ResumeLayout(false);
panelCompanyTools.ResumeLayout(false);
panelCompanyTools.PerformLayout();
panelStorage.ResumeLayout(false);
panelStorage.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
panelCompanyTools.ResumeLayout(false);
panelCompanyTools.PerformLayout();
menuStrip.ResumeLayout(false);
menuStrip.PerformLayout();
ResumeLayout(false);
PerformLayout();
}
#endregion
@ -297,5 +351,11 @@
private Button buttonCreateCompany;
private Button buttonCollectionDel;
private Panel panelCompanyTools;
private MenuStrip menuStrip;
private ToolStripMenuItem файлToolStripMenuItem;
private ToolStripMenuItem saveToolStripMenuItem;
private ToolStripMenuItem loadToolStripMenuItem;
private SaveFileDialog saveFileDialog;
private OpenFileDialog openFileDialog;
}
}

View File

@ -51,7 +51,7 @@ public partial class FormTankCollection : Form
return;
}
if (_company + tank != -1)
if (_company + tank)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _company.Show();
@ -208,5 +208,57 @@ public partial class FormTankCollection : Form
panelCompanyTools.Enabled = true;
RerfreshListBoxItems();
}
private void pictureBox_Click(object sender, EventArgs e)
{
}
private void RefreshListBoxItems()
{
listBoxCollection.Items.Clear();
for (int i = 0; i < _storageCollection.Keys?.Count; i++)
{
string? colName = _storageCollection.Keys?[i];
if (!string.IsNullOrEmpty(colName))
{
listBoxCollection.Items.Add(colName);
}
}
}
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);
RefreshListBoxItems();
}
else
{
MessageBox.Show("Не загрузилось", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

View File

@ -117,4 +117,13 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</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>126, 17</value>
</metadata>
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>261, 17</value>
</metadata>
</root>