private async void Button_Register_Click(object sender, EventArgs e)
        {
            Button_Register.Enabled = false;
            bool eventChoosen         = ComboBox_Events.SelectedItem == null ? false : true;
            bool paymentAmountCorrect = true;

            if (ComboBox_PaymentStatus.SelectedIndex != 2)
            {
                paymentAmountCorrect = participantServices.paymentAmountStringCorrect(TextBox_PaymentAmount.Text);
            }
            int partcipantInformationManditoryFieldsFilled =
                participantServices.isPartcipantInformationManditoryFieldsCorrect(
                    TextBox_FirstName.Text, TextBox_LastName.Text, TextBox_Email.Text
                    );

            if (partcipantInformationManditoryFieldsFilled > 0 || !eventChoosen || !paymentAmountCorrect)
            {
                if (partcipantInformationManditoryFieldsFilled == 1)
                {
                    messageBoxHelper.showWarning(this,
                                                 "First Name field text is too short (not correct name entered " +
                                                 "(is shorter than 3 characters) or name has not been entered)", "Warning");
                }
                else if (partcipantInformationManditoryFieldsFilled == 2)
                {
                    messageBoxHelper.showWarning(this,
                                                 "Last Name field text is too short (not correct last name entered " +
                                                 "(is shorter than 3 characters) or last name has not been entered)", "Warning");
                }
                else if (partcipantInformationManditoryFieldsFilled == 3)
                {
                    messageBoxHelper.showWarning(this,
                                                 "Email field text is not correct (not correct email format " +
                                                 "(must be: (some cheracters)@(domain) etc. [email protected])" +
                                                 " or email has not been entered)", "Warning");
                }
                else if (!eventChoosen)
                {
                    messageBoxHelper.showWarning(this,
                                                 "You have not choosen event!", "Warning");
                }
                else if (!paymentAmountCorrect)
                {
                    messageBoxHelper.showWarning(this,
                                                 "Payment amount is negative or not a number", "Warning");
                }
            }
            else
            {
                double paymentAmount;
                bool   paymentAmountParsed = Double.TryParse(TextBox_PaymentAmount.Text, out paymentAmount);
                if (ComboBox_PaymentStatus.SelectedIndex == 2 || !paymentAmountParsed)
                {
                    paymentAmount = 0;
                }

                DateTime    paymentDate        = DateTime_PaymentDate.Value;
                Participant createdParticipant = await participantServices.createParticipant(
                    events[ComboBox_Events.SelectedIndex].id.ToString(),
                    TextBox_FirstName.Text,
                    TextBox_LastName.Text,
                    TextBox_JobTitle.Text,
                    TextBox_CompanyName.Text,
                    ComboBox_CompanyType.Text,
                    TextBox_Email.Text,
                    TextBox_PhoneNumber.Text,
                    TextBox_Country.Text,
                    ComboBox_ParticipationFormat.Text,
                    ComboBox_PaymentStatus.Text,
                    ComboBox_Materials.Text.Equals("Yes")?true : false,
                    ComboBox_ParticipateEveningEvent.Text.Equals("Yes")?true : false,
                    ComboBox_ParticipateDay1.Text.Equals("Yes")?true : false,
                    ComboBox_ParticipateDay2.Text.Equals("Yes")?true : false,
                    ComboBox_ParticipateDay3.Text.Equals("Yes")?true : false,
                    ComboBox_ParticipateDay4.Text.Equals("Yes")?true : false,
                    DateHelper.setDateToMidnight(paymentDate),
                    DateHelper.setDateToMidnight(DateTime_RegistrationDate.Value),
                    paymentAmount,
                    TextBox_AdditionalPhoneNumber.Text,
                    TextBox_Comment.Text

                    );

                if (createdParticipant != null)
                {
                    mainWindow.Enabled = true;
                    mainWindow.allParticipants.Add(createdParticipant);
                    if (mainWindow.selectedEvent != null)
                    {
                        if (createdParticipant.eventId.Equals(mainWindow.selectedEvent.id.ToString()))
                        {
                            List <Participant> currentParticipantList = new List <Participant>();
                            currentParticipantList.Add(createdParticipant);
                            List <Participant> filteredParticipant = participantFilteringServices.filterParticipants(currentParticipantList, mainWindow.filterWindowData, mainWindow.selectedEvent);
                            if (filteredParticipant.Count > 0)
                            {
                                mainWindow.filteredParticipants.Add(createdParticipant);

                                if (mainWindow.selectedEvent != null)
                                {
                                    if (createdParticipant.eventId.Equals(mainWindow.selectedEvent.id.ToString()))
                                    {
                                        mainWindow.selectedEventParticipants.Add(createdParticipant);
                                    }
                                    mainWindow.UpdateCheckedInAndRegistered(mainWindow.selectedEventParticipants, mainWindow.selectedEvent, false);
                                    int filteredAmount = Int32.Parse(mainWindow.Label_FilteredAmount.Text) + 1;
                                    mainWindow.Label_FilteredAmount.Text = filteredAmount.ToString();
                                }
                                mainWindow.addParticipantTableRow();
                                mainWindow.addParticipantToParticipantTableRow(
                                    createdParticipant, mainWindow.Table_ParticipantsData1.RowCount - 1, events);
                            }
                        }
                    }
                    this.Dispose();
                }
                else
                {
                    messageBoxHelper.showWarning(this, "Event creation was unsuccesfull, because of internet connection" +
                                                 "or database write request number exceeded", "Warning");
                }
            }
            Button_Register.Enabled = true;
        }
Exemple #2
0
        private async void Button_Save_Click(object sender, EventArgs e)
        {
            Button_Save.Enabled   = false;
            Button_Send.Enabled   = false;
            Button_Delete.Enabled = false;
            int partcipantInformationManditoryFieldsFilled =
                participantServices.isPartcipantInformationManditoryFieldsCorrect(
                    TextBox_FirstName.Text, TextBox_LastName.Text, TextBox_Email.Text
                    );
            bool paymentAmountCorrect = true;

            if (ComboBox_PaymentStatus.SelectedIndex != 2)
            {
                paymentAmountCorrect = participantServices.paymentAmountStringCorrect(TextBox_PaymentAmount.Text);
            }
            if (partcipantInformationManditoryFieldsFilled > 0 || !paymentAmountCorrect)
            {
                if (partcipantInformationManditoryFieldsFilled == 1)
                {
                    messageBoxHelper.showWarning(this,
                                                 "First Name field text is too short (not correct name entered " +
                                                 "(is shorter than 3 characters) or name has not been entered)", "Warning");
                }
                else if (partcipantInformationManditoryFieldsFilled == 2)
                {
                    messageBoxHelper.showWarning(this,
                                                 "Last Name field text is too short (not correct last name entered " +
                                                 "(is shorter than 3 characters) or last name has not been entered)", "Warning");
                }
                else if (partcipantInformationManditoryFieldsFilled == 3)
                {
                    messageBoxHelper.showWarning(this,
                                                 "Email field text is not correct (not correct email format " +
                                                 "(must be: (some cheracters)@(domain) etc. [email protected])" +
                                                 " or email has not been entered)", "Warning");
                }
                else if (!paymentAmountCorrect)
                {
                    messageBoxHelper.showWarning(this,
                                                 "Payment amount is negative or not a number", "Warning");
                }
            }
            else
            {
                double paymentAmount;
                bool   parsedAmount = Double.TryParse(TextBox_PaymentAmount.Text, out paymentAmount);
                if (ComboBox_PaymentStatus.SelectedIndex == 2 || !parsedAmount)
                {
                    paymentAmount = 0;
                }
                Participant createdParticipant = new Participant(
                    participant.participantId,
                    participant.eventId,
                    TextBox_FirstName.Text,
                    TextBox_LastName.Text,
                    TextBox_JobTitle.Text,
                    TextBox_CompanyName.Text,
                    ComboBox_CompanyType.Text,
                    TextBox_Email.Text,
                    TextBox_PhoneNumber.Text,
                    TextBox_Country.Text,
                    ComboBox_ParticipationFormat.Text,
                    ComboBox_PaymentStatus.Text,
                    ComboBox_Materials.Text.Equals("Yes") ? true : false,
                    participant.ticketBarcode,
                    participant.ticketSent,
                    ComboBox_ParticipateEveningEvent.Text.Equals("Yes") ? true : false,
                    ComboBox_ParticipateDay1.Text.Equals("Yes") ? true : false,
                    ComboBox_ParticipateDay2.Text.Equals("Yes") ? true : false,
                    ComboBox_ParticipateDay3.Text.Equals("Yes") ? true : false,
                    ComboBox_ParticipateDay4.Text.Equals("Yes") ? true : false,
                    participant.checkedInDay1,
                    participant.checkedInDay2,
                    participant.checkedInDay3,
                    participant.checkedInDay4,
                    DateHelper.setDateToMidnight(DateTime_RegistrationDate.Value),
                    DateHelper.setDateToMidnight(DateTime_PaymentDate.Value),
                    paymentAmount,
                    TextBox_AdditionalPhoneNumber.Text,
                    TextBox_Comment.Text
                    );
                bool editedSuccesfully = true;
                try
                {
                    await participantServices.editParticipant(createdParticipant);
                }
                catch (Exception)
                {
                    editedSuccesfully = false;
                }
                if (createdParticipant != null && mainWindow.selectedEvent != null && editedSuccesfully)
                {
                    mainWindow.Enabled = true;
                    int participantRow = this.mainWindow.filteredParticipants.FindLastIndex(delegate(Participant participant)
                    {
                        return(participant.participantId == createdParticipant.participantId);
                    });
                    mainWindow.editParticipantTableRow(createdParticipant, participantRow);
                    this.Dispose();
                }
                else
                {
                    messageBoxHelper.showWarning(this, "Event creation was unsuccesfull, because of internet connection" +
                                                 "or database write request number exceeded", "Warning");
                }
            }
            Button_Save.Enabled   = true;
            Button_Send.Enabled   = true;
            Button_Delete.Enabled = true;
        }