Esempio n. 1
0
        private void FillMessageThread()
        {
            List <WebChatMessage>   listWebChatMessages = WebChatMessages.GetAllForSessions(_webChatSession.WebChatSessionNum);
            List <SmsThreadMessage> listThreadMessages  = new List <SmsThreadMessage>();

            foreach (WebChatMessage webChatMessage in listWebChatMessages)
            {
                string strMsg = webChatMessage.MessageText;
                if (webChatMessage.MessageType == WebChatMessageType.EndSession)
                {
                    strMsg = MarkupEdit.ConvertToPlainText(strMsg);
                }
                SmsThreadMessage msg = new SmsThreadMessage(webChatMessage.DateT,
                                                            strMsg,
                                                            (webChatMessage.MessageType == WebChatMessageType.Customer),
                                                            false,
                                                            false,
                                                            webChatMessage.UserName
                                                            );
                listThreadMessages.Add(msg);
            }
            webChatThread.ListSmsThreadMessages = listThreadMessages;
        }
Esempio n. 2
0
 public static int CompareMessages(SmsThreadMessage msg1, SmsThreadMessage msg2)
 {
     return(msg1.MsgDateTime.CompareTo(msg2.MsgDateTime));
 }
Esempio n. 3
0
        private void FillMessageThread()
        {
            //Clear controls and reset navigation bars.
            panelScroll.Controls.Clear();
            panelNavigation.Visible = false;
            panelScroll.Location    = new Point(0, 0);
            Invalidate();
            if (_listSmsThreadMessages == null || _listSmsThreadMessages.Count < 1)
            {
                return;
            }
            BuildListMessages();
            int     bodyWidth        = panelScroll.Width - SystemInformation.VerticalScrollBarWidth;
            int     verticalPadding  = 5;
            int     horizontalMargin = (int)(bodyWidth * 0.02);
            int     y = 0;
            Control controlHighlighted = null;

            panelScroll.SuspendLayout();
            for (int i = 0; i < _listSmsThreadToDisplay.Count; i++)
            {
                SmsThreadMessage msg = _listSmsThreadToDisplay[i];
                y += verticalPadding;
                Label labelMessageHeader = new Label();
                SetDoubleBuffered(labelMessageHeader, true);
                //labelMessageHeader.MouseWheel+=MouseWheel_Scroll;//Labels automatically pass their scroll events through to their parent controls.
                labelMessageHeader.Name = "labelMessageHeader" + i;
                labelMessageHeader.Text = ((msg.UserName == null)?"":(msg.UserName + "  ")) + msg.MsgDateTime.ToString();
                if (msg.IsAlignedLeft)
                {
                    labelMessageHeader.TextAlign = ContentAlignment.MiddleLeft;
                }
                else                  //Aligned right
                {
                    labelMessageHeader.TextAlign = ContentAlignment.MiddleRight;
                }
                Size textSize = TextRenderer.MeasureText(labelMessageHeader.Text, panelScroll.Font,
                                                         new Size(bodyWidth, Int32.MaxValue), TextFormatFlags.WordBreak | TextFormatFlags.TextBoxControl);
                labelMessageHeader.Width    = bodyWidth;
                labelMessageHeader.Height   = textSize.Height + 2;          //Extra vertical padding to ensure that the text will fit when including the border.
                labelMessageHeader.Location = new Point(0, y);
                panelScroll.Controls.Add(labelMessageHeader);
                y += labelMessageHeader.Height;
                TextBox textBoxMessage = new TextBox();
                SetDoubleBuffered(textBoxMessage, true);
                textBoxMessage.MouseWheel += MouseWheel_Scroll;              //Textboxes handle their own scroll events, because they have their own scroll bars.
                textBoxMessage.Font        = panelScroll.Font;
                textBoxMessage.BackColor   = msg.BackColor;
                if (msg.IsHighlighted)
                {
                    controlHighlighted = textBoxMessage;
                }
                if (msg.IsImportant)
                {
                    textBoxMessage.ForeColor = Color.Red;
                }
                textBoxMessage.Name        = "textSmsThreadMsg" + i;
                textBoxMessage.BorderStyle = BorderStyle.FixedSingle;
                textBoxMessage.Multiline   = true;
                textBoxMessage.Text        = msg.Message.Replace("\r\n", "\n").Replace("\n", "\r\n");     //Normalize \n coming from RichTextBox to \r\n for TextBox.
                //Each message wraps horizontally.
                textSize = TextRenderer.MeasureText(textBoxMessage.Text, panelScroll.Font,
                                                    new Size((int)(bodyWidth * 0.7), Int32.MaxValue), TextFormatFlags.WordBreak | TextFormatFlags.TextBoxControl);
                textBoxMessage.Width    = textSize.Width + 4;         //Extra horizontal padding to ensure that the text will fit when including the border.
                textBoxMessage.Height   = textSize.Height + 4;        //Extra vertical padding to ensure that the text will fit when including the border.
                textBoxMessage.ReadOnly = true;
                if (msg.IsAlignedLeft)
                {
                    textBoxMessage.Location = new Point(horizontalMargin, y);
                }
                else                  //Right aligned
                {
                    textBoxMessage.Location = new Point(bodyWidth - horizontalMargin - textBoxMessage.Width, y);
                }
                panelScroll.Controls.Add(textBoxMessage);
                y += textBoxMessage.Height;
            }
            Label labelBottomSpacer = new Label();

            SetDoubleBuffered(labelBottomSpacer, true);
            //labelBottomSpacer.MouseWheel+=MouseWheel_Scroll;//Labels automatically pass their scroll events through to their parent controls.
            labelBottomSpacer.Name     = "labelBottomSpacer";
            labelBottomSpacer.Width    = bodyWidth;
            labelBottomSpacer.Height   = verticalPadding;
            labelBottomSpacer.Location = new Point(0, y);
            panelScroll.Controls.Add(labelBottomSpacer);
            y += labelBottomSpacer.Height;
            if (controlHighlighted == null)
            {
                controlHighlighted = labelBottomSpacer;
            }
            if (panelScroll.VerticalScroll.Value != panelScroll.VerticalScroll.Maximum)
            {
                panelScroll.VerticalScroll.Value = panelScroll.VerticalScroll.Maximum;               //scroll to the end first then scroll to control
            }
            panelScroll.ResumeLayout();
            panelScroll.ScrollControlIntoView(controlHighlighted);            //Scroll to highlighted control, or if none highlighted, then scroll to the end.
        }