private bool LoadConfigFileAndTryConnectSql() { string nameServer = string.Empty; string nameUser = string.Empty; string password = string.Empty; bool isLoadAndConnect = true; try { using (System.IO.StreamReader file = new System.IO.StreamReader("Config.file")) { nameServer = file.ReadLine(); nameUser = file.ReadLine(); password = file.ReadLine(); } } catch (Exception) { ApplicationLog.LogService.AddRaportError("Nie udało się otworzyć pliku konfiguracyjnego.", ApplicationLog.LogService.GetNameCurrentMethod() + "()", System.IO.Directory.GetParent(System.IO.Directory.GetCurrentDirectory()).Parent.FullName + @"\RunApplication.cs"); isLoadAndConnect = false; } if (isLoadAndConnect) { isLoadAndConnect = DataBase.TryConnectToSql(nameServer, nameUser, password); } return(isLoadAndConnect); }
private void acceptButton_Click(object sender, RoutedEventArgs e) { if (CheckIfGiveDataIsCorrect()) { if (DataBase.TryConnectToSql(nameServer.Text, nameUser.Text, password.Password)) { if (DataBase.ConnectToDataBase()) { DataBase.CloseConnection(); using (System.IO.StreamWriter file = new System.IO.StreamWriter("Config.file", true)) { file.WriteLine(nameServer.Text); file.WriteLine(nameUser.Text); file.WriteLine(password.Password); } CanRunApplication = true; this.Close(); } else { CanRunApplication = false; BuildAndDisplayMessageErrorConnectToDataBase(); } } else { CanRunApplication = false; BuildAndDisplayMessageErrorConnectToSql(); } } }