public static int MaxScore(int SID) { var maxScore = 0; var dsQ = SurveyQuestion.GetAll(SID); foreach (DataRow qRow in dsQ.Tables[0].Rows) { var qType = Convert.ToInt32(qRow["QType"]); if (qType == 3) { return(0); // cannot score a test that has multiple choice } var isRequired = Convert.ToBoolean(qRow["IsRequired"]); if ((qType == 2 && !isRequired) || (qType == 4 && !isRequired)) { return(0); // cannot score a test that does not have all questions/answers required } var isCheckbox = Convert.ToInt32(qRow["DisplayControl"]) == 1; var QID = Convert.ToInt32(qRow["QID"]); var qScore = 0; if (qType == 2 || qType == 4) { var dsA = SQChoices.GetAll(QID); var maxAScore = 0; foreach (DataRow aRow in dsA.Tables[0].Rows) { var score = Convert.ToInt32(aRow["Score"]); if (isCheckbox) { qScore += score; } else { if (score > maxAScore) { maxAScore = score; } } } if (!isCheckbox) { qScore += maxAScore; } } if (qType == 4) { //Matrix, how many lines? var dsML = SQMatrixLines.GetAll(QID); var numLines = dsML.Tables[0].Rows.Count; qScore = qScore * numLines; } maxScore += qScore; } return(maxScore); }
public static bool IsScorable(int SID) { var dsQ = SurveyQuestion.GetAll(SID); foreach (DataRow qRow in dsQ.Tables[0].Rows) { var qType = Convert.ToInt32(qRow["QType"]); if (qType == 3) { return(false); // cannot score a test that has multiple choice } var isRequired = Convert.ToBoolean(qRow["IsRequired"]); if ((qType == 2 && !isRequired) || (qType == 4 && !isRequired)) { return(false); // cannot score a test that does not have all questions/answers required } } return(true); }