From 7dfb6b2606200866d5c9e5fc517e545744ef7e62 Mon Sep 17 00:00:00 2001 From: Kirill <117719052+KirillFirsof@users.noreply.github.com> Date: Fri, 8 Dec 2023 08:35:28 +0400 Subject: [PATCH 1/6] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BB=202=20?= =?UTF-8?q?=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ExtentionDrawningTractor.cs | 68 +++++++++++ .../TractorsGenericCollection.cs | 4 + .../TractorsGenericStorage.cs | 109 ++++++++++++++++++ 3 files changed, 181 insertions(+) create mode 100644 RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/ExtentionDrawningTractor.cs diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/ExtentionDrawningTractor.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/ExtentionDrawningTractor.cs new file mode 100644 index 0000000..1b9b807 --- /dev/null +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/ExtentionDrawningTractor.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectTractor.Entities; + +namespace ProjectTractor.DrawningObjects +{ + /// + /// Расширение для класса EntityTractor + /// + public static class ExtentionDrawningTractor + { + /// + /// Создание объекта из строки + /// + /// Строка с данными для создания объекта + /// Разделитель даннных + /// Ширина + /// Высота + /// Объект + public static DrawningTractor? CreateDrawningTractor(this string info, char + separatorForObject, int width, int height) + { + string[] strs = info.Split(separatorForObject); + if (strs.Length == 3) + { + return new DrawningTractor(Convert.ToInt32(strs[0]), + Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height); + } + if (strs.Length == 7) + { + return new DrawningBulldoser(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 DrawningTractor drawningTractor, + char separatorForObject) + { + var tractor = drawningTractor.EntityTractor; + if (tractor == null) + { + return string.Empty; + } + var str = + $"{tractor.Speed}{separatorForObject}{tractor.Weight}{separatorForObject}{tractor.BodyColor.Name}"; + if (tractor is not EntityBulldoser bulldoser) + { + return str; + } + return + $"{str}{separatorForObject}{bulldoser.AdditionalColor.Name}{separatorForObject}{bulldoser.Blade}{separatorForObject}{bulldoser.WheelsOrnament}"; + } + } + +} diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs index d978071..ffca693 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs @@ -17,6 +17,10 @@ namespace ProjectTractor.Generics where T : DrawningTractor where U : IMoveableObject { + /// + /// Получение объектов коллекции + /// + public IEnumerable GetTractors => _collection.GetTractors(); /// /// Ширина окна прорисовки /// diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericStorage.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericStorage.cs index 14ed5b5..b082c78 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericStorage.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericStorage.cs @@ -31,6 +31,18 @@ namespace ProjectTractor /// private readonly int _pictureHeight; /// + /// Разделитель для записи ключа и значения элемента словаря + /// + private static readonly char _separatorForKeyValue = '|'; + /// + /// Разделитель для записей коллекции данных в файл + /// + private readonly char _separatorRecords = ';'; + /// + /// Разделитель для записи информации по объекту в файл + /// + private static readonly char _separatorForObject = ':'; + /// /// Конструктор /// /// @@ -77,5 +89,102 @@ namespace ProjectTractor return null; } } + + + + /// + /// Сохранение информации по автомобилям в хранилище в файл + /// + /// Путь и имя файла + /// true - сохранение прошло успешно, false - ошибка при сохранении данных + public bool SaveData(string filename) + { + if (File.Exists(filename)) + { + File.Delete(filename); + } + StringBuilder data = new(); + foreach (KeyValuePair> record in _tractorStorages) + { + StringBuilder records = new(); + foreach (DrawningTractor? elem in record.Value.GetTractors) + { + records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}"); + } + data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}"); + } + if (data.Length == 0) + { + return false; + } + using FileStream fs = new(filename, FileMode.Create); + byte[] info = new + UTF8Encoding(true).GetBytes($"TractorStorage{Environment.NewLine}{data}"); + fs.Write(info, 0, info.Length); + return true; + } + /// + /// Загрузка информации по автомобилям в хранилище из файла + /// + /// Путь и имя файла + /// true - загрузка прошла успешно, false - ошибка при загрузке данных + 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(true); + while (fs.Read(b, 0, b.Length) > 0) + { + bufferTextFromFile += temp.GetString(b); + } + } + var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, + StringSplitOptions.RemoveEmptyEntries); + if (strs == null || strs.Length == 0) + { + return false; + } + if (!strs[0].StartsWith("TractorStorage")) + { + //если нет такой записи, то это не те данные + return false; + } + _tractorStorages.Clear(); + foreach (string data in strs) + { + string[] record = data.Split(_separatorForKeyValue, + StringSplitOptions.RemoveEmptyEntries); + if (record.Length != 2) + { + continue; + } + TractorsGenericCollection + collection = new(_pictureWidth, _pictureHeight); + string[] set = record[1].Split(_separatorRecords, + StringSplitOptions.RemoveEmptyEntries); + foreach (string elem in set) + { + DrawningTractor? tractor = + elem?.CreateDrawningTractor(_separatorForObject, _pictureWidth, _pictureHeight); + if (tractor != null) + { + if (!(collection + tractor)) + { + return false; + } + } + } + _tractorStorages.Add(record[0], collection); + } + return true; + } } } + -- 2.25.1 From e785755a98e033b922395418a738dfc3e0c921b7 Mon Sep 17 00:00:00 2001 From: Kirill <117719052+KirillFirsof@users.noreply.github.com> Date: Thu, 21 Dec 2023 19:29:49 +0400 Subject: [PATCH 2/6] =?UTF-8?q?=D0=9A=D0=BE=D0=BD=D0=B5=D1=86=20=D1=88?= =?UTF-8?q?=D0=B5=D1=81=D1=82=D0=BE=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DrawningBulldoser.cs | 2 +- .../RPP_FirstLaba_Tractor/DrawningTractor.cs | 2 +- .../RPP_FirstLaba_Tractor/EntityBulldoser.cs | 7 +- .../RPP_FirstLaba_Tractor/EntityTractor.cs | 7 +- .../ExtentionDrawningTractor.cs | 10 +- .../FormTractorCollection.cs | 112 ++++++++++++++++-- .../FormTractorCollection.resx | 12 ++ .../TractorsGenericCollection.cs | 5 + .../TractorsGenericStorage.cs | 10 +- .../RPP_FirstLaba_Tractor/набор №1.txt | 3 + 10 files changed, 147 insertions(+), 23 deletions(-) create mode 100644 RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/набор №1.txt diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawningBulldoser.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawningBulldoser.cs index 42d7618..05a2d99 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawningBulldoser.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawningBulldoser.cs @@ -97,7 +97,7 @@ namespace ProjectTractor.DrawningObjects public void ChangeAdditionalColor(Color color) { - ((EntityBulldoser)EntityTractor).AdditionalColor = color; + ((EntityBulldoser)EntityTractor).setAdditionalColor(color); } } diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawningTractor.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawningTractor.cs index 39e7239..30666d8 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawningTractor.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawningTractor.cs @@ -234,7 +234,7 @@ namespace ProjectTractor.DrawningObjects { { return; } - EntityTractor.BodyColor = color; + EntityTractor.setBodyColor(color); } public void ChangePictureBoxSize(int pictureBoxWidth, int pictureBoxHeight) diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/EntityBulldoser.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/EntityBulldoser.cs index c0e5211..d8ab444 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/EntityBulldoser.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/EntityBulldoser.cs @@ -14,7 +14,7 @@ namespace ProjectTractor.Entities /// /// Дополнительный цвет (для опциональных элементов) /// - public Color AdditionalColor { get; set; } + public Color AdditionalColor { get; private set; } /// /// Признак (опция) наличия обвеса /// @@ -41,6 +41,11 @@ namespace ProjectTractor.Entities WheelsOrnament = wheelsOrnament; Blade = blade; } + + public void setAdditionalColor(Color color) + { + AdditionalColor = color; + } } } diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/EntityTractor.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/EntityTractor.cs index 0de2fbe..62f6e0e 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/EntityTractor.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/EntityTractor.cs @@ -22,7 +22,7 @@ namespace ProjectTractor.Entities /// /// Основной цвет /// - public Color BodyColor { get; set; } + public Color BodyColor { get; private set; } /// /// Шаг перемещения автомобиля /// @@ -39,5 +39,10 @@ namespace ProjectTractor.Entities Weight = weight; BodyColor = bodyColor; } + + public void setBodyColor(Color color) + { + BodyColor = color; + } } } diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/ExtentionDrawningTractor.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/ExtentionDrawningTractor.cs index 1b9b807..7b66eb8 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/ExtentionDrawningTractor.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/ExtentionDrawningTractor.cs @@ -29,7 +29,7 @@ namespace ProjectTractor.DrawningObjects return new DrawningTractor(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height); } - if (strs.Length == 7) + if (strs.Length == 6) { return new DrawningBulldoser(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), @@ -43,7 +43,7 @@ namespace ProjectTractor.DrawningObjects /// /// Получение данных для сохранения в файл /// - /// Сохраняемый объект + /// Сохраняемый объект /// Разделитель даннных /// Строка с данными по объекту public static string GetDataForSave(this DrawningTractor drawningTractor, @@ -54,15 +54,13 @@ namespace ProjectTractor.DrawningObjects { return string.Empty; } - var str = - $"{tractor.Speed}{separatorForObject}{tractor.Weight}{separatorForObject}{tractor.BodyColor.Name}"; + var str = $"{tractor.Speed}{separatorForObject}{tractor.Weight}{separatorForObject}{tractor.BodyColor.Name}"; if (tractor is not EntityBulldoser bulldoser) { return str; } return - $"{str}{separatorForObject}{bulldoser.AdditionalColor.Name}{separatorForObject}{bulldoser.Blade}{separatorForObject}{bulldoser.WheelsOrnament}"; + $"{str}{separatorForObject}{bulldoser.AdditionalColor.Name}{separatorForObject}{bulldoser.WheelsOrnament}{separatorForObject}{bulldoser.Blade}"; } } - } diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs index 58ac92d..8ae0e7d 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs @@ -93,6 +93,7 @@ namespace ProjectTractor if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { _storage.DelSet(listBoxStorages.SelectedItem.ToString() ?? string.Empty); + listBoxStorages.SelectedItems.Clear(); ReloadObjects(); } } @@ -185,6 +186,52 @@ namespace ProjectTractor } pictureBoxCollection.Image = obj.ShowTractors(); } + /// + /// Обработка нажатия "Сохранение" + /// + /// + /// + private void toolStripMenuItemSave_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 toolStripMenuItemload_Click(object sender, EventArgs e) + { + if (openFileDialog.ShowDialog() == DialogResult.OK) + { + if (_storage.LoadData(openFileDialog.FileName)) + { + MessageBox.Show("Загрузка прошла успешно", + "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + foreach (var collection in _storage.Keys) + { + listBoxStorages.Items.Add(collection); + } + } + else + { + MessageBox.Show("Не удалось загрузить", "Результат", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } private void InitializeComponent() { this.pictureBoxCollection = new System.Windows.Forms.PictureBox(); @@ -198,9 +245,15 @@ namespace ProjectTractor this.ButtonRemoveTractor = new System.Windows.Forms.Button(); this.ButtonAddTractor = new System.Windows.Forms.Button(); this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox(); + this.file = new System.Windows.Forms.MenuStrip(); + this.toolStripMenuItemSave = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripMenuItemload = new System.Windows.Forms.ToolStripMenuItem(); + this.openFileDialog = new System.Windows.Forms.OpenFileDialog(); + this.saveFileDialog = new System.Windows.Forms.SaveFileDialog(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit(); this.groupBox.SuspendLayout(); this.groupBox1.SuspendLayout(); + this.file.SuspendLayout(); this.SuspendLayout(); // // pictureBoxCollection @@ -208,7 +261,7 @@ namespace ProjectTractor this.pictureBoxCollection.Dock = System.Windows.Forms.DockStyle.Left; this.pictureBoxCollection.Location = new System.Drawing.Point(0, 0); this.pictureBoxCollection.Name = "pictureBoxCollection"; - this.pictureBoxCollection.Size = new System.Drawing.Size(620, 536); + this.pictureBoxCollection.Size = new System.Drawing.Size(620, 532); this.pictureBoxCollection.TabIndex = 1; this.pictureBoxCollection.TabStop = false; // @@ -219,9 +272,10 @@ namespace ProjectTractor this.groupBox.Controls.Add(this.ButtonRemoveTractor); this.groupBox.Controls.Add(this.ButtonAddTractor); this.groupBox.Controls.Add(this.maskedTextBoxNumber); + this.groupBox.Controls.Add(this.file); this.groupBox.Location = new System.Drawing.Point(626, 12); this.groupBox.Name = "groupBox"; - this.groupBox.Size = new System.Drawing.Size(255, 522); + this.groupBox.Size = new System.Drawing.Size(255, 524); this.groupBox.TabIndex = 2; this.groupBox.TabStop = false; this.groupBox.Text = "Инструменты"; @@ -232,7 +286,7 @@ namespace ProjectTractor this.groupBox1.Controls.Add(this.listBoxStorages); this.groupBox1.Controls.Add(this.ButtonAddObject); this.groupBox1.Controls.Add(this.textBoxStorageName); - this.groupBox1.Location = new System.Drawing.Point(16, 29); + this.groupBox1.Location = new System.Drawing.Point(16, 54); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(224, 279); this.groupBox1.TabIndex = 9; @@ -278,7 +332,7 @@ namespace ProjectTractor // // ButtonRefreshCollection // - this.ButtonRefreshCollection.Location = new System.Drawing.Point(28, 464); + this.ButtonRefreshCollection.Location = new System.Drawing.Point(28, 463); this.ButtonRefreshCollection.Name = "ButtonRefreshCollection"; this.ButtonRefreshCollection.Size = new System.Drawing.Size(203, 35); this.ButtonRefreshCollection.TabIndex = 8; @@ -288,7 +342,7 @@ namespace ProjectTractor // // ButtonRemoveTractor // - this.ButtonRemoveTractor.Location = new System.Drawing.Point(28, 390); + this.ButtonRemoveTractor.Location = new System.Drawing.Point(28, 410); this.ButtonRemoveTractor.Name = "ButtonRemoveTractor"; this.ButtonRemoveTractor.Size = new System.Drawing.Size(203, 33); this.ButtonRemoveTractor.TabIndex = 7; @@ -298,7 +352,7 @@ namespace ProjectTractor // // ButtonAddTractor // - this.ButtonAddTractor.Location = new System.Drawing.Point(28, 317); + this.ButtonAddTractor.Location = new System.Drawing.Point(28, 337); this.ButtonAddTractor.Name = "ButtonAddTractor"; this.ButtonAddTractor.Size = new System.Drawing.Size(203, 34); this.ButtonAddTractor.TabIndex = 6; @@ -308,14 +362,49 @@ namespace ProjectTractor // // maskedTextBoxNumber // - this.maskedTextBoxNumber.Location = new System.Drawing.Point(28, 357); + this.maskedTextBoxNumber.Location = new System.Drawing.Point(28, 377); this.maskedTextBoxNumber.Name = "maskedTextBoxNumber"; this.maskedTextBoxNumber.Size = new System.Drawing.Size(203, 27); this.maskedTextBoxNumber.TabIndex = 5; // + // file + // + this.file.ImageScalingSize = new System.Drawing.Size(20, 20); + this.file.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripMenuItemSave, + this.toolStripMenuItemload}); + this.file.Location = new System.Drawing.Point(3, 23); + this.file.Name = "file"; + this.file.Size = new System.Drawing.Size(249, 28); + this.file.TabIndex = 10; + this.file.Text = "файл"; + // + // toolStripMenuItemSave + // + this.toolStripMenuItemSave.Name = "toolStripMenuItemSave"; + this.toolStripMenuItemSave.Size = new System.Drawing.Size(97, 24); + this.toolStripMenuItemSave.Text = "Сохранить"; + this.toolStripMenuItemSave.Click += new System.EventHandler(this.toolStripMenuItemSave_Click); + // + // toolStripMenuItemload + // + this.toolStripMenuItemload.Name = "toolStripMenuItemload"; + this.toolStripMenuItemload.Size = new System.Drawing.Size(83, 24); + this.toolStripMenuItemload.Text = "Загрузка"; + this.toolStripMenuItemload.Click += new System.EventHandler(this.toolStripMenuItemload_Click); + // + // openFileDialog + // + this.openFileDialog.FileName = "openFileDialog"; + this.openFileDialog.Filter = "txt file | *.txt"; + // + // saveFileDialog + // + this.saveFileDialog.Filter = "txt file | *.txt"; + // // FormTractorCollection // - this.ClientSize = new System.Drawing.Size(893, 536); + this.ClientSize = new System.Drawing.Size(893, 532); this.Controls.Add(this.groupBox); this.Controls.Add(this.pictureBoxCollection); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; @@ -328,6 +417,8 @@ namespace ProjectTractor this.groupBox.PerformLayout(); this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); + this.file.ResumeLayout(false); + this.file.PerformLayout(); this.ResumeLayout(false); } @@ -342,6 +433,11 @@ namespace ProjectTractor private ListBox listBoxStorages; private Button ButtonAddObject; private MaskedTextBox textBoxStorageName; + private MenuStrip file; + private ToolStripMenuItem toolStripMenuItemSave; + private ToolStripMenuItem toolStripMenuItemload; + private OpenFileDialog openFileDialog; + private SaveFileDialog saveFileDialog; private PictureBox pictureBoxCollection; } } diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.resx b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.resx index f298a7b..b784c16 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.resx +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.resx @@ -57,4 +57,16 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + + + 94, 17 + + + 261, 17 + + + 25 + \ No newline at end of file diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs index ffca693..bc72f1b 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs @@ -86,6 +86,10 @@ namespace ProjectTractor.Generics return true; } /// + /// Получение объектов коллекции + /// + public IEnumerable GetCars => _collection.GetTractors(); + /// /// Получение объекта IMoveableObject /// /// @@ -144,6 +148,7 @@ namespace ProjectTractor.Generics i++; } } + } } diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericStorage.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericStorage.cs index b082c78..7363e95 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericStorage.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericStorage.cs @@ -124,11 +124,11 @@ namespace ProjectTractor fs.Write(info, 0, info.Length); return true; } - /// - /// Загрузка информации по автомобилям в хранилище из файла - /// - /// Путь и имя файла - /// true - загрузка прошла успешно, false - ошибка при загрузке данных + /// + /// Загрузка информации по автомобилям в хранилище из файла + /// + /// Путь и имя файла + // true - загрузка прошла успешно, false - ошибка при загрузке данных public bool LoadData(string filename) { if (!File.Exists(filename)) diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/набор №1.txt b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/набор №1.txt new file mode 100644 index 0000000..2297a21 --- /dev/null +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/набор №1.txt @@ -0,0 +1,3 @@ +TractorStorage +апр|100:100:White;100:100:ff0000c0:Yellow:True:True; +fff|100:100:White:Yellow:False:True;100:100:White:Black:False:True; -- 2.25.1 From 39e4865cc70783d8df1b8c6bdc7dd3f05ce5b8f2 Mon Sep 17 00:00:00 2001 From: Kirill <117719052+KirillFirsof@users.noreply.github.com> Date: Mon, 25 Dec 2023 21:36:16 +0400 Subject: [PATCH 3/6] =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B0=D0=BB=20StreamWriter=20=D0=B8=20StreamReader?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ExtentionDrawningTractor.cs | 4 +- .../FormTractorCollection.cs | 6 +- .../FormTractorConfig.Designer.cs | 4 +- .../TractorsGenericCollection.cs | 2 +- .../TractorsGenericStorage.cs | 114 ++++++++---------- .../RPP_FirstLaba_Tractor/набор №1.txt | 5 +- 6 files changed, 62 insertions(+), 73 deletions(-) diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/ExtentionDrawningTractor.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/ExtentionDrawningTractor.cs index 7b66eb8..9e10ba1 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/ExtentionDrawningTractor.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/ExtentionDrawningTractor.cs @@ -59,8 +59,8 @@ namespace ProjectTractor.DrawningObjects { return str; } - return - $"{str}{separatorForObject}{bulldoser.AdditionalColor.Name}{separatorForObject}{bulldoser.WheelsOrnament}{separatorForObject}{bulldoser.Blade}"; + str = $"{str}{separatorForObject}{bulldoser.AdditionalColor.Name}{separatorForObject}{bulldoser.WheelsOrnament}{separatorForObject}{bulldoser.Blade}"; + return str; } } } diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs index 8ae0e7d..2a60f57 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs @@ -261,7 +261,7 @@ namespace ProjectTractor this.pictureBoxCollection.Dock = System.Windows.Forms.DockStyle.Left; this.pictureBoxCollection.Location = new System.Drawing.Point(0, 0); this.pictureBoxCollection.Name = "pictureBoxCollection"; - this.pictureBoxCollection.Size = new System.Drawing.Size(620, 532); + this.pictureBoxCollection.Size = new System.Drawing.Size(643, 532); this.pictureBoxCollection.TabIndex = 1; this.pictureBoxCollection.TabStop = false; // @@ -273,7 +273,7 @@ namespace ProjectTractor this.groupBox.Controls.Add(this.ButtonAddTractor); this.groupBox.Controls.Add(this.maskedTextBoxNumber); this.groupBox.Controls.Add(this.file); - this.groupBox.Location = new System.Drawing.Point(626, 12); + this.groupBox.Location = new System.Drawing.Point(649, 12); this.groupBox.Name = "groupBox"; this.groupBox.Size = new System.Drawing.Size(255, 524); this.groupBox.TabIndex = 2; @@ -404,7 +404,7 @@ namespace ProjectTractor // // FormTractorCollection // - this.ClientSize = new System.Drawing.Size(893, 532); + this.ClientSize = new System.Drawing.Size(916, 532); this.Controls.Add(this.groupBox); this.Controls.Add(this.pictureBoxCollection); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorConfig.Designer.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorConfig.Designer.cs index 31df060..14a18a5 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorConfig.Designer.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorConfig.Designer.cs @@ -166,7 +166,7 @@ // panelBlue // this.panelBlue.AllowDrop = true; - this.panelBlue.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(192))))); + this.panelBlue.BackColor = System.Drawing.Color.Blue; this.panelBlue.Location = new System.Drawing.Point(98, 23); this.panelBlue.Name = "panelBlue"; this.panelBlue.Size = new System.Drawing.Size(40, 40); @@ -188,7 +188,7 @@ // panelGreen // this.panelGreen.AllowDrop = true; - this.panelGreen.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(0))))); + this.panelGreen.BackColor = System.Drawing.Color.Green; this.panelGreen.Location = new System.Drawing.Point(52, 23); this.panelGreen.Name = "panelGreen"; this.panelGreen.Size = new System.Drawing.Size(40, 40); diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs index bc72f1b..8cc895e 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs @@ -142,7 +142,7 @@ namespace ProjectTractor.Generics if (tractor != null) { int countRows = _pictureWidth / _placeSizeWidth; - tractor.SetPosition(_pictureWidth - _placeSizeWidth * 2 - (i % countRows * _placeSizeWidth) + 20, _pictureHeight - i / countRows * _placeSizeHeight - 160); + tractor.SetPosition(_pictureWidth - _placeSizeWidth * 2 - (i % countRows * _placeSizeWidth) + 210, _pictureHeight - i / countRows * _placeSizeHeight - 160); tractor.DrawTransport(g); } i++; diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericStorage.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericStorage.cs index 7363e95..00378ca 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericStorage.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericStorage.cs @@ -90,40 +90,38 @@ namespace ProjectTractor } } - - /// /// Сохранение информации по автомобилям в хранилище в файл /// /// Путь и имя файла /// true - сохранение прошло успешно, false - ошибка при сохранении данных public bool SaveData(string filename) + { + if (File.Exists(filename)) + { + File.Delete(filename); + } + StringBuilder data = new(); + foreach (KeyValuePair> record in _tractorStorages) + { + StringBuilder records = new(); + foreach (DrawningTractor? elem in record.Value.GetTractors) { - if (File.Exists(filename)) - { - File.Delete(filename); - } - StringBuilder data = new(); - foreach (KeyValuePair> record in _tractorStorages) - { - StringBuilder records = new(); - foreach (DrawningTractor? elem in record.Value.GetTractors) - { - records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}"); - } - data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}"); - } - if (data.Length == 0) - { - return false; - } - using FileStream fs = new(filename, FileMode.Create); - byte[] info = new - UTF8Encoding(true).GetBytes($"TractorStorage{Environment.NewLine}{data}"); - fs.Write(info, 0, info.Length); - return true; + records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}"); } + data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}"); + } + if (data.Length == 0) + { + return false; + } + using (StreamWriter streamWriter = new(filename)) + { + streamWriter.WriteLine($"TractorStorage{Environment.NewLine}{data}"); + } + return true; + } /// /// Загрузка информации по автомобилям в хранилище из файла /// @@ -135,53 +133,43 @@ namespace ProjectTractor { return false; } - string bufferTextFromFile = ""; - using (FileStream fs = new(filename, FileMode.Open)) + using (StreamReader streamReader = new(filename)) { - byte[] b = new byte[fs.Length]; - UTF8Encoding temp = new(true); - while (fs.Read(b, 0, b.Length) > 0) + string str = streamReader.ReadLine(); + string[] strings = str.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); + if (strings == null || strings.Length == 0) { - bufferTextFromFile += temp.GetString(b); + return false; } - } - var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, - StringSplitOptions.RemoveEmptyEntries); - if (strs == null || strs.Length == 0) - { - return false; - } - if (!strs[0].StartsWith("TractorStorage")) - { - //если нет такой записи, то это не те данные - return false; - } - _tractorStorages.Clear(); - foreach (string data in strs) - { - string[] record = data.Split(_separatorForKeyValue, - StringSplitOptions.RemoveEmptyEntries); - if (record.Length != 2) + if (!strings[0].StartsWith("TractorStorage")) { - continue; + return false; } - TractorsGenericCollection - collection = new(_pictureWidth, _pictureHeight); - string[] set = record[1].Split(_separatorRecords, - StringSplitOptions.RemoveEmptyEntries); - foreach (string elem in set) + _tractorStorages.Clear(); + do { - DrawningTractor? tractor = - elem?.CreateDrawningTractor(_separatorForObject, _pictureWidth, _pictureHeight); - if (tractor != null) + string[] record = str.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries); + if (record.Length != 2) { - if (!(collection + tractor)) + str = streamReader.ReadLine(); + continue; + } + TractorsGenericCollection collection = new(_pictureWidth, _pictureHeight); + string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries); + foreach (string elem in set) + { + DrawningTractor? bus = elem?.CreateDrawningTractor(_separatorForObject, _pictureWidth, _pictureHeight); + if (bus != null) { - return false; + if (!(collection + bus)) + { + return false; + } } } - } - _tractorStorages.Add(record[0], collection); + _tractorStorages.Add(record[0], collection); + str = streamReader.ReadLine(); + } while (str != null); } return true; } diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/набор №1.txt b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/набор №1.txt index 2297a21..f0efeb4 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/набор №1.txt +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/набор №1.txt @@ -1,3 +1,4 @@ TractorStorage -апр|100:100:White;100:100:ff0000c0:Yellow:True:True; -fff|100:100:White:Yellow:False:True;100:100:White:Black:False:True; +gg|100:100:Yellow;100:100:Blue:Green:True:True; +ii|100:100:Purple:Green:True:True;100:100:Red:Yellow:True:True; + -- 2.25.1 From 47cf7a6743095502a969fc664014e3e6e5b8aa37 Mon Sep 17 00:00:00 2001 From: Kirill <117719052+KirillFirsof@users.noreply.github.com> Date: Mon, 25 Dec 2023 22:08:53 +0400 Subject: [PATCH 4/6] =?UTF-8?q?=D0=BA=D0=BE=D0=BC=D0=BC=D0=B8=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CarNotFoundException.cs | 24 +++++++++++++++++++ .../StorageOverflowException.cs | 23 ++++++++++++++++++ .../TractorsGenericStorage.cs | 6 ++--- 3 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/CarNotFoundException.cs create mode 100644 RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/StorageOverflowException.cs diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/CarNotFoundException.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/CarNotFoundException.cs new file mode 100644 index 0000000..19b8d4a --- /dev/null +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/CarNotFoundException.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Runtime.Serialization; + + +namespace ProjectTractor.Exceptions +{ + [Serializable] + internal class CarNotFoundException : ApplicationException + { + public CarNotFoundException(int i) : base($"Не найден объект по позиции { i}") { } + public CarNotFoundException() : base() { } + public CarNotFoundException(string message) : base(message) { } + public CarNotFoundException(string message, Exception exception) : + base(message, exception) + { } + protected CarNotFoundException(SerializationInfo info, + StreamingContext contex) : base(info, contex) { } + } + +} diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/StorageOverflowException.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/StorageOverflowException.cs new file mode 100644 index 0000000..81d05e7 --- /dev/null +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/StorageOverflowException.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Runtime.Serialization; + + +namespace ProjectTractor.Exceptions +{ + [Serializable] + internal class StorageOverflowException : ApplicationException + { + public StorageOverflowException(int count) : base($"В наборе превышено допустимое количество: { count}") { } + public StorageOverflowException() : base() { } + public StorageOverflowException(string message) : base(message) { } + public StorageOverflowException(string message, Exception exception) + : base(message, exception) { } + protected StorageOverflowException(SerializationInfo info, + StreamingContext contex) : base(info, contex) { } + } + +} diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericStorage.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericStorage.cs index 00378ca..d71695f 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericStorage.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericStorage.cs @@ -158,10 +158,10 @@ namespace ProjectTractor string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries); foreach (string elem in set) { - DrawningTractor? bus = elem?.CreateDrawningTractor(_separatorForObject, _pictureWidth, _pictureHeight); - if (bus != null) + DrawningTractor? tractor = elem?.CreateDrawningTractor(_separatorForObject, _pictureWidth, _pictureHeight); + if (tractor != null) { - if (!(collection + bus)) + if (!(collection + tractor)) { return false; } -- 2.25.1 From baa9a24290cd1f669ff0f4b4ae6104dada36eb15 Mon Sep 17 00:00:00 2001 From: Kirill <117719052+KirillFirsof@users.noreply.github.com> Date: Mon, 25 Dec 2023 22:22:47 +0400 Subject: [PATCH 5/6] =?UTF-8?q?=D0=BA=D0=BE=D0=BC=D0=BC=D0=B8=D1=821?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CarNotFoundException.cs | 24 ------------------- .../StorageOverflowException.cs | 23 ------------------ .../TractorsGenericStorage.cs | 8 +++---- 3 files changed, 4 insertions(+), 51 deletions(-) delete mode 100644 RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/CarNotFoundException.cs delete mode 100644 RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/StorageOverflowException.cs diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/CarNotFoundException.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/CarNotFoundException.cs deleted file mode 100644 index 19b8d4a..0000000 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/CarNotFoundException.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Runtime.Serialization; - - -namespace ProjectTractor.Exceptions -{ - [Serializable] - internal class CarNotFoundException : ApplicationException - { - public CarNotFoundException(int i) : base($"Не найден объект по позиции { i}") { } - public CarNotFoundException() : base() { } - public CarNotFoundException(string message) : base(message) { } - public CarNotFoundException(string message, Exception exception) : - base(message, exception) - { } - protected CarNotFoundException(SerializationInfo info, - StreamingContext contex) : base(info, contex) { } - } - -} diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/StorageOverflowException.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/StorageOverflowException.cs deleted file mode 100644 index 81d05e7..0000000 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/StorageOverflowException.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Runtime.Serialization; - - -namespace ProjectTractor.Exceptions -{ - [Serializable] - internal class StorageOverflowException : ApplicationException - { - public StorageOverflowException(int count) : base($"В наборе превышено допустимое количество: { count}") { } - public StorageOverflowException() : base() { } - public StorageOverflowException(string message) : base(message) { } - public StorageOverflowException(string message, Exception exception) - : base(message, exception) { } - protected StorageOverflowException(SerializationInfo info, - StreamingContext contex) : base(info, contex) { } - } - -} diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericStorage.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericStorage.cs index d71695f..273c34d 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericStorage.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericStorage.cs @@ -114,7 +114,7 @@ namespace ProjectTractor } if (data.Length == 0) { - return false; + throw new Exception("Невалидная операция, нет данных для сохранения"); } using (StreamWriter streamWriter = new(filename)) { @@ -139,11 +139,11 @@ namespace ProjectTractor string[] strings = str.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); if (strings == null || strings.Length == 0) { - return false; + throw new IOException("Нет данных для загрузки"); } if (!strings[0].StartsWith("TractorStorage")) { - return false; + throw new IOException("Неверный формат данных"); } _tractorStorages.Clear(); do @@ -163,7 +163,7 @@ namespace ProjectTractor { if (!(collection + tractor)) { - return false; + throw new ArgumentNullException("Ошибка добавления в коллекцию"); } } } -- 2.25.1 From 5ca50283c7fd1d72f04ee01cd2f0824a86fc9411 Mon Sep 17 00:00:00 2001 From: Kirill <117719052+KirillFirsof@users.noreply.github.com> Date: Mon, 25 Dec 2023 22:24:52 +0400 Subject: [PATCH 6/6] =?UTF-8?q?=D0=BA=D0=BE=D0=BC=D0=BC=D0=B8=D1=822?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RPP_FirstLaba_Tractor/TractorsGenericStorage.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericStorage.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericStorage.cs index 273c34d..d71695f 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericStorage.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericStorage.cs @@ -114,7 +114,7 @@ namespace ProjectTractor } if (data.Length == 0) { - throw new Exception("Невалидная операция, нет данных для сохранения"); + return false; } using (StreamWriter streamWriter = new(filename)) { @@ -139,11 +139,11 @@ namespace ProjectTractor string[] strings = str.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); if (strings == null || strings.Length == 0) { - throw new IOException("Нет данных для загрузки"); + return false; } if (!strings[0].StartsWith("TractorStorage")) { - throw new IOException("Неверный формат данных"); + return false; } _tractorStorages.Clear(); do @@ -163,7 +163,7 @@ namespace ProjectTractor { if (!(collection + tractor)) { - throw new ArgumentNullException("Ошибка добавления в коллекцию"); + return false; } } } -- 2.25.1