StaffWindow.xaml.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Shapes;
  15. namespace olimp8
  16. {
  17. /// <summary>
  18. /// Interaction logic for StaffWindow.xaml
  19. /// </summary>
  20. public partial class StaffWindow : Window
  21. {
  22. olimp_8Entities entities = new olimp_8Entities();
  23. public User currentUser { get; set; }
  24. public List<int> idUsers = new List<int>();
  25. ObservableCollection<User> UserCollection = new ObservableCollection<User>();
  26. public StaffWindow(string _login)
  27. {
  28. InitializeComponent();
  29. usersList.ItemsSource = entities.User.ToList();
  30. LoginLabel.Content = _login;
  31. }
  32. private void Button_Click(object sender, RoutedEventArgs e)
  33. {
  34. if (CurrentStaff.Items == null)
  35. {
  36. MessageBox.Show("Добавьте работников!");
  37. return;
  38. }
  39. else
  40. {
  41. string _numberStaff = RandomString(5);
  42. for (int i = 0; i < CurrentStaff.Items.Count; i++)
  43. {
  44. StaffList newStaff = new StaffList
  45. {
  46. UserID = idUsers[i],
  47. Number = _numberStaff
  48. };
  49. entities.StaffList.Add(newStaff);
  50. }
  51. entities.SaveChanges();
  52. MessageBox.Show("Команда #: " + _numberStaff + " добавлена!");
  53. }
  54. }
  55. private void Button_Click_1(object sender, RoutedEventArgs e)
  56. {
  57. idUsers.Clear();
  58. CurrentStaff.Items.Clear();
  59. }
  60. private void ListButton_Click(object sender, RoutedEventArgs e)
  61. {
  62. currentUser = (sender as Button).DataContext as User;
  63. if (CurrentStaff.Items.Contains(currentUser))
  64. {
  65. MessageBox.Show("Этот пользователь уже в списке!");
  66. return;
  67. }
  68. else
  69. {
  70. UserCollection.Add(currentUser);
  71. idUsers.Add(currentUser.IdUser);
  72. CurrentStaff.Items.Add(currentUser);
  73. }
  74. }
  75. private static Random random = new Random();
  76. public static string RandomString(int length)
  77. {
  78. const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  79. return new string(Enumerable.Repeat(chars, length).Select(s => s[random.Next(s.Length)]).ToArray());
  80. }
  81. private void Button_Click_2(object sender, RoutedEventArgs e)
  82. {
  83. string Login = Convert.ToString(LoginLabel.Content);
  84. MainWindow mainWindow = new MainWindow(Login);
  85. mainWindow.Show();
  86. this.Hide();
  87. }
  88. private void Button_Click_3(object sender, RoutedEventArgs e)
  89. {
  90. CreateStaffWindow createStaffWindow = new CreateStaffWindow();
  91. createStaffWindow.Show();
  92. }
  93. }
  94. }