Пример #1
0
        protected void showChat()
        {
            client.User = new User(userNameTextBox.Text, passwordTextBox.Text);
            var frm = new Views.Chat(client);

            frm.Location      = this.Location;
            frm.StartPosition = FormStartPosition.Manual;
            frm.FormClosing  += delegate
            {
                client = null;
                this.Show();
            };
            frm.Show();
            this.Hide();
        }
Пример #2
0
        /// <summary>
        /// Action perform on Login button click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void loginButton_Click(object sender, EventArgs e)
        {
            ChatMessage messageJoin = new ChatMessage(ChatMessage.Header.JOIN);

            messageJoin.addData(usernameTextBox.Text);
            messageJoin.addData(passwordTextBox.Text);
            client.sendMessage(messageJoin);

            ChatMessage reply = client.getMessage();

            if (reply == null)
            {
                MessageBox.Show("Server failure",
                                "Connection error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }

            if (reply.MessageList.First() == "success")
            {
                client.User = new ChatUser(usernameTextBox.Text, passwordTextBox.Text);
                var frm = new Chat(client);
                frm.Location      = this.Location;
                frm.StartPosition = FormStartPosition.Manual;
                frm.FormClosing  += delegate { this.Close(); };
                frm.Show();
                this.Hide();
            }
            else if (reply.MessageList.First() == "error")
            {
                MessageBox.Show("Wrong password",
                                "Connection error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }