Ejemplo n.º 1
0
        /// <summary>
        /// 通过区域ID,查找对应定位卡号
        /// </summary>
        /// <param name="areaId"></param>
        /// <returns></returns>
        public TopologyToLocationCards GetAreaLocationCardById(int areaId)
        {
            TopologyToLocationCards result = new TopologyToLocationCards();

            result.AreaId = areaId;
            List <LocationCardToArea> relations = db.LocationCardToArea.FindAll(i => i.AreaId == areaId);

            if (relations != null)
            {
                result.LocationCards = new List <string>();
                foreach (var rela in relations)
                {
                    LocationCard card = db.LocationCards.Find(i => i.Id == rela.LocationCardId);
                    if (card != null)
                    {
                        result.LocationCards.Add(card.Code);
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
 public TopologyToLocationCards EditDynamicRange(TopologyToLocationCards pt)
 {
     return(service.EditDynamicRange(pt));
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 编辑动态区域信息
 /// </summary>
 /// <param name="pt"></param>
 /// <returns></returns>
 public TopologyToLocationCards EditDynamicRange(TopologyToLocationCards pt)
 {
     try
     {
         List <LocationCard> cardList = new List <LocationCard>();
         foreach (var item in pt.LocationCards)
         {
             if (string.IsNullOrEmpty(item))
             {
                 continue;
             }
             LocationCard cardT = db.LocationCards.Find(i => i.Code.ToLower() == item.ToLower());
             //异常情况:1.定位卡编号不存在
             if (cardT == null && !string.IsNullOrEmpty(item))
             {
                 pt.ErrorInfo = string.Format("定位卡,卡号:{0} 不存在!", item);
                 return(pt);
             }
             //2.定位卡已经绑定其他区域
             LocationCardToArea bindingOther = db.LocationCardToArea.Find(i => i.LocationCardId == cardT.Id && i.AreaId != pt.AreaId);
             if (bindingOther != null)
             {
                 Area area = db.Areas.Find(i => i.Id == bindingOther.AreaId);
                 pt.ErrorInfo = string.Format("定位卡,卡号:{0},已绑定区域:{1} \n请更换其他定位卡,获取解绑该定位卡!", item, area == null?bindingOther.AreaId.ToString():area.Name);
                 return(pt);
             }
             //如没有异常,则保存到数据库
             if (cardT != null)
             {
                 cardList.Add(cardT);
             }
         }
         List <LocationCardToArea> relations = db.LocationCardToArea.FindAll(i => i.AreaId == pt.AreaId);
         if (relations != null)
         {
             db.LocationCardToArea.RemoveList(relations);
         }
         List <LocationCardToArea> newRelations = new List <LocationCardToArea>();
         foreach (var item in cardList)
         {
             LocationCardToArea card = new LocationCardToArea();
             card.AreaId         = pt.AreaId;
             card.LocationCardId = item.Id;
             newRelations.Add(card);
         }
         if (newRelations.Count != 0)
         {
             bool value = db.LocationCardToArea.AddRange(newRelations);
             if (value)
             {
                 return(pt);
             }
         }
         pt.ErrorInfo = "修改区域关联定位卡失败!";
         return(pt);
     }
     catch (Exception e)
     {
         pt.ErrorInfo = "修改区域关联定位卡失败!";
         return(pt);
     }
 }