Exemplo n.º 1
0
        public List <SubQuestion> getSubQuestions(Question parentQuestion)
        {
            var questions          = new List <SubQuestion>();
            var dataBaseConnection = ConnexionClasse.getConnexion();

            dataBaseConnection.Open();
            var result = ExecuteStoredProcedure(dataBaseConnection, "sel_sub_questions",
                                                new Dictionary <string, object>()
            {
                { "@question_id", parentQuestion.Id },
                { "@question_type", parentQuestion.Category }
            });

            while (result.Read())
            {
                SubQuestion q = new SubQuestion();
                q.ParentQuestion = parentQuestion;
                q.Category       = parentQuestion.Category;
                try
                {
                    mapQuestion(result, q);
                }
                catch (Exception)
                {
                }
                questions.Add(q);
            }
            dataBaseConnection.Close();
            foreach (SubQuestion q in questions)
            {
                q.Choices = getChoices(q);
            }
            return(questions);
        }
Exemplo n.º 2
0
        public static int NumberResponse_GeneralQuestion(string table, string nomC, string label)
        {
            SqlConnection conn;

            conn = ConnexionClasse.getConnexion();
            conn.Open();


            SqlCommand getNumberResponse = new SqlCommand("selReponse", conn);

            getNumberResponse.CommandType = CommandType.StoredProcedure;
            getNumberResponse.Parameters.AddWithValue("@table", table);
            getNumberResponse.Parameters.AddWithValue("@column", nomC);
            getNumberResponse.Parameters.AddWithValue("@label", label);

            var result = getNumberResponse.ExecuteReader();
            var nb     = 0;

            while (result.Read())
            {
                try
                {
                    nb = Int32.Parse(result["nb"].ToString());
                }
                catch (Exception e)
                {
                }
            }
            conn.Close();


            return(nb);
        }
Exemplo n.º 3
0
        public static bool AlreadyAnswerd(int poll_id, int person_id)
        {
            var dataBaseConnection = ConnexionClasse.getConnexion();

            dataBaseConnection.Open();
            var result = Manager.ExecuteStoredProcedure(dataBaseConnection, "sel_poll_survey",
                                                        new Dictionary <string, object>()
            {
                { "@poll_id", poll_id },
                { "@person_id", person_id }
            });
            var count = 0;

            while (result.Read())
            {
                try
                {
                    count = int.Parse(result["c"].ToString());
                }
                catch (Exception)
                {
                }
            }
            dataBaseConnection.Close();
            return(count > 0);
        }
Exemplo n.º 4
0
        public string getAnswer(int pollId, string tableName, string category, string column, int personId,
                                int activityId = 0)
        {
            var dataBaseConnection = ConnexionClasse.getConnexion();

            dataBaseConnection.Open();
            var result = ExecuteStoredProcedure(dataBaseConnection, "get_rep_person", new Dictionary <string, object>()
            {
                { "@poll_id", pollId },
                { "@person_id", personId },
                { "@table", tableName },
                { "@activity_id", activityId },
                { "@question_type", category },
                { "@column_name", column }
            });

            result.Read();
            var tmp = "";

            try
            {
                tmp = result[column].ToString();
            }
            catch (Exception)
            {
            }
            dataBaseConnection.Close();
            return(tmp);
        }
Exemplo n.º 5
0
        public DataSet getSessionWsAnswers(string category, string tablename)
        {
            if (category.Equals("Activity"))
            {
                table = "ATELIER_SESSION";
            }
            else
            if (category.Equals("Workshop"))
            {
                table = "ATELIER_WS";
            }
            SqlConnection conn;

            conn = ConnexionClasse.getConnexion();
            SqlCommand Answers = new SqlCommand("sel_session_ws_answers", conn);

            Answers.Parameters.AddWithValue("@table", tablename);
            Answers.Parameters.AddWithValue("@tableSorWS", table);
            Answers.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter dscmd = new SqlDataAdapter(Answers);

            dscmd.SelectCommand = Answers;
            DataSet ds = new DataSet();

            dscmd.Fill(ds);

            return(ds);
        }
Exemplo n.º 6
0
        public int getNbParticipants(int poll_id, string table)
        {
            SqlConnection conn;

            //
            conn = ConnexionClasse.getConnexion();
            conn.Open();
            SqlCommand nbParticipants = new SqlCommand("sel_nb_participants", conn);

            nbParticipants.CommandType = CommandType.StoredProcedure;
            nbParticipants.Parameters.AddWithValue("@poll_id", poll_id);
            nbParticipants.Parameters.AddWithValue("@table", table);
            var result = nbParticipants.ExecuteReader();
            var nb     = 0;

            while (result.Read())
            {
                try
                {
                    nb = Int32.Parse(result["nb"].ToString());
                }
                catch (Exception) { }
            }
            conn.Close();


            return(nb);
        }
Exemplo n.º 7
0
        public string getMeetingParticipants(int id_meeting, int id_company)
        {
            SqlConnection conn;

            conn = ConnexionClasse.getConnexion();
            conn.Open();
            SqlCommand nbParticipants = new SqlCommand("sel_participantscompanies", conn);

            nbParticipants.CommandType = CommandType.StoredProcedure;
            nbParticipants.Parameters.AddWithValue("@id_meeting", id_meeting);
            nbParticipants.Parameters.AddWithValue("@id_company", id_company);
            var result = nbParticipants.ExecuteReader();
            var nb     = "";

            while (result.Read())
            {
                try
                {
                    nb = result["participants"].ToString();
                }
                catch (Exception e) { }
            }
            conn.Close();


            return(nb);
        }
Exemplo n.º 8
0
        public int NumberResponseMultipleChoiceMeeting(String nomC, String label, String table_met_name)
        {
            SqlConnection dataBaseConnection = ConnexionClasse.getConnexion();

            dataBaseConnection.Open();
            SqlCommand getNumberResponse = new SqlCommand("selReponseCheckBoxListMeeting", dataBaseConnection);

            getNumberResponse.CommandType = CommandType.StoredProcedure;
            getNumberResponse.Parameters.AddWithValue("@column", nomC);
            getNumberResponse.Parameters.AddWithValue("@label", label);
            getNumberResponse.Parameters.AddWithValue("@table_met_name", table_met_name);
            var result = getNumberResponse.ExecuteReader();
            var nb     = 0;

            while (result.Read())
            {
                try
                {
                    nb = Int32.Parse(result["nb"].ToString());
                }
                catch (Exception)
                {
                    dataBaseConnection.Close();
                    throw new InvalidOperationException("invalide parse number !!");
                }
            }
            dataBaseConnection.Close();
            return(nb);
        }
Exemplo n.º 9
0
        public Poll getPoll(int idPoll, int idPerson = 0)
        {
            var poll = new Poll {
                PersonId = idPerson
            };
            var dataBaseConnection = ConnexionClasse.getConnexion();

            dataBaseConnection.Open();

            var result = ExecuteStoredProcedure(dataBaseConnection, "sel_poll", new Dictionary <string, object>()
            {
                { "@poll_id", idPoll }
            });

            while (result.Read())
            {
                poll.Id = idPoll;
                try
                {
                    poll.Name        = result["POL_name"].ToString();
                    poll.Description = result["POL_description"].ToString();
                }
                catch (Exception)
                {
                }
                poll.ExternalId       = result["POL_external_id"].ToString();
                poll.TableName        = result["POL_table_name"].ToString();
                poll.TableMeetingName = result["POL_table_meeting_name"].ToString();
                poll.TableWsName      = result["POL_table_ws_name"].ToString();
                poll.TableSessionName = result["POL_table_session_name"].ToString();
                try
                {
                    poll.SurveyId = int.Parse(result["POL_id_poll"].ToString());
                }
                catch (Exception)
                {
                }
                try
                {
                    poll.EventId = int.Parse(result["POL_id_event"].ToString());
                }
                catch (Exception)
                {
                    throw new Exception("no event id in poll table");
                }
            }
            dataBaseConnection.Close();
            poll.Questions = this.getQuestions(poll.Id);
            poll.Questions.Sort((q1, q2) => q1.Order.CompareTo(q2.Order));
            poll.Meetings  = getMeetings(poll.EventId, idPerson);
            poll.Sessions  = getSessions(poll.EventId, idPerson);
            poll.Workshops = getWorkshops(poll.EventId, idPerson);
            poll.Blocks    = getBlocks(poll.Id);
            return(poll);
        }
Exemplo n.º 10
0
        public List <Meeting> getMeetings(int eventId, int personId)
        {
            var meetings           = new List <Meeting>();
            var dataBaseConnection = ConnexionClasse.getConnexion();

            dataBaseConnection.Open();
            var result = ExecuteStoredProcedure(dataBaseConnection, "sel_meetings", new Dictionary <string, object>()
            {
                { "@id_person", personId },
                { "@id_event", eventId }
            });

            while (result.Read())
            {
                Meeting m = new Meeting();
                m.company_name = result["COM_company"].ToString();
                // owner
                // guests
                try
                {
                    m.id_company = int.Parse(result["MEE_id_company"].ToString());
                }
                catch (Exception)
                {
                }
                try
                {
                    m.date_start = Convert.ToDateTime(result["TIM_date_start"]);
                }
                catch (Exception)
                {
                }
                try
                {
                    m.id_meeting = int.Parse(result["MEE_id_meeting"].ToString());
                }
                catch (Exception)
                {
                }
                try
                {
                    m.date_end = Convert.ToDateTime(result["TIM_date_end"]);
                }
                catch (Exception)
                {
                }
                m.location_name = result["LOC_location"].ToString();
                meetings.Add(m);
            }
            dataBaseConnection.Close();
            return(meetings);
        }
Exemplo n.º 11
0
        public static void SaveInPollSurvey(int poll_id, int person_id, DateTime time)
        {
            var dataBaseConnection = ConnexionClasse.getConnexion();

            dataBaseConnection.Open();
            ExecuteStoredProcedure(dataBaseConnection, "i_poll_survey", new Dictionary <string, object>()
            {
                { "@poll_id", poll_id },
                { "@person_id", person_id },
                { "@saved_date", time }
            });
            dataBaseConnection.Close();
        }
Exemplo n.º 12
0
        public List <Session> getSessions(int eventId, int personId)
        {
            var sessions           = new List <Session>();
            var dataBaseConnection = ConnexionClasse.getConnexion();

            dataBaseConnection.Open();
            var result = ExecuteStoredProcedure(dataBaseConnection, "sel_sessions", new Dictionary <string, object>()
            {
                { "@id_person", personId },
                { "@id_event", eventId }
            });

            while (result.Read())
            {
                Session s = new Session();
                try
                {
                    s.etat = Int32.Parse(result["etat"].ToString());
                }
                catch (Exception)
                {
                }
                try
                {
                    s.id_atelier = Int32.Parse(result["id_atelier"].ToString());
                }
                catch (Exception)
                {
                    throw new Exception("id atelier not found");
                }
                try
                {
                    s.attended_date = Convert.ToDateTime(result["attended_date"]);
                }
                catch (Exception)
                {
                }
                try
                {
                    s.creation_date = Convert.ToDateTime(result["creation_date"]);
                }
                catch (Exception)
                {
                }
                s.theme       = result["theme"].ToString();
                s.description = result["description"].ToString();
                sessions.Add(s);
            }
            dataBaseConnection.Close();
            return(sessions);
        }
Exemplo n.º 13
0
        public static DataSet GetAnswersByColumn(string tableName, string columnName)
        {
            var conn     = ConnexionClasse.getConnexion();
            var commande = new SqlCommand("sel_answers", conn);

            commande.CommandType = CommandType.StoredProcedure;
            commande.Parameters.AddWithValue("@table", tableName);
            commande.Parameters.AddWithValue("@column", columnName);
            var sqlAdapter = new SqlDataAdapter(commande);
            var dataSet    = new DataSet();

            sqlAdapter.Fill(dataSet);
            return(dataSet);
        }
Exemplo n.º 14
0
        public List <Workshop> getWorkshops(int eventId, int personId)
        {
            var workshps           = new List <Workshop>();
            var dataBaseConnection = ConnexionClasse.getConnexion();

            dataBaseConnection.Open();
            var result = ExecuteStoredProcedure(dataBaseConnection, "sel_workshops", new Dictionary <string, object>()
            {
                { "@id_person", personId },
                { "@id_event", eventId }
            });

            while (result.Read())
            {
                Workshop ws = new Workshop();
                try
                {
                    ws.etat = Int32.Parse(result["etat"].ToString());
                }
                catch (Exception)
                {
                }
                try
                {
                    ws.id_atelier = Int32.Parse(result["id_atelier"].ToString());
                }
                catch (Exception)
                {
                    throw new Exception("id atelier not found");
                }
                try
                {
                    ws.attended_date = Convert.ToDateTime(result["attended_date"]);
                }

                /*catch (Exception) { }
                 * try
                 * {
                 *  ws.creation_date = Convert.ToDateTime(result["creation_date"]);
                 * }*/
                catch (Exception)
                {
                }
                ws.theme       = result["theme"].ToString();
                ws.description = result["description"].ToString();
                workshps.Add(ws);
            }
            dataBaseConnection.Close();
            return(workshps);
        }
Exemplo n.º 15
0
        public List <Question> getQuestions(int pollId)
        {
            List <Question> questions          = new List <Question>();
            var             dataBaseConnection = ConnexionClasse.getConnexion();

            dataBaseConnection.Open();
            var result = ExecuteStoredProcedure(dataBaseConnection, "sel_questions", new Dictionary <string, object>()
            {
                { "@poll_id", pollId }
            });

            while (result.Read())
            {
                Question q = new Question();
                try
                {
                    q.BlockNumber = Int32.Parse(result["QUE_id_block"].ToString());
                }
                catch (Exception)
                {
                    throw new Exception("QUE_id_block is not an int");
                }
                try
                {
                    q.Category = result["QUET_question_type"].ToString();
                }
                catch (Exception)
                {
                    throw new Exception("Question type unknown");
                }
                mapQuestion(result, q);
                questions.Add(q);
            }
            dataBaseConnection.Close();
            foreach (Question q in questions)
            {
                switch (q.Category)
                {
                case QuestionType.Session:
                case QuestionType.Meeting:
                case QuestionType.Workshop:
                    q.SubQuestions = getSubQuestions(q);
                    break;
                }
                q.Choices = getChoices(q);
            }
            return(questions);
        }
Exemplo n.º 16
0
        public static int NumberResponse(string table, string nomC, string label, string category, int id_atelier,
                                         int id_person)
        {
            var           clumnname = "";
            var           ps        = "";
            SqlConnection conn;

            conn = ConnexionClasse.getConnexion();

            if (category.Equals("Activity") || category.Equals("Workshop"))
            {
                clumnname = "SUB_" + nomC;
                ps        = "sel_session_ws_responses";
            }
            else if (category.Equals("Meeting"))
            {
                clumnname = "SUM_" + nomC;
                ps        = "sel_meeting_responses";
            }

            conn.Open();
            SqlCommand getNumberResponse = new SqlCommand(ps, conn);

            getNumberResponse.CommandType = CommandType.StoredProcedure;
            getNumberResponse.Parameters.AddWithValue("@column", clumnname);
            getNumberResponse.Parameters.AddWithValue("@label", label);
            getNumberResponse.Parameters.AddWithValue("@table", table);
            getNumberResponse.Parameters.AddWithValue("@id_atelier", id_atelier);
            getNumberResponse.Parameters.AddWithValue("@id_person", id_person);
            var result = getNumberResponse.ExecuteReader();
            var nb     = 0;

            while (result.Read())
            {
                try
                {
                    nb = Int32.Parse(result["nb"].ToString());
                }
                catch (Exception)
                {
                }
            }
            conn.Close();


            return(nb);
        }
Exemplo n.º 17
0
        private void ExecuteStoredProcedure(string fileName)
        {
            string        script    = System.IO.File.ReadAllText(fileName);
            SqlConnection connexion = ConnexionClasse.getConnexion();

            connexion.Open();
            try
            {
                Server server = new Server(new ServerConnection(connexion));
                server.ConnectionContext.ExecuteNonQuery(script);
            }
            catch (Exception e)
            {
                throw e;
            }
            connexion.Close();
        }
Exemplo n.º 18
0
        public Dictionary <int, string> getBlocks(int pollId)
        {
            var blocks             = new Dictionary <int, string>();
            var dataBaseConnection = ConnexionClasse.getConnexion();

            dataBaseConnection.Open();
            var result = ExecuteStoredProcedure(dataBaseConnection, "sel_blocks", new Dictionary <string, object>()
            {
                { "@poll_id", pollId }
            });

            while (result.Read())
            {
                blocks.Add(Int32.Parse(result["POLB_id_block"].ToString()), result["POLB_label"].ToString());
            }
            dataBaseConnection.Close();
            return(blocks);
        }
Exemplo n.º 19
0
        private List <Choice> getChoices(Question q)
        {
            var choices            = new List <Choice>();
            var dataBaseConnection = ConnexionClasse.getConnexion();

            dataBaseConnection.Open();
            SqlDataReader result;

            if (q.GetType() == typeof(SubQuestion))
            {
                result = ExecuteStoredProcedure(dataBaseConnection, "sel_sub_questions_choices",
                                                new Dictionary <string, object>()
                {
                    { "@question_id", q.Id },
                    { "@question_type", q.Category }
                });
            }
            else
            {
                result = ExecuteStoredProcedure(dataBaseConnection, "sel_choices", new Dictionary <string, object>()
                {
                    { "@question_id", q.Id }
                });
            }

            while (result.Read())
            {
                var r = new Choice();
                try
                {
                    r.Id    = int.Parse(result["choice_id"].ToString());
                    r.Label = result["choice_label"].ToString();
                    r.Id    = int.Parse(result["choice_order"].ToString());
                    //r.Value = result["choice_label"].ToString();
                    r.Value = result["choice_value"].ToString();
                }
                catch (Exception)
                {
                }
                choices.Add(r);
            }
            dataBaseConnection.Close();
            return(choices);
        }
Exemplo n.º 20
0
        public string getCompany(int id_company)
        {
            string        company_name = "";
            SqlConnection conn;

            conn = ConnexionClasse.getConnexion();
            conn.Open();
            SqlCommand getPersons = new SqlCommand("sel_getCompanyName", conn);

            getPersons.CommandType = CommandType.StoredProcedure;
            getPersons.Parameters.AddWithValue("@id_company", id_company);
            var result = getPersons.ExecuteReader();

            while (result.Read())
            {
                company_name = result["COM_company"].ToString();
            }
            conn.Close();
            return(company_name);
        }
Exemplo n.º 21
0
        public DataSet getGeneralAnswers(int id_poll, string tablename)
        {
            SqlConnection conn;

            conn = ConnexionClasse.getConnexion();

            SqlCommand Answers = new SqlCommand("sel_general_answers", conn);

            Answers.Parameters.AddWithValue("@id_poll", id_poll);
            Answers.Parameters.AddWithValue("@table", tablename);
            Answers.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter dscmd = new SqlDataAdapter(Answers);

            dscmd.SelectCommand = Answers;
            DataSet ds = new DataSet();

            dscmd.Fill(ds);

            return(ds);
        }
Exemplo n.º 22
0
        public static List <Atelier> getWsAtelier(int poll_id, string table)
        {
            var           atelier = new List <Atelier>();
            SqlConnection conn;

            conn = ConnexionClasse.getConnexion();
            conn.Open();
            SqlCommand getWs_Atelier = new SqlCommand("sel_ws_Atelier", conn);

            getWs_Atelier.CommandType = CommandType.StoredProcedure;
            getWs_Atelier.Parameters.AddWithValue("@id_poll", poll_id);
            getWs_Atelier.Parameters.AddWithValue("@table", table);
            var result = getWs_Atelier.ExecuteReader();

            while (result.Read())
            {
                Atelier ate = new Atelier();
                try
                {
                    ate.id_event = Int32.Parse(result["id_event"].ToString());
                }
                catch (Exception)
                {
                }
                try
                {
                    ate.id_atelier = Int32.Parse(result["id_atelier"].ToString());
                }
                catch (Exception)
                {
                    throw new Exception("id atelier not found");
                }

                ate.theme       = result["theme"].ToString();
                ate.description = result["description"].ToString();
                atelier.Add(ate);
            }
            conn.Close();
            return(atelier);
        }
Exemplo n.º 23
0
        public static List <Meeting> getAttendedMeetings(int id_poll, string tablename)
        {
            var meetings = new List <Meeting>();

            SqlConnection conn;

            conn = ConnexionClasse.getConnexion();
            conn.Open();
            SqlCommand getMeetings = new SqlCommand("sel_attended_meetings", conn);

            getMeetings.CommandType = CommandType.StoredProcedure;
            getMeetings.Parameters.AddWithValue("@id_poll", id_poll);
            getMeetings.Parameters.AddWithValue("@table", tablename);
            var result = getMeetings.ExecuteReader();

            while (result.Read())
            {
                Meeting m = new Meeting();

                try
                {
                    m.id_meeting = Int32.Parse(result["SUM_id_meeting"].ToString());
                }
                catch (Exception)
                {
                }
                try
                {
                    m.id_company = Int32.Parse(result["SUM_id_company"].ToString());
                }
                catch (Exception)
                {
                }
                meetings.Add(m);
            }
            conn.Close();

            return(meetings);
        }
Exemplo n.º 24
0
        public List <Meeting> getMeetings(int id_poll, string table)
        {
            var meetings = new List <Meeting>();

            SqlConnection conn;

            conn = ConnexionClasse.getConnexion();
            conn.Open();
            SqlCommand getQuestions = new SqlCommand("sel_all_meetings", conn);

            getQuestions.CommandType = CommandType.StoredProcedure;
            getQuestions.Parameters.AddWithValue("@id_poll", id_poll);
            getQuestions.Parameters.AddWithValue("@table", table);
            var result = getQuestions.ExecuteReader();

            while (result.Read())
            {
                Meeting m = new Meeting();

                try
                {
                    m.id_meeting = Int32.Parse(result["MEE_id_meeting"].ToString());
                }
                catch (Exception) { }


                meetings.Add(m);
            }


            conn.Close();
            foreach (Meeting m in meetings)
            {
                m.guests = getPersons(m.id_meeting);
                // m.owner = getPerson(getIdOwner(m.id_meeting));
            }

            return(meetings);
        }
Exemplo n.º 25
0
        public List <Person> getPersons(int id_metting)
        {
            var           persons = new List <Person>();
            SqlConnection conn;

            conn = ConnexionClasse.getConnexion();
            conn.Open();
            SqlCommand getPersons = new SqlCommand("sel_persons", conn);

            getPersons.CommandType = CommandType.StoredProcedure;
            getPersons.Parameters.AddWithValue("@id_meeting", id_metting);
            var result = getPersons.ExecuteReader();

            while (result.Read())
            {
                Person person = new Person();
                try
                {
                    person.Id = Int32.Parse(result["PER_id_person"].ToString());
                }
                catch (Exception) { }
                try
                {
                    person.CompanyId = Int32.Parse(result["PER_id_company"].ToString());
                }
                catch (Exception) { throw new Exception(""); }

                person.FirstName = result["PER_first_name"].ToString();
                person.LastName  = result["PER_last_name"].ToString();
                persons.Add(person);
            }
            conn.Close();
            foreach (Person p in persons)
            {
                p.CompanyName = getCompany(p.CompanyId);
            }
            return(persons);
        }
Exemplo n.º 26
0
        public static int GetHashedId(string hash, int pollId)
        {
            var dataBaseConnection = ConnexionClasse.getConnexion();

            dataBaseConnection.Open();
            var result = ExecuteStoredProcedure(dataBaseConnection, "get_hased_id", new Dictionary <string, object>()
            {
                { "@hash", hash },
                { "@poll_id", pollId }
            });
            var personId = -1;

            if (result.Read())
            {
                try
                {
                    personId = int.Parse(result["person_id"].ToString());
                }
                catch (Exception) {}
            }
            dataBaseConnection.Close();
            return(personId);
        }
Exemplo n.º 27
0
        public Dictionary <int, String> Get_list_session_atelier(int id_poll, String table_name)
        {
            SqlConnection dataBaseConnection = ConnexionClasse.getConnexion();

            dataBaseConnection.Open();
            SqlCommand getNumberResponse = new SqlCommand("sel_session_atelier", dataBaseConnection);

            getNumberResponse.CommandType = CommandType.StoredProcedure;
            getNumberResponse.Parameters.AddWithValue("@id_poll", id_poll);
            getNumberResponse.Parameters.AddWithValue("@table", table_name);
            var result          = getNumberResponse.ExecuteReader();
            var atelier_session = new Dictionary <int, String>();

            while (result.Read())
            {
                try
                {
                    atelier_session.Add(int.Parse(result["id_atelier"].ToString()), result["theme"].ToString());
                }
                catch (Exception) { dataBaseConnection.Close(); }
            }
            dataBaseConnection.Close();
            return(atelier_session);
        }
Exemplo n.º 28
0
        public static void SaveAnswer(
            List <Question> questions,
            Poll poll,
            string externalId,
            int personId,
            DateTime time
            )
        {
            var dataBaseConnection = ConnexionClasse.getConnexion();
            var meetingCommands    = new Dictionary <int, SqlCommand>();
            var sessionCommands    = new Dictionary <int, SqlCommand>();
            var workshopCommands   = new Dictionary <int, SqlCommand>();

            foreach (var meeting in poll.Meetings)
            {
                var sqlc = new SqlCommand("I_MEETING_" + externalId, dataBaseConnection);
                sqlc.CommandType = CommandType.StoredProcedure;
                sqlc.Parameters.AddWithValue("@id_survey", poll.SurveyId);
                sqlc.Parameters.AddWithValue("@id_poll", poll.Id);
                sqlc.Parameters.AddWithValue("@id_meeting", meeting.id_meeting);
                sqlc.Parameters.AddWithValue("@id_person", personId);
                sqlc.Parameters.AddWithValue("@id_company", meeting.id_company);
                sqlc.Parameters.AddWithValue("@date_mod", time);
                meetingCommands.Add(meeting.id_meeting, sqlc);
            }
            foreach (var session in poll.Sessions)
            {
                var sqlc = new SqlCommand("I_SESSION_" + externalId, dataBaseConnection);
                sqlc.CommandType = CommandType.StoredProcedure;
                sqlc.Parameters.AddWithValue("@id_survey", poll.SurveyId);
                sqlc.Parameters.AddWithValue("@id_poll", poll.Id);
                sqlc.Parameters.AddWithValue("@id_person", personId);
                sqlc.Parameters.AddWithValue("@id_atelier", session.id_atelier);
                sqlc.Parameters.AddWithValue("@date_mod", time);
                sessionCommands.Add(session.id_atelier, sqlc);
            }
            foreach (var workshop in poll.Workshops)
            {
                var sqlc = new SqlCommand("I_WS_" + externalId, dataBaseConnection);
                sqlc.CommandType = CommandType.StoredProcedure;
                sqlc.Parameters.AddWithValue("@id_survey", poll.SurveyId);
                sqlc.Parameters.AddWithValue("@id_poll", poll.Id);
                sqlc.Parameters.AddWithValue("@id_person", personId);
                sqlc.Parameters.AddWithValue("@id_atelier", workshop.id_atelier);
                sqlc.Parameters.AddWithValue("@date_mod", time);
                workshopCommands.Add(workshop.id_atelier, sqlc);
            }
            var generalCommand = new SqlCommand("I" + externalId, dataBaseConnection);

            generalCommand.CommandType = CommandType.StoredProcedure;
            generalCommand.Parameters.AddWithValue("@person_id", personId);

            foreach (var q in questions)
            {
                switch (q.Category)
                {
                case QuestionType.General:
                    generalCommand.Parameters.AddWithValue("@" + q.Column, q.Answer);
                    break;

                case QuestionType.Meeting:
                    var m = (Meeting)((SubQuestion)q).Activity;
                    meetingCommands[m.id_meeting].Parameters.AddWithValue("@" + q.Column, q.Answer);
                    break;

                case QuestionType.Session:
                    var s = (Session)((SubQuestion)q).Activity;
                    sessionCommands[s.id_atelier].Parameters.AddWithValue("@" + q.Column, q.Answer);
                    break;

                case QuestionType.Workshop:
                    var ws = (Workshop)((SubQuestion)q).Activity;
                    workshopCommands[ws.id_atelier].Parameters.AddWithValue("@" + q.Column, q.Answer);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            foreach (var key in meetingCommands.Keys)
            {
                dataBaseConnection.Open();
                meetingCommands[key].ExecuteReader();
                dataBaseConnection.Close();
            }
            foreach (var key in sessionCommands.Keys)
            {
                dataBaseConnection.Open();
                sessionCommands[key].ExecuteReader();
                dataBaseConnection.Close();
            }
            foreach (var key in workshopCommands.Keys)
            {
                dataBaseConnection.Open();
                workshopCommands[key].ExecuteReader();
                dataBaseConnection.Close();
            }
            dataBaseConnection.Open();
            generalCommand.ExecuteReader();
            dataBaseConnection.Close();
        }