Commit dd941fdb authored by Alexander Scharfenberg's avatar Alexander Scharfenberg
Browse files

almost old status - button colouring missing yet

parent 5784a432
<Window x:Class="Raumverwaltung_HMWK.AddAssetWindow"
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="AddAssetWindow" Height="200" Width="300" ResizeMode="NoResize">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="100"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Margin="10">Asset dem Raum hinzufügen:</TextBlock>
<TextBox Name="Assetinput" BorderBrush="Black" Width="200" Height="30" FontSize="15"></TextBox>
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="0">
<Button Name="OK" Click="OK_OnClick" Height="30" Width="70">OK</Button>
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="1">
<Button Name="Abbruch" Click="Abbruch_OnClick" Height="30" Width="70">Abbruch</Button>
</StackPanel>
</Grid>
</Window>
\ No newline at end of file
using System;
using System.Collections.ObjectModel;
using System.Windows;
namespace Raumverwaltung_HMWK
{
public partial class AddAssetWindow : Window
{
private int RoomId;
private ObservableCollection<Asset> Assets;
public AddAssetWindow(int roomId, ObservableCollection<Asset> observableCollection)
{
RoomId = roomId;
Assets = observableCollection;
InitializeComponent();
}
private void OK_OnClick(object sender, RoutedEventArgs e)
{
if (!String.IsNullOrEmpty(Assetinput.Text))
{
string assetName = Assetinput.Text;
//insert Asset
SqLiteDataAccess.InsertAsset(RoomId,assetName);
Assets.Add(new Asset(SqLiteDataAccess.LatestAssetId(),assetName,RoomId));
MessageBox.Show("Asset hinzugefügt.", "Erfolgreich:", MessageBoxButton.OK, MessageBoxImage.Information);
Close();
}
}
private void Abbruch_OnClick(object sender, RoutedEventArgs e)
{
Close();
}
}
}
\ No newline at end of file
......@@ -17,7 +17,7 @@
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="1" FontSize="12" VerticalAlignment="Center" HorizontalAlignment="Center">Nutzerauswahl:</TextBlock>
<TextBlock Grid.Row="0" Grid.Column="1" FontSize="15" VerticalAlignment="Center" HorizontalAlignment="Center">Nutzerauswahl:</TextBlock>
<ComboBox Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" Name="AllUsers" VerticalAlignment="Center" Height="30" IsEditable="True"></ComboBox>
<Button Click="OK_OnClick" Grid.Row="2" Grid.Column="0" Name="OK" VerticalAlignment="Center" HorizontalAlignment="Right">Hinzufügen</Button>
<Button Click="ABBRUCH_OnClick" Grid.Row="2" Grid.Column="2" Name="ABBRUCH" VerticalAlignment="Center" HorizontalAlignment="Left">Abbrechen</Button>
......
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;
namespace Raumverwaltung_HMWK
......@@ -7,15 +8,30 @@ namespace Raumverwaltung_HMWK
public partial class AddUserForRoomWindow : Window
{
private ObservableCollection<User> userList;
private List<User> users;
private int RoomId;
public AddUserForRoomWindow(int roomId)
public AddUserForRoomWindow(int roomId, ObservableCollection<User> observableCollection)
{
InitializeComponent();
users = SqLiteDataAccess.LoadUsersNotinRoom(roomId);
RoomId = roomId;
users = SqLiteDataAccess.LoadUsers();
//updating UserList from RoomWindow
userList = observableCollection;
//delete users already in room
for (int i = 0; i < users.Count; i++)
{
for (int j = 0; j < userList.Count; j++)
{
if (users[i].Id.Equals(userList[j].Id))
{
users.RemoveAt(i);
}
}
AllUsers.Items.Add(users[i]);
}
......@@ -30,9 +46,14 @@ namespace Raumverwaltung_HMWK
{
if (AllUsers.SelectedItem != null)
{
//probiere aus und schau, ob index in Combobox und users gleich ist
User selectedUser = users[AllUsers.SelectedIndex];
//Add User to Room mit User-Id und weiterer SqLiteAccess-Funktion
SqLiteDataAccess.RoomUserRelation(RoomId,selectedUser.Id);
userList.Add(selectedUser);
MessageBox.Show("Benutzer wurde hinzugefügt", "Erfolgreich:", MessageBoxButton.OK,
MessageBoxImage.Information);
Close();
}
}
......
namespace Raumverwaltung_HMWK
using System.Runtime.CompilerServices;
namespace Raumverwaltung_HMWK
{
public class Asset
{
private int id;
private string name;
private int roomId;
private int AId;
private string AName;
private int RId;
public Asset()
......@@ -12,25 +14,32 @@
}
public Asset(string name)
public Asset(int id,string aName, int rId)
{
this.name = name;
AId = id;
AName = aName;
RId = rId;
}
public int Id
public int aId
{
get { return AId; }
set { AId = value; }
}
public string aName
{
get { return id; }
set { id = value; }
get { return AName; }
set { AName = value; }
}
public string Name
public int rId
{
get { return name; }
set { name = value; }
get { return RId; }
set { RId = value; }
}
public int RoomId
public override string ToString()
{
get { return roomId; }
set { roomId = value; }
return AName;
}
}
}
\ No newline at end of file
......@@ -62,9 +62,9 @@
<TextBlock Text="{Binding RoomSize}" FontSize="15"/>
<TextBlock Text="m²" FontSize="15"/>
<TextBlock Text="Arbeitsplätze:" FontSize="15" Margin="10,0,0,0"/>
<TextBlock Text="{Binding MaxWp}" FontSize="15" Margin="5,0,0,0"/>
<TextBlock Text="{Binding RealAmountUsers}" FontSize="15" Margin="5,0,0,0"/>
<TextBlock Text="/" FontSize="15"/>
<TextBlock Text="{Binding RealAmountUsers}" FontSize="15"></TextBlock>
<TextBlock Text="{Binding MaxWp}" FontSize="15"></TextBlock>
<TextBlock Text="(belegt/gesamt)" FontSize="15" Margin="5,0,0,0"/>
</WrapPanel>
</DataTemplate>
......
......@@ -81,6 +81,9 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="AddAssetWindow.xaml.cs">
<DependentUpon>AddAssetWindow.xaml</DependentUpon>
</Compile>
<Compile Include="AddUserToRoomWindow.xaml.cs">
<DependentUpon>AddUserToRoomWindow.xaml</DependentUpon>
</Compile>
......@@ -98,6 +101,7 @@
</Compile>
<Compile Include="SqLiteDataAccess.cs" />
<Compile Include="User.cs" />
<Page Include="AddAssetWindow.xaml" />
<Page Include="AddUserToRoomWindow.xaml" />
<Page Include="FloorWindow.xaml" />
<Page Include="MainWindow.xaml">
......
......@@ -30,11 +30,11 @@
<TextBlock FontSize="15" TextAlignment="Center" VerticalAlignment="Top" Background="Lavender" Grid.Column="0" Grid.Row="2" >Benutzer:</TextBlock>
<ListView Grid.Column="1" Grid.ColumnSpan="2" VerticalAlignment="Top" Grid.Row="2" Height="100" BorderBrush="Black" Name="Users"></ListView>
<Button Click="AddUser" Grid.Column="3" Grid.ColumnSpan="2" Grid.Row="2" Height="30" Width="120" Content="Benutzer hinzufügen" VerticalAlignment="Top" Margin="0,15,0,0"></Button>
<Button Grid.Column="3" Grid.ColumnSpan="2" Grid.Row="2" Height="30" Width="120" Content="Benutzer löschen" VerticalAlignment="Bottom" Margin="0,0,0,15"></Button>
<Button Click="DeleteUser" Grid.Column="3" Grid.ColumnSpan="2" Grid.Row="2" Height="30" Width="120" Content="Benutzer löschen" VerticalAlignment="Bottom" Margin="0,0,0,15"></Button>
<TextBlock Grid.Column="0" Grid.Row="3" FontSize="15" TextAlignment="Center" VerticalAlignment="Top" Background="Lavender">Assets:</TextBlock>
<ListView Grid.Column="1" Grid.ColumnSpan="2" VerticalAlignment="Top" Grid.Row="3" Height="100" BorderBrush="Black" Name="Materials"></ListView>
<Button Grid.Column="3" Grid.ColumnSpan="2" Grid.Row="3" Height="30" Width="100" Content="Asset hinzufügen" VerticalAlignment="Top" Margin="0,15,0,0"></Button>
<Button Grid.Column="3" Grid.ColumnSpan="2" Grid.Row="3" Height="30" Width="100" Content="Assetliste leeren" VerticalAlignment="Bottom" Margin="0,0,0,15"></Button>
<Button Click="AddAsset" Grid.Column="3" Grid.ColumnSpan="2" Grid.Row="3" Height="30" Width="100" Content="Asset hinzufügen" VerticalAlignment="Top" Margin="0,15,0,0"></Button>
<Button Click="DeleteAsset" Grid.Column="3" Grid.ColumnSpan="2" Grid.Row="3" Height="30" Width="100" Content="Asset löschen" VerticalAlignment="Bottom" Margin="0,0,0,15"></Button>
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
namespace Raumverwaltung_HMWK
{
public partial class RoomWindow : Window
{
private Room CurrentRoom;
private List<User> MyUsers = new List<User>();
private List<Asset> Assets = new List<Asset>();
private ObservableCollection<User> MyUsers;
private ObservableCollection<Asset> Assets;
public RoomWindow(int roomId)
{
CurrentRoom = SqLiteDataAccess.LoadRoom(roomId);
......@@ -16,8 +18,10 @@ namespace Raumverwaltung_HMWK
RoomName.Text = CurrentRoom.Name;
RoomSize.Text = CurrentRoom.Size + "m²";
Workplace.Text = CurrentRoom.MaxWp.ToString();
//Fill Users
MyUsers = SqLiteDataAccess.LoadUsersToRoom(roomId);
Users.ItemsSource = MyUsers;
//Fill Assets
Assets = SqLiteDataAccess.LoadAssetsToRoom(roomId);
Materials.ItemsSource = Assets;
}
......@@ -27,6 +31,8 @@ namespace Raumverwaltung_HMWK
try
{
SqLiteDataAccess.UpdateWorkplaces(CurrentRoom.Id,int.Parse(Workplace.Text));
MessageBox.Show("Obergrenze neu gesetzt.", "Erfolgreich:", MessageBoxButton.OK,
MessageBoxImage.Information);
}
catch (Exception)
{
......@@ -37,8 +43,63 @@ namespace Raumverwaltung_HMWK
private void AddUser(object sender, RoutedEventArgs e)
{
var window = new AddUserForRoomWindow(CurrentRoom.Id);
var window = new AddUserForRoomWindow(CurrentRoom.Id,MyUsers);
window.Show();
}
private void DeleteUser(object sender, RoutedEventArgs e)
{
if (Users.SelectedItem != null)
{
MessageBoxResult result = MessageBox.Show("Sind Sie Sicher, dass sie den Benutzer vom Raum entfernen wollen?", "Achtung:",
MessageBoxButton.YesNo, MessageBoxImage.Question);
switch (result)
{
case MessageBoxResult.Yes:
{
User selectedUser = MyUsers[Users.SelectedIndex];
SqLiteDataAccess.DeleteRoomUserRelation(CurrentRoom.Id,selectedUser.Id);
MyUsers.Remove(selectedUser);
break;
}
case MessageBoxResult.No:
{
break;
}
}
}
}
private void AddAsset(object sender, RoutedEventArgs e)
{
var window = new AddAssetWindow(CurrentRoom.Id,Assets);
window.Show();
}
private void DeleteAsset(object sender, RoutedEventArgs e)
{
if (Materials.SelectedItem != null)
{
MessageBoxResult result = MessageBox.Show("Sind Sie Sicher, dass sie das Asset löschen wollen?", "Achtung:",
MessageBoxButton.YesNo, MessageBoxImage.Question);
switch (result)
{
case MessageBoxResult.Yes:
{
Asset asset = Assets[Materials.SelectedIndex];
SqLiteDataAccess.DeleteAsset(asset.aId);
Assets.Remove(asset);
break;
}
case MessageBoxResult.No:
{
break;
}
}
}
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Data.SQLite;
using System.Linq;
using System.Windows;
......@@ -14,23 +16,24 @@ namespace Raumverwaltung_HMWK
private static string LoadConnectionString(string id = "Default")
{
return ConfigurationManager.ConnectionStrings[id].ConnectionString;
}
public static List<Building> GetBuildings()
{
using (IDbConnection cnn = new SQLiteConnection(new SQLiteConnection(LoadConnectionString())))
{
var roomoutput = cnn.Query<Room>("select Id, Name, Size, MaxWP, FloorId from Room", new DynamicParameters());
var roomoutput = cnn.Query<Room>("select Id, Name, Size, MaxWP, FloorId from Room",
new DynamicParameters());
var flooroutput = cnn.Query<Floor>("select Id, Name, BuildingId from Floor", new DynamicParameters());
var buildingoutput = cnn.Query<Building>("select BId, Name from Building", new DynamicParameters());
var buildingoutput = cnn.Query<Building>("select BId, Name from Building", new DynamicParameters());
List<Room> rooms = roomoutput.ToList();
List<Floor> floors = flooroutput.ToList();
List<Building> buildings = buildingoutput.ToList();
for (int i = 0; i < rooms.Count; i++)
{
for (int j = 0; j < floors.Count; j++)
......@@ -38,7 +41,7 @@ namespace Raumverwaltung_HMWK
if (rooms[i].FloorId.Equals(floors[j].Id))
{
floors[j].Rooms.Add(rooms[i]);
}
}
}
}
......@@ -52,7 +55,7 @@ namespace Raumverwaltung_HMWK
}
}
}
return buildings;
}
}
......@@ -62,17 +65,18 @@ namespace Raumverwaltung_HMWK
using (IDbConnection cnn = new SQLiteConnection(new SQLiteConnection(LoadConnectionString())))
{
string query = "Select COUNT(*) from Room_User where RId = @Id";
var output = cnn.ExecuteScalar<int>(query,new {Id});
var output = cnn.ExecuteScalar<int>(query, new {Id});
return output;
}
}
public static Floor GetFloor(int floorId)
{
using (IDbConnection cnn = new SQLiteConnection(new SQLiteConnection(LoadConnectionString())))
{
string sql = "select Id, Name, Image, BuildingId from Floor where Id = @floorId";
Floor floor = cnn.Query<Floor>(sql,new {floorId}).First();
Floor floor = cnn.Query<Floor>(sql, new {floorId}).First();
return floor;
}
}
......@@ -110,24 +114,26 @@ namespace Raumverwaltung_HMWK
}
}
public static List<User> LoadUsersToRoom(int roomId)
public static ObservableCollection<User> LoadUsersToRoom(int roomId)
{
using (IDbConnection cnn = new SQLiteConnection(new SQLiteConnection(LoadConnectionString())))
{
string sql =
"select Id, Vorname, Nachname, Department, Referat, Orga from User INNER JOIN Room_User ON User.Id = Room_User.UId where RId=@roomId";
var output = cnn.Query<User>(sql, new {roomId});
return output.ToList();
ObservableCollection<User> UserList = new ObservableCollection<User>(output.ToList());
return UserList;
}
}
public static List<Asset> LoadAssetsToRoom(int roomId)
public static ObservableCollection<Asset> LoadAssetsToRoom(int roomId)
{
using (IDbConnection cnn = new SQLiteConnection(new SQLiteConnection(LoadConnectionString())))
{
string sql = "select AId, AName, RId from Asset where RId = @roomId";
var output = cnn.Query<Asset>(sql, new {roomId});
return output.ToList();
ObservableCollection<Asset> AssetList = new ObservableCollection<Asset>(output.ToList());
return AssetList;
}
}
......@@ -143,17 +149,73 @@ namespace Raumverwaltung_HMWK
}
}
public static List<User> LoadUsersNotinRoom(int roomId)
public static List<User> LoadUsers()
{
using (IDbConnection cnn = new SQLiteConnection(new SQLiteConnection(LoadConnectionString())))
{
string sql =
"select Id, Vorname, Nachname, Department, Referat, Orga from User INNER JOIN Room_User ON User.Id = Room_User.UId where RId!=@roomId";
var output = cnn.Query<User>(sql, new {roomId});
"select Id, Vorname, Nachname, Department, Referat, Orga from User";
var output = cnn.Query<User>(sql);
return output.ToList();
}
}
public static void RoomUserRelation(int roomId, int userId)
{
using (IDbConnection cnn = new SQLiteConnection(new SQLiteConnection(LoadConnectionString())))
{
string sql = "insert into Room_User (RId,UId) VALUES (@roomId, @userId)";
var dynamicParameters = new DynamicParameters();
dynamicParameters.Add("roomId", roomId);
dynamicParameters.Add("userId", userId);
cnn.Execute(sql, dynamicParameters);
}
}
public static void DeleteRoomUserRelation(int roomId, int userId)
{
using (IDbConnection cnn = new SQLiteConnection(new SQLiteConnection(LoadConnectionString())))
{
string sql = "DELETE FROM Room_User where RId=@roomId and UId=@userId";
var dynamicParameters = new DynamicParameters();
dynamicParameters.Add("roomId", roomId);
dynamicParameters.Add("userId", userId);
cnn.Execute(sql, dynamicParameters);
}
}
public static void InsertAsset(int roomId, string assetName)
{
using (IDbConnection cnn = new SQLiteConnection(new SQLiteConnection(LoadConnectionString())))
{
string sql = "Insert into Asset (AName, RId) VALUES (@assetName, @roomId)";
var dynamicParameters = new DynamicParameters();
dynamicParameters.Add("assetName", assetName);
dynamicParameters.Add("roomId", roomId);
cnn.Execute(sql, dynamicParameters);
}
}
public static void DeleteAsset(int assetId)
{
using (IDbConnection cnn = new SQLiteConnection(new SQLiteConnection(LoadConnectionString())))
{
string sql = "DELETE FROM Asset WHERE AId=@assetId";
var dynamicParameters = new DynamicParameters();
dynamicParameters.Add("assetId", assetId);
cnn.Execute(sql, dynamicParameters);
}
}
public static int LatestAssetId()
{
using (IDbConnection cnn = new SQLiteConnection(new SQLiteConnection(LoadConnectionString())))
{
string sql = "Select max(AId) from Asset";
return Convert.ToInt32(cnn.ExecuteScalar(sql));
}
}
}
}
\ No newline at end of file
}
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