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] =?UTF-8?q?=D0=9A=D0=BE=D0=BD=D0=B5=D1=86=20=D1=88=D0=B5?= =?UTF-8?q?=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;