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; } }
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; } }
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(); } } }