f9d5053029
Kommentare hinzugefügt wo sie noch gefehlt haben
135 lines
3.9 KiB
C#
135 lines
3.9 KiB
C#
using Microsoft.Win32;
|
|
using System;
|
|
using System.Windows;
|
|
using System.Windows.Input;
|
|
using System.Windows.Threading;
|
|
using bib_talk.Business;
|
|
|
|
namespace bib_talk
|
|
{
|
|
public partial class MainWindow : Window
|
|
{
|
|
MainWindowManager mwManager; // MainWindowManager initializeren
|
|
|
|
private DispatcherTimer _timer; // DispatcherTimer initialisieren
|
|
public string loggedinUser; // Feld um eingeloggten User zu speichern
|
|
private bool isFirstLoad = true;
|
|
|
|
// MainWindow Konstruktor mit einem User und LoadMessages Methode
|
|
public MainWindow(string user)
|
|
{
|
|
loggedinUser = user;
|
|
InitializeComponent();
|
|
InitializeTimer();
|
|
LoadData();
|
|
|
|
mwManager = new MainWindowManager(this, user);
|
|
|
|
mwManager.LoadMessages();
|
|
}
|
|
|
|
// Der 3 Sekunden Timer für die Nachrichten und Online Benutzer
|
|
private void InitializeTimer()
|
|
{
|
|
_timer = new DispatcherTimer
|
|
{
|
|
Interval = TimeSpan.FromSeconds(2)
|
|
};
|
|
_timer.Tick += (sender, e) => { mwManager.LoadMessages(); mwManager.LoadOnlineUsers(); };
|
|
_timer.Start();
|
|
}
|
|
|
|
// Methode zum Usernamen in dem MainWindow anzeigen
|
|
public void LoadData()
|
|
{
|
|
loggedInUser.Text = "Logged in as: " + loggedinUser;
|
|
}
|
|
|
|
// Methode zum User ausloggen und App schließen
|
|
private void CloseButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
mwManager.LogoutUser();
|
|
this.Close();
|
|
}
|
|
|
|
// Custom DraggableArea für das MainWindow
|
|
private void DraggableArea_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
|
{
|
|
if (e.ButtonState == MouseButtonState.Pressed)
|
|
{
|
|
DragMove();
|
|
}
|
|
}
|
|
|
|
// Hotkey (Enter) für das Senden einer Nachricht
|
|
private async void messageBox_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.Key == Key.Enter)
|
|
{
|
|
mwManager.SendMessage();
|
|
}
|
|
}
|
|
|
|
// Senden Button für das Senden einer Nachricht
|
|
private async void send_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
mwManager.SendMessage();
|
|
}
|
|
|
|
// temporäre Methoden, löschen wenn karl nichts gemacht hat
|
|
#region Temporär, Karl
|
|
private void ChatFenster_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (popup.IsOpen = true)
|
|
{
|
|
popup.Focus();
|
|
}
|
|
else
|
|
{
|
|
popup.IsOpen = true;
|
|
}
|
|
|
|
}
|
|
private void Button1_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
MessageBox.Show("Button 1 wurde geklickt!");
|
|
ClosePopup();
|
|
}
|
|
|
|
private void Button2_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
MessageBox.Show("Button 2 wurde geklickt!");
|
|
ClosePopup();
|
|
}
|
|
|
|
private void Button3_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
MessageBox.Show("Button 3 wurde geklickt!");
|
|
ClosePopup();
|
|
}
|
|
|
|
private void Popup_LostFocus(object sender, RoutedEventArgs e)
|
|
{
|
|
ClosePopup();
|
|
}
|
|
|
|
private void ClosePopup()
|
|
{
|
|
popup.IsOpen = false;
|
|
}
|
|
#endregion
|
|
|
|
// Methode zum Profilbilder hochladen
|
|
private async void uploadpbclick(object sender, RoutedEventArgs e)
|
|
{
|
|
OpenFileDialog openFileDialog = new OpenFileDialog();
|
|
openFileDialog.Filter = "Image files (*.jpg, *.jpeg, *.png, *.gif) | *.jpg; *.jpeg; *.png; *.gif";
|
|
if (openFileDialog.ShowDialog() == true)
|
|
{
|
|
string filePath = openFileDialog.FileName;
|
|
await mwManager.UploadProfileImage(filePath);
|
|
}
|
|
}
|
|
}
|
|
}
|