private void Button_Click_2(object sender, RoutedEventArgs e) { if (group2.SelectedValue != null) { byte[] code = Encoding.UTF8.GetBytes("04"); client_socket.Send(code); Group group = null; foreach (Group gr in groups) { if (gr == group2.SelectedValue) { group = gr; break; } } User my = null; foreach (User us in users) { if (us.UserID == myId) { my = us; break; } } ClaimToGroup claimToGroup = new ClaimToGroup(my, group); IFormatter formatter = new BinaryFormatter(); Stream stream = new MemoryStream(); formatter.Serialize(stream, claimToGroup); byte[] buffer2 = new byte[1024]; stream.Position = 0; while (stream.Position < stream.Length) { int readCount = stream.Read(buffer2, 0, 1024); client_socket.Send(buffer2, readCount, 0); } } }
void SetNewClaimToList(ClaimToGroup claim) { bool exist = false; foreach (ClaimToGroup cl in listBox2.Items) { if (cl.User.UserID == claim.User.UserID && cl.Group.Id == claim.Group.Id) { exist = true; break; } } if(!exist) listBox2.Items.Add(claim); }
private void Button_Click(object sender, RoutedEventArgs e) { //выйти из группы if (group1.SelectedValue.ToString() == "GENERAL") { MessageBox.Show("Вы не можете выйти из основной группы"); } else { byte[] code = Encoding.UTF8.GetBytes("05"); client_socket.Send(code); Group group = null; foreach (Group gr in groups) { if (gr == group1.SelectedValue) { group = gr; break; } } User my = null; foreach (User us in users) { if (us.UserID == myId) { my = us; break; } } ClaimToGroup claimToGroup = new ClaimToGroup(my, group); IFormatter formatter = new BinaryFormatter(); Stream stream = new MemoryStream(); formatter.Serialize(stream, claimToGroup); byte[] buffer2 = new byte[1024]; stream.Position = 0; while (stream.Position < stream.Length) { int readCount = stream.Read(buffer2, 0, 1024); client_socket.Send(buffer2, readCount, 0); } foreach (MemberOfGroup mem in memeberOgGroups) { if (mem.GroupID == group.Id) { memeberOgGroups.Remove(mem); break; } } Action<Group> groupMixered = GroupMixer2; group1.Dispatcher.Invoke(groupMixered, group); stacMess.Dispatcher.Invoke(new Action(() => { stacMess.Children.Clear(); })); foreach (Message message in messages) { PrintMessage(message); } messScroll.Dispatcher.Invoke(new Action(() => { messScroll.ScrollToVerticalOffset(messScroll.ActualHeight); })); for (int i = 0; i < messages.Count; i++) { if (messages[i].GroupID == claimToGroup.Group.Id) { messages.RemoveAt(i); i--; } } } }