Esempio n. 1
0
        private void btnTest_Click(object sender, EventArgs e)
        {
            ThongSo.DB_Mode       = (DBMS)cboDatasource.SelectedIndex;
            ThongSo.DB_Server     = txtServer.Text;
            ThongSo.DB_UserName   = txtUserName.Text;
            ThongSo.DB_Password   = txtPassword.Text;
            ThongSo.DB_AccessFile = bfcFileBrowse.txtFileName.Text;

            DBProviderBase database = new DBProviderBase();

            if (database.TestConnection())
            {
                DevExpress.XtraEditors.XtraMessageBox.Show("Test Connection succecced");
            }
            else
            {
                DevExpress.XtraEditors.XtraMessageBox.Show("Test Connection failed", "Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 2
0
        public List <string> Process()
        {
            List <string> listCreateTable = new List <string>();
            List <string> listPK          = new List <string>();
            List <string> listFK          = new List <string>();

            DBProviderBase database = new DBProviderBase();

            foreach (Table table in mdp.Tables)
            {
                string strCreateTable = CreateTable(table.name, table.columns);

                listCreateTable.Add(strCreateTable);

                List <string> listPKName = new List <string>();
                foreach (Column col in table.columns)
                {
                    if (col.PrimaryKey)
                    {
                        listPKName.Add(col.Name);
                    }
                }
                string strPK = CreatePrimaryKey(table.name, listPKName);
                listPK.Add(strPK);
            }
            foreach (ForeignKey fk in mdp.ForeignKeys)
            {
                string strFK = CreateForeignKey(fk.Name, fk.ParentTable, fk.ParentColumn, fk.ChildTable, fk.ChildColumn);
                listFK.Add(strFK);
            }

            string        strDB      = CreateDataBase(dbName);
            string        strTables  = GenerateTables(listCreateTable, listPK);
            string        strFKs     = GenerateForeignKeys(listFK);
            List <string> listScript = new List <string>();

            listScript.Add(strDB);
            listScript.Add(strTables);
            listScript.Add(strFKs);
            return(listScript);
        }
Esempio n. 3
0
        public void GenerateDirect(string FolderPath, string dbName, string script)
        {
            if (ThongSo.DB_Server != "" && ThongSo.DB_Server != null || ThongSo.DB_Mode == DBMS.Access)
            {
                DBProviderBase database = new DBProviderBase();

                if (ThongSo.DB_Mode == DBMS.Access)
                {
                    string filePath = "";
                    if (!ThongSo.DB_IsNewDatabase)
                    {
                        filePath = ThongSo.DB_AccessFile;
                    }
                    else
                    {
                        filePath = FolderPath + "\\" + dbName + ".mdb";
                    }

                    FileInfo fi = new FileInfo(filePath);
                    if (fi.Exists)
                    {
                        if (DevExpress.XtraEditors.XtraMessageBox.Show("This database already existed\nDo you want to overwrite it ?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            fi.Delete();
                        }
                    }
                    if (database.CreateDatabase(dbName, FolderPath))
                    {
                        if (database.Connect(filePath))
                        {
                            if (database.Execute(script))
                            {
                                database.Close();
                            }
                            else
                            {
                                DevExpress.XtraEditors.XtraMessageBox.Show("Generate Failed, please manual check the generated script !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }
                    else
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show("Cannot create the database\nMay be the file name is duplicated with write protected file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    if (database.TestConnection())
                    {
                        if (!database.Connect(dbName))
                        {
                            database.CreateDatabase(dbName, FolderPath);
                            if (database.Connect(dbName))
                            {
                                database.Execute(script);
                            }
                        }
                        else
                        {
                            if (ThongSo.DB_Mode == DBMS.Oracle)
                            {
                                database.Execute(script);
                            }
                            else if (DevExpress.XtraEditors.XtraMessageBox.Show("This database already existed\nDo you want to overwrite it ?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                            {
                                database.Execute(script);
                            }
                        }

                        database.Close();
                    }
                    else
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show("Cannot connect to database\nYou must start the database first", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            else
            {
                DevExpress.XtraEditors.XtraMessageBox.Show("Cannot connect to database\nPlease specify connection setting", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }