2023-12-21 21:20:07 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection.Metadata.Ecma335;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using System.Xml.Linq;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using ProjectLainer.DrawningObjects;
|
|
|
|
|
using ProjectLainer.Exceptions;
|
2023-12-08 21:10:19 +04:00
|
|
|
|
using ProjectLainer.Generics;
|
|
|
|
|
using ProjectLainer.MovementStrategy;
|
|
|
|
|
|
|
|
|
|
namespace ProjectLainer
|
|
|
|
|
{
|
|
|
|
|
public partial class FormLainerCollection : Form
|
|
|
|
|
{
|
2023-12-19 18:48:02 +04:00
|
|
|
|
private readonly LainersGenericStorage _storage;
|
2023-12-21 21:20:07 +04:00
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
public FormLainerCollection(ILogger<FormLainerCollection> logger)
|
2023-12-08 21:10:19 +04:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2023-12-21 21:20:07 +04:00
|
|
|
|
_storage = new LainersGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
|
|
|
|
_logger = logger;
|
2023-12-19 18:48:02 +04:00
|
|
|
|
}
|
|
|
|
|
private void ReloadObjects()
|
|
|
|
|
{
|
|
|
|
|
int index = listBoxStorages.SelectedIndex;
|
|
|
|
|
listBoxStorages.Items.Clear();
|
2023-12-19 19:31:20 +04:00
|
|
|
|
foreach (string key in _storage.Keys)
|
|
|
|
|
{
|
|
|
|
|
listBoxStorages.Items.Add(key);
|
|
|
|
|
if (listBoxStorages.Items.Count > 0 && (index == -1 || index >= listBoxStorages.Items.Count))
|
|
|
|
|
{
|
|
|
|
|
listBoxStorages.SelectedIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
else if (listBoxStorages.Items.Count > 0 && index > -1 && index < listBoxStorages.Items.Count)
|
|
|
|
|
{
|
|
|
|
|
listBoxStorages.SelectedIndex = index;
|
|
|
|
|
}
|
2023-12-21 21:20:07 +04:00
|
|
|
|
}
|
2023-12-19 18:48:02 +04:00
|
|
|
|
}
|
|
|
|
|
private void ButtonAddObject_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(textBoxStorageName.Text))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
|
|
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_storage.AddSet(textBoxStorageName.Text);
|
|
|
|
|
ReloadObjects();
|
2023-12-21 21:20:07 +04:00
|
|
|
|
_logger.LogInformation($"Добавлен набор: {textBoxStorageName.Text}");
|
|
|
|
|
|
2023-12-19 18:48:02 +04:00
|
|
|
|
}
|
|
|
|
|
private void ButtonDelObject_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (listBoxStorages.SelectedIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-12-21 21:20:07 +04:00
|
|
|
|
string name = listBoxStorages.SelectedItem.ToString() ?? string.Empty;
|
|
|
|
|
if (MessageBox.Show($"Удалить объект {name}?", "Удаление",
|
|
|
|
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
2023-12-19 18:48:02 +04:00
|
|
|
|
{
|
2023-12-21 21:20:07 +04:00
|
|
|
|
_storage.DelSet(name);
|
2023-12-19 18:48:02 +04:00
|
|
|
|
ReloadObjects();
|
2023-12-21 21:20:07 +04:00
|
|
|
|
_logger.LogInformation($"Удален набор: {name}");
|
2023-12-19 18:48:02 +04:00
|
|
|
|
}
|
2023-12-08 21:10:19 +04:00
|
|
|
|
}
|
|
|
|
|
private void ButtonAddLainer_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-12-19 18:48:02 +04:00
|
|
|
|
if (listBoxStorages.SelectedIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
|
|
|
|
if (obj == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-12-19 19:32:23 +04:00
|
|
|
|
var formLinerConfig = new FormLainerConfig();
|
|
|
|
|
formLinerConfig.AddEvent(AddLainer);
|
|
|
|
|
formLinerConfig.Show();
|
2023-12-08 21:10:19 +04:00
|
|
|
|
}
|
|
|
|
|
private void ButtonRemove_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-12-19 18:48:02 +04:00
|
|
|
|
if (listBoxStorages.SelectedIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-12-21 21:20:07 +04:00
|
|
|
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
2023-12-19 18:48:02 +04:00
|
|
|
|
if (obj == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-12-08 21:10:19 +04:00
|
|
|
|
if (MessageBox.Show("Удалить объект?", "Удаление",
|
|
|
|
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-12-19 18:48:02 +04:00
|
|
|
|
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
2023-12-21 21:20:07 +04:00
|
|
|
|
try
|
2023-12-08 21:10:19 +04:00
|
|
|
|
{
|
2023-12-21 21:20:07 +04:00
|
|
|
|
if (obj - pos != null)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект удален");
|
|
|
|
|
pictureBoxCollection.Image = obj.ShowLainers();
|
|
|
|
|
_logger.LogInformation($"удален лайнер из набора :{listBoxStorages.SelectedItem.ToString() ?? string.Empty}");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не удалось удалить объект");
|
|
|
|
|
}
|
2023-12-08 21:10:19 +04:00
|
|
|
|
}
|
2023-12-21 21:20:07 +04:00
|
|
|
|
catch (LainerNotFoundException ex)
|
2023-12-19 18:48:02 +04:00
|
|
|
|
{
|
2023-12-21 21:20:07 +04:00
|
|
|
|
MessageBox.Show(ex.Message);
|
|
|
|
|
_logger.LogWarning("ошибка лайнер не найден");
|
2023-12-19 18:48:02 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (listBoxStorages.SelectedIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
|
|
|
|
string.Empty];
|
|
|
|
|
if (obj == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
pictureBoxCollection.Image = obj.ShowLainers();
|
2023-12-08 21:10:19 +04:00
|
|
|
|
}
|
2023-12-19 18:48:02 +04:00
|
|
|
|
private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
|
2023-12-08 21:10:19 +04:00
|
|
|
|
{
|
2023-12-19 18:48:02 +04:00
|
|
|
|
pictureBoxCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowLainers();
|
2023-12-08 21:10:19 +04:00
|
|
|
|
}
|
2023-12-21 21:20:07 +04:00
|
|
|
|
private void AddLainer(DrawingLainer lainer)
|
2023-12-19 19:32:23 +04:00
|
|
|
|
{
|
|
|
|
|
if (listBoxStorages.SelectedIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
|
|
|
|
if (obj == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-12-21 21:20:07 +04:00
|
|
|
|
try
|
2023-12-19 19:32:23 +04:00
|
|
|
|
{
|
2023-12-21 21:20:07 +04:00
|
|
|
|
if (obj + lainer)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект добавлен");
|
|
|
|
|
pictureBoxCollection.Image = obj.ShowLainers();
|
|
|
|
|
_logger.LogInformation($"добавлен лайнер в набор: {listBoxStorages.SelectedItem.ToString() ?? string.Empty}");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не удалось добавить объект");
|
|
|
|
|
}
|
2023-12-19 19:32:23 +04:00
|
|
|
|
}
|
2023-12-21 21:20:07 +04:00
|
|
|
|
catch (OverflowException ex)
|
2023-12-19 19:32:23 +04:00
|
|
|
|
{
|
2023-12-21 21:20:07 +04:00
|
|
|
|
MessageBox.Show(ex.Message);
|
|
|
|
|
_logger.LogWarning("ошибка переполнения");
|
2023-12-19 19:32:23 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-19 20:12:51 +04:00
|
|
|
|
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
2023-12-21 21:20:07 +04:00
|
|
|
|
try
|
2023-12-19 20:12:51 +04:00
|
|
|
|
{
|
2023-12-21 21:20:07 +04:00
|
|
|
|
_storage.SaveData(saveFileDialog.FileName);
|
|
|
|
|
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
2023-12-19 20:12:51 +04:00
|
|
|
|
}
|
2023-12-21 21:20:07 +04:00
|
|
|
|
catch (Exception ex)
|
2023-12-19 20:12:51 +04:00
|
|
|
|
{
|
2023-12-21 21:20:07 +04:00
|
|
|
|
MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
2023-12-19 20:12:51 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void LoadToolStripItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
2023-12-21 21:20:07 +04:00
|
|
|
|
try
|
2023-12-19 20:12:51 +04:00
|
|
|
|
{
|
2023-12-21 21:20:07 +04:00
|
|
|
|
_storage.LoadData(openFileDialog.FileName);
|
2023-12-19 20:12:51 +04:00
|
|
|
|
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
foreach (var collection in _storage.Keys)
|
|
|
|
|
{
|
|
|
|
|
listBoxStorages.Items.Add(collection);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-21 21:20:07 +04:00
|
|
|
|
catch (Exception)
|
2023-12-19 20:12:51 +04:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-08 21:10:19 +04:00
|
|
|
|
}
|
|
|
|
|
}
|