PIbd-23 Firsov Kirill LabWork 04 #23
@ -14,32 +14,112 @@ using ProjectTractor.MovementStrategy;
|
||||
namespace ProjectTractor
|
||||
{
|
||||
public partial class FormTractorCollection : Form
|
||||
{
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Набор объектов
|
||||
/// </summary>
|
||||
private readonly TractorsGenericCollection<DrawningTractor,
|
||||
DrawningObjectTractor> _tractors;
|
||||
private readonly TractorsGenericStorage _storage;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormTractorCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_tractors = new TractorsGenericCollection<DrawningTractor,
|
||||
DrawningObjectTractor>(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
_storage = new TractorsGenericStorage(pictureBoxCollection.Width,
|
||||
pictureBoxCollection.Height);
|
||||
}
|
||||
/// <summary>
|
||||
/// Заполнение listBoxObjects
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление набора в коллекцию
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
///
|
||||
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();
|
||||
}
|
||||
/// <summary>
|
||||
/// Выбор набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ListBoxObjects_SelectedIndexChanged(object sender,
|
||||
EventArgs e)
|
||||
{
|
||||
pictureBoxCollection.Image =
|
||||
_storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowTractors();
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonDelObject_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();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddTractor_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormTractor form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_tractors + form.SelectedTractor)
|
||||
if (obj + form.SelectedTractor)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = _tractors.ShowTractors();
|
||||
pictureBoxCollection.Image = obj.ShowTractors();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -55,16 +135,26 @@ namespace ProjectTractor
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRemoveTractor_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 = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||
if (_tractors - pos)
|
||||
if (obj - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxCollection.Image = _tractors.ShowTractors();
|
||||
pictureBoxCollection.Image = obj.ShowTractors();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -76,25 +166,34 @@ namespace ProjectTractor
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRefreshCollection_Click(object sender, EventArgs
|
||||
e)
|
||||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
pictureBoxCollection.Image = _tractors.ShowTractors();
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||
string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBoxCollection.Image = obj.ShowTractors();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
|
||||
this.groupBox = new System.Windows.Forms.GroupBox();
|
||||
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
this.ButtonDelObject = new System.Windows.Forms.Button();
|
||||
this.listBoxStorages = new System.Windows.Forms.ListBox();
|
||||
this.ButtonAddObject = new System.Windows.Forms.Button();
|
||||
this.textBoxStorageName = new System.Windows.Forms.MaskedTextBox();
|
||||
this.ButtonRefreshCollection = new System.Windows.Forms.Button();
|
||||
this.ButtonRemoveTractor = new System.Windows.Forms.Button();
|
||||
this.ButtonAddTractor = new System.Windows.Forms.Button();
|
||||
this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox();
|
||||
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
this.maskedTextBox1 = new System.Windows.Forms.MaskedTextBox();
|
||||
this.button1 = new System.Windows.Forms.Button();
|
||||
this.listBoxStorages = new System.Windows.Forms.ListBox();
|
||||
this.button2 = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
|
||||
this.groupBox.SuspendLayout();
|
||||
this.groupBox1.SuspendLayout();
|
||||
@ -123,6 +222,53 @@ namespace ProjectTractor
|
||||
this.groupBox.TabStop = false;
|
||||
this.groupBox.Text = "Инструменты";
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
this.groupBox1.Controls.Add(this.ButtonDelObject);
|
||||
this.groupBox1.Controls.Add(this.listBoxStorages);
|
||||
this.groupBox1.Controls.Add(this.ButtonAddObject);
|
||||
this.groupBox1.Controls.Add(this.textBoxStorageName);
|
||||
this.groupBox1.Location = new System.Drawing.Point(16, 29);
|
||||
this.groupBox1.Name = "groupBox1";
|
||||
this.groupBox1.Size = new System.Drawing.Size(224, 279);
|
||||
this.groupBox1.TabIndex = 9;
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "Наборы";
|
||||
//
|
||||
// ButtonDelObject
|
||||
//
|
||||
this.ButtonDelObject.Location = new System.Drawing.Point(12, 227);
|
||||
this.ButtonDelObject.Name = "ButtonDelObject";
|
||||
this.ButtonDelObject.Size = new System.Drawing.Size(203, 35);
|
||||
this.ButtonDelObject.TabIndex = 3;
|
||||
this.ButtonDelObject.Text = "Удалить набор";
|
||||
this.ButtonDelObject.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// listBoxStorages
|
||||
//
|
||||
this.listBoxStorages.FormattingEnabled = true;
|
||||
this.listBoxStorages.ItemHeight = 20;
|
||||
this.listBoxStorages.Location = new System.Drawing.Point(12, 116);
|
||||
this.listBoxStorages.Name = "listBoxStorages";
|
||||
this.listBoxStorages.Size = new System.Drawing.Size(203, 84);
|
||||
this.listBoxStorages.TabIndex = 2;
|
||||
//
|
||||
// ButtonAddObject
|
||||
//
|
||||
this.ButtonAddObject.Location = new System.Drawing.Point(12, 59);
|
||||
this.ButtonAddObject.Name = "ButtonAddObject";
|
||||
this.ButtonAddObject.Size = new System.Drawing.Size(203, 29);
|
||||
this.ButtonAddObject.TabIndex = 1;
|
||||
this.ButtonAddObject.Text = "Добавить набор";
|
||||
this.ButtonAddObject.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// textBoxStorageName
|
||||
//
|
||||
this.textBoxStorageName.Location = new System.Drawing.Point(12, 26);
|
||||
this.textBoxStorageName.Name = "textBoxStorageName";
|
||||
this.textBoxStorageName.Size = new System.Drawing.Size(203, 27);
|
||||
this.textBoxStorageName.TabIndex = 0;
|
||||
//
|
||||
// ButtonRefreshCollection
|
||||
//
|
||||
this.ButtonRefreshCollection.Location = new System.Drawing.Point(28, 464);
|
||||
@ -160,53 +306,6 @@ namespace ProjectTractor
|
||||
this.maskedTextBoxNumber.Size = new System.Drawing.Size(203, 27);
|
||||
this.maskedTextBoxNumber.TabIndex = 5;
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
this.groupBox1.Controls.Add(this.button2);
|
||||
this.groupBox1.Controls.Add(this.listBoxStorages);
|
||||
this.groupBox1.Controls.Add(this.button1);
|
||||
this.groupBox1.Controls.Add(this.maskedTextBox1);
|
||||
this.groupBox1.Location = new System.Drawing.Point(16, 29);
|
||||
this.groupBox1.Name = "groupBox1";
|
||||
this.groupBox1.Size = new System.Drawing.Size(224, 279);
|
||||
this.groupBox1.TabIndex = 9;
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "Наборы";
|
||||
//
|
||||
// maskedTextBox1
|
||||
//
|
||||
this.maskedTextBox1.Location = new System.Drawing.Point(12, 26);
|
||||
this.maskedTextBox1.Name = "maskedTextBox1";
|
||||
this.maskedTextBox1.Size = new System.Drawing.Size(203, 27);
|
||||
this.maskedTextBox1.TabIndex = 0;
|
||||
//
|
||||
// button1
|
||||
//
|
||||
this.button1.Location = new System.Drawing.Point(12, 59);
|
||||
this.button1.Name = "button1";
|
||||
this.button1.Size = new System.Drawing.Size(203, 29);
|
||||
this.button1.TabIndex = 1;
|
||||
this.button1.Text = "Добавить набор";
|
||||
this.button1.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// listBoxStorages
|
||||
//
|
||||
this.listBoxStorages.FormattingEnabled = true;
|
||||
this.listBoxStorages.ItemHeight = 20;
|
||||
this.listBoxStorages.Location = new System.Drawing.Point(12, 116);
|
||||
this.listBoxStorages.Name = "listBoxStorages";
|
||||
this.listBoxStorages.Size = new System.Drawing.Size(203, 84);
|
||||
this.listBoxStorages.TabIndex = 2;
|
||||
//
|
||||
// button2
|
||||
//
|
||||
this.button2.Location = new System.Drawing.Point(12, 227);
|
||||
this.button2.Name = "button2";
|
||||
this.button2.Size = new System.Drawing.Size(203, 35);
|
||||
this.button2.TabIndex = 3;
|
||||
this.button2.Text = "Удалить набор";
|
||||
this.button2.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// FormTractorCollection
|
||||
//
|
||||
this.ClientSize = new System.Drawing.Size(893, 536);
|
||||
@ -232,10 +331,10 @@ namespace ProjectTractor
|
||||
private Button ButtonAddTractor;
|
||||
private MaskedTextBox maskedTextBoxNumber;
|
||||
private GroupBox groupBox1;
|
||||
private Button button2;
|
||||
private Button ButtonDelObject;
|
||||
private ListBox listBoxStorages;
|
||||
private Button button1;
|
||||
private MaskedTextBox maskedTextBox1;
|
||||
private Button ButtonAddObject;
|
||||
private MaskedTextBox textBoxStorageName;
|
||||
private PictureBox pictureBoxCollection;
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user