private bool ReLoadDatabases() { if (reloadingDatabases) { return(true); } dataBases = null; try { cboDatabase.Sensitive = false; btnOK.Sensitive = false; reloadingDatabases = true; cboDatabase.Load(new [] { Translator.GetString("Loading...") }, null, null, null); PresentationDomain.ProcessUIEvents(); string dbProviderName = DbProvider; if (!BusinessDomain.TryConnect(dbProviderName, Server, SlaveServer, User, Password)) { cboDatabase.Load(new [] { Translator.GetString("None", "Database") }, null, null, null); reloadingDatabases = false; return(false); } DataHelper.FireAndForget(startedProvider => { try { dataBases = BusinessDomain.GetDatabases(); // If the provider changed after we started to look for databases, don't show them if (startedProvider != DbProvider) { return; } PresentationDomain.Invoke(() => { bool hasDbs = dataBases.Length > 0; if (hasDbs) { cboDatabase.Load(dataBases, null, null, BusinessDomain.AppConfiguration.DbDatabase); } else { cboDatabase.Load(new [] { Translator.GetString("None", "Database") }, null, null, null); } cboDatabase.Sensitive = hasDbs; btnOK.Sensitive = hasDbs; reloadingDatabases = false; }); } catch { cboDatabase.Load(new [] { Translator.GetString("None", "Database") }, null, null, null); reloadingDatabases = false; } }, dbProviderName); return(true); } catch (Exception ex) { ErrorHandling.LogException(ex); return(false); } }
private void btnNew_Clicked(object sender, EventArgs e) { if (!BusinessDomain.TryConnect(DbProvider, Server, SlaveServer, User, Password)) { MessageError.ShowDialog(Translator.GetString("The connection to the server was not successful!"), "Icons.Database32.png"); return; } CreateDatabaseType dbType; using (NewDatabase dlgNewDB = new NewDatabase()) { ResponseType response = dlgNewDB.Run(); if (response == ResponseType.Apply) { BusinessDomain.AppConfiguration.DbDatabase = dlgNewDB.DatabaseName; ReLoadDatabases(); } if (response != ResponseType.Ok) { return; } dbType = dlgNewDB.DatabaseType; // Set the new database as the only one as at this point we are closing the dialog and we don't nee the full list cboDatabase.Load(new [] { dlgNewDB.DatabaseName }, null, null, null); } // Unclutter the screen by hiding the background dialog which is no longer needed anyway dlgEditDBConnection.Hide(); if (dbType == CreateDatabaseType.Blank) { SetSettings(); BusinessDomain.AppConfiguration.Load(false); using (Assistant assistant = new Assistant(AssistType.DatabaseSetup)) assistant.Run(); BusinessDomain.AppConfiguration.Save(true); } dlgEditDBConnection.Respond(ResponseType.Ok); }