lab6 #6
@ -0,0 +1,61 @@
|
||||
using SelfPropelledArtilleryUnit.Entities;
|
||||
namespace SelfPropelledArtilleryUnit.DrawningObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Расширение для класса EntityUsta
|
||||
/// </summary>
|
||||
public static class ExtentionDrawningUsta
|
||||
{
|
||||
/// <summary>
|
||||
/// Создание объекта из строки
|
||||
/// </summary>
|
||||
/// <param name="info">Строка с данными для создания объекта</param>
|
||||
/// <param name="separatorForObject">Разделитель даннных</param>
|
||||
/// <param name="width">Ширина</param>
|
||||
/// <param name="height">Высота</param>
|
||||
/// <returns>Объект</returns>
|
||||
public static DrawningUsta? CreateDrawningUsta(this string info, char
|
||||
separatorForObject, int width, int height)
|
||||
{
|
||||
string[] strs = info.Split(separatorForObject);
|
||||
if (strs.Length == 3)
|
||||
{
|
||||
return new DrawningUsta(Convert.ToInt32(strs[0]),
|
||||
Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height);
|
||||
}
|
||||
else if (strs.Length == 6)
|
||||
{
|
||||
return new DrawningUstaBat(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="drawningUsta">Сохраняемый объект</param>
|
||||
/// <param name="separatorForObject">Разделитель даннных</param>
|
||||
/// <returns>Строка с данными по объекту</returns>
|
||||
public static string GetDataForSave(this DrawningUsta drawningUsta,
|
||||
char separatorForUsta)
|
||||
{
|
||||
var usta = drawningUsta.EntityUsta;
|
||||
if (usta == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
var str =
|
||||
$"{usta.Speed}{separatorForUsta}{usta.Weight}{separatorForUsta}{usta.BodyColor.Name}";
|
||||
if (usta is not EntityUstaBat sportUsta)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
return $"{str}{separatorForUsta}{sportUsta.AdditionalColor.Name}{separatorForUsta}{sportUsta.BodyKit}{separatorForUsta}{sportUsta.Pushka}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,14 +39,21 @@
|
||||
ButtonDelObject = new Button();
|
||||
ButtonAddObject = new Button();
|
||||
textBoxStorageName = new TextBox();
|
||||
menuStrip = new MenuStrip();
|
||||
fileToolStripMenuItem = new ToolStripMenuItem();
|
||||
SaveToolStripMenuItem = new ToolStripMenuItem();
|
||||
LoadToolStripMenuItem = new ToolStripMenuItem();
|
||||
openFileDialog = new OpenFileDialog();
|
||||
saveFileDialog = new SaveFileDialog();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||
groupBox1.SuspendLayout();
|
||||
groupBox2.SuspendLayout();
|
||||
menuStrip.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// ButtonAddUsta
|
||||
//
|
||||
ButtonAddUsta.Location = new Point(26, 314);
|
||||
ButtonAddUsta.Location = new Point(26, 366);
|
||||
ButtonAddUsta.Name = "ButtonAddUsta";
|
||||
ButtonAddUsta.Size = new Size(166, 40);
|
||||
ButtonAddUsta.TabIndex = 0;
|
||||
@ -56,7 +63,7 @@
|
||||
//
|
||||
// ButtonRemoveUsta
|
||||
//
|
||||
ButtonRemoveUsta.Location = new Point(26, 400);
|
||||
ButtonRemoveUsta.Location = new Point(26, 457);
|
||||
ButtonRemoveUsta.Name = "ButtonRemoveUsta";
|
||||
ButtonRemoveUsta.Size = new Size(166, 39);
|
||||
ButtonRemoveUsta.TabIndex = 1;
|
||||
@ -66,7 +73,7 @@
|
||||
//
|
||||
// ButtonRefreshCollection
|
||||
//
|
||||
ButtonRefreshCollection.Location = new Point(26, 478);
|
||||
ButtonRefreshCollection.Location = new Point(26, 502);
|
||||
ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||
ButtonRefreshCollection.Size = new Size(166, 40);
|
||||
ButtonRefreshCollection.TabIndex = 2;
|
||||
@ -86,7 +93,7 @@
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
maskedTextBoxNumber.Font = new Font("Showcard Gothic", 9F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
maskedTextBoxNumber.Location = new Point(56, 371);
|
||||
maskedTextBoxNumber.Location = new Point(58, 429);
|
||||
maskedTextBoxNumber.Mask = "00";
|
||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
maskedTextBoxNumber.Size = new Size(100, 22);
|
||||
@ -100,9 +107,10 @@
|
||||
groupBox1.Controls.Add(ButtonRefreshCollection);
|
||||
groupBox1.Controls.Add(maskedTextBoxNumber);
|
||||
groupBox1.Controls.Add(ButtonRemoveUsta);
|
||||
groupBox1.Controls.Add(menuStrip);
|
||||
groupBox1.Location = new Point(643, 12);
|
||||
groupBox1.Name = "groupBox1";
|
||||
groupBox1.Size = new Size(209, 533);
|
||||
groupBox1.Size = new Size(209, 560);
|
||||
groupBox1.TabIndex = 5;
|
||||
groupBox1.TabStop = false;
|
||||
groupBox1.Text = "Инструменты";
|
||||
@ -113,7 +121,7 @@
|
||||
groupBox2.Controls.Add(ButtonDelObject);
|
||||
groupBox2.Controls.Add(ButtonAddObject);
|
||||
groupBox2.Controls.Add(textBoxStorageName);
|
||||
groupBox2.Location = new Point(6, 22);
|
||||
groupBox2.Location = new Point(6, 64);
|
||||
groupBox2.Name = "groupBox2";
|
||||
groupBox2.Size = new Size(197, 274);
|
||||
groupBox2.TabIndex = 6;
|
||||
@ -157,6 +165,47 @@
|
||||
textBoxStorageName.Size = new Size(158, 23);
|
||||
textBoxStorageName.TabIndex = 0;
|
||||
//
|
||||
// menuStrip
|
||||
//
|
||||
menuStrip.Items.AddRange(new ToolStripItem[] { fileToolStripMenuItem });
|
||||
menuStrip.Location = new Point(3, 19);
|
||||
menuStrip.Name = "menuStrip";
|
||||
menuStrip.Size = new Size(203, 24);
|
||||
menuStrip.TabIndex = 7;
|
||||
menuStrip.Text = "menuStrip1";
|
||||
//
|
||||
// fileToolStripMenuItem
|
||||
//
|
||||
fileToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { SaveToolStripMenuItem, LoadToolStripMenuItem });
|
||||
fileToolStripMenuItem.Name = "fileToolStripMenuItem";
|
||||
fileToolStripMenuItem.Size = new Size(48, 20);
|
||||
fileToolStripMenuItem.Text = "Файл";
|
||||
//
|
||||
// SaveToolStripMenuItem
|
||||
//
|
||||
SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
|
||||
SaveToolStripMenuItem.Size = new Size(180, 22);
|
||||
SaveToolStripMenuItem.Text = "Сохранение";
|
||||
SaveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
|
||||
//
|
||||
// LoadToolStripMenuItem
|
||||
//
|
||||
LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
|
||||
LoadToolStripMenuItem.Size = new Size(180, 22);
|
||||
LoadToolStripMenuItem.Text = "Загрузка";
|
||||
LoadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
|
||||
//
|
||||
// openFileDialog
|
||||
//
|
||||
openFileDialog.FileName = "openFileDialog1";
|
||||
openFileDialog.Filter = "txt file | *.txt";
|
||||
openFileDialog.Title = "Сохранить текстовый файл";
|
||||
//
|
||||
// saveFileDialog
|
||||
//
|
||||
saveFileDialog.Filter = "txt file | *.txt";
|
||||
saveFileDialog.Title = "Выберите текстовый файл";
|
||||
//
|
||||
// FormSelfPropelledArtilleryUnitCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
@ -164,6 +213,7 @@
|
||||
ClientSize = new Size(867, 584);
|
||||
Controls.Add(groupBox1);
|
||||
Controls.Add(pictureBoxCollection);
|
||||
MainMenuStrip = menuStrip;
|
||||
Name = "FormSelfPropelledArtilleryUnitCollection";
|
||||
Text = "Набор арт. установок";
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||
@ -171,6 +221,8 @@
|
||||
groupBox1.PerformLayout();
|
||||
groupBox2.ResumeLayout(false);
|
||||
groupBox2.PerformLayout();
|
||||
menuStrip.ResumeLayout(false);
|
||||
menuStrip.PerformLayout();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
@ -187,5 +239,11 @@
|
||||
private ListBox listBoxStorage;
|
||||
private Button ButtonDelObject;
|
||||
private Button ButtonAddObject;
|
||||
private MenuStrip menuStrip;
|
||||
private ToolStripMenuItem fileToolStripMenuItem;
|
||||
private ToolStripMenuItem SaveToolStripMenuItem;
|
||||
private ToolStripMenuItem LoadToolStripMenuItem;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
}
|
||||
}
|
@ -131,7 +131,7 @@ namespace SelfPropelledArtilleryUnit
|
||||
formSelfPropelledArtilleryUnitConfig.Show();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора
|
||||
/// </summary>
|
||||
@ -185,6 +185,50 @@ namespace SelfPropelledArtilleryUnit
|
||||
}
|
||||
pictureBoxCollection.Image = obj.ShowUsta();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия "Сохранение"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Обработка нажатия "Загрузка"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_storage.LoadData(openFileDialog.FileName))
|
||||
{
|
||||
MessageBox.Show("Данные успешно загружены.", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
ReloadObjects();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Ошибка при загрузке данных.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>126, 17</value>
|
||||
</metadata>
|
||||
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>259, 17</value>
|
||||
</metadata>
|
||||
</root>
|
@ -71,11 +71,9 @@
|
||||
groupBox1.Controls.Add(numericUpDownSpeed);
|
||||
groupBox1.Controls.Add(label2);
|
||||
groupBox1.Controls.Add(label1);
|
||||
groupBox1.Location = new Point(14, 16);
|
||||
groupBox1.Margin = new Padding(3, 4, 3, 4);
|
||||
groupBox1.Location = new Point(12, 12);
|
||||
groupBox1.Name = "groupBox1";
|
||||
groupBox1.Padding = new Padding(3, 4, 3, 4);
|
||||
groupBox1.Size = new Size(519, 304);
|
||||
groupBox1.Size = new Size(454, 228);
|
||||
groupBox1.TabIndex = 0;
|
||||
groupBox1.TabStop = false;
|
||||
groupBox1.Text = "Параметры";
|
||||
@ -83,9 +81,9 @@
|
||||
// labelModifiedObject
|
||||
//
|
||||
labelModifiedObject.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelModifiedObject.Location = new Point(358, 195);
|
||||
labelModifiedObject.Location = new Point(313, 146);
|
||||
labelModifiedObject.Name = "labelModifiedObject";
|
||||
labelModifiedObject.Size = new Size(99, 35);
|
||||
labelModifiedObject.Size = new Size(87, 27);
|
||||
labelModifiedObject.TabIndex = 8;
|
||||
labelModifiedObject.Text = "Продвинутый";
|
||||
labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter;
|
||||
@ -94,9 +92,9 @@
|
||||
// labelSimpleObject
|
||||
//
|
||||
labelSimpleObject.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelSimpleObject.Location = new Point(246, 195);
|
||||
labelSimpleObject.Location = new Point(215, 146);
|
||||
labelSimpleObject.Name = "labelSimpleObject";
|
||||
labelSimpleObject.Size = new Size(99, 35);
|
||||
labelSimpleObject.Size = new Size(87, 27);
|
||||
labelSimpleObject.TabIndex = 7;
|
||||
labelSimpleObject.Text = "Простой";
|
||||
labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter;
|
||||
@ -112,102 +110,91 @@
|
||||
groupBox2.Controls.Add(panelGreen);
|
||||
groupBox2.Controls.Add(panelWhite);
|
||||
groupBox2.Controls.Add(panelRed);
|
||||
groupBox2.Location = new Point(246, 43);
|
||||
groupBox2.Margin = new Padding(3, 4, 3, 4);
|
||||
groupBox2.Location = new Point(215, 32);
|
||||
groupBox2.Name = "groupBox2";
|
||||
groupBox2.Padding = new Padding(3, 4, 3, 4);
|
||||
groupBox2.Size = new Size(211, 141);
|
||||
groupBox2.Size = new Size(185, 106);
|
||||
groupBox2.TabIndex = 6;
|
||||
groupBox2.TabStop = false;
|
||||
groupBox2.Text = "Цвета";
|
||||
//
|
||||
// panelPurple
|
||||
//
|
||||
panelPurple.BackColor = Color.FromArgb(192, 0, 192);
|
||||
panelPurple.Location = new Point(159, 84);
|
||||
panelPurple.Margin = new Padding(3, 4, 3, 4);
|
||||
panelPurple.BackColor = Color.Purple;
|
||||
panelPurple.Location = new Point(139, 63);
|
||||
panelPurple.Name = "panelPurple";
|
||||
panelPurple.Size = new Size(40, 40);
|
||||
panelPurple.Size = new Size(35, 30);
|
||||
panelPurple.TabIndex = 7;
|
||||
panelPurple.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// panelYellow
|
||||
//
|
||||
panelYellow.BackColor = Color.Yellow;
|
||||
panelYellow.Location = new Point(159, 29);
|
||||
panelYellow.Margin = new Padding(3, 4, 3, 4);
|
||||
panelYellow.Location = new Point(139, 22);
|
||||
panelYellow.Name = "panelYellow";
|
||||
panelYellow.Size = new Size(40, 40);
|
||||
panelYellow.Size = new Size(35, 30);
|
||||
panelYellow.TabIndex = 3;
|
||||
panelYellow.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// panelBlack
|
||||
//
|
||||
panelBlack.BackColor = Color.Black;
|
||||
panelBlack.Location = new Point(112, 84);
|
||||
panelBlack.Margin = new Padding(3, 4, 3, 4);
|
||||
panelBlack.Location = new Point(98, 63);
|
||||
panelBlack.Name = "panelBlack";
|
||||
panelBlack.Size = new Size(40, 40);
|
||||
panelBlack.Size = new Size(35, 30);
|
||||
panelBlack.TabIndex = 6;
|
||||
panelBlack.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// panelBlue
|
||||
//
|
||||
panelBlue.BackColor = Color.Blue;
|
||||
panelBlue.Location = new Point(112, 29);
|
||||
panelBlue.Margin = new Padding(3, 4, 3, 4);
|
||||
panelBlue.Location = new Point(98, 22);
|
||||
panelBlue.Name = "panelBlue";
|
||||
panelBlue.Size = new Size(40, 40);
|
||||
panelBlue.Size = new Size(35, 30);
|
||||
panelBlue.TabIndex = 2;
|
||||
panelBlue.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// panelGray
|
||||
//
|
||||
panelGray.BackColor = Color.Gray;
|
||||
panelGray.Location = new Point(65, 84);
|
||||
panelGray.Margin = new Padding(3, 4, 3, 4);
|
||||
panelGray.Location = new Point(57, 63);
|
||||
panelGray.Name = "panelGray";
|
||||
panelGray.Size = new Size(40, 40);
|
||||
panelGray.Size = new Size(35, 30);
|
||||
panelGray.TabIndex = 5;
|
||||
panelGray.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// panelGreen
|
||||
//
|
||||
panelGreen.BackColor = Color.FromArgb(0, 192, 0);
|
||||
panelGreen.Location = new Point(65, 29);
|
||||
panelGreen.Margin = new Padding(3, 4, 3, 4);
|
||||
panelGreen.BackColor = Color.Green;
|
||||
panelGreen.Location = new Point(57, 22);
|
||||
panelGreen.Name = "panelGreen";
|
||||
panelGreen.Size = new Size(40, 40);
|
||||
panelGreen.Size = new Size(35, 30);
|
||||
panelGreen.TabIndex = 1;
|
||||
panelGreen.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// panelWhite
|
||||
//
|
||||
panelWhite.BackColor = Color.White;
|
||||
panelWhite.Location = new Point(18, 84);
|
||||
panelWhite.Margin = new Padding(3, 4, 3, 4);
|
||||
panelWhite.Location = new Point(16, 63);
|
||||
panelWhite.Name = "panelWhite";
|
||||
panelWhite.Size = new Size(40, 40);
|
||||
panelWhite.Size = new Size(35, 30);
|
||||
panelWhite.TabIndex = 4;
|
||||
panelWhite.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// panelRed
|
||||
//
|
||||
panelRed.BackColor = Color.Red;
|
||||
panelRed.Location = new Point(18, 29);
|
||||
panelRed.Margin = new Padding(3, 4, 3, 4);
|
||||
panelRed.Location = new Point(16, 22);
|
||||
panelRed.Name = "panelRed";
|
||||
panelRed.Size = new Size(40, 40);
|
||||
panelRed.Size = new Size(35, 30);
|
||||
panelRed.TabIndex = 0;
|
||||
panelRed.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// checkBoxBodyKit
|
||||
//
|
||||
checkBoxBodyKit.AutoSize = true;
|
||||
checkBoxBodyKit.Location = new Point(11, 205);
|
||||
checkBoxBodyKit.Margin = new Padding(3, 4, 3, 4);
|
||||
checkBoxBodyKit.Location = new Point(10, 154);
|
||||
checkBoxBodyKit.Name = "checkBoxBodyKit";
|
||||
checkBoxBodyKit.Size = new Size(215, 24);
|
||||
checkBoxBodyKit.Size = new Size(170, 19);
|
||||
checkBoxBodyKit.TabIndex = 5;
|
||||
checkBoxBodyKit.Text = "Признак наличия батареи";
|
||||
checkBoxBodyKit.UseVisualStyleBackColor = true;
|
||||
@ -215,47 +202,44 @@
|
||||
// checkBoxPushka
|
||||
//
|
||||
checkBoxPushka.AutoSize = true;
|
||||
checkBoxPushka.Location = new Point(11, 159);
|
||||
checkBoxPushka.Margin = new Padding(3, 4, 3, 4);
|
||||
checkBoxPushka.Location = new Point(10, 119);
|
||||
checkBoxPushka.Name = "checkBoxPushka";
|
||||
checkBoxPushka.Size = new Size(202, 24);
|
||||
checkBoxPushka.Size = new Size(163, 19);
|
||||
checkBoxPushka.TabIndex = 4;
|
||||
checkBoxPushka.Text = "Признак наличия пушки";
|
||||
checkBoxPushka.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// numericUpDownWeight
|
||||
//
|
||||
numericUpDownWeight.Location = new Point(87, 80);
|
||||
numericUpDownWeight.Margin = new Padding(3, 4, 3, 4);
|
||||
numericUpDownWeight.Location = new Point(76, 60);
|
||||
numericUpDownWeight.Name = "numericUpDownWeight";
|
||||
numericUpDownWeight.Size = new Size(83, 27);
|
||||
numericUpDownWeight.Size = new Size(73, 23);
|
||||
numericUpDownWeight.TabIndex = 3;
|
||||
numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
//
|
||||
// numericUpDownSpeed
|
||||
//
|
||||
numericUpDownSpeed.Location = new Point(87, 41);
|
||||
numericUpDownSpeed.Margin = new Padding(3, 4, 3, 4);
|
||||
numericUpDownSpeed.Location = new Point(76, 31);
|
||||
numericUpDownSpeed.Name = "numericUpDownSpeed";
|
||||
numericUpDownSpeed.Size = new Size(83, 27);
|
||||
numericUpDownSpeed.Size = new Size(73, 23);
|
||||
numericUpDownSpeed.TabIndex = 2;
|
||||
numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
//
|
||||
// label2
|
||||
//
|
||||
label2.AutoSize = true;
|
||||
label2.Location = new Point(11, 83);
|
||||
label2.Location = new Point(10, 62);
|
||||
label2.Name = "label2";
|
||||
label2.Size = new Size(36, 20);
|
||||
label2.Size = new Size(29, 15);
|
||||
label2.TabIndex = 1;
|
||||
label2.Text = "Вес:";
|
||||
//
|
||||
// label1
|
||||
//
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new Point(11, 44);
|
||||
label1.Location = new Point(10, 33);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(76, 20);
|
||||
label1.Size = new Size(62, 15);
|
||||
label1.TabIndex = 0;
|
||||
label1.Text = "Скорость:";
|
||||
//
|
||||
@ -265,10 +249,9 @@
|
||||
panelColor.Controls.Add(labelDopColor);
|
||||
panelColor.Controls.Add(labelBaseColor);
|
||||
panelColor.Controls.Add(pictureBoxObject);
|
||||
panelColor.Location = new Point(539, 16);
|
||||
panelColor.Margin = new Padding(3, 4, 3, 4);
|
||||
panelColor.Location = new Point(472, 12);
|
||||
panelColor.Name = "panelColor";
|
||||
panelColor.Size = new Size(315, 245);
|
||||
panelColor.Size = new Size(276, 184);
|
||||
panelColor.TabIndex = 1;
|
||||
panelColor.DragDrop += PanelObject_DragDrop;
|
||||
panelColor.DragEnter += PanelObject_DragEnter;
|
||||
@ -277,9 +260,9 @@
|
||||
//
|
||||
labelDopColor.AllowDrop = true;
|
||||
labelDopColor.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelDopColor.Location = new Point(187, 13);
|
||||
labelDopColor.Location = new Point(164, 10);
|
||||
labelDopColor.Name = "labelDopColor";
|
||||
labelDopColor.Size = new Size(114, 38);
|
||||
labelDopColor.Size = new Size(100, 29);
|
||||
labelDopColor.TabIndex = 2;
|
||||
labelDopColor.Text = "Доп. цвет";
|
||||
labelDopColor.TextAlign = ContentAlignment.MiddleCenter;
|
||||
@ -291,9 +274,9 @@
|
||||
//
|
||||
labelBaseColor.AllowDrop = true;
|
||||
labelBaseColor.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelBaseColor.Location = new Point(14, 13);
|
||||
labelBaseColor.Location = new Point(12, 10);
|
||||
labelBaseColor.Name = "labelBaseColor";
|
||||
labelBaseColor.Size = new Size(114, 38);
|
||||
labelBaseColor.Size = new Size(100, 29);
|
||||
labelBaseColor.TabIndex = 2;
|
||||
labelBaseColor.Text = "Цвет";
|
||||
labelBaseColor.TextAlign = ContentAlignment.MiddleCenter;
|
||||
@ -303,19 +286,17 @@
|
||||
//
|
||||
// pictureBoxObject
|
||||
//
|
||||
pictureBoxObject.Location = new Point(14, 61);
|
||||
pictureBoxObject.Margin = new Padding(3, 4, 3, 4);
|
||||
pictureBoxObject.Location = new Point(12, 46);
|
||||
pictureBoxObject.Name = "pictureBoxObject";
|
||||
pictureBoxObject.Size = new Size(288, 169);
|
||||
pictureBoxObject.Size = new Size(252, 127);
|
||||
pictureBoxObject.TabIndex = 0;
|
||||
pictureBoxObject.TabStop = false;
|
||||
//
|
||||
// ButtonOk
|
||||
//
|
||||
ButtonOk.Location = new Point(553, 277);
|
||||
ButtonOk.Margin = new Padding(3, 4, 3, 4);
|
||||
ButtonOk.Location = new Point(484, 208);
|
||||
ButtonOk.Name = "ButtonOk";
|
||||
ButtonOk.Size = new Size(114, 43);
|
||||
ButtonOk.Size = new Size(100, 32);
|
||||
ButtonOk.TabIndex = 2;
|
||||
ButtonOk.Text = "Добавить";
|
||||
ButtonOk.UseVisualStyleBackColor = true;
|
||||
@ -323,24 +304,22 @@
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Location = new Point(727, 277);
|
||||
buttonCancel.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonCancel.Location = new Point(636, 208);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(114, 43);
|
||||
buttonCancel.Size = new Size(100, 32);
|
||||
buttonCancel.TabIndex = 3;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// FormSelfPropelledArtilleryUnitConfig
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(914, 336);
|
||||
ClientSize = new Size(800, 252);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(ButtonOk);
|
||||
Controls.Add(panelColor);
|
||||
Controls.Add(groupBox1);
|
||||
Margin = new Padding(3, 4, 3, 4);
|
||||
Name = "FormSelfPropelledArtilleryUnitConfig";
|
||||
Text = "FormSelfPropelledArtilleryUnitConfig";
|
||||
groupBox1.ResumeLayout(false);
|
||||
|
@ -24,9 +24,6 @@ namespace SelfPropelledArtilleryUnit.MovementStrategy
|
||||
objParams.DownBorder + GetStep() >= FieldHeight;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
@ -45,9 +42,6 @@ namespace SelfPropelledArtilleryUnit.MovementStrategy
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,11 @@ namespace SelfPropelledArtilleryUnit.Generics
|
||||
where T : DrawningUsta
|
||||
where U : IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение объектов коллекции
|
||||
/// </summary>
|
||||
public IEnumerable<T?> GetUsta => _collection.GetUsta();
|
||||
|
||||
/// <summary>
|
||||
/// Ширина окна прорисовки
|
||||
/// </summary>
|
||||
|
@ -1,8 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using SelfPropelledArtilleryUnit.Drawnings;
|
||||
using SelfPropelledArtilleryUnit.MovementStrategy;
|
||||
@ -30,6 +29,18 @@ namespace SelfPropelledArtilleryUnit.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>
|
||||
@ -81,7 +92,98 @@ namespace SelfPropelledArtilleryUnit.Generics
|
||||
return _ustaStorages[ind];
|
||||
}
|
||||
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, UstaGenericCollection<DrawningUsta, DrawningObjectUsta>> record in _ustaStorages)
|
||||
{
|
||||
StringBuilder records = new();
|
||||
foreach (DrawningUsta? elem in record.Value.GetUsta)
|
||||
{
|
||||
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($"UstaStorage{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 reader = new StreamReader(filename))
|
||||
{
|
||||
string cheker = reader.ReadLine();
|
||||
if (cheker == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!cheker.StartsWith("UstaStorage"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_ustaStorages.Clear();
|
||||
string strs;
|
||||
bool firstinit = true;
|
||||
while ((strs = reader.ReadLine()) != null)
|
||||
{
|
||||
if (strs == null && firstinit)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (strs == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
firstinit = false;
|
||||
string name = strs.Split(_separatorForKeyValue)[0];
|
||||
UstaGenericCollection<DrawningUsta, DrawningObjectUsta> collection = new(_pictureWidth, _pictureHeight);
|
||||
foreach (string data in strs.Split(_separatorForKeyValue)[1].Split(_separatorRecords))
|
||||
{
|
||||
DrawningUsta? usta =
|
||||
data?.CreateDrawningUsta(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||
if (usta != null)
|
||||
{
|
||||
int? result = collection + usta;
|
||||
if (result == null || result.Value == -1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
_ustaStorages.Add(name, collection);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user