예제 #1
0
        private void CreateVariableFor(QuestionVM question, int questionIndex)
        {
            VariableGenerationInfo oldInfo = question.VariableGenerationInfo;
            VariableGenerationInfo newInfo = question.CreateVariableGenerationInfo();

            if (oldInfo != null && oldInfo.VariableGenerationType == newInfo.VariableGenerationType)
            {
                return;
            }
            question.VariableGenerationInfo = newInfo;

            // remove old variables
            List <VariableVM> generatedVariables = VariableVM.FindByQuestionId(Variables, question.Id);

            Debug.WriteLine(generatedVariables.Count);
            int removeIndex = Variables.Count;

            foreach (VariableVM variable in generatedVariables)
            {
                if (removeIndex == Variables.Count)
                {
                    removeIndex = Variables.IndexOf(variable);
                }
                StudyUnit.OnRemoveVariable(variable);
                Variables.Remove(variable);
            }

            // create single or multiple variables
            if (newInfo.VariableGenerationType == VariableGenerationType.SingleVariable)
            {
                CreateVariable((variableMovel) => {
                    variableMovel.Title = "V" + (questionIndex + 1);
                }, question, removeIndex);
            }
            else
            {
                CodeSchemeVM         codeScheme = question.Response.CodeScheme;
                ICollection <CodeVM> codes      = codeScheme.Codes;
                string variablePrefix           = "V" + (questionIndex + 1) + "_";
                foreach (CodeVM code in codes)
                {
                    CreateVariable((variableModel) => {
                        variableModel.Title                 = variablePrefix + code.Value;
                        variableModel.Label                 = code.Label;
                        variableModel.Response              = question.DupResponseModel();
                        variableModel.Response.TypeCode     = Options.RESPONSE_TYPE_CHOICES_CODE;
                        variableModel.Response.CodeSchemeId = StudyUnit.BinaryCodeSchemeId;
                    }, question, removeIndex++);
                }
            }
        }
예제 #2
0
 public void RemoveVariable()
 {
     StudyUnit.OnRemoveVariable(SelectedVariable);
     Variables.Remove(SelectedVariable);
     SelectedVariableItem = null;
 }