Diagram.xaml.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. using PP_Ven_MosS.Classes;
  16. using PP_Ven_MosS.ModelBase;
  17. namespace PP_Ven_MosS.Pages
  18. {
  19. /// <summary>
  20. /// Логика взаимодействия для Diagram.xaml
  21. /// </summary>
  22. public partial class Diagram : Page
  23. {
  24. public Diagram()
  25. {
  26. InitializeComponent();
  27. Sort();
  28. }
  29. async public void Sort()
  30. {
  31. User user = Database.entities.User.ToList().Where(x => x.Id_role == 2).FirstOrDefault();
  32. List<Rectangle> rectangles = new List<Rectangle>(); ;
  33. List<User> users = await Task.Run(() =>
  34. {
  35. return Database.entities.User.Where(x => x.Id_role == 2).ToList();
  36. });
  37. int[] mass = new int[users.Count];
  38. foreach (var usr in users)
  39. {
  40. Rectangle newRectangle = new Rectangle();
  41. newRectangle.Width = 100;
  42. newRectangle.Height = Convert.ToInt32(usr.Count_complete_app) * 30;
  43. if (usr.Count_complete_app > 5)
  44. {
  45. newRectangle.Fill = new SolidColorBrush(Colors.Green);
  46. }
  47. else if (usr.Count_complete_app < 2)
  48. {
  49. newRectangle.Fill = new SolidColorBrush(Colors.Red);
  50. }
  51. else
  52. {
  53. newRectangle.Fill = new SolidColorBrush(Colors.Blue);
  54. }
  55. newRectangle.Margin = new Thickness(20, 0, 0, 0);
  56. newRectangle.VerticalAlignment = VerticalAlignment.Bottom;
  57. dgm.Children.Add(newRectangle);
  58. rectangles.Add(newRectangle);
  59. }
  60. foreach (var usr in users)
  61. {
  62. TextBlock block = new TextBlock
  63. {
  64. Text = usr.Surname,
  65. HorizontalAlignment = HorizontalAlignment.Center,
  66. VerticalAlignment = VerticalAlignment.Bottom,
  67. Width = 100,
  68. Margin = new Thickness(20, 250, 0, 0)
  69. };
  70. dgmu.Children.Add(block);
  71. }
  72. }
  73. private void Button_Click(object sender, RoutedEventArgs e)
  74. {
  75. System.Windows.Controls.PrintDialog printDialog = new PrintDialog();
  76. if (printDialog.ShowDialog() == true)
  77. {
  78. printDialog.PrintVisual(diagram, "Отчет");
  79. }
  80. }
  81. private void Exit_Click(object sender, RoutedEventArgs e)
  82. {
  83. FrameClass.MainFrame.Navigate(new MenuAdmin());
  84. }
  85. }
  86. }