greenapple.Form1.loadRelations C# (CSharp) Метод

loadRelations() приватный Метод

private loadRelations ( ) : void
Результат void
        void loadRelations()
        {
            relations.Clear();
            switch (myproject.platform)
            {
                case ".NET":
                    if (myproject.language == "" || myproject.selectedProject == "" || myproject.type == "")
                    {
                        MessageBox.Show("For .NET,please select Type as well as langauge");
                    }
                    else
                    {
                    }
                    break;
                case "PHP":
                    break;
            }

            //counter to keep the names of the database tables
            int tableCounter = 0;
            //get all database table
            DataTable dat = new Connectoperations().showDatabaseTables();
            //loop for counter
            for (int y = 0; y < dat.Rows.Count; y++)
            {
                // create relation class
                ClassRelations cr = new ClassRelations();
                cr.belongsTo = new List<string>();
                cr.has = new List<string>();
                cr.name = dat.Rows[tableCounter][0].ToString();

                //loop through each table
                for (int i = 0; i < dat.Rows.Count; i++)
                {
                    //prevent double deal
                    if (dat.Rows[i][0].ToString() != cr.name)
                    {
                        //get attributes of the table
                        string tabname = dat.Rows[i][0].ToString();
                        DataTable tab = new Connectoperations().describeTable(tabname);

                        string hasrel = tabname + "_id";
                        string relationshipField = cr.name + "_id";

                        DataTable tabb = new Connectoperations().describeTable(cr.name);

                        //go throuh each table check if the current table has 'has' relations with others
                        foreach (DataRow drow in tab.Rows)
                        {
                          //field from other table
                            string comp = drow[0].ToString();
                            //adding has relationship
                            if (relationshipField == comp)
                            {
                                cr.has.Add(dat.Rows[i][0].ToString() + "#" + comp);
                            }

                        }//end for each

                        //belongs to
                        foreach (DataRow myrow in tabb.Rows)
                        {
                            string c = myrow[0].ToString();
                            //add belongs to
                            if (c == hasrel)
                            {
                                // if(cr.belongsTo.Contains(row[0].ToString().Split('_')[0] + "#" + hasrel )==false )
                                cr.belongsTo.Add(c.Split('_')[0] + "#" + hasrel);
                            }

                        }//end foreach

                    }//end double deal

                }//end for loop
                tableCounter++;
                //add list or relations
                relations.Add(cr);
            }//end counter for loop
        }