コード例 #1
0
        private void lstParticipants_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (lstParticipants.SelectedIndex == -1)
            {
                btnDelete.IsEnabled = false;
                dgParticipant.ItemsSource = null;
                return;
            }
            RegistrationHelper client = new RegistrationHelper();
            try
            {

                List<FieldAnswer> fieldAnswers = client.GetParticipantFieldAnswer(user, event_.EventID, (int)lstParticipants.SelectedValue).ToList();
                List<Field> fields = client.ViewField(event_.EventID).ToList();

                List<Tuple<Field, FieldAnswer>> answers = new List<Tuple<Field, FieldAnswer>>();
                foreach (Field field in fields)
                {
                    FieldAnswer fieldAnswer = fieldAnswers.Find(
                        delegate(FieldAnswer fa)
                        {
                            return fa.FieldID == field.FieldID;
                        }
                    );
                    if (fieldAnswer != null)
                    {
                        field.FieldName += ":";
                        answers.Add(Tuple.Create(field, fieldAnswer));
                    }
                }

                cboPaid.Checked -= cboPaid_Checked;
                cboPaid.Unchecked -= cboPaid_Unchecked;
                ParticipantWithName p = (ParticipantWithName)lstParticipants.SelectedItem;
                cboPaid.IsChecked = p.participant.Paid;

                cboPaid.Checked += cboPaid_Checked;
                cboPaid.Unchecked += cboPaid_Unchecked;
                dgParticipant.ItemsSource = answers;

                btnDelete.IsEnabled = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                client.Close();
            }
        }