Ejemplo n.º 1
0
        private void SendFriendList(ClassMsg msg, IPAddress ip, int port)
        {
            LoginMsg   loginmsg   = (LoginMsg) new ClassSerializers().DeSerializeBinary(new MemoryStream(msg.Data));
            MsgCommand msgState   = msg.msgCommand;
            string     UserName   = loginmsg.UserName; //登录用户名称
            string     vIP        = ip.ToString();     //用户IP地址
            FriendList FriendList = new MyIM.FriendList();
            DataTable  dt         = OptionData.ExSQLReDr("select * from user Where UserAccount=" + "'" + UserName + "'");
            string     UserID     = dt.Rows[0]["UserID"].ToString();
            DataTable  dt1        = OptionData.ExSQLReDr(string.Format("select * from friendgroup where UserID={0}", UserID));

            for (int i = 0; i < dt1.Rows.Count; i++)
            {
                DataRow dtr = dt1.NewRow();
                dtr = dt1.Rows[i];
                FriendList.Group[i].GroupName = dtr["GrouName"].ToString();
                FriendList.Group[i].GroupID   = dtr["GrouID"].ToString();
                DataTable dt2 = OptionData.ExSQLReDr("select GrouID,Use_UserID,AlternateName,frs.UserID from friendrelationship frs"
                                                     + " join user user on frs.UserID=user.UserID"
                                                     + string.Format(" where user.UserAccount='{0}' and frs.GrouID='{1}'", UserName, FriendList.Group[i].GroupID)
                                                     + " order by GrouID");
                for (int l = 0; l < dt2.Rows.Count; l++)
                {
                    DataTable dt3  = OptionData.ExSQLReDr("select * from user where UserID='" + dt2.Rows[l]["Use_UserID"] + "'");
                    DataRow   dtr1 = dt3.NewRow();
                    dtr1 = dt3.Rows[0];
                    FriendList.Group[i].Friend[l].NickName            = dtr1["UserNickName"].ToString();
                    FriendList.Group[i].Friend[l].UserID              = dtr1["UserID"].ToString();
                    FriendList.Group[i].Friend[l].AlternateName       = dt2.Rows[l]["AlternateName"].ToString();
                    FriendList.Group[i].Friend[l].UserPersonalMessage = dtr1["UserPersonalMessage"].ToString();
                }
                loginmsg.FriendList = FriendList;
                msg.sendKind        = SendKind.SendCommand;
                msg.msgCommand      = MsgCommand.GetFriendList;
                msg.Data            = new ClassSerializers().SerializeBinary(loginmsg).ToArray();
                SendMsgToOne(ip, port, msg);
            }
        }
Ejemplo n.º 2
0
 private void SendFriendList(ClassMsg msg, IPAddress ip, int port)
 {
     LoginMsg loginmsg = (LoginMsg)new ClassSerializers().DeSerializeBinary(new MemoryStream(msg.Data));
     MsgCommand msgState = msg.msgCommand;
     string UserName = loginmsg.UserName;    //登录用户名称
     string vIP = ip.ToString();             //用户IP地址
     FriendList FriendList = new MyIM.FriendList();
     DataTable dt = OptionData.ExSQLReDr("select * from user Where UserAccount=" + "'" + UserName + "'");
     string UserID = dt.Rows[0]["UserID"].ToString();
     DataTable dt1 = OptionData.ExSQLReDr(string.Format("select * from friendgroup where UserID={0}", UserID));
     for (int i = 0; i < dt1.Rows.Count; i++)
     {
         DataRow dtr = dt1.NewRow();
         dtr = dt1.Rows[i];
         FriendList.Group[i].GroupName = dtr["GrouName"].ToString();
         FriendList.Group[i].GroupID = dtr["GrouID"].ToString();
         DataTable dt2 = OptionData.ExSQLReDr("select GrouID,Use_UserID,AlternateName,frs.UserID from friendrelationship frs"
         + " join user user on frs.UserID=user.UserID"
         + string.Format(" where user.UserAccount='{0}' and frs.GrouID='{1}'", UserName, FriendList.Group[i].GroupID)
         + " order by GrouID");
         for (int l = 0; l < dt2.Rows.Count; l++)
         {
             DataTable dt3 = OptionData.ExSQLReDr("select * from user where UserID='"+dt2.Rows[l]["Use_UserID"]+"'");
             DataRow dtr1 = dt3.NewRow();
             dtr1 = dt3.Rows[0];
             FriendList.Group[i].Friend[l].NickName = dtr1["UserNickName"].ToString();
             FriendList.Group[i].Friend[l].UserID = dtr1["UserID"].ToString();
             FriendList.Group[i].Friend[l].AlternateName = dt2.Rows[l]["AlternateName"].ToString() ;
             FriendList.Group[i].Friend[l].UserPersonalMessage = dtr1["UserPersonalMessage"].ToString();
         }
         loginmsg.FriendList = FriendList;
         msg.sendKind = SendKind.SendCommand;
         msg.msgCommand = MsgCommand.GetFriendList;
         msg.Data = new ClassSerializers().SerializeBinary(loginmsg).ToArray();
         SendMsgToOne(ip, port, msg);
     }
 }