From b3a5559303b3bd6b9eb1c7ef05c95bdf03e547b7 Mon Sep 17 00:00:00 2001 From: KirillFirsof <117719052+KirillFirsof@users.noreply.github.com> Date: Thu, 9 Nov 2023 21:01:58 +0400 Subject: [PATCH 1/6] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormTractorCollection.cs | 91 ++++++++++++++++--- .../RPP_FirstLaba_Tractor/SetGeneric.cs | 61 ++++++++----- .../TractorsGenericCollection.cs | 20 ++-- .../TractorsGenericStorage.cs | 81 +++++++++++++++++ 4 files changed, 206 insertions(+), 47 deletions(-) create mode 100644 RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericStorage.cs diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs index ce60c1b..2d758b7 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs @@ -20,14 +20,14 @@ namespace ProjectTractor /// Набор объектов /// private readonly TractorsGenericCollection _cars; + DrawningObjectTractor> _tractors; /// /// Конструктор /// public FormTractorCollection() { InitializeComponent(); - _cars = new TractorsGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height); } @@ -36,10 +36,10 @@ namespace ProjectTractor FormTractor form = new(); if (form.ShowDialog() == DialogResult.OK) { - if (_cars + form.SelectedTractor) + if (_tractors + form.SelectedTractor) { MessageBox.Show("Объект добавлен"); - pictureBoxCollection.Image = _cars.ShowCars(); + pictureBoxCollection.Image = _tractors.ShowTractors(); } else { @@ -61,10 +61,10 @@ namespace ProjectTractor return; } int pos = Convert.ToInt32(maskedTextBoxNumber.Text); - if (_cars - pos) + if (_tractors - pos) { MessageBox.Show("Объект удален"); - pictureBoxCollection.Image = _cars.ShowCars(); + pictureBoxCollection.Image = _tractors.ShowTractors(); } else { @@ -79,7 +79,7 @@ namespace ProjectTractor private void ButtonRefreshCollection_Click(object sender, EventArgs e) { - pictureBoxCollection.Image = _cars.ShowCars(); + pictureBoxCollection.Image = _tractors.ShowTractors(); } private void InitializeComponent() @@ -90,8 +90,14 @@ namespace ProjectTractor 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(); this.SuspendLayout(); // // pictureBoxCollection @@ -99,28 +105,29 @@ namespace ProjectTractor this.pictureBoxCollection.Dock = System.Windows.Forms.DockStyle.Left; this.pictureBoxCollection.Location = new System.Drawing.Point(0, 0); this.pictureBoxCollection.Name = "pictureBoxCollection"; - this.pictureBoxCollection.Size = new System.Drawing.Size(620, 437); + this.pictureBoxCollection.Size = new System.Drawing.Size(620, 536); this.pictureBoxCollection.TabIndex = 1; this.pictureBoxCollection.TabStop = false; // // groupBox // + this.groupBox.Controls.Add(this.groupBox1); this.groupBox.Controls.Add(this.ButtonRefreshCollection); this.groupBox.Controls.Add(this.ButtonRemoveTractor); this.groupBox.Controls.Add(this.ButtonAddTractor); this.groupBox.Controls.Add(this.maskedTextBoxNumber); this.groupBox.Location = new System.Drawing.Point(626, 12); this.groupBox.Name = "groupBox"; - this.groupBox.Size = new System.Drawing.Size(255, 413); + this.groupBox.Size = new System.Drawing.Size(255, 522); this.groupBox.TabIndex = 2; this.groupBox.TabStop = false; this.groupBox.Text = "Инструменты"; // // ButtonRefreshCollection // - this.ButtonRefreshCollection.Location = new System.Drawing.Point(20, 331); + this.ButtonRefreshCollection.Location = new System.Drawing.Point(28, 464); this.ButtonRefreshCollection.Name = "ButtonRefreshCollection"; - this.ButtonRefreshCollection.Size = new System.Drawing.Size(211, 35); + this.ButtonRefreshCollection.Size = new System.Drawing.Size(203, 35); this.ButtonRefreshCollection.TabIndex = 8; this.ButtonRefreshCollection.Text = "Обновить коллекцию"; this.ButtonRefreshCollection.UseVisualStyleBackColor = true; @@ -128,7 +135,7 @@ namespace ProjectTractor // // ButtonRemoveTractor // - this.ButtonRemoveTractor.Location = new System.Drawing.Point(28, 156); + this.ButtonRemoveTractor.Location = new System.Drawing.Point(28, 390); this.ButtonRemoveTractor.Name = "ButtonRemoveTractor"; this.ButtonRemoveTractor.Size = new System.Drawing.Size(203, 33); this.ButtonRemoveTractor.TabIndex = 7; @@ -138,7 +145,7 @@ namespace ProjectTractor // // ButtonAddTractor // - this.ButtonAddTractor.Location = new System.Drawing.Point(28, 46); + this.ButtonAddTractor.Location = new System.Drawing.Point(28, 317); this.ButtonAddTractor.Name = "ButtonAddTractor"; this.ButtonAddTractor.Size = new System.Drawing.Size(203, 34); this.ButtonAddTractor.TabIndex = 6; @@ -148,14 +155,61 @@ namespace ProjectTractor // // maskedTextBoxNumber // - this.maskedTextBoxNumber.Location = new System.Drawing.Point(28, 113); + this.maskedTextBoxNumber.Location = new System.Drawing.Point(28, 357); this.maskedTextBoxNumber.Name = "maskedTextBoxNumber"; 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, 437); + this.ClientSize = new System.Drawing.Size(893, 536); this.Controls.Add(this.groupBox); this.Controls.Add(this.pictureBoxCollection); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; @@ -166,6 +220,8 @@ namespace ProjectTractor ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit(); this.groupBox.ResumeLayout(false); this.groupBox.PerformLayout(); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); this.ResumeLayout(false); } @@ -175,6 +231,11 @@ namespace ProjectTractor private Button ButtonRemoveTractor; private Button ButtonAddTractor; private MaskedTextBox maskedTextBoxNumber; + private GroupBox groupBox1; + private Button button2; + private ListBox listBoxStorages; + private Button button1; + private MaskedTextBox maskedTextBox1; private PictureBox pictureBoxCollection; } diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs index 6ca1fd8..bf52cc5 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs @@ -12,18 +12,23 @@ namespace ProjectTractor.Generics /// /// Массив объектов, которые храним /// - private readonly T?[] _places; + private readonly List _places; /// /// Количество объектов в массиве /// - public int Count => _places.Length; + public int Count => _places.Count; + /// + /// Максимальное количество объектов в списке + /// + private readonly int _maxCount; /// /// Конструктор /// /// public SetGeneric(int count) { - _places = new T?[count]; + _maxCount = count; + _places = new List(count); } /// /// Добавление объекта в набор @@ -50,20 +55,9 @@ namespace ProjectTractor.Generics /// public bool Insert(T tractor, int position) { - - if (!(position >= 0 && position < Count)) + if (!(position >= 0 && position <= Count && _places.Count < _maxCount)) return false; - if (_places[position] != null) - { - int ind = position; - while (ind < Count && _places[ind] != null) - ind++; - if (ind == Count) - return false; - for (int i = ind - 1; i >= position; i--) - _places[i + 1] = _places[i]; - } - _places[position] = tractor; + _places.Insert(position, tractor); return true; } /// @@ -74,10 +68,8 @@ namespace ProjectTractor.Generics public bool Remove(int position) { if (!(position >= 0 && position < Count)) - { return false; - } - _places[position] = null; + _places.RemoveAt(position); return true; } /// @@ -85,13 +77,36 @@ namespace ProjectTractor.Generics /// /// /// - public T? Get(int position) + public T? this[int position] { - if (!(position >= 0 && position < Count)) + get { - return null; + if (!(position >= 0 && position <= Count)) + return null; + return _places[position]; + } + set + { + if (!(position >= 0 && position <= Count)) + return; + _places.Insert(position, value); } - return _places[position]; } + /// + /// Проход по списку + /// + /// + public IEnumerable GetCars(int? maxTractors = null) + { + for (int i = 0; i < _places.Count; ++i) + { + yield return _places[i]; + if (maxTractors.HasValue && i == maxTractors.Value) + { + yield break; + } + } + } + } } diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs index 2bec09d..54f0f69 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs @@ -71,9 +71,10 @@ namespace ProjectTractor.Generics /// /// /// - public static bool operator -(TractorsGenericCollection collect, int pos) + public static bool operator -(TractorsGenericCollection collect, int + pos) { - T? obj = collect._collection.Get(pos); + T? obj = collect._collection[pos]; if (obj != null) { collect._collection.Remove(pos); @@ -87,13 +88,13 @@ namespace ProjectTractor.Generics /// public U? GetU(int pos) { - return (U?)_collection.Get(pos)?.GetMoveableObject; + return (U?)_collection[pos]?.GetMoveableObject; } /// /// Вывод всего набора объектов /// /// - public Bitmap ShowCars() + public Bitmap ShowTractors() { Bitmap bmp = new(_pictureWidth, _pictureHeight); Graphics gr = Graphics.FromImage(bmp); @@ -121,21 +122,22 @@ namespace ProjectTractor.Generics _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight); } } + /// /// Метод прорисовки объектов /// /// private void DrawObjects(Graphics g) { - for (int i = 0; i < _collection.Count; i++) + int i = 0; + foreach (var tractor in _collection.GetCars()) { - - DrawningTractor? tractor = _collection.Get(i); if (tractor != null) { - int countRows = _pictureWidth / _placeSizeWidth; - tractor.SetPosition(_pictureWidth - _placeSizeWidth*2 - (i % countRows * _placeSizeWidth) + 20, _pictureHeight - i / countRows * _placeSizeHeight - 150); + int inRow = _pictureWidth / _placeSizeWidth; + tractor.SetPosition(_pictureWidth - _placeSizeWidth - (i % inRow * _placeSizeWidth) - _placeSizeHeight / 2 - 8, i / inRow * _placeSizeHeight + 20); tractor.DrawTransport(g); } + i++; } } } diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericStorage.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericStorage.cs new file mode 100644 index 0000000..14ed5b5 --- /dev/null +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericStorage.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectTractor.DrawningObjects; +using ProjectTractor.MovementStrategy; +using ProjectTractor.Generics; + +namespace ProjectTractor +{ + /// + /// Класс для хранения коллекции + /// + internal class TractorsGenericStorage + { + /// + /// Словарь (хранилище) + /// + readonly Dictionary> _tractorStorages; + /// + /// Возвращение списка названий наборов + /// + public List Keys => _tractorStorages.Keys.ToList(); + /// + /// Ширина окна отрисовки + /// + private readonly int _pictureWidth; + /// + /// Высота окна отрисовки + /// + private readonly int _pictureHeight; + /// + /// Конструктор + /// + /// + /// + public TractorsGenericStorage(int pictureWidth, int pictureHeight) + { + _tractorStorages = new Dictionary>(); + _pictureWidth = pictureWidth; + _pictureHeight = pictureHeight; + } + /// + /// Добавление набора + /// + /// Название набора + public void AddSet(string name) + { + _tractorStorages.Add(name, + new TractorsGenericCollection(_pictureWidth, _pictureHeight)); + } + /// + /// Удаление набора + /// + /// Название набора + public void DelSet(string name) + { + if (!_tractorStorages.ContainsKey(name)) + return; + _tractorStorages.Remove(name); + } + /// + /// Доступ к набору + /// + /// + /// + public TractorsGenericCollection? + this[string ind] + { + get + { + if (_tractorStorages.ContainsKey(ind)) + return _tractorStorages[ind]; + return null; + } + } + } +} From 988e9bf8d6b7b2face3b0234f9dc44a0f769ff9e Mon Sep 17 00:00:00 2001 From: KirillFirsof <117719052+KirillFirsof@users.noreply.github.com> Date: Thu, 9 Nov 2023 21:34:06 +0400 Subject: [PATCH 2/6] =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20?= =?UTF-8?q?=D1=81=20=D1=84=D0=BE=D1=80=D0=BC=D0=BE=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormTractorCollection.cs | 233 +++++++++++++----- 1 file changed, 166 insertions(+), 67 deletions(-) diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs index 2d758b7..2c883d3 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs @@ -14,32 +14,112 @@ using ProjectTractor.MovementStrategy; namespace ProjectTractor { public partial class FormTractorCollection : Form - { + { /// /// Набор объектов /// - private readonly TractorsGenericCollection _tractors; + private readonly TractorsGenericStorage _storage; /// /// Конструктор /// public FormTractorCollection() { InitializeComponent(); - _tractors = new TractorsGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height); + _storage = new TractorsGenericStorage(pictureBoxCollection.Width, + pictureBoxCollection.Height); + } + /// + /// Заполнение listBoxObjects + /// + 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 ButtonAddObject_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxStorageName.Text)) + { + MessageBox.Show("Не все данные заполнены", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _storage.AddSet(textBoxStorageName.Text); + ReloadObjects(); + } + /// + /// Выбор набора + /// + /// + /// + private void ListBoxObjects_SelectedIndexChanged(object sender, + EventArgs e) + { + pictureBoxCollection.Image = + _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowTractors(); + } + /// + /// Удаление набора + /// + /// + /// + 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(); + } } + /// + /// Добавление объекта в набор + /// + /// + /// 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 /// 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 /// /// /// - 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; } From c06691432d0ab3ec1f56bbf67b27d01c77804740 Mon Sep 17 00:00:00 2001 From: KirillFirsof <117719052+KirillFirsof@users.noreply.github.com> Date: Thu, 9 Nov 2023 21:54:25 +0400 Subject: [PATCH 3/6] =?UTF-8?q?=D0=BA=D0=BE=D0=BC=D0=BC=D0=B8=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RPP_FirstLaba_Tractor/FormTractorCollection.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs index 2c883d3..e8c12e9 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs @@ -243,6 +243,7 @@ namespace ProjectTractor this.ButtonDelObject.TabIndex = 3; this.ButtonDelObject.Text = "Удалить набор"; this.ButtonDelObject.UseVisualStyleBackColor = true; + this.ButtonDelObject.Click += new System.EventHandler(this.ButtonDelObject_Click); // // listBoxStorages // @@ -261,6 +262,7 @@ namespace ProjectTractor this.ButtonAddObject.TabIndex = 1; this.ButtonAddObject.Text = "Добавить набор"; this.ButtonAddObject.UseVisualStyleBackColor = true; + this.ButtonAddObject.Click += new System.EventHandler(this.ButtonAddObject_Click); // // textBoxStorageName // @@ -337,5 +339,6 @@ namespace ProjectTractor private MaskedTextBox textBoxStorageName; private PictureBox pictureBoxCollection; + } } From caaf1bf16211fbc7ce61f5e906f9c319fd5b1471 Mon Sep 17 00:00:00 2001 From: KirillFirsof <117719052+KirillFirsof@users.noreply.github.com> Date: Fri, 10 Nov 2023 08:32:07 +0400 Subject: [PATCH 4/6] =?UTF-8?q?=D0=9A=D0=BE=D0=BD=D0=B5=D1=86=20=D1=87?= =?UTF-8?q?=D0=B5=D1=82=D0=B2=D0=B5=D1=80=D1=82=D0=BE=D0=B9=20=D0=BB=D0=B0?= =?UTF-8?q?=D0=B1=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RPP_FirstLaba_Tractor/DrawningTractor.cs | 2 +- .../RPP_FirstLaba_Tractor/SetGeneric.cs | 15 +++++---------- .../TractorsGenericCollection.cs | 8 ++++---- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawningTractor.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawningTractor.cs index 578ec20..99015c2 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawningTractor.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawningTractor.cs @@ -81,7 +81,7 @@ namespace ProjectTractor.DrawningObjects { } /// - /// Получение объекта IMoveableObject из объекта DrawningCar + /// Получение объекта IMoveableObject из объекта DrawningTractor /// public IMoveableObject GetMoveableObject => new DrawningObjectTractor(this); diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs index bf52cc5..37df499 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs @@ -37,20 +37,15 @@ namespace ProjectTractor.Generics /// public bool Insert(T tractor) { - if (_places[0] == null) - { - _places[0] = tractor; - } - else - { - return Insert(tractor, 0); - } + if (_places.Count == _maxCount) + return false; + Insert(tractor, 0); return true; } /// /// Добавление объекта в набор на конкретную позицию /// - /// Добавляемый автомобиль + /// Добавляемый автомобиль /// Позиция /// public bool Insert(T tractor, int position) @@ -96,7 +91,7 @@ namespace ProjectTractor.Generics /// Проход по списку /// /// - public IEnumerable GetCars(int? maxTractors = null) + public IEnumerable GetTractors(int? maxTractors = null) { for (int i = 0; i < _places.Count; ++i) { diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs index 54f0f69..d978071 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs @@ -9,7 +9,7 @@ using ProjectTractor.MovementStrategy; namespace ProjectTractor.Generics { /// - /// Параметризованный класс для набора объектов DrawningCar + /// Параметризованный класс для набора объектов DrawningTractor /// /// /// @@ -129,12 +129,12 @@ namespace ProjectTractor.Generics private void DrawObjects(Graphics g) { int i = 0; - foreach (var tractor in _collection.GetCars()) + foreach (var tractor in _collection.GetTractors()) { if (tractor != null) { - int inRow = _pictureWidth / _placeSizeWidth; - tractor.SetPosition(_pictureWidth - _placeSizeWidth - (i % inRow * _placeSizeWidth) - _placeSizeHeight / 2 - 8, i / inRow * _placeSizeHeight + 20); + int countRows = _pictureWidth / _placeSizeWidth; + tractor.SetPosition(_pictureWidth - _placeSizeWidth * 2 - (i % countRows * _placeSizeWidth) + 20, _pictureHeight - i / countRows * _placeSizeHeight - 160); tractor.DrawTransport(g); } i++; From 78d95849d236beb314002908ce1f0f8c0f9998fe Mon Sep 17 00:00:00 2001 From: Kirill <117719052+KirillFirsof@users.noreply.github.com> Date: Thu, 23 Nov 2023 13:20:47 +0400 Subject: [PATCH 5/6] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=D0=B8=D1=80=D1=83?= =?UTF-8?q?=D1=8E=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RPP_FirstLaba_Tractor/FormTractorCollection.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs index e8c12e9..95a0047 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs @@ -73,7 +73,7 @@ namespace ProjectTractor /// /// /// - private void ListBoxObjects_SelectedIndexChanged(object sender, + private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e) { pictureBoxCollection.Image = @@ -253,6 +253,7 @@ namespace ProjectTractor this.listBoxStorages.Name = "listBoxStorages"; this.listBoxStorages.Size = new System.Drawing.Size(203, 84); this.listBoxStorages.TabIndex = 2; + this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.listBoxStorages_SelectedIndexChanged); // // ButtonAddObject // From 618799ec778fea1230c8236b084ff5b7b940d117 Mon Sep 17 00:00:00 2001 From: Kirill <117719052+KirillFirsof@users.noreply.github.com> Date: Thu, 7 Dec 2023 14:48:31 +0400 Subject: [PATCH 6/6] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D1=8F=D1=8E=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8=20=D0=B2=20?= =?UTF-8?q?=D0=BF=D1=83=D0=BB=D0=B5=20=D0=9F=D0=BE=D0=BF=D1=8B=D1=82=D0=BA?= =?UTF-8?q?=D0=B0=20=E2=84=96764685?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RPP_FirstLaba_Tractor/FormTractorCollection.cs | 6 +++--- .../RPP_FirstLaba_Tractor/TractorsGenericCollection.cs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs index 95a0047..e769e02 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs @@ -204,7 +204,7 @@ namespace ProjectTractor this.pictureBoxCollection.Dock = System.Windows.Forms.DockStyle.Left; this.pictureBoxCollection.Location = new System.Drawing.Point(0, 0); this.pictureBoxCollection.Name = "pictureBoxCollection"; - this.pictureBoxCollection.Size = new System.Drawing.Size(620, 536); + this.pictureBoxCollection.Size = new System.Drawing.Size(675, 536); this.pictureBoxCollection.TabIndex = 1; this.pictureBoxCollection.TabStop = false; // @@ -215,7 +215,7 @@ namespace ProjectTractor this.groupBox.Controls.Add(this.ButtonRemoveTractor); this.groupBox.Controls.Add(this.ButtonAddTractor); this.groupBox.Controls.Add(this.maskedTextBoxNumber); - this.groupBox.Location = new System.Drawing.Point(626, 12); + this.groupBox.Location = new System.Drawing.Point(681, 12); this.groupBox.Name = "groupBox"; this.groupBox.Size = new System.Drawing.Size(255, 522); this.groupBox.TabIndex = 2; @@ -311,7 +311,7 @@ namespace ProjectTractor // // FormTractorCollection // - this.ClientSize = new System.Drawing.Size(893, 536); + this.ClientSize = new System.Drawing.Size(948, 536); this.Controls.Add(this.groupBox); this.Controls.Add(this.pictureBoxCollection); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs index d978071..5563000 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs @@ -134,7 +134,7 @@ namespace ProjectTractor.Generics if (tractor != null) { int countRows = _pictureWidth / _placeSizeWidth; - tractor.SetPosition(_pictureWidth - _placeSizeWidth * 2 - (i % countRows * _placeSizeWidth) + 20, _pictureHeight - i / countRows * _placeSizeHeight - 160); + tractor.SetPosition(_pictureWidth - _placeSizeWidth * 2 - (i % countRows * _placeSizeWidth) + 190, _pictureHeight - i / countRows * _placeSizeHeight - 160); tractor.DrawTransport(g); } i++;