From f210de00c3bd91d3acd29bb7b5060a154bb78cb4 Mon Sep 17 00:00:00 2001 From: malimova Date: Wed, 22 Nov 2023 22:45:15 +0400 Subject: [PATCH 1/5] =?UTF-8?q?=D0=9D=D0=B0=D1=87=D0=B0=D0=BB=D0=BE=20Lab6?= =?UTF-8?q?.=20=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BA?= =?UTF-8?q?=D0=BB=D0=B0=D1=81=D1=81=D0=B0=20ExtentionDrawningAirPlane?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/ExtentionDrawningAirPlane.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 AirBomber/AirBomber/ExtentionDrawningAirPlane.cs diff --git a/AirBomber/AirBomber/ExtentionDrawningAirPlane.cs b/AirBomber/AirBomber/ExtentionDrawningAirPlane.cs new file mode 100644 index 0000000..f9a8ae4 --- /dev/null +++ b/AirBomber/AirBomber/ExtentionDrawningAirPlane.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + internal class ExtentionDrawningAirPlane + { + } +} -- 2.25.1 From 937cf9e202e467c33c1ef639ce977ae35f8eec69 Mon Sep 17 00:00:00 2001 From: malimova Date: Wed, 22 Nov 2023 22:47:20 +0400 Subject: [PATCH 2/5] =?UTF-8?q?=D0=9D=D0=B0=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0=20Ext?= =?UTF-8?q?entionDrawningAirPlane?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AirBomber/ExtentionDrawningAirPlane.cs | 50 ++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/AirBomber/AirBomber/ExtentionDrawningAirPlane.cs b/AirBomber/AirBomber/ExtentionDrawningAirPlane.cs index f9a8ae4..5552817 100644 --- a/AirBomber/AirBomber/ExtentionDrawningAirPlane.cs +++ b/AirBomber/AirBomber/ExtentionDrawningAirPlane.cs @@ -6,7 +6,55 @@ using System.Threading.Tasks; namespace AirBomber { - internal class ExtentionDrawningAirPlane + public static class ExtentionDrawningAirPlane { + /// + /// Создание объекта из строки + /// + /// Строка с данными для создания объекта + /// Разделитель даннных + /// Ширина + /// Высота + /// Объект + public static DrawningAirPlane? CreateDrawningAirPlane(this string info, char separatorForObject, int width, int height) + { + string[] strs = info.Split(separatorForObject); + if (strs.Length == 3) + { + return new DrawningAirPlane(Convert.ToInt32(strs[0]), + Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height); + } + if (strs.Length == 7) + { + return new DrawningAirBomber(Convert.ToInt32(strs[0]), + Convert.ToInt32(strs[1]), + Color.FromName(strs[2]), + Color.FromName(strs[3]), + Convert.ToBoolean(strs[4]), + Convert.ToBoolean(strs[5]), width, height); + } + return null; + } + /// + /// Получение данных для сохранения в файл + /// + /// Сохраняемый объект + /// Разделитель даннных + /// Строка с данными по объекту + public static string GetDataForSave(this DrawningAirPlane drawningAirPlane, char separatorForObject) + { + var plane = drawningAirPlane.EntityAirPlane; + if (plane == null) + { + return string.Empty; + } + var str = $"{plane.Speed}{separatorForObject}{plane.Weight}{separatorForObject}{plane.BodyColor.Name}"; + if (plane is not EntityAirBomber airBomber) + { + return str; + } + return $"{str}{separatorForObject}{airBomber.AdditionalColor.Name}{separatorForObject}{airBomber.Bombs}{separatorForObject}{airBomber.FuelTanks}"; + } } } + -- 2.25.1 From 7adc066c5c4dc741a38e3eb85f86ceaeebdaa648 Mon Sep 17 00:00:00 2001 From: malimova Date: Wed, 22 Nov 2023 23:08:45 +0400 Subject: [PATCH 3/5] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=BD=D1=8B=D0=B9=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=20?= =?UTF-8?q?=D0=B2=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81-=D0=BA=D0=BE=D0=BB?= =?UTF-8?q?=D0=BB=D0=B5=D0=BA=D1=86=D0=B8=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/PlanesGenericCollection.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/AirBomber/AirBomber/PlanesGenericCollection.cs b/AirBomber/AirBomber/PlanesGenericCollection.cs index b9950a1..80f7989 100644 --- a/AirBomber/AirBomber/PlanesGenericCollection.cs +++ b/AirBomber/AirBomber/PlanesGenericCollection.cs @@ -132,5 +132,9 @@ namespace AirBomber } } } + /// + /// Получение объектов коллекции + /// + public IEnumerable GetPlanes => _collection.GetPlanes(); } } -- 2.25.1 From 906637e4b81888fece58ecabc7cc9aa7063bb76d Mon Sep 17 00:00:00 2001 From: malimova Date: Sun, 26 Nov 2023 13:23:44 +0400 Subject: [PATCH 4/5] =?UTF-8?q?=D0=94=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F,=20=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8,=20?= =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD=D1=8B=20TODO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AirBomber/ExtentionDrawningAirPlane.cs | 8 +- .../AirBomber/FormPlaneCollection.Designer.cs | 62 ++++++++++- AirBomber/AirBomber/FormPlaneCollection.cs | 48 ++++++++- AirBomber/AirBomber/FormPlaneCollection.resx | 12 +++ .../AirBomber/FormPlaneConfig.Designer.cs | 2 +- AirBomber/AirBomber/PlanesGenericStorage.cs | 102 ++++++++++++++++++ 6 files changed, 225 insertions(+), 9 deletions(-) diff --git a/AirBomber/AirBomber/ExtentionDrawningAirPlane.cs b/AirBomber/AirBomber/ExtentionDrawningAirPlane.cs index 5552817..a3308d2 100644 --- a/AirBomber/AirBomber/ExtentionDrawningAirPlane.cs +++ b/AirBomber/AirBomber/ExtentionDrawningAirPlane.cs @@ -24,7 +24,7 @@ namespace AirBomber return new DrawningAirPlane(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height); } - if (strs.Length == 7) + if (strs.Length == 6) { return new DrawningAirBomber(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), @@ -53,7 +53,11 @@ namespace AirBomber { return str; } - return $"{str}{separatorForObject}{airBomber.AdditionalColor.Name}{separatorForObject}{airBomber.Bombs}{separatorForObject}{airBomber.FuelTanks}"; + else + { + return $"{str}{separatorForObject}{airBomber.AdditionalColor.Name}{separatorForObject}{airBomber.Bombs}{separatorForObject}{airBomber.FuelTanks}"; + } + } } } diff --git a/AirBomber/AirBomber/FormPlaneCollection.Designer.cs b/AirBomber/AirBomber/FormPlaneCollection.Designer.cs index b670071..be572a7 100644 --- a/AirBomber/AirBomber/FormPlaneCollection.Designer.cs +++ b/AirBomber/AirBomber/FormPlaneCollection.Designer.cs @@ -39,18 +39,25 @@ buttonDelObject = new Button(); buttonAddObject = new Button(); listBoxStorages = new ListBox(); + menuStrip = new MenuStrip(); + ToolStripMenuItem = new ToolStripMenuItem(); + сохранениеToolStripMenuItem = new ToolStripMenuItem(); + загрузкаToolStripMenuItem = new ToolStripMenuItem(); + openFileDialog = new OpenFileDialog(); + saveFileDialog = new SaveFileDialog(); ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit(); groupBoxTools.SuspendLayout(); groupBoxStorages.SuspendLayout(); + menuStrip.SuspendLayout(); SuspendLayout(); // // pictureBoxCollection // pictureBoxCollection.BackColor = SystemColors.Control; pictureBoxCollection.Dock = DockStyle.Left; - pictureBoxCollection.Location = new Point(0, 0); + pictureBoxCollection.Location = new Point(0, 33); pictureBoxCollection.Name = "pictureBoxCollection"; - pictureBoxCollection.Size = new Size(708, 746); + pictureBoxCollection.Size = new Size(708, 713); pictureBoxCollection.TabIndex = 0; pictureBoxCollection.TabStop = false; // @@ -157,6 +164,46 @@ listBoxStorages.TabIndex = 0; listBoxStorages.SelectedIndexChanged += listBoxStorages_SelectedIndexChanged; // + // menuStrip + // + menuStrip.ImageScalingSize = new Size(24, 24); + menuStrip.Items.AddRange(new ToolStripItem[] { ToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Size = new Size(1030, 33); + menuStrip.TabIndex = 5; + menuStrip.Text = "menuStrip1"; + // + // ToolStripMenuItem + // + ToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { сохранениеToolStripMenuItem, загрузкаToolStripMenuItem }); + ToolStripMenuItem.Name = "ToolStripMenuItem"; + ToolStripMenuItem.Size = new Size(69, 29); + ToolStripMenuItem.Text = "Файл"; + // + // сохранениеToolStripMenuItem + // + сохранениеToolStripMenuItem.Name = "сохранениеToolStripMenuItem"; + сохранениеToolStripMenuItem.Size = new Size(270, 34); + сохранениеToolStripMenuItem.Text = "Сохранение"; + сохранениеToolStripMenuItem.Click += SaveToolStripMenuItem_Click; + // + // загрузкаToolStripMenuItem + // + загрузкаToolStripMenuItem.Name = "загрузкаToolStripMenuItem"; + загрузкаToolStripMenuItem.Size = new Size(270, 34); + загрузкаToolStripMenuItem.Text = "Загрузка"; + загрузкаToolStripMenuItem.Click += LoadToolStripMenuItem_Click; + // + // openFileDialog + // + openFileDialog.FileName = "openFileDialog1"; + openFileDialog.Filter = "txt file | *.txt"; + // + // saveFileDialog + // + saveFileDialog.Filter = "txt file | *.txt"; + // // FormPlaneCollection // AutoScaleDimensions = new SizeF(10F, 25F); @@ -164,6 +211,8 @@ ClientSize = new Size(1030, 746); Controls.Add(groupBoxTools); Controls.Add(pictureBoxCollection); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; Name = "FormPlaneCollection"; Text = "Набор самолетов"; ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit(); @@ -171,7 +220,10 @@ groupBoxTools.PerformLayout(); groupBoxStorages.ResumeLayout(false); groupBoxStorages.PerformLayout(); + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); ResumeLayout(false); + PerformLayout(); } #endregion @@ -187,5 +239,11 @@ private Button buttonDelObject; private Button buttonAddObject; private ListBox listBoxStorages; + private MenuStrip menuStrip; + private ToolStripMenuItem ToolStripMenuItem; + private ToolStripMenuItem сохранениеToolStripMenuItem; + private ToolStripMenuItem загрузкаToolStripMenuItem; + private OpenFileDialog openFileDialog; + private SaveFileDialog saveFileDialog; } } \ No newline at end of file diff --git a/AirBomber/AirBomber/FormPlaneCollection.cs b/AirBomber/AirBomber/FormPlaneCollection.cs index 6ed5627..2c07129 100644 --- a/AirBomber/AirBomber/FormPlaneCollection.cs +++ b/AirBomber/AirBomber/FormPlaneCollection.cs @@ -49,7 +49,7 @@ namespace AirBomber /// private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e) { - pictureBoxCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString()?? string.Empty]?.ShowPlanes(); + pictureBoxCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowPlanes(); } /// /// Добавление объекта в набор @@ -157,11 +157,51 @@ namespace AirBomber return; } if (MessageBox.Show($"Удалить объект{listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) -{ - _storage.DelSet(listBoxStorages.SelectedItem.ToString()?? string.Empty); + { + _storage.DelSet(listBoxStorages.SelectedItem.ToString() ?? string.Empty); ReloadObjects(); } } - + /// + /// Обработка нажатия "Сохранение" + /// + /// + /// + private void SaveToolStripMenuItem_Click(object sender, EventArgs e) + { + if (saveFileDialog.ShowDialog() == DialogResult.OK) + { + if (_storage.SaveData(saveFileDialog.FileName)) + { + MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + /// + /// Обработка нажатия "Загрузка" + /// + /// + /// + private void LoadToolStripMenuItem_Click(object sender, EventArgs e) + { + // TODO продумать логику DONE + if (openFileDialog.ShowDialog() == DialogResult.OK) + { + if (_storage.LoadData(openFileDialog.FileName)) + { + MessageBox.Show("Загрузка прошла успешно!", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + ReloadObjects(); + } + else + { + MessageBox.Show("Не загрузилось!", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + + } + } + } } } diff --git a/AirBomber/AirBomber/FormPlaneCollection.resx b/AirBomber/AirBomber/FormPlaneCollection.resx index f298a7b..0459224 100644 --- a/AirBomber/AirBomber/FormPlaneCollection.resx +++ b/AirBomber/AirBomber/FormPlaneCollection.resx @@ -57,4 +57,16 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + + + 163, 17 + + + 357, 17 + + + 71 + \ No newline at end of file diff --git a/AirBomber/AirBomber/FormPlaneConfig.Designer.cs b/AirBomber/AirBomber/FormPlaneConfig.Designer.cs index dbf6319..1eaa16d 100644 --- a/AirBomber/AirBomber/FormPlaneConfig.Designer.cs +++ b/AirBomber/AirBomber/FormPlaneConfig.Designer.cs @@ -175,7 +175,7 @@ // // panelGreen // - panelGreen.BackColor = Color.FromArgb(0, 192, 0); + panelGreen.BackColor = Color.Green; panelGreen.Location = new Point(96, 43); panelGreen.Name = "panelGreen"; panelGreen.Size = new Size(54, 54); diff --git a/AirBomber/AirBomber/PlanesGenericStorage.cs b/AirBomber/AirBomber/PlanesGenericStorage.cs index 40918b3..3de897f 100644 --- a/AirBomber/AirBomber/PlanesGenericStorage.cs +++ b/AirBomber/AirBomber/PlanesGenericStorage.cs @@ -25,6 +25,18 @@ namespace AirBomber /// private readonly int _pictureHeight; /// + /// Разделитель для записи ключа и значения элемента словаря + /// + private static readonly char _separatorForKeyValue = '|'; + /// + /// Разделитель для записей коллекции данных в файл + /// + private readonly char _separatorRecords = ';'; + /// + /// Разделитель для записи информации по объекту в файл + /// + private static readonly char _separatorForObject = ':'; + /// /// Конструктор /// /// @@ -77,5 +89,95 @@ namespace AirBomber return null; } } + /// + /// Сохранение информации по самолетам в хранилище в файл + /// + /// Путь и имя файла + /// true - сохранение прошло успешно, false - ошибка при сохранении данных + public bool SaveData(string filename) + { + if (File.Exists(filename)) + { + File.Delete(filename); + } + StringBuilder data = new(); + foreach (KeyValuePair>record in _planeStorages) + { + StringBuilder records = new(); + foreach (DrawningAirPlane? elem in record.Value.GetPlanes) + { + records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}"); + } + data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}"); + } + if (data.Length == 0) + { + return false; + } + + using StreamWriter sw = new(filename); + sw.Write($"PlaneStorage{Environment.NewLine}{data}"); + return true; + } + /// + /// Загрузка информации по самолетам в хранилище из файла + /// + /// Путь и имя файла + /// true - загрузка прошла успешно, false - ошибка при загрузке данных + public bool LoadData(string filename) + { + if (!File.Exists(filename)) + { + return false; + } + using (StreamReader sr = new(filename)) + { + string str = sr.ReadLine(); + + if (str == null || str.Length == 0) + { + return false; + } + if (!str.StartsWith("PlaneStorage")) + { + //если нет такой записи, то это не те данные + return false; + } + + _planeStorages.Clear(); + string strs = ""; + + while ((strs = sr.ReadLine()) != null) + { + if (strs == null) + { + return false; + } + + string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries); + if (record.Length != 2) + { + continue; + } + + PlanesGenericCollection collection = new(_pictureWidth, _pictureHeight); + string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries); + + foreach (string elem in set) + { + DrawningAirPlane? plane = elem?.CreateDrawningAirPlane(_separatorForObject, _pictureWidth, _pictureHeight); + if (plane != null) + { + if ((collection + plane) == -1) + { + return false; + } + } + } + _planeStorages.Add(record[0], collection); + } + return true; + } + } } } -- 2.25.1 From 726373a2a1fda7f624bca1544076c83725dde3dc Mon Sep 17 00:00:00 2001 From: malimova Date: Wed, 29 Nov 2023 21:20:11 +0400 Subject: [PATCH 5/5] =?UTF-8?q?Lab6=20=D1=81=D0=B4=D0=B0=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AirBomber/FormPlaneCollection.Designer.cs | 30 +++++++++---------- AirBomber/AirBomber/FormPlaneConfig.cs | 3 -- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/AirBomber/AirBomber/FormPlaneCollection.Designer.cs b/AirBomber/AirBomber/FormPlaneCollection.Designer.cs index be572a7..dfb5dfb 100644 --- a/AirBomber/AirBomber/FormPlaneCollection.Designer.cs +++ b/AirBomber/AirBomber/FormPlaneCollection.Designer.cs @@ -41,8 +41,8 @@ listBoxStorages = new ListBox(); menuStrip = new MenuStrip(); ToolStripMenuItem = new ToolStripMenuItem(); - сохранениеToolStripMenuItem = new ToolStripMenuItem(); - загрузкаToolStripMenuItem = new ToolStripMenuItem(); + SaveToolStripMenuItem = new ToolStripMenuItem(); + LoadToolStripMenuItem = new ToolStripMenuItem(); openFileDialog = new OpenFileDialog(); saveFileDialog = new SaveFileDialog(); ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit(); @@ -176,24 +176,24 @@ // // ToolStripMenuItem // - ToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { сохранениеToolStripMenuItem, загрузкаToolStripMenuItem }); + ToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { SaveToolStripMenuItem, LoadToolStripMenuItem }); ToolStripMenuItem.Name = "ToolStripMenuItem"; ToolStripMenuItem.Size = new Size(69, 29); ToolStripMenuItem.Text = "Файл"; // - // сохранениеToolStripMenuItem + // SaveToolStripMenuItem // - сохранениеToolStripMenuItem.Name = "сохранениеToolStripMenuItem"; - сохранениеToolStripMenuItem.Size = new Size(270, 34); - сохранениеToolStripMenuItem.Text = "Сохранение"; - сохранениеToolStripMenuItem.Click += SaveToolStripMenuItem_Click; + SaveToolStripMenuItem.Name = "SaveToolStripMenuItem"; + SaveToolStripMenuItem.Size = new Size(270, 34); + SaveToolStripMenuItem.Text = "Сохранение"; + SaveToolStripMenuItem.Click += SaveToolStripMenuItem_Click; // - // загрузкаToolStripMenuItem + // LoadToolStripMenuItem // - загрузкаToolStripMenuItem.Name = "загрузкаToolStripMenuItem"; - загрузкаToolStripMenuItem.Size = new Size(270, 34); - загрузкаToolStripMenuItem.Text = "Загрузка"; - загрузкаToolStripMenuItem.Click += LoadToolStripMenuItem_Click; + LoadToolStripMenuItem.Name = "LoadToolStripMenuItem"; + LoadToolStripMenuItem.Size = new Size(270, 34); + LoadToolStripMenuItem.Text = "Загрузка"; + LoadToolStripMenuItem.Click += LoadToolStripMenuItem_Click; // // openFileDialog // @@ -241,8 +241,8 @@ private ListBox listBoxStorages; private MenuStrip menuStrip; private ToolStripMenuItem ToolStripMenuItem; - private ToolStripMenuItem сохранениеToolStripMenuItem; - private ToolStripMenuItem загрузкаToolStripMenuItem; + private ToolStripMenuItem SaveToolStripMenuItem; + private ToolStripMenuItem LoadToolStripMenuItem; private OpenFileDialog openFileDialog; private SaveFileDialog saveFileDialog; } diff --git a/AirBomber/AirBomber/FormPlaneConfig.cs b/AirBomber/AirBomber/FormPlaneConfig.cs index b41872a..c9dd6b3 100644 --- a/AirBomber/AirBomber/FormPlaneConfig.cs +++ b/AirBomber/AirBomber/FormPlaneConfig.cs @@ -24,9 +24,6 @@ namespace AirBomber /// /// Конструктор /// - /// - /// Конструктор - /// public FormPlaneConfig() { InitializeComponent(); -- 2.25.1