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);
            }
        }
Exemple #2
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);
            }
        }