191 lines
5.3 KiB
C#
191 lines
5.3 KiB
C#
using Monorail.DrawningObjects;
|
||
using Monorail.Generics;
|
||
using Monorail.MovementStrategy;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Data;
|
||
using System.Drawing;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Forms;
|
||
|
||
|
||
namespace Cruiser
|
||
{
|
||
public partial class FormCruiserCollection : Form
|
||
{
|
||
private readonly MonorailGenericStorage _storage;
|
||
|
||
public FormCruiserCollection()
|
||
{
|
||
InitializeComponent();
|
||
_storage = new MonorailGenericStorage(pictureBox1.Width, pictureBox1.Height);
|
||
}
|
||
|
||
private void pictureBox1_Click(object sender, EventArgs e)
|
||
{
|
||
|
||
}
|
||
|
||
|
||
private void ButtonAddCruiser_Click(object sender, EventArgs e)
|
||
{
|
||
if (listBoxStorages.SelectedIndex == -1)
|
||
{
|
||
return;
|
||
}
|
||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||
string.Empty];
|
||
if (obj == null)
|
||
{
|
||
return;
|
||
}
|
||
CruiserForm form = new();
|
||
|
||
|
||
|
||
|
||
if (form.ShowDialog() == DialogResult.OK)
|
||
{
|
||
if (obj + form.SelectedCar != null)
|
||
{
|
||
MessageBox.Show("Объект добавлен");
|
||
pictureBox1.Image = obj.ShowMonorails();
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("Не удалось добавить объект");
|
||
}
|
||
}
|
||
}
|
||
private void ReloadObjects()
|
||
{
|
||
int index = listBoxStorages.SelectedIndex;
|
||
|
||
listBoxStorages.Items.Clear();
|
||
for (int i = 0; i < _storage.Keys.Count; i++)
|
||
{
|
||
listBoxStorages.Items.Add(_storage.Keys[i]);
|
||
}
|
||
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;
|
||
}
|
||
|
||
}
|
||
|
||
private void ButtonRemoveCar_Click(object sender, EventArgs e)
|
||
{
|
||
if (listBoxStorages.SelectedIndex == -1)
|
||
{
|
||
return;
|
||
}
|
||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||
string.Empty];
|
||
if (obj == null)
|
||
{
|
||
return;
|
||
}
|
||
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||
{
|
||
return;
|
||
}
|
||
int pos;
|
||
if (textBox1.Text == null || !int.TryParse(textBox1.Text, out pos))
|
||
{
|
||
MessageBox.Show("Введите номер парковочного места");
|
||
return;
|
||
}
|
||
|
||
if (obj - pos != null)
|
||
{
|
||
MessageBox.Show("Объект удален");
|
||
pictureBox1.Image = obj.ShowMonorails();
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("Не удалось удалить объект");
|
||
}
|
||
|
||
}
|
||
|
||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||
{
|
||
// pictureBox1.Image = obj.ShowMonorails();
|
||
}
|
||
|
||
private void maskedTextBoxNumber_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
|
||
{
|
||
|
||
}
|
||
|
||
private void textBox1_TextChanged(object sender, EventArgs e)
|
||
{
|
||
|
||
}
|
||
|
||
private void button1_Click(object sender, EventArgs e)
|
||
{
|
||
if (listBoxStorages.SelectedIndex == -1)
|
||
{
|
||
return;
|
||
}
|
||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||
string.Empty];
|
||
if (obj == null)
|
||
{
|
||
return;
|
||
}
|
||
pictureBox1.Image = obj.ShowMonorails();
|
||
|
||
|
||
}
|
||
|
||
private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
|
||
{
|
||
pictureBox1.Image =
|
||
_storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowMonorails();
|
||
}
|
||
|
||
private void delStorageButton_Click(object sender, EventArgs e)
|
||
{
|
||
if (listBoxStorages.SelectedIndex == -1)
|
||
{
|
||
return;
|
||
}
|
||
if (MessageBox.Show($"Удалить объект{listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo,
|
||
MessageBoxIcon.Question) == DialogResult.Yes)
|
||
{
|
||
_storage.DelSet(listBoxStorages.SelectedItem.ToString()
|
||
?? string.Empty);
|
||
ReloadObjects();
|
||
}
|
||
|
||
}
|
||
|
||
private void addStorageButton_Click(object sender, EventArgs e)
|
||
{
|
||
if (string.IsNullOrEmpty(textBox1.Text))
|
||
{
|
||
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
return;
|
||
}
|
||
_storage.AddSet(textBox1.Text);
|
||
ReloadObjects();
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|