示例#1
0
        public static Note[] GetAllNotes(int hour)
        {
            List<Note> alist = new List<Note>();

            string sql;
            sql = SqlFormat.Format("SELECT * FROM Notes WHERE qhour={0} AND deleted=0", hour);

            SqlConnection conn = Connection.Open();

            SqlCommand cmd = new SqlCommand(sql, conn);

            using (SqlDataReader reader = cmd.ExecuteReader())
            {

                while (reader.Read())
                {
                    Note note = new Note(
                        int.Parse(reader["id"].ToString()),
                        int.Parse(reader["qhour"].ToString()),
                        int.Parse(reader["qnumber"].ToString()),
                        reader["qtext"].ToString(),
                        reader["whosubmitted"].ToString());

                    alist.Add(note);
                }

                return alist.ToArray();
            }
        }
示例#2
0
        public static void AddNote(Note note)
        {
            string sql = SqlFormat.Format("INSERT INTO Notes (qhour, qnumber, qtext, whosubmitted) VALUES ({0},{1},'{2}','{3}')", note.HourNumber, note.QuestionNumber, note.Text, note.Submitter);

            SqlConnection conn = Connection.Open();

            SqlCommand cmd = new SqlCommand(sql, conn);

            cmd.ExecuteNonQuery();
        }
示例#3
0
        public static void Start(ClientOrchestrator orchestrator, TriviaViewModel viewModel, CommandBindingCollection bindings, TriviaClient window)
        {
            Contract.Requires(orchestrator != null);

            bindings.Add(new CommandBinding(TriviaCommands.WrongAnswer,
                (object source, ExecutedRoutedEventArgs e) =>
                {
                    AnswerViewModel a = (AnswerViewModel)e.Parameter;

                    a.WhoCalledIn = TriviaClient.PlayerName;

                    orchestrator.SendUpdateAnswerRequest(a.CreateModel(), false);
                }));

            bindings.Add(new CommandBinding(TriviaCommands.CorrectAnswer,
                (object source, ExecutedRoutedEventArgs e) =>
                {
                    CorrectAnswerData cad = (CorrectAnswerData)e.Parameter;

                    AnswerViewModel a = cad.Answer;

                    a.WhoCalledIn = TriviaClient.PlayerName;

                    orchestrator.SendUpdateAnswerRequest(a.CreateModel(), false);

                    QuestionChanges questionChanges = new QuestionChanges(new QuestionId(a.Hour, a.Number))
                    {
                        Open = false,
                        Correct = true,
                        Answer = a.Text,
                        PhoneBankOperator = cad.PhoneBankOperator
                    };

                    // Update the correct answer

                    orchestrator.SendUpdateQuestionRequest(questionChanges);
                }));

            bindings.Add(new CommandBinding(TriviaCommands.PartialAnswer,
                (object source, ExecutedRoutedEventArgs e) =>
                {
                    AnswerViewModel a = (AnswerViewModel)e.Parameter;

                    a.WhoCalledIn = TriviaClient.PlayerName;
                    a.Partial = true;

                    orchestrator.SendUpdateAnswerRequest(a.CreateModel(), true);  // Flag as a partial
                }));

            bindings.Add(new CommandBinding(TriviaCommands.EditAnswer,
                (object source, ExecutedRoutedEventArgs e) =>
                {
                    // An edited answer was already modified by the command sender, so just update it to the server

                    // Note: this is usually done by fixing the text of a partial answer

                    AnswerViewModel a = (AnswerViewModel)e.Parameter;

                    orchestrator.SendUpdateAnswerRequest(a.CreateModel(), false);  // Flag not "partial changed".  We don't know it to be the case, but that's the behavior we want
                }));

            bindings.Add(new CommandBinding(TriviaCommands.ShowSubmitAnswerDialog,
                 (object source, ExecutedRoutedEventArgs e) =>
                 {
                     QuestionViewModel question = (QuestionViewModel)e.Parameter;

                     SubmitAnswerDialog submitAnswerDialog = new SubmitAnswerDialog(question);
                     submitAnswerDialog.Owner = window;

                     bool? submitted = submitAnswerDialog.ShowDialog();

                     if (submitted == true)
                     {
                         // 2014 - don't think this is true, but preserving the comment... Must execute the command against "this" current window so the commandbindings are hit
                         TriviaCommands.SubmitAnswer.Execute(submitAnswerDialog.AnswerSubmitted, null);  // Using "null" as the target means we avoid weird bugs where the event actually doesn't fire
                     }
                 }));

            bindings.Add(new CommandBinding(TriviaCommands.SubmitAnswer,
                (object source, ExecutedRoutedEventArgs e) =>
                {
                    Answer a = (Answer)e.Parameter;

                    QuestionViewModel q;
                   
                    if (!(viewModel.TryGetQuestion(a, out q)))
                    {
                        throw new InvalidOperationException("Couldn't get question for answer submitted, that's really odd...");
                    }

                    if (ContestConfiguration.PreventDuplicateAnswerSubmission && 
                        CommandHandler.ShouldStopAnswerSubmission(a, q, window))
                    {
                        return;
                    }

                    orchestrator.SendSubmitAnswerRequest(a);  // Inform the server

                    // If you're submitting an answer, it's likely to assume you're researching the question
                    if (!(q.IsBeingResearched))
                    {
                        q.IsBeingResearched = true;

                        TriviaCommands.ResearcherChanged.Execute(q, null);
                    }
                }));

            bindings.Add(new CommandBinding(TriviaCommands.OpenQuestion,
                (object source, ExecutedRoutedEventArgs e) =>
                {
                    QuestionId questionId = (QuestionId)e.Parameter;

                    orchestrator.SendOpenQuestionRequest(questionId.Hour, questionId.Number);
                }));

            bindings.Add(new CommandBinding(TriviaCommands.EditQuestion,
                (object source, ExecutedRoutedEventArgs e) =>
                {
                    QuestionViewModel question = (QuestionViewModel)e.Parameter;

                    EditingQuestionData data = new EditingQuestionData() 
                    { 
                        HourNumber = question.Identifier.Hour, 
                        QuestionNumber = question.Identifier.Number, 
                        WhoEditing = TriviaClient.PlayerName 
                    };

                    // Tell everyone else that "I'm editing this question, so back off!"
                    orchestrator.SendEditingQuestionMessage(data);

                    EditQuestionDialog dialog = new EditQuestionDialog(orchestrator, question, false);
                    dialog.Owner = window;

                    bool? result = dialog.ShowDialog();

                    if (!(result.HasValue) || result.Value == false)
                    {
                        data.WhoEditing = null; // Signal that the edit was cancelled
                        
                        orchestrator.SendEditingQuestionMessage(data);

                        // If the user made a change to the question (in-memory viewmodel), should refresh from the server (it's just the easiest thing to do)
                        if (dialog.GetChangesMade().Changes != QuestionChanges.Change.None)
                        {
                            orchestrator.SendGetCompleteHourDataRequest(question.Identifier.Hour);
                        }

                        return;  // Cancelled / Closed without saving
                    }

                    QuestionChanges changes = dialog.GetChangesMade();

                    if (changes.Changes == QuestionChanges.Change.None)
                    {
                        return;  // No changes actually were made even though the user clicked the Save button
                    }

                    orchestrator.SendUpdateQuestionRequest(changes);
                }));

            bindings.Add(new CommandBinding(TriviaCommands.UpdateQuestionPoints,
                (object source, ExecutedRoutedEventArgs e) =>
                {
                    // Only Beerpigs use this
                    QuestionChanges changes = (QuestionChanges)e.Parameter;

                    orchestrator.SendUpdateQuestionRequest(changes);
                }));

            bindings.Add(new CommandBinding(TriviaCommands.PlayAudioTrivia,
                (object source, ExecutedRoutedEventArgs e) =>
                {
                    string audioTriviaFileName = (string)e.Parameter;

                    CommandHandler.PlayAudioTrivia(audioTriviaFileName, window);
                }));

            bindings.Add(new CommandBinding(TriviaCommands.ShowAddNoteDialog,
                (object source, ExecutedRoutedEventArgs e) =>
                {
                    QuestionViewModel question = (QuestionViewModel)e.Parameter;

                    Note note = new Note();
                    note.Submitter = TriviaClient.PlayerName;
                    note.HourNumber = question.Identifier.Hour;
                    note.QuestionNumber = question.Identifier.Number;

                    AddNoteDialog dialog = new AddNoteDialog(note);
                    dialog.Owner = window;

                    bool? result = dialog.ShowDialog();

                    if (!(result.HasValue) || result.Value == false)
                    {
                         return;  // Cancelled / Closed without saving
                    }

                    note.Text = note.Text.Trim();  // Trim it.

                    // Save the note
                    orchestrator.SendAddNoteMessage(note);

                    // If you're adding a note, it's likely to assume you're researching the question

                    if (!(question.IsBeingResearched))
                    {
                        question.IsBeingResearched = true;

                        TriviaCommands.ResearcherChanged.Execute(question, null);
                    }
                }));

            bindings.Add(new CommandBinding(TriviaCommands.CorrectAnswerWithoutSubmission,
                (object source, ExecutedRoutedEventArgs e) =>
                {
                    QuestionViewModel question = (QuestionViewModel)e.Parameter;

                    Answer answer = new Answer();
                    answer.Hour = question.Identifier.Hour;
                    answer.Number = question.Identifier.Number;
                    answer.WhoCalledIn = TriviaClient.PlayerName;

                    AnswerViewModel answerViewModel = new AnswerViewModel(answer);

                    // Show the "blank" dialog
                    CorrectAnswerDialog dialog = new CorrectAnswerDialog(answerViewModel);
                    dialog.Owner = window;

                    bool? result = dialog.ShowDialog();

                    if (!(result.HasValue) || result.Value == false)
                    {
                        return;  // Cancelled / Closed without saving
                    }

                    QuestionChanges changes = new QuestionChanges(question.Identifier)
                    {
                        Open = false,
                        Correct = true,
                        Answer = dialog.Answer.Text,
                        PhoneBankOperator = dialog.PhoneBankOperator
                    };

                    // Update the correct answer

                    orchestrator.SendUpdateQuestionRequest(changes);
                }));

            bindings.Add(new CommandBinding(TriviaCommands.ResearcherChanged,
                (object source, ExecutedRoutedEventArgs e) =>
                {
                    QuestionViewModel questionThatChanged = (QuestionViewModel)e.Parameter;

                    if (questionThatChanged.IsBeingResearched == false)
                    {
                        // User said they're not researching this question (and by extension, aren't researching *anything* anymore)
                        orchestrator.SendResearcherChangedRequest(
                            new ResearcherChange
                            {
                                HourNumber = 0,  // Signaling that current user is researching nothing
                                QuestionNumber = 0,  // Signaling that current user is researching nothing
                                Name = TriviaClient.PlayerName
                            });
                    }
                    else
                    {
                        orchestrator.SendResearcherChangedRequest(
                          new ResearcherChange
                          {
                              HourNumber = questionThatChanged.Identifier.Hour,
                              QuestionNumber = questionThatChanged.Identifier.Number,
                              Name = TriviaClient.PlayerName
                          });
                    }
                }));


            bindings.Add(new CommandBinding(TriviaCommands.ShowEditPartialsDialog,
                (object source, ExecutedRoutedEventArgs e) =>
                {
                    ListCollectionView partials = (ListCollectionView)e.Parameter;

                    EditPartialsDialog dialog = new EditPartialsDialog();
                    dialog.DataContext = partials;
                    dialog.Owner = window;

                    dialog.ShowDialog();
                }));

            bindings.Add(new CommandBinding(TriviaCommands.ShowCombinePartialsDialog,
                (object source, ExecutedRoutedEventArgs e) =>
                {
                    QuestionViewModel question = (QuestionViewModel)e.Parameter;

                    string combinationAnswer = string.Join("\n", question.PartialAnswers.Cast<AnswerViewModel>().Select(avm => avm.Text));

                    SubmitAnswerDialog submitAnswerDialog = new SubmitAnswerDialog(question, combinationAnswer);
                    submitAnswerDialog.Owner = window;

                    bool? submitted = submitAnswerDialog.ShowDialog();

                    if (submitted == true)
                    {
                        // 2014, don't think this is true, ubt pres3erving the original comment.....  Must execute the command against "this" current window so the commandbindings are hit
                        TriviaCommands.SubmitAnswer.Execute(submitAnswerDialog.AnswerSubmitted, null);  // Using "null" as the target means we avoid weird bugs where the event actually doesn't fire
                    }
                }));


            bindings.Add(new CommandBinding(TriviaCommands.ShowAddLinkDialog,
                (object source, ExecutedRoutedEventArgs e) =>
                {
                    AddLinkDialog dialog = new AddLinkDialog();
                    dialog.Owner = window;

                    bool? result = dialog.ShowDialog();

                    if (!(result.HasValue) || result.Value == false)
                    {
                        return;  // Cancelled / Closed without saving
                    }

                    dialog.Link.Description = dialog.Link.Description.Trim();
                    dialog.Link.Url = dialog.Link.Url.Trim();

                    // Save the link
                    orchestrator.SendAddLinkRequest(dialog.Link);
                }));            
            bindings.Add(new CommandBinding(TriviaCommands.DeleteNote,
                (object source, ExecutedRoutedEventArgs e) =>
                {
                    orchestrator.SendDeleteNoteMessage((Note)e.Parameter);
                }));
        }
示例#4
0
 public AddNoteDialog(Note note)
     : this()
 {
     this.mNote = note;
     this.DataContext = note;
 }