예제 #1
0
        private void InsertFactorsResultIntoDbAndFactorScoreList(int factorId, string factoreScoreInString)
        {
            int factorScore;
            var parseToInt = Int32.TryParse(factoreScoreInString, out factorScore);

            if (parseToInt)
            {
                try
                {
                    var factorName = GetFactorNameById(factorId);
                    FactorAnalize.SetFactorAndFactorScore(new Factor {
                        Name = factorName
                    }, factorScore);
                    if (Options.HaveFactorsHistory)
                    {
                        InsertFactorInDb(factorId, factorScore);
                    }
                    else
                    {
                        if (_maxInterviewNum > 0)
                        {
                            var query = "select FactorResults.id " +
                                        "from main.FactorResults," +
                                        "main.Factors " +
                                        "where FactorResults.interview_number = " + _maxInterviewNum +
                                        " and FactorResults.respondent_id = " + _respondentId +
                                        " and Factors.theme_id = " + _themeId +
                                        " and FactorResults.factor_id = " + factorId +
                                        " and FactorResults.factor_id = Factors.id";
                            var factorResultId = DbConnection.SelectScalarFromDb(query);
                            if (factorResultId.ToString() == "")
                            {
                                throw new Exception("Factor was not found!");
                            }
                            query = "update main.FactorResults " +
                                    "set answer_date = current_date " +
                                    ", score = " + factorScore +
                                    ", interview_number = " + (_maxInterviewNum + 1) +
                                    " where FactorResults.id = " + Convert.ToInt32(factorResultId);
                            DbConnection.DmlOperation(query);
                        }
                        else
                        {
                            InsertFactorInDb(factorId, factorScore);
                        }
                    }
                }
                catch (Exception exp)
                {
                    throw new Exception("InsertFactorsResultIntoDbAndFactorScoreList: " + exp);
                }
            }
        }
예제 #2
0
 private DataTable TryGetScoreOfFactors(DataTable table, string factorRowName)
 {
     if (table.Columns.Contains(factorRowName))
     {
         var modifiedFactorDataTable = table;
         for (int i = 0; i < table.Rows.Count; i++)
         {
             var factorId = table.Rows[i][factorRowName];
             if (factorId.ToString() != "")
             {
                 var factorName = GetFactorNameById(Convert.ToInt32(factorId));
                 modifiedFactorDataTable.Rows[i][factorRowName] =
                     FactorAnalize.GetFactorScoreByFactorName(factorName);
             }
         }
         return(modifiedFactorDataTable);
     }
     throw new Exception("TryGetScoreOfFactors: Can't find need row!");
 }