This commit is contained in:
Baryshev Dmitry 2024-05-03 12:01:06 +04:00
parent a261b3d661
commit 1b5742017b
7 changed files with 81 additions and 36 deletions

View File

@ -45,7 +45,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

@ -18,16 +18,15 @@ public static class ExtentionDrawningTruck
public static DrawningTruck? CreateDrawningTruck(this string info) public static DrawningTruck? CreateDrawningTruck(this string info)
{ {
string[] strs = info.Split(_separatorForObject); string[] strs = info.Split(_separatorForObject);
EntityTruck? truck = EntityDumpTruck.CreateEntityDumpTruck(strs); EntityTruck? truck = EntityDumpTruck.CreateEntityDumpTruck(strs);
if (truck != null) return new DrawningDumpTruck(truck); if (truck != null) return new DrawningDumpTruck(truck);
truck = EntityTruck.CreateEntityTruck(strs); truck = EntityTruck.CreateEntityTruck(strs);
if (truck != null)
{ if (truck != null) return new DrawningTruck(truck);
return new DrawningTruck(truck);
}
return null; return null;
} }

View File

@ -43,7 +43,7 @@ public class EntityDumpTruck : EntityTruck
Tent = tent; Tent = tent;
} }
public virtual string[] GetStringRepresentation() public override string[] GetStringRepresentation()
{ {
return new[] { nameof(EntityDumpTruck), Speed.ToString(), Weight.ToString(), BodyColor.Name, AdditionalColor.Name, Awning.ToString() , Tent.ToString() }; return new[] { nameof(EntityDumpTruck), Speed.ToString(), Weight.ToString(), BodyColor.Name, AdditionalColor.Name, Awning.ToString() , Tent.ToString() };
} }

View File

@ -48,8 +48,10 @@
pictureBox = new PictureBox(); pictureBox = new PictureBox();
menuStrip = new MenuStrip(); menuStrip = new MenuStrip();
файлToolStripMenuItem = new ToolStripMenuItem(); файлToolStripMenuItem = new ToolStripMenuItem();
SaveToolStripMenuItem = new ToolStripMenuItem(); saveToolStripMenuItem = new ToolStripMenuItem();
LoadToolStripMenuItem = new ToolStripMenuItem(); loadToolStripMenuItem = new ToolStripMenuItem();
saveFileDialog = new SaveFileDialog();
openFileDialog = new OpenFileDialog();
groupBoxTools.SuspendLayout(); groupBoxTools.SuspendLayout();
panelStorage.SuspendLayout(); panelStorage.SuspendLayout();
panelCompanyTools.SuspendLayout(); panelCompanyTools.SuspendLayout();
@ -255,24 +257,34 @@
// //
// файлToolStripMenuItem // файлToolStripMenuItem
// //
файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { SaveToolStripMenuItem, LoadToolStripMenuItem }); файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { saveToolStripMenuItem, loadToolStripMenuItem });
файлToolStripMenuItem.Name = айлToolStripMenuItem"; файлToolStripMenuItem.Name = айлToolStripMenuItem";
файлToolStripMenuItem.Size = new Size(59, 24); файлToolStripMenuItem.Size = new Size(59, 24);
файлToolStripMenuItem.Text = "Файл"; файлToolStripMenuItem.Text = "Файл";
// //
// SaveToolStripMenuItem // saveToolStripMenuItem
// //
SaveToolStripMenuItem.Name = "SaveToolStripMenuItem"; saveToolStripMenuItem.Name = "saveToolStripMenuItem";
SaveToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S; saveToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S;
SaveToolStripMenuItem.Size = new Size(227, 26); saveToolStripMenuItem.Size = new Size(227, 26);
SaveToolStripMenuItem.Text = "Сохранение"; saveToolStripMenuItem.Text = "Сохранение";
saveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
// //
// LoadToolStripMenuItem // loadToolStripMenuItem
// //
LoadToolStripMenuItem.Name = "LoadToolStripMenuItem"; loadToolStripMenuItem.Name = "loadToolStripMenuItem";
LoadToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.L; loadToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.L;
LoadToolStripMenuItem.Size = new Size(227, 26); loadToolStripMenuItem.Size = new Size(227, 26);
LoadToolStripMenuItem.Text = "Загрузка"; loadToolStripMenuItem.Text = "Загрузка";
loadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
//
// saveFileDialog
//
saveFileDialog.Filter = "txt file | *.txt";
//
// openFileDialog
//
openFileDialog.Filter = "txt file | *.txt";
// //
// FormTruckCollection // FormTruckCollection
// //
@ -319,7 +331,9 @@
private Button buttonCollectionDel; private Button buttonCollectionDel;
private MenuStrip menuStrip; private MenuStrip menuStrip;
private ToolStripMenuItem файлToolStripMenuItem; private ToolStripMenuItem файлToolStripMenuItem;
private ToolStripMenuItem SaveToolStripMenuItem; private ToolStripMenuItem saveToolStripMenuItem;
private ToolStripMenuItem LoadToolStripMenuItem; private ToolStripMenuItem loadToolStripMenuItem;
private SaveFileDialog saveFileDialog;
private OpenFileDialog openFileDialog;
} }
} }

View File

@ -238,6 +238,47 @@ public partial class FormTruckCollection : Form
panelCompanyTools.Enabled = true; panelCompanyTools.Enabled = true;
RefreshListBoxItems(); RefreshListBoxItems();
} }
/// <summary>
/// Обработка нажатия "Сохранение"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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);
}
}
}
/// <summary>
/// Обработка нажатия "Загрузка"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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

@ -120,4 +120,10 @@
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value> <value>17, 17</value>
</metadata> </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>
</root> </root>

View File

@ -1,15 +0,0 @@
using ProjectDumpTruck.Drawnings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectDumpTruck;
/// <summary>
/// Делегат переадчи объекта класса-прорисовки
/// </summary>
/// <param name="truck"></param>
public delegate void TruckDelegate(DrawningTruck truck);