private void btn_add_Click(object sender, RoutedEventArgs e) { int pID = int.Parse(txt_playerID.Text); String fname = txt_fname.Text; String lname = txt_lname1.Text; decimal bav = decimal.Parse(txt_battingAverage.Text); Player p = new Player(); p.PlayerID = pID; p.FirstName = fname; p.LastName = lname; p.BattingAverage = bav; dbContent = new BaseballEntities(); dbContent.Players.Load(); dbContent.Players.Add(p); dbContent.SaveChanges(); dtGrid.ItemsSource = dbContent.Players.ToList(); }
private void btn_search_Click(object sender, RoutedEventArgs e) { String playerLname; playerLname = txt_lname.Text; try { if (txt_lname.Text == "") { MessageBox.Show("No data found"); dbContent = new BaseballEntities(); dbContent.Players.Load(); dtGrid.ItemsSource = dbContent.Players.ToList(); } else { dbContent = new BaseballEntities(); dbContent.Players.Load(); var query = from item in dbContent.Players where item.LastName == txt_lname.Text select item; dtGrid.ItemsSource = query.ToList(); /* foreach (var s in query) * { * txt_modifyAverage.Text = s.BattingAverage.ToString(); * playerID = s.PlayerID; * } * // MessageBox.Show(playerID); */ } } catch (Exception ex) { MessageBox.Show("ERROR!!!!" + "\n" + ex.ToString()); } }
private void btn_modify_Click(object sender, RoutedEventArgs e) { decimal battingAverage = decimal.Parse(txt_modifyAverage.Text); dbContent = new BaseballEntities(); dbContent.Players.Load(); (from item in dbContent.Players where item.LastName == txt_lname.Text select item).ToList().ForEach(x => x.BattingAverage = battingAverage);; dbContent.SaveChanges(); //dtGrid.ItemsSource = query.ToList(); var query = from item in dbContent.Players where item.LastName == txt_lname.Text select item; dtGrid.ItemsSource = query.ToList(); }