private void OnQuestionAnswersReceived(QuestionModel model) { while (!this.IsHandleCreated); if (this.InvokeRequired) { this.Invoke((QuestionController.ExternalEventHandler) OnQuestionAnswersReceived, model); return; } int start = 0; if (answersRichTextBox.Text.Length != 0) start = model.Answers.Count - 1; for (int i=start; i<model.Answers.Count; i++) { answersRichTextBox.SelectionStart = answersRichTextBox.Text.Length; answersRichTextBox.SelectionFont = new Font("Verdana", 8, FontStyle.Bold); answersRichTextBox.SelectionBackColor = Color.LightGray; UserData owner = new UserData("x","y"); for (int j = 0; j < model.AnswerOwners.Count; j++) if (model.Answers[i].Owner == model.AnswerOwners[j].Id) { owner = model.AnswerOwners[j]; break; } answersRichTextBox.SelectedText = owner.Username + "\t" + model.Answers[i].Timestamp + "\n"; answersRichTextBox.SelectedRtf = model.Answers[i].Content; answersRichTextBox.SelectedText = "\n\n"; } answersRichTextBox.ScrollToCaret(); int index = 0; ratingUsers = new Dictionary<RatingControl, UserData>(); usersPanel.Controls.Clear(); foreach (UserData user in model.AnswerOwners) { RatingControl voteWidget = new RatingControl(); voteWidget.Location = new Point(10, 27 + index * 45); voteWidget.AutoSize = false; voteWidget.Scale(new SizeF((float)0.45, (float)0.5)); voteWidget.Fixed = false; if (user.Id == LoggedInUserModel.Instance.User.Id) voteWidget.Enabled = false; voteWidget.SelectRating += new Rating.RatingControl.SelectRatingHandler(this.onVoteWidgetClick); if (model.My_votes.ContainsKey(user.Id)) voteWidget.Rating = model.My_votes[user.Id]; else controller.CheckUserVote(user); usersPanel.Controls.Add(voteWidget); Label userLabel = new Label(); userLabel.Text = user.Username + " (" + String.Format("{0:0.##}", user.Rank) + ")"; userLabel.Location = new Point(55, 15 + index * 22); userLabel.AutoSize = true; usersPanel.Controls.Add(userLabel); userLabels.Add(userLabel, user.Id); userLabel.MouseClick += new System.Windows.Forms.MouseEventHandler(userClicked); index++; ratingUsers.Add(voteWidget, user); } postRichTextBox.Focus(); changeStateIMButtons(model); }
private void OnAllTestsFinished(NewAccountModel model) { while (!this.IsHandleCreated); if (this.InvokeRequired) { this.Invoke((NewAccountController.ExternalEventHandler) OnAllTestsFinished, model); return; } timer1.Enabled = false; if (type == TAKE_NEW_CERT) { int score = model.GetScoreForTest(0); if (score >= NewAccountModel.MIN_PASSING_SCORE) { MessageBox.Show( "You obtained " + score + " points and received the certification for the domain!", "REACH"); controller.TakeNewCert(model.CertifiedDomains[0], score); } else MessageBox.Show( "You didn't pass the test and did not received the certification. You may try again.", "REACH"); parentForm.Close(); this.Close(); return; } testContainer.Visible = false; resultsContainer.Visible = true; int passed = 0; for (int i = 0; i < model.CertifiedDomains.Count; ++i) { // rating control RatingControl r = new RatingControl(); r.Location = new Point(89, 99 + i * (r.Height+1)); r.Rating = model.GetScoreForTest(i); r.Fixed = true; if (r.Rating >= NewAccountModel.MIN_PASSING_SCORE) ++passed; r.Visible = true; resultsContainer.Controls.Add(r); // the label with the domain Label domainTitle = new Label(); domainTitle.Location = new Point(12, 106 + i * (r.Height + 1)); domainTitle.Font = new Font( "Microsoft Sans Serif", 9.75F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0))); domainTitle.Text = model.CertifiedDomains[i].Name + ":"; domainTitle.Visible = true; resultsContainer.Controls.Add(domainTitle); // the label with the result Label domainStatus = new Label(); domainStatus.Location = new Point(211, 106 + i * (r.Height+1)); domainStatus.Font = new Font( "Microsoft Sans Serif", 9.75F, FontStyle.Bold, GraphicsUnit.Point, ((byte)(0))); if (r.Rating >= NewAccountModel.MIN_PASSING_SCORE) { domainStatus.ForeColor = Color.Green; domainStatus.Text = "Passed"; } else { domainStatus.ForeColor = Color.Red; domainStatus.Text = "Failed"; } domainStatus.Visible = true; resultsContainer.Controls.Add(domainStatus); } if (passed > 0) { resultTitle.Text = "Your account was created. You will receive a certificate for each domain that you passed successfully."; controller.CreateAccount(); } else resultTitle.Text = "You didn't pass any test. Your account was not created. You may try again."; }