示例#1
0
 private void Clear()
 {
     codeScheme = null;
     Min        = null;
     Max        = null;
     DetailTypes.Clear();
 }
示例#2
0
        public ResponseVM SelectAndCreateResponse(ResponseVM sourceResponse)
        {
            ResponseVM newResponse = null;

            if (sourceResponse.IsTypeChoices)
            {
                StudyUnit.CompleteResponse(sourceResponse);
                CodeSchemeVM sourceCodeScheme = sourceResponse.CodeScheme;

                ObservableCollection <CodeSchemeVM> codeSchemes = new ObservableCollection <CodeSchemeVM>(StudyUnit.CodeSchemes);

                SelectObjectWindowVM <CodeSchemeVM> vm = new SelectObjectWindowVM <CodeSchemeVM>(codeSchemes);
                CodeSchemeVM codeScheme = SelectObjectWindow.Select(Resources.SelectResponse, vm) as CodeSchemeVM; //Select Response Style
                if (codeScheme != null && sourceCodeScheme != codeScheme)
                {
                    Response responseModel = new Response();
                    responseModel.TypeCode = Options.RESPONSE_TYPE_CHOICES_CODE;
                    responseModel.Title    = codeScheme.Title;
                    newResponse            = new ResponseVM(responseModel, codeScheme);
                }
            }
            else
            {
                ObservableCollection <ResponseVM> responses = GetCandidateResponses();
                SelectObjectWindowVM <ResponseVM> vm        = new SelectObjectWindowVM <ResponseVM>(responses);
                ResponseVM selectedResponse = SelectObjectWindow.Select(Resources.SelectResponse, vm) as ResponseVM;
                if (selectedResponse != null && sourceResponse != selectedResponse)
                {
                    newResponse = selectedResponse.Dup();
                }
            }
            return(newResponse);
        }
示例#3
0
        public List <ResponseVM> FindResponses(CodeSchemeVM codeScheme)
        {
            List <ResponseVM> questionResponses = questionForm.FindResponses(codeScheme);
            List <ResponseVM> variableResponses = variableForm.FindResponses(codeScheme);
            List <ResponseVM> allResponses      = new List <ResponseVM>();

            allResponses.AddRange(questionResponses);
            allResponses.AddRange(variableResponses);
            return(allResponses);
        }
示例#4
0
 public ResponseVM(Response response, CodeSchemeVM codeScheme)
 {
     this.response             = response;
     this.isQuestionDesignMode = true;
     if (codeScheme == null)
     {
         codeScheme = new CodeSchemeVM();
         codeScheme.OwnerResponse = this;
     }
     books = new ObservableCollection <BookVM>();
     Init(response.DetailTypeCode, response.Min, response.Max, codeScheme, new List <MissingValue>(response.MissingValues), response.Layout);
 }
示例#5
0
        public ResponseVM CreateResponse(Response responseModel)
        {
            CodeSchemeVM codeScheme = null;

            if (responseModel.IsTypeChoices)
            {
                codeScheme = StudyUnit.FindCodeScheme(responseModel);
            }
            ResponseVM response = new ResponseVM(responseModel, codeScheme);

            return(response);
        }
示例#6
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++);
                }
            }
        }
示例#7
0
        public List <ResponseVM> FindResponses(CodeSchemeVM codeScheme)
        {
            List <ResponseVM> responses = new List <ResponseVM>();

            foreach (VariableVM variable in Variables)
            {
                ResponseVM response = variable.Response;
                if (response.IsTypeChoices && response.CodeScheme == codeScheme)
                {
                    responses.Add(response);
                }
            }
            return(responses);
        }
示例#8
0
        public void RemoveCodeSchemeFromResponse(CodeSchemeVM codeScheme)
        {
            //Code scheme may be referenced by more than one answer
            //and it may be referenced by both Question and Vareable,
            //so it is one-to-many relationship.
            List <ResponseVM> responses = FindResponses(codeScheme);

            foreach (ResponseVM response in responses)
            {
                //if you leave Response Style to branch, Unnamed Category Scheme would be created by such as CompleteVariable
                //Return Response Style to Unknown
                response.TypeCode = Options.RESPONSE_TYPE_UNKNOWN.Code;
            }
        }
示例#9
0
        public List <ResponseVM> FindResponses(CodeSchemeVM codeScheme)
        {
            List <ResponseVM> responses    = new List <ResponseVM>();
            List <ResponseVM> allResponses = AllResponses;

            foreach (ResponseVM response in allResponses)
            {
                if (response.CodeScheme == codeScheme)
                {
                    responses.Add(response);
                }
            }
            return(responses);
        }
示例#10
0
        public void CompleteResponse(ResponseVM response)
        {
            if (!response.IsTypeChoices)
            {
                return;
            }

            CodeSchemeVM codeScheme = response.CodeScheme;

            if (!codeForm.CodeSchemes.Contains(codeScheme))
            {
                //If newly added in the question window
                //Set the title(if the code is not added and the title of response is blank, "Untitled" or "Unnamed" title will be set by adding null
                codeScheme.Title = string.IsNullOrEmpty(response.Title) ? CodeVM.JoinLabels(codeScheme.Codes) : response.Title;
                //Add CodeScheme
                codeForm.CodeSchemes.Add(codeScheme);
            }

            List <CodeVM> orphanCodes = new List <CodeVM>();

            foreach (CodeVM code in codeScheme.Codes)
            {
                if (!categoryForm.Contains(code.CategoryId))
                {
                    //remember the code isolated if the category scheme corresponding to the question does not exist
                    orphanCodes.Add(code);
                }
            }

            if (orphanCodes.Count > 0)
            {
                //isolated code(Category is not included in the existent category set)
                //Create Category scheme and then add Category in it
                CategorySchemeVM categoryScheme = categoryForm.FindCategorySchemeByResponseId(response.Id);
                if (categoryScheme == null)
                {
                    categoryScheme            = new CategorySchemeVM();
                    categoryScheme.ResponseId = response.Id;
                    categoryScheme.Title      = string.IsNullOrEmpty(response.Title) ? CodeVM.JoinLabels(orphanCodes) : response.Title; //Create from isolated code
                    categoryForm.CategorySchemes.Add(categoryScheme);
                }
                //Add Category here(since categories are not added automatically, while the code is added automatically)
                foreach (CodeVM code in orphanCodes)
                {
                    //Add CategoryVM included in CodeVM to CategoryScheme
                    categoryScheme.Categories.Add(code.Category);
                }
            }
        }
示例#11
0
        private void Init(string detailTypeCode, decimal?min, decimal?max, CodeSchemeVM codeScheme, List <MissingValue> missingValueModels, ResponseLayout layoutModel)
        {
            DetailTypeCode = detailTypeCode;
            Min            = min;
            Max            = max;
            CodeScheme     = codeScheme;

            DetailTypes = new ObservableCollection <Option>();
            if (response.IsTypeChoices)
            {
            }
            else if (response.IsTypeDateTime)
            {
                DetailTypes = Options.DateTimeTypes;
            }
            else if (response.IsTypeFree)
            {
            }
            else if (response.IsTypeNumber)
            {
                DetailTypes = Options.NumberTypes;
            }

            missingValues = new ObservableCollection <MissingValueVM>();
            foreach (MissingValue mv in missingValueModels)
            {
                MissingValueVM missingValue = new MissingValueVM(mv)
                {
                    Parent = this
                };
                missingValues.Add(missingValue);
            }
            modelSyncher = new ModelSyncher <MissingValueVM, MissingValue>(this, missingValues, response.MissingValues);


            ResponseLayout newLayoutModel = layoutModel;

            layout          = CreateLayout(response, layoutModel);
            response.Layout = layout.Layout;
        }
示例#12
0
 public bool IsBinaryCodeScheme(CodeSchemeVM codeScheme)
 {
     return(studyUnit.BinaryCodeSchemeId == codeScheme.Id);
 }