diff --git a/ProjectBoat_base/ProjectBoat_bae/DrawningObjects/DrawningBoat.cs b/ProjectBoat_base/ProjectBoat_bae/DrawningObjects/DrawningBoat.cs index 43bd97f..e1f41f8 100644 --- a/ProjectBoat_base/ProjectBoat_bae/DrawningObjects/DrawningBoat.cs +++ b/ProjectBoat_base/ProjectBoat_bae/DrawningObjects/DrawningBoat.cs @@ -76,11 +76,11 @@ namespace ProjectBoat_bae.DrawningObjects { if (x < 0 || x + _boatWidth > _pictureWidth) { - x = Math.Max(0, _pictureWidth - _boatWidth + 60); + x = Math.Max(0, _pictureWidth - _boatWidth); } if (y < 0 || y + _boatHeight > _pictureHeight) { - y = Math.Max(0, _pictureHeight - _boatHeight + 60); + y = Math.Max(0, _pictureHeight - _boatHeight); } _startPosX = x; _startPosY = y; diff --git a/ProjectBoat_base/ProjectBoat_bae/FormBoatCollection.cs b/ProjectBoat_base/ProjectBoat_bae/FormBoatCollection.cs index bdb8e03..9ce6186 100644 --- a/ProjectBoat_base/ProjectBoat_bae/FormBoatCollection.cs +++ b/ProjectBoat_base/ProjectBoat_bae/FormBoatCollection.cs @@ -14,6 +14,7 @@ using ProjectBoat_bae.DrawningObjects; using ProjectBoat_bae.Generics; using ProjectBoat_bae.Exceptions; using ProjectBoat_bae.MovementStrategy; +using Microsoft.Extensions.Logging; using NLog; namespace ProjectBoat_bae @@ -24,7 +25,9 @@ namespace ProjectBoat_bae private readonly BoatsGenericStorage _storage; // Логер - private readonly Microsoft.Extensions.Logging.ILogger? _logger; + private readonly + //Microsoft.Extensions.Logging. + ILogger? _logger; public FormBoatCollection(ILogger logger) { @@ -57,14 +60,6 @@ namespace ProjectBoat_bae // Добавление набора в коллекцию private void ButtonAddObject_Click_1(object sender, EventArgs e) { - //if (string.IsNullOrEmpty(textBoxStorageName.Text)) - //{ - // MessageBox.Show("Не все данные заполнены", "Ошибка", - // MessageBoxButtons.OK, MessageBoxIcon.Error); - // return; - //} - //_storage.AddSet(textBoxStorageName.Text); - //ReloadObjects(); if (string.IsNullOrEmpty(textBoxStorageName.Text)) { @@ -84,13 +79,7 @@ namespace ProjectBoat_bae { return; } - // if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, - //MessageBoxIcon.Question) == DialogResult.Yes) - // { - // _storage.DelSet(listBoxStorages.SelectedItem.ToString() - // ?? string.Empty); - // ReloadObjects(); - // } + if (string.IsNullOrEmpty(textBoxStorageName.Text)) { MessageBox.Show("Не всё заполнено", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); @@ -101,39 +90,11 @@ namespace ProjectBoat_bae ReloadObjects(); _logger.LogInformation($"Добавлен набор: {textBoxStorageName.Text}"); - - //string name = listBoxStorages.SelectedItem.ToString() ?? string.Empty; - //if (MessageBox.Show($"Удалить объект {name}?", "Удаление", - //MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) - //{ - // _storage.DelSet(name); - // ReloadObjects(); - // _logger.LogInformation($"Deleted set: {name}"); - //} } // Добавление объекта в набор private void ButtonAddBoat_Click(object sender, EventArgs e) { - //if (listBoxStorages.SelectedIndex == -1) return; - //var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; - //if (obj == null) return; - - //FormBoatConfig form = new FormBoatConfig(); - //form.AddEvent(AddBoat); - //form.Show(); - //if (listBoxStorages.SelectedIndex == -1) - //{ - // return; - //} - //var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; - //if (obj == null) - //{ - // return; - //} - //FormBoatConfig formPlaneConfig = new FormBoatConfig(); - //formPlaneConfig.AddEvent(AddBoat); - //formPlaneConfig.Show(); FormBoatConfig formPlaneConfig = new FormBoatConfig(); formPlaneConfig.AddEvent(AddBoat); diff --git a/ProjectBoat_base/ProjectBoat_bae/Generics/BoatsGenericStorage.cs b/ProjectBoat_base/ProjectBoat_bae/Generics/BoatsGenericStorage.cs index 216d966..d5d2a6f 100644 --- a/ProjectBoat_base/ProjectBoat_bae/Generics/BoatsGenericStorage.cs +++ b/ProjectBoat_base/ProjectBoat_bae/Generics/BoatsGenericStorage.cs @@ -53,30 +53,6 @@ namespace ProjectBoat_bae.Generics public void SaveData(string filename) { - //if (File.Exists(filename)) - //{ - // File.Delete(filename); - //} - //StringBuilder data = new(); - //foreach (KeyValuePair> 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) - //{ - // throw new Exception("Невалиданя операция, нет данных для сохранения"); - //} - //using FileStream fs = new(filename, FileMode.Create); - //byte[] info = new - //UTF8Encoding(true).GetBytes($"CarStorage{Environment.NewLine}{data}"); - //fs.Write(info, 0, info.Length); - //return; if (File.Exists(filename)) { @@ -107,213 +83,7 @@ namespace ProjectBoat_bae.Generics public void 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("ShipStorage")) - // { - // 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 collection = new(_pictureWidth, _pictureHeight); - // string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries); - // foreach (string elem in set) - // { - // Drawningboat? boat = elem?.CreateDrawningBoat(_separatorForObject, _pictureWidth, _pictureHeight); - // if (boat != null) - // { - // if (!(collection + boat)) - // { - // return false; - // } - // } - // } - // _boatStorages.Add(record[0], collection); - // } - // return true; - //} - //if (!File.Exists(filename)) - //{ - // throw new Exception("Файл не найден"); - //} - //string bufferTextFromFile = ""; - //using (FileStream fs = new(filename, FileMode.Open)) - //{ - // byte[] b = new byte[fs.Length]; - // UTF8Encoding temp = new(true); - // while (fs.Read(b, 0, b.Length) > 0) - // { - // bufferTextFromFile += temp.GetString(b); - // } - //} - //var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, - //StringSplitOptions.RemoveEmptyEntries); - //if (strs == null || strs.Length == 0) - //{ - // throw new Exception("Нет данных для загрузки"); - //} - //if (!strs[0].StartsWith("BusStorage")) - //{ - // //если нет такой записи, то это не те данные - // throw new Exception("Неверный формат данных"); - //} - //_boatStorages.Clear(); - //foreach (string data in strs) - //{ - // string[] record = data.Split(_separatorForKeyValue, - // StringSplitOptions.RemoveEmptyEntries); - // if (record.Length != 2) - // { - // continue; - // } - // BoatsGenericCollection - // collection = new(_pictureWidth, _pictureHeight); - // string[] set = record[1].Split(_separatorRecords, - // StringSplitOptions.RemoveEmptyEntries); - // foreach (string elem in set) - // { - // Drawningboat? boat = - // elem?.CreateDrawningBoat(_separatorForObject, _pictureWidth, _pictureHeight); - // if (boat != null) - // { - // if (!(collection + boat)) - // { - // throw new Exception("Ошибка добавления в коллекцию"); - // } - // } - // } - // _boatStorages.Add(record[0], collection); - //} - - //using (StreamReader fs = File.OpenText(filename)) - //{ - - // string str = fs.ReadLine(); - - // if (str == null || str.Length == 0) - // { - // throw new IOException("Нет данных для загрузки"); - // } - - // if (!str.StartsWith("LocomotiveStorage")) - // { - // //если нет такой записи, то это не те данные - // throw new FileFormatException("Неверный формат данных"); - // } - - // _boatStorages.Clear(); - // string strs = ""; - - - // while ((strs = fs.ReadLine()) != null) - // { - - // if (strs == null) - // { - // throw new FileNotFoundException("Нет данных для загрузки"); - // } - - // string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries); - // if (record.Length != 2) - // { - // continue; - // } - // BoatsGenericCollection collection = new(_pictureWidth, _pictureHeight); - // string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries); - // foreach (string elem in set) - // { - // Drawningboat? boat = elem?.CreateDrawningBoat(_separatorForObject, _pictureWidth, _pictureHeight); - // if (boat != null) - // { - // if (!(collection + boat)) // for my realization it's -1, for eegov's realization it's boolean - // { - // throw new Exception("Ошибка добавления "); - // } - // } - // } - // _boatStorages.Add(record[0], collection); - // } - // return; - //} - - //if (!File.Exists(filename)) - //{ - // throw new FileNotFoundException("Файл не найден"); - //} - - //using (StreamReader fs = File.OpenText(filename)) - //{ - - // string str = fs.ReadLine(); - - // if (str == null || str.Length == 0) - // { - // throw new IOException("Нет данных для загрузки"); - // } - - // if (!str.StartsWith("LocomotiveStorage")) - // { - // //если нет такой записи, то это не те данные - // throw new FileFormatException("Неверный формат данных"); - // } - - // _boatStorages.Clear(); - // string strs = ""; - - - // while ((strs = fs.ReadLine()) != null) - // { - - // if (strs == null) - // { - // throw new FileNotFoundException("Нет данных для загрузки"); - // } - - // string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries); - // if (record.Length != 2) - // { - // continue; - // } - // BoatsGenericCollection collection = new(_pictureWidth, _pictureHeight); - // string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries); - // foreach (string elem in set) - // { - // Drawningboat? boat = elem?.CreateDrawningBoat(_separatorForObject, _pictureWidth, _pictureHeight); - // if (boat != null) - // { - // if ((collection + boat) == -1) // for my realization it's -1, for eegov's realization it's boolean - // { - // throw new Exception("Ошибка добавления "); - // } - // } - // } - // _boatStorages.Add(record[0], collection); - // } - // return; - //} + if (!File.Exists(filename)) { throw new FileNotFoundException("Файл не найден"); diff --git a/ProjectBoat_base/ProjectBoat_bae/ProjectBoat_bae.csproj b/ProjectBoat_base/ProjectBoat_bae/ProjectBoat_bae.csproj index 19587fe..707749f 100644 --- a/ProjectBoat_base/ProjectBoat_bae/ProjectBoat_bae.csproj +++ b/ProjectBoat_base/ProjectBoat_bae/ProjectBoat_bae.csproj @@ -12,10 +12,6 @@ - - - -