Сделал лабораторную 6

This commit is contained in:
Никита Волков 2023-12-25 00:54:31 +04:00
parent 3a02eacd59
commit 9874caf690
2 changed files with 41 additions and 56 deletions

View File

@ -125,7 +125,6 @@
this.labelModifiedObject.TabIndex = 8; this.labelModifiedObject.TabIndex = 8;
this.labelModifiedObject.Text = "Продвинутый"; this.labelModifiedObject.Text = "Продвинутый";
this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelModifiedObject.MouseDown += labelObject_MouseDown;
// //
// labelSimpleObject // labelSimpleObject
// //
@ -138,7 +137,6 @@
this.labelSimpleObject.TabIndex = 7; this.labelSimpleObject.TabIndex = 7;
this.labelSimpleObject.Text = "Простой"; this.labelSimpleObject.Text = "Простой";
this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelSimpleObject.MouseDown += labelObject_MouseDown;
// //
// groupBoxColors // groupBoxColors
// //
@ -158,8 +156,6 @@
this.groupBoxColors.TabIndex = 6; this.groupBoxColors.TabIndex = 6;
this.groupBoxColors.TabStop = false; this.groupBoxColors.TabStop = false;
this.groupBoxColors.Text = "Цвета"; this.groupBoxColors.Text = "Цвета";
this.groupBoxColors.DragDrop += PanelObject_DragDrop;
this.groupBoxColors.DragEnter += PanelObject_DragEnter;
// //
// panelPurple // panelPurple
// //
@ -169,7 +165,6 @@
this.panelPurple.Name = "panelPurple"; this.panelPurple.Name = "panelPurple";
this.panelPurple.Size = new System.Drawing.Size(43, 43); this.panelPurple.Size = new System.Drawing.Size(43, 43);
this.panelPurple.TabIndex = 1; this.panelPurple.TabIndex = 1;
this.panelPurple.MouseDown += panelColor_MouseDown;
// //
// panelBlack // panelBlack
// //
@ -179,7 +174,6 @@
this.panelBlack.Name = "panelBlack"; this.panelBlack.Name = "panelBlack";
this.panelBlack.Size = new System.Drawing.Size(43, 43); this.panelBlack.Size = new System.Drawing.Size(43, 43);
this.panelBlack.TabIndex = 1; this.panelBlack.TabIndex = 1;
this.panelBlack.MouseDown += panelColor_MouseDown;
// //
// panelGray // panelGray
// //
@ -189,7 +183,6 @@
this.panelGray.Name = "panelGray"; this.panelGray.Name = "panelGray";
this.panelGray.Size = new System.Drawing.Size(43, 43); this.panelGray.Size = new System.Drawing.Size(43, 43);
this.panelGray.TabIndex = 1; this.panelGray.TabIndex = 1;
this.panelGray.MouseDown += panelColor_MouseDown;
// //
// panelWhite // panelWhite
// //
@ -199,7 +192,6 @@
this.panelWhite.Name = "panelWhite"; this.panelWhite.Name = "panelWhite";
this.panelWhite.Size = new System.Drawing.Size(43, 43); this.panelWhite.Size = new System.Drawing.Size(43, 43);
this.panelWhite.TabIndex = 1; this.panelWhite.TabIndex = 1;
this.panelWhite.MouseDown += panelColor_MouseDown;
// //
// panelYellow // panelYellow
// //
@ -209,7 +201,6 @@
this.panelYellow.Name = "panelYellow"; this.panelYellow.Name = "panelYellow";
this.panelYellow.Size = new System.Drawing.Size(43, 43); this.panelYellow.Size = new System.Drawing.Size(43, 43);
this.panelYellow.TabIndex = 1; this.panelYellow.TabIndex = 1;
this.panelYellow.MouseDown += panelColor_MouseDown;
// //
// panelBlue // panelBlue
// //
@ -219,17 +210,15 @@
this.panelBlue.Name = "panelBlue"; this.panelBlue.Name = "panelBlue";
this.panelBlue.Size = new System.Drawing.Size(43, 43); this.panelBlue.Size = new System.Drawing.Size(43, 43);
this.panelBlue.TabIndex = 1; this.panelBlue.TabIndex = 1;
this.panelBlue.MouseDown += panelColor_MouseDown;
// //
// panelGreen // panelGreen
// //
this.panelGreen.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(0))))); this.panelGreen.BackColor = System.Drawing.Color.Green;
this.panelGreen.Location = new System.Drawing.Point(77, 34); this.panelGreen.Location = new System.Drawing.Point(77, 34);
this.panelGreen.Margin = new System.Windows.Forms.Padding(2); this.panelGreen.Margin = new System.Windows.Forms.Padding(2);
this.panelGreen.Name = "panelGreen"; this.panelGreen.Name = "panelGreen";
this.panelGreen.Size = new System.Drawing.Size(43, 43); this.panelGreen.Size = new System.Drawing.Size(43, 43);
this.panelGreen.TabIndex = 1; this.panelGreen.TabIndex = 1;
this.panelGreen.MouseDown += panelColor_MouseDown;
// //
// panelRed // panelRed
// //
@ -239,7 +228,6 @@
this.panelRed.Name = "panelRed"; this.panelRed.Name = "panelRed";
this.panelRed.Size = new System.Drawing.Size(43, 43); this.panelRed.Size = new System.Drawing.Size(43, 43);
this.panelRed.TabIndex = 0; this.panelRed.TabIndex = 0;
this.panelRed.MouseDown += panelColor_MouseDown;
// //
// numericUpDownWeight // numericUpDownWeight
// //
@ -327,8 +315,6 @@
this.panelObject.Name = "panelObject"; this.panelObject.Name = "panelObject";
this.panelObject.Size = new System.Drawing.Size(334, 202); this.panelObject.Size = new System.Drawing.Size(334, 202);
this.panelObject.TabIndex = 2; this.panelObject.TabIndex = 2;
this. panelObject.DragDrop += PanelObject_DragDrop;
panelObject.DragEnter += PanelObject_DragEnter;
// //
// labelAddColor // labelAddColor
// //
@ -341,8 +327,6 @@
this.labelAddColor.TabIndex = 3; this.labelAddColor.TabIndex = 3;
this.labelAddColor.Text = "Дополн. цвет"; this.labelAddColor.Text = "Дополн. цвет";
this.labelAddColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.labelAddColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelAddColor.DragDrop += labelColor_dragDrop;
this.labelAddColor.DragEnter += labelColor_dragEnter;
// //
// labelColor // labelColor
// //
@ -355,8 +339,6 @@
this.labelColor.TabIndex = 2; this.labelColor.TabIndex = 2;
this.labelColor.Text = "Основной цвет"; this.labelColor.Text = "Основной цвет";
this.labelColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.labelColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelColor.DragDrop += labelColor_dragDrop;
this.labelColor.DragEnter += labelColor_dragEnter;
// //
// buttonAdd // buttonAdd
// //
@ -367,7 +349,6 @@
this.buttonAdd.TabIndex = 3; this.buttonAdd.TabIndex = 3;
this.buttonAdd.Text = "Добавить"; this.buttonAdd.Text = "Добавить";
this.buttonAdd.UseVisualStyleBackColor = true; this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += buttonAdd_Click;
// //
// buttonCancel // buttonCancel
// //

View File

@ -67,7 +67,7 @@ namespace Bulldozer.Generics
/// </summary> /// </summary>
/// <param name="ind"></param> /// <param name="ind"></param>
/// <returns></returns> /// <returns></returns>
public BulldozersGenericCollection<DrawingBulldozer, DrawingObjectBulldozer> ? this[string ind] public BulldozersGenericCollection<DrawingBulldozer, DrawingObjectBulldozer>? this[string ind]
{ {
get get
{ {
@ -118,9 +118,15 @@ namespace Bulldozer.Generics
{ {
return false; return false;
} }
using FileStream fs = new(filename, FileMode.Create); string toWrite = $"BulldozerStorage{Environment.NewLine}{data}";
byte[] info = new UTF8Encoding(true).GetBytes($"BulldozerStorage{Environment.NewLine}{data}"); var strs = toWrite.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
fs.Write(info, 0, info.Length); using (StreamWriter sw = new(filename))
{
foreach (var str in strs)
{
sw.WriteLine(str);
}
}
return true; return true;
} }
@ -135,50 +141,48 @@ namespace Bulldozer.Generics
{ {
return false; return false;
} }
string bufferTextFromFile = ""; using (StreamReader sr = new(filename))
using (FileStream fs = new(filename, FileMode.Open))
{ {
byte[] b = new byte[fs.Length]; string str = sr.ReadLine();
UTF8Encoding temp = new(true); var strs = str.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
while (fs.Read(b, 0, b.Length) > 0) if (strs == null || strs.Length == 0)
{ {
bufferTextFromFile += temp.GetString(b); return false;
} }
} if (!strs[0].StartsWith("BulldozerStorage"))
var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
if (strs == null || strs.Length == 0)
{
return false;
}
if (!strs[0].StartsWith("BulldozerStorage"))
{
return false;
}
_bulldozerStorages.Clear();
foreach (string data in strs)
{
string[] record = data.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
if (record.Length != 2)
{ {
continue; return false;
} }
BulldozersGenericCollection<DrawingBulldozer, DrawingObjectBulldozer> collection = new(_pictureWidth, _pictureHeight); _bulldozerStorages.Clear();
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries); do
foreach (string elem in set)
{ {
DrawingBulldozer? bulldozer = elem?.CreateDrawingBulldozer(_separatorForObject, _pictureWidth, _pictureHeight); string[] record = str.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
if (bulldozer != null) if (record.Length != 2)
{ {
if ((collection + bulldozer) == -1) str = sr.ReadLine();
continue;
}
BulldozersGenericCollection<DrawingBulldozer, DrawingObjectBulldozer> collection = new(_pictureWidth, _pictureHeight);
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set)
{
DrawingBulldozer? bulldozer =
elem?.CreateDrawingBulldozer(_separatorForObject, _pictureWidth, _pictureHeight);
if (bulldozer != null)
{ {
return false; if ((collection + bulldozer) == -1)
{
return false;
}
} }
} }
} _bulldozerStorages.Add(record[0], collection);
_bulldozerStorages.Add(record[0], collection);
str = sr.ReadLine();
} while (str != null);
} }
return true; return true;
} }
} }
} }