Exemplo n.º 1
0
        /// <summary>用户退出</summary>
        public void Logout(int id, string userName)
        {
            MyUser logoutUser = CC.GetUser(userName);

            CC.Users.Remove(logoutUser);

            List <Userdata> userdatas = new List <Userdata>();

            foreach (var item in CC.Users)
            {
                if (item.id == id)
                {
                    Userdata t = new Userdata();
                    t.Acount = item.Acount;
                    t.Avart  = item.Avart;
                    t.Grade  = item.Grade;
                    t.Name   = item.Name;
                    t.Room   = item.Room;
                    t.Score  = item.Score;
                    t.Sign   = item.Sign;
                    userdatas.Add(t);
                }
            }
            foreach (var item in CC.Users)
            {
                if (item.id == id)
                {
                    item.callback.ShowLogout(userName);
                    item.callback.ShowInfo(userdatas);
                }
            }
            logoutUser = null; //将其设置为null后,WCF会自动关闭该客户端
        }
Exemplo n.º 2
0
        public void Login(int id, string userName)
        {
            // throw new NotImplementedException();
            OperationContext context  = OperationContext.Current;
            IServiceCallback callback = context.GetCallbackChannel <IServiceCallback>();
            MyUser           newUser  = new MyUser(userName, callback);

            User tmp = null;
            //数据库实例
            MyDbEntities myDbEntities = new MyDbEntities();
            //选中这一条数据
            var q = from p in myDbEntities.User
                    where p.Name == userName
                    select p;

            tmp            = q.FirstOrDefault();
            newUser.Acount = tmp.Acount;
            newUser.Avart  = tmp.Avart;
            newUser.Grade  = tmp.Grade;
            newUser.Name   = tmp.Name;
            newUser.Room   = tmp.Room;
            newUser.Score  = tmp.Score;
            newUser.Sign   = tmp.Sign;
            newUser.id     = id;

            CC.Users.Add(newUser);
            List <Userdata> userdatas = new List <Userdata>();

            foreach (var item in CC.Users)
            {
                if (item.id == id)
                {
                    Userdata t = new Userdata();
                    t.Acount = item.Acount;
                    t.Avart  = item.Avart;
                    t.Grade  = item.Grade;
                    t.Name   = item.Name;
                    t.Room   = item.Room;
                    t.Score  = item.Score;
                    t.Sign   = item.Sign;
                    userdatas.Add(t);
                }
            }
            foreach (var item in CC.Users)
            {
                if (item.id == id)
                {
                    item.callback.ShowLogin(userName);
                    item.callback.ShowInfo(userdatas);
                }
            }
        }