Ejemplo n.º 1
0
        private FileDBTable loadTable(String tableName)
        {
            if (File.Exists(dbPath + @"\" + tableName + tbExtention))
            {
                String[] tableLines = File.ReadAllLines(dbPath + @"\" + tableName + tbExtention);
                FileDBTable table = new FileDBTable(this, tableName);

                // Split column types into array and column names into array.
                String[] types = tableLines[2].Split(',');
                String[] names = tableLines[3].Split(',');

                // Add columns to table.
                for (int i = 0; i < names.Length; i++)
                {
                    table.addColumn(names[i], Type.GetType(types[i]));
                }

                // Add rows to table.
                for (int i = 4; i < tableLines.Length; i++)
                {
                    String[] rowIDData = tableLines[i].Split(',');
                    int rowID = Convert.ToInt32(rowIDData[0]);
                    String[] rowData = new String[rowIDData.Length-1];
                    Array.Copy(rowIDData, rowData, rowData.Length);
                    table.addRow(rowID, rowData);
                }

                // Return the table.
                return table;
            }
            else
            {
                // If table file not found.
                throw new FileNotFoundException("Table '" + tableName + "' not found!");
            }
        }