Exemple #1
0
        private async void GenerateDocumentsAndSendEmails()
        {
            List <Participant> participants = this.participants;
            List <Event>       events       = this.events;


            sendingStatus = "SendingEmails";
            List <string> toEmails      = new List <string>();
            List <string> emailBodies   = new List <string>();
            List <string> emailSubjects = new List <string>();

            foreach (Participant p in participants)
            {
                toEmails.Add(p.email);
                Event  eventEntity = events.Find(ev => ev.id.ToString().Equals(p.eventId));
                string body        = "";
                string subject     = "";
                if (eventEntity.useTemplate)
                {
                    EmailTemplate temp = emailTemplates.Find(et =>
                                                             et.templateName.Equals(eventEntity.current_Mail_Template));
                    body    = temp.body;
                    subject = temp.subject;
                }
                else
                {
                    body    = eventEntity.emailBody;
                    subject = eventEntity.emailSubject;
                }
                emailBodies.Add(emailStringHelper.formatEmailString(body, p, eventEntity));
                emailSubjects.Add(emailStringHelper.formatEmailString(subject, p, eventEntity));
            }
            EmailTemplate currentEmailTemplate = emailTemplates[currentEmailTemplateIndex];

            sendEmail.SendEmails(toEmails, emailSubjects, emailBodies);
            sendingStatus = "EmailsSent";
            foreach (Participant p in participants)
            {
                p.ticketSent = true;
                Participant participant = await participantServices.editParticipant(p);

                if (participant != null)
                {
                    int allParticipantsIndex           = mainWindow.allParticipants.FindIndex(par => par.participantId.Equals(p.participantId));
                    int selectedEventParticipantsIndex = 0;
                    int filteredEventParticipantsIndex = 0;
                    if (mainWindow.selectedEventParticipants.Count > 0)
                    {
                        selectedEventParticipantsIndex = mainWindow.selectedEventParticipants.FindIndex(par => par.participantId.Equals(p.participantId));
                        filteredEventParticipantsIndex = mainWindow.filteredParticipants.FindIndex(par => par.participantId.Equals(p.participantId));
                    }
                    mainWindow.allParticipants[allParticipantsIndex] = p;
                    if (mainWindow.selectedEventParticipants.Count > 0)
                    {
                        mainWindow.selectedEventParticipants[selectedEventParticipantsIndex] = p;
                        mainWindow.filteredParticipants[filteredEventParticipantsIndex]      = p;
                    }
                }
            }
        }
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;
        }
        private async void Button_CheckIn_Click(object sender, EventArgs e)
        {
            DateTime today      = getToday();
            bool     successful = false;

            if (selectedEvent != null)
            {
                if (today == selectedEvent.date_From && selectedParticipant.participateInDay1)
                {
                    selectedParticipant.checkedInDay1 = true;
                    successful = true;
                }
                else if (today == selectedEvent.date_From.AddDays(1) && selectedEvent.eventLengthDays >= 2 &&
                         selectedParticipant.participateInDay2)
                {
                    selectedParticipant.checkedInDay2 = true;
                    successful = true;
                }
                else if (today == selectedEvent.date_From.AddDays(2) && selectedEvent.eventLengthDays >= 3 &&
                         selectedParticipant.participateInDay3)
                {
                    selectedParticipant.checkedInDay3 = true;
                    successful = true;
                }
                else if (today == selectedEvent.date_From.AddDays(3) && selectedEvent.eventLengthDays >= 4 &&
                         selectedParticipant.participateInDay4)
                {
                    selectedParticipant.checkedInDay4 = true;
                    successful = true;
                }
                else
                {
                    messageBoxHelper.showWarning(this,
                                                 "Check in unsuccessful. Possible problems:" +
                                                 "1) Event is ended\n" +
                                                 "2) Event has not started yet\n" +
                                                 "3) Participant is not participanting in this event day",
                                                 "Warning");
                }
                if (successful)
                {
                    Participant resultParticipant = await participantServices.editParticipant(selectedParticipant);

                    if (resultParticipant != null)
                    {
                        int filteredParticipantsId = mainWindow.filteredParticipants.FindIndex(p => p.participantId.Equals(resultParticipant.participantId));
                        int allParticipantsId      = mainWindow.allParticipants.FindIndex(p => p.participantId.Equals(resultParticipant.participantId));

                        mainWindow.filteredParticipants[filteredParticipantsId] = resultParticipant;
                        mainWindow.allParticipants[allParticipantsId]           = resultParticipant;

                        mainWindow.editParticipantTableRow(resultParticipant, filteredParticipantsId);
                        mainWindow.Enabled = true;
                        scanningWindow.Dispose();
                        this.Dispose();
                    }
                    else
                    {
                        messageBoxHelper.showWarning(this,
                                                     "Participant saving was unsuccessful. Check your internet connection. If problem continues " +
                                                     "contact support (might be problems with database or server)",
                                                     "Warning");
                    }
                }
            }
        }
Exemple #4
0
        private async void Button_SendTickets_Click(object sender, EventArgs e)
        {
            if (companyData.emailUsername.Length == 0 || companyData.emailUsername.Length == 0)
            {
                metroMessageBoxHelper.showWarning(this, "You cannot send email because you have not entered " +
                                                  "your email credentials, which are mandatory to send email. Go to Main Window -> Settings -> Add/" +
                                                  "Change company information to fill email credentials", "Warning");
            }
            else
            {
                for (int i = 0; i < SendCheckBoxes.Count; i++)
                {
                    if (SendCheckBoxes[i].Checked)
                    {
                        checkedParticipants.Add(filteredParticipants[i]);
                    }
                }
                if (checkedParticipants.Count > 0)
                {
                    cancelationTokenSource     = new CancellationTokenSource();
                    Button_SendTickets.Enabled = false;
                    generateSendInfoWindow     = new GenerateSendInfoWindow(this);
                    sendingStatus = "GeneratingDocuments";
                    Timer_StringChanged.Enabled = true;

                    generateSendInfoWindow.Show();
                    generateSendInfoWindow.BringToFront();

                    var tasks = new[]
                    {
                        Task.Factory.StartNew(() => GenerateDocumentsAndSendEmailsWithTickets(), cancelationTokenSource.Token)
                    };
                    foreach (Task t in tasks)
                    {
                        await t;
                    }
                    foreach (Participant p in checkedParticipants)
                    {
                        p.ticketSent = true;
                        Participant participant = await participantServices.editParticipant(p);

                        if (participant != null)
                        {
                            int allParticipantsIndex           = mainWindow.allParticipants.FindIndex(par => par.participantId.Equals(p.participantId));
                            int selectedEventParticipantsIndex = 0;
                            int filteredEventParticipantsIndex = 0;
                            if (mainWindow.selectedEventParticipants.Count > 0)
                            {
                                selectedEventParticipantsIndex = mainWindow.selectedEventParticipants.FindIndex(par => par.participantId.Equals(p.participantId));
                                filteredEventParticipantsIndex = mainWindow.filteredParticipants.FindIndex(par => par.participantId.Equals(p.participantId));
                            }
                            mainWindow.allParticipants[allParticipantsIndex] = p;
                            if (mainWindow.selectedEventParticipants.Count > 0)
                            {
                                mainWindow.selectedEventParticipants[selectedEventParticipantsIndex] = p;
                                mainWindow.filteredParticipants[filteredEventParticipantsIndex]      = p;
                                mainWindow.editParticipantTableRow(participant, filteredEventParticipantsIndex);
                            }
                        }
                    }
                }
                else
                {
                    metroMessageBoxHelper.showWarning(this, "You have not choosen any particicipants, to send emails!", "Warning");
                }
            }
            //mainWindow.Enabled = true;
            //this.Dispose();
        }