Exemple #1
0
        private void OpenChatWindow(ChatServiceHandler handler)
        {
            var chatWindow = new ChatWindow(handler);

            chatWindow.Show();
            Close();
            chatWindow.Focus();
        }
Exemple #2
0
        public MainWindow()
        {
            InitializeComponent();

            ConnectButton.Click += (s, ev) => {
                try {
                    Hide();
                    ChatWindow chatWindow = new ChatWindow(UsernameTextBox.Text);
                    chatWindow.Show();
                } catch (Exception ex) {
                    MessageBox.Show(ex.Message);
                }
            };
        }
        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!";
            }
        }
Exemple #4
0
        private void loginBut_Click(object sender, EventArgs e)
        {
            String user = userText.Text;
            String pass = passText.Text;

            try
            {
                ctrl.login(user, pass);
                //MessageBox.Show("Login succeded");
                ChatWindow chatWin = new ChatWindow(ctrl);
                chatWin.Text = "Chat window for " + user;
                chatWin.Show();
                this.Hide();
            }catch (Exception ex)
            {
                MessageBox.Show(this, "Login Error " + ex.Message + ex.StackTrace, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
Exemple #5
0
        public void GetConnected()
        {
            tcpClient = new TcpClient("192.168.10.1", 51888);
            NetworkStream ns = tcpClient.GetStream();

            br = new BinaryReader(ns);
            bw = new BinaryWriter(ns);
            Task.Run(() =>
            {
                while (true)
                {
                    string receiveString = null;
                    try
                    {
                        receiveString = br.ReadString();
                    }
                    catch
                    {
                        //异常处理
                    }
                    switch (receiveString)
                    {
                    case "LOGIN SUCCESS":
                        ChatWindow cw = new ChatWindow();
                        cw.Show();
                        this.Close();
                        break;

                    case "LOGIN FAILURE":
                        MessageBox.Show("用户名密码错误!");
                        this.txtPwd.Password = "";
                        break;

                    default:
                        MessageBox.Show(receiveString);
                        break;
                    }
                }
            });
        }
        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 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");
     }
 }