2024-10-08 09:53:24 +03:00
|
|
|
|
using GtaVUsersInfo.Helpers;
|
2024-10-10 12:30:53 +03:00
|
|
|
|
using GtaVUsersInfo.Sources;
|
2024-10-08 09:53:24 +03:00
|
|
|
|
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;
|
|
|
|
|
|
2024-10-08 11:44:50 +03:00
|
|
|
|
namespace GtaVUsersInfo.Forms
|
2024-10-08 09:53:24 +03:00
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-10 12:30:53 +03:00
|
|
|
|
|
|
|
|
|
public void ChangeFonts(FontSettings settings)
|
|
|
|
|
{
|
|
|
|
|
FontSettings.ChangeFontInControls(this, settings);
|
|
|
|
|
this.Size = new Size(this.carLabel.Width, this.Size.Height);
|
|
|
|
|
}
|
2024-10-08 09:53:24 +03:00
|
|
|
|
}
|
|
|
|
|
}
|