コード例 #1
0
        private void menu_TSQL_Click(object sender, EventArgs e)
        {
            //TODO - Add menu to connect remote

            Model.AddSingleProperty("SQL", "TSQL");

            //will attempt to connect to local machine,
            SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder("Data Source = (local); Integrated Security = True");
            TSQL TSQL = new TSQL(builder);

            //get list of databases
            List <object> databases = new List <object>(TSQL.GetDatabases());

            Model.AddMultiProperty("databases", databases);

            //Update form with new information
            Form f = new form_SelectDatabase(Model, this);

            f.Show();
        }
コード例 #2
0
        public void ContextUpdate()
        {
            //Attempt to connect to database
            if (Model.CheckSingleProperty("SQL"))
            {
                string db_type = "";
                Model.GetSingleProperty("SQL", out db_type);

                switch (db_type)
                {
                case "MySQL":
                    if (!Model.CheckSingleProperty("SelectedDatabase"))
                    {
                        try
                        {
                            MySQL mySql;
                            //Connect to SQL server
                            string server, username, password;
                            server   = Model.GetSingleProperty("server", out server);
                            username = Model.GetSingleProperty("username", out username);
                            password = Model.GetSingleProperty("password", out password);

                            mySql = new MySQL(server, username, password);

                            //get SQL tables information
                            List <object> databases = new List <object>(mySql.GetDatabases());

                            Model.AddMultiProperty("databases", databases);

                            //Update form with new information
                            Form f = new form_SelectDatabase(Model, this);
                            f.Show();
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                    }
                    else
                    {
                        try
                        {
                            MySQL mySql;
                            //Connect to SQL server
                            string server, username, password, database;
                            server   = Model.GetSingleProperty("server", out server);
                            username = Model.GetSingleProperty("username", out username);
                            password = Model.GetSingleProperty("password", out password);
                            database = Model.GetSingleProperty("SelectedDatabase", out database);

                            mySql = new MySQL(server, username, password, database);

                            //update database with database name
                            mySql.updateDatabase();

                            //get SQL information
                            List <object> storedProcedures = new List <object>(mySql.GetProcedures());
                            Model.AddMultiProperty("storedProcedures", storedProcedures);

                            List <object> functions = new List <object>(mySql.GetFunctions());
                            Model.AddMultiProperty("functions", functions);

                            List <object> views = new List <object>(mySql.GetViews());
                            Model.AddMultiProperty("views", views);

                            //Update Titles
                            string title;
                            Model.GetSingleProperty("SelectedDatabase", out title);
                            lbl_CurrentDB.Text = title;

                            //Update form with new information
                            Form f = new form_Root(Model);
                            f.TopLevel = false;
                            f.Parent   = tabRoot;
                            f.Show();
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                    }
                    break;

                case "TSQL":
                    if (Model.CheckSingleProperty("SelectedDatabase"))
                    {
                        //Connect to DB and get all data
                        SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder("Data Source = (local); Integrated Security = True");
                        TSQL TSQL = new TSQL(builder);

                        //Update Titles
                        string title;
                        Model.GetSingleProperty("SelectedDatabase", out title);
                        lbl_CurrentDB.Text = title;

                        TSQL.SetSchema(title);

                        List <object> storedProcedures = new List <object>(TSQL.GetProcedures());
                        Model.AddMultiProperty("storedProcedures", storedProcedures);

                        List <object> functions = new List <object>(TSQL.GetFunctions());
                        Model.AddMultiProperty("functions", functions);

                        List <object> views = new List <object>(TSQL.GetViews());
                        Model.AddMultiProperty("views", views);

                        //Update form with new information
                        Form f = new form_Root(Model);
                        f.TopLevel = false;
                        f.Parent   = tabRoot;
                        f.Show();
                    }
                    break;

                default:
                    break;
                }
            }
        }