示例#1
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) { }
        }