Compare commits

..

2 Commits

Author SHA1 Message Date
1d71499845 Lab_6 2024-05-05 22:45:24 +03:00
e0a52ea60c Готовая Lab_6 2024-05-05 18:52:43 +03:00
7 changed files with 427 additions and 167 deletions

View File

@ -37,6 +37,8 @@ namespace Sailboat.Generics
/// Набор объектов
/// </summary>
private readonly SetGeneric<T> _collection;
internal IEnumerable<DrawingBoat> GetBoats;
/// <summary>
/// Конструктор
/// </summary>

View File

@ -28,6 +28,18 @@ namespace Sailboat.Generics
/// </summary>
private readonly int _pictureHeight;
/// <summary>
/// Разделитель для записи ключа и значения элемента словаря
/// </summary>
private static readonly char _separatorForKeyValue = '|';
/// <summary>
/// Разделитель для записей коллекции данных в файл
/// </summary>
private readonly char _separatorRecords = ';';
/// <summary>
/// Разделитель для записи информации по объекту в файл
/// </summary>
private static readonly char _separatorForObject = ':';
/// <summary>
/// Конструктор
/// </summary>
/// <param name="pictureWidth"></param>
@ -80,5 +92,94 @@ namespace Sailboat.Generics
return null;
}
}
/// <summary>
/// Сохранение информации по лодкам в хранилище в файл
/// </summary>
/// <param name="filename">Путь и имя файла</param>
/// <returns>true - сохранение прошло успешно, false - ошибка при сохранении данных</returns>
public bool SaveData(string filename)
{
if (File.Exists(filename))
{
File.Delete(filename);
}
StringBuilder data = new();
foreach (KeyValuePair<string, BoatsGenericCollection<DrawingBoat, DrawingObjectBoat>> record in _boatStorages)
{
StringBuilder records = new();
foreach (DrawingBoat? elem in record.Value.GetBoats)
{
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.Write($"BoatStorage{Environment.NewLine}{data}");
}
return true;
}
/// <summary>
/// Загрузка информации по лодкам в хранилище из файла
/// </summary>
/// <param name="filename">Путь и имя файла</param>
/// <returns>true - загрузка прошла успешно, false - ошибка призагрузке данных</returns>
public bool LoadData(string filename)
{
if (!File.Exists(filename))
{
return false;
}
using (StreamReader fs = File.OpenText(filename))
{
string str = fs.ReadLine();
if (str == null || str.Length == 0)
{
return false;
}
if (!str.StartsWith("BoatStorage"))
{
return false;
}
_boatStorages.Clear();
string strs = "";
while ((strs = fs.ReadLine()) != null)
{
if (strs == null)
{
return false;
}
string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
if (record.Length != 2)
{
continue;
}
BoatsGenericCollection<DrawingBoat, DrawingObjectBoat> collection = new(_pictureWidth, _pictureHeight);
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set)
{
DrawingBoat? boat = elem?.CreateDrawingBoat(_separatorForObject, _pictureWidth, _pictureHeight);
if (boat != null)
{
if (!(collection + boat))
{
return false;
}
}
}
_boatStorages.Add(record[0], collection);
}
return true;
}
}
}
}
}

View File

@ -0,0 +1,63 @@
using Sailboat.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;
namespace Sailboat.DrawingObjects
{
public static class ExtentionDrawingBoat
{
/// <summary>
/// Создание объекта из строки
/// </summary>
/// <param name="info">Строка с данными для создания объекта</param>
/// <param name="separatorForObject">Разделитель даннных</param>
/// <param name="width">Ширина</param>
/// <param name="height">Высота</param>
/// <returns>Объект</returns>
public static DrawingBoat? CreateDrawingBoat(this string info, char separatorForObject, int width, int height)
{
string[] strs = info.Split(separatorForObject);
if (strs.Length == 3)
{
return new DrawingBoat(Convert.ToInt32(strs[0]),
Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height);
}
if (strs.Length == 6)
{
return new DrawingSailboat(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;
}
/// <summary>
/// Получение данных для сохранения в файл
/// </summary>
/// <param name="drawningCar">Сохраняемый объект</param>
/// <param name="separatorForObject">Разделитель даннных</param>
/// <returns>Строка с данными по объекту</returns>
public static string GetDataForSave(this DrawingBoat drawingBoat, char separatorForObject)
{
var boat = drawingBoat.EntityBoat;
if (boat == null)
{
return string.Empty;
}
var str = $"{boat.Speed}{separatorForObject}{boat.Weight}{separatorForObject}{boat.BodyColor.Name}";
if (boat is not EntitySailboat sailboat)
{
return str;
}
return $"{str}{separatorForObject}{sailboat.AdditionalColor.Name}{separatorForObject}{sailboat.Hull}{separatorForObject}{sailboat.Sail}";
}
}
}

View File

@ -28,160 +28,207 @@
/// </summary>
private void InitializeComponent()
{
pictureBoxCollection = new PictureBox();
panelTools = new Panel();
panelCollection = new Panel();
buttonDelObject = new Button();
listBoxStorages = new ListBox();
buttonAddObject = new Button();
textBoxStorageName = new TextBox();
maskedTextBoxNumber = new MaskedTextBox();
buttonRefreshCollection = new Button();
buttonRemoveBoat = new Button();
buttonAddBoat = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
panelTools.SuspendLayout();
panelCollection.SuspendLayout();
SuspendLayout();
this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
this.panelTools = new System.Windows.Forms.Panel();
this.panelCollection = new System.Windows.Forms.Panel();
this.buttonDelObject = new System.Windows.Forms.Button();
this.listBoxStorages = new System.Windows.Forms.ListBox();
this.buttonAddObject = new System.Windows.Forms.Button();
this.textBoxStorageName = new System.Windows.Forms.TextBox();
this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox();
this.buttonRefreshCollection = new System.Windows.Forms.Button();
this.buttonRemoveBoat = new System.Windows.Forms.Button();
this.buttonAddBoat = new System.Windows.Forms.Button();
this.menuStrip = new System.Windows.Forms.MenuStrip();
this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.SaveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.LoadToolStripMenuItem = 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.panelTools.SuspendLayout();
this.panelCollection.SuspendLayout();
this.menuStrip.SuspendLayout();
this.SuspendLayout();
//
// pictureBoxCollection
//
pictureBoxCollection.Location = new Point(0, 0);
pictureBoxCollection.Margin = new Padding(3, 2, 3, 2);
pictureBoxCollection.Name = "pictureBoxCollection";
pictureBoxCollection.Size = new Size(750, 600);
pictureBoxCollection.SizeMode = PictureBoxSizeMode.AutoSize;
pictureBoxCollection.TabIndex = 0;
pictureBoxCollection.TabStop = false;
pictureBoxCollection.Click += pictureBoxCollection_Click;
this.pictureBoxCollection.Location = new System.Drawing.Point(0, 0);
this.pictureBoxCollection.Name = "pictureBoxCollection";
this.pictureBoxCollection.Size = new System.Drawing.Size(750, 600);
this.pictureBoxCollection.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxCollection.TabIndex = 0;
this.pictureBoxCollection.TabStop = false;
//
// panelTools
//
panelTools.BackColor = SystemColors.ScrollBar;
panelTools.Controls.Add(panelCollection);
panelTools.Controls.Add(maskedTextBoxNumber);
panelTools.Controls.Add(buttonRefreshCollection);
panelTools.Controls.Add(buttonRemoveBoat);
panelTools.Controls.Add(buttonAddBoat);
panelTools.Location = new Point(639, 20);
panelTools.Margin = new Padding(3, 2, 3, 2);
panelTools.Name = "panelTools";
panelTools.Size = new Size(183, 441);
panelTools.TabIndex = 1;
panelTools.Paint += panelTools_Paint;
this.panelTools.BackColor = System.Drawing.SystemColors.ScrollBar;
this.panelTools.Controls.Add(this.panelCollection);
this.panelTools.Controls.Add(this.maskedTextBoxNumber);
this.panelTools.Controls.Add(this.buttonRefreshCollection);
this.panelTools.Controls.Add(this.buttonRemoveBoat);
this.panelTools.Controls.Add(this.buttonAddBoat);
this.panelTools.Controls.Add(this.menuStrip);
this.panelTools.Location = new System.Drawing.Point(756, 0);
this.panelTools.Name = "panelTools";
this.panelTools.Size = new System.Drawing.Size(209, 722);
this.panelTools.TabIndex = 1;
//
// panelCollection
//
panelCollection.BackColor = SystemColors.AppWorkspace;
panelCollection.Controls.Add(buttonDelObject);
panelCollection.Controls.Add(listBoxStorages);
panelCollection.Controls.Add(buttonAddObject);
panelCollection.Controls.Add(textBoxStorageName);
panelCollection.Location = new Point(14, 11);
panelCollection.Margin = new Padding(3, 2, 3, 2);
panelCollection.Name = "panelCollection";
panelCollection.Size = new Size(158, 215);
panelCollection.TabIndex = 4;
this.panelCollection.BackColor = System.Drawing.SystemColors.AppWorkspace;
this.panelCollection.Controls.Add(this.buttonDelObject);
this.panelCollection.Controls.Add(this.listBoxStorages);
this.panelCollection.Controls.Add(this.buttonAddObject);
this.panelCollection.Controls.Add(this.textBoxStorageName);
this.panelCollection.Location = new System.Drawing.Point(20, 166);
this.panelCollection.Name = "panelCollection";
this.panelCollection.Size = new System.Drawing.Size(181, 287);
this.panelCollection.TabIndex = 4;
//
// buttonDelObject
//
buttonDelObject.Location = new Point(10, 172);
buttonDelObject.Margin = new Padding(3, 2, 3, 2);
buttonDelObject.Name = "buttonDelObject";
buttonDelObject.Size = new Size(135, 26);
buttonDelObject.TabIndex = 5;
buttonDelObject.Text = "Удалить набор";
buttonDelObject.UseVisualStyleBackColor = true;
buttonDelObject.Click += buttonDelObject_Click;
this.buttonDelObject.Location = new System.Drawing.Point(12, 230);
this.buttonDelObject.Name = "buttonDelObject";
this.buttonDelObject.Size = new System.Drawing.Size(154, 34);
this.buttonDelObject.TabIndex = 5;
this.buttonDelObject.Text = "Удалить набор";
this.buttonDelObject.UseVisualStyleBackColor = true;
this.buttonDelObject.Click += new System.EventHandler(this.buttonDelObject_Click);
//
// listBoxStorages
//
listBoxStorages.FormattingEnabled = true;
listBoxStorages.ItemHeight = 15;
listBoxStorages.Location = new Point(10, 76);
listBoxStorages.Margin = new Padding(3, 2, 3, 2);
listBoxStorages.Name = "listBoxStorages";
listBoxStorages.Size = new Size(135, 79);
listBoxStorages.TabIndex = 6;
listBoxStorages.SelectedIndexChanged += ListBoxObjects_SelectedIndexChanged;
this.listBoxStorages.FormattingEnabled = true;
this.listBoxStorages.ItemHeight = 20;
this.listBoxStorages.Location = new System.Drawing.Point(12, 102);
this.listBoxStorages.Name = "listBoxStorages";
this.listBoxStorages.Size = new System.Drawing.Size(154, 104);
this.listBoxStorages.TabIndex = 6;
this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.ListBoxObjects_SelectedIndexChanged);
//
// buttonAddObject
//
buttonAddObject.Location = new Point(10, 46);
buttonAddObject.Margin = new Padding(3, 2, 3, 2);
buttonAddObject.Name = "buttonAddObject";
buttonAddObject.Size = new Size(135, 26);
buttonAddObject.TabIndex = 5;
buttonAddObject.Text = "Добавить набор";
buttonAddObject.UseVisualStyleBackColor = true;
buttonAddObject.Click += buttonAddObject_Click;
this.buttonAddObject.Location = new System.Drawing.Point(12, 62);
this.buttonAddObject.Name = "buttonAddObject";
this.buttonAddObject.Size = new System.Drawing.Size(154, 34);
this.buttonAddObject.TabIndex = 5;
this.buttonAddObject.Text = "Добавить набор";
this.buttonAddObject.UseVisualStyleBackColor = true;
this.buttonAddObject.Click += new System.EventHandler(this.buttonAddObject_Click);
//
// textBoxStorageName
//
textBoxStorageName.Location = new Point(25, 22);
textBoxStorageName.Margin = new Padding(3, 2, 3, 2);
textBoxStorageName.Name = "textBoxStorageName";
textBoxStorageName.Size = new Size(110, 23);
textBoxStorageName.TabIndex = 0;
this.textBoxStorageName.Location = new System.Drawing.Point(29, 29);
this.textBoxStorageName.Name = "textBoxStorageName";
this.textBoxStorageName.Size = new System.Drawing.Size(125, 27);
this.textBoxStorageName.TabIndex = 0;
//
// maskedTextBoxNumber
//
maskedTextBoxNumber.Location = new Point(39, 312);
maskedTextBoxNumber.Margin = new Padding(3, 2, 3, 2);
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
maskedTextBoxNumber.Size = new Size(110, 23);
maskedTextBoxNumber.TabIndex = 3;
this.maskedTextBoxNumber.Location = new System.Drawing.Point(49, 567);
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
this.maskedTextBoxNumber.Size = new System.Drawing.Size(125, 27);
this.maskedTextBoxNumber.TabIndex = 3;
//
// buttonRefreshCollection
//
buttonRefreshCollection.Location = new Point(14, 398);
buttonRefreshCollection.Margin = new Padding(3, 2, 3, 2);
buttonRefreshCollection.Name = "buttonRefreshCollection";
buttonRefreshCollection.Size = new Size(158, 26);
buttonRefreshCollection.TabIndex = 2;
buttonRefreshCollection.Text = "Обновить коллекцию";
buttonRefreshCollection.UseVisualStyleBackColor = true;
buttonRefreshCollection.Click += buttonRefreshCollection_Click;
this.buttonRefreshCollection.Location = new System.Drawing.Point(20, 682);
this.buttonRefreshCollection.Name = "buttonRefreshCollection";
this.buttonRefreshCollection.Size = new System.Drawing.Size(180, 34);
this.buttonRefreshCollection.TabIndex = 2;
this.buttonRefreshCollection.Text = "Обновить коллекцию";
this.buttonRefreshCollection.UseVisualStyleBackColor = true;
this.buttonRefreshCollection.Click += new System.EventHandler(this.buttonRefreshCollection_Click);
//
// buttonRemoveBoat
//
buttonRemoveBoat.Location = new Point(15, 352);
buttonRemoveBoat.Margin = new Padding(3, 2, 3, 2);
buttonRemoveBoat.Name = "buttonRemoveBoat";
buttonRemoveBoat.Size = new Size(158, 26);
buttonRemoveBoat.TabIndex = 1;
buttonRemoveBoat.Text = "Удалить лодку";
buttonRemoveBoat.UseVisualStyleBackColor = true;
buttonRemoveBoat.Click += buttonRemoveBoat_Click;
this.buttonRemoveBoat.Location = new System.Drawing.Point(21, 620);
this.buttonRemoveBoat.Name = "buttonRemoveBoat";
this.buttonRemoveBoat.Size = new System.Drawing.Size(180, 34);
this.buttonRemoveBoat.TabIndex = 1;
this.buttonRemoveBoat.Text = "Удалить лодку";
this.buttonRemoveBoat.UseVisualStyleBackColor = true;
this.buttonRemoveBoat.Click += new System.EventHandler(this.buttonRemoveBoat_Click);
//
// buttonAddBoat
//
buttonAddBoat.Location = new Point(14, 254);
buttonAddBoat.Margin = new Padding(3, 2, 3, 2);
buttonAddBoat.Name = "buttonAddBoat";
buttonAddBoat.Size = new Size(158, 26);
buttonAddBoat.TabIndex = 0;
buttonAddBoat.Text = "Добавить лодку";
buttonAddBoat.UseVisualStyleBackColor = true;
buttonAddBoat.Click += buttonAddBoat_Click;
this.buttonAddBoat.Location = new System.Drawing.Point(20, 490);
this.buttonAddBoat.Name = "buttonAddBoat";
this.buttonAddBoat.Size = new System.Drawing.Size(180, 34);
this.buttonAddBoat.TabIndex = 0;
this.buttonAddBoat.Text = "Добавить лодку";
this.buttonAddBoat.UseVisualStyleBackColor = true;
this.buttonAddBoat.Click += new System.EventHandler(this.buttonAddBoat_Click);
//
// menuStrip
//
this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20);
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripMenuItem1,
this.ToolStripMenuItem});
this.menuStrip.Location = new System.Drawing.Point(0, 0);
this.menuStrip.Name = "menuStrip";
this.menuStrip.Size = new System.Drawing.Size(209, 28);
this.menuStrip.TabIndex = 5;
//
// toolStripMenuItem1
//
this.toolStripMenuItem1.Name = "toolStripMenuItem1";
this.toolStripMenuItem1.Size = new System.Drawing.Size(14, 24);
//
// ToolStripMenuItem
//
this.ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.SaveToolStripMenuItem,
this.LoadToolStripMenuItem});
this.ToolStripMenuItem.Name = "ToolStripMenuItem";
this.ToolStripMenuItem.Size = new System.Drawing.Size(59, 24);
this.ToolStripMenuItem.Text = "Файл";
//
// SaveToolStripMenuItem
//
this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
this.SaveToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
this.SaveToolStripMenuItem.Text = "Сохранение";
this.SaveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click);
//
// LoadToolStripMenuItem
//
this.LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
this.LoadToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
this.LoadToolStripMenuItem.Text = "Загрузка";
this.LoadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click);
//
// openFileDialog
//
this.openFileDialog.FileName = "openFileDialog";
this.openFileDialog.Filter = "txt file | *.txt";
//
// saveFileDialog
//
this.saveFileDialog.Filter = "txt file | *.txt";
//
// FormBoatCollection
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(834, 546);
Controls.Add(panelTools);
Controls.Add(pictureBoxCollection);
Margin = new Padding(3, 2, 3, 2);
Name = "FormBoatCollection";
Text = "FormBoatCollection";
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
panelTools.ResumeLayout(false);
panelTools.PerformLayout();
panelCollection.ResumeLayout(false);
panelCollection.PerformLayout();
ResumeLayout(false);
PerformLayout();
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(969, 728);
this.Controls.Add(this.panelTools);
this.Controls.Add(this.pictureBoxCollection);
this.MainMenuStrip = this.menuStrip;
this.Name = "FormBoatCollection";
this.Text = "FormBoatCollection";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
this.panelTools.ResumeLayout(false);
this.panelTools.PerformLayout();
this.panelCollection.ResumeLayout(false);
this.panelCollection.PerformLayout();
this.menuStrip.ResumeLayout(false);
this.menuStrip.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
@ -197,5 +244,12 @@
private ListBox listBoxStorages;
private Button buttonAddObject;
private TextBox textBoxStorageName;
private MenuStrip menuStrip;
private ToolStripMenuItem toolStripMenuItem1;
private ToolStripMenuItem ToolStripMenuItem;
private ToolStripMenuItem SaveToolStripMenuItem;
private ToolStripMenuItem LoadToolStripMenuItem;
private OpenFileDialog openFileDialog;
private SaveFileDialog saveFileDialog;
}
}

View File

@ -48,6 +48,23 @@ namespace Sailboat
}
private void buttonAddBoat_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
if (obj == null)
{
return;
}
var formBoatConfig = new FormBoatConfig();
formBoatConfig.AddEvent(AddBoat);
formBoatConfig.Show();
}
private void AddBoat(DrawingBoat drawingBoat)
{
if (listBoxStorages.SelectedIndex == -1)
{
@ -59,21 +76,16 @@ namespace Sailboat
{
return;
}
FormBoatConfig form = new FormBoatConfig(pictureBoxCollection.Width, pictureBoxCollection.Height);
form.Show();
Action<DrawingBoat>? boatDelegate = new((plane) =>
if (obj + drawingBoat)
{
if (obj + plane)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = obj.ShowBoats();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
});
form.AddEvent(boatDelegate);
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = obj.ShowBoats();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
private void buttonRemoveBoat_Click(object sender, EventArgs e)
@ -146,7 +158,7 @@ namespace Sailboat
{
return;
}
if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
if (MessageBox.Show($"Удалить объект { listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
_storage.DelSet(listBoxStorages.SelectedItem.ToString()
?? string.Empty);
@ -154,14 +166,40 @@ namespace Sailboat
}
}
private void panelTools_Paint(object sender, PaintEventArgs e)
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 pictureBoxCollection_Click(object sender, EventArgs e)
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
{
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
if (_storage.LoadData(openFileDialog.FileName))
{
MessageBox.Show("Загрузка прошла успешно",
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Не загрузилось", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
ReloadObjects();
}
}
}

View File

@ -176,7 +176,7 @@
this.labelModifiedObject.TabIndex = 8;
this.labelModifiedObject.Text = "Продвинутый";
this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LableObject_MouseDown);
this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
//
// labelSimpleObject
//
@ -187,7 +187,7 @@
this.labelSimpleObject.TabIndex = 7;
this.labelSimpleObject.Text = "Простой";
this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LableObject_MouseDown);
this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
//
// checkBoxSail
//
@ -326,7 +326,7 @@
this.buttonOk.TabIndex = 3;
this.buttonOk.Text = "Добавить";
this.buttonOk.UseVisualStyleBackColor = true;
this.buttonOk.Click += new System.EventHandler(this.buttonOk_Click);
this.buttonOk.Click += new System.EventHandler(this.ButtonOk_Click);
//
// buttonCancel
//

View File

@ -1,6 +1,4 @@
using Sailboat.DrawingObjects;
using Sailboat.Entities;
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
@ -10,18 +8,19 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Sailboat.DrawingObjects;
using Sailboat.Generics;
using Sailboat.MovementStrategy;
using Sailboat.Entities;
namespace Sailboat
{
public partial class FormBoatConfig : Form
{
DrawingBoat? _boat = null;
private event Action<DrawingBoat>? EventAddBoat;
public int _pictureWidth { get; private set; }
public int _pictureHeight { get; private set; }
public FormBoatConfig(int pictureWidth, int pictureHeight)
private event Action <DrawingBoat>? EventAddBoat;
public FormBoatConfig()
{
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
InitializeComponent();
panelBlack.MouseDown += PanelColor_MouseDown;
panelPurple.MouseDown += PanelColor_MouseDown;
@ -54,21 +53,18 @@ namespace Sailboat
EventAddBoat += ev;
}
}
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
{
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
}
private void LableObject_MouseDown(object sender, MouseEventArgs e)
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
{
(sender as Label)?.DoDragDrop((sender as Label)?.Name,
DragDropEffects.Move | DragDropEffects.Copy);
}
private void PanelObject_DragEnter(object sender, DragEventArgs e)
{
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
{
e.Effect = DragDropEffects.Copy;
@ -85,29 +81,34 @@ namespace Sailboat
{
case "labelSimpleObject":
_boat = new DrawingBoat((int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value, Color.White, _pictureWidth, _pictureHeight);
(int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width,
pictureBoxObject.Height);
break;
case "labelModifiedObject":
_boat = new DrawingSailboat((int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxHull.Checked,
checkBoxSail.Checked, _pictureWidth, _pictureHeight);
checkBoxSail.Checked, pictureBoxObject.Width,
pictureBoxObject.Height);
break;
}
DrawBoat();
}
private void LabelColor_DragDrop(object sender, DragEventArgs e)
{
if (_boat?.EntityBoat == null)
if (_boat == null)
return;
Color bodyColor = (Color)e.Data.GetData(typeof(Color));
_boat.EntityBoat.ChangeColor(bodyColor);
DrawBoat();
}
private void addColorLabel_DragDrop(object sender, DragEventArgs e)
{
if ((_boat?.EntityBoat == null) || (_boat is DrawingSailboat == false))
return;
((EntitySailboat)_boat.EntityBoat).ChangeAddColor((Color)e.Data.GetData(typeof(Color)));
switch (((Label)sender).Name)
{
case "labelColor":
_boat.EntityBoat.setBodyColor((Color)e.Data.GetData(typeof(Color)));
break;
case "labelAddColor":
if (!(_boat is DrawingSailboat))
return;
(_boat.EntityBoat as EntitySailboat).setAdditionalColor((Color)e.Data.GetData(typeof(Color)));
break;
}
DrawBoat();
}
private void LabelColor_DragEnter(object sender, DragEventArgs e)
@ -121,7 +122,8 @@ namespace Sailboat
e.Effect = DragDropEffects.None;
}
}
private void buttonOk_Click(object sender, EventArgs e)
private void ButtonOk_Click(object sender, EventArgs e)
{
EventAddBoat?.Invoke(_boat);
Close();