public ActionResult SaveDeviceRelation(DeviceRelation relation, string plantId)
        {
            relation.monitorCode = Request["monitorCode"] == null ? "," : Request["monitorCode"];
            TempData["hdndid"] = relation.parentDeviceId;
            TempData["name"] = relation.name;
            if (relation.deviceId.Equals(relation.parentDeviceId))
                TempData["error"] = Resources.SunResource.DEVICE_RELATION_NOTICE3;
            else
            {
                //查询当前设备的下级设备

                var drs = DeviceRelationService.GetInstance().getListbyparentDeviceId(relation.deviceId);
                string ids = childDeviceIds(drs);
                if (ids.Contains(relation.parentDeviceId + ","))
                {
                    TempData["error"] = Resources.SunResource.DEVICE_RELATION_NOTICE3;
                }
                else
                {
                    DeviceRelationService.GetInstance().Save(relation);
                    IList<DeviceRelation> tmpRelations = DeviceRelationService.GetInstance().getListbyparentDeviceId(relation.parentDeviceId);
                    tmpRelations = tmpRelations.Where(m => m.name.Equals(relation.name)).ToList<DeviceRelation>();
                    if (tmpRelations.Count == 0 || DeviceRelationService.GetInstance().getNamesPlantId(relation.plantId).Count == 0)
                    {
                        relation.deviceId = relation.parentDeviceId;
                        relation.parentDeviceId = 0;
                        DeviceRelationService.GetInstance().Save(relation);
                    }
                }
            }

            return Redirect("/plant/devicerelation/" + plantId + "?name=" + relation.name);
        }
 public int Remove(DeviceRelation rolation)
 {
     return _deviceRelationDao.Remove(rolation);
 }
 public int Save(DeviceRelation relation)
 {
     if (relation.id > 0)
         return _deviceRelationDao.Update(relation);
     return _deviceRelationDao.Insert(relation);
 }
 public DeviceRelation Get(DeviceRelation rolation)
 {
     return _deviceRelationDao.Get(rolation);
 }