private void edit_participant_paid(bool paid)
        {
            RegistrationHelper client = new RegistrationHelper();
            try
            {
                ParticipantWithName p = (ParticipantWithName)lstParticipants.SelectedItem;
                client.EditParticipant(p.participant.ParticipantID, paid);
                loadParticipants();
                MessageBox.Show("Operation succeeded!");
                lstParticipants_SelectionChanged(null, null);

                for (int i = 0; i < lstParticipants.Items.Count; i++)
                {
                    ParticipantWithName part = (ParticipantWithName)lstParticipants.Items[i];

                    if (part.participant.ParticipantID == p.participant.ParticipantID)
                    {
                        lstParticipants.SelectedIndex = i;
                        return;
                    }
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                client.Close();
            }
        }
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     RegistrationHelper client = new RegistrationHelper();
     try
     {
         List<StaticField> staticFields = client.ViewStaticField().ToList();
         dgStaticFields.ItemsSource = staticFields;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     finally
     {
         client.Close();
     }
 }
 private void btnDelete_Click(object sender, RoutedEventArgs e)
 {
     if (lstParticipants.SelectedIndex == -1)
         return;
     RegistrationHelper client = new RegistrationHelper();
     try
     {
         client.DeleteParticipant(user, event_.EventID, (int)lstParticipants.SelectedValue);
         loadParticipants();
         MessageBox.Show("Operation succeeded!");
         lstParticipants_SelectionChanged(null, null);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     finally
     {
         client.Close();
     }
 }
        public override bool saveChanges()
        {
            if (dtpStart.SelectedDateTime == default(DateTime))
            {
                MessageBox.Show("Invalid publish start date.",
                    "Invalid Input", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return false;
            }
            if (dtpEnd.SelectedDateTime == default(DateTime))
            {
                MessageBox.Show("Invalid publish end date.",
                    "Invalid Input", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return false;
            }
            RegistrationHelper client = new RegistrationHelper();
            try
            {
                DateTime startTime = dtpStart.SelectedDateTime;
                DateTime endTime = dtpEnd.SelectedDateTime;

                if (endTime > event_.StartDateTime)
                {
                    MessageBox.Show("Event starts at " + event_.EndDateTime + ", publish date must end before that.");
                    return false;
                }
                if (endTime <= startTime)
                {
                    MessageBox.Show("Publish end date must be after its start date.");
                    return false;
                }

                decimal result = 0;
                if (cboIsPayable.IsChecked == true)
                {
                    if (!decimal.TryParse(txtamount.Text, out result))
                    {
                        MessageBox.Show("invalid amount");
                        return false;
                    }
                }

                if (publish == null)
                {// need to change here
                    client.AddPublish(user, event_.EventID, startTime, endTime, txtRemarks.Text, cboIsPayable.IsChecked.Value, result);
                }
                else
                    client.EditPublish(user, event_.EventID, startTime, endTime, txtRemarks.Text, cboIsPayable.IsChecked.Value, result);

                btnDelete.IsEnabled = true;
                changed = false;
                MessageBox.Show("Operation succeeded!");
                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return false;
            }finally{
                client.Close();
            }
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            RegistrationHelper client = new RegistrationHelper();
            try
            {

                publish = client.ViewPublish(event_.EventID);

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                client.Close();
            }

            if (publish != null)
            {
                txtRemarks.Text = publish.Remarks;
                dtpStart.SelectedDateTime = publish.StartDateTime;
                dtpEnd.SelectedDateTime = publish.EndDateTime;
                cboIsPayable.IsChecked = publish.IsPayable;
                txtamount.Text = publish.PaymentAMount.ToString();
            }
            else
            {
                btnDelete.IsEnabled = false;
            }

            dtpStart.dtpDate.SelectedDateChanged += dateChanged;
            dtpEnd.dtpDate.SelectedDateChanged += dateChanged;

            dtpStart.cboHr.SelectionChanged += dateChanged;
            dtpStart.cboMin.SelectionChanged += dateChanged;

            dtpEnd.cboHr.SelectionChanged += dateChanged;
            dtpEnd.cboMin.SelectionChanged += dateChanged;

            dtpStart.cboHr.SelectionChanged += starthourChanged;

            dtpEnd.cboHr.SelectionChanged += endhourChanged;

            changed = false;
        }
 private void btnDelete_Click(object sender, RoutedEventArgs e)
 {
     RegistrationHelper client = new RegistrationHelper();
     try
     {
         client.DeletePublish(user, event_.EventID);
         btnClear_Click(null, null);
         btnDelete.IsEnabled = false;
         MessageBox.Show("Operation succeeded!");
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     finally
     {
         client.Close();
     }
 }
        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();
            }
        }
        private void loadParticipants()
        {
            RegistrationHelper client = new RegistrationHelper();
            try
            {
                participants = client.ViewEventParticipantWithName(user, event_.EventID);
                lstParticipants.ItemsSource = participants;

                if (participants != null && participants.Count<ParticipantWithName>() > 0)
                {
                    lstParticipants.SelectedIndex = 0;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                client.Close();
            }
        }