From 21cf14be5b48e8d83ab696c2ff8f727dfb98e7a5 Mon Sep 17 00:00:00 2001 From: AnnaLioness Date: Fri, 17 Nov 2023 22:12:13 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BB=D0=B0=D0=B16?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lab1ContainersShip/Lab1ContainersShip.sln | 4 +- .../Lab1ContainersShip/ExtensionShip.cs | 68 ++++++++ .../FormShipCollection.Designer.cs | 111 ++++++++++--- .../Lab1ContainersShip/FormShipCollection.cs | 35 ++++ .../FormShipCollection.resx | 71 ++------ .../FormShipConfig.Designer.cs | 151 +++++++++++------- .../Lab1ContainersShip/FormShipConfig.resx | 62 +------ .../Lab1ContainersShip.csproj | 129 +-------------- .../Properties/AssemblyInfo.cs | 36 ----- .../ShipGenericCollection.cs | 1 + .../Lab1ContainersShip/ShipGenericStorage.cs | 106 ++++++++++++ 11 files changed, 412 insertions(+), 362 deletions(-) create mode 100644 Lab1ContainersShip/Lab1ContainersShip/ExtensionShip.cs delete mode 100644 Lab1ContainersShip/Lab1ContainersShip/Properties/AssemblyInfo.cs diff --git a/Lab1ContainersShip/Lab1ContainersShip.sln b/Lab1ContainersShip/Lab1ContainersShip.sln index 80adb21..6bbc4cb 100644 --- a/Lab1ContainersShip/Lab1ContainersShip.sln +++ b/Lab1ContainersShip/Lab1ContainersShip.sln @@ -1,9 +1,9 @@ - + Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.4.33122.133 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab1ContainersShip", "Lab1ContainersShip\Lab1ContainersShip.csproj", "{AFA56719-1551-4DFA-9EC2-1FD7AB801A5E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lab1ContainersShip", "Lab1ContainersShip\Lab1ContainersShip.csproj", "{AFA56719-1551-4DFA-9EC2-1FD7AB801A5E}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/Lab1ContainersShip/Lab1ContainersShip/ExtensionShip.cs b/Lab1ContainersShip/Lab1ContainersShip/ExtensionShip.cs new file mode 100644 index 0000000..af62476 --- /dev/null +++ b/Lab1ContainersShip/Lab1ContainersShip/ExtensionShip.cs @@ -0,0 +1,68 @@ +using Lab1ContainersShip.DrawingObjects; +using Lab1ContainersShip.Entities; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Lab1ContainersShip.Entities; + +namespace Lab1ContainersShip.DrawingObjects +{ + public static class ExtensionShip + { + /// + /// Создание объекта из строки + /// + /// Строка с данными для создания объекта + /// Разделитель даннных + /// Ширина + /// Высота + /// Объект + public static DrawingShip CreateDrawingShip(this string info, char + separatorForObject, int width, int height) + { + string[] strs = info.Split(separatorForObject); + if (strs.Length == 3) + { + return new DrawingShip(Convert.ToInt32(strs[0]), + Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height); + } + if (strs.Length == 6) + { + return new DrawingContainerShip(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 DrawingShip drawingShip, + char separatorForObject) + { + var ship = drawingShip.EntityShip; + if (ship == null) + { + return string.Empty; + } + var str = + $"{ship.Speed}{separatorForObject}{ship.Weight}{separatorForObject}{ship.BodyColor.Name}"; + if (ship is not EntityContainerShip containerShip) + { + return str; + } + return + $"{str}{separatorForObject}{containerShip.AdditionalColor.Name}{separatorForObject}{containerShip.Crane}{separatorForObject}{containerShip.Conteiners}"; + } + } +} diff --git a/Lab1ContainersShip/Lab1ContainersShip/FormShipCollection.Designer.cs b/Lab1ContainersShip/Lab1ContainersShip/FormShipCollection.Designer.cs index 70162f1..84f9798 100644 --- a/Lab1ContainersShip/Lab1ContainersShip/FormShipCollection.Designer.cs +++ b/Lab1ContainersShip/Lab1ContainersShip/FormShipCollection.Designer.cs @@ -37,8 +37,15 @@ this.ButtonRefreshCollection = new System.Windows.Forms.Button(); this.ButtonRemoveCar = new System.Windows.Forms.Button(); this.ButtonAddCar = new System.Windows.Forms.Button(); + this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.файлToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.LoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.SaveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.pictureBoxCollection = new System.Windows.Forms.PictureBox(); + this.openFileDialog = new System.Windows.Forms.OpenFileDialog(); + this.saveFileDialog = new System.Windows.Forms.SaveFileDialog(); this.panel1.SuspendLayout(); + this.menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit(); this.SuspendLayout(); // @@ -52,23 +59,27 @@ this.panel1.Controls.Add(this.ButtonRefreshCollection); this.panel1.Controls.Add(this.ButtonRemoveCar); this.panel1.Controls.Add(this.ButtonAddCar); - this.panel1.Location = new System.Drawing.Point(646, 0); + this.panel1.Controls.Add(this.menuStrip1); + this.panel1.Location = new System.Drawing.Point(754, 0); + this.panel1.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.panel1.Name = "panel1"; - this.panel1.Size = new System.Drawing.Size(157, 449); + this.panel1.Size = new System.Drawing.Size(183, 518); this.panel1.TabIndex = 1; // // textBoxStorageName // - this.textBoxStorageName.Location = new System.Drawing.Point(18, 25); + this.textBoxStorageName.Location = new System.Drawing.Point(21, 29); + this.textBoxStorageName.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.textBoxStorageName.Name = "textBoxStorageName"; - this.textBoxStorageName.Size = new System.Drawing.Size(118, 20); + this.textBoxStorageName.Size = new System.Drawing.Size(137, 23); this.textBoxStorageName.TabIndex = 5; // // ButtonAddObject // - this.ButtonAddObject.Location = new System.Drawing.Point(18, 51); + this.ButtonAddObject.Location = new System.Drawing.Point(21, 59); + this.ButtonAddObject.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.ButtonAddObject.Name = "ButtonAddObject"; - this.ButtonAddObject.Size = new System.Drawing.Size(118, 29); + this.ButtonAddObject.Size = new System.Drawing.Size(138, 33); this.ButtonAddObject.TabIndex = 2; this.ButtonAddObject.Text = "добавить набор"; this.ButtonAddObject.UseVisualStyleBackColor = true; @@ -77,17 +88,20 @@ // listBoxStorages // this.listBoxStorages.FormattingEnabled = true; - this.listBoxStorages.Location = new System.Drawing.Point(18, 86); + this.listBoxStorages.ItemHeight = 15; + this.listBoxStorages.Location = new System.Drawing.Point(21, 99); + this.listBoxStorages.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.listBoxStorages.Name = "listBoxStorages"; - this.listBoxStorages.Size = new System.Drawing.Size(120, 95); + this.listBoxStorages.Size = new System.Drawing.Size(139, 109); this.listBoxStorages.TabIndex = 4; this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.ListBoxObjects_SelectedIndexChanged); // // ButtonDelObject // - this.ButtonDelObject.Location = new System.Drawing.Point(18, 187); + this.ButtonDelObject.Location = new System.Drawing.Point(21, 216); + this.ButtonDelObject.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.ButtonDelObject.Name = "ButtonDelObject"; - this.ButtonDelObject.Size = new System.Drawing.Size(118, 30); + this.ButtonDelObject.Size = new System.Drawing.Size(138, 35); this.ButtonDelObject.TabIndex = 2; this.ButtonDelObject.Text = "удалить набор"; this.ButtonDelObject.UseVisualStyleBackColor = true; @@ -95,16 +109,18 @@ // // maskedTextBoxNumber // - this.maskedTextBoxNumber.Location = new System.Drawing.Point(16, 330); + this.maskedTextBoxNumber.Location = new System.Drawing.Point(19, 381); + this.maskedTextBoxNumber.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.maskedTextBoxNumber.Name = "maskedTextBoxNumber"; - this.maskedTextBoxNumber.Size = new System.Drawing.Size(100, 20); + this.maskedTextBoxNumber.Size = new System.Drawing.Size(116, 23); this.maskedTextBoxNumber.TabIndex = 3; // // ButtonRefreshCollection // - this.ButtonRefreshCollection.Location = new System.Drawing.Point(16, 401); + this.ButtonRefreshCollection.Location = new System.Drawing.Point(19, 463); + this.ButtonRefreshCollection.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.ButtonRefreshCollection.Name = "ButtonRefreshCollection"; - this.ButtonRefreshCollection.Size = new System.Drawing.Size(118, 37); + this.ButtonRefreshCollection.Size = new System.Drawing.Size(138, 43); this.ButtonRefreshCollection.TabIndex = 2; this.ButtonRefreshCollection.Text = "обновить коллекцию"; this.ButtonRefreshCollection.UseVisualStyleBackColor = true; @@ -112,9 +128,10 @@ // // ButtonRemoveCar // - this.ButtonRemoveCar.Location = new System.Drawing.Point(16, 356); + this.ButtonRemoveCar.Location = new System.Drawing.Point(19, 411); + this.ButtonRemoveCar.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.ButtonRemoveCar.Name = "ButtonRemoveCar"; - this.ButtonRemoveCar.Size = new System.Drawing.Size(118, 39); + this.ButtonRemoveCar.Size = new System.Drawing.Size(138, 45); this.ButtonRemoveCar.TabIndex = 1; this.ButtonRemoveCar.Text = "удалить контейнеровоз"; this.ButtonRemoveCar.UseVisualStyleBackColor = true; @@ -122,34 +139,80 @@ // // ButtonAddCar // - this.ButtonAddCar.Location = new System.Drawing.Point(16, 286); + this.ButtonAddCar.Location = new System.Drawing.Point(19, 330); + this.ButtonAddCar.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.ButtonAddCar.Name = "ButtonAddCar"; - this.ButtonAddCar.Size = new System.Drawing.Size(118, 38); + this.ButtonAddCar.Size = new System.Drawing.Size(138, 44); this.ButtonAddCar.TabIndex = 0; this.ButtonAddCar.Text = "добавить контейнеровоз"; this.ButtonAddCar.UseVisualStyleBackColor = true; this.ButtonAddCar.Click += new System.EventHandler(this.ButtonAddCar_Click); // + // menuStrip1 + // + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.файлToolStripMenuItem}); + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Size = new System.Drawing.Size(183, 24); + this.menuStrip1.TabIndex = 6; + this.menuStrip1.Text = "menuStrip1"; + // + // файлToolStripMenuItem + // + this.файлToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.LoadToolStripMenuItem, + this.SaveToolStripMenuItem}); + this.файлToolStripMenuItem.Name = "файлToolStripMenuItem"; + this.файлToolStripMenuItem.Size = new System.Drawing.Size(48, 20); + this.файлToolStripMenuItem.Text = "файл"; + // + // LoadToolStripMenuItem + // + this.LoadToolStripMenuItem.Name = "LoadToolStripMenuItem"; + this.LoadToolStripMenuItem.Size = new System.Drawing.Size(131, 22); + this.LoadToolStripMenuItem.Text = "загрузить"; + this.LoadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click); + // + // SaveToolStripMenuItem + // + this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem"; + this.SaveToolStripMenuItem.Size = new System.Drawing.Size(131, 22); + this.SaveToolStripMenuItem.Text = "сохранить"; + this.SaveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click); + // // pictureBoxCollection // this.pictureBoxCollection.Location = new System.Drawing.Point(0, 0); + this.pictureBoxCollection.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.pictureBoxCollection.Name = "pictureBoxCollection"; - this.pictureBoxCollection.Size = new System.Drawing.Size(640, 449); + this.pictureBoxCollection.Size = new System.Drawing.Size(747, 518); this.pictureBoxCollection.TabIndex = 0; this.pictureBoxCollection.TabStop = false; // + // openFileDialog + // + this.openFileDialog.Filter = "txt file | *.txt"; + // + // saveFileDialog + // + this.saveFileDialog.Filter = "txt file | *.txt"; + // // FormShipCollection // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); + this.ClientSize = new System.Drawing.Size(933, 519); this.Controls.Add(this.panel1); this.Controls.Add(this.pictureBoxCollection); + this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.Name = "FormShipCollection"; this.Text = "FormShipCollection"; this.Load += new System.EventHandler(this.FormShipCollection_Load); this.panel1.ResumeLayout(false); this.panel1.PerformLayout(); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit(); this.ResumeLayout(false); @@ -167,5 +230,11 @@ private System.Windows.Forms.Button ButtonAddObject; private System.Windows.Forms.ListBox listBoxStorages; private System.Windows.Forms.Button ButtonDelObject; + private System.Windows.Forms.MenuStrip menuStrip1; + private System.Windows.Forms.ToolStripMenuItem файлToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem LoadToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem SaveToolStripMenuItem; + private System.Windows.Forms.OpenFileDialog openFileDialog; + private System.Windows.Forms.SaveFileDialog saveFileDialog; } } \ No newline at end of file diff --git a/Lab1ContainersShip/Lab1ContainersShip/FormShipCollection.cs b/Lab1ContainersShip/Lab1ContainersShip/FormShipCollection.cs index 30f6a40..4015943 100644 --- a/Lab1ContainersShip/Lab1ContainersShip/FormShipCollection.cs +++ b/Lab1ContainersShip/Lab1ContainersShip/FormShipCollection.cs @@ -162,5 +162,40 @@ namespace Lab1ContainersShip 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) + { + if (openFileDialog.ShowDialog() == DialogResult.OK) + { + if (_storage.LoadData(openFileDialog.FileName)) + { + ReloadObjects(); + MessageBox.Show("Загрузка прошла успешно", + "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Не загрузилось", "Результат", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } } } diff --git a/Lab1ContainersShip/Lab1ContainersShip/FormShipCollection.resx b/Lab1ContainersShip/Lab1ContainersShip/FormShipCollection.resx index 1af7de1..5c29201 100644 --- a/Lab1ContainersShip/Lab1ContainersShip/FormShipCollection.resx +++ b/Lab1ContainersShip/Lab1ContainersShip/FormShipCollection.resx @@ -1,64 +1,4 @@ - - - + @@ -117,4 +57,13 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 175, 31 + + + 290, 31 + + + 430, 31 + \ No newline at end of file diff --git a/Lab1ContainersShip/Lab1ContainersShip/FormShipConfig.Designer.cs b/Lab1ContainersShip/Lab1ContainersShip/FormShipConfig.Designer.cs index d933236..8249131 100644 --- a/Lab1ContainersShip/Lab1ContainersShip/FormShipConfig.Designer.cs +++ b/Lab1ContainersShip/Lab1ContainersShip/FormShipConfig.Designer.cs @@ -79,9 +79,11 @@ this.groupBox1.Controls.Add(this.label3); this.groupBox1.Controls.Add(this.label2); this.groupBox1.Controls.Add(this.label1); - this.groupBox1.Location = new System.Drawing.Point(12, 12); + this.groupBox1.Location = new System.Drawing.Point(14, 14); + this.groupBox1.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.groupBox1.Name = "groupBox1"; - this.groupBox1.Size = new System.Drawing.Size(466, 323); + this.groupBox1.Padding = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.groupBox1.Size = new System.Drawing.Size(544, 373); this.groupBox1.TabIndex = 0; this.groupBox1.TabStop = false; this.groupBox1.Text = "Параметры"; @@ -89,9 +91,10 @@ // labelModifiedObject // this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.labelModifiedObject.Location = new System.Drawing.Point(331, 229); + this.labelModifiedObject.Location = new System.Drawing.Point(386, 264); + this.labelModifiedObject.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.labelModifiedObject.Name = "labelModifiedObject"; - this.labelModifiedObject.Size = new System.Drawing.Size(100, 32); + this.labelModifiedObject.Size = new System.Drawing.Size(116, 37); this.labelModifiedObject.TabIndex = 10; this.labelModifiedObject.Text = "Продвинутый"; this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown); @@ -99,9 +102,10 @@ // labelSimpleObject // this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.labelSimpleObject.Location = new System.Drawing.Point(206, 229); + this.labelSimpleObject.Location = new System.Drawing.Point(240, 264); + this.labelSimpleObject.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.labelSimpleObject.Name = "labelSimpleObject"; - this.labelSimpleObject.Size = new System.Drawing.Size(100, 32); + this.labelSimpleObject.Size = new System.Drawing.Size(116, 37); this.labelSimpleObject.TabIndex = 9; this.labelSimpleObject.Text = "Простой"; this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown); @@ -116,9 +120,11 @@ this.groupBox2.Controls.Add(this.panelYellow); this.groupBox2.Controls.Add(this.panelOrange); this.groupBox2.Controls.Add(this.panelRed); - this.groupBox2.Location = new System.Drawing.Point(196, 31); + this.groupBox2.Location = new System.Drawing.Point(229, 36); + this.groupBox2.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.groupBox2.Name = "groupBox2"; - this.groupBox2.Size = new System.Drawing.Size(246, 158); + this.groupBox2.Padding = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.groupBox2.Size = new System.Drawing.Size(287, 182); this.groupBox2.TabIndex = 8; this.groupBox2.TabStop = false; this.groupBox2.Text = "Цвета"; @@ -126,98 +132,110 @@ // panelPink // this.panelPink.BackColor = System.Drawing.Color.Fuchsia; - this.panelPink.Location = new System.Drawing.Point(187, 75); + this.panelPink.Location = new System.Drawing.Point(218, 87); + this.panelPink.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.panelPink.Name = "panelPink"; - this.panelPink.Size = new System.Drawing.Size(43, 41); + this.panelPink.Size = new System.Drawing.Size(50, 47); this.panelPink.TabIndex = 0; // // panelPurple // - this.panelPurple.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(0)))), ((int)(((byte)(64))))); - this.panelPurple.Location = new System.Drawing.Point(125, 75); + this.panelPurple.BackColor = System.Drawing.Color.Purple; + this.panelPurple.Location = new System.Drawing.Point(146, 87); + this.panelPurple.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.panelPurple.Name = "panelPurple"; - this.panelPurple.Size = new System.Drawing.Size(43, 40); + this.panelPurple.Size = new System.Drawing.Size(50, 46); this.panelPurple.TabIndex = 0; // // panelBlue // this.panelBlue.BackColor = System.Drawing.Color.Blue; - this.panelBlue.Location = new System.Drawing.Point(64, 75); + this.panelBlue.Location = new System.Drawing.Point(75, 87); + this.panelBlue.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.panelBlue.Name = "panelBlue"; - this.panelBlue.Size = new System.Drawing.Size(43, 40); + this.panelBlue.Size = new System.Drawing.Size(50, 46); this.panelBlue.TabIndex = 0; // // panelLightBlue // this.panelLightBlue.BackColor = System.Drawing.Color.Cyan; - this.panelLightBlue.Location = new System.Drawing.Point(6, 75); + this.panelLightBlue.Location = new System.Drawing.Point(7, 87); + this.panelLightBlue.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.panelLightBlue.Name = "panelLightBlue"; - this.panelLightBlue.Size = new System.Drawing.Size(40, 40); + this.panelLightBlue.Size = new System.Drawing.Size(47, 46); this.panelLightBlue.TabIndex = 13; // // panelGreen // this.panelGreen.BackColor = System.Drawing.Color.Lime; - this.panelGreen.Location = new System.Drawing.Point(187, 19); + this.panelGreen.Location = new System.Drawing.Point(218, 22); + this.panelGreen.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.panelGreen.Name = "panelGreen"; - this.panelGreen.Size = new System.Drawing.Size(43, 41); + this.panelGreen.Size = new System.Drawing.Size(50, 47); this.panelGreen.TabIndex = 12; // // panelYellow // this.panelYellow.BackColor = System.Drawing.Color.Yellow; this.panelYellow.Controls.Add(this.panel6); - this.panelYellow.Location = new System.Drawing.Point(125, 19); + this.panelYellow.Location = new System.Drawing.Point(146, 22); + this.panelYellow.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.panelYellow.Name = "panelYellow"; - this.panelYellow.Size = new System.Drawing.Size(43, 38); + this.panelYellow.Size = new System.Drawing.Size(50, 44); this.panelYellow.TabIndex = 11; // // panel6 // - this.panel6.Location = new System.Drawing.Point(0, 44); + this.panel6.Location = new System.Drawing.Point(0, 51); + this.panel6.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.panel6.Name = "panel6"; - this.panel6.Size = new System.Drawing.Size(43, 56); + this.panel6.Size = new System.Drawing.Size(50, 65); this.panel6.TabIndex = 0; // // panelOrange // - this.panelOrange.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(0))))); + this.panelOrange.BackColor = System.Drawing.Color.OrangeRed; this.panelOrange.Controls.Add(this.panel4); - this.panelOrange.Location = new System.Drawing.Point(64, 19); + this.panelOrange.Location = new System.Drawing.Point(75, 22); + this.panelOrange.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.panelOrange.Name = "panelOrange"; - this.panelOrange.Size = new System.Drawing.Size(43, 38); + this.panelOrange.Size = new System.Drawing.Size(50, 44); this.panelOrange.TabIndex = 10; // // panel4 // - this.panel4.Location = new System.Drawing.Point(0, 44); + this.panel4.Location = new System.Drawing.Point(0, 51); + this.panel4.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.panel4.Name = "panel4"; - this.panel4.Size = new System.Drawing.Size(43, 56); + this.panel4.Size = new System.Drawing.Size(50, 65); this.panel4.TabIndex = 0; // // panelRed // this.panelRed.BackColor = System.Drawing.Color.Red; this.panelRed.Controls.Add(this.panel2); - this.panelRed.Location = new System.Drawing.Point(6, 19); + this.panelRed.Location = new System.Drawing.Point(7, 22); + this.panelRed.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.panelRed.Name = "panelRed"; - this.panelRed.Size = new System.Drawing.Size(40, 38); + this.panelRed.Size = new System.Drawing.Size(47, 44); this.panelRed.TabIndex = 9; this.panelRed.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); // // panel2 // - this.panel2.Location = new System.Drawing.Point(157, 72); + this.panel2.Location = new System.Drawing.Point(183, 83); + this.panel2.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.panel2.Name = "panel2"; - this.panel2.Size = new System.Drawing.Size(43, 28); + this.panel2.Size = new System.Drawing.Size(50, 32); this.panel2.TabIndex = 0; // // checkBoxContainers // this.checkBoxContainers.AutoSize = true; - this.checkBoxContainers.Location = new System.Drawing.Point(9, 129); + this.checkBoxContainers.Location = new System.Drawing.Point(10, 149); + this.checkBoxContainers.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.checkBoxContainers.Name = "checkBoxContainers"; - this.checkBoxContainers.Size = new System.Drawing.Size(88, 17); + this.checkBoxContainers.Size = new System.Drawing.Size(94, 19); this.checkBoxContainers.TabIndex = 7; this.checkBoxContainers.Text = "Контейнеры"; this.checkBoxContainers.UseVisualStyleBackColor = true; @@ -225,16 +243,18 @@ // checkBoxCrane // this.checkBoxCrane.AutoSize = true; - this.checkBoxCrane.Location = new System.Drawing.Point(9, 106); + this.checkBoxCrane.Location = new System.Drawing.Point(10, 122); + this.checkBoxCrane.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.checkBoxCrane.Name = "checkBoxCrane"; - this.checkBoxCrane.Size = new System.Drawing.Size(51, 17); + this.checkBoxCrane.Size = new System.Drawing.Size(53, 19); this.checkBoxCrane.TabIndex = 6; this.checkBoxCrane.Text = "Кран"; this.checkBoxCrane.UseVisualStyleBackColor = true; // // numericUpDownWeight // - this.numericUpDownWeight.Location = new System.Drawing.Point(41, 65); + this.numericUpDownWeight.Location = new System.Drawing.Point(48, 75); + this.numericUpDownWeight.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.numericUpDownWeight.Maximum = new decimal(new int[] { 1000, 0, @@ -246,7 +266,7 @@ 0, 0}); this.numericUpDownWeight.Name = "numericUpDownWeight"; - this.numericUpDownWeight.Size = new System.Drawing.Size(120, 20); + this.numericUpDownWeight.Size = new System.Drawing.Size(140, 23); this.numericUpDownWeight.TabIndex = 5; this.numericUpDownWeight.Value = new decimal(new int[] { 100, @@ -256,7 +276,8 @@ // // numericUpDownSpeed // - this.numericUpDownSpeed.Location = new System.Drawing.Point(70, 29); + this.numericUpDownSpeed.Location = new System.Drawing.Point(82, 33); + this.numericUpDownSpeed.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.numericUpDownSpeed.Maximum = new decimal(new int[] { 1000, 0, @@ -268,7 +289,7 @@ 0, 0}); this.numericUpDownSpeed.Name = "numericUpDownSpeed"; - this.numericUpDownSpeed.Size = new System.Drawing.Size(120, 20); + this.numericUpDownSpeed.Size = new System.Drawing.Size(140, 23); this.numericUpDownSpeed.TabIndex = 4; this.numericUpDownSpeed.Value = new decimal(new int[] { 100, @@ -279,26 +300,29 @@ // label3 // this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(17, 47); + this.label3.Location = new System.Drawing.Point(20, 54); + this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(0, 13); + this.label3.Size = new System.Drawing.Size(0, 15); this.label3.TabIndex = 3; // // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(6, 67); + this.label2.Location = new System.Drawing.Point(7, 77); + this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(29, 13); + this.label2.Size = new System.Drawing.Size(29, 15); this.label2.TabIndex = 2; this.label2.Text = "Вес:"; // // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(6, 31); + this.label1.Location = new System.Drawing.Point(7, 36); + this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(58, 13); + this.label1.Size = new System.Drawing.Size(62, 15); this.label1.TabIndex = 1; this.label1.Text = "Скорость:"; // @@ -306,26 +330,29 @@ // this.panel12.AllowDrop = true; this.panel12.Controls.Add(this.pictureBoxObject); - this.panel12.Location = new System.Drawing.Point(484, 43); + this.panel12.Location = new System.Drawing.Point(565, 50); + this.panel12.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.panel12.Name = "panel12"; - this.panel12.Size = new System.Drawing.Size(316, 235); + this.panel12.Size = new System.Drawing.Size(369, 271); this.panel12.TabIndex = 1; this.panel12.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop); this.panel12.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter); // // pictureBoxObject // - this.pictureBoxObject.Location = new System.Drawing.Point(3, 3); + this.pictureBoxObject.Location = new System.Drawing.Point(4, 3); + this.pictureBoxObject.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.pictureBoxObject.Name = "pictureBoxObject"; - this.pictureBoxObject.Size = new System.Drawing.Size(310, 204); + this.pictureBoxObject.Size = new System.Drawing.Size(362, 235); this.pictureBoxObject.TabIndex = 0; this.pictureBoxObject.TabStop = false; // // buttonOk // - this.buttonOk.Location = new System.Drawing.Point(526, 284); + this.buttonOk.Location = new System.Drawing.Point(614, 328); + this.buttonOk.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.buttonOk.Name = "buttonOk"; - this.buttonOk.Size = new System.Drawing.Size(89, 39); + this.buttonOk.Size = new System.Drawing.Size(104, 45); this.buttonOk.TabIndex = 2; this.buttonOk.Text = "Добавить"; this.buttonOk.UseVisualStyleBackColor = true; @@ -333,9 +360,10 @@ // // buttonCancel // - this.buttonCancel.Location = new System.Drawing.Point(702, 284); + this.buttonCancel.Location = new System.Drawing.Point(819, 328); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.buttonCancel.Name = "buttonCancel"; - this.buttonCancel.Size = new System.Drawing.Size(95, 39); + this.buttonCancel.Size = new System.Drawing.Size(111, 45); this.buttonCancel.TabIndex = 3; this.buttonCancel.Text = "Отмена"; this.buttonCancel.UseVisualStyleBackColor = true; @@ -344,9 +372,10 @@ // this.labelColor.AllowDrop = true; this.labelColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.labelColor.Location = new System.Drawing.Point(494, 12); + this.labelColor.Location = new System.Drawing.Point(576, 14); + this.labelColor.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.labelColor.Name = "labelColor"; - this.labelColor.Size = new System.Drawing.Size(100, 23); + this.labelColor.Size = new System.Drawing.Size(116, 26); this.labelColor.TabIndex = 4; this.labelColor.Text = "Цвет"; this.labelColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragDrop); @@ -356,9 +385,10 @@ // this.labelAddColor.AllowDrop = true; this.labelAddColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.labelAddColor.Location = new System.Drawing.Point(632, 13); + this.labelAddColor.Location = new System.Drawing.Point(737, 15); + this.labelAddColor.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.labelAddColor.Name = "labelAddColor"; - this.labelAddColor.Size = new System.Drawing.Size(100, 23); + this.labelAddColor.Size = new System.Drawing.Size(116, 26); this.labelAddColor.TabIndex = 5; this.labelAddColor.Text = "Доп. цвет"; this.labelAddColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelAddColor_DragDrop); @@ -366,15 +396,16 @@ // // FormShipConfig // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 347); + this.ClientSize = new System.Drawing.Size(933, 400); this.Controls.Add(this.labelAddColor); this.Controls.Add(this.labelColor); this.Controls.Add(this.buttonCancel); this.Controls.Add(this.buttonOk); this.Controls.Add(this.panel12); this.Controls.Add(this.groupBox1); + this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.Name = "FormShipConfig"; this.Text = "FormShipConfig"; this.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelAddColor_DragDrop); diff --git a/Lab1ContainersShip/Lab1ContainersShip/FormShipConfig.resx b/Lab1ContainersShip/Lab1ContainersShip/FormShipConfig.resx index 1af7de1..f298a7b 100644 --- a/Lab1ContainersShip/Lab1ContainersShip/FormShipConfig.resx +++ b/Lab1ContainersShip/Lab1ContainersShip/FormShipConfig.resx @@ -1,64 +1,4 @@ - - - + diff --git a/Lab1ContainersShip/Lab1ContainersShip/Lab1ContainersShip.csproj b/Lab1ContainersShip/Lab1ContainersShip/Lab1ContainersShip.csproj index d7e5d07..43d2678 100644 --- a/Lab1ContainersShip/Lab1ContainersShip/Lab1ContainersShip.csproj +++ b/Lab1ContainersShip/Lab1ContainersShip/Lab1ContainersShip.csproj @@ -1,129 +1,16 @@ - - - + - Debug - AnyCPU - {AFA56719-1551-4DFA-9EC2-1FD7AB801A5E} + net7.0-windows WinExe - Lab1ContainersShip - Lab1ContainersShip - v4.7.2 - 512 - true - true - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 + false + true + true - - - - - - - - - - - + + - - - Form - - - FormShipCollection.cs - - - Form - - - FormShipConfig.cs - - - - - - - - - - Form - - - FormContainerShip.cs - - - - - - - - - - - - FormContainerShip.cs - - - FormShipCollection.cs - - - FormShipConfig.cs - - - ResXFileCodeGenerator - Resources.Designer.cs - Designer - - - True - Resources.resx - True - - - SettingsSingleFileGenerator - Settings.Designer.cs - - - True - Settings.settings - True - + - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Lab1ContainersShip/Lab1ContainersShip/Properties/AssemblyInfo.cs b/Lab1ContainersShip/Lab1ContainersShip/Properties/AssemblyInfo.cs deleted file mode 100644 index 70bb622..0000000 --- a/Lab1ContainersShip/Lab1ContainersShip/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// Общие сведения об этой сборке предоставляются следующим набором -// набора атрибутов. Измените значения этих атрибутов для изменения сведений, -// связанных со сборкой. -[assembly: AssemblyTitle("Lab1ContainersShip")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Lab1ContainersShip")] -[assembly: AssemblyCopyright("Copyright © 2023")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Установка значения False для параметра ComVisible делает типы в этой сборке невидимыми -// для компонентов COM. Если необходимо обратиться к типу в этой сборке через -// COM, следует установить атрибут ComVisible в TRUE для этого типа. -[assembly: ComVisible(false)] - -// Следующий GUID служит для идентификации библиотеки типов, если этот проект будет видимым для COM -[assembly: Guid("afa56719-1551-4dfa-9ec2-1fd7ab801a5e")] - -// Сведения о версии сборки состоят из указанных ниже четырех значений: -// -// Основной номер версии -// Дополнительный номер версии -// Номер сборки -// Редакция -// -// Можно задать все значения или принять номера сборки и редакции по умолчанию -// используя "*", как показано ниже: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Lab1ContainersShip/Lab1ContainersShip/ShipGenericCollection.cs b/Lab1ContainersShip/Lab1ContainersShip/ShipGenericCollection.cs index 67a369e..e5dda48 100644 --- a/Lab1ContainersShip/Lab1ContainersShip/ShipGenericCollection.cs +++ b/Lab1ContainersShip/Lab1ContainersShip/ShipGenericCollection.cs @@ -13,6 +13,7 @@ namespace Lab1ContainersShip where T : DrawingShip where U : IMoveableObject { + public IEnumerable GetShips => _collection.GetShips(); /// /// Ширина окна прорисовки /// diff --git a/Lab1ContainersShip/Lab1ContainersShip/ShipGenericStorage.cs b/Lab1ContainersShip/Lab1ContainersShip/ShipGenericStorage.cs index 5efa8d2..4f72e9d 100644 --- a/Lab1ContainersShip/Lab1ContainersShip/ShipGenericStorage.cs +++ b/Lab1ContainersShip/Lab1ContainersShip/ShipGenericStorage.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -14,6 +15,18 @@ namespace Lab1ContainersShip { readonly Dictionary> _shipStorages; + /// + /// Разделитель для записи ключа и значения элемента словаря + /// + private static readonly char _separatorForKeyValue = '|'; + /// + /// Разделитель для записей коллекции данных в файл + /// + private readonly char _separatorRecords = ';'; + /// + /// Разделитель для записи информации по объекту в файл + /// + private static readonly char _separatorForObject = ':'; /// /// Возвращение списка названий наборов /// @@ -91,6 +104,99 @@ DrawningObjectShip>>(); } } } + /// + /// Сохранение информации по автомобилям в хранилище в файл + /// + /// Путь и имя файла + /// true - сохранение прошло успешно, false - ошибка при + //сохранении данных +public bool SaveData(string filename) + { + if (File.Exists(filename)) + { + File.Delete(filename); + } + StringBuilder data = new StringBuilder(); + foreach (KeyValuePair> record in _shipStorages) + { + StringBuilder records = new StringBuilder(); + foreach (DrawingShip elem in record.Value.GetShips) + { + records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}"); + } + data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}"); + } + if (data.Length == 0) + { + return false; + } + using FileStream fs = new FileStream(filename, FileMode.Create); + byte[] info = new + UTF8Encoding(true).GetBytes($"ShipStorage{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 FileStream(filename, FileMode.Open)) + { + byte[] b = new byte[fs.Length]; + UTF8Encoding temp = new UTF8Encoding(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("ShipStorage")) + { + //если нет такой записи, то это не те данные + return false; + } + _shipStorages.Clear(); + foreach (string data in strs) + { + string[] record = data.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries); + if (record.Length != 2) + { + continue; + } + ShipGenericCollectioncollection = new ShipGenericCollection(_pictureWidth, _pictureHeight); + string[] set = record[1].Split(_separatorRecords,StringSplitOptions.RemoveEmptyEntries); + foreach (string elem in set) + { + DrawingShip ship = + elem?.CreateDrawingShip(_separatorForObject, _pictureWidth, _pictureHeight); + if (ship != null) + { + if (collection + ship == -1) + { + return false; + } + } + } + _shipStorages.Add(record[0], collection); + } + return true; + } + } }