private void LoginUser()
        {
            var username = UsernameTextbox.GetLineText(0);
            var password = PasswordBox.Password;

            Boolean correctData = userDao.ValidateCredentials(username, password);
            if (correctData)
            {
                ChatWindow win2 = new ChatWindow(username);
                win2.Show();
                this.Close();
            }
            else
            {
                ErrorLabel.Content = "Entered credentials do not match any user!";
            }
        }
        private void RegisterUser()
        {
            var username = UsernameTextbox.GetLineText(0);
            var password = PasswordBox.Password;

            if (!userDao.Exists(username))
            {
                if (userDao.CreateUser(username, password))
                {
                    ChatWindow win2 = new ChatWindow(username);
                    win2.Show();
                    this.Close();
                }
                else
                {
                    ErrorLabel.Content = "Registering failed!";
                }
            }
            else
            {
                ErrorLabel.Content = "Username is already taken!";
            }
        }
        private void lbContacts_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (lbContacts.SelectedItem != null)
            {
                ContactItem selected = (ContactItem)lbContacts.SelectedItem;
                if (selected.Protocol == "msn")
                {
                    MSNPSharp.Contact contact = selected.Contact;

                    bool activate = false;
                    MsnChatWindow activeForm = null;
                    foreach (MsnChatWindow conv in ConversationWindows)
                    {
                        if (conv.Conversation.HasContact(contact) &&
                            (conv.Conversation.Type & ConversationType.Chat) == ConversationType.Chat)
                        {
                            activeForm = conv;
                            activate = true;
                        }

                    }

                    if (activate)
                    {
                        if (activeForm.WindowState == WindowState.Minimized)
                            activeForm.Show();

                        activeForm.Activate();
                        return;
                    }

                    Conversation convers = this.m_messenger.CreateConversation();
                    MsnChatWindow window = CreateConversationWindow(convers, contact);

                    window.Show();

                    return;
                }

                if (!this.m_windows.Contains(selected.Address) || !((ChatWindow)this.m_windows[selected.Address]).Open)
                {
                    ChatWindow window = new ChatWindow(selected.Address, Properties.Settings.Default.ClientPort);
                    window.Nickname = this.m_contacts.Nickname;
                    window.Nickname = this.m_contacts.Status;
                    window.ContactNickname = selected.Nickname;
                    window.ContactStatus = selected.Status;
                    this.m_windows[selected.Address] = window;
                    window.Show();
                    window.Activate();
                }
                else
                {
                    ((ChatWindow)this.m_windows[selected.Address]).Focus();
                }
            }
        }
        private void Server_ConnectionAccepted(System.Net.Sockets.TcpClient client)
        {
            String address = ((IPEndPoint)client.Client.RemoteEndPoint).Address.ToString();
            if (!this.m_windows.Contains(address) || !((ChatWindow)this.m_windows[address]).Open)
            {
                ChatWindow window = new ChatWindow(client);

                int index = ContactIndex(address);
                if (index != -1)
                {
                    window.ContactNickname = this.ContactsCollection[index].Nickname;
                    window.ContactStatus = this.ContactsCollection[index].Status;
                }

                this.m_windows[address] = window;
                window.ShowActivated = false;
            }
            else
            {
                ChatWindow window = (ChatWindow)this.m_windows[address];
                window.Reconnect(client);
            }
        }
 private void ChatConnectDialog_Click(object sender, RoutedEventArgs e)
 {
     String ipaddress = this.m_ChatConnectDialog.tbValue.Text;
     if (App.IsValidIP(ipaddress))
     {
         ChatWindow window = new ChatWindow(ipaddress, Properties.Settings.Default.ClientPort);
         window.Show();
     }
     else
     {
         MessageBox.Show("Non valid ip address given");
     }
 }