Esempio n. 1
0
        public void RefreshChat()
        {
            dtnew  = new DataTable();
            LastID = 0;
            try
            {
                string lastUser = "";
                panChat.Controls.Clear();
                //ChatItem None = new ChatItem();
                //None.BackColor = None.edtText.BackColor = Color.Snow;
                //panChat.Controls.Add(None);
                dt = DHuy.SELECT_SQL("SELECT * FROM CHAT WHERE USERCODE = '" + Control_Remote + "' ORDER BY ID ASC ");

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    String type = DBase.StringReturn(dt.Rows[i]["TYPE"]);

                    if (type == "")
                    {
                        ChatItem C = new ChatItem();
                        C.Width = panChat.Width;
                        C.M     = this;
                        C.ID    = DBase.IntReturn(dt.Rows[i]["ID"]);
                        String   DataNick    = DBase.StringReturn(dt.Rows[i]["NICKNAME"]) + " ";
                        String   ColorString = "";
                        String   Text        = DBase.StringReturn(dt.Rows[i]["TEXT"]);
                        DateTime cdatetime   = DBase.DatetimeReturn(dt.Rows[i]["CDATETIME"]);

                        if (curNick == DataNick)
                        {
                            //  C.edtUserCode.ForeColor = C.edtUserCode.BackColor;
                            //  C.edtIcon.Visible = false;
                            ////  else C.edtUserCode.ForeColor = Color.Blue;
                            colorIndex++;
                            //  C.edtIcon.Visible = true;
                            if (colorIndex == C.L.Count)
                            {
                                colorIndex = 0;
                            }
                            //   C.edtUserCode.ForeColor = Color.Blue;
                        }
                        else
                        {
                            colorIndex++;
                            //  C.edtIcon.Visible = true;
                            if (colorIndex == C.L.Count)
                            {
                                colorIndex = 0;
                            }
                            //   C.edtUserCode.ForeColor = Color.Blue;
                        }

                        curNick = DataNick;

                        C.BackColor = C.edtText.BackColor = C.L[colorIndex];

                        //   C.edtUserCode.Text = DataNick + ":";
                        C.edtText.Text = DataNick + ": " + Text + "  ( " + cdatetime.ToString("dd/MM HH:mm") + " )";
                        if (ColorString == "RED")
                        {
                            // C.BackColor = Color.Pink;
                            C.edtText.BackColor = Color.Pink;
                        }
                        else if (ColorString == "GREEN")
                        {
                            C.BackColor         = Color.Honeydew;
                            C.edtText.BackColor = Color.Honeydew;
                        }

                        panChat.Controls.Add(C);
                    }

                    else if (type.ToUpper() == ".JPG" || type.ToUpper() == ".BMP" || type.ToUpper() == ".PNG" || type.ToUpper() == ".GIF")
                    {
                        try
                        {
                            String         FileName = DBase.StringReturn(dt.Rows[i]["FILENAME"]);
                            Image          I        = DBase.ByteToImage((byte[])dt.Rows[i]["THUMBNAIL"]);
                            ChatItem_Image C        = new ChatItem_Image(I, FileName);

                            C.M  = this;
                            C.ID = DBase.IntReturn(dt.Rows[i]["ID"]);
                            DateTime cdatetime = DBase.DatetimeReturn(dt.Rows[i]["CDATETIME"]);

                            panChat.Controls.Add(C);
                        }
                        catch (Exception ex) { }
                    }

                    else if (type != "")
                    {
                        try
                        {
                            String FileName = DBase.StringReturn(dt.Rows[i]["FILENAME"]);
                            Image  I        = null;
                            try
                            {
                                I = DBase.ByteToImage((byte[])dt.Rows[i]["THUMBNAIL"]);
                            }
                            catch (Exception ex) { }
                            ChatItem_Files C = new ChatItem_Files(type, FileName, I);

                            C.M  = this;
                            C.ID = DBase.IntReturn(dt.Rows[i]["ID"]);
                            DateTime cdatetime = DBase.DatetimeReturn(dt.Rows[i]["CDATETIME"]);

                            panChat.Controls.Add(C);
                        }
                        catch (Exception ex) { }
                    }
                }

                //ChatItem C2 = new ChatItem();

                //panChat.Controls.Add(C2);

                panChat.VerticalScroll.Value = panChat.VerticalScroll.Maximum;
            }
            catch (Exception ex) { }
        }
Esempio n. 2
0
        public void RefreshChat_Append()
        {
            try
            {
                if (dt.Rows.Count > 0)
                {
                    LastID = DBase.IntReturn(dt.Rows[dt.Rows.Count - 1]["ID"]);
                }
                else
                {
                    LastID = 0;
                }
                if (dtnew.Rows.Count > 0)
                {
                    LastID = DBase.IntReturn(dtnew.Rows[dtnew.Rows.Count - 1]["ID"]);
                }
                dtnew = DHuy.SELECT_SQL("SELECT * FROM CHAT WHERE ID > @DATE1 AND USERCODE = '" + Control_Remote + "' ORDER BY ID ASC ", LastID.ToString());
                for (int i = 0; i < dtnew.Rows.Count; i++)
                {
                    String type = DBase.StringReturn(dtnew.Rows[i]["TYPE"]);
                    if (type == "")
                    {
                        ChatItem C = new ChatItem();
                        C.Width = panChat.Width;
                        C.M     = this;
                        C.ID    = DBase.IntReturn(dtnew.Rows[i]["ID"]);
                        String DataNick = DBase.StringReturn(dtnew.Rows[i]["NICKNAME"]) + " ";

                        String   Text      = DBase.StringReturn(dtnew.Rows[i]["TEXT"]);
                        DateTime cdatetime = DBase.DatetimeReturn(dtnew.Rows[i]["CDATETIME"]);

                        if (curNick == DataNick)
                        {
                            //C.edtUserCode.ForeColor = C.edtUserCode.BackColor;
                            //C.edtIcon.Visible = false;
                            ////  else C.edtUserCode.ForeColor = Color.Blue;

                            colorIndex++;
                            //  C.edtIcon.Visible = true;
                            if (colorIndex == C.L.Count)
                            {
                                colorIndex = 0;
                            }
                            // C.edtUserCode.ForeColor = Color.Blue;
                        }
                        else
                        {
                            colorIndex++;
                            //  C.edtIcon.Visible = true;
                            if (colorIndex == C.L.Count)
                            {
                                colorIndex = 0;
                            }
                            //  C.edtUserCode.ForeColor = Color.Blue;
                        }

                        curNick = DataNick;

                        C.BackColor = C.edtText.BackColor = C.L[colorIndex];

                        //   C.edtUserCode.Text = DataNick + ":";
                        C.edtText.Text = DataNick + ": " + Text + "  ( " + cdatetime.ToString("dd/MM HH:mm") + " )";

                        panChat.Controls.Add(C);
                    }

                    else if (type.ToUpper() == ".JPG" || type.ToUpper() == ".BMP" || type.ToUpper() == ".PNG" || type.ToUpper() == ".GIF")
                    {
                        try
                        {
                            String         FileName = DBase.StringReturn(dtnew.Rows[i]["FILENAME"]);
                            Image          I        = DBase.ByteToImage((byte[])dtnew.Rows[i]["THUMBNAIL"]);
                            ChatItem_Image C        = new ChatItem_Image(I, FileName);

                            C.M  = this;
                            C.ID = DBase.IntReturn(dt.Rows[i]["ID"]);
                            DateTime cdatetime = DBase.DatetimeReturn(dtnew.Rows[i]["CDATETIME"]);

                            panChat.Controls.Add(C);
                        }
                        catch (Exception ex) { }
                    }

                    else if (type != "")
                    {
                        try
                        {
                            String FileName = DBase.StringReturn(dtnew.Rows[i]["FILENAME"]);
                            Image  I        = null;
                            try
                            {
                                I = DBase.ByteToImage((byte[])dtnew.Rows[i]["THUMBNAIL"]);
                            }
                            catch (Exception ex) { }
                            ChatItem_Files C = new ChatItem_Files(type, FileName, I);

                            C.M  = this;
                            C.ID = DBase.IntReturn(dtnew.Rows[i]["ID"]);
                            DateTime cdatetime = DBase.DatetimeReturn(dtnew.Rows[i]["CDATETIME"]);

                            panChat.Controls.Add(C);
                        }
                        catch (Exception ex) { }
                    }
                }

                if (dtnew.Rows.Count > 0)
                {
                    dt.Merge(dtnew);
                    panChat.VerticalScroll.Value = panChat.VerticalScroll.Maximum;
                }
            }
            catch (Exception ex) { }
        }