PIbd-14 Pruidze_I.K. LabWork06 Simple #6
68
ProjectCruiser/ListGenObj.cs
Normal file
68
ProjectCruiser/ListGenObj.cs
Normal file
@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace ProjectCruiser;
|
||||
|
||||
// Параметризованный набор объектов
|
||||
public class ListGenericObjects<T> : ICollectionGenObj<T>
|
||||
where T : class
|
||||
{
|
||||
// Список объектов, которые храним
|
||||
private readonly List<T?> _collection;
|
||||
|
||||
// Максимально допустимое число объектов в списке
|
||||
private int _maxCount;
|
||||
public int Count => _collection.Count;
|
||||
|
||||
public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } }
|
||||
|
||||
public ListGenericObjects()
|
||||
{
|
||||
_collection = new();
|
||||
}
|
||||
|
||||
public T? GetItem(int position)
|
||||
{
|
||||
if (position > _maxCount - 1 || position < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
public int Insert(T obj)
|
||||
{
|
||||
if (Count + 1 < _maxCount || obj == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
_collection.Add(obj);
|
||||
return Count;
|
||||
}
|
||||
|
||||
public int Insert(T obj, int position)
|
||||
{
|
||||
if (position >= _maxCount || position < 0 ||
|
||||
_collection[position] != null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
_collection.Insert(position, obj);
|
||||
return position;
|
||||
}
|
||||
|
||||
public T? Remove(int position)
|
||||
{
|
||||
if (position >= Count || position < 0)
|
||||
// on the other positions items don't exist
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
T? item = _collection[position];
|
||||
_collection.RemoveAt(position);
|
||||
return item;
|
||||
}
|
||||
}
|
178
ProjectCruiser/ServiceForm2.Designer.cs
generated
178
ProjectCruiser/ServiceForm2.Designer.cs
generated
@ -37,8 +37,20 @@
|
||||
maskedTextBoxPosition = new MaskedTextBox();
|
||||
btnAddCruiser = new Button();
|
||||
pictureBox = new PictureBox();
|
||||
companyPanel = new Panel();
|
||||
label = new Label();
|
||||
maskedTxtBoxCName = new MaskedTextBox();
|
||||
rBtnArray = new RadioButton();
|
||||
rBtnList = new RadioButton();
|
||||
btnAddCollection = new Button();
|
||||
listBox = new ListBox();
|
||||
btnDeleteCollection = new Button();
|
||||
btnCreateCompany = new Button();
|
||||
toolPanel = new Panel();
|
||||
groupBox.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||
companyPanel.SuspendLayout();
|
||||
toolPanel.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// comboBoxArrList
|
||||
@ -46,18 +58,18 @@
|
||||
comboBoxArrList.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
comboBoxArrList.FormattingEnabled = true;
|
||||
comboBoxArrList.Items.AddRange(new object[] { "Storage" });
|
||||
comboBoxArrList.Location = new Point(17, 54);
|
||||
comboBoxArrList.Location = new Point(17, 41);
|
||||
comboBoxArrList.Name = "comboBoxArrList";
|
||||
comboBoxArrList.Size = new Size(268, 40);
|
||||
comboBoxArrList.Size = new Size(243, 40);
|
||||
comboBoxArrList.TabIndex = 0;
|
||||
comboBoxArrList.SelectedIndexChanged += SelectorCompany_SelectedIndexChanged;
|
||||
//
|
||||
// btnAddBase
|
||||
//
|
||||
btnAddBase.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
btnAddBase.Location = new Point(17, 561);
|
||||
btnAddBase.Location = new Point(17, 13);
|
||||
btnAddBase.Name = "btnAddBase";
|
||||
btnAddBase.Size = new Size(268, 46);
|
||||
btnAddBase.Size = new Size(192, 43);
|
||||
btnAddBase.TabIndex = 1;
|
||||
btnAddBase.Text = "Add ship";
|
||||
btnAddBase.UseVisualStyleBackColor = true;
|
||||
@ -66,16 +78,12 @@
|
||||
// groupBox
|
||||
//
|
||||
groupBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
groupBox.Controls.Add(btnUpdate);
|
||||
groupBox.Controls.Add(btnTest);
|
||||
groupBox.Controls.Add(btnDelete);
|
||||
groupBox.Controls.Add(maskedTextBoxPosition);
|
||||
groupBox.Controls.Add(btnAddCruiser);
|
||||
groupBox.Controls.Add(btnAddBase);
|
||||
groupBox.Controls.Add(toolPanel);
|
||||
groupBox.Controls.Add(btnCreateCompany);
|
||||
groupBox.Controls.Add(comboBoxArrList);
|
||||
groupBox.Location = new Point(1437, 12);
|
||||
groupBox.Location = new Point(1402, 12);
|
||||
groupBox.Name = "groupBox";
|
||||
groupBox.Size = new Size(300, 938);
|
||||
groupBox.Size = new Size(275, 986);
|
||||
groupBox.TabIndex = 2;
|
||||
groupBox.TabStop = false;
|
||||
groupBox.Text = "Tool panel";
|
||||
@ -83,9 +91,9 @@
|
||||
// btnUpdate
|
||||
//
|
||||
btnUpdate.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
btnUpdate.Location = new Point(17, 865);
|
||||
btnUpdate.Location = new Point(17, 315);
|
||||
btnUpdate.Name = "btnUpdate";
|
||||
btnUpdate.Size = new Size(268, 46);
|
||||
btnUpdate.Size = new Size(192, 49);
|
||||
btnUpdate.TabIndex = 6;
|
||||
btnUpdate.Text = "Update";
|
||||
btnUpdate.UseVisualStyleBackColor = true;
|
||||
@ -94,20 +102,20 @@
|
||||
// btnTest
|
||||
//
|
||||
btnTest.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
btnTest.Location = new Point(17, 795);
|
||||
btnTest.Location = new Point(17, 224);
|
||||
btnTest.Name = "btnTest";
|
||||
btnTest.Size = new Size(268, 64);
|
||||
btnTest.Size = new Size(192, 85);
|
||||
btnTest.TabIndex = 5;
|
||||
btnTest.Text = "Choose for testing";
|
||||
btnTest.Text = "Choose\r\nfor testing";
|
||||
btnTest.UseVisualStyleBackColor = true;
|
||||
btnTest.Click += btnChooseforTest_Click;
|
||||
//
|
||||
// btnDelete
|
||||
//
|
||||
btnDelete.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
btnDelete.Location = new Point(17, 732);
|
||||
btnDelete.Location = new Point(17, 170);
|
||||
btnDelete.Name = "btnDelete";
|
||||
btnDelete.Size = new Size(268, 46);
|
||||
btnDelete.Size = new Size(192, 48);
|
||||
btnDelete.TabIndex = 4;
|
||||
btnDelete.Text = "Delete";
|
||||
btnDelete.UseVisualStyleBackColor = true;
|
||||
@ -116,19 +124,19 @@
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
maskedTextBoxPosition.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
maskedTextBoxPosition.Location = new Point(17, 682);
|
||||
maskedTextBoxPosition.Location = new Point(17, 119);
|
||||
maskedTextBoxPosition.Mask = "00";
|
||||
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
maskedTextBoxPosition.Size = new Size(268, 39);
|
||||
maskedTextBoxPosition.Size = new Size(192, 39);
|
||||
maskedTextBoxPosition.TabIndex = 3;
|
||||
maskedTextBoxPosition.ValidatingType = typeof(int);
|
||||
//
|
||||
// btnAddCruiser
|
||||
//
|
||||
btnAddCruiser.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
btnAddCruiser.Location = new Point(17, 613);
|
||||
btnAddCruiser.Location = new Point(17, 62);
|
||||
btnAddCruiser.Name = "btnAddCruiser";
|
||||
btnAddCruiser.Size = new Size(268, 46);
|
||||
btnAddCruiser.Size = new Size(192, 51);
|
||||
btnAddCruiser.TabIndex = 2;
|
||||
btnAddCruiser.Text = "Add cruiser";
|
||||
btnAddCruiser.UseVisualStyleBackColor = true;
|
||||
@ -139,22 +147,130 @@
|
||||
pictureBox.Dock = DockStyle.Left;
|
||||
pictureBox.Location = new Point(0, 0);
|
||||
pictureBox.Name = "pictureBox";
|
||||
pictureBox.Size = new Size(1417, 959);
|
||||
pictureBox.Size = new Size(1385, 1007);
|
||||
pictureBox.TabIndex = 3;
|
||||
pictureBox.TabStop = false;
|
||||
//
|
||||
// companyPanel
|
||||
//
|
||||
companyPanel.Controls.Add(btnDeleteCollection);
|
||||
companyPanel.Controls.Add(listBox);
|
||||
companyPanel.Controls.Add(btnAddCollection);
|
||||
companyPanel.Controls.Add(rBtnList);
|
||||
companyPanel.Controls.Add(rBtnArray);
|
||||
companyPanel.Controls.Add(maskedTxtBoxCName);
|
||||
companyPanel.Controls.Add(label);
|
||||
companyPanel.Location = new Point(1419, 101);
|
||||
companyPanel.Name = "panel1";
|
||||
companyPanel.Size = new Size(243, 429);
|
||||
companyPanel.TabIndex = 7;
|
||||
//
|
||||
// label
|
||||
//
|
||||
label.AutoSize = true;
|
||||
label.Location = new Point(29, 6);
|
||||
label.Name = "label";
|
||||
label.Size = new Size(188, 32);
|
||||
label.TabIndex = 0;
|
||||
label.Text = "Collection name";
|
||||
//
|
||||
// maskedTxtBoxCName
|
||||
//
|
||||
maskedTxtBoxCName.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
maskedTxtBoxCName.Location = new Point(16, 43);
|
||||
maskedTxtBoxCName.Name = "maskedTextBox1";
|
||||
maskedTxtBoxCName.Size = new Size(214, 39);
|
||||
maskedTxtBoxCName.TabIndex = 7;
|
||||
//
|
||||
// rBtnArray
|
||||
//
|
||||
rBtnArray.AutoSize = true;
|
||||
rBtnArray.Location = new Point(16, 88);
|
||||
rBtnArray.Name = "rBtnArray";
|
||||
rBtnArray.Size = new Size(100, 36);
|
||||
rBtnArray.TabIndex = 8;
|
||||
rBtnArray.TabStop = true;
|
||||
rBtnArray.Text = "Array";
|
||||
rBtnArray.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// rBtnList
|
||||
//
|
||||
rBtnList.AutoSize = true;
|
||||
rBtnList.Location = new Point(150, 88);
|
||||
rBtnList.Name = "rBtnList";
|
||||
rBtnList.Size = new Size(80, 36);
|
||||
rBtnList.TabIndex = 9;
|
||||
rBtnList.TabStop = true;
|
||||
rBtnList.Text = "List";
|
||||
rBtnList.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// btnAddCollection
|
||||
//
|
||||
btnAddCollection.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
btnAddCollection.Location = new Point(15, 130);
|
||||
btnAddCollection.Name = "btnAddCollection";
|
||||
btnAddCollection.Size = new Size(214, 61);
|
||||
btnAddCollection.TabIndex = 7;
|
||||
btnAddCollection.Text = "Add Collection";
|
||||
btnAddCollection.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// listBox1
|
||||
//
|
||||
listBox.FormattingEnabled = true;
|
||||
listBox.Location = new Point(16, 199);
|
||||
listBox.Name = "listBox1";
|
||||
listBox.Size = new Size(214, 164);
|
||||
listBox.TabIndex = 10;
|
||||
//
|
||||
// btnDeleteCollection
|
||||
//
|
||||
btnDeleteCollection.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
btnDeleteCollection.Location = new Point(15, 371);
|
||||
btnDeleteCollection.Name = "btnDeleteCollection";
|
||||
btnDeleteCollection.Size = new Size(214, 43);
|
||||
btnDeleteCollection.TabIndex = 11;
|
||||
btnDeleteCollection.Text = "Remove Collection";
|
||||
btnDeleteCollection.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// btnCreateCompany
|
||||
//
|
||||
btnCreateCompany.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
btnCreateCompany.Location = new Point(17, 526);
|
||||
btnCreateCompany.Name = "btnCreateCompany";
|
||||
btnCreateCompany.Size = new Size(243, 61);
|
||||
btnCreateCompany.TabIndex = 12;
|
||||
btnCreateCompany.Text = "Create Company";
|
||||
btnCreateCompany.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// toolPanel
|
||||
//
|
||||
toolPanel.Controls.Add(btnUpdate);
|
||||
toolPanel.Controls.Add(btnTest);
|
||||
toolPanel.Controls.Add(maskedTextBoxPosition);
|
||||
toolPanel.Controls.Add(btnDelete);
|
||||
toolPanel.Controls.Add(btnAddCruiser);
|
||||
toolPanel.Controls.Add(btnAddBase);
|
||||
toolPanel.Location = new Point(26, 596);
|
||||
toolPanel.Name = "panel2";
|
||||
toolPanel.Size = new Size(226, 377);
|
||||
toolPanel.TabIndex = 13;
|
||||
//
|
||||
// ServiceForm2
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(13F, 32F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1749, 959);
|
||||
ClientSize = new Size(1689, 1007);
|
||||
Controls.Add(companyPanel);
|
||||
Controls.Add(pictureBox);
|
||||
Controls.Add(groupBox);
|
||||
Name = "ServiceForm2";
|
||||
Text = "ServiceForm2";
|
||||
groupBox.ResumeLayout(false);
|
||||
groupBox.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||
companyPanel.ResumeLayout(false);
|
||||
companyPanel.PerformLayout();
|
||||
toolPanel.ResumeLayout(false);
|
||||
toolPanel.PerformLayout();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
@ -169,5 +285,15 @@
|
||||
private Button btnDelete;
|
||||
private MaskedTextBox maskedTextBoxPosition;
|
||||
private PictureBox pictureBox;
|
||||
private Panel companyPanel;
|
||||
private RadioButton rBtnArray;
|
||||
private MaskedTextBox maskedTxtBoxCName;
|
||||
private Label label;
|
||||
private RadioButton rBtnList;
|
||||
private Button btnAddCollection;
|
||||
private ListBox listBox;
|
||||
private Button btnDeleteCollection;
|
||||
private Button btnCreateCompany;
|
||||
private Panel toolPanel;
|
||||
}
|
||||
}
|
@ -24,14 +24,14 @@ public partial class ServiceForm2 : Form
|
||||
}
|
||||
}
|
||||
|
||||
// Color picker
|
||||
// Color picker (default : random)
|
||||
private static Color pickColor(Random r)
|
||||
{
|
||||
Color cl = Color.FromArgb(r.Next(0, 256), r.Next(0, 256), r.Next(0, 256));
|
||||
Color cl = new Color();
|
||||
ColorDialog dialog = new();
|
||||
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{ cl = dialog.Color; }
|
||||
if (dialog.ShowDialog() == DialogResult.OK) cl = dialog.Color;
|
||||
else Color.FromArgb(r.Next(0, 256), r.Next(0, 256), r.Next(0, 256));
|
||||
|
||||
return cl;
|
||||
}
|
||||
@ -84,7 +84,7 @@ public partial class ServiceForm2 : Form
|
||||
// Удаление объекта
|
||||
private void btnRemoveCar_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)
|
||||
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)
|
||||
|| _company == null) return;
|
||||
|
||||
if (MessageBox.Show("[*] Remove object: Are you sure?", "Remove",
|
||||
@ -135,4 +135,6 @@ public partial class ServiceForm2 : Form
|
||||
}
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
|
||||
// continue
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user