public static void LoadMembersOfGroup(SqlDataReader reader) { while (reader.Read()) { MemberOfGroup memberOfGroup = new MemberOfGroup(); memberOfGroup.UserID = (int)reader["UserID"]; memberOfGroup.GroupID = (int)reader["GroupID"]; memberOfGroup.Status = (int)Statuses.unchanged; membersOfGroup.Add(memberOfGroup); } }
private void Button_Click_5(object sender, RoutedEventArgs e) { if (listBox2.SelectedValue != null) { ClaimToGroup currentClaim = (ClaimToGroup)listBox2.SelectedValue; MemberOfGroup memOfGroup = new MemberOfGroup(currentClaim.User.UserID, currentClaim.Group.Id); MemberOfGroupManager.MembersOfGroup.Add(memOfGroup); string query = string.Format("insert into MemeberOfGroups (GroupID, UserID) values ({0}, {1})", currentClaim.Group.Id, currentClaim.User.UserID); SqlCommand command = new SqlCommand(query, DataBase.Sql); command.ExecuteNonQuery(); Action<string> action = MessageToInfoStackAdd; string messa = String.Format("Заявка на вступление в группу {0} юзера {1} принята", currentClaim.Group, currentClaim.User); infoStack.Dispatcher.Invoke(action, messa); int numOfSocket = -1; Dictionary<Socket, User>.ValueCollection usCol = dictSocketUser.Values; for (numOfSocket = 0; numOfSocket < usCol.Count; numOfSocket++) { if (usCol.ElementAt(numOfSocket).UserID == currentClaim.User.UserID) { break; } } Socket socketToSend = dictSocketUser.ElementAt(numOfSocket).Key; byte[] code = Encoding.UTF8.GetBytes("10"); socketToSend.Send(code); IFormatter formatter2 = new BinaryFormatter(); Stream stream2 = new MemoryStream(); formatter2.Serialize(stream2, memOfGroup); byte[] buffer2 = new byte[1024]; stream2.Position = 0; while (stream2.Position < stream2.Length) { int readCount = stream2.Read(buffer2, 0, 1024); socketToSend.Send(buffer2, readCount, 0); } Thread.Sleep(50); List<Message> messToSend = new List<Message>(); foreach (Message mess in MessageManager.Messages) { if (mess.GroupID == memOfGroup.GroupID) messToSend.Add(mess); } byte[] code3 = Encoding.UTF8.GetBytes("11"); socketToSend.Send(code3); IFormatter formatter3 = new BinaryFormatter(); Stream stream3 = new MemoryStream(); formatter3.Serialize(stream3, messToSend); byte[] buffer3 = new byte[1024]; stream3.Position = 0; while (stream3.Position < stream3.Length) { int readCount = stream3.Read(buffer3, 0, 1024); socketToSend.Send(buffer3, readCount, 0); } Thread.Sleep(50); foreach (Socket socket in dictSocketUser.Keys) { bool member = false; foreach (MemberOfGroup mem in MemberOfGroupManager.MembersOfGroup) { if (dictSocketUser[socket].UserID == mem.UserID && mem.GroupID == memOfGroup.GroupID) { member = true; break; } } if (member) { byte[] code2 = Encoding.UTF8.GetBytes("07"); socket.Send(code2); IFormatter formatter = new BinaryFormatter(); Stream stream = new MemoryStream(); formatter.Serialize(stream, String.Format("{0} принят в группу {1}", currentClaim.User.ToString(), currentClaim.Group.ToString())); byte[] buffer = new byte[1024]; stream.Position = 0; while (stream.Position < stream.Length) { int readCount = stream.Read(buffer, 0, 1024); socket.Send(buffer, readCount, 0); } } } listBox2.Items.Remove(listBox2.SelectedValue); } //else //{ // mainEvent.OnSomeEvent(123456); //} }