public static Users GetUserByUserName(string loginname, string pwd,out int result, string operateip)
        {
            pwd = CloudSalesTool.Encrypt.GetEncryptPwd(pwd, loginname);
            DataSet ds = new OrganizationDAL().GetUserByUserName(loginname, pwd, out result);
            Users model = null;
            if (ds.Tables.Contains("User") && ds.Tables["User"].Rows.Count > 0)
            {
                model = new Users();
                model.FillData(ds.Tables["User"].Rows[0]);

                model.LogGUID = Guid.NewGuid().ToString();

                model.Department = GetDepartmentByID(model.DepartID, model.AgentID);
                model.Role = GetRoleByIDCache(model.RoleID, model.AgentID);
                
                //处理缓存
                if (!Users.ContainsKey(model.AgentID))
                {
                    GetUsers(model.AgentID);
                }
                if (Users[model.AgentID].Where(u => u.UserID == model.UserID).Count() == 0)
                {
                    Users[model.AgentID].Add(model);
                }
                else
                {
                    var user = Users[model.AgentID].Where(u => u.UserID == model.UserID).FirstOrDefault();
                    user.LogGUID = model.LogGUID;
                }

                model.Client = Manage.ClientBusiness.GetClientDetail(model.ClientID);

                //权限
                if (model.Role != null && model.Role.IsDefault == 1)
                {
                    model.Menus = CommonBusiness.ClientMenus;
                }
                else
                {
                    model.Menus = new List<Menu>();
                    foreach (DataRow dr in ds.Tables["Permission"].Rows)
                    {
                        Menu menu = new Menu();
                        menu.FillData(dr);
                        model.Menus.Add(menu);
                    }
                }
            }

            //记录登录日志
            if (model != null)
            {
                LogBusiness.AddLoginLog(loginname, true,Manage.ClientBusiness.GetClientDetail(model.ClientID).AgentID == model.AgentID ? IntFactoryEnum.EnumSystemType.Client : IntFactoryEnum.EnumSystemType.Agent, operateip, model.UserID, model.AgentID, model.ClientID);
            }
            else
            {
                LogBusiness.AddLoginLog(loginname, false, IntFactoryEnum.EnumSystemType.Client, operateip, "", "", "");
            }

            return model;
        }
 public bool UpdateDepartment(string departid, string name, string description, string operateid, string operateip, string agentid)
 {
     var dal = new OrganizationDAL();
     bool bl = dal.UpdateDepartment(departid, name, description, agentid);
     if (bl)
     {
         //处理缓存
         var model = GetDepartments(agentid).Where(d => d.DepartID == departid).FirstOrDefault();
         model.Name = name;
         model.Description = description;
     }
     return bl;
 }
 public static List<Role> GetRoles(string agentid)
 {
     if (!Roles.ContainsKey(agentid))
     {
         DataTable dt = new OrganizationDAL().GetRoles(agentid);
         List<Role> list = new List<Role>();
         foreach (DataRow dr in dt.Rows)
         {
             Role model = new Role();
             model.FillData(dr);
             list.Add(model);
         }
         Roles.Add(agentid, list);
         return list;
     }
     return Roles[agentid].Where(m => m.Status == 1).ToList();
 }
 public static List<Department> GetDepartments(string agentid)
 {
     if (!Departments.ContainsKey(agentid))
     {
         DataTable dt = new OrganizationDAL().GetDepartments(agentid);
         List<Department> list = new List<Department>();
         foreach (DataRow dr in dt.Rows)
         {
             Department model = new Department();
             model.FillData(dr);
             list.Add(model);
         }
         Departments.Add(agentid, list);
         return list;
     }
     return Departments[agentid].Where(m => m.Status == 1).ToList();
 }
        public static Users GetUserByUserID(string userid, string agentid)
        {
            
            if (string.IsNullOrEmpty(userid) || string.IsNullOrEmpty(agentid))
            {
                return null;
            }
            userid = userid.ToLower();
            var list = GetUsers(agentid);
            if (list.Where(u => u.UserID == userid).Count() > 0)
            {
                return list.Where(u => u.UserID == userid).FirstOrDefault();
            }
            else
            {
                DataTable dt = new OrganizationDAL().GetUserByUserID(userid);
                Users model = new Users();
                if (dt.Rows.Count > 0)
                {
                    model.FillData(dt.Rows[0]);

                    if (agentid == model.AgentID)
                    {
                        model.Department = GetDepartmentByID(model.DepartID, agentid);
                        model.Role = GetRoleByIDCache(model.RoleID, agentid);
                        Users[agentid].Add(model);
                    }
                }
                return model;
            }
        }
        public static bool ConfirmLoginPwd(string loginname, string pwd)
        {
            pwd = CloudSalesTool.Encrypt.GetEncryptPwd(pwd, loginname);
            int result;
            DataSet ds = new OrganizationDAL().GetUserByUserName(loginname, pwd,out result);

            if (ds.Tables.Contains("User") && ds.Tables["User"].Rows.Count > 0)
            {
                return true;
            }

            return false;
        }