Пример #1
0
        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
        }
Пример #2
0
        private void toolStripMenuItemconnect_Click(object sender, EventArgs e)
        {
            if (labelselectedproj.Text != "")
            {
                greenapple.Properties.Settings.Default.server = toolStripTextBoxserver.Text;
                greenapple.Properties.Settings.Default.database = toolStripTextBoxdatabase.Text;
                greenapple.Properties.Settings.Default.user = toolStripTextBoxuser.Text;
                greenapple.Properties.Settings.Default.password = toolStripTextBoxpassword.Text;
                greenapple.Properties.Settings.Default.Save();

                //get the names of all the tables of the database into a Datatable
                DataTable dat = new Connectoperations().showDatabaseTables();
                //a loop to put items in the table into the listview
                int i = 1;
                listView1.Items.Clear();
                foreach (DataRow row in dat.Rows)
                {
                    //an instance of a lisviewitem
                    ListViewItem lv = new ListViewItem((i++).ToString());
                    lv.SubItems.Add(row[0].ToString());
                    //add the lisviewitem to listview1
                    listView1.Items.Add(lv);
                    //table controls

                }
                loadRelations();
            }
            else
            {
                MessageBox.Show("Select a Project");
            }
            string path = "";
            path = Directory.GetCurrentDirectory() + "\\" + myproject.selectedProject + "\\" + myproject.selectedProject + "\\controls.xml";

            DataSet ds = new DataSet();
            try
            {
                tableControls.Clear();
                ds.ReadXml(path);

                foreach (DataTable tab in ds.Tables)
                {
                    ClassTableControls ctc = new ClassTableControls();
                    ctc.controls = new List<string>();

                    foreach (DataRow row in tab.Rows)
                    {
                        string controlName = row[0].ToString();
                        ctc.controls.Add(controlName);
                        ctc.tablename = tab.TableName;

                    }
                    tableControls.Add(ctc);

                }

            }
            catch
            {

            }
        }
Пример #3
0
        private void listView1_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
        {
            //tablename
            string tableName = e.Item.SubItems[1].Text;
            //get a the names of the attributes of the selected table in listview1 into a table
            DataTable dat = new Connectoperations().describeTable(tableName);
            //a loop to attributes in the table into the listview
            dataGridView1.Rows.Clear();

            int i = 0;
            foreach (DataRow row in dat.Rows)
            {

                dataGridView1.Rows.Add(row[0]);
                for (int j = 0; j < 6; j++)
                {
                    dataGridView1[j, i].Value = row[j].ToString();
                }

                if (tableControls.Count < 1)
                {
                    //setting the default of the suggested control to textbox
                    dataGridView1[6, i].Value = "TextBox";
                }
                else
                {
                    dataGridView1[6, i].Value = "TextBox";
                    //load control settings stored earlier

                    for (int a = 0; a < tableControls.Count; a++)
                    {
                        //the table names match
                        if (tableControls[a].tablename == tableName)
                        {
                            //load appropriate controlGUYYYYYYYYYYYYYYYYYYYYYY
                            try
                            {
                                dataGridView1[6, i].Value = tableControls[a].controls[i];
                            }
                            catch
                            {

                            }
                        }
                    }
                }
                i++;

            }
            listView1.Items[seleteclistviewindex].BackColor = Color.White;
            seleteclistviewindex = e.ItemIndex;
            listView1.Items[seleteclistviewindex].BackColor = Color.Orange;
            myproject.selectedTable = e.Item.SubItems[1].Text;

            //load relations
            for (int y = 0; y < relations.Count; y++)
            {
                if (relations[y].name == tableName)
                {
                    int counter = 1;
                    //load has many
                    listView3.Items.Clear();
                    for (int x = 0; x < relations[y].has.Count; x++)
                    {
                        ListViewItem lvi = new ListViewItem(counter.ToString());
                        lvi.SubItems.Add(relations[y].has[x]);
                        listView3.Items.Add(lvi);
                        counter++;
                    }
                    //load belong to
                    listView4.Items.Clear();
                    counter = 1;
                    for (int x = 0; x < relations[y].belongsTo.Count; x++)
                    {
                        ListViewItem lvi = new ListViewItem(counter.ToString());
                        lvi.SubItems.Add(relations[y].belongsTo[x]);
                        listView4.Items.Add(lvi);
                        counter++;
                    }
                }
            }
        }