private void ImageButton_Click(object sender, RoutedEventArgs e) { FolderBrowserDialog diag = new FolderBrowserDialog(); if (diag.ShowDialog() == System.Windows.Forms.DialogResult.OK) { ImportStatus.Visibility = Visibility.Visible; string folder = diag.SelectedPath; //selected folder path var files = Directory.GetFiles(folder); using (var bgw = new BackgroundWorker()) { bgw.DoWork += (_, __) => { ImageHelper.ImportImages(files); }; bgw.RunWorkerCompleted += (_, __) => { ImportStatus.Visibility = Visibility.Collapsed; if (usc != null) { using (var context = new ActiveRosterDBEntities()) { List <tbl_Player> players = context.tbl_Player.ToList(); usc.PlayerList.ItemsSource = players; } } }; bgw.RunWorkerAsync(); } } }
public static List <tbl_Team> GetTeams() { using (var context = new ActiveRosterDBEntities()) { return(context.tbl_Team.ToList()); } }
private void ImportButton_Click(object sender, RoutedEventArgs e) { Microsoft.Win32.OpenFileDialog openfile = new Microsoft.Win32.OpenFileDialog(); openfile.Filter = "Excel Files|*.xls;*.xlsx;*.xlsm"; var browsefile = openfile.ShowDialog(); if (browsefile == true) { ImportStatus.Visibility = Visibility.Visible; using (var bgw = new BackgroundWorker()) { bgw.DoWork += (_, __) => { ExcelHelper.ReadFile(openfile.FileName); }; bgw.RunWorkerCompleted += (_, __) => { ImportStatus.Visibility = Visibility.Collapsed; using (var context = new ActiveRosterDBEntities()) { teams = context.tbl_Team.ToList(); ListViewMenu.ItemsSource = teams; } }; bgw.RunWorkerAsync(); } } }
private void ClearButton_Click(object sender, RoutedEventArgs e) { using (var context = new ActiveRosterDBEntities()) { List <tbl_Team> teams = context.tbl_Team.ToList(); foreach (tbl_Team team in teams) { List <tbl_Player> players = context.tbl_Player.Where(p => p.Team == team.Id).ToList(); foreach (tbl_Player player in players) { context.tbl_Player.Remove(player); } context.tbl_Team.Remove(team); context.SaveChanges(); } teams = new List <tbl_Team>(); ListViewMenu.ItemsSource = teams; GridMain.Children.Clear(); } }
public static void SavePlayer(string registrationNumber, string first, string last, string weight, string dateOfBirth, string level, int team) { decimal convertedWeight = 0.0m; try { convertedWeight = Convert.ToDecimal(weight); } catch (Exception ex) { } tbl_Player player = new tbl_Player() { FirstName = first, LastName = last, Weight = convertedWeight, RegistrationNumber = registrationNumber, DateOfBirth = DateTime.ParseExact(dateOfBirth, "M/d/yyyy h:mm:ss tt", System.Globalization.CultureInfo.CurrentCulture), Team = team }; using (var context = new ActiveRosterDBEntities()) { context.tbl_Player.Add(player); context.SaveChanges(); } }
public static List <tbl_Player> GetPlayersByTeamId(int teamId) { using (var context = new ActiveRosterDBEntities()) { return(context.tbl_Player.Where(p => p.Team == teamId).ToList()); } }
public static tbl_Player GetPlayerById(int playerId) { using (var context = new ActiveRosterDBEntities()) { return(context.tbl_Player.Where(p => p.Id == playerId).FirstOrDefault()); } }
public UserControlTeam(int team) { InitializeComponent(); using (var context = new ActiveRosterDBEntities()) { players = DataHelper.GetPlayersByTeamId(team).ToList(); PlayerList.ItemsSource = players; } }
public MainWindow() { InitializeComponent(); usc = null; using (var context = new ActiveRosterDBEntities()) { teams = context.tbl_Team.ToList(); ListViewMenu.ItemsSource = teams; } }
public static void SaveImage(string playerNumber, Image image) { using (var context = new ActiveRosterDBEntities()) { tbl_Player player = context.tbl_Player.Where(p => p.RegistrationNumber.Contains(playerNumber)).FirstOrDefault(); if (player != null) { player.Image = ImageHelper.ImageToByteArray(image); context.SaveChanges(); } } }
public static int GetTeamId(string teamName) { using (var context = new ActiveRosterDBEntities()) { var team = context.tbl_Team.Where(t => t.Name == teamName).FirstOrDefault(); if (null == team) { return(-1); } else { return(team.Id); } } }
public static bool TeamExist(string teamName) { using (var context = new ActiveRosterDBEntities()) { var team = context.tbl_Team.Where(t => t.Name == teamName).FirstOrDefault(); if (null == team) { return(false); } else { return(true); } } }
public static int SaveTeam(string teamName) { tbl_Team team = new tbl_Team() { Name = teamName }; using (var context = new ActiveRosterDBEntities()) { context.tbl_Team.Add(team); context.SaveChanges(); } return(team.Id); }