зафиксировать
This commit is contained in:
parent
41542e271d
commit
e085b87859
@ -1,44 +1,43 @@
|
||||
using ProjectBoat_bae.DrawningObjects;
|
||||
using ProjectBoat_bae.Entities;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing.Text;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using ProjectBoat_bae.DrawningObjects;
|
||||
using ProjectBoat_bae.Entities;
|
||||
|
||||
namespace ProjectBoat_bae
|
||||
{
|
||||
public static class ExtentionBoat
|
||||
internal static class ExtentionCar
|
||||
{
|
||||
// Разделитель для записи информации по объекту в файл
|
||||
private static readonly char _separatorForObject = ':';
|
||||
|
||||
// Создание объекта из строки
|
||||
public static Drawningboat CreateDrawningBoat(this string info)
|
||||
public static Drawningboat CreateDrawningBoat(this string info, char _separatorForObject, int _pictureWidth)
|
||||
{
|
||||
string[] strs = info.Split(_separatorForObject);
|
||||
if (strs.Length == 3)
|
||||
{
|
||||
return new Drawningboat(Convert.ToInt32(strs[0]),
|
||||
Convert.ToInt32(strs[1]), Color.FromName(strs[2]));
|
||||
Convert.ToInt32(strs[1]), Color.FromName(strs[2]), Convert.ToInt32(strs[3]), Convert.ToInt32(strs[4]));
|
||||
}
|
||||
if (strs.Length == 7)
|
||||
{
|
||||
return new DrawningMotorBoat(Convert.ToInt32(strs[0]),
|
||||
Convert.ToInt32(strs[1]), Color.FromName(strs[2]),
|
||||
Color.FromName(strs[3]), Convert.ToBoolean(strs[4]),
|
||||
Convert.ToBoolean(strs[5]), Convert.ToBoolean(strs[6]));
|
||||
Convert.ToBoolean(strs[5]), Convert.ToInt32(strs[6]), Convert.ToInt32(strs[7]));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение данных для сохранения в файл
|
||||
/// </summary>
|
||||
/// <param name="drawningCar"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetDataForSave(this DrawningBoat drawningBoat)
|
||||
|
||||
// Получение данных для сохранения в файл
|
||||
public static string GetDataForSave(this Drawningboat drawningBoat, char _separatorForObject)
|
||||
{
|
||||
var boat = drawningBoat.Boat;
|
||||
var boat = drawningBoat.EntityBoat;
|
||||
var str =
|
||||
$"{boat.Speed}{_separatorForObject}{boat.Weight}{_separatorForObject}{boat.BodyColor.Name}";
|
||||
if (boat is not EntityMotorBoat motorBoat)
|
||||
@ -46,7 +45,7 @@ namespace ProjectBoat_bae
|
||||
return str;
|
||||
}
|
||||
return
|
||||
$"{str}{_separatorForObject}{motorBoat.DopColor.Name}{_separatorForObject}{motorBoat.BodyKit}{_separatorForObject}{motorBoat.Wing}{_separatorForObject}{motorBoat.SportLine}";
|
||||
$"{str}{_separatorForObject}{motorBoat.AdditionalColor.Name}{_separatorForObject}{motorBoat.Body}{_separatorForObject}{motorBoat.Wing}{_separatorForObject}";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -37,7 +37,14 @@
|
||||
ButtonRemoveBoat = new Button();
|
||||
ButtonRefreshCollection = new Button();
|
||||
textBoxBoat = new TextBox();
|
||||
menuStrip1 = new MenuStrip();
|
||||
файлToolStripMenuItem = new ToolStripMenuItem();
|
||||
сохранениеToolStripMenuItem = new ToolStripMenuItem();
|
||||
загрузкаToolStripMenuItem = new ToolStripMenuItem();
|
||||
openFileDialog = new OpenFileDialog();
|
||||
saveFileDialog = new SaveFileDialog();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||
menuStrip1.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// pictureBoxCollection
|
||||
@ -127,11 +134,50 @@
|
||||
textBoxBoat.Size = new Size(173, 31);
|
||||
textBoxBoat.TabIndex = 8;
|
||||
//
|
||||
// menuStrip1
|
||||
//
|
||||
menuStrip1.ImageScalingSize = new Size(24, 24);
|
||||
menuStrip1.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem });
|
||||
menuStrip1.Location = new Point(0, 0);
|
||||
menuStrip1.Name = "menuStrip1";
|
||||
menuStrip1.Size = new Size(1178, 33);
|
||||
menuStrip1.TabIndex = 9;
|
||||
menuStrip1.Text = "menuStrip1";
|
||||
//
|
||||
// файлToolStripMenuItem
|
||||
//
|
||||
файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { сохранениеToolStripMenuItem, загрузкаToolStripMenuItem });
|
||||
файлToolStripMenuItem.Name = "файлToolStripMenuItem";
|
||||
файлToolStripMenuItem.Size = new Size(69, 29);
|
||||
файлToolStripMenuItem.Text = "Файл";
|
||||
//
|
||||
// сохранениеToolStripMenuItem
|
||||
//
|
||||
сохранениеToolStripMenuItem.Name = "сохранениеToolStripMenuItem";
|
||||
сохранениеToolStripMenuItem.Size = new Size(270, 34);
|
||||
сохранениеToolStripMenuItem.Text = "Сохранение";
|
||||
//
|
||||
// загрузкаToolStripMenuItem
|
||||
//
|
||||
загрузкаToolStripMenuItem.Name = "загрузкаToolStripMenuItem";
|
||||
загрузкаToolStripMenuItem.Size = new Size(270, 34);
|
||||
загрузкаToolStripMenuItem.Text = "Загрузка";
|
||||
//
|
||||
// openFileDialog
|
||||
//
|
||||
openFileDialog.FileName = "openFileDialog1";
|
||||
openFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// saveFileDialog
|
||||
//
|
||||
saveFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// FormBoatCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(10F, 25F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1178, 644);
|
||||
Controls.Add(menuStrip1);
|
||||
Controls.Add(textBoxBoat);
|
||||
Controls.Add(ButtonRefreshCollection);
|
||||
Controls.Add(ButtonRemoveBoat);
|
||||
@ -141,9 +187,12 @@
|
||||
Controls.Add(ButtonAddObject);
|
||||
Controls.Add(listBoxStorages);
|
||||
Controls.Add(pictureBoxCollection);
|
||||
MainMenuStrip = menuStrip1;
|
||||
Name = "FormBoatCollection";
|
||||
Text = "FormBoatCollection";
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||
menuStrip1.ResumeLayout(false);
|
||||
menuStrip1.PerformLayout();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
@ -159,5 +208,11 @@
|
||||
private Button ButtonRemoveBoat;
|
||||
private Button ButtonRefreshCollection;
|
||||
private TextBox textBoxBoat;
|
||||
private MenuStrip menuStrip1;
|
||||
private ToolStripMenuItem файлToolStripMenuItem;
|
||||
private ToolStripMenuItem сохранениеToolStripMenuItem;
|
||||
private ToolStripMenuItem загрузкаToolStripMenuItem;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
}
|
||||
}
|
@ -83,7 +83,7 @@ namespace ProjectBoat_bae
|
||||
if (obj == null) return;
|
||||
|
||||
FormBoatConfig form = new FormBoatConfig();
|
||||
|
||||
|
||||
form.AddEvent(AddBoat);
|
||||
form.Show();
|
||||
}
|
||||
@ -161,5 +161,42 @@ namespace ProjectBoat_bae
|
||||
pictureBoxCollection.Image =
|
||||
_storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowBoats();
|
||||
}
|
||||
|
||||
//сохранение
|
||||
private void SaveToolStripMenu_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_storage.SaveData(saveFileDialog.FileName))
|
||||
{
|
||||
MessageBox.Show("Save Complete", "Result",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Save Not Complete", "Result",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//загрузка
|
||||
private void LoadToolStripMenu_Click(object sender, EventArgs args)
|
||||
{
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_storage.LoadData(openFileDialog.FileName))
|
||||
{
|
||||
MessageBox.Show("Load Complete", "Result",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
ReloadObjects();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Load Not Complete", "Result",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -117,4 +117,16 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="menuStrip1.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>176, 16</value>
|
||||
</metadata>
|
||||
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>363, 21</value>
|
||||
</metadata>
|
||||
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>38</value>
|
||||
</metadata>
|
||||
</root>
|
@ -108,5 +108,8 @@ namespace ProjectBoat_bae.Generics
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Получение объектов коллекции
|
||||
public IEnumerable<T?> GetCars => _collection.GetBoats();
|
||||
}
|
||||
}
|
||||
|
@ -43,5 +43,179 @@ namespace ProjectBoat_bae.Generics
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//// Разделитель для записи ключа и значения элемента словаря
|
||||
//private static readonly char _separatorForKeyValue = '|';
|
||||
|
||||
//// Разделитель для записей коллекции данных в файл
|
||||
//private readonly char _separatorRecords = ';';
|
||||
|
||||
//// Разделитель для записи информации по объекту в файл
|
||||
//private static readonly char _separatorForObject = ':';
|
||||
|
||||
//// Сохранение информации по автомобилям в хранилище в файл
|
||||
//public bool SaveData(string filename)
|
||||
//{
|
||||
// if (File.Exists(filename))
|
||||
// {
|
||||
// File.Delete(filename);
|
||||
// }
|
||||
// StringBuilder data = new();
|
||||
// foreach (KeyValuePair<string, BoatsGenericCollection<Drawningboat, DrawningObjectBoat>> record in _boatStorages)
|
||||
// {
|
||||
// StringBuilder records = new();
|
||||
// foreach (Drawningboat? 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($"PlaneStorage{Environment.NewLine}{data}");
|
||||
// }
|
||||
// return true;
|
||||
//}
|
||||
|
||||
///// Загрузка информации в хранилище из файла
|
||||
//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("PlaneStorage"))
|
||||
// {
|
||||
// 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<Drawningboat, DrawningObjectBoat> collection = new(_pictureWidth, _pictureHeight);
|
||||
// string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
|
||||
// foreach (string elem in set)
|
||||
// {
|
||||
// Drawningboat? plane = elem?.CreateDrawningBoat(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||
// if (plane != null)
|
||||
// {
|
||||
// if (!(collection + plane))
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// _boatStorages.Add(record[0], collection);
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
|
||||
private static readonly char _separatorForKeyValue = '|';
|
||||
private readonly char _separatorRecords = ';';
|
||||
private static readonly char _separatorForObject = ':';
|
||||
|
||||
public bool SaveData(string filename)
|
||||
{
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
File.Delete(filename);
|
||||
}
|
||||
StringBuilder data = new();
|
||||
foreach (KeyValuePair<string, BoatsGenericCollection<Drawningboat, DrawningObjectBoat>> record in _boatStorages)
|
||||
{
|
||||
StringBuilder records = new();
|
||||
foreach (Drawningboat? 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($"PlaneStorage{Environment.NewLine}{data}");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
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("PlaneStorage"))
|
||||
{
|
||||
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<Drawningboat, DrawningObjectBoat> collection = new(_pictureWidth, _pictureHeight);
|
||||
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string elem in set)
|
||||
{
|
||||
Drawningboat? plane = elem?.CreateDrawningBoat(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||
if (plane != null)
|
||||
{
|
||||
if (!(collection + plane))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
_boatStorages.Add(record[0], collection);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user