diff --git a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObject/AbstractCompany.cs b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObject/AbstractCompany.cs index a1ccc44..ae1c735 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObject/AbstractCompany.cs +++ b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObject/AbstractCompany.cs @@ -45,7 +45,7 @@ public abstract class AbstractCompany _pictureWidth = picWidth; _pictureHeight = picHeight; _collection = collection; - _collection.SetMaxCount = GetMaxCount; + _collection.MaxCount = GetMaxCount; } /// /// Перегрузка оператора сложения для класса diff --git a/ProjectDumpTruck/ProjectDumpTruck/Drawnings/ExtentionDrawningTruck.cs b/ProjectDumpTruck/ProjectDumpTruck/Drawnings/ExtentionDrawningTruck.cs index af05436..7eb01d2 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/Drawnings/ExtentionDrawningTruck.cs +++ b/ProjectDumpTruck/ProjectDumpTruck/Drawnings/ExtentionDrawningTruck.cs @@ -18,17 +18,16 @@ public static class ExtentionDrawningTruck public static DrawningTruck? CreateDrawningTruck(this string info) { string[] strs = info.Split(_separatorForObject); + EntityTruck? truck = EntityDumpTruck.CreateEntityDumpTruck(strs); if (truck != null) return new DrawningDumpTruck(truck); truck = EntityTruck.CreateEntityTruck(strs); - if (truck != null) - { - return new DrawningTruck(truck); - } + if (truck != null) return new DrawningTruck(truck); + return null; } diff --git a/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityDumpTruck.cs b/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityDumpTruck.cs index 5ebd2c2..62329c6 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityDumpTruck.cs +++ b/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityDumpTruck.cs @@ -43,7 +43,7 @@ public class EntityDumpTruck : EntityTruck 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() }; } diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.Designer.cs b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.Designer.cs index a09c692..fdafef4 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.Designer.cs +++ b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.Designer.cs @@ -48,8 +48,10 @@ pictureBox = new PictureBox(); menuStrip = new MenuStrip(); файлToolStripMenuItem = new ToolStripMenuItem(); - SaveToolStripMenuItem = new ToolStripMenuItem(); - LoadToolStripMenuItem = new ToolStripMenuItem(); + saveToolStripMenuItem = new ToolStripMenuItem(); + loadToolStripMenuItem = new ToolStripMenuItem(); + saveFileDialog = new SaveFileDialog(); + openFileDialog = new OpenFileDialog(); groupBoxTools.SuspendLayout(); panelStorage.SuspendLayout(); panelCompanyTools.SuspendLayout(); @@ -255,24 +257,34 @@ // // файлToolStripMenuItem // - файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { SaveToolStripMenuItem, LoadToolStripMenuItem }); + файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { saveToolStripMenuItem, loadToolStripMenuItem }); файлToolStripMenuItem.Name = "файлToolStripMenuItem"; файлToolStripMenuItem.Size = new Size(59, 24); файлToolStripMenuItem.Text = "Файл"; // - // SaveToolStripMenuItem + // saveToolStripMenuItem // - SaveToolStripMenuItem.Name = "SaveToolStripMenuItem"; - SaveToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S; - SaveToolStripMenuItem.Size = new Size(227, 26); - SaveToolStripMenuItem.Text = "Сохранение"; + saveToolStripMenuItem.Name = "saveToolStripMenuItem"; + saveToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S; + saveToolStripMenuItem.Size = new Size(227, 26); + saveToolStripMenuItem.Text = "Сохранение"; + saveToolStripMenuItem.Click += SaveToolStripMenuItem_Click; // - // LoadToolStripMenuItem + // loadToolStripMenuItem // - LoadToolStripMenuItem.Name = "LoadToolStripMenuItem"; - LoadToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.L; - LoadToolStripMenuItem.Size = new Size(227, 26); - LoadToolStripMenuItem.Text = "Загрузка"; + loadToolStripMenuItem.Name = "loadToolStripMenuItem"; + loadToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.L; + loadToolStripMenuItem.Size = new Size(227, 26); + loadToolStripMenuItem.Text = "Загрузка"; + loadToolStripMenuItem.Click += LoadToolStripMenuItem_Click; + // + // saveFileDialog + // + saveFileDialog.Filter = "txt file | *.txt"; + // + // openFileDialog + // + openFileDialog.Filter = "txt file | *.txt"; // // FormTruckCollection // @@ -319,7 +331,9 @@ private Button buttonCollectionDel; private MenuStrip menuStrip; private ToolStripMenuItem файлToolStripMenuItem; - private ToolStripMenuItem SaveToolStripMenuItem; - private ToolStripMenuItem LoadToolStripMenuItem; + private ToolStripMenuItem saveToolStripMenuItem; + private ToolStripMenuItem loadToolStripMenuItem; + private SaveFileDialog saveFileDialog; + private OpenFileDialog openFileDialog; } } \ No newline at end of file diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.cs b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.cs index 1e74ff6..a35e3e0 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.cs +++ b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.cs @@ -238,6 +238,47 @@ public partial class FormTruckCollection : Form panelCompanyTools.Enabled = true; RefreshListBoxItems(); } + + /// + /// Обработка нажатия "Сохранение" + /// + /// + /// + 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); + } + } + } } diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.resx b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.resx index 6c82d08..ee1748a 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.resx +++ b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.resx @@ -120,4 +120,10 @@ 17, 17 + + 145, 17 + + + 310, 17 + \ No newline at end of file diff --git a/ProjectDumpTruck/ProjectDumpTruck/TruckDelegate.cs b/ProjectDumpTruck/ProjectDumpTruck/TruckDelegate.cs deleted file mode 100644 index 002ab38..0000000 --- a/ProjectDumpTruck/ProjectDumpTruck/TruckDelegate.cs +++ /dev/null @@ -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; - -/// -/// Делегат переадчи объекта класса-прорисовки -/// -/// -public delegate void TruckDelegate(DrawningTruck truck); -