private void MenuAddRecord_OnClick(object sender, RoutedEventArgs e)
        {
            AreaAuthorization aa = DataGrid1.SelectedItem as AreaAuthorization;

            if (aa == null)
            {
                return;
            }
            var win = new CardRoleWindow();

            win.ShowOkButton();
            if (win.ShowDialog() == true)
            {
                //var roles = win.GetSelectedRoles();
                //foreach (var role in roles)
                //{
                //    AreaAuthorizationRecord aar = new AreaAuthorizationRecord(aa, role);
                //    if (aarService.Post(aar) == null)
                //    {
                //        MessageBox.Show("分配权限失败");
                //        break;
                //    }
                //}

                var role = win.Role;
                if (role != null)
                {
                    AreaAuthorizationRecord aar = new AreaAuthorizationRecord(aa, role);
                    if (aarService.Post(aar) == null)
                    {
                        MessageBox.Show("分配权限失败");
                    }
                }
            }
        }
        public ActionResult Create(AreaAuthorization aa, FormCollection col)
        {
            if (ModelState.IsValid)
            {
                //aa.RepeatDay = col["RepeatType"];
                aa.CreateTime = DateTime.Now;
                aa.ModifyTime = null;
                aa.DeleteTime = null;
                aa.SetTimeSpane();
                //bll.JurisDictions.Add(jd);
                //return RedirectToAction("Index");

                var result = bll.AreaAuthorizations.Add(aa);
                if (result)
                {
                    return(Json(new { success = result }));
                }
                else
                {
                    return(Json(new { success = result, errors = bll.AreaAuthorizations.ErrorMessage }));
                }
            }

            GetListToViewBag();
            return(View(aa));
        }
        private void BtnSubmit_OnClick(object sender, RoutedEventArgs e)
        {
            Bll bll = AppContext.GetLocationBll();
            var aa  = new AreaAuthorization();

            aa.Name        = TbName.Text;
            aa.Description = TbDescription.Text;

            var area = CbAreaList.SelectedItem as PhysicalTopology;

            aa.AreaId = area.Id;

            if (bll.AreaAuthorizations.Add(aa) == false)
            {
                MessageBox.Show("添加失败1");
            }

            var role = CbAreaList.SelectedItem as CardRole;

            var aar = new AreaAuthorizationRecord(aa, role);

            if (bll.AreaAuthorizationRecords.Add(aar) == false)
            {
                MessageBox.Show("添加失败2");
            }

            MessageBox.Show("添加成功");
        }
        public ActionResult Create()
        {
            AreaAuthorization jd = new AreaAuthorization();

            GetListToViewBag();
            return(PartialView(jd));
        }
        private static AreaAuthorization CreateAreaAuthorization(Area area, AreaAccessType accType)
        {
            var aa = AreaAuthorization.New();

            aa.AreaId = area.Id;
            //aa.Area = area;
            aa.AccessType  = accType; //可进入的权限
            aa.RangeType   = AreaRangeType.WithParent;
            aa.Description = string.Format("权限[{0}][{1}]", accType, area.Name);
            aa.Name        = string.Format("权限:[{0}]区域‘{1}’", accType, area.Name);
            aa.RepeatDay   = RepeatDay.每天;
            aa.SetTime(8, 30, 17, 30);
            return(aa);
        }
 private void SetRoleAuthorization3(CardRole role, List <Area> buildAreaList)
 {
     foreach (var area in buildAreaList)
     {
         var aa = AreaAuthorization.New();
         aa.AreaId      = area.Id;             //根节点
         aa.AccessType  = AreaAccessType.可以进出; //可进入的权限
         aa.RangeType   = AreaRangeType.WithParent;
         aa.Name        = string.Format("权限[园区参观(高级)]");
         aa.Description = string.Format("权限:可以进入园区参观,可以靠近建筑物。");
         areaAuthorizations.Add(aa);
         AreaAuthorizations.Add(aa);
         AddAAR(role, aa);
     }
 }
 private void SetRoleAuthorization4(List <Area> floors, CardRole role)
 {
     foreach (var area in floors)
     {
         var aa = AreaAuthorization.New();
         aa.AreaId      = area.Id;             //根节点
         aa.AccessType  = AreaAccessType.可以进出; //可进入的权限
         aa.RangeType   = AreaRangeType.WithParent;
         aa.Name        = string.Format("权限[大楼内部]");
         aa.Description = string.Format("权限:可以进入大楼内部,不能进入机房。");
         areaAuthorizations.Add(aa);
         AreaAuthorizations.Add(aa);
         AddAAR(role, aa);
     }
 }
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AreaAuthorization jd = bll.AreaAuthorizations.Find(id);

            if (jd == null)
            {
                return(HttpNotFound());
            }
            //return View(jd);
            return(PartialView(jd));
        }
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AreaAuthorization jd = bll.AreaAuthorizations.Find(id);

            if (jd == null)
            {
                return(HttpNotFound());
            }

            GetListToViewBag();
            return(PartialView(jd));
        }
        private void SetRoleAuthorization1(CardRole role)
        {
            //foreach (var area in areaList)
            {
                var aa = AreaAuthorization.New();
                aa.AreaId      = 1;                   //根节点
                aa.AccessType  = AreaAccessType.可以进出; //可进入的权限
                aa.RangeType   = AreaRangeType.All;
                aa.Name        = string.Format("权限[全部区域]");
                aa.Description = string.Format("权限:可以进入全部区域");
                aa.SetTime(0, 0, 23, 59, 59);
                areaAuthorizations.Add(aa);
                AreaAuthorizations.Add(aa);

                AddAAR(role, aa);
            }
        }
        private void SetAlarmArea(CardRole role, int areaId)
        {
            var aa = AreaAuthorization.New();

            aa.AreaId      = areaId;             //根节点
            aa.AccessType  = AreaAccessType.能进入; //不能进入
            aa.RangeType   = AreaRangeType.Single;
            aa.Name        = string.Format("权限[不能进入]");
            aa.Description = string.Format("权限:告警区域");
            if (areaAuthorizations == null)
            {
                areaAuthorizations = new List <AreaAuthorization>();
            }
            areaAuthorizations.Add(aa);
            AreaAuthorizations.Add(aa);
            AddAAR(role, aa);
        }
        private void AddAAR(CardRole role, AreaAuthorization aa)
        {
            var aar = new AreaAuthorizationRecord(aa, role);

            if (authorizationRecords == null)
            {
                authorizationRecords = new List <AreaAuthorizationRecord>();
            }
            authorizationRecords.Add(aar);
            AreaAuthorizationRecords.Add(aar);

            if (authorizationAreas != null)
            {
                var aa2 = authorizationAreas.Find(i => i.Id == aa.AreaId);
                if (aa2 != null)
                {
                    aa2.Records.Add(aar);
                }
            }
        }
        private void SetRoleAuthorization5(List <Area> areaList)
        {
            for (int j = 1; j <= 4; j++)
            {
                var role = _roles[j];
                foreach (var area in areaList)
                {
                    var aa = AreaAuthorization.New();
                    aa.AreaId      = area.Id;             //根节点
                    aa.AccessType  = AreaAccessType.可以进出; //可进入的权限
                    aa.RangeType   = AreaRangeType.WithParent;
                    aa.Name        = string.Format("权限[机房]");
                    aa.Description = string.Format("权限:可以进入机房。");
                    areaAuthorizations.Add(aa);
                    AreaAuthorizations.Add(aa);

                    AddAAR(role, aa);
                }
            }
        }
        public ActionResult Edit(AreaAuthorization jd, FormCollection col)
        {
            if (ModelState.IsValid)
            {
                jd.ModifyTime = DateTime.Now;
                //jd.RepeatDay = col["RepeatDay"];

                var result = bll.AreaAuthorizations.Edit(jd);
                if (result)
                {
                    return(Json(new { success = result }));
                }
                else
                {
                    return(Json(new { success = result, errors = bll.AreaAuthorizations.ErrorMessage }));
                }
            }

            GetListToViewBag();
            return(View(jd));
        }
 private void SetRoleAuthorization2(List <Area> areaList)
 {
     {
         foreach (var role in _roles)
         {
             foreach (var area in areaList)
             {
                 //var role = roles[7];
                 //  role7 = AddCardRole("参观人员(一般)", "能够进入生活区域和少部分生产区域");
                 var aa = AreaAuthorization.New();
                 aa.AreaId      = area.Id;             //根节点
                 aa.AccessType  = AreaAccessType.可以进出; //可进入的权限
                 aa.RangeType   = AreaRangeType.Single;
                 aa.Name        = string.Format("权限[园区参观(一般)]");
                 aa.Description = string.Format("权限:可以进入园区参观,不能靠近建筑物。");
                 areaAuthorizations.Add(aa);
                 AreaAuthorizations.Add(aa);
                 AddAAR(role, aa);
             }
         }
     }
 }
Example #16
0
        public bool SetCardRoleAccessAreas(int roleId, List <int> areaIds)
        {
            try
            {
                HashSet <int> areaIdHs    = new HashSet <int>(areaIds); //保证角色对应区域唯一性
                var           bll         = AppContext.GetLocationBll();
                var           aarService  = new AreaAuthorizationRecordService(bll);
                var           aaService   = new AreaAuthorizationService(bll);
                var           roleService = new TagRoleService(bll);
                var           role        = roleService.GetEntity(roleId + "");

                var aarList = aarService.GetListByRole(roleId + "");


                List <int> removeList = new List <int>();
                List <int> newList    = new List <int>();

                for (int i = 0; i < aarList.Count; i++)
                {
                    var aar = aarList[i];
                    if (aar.AccessType == AreaAccessType.能进入) //设置的是可以进入的权限,同时要把不能进入的权限都删了
                    {
                        //removeList.Add(aarList[i].Id);
                        var r = aarService.Delete(aar.Id + "");
                        aarList.RemoveAt(i);
                        i--;
                    }
                }

                List <int> areasIds = new List <int>();
                foreach (var item in aarList)
                {
                    if (item.Area != null)
                    {
                        int areaId = item.Area.Id;
                        if (!areasIds.Contains(areaId))
                        {
                            areasIds.Add(areaId);                           //保证areasIds唯一性
                        }
                    }
                }

                foreach (var item in areaIdHs)
                {
                    if (areasIds.Contains(item))
                    {
                        areasIds.Remove(item);
                    }
                    else
                    {
                        newList.Add(item);
                    }
                }
                removeList.AddRange(areasIds);

                foreach (var areaId in removeList)
                {
                    //var aar = aarList.FirstOrDefault(i => i.Area!=null&&i.Area.Id == areaId);
                    //if (aar != null)
                    //{
                    //    var r = aarService.Delete(aar.Id + "");
                    //}

                    //权限表中,出现过AreaId和cardId对应并重复的数据。现在取消权限时,把AreadId重复的都删除掉
                    aarService.RemoveListByAreaId(areaId, aarList);
                }

                foreach (var areaId in newList)
                {
                    var list = aaService.GetListByArea(areaId + "");
                    if (list.Count == 0)//新增的区域没有对应的权限设置数据
                    {
                        var aaNew = AreaAuthorization.New();
                        aaNew.AreaId     = areaId;              //根节点
                        aaNew.AccessType = AreaAccessType.可以进出; //可进入的权限
                        aaNew.RangeType  = AreaRangeType.Single;
                        string areaType = "区域";
                        aaNew.Name        = string.Format("权限[" + areaType + "]");
                        aaNew.Description = string.Format("权限:可以进入" + areaType + "。");
                        var aaNewR = aaService.Post(aaNew);
                        list.Add(aaNewR);//后续挪动到aaService里面。
                    }
                    var aa = list.FirstOrDefault(i => i.AccessType == AreaAccessType.可以进出);
                    if (aa != null)
                    {
                        var aar = new AreaAuthorizationRecord(aa, role);
                        var r   = aarService.Post(aar);
                    }
                    else
                    {
                        Log.Error("SetCardRoleAccessAreas", "为找到区域对应的权限数据:" + areaId);
                    }
                }
                RefreshData();
            }
            catch (Exception ex)
            {
                Log.Error(tag, "SetCardRoleAccessAreas", ex.ToString());
                return(false);
            }
            return(true);
        }
        private void SetRoleAuthorization5(List <Area> areaList)
        {
            List <AreaAuthorization> temp  = new List <AreaAuthorization>();
            List <CardRole>          temp2 = new List <CardRole>();

            for (int j = 1; j <= 4; j++)
            {
                var role = _roles[j];
                foreach (var area in areaList)
                {
                    var aa = AreaAuthorization.New();
                    aa.AreaId      = area.Id;             //根节点
                    aa.AccessType  = AreaAccessType.可以进出; //可进入的权限
                    aa.RangeType   = AreaRangeType.WithParent;
                    aa.Name        = string.Format("权限[机房]");
                    aa.Description = string.Format("权限:可以进入机房。");
                    areaAuthorizations.Add(aa);

                    temp.Add(aa);
                    temp2.Add(role);

                    //AreaAuthorizations.Add(aa);
                    //AddAAR(role, aa);
                }
            }
            AreaAuthorizations.AddRange(temp);

            if (authorizationRecords == null)
            {
                authorizationRecords = new List <AreaAuthorizationRecord>();
            }

            List <AreaAuthorizationRecord> temp3 = new List <AreaAuthorizationRecord>();

            for (int i = 0; i < temp.Count; i++)
            {
                var role = temp2[i];
                var aa   = temp[i];
                //AddAAR(role, aa);

                var aar = new AreaAuthorizationRecord(aa, role);

                authorizationRecords.Add(aar);

                temp3.Add(aar);

                //AreaAuthorizationRecords.Add(aar);

                //if (authorizationAreas != null)
                //{
                //    var aa2 = authorizationAreas.Find(item => item.Id == aa.AreaId);
                //    if (aa2 != null)
                //    {
                //        aa2.Records.Add(aar);
                //    }
                //}
            }

            AreaAuthorizationRecords.AddRange(temp3);

            foreach (var aar in temp3)
            {
                if (authorizationAreas != null)
                {
                    var aa2 = authorizationAreas.Find(item => item.Id == aar.AreaId);
                    if (aa2 != null)
                    {
                        aa2.Records.Add(aar);
                    }
                }
            }
        }