Пример #1
0
        private static void HandleServerResponse(object sender, UploadValuesCompletedEventArgs e)
        {
            Communicating = false;
            if (e.Error != null || e.Cancelled)
            {
                MessageBox.Show(e.Error.Message, "Fel", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            string responseString = Encoding.Default.GetString(e.Result);

            if (responseString.StartsWith("RTL:"))
            {
                if (responseString.Substring(4, 2) == "S:")
                {
                    MessageBox.Show(responseString.Substring(6), "Respons", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show(responseString.Substring(6), "Fel", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            else if (responseString.StartsWith("RTR:"))
            {
                if (responseString.Substring(4, 2) == "S:")
                {
                    MessageBox.Show(responseString.Substring(6), "Respons", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show(responseString.Substring(6), "Fel", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            else if (responseString.StartsWith("RTSM:"))
            {
                if (responseString.Substring(5, 2) == "S:")
                {
                    //Ta bort från pending_messages
                    if (int.TryParse(responseString.Substring(7), out int msgId))
                    {
                        PendingMessages.RemovePendingMessage(msgId);
                    }
                }
                else
                {
                    MessageBox.Show(responseString.Substring(7), "Fel", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }
Пример #2
0
 private void TextBoxSend_KeyDown(object o, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Enter)
     {
         e.SuppressKeyPress = true;
         if (!string.IsNullOrEmpty(currentSendTextBox.Text.Trim()))
         {
             TimeSpan utcOffset = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now);
             string   timestamp = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss" + ((utcOffset < TimeSpan.Zero) ? "-" : "+") + utcOffset.Hours.ToString("00") + ":" + utcOffset.Minutes.ToString("00"));
             int      msgId     = PendingMessages.AppendPendingMessage(Username, tabControlConversations.SelectedTab.Text, timestamp, currentSendTextBox.Text);
             currentReadTextBox.AppendText(currentSendTextBox.Text + "\n");
             currentSendTextBox.Clear();
             currentSendTextBox.Select(0, 0);
             ServerCommunicator.SendMessage(Username, tabControlConversations.SelectedTab.Text, timestamp, currentSendTextBox.Text, msgId.ToString());
         }
     }
 }