laba6 BlokhinDA PIbd-21 Airbus #6
@ -17,7 +17,7 @@ namespace RPP.Generics
|
||||
private readonly int _placeSizeHeight = 120;
|
||||
|
||||
private readonly SetGeneric<T> _collection;
|
||||
|
||||
public IEnumerable<T?> GetAirbus => _collection.GetAirbus();
|
||||
public AirbusGenericCollection(int picWidth, int picHeight)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
|
@ -19,6 +19,9 @@ namespace RPP.Generics
|
||||
|
||||
private readonly int _pictureHeight;
|
||||
|
||||
private static readonly char _separatorForKeyValue = '|';
|
||||
private readonly char _separatorRecords = ';';
|
||||
private static readonly char _separatorForObject = ':';
|
||||
public AirbusGenericStorage(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_airbusStorages = new Dictionary<string,
|
||||
@ -51,5 +54,79 @@ namespace RPP.Generics
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public bool SaveData(string filename)
|
||||
{
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
File.Delete(filename);
|
||||
}
|
||||
StringBuilder data = new();
|
||||
foreach (KeyValuePair<string, AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus>> record in _airbusStorages)
|
||||
{
|
||||
StringBuilder records = new();
|
||||
foreach (DrawningAirbus? elem in record.Value.GetAirbus)
|
||||
{
|
||||
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
|
||||
}
|
||||
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}");
|
||||
|
||||
}
|
||||
if (data.Length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
using (StreamWriter writer = new StreamWriter(filename))
|
||||
{
|
||||
writer.WriteLine("AirbusStorage");
|
||||
writer.Write(data.ToString());
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public bool LoadData(string filename)
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
using (StreamReader reader = new StreamReader(filename))
|
||||
{
|
||||
string checker = reader.ReadLine();
|
||||
if (checker == null)
|
||||
return false;
|
||||
if (!checker.StartsWith("AirbusStorage"))
|
||||
return false;
|
||||
_airbusStorages.Clear();
|
||||
string strs;
|
||||
bool firstinit = true;
|
||||
while ((strs = reader.ReadLine()) != null)
|
||||
{
|
||||
if (strs == null && firstinit)
|
||||
return false;
|
||||
if (strs == null)
|
||||
break;
|
||||
firstinit = false;
|
||||
string name = strs.Split('|')[0];
|
||||
AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus> collection = new(_pictureWidth, _pictureHeight);
|
||||
foreach (string data in strs.Split('|')[1].Split(';'))
|
||||
{
|
||||
DrawningAirbus? car =
|
||||
data?.CreateDrawningAirbus(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||
if (car != null)
|
||||
{
|
||||
if (!(collection + car))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
_airbusStorages.Add(name, collection);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
50
RPP/RPP/ExtentionDrawningAirbus.cs
Normal file
50
RPP/RPP/ExtentionDrawningAirbus.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using RPP.Entities;
|
||||
|
||||
namespace RPP.DrawningObjects
|
||||
{
|
||||
public static class ExtentionDrawningAirbus
|
||||
{
|
||||
public static DrawningAirbus? CreateDrawningAirbus(this string info, char
|
||||
separatorForObject, int width, int height)
|
||||
{
|
||||
string[] strs = info.Split(separatorForObject);
|
||||
if (strs.Length == 3)
|
||||
{
|
||||
return new DrawningAirbus(Convert.ToInt32(strs[0]),
|
||||
Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height);
|
||||
}
|
||||
if (strs.Length == 6)
|
||||
{
|
||||
return new DrawningFlyAirbus(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 DrawningAirbus drawningAirbus,
|
||||
char separatorForObject)
|
||||
{
|
||||
var plane = drawningAirbus._EntityAirbus;
|
||||
if (plane == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
var str =
|
||||
$"{plane.Speed}{separatorForObject}{plane.Weight}{separatorForObject}{plane.BodyColor.Name}";
|
||||
if (plane is not EntityFlyAirbus FlyAirbus)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
return
|
||||
$"{str}{separatorForObject}{FlyAirbus.AdditionalColor.Name}{separatorForObject}{FlyAirbus.Compartment}{separatorForObject}{FlyAirbus.Engine}";
|
||||
}
|
||||
}
|
||||
}
|
83
RPP/RPP/FormAirbusCollection.Designer.cs
generated
83
RPP/RPP/FormAirbusCollection.Designer.cs
generated
@ -35,14 +35,21 @@
|
||||
buttonAddObject = new Button();
|
||||
textBoxStorageName = new TextBox();
|
||||
label2 = new Label();
|
||||
label1 = new Label();
|
||||
ButtonRefreshCollection = new Button();
|
||||
ButtonRemoveAirbus = new Button();
|
||||
maskedTextBoxNumber = new TextBox();
|
||||
AddAirbusButton = new Button();
|
||||
label1 = new Label();
|
||||
menuStrip = new MenuStrip();
|
||||
menuToolStripMenuItem = new ToolStripMenuItem();
|
||||
SaveToolStripMenuItem = new ToolStripMenuItem();
|
||||
LoadToolStripMenuItem = new ToolStripMenuItem();
|
||||
pictureBoxCollection = new PictureBox();
|
||||
saveFileDialog = new SaveFileDialog();
|
||||
openFileDialog = new OpenFileDialog();
|
||||
panel1.SuspendLayout();
|
||||
panel2.SuspendLayout();
|
||||
menuStrip.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -53,13 +60,14 @@
|
||||
panel1.Controls.Add(ButtonRemoveAirbus);
|
||||
panel1.Controls.Add(maskedTextBoxNumber);
|
||||
panel1.Controls.Add(AddAirbusButton);
|
||||
panel1.Controls.Add(label1);
|
||||
panel1.Controls.Add(menuStrip);
|
||||
panel1.Dock = DockStyle.Right;
|
||||
panel1.Location = new Point(685, 0);
|
||||
panel1.Location = new Point(682, 0);
|
||||
panel1.Margin = new Padding(3, 4, 3, 4);
|
||||
panel1.Name = "panel1";
|
||||
panel1.Size = new Size(229, 600);
|
||||
panel1.Size = new Size(232, 600);
|
||||
panel1.TabIndex = 0;
|
||||
panel1.Paint += panel1_Paint;
|
||||
//
|
||||
// panel2
|
||||
//
|
||||
@ -68,6 +76,7 @@
|
||||
panel2.Controls.Add(buttonAddObject);
|
||||
panel2.Controls.Add(textBoxStorageName);
|
||||
panel2.Controls.Add(label2);
|
||||
panel2.Controls.Add(label1);
|
||||
panel2.Location = new Point(3, 36);
|
||||
panel2.Margin = new Padding(3, 4, 3, 4);
|
||||
panel2.Name = "panel2";
|
||||
@ -126,9 +135,17 @@
|
||||
label2.Text = "Наборы";
|
||||
label2.Click += label2_Click;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new Point(117, 1);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(0, 20);
|
||||
label1.TabIndex = 0;
|
||||
//
|
||||
// ButtonRefreshCollection
|
||||
//
|
||||
ButtonRefreshCollection.Location = new Point(6, 543);
|
||||
ButtonRefreshCollection.Location = new Point(8, 531);
|
||||
ButtonRefreshCollection.Margin = new Padding(3, 4, 3, 4);
|
||||
ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||
ButtonRefreshCollection.Size = new Size(217, 53);
|
||||
@ -167,14 +184,37 @@
|
||||
AddAirbusButton.UseVisualStyleBackColor = true;
|
||||
AddAirbusButton.Click += AddAirbusButton_Click;
|
||||
//
|
||||
// label1
|
||||
// menuStrip
|
||||
//
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new Point(6, 0);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(103, 20);
|
||||
label1.TabIndex = 0;
|
||||
label1.Text = "Инструменты";
|
||||
menuStrip.ImageScalingSize = new Size(20, 20);
|
||||
menuStrip.Items.AddRange(new ToolStripItem[] { menuToolStripMenuItem });
|
||||
menuStrip.Location = new Point(0, 0);
|
||||
menuStrip.Name = "menuStrip";
|
||||
menuStrip.Padding = new Padding(7, 3, 0, 3);
|
||||
menuStrip.Size = new Size(232, 30);
|
||||
menuStrip.TabIndex = 6;
|
||||
menuStrip.Text = "menuStrip1";
|
||||
//
|
||||
// menuToolStripMenuItem
|
||||
//
|
||||
menuToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { SaveToolStripMenuItem, LoadToolStripMenuItem });
|
||||
menuToolStripMenuItem.Name = "menuToolStripMenuItem";
|
||||
menuToolStripMenuItem.Size = new Size(65, 24);
|
||||
menuToolStripMenuItem.Text = "Меню";
|
||||
//
|
||||
// SaveToolStripMenuItem
|
||||
//
|
||||
SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
|
||||
SaveToolStripMenuItem.Size = new Size(224, 26);
|
||||
SaveToolStripMenuItem.Text = "Сохранить";
|
||||
SaveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
|
||||
//
|
||||
// LoadToolStripMenuItem
|
||||
//
|
||||
LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
|
||||
LoadToolStripMenuItem.Size = new Size(224, 26);
|
||||
LoadToolStripMenuItem.Text = "Загрузить";
|
||||
LoadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
|
||||
//
|
||||
// pictureBoxCollection
|
||||
//
|
||||
@ -182,10 +222,18 @@
|
||||
pictureBoxCollection.Location = new Point(0, 0);
|
||||
pictureBoxCollection.Margin = new Padding(3, 4, 3, 4);
|
||||
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
pictureBoxCollection.Size = new Size(685, 600);
|
||||
pictureBoxCollection.Size = new Size(682, 600);
|
||||
pictureBoxCollection.TabIndex = 1;
|
||||
pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
// saveFileDialog
|
||||
//
|
||||
saveFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// openFileDialog
|
||||
//
|
||||
openFileDialog.FileName = "openFileDialog1";
|
||||
//
|
||||
// FormAirbusCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
@ -193,6 +241,7 @@
|
||||
ClientSize = new Size(914, 600);
|
||||
Controls.Add(pictureBoxCollection);
|
||||
Controls.Add(panel1);
|
||||
MainMenuStrip = menuStrip;
|
||||
Margin = new Padding(3, 4, 3, 4);
|
||||
Name = "FormAirbusCollection";
|
||||
Text = "FormFlyAirbus";
|
||||
@ -201,6 +250,8 @@
|
||||
panel1.PerformLayout();
|
||||
panel2.ResumeLayout(false);
|
||||
panel2.PerformLayout();
|
||||
menuStrip.ResumeLayout(false);
|
||||
menuStrip.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
@ -220,5 +271,11 @@
|
||||
private ListBox listBoxStorages;
|
||||
private Button buttonAddObject;
|
||||
private Button buttonDelObject;
|
||||
private MenuStrip menuStrip;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private ToolStripMenuItem menuToolStripMenuItem;
|
||||
private ToolStripMenuItem SaveToolStripMenuItem;
|
||||
private ToolStripMenuItem LoadToolStripMenuItem;
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
using RPP.DrawningObjects;
|
||||
using RPP.Generics;
|
||||
using RPP.MovementStrategy;
|
||||
using System.Windows.Forms;
|
||||
|
||||
|
||||
namespace RPP
|
||||
@ -146,6 +146,36 @@ namespace RPP
|
||||
}
|
||||
pictureBoxCollection.Image = obj.ShowCars();
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void panel2_Paint(object sender, PaintEventArgs e)
|
||||
{
|
||||
@ -156,5 +186,10 @@ namespace RPP
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void panel1_Paint(object sender, PaintEventArgs e)
|
||||
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -117,4 +117,13 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>291, 17</value>
|
||||
</metadata>
|
||||
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>152, 17</value>
|
||||
</metadata>
|
||||
</root>
|
@ -9,8 +9,6 @@ namespace RPP.Generics
|
||||
{
|
||||
public class SetGeneric<T> where T : class
|
||||
{
|
||||
|
||||
|
||||
private readonly List<T?> _places;
|
||||
|
||||
public int Count => _places.Count;
|
||||
@ -63,12 +61,16 @@ namespace RPP.Generics
|
||||
{
|
||||
if (position < 0 || position > _maxCount)
|
||||
return null;
|
||||
if (_places.Count <= position)
|
||||
return null;
|
||||
return _places[position];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (position < 0 || position > _maxCount)
|
||||
return;
|
||||
if (_places.Count <= position)
|
||||
return;
|
||||
_places[position] = value;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user
Пустых методов быть не должно