/
Ermoha
/
SqlDataDrivers
Обзор
Документация
Войти
/
Ermoha
/
SqlDataDrivers
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
ProductCardControl.cs
117 строк
4 KB
ermoh
Добавьте файлы проекта.
26 май 2026, 22:28
26 май 2026, 22:28
b563253
Код
Авторство
О чём код?
using System; using System.Data; using System.Drawing; using System.Globalization; using System.Windows.Forms; namespace Demo { internal partial class ProductCardControl : UserControl { public event EventHandler ProductSelected; public int ProductId { get; private set; } public ProductCardControl() { InitializeComponent(); } public ProductCardControl(DataRow row, bool canEdit) : this() { FillData(row); if (canEdit) { Cursor = Cursors.Hand; AddClickHandler(this); } } private void FillData(DataRow row) { ProductId = Convert.ToInt32(row["ProductId"]); int quantity = Convert.ToInt32(row["Quantity"]); int discount = Convert.ToInt32(row["Discount"]); decimal price = Convert.ToDecimal(row["Price"]); decimal finalPrice = price - price * discount / 100m; SetColors(quantity, discount); photoPictureBox.Image = AppHelper.LoadImage(row["PhotoPath"].ToString()); titleInfoLabel.Text = row["CategoryName"] + " | " + row["ProductName"]; descriptionValueLabel.Text = row["Description"].ToString(); manufacturerValueLabel.Text = row["ManufacturerName"].ToString(); supplierValueLabel.Text = row["SupplierName"].ToString(); unitValueLabel.Text = row["UnitName"].ToString(); quantityValueLabel.Text = quantity.ToString(); discountPercentLabel.Text = discount + "%"; oldPriceLabel.Text = price.ToString("0.00", CultureInfo.InvariantCulture) + " руб."; newPriceLabel.Text = finalPrice.ToString("0.00", CultureInfo.InvariantCulture) + " руб."; normalPriceLabel.Text = price.ToString("0.00", CultureInfo.InvariantCulture) + " руб."; oldPriceLabel.Visible = discount > 0; newPriceLabel.Visible = discount > 0; normalPriceLabel.Visible = discount == 0; } private void SetColors(int quantity, int discount) { Color cardColor = Color.White; if (discount > 15) { cardColor = ColorTranslator.FromHtml("#2E8B57"); } BackColor = cardColor; photoPanel.BackColor = cardColor; infoPanel.BackColor = cardColor; discountPanel.BackColor = cardColor; titleInfoLabel.BackColor = cardColor; descriptionTitleLabel.BackColor = cardColor; descriptionValueLabel.BackColor = cardColor; manufacturerTitleLabel.BackColor = cardColor; manufacturerValueLabel.BackColor = cardColor; supplierTitleLabel.BackColor = cardColor; supplierValueLabel.BackColor = cardColor; unitTitleLabel.BackColor = cardColor; unitValueLabel.BackColor = cardColor; quantityTitleLabel.BackColor = cardColor; quantityValueLabel.BackColor = cardColor; priceTitleLabel.BackColor = cardColor; oldPriceLabel.BackColor = cardColor; newPriceLabel.BackColor = cardColor; normalPriceLabel.BackColor = cardColor; discountTitleLabel.BackColor = cardColor; discountPercentLabel.BackColor = cardColor; discountPercentLabel.ForeColor = Color.Black; if (quantity == 0 && discount <= 15) { quantityTitleLabel.BackColor = Color.LightBlue; quantityValueLabel.BackColor = Color.LightBlue; } } private void AddClickHandler(Control control) { control.Click += Card_Click; foreach (Control child in control.Controls) { AddClickHandler(child); } } private void Card_Click(object sender, EventArgs e) { if (ProductSelected != null) { ProductSelected(this, EventArgs.Empty); } } } }