private bool CheckServerDatabase() { try { using (var context = new PostgreSQL.Model.StudentElectionContext()) { } return(true); } catch (Exception ex) { Logger.LogError(ex); MessageBox.Show("Unable to connect with the database. Press OK to enter the setup", "Database connection problem", MessageBoxButton.OK, MessageBoxImage.Exclamation); var window = new DatabaseSetupWindow(); window.WindowStartupLocation = WindowStartupLocation.CenterScreen; window.ShowInTaskbar = true; var result = window.ShowDialog(); if (result != true) { MessageBox.Show("You cannot use this system without a database", "No database", MessageBoxButton.OK, MessageBoxImage.Stop); return(false); } return(true); } }
private void SetUpDatabase() { MessageBox.Show("There's no database to be used. Press OK to enter the setup", "No database", MessageBoxButton.OK, MessageBoxImage.Exclamation); var window = new DatabaseSetupWindow(); window.WindowStartupLocation = WindowStartupLocation.CenterScreen; window.ShowInTaskbar = true; var result = window.ShowDialog(); if (result != true) { MessageBox.Show("You cannot use this system without a database", "No database", MessageBoxButton.OK, MessageBoxImage.Stop); Environment.Exit(0); return; } }
private async void Application_Startup(object sender, StartupEventArgs e) { System.Windows.Forms.Application.EnableVisualStyles(); System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false); var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); Enum.TryParse <DatabaseType>(configFile.AppSettings.Settings["DatabaseType"].Value, out var databaseType); SetFolderPaths(databaseType); switch (databaseType) { case DatabaseType.Unknown: SetUpDatabase(); return; case DatabaseType.File: var result = ProvideMSAccessPassword(); if (result == false) { Environment.Exit(0); return; } break; case DatabaseType.Server: result = CheckServerDatabase(); if (result == false) { Environment.Exit(0); return; } break; } ConfigurationHelper.ProtectConfiguration(); if (!Directory.Exists(ImageFolderDirectory)) { MessageBox.Show("There's no network folder. Press OK to enter the setup", "No network folder", MessageBoxButton.OK, MessageBoxImage.Exclamation); var window = new DatabaseSetupWindow(); window.WindowStartupLocation = WindowStartupLocation.CenterScreen; window.ShowInTaskbar = true; var result = window.ShowDialog(); if (result != true) { MessageBox.Show("You cannot use this system without a network folder", "No network folder", MessageBoxButton.OK, MessageBoxImage.Stop); } Environment.Exit(0); return; } if (!Directory.Exists(ImageFolderPath)) { Directory.CreateDirectory(ImageFolderPath); } var userService = new UserService(); int usersCount = await userService.CountUsersAsync(); if (usersCount == 0) { MessageBox.Show("No users yet. Press OK to add a superuser", "No users", MessageBoxButton.OK, MessageBoxImage.Exclamation); var userWindow = new StaffWindow { PresetUserType = UserType.Superuser }; userWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen; userWindow.WindowStyle = WindowStyle.ToolWindow; userWindow.Title = "Add superuser"; userWindow.ShowInTaskbar = true; userWindow.ShowDialog(); usersCount = await userService.CountUsersAsync(); if (usersCount == 0) { MessageBox.Show("You cannot use this system without a user", "No users", MessageBoxButton.OK, MessageBoxImage.Stop); Environment.Exit(0); return; } } }