123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- 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 WpfApp2
- {
- /// <summary>
- /// Логика взаимодействия для MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- user1Entities c = new user1Entities();
- var l = c.Service.ToList();
- ComboBox1.ItemsSource = l;
- ComboBox1.DisplayMemberPath = "Service1";
- ComboBox1.SelectionChanged += ComboBox1_SelectionChanged;
- foreach (var item in l)
- {
- CreateMaterialList(item.Service1, item.Code);
- }
- }
- private void ComboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- MessageBox.Show("" + ((Service)ComboBox1.SelectedItem).Code);
- }
- private void BDel_Click(object sender, RoutedEventArgs e)
- {
- MessageBox.Show("Удалить");
- }
- private void BEdit_Click(object sender, RoutedEventArgs e)
- {
- MessageBox.Show("Изменить");
- }
- private void CreateMaterialList(string text, int count)
- {
- Border border = new Border();
- border.Margin = new Thickness(10);
- border.BorderBrush = Brushes.Black;
- border.BorderThickness = new Thickness(1);
- var st1 = CreateStackPanel(0, Orientation.Horizontal);
- var st2 = CreateStackPanel(10, Orientation.Vertical);
- var st3 = CreateStackPanel(10, Orientation.Vertical);
- var st4 = CreateStackPanel(10, Orientation.Vertical);
- Image image = new Image();
- BitmapImage bi3 = new BitmapImage();
- bi3.BeginInit();
- bi3.UriSource = new Uri("Image/picture.png", UriKind.Relative);
- bi3.EndInit();
- image.Source = bi3;
- image.Width = 64;
- image.Margin = new Thickness(10);
- st2.Children.Add(image);
- st3.Width = 520;
- st3.Children.Add(CreateTextBlock("Металл | Хирургическая сталь", 20));
- st3.Children.Add(CreateTextBlock("Минимальное количество: " + count + "шт", 14));
- st3.Children.Add(CreateTextBlock(text, 14));
- st4.Children.Add(CreateTextBlock("Остаток: " + count + "шт"));
- Button bEdit = new Button();
- bEdit.Content = "Изменить";
- bEdit.Click += BEdit_Click;
- Button bDel = new Button();
- bDel.Content = "Удалить";
- bDel.Click += BDel_Click;
- st4.Children.Add(bEdit);
- st4.Children.Add(bDel);
- st1.Children.Add(st2);
- st1.Children.Add(st3);
- st1.Children.Add(st4);
- border.Child = st1;
- StackPanel1.Children.Add(border);
- }
- private StackPanel CreateStackPanel(double margin, Orientation orientation)
- {
- StackPanel st = new StackPanel();
- st.Margin = new Thickness(margin);
- st.Orientation = orientation;
- return st;
- }
- private TextBlock CreateTextBlock(string text, double fontSize = 14)
- {
- TextBlock tb = new TextBlock();
- tb.Text = text;
- tb.FontSize = fontSize;
- return tb;
- }
- }
- }
|