diff --git a/AddCars.Designer.cs b/AddCars.Designer.cs new file mode 100644 index 0000000..cef5a47 --- /dev/null +++ b/AddCars.Designer.cs @@ -0,0 +1,186 @@ +namespace GtaVUsersInfo +{ + partial class AddCars + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + 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; + } +} \ No newline at end of file diff --git a/AddCars.cs b/AddCars.cs new file mode 100644 index 0000000..7e66e1a --- /dev/null +++ b/AddCars.cs @@ -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 carList; + Car carItem; + + public AddCars(List 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; + } + } + } +} diff --git a/AddCars.resx b/AddCars.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/AddCars.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Car.cs b/Car.cs new file mode 100644 index 0000000..f1a478c --- /dev/null +++ b/Car.cs @@ -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; } + } +} diff --git a/CarPrice.cs b/CarPrice.cs new file mode 100644 index 0000000..5b5981b --- /dev/null +++ b/CarPrice.cs @@ -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 ConvertToCarPriceList(List cars) + { + return cars.Select(car => new CarPrice + { + Name = car.Name, + Price = car.Price + }).ToList(); + } + } +} \ No newline at end of file diff --git a/Controls/CarItem.Designer.cs b/Controls/CarItem.Designer.cs new file mode 100644 index 0000000..d24e23e --- /dev/null +++ b/Controls/CarItem.Designer.cs @@ -0,0 +1,240 @@ +namespace GtaVUsersInfo.Controls +{ + partial class CarItem + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + 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; + } +} diff --git a/Controls/CarItem.cs b/Controls/CarItem.cs new file mode 100644 index 0000000..211c3b6 --- /dev/null +++ b/Controls/CarItem.cs @@ -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(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; + } + } + } +} \ No newline at end of file diff --git a/Controls/CarItem.resx b/Controls/CarItem.resx new file mode 100644 index 0000000..ad53752 --- /dev/null +++ b/Controls/CarItem.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/Controls/ParameterControl.Designer.cs b/Controls/ParameterControl.Designer.cs new file mode 100644 index 0000000..98a5fb8 --- /dev/null +++ b/Controls/ParameterControl.Designer.cs @@ -0,0 +1,90 @@ +namespace GtaVUsersInfo.Controls +{ + partial class ParameterControl + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + 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; + } +} diff --git a/Controls/ParameterControl.cs b/Controls/ParameterControl.cs new file mode 100644 index 0000000..8610682 --- /dev/null +++ b/Controls/ParameterControl.cs @@ -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; + } + } +} diff --git a/Controls/ParameterControl.resx b/Controls/ParameterControl.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Controls/ParameterControl.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/GtaVUsersInfo.csproj b/GtaVUsersInfo.csproj index cffbae8..0757647 100644 --- a/GtaVUsersInfo.csproj +++ b/GtaVUsersInfo.csproj @@ -85,7 +85,22 @@ - + + Form + + + AddCars.cs + + + + + UserControl + + + CarItem.cs + + + Form @@ -95,6 +110,18 @@ + + UserControl + + + ParameterControl.cs + + + AddCars.cs + + + CarItem.cs + MainForm.cs @@ -107,6 +134,9 @@ True Resources.resx + + ParameterControl.cs + SettingsSingleFileGenerator diff --git a/Helpers/CarParser.cs b/Helpers/CarParser.cs index 93f18b3..f2b7eb0 100644 --- a/Helpers/CarParser.cs +++ b/Helpers/CarParser.cs @@ -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 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"); - } - } - } } diff --git a/Helpers/ErrorsShow.cs b/Helpers/ErrorsShow.cs new file mode 100644 index 0000000..f1636ea --- /dev/null +++ b/Helpers/ErrorsShow.cs @@ -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); + } + } +} diff --git a/Helpers/Strings.cs b/Helpers/ReadonlyStrings.cs similarity index 68% rename from Helpers/Strings.cs rename to Helpers/ReadonlyStrings.cs index de06b31..606f544 100644 --- a/Helpers/Strings.cs +++ b/Helpers/ReadonlyStrings.cs @@ -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"; } } diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs index 4863613..5872749 100644 --- a/MainForm.Designer.cs +++ b/MainForm.Designer.cs @@ -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; } } diff --git a/MainForm.cs b/MainForm.cs index 4382c08..aeaa534 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -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 debugControlsList; + private List carList; + public MainForm() { InitializeComponent(); + + debugControlsList = new List { parserButton, readJsonButton }; + + this.visible(debugControlsList, false); + + carList = LoadCarsFromJson(ReadonlyStrings.carJsonPath); + } + + public static List LoadCarsFromJson(string filePath) + { + try + { + string json = File.ReadAllText(filePath); + List cars = JsonConvert.DeserializeObject>(json); + + return cars; + } + catch (FileNotFoundException) + { + string message = $"Файл с автомобилями не найден: {filePath}"; + Console.WriteLine(message); + MessageBox.Show(message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return new List(); + } + catch (JsonException ex) + { + ErrorsShow.ShowErrorMessage($"Ошибка при десериализации JSON автомобилей: {ex.Message}"); + return new List(); + } + catch (Exception ex) + { + ErrorsShow.ShowErrorMessage($"Произошла неожиданная ошибка при открытии файла с автомобилями: {ex.Message}"); + return new List(); + } } 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 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); } } }