void Setting(Guid userId)
        {
            var userEntity = UMC.Data.Database.Instance().ObjectEntity <UMC.Data.Entities.User>();
            var user       = userEntity.Where.And().Equal(new Data.Entities.User {
                Id = userId
            }).Entities.Single();
            var userRoleEntity = UMC.Data.Database.Instance().ObjectEntity <UMC.Data.Entities.UserToRole>();

            userRoleEntity.Where.And().Equal(new Data.Entities.UserToRole {
                user_id = user.Id
            });
            var roleEntity = UMC.Data.Database.Instance().ObjectEntity <UMC.Data.Entities.Role>();

            roleEntity.Where.And().Unequal(new Data.Entities.Role {
                Rolename = UMC.Security.Membership.GuestRole
            });
            var userValue = Web.UIFormDialog.AsyncDialog("User", d =>
            {
                var fdlg = new Web.UIFormDialog();
                fdlg.Menu("角色", "Settings", "Role");
                fdlg.Title = String.Format("账户设置", user.Username);

                var opts2 = new Web.ListItemCollection();

                opts2.Add("别名", user.Alias);
                opts2.Add("登录名", user.Username);
                if (user.ActiveTime.HasValue)
                {
                    opts2.Add("最后登录", String.Format("{0:yy-MM-dd HH:mm}", user.ActiveTime));
                }
                if (user.RegistrTime.HasValue)
                {
                    opts2.Add("注册时间", String.Format("{0:yy-MM-dd HH:mm}", user.RegistrTime));
                }

                fdlg.AddTextValue(opts2);
                var flags    = user.Flags ?? UMC.Security.UserFlags.Normal;
                var opts     = new Web.ListItemCollection();
                var selected = ((int)(flags & UMC.Security.UserFlags.Lock)) > 0;
                opts.Add("锁定", "1", selected);
                selected = ((int)(flags & UMC.Security.UserFlags.Disabled)) > 0;
                opts.Add("禁用", "16", selected);
                fdlg.AddCheckBox("状态", "Flags", opts, "0");

                var uRs = new List <UMC.Data.Entities.UserToRole>(userRoleEntity.Query());
                opts    = new Web.ListItemCollection();



                roleEntity.Query(dr =>
                {
                    switch (dr.Rolename)
                    {
                    case UMC.Security.Membership.AdminRole:
                        opts.Add("超级管理员", dr.Id.ToString(), uRs.Exists(ur => ur.role_id == dr.Id));
                        break;

                    case UMC.Security.Membership.UserRole:
                        opts.Add("内部员工", dr.Id.ToString(), uRs.Exists(ur => ur.role_id == dr.Id));
                        break;

                    case "TrainAdmin":
                        opts.Add("培训管理员", dr.Id.ToString(), uRs.Exists(ur => ur.role_id == dr.Id));
                        break;


                    case "StoreManager":
                        opts.Add("店长", dr.Id.ToString(), uRs.Exists(ur => ur.role_id == dr.Id));
                        break;

                    case "Finance":
                        opts.Add("财务", dr.Id.ToString(), uRs.Exists(ur => ur.role_id == dr.Id));
                        break;

                    default:
                        opts.Add(dr.Rolename, dr.Id.ToString(), uRs.Exists(ur => ur.role_id == dr.Id));
                        break;
                    }
                });

                fdlg.AddCheckBox("部门角色", "Roles", opts, "None");
                return(fdlg);
            });
            var Flags = UMC.Security.UserFlags.Normal;

            foreach (var k in userValue["Flags"].Split(','))
            {
                Flags = Flags | UMC.Data.Utility.Parse(k, UMC.Security.UserFlags.Normal);
            }
            userEntity.Update(new Data.Entities.User {
                Flags = Flags, Alias = userValue["Alias"]
            });

            if ((Flags & Security.UserFlags.Disabled) == Security.UserFlags.Disabled)
            {
                UMC.Data.Database.Instance().ObjectEntity <UMC.Data.Entities.Session>()
                .Where.And().Equal(new Data.Entities.Session
                {
                    user_id = user.Id
                }).Entities.Delete();
            }

            var rids = new List <Data.Entities.UserToRole>();

            foreach (var k in userValue["Roles"].Split(','))
            {
                switch (k)
                {
                case "None":
                    break;

                default:
                    rids.Add(new Data.Entities.UserToRole {
                        role_id = new Guid(k), user_id = userId
                    });
                    break;
                }
            }
            userRoleEntity.Delete();
            if (rids.Count > 0)
            {
                userRoleEntity.Insert(rids.ToArray());

                UMC.Data.Database.Instance().ObjectEntity <UMC.Data.Entities.Session>()
                .Where.And().Equal(new Data.Entities.Session {
                    user_id = userId
                }).Entities.Delete();
            }


            UMC.Data.Database.Instance().ObjectEntity <UMC.Data.Entities.Session>()
            .Where.And().Equal(new Data.Entities.Session {
                user_id = userId
            }).Entities.Delete();

            this.Prompt("设置成功");
        }