Добавлено контекстное меню к панели автомобилей

This commit is contained in:
MisterMLiL 2024-10-08 14:41:32 +03:00
parent 3e04430a86
commit a7e5c55a5d
13 changed files with 648 additions and 58 deletions

View File

@ -36,15 +36,15 @@
this.MoneyTextBox = new System.Windows.Forms.TextBox();
this.MoneyLabel = new System.Windows.Forms.Label();
this.ClassPanel = new System.Windows.Forms.Panel();
this.ClassTextBox = new System.Windows.Forms.TextBox();
this.ClassLabel = new System.Windows.Forms.Label();
this.NamePanel = new System.Windows.Forms.Panel();
this.ManufacturerLabel = new System.Windows.Forms.Label();
this.NameLabel = new System.Windows.Forms.Label();
this.ModelPanel = new System.Windows.Forms.Panel();
this.ModelTextBox = new System.Windows.Forms.TextBox();
this.ModelLabel = new System.Windows.Forms.Label();
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
this.ModelTextBox = new System.Windows.Forms.TextBox();
this.ClassTextBox = new System.Windows.Forms.TextBox();
this.MainPanel.SuspendLayout();
this.PhotoPanel.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.PhotoBox)).BeginInit();
@ -136,6 +136,18 @@
this.ClassPanel.Size = new System.Drawing.Size(210, 17);
this.ClassPanel.TabIndex = 2;
//
// ClassTextBox
//
this.ClassTextBox.BackColor = System.Drawing.Color.White;
this.ClassTextBox.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.ClassTextBox.Dock = System.Windows.Forms.DockStyle.Top;
this.ClassTextBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
this.ClassTextBox.Location = new System.Drawing.Point(48, 0);
this.ClassTextBox.Name = "ClassTextBox";
this.ClassTextBox.ReadOnly = true;
this.ClassTextBox.Size = new System.Drawing.Size(160, 15);
this.ClassTextBox.TabIndex = 3;
//
// ClassLabel
//
this.ClassLabel.AutoSize = true;
@ -195,6 +207,18 @@
this.ModelPanel.Size = new System.Drawing.Size(210, 17);
this.ModelPanel.TabIndex = 0;
//
// ModelTextBox
//
this.ModelTextBox.BackColor = System.Drawing.Color.White;
this.ModelTextBox.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.ModelTextBox.Dock = System.Windows.Forms.DockStyle.Top;
this.ModelTextBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
this.ModelTextBox.Location = new System.Drawing.Point(60, 0);
this.ModelTextBox.Name = "ModelTextBox";
this.ModelTextBox.ReadOnly = true;
this.ModelTextBox.Size = new System.Drawing.Size(148, 15);
this.ModelTextBox.TabIndex = 2;
//
// ModelLabel
//
this.ModelLabel.AutoSize = true;
@ -211,30 +235,6 @@
this.contextMenuStrip1.Name = "contextMenuStrip1";
this.contextMenuStrip1.Size = new System.Drawing.Size(61, 4);
//
// ModelTextBox
//
this.ModelTextBox.BackColor = System.Drawing.Color.White;
this.ModelTextBox.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.ModelTextBox.Dock = System.Windows.Forms.DockStyle.Top;
this.ModelTextBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
this.ModelTextBox.Location = new System.Drawing.Point(60, 0);
this.ModelTextBox.Name = "ModelTextBox";
this.ModelTextBox.ReadOnly = true;
this.ModelTextBox.Size = new System.Drawing.Size(148, 15);
this.ModelTextBox.TabIndex = 2;
//
// ClassTextBox
//
this.ClassTextBox.BackColor = System.Drawing.Color.White;
this.ClassTextBox.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.ClassTextBox.Dock = System.Windows.Forms.DockStyle.Top;
this.ClassTextBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
this.ClassTextBox.Location = new System.Drawing.Point(48, 0);
this.ClassTextBox.Name = "ClassTextBox";
this.ClassTextBox.ReadOnly = true;
this.ClassTextBox.Size = new System.Drawing.Size(160, 15);
this.ClassTextBox.TabIndex = 3;
//
// CarItem
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

View File

@ -11,18 +11,46 @@ namespace GtaVUsersInfo.Controls
public partial class CarItem : UserControl
{
private static readonly HttpClient httpClient = new HttpClient();
private Car car;
public Car Car
{
get { return car; }
set { car = value; }
}
public ContextMenuStrip MenuStrip
{
get { return ContextMenuStrip; }
set { ContextMenuStrip = value; }
}
public CarItem(Car carItem)
{
InitializeComponent();
NameLabel.Text = carItem.Name;
ManufacturerLabel.Text = carItem.Manufacturer;
ClassTextBox.Text = carItem.Class;
ModelTextBox.Text = carItem.Model;
MoneyTextBox.Text = '$' + carItem.Price.ToString();
Car = carItem;
LoadImageAsync(carItem.Photo);
NameLabel.Text = Car.Name;
ManufacturerLabel.Text = Car.Manufacturer;
ClassTextBox.Text = Car.Class;
ModelTextBox.Text = Car.Model;
MoneyTextBox.Text = '$' + Car.Price.ToString();
LoadImageAsync(Car.Photo);
}
public void EditCar(Car car)
{
Car = car;
NameLabel.Text = Car.Name;
ManufacturerLabel.Text = Car.Manufacturer;
ClassTextBox.Text = Car.Class;
ModelTextBox.Text = Car.Model;
MoneyTextBox.Text = '$' + Car.Price.ToString();
LoadImageAsync(Car.Photo);
}
private async void LoadImageAsync(string imageUrl)
@ -66,6 +94,7 @@ namespace GtaVUsersInfo.Controls
private void carPrice_Leave(object sender, EventArgs e)
{
Car.Price = int.Parse((sender as TextBox).Text);
(sender as TextBox).Text = '$' + (sender as TextBox).Text;
}

84
Controls/CarItemMenuStrip.Designer.cs generated Normal file
View File

@ -0,0 +1,84 @@
namespace GtaVUsersInfo.Controls
{
partial class CarItemMenuStrip
{
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.myMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
this.addNewToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.editToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.deleteToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.myMenuStrip.SuspendLayout();
this.SuspendLayout();
//
// myMenuStrip
//
this.myMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.addNewToolStripMenuItem,
this.editToolStripMenuItem,
this.deleteToolStripMenuItem});
this.myMenuStrip.Name = "contextMenuStrip";
this.myMenuStrip.Size = new System.Drawing.Size(181, 92);
//
// addNewToolStripMenuItem
//
this.addNewToolStripMenuItem.Name = "addNewToolStripMenuItem";
this.addNewToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.addNewToolStripMenuItem.Text = "Создать";
//
// editToolStripMenuItem
//
this.editToolStripMenuItem.Name = "editToolStripMenuItem";
this.editToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.editToolStripMenuItem.Text = "Изменить";
//
// deleteToolStripMenuItem
//
this.deleteToolStripMenuItem.Name = "deleteToolStripMenuItem";
this.deleteToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.deleteToolStripMenuItem.Text = "Удалить";
//
// CarMenuStrip
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Name = "CarMenuStrip";
this.Size = new System.Drawing.Size(158, 245);
this.myMenuStrip.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.ContextMenuStrip myMenuStrip;
private System.Windows.Forms.ToolStripMenuItem addNewToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem editToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem deleteToolStripMenuItem;
}
}

View File

@ -0,0 +1,37 @@
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 GtaVUsersInfo.Controls
{
public partial class CarItemMenuStrip : UserControl
{
public ContextMenuStrip Menu
{
get { return myMenuStrip; }
}
public CarItem Car;
public CarItemMenuStrip(EventHandler add, EventHandler edit, EventHandler delete, CarItem car)
{
InitializeComponent();
addNewToolStripMenuItem.Click += add;
editToolStripMenuItem.Click += edit;
deleteToolStripMenuItem.Click += delete;
Car = car;
addNewToolStripMenuItem.Tag = this;
editToolStripMenuItem.Tag = this;
deleteToolStripMenuItem.Tag = this;
}
}
}

View File

@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="myMenuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

65
Controls/CarPanelMenuStrip.Designer.cs generated Normal file
View File

@ -0,0 +1,65 @@
namespace GtaVUsersInfo.Controls
{
partial class CarPanelMenuStrip
{
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.myMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
this.addNewToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.myMenuStrip.SuspendLayout();
this.SuspendLayout();
//
// myMenuStrip
//
this.myMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.addNewToolStripMenuItem});
this.myMenuStrip.Name = "contextMenuStrip";
this.myMenuStrip.Size = new System.Drawing.Size(118, 26);
//
// addNewToolStripMenuItem
//
this.addNewToolStripMenuItem.Name = "addNewToolStripMenuItem";
this.addNewToolStripMenuItem.Size = new System.Drawing.Size(117, 22);
this.addNewToolStripMenuItem.Text = "Создать";
//
// CarPanelMenuStrip
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Name = "CarPanelMenuStrip";
this.myMenuStrip.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.ContextMenuStrip myMenuStrip;
private System.Windows.Forms.ToolStripMenuItem addNewToolStripMenuItem;
}
}

View File

@ -0,0 +1,27 @@
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 GtaVUsersInfo.Controls
{
public partial class CarPanelMenuStrip : UserControl
{
public ContextMenuStrip Menu
{
get { return myMenuStrip; }
}
public CarPanelMenuStrip(EventHandler add)
{
InitializeComponent();
addNewToolStripMenuItem.Click += add;
}
}
}

View File

@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="myMenuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -32,8 +32,8 @@
this.saveItem = new System.Windows.Forms.Button();
this.separatopPanel1 = new System.Windows.Forms.Panel();
this.CarPanel = new System.Windows.Forms.Panel();
this.nameLabel = new System.Windows.Forms.Label();
this.nameTextBox = new System.Windows.Forms.TextBox();
this.nameLabel = new System.Windows.Forms.Label();
this.MainPanel.SuspendLayout();
this.CarPanel.SuspendLayout();
this.SuspendLayout();
@ -81,6 +81,14 @@
this.CarPanel.Size = new System.Drawing.Size(248, 33);
this.CarPanel.TabIndex = 3;
//
// nameTextBox
//
this.nameTextBox.Dock = System.Windows.Forms.DockStyle.Top;
this.nameTextBox.Location = new System.Drawing.Point(0, 13);
this.nameTextBox.Name = "nameTextBox";
this.nameTextBox.Size = new System.Drawing.Size(248, 20);
this.nameTextBox.TabIndex = 4;
//
// nameLabel
//
this.nameLabel.AutoSize = true;
@ -91,14 +99,6 @@
this.nameLabel.TabIndex = 2;
this.nameLabel.Text = "Название:";
//
// nameTextBox
//
this.nameTextBox.Dock = System.Windows.Forms.DockStyle.Top;
this.nameTextBox.Location = new System.Drawing.Point(0, 13);
this.nameTextBox.Name = "nameTextBox";
this.nameTextBox.Size = new System.Drawing.Size(248, 20);
this.nameTextBox.TabIndex = 4;
//
// AddParameter
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

View File

@ -85,6 +85,18 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Controls\CarItemMenuStrip.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Controls\CarItemMenuStrip.Designer.cs">
<DependentUpon>CarItemMenuStrip.cs</DependentUpon>
</Compile>
<Compile Include="Controls\CarPanelMenuStrip.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Controls\CarPanelMenuStrip.Designer.cs">
<DependentUpon>CarPanelMenuStrip.cs</DependentUpon>
</Compile>
<Compile Include="Forms\AddCars.cs">
<SubType>Form</SubType>
</Compile>
@ -126,6 +138,12 @@
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<EmbeddedResource Include="Controls\CarItemMenuStrip.resx">
<DependentUpon>CarItemMenuStrip.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Controls\CarPanelMenuStrip.resx">
<DependentUpon>CarPanelMenuStrip.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\AddCars.resx">
<DependentUpon>AddCars.cs</DependentUpon>
</EmbeddedResource>

View File

@ -21,27 +21,58 @@ namespace GtaVUsersInfo
public partial class MainForm : Form
{
private List<Control> debugControlsList;
private List<Car> carList;
private List<Control> parameters;
private List<CarItem> cars;
public MainForm()
{
InitializeComponent();
debugControlsList = new List<Control> { parserButton, readJsonButton };
parameters = new List<Control> { new ParameterControl("Деньги"), new ParameterControl("Имя") };
this.visible(debugControlsList, false);
carList = LoadCarsFromJson(Resources.carJsonPath);
parameters = new List<Control> { new ParameterControl("Имя"), new ParameterControl("Деньги") };
cars = new List<CarItem>();
carsItems.ContextMenuStrip = new CarPanelMenuStrip(addNewCar).Menu;
}
private void MainForm_Load(object sender, EventArgs e)
{
AllPanelCreate();
}
private void AllPanelCreate()
{
ParameterPanelCreate();
CarPanelCreate();
}
private void ParameterPanelCreate()
{
parametersPanel.Controls.Clear();
foreach (Control param in parameters)
{
param.Dock = DockStyle.Top;
parametersPanel.Controls.Add(param);
parametersPanel.Controls.SetChildIndex(param, 0);
}
}
private void CarPanelCreate()
{
carsItems.Controls.Clear();
foreach (CarItem car in cars)
{
carsItems.Controls.Add(car);
}
}
@ -122,7 +153,74 @@ namespace GtaVUsersInfo
if (car.Name != null)
{
CarItem item = new CarItem(car);
carsItems.Controls.Add(item);
item.MenuStrip = new CarItemMenuStrip(addNewCar, editCar, deleteCar, item).Menu;
cars.Add(item);
CarPanelCreate();
}
}
private void addNewCar(object sender, EventArgs e)
{
addCar_Click(sender, e);
}
private void editCar(object sender, EventArgs e)
{
if (carList.Count <= 0)
{
ErrorsShow.ShowErrorMessage($"Список автомобилей пуст, ошибка чтения файла: {Resources.carJsonPath}");
return;
}
ToolStripMenuItem clickedMenuItem = sender as ToolStripMenuItem;
if (clickedMenuItem == null)
return;
CarItemMenuStrip menu = clickedMenuItem.Tag as CarItemMenuStrip;
if (menu == null)
return;
CarItem carItem = menu.Car as CarItem;
if (carItem == null)
return;
Car car = new Car();
using (AddCars form = new AddCars(carList, car))
{
form.ShowDialog();
}
if (car.Name != null)
{
carItem.EditCar(car);
}
}
private void deleteCar(object sender, EventArgs e)
{
if (carList.Count <= 0)
{
ErrorsShow.ShowErrorMessage($"Список автомобилей пуст, ошибка чтения файла: {Resources.carJsonPath}");
return;
}
ToolStripMenuItem clickedMenuItem = sender as ToolStripMenuItem;
if (clickedMenuItem == null)
return;
CarItemMenuStrip menu = clickedMenuItem.Tag as CarItemMenuStrip;
if (menu == null)
return;
CarItem carItem = menu.Car;
if (carItem == null)
return;
if (cars.Contains(carItem))
{
cars.Remove(carItem);
CarPanelCreate();
}
}
@ -139,7 +237,7 @@ namespace GtaVUsersInfo
{
parameter.Dock = DockStyle.Top;
parameters.Add(parameter);
parametersPanel.Controls.Add(parameter);
ParameterPanelCreate();
}
}
}

10
Resources.Designer.cs generated
View File

@ -69,16 +69,6 @@ namespace GtaVUsersInfo {
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Byte[].
/// </summary>
internal static byte[] cars {
get {
object obj = ResourceManager.GetObject("cars", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// Ищет локализованную строку, похожую на https://gtacars.net/.
/// </summary>

View File

@ -120,10 +120,6 @@
<data name="carJsonPath" xml:space="preserve">
<value>data/cars.json</value>
</data>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="cars" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>bin\Debug\data\cars.json;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="carUrl" xml:space="preserve">
<value>https://gtacars.net/</value>
</data>