This commit is contained in:
Камилия Сафиулова 2023-11-22 10:49:19 +04:00
parent 71b1caa094
commit c549fc6a3c
6 changed files with 112 additions and 62 deletions

View File

@ -150,6 +150,8 @@ namespace Catamaran.Generics
}
if (catamaran != null)
{
catamaran._pictureWidth = _pictureWidth;
catamaran._pictureHeight = _pictureHeight;
catamaran.SetPosition(i % width * _placeSizeWidth + _placeSizeWidth / 40,
(height - diff) * _placeSizeHeight + _placeSizeHeight / 15);
catamaran.DrawTransport(g);

View File

@ -99,7 +99,7 @@ namespace Catamaran.Generics
File.Delete(filename);
}
StringBuilder data = new();
foreach (KeyValuePair<string, CatamaransGenericCollection<DrawningCatamaran, DrawningObjectCatamaran>> record in _catamaranStorages)
foreach (KeyValuePair<string,CatamaransGenericCollection<DrawningCatamaran, DrawningObjectCatamaran>> record in _catamaranStorages)
{
StringBuilder records = new();
foreach (DrawningCatamaran? elem in record.Value.GetCatamarans)
@ -112,70 +112,64 @@ namespace Catamaran.Generics
{
return false;
}
using FileStream fs = new(filename, FileMode.Create);
byte[] info = new
UTF8Encoding(true).GetBytes($"CatamaranStorage{Environment.NewLine}{data}");
fs.Write(info, 0, info.Length);
using (StreamWriter writer = new StreamWriter(filename))
{
writer.Write($"CatamaranStorage{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;
}
string bufferTextFromFile = "";
using (FileStream fs = new(filename, FileMode.Open))
using (StreamReader fs = File.OpenText(filename))
{
byte[] b = new byte[fs.Length];
UTF8Encoding temp = new(true);
while (fs.Read(b, 0, b.Length) > 0)
string str = fs.ReadLine();
if (str == null || str.Length == 0)
{
bufferTextFromFile += temp.GetString(b);
return false;
}
}
var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' },
StringSplitOptions.RemoveEmptyEntries);
if (strs == null || strs.Length == 0)
{
return false;
}
if (!strs[0].StartsWith("CatamaranStorage"))
{
//если нет такой записи, то это не те данные
return false;
}
_catamaranStorages.Clear();
foreach (string data in strs)
{
string[] record = data.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
if (record.Length != 2)
if (!str.StartsWith("CatamaranStorage"))
{
continue;
return false;
}
CatamaransGenericCollection<DrawningCatamaran, DrawningObjectCatamaran>
collection = new(_pictureWidth, _pictureHeight);
string[] set = record[1].Split(_separatorRecords,
StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set)
_catamaranStorages.Clear();
string strs = "";
while ((strs = fs.ReadLine()) != null)
{
DrawningCatamaran? catamaran = elem?.CreateDrawningCatamaran(_separatorForObject, _pictureWidth, _pictureHeight);
if (catamaran != null)
if (strs == null)
{
if (!(collection + catamaran))
return false;
}
string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
if (record.Length != 2)
{
continue;
}
CatamaransGenericCollection<DrawningCatamaran, DrawningObjectCatamaran> collection = new(_pictureWidth, _pictureHeight);
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set)
{
DrawningCatamaran? catamaran = elem?.CreateDrawningCatamaran(_separatorForObject, _pictureWidth, _pictureHeight);
if (catamaran != null)
{
return false;
if (!(collection + catamaran))
{
return false;
}
}
}
_catamaranStorages.Add(record[0], collection);
}
_catamaranStorages.Add(record[0], collection);
return true;
}
return true;
}
}
}

View File

@ -20,11 +20,11 @@ namespace Catamaran.DrawningObjects
/// <summary>
/// Ширина окна
/// </summary>
private int _pictureWidth;
public int _pictureWidth;
/// <summary>
/// Высота окна
/// </summary>
private int _pictureHeight;
public int _pictureHeight;
/// <summary>
/// Левая координата прорисовки катамарана
/// </summary>

View File

@ -39,9 +39,16 @@
this.ButtonRefreshCollection = new System.Windows.Forms.Button();
this.ButtonRemoveCatamaran = new System.Windows.Forms.Button();
this.ButtonAddCatamaran = new System.Windows.Forms.Button();
this.menuStrip = new System.Windows.Forms.MenuStrip();
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.SaveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.LoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
this.groupBoxTools.SuspendLayout();
this.groupBoxSets.SuspendLayout();
this.menuStrip.SuspendLayout();
this.SuspendLayout();
//
// pictureBoxCollection
@ -59,6 +66,7 @@
this.groupBoxTools.Controls.Add(this.ButtonRefreshCollection);
this.groupBoxTools.Controls.Add(this.ButtonRemoveCatamaran);
this.groupBoxTools.Controls.Add(this.ButtonAddCatamaran);
this.groupBoxTools.Controls.Add(this.menuStrip);
this.groupBoxTools.Location = new System.Drawing.Point(739, 1);
this.groupBoxTools.Name = "groupBoxTools";
this.groupBoxTools.Size = new System.Drawing.Size(147, 460);
@ -72,23 +80,23 @@
this.groupBoxSets.Controls.Add(this.buttonDelObject);
this.groupBoxSets.Controls.Add(this.listBoxStorages);
this.groupBoxSets.Controls.Add(this.buttonAddObject);
this.groupBoxSets.Location = new System.Drawing.Point(3, 21);
this.groupBoxSets.Location = new System.Drawing.Point(3, 63);
this.groupBoxSets.Name = "groupBoxSets";
this.groupBoxSets.Size = new System.Drawing.Size(138, 245);
this.groupBoxSets.Size = new System.Drawing.Size(138, 203);
this.groupBoxSets.TabIndex = 4;
this.groupBoxSets.TabStop = false;
this.groupBoxSets.Text = "Наборы";
//
// textBoxStorageName
//
this.textBoxStorageName.Location = new System.Drawing.Point(3, 36);
this.textBoxStorageName.Location = new System.Drawing.Point(6, 22);
this.textBoxStorageName.Name = "textBoxStorageName";
this.textBoxStorageName.Size = new System.Drawing.Size(134, 23);
this.textBoxStorageName.Size = new System.Drawing.Size(130, 23);
this.textBoxStorageName.TabIndex = 4;
//
// buttonDelObject
//
this.buttonDelObject.Location = new System.Drawing.Point(3, 209);
this.buttonDelObject.Location = new System.Drawing.Point(3, 167);
this.buttonDelObject.Name = "buttonDelObject";
this.buttonDelObject.Size = new System.Drawing.Size(134, 27);
this.buttonDelObject.TabIndex = 3;
@ -100,17 +108,17 @@
//
this.listBoxStorages.FormattingEnabled = true;
this.listBoxStorages.ItemHeight = 15;
this.listBoxStorages.Location = new System.Drawing.Point(3, 102);
this.listBoxStorages.Location = new System.Drawing.Point(6, 82);
this.listBoxStorages.Name = "listBoxStorages";
this.listBoxStorages.Size = new System.Drawing.Size(134, 94);
this.listBoxStorages.Size = new System.Drawing.Size(132, 79);
this.listBoxStorages.TabIndex = 2;
this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.ListBoxObjects_SelectedIndexChanged);
//
// buttonAddObject
//
this.buttonAddObject.Location = new System.Drawing.Point(3, 65);
this.buttonAddObject.Location = new System.Drawing.Point(6, 51);
this.buttonAddObject.Name = "buttonAddObject";
this.buttonAddObject.Size = new System.Drawing.Size(134, 25);
this.buttonAddObject.Size = new System.Drawing.Size(131, 25);
this.buttonAddObject.TabIndex = 1;
this.buttonAddObject.Text = "Добавить набор";
this.buttonAddObject.UseVisualStyleBackColor = true;
@ -153,13 +161,51 @@
this.ButtonAddCatamaran.UseVisualStyleBackColor = true;
this.ButtonAddCatamaran.Click += new System.EventHandler(this.ButtonAddCatamaran_Click);
//
// menuStrip
//
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.ToolStripMenuItem});
this.menuStrip.Location = new System.Drawing.Point(3, 19);
this.menuStrip.Name = "menuStrip";
this.menuStrip.Size = new System.Drawing.Size(141, 24);
this.menuStrip.TabIndex = 5;
this.menuStrip.Text = "menuStrip";
//
// 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(48, 20);
this.ToolStripMenuItem.Text = "Файл";
//
// SaveToolStripMenuItem
//
this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
this.SaveToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.SaveToolStripMenuItem.Text = "Сохранение";
this.SaveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click);
//
// LoadToolStripMenuItem
//
this.LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
this.LoadToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.LoadToolStripMenuItem.Text = "Загрузка";
this.LoadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click);
//
// openFileDialog
//
this.openFileDialog.FileName = "openFileDialog1";
//
// FormCatamaranCollection
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(884, 461);
this.ClientSize = new System.Drawing.Size(885, 461);
this.Controls.Add(this.groupBoxTools);
this.Controls.Add(this.pictureBoxCollection);
this.MainMenuStrip = this.menuStrip;
this.Name = "FormCatamaranCollection";
this.Text = "Набор катамаранов";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
@ -167,6 +213,8 @@
this.groupBoxTools.PerformLayout();
this.groupBoxSets.ResumeLayout(false);
this.groupBoxSets.PerformLayout();
this.menuStrip.ResumeLayout(false);
this.menuStrip.PerformLayout();
this.ResumeLayout(false);
}
@ -184,5 +232,11 @@
private Button buttonDelObject;
private ListBox listBoxStorages;
private TextBox textBoxStorageName;
private MenuStrip menuStrip;
private ToolStripMenuItem ToolStripMenuItem;
private ToolStripMenuItem SaveToolStripMenuItem;
private ToolStripMenuItem LoadToolStripMenuItem;
private SaveFileDialog saveFileDialog;
private OpenFileDialog openFileDialog;
}
}

View File

@ -60,13 +60,13 @@
<metadata name="menuStrip.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">
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>125, 17</value>
</metadata>
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>258, 17</value>
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>254, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>154</value>
<value>96</value>
</metadata>
</root>

View File

@ -145,7 +145,7 @@
//
// panelYellow
//
this.panelYellow.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(128)))));
this.panelYellow.BackColor = System.Drawing.Color.Gold;
this.panelYellow.Location = new System.Drawing.Point(187, 29);
this.panelYellow.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.panelYellow.Name = "panelYellow";