コード例 #1
0
        //------------------------------------------
        #endregion

        #region --------------GetObject--------------
        public static VoteQuestionsEntity GetObject(int quesID)
        {
            VoteQuestionsEntity voteQuestions = VoteQuestionsSqlDataPrvider.Instance.GetObject(quesID);

            //return the object
            return(voteQuestions);
        }
コード例 #2
0
        //------------------------------------------
        #endregion

        #region --------------GetMain--------------
        public VoteQuestionsEntity GetMain(Languages langID)
        {
            VoteQuestionsEntity voteQuestions = null;

            using (SqlConnection myConnection = GetSqlConnection())
            {
                SqlCommand myCommand = new SqlCommand("VoteQuestions_GetMain", myConnection);
                myCommand.CommandType = CommandType.StoredProcedure;
                // Set the parameters
                myCommand.Parameters.Add("@LangID", SqlDbType.Int, 4).Value = (int)langID;
                //----------------------------------------------------------------------------------------------
                //OwnerID
                myCommand.Parameters.Add("@OwnerID", SqlDbType.UniqueIdentifier).Value = SitesHandler.GetOwnerIDAsGuid();
                //----------------------------------------------------------------------------------------------
                // Execute the command
                myConnection.Open();
                using (SqlDataReader dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection))
                {
                    if (dr.Read())
                    {
                        voteQuestions = PopulateEntity(dr);
                    }
                    dr.Close();
                }
                myConnection.Close();
                return(voteQuestions);
            }
        }
コード例 #3
0
        //------------------------------------------
        #endregion


        #region --------------GetMain--------------
        public static VoteQuestionsEntity GetMain()
        {
            Languages           langID        = SiteSettings.GetCurrentLanguage();
            VoteQuestionsEntity voteQuestions = VoteQuestionsSqlDataPrvider.Instance.GetMain(langID);

            //return the object
            return(voteQuestions);
        }
コード例 #4
0
        //----------------------------------------------------------
        #endregion


        #region ----------------InsertTestingDataForVoteModule---------------
        //----------------------------------------------------------
        //InsertTestingDataForVoteModule
        //----------------------------------------------------------
        public void InsertTestingDataForVoteModule()
        {
            //---------------------------------------------------------------------
            VoteQuestionsEntity ArVoteQuestions = new VoteQuestionsEntity();
            string ArQuestionText = "سؤال تجريبي {0} ؟";

            ArVoteQuestions.AnswersCount = 4;
            ArVoteQuestions.IsMain       = true;
            ArVoteQuestions.LangID       = Languages.Ar;
            //---------------------------------------------------------------------
            string            ArAnswer     = "إجابة رقم ";
            VoteAnswersEntity ArVoteAnswer = new VoteAnswersEntity();
            //---------------------------------------------------------------------
            //---------------------------------------------------------------------
            VoteQuestionsEntity EnVoteQuestions = new VoteQuestionsEntity();
            string EnQuestionText = "Testing Question {0} ?";

            EnVoteQuestions.AnswersCount = 4;
            EnVoteQuestions.IsMain       = true;
            EnVoteQuestions.LangID       = Languages.En;
            //---------------------------------------------------------------------
            string            EnAnswer     = "Answer no ";
            VoteAnswersEntity EnVoteAnswer = new VoteAnswersEntity();

            //---------------------------------------------------------------------
            for (int i = 1; i <= 2; i++)
            {
                if (SiteSettings.Languages_HasArabicLanguages)
                {
                    ArVoteQuestions.QuestionText = string.Format(ArQuestionText, i.ToString());
                    bool ArResult = VoteQuestionsFactory.Save(ArVoteQuestions, SPOperation.Insert);
                    if (ArResult)
                    {
                        for (int b = 1; b <= 4; b++)
                        {
                            ArVoteAnswer.QuesID     = ArVoteQuestions.QuesID;
                            ArVoteAnswer.AnswerText = ArAnswer + b.ToString();
                            VoteAnswersFactory.Create(ArVoteAnswer);
                        }
                    }
                }
                if (SiteSettings.Languages_HasEnglishLanguages)
                {
                    EnVoteQuestions.QuestionText = string.Format(EnQuestionText, i.ToString());
                    bool EnResult = VoteQuestionsFactory.Save(EnVoteQuestions, SPOperation.Insert);
                    if (EnResult)
                    {
                        for (int b = 1; b <= 4; b++)
                        {
                            EnVoteAnswer.QuesID     = EnVoteQuestions.QuesID;
                            EnVoteAnswer.AnswerText = EnAnswer + b.ToString();
                            VoteAnswersFactory.Create(EnVoteAnswer);
                        }
                    }
                }
            }
        }
コード例 #5
0
        //------------------------------------------
        #endregion

        #region --------------PopulateEntity--------------
        private VoteQuestionsEntity PopulateEntity(IDataReader reader)
        {
            //Create a new VoteQuestions object
            VoteQuestionsEntity voteQuestions = new VoteQuestionsEntity();

            //Fill the object with data
            //QuesID
            if (reader["QuesID"] != DBNull.Value)
            {
                voteQuestions.QuesID = (int)reader["QuesID"];
            }
            //QuestionText
            if (reader["QuestionText"] != DBNull.Value)
            {
                voteQuestions.QuestionText = (string)reader["QuestionText"];
            }
            //LangID
            if (reader["LangID"] != DBNull.Value)
            {
                voteQuestions.LangID = (Languages)reader["LangID"];
            }
            //CreatedOn
            if (reader["CreatedOn"] != DBNull.Value)
            {
                voteQuestions.CreatedOn = (DateTime)reader["CreatedOn"];
            }
            //IsClosed
            if (reader["IsClosed"] != DBNull.Value)
            {
                voteQuestions.IsClosed = (bool)reader["IsClosed"];
            }
            //AnswersCount
            if (reader["AnswersCount"] != DBNull.Value)
            {
                voteQuestions.AnswersCount = (int)reader["AnswersCount"];
            }
            //IsMain
            if (reader["IsMain"] != DBNull.Value)
            {
                voteQuestions.IsMain = (bool)reader["IsMain"];
            }
            //TotalHits
            if (reader["TotalHits"] != DBNull.Value)
            {
                voteQuestions.TotalHits = (int)reader["TotalHits"];
            }
            //Return the populated object
            return(voteQuestions);
        }
コード例 #6
0
        //------------------------------------------
        #endregion

        #region --------------Save--------------
        public bool Save(VoteQuestionsEntity voteQuestions, SPOperation operation)
        {
            using (SqlConnection myConnection = GetSqlConnection())
            {
                SqlCommand myCommand = new SqlCommand("VoteQuestions_Save", myConnection);
                myCommand.CommandType = CommandType.StoredProcedure;
                // Set the parameters
                myCommand.Parameters.Add("@SPOperation", SqlDbType.Int, 4).Value = (int)operation;
                if (operation == SPOperation.Insert)
                {
                    myCommand.Parameters.Add("@QuesID", SqlDbType.Int, 4).Direction = ParameterDirection.Output;
                }
                else
                {
                    myCommand.Parameters.Add("@QuesID", SqlDbType.Int, 4).Value = voteQuestions.QuesID;
                }

                myCommand.Parameters.Add("@QuestionText", SqlDbType.NVarChar, 128).Value = voteQuestions.QuestionText;
                myCommand.Parameters.Add("@LangID", SqlDbType.Int).Value          = (int)voteQuestions.LangID;
                myCommand.Parameters.Add("@AnswersCount", SqlDbType.Int, 4).Value = voteQuestions.AnswersCount;
                myCommand.Parameters.Add("@IsMain", SqlDbType.Bit, 1).Value       = voteQuestions.IsMain;
                myCommand.Parameters.Add("@IsClosed", SqlDbType.Bit, 1).Value     = voteQuestions.IsClosed;
                //----------------------------------------------------------------------------------------------
                //OwnerID
                myCommand.Parameters.Add("@OwnerID", SqlDbType.UniqueIdentifier).Value = SitesHandler.GetOwnerIDAsGuid();
                //----------------------------------------------------------------------------------------------
                // Execute the command
                bool status = false;
                myConnection.Open();
                if (myCommand.ExecuteNonQuery() > 0)
                {
                    status = true;
                    //Get ID value from database and set it in object
                    voteQuestions.QuesID = (int)myCommand.Parameters["@QuesID"].Value;
                }
                myConnection.Close();
                return(status);
            }
        }
コード例 #7
0
 public static bool Save(VoteQuestionsEntity voteQuestions, SPOperation operation)
 {
     return(VoteQuestionsSqlDataPrvider.Instance.Save(voteQuestions, operation));
 }