Beispiel #1
0
        public static DialogResult Show(string text,string Caption,Font _font)
        {
            MessageCustom ms = new MessageCustom(text, Caption,_font);
            ms.ShowDialog();

            return Result;
        }
Beispiel #2
0
        public static DialogResult Show(string text, string Caption, Font _font)
        {
            MessageCustom ms = new MessageCustom(text, Caption, _font);

            ms.ShowDialog();

            return(Result);
        }
Beispiel #3
0
 private void bbt_findFriend_Click(object sender, EventArgs e)
 {
     if (txt_findFriend.Text == "")
     {
         MessageCustom.Show("Vui lòng nhập Talk ID hay Tên \n người cần kết bạn!", "Thông báo",
                            new Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular,
                                     System.Drawing.GraphicsUnit.Point, ((byte)(0))));
     }
     else
     {
         Command cm = new Command(Enum.CommandType_.FindFriend, txt_findFriend.Text);
         client.SendCommand(cm);
     }
 }
Beispiel #4
0
        void Click_dangnhap()
        {
            this.txt_dangnhap._lost();
            this.txt_password._lost();
            if (txt_dangnhap.NullText == false || txt_password.NullText == false)
            {
                MessageCustom.Show("Vui lòng nhập tài khoản và mật khẩu \n chính xác  để đăng nhập! ", "Thông báo đăng nhập", new Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))));
            }
            else
            {
                try
                {
                    if (client == null)
                    {
                        socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                        IPep   = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9999);
                        socket.Connect(IPep);
                        client = new ClientManager(this, socket);
                        stream = new NetworkStream(socket);
                    }

                    byte[] buffer = new byte[4];
                    buffer = BitConverter.GetBytes((int)CommandType_.Login);
                    stream.Write(buffer, 0, 4);
                    stream.Flush();
                    buffer = BitConverter.GetBytes(txt_dangnhap.Text.Length);
                    stream.Write(buffer, 0, 4);
                    stream.Flush();
                    byte[] data = new byte[txt_dangnhap.Text.Length];
                    data = Encoding.ASCII.GetBytes(txt_dangnhap.Text);
                    stream.Write(data, 0, txt_dangnhap.Text.Length);
                    stream.Flush();
                    buffer = BitConverter.GetBytes(txt_password.Text.Length);
                    stream.Write(buffer, 0, 4);
                    stream.Flush();
                    data = new byte[txt_password.Text.Length];
                    data = Encoding.ASCII.GetBytes(txt_password.Text);
                    stream.Write(data, 0, txt_password.Text.Length);
                    stream.Flush();
                }
                catch
                {
                    MessageCustom.Show("Server đang bảo trì. \nVui lòng đăng nhập lại sau. ", "Thông báo đăng nhập", new Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))));
                }
            }
        }
Beispiel #5
0
 private void bbt_gui_Click(object sender, EventArgs e)
 {
     if (_client.socket.Connected)
     {
         if (rTB_content.Text != "")
         {
             Messeage ms = new Messeage(_client.userName, rTB_content.Text, _fontMessage);
             flp_messeage.Controls.Add(ms);
             _fontMessage = rTB_content.Font;
             Command cmd = new Command(Enum.CommandType_.Message, rTB_content.Text, _fontMessage);
             rTB_content.Text = "";
             _client.SendCommand(cmd);
         }
     }
     else
     {
         MessageCustom.Show("Kết nối với client đã bị đóng!", "Thông báo", new Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))));
     }
 }
Beispiel #6
0
        /// <summary>
        /// ptb_dangki
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void ptb_dangki_Click(object sender, EventArgs e)
        {
            try
            {
                if (client == null)
                {
                    socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    IPep   = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9999);
                    socket.Connect(IPep);
                    stream = new NetworkStream(socket);
                    client = new ClientManager(this, socket);
                }
                Register dangki = new Register(socket);
                dangki.Show();
            }
            catch
            {
                MessageCustom.Show("Server đang bảo trì. \nBạn không thể đăng kí lúc này. ", "Thông báo đăng nhập", new Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))));
            }
        }
Beispiel #7
0
        public void bw_receive_DoWork(object sender, DoWorkEventArgs e)
        {
            byte[] buffer = new byte[4];
            byte[] data   = null;
            string usernameTemp;
            bool   check_addMessage = false;

            while (socket.Connected)
            {
                try
                {
                    stream.Read(buffer, 0, 4);
                    CommandType_ cmt = (CommandType_)BitConverter.ToInt32(buffer, 0);
                    if (cmt == CommandType_.Message)
                    {
                        string cmdMetaData = "";
                        buffer = new byte[4];
                        //đọc nội dung tin nhắn
                        stream.Read(buffer, 0, 4);
                        int    lenght     = BitConverter.ToInt32(buffer, 0);
                        byte[] metaBuffer = new byte[lenght];
                        stream.Read(metaBuffer, 0, lenght);
                        cmdMetaData = Encoding.ASCII.GetString(metaBuffer);
                        //đọc font
                        stream.Read(buffer, 0, 4);
                        lenght     = BitConverter.ToInt32(buffer, 0);
                        metaBuffer = new byte[lenght];
                        stream.Read(metaBuffer, 0, lenght);
                        MemoryStream    s    = new MemoryStream(metaBuffer);
                        BinaryFormatter bf   = new BinaryFormatter();
                        Font            temp = new Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular);
                        temp = (Font)bf.Deserialize(s);
                        Chat chatForm = null;
                        _frmMain.Invoke(new Action(delegate()
                        {
                            if ((chatForm = IsShow("Server")) == null)
                            {
                                chatForm      = new Chat(this, "Server");
                                chatForm.Text = "Server";
                                chatForm.Show();
                                listFormChat.Add(chatForm);
                            }
                        }));
                        chatForm.Receive("Server", cmdMetaData, temp);
                    }//end message

                    if (cmt == CommandType_.LoadMessage)
                    {
                        buffer = new byte[4];
                        stream.Read(buffer, 0, 4);
                        int count = BitConverter.ToInt16(buffer, 0);
                        if (count > 0)
                        {
                            buffer = new byte[4];
                            stream.Read(buffer, 0, 4);
                            int lengh = BitConverter.ToInt32(buffer, 0);
                            data = new byte[lengh];
                            stream.Read(data, 0, lengh);
                            usernameTemp = Encoding.ASCII.GetString(data);
                            LinkedList <MessageText> listmessageTemp = new System.Collections.Generic.LinkedList <MessageText>();
                            for (int i = 0; i < count; i++)
                            {
                                buffer = new byte[4];
                                stream.Read(buffer, 0, 4);
                                lengh = BitConverter.ToInt32(buffer, 0);
                                data  = new byte[lengh];
                                stream.Read(data, 0, lengh);
                                string content = Encoding.ASCII.GetString(data);


                                stream.Read(buffer, 0, 4);
                                int lenght = BitConverter.ToInt32(buffer, 0);
                                data = new byte[lenght];
                                stream.Read(data, 0, lenght);
                                MemoryStream s = new MemoryStream(data);
                                s.Position = 0;
                                BinaryFormatter bf   = new BinaryFormatter();
                                Font            temp = new Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular);
                                temp = (Font)bf.Deserialize(s);

                                buffer = new byte[4];
                                stream.Read(buffer, 0, 4);
                                int         type = BitConverter.ToInt16(buffer, 0);
                                MessageText mst  = new MessageText(content, temp, type);

                                listmessageTemp.AddLast(mst);
                            }
                            foreach (var s in listmessageTemp)
                            {
                                IsShow(usernameTemp).listmessage.AddFirst(s);
                            }
                            IsShow(usernameTemp).update_message(true);
                        }
                    }
                    if (cmt == CommandType_.MessageFriend)
                    {
                        buffer = new byte[4];
                        stream.Read(buffer, 0, 4);
                        int lengh = BitConverter.ToInt32(buffer, 0);
                        data = new byte[lengh];
                        stream.Read(data, 0, lengh);
                        usernameTemp = Encoding.ASCII.GetString(data);

                        //đọc nội dung tin nhắn
                        string cmdMetaData = "";
                        buffer = new byte[4];
                        stream.Read(buffer, 0, 4);
                        int    lenght     = BitConverter.ToInt32(buffer, 0);
                        byte[] metaBuffer = new byte[lenght];
                        stream.Read(metaBuffer, 0, lenght);
                        cmdMetaData = Encoding.UTF8.GetString(metaBuffer);
                        //đọc font
                        stream.Read(buffer, 0, 4);
                        lenght     = BitConverter.ToInt32(buffer, 0);
                        metaBuffer = new byte[lenght];
                        stream.Read(metaBuffer, 0, lenght);
                        //convert byte sang font
                        MemoryStream    s    = new MemoryStream(metaBuffer);
                        BinaryFormatter bf   = new BinaryFormatter();
                        Font            temp = new Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular);
                        temp = (Font)bf.Deserialize(s);
                        Chat chatForm = null;
                        _frmMain.Invoke(new Action(delegate()
                        {
                            if ((chatForm = IsShow(usernameTemp)) == null)
                            {
                                chatForm      = new Chat(this, usernameTemp);
                                chatForm.Text = usernameTemp;
                                //Command cmd = new Command(CommandType_.LoadMessage, usernameTemp, 0);
                                // this.SendCommand(cmd);
                                chatForm.Show();
                                listFormChat.Add(chatForm);
                            }
                        }));
                        chatForm.Receive(usernameTemp, cmdMetaData, temp);
                    }
                    if (cmt == CommandType_.LoginSuccess)
                    {
                        stream.Read(buffer, 0, 4);
                        int stt = BitConverter.ToInt32(buffer, 0);

                        byte[] dataPicture;
                        //đọc tên username
                        stream.Read(buffer, 0, 4);
                        int lenght = BitConverter.ToInt32(buffer, 0);
                        data = new byte[lenght];
                        stream.Read(data, 0, lenght);
                        string username = Encoding.ASCII.GetString(data);
                        this._userName = username;


                        //nhận email
                        stream.Read(buffer, 0, 4);
                        lenght = BitConverter.ToInt32(buffer, 0);
                        data   = new byte[lenght];
                        stream.Read(data, 0, lenght);
                        string email = Encoding.ASCII.GetString(data);


                        //đọc avatar
                        Image image;
                        stream.Read(buffer, 0, 4);
                        lenght      = BitConverter.ToInt32(buffer, 0);
                        dataPicture = new byte[lenght];
                        ReadBigData(stream, lenght, ref dataPicture);
                        MemoryStream mem = new MemoryStream(dataPicture);
                        image = Image.FromStream(mem);

                        //đọc status
                        stream.Read(buffer, 0, 4);
                        lenght = BitConverter.ToInt32(buffer, 0);
                        data   = new byte[lenght];
                        ReadBigData(stream, lenght, ref data);
                        string status = Encoding.UTF8.GetString(data);

                        //Đăng nhập thành công
                        //Khởi tạo form chính
                        //dangnhapForm.KillThreard();
                        if (_frmMain == null)
                        {
                            dangnhapForm.Invoke(new Action(delegate()
                            {
                                {
                                    _frmMain      = new Form1(dangnhapForm, 1, this._userName, email, image, status, this);
                                    _frmMain.Text = "Frozen";
                                    _frmMain.Show();
                                    dangnhapForm.Hide();
                                }
                            }));
                        }
                        Command cmd = new Command(CommandType_.ListFriend, this._userName);
                        this.SendCommand(cmd);
                        //load list friend
                        //đọc thông tin list Friend
                        //Thread.Sleep(2000);
                        //--Đọc số lượng friend của user
                    }//End LoginSuccess
                    if (cmt == CommandType_.ListFriend)
                    {
                        stream.Read(buffer, 0, 4);
                        int _CountTemp;
                        _CountTemp          = BitConverter.ToInt32(buffer, 0);
                        _frmMain.listFriend = new List <FriendList>();
                        for (int i = 0; i < _CountTemp; i++)
                        {
                            //đọc useer friend
                            //int a = _abc;
                            stream.Read(buffer, 0, 4);
                            int lenght = BitConverter.ToInt32(buffer, 0);
                            data = new byte[lenght];
                            stream.Read(data, 0, lenght);
                            string usernameFriend = Encoding.ASCII.GetString(data);



                            //đọc avatar friend
                            Image _avatarFriend;
                            stream.Read(buffer, 0, 4);
                            lenght = BitConverter.ToInt32(buffer, 0);
                            byte[] dataPicture = new byte[lenght];
                            ReadBigData(stream, lenght, ref dataPicture);
                            MemoryStream memTemp = new MemoryStream(dataPicture);
                            _avatarFriend = Image.FromStream(memTemp);


                            stream.Read(buffer, 0, 4);
                            lenght = BitConverter.ToInt32(buffer, 0);
                            data   = new byte[lenght];
                            ReadBigData(stream, lenght, ref data);
                            string _status = Encoding.UTF8.GetString(data);

                            //đọc trạng thái của friend này
                            stream.Read(buffer, 0, 4);
                            CommandType_ status = (CommandType_)BitConverter.ToInt32(buffer, 0);
                            FriendList   friendTemp;
                            if (status == CommandType_.Online)
                            {
                                friendTemp = new FriendList(usernameFriend, _avatarFriend, true, _status);
                            }
                            else
                            {
                                friendTemp = new FriendList(usernameFriend, _avatarFriend, false, _status);
                            }
                            _frmMain.listFriend.Add(friendTemp);
                        }
                        _frmMain.update_listFriend(true);
                    }
                    if (cmt == CommandType_.Found)
                    {
                        stream.Read(buffer, 0, 4);
                        int lenght = BitConverter.ToInt32(buffer, 0);
                        data = new byte[lenght];
                        stream.Read(data, 0, lenght);
                        string username = Encoding.ASCII.GetString(data);


                        stream.Read(buffer, 0, 4);
                        lenght = BitConverter.ToInt32(buffer, 0);
                        data   = new byte[lenght];
                        stream.Read(data, 0, lenght);
                        string email = Encoding.ASCII.GetString(data);

                        byte[] dataPicture;
                        //đọc avatar
                        Image image;
                        stream.Read(buffer, 0, 4);
                        lenght      = BitConverter.ToInt32(buffer, 0);
                        dataPicture = new byte[lenght];
                        ReadBigData(stream, lenght, ref dataPicture);
                        MemoryStream mem = new MemoryStream(dataPicture);
                        image = Image.FromStream(mem);
                        ff_Form.Found(username, email, image);
                    }
                    if (cmt == CommandType_.NotFound)
                    {
                        ff_Form.Notfound();
                    }
                    if (cmt == CommandType_.NameExists)
                    {
                        MessageCustom.Show("Tài khoản bạn đã được đang nhập bởi người khác!", "Thông báo", new Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))));
                        dangnhapForm.ChangePanel();
                    }
                    if (cmt == CommandType_.Failure)
                    {
                        MessageCustom.Show("Tài khoản hoặc mật khẩu không đúng!", "Error", new Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))));
                        dangnhapForm.ChangePanel();
                    }
                    if (cmt == CommandType_.RegisterFailure)
                    {
                        MessageCustom.Show("Tài khoản hoặc tên người dùng đã tồn tại!", "Thông báo", new Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))));
                    }
                    if (cmt == CommandType_.RegisterSuccess)
                    {
                        MessageCustom.Show("Đăng kí thành công!", "Thông báo", new Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))));
                    }
                    if (cmt == CommandType_.Online)
                    {
                        stream.Read(buffer, 0, 4);
                        int lenght = BitConverter.ToInt32(buffer, 0);
                        data = new byte[lenght];
                        stream.Read(data, 0, lenght);
                        string usernameFriend = Encoding.ASCII.GetString(data);
                        foreach (var s in _frmMain.listFriend)
                        {
                            if (s._userFriend == usernameFriend)
                            {
                                s.Status = true;
                            }
                        }
                        _frmMain.update_listFriend(true);
                    }
                    if (cmt == CommandType_.Offline)
                    {
                        stream.Read(buffer, 0, 4);
                        int lenght = BitConverter.ToInt32(buffer, 0);
                        data = new byte[lenght];
                        stream.Read(data, 0, lenght);
                        string usernameFriend = Encoding.ASCII.GetString(data);
                        foreach (var s in _frmMain.listFriend)
                        {
                            if (s._userFriend == usernameFriend)
                            {
                                s.Status = false;
                            }
                        }
                        _frmMain.update_listFriend(true);
                    }
                    //load toàn bộ thông báo
                    if (cmt == CommandType_.LoadNotice)
                    {
                        stream.Read(buffer, 0, 4);
                        int count = BitConverter.ToInt32(buffer, 0);
                        for (int i = 0; i < count; i++)
                        {
                            stream.Read(buffer, 0, 4);
                            int _stt = BitConverter.ToInt32(buffer, 0);

                            stream.Read(buffer, 0, 4);
                            int lenght = BitConverter.ToInt32(buffer, 0);
                            data = new byte[lenght];
                            stream.Read(data, 0, lenght);
                            string _userPrimary = Encoding.ASCII.GetString(data);

                            stream.Read(buffer, 0, 4);
                            lenght = BitConverter.ToInt32(buffer, 0);
                            data   = new byte[lenght];
                            stream.Read(data, 0, lenght);
                            string _userReference = Encoding.ASCII.GetString(data);

                            stream.Read(buffer, 0, 4);
                            lenght = BitConverter.ToInt32(buffer, 0);
                            data   = new byte[lenght];
                            stream.Read(data, 0, lenght);
                            string _type = Encoding.ASCII.GetString(data);

                            stream.Read(buffer, 0, 4);
                            lenght = BitConverter.ToInt32(buffer, 0);
                            data   = new byte[lenght];
                            stream.Read(data, 0, lenght);
                            string _content = Encoding.ASCII.GetString(data);

                            stream.Read(buffer, 0, 4);
                            lenght = BitConverter.ToInt32(buffer, 0);
                            data   = new byte[lenght];
                            stream.Read(data, 0, lenght);
                            string      _time      = Encoding.ASCII.GetString(data);
                            Notice_List noticeTemp = new Notice_List(_stt, _userPrimary, _userReference, _type, _time);
                            Notice_frm.listNotice.Add(noticeTemp);
                        }
                        Notice_frm.update_Notice(false);
                    }
                    if (cmt == CommandType_.DeleteNoticeSuccess)
                    {
                        Notice_frm.update_Notice(true);
                    }
                    if (cmt == CommandType_.AddNoticeSuccess)
                    {
                        ff_Form.AddNoticeSuccess();
                    }
                    if (cmt == CommandType_.AddNoticeFailure)
                    {
                        ff_Form.AddNoticeFailure();
                    }
                    if (cmt == CommandType_.AddFriendFailure)
                    {
                        ff_Form.AddFriendFailure();
                    }
                }
                catch
                {
                    if (_check)
                    {
                        MessageCustom.Show("Server đang bảo trì !", "Thông báo", new Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))));
                        socket.Close();
                        dangnhapForm.Client = null;
                    }
                }
            }//end while
        }
Beispiel #8
0
        public void bw_receive_DoWork(object sender, DoWorkEventArgs e)
        {
            byte[] buffer = new byte[4];

            while (socket.Connected)
            {
                try
                {
                    //đọc thông điệp server chuyễn đến
                    stream.Read(buffer, 0, 4);
                    CommandType_ cmt = (CommandType_)BitConverter.ToInt32(buffer, 0);
                    if (cmt == CommandType_.Message)
                    {
                        string cmdMetaData = "";
                        buffer = new byte[4];
                        //đọc nội dung tin nhắn
                        stream.Read(buffer, 0, 4);
                        int    lenght     = BitConverter.ToInt32(buffer, 0);
                        byte[] metaBuffer = new byte[lenght];
                        stream.Read(metaBuffer, 0, lenght);
                        cmdMetaData = Encoding.ASCII.GetString(metaBuffer);
                        //đọc font
                        stream.Read(buffer, 0, 4);
                        lenght     = BitConverter.ToInt32(buffer, 0);
                        metaBuffer = new byte[lenght];
                        stream.Read(metaBuffer, 0, lenght);
                        MemoryStream    s    = new MemoryStream(metaBuffer);
                        BinaryFormatter bf   = new BinaryFormatter();
                        Font            temp = new Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular);
                        temp = (Font)bf.Deserialize(s);
                        _frmMain.Invoke(new Action(delegate()
                        {
                            if (chatForm == null || chatForm.IsDisposed)
                            {
                                chatForm      = new Chat(this);
                                chatForm.Text = "Server";
                                chatForm.Show();
                            }
                        }));

                        chatForm.Receive(cmdMetaData, temp);
                    }//end message
                    if (cmt == CommandType_.LoginSuccess)
                    {
                        byte[] data;
                        byte[] dataPicture;
                        //đọc tên username
                        stream.Read(buffer, 0, 4);
                        int lenght = BitConverter.ToInt32(buffer, 0);
                        data = new byte[lenght];
                        stream.Read(data, 0, lenght);
                        string username = Encoding.ASCII.GetString(data);
                        this._userName = username;


                        //đọc avatar
                        Image image;
                        stream.Read(buffer, 0, 4);
                        lenght      = BitConverter.ToInt32(buffer, 0);
                        dataPicture = new byte[lenght];
                        stream.Read(dataPicture, 0, lenght);
                        MemoryStream mem = new MemoryStream(dataPicture);
                        image = Image.FromStream(mem);


                        //Đăng nhập thành công
                        //Khởi tạo form chính
                        dangnhapForm.Invoke(new Action(delegate()
                        {
                            {
                                _frmMain      = new Form1(dangnhapForm, this._userName, image);
                                _frmMain.Text = "Server";
                                _frmMain.Show();
                                dangnhapForm.Hide();
                            }
                        }));
                        //load list friend
                        //đọc thông tin list Friend

                        //--Đọc số lượng friend của user
                        stream.Read(buffer, 0, 4);
                        int _CountTemp;
                        _CountTemp = BitConverter.ToInt32(buffer, 0);
                        for (int i = 0; i < _CountTemp; i++)
                        {
                            stream.Read(buffer, 0, 4);
                            lenght = BitConverter.ToInt32(buffer, 0);
                            data   = new byte[lenght];
                            stream.Read(data, 0, lenght);
                            string usernameFriend = Encoding.ASCII.GetString(data);



                            //đọc avatar
                            Image _avatarFriend;
                            stream.Read(buffer, 0, 4);
                            lenght      = BitConverter.ToInt32(buffer, 0);
                            dataPicture = new byte[lenght];
                            stream.Read(dataPicture, 0, lenght);
                            MemoryStream memTemp = new MemoryStream(dataPicture);
                            _avatarFriend = Image.FromStream(memTemp);
                            _frmMain.update_listFriend(usernameFriend, _avatarFriend);
                        }
                    }//End LoginSuccess
                    if (cmt == CommandType_.NameExists)
                    {
                        MessageCustom.Show("Tài khoản bạn đã được đang nhập bởi người khác!", "Thông báo", new Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))));
                    }
                    if (cmt == CommandType_.Failure)
                    {
                        MessageCustom.Show("Tài khoản hoặc mật khẩu không đúng!", "Error", new Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))));
                    }
                    if (cmt == CommandType_.RegisterFailure)
                    {
                        MessageCustom.Show("Tài khoản hoặc tên người dùng đã tồn tại!", "Thông báo", new Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))));
                    }
                    if (cmt == CommandType_.RegisterSuccess)
                    {
                        MessageCustom.Show("Đăng kí thành công!", "Thông báo", new Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))));
                    }
                }
                catch
                {
                    MessageCustom.Show("Server đang bảo trì !", "Thông báo", new Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))));
                }
            }//end while
        }
Beispiel #9
0
        void Click_dangnhap()
        {
            panel1.Visible       = false;
            panel2.Visible       = true;
            progressBar1.Maximum = 100;
            progressBar1.Step    = 1;
            progressBar1.Value   = 0;
            //backgroundWorker = new BackgroundWorker();
            //backgroundWorker.DoWork+=backgroundWorker_DoWork;
            //backgroundWorker.WorkerReportsProgress = true;
            //backgroundWorker.WorkerSupportsCancellation = true;
            //backgroundWorker.ProgressChanged+=backgroundWorker_ProgressChanged;
            //backgroundWorker.RunWorkerAsync();
            this.txt_password._lost();
            this.txt_dangnhap._lost();
            if (txt_password.NullText == false || txt_dangnhap.NullText == false)
            {
                MessageCustom.Show("Vui lòng nhập tài khoản và mật khẩu \n chính xác  để đăng nhập! ", "Thông báo đăng nhập", new Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))));
                panel1.Visible = true;
                panel2.Visible = false;
            }
            else
            {
                try
                {
                    if (client == null)
                    {
                        socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                        IPep   = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9999);
                        socket.Connect(IPep);
                        client = new ClientManager(this, socket);
                        stream = new NetworkStream(socket);
                    }

                    byte[] buffer = new byte[4];
                    buffer = BitConverter.GetBytes((int)CommandType_.Login);
                    stream.Write(buffer, 0, 4);
                    stream.Flush();

                    buffer = BitConverter.GetBytes(txt_dangnhap.Text.Length);
                    stream.Write(buffer, 0, 4);
                    stream.Flush();
                    byte[] data = new byte[txt_dangnhap.Text.Length];
                    data = Encoding.ASCII.GetBytes(txt_dangnhap.Text);
                    stream.Write(data, 0, txt_dangnhap.Text.Length);
                    stream.Flush();

                    buffer = BitConverter.GetBytes(txt_password.Text.Length);
                    stream.Write(buffer, 0, 4);
                    stream.Flush();
                    data = new byte[txt_password.Text.Length];
                    data = Encoding.ASCII.GetBytes(txt_password.Text);
                    stream.Write(data, 0, txt_password.Text.Length);
                    stream.Flush();
                }
                catch
                {
                    MessageCustom.Show("Server đang bảo trì. \nVui lòng đăng nhập lại sau. ", "Thông báo đăng nhập", new Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))));
                    panel1.Visible = true;
                    panel2.Visible = false;
                }
            }
        }
Beispiel #10
0
 private void bbt_register_Click(object sender, EventArgs e)
 {
     if (txt_account.Text.Length < 8 || txt_password.Text.Length < 8 || txt_username.Text.Length < 8)
     {
         MessageCustom.Show("Độ dài tên người dùng hoặc tài khoản \n ,mật khẩu phải lớn hơn 8 kí tự!", "Thông báo", new Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))));
     }
     else
     {
         if (txt_password.Text != txt_confirm.Text)
         {
             MessageCustom.Show("Mật khẩu xác nhận không đúng", "Thông báo", new Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))));
         }
         else
         {
             try
             {
                 NetworkStream stream = new NetworkStream(socket);
                 byte[]        buffer = new byte[4];
                 //sen command type
                 buffer = BitConverter.GetBytes((int)CommandType_.Register);
                 stream.Write(buffer, 0, 4);
                 stream.Flush();
                 //send username
                 buffer = BitConverter.GetBytes(txt_username.Text.Length);
                 stream.Write(buffer, 0, 4);
                 stream.Flush();
                 byte[] data = new byte[txt_username.Text.Length];
                 data = Encoding.ASCII.GetBytes(txt_username.Text);
                 stream.Write(data, 0, txt_username.Text.Length);
                 stream.Flush();
                 //send account
                 buffer = BitConverter.GetBytes(txt_account.Text.Length);
                 stream.Write(buffer, 0, 4);
                 stream.Flush();
                 data = new byte[txt_account.Text.Length];
                 data = Encoding.ASCII.GetBytes(txt_account.Text);
                 stream.Write(data, 0, txt_account.Text.Length);
                 stream.Flush();
                 //send password
                 buffer = BitConverter.GetBytes(txt_password.Text.Length);
                 stream.Write(buffer, 0, 4);
                 stream.Flush();
                 data = new byte[txt_password.Text.Length];
                 data = Encoding.ASCII.GetBytes(txt_password.Text);
                 stream.Write(data, 0, txt_password.Text.Length);
                 stream.Flush();
                 //sen email
                 buffer = BitConverter.GetBytes(txt_email.Text.Length);
                 stream.Write(buffer, 0, 4);
                 stream.Flush();
                 data = new byte[txt_email.Text.Length];
                 data = Encoding.ASCII.GetBytes(txt_email.Text);
                 stream.Write(data, 0, txt_email.Text.Length);
                 stream.Flush();
             }
             catch
             {
                 MessageCustom.Show("Server đang bảo trì,không thể đăng kí!", "Thông báo", new Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))));
             }
         }
     }
 }
Beispiel #11
0
 void SendMessage()
 {
     if (_client.socket.Connected)
     {
         rTB_content.Text = rTB_content.Text.Trim();
         if (rTB_content.Text != "\n" && rTB_content.Text != "")
         {
             //chưa gởi hoặc đã nhận thì gởi message
             if (_bSend && _bRecive)//chưa gởi và chưa nhận
             {
                 string _time = DateTime.Now.ToString();
                 Button a     = new Button();
                 a.Width     = 490;
                 a.Text      = _time;
                 a.BackColor = System.Drawing.Color.Transparent;
                 a.Dock      = DockStyle.None;
                 a.FlatAppearance.BorderSize = 0;
                 a.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
                 a.Enabled   = false;
                 flp_messeage.Controls.Add(a);
             }
             if (_bSend)
             {
                 Messeage ms = new Messeage(_client.userName, rTB_content.Text, _fontMessage);
                 ms.Anchor = AnchorStyles.Right;
                 flp_messeage.Controls.Add(ms);
                 _fontMessage = rTB_content.Font;
                 flp_messeage.ScrollControlIntoView(ms);
                 _bSend   = false;//đã send và chưa nhận
                 _bRecive = true;
                 MessageText mst = new MessageText(rTB_content.Text, _fontMessage, 1);
                 listmessage.AddLast(mst);
             }
             else
             {
                 Message1 ms = new Message1(rTB_content.Text, _fontMessage);
                 ms.Anchor = AnchorStyles.Right;
                 flp_messeage.Controls.Add(ms);
                 _fontMessage = rTB_content.Font;
                 flp_messeage.ScrollControlIntoView(ms);
                 //int a = flp_messeage.VerticalScroll.Value;
                 MessageText mst = new MessageText(rTB_content.Text, _fontMessage, 1);
                 listmessage.AddLast(mst);
             }
             if (_usernameReference == "Server")
             {
                 Command cmd = new Command(Enum.CommandType_.Message, rTB_content.Text, _fontMessage);
                 _client.SendCommand(cmd);
             }
             else
             {
                 Command cmd = new Command(Enum.CommandType_.MessageFriend, this._usernameReference, rTB_content.Text, _fontMessage);
                 _client.SendCommand(cmd);
             }
             rTB_content.Text = "";
         }
         else
         {
             rTB_content.Text = "";
         }
     }
     else
     {
         MessageCustom.Show("Kết nối với client đã bị đóng!", "Thông báo", new Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))));
     }
 }