/// <summary> /// 保存用户及授权信息(添加,修改) /// </summary> /// <param name="currentUser"></param> /// <param name="roleOrgDictionary"></param> /// <returns></returns> public int SaveAuthorityRoleOrg(User currentUser, Dictionary <String, List <String> > roleOrgDictionary) { List <String[]> roleOrgList = new List <String[]>();//0,id;1,useId;2,roleId;3,orgId; //修改时,要找到主键,检索传递信息是否已经存在? List <String[]> judgeRoleOrgList = new List <string[]>(); UserLogic userLogic = new UserLogic(); //using (DaoManager daoMgr = new DaoManager()) //{ try { //daoMgr.BeginTransaction(); if (userLogic.Update(currentUser) == -1) { //currentUser.Id = Neusoft.Framework.Facade.Context.GetSequence("Seq_UserId"); currentUser.Id = this.GetSequence("PRIV.SEQ_USERID"); if (userLogic.Insert(currentUser) == -1) { return(-1); } } //从数据库中得到所有该用户的信息,比较新的数据字典中的Role是否和表中的Role的数量一样,不一样则删除。 judgeRoleOrgList = authorityLogic.Query(currentUser.Id); foreach (String role in roleOrgDictionary.Keys) { //当不设置组织结构时 if (roleOrgDictionary[role].Count == 0) { string[] newRoleOrg = new string[4]; newRoleOrg[1] = currentUser.Id; newRoleOrg[2] = role; //当不为角色收组织结构是,组织结构默认为空。 newRoleOrg[3] = null; //当不设置组织结构时,设置主键值 foreach (String[] judge in judgeRoleOrgList) { if (judge[1] == newRoleOrg[1] && judge[2] == newRoleOrg[2] && judge[3] == newRoleOrg[3]) { newRoleOrg[0] = judge[0]; } } roleOrgList.Add(newRoleOrg); } foreach (String org in roleOrgDictionary[role]) { string[] newRoleOrg = new string[4]; newRoleOrg[1] = currentUser.Id; newRoleOrg[2] = role; newRoleOrg[3] = org; //设置主键值 foreach (String[] judge in judgeRoleOrgList) { if (judge[1] == newRoleOrg[1] && judge[2] == newRoleOrg[2] && judge[3] == newRoleOrg[3]) { newRoleOrg[0] = judge[0]; } } roleOrgList.Add(newRoleOrg); } } foreach (String[] newString in roleOrgList) { if (authorityLogic.Update(newString) == -1) { //newString[0] = Neusoft.Framework.Facade.Context.GetSequence("SEQ_COM_AUTHORITY_ROLE"); newString[0] = this.GetSequence("PRIV.SEQ_COM_AUTHORITY_ROLE"); if (authorityLogic.Insert(newString) == -1) { return(-1); } } } ////比较新的数据字典中的Role是否和表中的Role的数量一样,不一样则删除。 foreach (String[] oldRoleOrg in judgeRoleOrgList) { bool Judge = true; foreach (String[] roleOrg in roleOrgList) { if (oldRoleOrg[2] == roleOrg[2] && oldRoleOrg[1] == roleOrg[1] && oldRoleOrg[3] == roleOrg[3]) { Judge = false; continue; } } if (Judge) { authorityLogic.Delete(oldRoleOrg[0]); } } ////同时筛选出用户对应的角色改变,其角色也相应改变,删除用户权限表中对应的角色所对应的权限信息。 ////当前用户所有角色列表。 //List<String> roleIdList = new List<string>(); //foreach (String roleId in roleOrgDictionary.Keys) //{ // roleIdList.Add(roleId); //} //////得到当前用户所拥有的角色中所对应的权限列表 ////List<Priv> privList = QueryPriv(roleIdList); ////得到当前用户所设置的权限信息 //List<String> userPrivIdList = authorityLogic.QueryPrivId(currentUser.Id); //foreach (String userPrivId in userPrivIdList) //{ // bool judge = true; // foreach (Priv priv in privList) // { // if (userPrivId == priv.Id) // { // judge = false; // continue; // } // } // if (judge) // { // authorityLogic.DeletePri(currentUser.Id, userPrivId); // } //} //daoMgr.CommitTransaction(); return(0); } catch (Exception ex) { //daoMgr.RollBackTransaction(); throw ex; } //} }