Beispiel #1
0
        public static Database Clone(Database oldDatabase)
        {
            Database db = new Database();

            db.SetName(oldDatabase.GetName());
            db.tables = new List <Table>();
            for (int i = 0; i < oldDatabase.tables.Count; i++)
            {
                Table tab = new Table();
                tab.SetId(oldDatabase.tables[i].GetId());
                tab.SetName(oldDatabase.tables[i].GetName());
                tab.columns = new List <Column>();
                for (int j = 0; j < oldDatabase.tables[i].columns.Count; j++)
                {
                    Column col = new Column();
                    col.SetId(oldDatabase.tables[i].columns[j].GetId());
                    col.SetName(oldDatabase.tables[i].columns[j].GetName());
                    col.SetColor(oldDatabase.tables[i].columns[j].GetColor());
                    col.SetType(oldDatabase.tables[i].columns[j].GetType());
                    col.fields = new List <string>();
                    for (int k = 0; k < oldDatabase.tables[i].columns[j].fields.Count; k++)
                    {
                        col.AddField(oldDatabase.tables[i].columns[j].fields[k]);
                    }
                    tab.AddColumn(col);
                }
                db.AddTable(tab);
            }
            return(db);
        }
Beispiel #2
0
        public SelectTable(string data, string id, string name)
        {
            Dictionary <string, string> dic = new Dictionary <string, string>(); // Color matching

            table = new Table();
            table.SetId(id);
            table.SetName(name);
            table.columns = new List <Column>();
            // Loops through all the columns for this table.
            int columnCounter = 0;

            while (true)
            {
                columnCounter++;
                Column col = new Column();
                col.SetName(data.Substring(0, data.IndexOf(":")));
                col.SetId("T:" + name + "-C:" + columnCounter);
                // If column exists elsewhere, use same color.
                if (dic.ContainsKey(col.GetName()))
                {
                    col.SetColor(dic[col.GetName()]);
                }
                else
                {
                    string c = DatabaseBuilder.GetRandomColor();
                    dic.Add(col.GetName(), c);
                    col.SetColor(c);
                }
                col.fields = new List <string>();
                data       = data.Substring(data.IndexOf("[") + 1);

                // Loops through all the fields for this column.
                do
                {
                    if (data.IndexOf(",") != -1 && data.IndexOf(",") < data.IndexOf("]"))
                    {
                        col.AddField(data.Substring(0, data.IndexOf(",")));
                        data = data.Substring(data.IndexOf(",") + 1); // There's a 'next' field
                    }
                    else
                    {
                        col.AddField(data.Substring(0, data.IndexOf("]")));
                        data = data.Substring(data.IndexOf("]") + 1);
                        break;
                    }
                } while (true);
                table.AddColumn(col);
                if (data.Substring(0, 1).Equals(","))
                {
                    data = data.Substring(1); // There's a 'next' column
                }
                else
                {
                    data = data.Substring(1);
                    break;
                }
            }
        }
Beispiel #3
0
        // Get Analytic 2 database (datatype proportions)
        public static Database GetDataTypeDB()
        {
            Database db = new Database();

            db.SetName("Analytic_2");
            db.tables = new List <Table>();
            Table tab = new Table();

            tab.SetId("A-2");
            tab.SetName("DataTypes in Proportion");
            tab.columns = new List <Column>();


            for (int i = 0; i < VedicDatabase.db.tables.Count; i++)
            {
                for (int j = 0; j < VedicDatabase.db.tables[i].columns.Count; j++)
                {
                    if (dataTypeDic.ContainsKey(VedicDatabase.db.tables[i].columns[j].GetType()))
                    {
                        dataTypeDic[VedicDatabase.db.tables[i].columns[j].GetType()]++;
                    }
                    else
                    {
                        dataTypeDic.Add(VedicDatabase.db.tables[i].columns[j].GetType(), 1);
                    }
                }
            }

            Dictionary <string, int> .KeyCollection keyColl = dataTypeDic.Keys;

            int total = 0;

            foreach (string s in keyColl)
            {
                total += dataTypeDic[s];
            }

            foreach (string s in keyColl)
            {
                Column col = new Column();
                col.SetName(s);
                col.SetId(s + "-2");
                col.SetColor(VariableColorTable.GetVariableColor(s));
                col.SetType(s);
                col.fields = new List <string>();
                col.fields.Add(((double)dataTypeDic[s] / (double)total).ToString());
                tab.columns.Add(col);
            }
            db.tables.Add(tab);
            return(db);
        }
Beispiel #4
0
        public static Database ConstructDB(string name, string data)
        {
            Dictionary <string, string> dic = new Dictionary <string, string>(); // Color matching
            Database db = new Database();

            db.SetName(name);
            db.tables = new List <Table>();
            data      = data.Substring(10);
            int tableCounter  = -1;
            int columnCounter = -1;

            // Loops through all the tables for this database.
            while (true)
            {
                tableCounter++;
                columnCounter = -1;
                Table tb = new Table();
                tb.SetName(data.Substring(0, data.IndexOf(":")));
                tb.SetId("T" + tableCounter);
                tb.columns = new List <Column>();
                data       = data.Substring(data.IndexOf("{") + 1);

                // Loops through all the columns for this table.
                while (true)
                {
                    columnCounter++;
                    Column col = new Column();
                    col.SetName(data.Substring(0, data.IndexOf(":")));
                    col.SetId("T" + tableCounter + "-C" + columnCounter);
                    // If column exists elsewhere, use same color.
                    if (dic.ContainsKey(tb.GetName()))
                    {
                        col.SetColor(dic[tb.GetName()]);
                    }
                    else
                    {
                        string c = GetRandomColor();
                        dic.Add(tb.GetName(), c);
                        col.SetColor(c);
                    }
                    col.fields = new List <string>();
                    data       = data.Substring(data.IndexOf("[") + 1);

                    // Loops through all the fields for this column.
                    do
                    {
                        if (data.IndexOf(",") != -1 && data.IndexOf(",") < data.IndexOf("]"))
                        {
                            col.AddField(data.Substring(0, data.IndexOf(",")));
                            data = data.Substring(data.IndexOf(",") + 1); // There's a 'next' field
                        }
                        else
                        {
                            col.AddField(data.Substring(0, data.IndexOf("]")));
                            data = data.Substring(data.IndexOf("]") + 1);
                            break;
                        }
                    } while (true);
                    tb.AddColumn(col);
                    if (data.Substring(0, 1).Equals(","))
                    {
                        data = data.Substring(1); // There's a 'next' column
                    }
                    else
                    {
                        data = data.Substring(1);
                        break;
                    }
                }
                db.AddTable(tb);
                if (data.Substring(0, 1).Equals(","))
                {
                    data = data.Substring(1); // There's a 'next' table
                }
                else
                {
                    break;
                }
            }
            return(db);
        }