private string ExportCSVStyleTwo()
        {
            DateTime startDate;
            DateTime endDate;
            if (rdAllDates.Checked)
            {
                startDate = new DateTime(2004, 1, 1);
                endDate = DateTime.Today;
            }
            else
            {
                startDate = (StartDateTextBox.Text == null && !Information.IsDate(StartDateTextBox.Text)) ?
                     new DateTime(2004, 1, 1) : DateTime.Parse(StartDateTextBox.Text);
                endDate = (EndDateTextBox.Text == null && !Information.IsDate(EndDateTextBox.Text)) ?
                     new DateTime(2010, 1, 1) : DateTime.Parse(EndDateTextBox.Text);
            }

            System.Text.StringBuilder csvData = new System.Text.StringBuilder();
            bool scored = new Surveys().IsSurveyScored(SurveyId);

            // Get an instance of the voter DAL using the DALFactory
            CSVExportData csvExportData = new Voters().GetCSVExport(SurveyId, startDate, endDate);


            string textDelimiter = TextDelimiterTextBox.Text,
                fieldDelimiter = FieldDelimiterTextBox.Text;

            csvData.Append(textDelimiter + "VoterID" + textDelimiter);
            csvData.Append(fieldDelimiter + textDelimiter + "Section" + textDelimiter);
            csvData.Append(fieldDelimiter + textDelimiter + "Start date" + textDelimiter);
            csvData.Append(fieldDelimiter + textDelimiter + "End date" + textDelimiter);
            csvData.Append(fieldDelimiter + textDelimiter + "IP" + textDelimiter);
            if (scored)
            {
                csvData.Append(fieldDelimiter + textDelimiter + "Score" + textDelimiter);
            }
            csvData.Append(fieldDelimiter + textDelimiter + "Email" + textDelimiter);
            csvData.Append(fieldDelimiter + textDelimiter + "UserName" + textDelimiter);

            // Build CSV header
            foreach (CSVExportData.ExportAnswersRow headerColumn in csvExportData.ExportAnswers.Rows)
            {

                headerColumn.ColumnHeader = System.Text.RegularExpressions.Regex.Replace(GetHeader(headerColumn), "<[^>]*>", " ");
                csvData.Append(fieldDelimiter + textDelimiter + headerColumn.ColumnHeader.Replace("[[", "").Replace("]]", "").Replace("!", "").Replace(textDelimiter, textDelimiter + textDelimiter) + textDelimiter);
            }

            WebSecurityAddInCollection securityAddIns = WebSecurityAddInFactory.CreateWebSecurityAddInCollection(new SecurityAddIns().GetWebSecurityAddIns(SurveyId), ViewState, null);
            NameValueCollection addInVoterData;

            if (csvExportData.Voters.Rows.Count > 0)
            {

                // Get security addins data if any available and get key name
                // to add to the export header
                for (int i = 0; i < securityAddIns.Count; i++)
                {
                    addInVoterData = securityAddIns[i].GetAddInVoterData(csvExportData.Voters[0].VoterID);
                    if (addInVoterData != null)
                    {
                        for (int j = 0; j < addInVoterData.Count; j++)
                        {
                            csvData.Append(string.Format("{0}{1}{2}{1}",
                                fieldDelimiter, textDelimiter, addInVoterData.GetKey(j).Replace(textDelimiter, textDelimiter + textDelimiter)));
                        }
                    }
                }
            }

            foreach (CSVExportData.VotersRow voter in csvExportData.Voters.Rows)
            {

                for (int voterSections = 0; voterSections <= GetVoterMaxSections(voter.VoterID, csvExportData); voterSections++)
                {
                    csvData.Append(System.Environment.NewLine);
                    csvData.Append(textDelimiter + voter.VoterID + textDelimiter);
                    csvData.Append(fieldDelimiter + textDelimiter + voterSections + textDelimiter);
                    csvData.Append(fieldDelimiter + textDelimiter + voter.StartDate + textDelimiter);
                    csvData.Append(fieldDelimiter + textDelimiter + voter.VoteDate + textDelimiter);
                    csvData.Append(fieldDelimiter + textDelimiter + voter.IPSource + textDelimiter);
                    if (scored)
                    {
                        csvData.Append(fieldDelimiter + textDelimiter + voter.Score + textDelimiter);
                    }
                    csvData.Append(fieldDelimiter + textDelimiter + voter.Email + textDelimiter);
                    csvData.Append(fieldDelimiter + textDelimiter + voter.UserName + textDelimiter);

                    // reparse all answers to see which answer was answered or not by the voter
                    foreach (CSVExportData.ExportAnswersRow headerColumn in csvExportData.ExportAnswers.Rows)
                    {
                        // Check if the voter has answered
                        CSVExportData.VoterAnswersRow[] answer = (CSVExportData.VoterAnswersRow[])csvExportData.VoterAnswers.Select(string.Format("VoterID={0} AND AnswerID = {1} AND SectionNumber={2}",
                            voter.VoterID, headerColumn.AnswerId, voterSections));
                        if (answer.Length > 0)
                        {
                            int i = answer[0].AnswerTypeId;

                            if (answer[0].IsAnswerTextNull())
                            {
                                csvData.Append(fieldDelimiter + textDelimiter + 1 + textDelimiter);
                            }
                            else
                            {
                                switch (CarriageReturnDropDownList.SelectedValue)
                                {
                                    case "1":
                                        {
                                            csvData.Append(fieldDelimiter + textDelimiter + GetDetail(answer[0], (AnswerTypeEnum)headerColumn.AnswerTypeId).Replace(textDelimiter, textDelimiter + textDelimiter).Replace(Environment.NewLine, ((char)10).ToString()) + textDelimiter);
                                            break;
                                        }
                                    case "2":
                                        {
                                            csvData.Append(fieldDelimiter + textDelimiter + GetDetail(answer[0], (AnswerTypeEnum)headerColumn.AnswerTypeId).Replace(textDelimiter, textDelimiter + textDelimiter).Replace(Environment.NewLine, CRCharTextbox.Text) + textDelimiter);
                                            break;
                                        }
                                    default:
                                        {
                                            csvData.Append(fieldDelimiter + textDelimiter + GetDetail(answer[0], (AnswerTypeEnum)headerColumn.AnswerTypeId).Replace(textDelimiter, textDelimiter + textDelimiter) + textDelimiter);
                                            break;
                                        }

                                }
                            }
                        }
                        else
                        {
                            csvData.Append(fieldDelimiter + textDelimiter + textDelimiter);
                        }
                    }

                    // Get security addins data if any available
                    for (int i = 0; i < securityAddIns.Count; i++)
                    {
                        addInVoterData = securityAddIns[i].GetAddInVoterData(voter.VoterID);
                        if (addInVoterData != null)
                        {
                            for (int j = 0; j < addInVoterData.Count; j++)
                            {
                                if (addInVoterData[j] != null)
                                {
                                    switch (CarriageReturnDropDownList.SelectedValue)
                                    {
                                        case "1":
                                            {
                                                csvData.Append(string.Format("{0}{1}{2}{1}",
                                                    fieldDelimiter, textDelimiter, addInVoterData[j].Replace(textDelimiter, textDelimiter + textDelimiter).Replace(Environment.NewLine, ((char)10).ToString())));
                                                break;
                                            }
                                        case "2":
                                            {
                                                csvData.Append(string.Format("{0}{1}{2}{1}",
                                                    fieldDelimiter, textDelimiter, addInVoterData[j].Replace(textDelimiter, textDelimiter + textDelimiter).Replace(Environment.NewLine, CRCharTextbox.Text)));
                                                break;
                                            }
                                        default:
                                            {
                                                csvData.Append(string.Format("{0}{1}{2}{1}",
                                                    fieldDelimiter, textDelimiter, addInVoterData[j].Replace(textDelimiter, textDelimiter + textDelimiter)));
                                                break;
                                            }

                                    }
                                }
                                else
                                {
                                    csvData.Append(fieldDelimiter + textDelimiter + textDelimiter);
                                }
                            }
                        }
                    }
                }
            }

            return csvData.ToString();
        }
        private string ExportCSVStyleOne()
        {
            try
            {
                DateTime startDate;
                DateTime endDate;
                if (rdAllDates.Checked)
                {
                    startDate = new DateTime(2004, 1, 1);
                    endDate = DateTime.Today;
                }
                else
                {
                    startDate = DateTime.Parse(StartDateTextBox.Text);
                    endDate =  DateTime.Parse(EndDateTextBox.Text);
                }

                System.Text.StringBuilder csvData = new System.Text.StringBuilder();
                bool scored = new Surveys().IsSurveyScored(SurveyId);

                // Get an instance of the voter DAL using the DALFactory
                CSVExportData csvExportData = new Voters().GetCSVExport(SurveyId, startDate, endDate);


                string textDelimiter = TextDelimiterTextBox.Text,
                    fieldDelimiter = FieldDelimiterTextBox.Text;
                csvData.Append(textDelimiter + "VoterID" + textDelimiter);
                csvData.Append(Delimit("Section"));
                csvData.Append(Delimit("Start date"));
                csvData.Append(Delimit("End date"));
                csvData.Append(Delimit("IP"));
                if (scored)
                {
                    csvData.Append(Delimit("Score"));
                }
                csvData.Append(Delimit("Email"));
                csvData.Append(Delimit("UserName"));

                // Build CSV header
                //
                //Whenever question Changes we need to detect
                int questionIdPrev = -1;
                foreach (CSVExportData.ExportAnswersRow headerColumn in csvExportData.ExportAnswers.Rows)
                {
                    QuestionSelectionMode selectionMode;
                    if (headerColumn.QuestionId != questionIdPrev) // Detect Question Change to emit Question Text alone for Certain conditions
                    {
                        selectionMode = (QuestionSelectionMode)headerColumn.SelectionModeId;
                        questionIdPrev = headerColumn.QuestionId;
                        if (csvExportData.ExportAnswers.FirstOrDefault(x => x.QuestionId == questionIdPrev &&
                           ((AnswerTypeEnum)x.AnswerTypeId == AnswerTypeEnum.SelectionTextType)) != null)
                            csvData.Append(StripCharactesAndDelimit(GetQuestionOnlyHeader(headerColumn)));

                        // New requirement for Others we need a seperate column
                        var firstRec = csvExportData.ExportAnswers.FirstOrDefault(x => x.QuestionId == questionIdPrev &&
                           ((AnswerTypeEnum)x.AnswerTypeId == AnswerTypeEnum.SelectionOtherType));
                        if (firstRec != null)
                            csvData.Append(StripCharactesAndDelimit(GetHeader(firstRec)));
                    }
                    if ((AnswerTypeEnum)headerColumn.AnswerTypeId != AnswerTypeEnum.SelectionTextType && //Selection Types go Under Question Header
                       (AnswerTypeEnum)headerColumn.AnswerTypeId != AnswerTypeEnum.SelectionOtherType)
                        csvData.Append(StripCharactesAndDelimit(GetHeader(headerColumn)));
                }

                WebSecurityAddInCollection securityAddIns = WebSecurityAddInFactory.CreateWebSecurityAddInCollection(new SecurityAddIns().GetWebSecurityAddIns(SurveyId), ViewState, null);
                NameValueCollection addInVoterData;

                if (csvExportData.Voters.Rows.Count > 0)
                {

                    // Get security addins data if any available and get key name
                    // to add to the export header
                    for (int i = 0; i < securityAddIns.Count; i++)
                    {
                        addInVoterData = securityAddIns[i].GetAddInVoterData(csvExportData.Voters[0].VoterID);
                        if (addInVoterData != null)
                        {
                            for (int j = 0; j < addInVoterData.Count; j++)
                                csvData.Append(Delimit(ReplaceDelimitersInText(addInVoterData.GetKey(j), textDelimiter)));
                        }
                    }
                }

                foreach (CSVExportData.VotersRow voter in csvExportData.Voters.Rows)
                {

                    for (int voterSections = 0; voterSections <= GetVoterMaxSections(voter.VoterID, csvExportData); voterSections++)
                    {
                        csvData.Append(System.Environment.NewLine);

                        csvData.Append(textDelimiter + voter.VoterID + textDelimiter);
                        csvData.Append(fieldDelimiter + textDelimiter + voterSections + textDelimiter);
                        csvData.Append(fieldDelimiter + textDelimiter + voter.StartDate + textDelimiter);
                        csvData.Append(fieldDelimiter + textDelimiter + voter.VoteDate + textDelimiter);
                        csvData.Append(fieldDelimiter + textDelimiter + voter.IPSource + textDelimiter);
                        if (scored)
                        {
                            csvData.Append(fieldDelimiter + textDelimiter + voter.Score + textDelimiter);
                        }
                        csvData.Append(fieldDelimiter + textDelimiter + voter.Email + textDelimiter);
                        csvData.Append(fieldDelimiter + textDelimiter + voter.UserName + textDelimiter);


                        // For every new question concatenate with # all Select type Answers and emit as first row
                        // Thereafter look only at non select type answers
                        //Do the above only if the Voter has answered the question
                        //
                        questionIdPrev = -1;

                        foreach (CSVExportData.ExportAnswersRow headerColumn in csvExportData.ExportAnswers.Rows)
                        {
                            if (headerColumn.QuestionId != questionIdPrev) // Detect Question Change to emit Question Text alone for Certain conditions
                            {
                                questionIdPrev = headerColumn.QuestionId;
                                //if this question has any answers of type Select then we need to emit the Question Text
                                // Once that is done skip all Select type questions as they have only one answer and it goes under Question heading

                                string concatenatedOthers = string.Empty;
                                if (csvExportData.ExportAnswers.FirstOrDefault(x => x.QuestionId == questionIdPrev && (AnswerTypeEnum)x.AnswerTypeId == AnswerTypeEnum.SelectionOtherType) != null)
                                {
                                    csvExportData.VoterAnswers
                                        .Where(x => x.VoterID == voter.VoterID &&
                                               x.QuestionId == questionIdPrev &&
                                               x.SectionNumber == voterSections &&
                                               (AnswerTypeEnum)x.AnswerTypeId == AnswerTypeEnum.SelectionOtherType)
                                       .ToList().ForEach(y => concatenatedOthers += GetDetail(y, AnswerTypeEnum.SelectionOtherType) +
                                           (MultiSeparatorTextBox.Text == string.Empty ? "#" : MultiSeparatorTextBox.Text));
                                    // csvData.Append(ReplaceCRAndDelimitAnswers(concatenatedOthers.TrimEnd('#')));
                                }

                                string concatenatedAnswers = string.Empty;
                                if (csvExportData.ExportAnswers.FirstOrDefault(x => x.QuestionId == questionIdPrev &&
                                   (AnswerTypeEnum)x.AnswerTypeId == AnswerTypeEnum.SelectionTextType) != null)
                                {
                                    csvExportData.VoterAnswers
                                        .Where(x => x.VoterID == voter.VoterID &&
                                               x.QuestionId == questionIdPrev &&
                                               x.SectionNumber == voterSections &&
                                               (AnswerTypeEnum)x.AnswerTypeId == AnswerTypeEnum.SelectionTextType)
                                       .ToList().ForEach(y => concatenatedAnswers += GetDetail(y, AnswerTypeEnum.SelectionTextType) +
                                       (MultiSeparatorTextBox.Text == string.Empty ? "#" : MultiSeparatorTextBox.Text));



                                }

                                //Another change.If the there is Other types get the heading of the orher and add it.
                                // if ((headerColumn.SelectionModeId == 1 || headerColumn.SelectionModeId == 2) && !string.IsNullOrEmpty(concatenatedOthers))//radiobutton selection

                                if (!string.IsNullOrEmpty(concatenatedOthers))//radiobutton selection
                                {
                                    var dat = csvExportData.ExportAnswers.Where(x => x.QuestionId == questionIdPrev &&
                                                   (AnswerTypeEnum)x.AnswerTypeId == AnswerTypeEnum.SelectionOtherType).FirstOrDefault();
                                    if (dat != null)
                                    {
                                        concatenatedAnswers += GetAnswerOnlyHeader(dat);
                                    }

                                }
                                if (csvExportData.ExportAnswers.FirstOrDefault(x => x.QuestionId == questionIdPrev &&
                                  (AnswerTypeEnum)x.AnswerTypeId == AnswerTypeEnum.SelectionTextType) != null)
                                {
                                    csvData.Append(ReplaceCRAndDelimitAnswers(concatenatedAnswers.TrimEnd((MultiSeparatorTextBox.Text == string.Empty ? '#' : MultiSeparatorTextBox.Text[0]))));
                                }
                                if (csvExportData.ExportAnswers.FirstOrDefault(x => x.QuestionId == questionIdPrev && (AnswerTypeEnum)x.AnswerTypeId == AnswerTypeEnum.SelectionOtherType) != null)
                                {
                                    csvData.Append(ReplaceCRAndDelimitAnswers(concatenatedOthers.TrimEnd(MultiSeparatorTextBox.Text == string.Empty ? '#' : MultiSeparatorTextBox.Text[0])));
                                }

                            }

                            if (((AnswerTypeEnum)headerColumn.AnswerTypeId != AnswerTypeEnum.SelectionTextType &&
                                   (AnswerTypeEnum)headerColumn.AnswerTypeId != AnswerTypeEnum.SelectionOtherType))
                            {
                                // Check if the voter has answered
                                CSVExportData.VoterAnswersRow[] answer = (CSVExportData.VoterAnswersRow[])csvExportData.VoterAnswers.Select(string.Format("VoterID={0} AND AnswerID = {1} AND SectionNumber={2}",
                                    voter.VoterID, headerColumn.AnswerId, voterSections));
                                if (answer.Length > 0) csvData.Append(ReplaceCRAndDelimitAnswers(GetDetail(answer[0], (AnswerTypeEnum)headerColumn.AnswerTypeId)));
                                else csvData.Append(Delimit(string.Empty));
                            }
                        }

                        // Get security addins data if any available
                        for (int i = 0; i < securityAddIns.Count; i++)
                        {
                            addInVoterData = securityAddIns[i].GetAddInVoterData(voter.VoterID);
                            if (addInVoterData != null)
                            {
                                for (int j = 0; j < addInVoterData.Count; j++)
                                {
                                    if (addInVoterData[j] != null) csvData.Append(ReplaceCRAndDelimitAnswers(addInVoterData[j]));
                                    else csvData.Append(fieldDelimiter + textDelimiter + textDelimiter);

                                }
                            }
                        }
                    }
                }

                return csvData.ToString();
            }
            catch (Exception ex)
            {
                ShowErrorMessage(MessageLabel, ex.Message);
                return string.Empty;
            }
        }
 /// <summary>
 /// Try to resume a saved session
 /// </summary>
 /// <returns></returns>
 protected virtual bool ResumeSession(string resumeUId)
 {
     if (resumeUId != null)
     {
         this.OnSessionResuming(new FormSessionEventArgs(this.VoterAnswers, resumeUId));
         VoterAnswersData dataSet = new Voters().ResumeVoterAnswers(this.SurveyId, resumeUId);
         if ((dataSet != null) && (dataSet.Voters.Rows.Count > 0))
         {
             this.VoterAnswers.Clear();
             this.VoterAnswers.Merge(dataSet, false);
             VoterAnswersData.VotersRow row = this.VoterAnswers.Voters[0];
             this.CurrentPageIndex = row.ResumeAtPageNumber;
             this.QuestionNumber = row.ResumeQuestionNumber;
             this.HighestPageNumber = row.IsResumeHighestPageNumberNull() ? row.ResumeAtPageNumber : row.ResumeHighestPageNumber;
             row.IPSource = (this.Context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null) ? this.Context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] : this.Context.Request.ServerVariables["REMOTE_ADDR"];
             this.LanguageCode = row.LanguageCode;
             this.OnSessionResumed(new FormSessionEventArgs(this.VoterAnswers, resumeUId));
             return true;
         }
     }
     return false;
 }
        private void VoterExportXMLButton_Click(object sender, System.EventArgs e)
        {
            DateTime startDate;
            DateTime endDate;
            if (rdAllDates.Checked)
            {
                startDate = new DateTime(2004, 1, 1);
                endDate = DateTime.Today;
            }
            else
            {
                startDate = (StartDateTextBox.Text == null && !Information.IsDate(StartDateTextBox.Text)) ?
                     new DateTime(2004, 1, 1) : DateTime.Parse(StartDateTextBox.Text);
                endDate = (EndDateTextBox.Text == null && !Information.IsDate(EndDateTextBox.Text)) ?
                     new DateTime(2010, 1, 1) : DateTime.Parse(EndDateTextBox.Text);
            }

            Response.Charset = "utf-8";
            Response.ContentType = "text/xml";
            Response.AddHeader("Content-Disposition", "attachment; filename=\"survey_results" + SurveyId + ".xml\"");

            NSurveyVoter voterAnswers = new Voters().GetForExport(SurveyId, startDate, endDate);


            WebSecurityAddInCollection securityAddIns = WebSecurityAddInFactory.CreateWebSecurityAddInCollection(new SecurityAddIns().GetWebSecurityAddIns(SurveyId), ViewState, null);
            NameValueCollection addInVoterData;

            if (voterAnswers.Voter.Rows.Count > 0)
            {
                // Get security addins data if any available and get key name
                // to add it as new column to the voter table
                for (int i = 0; i < securityAddIns.Count; i++)
                {
                    addInVoterData = securityAddIns[i].GetAddInVoterData(voterAnswers.Voter[0].VoterID);
                    if (addInVoterData != null)
                    {
                        for (int j = 0; j < addInVoterData.Count; j++)
                        {
                            voterAnswers.Voter.Columns.Add(new DataColumn(addInVoterData.GetKey(j), typeof(string), null, System.Data.MappingType.Element));
                        }
                    }
                }

                for (int voterIndex = 0; voterIndex < voterAnswers.Voter.Rows.Count; voterIndex++)
                {
                    // Get security addins data if any available
                    for (int i = 0; i < securityAddIns.Count; i++)
                    {
                        addInVoterData =
                            securityAddIns[i].GetAddInVoterData(((NSurveyVoter.VoterRow)voterAnswers.Voter.Rows[voterIndex]).VoterID);
                        if (addInVoterData != null)
                        {
                            for (int j = 0; j < addInVoterData.Count; j++)
                            {
                                voterAnswers.Voter.Rows[voterIndex][addInVoterData.GetKey(j)] = addInVoterData[j];
                            }
                        }
                    }
                }
            }


            XmlReader reader = new XmlTextReader(voterAnswers.GetXml(), XmlNodeType.Document, null); ;
            XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, System.Text.Encoding.UTF8); ;

            writer.WriteStartDocument(true);

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                    case XmlNodeType.Element:
                        writer.WriteStartElement(reader.Prefix,
                            reader.LocalName, reader.NamespaceURI);
                        if (reader.HasAttributes)
                        {
                            writer.WriteAttributes(reader, true);
                            reader.MoveToElement();
                        }
                        if (reader.IsEmptyElement)
                            writer.WriteEndElement();
                        break;
                    case XmlNodeType.EndElement:
                        writer.WriteEndElement();
                        break;
                    case XmlNodeType.Text:
                        // removes any invalid xml char
                        writer.WriteString(reader.Value.Replace(((char)12).ToString(), ""));
                        break;
                    case XmlNodeType.CDATA:
                        writer.WriteCData(reader.Value);
                        break;
                }
            }
            writer.WriteEndDocument();

            writer.Close();
            reader.Close();

            Response.End();
        }
		/// <summary>
		/// Get the current DB stats and fill 
		/// the label with them
		/// </summary>
		private void BindData()
		{
			int totalPages = 0,
				totalRecords = 0;
			
			DataSet textEntries = new Voters().GetVotersTextEntries(SurveyId, FieldReportDataGrid.CurrentPageIndex, 25, new DateTime(2004,1,1), DateTime.Now);

			FieldReportDataGrid.DataSource = textEntries ;
			FieldReportDataGrid.DataKeyField = "VoterID";
			FieldReportDataGrid.DataBind();

			if (textEntries.Tables[0].Rows.Count != 0)
			{
				totalRecords = int.Parse(textEntries.Tables[0].Rows[0]["TotalRecords"].ToString());
				CurrentPageLabel.Text = FieldReportDataGrid.CurrentPageIndex.ToString();
				if (textEntries.Tables[0].Rows.Count > 0)
				{
					if ((totalRecords%25) == 0)
					{
						totalPages = totalRecords/25;
					}
					else
					{
						totalPages = (totalRecords/25) + 1;
					}
				
				}
				TotalPagesLabel.Text = totalPages.ToString();
			}

			// Should we enable the next link?
			if (totalPages == 1 || totalRecords == 0)
			{
				PreviousPageLinkButton.Enabled = false;
				NextPageLinkButton.Enabled = false;
			}
		}
 /// <summary>
 /// Queue an invitation request for a future voter and 
 /// returns the generate UID
 /// </summary>
 public string GenerateVoterInvitationUId(int surveyId, string email, bool anonymousEntry)
 {
     string emailUId = new Voters().GetEmailUId(surveyId, email);
     if (emailUId == null)
     {
         emailUId = this.GenerateUId();
         VoterFactory.Create().AddVoterInvitation(surveyId, email, anonymousEntry, emailUId);
     }
     return emailUId;
 }
		/// <summary>
		/// Get the current DB stats and fill 
		/// the label with them
		/// </summary>
		private void BindData()
		{
			isScored = new Surveys().IsSurveyScored(SurveyId);

			TimeSpan timeTaken;
			_voterAnswers = new Voters().GetVoterAnswers(_voterId);

			if (!_voterAnswers.Voters[0].IsVoteDateNull() && !_voterAnswers.Voters[0].IsStartDateNull())
			{
				timeTaken = _voterAnswers.Voters[0].VoteDate - _voterAnswers.Voters[0].StartDate;
			}
			else
			{
				timeTaken = new TimeSpan(0);
			}

			VoterUIDLabel.Text = _voterId.ToString();
			IPAddressLabel.Text = _voterAnswers.Voters[0].IPSource;
			VoteDateLabel.Text = _voterAnswers.Voters[0].VoteDate.ToString();
			VoterEmail.Text = _voterAnswers.Voters[0].IsEmailNull() ? GetPageResource("AnonymousVoteInfo") : _voterAnswers.Voters[0].Email;
			VoterUserName.Text = _voterAnswers.Voters[0].IsContextUserNameNull() ?  GetPageResource("ContextUserNameDisabled") : _voterAnswers.Voters[0].ContextUserName;
			VoterLanguageValueLabel.Text = _voterAnswers.Voters[0].IsLanguageCodeNull() || _voterAnswers.Voters[0].LanguageCode.Length == 0 ?  
				GetPageResource("LanguageUndefined") : _voterAnswers.Voters[0].LanguageCode;
			TimeToTakeSurveyLabel.Text = string.Format("{0} {1}, {2} secs.", timeTaken.Minutes.ToString(), GetPageResource("MinutesInfo"), timeTaken.Seconds.ToString());

			WebSecurityAddInCollection securityAddIns = WebSecurityAddInFactory.CreateWebSecurityAddInCollection(new SecurityAddIns().GetWebSecurityAddIns(SurveyId), ViewState, null);
			NameValueCollection addInVoterData;
			for (int i=0;i<securityAddIns.Count;i++)
			{
				addInVoterData = securityAddIns[i].GetAddInVoterData(_voterId);
				if (addInVoterData != null)
				{
					// Creates a new addin voter details page
					SecurityAddInVoterReportControl addInVoterControl = 
						(SecurityAddInVoterReportControl)LoadControl("UserControls/SecurityAddInVoterReportControl.ascx");

					addInVoterControl.AddInDescription = securityAddIns[i].Description;
					addInVoterControl.AddInVoterData = addInVoterData;
					AddInVoterDataPlaceHolder.Controls.Add(addInVoterControl);
				}
			}

			_questionData = new Questions().GetQuestionHierarchy(SurveyId);
			QuestionsDataGrid.DataSource = GetParentQuestions();
			QuestionsDataGrid.DataKeyField = "QuestionId";
			QuestionsDataGrid.DataBind();
			if (isScored)
			{
				VoterScoreTotalLabel.Text = GetPageResource("VoterScoreTotalLabel") + _totalScore.ToString();
			}
		}
		/// <summary>
		/// Get the current DB stats and fill 
		/// the label with them
		/// </summary>
		private void BindData()
		{
			TimeSpan timeTaken;
			_voterAnswers = new Voters().GetVoterAnswers(_voterId);

			if (!_voterAnswers.Voters[0].IsVoteDateNull() && !_voterAnswers.Voters[0].IsStartDateNull())
			{
				timeTaken = _voterAnswers.Voters[0].VoteDate - _voterAnswers.Voters[0].StartDate;
			}
			else
			{
				timeTaken = new TimeSpan(0);
			}

			VoterUIDLabel.Text = _voterId.ToString();
			IPAddressLabel.Text = _voterAnswers.Voters[0].IPSource;
			VoteDateLabel.Text = _voterAnswers.Voters[0].VoteDate.ToString();
			VoterEmail.Text = _voterAnswers.Voters[0].IsEmailNull() ? GetPageResource("AnonymousVoteInfo") : _voterAnswers.Voters[0].Email;
			VoterUserName.Text = _voterAnswers.Voters[0].IsContextUserNameNull() ?  GetPageResource("ContextUserNameDisabled") : _voterAnswers.Voters[0].ContextUserName;
			TimeToTakeSurveyLabel.Text = string.Format("{0} {1}, {2} secs.", 
				timeTaken.Minutes.ToString(), GetPageResource("MinutesInfo"), timeTaken.Seconds.ToString());

			WebSecurityAddInCollection securityAddIns = WebSecurityAddInFactory.CreateWebSecurityAddInCollection(new SecurityAddIns().GetWebSecurityAddIns(SurveyId), ViewState, null);
			NameValueCollection addInVoterData;
			for (int i=0;i<securityAddIns.Count;i++)
			{
				addInVoterData = securityAddIns[i].GetAddInVoterData(_voterId);
				if (addInVoterData != null)
				{
					// Creates a new addin voter details page
					SecurityAddInVoterReportControl addInVoterControl = 
						(SecurityAddInVoterReportControl)LoadControl("UserControls/SecurityAddInVoterReportControl.ascx");

					addInVoterControl.AddInDescription = securityAddIns[i].Description;
					addInVoterControl.AddInVoterData = addInVoterData;
					AddInVoterDataPlaceHolder.Controls.Add(addInVoterControl);
				}
			}
		}
		private void StatsCalendar_DayRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e)
		{	
			int voterNumber = new Voters().GetDayStats(SurveyId, e.Day.Date);
			if (voterNumber > 0)
			{
				e.Cell.Controls.Add(new LiteralControl(string.Format("<br /><b>" + GetPageResource("EntriesNumber") + "</b>", voterNumber)));
			}
			else
			{
				e.Cell.Controls.Add(new LiteralControl(string.Format("<br />&nbsp;")));
			}
		}