Пример #1
0
        private void VideoWindow_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (MessageBox.Show("Are you sure to leave the class room", "VCES - Leave confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                if (tcpClientForStudent.Connected)
                {
                    Data data = new Data();
                    data.cmd      = Command.Leave;
                    data.userName = lblUser.Text;
                    byte[] outStream = data.ToByte();
                    serverStream.Write(outStream, 0, outStream.Length);
                    serverStream.Flush();
                    tcpClientForStudent.Close();
                    udpAudioReceiving.Close();
                }

                sin = new SignIn();
                sin.txtVCESName.Text = lblUser.Text;

                this.Dispose();
                sin.Show();
                sin.txtPassword.Focus();
            }
            else
            {
                e.Cancel = true;
            }
        }
Пример #2
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            Data data = new Data();

            data.cmd      = Command.TextMessage;
            data.userName = lblUser.Text;
            data.chatText = txtChat.Text;
            byte[] outStream = data.ToByte();
            serverStream.Write(outStream, 0, outStream.Length);
            serverStream.Flush();
            txtChat.Text = "";
        }
Пример #3
0
        private void btnQuestionRequest_Click(object sender, EventArgs e)
        {
            if (true)
            {
            }

            if (hHwnd == 0)
            {
                if (MessageBox.Show("Either webcam is not attached with your system or you did not start it\nPlease check your cam settings or click 'Start camera' button to start it\notherwise teacher will not be able to watch you\n\nContinue any way?", "VCES - Webcam error", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                {
                    return;
                }
            }
            Data data = new Data();

            data.cmd      = Command.QuestionRequest;
            data.userName = lblUser.Text;
            byte[] outStream = data.ToByte();

            serverStream.Write(outStream, 0, outStream.Length);
            serverStream.Flush();

            btnQuestionRequest.Enabled = false;
        }
Пример #4
0
        private void btnSignIn_Click(object sender, EventArgs e)
        {
            if (txtVCESName.Text.Length == 0 && txtPassword.Text.Length == 0)
            {
                MessageBox.Show("Please enter user name\nand password", "VCES", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                txtVCESName.Focus();
                return;
            }
            else if (txtVCESName.Text.Length == 0)
            {
                MessageBox.Show("Please enter user name", "VCES", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                txtVCESName.Focus();
                return;
            }
            else if (txtPassword.Text.Length == 0)
            {
                MessageBox.Show("Please enter password", "VCES", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                txtPassword.Focus();
                return;
            }
            btnSignIn.Enabled = false;

            IPEndPoint dataBaseEP = new IPEndPoint(IPAddress.Parse("169.254.133.4"), 1350);

            TcpClient     myTcpClient = new TcpClient();
            NetworkStream dataBaseStream;

            try
            {
                myTcpClient.Connect(dataBaseEP);
                dataBaseStream = myTcpClient.GetStream();

                Data data = new Data();
                data.cmd      = Command.SignInStudent;
                data.userName = txtVCESName.Text;
                data.pwd      = txtPassword.Text;
                byte[] outStream = data.ToByte();

                dataBaseStream.Write(outStream, 0, outStream.Length);
                dataBaseStream.Flush();

                byte[] inStream = new byte[myTcpClient.ReceiveBufferSize];

                dataBaseStream.Read(inStream, 0, inStream.Length);
                dataBaseStream.Close();
                myTcpClient.Close();

                Data receivedData = new Data(inStream);

                switch (receivedData.cmd)
                {
                case Command.Varified:
                    vw.userName = txtVCESName.Text;
                    this.Hide();
                    vw.Show();
                    break;

                case Command.NotVarified:
                    MessageBox.Show("Invalid User Name OR Password!", "VCES - Sign in", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    break;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("VCES can't connect with server.\nPlease check your network connection", "VCES - Connection Error Message", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            finally
            {
                btnSignIn.Enabled = true;
            }
        }
Пример #5
0
        private void btnSignUp_Click(object sender, EventArgs e)
        {
            if (txtFullName.ForeColor == Color.Gray || txtVCESName.ForeColor == Color.Gray || txtPassword.ForeColor == Color.Gray || txtRepPassword.ForeColor == Color.Gray || txtEmail.ForeColor == Color.Gray || cmbGender.Text.Length == 0 || cmbSubject.Text.Length == 0)
            {
                MessageBox.Show("Please enter complete information", "VCES - Sign up", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            btnSignUp.Enabled = false;

            IPEndPoint dataBaseEP = new IPEndPoint(IPAddress.Parse("169.254.133.4s"), 1350);

            TcpClient     myTcpClient = new TcpClient();
            NetworkStream dataBaseStream;

            try
            {
                myTcpClient.Connect(dataBaseEP);
                dataBaseStream = myTcpClient.GetStream();

                Data data = new Data();
                data.cmd    = Command.SignUpStudent;
                data.record = txtFullName.Text + "|" + txtVCESName.Text + "|" + txtPassword.Text + "|" + txtRepPassword.Text + "|" + txtEmail.Text + "|" + cmbGender.SelectedItem + "|" + cmbSubject.SelectedItem;
                byte[] outStream = data.ToByte();

                dataBaseStream.Write(outStream, 0, outStream.Length);
                dataBaseStream.Flush();

                byte[] inStream = new byte[myTcpClient.ReceiveBufferSize];

                dataBaseStream.Read(inStream, 0, inStream.Length);
                dataBaseStream.Close();
                myTcpClient.Close();

                Data receivedData = new Data(inStream);

                switch (receivedData.cmd)
                {
                case Command.SignUpTrue:
                    if (MessageBox.Show("Congratulation!\nYour new VCES account is created succesfully", "VCES - Create new account", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) == DialogResult.OK)
                    {
                        this.Hide();
                        sin.Show();
                        sin.txtVCESName.Text = txtVCESName.Text;
                        sin.txtPassword.Focus();
                    }
                    break;

                case Command.SignUpFalse:
                    MessageBox.Show("VCES name is not available\nPlease try different name", "VCES - Sign in", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    break;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("VCES can't connect with server.\nPlease check your network connection", "VCES - Connection Error Message", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            finally
            {
                btnSignUp.Enabled = true;
            }
        }
Пример #6
0
        private void msg()
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new MethodInvoker(msg));
            }
            else
            {
                switch (msgReceived.cmd)
                {
                case Command.JoinRequestAccepted:
                    lblRemote.Text = msgReceived.senderName;
                    break;

                case Command.Join:
                    lstBoxStudents.Items.Add(msgReceived.senderName);
                    break;

                case Command.Leave:
                    lstBoxStudents.Items.Remove(msgReceived.senderName);
                    break;

                case Command.QuestionRequstAccepted:
                    dlgAskingQuestion = DialogResult.None;
                    using (new TimedDialog(30000))
                    {
                        dlgAskingQuestion = MessageBox.Show("Your question request has been accepted\nClick OK button to start asking your question", "VCES", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                    }
                    Data data = new Data();
                    data.userName = lblUser.Text;
                    if (dlgAskingQuestion == DialogResult.OK)
                    {
                        data.cmd = Command.AskingQuestionStart;

                        serverStream.Write(data.ToByte(), 0, data.ToByte().Length);
                        serverStream.Flush();
                        if (!timer1.Enabled)
                        {
                            timer1.Enabled = true;
                        }
                    }
                    else if (dlgAskingQuestion == DialogResult.Cancel)
                    {
                        data.cmd = Command.AskingQuestionCancel;
                        serverStream.Write(data.ToByte(), 0, data.ToByte().Length);
                        serverStream.Flush();
                    }
                    else
                    {
                        data.cmd = Command.AskingQuestionCancel;
                        serverStream.Write(data.ToByte(), 0, data.ToByte().Length);
                        serverStream.Flush();
                        MessageBox.Show("Your question asking time of 30 seconds is over\nYou cannot continue asking this question.\n\nTo send the request again, use 'Question Request' button.", "VCES - Question Time out", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        btnQuestionRequest.Enabled = true;
                    }
                    break;

                case Command.AskingQuestionStart:
                    picBoxStudent.Visible = true;
                    break;

                case Command.AskingQuestionStop:
                    picBoxStudent.Visible = false;
                    if (timer1.Enabled)
                    {
                        timer1.Enabled = false;
                    }
                    if (threadAudioSend.IsAlive)
                    {
                        audioSend = false;
                        //udpAudioSending.Close();

                        //threadAudioSend.Abort();
                    }
                    btnQuestionRequest.Enabled = true;
                    break;

                case Command.LectureEnded:
                    picBoxTeacher.Image = Image.FromFile("NUMLLOGO.jpg");
                    break;

                case Command.TextMessage:
                    rtChat.Text = rtChat.Text + Environment.NewLine + msgReceived.senderName + " >>   " + msgReceived.chatText + Environment.NewLine;
                    break;
                }
            }
        }
Пример #7
0
        private void btnJoinLeave_Click(object sender, EventArgs e)
        {
            if (btnJoinLeave.Text.Equals("Join"))
            {
                btnJoinLeave.Enabled = false;
                if (!connectToServer())
                {
                    if (MessageBox.Show("Server User is not online right now!", "Server not responding", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry)
                    {
                        btnJoinLeave_Click(sender, e);
                        return;
                    }
                    else
                    {
                        btnJoinLeave.Enabled = true;
                        return;
                    }
                }

                Thread text = new Thread(messageReceived);
                text.Start();



                Data data = new Data();
                data.cmd      = Command.Join;
                data.userName = lblUser.Text;

                byte[] outStream = data.ToByte();

                serverStream.Write(outStream, 0, outStream.Length);
                serverStream.Flush();

                btnJoinLeave.Text          = "Leave";
                btnJoinLeave.Enabled       = true;
                btnQuestionRequest.Enabled = true;
                btnSend.Enabled            = true;
            }
            else if (btnJoinLeave.Text.Equals("Leave"))
            {
                if (MessageBox.Show("Are you sure to leave the  room", "Leave confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    if (tcpClientForStudent.Connected)
                    {
                        Data data = new Data();
                        data.cmd      = Command.Leave;
                        data.userName = lblUser.Text;
                        byte[] outStream = data.ToByte();
                        serverStream.Write(outStream, 0, outStream.Length);
                        serverStream.Flush();
                        tcpClientForStudent.Close();
                        udpAudioReceiving.Close();
                    }

                    sin = new SignIn();
                    sin.txtVCESName.Text = lblUser.Text;

                    this.Dispose();
                    this.Hide();
                    sin.Show();
                    sin.txtPassword.Focus();
                }
            }
        }