private void Button_Click(object sender, RoutedEventArgs e) { if (ConnectionList.SelectedItem != null) { dynamic data = ConnectionList.SelectedItem; var editwindow = new EditWindow(data.ID, data.Address, data.Login, data.Password, data.Port); if (editwindow.ShowDialog() == true) { } using (var context = new DatabasesContext()) { var connections = context.Db .Select(q => new { ID = q.DatabaseID, Address = q.Server_address, Login = q.Login, Password = q.Password, Port = q.Port }) .ToList(); databaseEntries.Clear(); foreach (var item in connections) { databaseEntries.Add(item); } } } }
private void Button_Click(object sender, RoutedEventArgs e) { if (ConnectionList.SelectedItem != null) { dynamic data = ConnectionList.SelectedItem; int id = data.ID; using (var context = new DatabasesContext()) { var remove = context.Db.SingleOrDefault(q => q.DatabaseID == id); context.Db.Remove(remove); context.SaveChanges(); } using (var context = new DatabasesContext()) { var connections = context.Db .Select(q => new { ID = q.DatabaseID, Address = q.Server_address, Login = q.Login, Password = q.Password, Port = q.Port }) .ToList(); databaseEntries.Clear(); foreach (var item in connections) { databaseEntries.Add(item); } } } }
/// <summary> /// Kontruktor klasy ktory inicjalizuje komponenty i wyswietlajacy liste baz. /// </summary> public ConnectDatabaseWindow() { InitializeComponent(); DataContext = this; using var context = new DatabasesContext(); var connections = context.Db .Select(q => new { ID = q.DatabaseID, q.Server_address, q.Login }) .ToList(); ConnectionList.ItemsSource = connections; }
/// <summary> /// Metoda ktora edytuje dany rekord i zamyka okno edytowania. /// </summary> private void Button_Click(object sender, RoutedEventArgs e) { using var context = new DatabasesContext(); var update = context.Db.SingleOrDefault(q => q.DatabaseID == id_db); string encrypt_pass = PasswordHash.Encrypt(password.Text); update.Server_address = server_address.Text; update.Login = login.Text; update.Password = encrypt_pass; update.Port = port.Text; context.SaveChanges(); this.Close(); }
/// <summary> /// Kontruktor klasy ktory inicjalizuje komponenty oraz wyswietla dane z pliku z zapisanymi bazami po czym zapisuje je do tablicy. /// </summary> public EditDatabaseWindow() { InitializeComponent(); using (var context = new DatabasesContext()) { var connections = context.Db .Select(q => new { ID = q.DatabaseID, Address = q.Server_address, q.Login, q.Password, q.Port }) .ToList(); foreach (var item in connections) { databaseEntries.Add(item); } } ConnectionList.ItemsSource = databaseEntries; }
/// <summary> /// metoda ktora dodaje baze /// </summary> private void AddDatabase() { string pass_hash = PasswordHash.Encrypt(Password.Password); var db = new Database { Server_address = Server_address.Text, Login = Login.Text, Password = pass_hash, Port = Port.Text }; using (var context = new DatabasesContext()) { context.Db.Add(db); context.SaveChanges(); } Close(); }
/// <summary> /// metoda ktora laczy z dana baza po wpisaniu jej danych lub wybraniu z listy. /// </summary> private void Connect_Click(object sender, RoutedEventArgs e) { var button = sender as Button; if (button.Name == "ConnectOnce") { ConnectionString = $"Server=tcp:{ServerAddress.Text},{Port.Text};Initial Catalog=%%%;User ID={Login.Text};Password={Password.Password};Connection Timeout=15"; } else { using var context = new DatabasesContext(); var connectionParams = context.Db .Where(q => q.DatabaseID == selectedDatabaseID) .Select(q => new { q.Server_address, q.Login, q.Password, q.Port }) .FirstOrDefault(); string decrypt_pass = PasswordHash.Decrypt(connectionParams.Password); ConnectionString = $"Server=tcp:{connectionParams.Server_address},{connectionParams.Port};Initial Catalog=%%%;User ID={connectionParams.Login};Password={decrypt_pass};Connection Timeout=15"; } DialogResult = true; }