Exemple #1
0
        private void Frame_Load(object sender, EventArgs e)
        {
            this.lbUserName.Text    = User.firstName + " " + User.lastName;
            this.pbUserAvatar.Image = ChatAppUtils.ByteToImage(User.avatar);

            PnlConversation1.AutoScroll    = false;
            PnlConversation2.AutoScroll    = false;
            PnlConversation1.WrapContents  = false;
            PnlConversation2.WrapContents  = false;
            PnlConversation1.AutoSize      = true;
            PnlConversation2.AutoSize      = true;
            PnlConversation1.FlowDirection = FlowDirection.TopDown;
            PnlConversation2.FlowDirection = FlowDirection.BottomUp;
            pnlConversations.flowLayoutPanel.Controls.Add(PnlConversation2);
            pnlConversations.flowLayoutPanel.Controls.Add(PnlConversation1);
            pnlConversations.UpdateUi();

            this.pnlPages.Controls.Clear();
            WelcomeBox welcomeBox = new WelcomeBox(User);

            this.pnlPages.Controls.Add(welcomeBox);
            welcomeBox.BtnconversationClick(btnAddNewChat_Click);
            welcomeBox.Location = new Point(0, 0);
            Client.startReadResponse(new ReadResponseHandler(this));
        }
Exemple #2
0
        private void initUi()
        {
            unReadMessage.Visible = false;
            if (!Cvst.state && Cvst.memberList.Count == 2)
            {
                this.btnState.FillColor = System.Drawing.Color.LightSteelBlue;
            }
            if (Cvst.creatorId != Acc.id && Cvst.memberList.Count == 2)
            {
                foreach (var mb in Cvst.memberList)
                {
                    if (mb.id == Cvst.creatorId)
                    {
                        this.lbTitle.Text   = mb.firstName + " " + mb.lastName;
                        this.pbAvatar.Image = ChatAppUtils.ByteToImage(mb.avatar);
                        break;
                    }
                }
            }
            else
            {
                this.lbTitle.Text = Cvst.title;
                if (Cvst.avatar != null)
                {
                    this.pbAvatar.Image = ChatAppUtils.ByteToImage(Cvst.avatar);
                }
            }
            DateTime time = (DateTime)Cvst.createdAt;

            this.lbDate.Text = time.ToString("HH:mm dd/MM/yyyy");
        }
Exemple #3
0
        private void btnChooseAllFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog chooseFileDialog = new OpenFileDialog()
            {
                Filter = "Image files (*.*) | *.*",
                Title  = "Chọn một file"
            };

            chooseFileDialog.ShowDialog();
            if (!chooseFileDialog.FileName.Equals(""))
            {
                byte[]   file        = ChatAppUtils.ConvertFileToByte(chooseFileDialog.FileName);
                string[] arrFileName = chooseFileDialog.FileName.Split('\\');
                string   fn          = arrFileName[arrFileName.Length - 1];
                if (FileItem != null)
                {
                    this.Controls.Remove(FileItem);
                    FileItem = null;
                }
                FileItem = new FileItem(fn, file);
                this.Controls.Add(FileItem);
                FileItem.Location = new Point(25, 386);
                FileItem.BringToFront();
                FileItem.ButtonCloseClick(closeFileItem);
            }
            this.txtMessage.Focus();
        }
Exemple #4
0
        public List <ReferenceData.Entity.Account> SearchAccount(string keyword)
        {
            List <ReferenceData.Entity.Account> list = null;
            var resultSet = db.Usp_SearchAccountByEmailOrName(keyword).ToList();

            if (resultSet.Count > 0)
            {
                string imagesFolder = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + @"\Files\Images\";
                list = new List <ReferenceData.Entity.Account>();
                foreach (var a in resultSet)
                {
                    ReferenceData.Entity.Account acc = new ReferenceData.Entity.Account();
                    acc.id        = (int)a.id;
                    acc.email     = a.email;
                    acc.password  = a.password;
                    acc.firstName = a.firstName;
                    acc.lastName  = a.lastName;
                    acc.birthday  = a.birthday;
                    acc.createdAt = a.createdAt;
                    acc.avatar    = ChatAppUtils.ConvertFileToByte(imagesFolder + a.avatar);
                    list.Add(acc);
                }
            }
            return(list);
        }
 public SearchResult(Account acc)
 {
     InitializeComponent();
     Account             = acc;
     this.pbAvatar.Image = ChatAppUtils.ByteToImage(acc.avatar);
     this.lbInfo.Text    = acc.email;
     this.lbTitle.Text   = acc.firstName + " " + acc.lastName;
 }
 public IncomingMessage(byte[] avatar, int userId, string userName, DateTime time)
 {
     InitializeComponent();
     UList  = new List <UserControl>();
     Time   = time;
     UserId = userId;
     this.userAvatar.Image = ChatAppUtils.ByteToImage(avatar);
     this.info.Text        = userName + " - " + Time.ToString("HH:mm dd/MM/yyyy");
 }
 public void send(object obj)
 {
     try
     {
         ClientSocket.Send(ChatAppUtils.Serialize(obj));
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         ClientSocket.Close();
     }
 }
Exemple #8
0
        public List <ReferenceData.Entity.Conversation> GetConversationListOfAccount(int accId)
        {
            var resultSet = db.Usp_GetConversationsByUserId(accId).ToList();
            List <ReferenceData.Entity.Conversation> list = null;

            if (resultSet.Count > 0)
            {
                list = new List <ReferenceData.Entity.Conversation>();
                string imagesFolder = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + @"\Files\Images\";
                foreach (var c in resultSet)
                {
                    ReferenceData.Entity.Conversation cvst = new ReferenceData.Entity.Conversation();
                    cvst.id          = c.id;
                    cvst.creatorId   = c.creatorId;
                    cvst.senderId    = c.senderId;
                    cvst.messageType = c.messageType;
                    cvst.content     = c.content;
                    cvst.title       = c.title;
                    cvst.memberList  = new AccountDAO().GetAccountByConversationId(cvst.id);
                    if (cvst.memberList != null)
                    {
                        if (cvst.memberList.Count > 2)
                        {
                            cvst.state  = true;
                            cvst.avatar = ChatAppUtils.ConvertFileToByte(imagesFolder + c.avatar);
                        }
                        else
                        {
                            foreach (var u in cvst.memberList)
                            {
                                if (u.id != accId)
                                {
                                    foreach (var onl in onlineList)
                                    {
                                        if (onl.Acc.Equals(u))
                                        {
                                            cvst.state = true;
                                            break;
                                        }
                                    }
                                    cvst.title  = u.firstName + " " + u.lastName;
                                    cvst.avatar = u.avatar;
                                }
                            }
                        }
                    }
                    cvst.createdAt = c.createdAt;
                    list.Add(cvst);
                }
            }
            return(list);
        }
Exemple #9
0
 public void send(object obj)
 {
     if (IsConnected)
     {
         try
         {
             Socket.Send(ChatAppUtils.Serialize(obj));
         } catch (Exception ex)
         {
             Console.WriteLine(ex);
         }
     }
 }
Exemple #10
0
 private void Setting_Load(object sender, EventArgs e)
 {
     this.pbAvatar.Image  = ChatAppUtils.ByteToImage(form.User.avatar);
     this.lbFullName.Text = form.User.firstName + " " + form.User.lastName;
     this.lbEmail.Text    = form.User.email;
     if (form.User.birthday != null)
     {
         DateTime birthday = (DateTime)form.User.birthday;
         this.lbBirthday.Text = birthday.ToString("dd/MM/yyyy");
     }
     else
     {
         this.lbBirthday.Text = "Thêm ngày sinh";
     }
 }
Exemple #11
0
 public SocketData receive()
 {
     byte[] data = new byte[79000000];
     if (IsConnected)
     {
         try
         {
             Socket.Receive(data);
         }catch (Exception ex)
         {
             Console.WriteLine(ex);
         }
     }
     return((SocketData)ChatAppUtils.Deserialize(data));
 }
Exemple #12
0
        private void btnChangeAvatar_Click(object sender, EventArgs e)
        {
            OpenFileDialog choosePictureDialog = new OpenFileDialog()
            {
                Filter = "Image files (*.png;*.jpg;*.jpeg;*.gif) | *.png;*.jpg;*.jpeg;*.gif",
                Title  = "Chọn một file ảnh"
            };

            choosePictureDialog.ShowDialog();
            if (!choosePictureDialog.FileName.Equals(""))
            {
                Account acc = form.User;
                acc.avatar = ChatAppUtils.ConvertFileToByte(choosePictureDialog.FileName);
                new UpdateAccountHandler(form.Client).Handle(acc);
            }
        }
Exemple #13
0
 public void SuccessUpdate(Account acc)
 {
     if (Setting != null)
     {
         Setting.lbEmail.Text    = acc.email;
         Setting.lbFullName.Text = acc.firstName + " " + acc.lastName;
         if (acc.birthday != null)
         {
             DateTime birthday = (DateTime)acc.birthday;
             Setting.lbBirthday.Text = birthday.ToString("dd/MM/yyyy");
         }
         Setting.pbAvatar.Image = ChatAppUtils.ByteToImage(acc.avatar);
     }
     this.pbUserAvatar.Image = ChatAppUtils.ByteToImage(acc.avatar);
     this.lbUserName.Text    = acc.firstName + " " + acc.lastName;
 }
        private void btnChangeAvatar_Click(object sender, EventArgs e)
        {
            OpenFileDialog choosePictureDialog = new OpenFileDialog()
            {
                Filter = "Image files (*.png;*.jpg;*.jpeg;*.gif) | *.png;*.jpg;*.jpeg;*.gif",
                Title  = "Chọn một file ảnh"
            };

            choosePictureDialog.ShowDialog();
            if (!choosePictureDialog.FileName.Equals(""))
            {
                Avatar = ChatAppUtils.ConvertFileToByte(choosePictureDialog.FileName);
                string[] arrFileName = choosePictureDialog.FileName.Split('\\');
                AvatarName          = arrFileName[arrFileName.Length - 1];
                pbGroupAvatar.Image = ChatAppUtils.ByteToImage(Avatar);
            }
        }
        public SocketData receive()
        {
            byte[] data = new byte[79000000];
            try
            {
                ClientSocket.Receive(data);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                ClientSocket.Close();
            }
            SocketData d = (SocketData)ChatAppUtils.Deserialize(data);

            if (d == null)
            {
                return(new SocketData("NULLDATA", null));
            }
            return(d);
        }
Exemple #16
0
        public List <ReferenceData.Entity.Message> GetMessagesByConversationId(string conversationId, int offset, int limit)
        {
            string imagesFolder = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + @"\Files\Images\";
            string otherFolder  = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + @"\Files\Another_Files\";
            var    resultSet    = db.Usp_GetMessagesByConversationId(conversationId, offset, limit).ToList();
            List <ReferenceData.Entity.Message> list = null;

            if (resultSet.Count > 0)
            {
                list = new List <ReferenceData.Entity.Message>();
                foreach (var m in resultSet)
                {
                    ReferenceData.Entity.Message message = new ReferenceData.Entity.Message();
                    message.id             = m.id;
                    message.conversationId = m.conversationId;
                    message.senderId       = m.senderId;
                    message.content        = m.content;
                    message.messageType    = m.messageType;
                    if (m.messageType.Equals("FILE"))
                    {
                        if (getFileType(m.content).Equals("IMAGE"))
                        {
                            message.file = ChatAppUtils.ConvertFileToByte(imagesFolder + m.content);
                        }
                        else
                        {
                            message.file = ChatAppUtils.ConvertFileToByte(otherFolder + m.content);
                        }
                    }
                    message.createdAt = m.createdAt;
                    message.firstName = m.firstName;
                    message.lastName  = m.lastName;
                    message.avatar    = ChatAppUtils.ConvertFileToByte(imagesFolder + m.avatar);
                    list.Add(message);
                }
            }
            return(list);
        }
Exemple #17
0
        public ReferenceData.Entity.Account GetAccountBySignInInfo(string email, string password)
        {
            var list = db.Usp_GetAccountBySignInInfo(email, password).ToList();

            ReferenceData.Entity.Account acc = null;
            if (list.Count > 0)
            {
                string imagesFolder = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + @"\Files\Images\";
                acc = new ReferenceData.Entity.Account();
                foreach (var u in list)
                {
                    acc.id        = u.id;
                    acc.email     = u.email;
                    acc.password  = u.password;
                    acc.firstName = u.firstName;
                    acc.lastName  = u.lastName;
                    acc.avatar    = ChatAppUtils.ConvertFileToByte(imagesFolder + u.avatar);
                    acc.birthday  = u.birthday;
                    acc.createdAt = u.createdAt;
                }
            }
            return(acc);
        }
        public FileItem(string fileName, byte[] file)
        {
            File     = file;
            FileName = fileName;
            InitializeComponent();
            string[] arrFileName = fileName.Split('.');
            string   ex          = arrFileName[arrFileName.Length - 1].ToUpper();

            if (ex.Equals("JPG") || ex.Equals("JPEG") || ex.Equals("PNG") || ex.Equals("GIF"))
            {
                this.file.Size     = new Size(120, 90);
                this.file.Location = new Point(5, 5);
                this.file.Image    = ChatAppUtils.ByteToImage(File);
                this.file.SendToBack();
                this.lbFileName.Visible = false;
                this.lbFileSize.Visible = false;
            }
            else
            {
                this.lbFileName.Text = FileName;
                this.lbFileSize.Text = getFileSize(File);
            }
        }
Exemple #19
0
 public FileBubble(string fileName, byte[] file, msgType type)
 {
     InitializeComponent();
     string[] fileInfo = getFileInfo(fileName);
     FileName = fileInfo[0] + fileInfo[1].ToLower();
     Files    = file;
     if (type.ToString() == "Out")
     {
         this.pnlBubble.Location = new Point(457 - (pnlBubble.Width + 20), 0);
     }
     if (fileInfo[1].Equals(".JPG") || fileInfo[1].Equals(".JPEG") || fileInfo[1].Equals(".PNG") || fileInfo[1].Equals(".GIF"))
     {
         this.picture.Size     = new Size(230, 130);
         this.picture.Location = new Point(10, 10);
         this.picture.Image    = ChatAppUtils.ByteToImage(Files);
         this.fileName.Visible = false;
         this.fileSize.Visible = false;
     }
     else
     {
         this.fileName.Text = FileName;
         this.fileSize.Text = getFileSize(Files);
     }
 }
 private void GroupMember_Load(object sender, EventArgs e)
 {
     lbUserName.Text = Acc.lastName;
     pbAvatar.Image  = ChatAppUtils.ByteToImage(Acc.avatar);
 }
 private void genarate()
 {
     this.lbWelcome.Text   = "Xin chào " + user.lastName;
     this.userAvatar.Image = ChatAppUtils.ByteToImage(user.avatar);
 }