MainWindow.xaml.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. namespace WpfApp2
  16. {
  17. /// <summary>
  18. /// Логика взаимодействия для MainWindow.xaml
  19. /// </summary>
  20. public partial class MainWindow : Window
  21. {
  22. public MainWindow()
  23. {
  24. InitializeComponent();
  25. user1Entities c = new user1Entities();
  26. var l = c.Service.ToList();
  27. ComboBox1.ItemsSource = l;
  28. ComboBox1.DisplayMemberPath = "Service1";
  29. ComboBox1.SelectionChanged += ComboBox1_SelectionChanged;
  30. foreach (var item in l)
  31. {
  32. CreateMaterialList(item.Service1, item.Code);
  33. }
  34. }
  35. private void ComboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
  36. {
  37. MessageBox.Show("" + ((Service)ComboBox1.SelectedItem).Code);
  38. }
  39. private void BDel_Click(object sender, RoutedEventArgs e)
  40. {
  41. MessageBox.Show("Удалить");
  42. }
  43. private void BEdit_Click(object sender, RoutedEventArgs e)
  44. {
  45. MessageBox.Show("Изменить");
  46. }
  47. private void CreateMaterialList(string text, int count)
  48. {
  49. Border border = new Border();
  50. border.Margin = new Thickness(10);
  51. border.BorderBrush = Brushes.Black;
  52. border.BorderThickness = new Thickness(1);
  53. var st1 = CreateStackPanel(0, Orientation.Horizontal);
  54. var st2 = CreateStackPanel(10, Orientation.Vertical);
  55. var st3 = CreateStackPanel(10, Orientation.Vertical);
  56. var st4 = CreateStackPanel(10, Orientation.Vertical);
  57. Image image = new Image();
  58. BitmapImage bi3 = new BitmapImage();
  59. bi3.BeginInit();
  60. bi3.UriSource = new Uri("Image/picture.png", UriKind.Relative);
  61. bi3.EndInit();
  62. image.Source = bi3;
  63. image.Width = 64;
  64. image.Margin = new Thickness(10);
  65. st2.Children.Add(image);
  66. st3.Width = 520;
  67. st3.Children.Add(CreateTextBlock("Металл | Хирургическая сталь", 20));
  68. st3.Children.Add(CreateTextBlock("Минимальное количество: " + count + "шт", 14));
  69. st3.Children.Add(CreateTextBlock(text, 14));
  70. st4.Children.Add(CreateTextBlock("Остаток: " + count + "шт"));
  71. Button bEdit = new Button();
  72. bEdit.Content = "Изменить";
  73. bEdit.Click += BEdit_Click;
  74. Button bDel = new Button();
  75. bDel.Content = "Удалить";
  76. bDel.Click += BDel_Click;
  77. st4.Children.Add(bEdit);
  78. st4.Children.Add(bDel);
  79. st1.Children.Add(st2);
  80. st1.Children.Add(st3);
  81. st1.Children.Add(st4);
  82. border.Child = st1;
  83. StackPanel1.Children.Add(border);
  84. }
  85. private StackPanel CreateStackPanel(double margin, Orientation orientation)
  86. {
  87. StackPanel st = new StackPanel();
  88. st.Margin = new Thickness(margin);
  89. st.Orientation = orientation;
  90. return st;
  91. }
  92. private TextBlock CreateTextBlock(string text, double fontSize = 14)
  93. {
  94. TextBlock tb = new TextBlock();
  95. tb.Text = text;
  96. tb.FontSize = fontSize;
  97. return tb;
  98. }
  99. }
  100. }