ProductDetailsForm.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System.Drawing;
  2. using System.Windows.Forms;
  3. namespace TradeApp.WinForms.V08;
  4. public sealed partial class ProductDetailsForm : Form
  5. {
  6. private readonly ProductView _product;
  7. public ProductDetailsForm(ProductView product)
  8. {
  9. _product = product;
  10. InitializeComponent();
  11. FillProduct();
  12. }
  13. private void ProductDetailsForm_Load(object? sender, EventArgs e)
  14. {
  15. LoadProductImage();
  16. }
  17. private void CloseButton_Click(object? sender, EventArgs e)
  18. {
  19. Close();
  20. }
  21. private void FillProduct()
  22. {
  23. Text = $"Карточка товара - {_product.Name}";
  24. titleLabel.Text = $"{_product.Category} | {_product.Name}";
  25. descriptionValueLabel.Text = string.IsNullOrWhiteSpace(_product.Description) ? "Нет описания" : _product.Description;
  26. manufacturerValueLabel.Text = _product.Manufacturer;
  27. supplierValueLabel.Text = _product.Supplier;
  28. priceValueLabel.Text = $"{_product.Price:N2} руб.";
  29. if (_product.DiscountPercent > 0)
  30. {
  31. priceValueLabel.Font = new Font(priceValueLabel.Font, FontStyle.Strikeout);
  32. priceValueLabel.ForeColor = Color.Red;
  33. }
  34. else
  35. {
  36. priceValueLabel.Font = new Font(priceValueLabel.Font, FontStyle.Regular);
  37. priceValueLabel.ForeColor = Color.Black;
  38. }
  39. AsyncTaskOriginalPrice.Visible = false;
  40. unitValueLabel.Text = _product.Unit;
  41. stockValueLabel.Text = _product.StockQuantity.ToString();
  42. articleValueLabel.Text = _product.Article;
  43. AsyncTaskDiscountValue.Text = $"{_product.DiscountPercent:N2}%";
  44. finalPriceValueLabel.Text = $"{_product.FinalPrice:N2} руб.";
  45. }
  46. private void LoadProductImage()
  47. {
  48. var path = Path.Combine(AppContext.BaseDirectory, "Images", _product.ImagePath);
  49. if (!File.Exists(path))
  50. {
  51. path = Path.Combine(AppContext.BaseDirectory, "Images", "picture.png");
  52. }
  53. productPictureBox.Image = File.Exists(path) ? Image.FromFile(path) : null;
  54. photoPlaceholderLabel.Visible = productPictureBox.Image is null;
  55. }
  56. }