/// <summary> /// Pokazuje rezultate koji su napravljeni na engleskom jeziku. /// </summary> private void btnEnglish_Click(object sender, EventArgs e) { LoadingHighscore(); List <Highscore> englishHighscore = new List <Highscore>(); foreach (Highscore score in SortedList) { if (score.language == false) { englishHighscore.Add(score); } } if (englishHighscore.Count > 10) { using (dbTypingGameEntities baza = new dbTypingGameEntities()) { baza.Highscore.Attach(englishHighscore[englishHighscore.Count - 1]); baza.Highscore.Remove(englishHighscore[englishHighscore.Count - 1]); baza.SaveChanges(); } englishHighscore.Remove(englishHighscore[englishHighscore.Count - 1]); } highscoreBindingSource.DataSource = englishHighscore; }
/// <summary> /// Pokazuje rezultate koji su napravljeni na hrvatskom jeziku. /// </summary> private void btnCroatian_Click(object sender, EventArgs e) { LoadingHighscore(); List <Highscore> croatianHighscore = new List <Highscore>(); foreach (Highscore score in SortedList) { if (score.language == true) { croatianHighscore.Add(score); } } if (croatianHighscore.Count > 10) { using (dbTypingGameEntities baza = new dbTypingGameEntities()) { baza.Highscore.Attach(croatianHighscore[croatianHighscore.Count - 1]); baza.Highscore.Remove(croatianHighscore[croatianHighscore.Count - 1]); baza.SaveChanges(); } croatianHighscore.Remove(croatianHighscore[croatianHighscore.Count - 1]); } highscoreBindingSource.DataSource = croatianHighscore; }
/// <summary> /// Provjerava je li rezultat dovoljan za ući na listu. /// </summary> private void CheckForHighscore(int iCPM, int iWPM) { List <Highscore> sortedList = null; BindingList <Highscore> list = null; using (dbTypingGameEntities baza = new dbTypingGameEntities()) { list = new BindingList <Highscore>(baza.Highscore.ToList()); } sortedList = list.OrderByDescending(o => o.CPM).ToList(); List <Highscore> listEnglish = new List <Highscore>(); List <Highscore> listCroatian = new List <Highscore>(); foreach (Highscore item in sortedList) { if (item.language == hrvat) { listCroatian.Add(item); } else { listEnglish.Add(item); } } if (hrvat) { if (listCroatian.Count < 10 || listCroatian[listCroatian.Count - 1].CPM < iCPM) { ScoreInput scoreInput = new ScoreInput(iCPM, iWPM, hrvat); scoreInput.ShowDialog(); ShowHighscore(); } else { ShowHighscore(); } } else { if (listEnglish.Count < 10 || listEnglish[listEnglish.Count - 1].CPM < iCPM) { ScoreInput scoreInput = new ScoreInput(iCPM, iWPM, hrvat); scoreInput.ShowDialog(); ShowHighscore(); } else { ShowHighscore(); } } }
/// <summary> /// Učitava Highscore tablicu /// </summary> private void LoadingHighscore() { BindingList <Highscore> lista = null; using (dbTypingGameEntities baza = new dbTypingGameEntities()) { lista = new BindingList <Highscore>(baza.Highscore.ToList()); } SortedList = lista.OrderByDescending(o => o.CPM).ToList(); FirstTenHighscores = SortedList.Take(10).ToList(); }
/// <summary> /// Gumb prilikom kojeg se usnimava rezultat. /// </summary> private void btnSave_Click(object sender, EventArgs e) { using (dbTypingGameEntities baza = new dbTypingGameEntities()) { Highscore highscore = new Highscore { nickname = txtName.Text, CPM = CPM, WPM = WPM, language = Hrv, }; baza.Highscore.Add(highscore); baza.SaveChanges(); } Close(); }