Exemple #1
0
 public bool SetProperties(int FileId, CSVQuestion temp)
 {
     try
     {
         this.FileId     = FileId;
         this.Technology = temp[0];
         int value = 0;
         int.TryParse(temp[1], out value);
         if (value < 1 || value > 3)
         {
             return(false);
         }
         this.Level          = value;
         this.QuestionString = temp[2];
         this.Option1        = temp[3];
         this.Option2        = temp[4];
         this.Option3        = temp[5];
         this.Option4        = temp[6];
         value = 0;
         int.TryParse(temp[7], out value);
         if (value < 1 || value > 4)
         {
             return(false);
         }
         this.CorrectOption = value;
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemple #2
0
        public bool ReadRow(CSVQuestion row)
        {
            row.LineText = ReadLine();
            if (String.IsNullOrEmpty(row.LineText))
            {
                return(false);
            }
            int pos  = 0;
            int rows = 0;

            while (pos < row.LineText.Length)
            {
                string value;
                // Special handling for quoted field
                if (row.LineText[pos] == '"')
                {
                    // Skip initial quote
                    pos++;
                    // Parse quoted value
                    int start = pos;
                    while (pos < row.LineText.Length)
                    {
                        // Test for quote character
                        if (row.LineText[pos] == '"')
                        {
                            // Found one
                            pos++;
                            // If two quotes together, keep one
                            // Otherwise, indicates end of value
                            if (pos >= row.LineText.Length || row.LineText[pos] != '"')
                            {
                                pos--;
                                break;
                            }
                        }
                        pos++;
                    }
                    value = row.LineText.Substring(start, pos - start);
                    value = value.Replace("\"\"", "\"");
                }
                else
                {
                    // Parse unquoted value
                    int start = pos;
                    while (pos < row.LineText.Length && row.LineText[pos] != ',')
                    {
                        pos++;
                    }
                    value = row.LineText.Substring(start, pos - start);
                }
                // Add field to list
                if (rows < row.Count)
                {
                    row[rows] = value;
                }
                else
                {
                    row.Add(value);
                }
                rows++;
                // Eat up to and including next comma
                while (pos < row.LineText.Length && row.LineText[pos] != ',')
                {
                    pos++;
                }
                if (pos < row.LineText.Length)
                {
                    pos++;
                }
            }
            // Delete any unused items
            while (row.Count > rows)
            {
                row.RemoveAt(rows);
            }
            // Return true if any columns read
            return(row.Count > 0);
        }