public BasicResponse <AreaInfo> AddArea(AreaAddRequest arearequest) { var arearesponse = new BasicResponse <AreaInfo>(); //判断缓存中是否存在 AreaInfo oldArea = null; AreaCacheGetByKeyRequest AreaCacheRequest = new AreaCacheGetByKeyRequest(); AreaCacheRequest.Areaid = arearequest.AreaInfo.Areaid; oldArea = _AreaCacheService.GetByKeyAreaCache(AreaCacheRequest).Data; if (oldArea != null) { //缓存中存在此测点 arearesponse.Code = 1; arearesponse.Message = "当前添加的区域已存在!"; return(arearesponse); } //向网关同步数据 20180103 if (!string.IsNullOrEmpty(arearequest.AreaInfo.Bz3) && arearequest.AreaInfo.Bz3 == "1")//如果是广播分区,则需要向网关同步数据 { List <AreaInfo> SendItemList = new List <AreaInfo>(); SendItemList.Add(arearequest.AreaInfo); var resultSync = SynchronousDataToGateway(SendItemList); if (!resultSync) { arearesponse.Code = 1; arearesponse.Message = "向网关同步数据失败!"; return(arearesponse); } } var _area = ObjectConverter.Copy <AreaInfo, AreaModel>(arearequest.AreaInfo); var resultarea = _Repository.AddArea(_area); //更新区域限制、禁止进入人员信息 SaveRestrictedperson(arearequest.AreaInfo.Areaid, arearequest.AreaInfo.RestrictedpersonInfoList); //更新区域识别器定义限制信息 SaveAreaRule(arearequest.AreaInfo.Areaid, arearequest.AreaInfo.AreaRuleInfoList); //更新区域缓存 20171128 AreaCacheAddRequest AreaCacheAddRequest = new Sys.Safety.Request.PersonCache.AreaCacheAddRequest(); AreaCacheAddRequest.AreaInfo = arearequest.AreaInfo; _AreaCacheService.AddAreaCache(AreaCacheAddRequest); arearesponse.Data = ObjectConverter.Copy <AreaModel, AreaInfo>(resultarea); return(arearesponse); }
/// <summary> /// 添加或修改区域及其规则入数据库 /// </summary> private void AddAreaAndRulesToDB() { AreaInfo temparea = null; if (type == 0) { //新增 temparea = GetAreaInfoItem(txt_areaName.Text.Trim(), txt_areaPosition.Text); } else { //修改 temparea = GetAreaByAreaID(areaid); } List <AreaRuleInfo> areaRuleInfoList = new List <AreaRuleInfo>(); for (int i = 0; i < gridView1.RowCount; i++) { AreaRuleInfo areaRuleItem = GetAreaRuleItem(Convert.ToInt32(gridView1.GetRowCellValue(i, "devid").ToString()) , Convert.ToInt32(gridView1.GetRowCellValue(i, "deviceCount").ToString()) , float.Parse(gridView1.GetRowCellValue(i, "maxVal").ToString()) , float.Parse(gridView1.GetRowCellValue(i, "minVal").ToString()) , temparea.Areaid); areaRuleInfoList.Add(areaRuleItem); } if (type == 0) { //增加区域设备定义限制信息 temparea.AreaRuleInfoList = areaRuleInfoList; AreaAddRequest areaAddRequest = new AreaAddRequest(); areaAddRequest.AreaInfo = temparea; areaService.AddArea(areaAddRequest); } else { //修改 temparea.AreaBound = txt_areaPosition.Text; temparea.Areaname = txt_areaName.Text.Trim(); temparea.CreateUpdateTime = DateTime.Now; //增加人员报警信息 20171129 temparea.Bz1 = AlarmTime.Text; temparea.Bz2 = RatedPersonCount.Value.ToString(); temparea.RestrictedpersonInfoList = restrictedpersonInfoList; //增加区域设备定义限制信息 temparea.AreaRuleInfoList = areaRuleInfoList; AreaUpdateRequest areaUpdateRequest = new AreaUpdateRequest(); areaUpdateRequest.AreaInfo = temparea; areaService.UpdateArea(areaUpdateRequest); } //DeleteAreaRules(temparea.Areaid); //AreaRuleInfo areaRuleItem; //AreaRuleAddRequest areaRuleAddRequest; //for (int i = 0; i < gridView1.RowCount; i++) //{ // areaRuleItem = GetAreaRuleItem(Convert.ToInt32(gridView1.GetRowCellValue(i, "devid").ToString()) // , Convert.ToInt32(gridView1.GetRowCellValue(i, "deviceCount").ToString()) // , float.Parse(gridView1.GetRowCellValue(i, "maxVal").ToString()) // , float.Parse(gridView1.GetRowCellValue(i, "minVal").ToString()) // , temparea.Areaid); // areaRuleAddRequest = new AreaRuleAddRequest(); // areaRuleAddRequest.AreaRuleInfo = areaRuleItem; // areaRuleService.AddAreaRule(areaRuleAddRequest); //} }