private void btLoginLogin_Click(object sender, RoutedEventArgs e)
        {
            lbLoginError.Content = "";

            User = new User(tbLoginUsername.Text, "0:0", tbLoginPassword.Password);

            Response response = Exchange(new Document(), "LoginModule", "Login");

            User = response.Header.Targets.First();

            switch (response.Header.Code)
            {
            case ResponseCode.PlannedError:
                lbLoginError.Content = response.Header.Message;
                User = null;
                break;

            case ResponseCode.Ok:
                GetMain.UpdateInfoLabel();
                ChangeControl(MainWindow.Controls.Main);
                break;

            default:
                throw new Exception("Invalid response code.");
            }
        }
        private void btConnectionConnect_Click(object sender, RoutedEventArgs e)
        {
            DateTime startWaitTime = DateTime.Now;

            btConnectionConnect.IsEnabled = false;
            btConnectionConnect.Content   = "Connecting";
            lbConnectionError.Content     = "";
            DoEvents();

            try
            {
                GetMain.Connect();
            }
            catch (Exception ex)
            {
                btConnectionConnect.IsEnabled = true;
                btConnectionConnect.Content   = "Connect";
                lbConnectionError.Content     = ex.Message;
                return;
            }
            finally
            {
                GetMain.UpdateInfoLabel();
            }

            while (!Client.IsConnected)
            {
                System.Threading.Thread.Sleep(250);
                DoEvents();

                if (DateTime.Now > startWaitTime.AddSeconds(15))
                {
                    btConnectionConnect.IsEnabled = true;
                    btConnectionConnect.Content   = "Connect";
                    lbConnectionError.Content     = "Connection timed out";
                    Client.Close();
                    return;
                }
            }

            GetMain.UpdateInfoLabel();
            GetMain.ChangeControl(MainWindow.Controls.Login);
        }