Exemplo n.º 1
0
 private void QuesItem_SelectionChanged(object sender, SelectionChangedEventArgs e)           //显示问题详情与回答
 {
     if (QuesItem.SelectedIndex < 0)
     {
         return;
     }
     CurrentQuesIndex           = QuesItem.SelectedIndex;
     CurrentQuestion            = QuestionList[QuesItem.SelectedIndex];
     this.ques_info.DataContext = QuestionList[QuesItem.SelectedIndex];
     this.DisplayAnswers        = new List <DisplayAnswer>();
     foreach (Answer answer in QuestionList[QuesItem.SelectedIndex].Answers)
     {
         DisplayAnswer displayAnswer = new DisplayAnswer();
         displayAnswer.convert(answer);
         if (QuestionList[QuesItem.SelectedIndex].UserId == User.UserId && QuestionList[QuesItem.SelectedIndex].Solved == false)
         {
             displayAnswer.ShowAdoptBtn = true;
         }
         else
         {
             displayAnswer.ShowAdoptBtn = false;
         }
         if (answer.UserId == User.UserId)
         {
             displayAnswer.IsMyAnswer = true;
         }
         else
         {
             displayAnswer.IsMyAnswer = false;
         }
         this.DisplayAnswers.Add(displayAnswer);
     }
     this.AnsItem.ItemsSource = this.DisplayAnswers;
 }
Exemplo n.º 2
0
        private void Answer_Click(object sender, RoutedEventArgs e)                            //回答
        {
            if (CurrentQuestion == null)
            {
                return;
            }
            else if (User.UserId == null)
            {
                tipWindow warning = new tipWindow("请先登录");
                warning.ShowDialog();
                return;
            }
            else if (CurrentQuestion.UserId == User.UserId)
            {
                tipWindow warning = new tipWindow("不能回答自己的提问");
                warning.ShowDialog();
                return;
            }
            else if (AnswerContent.Text == null || AnswerContent.Text == "")
            {
                tipWindow warning = new tipWindow("回答不能为空");
                warning.ShowDialog();
                return;
            }
            else if (DisplayAnswers.Count >= 15)
            {
                tipWindow warning = new tipWindow("回答已满");
                warning.ShowDialog();
                return;
            }
            bool success = User.Answer(AnswerContent.Text, CurrentQuestion.QuestionId);

            if (success)
            {
                Answer newAnswer = new Answer(AnswerContent.Text, DateTime.Now, User.UserId, false, -1, 0);
                QuestionList[CurrentQuesIndex].Answers.Add(newAnswer);
                DisplayAnswer disp = new DisplayAnswer();
                disp.convert(newAnswer);
                disp.ShowAdoptBtn = false;
                disp.IsMyAnswer   = true;
                this.DisplayAnswers.Add(disp);
                AnswerContent.Text       = "";
                this.AnsItem.ItemsSource = null;
                this.AnsItem.ItemsSource = this.DisplayAnswers;
            }
            else
            {
                tipWindow warning = new tipWindow("未知错误");
                warning.ShowDialog();
                return;
            }
        }
Exemplo n.º 3
0
        public static AbstractAnswer GetDisplayAnswer(Answer answer)
        {
            DisplayAnswer displayAnswer = new DisplayAnswer();

            displayAnswer.AnswerId   = answer.AnswerId;
            displayAnswer.Content    = answer.Content;
            displayAnswer.CreateTime = answer.CreateTime;
            displayAnswer.IsAdopted  = answer.IsAdopted;
            displayAnswer.UserId     = answer.UserId;
            displayAnswer.AnswerId   = answer.AnswerId;
            displayAnswer.Like       = answer.Like;

            displayAnswer.IsMyAnswer   = false;
            displayAnswer.ShowAdoptBtn = false;
            return(displayAnswer);
        }
Exemplo n.º 4
0
        private void ToggleButton_Click(object sender, RoutedEventArgs e)                             //点赞
        {
            if (User.UserId == null)
            {
                tipWindow warning = new tipWindow("请先登录");
                warning.ShowDialog();
                return;
            }

            var           curItem = ((ListBoxItem)AnsItem.ContainerFromElement((System.Windows.Controls.Primitives.ToggleButton)sender)).Content;
            DisplayAnswer disp    = curItem as DisplayAnswer;

            if (disp.UserId == User.UserId)
            {
                tipWindow warning = new tipWindow("无法给自己点赞");
                warning.ShowDialog();
                return;
            }
            bool success = User.Like(disp.AnswerId);

            if (success)
            {
                foreach (DisplayAnswer da in DisplayAnswers)
                {
                    if (da.AnswerId == disp.AnswerId)
                    {
                        disp.Like++;
                    }
                }
                foreach (Answer a in QuestionList[CurrentQuesIndex].Answers)
                {
                    if (a.AnswerId == disp.AnswerId)
                    {
                        a.Like++;
                    }
                }

                this.AnsItem.ItemsSource = null;
                this.AnsItem.ItemsSource = this.DisplayAnswers;
            }
            else
            {
                tipWindow warning = new tipWindow("已经点过赞了");
                warning.ShowDialog();
                return;
            }
        }
Exemplo n.º 5
0
        private void Adopt_btn_Click(object sender, RoutedEventArgs e)                       //采纳按钮
        {
            var           curItem = ((ListBoxItem)AnsItem.ContainerFromElement((Button)sender)).Content;
            DisplayAnswer disp    = curItem as DisplayAnswer;
            bool          success = User.Adopt(disp.AnswerId, CurrentQuestion.QuestionId);

            if (success == true)
            {
                foreach (DisplayAnswer a in DisplayAnswers)
                {
                    a.ShowAdoptBtn = false;
                    if (a.AnswerId == disp.AnswerId)
                    {
                        a.IsAdopted = true;
                    }
                }
                QuestionList[QuesItem.SelectedIndex].Solved = true;
                foreach (Answer a in QuestionList[QuesItem.SelectedIndex].Answers)
                {
                    if (a.AnswerId == disp.AnswerId)
                    {
                        a.IsAdopted = true;
                    }
                }
                this.QuesItem.ItemsSource = null;
                this.AnsItem.ItemsSource  = null;
                this.AnsItem.ItemsSource  = this.DisplayAnswers;
                this.QuesItem.ItemsSource = this.QuestionList;
            }
            else
            {
                tipWindow warning = new tipWindow("未知错误");
                warning.ShowDialog();
                return;
            }
        }
Exemplo n.º 6
0
 /* Adding function*/
 private void btnPlus_Click(object sender, EventArgs e)
 {
     total1 = total1 + double.Parse(DisplayAnswer.Text);
     DisplayAnswer.Clear();
 }
Exemplo n.º 7
0
        /*END of number display functions*/

        /*Clearing function*/
        private void btnClear_Click(object sender, EventArgs e)
        {
            DisplayAnswer.Clear();
        }