Example #1
0
        public static SurveyResults GetSurveyResults(int surveyId, String user, DateTime date)
        {
            if (!isConnected)
            {
                Init();
            }

            SurveyResults resultsList = new SurveyResults();
            resultsList.surveyId = surveyId;
            SQLiteCommand sqliteCommand = dbConnection.CreateCommand();
            sqliteCommand.Parameters.Add(new SQLiteParameter(":survey_id", surveyId));
            sqliteCommand.Parameters.Add(new SQLiteParameter(":user_name", user));
            sqliteCommand.Parameters.Add(new SQLiteParameter(":date", date));
            sqliteCommand.CommandText = "SELECT * FROM " + RESULTS_TABLE + " WHERE ((survey_id=:survey_id) AND (user_name=:user_name) AND (date=:date))";
            SQLiteDataReader sqliteReader = sqliteCommand.ExecuteReader();

            // Save each result to resultsList
            while (sqliteReader.Read())
            {
                PollResult curResult = new PollResult();
                curResult.answerId = Convert.ToInt32(sqliteReader["answer_id"].ToString());
                curResult.customChoice = sqliteReader["custom_choice"].ToString();
                curResult.date = sqliteReader["date"].ToString();
                curResult.questionId = Convert.ToInt32(sqliteReader["question_id"].ToString());
                curResult.userName = sqliteReader["user_name"].ToString();
                resultsList.results.Add(curResult);
            }

            return resultsList;
        }
Example #2
0
        /// <summary>
        /// Receive from Client poll result and save it in database
        /// </summary>
        /// <param name="resultsList">PollResult</param>
        public static void SavePollResult(PollResult pollResult)
        {
            if (!isConnected)
            {
                Init();
            }

            SQLiteCommand sqliteCommand = dbConnection.CreateCommand();

            sqliteCommand.CommandText = "INSERT INTO " + RESULTS_TABLE + "(user_name, survey_id, question_id, answer_id, custom_choice) VALUES(:username, :survey, :question, :answer, :custom)";
            sqliteCommand.Parameters.AddWithValue(":username", pollResult.userName);
            sqliteCommand.Parameters.AddWithValue(":survey", -1);
            sqliteCommand.Parameters.AddWithValue(":question", pollResult.questionId);
            sqliteCommand.Parameters.AddWithValue(":answer", pollResult.answerId);
            sqliteCommand.Parameters.AddWithValue(":custom", pollResult.customChoice);
            sqliteCommand.ExecuteNonQuery();
        }
Example #3
0
        /// <summary>
        /// Select from DB all results of needed Poll
        /// </summary>
        /// <param name="surveyId">Id of Poll which results we need</param>
        /// <returns>List of results of needed Poll</returns>
        public static List<PollResult> GetPollResults(int pollId)
        {
            if (!isConnected)
            {
                Init();
            }

            List<PollResult> pollResults = new List<PollResult>();
            SQLiteCommand sqliteCommand = dbConnection.CreateCommand();
            sqliteCommand.Parameters.AddWithValue(":question_id", pollId);
            sqliteCommand.Parameters.AddWithValue(":survey_id", -1);
            sqliteCommand.CommandText = "SELECT * FROM " + RESULTS_TABLE + " WHERE question_id=:question_id AND survey_id=:survey_id";
            SQLiteDataReader sqliteReader = sqliteCommand.ExecuteReader();

            // Save each result to resultsList
            while (sqliteReader.Read())
            {
                PollResult curResult = new PollResult();
                curResult.answerId = Convert.ToInt32(sqliteReader["answer_id"].ToString());
                curResult.customChoice = sqliteReader["custom_choice"].ToString();
                curResult.questionId = Convert.ToInt32(sqliteReader["question_id"].ToString());
                curResult.userName = sqliteReader["user_name"].ToString();
                pollResults.Add(curResult);
            }

            return pollResults;
        }
Example #4
0
    protected void btnSurvey_Click(object sender, EventArgs e)
    {
        if (choiceList.SelectedIndex > -1)
        {
            errorMessage.Visible = false;

            PollResult pollResult = new PollResult();
            pollResult.questionId = survey.Polls[pollIndex].Id;
            pollResult.answerId = Convert.ToInt32(choiceList.SelectedValue);

            surveyResults.results.Add(pollResult);

            ++pollIndex;

            if (pollIndex == survey.Polls.Count)
            {
                PollDAL.SaveSurveyResult(surveyResults);
                Response.Redirect("Results.aspx");
            }

            LoadData();

            if (pollIndex == survey.Polls.Count - 1)
            {
                btnSurvey.Text = "Finish";
            }
        }
        else
        {
            errorMessage.Visible = true;
            errorMessage.Text = "Please select a choice";
        }
    }
Example #5
0
        private void ProcessResult()
        {
            PollResult result = new PollResult();
            result.questionId = survey.Polls[currentPoll - 1].Id;

            if (selectedChoice == survey.Polls[currentPoll - 1].Choices.Count())
            {
                result.answerId = -1;
                result.customChoice = customChoice;
            }
            else
            {
                result.answerId = survey.Polls[currentPoll - 1].Choices[selectedChoice].Id;
            }

            result.userName = PollClientGUI.userName;
            resultsList.results.Add(result);
        }
Example #6
0
        /// <summary>
        /// Send results of survey to server
        /// </summary>
        public static void SaveSurveyResults()
        {
            PollPacket sendPacket = new PollPacket();
            sendPacket.request = new Request();
            sendPacket.request.type = Request.SAVE_RESULT;
            sendPacket.resultsList = new SurveyResults();
            sendPacket.resultsList.userName = userName;
            sendPacket.resultsList.surveyId = survey.Id;

            foreach (Choice userChoice in userChoices)
            {
                PollResult curSurveyResult = new PollResult();
                curSurveyResult.questionId = userChoice.parent.Id;
                if (userChoice.Id == 0)
                {
                    curSurveyResult.answerId = 0;
                    curSurveyResult.customChoice = userChoice.choice;
                }
                else
                {
                    curSurveyResult.answerId = userChoice.Id;
                }
                sendPacket.resultsList.results.Add(curSurveyResult);
            }
            string sendString = PollSerializator.SerializePacket(sendPacket);
            client.Send(sendString);
            Console.WriteLine("-> Result of survey successfully sent to server");
        }
Example #7
0
 public void SaveAnswer()
 {
     int pollID = Convert.ToInt32(Request["poll_id"]);
     PollResult pollResult = new PollResult();
     pollResult.questionId = Convert.ToInt32(pollID);
     pollResult.answerId = Convert.ToInt32(choicesRadioButtonList.SelectedValue);
     pollResult.userName = "******";
     PollDAL.SavePollResult(pollResult);
 }