Example #1
0
        public void SignIn()
        {
            buttonSignIn.Enabled = false;
            //
            //帳號密碼驗證
            //
            if (textBoxUserName.Text == "")
            {
                MessageBox.Show("請輸入使用者名稱");
                buttonSignIn.Enabled = true;
                return;
            }
            else if (textBoxUserName.Text.IndexOf(" ") > -1)
            {
                MessageBox.Show("請輸入有效的字元");
                buttonSignIn.Enabled = true;
                return;
            }
            //將姓名寫入資料庫
            clientData.Name = textBoxUserName.Text;
            string result = FireBase.SetData(clientData, checkBoxAnonymous.Checked);

            if (result == "Error")
            {
                MessageBox.Show("與伺服器連結失敗");
                buttonSignIn.Enabled = true;
                return;
            }
            //轉換視窗
            FormChatClient f = new FormChatClient();

            this.DialogResult = DialogResult.OK;
            MessageBox.Show("登入成功");
            this.Close();
        }
        private void SendMsg(string Msg)
        {
            try
            {
                if (Client == null)
                {
                    Client = ChatClient.Connect(ChatSetting.IP);
                    Client.newListener(MsgComeIn);
                    Client.CloseException(ExceptionServerExit);

                    richTextBoxBoard.SelectionColor = Color.Blue;
                    Client.Send($"歡迎 {FireBase.GetData(clientData)} 加入。");
                }
                if (textBoxMsg.Text.Length > 0)
                {
                    Client.Send(FireBase.GetData(clientData) + ":" + Msg);
                    textBoxMsg.Text = "";
                }
            }
            catch (Exception)
            {
                MessageBox.Show("無法連接伺服器端");
                return;
            }
        }
 public void ExitChatRoom()
 {
     if (Client != null)
     {
         if (Client.socket.Connected)
         {
             Client.Send(FireBase.GetData(clientData) + " 已離開");
         }
         Client.Dispose();
         Client.listenThread.Abort();
     }
 }
        //登入視窗關閉判斷
        private void FormChatClient_Load(object sender, EventArgs e)
        {
            //登入視窗先顯示
            FormLogin f = new FormLogin();

            f.ShowDialog();

            if (f.DialogResult == DialogResult.OK)
            {
                clientData         = FormLogin.clientData;
                labelUserName.Text = FireBase.GetData(clientData);
            }
        }