Exemplo n.º 1
0
        private int GetSplitCount(ChoicesLayoutVM choicesLayout)
        {
            int count = 1;

            if (choicesLayout.ColumnCount != null && choicesLayout.ColumnCount.HasValue)
            {
                count = choicesLayout.ColumnCount.Value;
            }
            return(count);
        }
Exemplo n.º 2
0
        private void WriteChoicesResponse(Body body, QuestionVM question)
        {
            ResponseVM      response      = question.Response;
            ChoicesLayoutVM choicesLayout = (ChoicesLayoutVM)response.Layout;
            List <CodeVM>   validCodes    = GetValidCodes(response.Codes);

            if (choicesLayout.MeasurementMethod == ChoicesLayoutMesurementMethod.Single ||
                choicesLayout.MeasurementMethod == ChoicesLayoutMesurementMethod.Multiple)
            {
                //If Measurement is Single answer or Multiple answer
                Table table = CreateFilledTable(choicesLayout.Surround, false);
                List <List <CodeVM> > codesList = SplitCodes(validCodes, choicesLayout);

                //In the case of vertical(splitCount=number of columns)
                TableRow tableRow = new TableRow();
                table.Append(tableRow);
                int firstCodesCount = codesList[0].Count; //add the empty paragraph in the last column in order to match the paragraph number in the cell(or show the layout frame)
                foreach (List <CodeVM> codes in codesList)
                {
                    TableCell cell = CreateChoicesCell(codes, firstCodesCount);
                    tableRow.Append(cell);
                }
                body.Append(table);
            }
            else
            {
                //Meaning differentiation
                Table table = CreateFilledTable(true, true);

                TableRow tableRow1 = new TableRow();
                TableRow tableRow2 = new TableRow();
                table.Append(tableRow1);
                table.Append(tableRow2);
                foreach (CodeVM code in validCodes)
                {
                    tableRow1.Append(CreateCenterCell(code.Value));
                    tableRow2.Append(CreateCenterCell(code.Label));
                }

                body.Append(table);
            }
        }
Exemplo n.º 3
0
        private List <List <CodeVM> > SplitCodes(List <CodeVM> validCodes, ChoicesLayoutVM choicesLayout)
        {
            List <List <CodeVM> > codesList = new List <List <CodeVM> >();

            int count        = GetSplitCount(choicesLayout);
            int countPerArea = DivideCeil(validCodes.Count, count);

            if (choicesLayout.Direction == ChoicesLayoutDirection.Vertical)
            {
                List <CodeVM> codesPerArea = null;
                int           i            = 0;
                foreach (CodeVM code in validCodes)
                {
                    if (i % countPerArea == 0)
                    {
                        codesPerArea = new List <CodeVM>();
                        codesList.Add(codesPerArea);
                    }
                    codesPerArea.Add(code);
                    i++;
                }
            }
            else
            {
                int areaCount = DivideCeil(validCodes.Count, countPerArea); //This will be the number of cells.
                for (int j = 0; j < areaCount; j++)
                {
                    codesList.Add(new List <CodeVM>());
                }
                int i = 0; //Fill columns while replacing in order
                foreach (CodeVM code in validCodes)
                {
                    int codesIndex = i % areaCount;
                    codesList[codesIndex].Add(code);
                    i++;
                }
            }
            return(codesList);
        }