diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/ExtentionDrawningTractor.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/ExtentionDrawningTractor.cs index 7b66eb8..9e10ba1 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/ExtentionDrawningTractor.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/ExtentionDrawningTractor.cs @@ -59,8 +59,8 @@ namespace ProjectTractor.DrawningObjects { return str; } - return - $"{str}{separatorForObject}{bulldoser.AdditionalColor.Name}{separatorForObject}{bulldoser.WheelsOrnament}{separatorForObject}{bulldoser.Blade}"; + str = $"{str}{separatorForObject}{bulldoser.AdditionalColor.Name}{separatorForObject}{bulldoser.WheelsOrnament}{separatorForObject}{bulldoser.Blade}"; + return str; } } } diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs index 8ae0e7d..2a60f57 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs @@ -261,7 +261,7 @@ namespace ProjectTractor this.pictureBoxCollection.Dock = System.Windows.Forms.DockStyle.Left; this.pictureBoxCollection.Location = new System.Drawing.Point(0, 0); this.pictureBoxCollection.Name = "pictureBoxCollection"; - this.pictureBoxCollection.Size = new System.Drawing.Size(620, 532); + this.pictureBoxCollection.Size = new System.Drawing.Size(643, 532); this.pictureBoxCollection.TabIndex = 1; this.pictureBoxCollection.TabStop = false; // @@ -273,7 +273,7 @@ namespace ProjectTractor this.groupBox.Controls.Add(this.ButtonAddTractor); this.groupBox.Controls.Add(this.maskedTextBoxNumber); this.groupBox.Controls.Add(this.file); - this.groupBox.Location = new System.Drawing.Point(626, 12); + this.groupBox.Location = new System.Drawing.Point(649, 12); this.groupBox.Name = "groupBox"; this.groupBox.Size = new System.Drawing.Size(255, 524); this.groupBox.TabIndex = 2; @@ -404,7 +404,7 @@ namespace ProjectTractor // // FormTractorCollection // - this.ClientSize = new System.Drawing.Size(893, 532); + this.ClientSize = new System.Drawing.Size(916, 532); this.Controls.Add(this.groupBox); this.Controls.Add(this.pictureBoxCollection); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorConfig.Designer.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorConfig.Designer.cs index 31df060..14a18a5 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorConfig.Designer.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorConfig.Designer.cs @@ -166,7 +166,7 @@ // panelBlue // this.panelBlue.AllowDrop = true; - this.panelBlue.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(192))))); + this.panelBlue.BackColor = System.Drawing.Color.Blue; this.panelBlue.Location = new System.Drawing.Point(98, 23); this.panelBlue.Name = "panelBlue"; this.panelBlue.Size = new System.Drawing.Size(40, 40); @@ -188,7 +188,7 @@ // panelGreen // this.panelGreen.AllowDrop = true; - 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(52, 23); this.panelGreen.Name = "panelGreen"; this.panelGreen.Size = new System.Drawing.Size(40, 40); diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs index bc72f1b..8cc895e 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs @@ -142,7 +142,7 @@ namespace ProjectTractor.Generics if (tractor != null) { int countRows = _pictureWidth / _placeSizeWidth; - tractor.SetPosition(_pictureWidth - _placeSizeWidth * 2 - (i % countRows * _placeSizeWidth) + 20, _pictureHeight - i / countRows * _placeSizeHeight - 160); + tractor.SetPosition(_pictureWidth - _placeSizeWidth * 2 - (i % countRows * _placeSizeWidth) + 210, _pictureHeight - i / countRows * _placeSizeHeight - 160); tractor.DrawTransport(g); } i++; diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericStorage.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericStorage.cs index 7363e95..00378ca 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericStorage.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericStorage.cs @@ -90,40 +90,38 @@ namespace ProjectTractor } } - - /// /// Сохранение информации по автомобилям в хранилище в файл /// /// Путь и имя файла /// true - сохранение прошло успешно, false - ошибка при сохранении данных public bool SaveData(string filename) + { + if (File.Exists(filename)) + { + File.Delete(filename); + } + StringBuilder data = new(); + foreach (KeyValuePair> record in _tractorStorages) + { + StringBuilder records = new(); + foreach (DrawningTractor? elem in record.Value.GetTractors) { - if (File.Exists(filename)) - { - File.Delete(filename); - } - StringBuilder data = new(); - foreach (KeyValuePair> record in _tractorStorages) - { - StringBuilder records = new(); - foreach (DrawningTractor? elem in record.Value.GetTractors) - { - records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}"); - } - data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}"); - } - if (data.Length == 0) - { - return false; - } - using FileStream fs = new(filename, FileMode.Create); - byte[] info = new - UTF8Encoding(true).GetBytes($"TractorStorage{Environment.NewLine}{data}"); - fs.Write(info, 0, info.Length); - return true; + records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}"); } + data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}"); + } + if (data.Length == 0) + { + return false; + } + using (StreamWriter streamWriter = new(filename)) + { + streamWriter.WriteLine($"TractorStorage{Environment.NewLine}{data}"); + } + return true; + } /// /// Загрузка информации по автомобилям в хранилище из файла /// @@ -135,53 +133,43 @@ namespace ProjectTractor { return false; } - string bufferTextFromFile = ""; - using (FileStream fs = new(filename, FileMode.Open)) + using (StreamReader streamReader = new(filename)) { - byte[] b = new byte[fs.Length]; - UTF8Encoding temp = new(true); - while (fs.Read(b, 0, b.Length) > 0) + string str = streamReader.ReadLine(); + string[] strings = str.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); + if (strings == null || strings.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("TractorStorage")) - { - //если нет такой записи, то это не те данные - return false; - } - _tractorStorages.Clear(); - foreach (string data in strs) - { - string[] record = data.Split(_separatorForKeyValue, - StringSplitOptions.RemoveEmptyEntries); - if (record.Length != 2) + if (!strings[0].StartsWith("TractorStorage")) { - continue; + return false; } - TractorsGenericCollection - collection = new(_pictureWidth, _pictureHeight); - string[] set = record[1].Split(_separatorRecords, - StringSplitOptions.RemoveEmptyEntries); - foreach (string elem in set) + _tractorStorages.Clear(); + do { - DrawningTractor? tractor = - elem?.CreateDrawningTractor(_separatorForObject, _pictureWidth, _pictureHeight); - if (tractor != null) + string[] record = str.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries); + if (record.Length != 2) { - if (!(collection + tractor)) + str = streamReader.ReadLine(); + continue; + } + TractorsGenericCollection collection = new(_pictureWidth, _pictureHeight); + string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries); + foreach (string elem in set) + { + DrawningTractor? bus = elem?.CreateDrawningTractor(_separatorForObject, _pictureWidth, _pictureHeight); + if (bus != null) { - return false; + if (!(collection + bus)) + { + return false; + } } } - } - _tractorStorages.Add(record[0], collection); + _tractorStorages.Add(record[0], collection); + str = streamReader.ReadLine(); + } while (str != null); } return true; } diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/набор №1.txt b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/набор №1.txt index 2297a21..f0efeb4 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/набор №1.txt +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/набор №1.txt @@ -1,3 +1,4 @@ TractorStorage -апр|100:100:White;100:100:ff0000c0:Yellow:True:True; -fff|100:100:White:Yellow:False:True;100:100:White:Black:False:True; +gg|100:100:Yellow;100:100:Blue:Green:True:True; +ii|100:100:Purple:Green:True:True;100:100:Red:Yellow:True:True; +