Commit 7735f02f authored by Alexander Scharfenberg's avatar Alexander Scharfenberg
Browse files

changeUser & SearchUser + small changes

parent 6f1f9ea5
......@@ -5,7 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Raumverwaltung_HMWK"
mc:Ignorable="d"
Title="Nutzer auswählen" Height="200" Width="300" ResizeMode="NoResize">
Title="Nutzer auswählen" Height="200" Width="310" ResizeMode="NoResize">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
......
......@@ -5,31 +5,33 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Raumverwaltung_HMWK"
mc:Ignorable="d"
Title="Benutzer anlegen" Height="500" Width="270" ResizeMode="NoResize">
Title="Benutzer anlegen" Height="600" Width="300" ResizeMode="NoResize">
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="400"></RowDefinition>
<RowDefinition Height="500"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="125"></ColumnDefinition>
<ColumnDefinition Width="125"></ColumnDefinition>
<ColumnDefinition Width="150"></ColumnDefinition>
<ColumnDefinition Width="150"></ColumnDefinition>
</Grid.ColumnDefinitions>
<StackPanel HorizontalAlignment="Center" Grid.Row="0" Grid.ColumnSpan="2">
<TextBlock Margin="15">Nachname:</TextBlock>
<TextBlock Margin="0,15">Nachname:</TextBlock>
<TextBox Name="NameInput" BorderBrush="Black" Width="200" Height="30"></TextBox>
<TextBlock Margin="15">Vorname:</TextBlock>
<TextBlock Margin="0,15">Vorname:</TextBlock>
<TextBox Name="VorNameInput" BorderBrush="Black" Width="200" Height="30"></TextBox>
<TextBlock Margin="15">Abteilung:</TextBlock>
<TextBlock Margin="0,15">Abteilung:</TextBlock>
<TextBox Name="DepartmentInput" BorderBrush="Black" Width="200" Height="30"></TextBox>
<TextBlock Margin="15">Referat:</TextBlock>
<TextBlock Margin="0,15">Referat:</TextBlock>
<TextBox Name="ReferatInput" BorderBrush="Black" Width="200" Height="30"></TextBox>
<TextBlock Margin="15">Orga:</TextBlock>
<TextBlock Margin="0,15">Orga:</TextBlock>
<TextBox Name="OrgaInput" BorderBrush="Black" Width="200" Height="30"></TextBox>
<TextBlock Margin="0,15">Telefonnummer:</TextBlock>
<TextBox Name="NumberInput" BorderBrush="Black" Width="200" Height="30"></TextBox>
</StackPanel>
<Button Grid.Row="1" Grid.Column="0" Click="Add_Clicked" Content="Hinzufügen" Width="100" Height="30" Margin="10"></Button>
<Button Grid.Row="1" Grid.Column="1" Click="Abort_Clicked" Content="Abbrechen" Width="100" Height="30" Margin="10"></Button>
<Button Grid.Row="1" Grid.Column="0" Click="Add_Clicked" Content="Hinzufügen" Width="100" Height="30"></Button>
<Button Grid.Row="1" Grid.Column="1" Click="Abort_Clicked" Content="Abbrechen" Width="100" Height="30"></Button>
</Grid>
</Window>
<Window x:Class="Raumverwaltung_HMWK.ChangeUserWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Raumverwaltung_HMWK"
mc:Ignorable="d"
Title="Nutzer ändern" Height="700" Width="300">
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="550"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"></ColumnDefinition>
<ColumnDefinition Width="150"></ColumnDefinition>
</Grid.ColumnDefinitions>
<StackPanel HorizontalAlignment="Center" Grid.Row="0" Grid.ColumnSpan="2">
<TextBlock HorizontalAlignment="Center" Margin="0,10">Nutzerauswahl:</TextBlock>
<ComboBox SelectionChanged="AllUsers_OnSelectionChanged" Name="AllUsers" Width="200" Height="30"></ComboBox>
<TextBlock Margin="0,15">Nachname:</TextBlock>
<TextBox Name="NameInput" BorderBrush="Black" Width="200" Height="30"></TextBox>
<TextBlock Margin="0,15">Vorname:</TextBlock>
<TextBox Name="VorNameInput" BorderBrush="Black" Width="200" Height="30"></TextBox>
<TextBlock Margin="0,15">Abteilung:</TextBlock>
<TextBox Name="DepartmentInput" BorderBrush="Black" Width="200" Height="30"></TextBox>
<TextBlock Margin="0,15">Referat:</TextBlock>
<TextBox Name="ReferatInput" BorderBrush="Black" Width="200" Height="30"></TextBox>
<TextBlock Margin="0,15">Orga:</TextBlock>
<TextBox Name="OrgaInput" BorderBrush="Black" Width="200" Height="30"></TextBox>
<TextBlock Margin="0,15">Telefonnummer:</TextBlock>
<TextBox Name="NumberInput" BorderBrush="Black" Width="200" Height="30"></TextBox>
</StackPanel>
<Button Click="ChangeUser" Grid.Row="1" Grid.Column="0" Content="Ändern" Width="100" Height="30" Margin="0,10"></Button>
<Button Click="Abbort" Grid.Row="1" Grid.Column="1" Content="Abbrechen" Width="100" Height="30" Margin="0,10"></Button>
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
namespace Raumverwaltung_HMWK
{
public partial class ChangeUserWindow : Window
{
private List<User> users;
public ChangeUserWindow()
{
users = SqLiteDataAccess.LoadUsers();
InitializeComponent();
AllUsers.ItemsSource = users;
}
private void AllUsers_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
User selected = users[AllUsers.SelectedIndex];
NameInput.Text = selected.Nachnname;
VorNameInput.Text = selected.Vorname;
DepartmentInput.Text = selected.Department;
ReferatInput.Text = selected.Referat;
OrgaInput.Text = selected.Orga;
}
private void ChangeUser(object sender, RoutedEventArgs e)
{
if (!String.IsNullOrEmpty(NameInput.Text) && !String.IsNullOrEmpty(VorNameInput.Text))
{
MessageBoxResult result = MessageBox.Show("Sind Sie sicher, dass sie die Nutzerdaten ändern wollen?",
"Achtung", MessageBoxButton.YesNo, MessageBoxImage.Question);
switch (result)
{
case MessageBoxResult.Yes:
{
try
{
SqLiteDataAccess.ChangeUser(NameInput.Text, VorNameInput.Text, DepartmentInput.Text,
ReferatInput.Text, OrgaInput.Text, users[AllUsers.SelectedIndex].Id);
MessageBox.Show("Änderung durchgeführt", "Erfolgreich:", MessageBoxButton.OK,
MessageBoxImage.Information);
foreach (Window w in Application.Current.Windows)
{
if (w.Title != "Raumverwaltung-HMWK")
{
w.Close();
}
else
{
w.Close();
MainWindow window = new MainWindow();
window.Show();
}
}
}
catch (Exception)
{
MessageBox.Show("Die Änderung hat leider nicht geklappt", "Fehler:", MessageBoxButton.OK,
MessageBoxImage.Error);
}
break;
}
case MessageBoxResult.No:
{
break;
}
}
}
else
{
MessageBox.Show("Der Nutzer hat mindestens einen Vor- und Nachnamen.", "Fehler:", MessageBoxButton.OK,
MessageBoxImage.Error);
}
}
private void Abbort(object sender, RoutedEventArgs e)
{
Close();
}
}
}
\ No newline at end of file
......@@ -16,7 +16,7 @@
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<StackPanel Grid.Row="0" Grid.ColumnSpan="2" HorizontalAlignment="Center">
<TextBlock Margin="5,20,20,20" HorizontalAlignment="Left" FontSize="15">Nutzer:</TextBlock>
<TextBlock Margin="0,20,20,20" HorizontalAlignment="Center" FontSize="15">Nutzer:</TextBlock>
<ComboBox Name="allUsers" IsEditable="True" Width="200" Height="30"></ComboBox>
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="0">
......
......@@ -37,6 +37,8 @@
<MenuItem Header="Benutzer" FontSize="15" BorderBrush="Black" Margin="10,0" Background="Thistle">
<MenuItem Header="Anlegen" Click="AddUser"/>
<MenuItem Header="Löschen" Click="DeleteUser"/>
<MenuItem Header="Suchen" Click="SearchUser"/>
<MenuItem Header="Ändern" Click="ChangeUser"/>
</MenuItem>
<MenuItem Header="Hilfe" FontSize="15" BorderBrush="Black" Margin="10,0" Background="Thistle"></MenuItem>
</Menu>
......@@ -49,9 +51,7 @@
<TextBlock Text="Stockwerke:" FontSize="15" HorizontalAlignment="Center"></TextBlock>
<ComboBox Name="Stockwerkauswahl" SelectionChanged="Stockwerkauswahl_OnSelectionChanged" Height="30" Width="100"></ComboBox>
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="2" Orientation="Vertical" VerticalAlignment="Top">
<TextBlock Text="Auswahl:" FontSize="15" HorizontalAlignment="Center"></TextBlock>
<TextBox Name="Result" Margin="0,10" Height="30" Width="100"></TextBox>
<StackPanel Grid.Row="1" Grid.Column="2" Orientation="Vertical" VerticalAlignment="Top" Margin="0,20">
<Button Click="OpenFloor_OnClick" FontSize="15" IsEnabled="False" Name="OpenFloor" Content="Stockwerk öffnen" Height="30" Width="120"></Button>
</StackPanel>
<Grid Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3" VerticalAlignment="Top">
......
......@@ -66,7 +66,6 @@ namespace Raumverwaltung_HMWK
ComboBox cbx = (ComboBox) sender;
if(cbx.SelectedItem != null)
{
Result.Text = cbx.SelectedItem.ToString();
OpenFloor.IsEnabled = true;
FillOverview(cbx.SelectedItem.ToString());
}
......@@ -82,15 +81,12 @@ namespace Raumverwaltung_HMWK
{
for (int j = 0; j < buildings[i].Floors.Count; j++)
{
if (Result.Text.Equals(buildings[i].Floors[j].Name))
if (Stockwerkauswahl.Text.Equals(buildings[i].Floors[j].Name))
{
floorid = buildings[i].Floors[j].Id;
}
}
}
var window = new FloorWindow(floorid);
window.Show();
}
......@@ -167,5 +163,20 @@ namespace Raumverwaltung_HMWK
var window = new DeleteFloorWindow();
window.Show();
}
private void SearchUser(object sender, RoutedEventArgs e)
{
var window = new SearchUserWindow();
window.Show();
}
private void ChangeUser(object sender, RoutedEventArgs e)
{
var window = new ChangeUserWindow();
window.Show();
}
}
}
\ No newline at end of file
......@@ -101,6 +101,9 @@
</Compile>
<Compile Include="Asset.cs" />
<Compile Include="Building.cs" />
<Compile Include="ChangeUserWindow.xaml.cs">
<DependentUpon>ChangeUserWindow.xaml</DependentUpon>
</Compile>
<Compile Include="DeleteFloorWindow.xaml.cs">
<DependentUpon>DeleteFloorWindow.xaml</DependentUpon>
</Compile>
......@@ -123,6 +126,9 @@
<Compile Include="RoomWindow.xaml.cs">
<DependentUpon>RoomWindow.xaml</DependentUpon>
</Compile>
<Compile Include="SearchUserWindow.xaml.cs">
<DependentUpon>SearchUserWindow.xaml</DependentUpon>
</Compile>
<Compile Include="SqLiteDataAccess.cs" />
<Compile Include="User.cs" />
<Page Include="AddAssetWindow.xaml" />
......@@ -131,6 +137,7 @@
<Page Include="AddRoomWindow.xaml" />
<Page Include="AddUserToRoomWindow.xaml" />
<Page Include="AddUserWindow.xaml" />
<Page Include="ChangeUserWindow.xaml" />
<Page Include="DeleteFloorWindow.xaml" />
<Page Include="DeleteLocationWindow.xaml" />
<Page Include="DeleteRoomWindow.xaml" />
......@@ -149,6 +156,7 @@
<SubType>Code</SubType>
</Compile>
<Page Include="RoomWindow.xaml" />
<Page Include="SearchUserWindow.xaml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
......
<Window x:Class="Raumverwaltung_HMWK.SearchUserWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Raumverwaltung_HMWK"
mc:Ignorable="d"
Title="Nutzer suchen" Height="350" Width="310" ResizeMode="NoResize">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="1" FontSize="15" VerticalAlignment="Center" HorizontalAlignment="Center">Nutzerauswahl:</TextBlock>
<ComboBox SelectionChanged="AllUsers_OnSelectionChanged" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" Name="AllUsers" VerticalAlignment="Center" Height="30" IsEditable="True"></ComboBox>
<ComboBox Margin="0,15" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3" Name="AllRooms" VerticalAlignment="Center" Height="30" IsEnabled="False"></ComboBox>
<Button Click="OpenFloor" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="3" Name="OK" VerticalAlignment="Center" HorizontalAlignment="Center">Stockwerk des Raums öffnen</Button>
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
namespace Raumverwaltung_HMWK
{
public partial class SearchUserWindow : Window
{
private List<User> users;
private List<Room> rooms = new List<Room>();
public SearchUserWindow()
{
users = SqLiteDataAccess.LoadUsers();
InitializeComponent();
AllUsers.ItemsSource = users;
}
private void AllUsers_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (AllUsers.SelectedItem != null)
{
AllRooms.IsEnabled = true;
AllRooms.ItemsSource = null;
rooms.Clear();
User selected = users[AllUsers.SelectedIndex];
rooms = SqLiteDataAccess.LoadRoomsToUser(selected.Id);
if (rooms.Count == 0)
{
AllRooms.IsEnabled = false;
}
else
{
AllRooms.ItemsSource = rooms;
AllRooms.SelectedIndex = 0;
}
}
}
private void OpenFloor(object sender, RoutedEventArgs e)
{
try
{
Room selected = rooms[AllRooms.SelectedIndex];
FloorWindow window = new FloorWindow(selected.FloorId);
window.Show();
}
catch (Exception)
{
MessageBox.Show("Stockwerk des Raums konnte nicht geöffnet werden.", "Fehler:", MessageBoxButton.OK,
MessageBoxImage.Error);
}
}
}
}
\ No newline at end of file
......@@ -124,6 +124,17 @@ namespace Raumverwaltung_HMWK
}
}
public static List<Room> LoadRoomsToUser(int userId)
{
using (IDbConnection cnn = new SQLiteConnection(new SQLiteConnection(LoadConnectionString())))
{
string sql =
"Select Name, FloorId from Room JOIN Room_User ON Room.Id = Room_User.RId where UId=@userId";
var output = cnn.Query<Room>(sql, new {userId});
return output.ToList();
}
}
public static ObservableCollection<Asset> LoadAssetsToRoom(int roomId)
{
using (IDbConnection cnn = new SQLiteConnection(new SQLiteConnection(LoadConnectionString())))
......@@ -426,6 +437,26 @@ namespace Raumverwaltung_HMWK
}
public static void ChangeUser(string Nachname, string Vorname, string Department, string Referat, string Orga, int UserId)
{
using (IDbConnection cnn = new SQLiteConnection(new SQLiteConnection(LoadConnectionString())))
{
var dynamicParameters = new DynamicParameters();
dynamicParameters.Add("Vorname", Vorname);
dynamicParameters.Add("Nachname", Nachname);
dynamicParameters.Add("Department", Department);
dynamicParameters.Add("Referat", Referat);
dynamicParameters.Add("Orga", Orga);
dynamicParameters.Add("UserId", UserId);
string sql =
"UPDATE User SET Vorname=@Vorname, Nachname=@Nachname, Department=@Department, Referat=@Referat, Orga=@Orga WHERE Id=@UserId";
cnn.Execute(sql, dynamicParameters);
}
}
}
}
......@@ -8,6 +8,7 @@
private string department;
private string referat;
private string orga;
private string number;
public User(){}
......@@ -48,6 +49,12 @@
set { orga = value; }
}
public string Number
{
get { return number; }
set { number = value; }
}
public override string ToString()
{
return Nachnname+", "+Vorname+", "+Department+", "+Referat+", "+Orga;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment