public ActionResult CardSet(int?id) //添加id,接收点击某一行的人员传递的参数
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var psl = bll.Personnels.Find(id);//获取当前人员

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

            LocationCardToPersonnel lcp = bll.LocationCardToPersonnels.Find(p => p.PersonnelId == id);

            ViewBag.CardId = null;
            if (lcp != null)
            {
                ViewBag.CardId = lcp.LocationCardId;
            }

            //设置相关信息给前台
            ViewBag.PersonId = id;
            //ViewBag.CardId = ;
            ViewBag.PersonName = psl.Name;

            List <LocationCard> locationCardList = db.LocationCards.ToList();

            return(PartialView("CardSet", locationCardList));
        }
        public static LocationCardToPersonnel CreateRelationFromDataRow(string mainType, DataRow dr, ref List <Personnel> pList, ref List <LocationCard> LcList)
        {
            DataTable dt            = dr.Table;
            string    strPersonName = dr[0].ToString();
            string    strCode       = dr[1].ToString();

            if (strPersonName == "" || strCode == "")
            {
                return(null);
            }

            Bll bll     = new Bll();
            int nCount  = pList.Where(p => p.Name == strPersonName).Count();
            int nCount2 = LcList.Where(p => p.Code == strCode).Count();

            if (nCount == 0 || nCount2 == 0)
            {
                return(null);
            }

            int nPId = pList.Where(p => p.Name == strPersonName).Select(p => p.Id).FirstOrDefault();
            int nCId = LcList.Where(p => p.Code == strCode).Select(p => p.Id).FirstOrDefault();

            LocationCardToPersonnel lcp = new LocationCardToPersonnel();

            lcp.PersonnelId    = nPId;
            lcp.LocationCardId = nCId;

            return(lcp);
        }
        public LocationAlarm SetPerson(LocationCardToPersonnel p)
        {
            LocationCardId = p.LocationCardId;
            LocationCard   = p.LocationCard;
            PersonnelId    = p.PersonnelId;
            Personnel      = p.Personnel;

            return(this);
        }
Exemple #4
0
        public void BindCardToPerson(Personnel person, LocationCard tag)
        {
            if (tag != null && person != null)
            {
                LocationCardToPersonnel cardToPerson = new LocationCardToPersonnel();
                cardToPerson.PersonnelId    = person.Id;
                cardToPerson.LocationCardId = tag.Id;
                LocationCardToPersonnels.Add(cardToPerson);

                tag.IsActive = true;//绑定了人员就激活
                LocationCards.Edit(tag);
            }
        }
Exemple #5
0
        private Personnel AddPersonByTag(Position pos, LocationCard tag)
        {
            Personnel person = new Personnel();

            person.Name     = "Tag_" + pos.Code;
            person.ParentId = 6;//访客
            bool r2 = bll.Personnels.Add(person);

            if (r2)
            {
                var perToCard = new LocationCardToPersonnel();
                perToCard.LocationCard = tag;
                perToCard.Personnel    = person;
                bool r3 = bll.LocationCardToPersonnels.Add(perToCard);
                return(person);
            }
            return(null);
        }
        public static List <LocationCardToPersonnel> CreateRelationListFromDataTable(string mainType, DataTable dt, List <Personnel> pList, List <LocationCard> LcList)
        {
            List <LocationCardToPersonnel> list = new List <LocationCardToPersonnel>();

            foreach (DataRow dr in dt.Rows)
            {
                LocationCardToPersonnel lcp = CreateRelationFromDataRow(mainType, dr, ref pList, ref LcList);//根据表格内容创建KKS对象
                if (lcp == null)
                {
                    continue;
                }
                int nCount = list.FindAll(p => p.PersonnelId == lcp.PersonnelId && p.LocationCardId == lcp.LocationCardId).Count;
                if (nCount >= 1)
                {
                    continue;
                }

                list.Add(lcp);
            }
            return(list);
        }
        private void AddPerson(string name, Sexs sex, LocationCard tag, Department dep, Post pst, int worknumber, string phone)
        {
            Personnel person = new Personnel()
            {
                Name       = name,
                Sex        = sex,
                Enabled    = true,
                ParentId   = dep.Id,
                WorkNumber = worknumber,
                Phone      = phone,
                Pst        = pst.Name
            };

            Personnels.Add(person);


            if (tag != null && person != null)
            {
                LocationCardToPersonnel cardToPerson = new LocationCardToPersonnel();
                cardToPerson.PersonnelId    = person.Id;
                cardToPerson.LocationCardId = tag.Id;
                LocationCardToPersonnels.Add(cardToPerson);
            }
        }
        private List <LocationAlarm> GetAlarmList()
        {
            List <LocationAlarm> list = new List <LocationAlarm>();

            try
            {
                List <Personnel> personnelList         = db.Personnels.ToList();
                List <Area>      areaList              = db.Areas.ToList();
                List <AreaAuthorizationRecord> aarList = db.AreaAuthorizationRecords.FindAll(i => i.SignIn == true);
                foreach (Personnel person in personnelList)
                {
                    string   strsql = string.Format(@"select a.* from cardroles a  inner join locationcards  b  on a.id=b.CardRoleId  inner join  locationcardtopersonnels c on b.id=c.LocationCardId  where c.PersonnelId=" + person.Id);
                    CardRole role   = db.CardRoles.GetDataBySql <CardRole>(strsql);
                    LocationCardToPersonnel card = db.LocationCardToPersonnels.Find(i => i.PersonnelId == person.Id);
                    if (role == null || card == null)
                    {
                        continue;
                    }
                    foreach (Area area in areaList)
                    {
                        AreaAuthorizationRecord aar = aarList.Find(i => i.AreaId == area.Id && i.CardRoleId == role.Id);
                        if (aar != null)
                        {
                            DateTime nowTime      = DateTime.Now;
                            DateTime nowEndTime   = new DateTime(nowTime.Year, nowTime.Month, nowTime.Day, aar.EndTime.Hour, aar.EndTime.Minute, aar.EndTime.Second);
                            DateTime nowStartTime = new DateTime(nowTime.Year, nowTime.Month, nowTime.Day, aar.StartTime.Hour, aar.StartTime.Minute, aar.StartTime.Second);
                            if (nowTime > nowEndTime)//可以判断是否产生告警
                            {
                                Position position = new Position();
                                position.CardId      = card.LocationCardId;
                                position.RoleId      = role.Id;
                                position.PersonnelID = person.Id;
                                PersonnelFirstInArea personArea = db.PersonnelFirstInAreas.Find(i => i.areaId == area.Id && i.personId == person.Id && i.type == 1);
                                if (personArea == null)//表示人员person当天未到过该区域
                                {
                                    //未签到告警
                                    LocationAlarm alarm1 = new LocationAlarm(position, area.Id, aar, person.Name, LocationAlarmLevel.四级告警, LocationAlarmType.签到告警);
                                    list.Add(alarm1);
                                }
                                else
                                {
                                    DateTime dateTime = personArea.dateTime;
                                    if (dateTime > nowStartTime && dateTime < nowEndTime)//时间范围内进入过
                                    {
                                        //正常告警
                                        LocationAlarm alarm1 = new LocationAlarm(position, area.Id, aar, person.Name, LocationAlarmLevel.正常, LocationAlarmType.签到告警);
                                        list.Add(alarm1);
                                    }
                                    else
                                    {
                                        //未签到告警
                                        LocationAlarm alarm1 = new LocationAlarm(position, area.Id, aar, person.Name, LocationAlarmLevel.四级告警, LocationAlarmType.签到告警);
                                        list.Add(alarm1);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error("SignInAlarmThread.GetCacheList:" + ex.ToString());
            }
            return(list);
        }