private void BtnLogin_Click(object sender, RoutedEventArgs e) { try { string requestUrl = null; requestUrl = _hostUrl + $"/api/jsstudygame/login?emailOrLogin={txtLogin.Text}&password={txtPassword.Text}"; PlayerVM playerVM = ServerWorker.GetInfoFromServer <PlayerVM>(requestUrl); if (playerVM == null) { MessageBox.Show("Enter correct data!", "Error"); } else if (playerVM.Login == "none" && playerVM.Password == "none") { MessageBox.Show("Incorrect data! Try again!"); return; } else { Hide(); MainWindow.playerLogin = playerVM.Login; MainWindow.playerPassword = playerVM.Password; main = new MainWindow(_hostUrl); main.Owner = this; main.ShowDialog(); txtLogin.Text = $"{MainWindow.playerLogin}"; txtPassword.Text = $"{MainWindow.playerPassword}"; Show(); } } catch (Exception) { MessageBox.Show("Cannot connect to server!"); } }
private void BtnAdmin_Click(object sender, RoutedEventArgs e) { if (_isGame) { MessageBox.Show("At first you must end the game!"); return; } this.Hide(); AdminWindow admin = new AdminWindow(_hostUrl); admin.Owner = this; admin.ShowDialog(); if (MainWindow.playerLogin == "none" && MainWindow.playerPassword == "none") { this.Close(); return; } requestUrl = _hostUrl + $"/api/jsstudygame/login?emailOrLogin={MainWindow.playerLogin}&password={MainWindow.playerPassword}"; _player = ServerWorker.GetInfoFromServer <PlayerVM>(requestUrl); requestUrl = _hostUrl + $"/api/jsstudygame/addinfo?login={MainWindow.playerLogin}&password={MainWindow.playerPassword}"; _playerAddInfo = ServerWorker.GetInfoFromServer <PlayerAdditionalInfoVM>(requestUrl); requestUrl = _hostUrl + $"/api/jsstudygame/score?login={MainWindow.playerLogin}&password={MainWindow.playerPassword}"; _playerScore = ServerWorker.GetInfoFromServer <PlayerScoreVM>(requestUrl); _playerScore.IdPlayerScore = _player.Id; this.ShowDialog(); }
private void GetDataFromWebServer() { try { string requestUrl = _hostUrl + $"/api/jsstudygame/fullinfo?login={MainWindow.playerLogin}&password={MainWindow.playerPassword}&page={_activePage}&sword={_sword}"; _playersFullInfo = ServerWorker.GetInfoFromServer <ObservableCollection <PlayerFullInfo> >(requestUrl); if (_playersFullInfo == null) { dgShow.ItemsSource = null; return; } foreach (var item in _playersFullInfo) { item.Photo = _hostUrl + $"/photos/{item.Photo}"; } dgShow.ItemsSource = _playersFullInfo; MyPadding(); } catch (Exception) { MessageBox.Show("Cannot connect to server!"); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { _activePage = 1; string requestUrl = _hostUrl + $"/api/jsstudygame/amountofplayers?login={MainWindow.playerLogin}&password={MainWindow.playerPassword}"; TotalPlayers = ServerWorker.GetInfoFromServer <int>(requestUrl); if (TotalPlayers == 0) { TotalPlayers = 1; } _sword = null; GetDataFromWebServer(); }
private void BtnSearch_Click(object sender, RoutedEventArgs e) { _activePage = 1; wpWithDGV.Children.Clear(); _sword = txtboxSearch.Text; string requestUrl = _hostUrl + $"/api/jsstudygame/amountsearch?login={MainWindow.playerLogin}&password={MainWindow.playerPassword}&sword={_sword}"; TotalPlayers = ServerWorker.GetInfoFromServer <int>(requestUrl); if (TotalPlayers == 0) { TotalPlayers = 1; } GetDataFromWebServer(); }
private void DpScore_Loaded(object sender, RoutedEventArgs e) { string requestUrl = _hostUrl + $"/api/jsstudygame/score?login={MainWindow.playerLogin}&password={MainWindow.playerPassword}"; scoreVM = ServerWorker.GetInfoFromServer <PlayerScoreVM>(requestUrl); if (scoreVM == null) { return; } lblTotal.Content = scoreVM.TotalScore; lblCorrectAnswers.Content = scoreVM.CorrectAnswers; lblIncorrectAnswers.Content = scoreVM.IncorrectAnswers; lblSkippedAnswers.Content = scoreVM.SkippedAnswers; lblTimeGameInSeconds.Content = scoreVM.TimeGameInSeconds; lblProgressInGame.Content = scoreVM.ProgressInGame + " %"; }
private void BtnChange_Click(object sender, RoutedEventArgs e) { if (!(dgShow.SelectedItem is PlayerFullInfo)) { dgShow.SelectedItem = null; return; } string login = MainWindow.playerLogin; string password = MainWindow.playerPassword; MainWindow.playerLogin = ((PlayerFullInfo)dgShow.SelectedItem).Login; MainWindow.playerPassword = ((PlayerFullInfo)dgShow.SelectedItem).Password; this.Hide(); ProfileWindow profile = new ProfileWindow(_hostUrl); profile.Owner = this; profile.ShowDialog(); var currentPlayer = _playersFullInfo.SingleOrDefault(p => p.Login == MainWindow.playerLogin && p.Password == MainWindow.playerPassword); var requestUrl = _hostUrl + $"/api/jsstudygame/login?emailOrLogin={MainWindow.playerLogin}&password={MainWindow.playerPassword}"; var player = ServerWorker.GetInfoFromServer <PlayerVM>(requestUrl); requestUrl = _hostUrl + $"/api/jsstudygame/addinfo?login={MainWindow.playerLogin}&password={MainWindow.playerPassword}"; var playerAddInfo = ServerWorker.GetInfoFromServer <PlayerAdditionalInfoVM>(requestUrl); currentPlayer.Id = player.Id; currentPlayer.Password = player.Password; currentPlayer.Email = player.Email; currentPlayer.Login = player.Login; currentPlayer.IsAdmin = player.IsAdmin; currentPlayer.Name = playerAddInfo.Name; currentPlayer.Surname = playerAddInfo.Surname; currentPlayer.Photo = _hostUrl + $"/photos/{playerAddInfo.Photo}"; currentPlayer.BirthDate = playerAddInfo.BirthDate; currentPlayer.Gender = playerAddInfo.Gender == true ? "male" : "female"; MainWindow.playerLogin = login; MainWindow.playerPassword = password; this.ShowDialog(); }
private void Window_Loaded(object sender, RoutedEventArgs e) { string requestUrl = null; requestUrl = _hostUrl + $"/api/jsstudygame/login?emailOrLogin={MainWindow.playerLogin}&password={MainWindow.playerPassword}"; playerVM = ServerWorker.GetInfoFromServer <PlayerVM>(requestUrl); txtLogin.Text = playerVM.Login; txtLogin.IsReadOnly = true; txtEmail.Text = playerVM.Email; txtEmail.IsReadOnly = true; txtEmail.Text = playerVM.Email; txtPasswordOne.Password = playerVM.Password; txtPasswordOne.IsEnabled = false; txtPasswordOneTxt.Text = playerVM.Password; txtPasswordOneTxt.IsReadOnly = true; txtPasswordTwo.Password = playerVM.Password; txtPasswordTwoTxt.Text = playerVM.Password; txtPasswordTwoTxt.IsReadOnly = true; requestUrl = _hostUrl + $"/api/jsstudygame/addinfo?login={MainWindow.playerLogin}&password={MainWindow.playerPassword}"; playerAddInfoVM = ServerWorker.GetInfoFromServer <PlayerAdditionalInfoVM>(requestUrl); txtName.Text = playerAddInfoVM.Name; txtName.IsReadOnly = true; txtSurname.Text = playerAddInfoVM.Surname; txtSurname.IsReadOnly = true; dateChoose.SelectedDate = playerAddInfoVM.BirthDate; if (playerAddInfoVM.Gender == true) { radioBtnMale.IsChecked = true; radioBtnFemale.Visibility = Visibility.Hidden; } else { radioBtnFemale.IsChecked = true; radioBtnMale.Visibility = Visibility.Hidden; } ImgPhotoAndPicture_Loaded(sender, e); }
public MainWindow(string hostUrl) { _hostUrl = hostUrl; InitializeComponent(); requestUrl = _hostUrl + $"/api/jsstudygame/login?emailOrLogin={MainWindow.playerLogin}&password={MainWindow.playerPassword}"; _player = ServerWorker.GetInfoFromServer <PlayerVM>(requestUrl); requestUrl = _hostUrl + $"/api/jsstudygame/addinfo?login={MainWindow.playerLogin}&password={MainWindow.playerPassword}"; _playerAddInfo = ServerWorker.GetInfoFromServer <PlayerAdditionalInfoVM>(requestUrl); requestUrl = _hostUrl + $"/api/jsstudygame/score?login={MainWindow.playerLogin}&password={MainWindow.playerPassword}"; _playerScore = ServerWorker.GetInfoFromServer <PlayerScoreVM>(requestUrl); _playerScore.IdPlayerScore = _player.Id; requestUrl = _hostUrl + $"/api/jsstudygame/amountoftests?login={MainWindow.playerLogin}&password={MainWindow.playerPassword}"; _amountoftests = ServerWorker.GetInfoFromServer <int>(requestUrl); if (_amountoftests == 0) { _amountoftests = 1; } if (_player.IsAdmin) { btnAdmin.Visibility = Visibility.Visible; } spStartGame.Visibility = Visibility.Hidden; btnReference.Visibility = Visibility.Hidden; _skippedAnswer = new List <string>(); _wrongAnswer = new List <string>(); if (!string.IsNullOrWhiteSpace(_playerScore.AnswersSkipped)) { _skippedAnswer = _playerScore.AnswersSkipped.Split(',').ToList(); if (_skippedAnswer != null) { _skippedAnswer.Sort(); } foreach (var item in _skippedAnswer) { cbSkipped.Items.Add($"<< {item} >>"); } } if (!string.IsNullOrWhiteSpace(_playerScore.AnswersWrong)) { _wrongAnswer = _playerScore.AnswersWrong.Split(',').ToList(); if (_wrongAnswer != null) { _wrongAnswer.Sort(); } foreach (var item in _wrongAnswer) { cbWrong.Items.Add($"<< {item} >>"); } } _stopwatch = new Stopwatch(); Task.Run(() => { string imgPathStr = _hostUrl + $"/images/jsImg2.jpg"; Uri resourceUri = new Uri(imgPathStr, UriKind.Absolute); this.Dispatcher.Invoke(() => { backgroundImg.ImageSource = new BitmapImage(resourceUri); }); }); }
private bool UpdateQuestion(int idTest) { _isAnswer = false; if (CheckIsWinOrEndQuestions(idTest)) { return(false); } spStartGame.Visibility = Visibility.Visible; btnReference.Visibility = Visibility.Visible; btnNextQuestion.Visibility = Visibility.Visible; btnAnswerA.Background = Brushes.LightGray; btnAnswerB.Background = Brushes.LightGray; btnAnswerC.Background = Brushes.LightGray; btnAnswerD.Background = Brushes.LightGray; lblResult.Content = null; lblResult.Background = null; lblResult.Foreground = null; requestUrl = _hostUrl + $"/api/jsstudygame/test?login={MainWindow.playerLogin}" + $"&password={MainWindow.playerPassword}&id={idTest}"; _test = ServerWorker.GetInfoFromServer <TestVM>(requestUrl); if (_test == null) { return(false); } txtbtnAnswerA.Text = null; txtbtnAnswerB.Text = null; txtbtnAnswerC.Text = null; txtbtnAnswerD.Text = null; Random random = new Random(); switch (random.Next(4)) { case 0: txtQuestion.Text = _test.Question; txtbtnAnswerA.Text = _test.CorrectAnswer; txtbtnAnswerB.Text = _test.AnswerA; txtbtnAnswerC.Text = _test.AnswerB; txtbtnAnswerD.Text = _test.AnswerC; break; case 1: txtbtnAnswerA.Text = _test.AnswerA; txtbtnAnswerB.Text = _test.CorrectAnswer; txtbtnAnswerC.Text = _test.AnswerB; txtbtnAnswerD.Text = _test.AnswerC; break; case 2: txtbtnAnswerA.Text = _test.AnswerA; txtbtnAnswerB.Text = _test.AnswerB; txtbtnAnswerC.Text = _test.CorrectAnswer; txtbtnAnswerD.Text = _test.AnswerC; break; case 3: txtbtnAnswerA.Text = _test.AnswerA; txtbtnAnswerB.Text = _test.AnswerB; txtbtnAnswerC.Text = _test.AnswerC; txtbtnAnswerD.Text = _test.CorrectAnswer; break; default: txtbtnAnswerA.Text = _test.AnswerA; txtbtnAnswerB.Text = _test.AnswerB; txtbtnAnswerC.Text = _test.AnswerC; txtbtnAnswerD.Text = _test.CorrectAnswer; break; } txtQuestion.Text = _test.Question; lblQuestionN.Content = _test.Id; try { requestUrl = _hostUrl + $"/api/jsstudygame/section?login={MainWindow.playerLogin}" + $"&password={MainWindow.playerPassword}&id={_test.IdSection}"; _sectionVM = ServerWorker.GetInfoFromServer <SectionVM>(requestUrl); if (_sectionVM != null) { lblSection.Content = _sectionVM.NameOFSection; } } catch (Exception) { Debug.WriteLine("some mistake"); } return(true); }