using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
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.Shapes;
namespace olimp8
{
///
/// Interaction logic for StaffWindow.xaml
///
public partial class StaffWindow : Window
{
olimp_8Entities entities = new olimp_8Entities();
public User currentUser { get; set; }
public List idUsers = new List();
ObservableCollection UserCollection = new ObservableCollection();
public StaffWindow(string _login)
{
InitializeComponent();
usersList.ItemsSource = entities.User.ToList();
LoginLabel.Content = _login;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
if (CurrentStaff.Items == null)
{
MessageBox.Show("Добавьте работников!");
return;
}
else
{
string _numberStaff = RandomString(5);
for (int i = 0; i < CurrentStaff.Items.Count; i++)
{
StaffList newStaff = new StaffList
{
UserID = idUsers[i],
Number = _numberStaff
};
entities.StaffList.Add(newStaff);
}
entities.SaveChanges();
MessageBox.Show("Команда #: " + _numberStaff + " добавлена!");
}
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
idUsers.Clear();
CurrentStaff.Items.Clear();
}
private void ListButton_Click(object sender, RoutedEventArgs e)
{
currentUser = (sender as Button).DataContext as User;
if (CurrentStaff.Items.Contains(currentUser))
{
MessageBox.Show("Этот пользователь уже в списке!");
return;
}
else
{
UserCollection.Add(currentUser);
idUsers.Add(currentUser.IdUser);
CurrentStaff.Items.Add(currentUser);
}
}
private static Random random = new Random();
public static string RandomString(int length)
{
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
return new string(Enumerable.Repeat(chars, length).Select(s => s[random.Next(s.Length)]).ToArray());
}
private void Button_Click_2(object sender, RoutedEventArgs e)
{
string Login = Convert.ToString(LoginLabel.Content);
MainWindow mainWindow = new MainWindow(Login);
mainWindow.Show();
this.Hide();
}
private void Button_Click_3(object sender, RoutedEventArgs e)
{
CreateStaffWindow createStaffWindow = new CreateStaffWindow();
createStaffWindow.Show();
}
}
}