diff --git a/RPP/RPP/AirbusGenericStorage.cs b/RPP/RPP/AirbusGenericStorage.cs index 799d56b..f50ba23 100644 --- a/RPP/RPP/AirbusGenericStorage.cs +++ b/RPP/RPP/AirbusGenericStorage.cs @@ -19,43 +19,44 @@ namespace RPP.Generics private readonly int _pictureHeight; - private static readonly char _separatorForKeyValue = '|'; - private readonly char _separatorRecords = ';'; - private static readonly char _separatorForObject = ':'; public AirbusGenericStorage(int pictureWidth, int pictureHeight) { - _airbusStorages = new Dictionary>(); + _airbusStorages = new Dictionary>(); _pictureWidth = pictureWidth; _pictureHeight = pictureHeight; } public void AddSet(string name) { - // TODO Прописать логику для добавления - if (_airbusStorages.ContainsKey(name)) return; + if (_airbusStorages.ContainsKey(name)) + return; _airbusStorages[name] = new AirbusGenericCollection(_pictureWidth, _pictureHeight); } public void DelSet(string name) { - // TODO Прописать логику для удаления - if (!_airbusStorages.ContainsKey(name)) return; + if (!_airbusStorages.ContainsKey(name)) + return; _airbusStorages.Remove(name); } - public AirbusGenericCollection? + public AirbusGenericCollection this[string ind] { get { - // TODO Продумать логику получения набора - if(_airbusStorages.ContainsKey(ind)) return _airbusStorages[ind]; + if (_airbusStorages.ContainsKey(ind)) + return _airbusStorages[ind]; return null; } } - public bool SaveData(string filename) + + private static readonly char _separatorForKeyValue = '|'; + private readonly char _separatorRecords = ';'; + private static readonly char _separatorForObject = ':'; + public void SaveData(string filename) { + if (File.Exists(filename)) { File.Delete(filename); @@ -73,37 +74,35 @@ namespace RPP.Generics } if (data.Length == 0) { - return false; + throw new InvalidOperationException("Невалидная операция, нет данных для сохранения"); } using (StreamWriter writer = new StreamWriter(filename)) { writer.WriteLine("AirbusStorage"); writer.Write(data.ToString()); - return true; } } - public bool LoadData(string filename) + public void LoadData(string filename) { if (!File.Exists(filename)) - { - return false; - } + throw new FileNotFoundException("Файл не найден"); + using (StreamReader reader = new StreamReader(filename)) { string checker = reader.ReadLine(); - if (checker == null) - return false; + if (checker == null || checker.Length == 0) + throw new Exception("Нет данных для загрузки"); if (!checker.StartsWith("AirbusStorage")) - return false; + throw new Exception("Неверный формат ввода"); _airbusStorages.Clear(); string strs; bool firstinit = true; while ((strs = reader.ReadLine()) != null) { if (strs == null && firstinit) - return false; + throw new Exception("Нет данных для загрузки"); if (strs == null) break; firstinit = false; @@ -111,21 +110,23 @@ namespace RPP.Generics AirbusGenericCollection collection = new(_pictureWidth, _pictureHeight); foreach (string data in strs.Split('|')[1].Split(';')) { - DrawningAirbus? car = + DrawningAirbus? airbus = data?.CreateDrawningAirbus(_separatorForObject, _pictureWidth, _pictureHeight); - if (car != null) + if (airbus != null) { - if (!(collection + car)) + try { _ = collection + airbus; } + catch (AirbusNotFoundException e) { - return false; + throw e; + } + catch (StorageOverflowException e) + { + throw e; } } - - } _airbusStorages.Add(name, collection); } - return true; } } } diff --git a/RPP/RPP/AirbusNotFoundException.cs b/RPP/RPP/AirbusNotFoundException.cs new file mode 100644 index 0000000..e9ed676 --- /dev/null +++ b/RPP/RPP/AirbusNotFoundException.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace RPP +{ + internal class AirbusNotFoundException : ApplicationException + { + public AirbusNotFoundException(int i) : base($"Не найден объект по позиции {i}") { } + public AirbusNotFoundException() : base() { } + public AirbusNotFoundException(string message) : base(message) { } + public AirbusNotFoundException(string message, Exception exception) : base(message, exception) { } + protected AirbusNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { } + } +} diff --git a/RPP/RPP/FormAirbus.Designer.cs b/RPP/RPP/FormAirbus.Designer.cs index 82b812d..9caeb55 100644 --- a/RPP/RPP/FormAirbus.Designer.cs +++ b/RPP/RPP/FormAirbus.Designer.cs @@ -51,7 +51,6 @@ pictureBoxAirbus.SizeMode = PictureBoxSizeMode.AutoSize; pictureBoxAirbus.TabIndex = 0; pictureBoxAirbus.TabStop = false; - pictureBoxAirbus.Click += buttonMove_Click; // // buttonCreateAirbus // @@ -120,7 +119,6 @@ comboBoxStrategy.Name = "comboBoxStrategy"; comboBoxStrategy.Size = new Size(121, 23); comboBoxStrategy.TabIndex = 6; - comboBoxStrategy.SelectedIndexChanged += comboBoxStrategy_SelectedIndexChanged; // // buttonCreateFlyAirbus // @@ -169,7 +167,6 @@ Controls.Add(pictureBoxAirbus); Name = "FormAirbus"; Text = "Airbus"; - Load += FormAirbus_Load; ((System.ComponentModel.ISupportInitialize)pictureBoxAirbus).EndInit(); ResumeLayout(false); PerformLayout(); diff --git a/RPP/RPP/FormAirbus.cs b/RPP/RPP/FormAirbus.cs index 09f6aeb..cb1b933 100644 --- a/RPP/RPP/FormAirbus.cs +++ b/RPP/RPP/FormAirbus.cs @@ -140,20 +140,5 @@ namespace RPP SelectedAirbus = _drawningAirbus; DialogResult = DialogResult.OK; } - - private void pictureBoxAirbus_Click(object sender, EventArgs e) - { - - } - - private void FormAirbus_Load(object sender, EventArgs e) - { - - } - - private void comboBoxStrategy_SelectedIndexChanged(object sender, EventArgs e) - { - - } } } \ No newline at end of file diff --git a/RPP/RPP/FormAirbusCollection.Designer.cs b/RPP/RPP/FormAirbusCollection.Designer.cs index 7860e1d..03808de 100644 --- a/RPP/RPP/FormAirbusCollection.Designer.cs +++ b/RPP/RPP/FormAirbusCollection.Designer.cs @@ -62,12 +62,10 @@ panel1.Controls.Add(AddAirbusButton); panel1.Controls.Add(menuStrip); panel1.Dock = DockStyle.Right; - panel1.Location = new Point(682, 0); - panel1.Margin = new Padding(3, 4, 3, 4); + panel1.Location = new Point(597, 0); panel1.Name = "panel1"; - panel1.Size = new Size(232, 600); + panel1.Size = new Size(203, 450); panel1.TabIndex = 0; - panel1.Paint += panel1_Paint; // // panel2 // @@ -77,19 +75,16 @@ panel2.Controls.Add(textBoxStorageName); panel2.Controls.Add(label2); panel2.Controls.Add(label1); - panel2.Location = new Point(3, 36); - panel2.Margin = new Padding(3, 4, 3, 4); + panel2.Location = new Point(3, 27); panel2.Name = "panel2"; - panel2.Size = new Size(219, 292); + panel2.Size = new Size(192, 219); panel2.TabIndex = 5; - panel2.Paint += panel2_Paint; // // buttonDelObject // - buttonDelObject.Location = new Point(15, 240); - buttonDelObject.Margin = new Padding(3, 4, 3, 4); + buttonDelObject.Location = new Point(13, 180); buttonDelObject.Name = "buttonDelObject"; - buttonDelObject.Size = new Size(197, 48); + buttonDelObject.Size = new Size(172, 36); buttonDelObject.TabIndex = 4; buttonDelObject.Text = "Удалить набор"; buttonDelObject.UseVisualStyleBackColor = true; @@ -98,20 +93,18 @@ // listBoxStorages // listBoxStorages.FormattingEnabled = true; - listBoxStorages.ItemHeight = 20; - listBoxStorages.Location = new Point(15, 127); - listBoxStorages.Margin = new Padding(3, 4, 3, 4); + listBoxStorages.ItemHeight = 15; + listBoxStorages.Location = new Point(13, 95); listBoxStorages.Name = "listBoxStorages"; - listBoxStorages.Size = new Size(196, 104); + listBoxStorages.Size = new Size(172, 79); listBoxStorages.TabIndex = 3; listBoxStorages.SelectedIndexChanged += ListBoxObjects_SelectedIndexChanged; // // buttonAddObject // - buttonAddObject.Location = new Point(15, 64); - buttonAddObject.Margin = new Padding(3, 4, 3, 4); + buttonAddObject.Location = new Point(13, 48); buttonAddObject.Name = "buttonAddObject"; - buttonAddObject.Size = new Size(197, 55); + buttonAddObject.Size = new Size(172, 41); buttonAddObject.TabIndex = 2; buttonAddObject.Text = "Добавить набор"; buttonAddObject.UseVisualStyleBackColor = true; @@ -119,36 +112,33 @@ // // textBoxStorageName // - textBoxStorageName.Location = new Point(15, 25); - textBoxStorageName.Margin = new Padding(3, 4, 3, 4); + textBoxStorageName.Location = new Point(13, 19); textBoxStorageName.Name = "textBoxStorageName"; - textBoxStorageName.Size = new Size(196, 27); + textBoxStorageName.Size = new Size(172, 23); textBoxStorageName.TabIndex = 1; // // label2 // label2.AutoSize = true; - label2.Location = new Point(17, 0); + label2.Location = new Point(15, 0); label2.Name = "label2"; - label2.Size = new Size(66, 20); + label2.Size = new Size(52, 15); label2.TabIndex = 0; label2.Text = "Наборы"; - label2.Click += label2_Click; // // label1 // label1.AutoSize = true; - label1.Location = new Point(117, 1); + label1.Location = new Point(102, 1); label1.Name = "label1"; - label1.Size = new Size(0, 20); + label1.Size = new Size(0, 15); label1.TabIndex = 0; // // ButtonRefreshCollection // - ButtonRefreshCollection.Location = new Point(8, 531); - ButtonRefreshCollection.Margin = new Padding(3, 4, 3, 4); + ButtonRefreshCollection.Location = new Point(7, 398); ButtonRefreshCollection.Name = "ButtonRefreshCollection"; - ButtonRefreshCollection.Size = new Size(217, 53); + ButtonRefreshCollection.Size = new Size(190, 40); ButtonRefreshCollection.TabIndex = 4; ButtonRefreshCollection.Text = "Обновить коллекцию"; ButtonRefreshCollection.UseVisualStyleBackColor = true; @@ -156,10 +146,9 @@ // // ButtonRemoveAirbus // - ButtonRemoveAirbus.Location = new Point(6, 436); - ButtonRemoveAirbus.Margin = new Padding(3, 4, 3, 4); + ButtonRemoveAirbus.Location = new Point(5, 327); ButtonRemoveAirbus.Name = "ButtonRemoveAirbus"; - ButtonRemoveAirbus.Size = new Size(217, 53); + ButtonRemoveAirbus.Size = new Size(190, 40); ButtonRemoveAirbus.TabIndex = 3; ButtonRemoveAirbus.Text = "Удалить аэробус"; ButtonRemoveAirbus.UseVisualStyleBackColor = true; @@ -167,18 +156,16 @@ // // maskedTextBoxNumber // - maskedTextBoxNumber.Location = new Point(46, 397); - maskedTextBoxNumber.Margin = new Padding(3, 4, 3, 4); + maskedTextBoxNumber.Location = new Point(40, 298); maskedTextBoxNumber.Name = "maskedTextBoxNumber"; - maskedTextBoxNumber.Size = new Size(111, 27); + maskedTextBoxNumber.Size = new Size(98, 23); maskedTextBoxNumber.TabIndex = 2; // // AddAirbusButton // - AddAirbusButton.Location = new Point(6, 336); - AddAirbusButton.Margin = new Padding(3, 4, 3, 4); + AddAirbusButton.Location = new Point(5, 252); AddAirbusButton.Name = "AddAirbusButton"; - AddAirbusButton.Size = new Size(217, 53); + AddAirbusButton.Size = new Size(190, 40); AddAirbusButton.TabIndex = 1; AddAirbusButton.Text = "Добавить аэробус"; AddAirbusButton.UseVisualStyleBackColor = true; @@ -190,8 +177,7 @@ menuStrip.Items.AddRange(new ToolStripItem[] { menuToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; - menuStrip.Padding = new Padding(7, 3, 0, 3); - menuStrip.Size = new Size(232, 30); + menuStrip.Size = new Size(203, 24); menuStrip.TabIndex = 6; menuStrip.Text = "menuStrip1"; // @@ -199,20 +185,20 @@ // menuToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { SaveToolStripMenuItem, LoadToolStripMenuItem }); menuToolStripMenuItem.Name = "menuToolStripMenuItem"; - menuToolStripMenuItem.Size = new Size(65, 24); + menuToolStripMenuItem.Size = new Size(53, 20); menuToolStripMenuItem.Text = "Меню"; // // SaveToolStripMenuItem // SaveToolStripMenuItem.Name = "SaveToolStripMenuItem"; - SaveToolStripMenuItem.Size = new Size(224, 26); + SaveToolStripMenuItem.Size = new Size(133, 22); SaveToolStripMenuItem.Text = "Сохранить"; SaveToolStripMenuItem.Click += SaveToolStripMenuItem_Click; // // LoadToolStripMenuItem // LoadToolStripMenuItem.Name = "LoadToolStripMenuItem"; - LoadToolStripMenuItem.Size = new Size(224, 26); + LoadToolStripMenuItem.Size = new Size(133, 22); LoadToolStripMenuItem.Text = "Загрузить"; LoadToolStripMenuItem.Click += LoadToolStripMenuItem_Click; // @@ -220,9 +206,8 @@ // pictureBoxCollection.Dock = DockStyle.Fill; pictureBoxCollection.Location = new Point(0, 0); - pictureBoxCollection.Margin = new Padding(3, 4, 3, 4); pictureBoxCollection.Name = "pictureBoxCollection"; - pictureBoxCollection.Size = new Size(682, 600); + pictureBoxCollection.Size = new Size(597, 450); pictureBoxCollection.TabIndex = 1; pictureBoxCollection.TabStop = false; // @@ -236,13 +221,12 @@ // // FormAirbusCollection // - AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(914, 600); + ClientSize = new Size(800, 450); Controls.Add(pictureBoxCollection); Controls.Add(panel1); MainMenuStrip = menuStrip; - Margin = new Padding(3, 4, 3, 4); Name = "FormAirbusCollection"; Text = "FormFlyAirbus"; Load += FormFlyAirbus_Load; diff --git a/RPP/RPP/FormAirbusCollection.cs b/RPP/RPP/FormAirbusCollection.cs index d4c8c70..25448c8 100644 --- a/RPP/RPP/FormAirbusCollection.cs +++ b/RPP/RPP/FormAirbusCollection.cs @@ -1,19 +1,18 @@ using RPP.DrawningObjects; using RPP.Generics; -using System.Windows.Forms; - +using Microsoft.Extensions.Logging; namespace RPP { public partial class FormAirbusCollection : Form { private readonly AirbusGenericStorage _storage; - - public FormAirbusCollection() + private readonly ILogger _logger; + public FormAirbusCollection(ILogger logger) { InitializeComponent(); _storage = new AirbusGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height); - + _logger = logger; } private void FormFlyAirbus_Load(object sender, EventArgs e) @@ -29,16 +28,20 @@ namespace RPP var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; if (obj == null) { + _logger.LogWarning("Добавление пустого объекта"); return; } - if (obj + Airbus) + try { + _ = obj + Airbus; MessageBox.Show("Объект добавлен"); pictureBoxCollection.Image = obj.ShowCars(); + _logger.LogInformation($"Добавлен объект в набор {listBoxStorages.SelectedItem.ToString()}"); } - else + catch (Exception ex) { MessageBox.Show("Не удалось добавить объект"); + _logger.LogWarning($"{ex.Message} в наборе {listBoxStorages.SelectedItem.ToString()}"); } } @@ -83,10 +86,12 @@ namespace RPP { MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogWarning("Пустое название набора"); return; } _storage.AddSet(textBoxStorageName.Text); ReloadObjects(); + _logger.LogInformation($"Добавлен набор: {textBoxStorageName.Text}"); } private void ListBoxObjects_SelectedIndexChanged(object sender, EventArgs e) { @@ -97,12 +102,15 @@ namespace RPP { if (listBoxStorages.SelectedIndex == -1) { + _logger.LogWarning("Удаление невыбранного набора"); return; } - if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + string name = listBoxStorages.SelectedItem.ToString() ?? string.Empty; + if (MessageBox.Show($"Удалить объект {name}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { _storage.DelSet(listBoxStorages.SelectedItem.ToString() ?? string.Empty); ReloadObjects(); + _logger.LogInformation($"Удален набор: {name}"); } } @@ -110,6 +118,7 @@ namespace RPP { if (listBoxStorages.SelectedIndex == -1) { + _logger.LogWarning("Удаление объекта из несуществующего набора"); return; } var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; @@ -122,14 +131,24 @@ namespace RPP return; } int pos = Convert.ToInt32(maskedTextBoxNumber.Text); - if (obj - pos != null) + try { - MessageBox.Show("Объект удален"); - pictureBoxCollection.Image = obj.ShowCars(); + if (obj - pos != null) + { + MessageBox.Show("Объект удален"); + pictureBoxCollection.Image = obj.ShowCars(); + _logger.LogInformation($"Удален объект из набора {listBoxStorages.SelectedItem.ToString()}"); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + _logger.LogWarning($"Не удалось удалить объект из набора {listBoxStorages.SelectedItem.ToString()}"); + } } - else + catch (AirbusNotFoundException ex) { - MessageBox.Show("Не удалось удалить объект"); + MessageBox.Show(ex.Message); + _logger.LogWarning($"{ex.Message} из набора {listBoxStorages.SelectedItem.ToString()}"); } } @@ -150,13 +169,16 @@ namespace RPP { if (saveFileDialog.ShowDialog() == DialogResult.OK) { - if (_storage.SaveData(saveFileDialog.FileName)) + try { + _storage.SaveData(saveFileDialog.FileName); MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + _logger.LogInformation($"Сохранение наборов в файл {saveFileDialog.FileName}"); } - else + catch (Exception ex) { - MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogWarning($"Не удалось сохранить наборы с ошибкой: {ex.Message}"); } } } @@ -165,31 +187,19 @@ namespace RPP if (openFileDialog.ShowDialog() == DialogResult.OK) { - if (_storage.LoadData(openFileDialog.FileName)) + try { + _storage.LoadData(openFileDialog.FileName); ReloadObjects(); MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + _logger.LogInformation($"Загрузились наборы из файла {openFileDialog.FileName}"); } - else + catch (Exception ex) { - MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogWarning($"Не удалось сохранить наборы с ошибкой: {ex.Message}"); } } } - - private void panel2_Paint(object sender, PaintEventArgs e) - { - - } - - private void label2_Click(object sender, EventArgs e) - { - - } - - private void panel1_Paint(object sender, PaintEventArgs e) - { - - } } } diff --git a/RPP/RPP/FormAirbusCollection.resx b/RPP/RPP/FormAirbusCollection.resx index 6afff5b..62b0739 100644 --- a/RPP/RPP/FormAirbusCollection.resx +++ b/RPP/RPP/FormAirbusCollection.resx @@ -18,7 +18,7 @@ System.Resources.ResXResourceReader, System.Windows.Forms, ... System.Resources.ResXResourceWriter, System.Windows.Forms, ... this is my long stringthis is a comment - Blue + Blue [base64 mime encoded serialized .NET Framework object] diff --git a/RPP/RPP/FormAirbusConfig.Designer.cs b/RPP/RPP/FormAirbusConfig.Designer.cs index d34e4fd..33dff0c 100644 --- a/RPP/RPP/FormAirbusConfig.Designer.cs +++ b/RPP/RPP/FormAirbusConfig.Designer.cs @@ -71,11 +71,9 @@ groupBoxParameters.Controls.Add(label2); groupBoxParameters.Controls.Add(numericUpDownSpeed); groupBoxParameters.Controls.Add(label1); - groupBoxParameters.Location = new Point(14, 16); - groupBoxParameters.Margin = new Padding(3, 4, 3, 4); + groupBoxParameters.Location = new Point(12, 12); groupBoxParameters.Name = "groupBoxParameters"; - groupBoxParameters.Padding = new Padding(3, 4, 3, 4); - groupBoxParameters.Size = new Size(627, 368); + groupBoxParameters.Size = new Size(549, 276); groupBoxParameters.TabIndex = 0; groupBoxParameters.TabStop = false; groupBoxParameters.Text = "Параметры"; @@ -83,9 +81,9 @@ // labelFly // labelFly.BorderStyle = BorderStyle.FixedSingle; - labelFly.Location = new Point(446, 292); + labelFly.Location = new Point(390, 219); labelFly.Name = "labelFly"; - labelFly.Size = new Size(135, 47); + labelFly.Size = new Size(118, 36); labelFly.TabIndex = 8; labelFly.Text = "Продвинутый"; labelFly.TextAlign = ContentAlignment.MiddleCenter; @@ -94,9 +92,9 @@ // labelBase // labelBase.BorderStyle = BorderStyle.FixedSingle; - labelBase.Location = new Point(291, 292); + labelBase.Location = new Point(255, 219); labelBase.Name = "labelBase"; - labelBase.Size = new Size(129, 47); + labelBase.Size = new Size(113, 36); labelBase.TabIndex = 7; labelBase.Text = "Простой"; labelBase.TextAlign = ContentAlignment.MiddleCenter; @@ -112,11 +110,9 @@ groupBoxColor.Controls.Add(panelBlue); groupBoxColor.Controls.Add(panelGreen); groupBoxColor.Controls.Add(panelRed); - groupBoxColor.Location = new Point(272, 40); - groupBoxColor.Margin = new Padding(3, 4, 3, 4); + groupBoxColor.Location = new Point(238, 30); groupBoxColor.Name = "groupBoxColor"; - groupBoxColor.Padding = new Padding(3, 4, 3, 4); - groupBoxColor.Size = new Size(327, 223); + groupBoxColor.Size = new Size(286, 167); groupBoxColor.TabIndex = 6; groupBoxColor.TabStop = false; groupBoxColor.Text = "Цвета"; @@ -124,82 +120,73 @@ // panelPurple // panelPurple.BackColor = Color.Purple; - panelPurple.Location = new Point(255, 129); - panelPurple.Margin = new Padding(3, 4, 3, 4); + panelPurple.Location = new Point(223, 97); panelPurple.Name = "panelPurple"; - panelPurple.Size = new Size(54, 59); + panelPurple.Size = new Size(47, 44); panelPurple.TabIndex = 7; // // panelBlack // panelBlack.BackColor = Color.Black; - panelBlack.Location = new Point(174, 129); - panelBlack.Margin = new Padding(3, 4, 3, 4); + panelBlack.Location = new Point(152, 97); panelBlack.Name = "panelBlack"; - panelBlack.Size = new Size(54, 59); + panelBlack.Size = new Size(47, 44); panelBlack.TabIndex = 6; // // panelGray // panelGray.BackColor = Color.Gray; - panelGray.Location = new Point(95, 129); - panelGray.Margin = new Padding(3, 4, 3, 4); + panelGray.Location = new Point(83, 97); panelGray.Name = "panelGray"; - panelGray.Size = new Size(54, 59); + panelGray.Size = new Size(47, 44); panelGray.TabIndex = 5; // // panelWhite // panelWhite.BackColor = Color.White; - panelWhite.Location = new Point(19, 129); - panelWhite.Margin = new Padding(3, 4, 3, 4); + panelWhite.Location = new Point(17, 97); panelWhite.Name = "panelWhite"; - panelWhite.Size = new Size(54, 59); + panelWhite.Size = new Size(47, 44); panelWhite.TabIndex = 4; // // panelYellow // panelYellow.BackColor = Color.Yellow; - panelYellow.Location = new Point(255, 43); - panelYellow.Margin = new Padding(3, 4, 3, 4); + panelYellow.Location = new Point(223, 32); panelYellow.Name = "panelYellow"; - panelYellow.Size = new Size(54, 60); + panelYellow.Size = new Size(47, 45); panelYellow.TabIndex = 3; // // panelBlue // panelBlue.BackColor = Color.Blue; - panelBlue.Location = new Point(174, 43); - panelBlue.Margin = new Padding(3, 4, 3, 4); + panelBlue.Location = new Point(152, 32); panelBlue.Name = "panelBlue"; - panelBlue.Size = new Size(54, 60); + panelBlue.Size = new Size(47, 45); panelBlue.TabIndex = 2; // // panelGreen // panelGreen.BackColor = Color.Green; - panelGreen.Location = new Point(95, 43); - panelGreen.Margin = new Padding(3, 4, 3, 4); + panelGreen.Location = new Point(83, 32); panelGreen.Name = "panelGreen"; - panelGreen.Size = new Size(54, 60); + panelGreen.Size = new Size(47, 45); panelGreen.TabIndex = 1; // // panelRed // panelRed.BackColor = Color.Red; - panelRed.Location = new Point(19, 43); - panelRed.Margin = new Padding(3, 4, 3, 4); + panelRed.Location = new Point(17, 32); panelRed.Name = "panelRed"; - panelRed.Size = new Size(54, 59); + panelRed.Size = new Size(47, 44); panelRed.TabIndex = 0; // // checkBoxEngine // checkBoxEngine.AutoSize = true; - checkBoxEngine.Location = new Point(17, 264); - checkBoxEngine.Margin = new Padding(3, 4, 3, 4); + checkBoxEngine.Location = new Point(15, 198); checkBoxEngine.Name = "checkBoxEngine"; - checkBoxEngine.Size = new Size(269, 24); + checkBoxEngine.Size = new Size(213, 19); checkBoxEngine.TabIndex = 5; checkBoxEngine.Text = "Признак наличия доп. двигателей"; checkBoxEngine.UseVisualStyleBackColor = true; @@ -207,51 +194,48 @@ // checkBoxCompartment // checkBoxCompartment.AutoSize = true; - checkBoxCompartment.Location = new Point(17, 203); - checkBoxCompartment.Margin = new Padding(3, 4, 3, 4); + checkBoxCompartment.Location = new Point(15, 152); checkBoxCompartment.Name = "checkBoxCompartment"; - checkBoxCompartment.Size = new Size(236, 24); + checkBoxCompartment.Size = new Size(188, 19); checkBoxCompartment.TabIndex = 4; checkBoxCompartment.Text = "Признак наличия доп. отсека"; checkBoxCompartment.UseVisualStyleBackColor = true; // // numericUpDownWeight // - numericUpDownWeight.Location = new Point(95, 89); - numericUpDownWeight.Margin = new Padding(3, 4, 3, 4); + numericUpDownWeight.Location = new Point(83, 67); numericUpDownWeight.Maximum = new decimal(new int[] { 1000, 0, 0, 0 }); numericUpDownWeight.Minimum = new decimal(new int[] { 100, 0, 0, 0 }); numericUpDownWeight.Name = "numericUpDownWeight"; - numericUpDownWeight.Size = new Size(79, 27); + numericUpDownWeight.Size = new Size(69, 23); numericUpDownWeight.TabIndex = 3; numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 }); // // label2 // label2.AutoSize = true; - label2.Location = new Point(17, 89); + label2.Location = new Point(15, 67); label2.Name = "label2"; - label2.Size = new Size(36, 20); + label2.Size = new Size(29, 15); label2.TabIndex = 2; label2.Text = "Вес:"; // // numericUpDownSpeed // - numericUpDownSpeed.Location = new Point(95, 36); - numericUpDownSpeed.Margin = new Padding(3, 4, 3, 4); + numericUpDownSpeed.Location = new Point(83, 27); numericUpDownSpeed.Maximum = new decimal(new int[] { 1000, 0, 0, 0 }); numericUpDownSpeed.Minimum = new decimal(new int[] { 100, 0, 0, 0 }); numericUpDownSpeed.Name = "numericUpDownSpeed"; - numericUpDownSpeed.Size = new Size(79, 27); + numericUpDownSpeed.Size = new Size(69, 23); numericUpDownSpeed.TabIndex = 1; numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 }); // // label1 // label1.AutoSize = true; - label1.Location = new Point(17, 39); + label1.Location = new Point(15, 29); label1.Name = "label1"; - label1.Size = new Size(76, 20); + label1.Size = new Size(62, 15); label1.TabIndex = 0; label1.Text = "Скорость:"; // @@ -259,20 +243,18 @@ // panel9.AllowDrop = true; panel9.Controls.Add(pictureBoxObject); - panel9.Location = new Point(675, 87); - panel9.Margin = new Padding(3, 4, 3, 4); + panel9.Location = new Point(591, 65); panel9.Name = "panel9"; - panel9.Size = new Size(354, 244); + panel9.Size = new Size(310, 183); panel9.TabIndex = 1; panel9.DragDrop += PanelObject_DragDrop; panel9.DragEnter += PanelObject_DragEnter; // // pictureBoxObject // - pictureBoxObject.Location = new Point(27, 4); - pictureBoxObject.Margin = new Padding(3, 4, 3, 4); + pictureBoxObject.Location = new Point(24, 3); pictureBoxObject.Name = "pictureBoxObject"; - pictureBoxObject.Size = new Size(323, 236); + pictureBoxObject.Size = new Size(283, 177); pictureBoxObject.TabIndex = 2; pictureBoxObject.TabStop = false; // @@ -280,9 +262,9 @@ // labelAdditionalColor.AllowDrop = true; labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle; - labelAdditionalColor.Location = new Point(870, 35); + labelAdditionalColor.Location = new Point(761, 26); labelAdditionalColor.Name = "labelAdditionalColor"; - labelAdditionalColor.Size = new Size(133, 47); + labelAdditionalColor.Size = new Size(117, 36); labelAdditionalColor.TabIndex = 1; labelAdditionalColor.Text = "Доп. цвет"; labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter; @@ -293,9 +275,9 @@ // labelColor.AllowDrop = true; labelColor.BorderStyle = BorderStyle.FixedSingle; - labelColor.Location = new Point(703, 35); + labelColor.Location = new Point(615, 26); labelColor.Name = "labelColor"; - labelColor.Size = new Size(133, 47); + labelColor.Size = new Size(117, 36); labelColor.TabIndex = 0; labelColor.Text = "Цвет"; labelColor.TextAlign = ContentAlignment.MiddleCenter; @@ -304,10 +286,9 @@ // // buttonAdd // - buttonAdd.Location = new Point(703, 339); - buttonAdd.Margin = new Padding(3, 4, 3, 4); + buttonAdd.Location = new Point(615, 254); buttonAdd.Name = "buttonAdd"; - buttonAdd.Size = new Size(134, 45); + buttonAdd.Size = new Size(117, 34); buttonAdd.TabIndex = 2; buttonAdd.Text = "Добавить"; buttonAdd.UseVisualStyleBackColor = true; @@ -315,26 +296,24 @@ // // buttonCancel // - buttonCancel.Location = new Point(870, 339); - buttonCancel.Margin = new Padding(3, 4, 3, 4); + buttonCancel.Location = new Point(761, 254); buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(134, 45); + buttonCancel.Size = new Size(117, 34); buttonCancel.TabIndex = 3; buttonCancel.Text = "Отмена"; buttonCancel.UseVisualStyleBackColor = true; // // FormAirbusConfig // - AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1057, 400); + ClientSize = new Size(925, 300); Controls.Add(buttonCancel); Controls.Add(labelAdditionalColor); Controls.Add(labelColor); Controls.Add(buttonAdd); Controls.Add(panel9); Controls.Add(groupBoxParameters); - Margin = new Padding(3, 4, 3, 4); Name = "FormAirbusConfig"; Text = "FormAirbusConfig"; Load += FormAirbusConfig_Load; diff --git a/RPP/RPP/FormAirbusConfig.cs b/RPP/RPP/FormAirbusConfig.cs index 148c717..23c241a 100644 --- a/RPP/RPP/FormAirbusConfig.cs +++ b/RPP/RPP/FormAirbusConfig.cs @@ -16,9 +16,7 @@ namespace RPP public partial class FormAirbusConfig : Form { DrawningAirbus? _airbus = null; - /// - /// Событие - /// + private event Action? EventAddAirbus; public FormAirbusConfig() @@ -42,9 +40,6 @@ namespace RPP } - /// - /// Отрисовать машину - /// private void DrawAirbus() { Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); @@ -56,21 +51,13 @@ namespace RPP _airbus?.DrawTransport(gr); pictureBoxObject.Image = bmp; } - /// - /// Передаем информацию при нажатии на Label - /// - /// - /// + private void LabelObject_MouseDown(object sender, MouseEventArgs e) { (sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy); } - /// - /// Проверка получаемой информации (ее типа на соответствие требуемому) - /// - /// - /// + private void PanelObject_DragEnter(object sender, DragEventArgs e) { if (e.Data?.GetDataPresent(DataFormats.Text) ?? false) @@ -82,11 +69,7 @@ namespace RPP e.Effect = DragDropEffects.None; } } - /// - /// Действия при приеме перетаскиваемой информации - /// - /// - /// + private void PanelObject_DragDrop(object sender, DragEventArgs e) { switch (e.Data?.GetData(DataFormats.Text).ToString()) @@ -105,9 +88,6 @@ namespace RPP } DrawAirbus(); } - /// Добавление события - /// - /// Привязанный метод public void AddEvent(Action ev) { if (EventAddAirbus == null) @@ -119,11 +99,6 @@ namespace RPP EventAddAirbus += ev; } } - /// - /// Добавление машины - /// - /// - /// private void ButtonOk_Click(object sender, EventArgs e) { EventAddAirbus?.Invoke(_airbus); diff --git a/RPP/RPP/FormAirbusConfig.resx b/RPP/RPP/FormAirbusConfig.resx index a395bff..af32865 100644 --- a/RPP/RPP/FormAirbusConfig.resx +++ b/RPP/RPP/FormAirbusConfig.resx @@ -18,7 +18,7 @@ System.Resources.ResXResourceReader, System.Windows.Forms, ... System.Resources.ResXResourceWriter, System.Windows.Forms, ... this is my long stringthis is a comment - Blue + Blue [base64 mime encoded serialized .NET Framework object] diff --git a/RPP/RPP/Program.cs b/RPP/RPP/Program.cs index 580378d..e843f14 100644 --- a/RPP/RPP/Program.cs +++ b/RPP/RPP/Program.cs @@ -1,18 +1,42 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Serilog; +using System; namespace RPP { internal static class Program { - /// - /// The main entry point for the application. - /// [STAThread] static void Main() { - // To customize application configuration such as set high DPI settings or default font, - // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormAirbusCollection()); + var services = new ServiceCollection(); + ConfigureServices(services); + using (ServiceProvider serviceProvider = services.BuildServiceProvider()) + { + Application.Run(serviceProvider.GetRequiredService()); + } + + } + + private static void ConfigureServices(ServiceCollection services) + { + services.AddSingleton().AddLogging(option => + { + string[] path = Directory.GetCurrentDirectory().Split('\\'); + string pathNeed = ""; + for (int i = 0; i < path.Length - 3; i++) + { + pathNeed += path[i] + "\\"; + } + var configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile(path: $"{pathNeed}appsettings.json", optional: false, reloadOnChange: true).Build(); + var logger = new LoggerConfiguration().ReadFrom.Configuration(configuration).CreateLogger(); + + option.SetMinimumLevel(LogLevel.Information); + option.AddSerilog(logger); + }); } } -} \ No newline at end of file +} diff --git a/RPP/RPP/RPP.csproj b/RPP/RPP/RPP.csproj index 13ee123..834e6c4 100644 --- a/RPP/RPP/RPP.csproj +++ b/RPP/RPP/RPP.csproj @@ -8,6 +8,17 @@ enable + + + + + + + + + + + True diff --git a/RPP/RPP/SetGeneric.cs b/RPP/RPP/SetGeneric.cs index 8a81e38..d12f677 100644 --- a/RPP/RPP/SetGeneric.cs +++ b/RPP/RPP/SetGeneric.cs @@ -29,11 +29,11 @@ namespace RPP.Generics if (position < 0 || position >= _maxCount) { - return false; + throw new AirbusNotFoundException(position); } if (Count >= _maxCount) { - return false; + throw new StorageOverflowException(position); } _places.Insert(0, airbus); @@ -43,14 +43,8 @@ namespace RPP.Generics public bool Remove(int position) { - if (position < 0 || position > _maxCount) - { - return false; - } - if (position >= Count) - { - return false; - } + if (position < 0 || position > _maxCount || position >= Count) + throw new AirbusNotFoundException(position); _places.RemoveAt(position); return true; } diff --git a/RPP/RPP/StorageOverflowException.cs b/RPP/RPP/StorageOverflowException.cs new file mode 100644 index 0000000..17999c3 --- /dev/null +++ b/RPP/RPP/StorageOverflowException.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace RPP +{ + internal class StorageOverflowException : ApplicationException + { + public StorageOverflowException(int count) : base($"В наборе превышено допустимое количество: {count}") { } + public StorageOverflowException() : base() { } + public StorageOverflowException(string message) : base(message) { } + public StorageOverflowException(string message, Exception exception) : base(message, exception) { } + protected StorageOverflowException(SerializationInfo info, StreamingContext contex) : base(info, contex) { } + } +} diff --git a/RPP/RPP/appsettings.json b/RPP/RPP/appsettings.json new file mode 100644 index 0000000..359a9c2 --- /dev/null +++ b/RPP/RPP/appsettings.json @@ -0,0 +1,20 @@ +{ + "Serilog": { + "Using": [ "Serilog.Sinks.File" ], + "MinimumLevel": "Information", + "WriteTo": [ + { + "Name": "File", + "Args": { + "path": "Logs/log_.log", + "rollingInterval": "Day", + "outputTemplate": "[{Timestamp:HH:mm:ss.fff}]{Level:u4}: {Message:lj}{NewLine}{Exception}" + } + } + ], + "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ], + "Properties": { + "Application": "GasolineTanker" + } + } +} \ No newline at end of file diff --git a/RPP/RPP/nlog.config b/RPP/RPP/nlog.config new file mode 100644 index 0000000..54e4ba6 --- /dev/null +++ b/RPP/RPP/nlog.config @@ -0,0 +1,13 @@ + + + + + + + + + + + \ No newline at end of file