Добавление автомобилей

This commit is contained in:
MisterMLiL 2024-10-08 09:53:24 +03:00
parent 493f3ddbf4
commit d86dd4e39a
17 changed files with 1369 additions and 185 deletions

186
AddCars.Designer.cs generated Normal file
View File

@ -0,0 +1,186 @@
namespace GtaVUsersInfo
{
partial class AddCars
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.MainPanel = new System.Windows.Forms.Panel();
this.saveItem = new System.Windows.Forms.Button();
this.panel2 = new System.Windows.Forms.Panel();
this.panel1 = new System.Windows.Forms.Panel();
this.carPrice = new System.Windows.Forms.TextBox();
this.priceLabel = new System.Windows.Forms.Label();
this.separatopPanel1 = new System.Windows.Forms.Panel();
this.CarPanel = new System.Windows.Forms.Panel();
this.carComboBox = new System.Windows.Forms.ComboBox();
this.carLabel = new System.Windows.Forms.Label();
this.MainPanel.SuspendLayout();
this.panel1.SuspendLayout();
this.CarPanel.SuspendLayout();
this.SuspendLayout();
//
// MainPanel
//
this.MainPanel.Controls.Add(this.saveItem);
this.MainPanel.Controls.Add(this.panel2);
this.MainPanel.Controls.Add(this.panel1);
this.MainPanel.Controls.Add(this.separatopPanel1);
this.MainPanel.Controls.Add(this.CarPanel);
this.MainPanel.Dock = System.Windows.Forms.DockStyle.Fill;
this.MainPanel.Location = new System.Drawing.Point(0, 0);
this.MainPanel.Name = "MainPanel";
this.MainPanel.Padding = new System.Windows.Forms.Padding(3);
this.MainPanel.Size = new System.Drawing.Size(254, 118);
this.MainPanel.TabIndex = 0;
//
// saveItem
//
this.saveItem.Dock = System.Windows.Forms.DockStyle.Right;
this.saveItem.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.saveItem.Location = new System.Drawing.Point(176, 90);
this.saveItem.Name = "saveItem";
this.saveItem.Size = new System.Drawing.Size(75, 25);
this.saveItem.TabIndex = 7;
this.saveItem.Text = "Сохранить";
this.saveItem.UseVisualStyleBackColor = true;
this.saveItem.Click += new System.EventHandler(this.saveItem_Click);
//
// panel2
//
this.panel2.Dock = System.Windows.Forms.DockStyle.Top;
this.panel2.Location = new System.Drawing.Point(3, 80);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(248, 10);
this.panel2.TabIndex = 6;
//
// panel1
//
this.panel1.AutoSize = true;
this.panel1.Controls.Add(this.carPrice);
this.panel1.Controls.Add(this.priceLabel);
this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
this.panel1.Location = new System.Drawing.Point(3, 47);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(248, 33);
this.panel1.TabIndex = 5;
//
// carPrice
//
this.carPrice.Dock = System.Windows.Forms.DockStyle.Top;
this.carPrice.Location = new System.Drawing.Point(0, 13);
this.carPrice.Name = "carPrice";
this.carPrice.Size = new System.Drawing.Size(248, 20);
this.carPrice.TabIndex = 4;
this.carPrice.Enter += new System.EventHandler(this.carPrice_Enter);
this.carPrice.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.carPrice_KeyPress);
this.carPrice.Leave += new System.EventHandler(this.carPrice_Leave);
//
// priceLabel
//
this.priceLabel.AutoSize = true;
this.priceLabel.Dock = System.Windows.Forms.DockStyle.Top;
this.priceLabel.Location = new System.Drawing.Point(0, 0);
this.priceLabel.Name = "priceLabel";
this.priceLabel.Size = new System.Drawing.Size(36, 13);
this.priceLabel.TabIndex = 2;
this.priceLabel.Text = "Цена:";
//
// separatopPanel1
//
this.separatopPanel1.Dock = System.Windows.Forms.DockStyle.Top;
this.separatopPanel1.Location = new System.Drawing.Point(3, 37);
this.separatopPanel1.Name = "separatopPanel1";
this.separatopPanel1.Size = new System.Drawing.Size(248, 10);
this.separatopPanel1.TabIndex = 4;
//
// CarPanel
//
this.CarPanel.AutoSize = true;
this.CarPanel.Controls.Add(this.carComboBox);
this.CarPanel.Controls.Add(this.carLabel);
this.CarPanel.Dock = System.Windows.Forms.DockStyle.Top;
this.CarPanel.Location = new System.Drawing.Point(3, 3);
this.CarPanel.Name = "CarPanel";
this.CarPanel.Size = new System.Drawing.Size(248, 34);
this.CarPanel.TabIndex = 3;
//
// carComboBox
//
this.carComboBox.Dock = System.Windows.Forms.DockStyle.Top;
this.carComboBox.FormattingEnabled = true;
this.carComboBox.Location = new System.Drawing.Point(0, 13);
this.carComboBox.Name = "carComboBox";
this.carComboBox.Size = new System.Drawing.Size(248, 21);
this.carComboBox.TabIndex = 3;
this.carComboBox.SelectedIndexChanged += new System.EventHandler(this.carComboBox_SelectedIndexChanged);
//
// carLabel
//
this.carLabel.AutoSize = true;
this.carLabel.Dock = System.Windows.Forms.DockStyle.Top;
this.carLabel.Location = new System.Drawing.Point(0, 0);
this.carLabel.Name = "carLabel";
this.carLabel.Size = new System.Drawing.Size(72, 13);
this.carLabel.TabIndex = 2;
this.carLabel.Text = "Автомобиль:";
//
// AddCars
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(254, 118);
this.Controls.Add(this.MainPanel);
this.MaximumSize = new System.Drawing.Size(999999, 157);
this.MinimumSize = new System.Drawing.Size(270, 157);
this.Name = "AddCars";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Автомобиль";
this.MainPanel.ResumeLayout(false);
this.MainPanel.PerformLayout();
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
this.CarPanel.ResumeLayout(false);
this.CarPanel.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Panel MainPanel;
private System.Windows.Forms.Panel CarPanel;
private System.Windows.Forms.ComboBox carComboBox;
private System.Windows.Forms.Label carLabel;
private System.Windows.Forms.Panel separatopPanel1;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.TextBox carPrice;
private System.Windows.Forms.Label priceLabel;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.Button saveItem;
}
}

94
AddCars.cs Normal file
View File

@ -0,0 +1,94 @@
using GtaVUsersInfo.Helpers;
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
{
public partial class AddCars : Form
{
List<Car> carList;
Car carItem;
public AddCars(List<Car> carPrice, Car carItem)
{
InitializeComponent();
carList = carPrice;
this.carItem = carItem;
foreach (Car car in carList)
{
carComboBox.Items.Add(car.Name);
}
}
private void carComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
if ((sender as ComboBox).SelectedIndex == -1)
return;
carPrice.Text = "$" + carList[(sender as ComboBox).SelectedIndex].Price.ToString();
}
private void carPrice_Enter(object sender, EventArgs e)
{
(sender as TextBox).Text = (sender as TextBox).Text.Trim('$');
}
private void carPrice_Leave(object sender, EventArgs e)
{
(sender as TextBox).Text = '$' + (sender as TextBox).Text;
}
private void carPrice_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
saveItem.Focus();
e.Handled = true;
return;
}
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
{
e.Handled = true;
}
}
private void saveItem_Click(object sender, EventArgs e)
{
try
{
if (carComboBox.SelectedIndex == -1)
{
ErrorsShow.ShowErrorMessage("Не выбран ни один автомобиль");
return;
}
Car selectedCar = carList[carComboBox.SelectedIndex];
carItem.Name = selectedCar.Name;
carItem.Price = int.Parse(carPrice.Text.Trim('$'));
carItem.Photo = selectedCar.Photo;
carItem.Manufacturer = selectedCar.Manufacturer;
carItem.Class = selectedCar.Class;
carItem.Model = selectedCar.Model;
this.Close();
}
catch (Exception ex)
{
ErrorsShow.ShowErrorMessage($"Произошла неожиданная ошибка: {ex.Message}");
return;
}
}
}
}

120
AddCars.resx Normal file
View File

@ -0,0 +1,120 @@
<?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>
</root>

12
Car.cs Normal file
View File

@ -0,0 +1,12 @@
namespace GtaVUsersInfo
{
public class Car
{
public string Name { get; set; }
public int Price { get; set; }
public string Photo { get; set; }
public string Manufacturer { get; set; }
public string Class { get; set; }
public string Model { get; set; }
}
}

20
CarPrice.cs Normal file
View File

@ -0,0 +1,20 @@
using System.Collections.Generic;
using System.Linq;
namespace GtaVUsersInfo
{
public class CarPrice
{
public string Name { get; set; }
public int Price { get; set; }
public static List<CarPrice> ConvertToCarPriceList(List<Car> cars)
{
return cars.Select(car => new CarPrice
{
Name = car.Name,
Price = car.Price
}).ToList();
}
}
}

240
Controls/CarItem.Designer.cs generated Normal file
View File

@ -0,0 +1,240 @@
namespace GtaVUsersInfo.Controls
{
partial class CarItem
{
/// <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.panel1 = new System.Windows.Forms.Panel();
this.panel6 = new System.Windows.Forms.Panel();
this.PhotoBox = new System.Windows.Forms.PictureBox();
this.panel5 = new System.Windows.Forms.Panel();
this.MoneyTextBox = new System.Windows.Forms.TextBox();
this.MoneyLabel = new System.Windows.Forms.Label();
this.panel4 = new System.Windows.Forms.Panel();
this.ClassLabel = new System.Windows.Forms.Label();
this.panel3 = new System.Windows.Forms.Panel();
this.ManufacturerLabel = new System.Windows.Forms.Label();
this.NameLabel = new System.Windows.Forms.Label();
this.panel2 = new System.Windows.Forms.Panel();
this.ModelLabel = new System.Windows.Forms.Label();
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
this.panel1.SuspendLayout();
this.panel6.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.PhotoBox)).BeginInit();
this.panel5.SuspendLayout();
this.panel4.SuspendLayout();
this.panel3.SuspendLayout();
this.panel2.SuspendLayout();
this.SuspendLayout();
//
// panel1
//
this.panel1.Controls.Add(this.panel6);
this.panel1.Controls.Add(this.panel5);
this.panel1.Controls.Add(this.panel4);
this.panel1.Controls.Add(this.panel3);
this.panel1.Controls.Add(this.panel2);
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(212, 206);
this.panel1.TabIndex = 0;
//
// panel6
//
this.panel6.Controls.Add(this.PhotoBox);
this.panel6.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel6.Location = new System.Drawing.Point(0, 13);
this.panel6.Name = "panel6";
this.panel6.Size = new System.Drawing.Size(212, 134);
this.panel6.TabIndex = 4;
//
// PhotoBox
//
this.PhotoBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.PhotoBox.Location = new System.Drawing.Point(0, 0);
this.PhotoBox.Name = "PhotoBox";
this.PhotoBox.Size = new System.Drawing.Size(212, 134);
this.PhotoBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.PhotoBox.TabIndex = 0;
this.PhotoBox.TabStop = false;
//
// panel5
//
this.panel5.AutoSize = true;
this.panel5.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.panel5.Controls.Add(this.MoneyTextBox);
this.panel5.Controls.Add(this.MoneyLabel);
this.panel5.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panel5.Location = new System.Drawing.Point(0, 147);
this.panel5.Name = "panel5";
this.panel5.Size = new System.Drawing.Size(212, 33);
this.panel5.TabIndex = 3;
//
// MoneyTextBox
//
this.MoneyTextBox.Dock = System.Windows.Forms.DockStyle.Top;
this.MoneyTextBox.Location = new System.Drawing.Point(0, 13);
this.MoneyTextBox.Name = "MoneyTextBox";
this.MoneyTextBox.Size = new System.Drawing.Size(212, 20);
this.MoneyTextBox.TabIndex = 1;
this.MoneyTextBox.Enter += new System.EventHandler(this.carPrice_Enter);
this.MoneyTextBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.carPrice_KeyPress);
this.MoneyTextBox.Leave += new System.EventHandler(this.carPrice_Leave);
//
// MoneyLabel
//
this.MoneyLabel.AutoSize = true;
this.MoneyLabel.Dock = System.Windows.Forms.DockStyle.Top;
this.MoneyLabel.Location = new System.Drawing.Point(0, 0);
this.MoneyLabel.Name = "MoneyLabel";
this.MoneyLabel.Size = new System.Drawing.Size(48, 13);
this.MoneyLabel.TabIndex = 0;
this.MoneyLabel.Text = "Деньги:";
//
// panel4
//
this.panel4.AutoSize = true;
this.panel4.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.panel4.Controls.Add(this.ClassLabel);
this.panel4.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panel4.Location = new System.Drawing.Point(0, 180);
this.panel4.Name = "panel4";
this.panel4.Size = new System.Drawing.Size(212, 13);
this.panel4.TabIndex = 2;
//
// ClassLabel
//
this.ClassLabel.AutoSize = true;
this.ClassLabel.Dock = System.Windows.Forms.DockStyle.Fill;
this.ClassLabel.Location = new System.Drawing.Point(0, 0);
this.ClassLabel.Name = "ClassLabel";
this.ClassLabel.Size = new System.Drawing.Size(35, 13);
this.ClassLabel.TabIndex = 0;
this.ClassLabel.Text = "label2";
//
// panel3
//
this.panel3.AutoSize = true;
this.panel3.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.panel3.Controls.Add(this.ManufacturerLabel);
this.panel3.Controls.Add(this.NameLabel);
this.panel3.Dock = System.Windows.Forms.DockStyle.Top;
this.panel3.Location = new System.Drawing.Point(0, 0);
this.panel3.Name = "panel3";
this.panel3.Size = new System.Drawing.Size(212, 13);
this.panel3.TabIndex = 1;
//
// ManufacturerLabel
//
this.ManufacturerLabel.AutoSize = true;
this.ManufacturerLabel.Dock = System.Windows.Forms.DockStyle.Right;
this.ManufacturerLabel.Location = new System.Drawing.Point(177, 0);
this.ManufacturerLabel.Name = "ManufacturerLabel";
this.ManufacturerLabel.Size = new System.Drawing.Size(35, 13);
this.ManufacturerLabel.TabIndex = 1;
this.ManufacturerLabel.Text = "label1";
//
// NameLabel
//
this.NameLabel.AutoSize = true;
this.NameLabel.Dock = System.Windows.Forms.DockStyle.Fill;
this.NameLabel.Location = new System.Drawing.Point(0, 0);
this.NameLabel.Name = "NameLabel";
this.NameLabel.Size = new System.Drawing.Size(35, 13);
this.NameLabel.TabIndex = 0;
this.NameLabel.Text = "label1";
//
// panel2
//
this.panel2.AutoSize = true;
this.panel2.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.panel2.Controls.Add(this.ModelLabel);
this.panel2.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panel2.Location = new System.Drawing.Point(0, 193);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(212, 13);
this.panel2.TabIndex = 0;
//
// ModelLabel
//
this.ModelLabel.AutoSize = true;
this.ModelLabel.Dock = System.Windows.Forms.DockStyle.Fill;
this.ModelLabel.Location = new System.Drawing.Point(0, 0);
this.ModelLabel.Name = "ModelLabel";
this.ModelLabel.Size = new System.Drawing.Size(35, 13);
this.ModelLabel.TabIndex = 0;
this.ModelLabel.Text = "label2";
//
// contextMenuStrip1
//
this.contextMenuStrip1.Name = "contextMenuStrip1";
this.contextMenuStrip1.Size = new System.Drawing.Size(61, 4);
//
// CarItem
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.White;
this.Controls.Add(this.panel1);
this.Name = "CarItem";
this.Size = new System.Drawing.Size(212, 206);
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
this.panel6.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.PhotoBox)).EndInit();
this.panel5.ResumeLayout(false);
this.panel5.PerformLayout();
this.panel4.ResumeLayout(false);
this.panel4.PerformLayout();
this.panel3.ResumeLayout(false);
this.panel3.PerformLayout();
this.panel2.ResumeLayout(false);
this.panel2.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Panel panel5;
private System.Windows.Forms.Label MoneyLabel;
private System.Windows.Forms.Panel panel4;
private System.Windows.Forms.Label ClassLabel;
private System.Windows.Forms.Panel panel3;
private System.Windows.Forms.Label NameLabel;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.Label ModelLabel;
private System.Windows.Forms.Panel panel6;
private System.Windows.Forms.PictureBox PhotoBox;
private System.Windows.Forms.Label ManufacturerLabel;
private System.Windows.Forms.TextBox MoneyTextBox;
private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
}
}

87
Controls/CarItem.cs Normal file
View File

@ -0,0 +1,87 @@
using System;
using System.Drawing;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using System.Windows.Forms;
using GtaVUsersInfo.Helpers;
namespace GtaVUsersInfo.Controls
{
public partial class CarItem : UserControl
{
private static readonly HttpClient httpClient = new HttpClient();
public CarItem(Car carItem)
{
InitializeComponent();
NameLabel.Text = carItem.Name;
ClassLabel.Text = carItem.Class;
ModelLabel.Text = "Модель:" + carItem.Model;
ManufacturerLabel.Text = carItem.Manufacturer;
MoneyTextBox.Text = '$' + carItem.Price.ToString();
LoadImageAsync(carItem.Photo);
}
private async void LoadImageAsync(string imageUrl)
{
try
{
byte[] imageBytes = await httpClient.GetByteArrayAsync(imageUrl);
using (var ms = new MemoryStream(imageBytes))
{
var bitmap = new Bitmap(ms);
SetImage(bitmap);
}
}
catch (HttpRequestException ex)
{
ErrorsShow.ShowErrorMessage($"Ошибка HTTP: {ex.Message}");
}
catch (Exception ex)
{
ErrorsShow.ShowErrorMessage($"Произошла неожиданная ошибка: {ex.Message}");
}
}
private void SetImage(Image image)
{
if (InvokeRequired)
{
Invoke(new Action<Image>(SetImage), image);
}
else
{
PhotoBox.Image = image;
}
}
private void carPrice_Enter(object sender, EventArgs e)
{
(sender as TextBox).Text = (sender as TextBox).Text.Trim('$');
}
private void carPrice_Leave(object sender, EventArgs e)
{
(sender as TextBox).Text = '$' + (sender as TextBox).Text;
}
private void carPrice_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
NameLabel.Focus();
e.Handled = true;
return;
}
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
{
e.Handled = true;
}
}
}
}

123
Controls/CarItem.resx Normal file
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="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

90
Controls/ParameterControl.Designer.cs generated Normal file
View File

@ -0,0 +1,90 @@
namespace GtaVUsersInfo.Controls
{
partial class ParameterControl
{
/// <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.namePanel = new System.Windows.Forms.Panel();
this.Textbox = new System.Windows.Forms.TextBox();
this.Label = new System.Windows.Forms.Label();
this.namePanel.SuspendLayout();
this.SuspendLayout();
//
// namePanel
//
this.namePanel.AutoSize = true;
this.namePanel.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.namePanel.Controls.Add(this.Textbox);
this.namePanel.Controls.Add(this.Label);
this.namePanel.Dock = System.Windows.Forms.DockStyle.Top;
this.namePanel.Location = new System.Drawing.Point(0, 0);
this.namePanel.Name = "namePanel";
this.namePanel.Padding = new System.Windows.Forms.Padding(2);
this.namePanel.Size = new System.Drawing.Size(150, 37);
this.namePanel.TabIndex = 2;
//
// Textbox
//
this.Textbox.Dock = System.Windows.Forms.DockStyle.Top;
this.Textbox.Location = new System.Drawing.Point(2, 15);
this.Textbox.Multiline = true;
this.Textbox.Name = "Textbox";
this.Textbox.Size = new System.Drawing.Size(146, 20);
this.Textbox.TabIndex = 1;
//
// Label
//
this.Label.AutoSize = true;
this.Label.Dock = System.Windows.Forms.DockStyle.Top;
this.Label.Location = new System.Drawing.Point(2, 2);
this.Label.Name = "Label";
this.Label.Size = new System.Drawing.Size(32, 13);
this.Label.TabIndex = 0;
this.Label.Text = "Имя:";
//
// ParameterControl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoSize = true;
this.Controls.Add(this.namePanel);
this.Name = "ParameterControl";
this.Size = new System.Drawing.Size(150, 37);
this.namePanel.ResumeLayout(false);
this.namePanel.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Panel namePanel;
private System.Windows.Forms.TextBox Textbox;
private System.Windows.Forms.Label Label;
}
}

View File

@ -0,0 +1,23 @@
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 ParameterControl : UserControl
{
public ParameterControl(string name, string text = "")
{
InitializeComponent();
Label.Text = name + ':';
Textbox.Text = text;
}
}
}

View File

@ -0,0 +1,120 @@
<?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>
</root>

View File

@ -85,7 +85,22 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Helpers\Strings.cs" />
<Compile Include="AddCars.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="AddCars.Designer.cs">
<DependentUpon>AddCars.cs</DependentUpon>
</Compile>
<Compile Include="Car.cs" />
<Compile Include="CarPrice.cs" />
<Compile Include="Controls\CarItem.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Controls\CarItem.Designer.cs">
<DependentUpon>CarItem.cs</DependentUpon>
</Compile>
<Compile Include="Helpers\ErrorsShow.cs" />
<Compile Include="Helpers\ReadonlyStrings.cs" />
<Compile Include="MainForm.cs">
<SubType>Form</SubType>
</Compile>
@ -95,6 +110,18 @@
<Compile Include="Helpers\CarParser.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Controls\ParameterControl.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Controls\ParameterControl.Designer.cs">
<DependentUpon>ParameterControl.cs</DependentUpon>
</Compile>
<EmbeddedResource Include="AddCars.resx">
<DependentUpon>AddCars.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Controls\CarItem.resx">
<DependentUpon>CarItem.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="MainForm.resx">
<DependentUpon>MainForm.cs</DependentUpon>
</EmbeddedResource>
@ -107,6 +134,9 @@
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<EmbeddedResource Include="Controls\ParameterControl.resx">
<DependentUpon>ParameterControl.cs</DependentUpon>
</EmbeddedResource>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>

View File

@ -11,16 +11,6 @@ using OpenQA.Selenium.Support.UI;
namespace GtaVUsersInfo.Helpers
{
public class Car
{
public string Name { get; set; }
public int Price { get; set; }
public string Photo { get; set; }
public string Manufacturer { get; set; }
public string Class { get; set; }
public string Model { get; set; }
}
public class CarParser : IDisposable
{
private IWebDriver driver;
@ -115,6 +105,11 @@ namespace GtaVUsersInfo.Helpers
public void SaveToJson(List<Car> cars, string filePath)
{
if (!Directory.Exists(Path.GetDirectoryName(filePath)))
{
Directory.CreateDirectory(Path.GetDirectoryName(filePath));
}
var json = JsonConvert.SerializeObject(cars, Formatting.Indented);
File.WriteAllText(filePath, json);
}
@ -129,17 +124,4 @@ namespace GtaVUsersInfo.Helpers
}
}
}
class Program
{
static async Task Main(string[] args)
{
using (var parser = new CarParser())
{
var cars = await parser.ParseCarsFromPages(25);
parser.SaveToJson(cars, "cars.json");
Console.WriteLine("Data saved to cars.json");
}
}
}
}

24
Helpers/ErrorsShow.cs Normal file
View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace GtaVUsersInfo.Helpers
{
public static class ErrorsShow
{
public static void ShowErrorMessage(string message)
{
MessageBox.Show(message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
Console.WriteLine(message);
}
public static void ShowInfoMessage(string message)
{
MessageBox.Show(message, "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information);
Console.WriteLine(message);
}
}
}

View File

@ -6,8 +6,9 @@ using System.Threading.Tasks;
namespace GtaVUsersInfo.Helpers
{
public class Strings
public static class ReadonlyStrings
{
public readonly static string carUrl = "https://gtacars.net/";
public readonly static string carJsonPath = "data/cars.json";
}
}

256
MainForm.Designer.cs generated
View File

@ -29,20 +29,15 @@
private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.debugCheck = new System.Windows.Forms.CheckBox();
this.panel2 = new System.Windows.Forms.Panel();
this.buttonsPanel = new System.Windows.Forms.Panel();
this.readJsonButton = new System.Windows.Forms.Button();
this.addParameter = new System.Windows.Forms.Button();
this.parserButton = new System.Windows.Forms.Button();
this.addCar = new System.Windows.Forms.Button();
this.addParametrLabel = new System.Windows.Forms.Label();
this.parametersPanel = new System.Windows.Forms.Panel();
this.testPanel = new System.Windows.Forms.Panel();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.moneyPanel = new System.Windows.Forms.Panel();
this.userMoney = new System.Windows.Forms.TextBox();
this.userMoneyLabel = new System.Windows.Forms.Label();
this.namePanel = new System.Windows.Forms.Panel();
this.userName = new System.Windows.Forms.TextBox();
this.userNameLabel = new System.Windows.Forms.Label();
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.файлToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.считатьToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@ -63,37 +58,49 @@
this.splitterLeft = new System.Windows.Forms.Splitter();
this.splitterRigth = new System.Windows.Forms.Splitter();
this.carsPanel = new System.Windows.Forms.Panel();
this.parserButton = new System.Windows.Forms.Button();
this.carsItems = new System.Windows.Forms.FlowLayoutPanel();
this.panel1.SuspendLayout();
this.buttonsPanel.SuspendLayout();
this.parametersPanel.SuspendLayout();
this.testPanel.SuspendLayout();
this.moneyPanel.SuspendLayout();
this.namePanel.SuspendLayout();
this.menuStrip1.SuspendLayout();
this.carsPanel.SuspendLayout();
this.SuspendLayout();
//
// panel1
//
this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panel1.Controls.Add(this.debugCheck);
this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
this.panel1.Location = new System.Drawing.Point(0, 24);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(752, 20);
this.panel1.Size = new System.Drawing.Size(764, 20);
this.panel1.TabIndex = 0;
//
// debugCheck
//
this.debugCheck.AutoSize = true;
this.debugCheck.Dock = System.Windows.Forms.DockStyle.Right;
this.debugCheck.Location = new System.Drawing.Point(747, 0);
this.debugCheck.Name = "debugCheck";
this.debugCheck.Size = new System.Drawing.Size(15, 18);
this.debugCheck.TabIndex = 0;
this.debugCheck.UseVisualStyleBackColor = true;
this.debugCheck.CheckedChanged += new System.EventHandler(this.debugCheck_CheckedChanged);
//
// panel2
//
this.panel2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panel2.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panel2.Location = new System.Drawing.Point(0, 463);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(752, 20);
this.panel2.Size = new System.Drawing.Size(764, 20);
this.panel2.TabIndex = 1;
//
// buttonsPanel
//
this.buttonsPanel.AutoScroll = true;
this.buttonsPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.buttonsPanel.Controls.Add(this.readJsonButton);
this.buttonsPanel.Controls.Add(this.addParameter);
this.buttonsPanel.Controls.Add(this.parserButton);
this.buttonsPanel.Controls.Add(this.addCar);
this.buttonsPanel.Controls.Add(this.addParametrLabel);
@ -101,30 +108,77 @@
this.buttonsPanel.Location = new System.Drawing.Point(0, 44);
this.buttonsPanel.MinimumSize = new System.Drawing.Size(100, 100);
this.buttonsPanel.Name = "buttonsPanel";
this.buttonsPanel.Size = new System.Drawing.Size(100, 419);
this.buttonsPanel.Padding = new System.Windows.Forms.Padding(3);
this.buttonsPanel.Size = new System.Drawing.Size(116, 419);
this.buttonsPanel.TabIndex = 2;
//
// readJsonButton
//
this.readJsonButton.AutoSize = true;
this.readJsonButton.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.readJsonButton.Dock = System.Windows.Forms.DockStyle.Bottom;
this.readJsonButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 6.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
this.readJsonButton.Location = new System.Drawing.Point(3, 370);
this.readJsonButton.Name = "readJsonButton";
this.readJsonButton.Size = new System.Drawing.Size(108, 22);
this.readJsonButton.TabIndex = 5;
this.readJsonButton.Text = "Считать json";
this.readJsonButton.UseVisualStyleBackColor = true;
this.readJsonButton.Click += new System.EventHandler(this.readJsonButton_Click);
//
// addParameter
//
this.addParameter.AutoSize = true;
this.addParameter.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.addParameter.Dock = System.Windows.Forms.DockStyle.Top;
this.addParameter.FlatAppearance.BorderSize = 0;
this.addParameter.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.addParameter.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
this.addParameter.Location = new System.Drawing.Point(3, 48);
this.addParameter.Name = "addParameter";
this.addParameter.Size = new System.Drawing.Size(108, 26);
this.addParameter.TabIndex = 4;
this.addParameter.Text = "Параметр";
this.addParameter.UseVisualStyleBackColor = true;
//
// parserButton
//
this.parserButton.AutoSize = true;
this.parserButton.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.parserButton.Dock = System.Windows.Forms.DockStyle.Bottom;
this.parserButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 6.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
this.parserButton.Location = new System.Drawing.Point(3, 392);
this.parserButton.Name = "parserButton";
this.parserButton.Size = new System.Drawing.Size(108, 22);
this.parserButton.TabIndex = 3;
this.parserButton.Text = "Парсинг";
this.parserButton.UseVisualStyleBackColor = true;
this.parserButton.Click += new System.EventHandler(this.parserButton_Click);
//
// addCar
//
this.addCar.AutoSize = true;
this.addCar.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.addCar.Dock = System.Windows.Forms.DockStyle.Top;
this.addCar.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.addCar.FlatAppearance.BorderSize = 0;
this.addCar.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.addCar.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
this.addCar.Location = new System.Drawing.Point(0, 13);
this.addCar.Location = new System.Drawing.Point(3, 22);
this.addCar.Name = "addCar";
this.addCar.Size = new System.Drawing.Size(98, 26);
this.addCar.Size = new System.Drawing.Size(108, 26);
this.addCar.TabIndex = 2;
this.addCar.Text = "Автомобиль";
this.addCar.UseVisualStyleBackColor = true;
this.addCar.Click += new System.EventHandler(this.addCar_Click);
//
// addParametrLabel
//
this.addParametrLabel.AutoSize = true;
this.addParametrLabel.Dock = System.Windows.Forms.DockStyle.Top;
this.addParametrLabel.Location = new System.Drawing.Point(0, 0);
this.addParametrLabel.Location = new System.Drawing.Point(3, 3);
this.addParametrLabel.Name = "addParametrLabel";
this.addParametrLabel.Size = new System.Drawing.Size(60, 13);
this.addParametrLabel.Padding = new System.Windows.Forms.Padding(3);
this.addParametrLabel.Size = new System.Drawing.Size(66, 19);
this.addParametrLabel.TabIndex = 1;
this.addParametrLabel.Text = "Добавить:";
//
@ -132,112 +186,13 @@
//
this.parametersPanel.AutoScroll = true;
this.parametersPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.parametersPanel.Controls.Add(this.testPanel);
this.parametersPanel.Controls.Add(this.moneyPanel);
this.parametersPanel.Controls.Add(this.namePanel);
this.parametersPanel.Dock = System.Windows.Forms.DockStyle.Right;
this.parametersPanel.Location = new System.Drawing.Point(552, 44);
this.parametersPanel.Location = new System.Drawing.Point(564, 44);
this.parametersPanel.MinimumSize = new System.Drawing.Size(100, 100);
this.parametersPanel.Name = "parametersPanel";
this.parametersPanel.Size = new System.Drawing.Size(200, 419);
this.parametersPanel.TabIndex = 3;
//
// testPanel
//
this.testPanel.AutoSize = true;
this.testPanel.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.testPanel.Controls.Add(this.textBox1);
this.testPanel.Controls.Add(this.label1);
this.testPanel.Dock = System.Windows.Forms.DockStyle.Top;
this.testPanel.Location = new System.Drawing.Point(0, 74);
this.testPanel.Name = "testPanel";
this.testPanel.Padding = new System.Windows.Forms.Padding(2);
this.testPanel.Size = new System.Drawing.Size(198, 37);
this.testPanel.TabIndex = 3;
//
// textBox1
//
this.textBox1.Dock = System.Windows.Forms.DockStyle.Top;
this.textBox1.Location = new System.Drawing.Point(2, 15);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(194, 20);
this.textBox1.TabIndex = 1;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Dock = System.Windows.Forms.DockStyle.Top;
this.label1.Location = new System.Drawing.Point(2, 2);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(48, 13);
this.label1.TabIndex = 0;
this.label1.Text = "Деньги:";
//
// moneyPanel
//
this.moneyPanel.AutoSize = true;
this.moneyPanel.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.moneyPanel.Controls.Add(this.userMoney);
this.moneyPanel.Controls.Add(this.userMoneyLabel);
this.moneyPanel.Dock = System.Windows.Forms.DockStyle.Top;
this.moneyPanel.Location = new System.Drawing.Point(0, 37);
this.moneyPanel.Name = "moneyPanel";
this.moneyPanel.Padding = new System.Windows.Forms.Padding(2);
this.moneyPanel.Size = new System.Drawing.Size(198, 37);
this.moneyPanel.TabIndex = 2;
//
// userMoney
//
this.userMoney.Dock = System.Windows.Forms.DockStyle.Top;
this.userMoney.Location = new System.Drawing.Point(2, 15);
this.userMoney.Multiline = true;
this.userMoney.Name = "userMoney";
this.userMoney.Size = new System.Drawing.Size(194, 20);
this.userMoney.TabIndex = 1;
//
// userMoneyLabel
//
this.userMoneyLabel.AutoSize = true;
this.userMoneyLabel.Dock = System.Windows.Forms.DockStyle.Top;
this.userMoneyLabel.Location = new System.Drawing.Point(2, 2);
this.userMoneyLabel.Name = "userMoneyLabel";
this.userMoneyLabel.Size = new System.Drawing.Size(48, 13);
this.userMoneyLabel.TabIndex = 0;
this.userMoneyLabel.Text = "Деньги:";
//
// namePanel
//
this.namePanel.AutoSize = true;
this.namePanel.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.namePanel.Controls.Add(this.userName);
this.namePanel.Controls.Add(this.userNameLabel);
this.namePanel.Dock = System.Windows.Forms.DockStyle.Top;
this.namePanel.Location = new System.Drawing.Point(0, 0);
this.namePanel.Name = "namePanel";
this.namePanel.Padding = new System.Windows.Forms.Padding(2);
this.namePanel.Size = new System.Drawing.Size(198, 37);
this.namePanel.TabIndex = 1;
//
// userName
//
this.userName.Dock = System.Windows.Forms.DockStyle.Top;
this.userName.Location = new System.Drawing.Point(2, 15);
this.userName.Multiline = true;
this.userName.Name = "userName";
this.userName.Size = new System.Drawing.Size(194, 20);
this.userName.TabIndex = 1;
//
// userNameLabel
//
this.userNameLabel.AutoSize = true;
this.userNameLabel.Dock = System.Windows.Forms.DockStyle.Top;
this.userNameLabel.Location = new System.Drawing.Point(2, 2);
this.userNameLabel.Name = "userNameLabel";
this.userNameLabel.Size = new System.Drawing.Size(32, 13);
this.userNameLabel.TabIndex = 0;
this.userNameLabel.Text = "Имя:";
//
// menuStrip1
//
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
@ -245,7 +200,7 @@
this.стилиToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(752, 24);
this.menuStrip1.Size = new System.Drawing.Size(764, 24);
this.menuStrip1.TabIndex = 5;
this.menuStrip1.Text = "menuStrip1";
//
@ -364,7 +319,7 @@
//
// splitterLeft
//
this.splitterLeft.Location = new System.Drawing.Point(100, 44);
this.splitterLeft.Location = new System.Drawing.Point(116, 44);
this.splitterLeft.Name = "splitterLeft";
this.splitterLeft.Size = new System.Drawing.Size(5, 419);
this.splitterLeft.TabIndex = 6;
@ -373,7 +328,7 @@
// splitterRigth
//
this.splitterRigth.Dock = System.Windows.Forms.DockStyle.Right;
this.splitterRigth.Location = new System.Drawing.Point(547, 44);
this.splitterRigth.Location = new System.Drawing.Point(559, 44);
this.splitterRigth.Name = "splitterRigth";
this.splitterRigth.Size = new System.Drawing.Size(5, 419);
this.splitterRigth.TabIndex = 7;
@ -382,34 +337,28 @@
// carsPanel
//
this.carsPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.carsPanel.Controls.Add(this.carsItems);
this.carsPanel.Dock = System.Windows.Forms.DockStyle.Fill;
this.carsPanel.Location = new System.Drawing.Point(105, 44);
this.carsPanel.Location = new System.Drawing.Point(121, 44);
this.carsPanel.MinimumSize = new System.Drawing.Size(300, 100);
this.carsPanel.Name = "carsPanel";
this.carsPanel.Size = new System.Drawing.Size(442, 419);
this.carsPanel.Size = new System.Drawing.Size(438, 419);
this.carsPanel.TabIndex = 8;
//
// parserButton
// carsItems
//
this.parserButton.AutoSize = true;
this.parserButton.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.parserButton.Dock = System.Windows.Forms.DockStyle.Bottom;
this.parserButton.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.parserButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 6.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
this.parserButton.Location = new System.Drawing.Point(0, 395);
this.parserButton.Name = "parserButton";
this.parserButton.Size = new System.Drawing.Size(98, 22);
this.parserButton.TabIndex = 3;
this.parserButton.Text = "Парсинг";
this.parserButton.UseVisualStyleBackColor = true;
this.parserButton.Click += new System.EventHandler(this.parserButton_Click);
this.carsItems.Dock = System.Windows.Forms.DockStyle.Fill;
this.carsItems.Location = new System.Drawing.Point(0, 0);
this.carsItems.Name = "carsItems";
this.carsItems.Size = new System.Drawing.Size(436, 417);
this.carsItems.TabIndex = 0;
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(752, 483);
this.ClientSize = new System.Drawing.Size(764, 483);
this.Controls.Add(this.carsPanel);
this.Controls.Add(this.splitterRigth);
this.Controls.Add(this.splitterLeft);
@ -421,20 +370,16 @@
this.MainMenuStrip = this.menuStrip1;
this.MinimumSize = new System.Drawing.Size(526, 365);
this.Name = "MainForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "null";
this.Load += new System.EventHandler(this.MainForm_Load);
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
this.buttonsPanel.ResumeLayout(false);
this.buttonsPanel.PerformLayout();
this.parametersPanel.ResumeLayout(false);
this.parametersPanel.PerformLayout();
this.testPanel.ResumeLayout(false);
this.testPanel.PerformLayout();
this.moneyPanel.ResumeLayout(false);
this.moneyPanel.PerformLayout();
this.namePanel.ResumeLayout(false);
this.namePanel.PerformLayout();
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
this.carsPanel.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
@ -463,21 +408,16 @@
private System.Windows.Forms.ToolStripMenuItem праваяПанельToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem центральнаяПанельToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem верхнизToolStripMenuItem;
private System.Windows.Forms.Panel moneyPanel;
private System.Windows.Forms.TextBox userMoney;
private System.Windows.Forms.Label userMoneyLabel;
private System.Windows.Forms.Panel namePanel;
private System.Windows.Forms.TextBox userName;
private System.Windows.Forms.Label userNameLabel;
private System.Windows.Forms.Panel testPanel;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button addCar;
private System.Windows.Forms.Label addParametrLabel;
private System.Windows.Forms.Splitter splitterLeft;
private System.Windows.Forms.Splitter splitterRigth;
private System.Windows.Forms.Panel carsPanel;
private System.Windows.Forms.Button parserButton;
private System.Windows.Forms.CheckBox debugCheck;
private System.Windows.Forms.Button addParameter;
private System.Windows.Forms.FlowLayoutPanel carsItems;
private System.Windows.Forms.Button readJsonButton;
}
}

View File

@ -4,32 +4,124 @@ using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security.AccessControl;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;
using GtaVUsersInfo.Helpers;
using GtaVUsersInfo.Controls;
using Newtonsoft.Json;
using System.IO;
namespace GtaVUsersInfo
{
public partial class MainForm : Form
{
private List<Control> debugControlsList;
private List<Car> carList;
public MainForm()
{
InitializeComponent();
debugControlsList = new List<Control> { parserButton, readJsonButton };
this.visible(debugControlsList, false);
carList = LoadCarsFromJson(ReadonlyStrings.carJsonPath);
}
public static List<Car> LoadCarsFromJson(string filePath)
{
try
{
string json = File.ReadAllText(filePath);
List<Car> cars = JsonConvert.DeserializeObject<List<Car>>(json);
return cars;
}
catch (FileNotFoundException)
{
string message = $"Файл с автомобилями не найден: {filePath}";
Console.WriteLine(message);
MessageBox.Show(message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return new List<Car>();
}
catch (JsonException ex)
{
ErrorsShow.ShowErrorMessage($"Ошибка при десериализации JSON автомобилей: {ex.Message}");
return new List<Car>();
}
catch (Exception ex)
{
ErrorsShow.ShowErrorMessage($"Произошла неожиданная ошибка при открытии файла с автомобилями: {ex.Message}");
return new List<Car>();
}
}
private void MainForm_Load(object sender, EventArgs e)
{
var name = new ParameterControl("Имя");
var money = new ParameterControl("Деньги");
name.Dock = DockStyle.Top;
money.Dock = DockStyle.Top;
parametersPanel.Controls.Add(money);
parametersPanel.Controls.Add(name);
}
#region Methods
private void visible(List<Control> controls, bool isVisible)
{
controls.ForEach(control => { control.Visible = isVisible; control.Enabled = isVisible; });
}
#endregion
async private void parserButton_Click(object sender, EventArgs e)
{
using (var parser = new CarParser())
{
var cars = await parser.ParseCarsFromPages(25);
parser.SaveToJson(cars, "cars.json");
Console.WriteLine("Data saved to cars.json");
parser.SaveToJson(cars, ReadonlyStrings.carJsonPath);
ErrorsShow.ShowInfoMessage($"Данные сохранены: {ReadonlyStrings.carJsonPath}");
}
carList = LoadCarsFromJson(ReadonlyStrings.carJsonPath);
}
private void readJsonButton_Click(object sender, EventArgs e)
{
carList = LoadCarsFromJson(ReadonlyStrings.carJsonPath);
}
private void debugCheck_CheckedChanged(object sender, EventArgs e)
{
this.visible(debugControlsList, debugCheck.Checked);
}
private void addCar_Click(object sender, EventArgs e)
{
if (carList.Count <= 0)
{
ErrorsShow.ShowErrorMessage($"Список автомобилей пуст, ошибка чтения файла: {ReadonlyStrings.carJsonPath}");
return;
}
Car car = new Car();
using (AddCars cars = new AddCars(carList, car))
{
cars.ShowDialog();
}
if (car.Name != null)
{
CarItem item = new CarItem(car);
carsItems.Controls.Add(item);
}
}
}