Esempio n. 1
0
        private void txtEmailAddress_TextChanged(object sender, EventArgs e)
        {
            // see if email exists in respondents table
            if (RespondentsDB.EmailExists(txtEmailAddress.Text))
            {
                GetRespondent(txtEmailAddress.Text);
                DateTime nextSurveyDate = respondent.LastSurvey.AddYears(1);
                DisplayRespondent();
                DisableRespondentForm();
                txtAnswer1.Focus();

                // if email exists, look up the LastSurveyDate to see if a survey was taken in the last year
                // if the email took a survey in the last year, throw a message and tell the survey taker they cannot complete another survey for n days
                // and fill in the fields with the last survey's answers
                if (!RespondentsDB.CheckLastSurveyDate(txtEmailAddress.Text))
                {
                    MessageBox.Show("It has been less than a year since you responded to this survey. Please come back after " + nextSurveyDate.ToString() + "!", "Oops!");
                    GetResponse(GetLastResponseID(respondent.RespondentID));
                    DisplayResponses();
                    DisableResponseForm();
                }
                // if it has been over a year, continue
                else
                {
                    return;
                }
            }
            // if email doesn't exist, continue
            else
            {
                return;
            }
        }
Esempio n. 2
0
 private void GetRespondent(string email)
 {
     try
     {
         respondent = RespondentsDB.GetRespondent(email);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, ex.GetType().ToString());
     }
 }
Esempio n. 3
0
 private int GetLastRespondentID()
 {
     try
     {
         return(RespondentsDB.GetLastRespondentID());
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, ex.GetType().ToString());
         return(0);
     }
 }
Esempio n. 4
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            if (ValidateData())
            {
                this.PutRespondent(respondent);
                try
                {
                    if (!RespondentsDB.AddRespondent(respondent))
                    {
                        MessageBox.Show("This email already exists. Submitting new answers.",
                                        "Database Message");
                        this.DialogResult = DialogResult.OK;

                        int respondentID = RespondentsDB.GetRespondentID(respondent.EmailAddress);
                        PutResponse(response, respondentID);
                        if (!ResponsesDB.AddResponse(response))
                        {
                            MessageBox.Show("There was some database error.", "ERROR!");
                        }
                        else
                        {
                            MessageBox.Show("Responses submitted! Thank you!", "YAY!");
                            this.DialogResult = DialogResult.OK;
                            ClearDataForm();
                        }
                    }
                    else
                    {
                        int respondentID = GetLastRespondentID();
                        PutResponse(response, respondentID);
                        if (!ResponsesDB.AddResponse(response))
                        {
                            MessageBox.Show("There was some database error.", "ERROR!");
                        }
                        else
                        {
                            MessageBox.Show("Responses submitted! Thank you!", "YAY!");
                            this.DialogResult = DialogResult.OK;
                            ClearDataForm();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, ex.GetType().ToString());
                }
            }
        }