Exemple #1
0
        private void ImportDatabaseObjects(dataset data)
        {
            //if (append == false)
            //    P = L;

            //ShowInfoPanel(true);

            //MessageBox.Show("objects - " + L.Count);

            g.Nodes.Clear();

            datasets = new DataSet();

            foreach (DataTable row in data.ns)
            {
                TreeNode ng = new TreeNode(row.TableName);
                g.Nodes.Add(ng);
                //foreach (DataColumn cs in row.Table.Columns)
                {
                    DataTable b = row;// DataSourceWizard.GetTableSchema(data.connection, row[2].ToString());

                    datasets.Tables.Add(b);

                    foreach (DataColumn r in b.Columns)
                    {
                        string   cs    = r.ColumnName;
                        TreeNode nodes = new TreeNode(cs.ToString());
                        ng.Nodes.Add(nodes);
                    }
                }
            }
            string bb = AppDomain.CurrentDomain.BaseDirectory;

            vp = ExplorerForms.ef.GetVSProject();

            string s = vp.GetProjectFolder();

            string d = s + "\\" + data.name + ".xsd";

            datasets.WriteXmlSchema(d);

            ExplorerForms.ef.Command_TakeTypedDataset(d);

            vp.AddXSDItem(data.name);
        }
Exemple #2
0
        public static void LoadFromConnection(TreeNode db, DataConnection dc)
        {
            dataset data = new dataset();

            string c = dc.connectionString;

            string provider = dc.GetConnectionStringProvider();

            c = dc.GetConnectionStringr();

            if (provider == "Oracle")
            {
                LoadfromOracleConnection(db, c);
            }
            else
            {
                LoadFromSQLServerConnection(db, dc);
            }
        }
Exemple #3
0
        public static void LoadFromSQLServerConnection(TreeNode db, DataConnection dc)
        {
            dataset data = new dataset();

            string c = dc.connectionString;

            string[] cc = c.Split(";".ToCharArray());

            SqlConnection conn = new SqlConnection();

            // conn.ConnectionString =
            // "Data Source=localhost;" +
            //// "Initial Catalog=DataBaseName;" +
            ////"Integrated Security=SSPI; +
            // "User id=sa;" +
            // "Password=sa;";
            conn.ConnectionString = dc.GetConnectionStringr();
            try
            {
                //conn.Open();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Connection failed " + ex.Message);
                return;
            }

            data.connection = conn;

            List <DataRow> tables = GetTablesSchema(conn, "Tables");

            db.Nodes.Clear();
            TreeNode node = new TreeNode("Tables");

            db.Nodes.Add(node);
            foreach (DataRow row in tables)
            {
                string   name  = row[2].ToString();
                TreeNode nodes = new TreeNode(name);

                DataTable b = PullData(conn, name);// GetTableSchema(conn, name);

                foreach (DataColumn r in b.Columns)
                {
                    string cs = r.ColumnName;

                    TreeNode ng = new TreeNode(cs.ToString());
                    nodes.Nodes.Add(ng);
                }
                nodes.Tag           = b;
                nodes.StateImageKey = "data";
                node.Nodes.Add(nodes);
            }

            tables = GetTablesSchema(conn, "Views");
            node   = new TreeNode("Views");
            db.Nodes.Add(node);
            foreach (DataRow row in tables)
            {
                string   name  = row[2].ToString();
                TreeNode nodes = new TreeNode(name);

                DataTable b = PullData(conn, name);// GetTableSchema(conn, name);

                foreach (DataColumn r in b.Columns)
                {
                    string cs = r.ColumnName;

                    TreeNode ng = new TreeNode(cs.ToString());
                    nodes.Nodes.Add(ng);
                }
                nodes.Tag           = b;
                nodes.StateImageKey = "data";
                node.Nodes.Add(nodes);
            }

            //tables = GetTables(conn, "Procedures");
            //node = new TreeNode("Procedures");
            //db.Nodes.Add(node);
            //foreach (string s in tables)
            //{
            //    TreeNode nodes = new TreeNode(s);
            //    node.Nodes.Add(nodes);
            //}

            //tables = GetTables(conn, "UserDefinedTypes");
            //node = new TreeNode("UserDefinedTypes");
            //db.Nodes.Add(node);
            //foreach (string s in tables)
            //{
            //    TreeNode nodes = new TreeNode(s);
            //    node.Nodes.Add(nodes);
            //}
        }
Exemple #4
0
        public void LoadFromConnection()
        {
            data = new dataset();

            string c = cbcs.Text;

            string[] dd = c.Split("-".ToCharArray());

            string provider = dd[0].Trim();

            c = dd[1].Trim();

            string[] cc = c.Split(";".ToCharArray());

            textBox1.Text = cc[cc.Length - 2].Replace("Initial Catalog=", "");

            data.name = textBox1.Text;

            if (provider.ToLower() == "oracle")
            {
                DataConnection d = new DataConnection();
                d.Load(c);
                if (d.dict.ContainsKey("Data Source"))
                {
                    data.name = d.dict["Data Source"];
                }
                data.connectionString = c;
                LoadfromOracleConnection(db, c);
                return;
            }

            SqlConnection conn = new SqlConnection();

            // conn.ConnectionString =
            // "Data Source=localhost;" +
            //// "Initial Catalog=DataBaseName;" +
            ////"Integrated Security=SSPI; +
            // "User id=sa;" +
            // "Password=sa;";
            conn.ConnectionString = c;
            try
            {
                //conn.Open();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Connection failed " + ex.Message);
                return;
            }

            data.connection = conn;

            List <DataRow> tables = GetTablesSchema(conn, "Tables");

            db.Nodes.Clear();
            TreeNode node = new TreeNode("Tables");

            db.Nodes.Add(node);
            foreach (DataRow row in tables)
            {
                string   name  = row[2].ToString();
                TreeNode nodes = new TreeNode(name);

                DataTable b = PullData(conn, name);// GetTableSchema(conn, name);

                foreach (DataColumn r in b.Columns)
                {
                    string cs = r.ColumnName;

                    TreeNode ng = new TreeNode(cs.ToString());
                    nodes.Nodes.Add(ng);
                }
                nodes.Tag           = b;
                nodes.StateImageKey = "data";
                node.Nodes.Add(nodes);
            }

            tables = GetTablesSchema(conn, "Views");
            node   = new TreeNode("Views");
            db.Nodes.Add(node);
            foreach (DataRow row in tables)
            {
                string   name  = row[2].ToString();
                TreeNode nodes = new TreeNode(name);

                DataTable b = PullData(conn, name);// GetTableSchema(conn, name);

                foreach (DataColumn r in b.Columns)
                {
                    string cs = r.ColumnName;

                    TreeNode ng = new TreeNode(cs.ToString());
                    nodes.Nodes.Add(ng);
                }
                nodes.Tag           = b;
                nodes.StateImageKey = "data";
                node.Nodes.Add(nodes);
            }

            //tables = GetTables(conn, "Procedures");
            //node = new TreeNode("Procedures");
            //db.Nodes.Add(node);
            //foreach (string s in tables)
            //{
            //    TreeNode nodes = new TreeNode(s);
            //    node.Nodes.Add(nodes);
            //}

            //tables = GetTables(conn, "UserDefinedTypes");
            //node = new TreeNode("UserDefinedTypes");
            //db.Nodes.Add(node);
            //foreach (string s in tables)
            //{
            //    TreeNode nodes = new TreeNode(s);
            //    node.Nodes.Add(nodes);
            //}

            wz = wizard.databaseobjects;
        }
Exemple #5
0
        public static List <DataRow> GetTablesSchema(DbConnection connection, string schemas, dataset data = null)
        {
            //using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();
                DataTable      schema     = connection.GetSchema(schemas);
                List <DataRow> TableNames = new List <DataRow>();
                foreach (DataRow row in schema.Rows)
                {
                    TableNames.Add(row);

                    //  if (data != null)
                    //      data.ns.Add(row);
                }
                if (data != null)
                {
                    data.SchemaTables = schema;
                }

                connection.Close();

                return(TableNames);
            }
        }