Пример #1
0
 private void MyMessage_KeyDown(object sender, KeyEventArgs e)
 {
     if (Client != null)
     {
         if (e.Key == Key.Enter && (Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift)
         {
             Data packedData = new Data()
             {
                 Name = Client.GetUsername(), Message = MyMessage.Text, Target = SelectedTarget
             };
             MessageWrap wrap = new MessageWrap()
             {
                 From = "Me", Date = DateTime.Now.ToString(), Message = MyMessage.Text
             };
             MessageGrid.Items.Add(wrap);
             Dialogs[SelectedTarget].Add(wrap);
             Client.SendMessage(packedData);
             MyMessage.Clear();
             e.Handled = true;
         }
         if (!e.Handled && e.Key == Key.Enter)
         {
             MyMessage.AppendText("\n");
             MyMessage.CaretIndex = MyMessage.Text.Length;
         }
     }
 }
Пример #2
0
        private void Send_Message(object sender, RoutedEventArgs e)
        {
            if (NameDialog.SelectedItem == null)
            {
                MessageBox.Show("Выберите диалог!");
            }
            else
            {
                if (MyMessage.Text == null)
                {
                    MessageBox.Show("Введите сообщение!");
                }
                else
                {
                    Messages M = new Messages
                    {
                        Sender_ID   = (NameDialog.SelectedItem as Dialog).Sender_ID,
                        Receiver_ID = (NameDialog.SelectedItem as Dialog).Receiver_ID,
                        Message     = MyMessage.Text,
                        DialogID    = (NameDialog.SelectedItem as Dialog).ID
                    };

                    DB.Messages.Add(M);
                    DB.SaveChanges();
                    MyMessage.Clear();
                }
            }
        }
Пример #3
0
        private void Send_Message(object sender, RoutedEventArgs e)
        {
            try
            {
                if (NameDialog.SelectedItem == null)
                {
                    MessageBox.Show("Выберите диалог!");
                }
                else
                {
                    if (MyMessage.Text == null)
                    {
                        MessageBox.Show("Введите сообщение!");
                    }
                    else
                    {
                        DB.Dispose();
                        DB = new Database();

                        Message M = new Message
                        {
                            SenderID   = (NameDialog.SelectedItem as Dialog).Sender_ID,
                            ReceiverID = (NameDialog.SelectedItem as Dialog).Receiver_ID,
                            Message1   = MyMessage.Text
                        };
                        DB.Messages.Add(M);
                        DB.SaveChanges();
                        MyMessage.Clear();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "Произошла ошибка.\nПовторите попытку.");
            }
        }