using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WPF01.pages
{
	/// <summary>
	/// Логика взаимодействия для Product.xaml
	/// </summary>
	public partial class Product : Page
	{
		db2.Test02Entities database;

		public Product()
		{
			InitializeComponent();

			database = new db2.Test02Entities();

			LoadProduct();
		}

		void LoadProduct()
		{
			var products = database.Product.ToList();

			int productCouter = 0;

			for (int i = 0; i < 2; i++)
			{
				for (int j = 0; j < 3; j++) {

					Border border = new Border();
					border.BorderBrush = Brushes.Gray;
					border.BorderThickness = new Thickness(1);
					border.Margin = new Thickness(10);
					border.Background = Brushes.White;

					ProductGrid.Children.Add(border);
					Grid.SetRow(border, i);
					Grid.SetColumn(border, j);

					StackPanel stackPanel = new StackPanel();

					border.Child = stackPanel;

					//< Image Source = "/WPF01;component/Товары автосервиса/E9308929.jpg" Height = "129" Margin = "20,10,20,0" />

					Image image = new Image();
					image.Height = 130;

					stackPanel.Children.Add(image);

					Label l1 = new Label();
					l1.Content = products[productCouter].Title;
					l1.FontSize = 10;
					l1.Foreground = Brushes.DarkMagenta;
					l1.Padding = new Thickness(0);
					l1.Margin = new Thickness(0);
					l1.HorizontalContentAlignment = HorizontalAlignment.Center;

					stackPanel.Children.Add(l1);

					Label l2 = new Label();
					l2.Content = products[productCouter].Cost;

					stackPanel.Children.Add(l2);

					if (products[productCouter].IsActive == false) {
						Label l3 = new Label();
						l3.Content = "неактивен";

						stackPanel.Children.Add(l3);

						border.Background = Brushes.LightGray;
					}

					productCouter++;
				}
			}
		}
	}
}
