public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 {
     int villageID = (int)value;
     Village village = new Village();
     village.id = villageID;
     village.select();
     return String.Format(@"{0}:", village.name);
 }
 public bool isDirty()
 {
     for (int i = 0; i < villageList.Count; i++)
     {
         var village = villageList[i];
         var villageCopy = new Village();
         villageCopy.id = village.id;
         villageCopy.select();
         var houseList = village.houseList;
         var houseListCopy = villageCopy.getAllRelatedHouse();
         var commonHouse = village.commonHouse;
         var commonHouseCopy = villageCopy.getRelatedCommonHouse();
         if (!commonHouse.compare(commonHouseCopy))
         {
             return true;
         }
         if (houseList.Count != houseListCopy.Count)
         {
             return true;
         }
         for (int j = 0; j < houseList.Count; j++)
         {
             var house = houseList[j];
             var houseCopy = houseListCopy[j];
             if (!house.compare(houseCopy))
             {
                 return true;
             }
         }
     }
     return false;
 }
        private void FinishMainRoadButtonClick(object sender, RoutedEventArgs e)
        {
            if (isValid())
            {
                if (isDirty())
                {
                    if (Ut.C("继续操作会清空之后的数据, 是否继续?"))
                    {
                        dirty = true;
                        valid = true;

                        foreach (MainRoad mainRoad in mainRoadList)
                        {
                            if (mainRoad.needDelete)
                                mainRoad.delete();
                            else
                                mainRoad.saveOrUpdate();
                        }

                        //1. 靠主路生成区域.
                        GisUtil.CreateShapefile(C.PROGRAM_FOLDER, SiteSelectorUserControl.MAINROAD_LIST_SHP_NAME, mapControl.SpatialReference, "polyline");
                        List<IGeometry> mainRoadGeometryList = new List<IGeometry>();
                        foreach (MainRoad mainRoad in mainRoadList)
                        {
                            IElement element = mainRoad.lineElement as IElement;
                            mainRoadGeometryList.Add(element.Geometry);
                        }
                        GisUtil.AddGeometryListToShpFile(mainRoadGeometryList, C.PROGRAM_FOLDER, SiteSelectorUserControl.MAINROAD_LIST_SHP_NAME);
                        cachedVillageAreaPolygonList = GisUtil.GetPolygonListFromPolylineList(
                            Ut.MakePath(C.PROGRAM_FOLDER, SiteSelectorUserControl.MAINROAD_LIST_SHP_NAME),
                            Ut.MakePath(C.PROGRAM_FOLDER, SiteSelectorUserControl.VILLAGE_AREA_SHP_NAME));
                        foreach (IPolygon polygon in cachedVillageAreaPolygonList)
                        {
                            GisUtil.drawPolygon(polygon, mapControl);
                        }

                        //2. 检查生成的区域是否符合标准.
                        bool errorFlag = false;
                        if (cachedVillageAreaPolygonList.Count == 0)
                            errorFlag = true;
                        foreach (IPolygon polygon in cachedVillageAreaPolygonList)
                        {
                            IArea area = polygon as IArea;
                            if (area.Area > Village.VILLAGE_MAX_SIZE)
                            {
                                errorFlag = true;
                                break;
                            }
                        }
                        if (errorFlag)
                            Ut.M("生成的图形中包含错误.");

                        //3. 区域形成village对象和相应的内部路对象.
                        villageList = new ObservableCollection<Village>();
                        foreach (IPolygon polygon in cachedVillageAreaPolygonList)
                        {
                            Village village = new Village();
                            village.programID = program.id;
                            IPolygonElement polygonElement = new PolygonElementClass();
                            IElement element = polygonElement as IElement;
                            element.Geometry = polygon;
                            village.polygonElement = polygonElement;
                            village.updateBoundary();

                            InnerRoad innerRoad = new InnerRoad();
                            innerRoad.programID = program.id;
                            innerRoad.villageID = village.id;
                            village.innerRoad = innerRoad;
                            villageList.Add(village);
                        }
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    valid = true;
                    return;
                }
            }
            else
            {
                Ut.M("请完整填写信息");
                return;
            }
        }
        private void onMapControlMouseDown(Village village)
        {
            IPolyline innerRoadPolyline = mapControl.TrackLine() as IPolyline;
            //这里是不是要对画好的线做一下检查, 比如保证内部路穿过了小区区域.
            IPolygonElement villagePolygonElement = village.polygonElement;
            IPolygon villagePolygon = (villagePolygonElement as IElement).Geometry as IPolygon;
            IRelationalOperator innerRoadPolylineRelationalOperator = innerRoadPolyline as IRelationalOperator;
            IRelationalOperator villagePolygonRelationOperator = villagePolygon as IRelationalOperator;
            ITopologicalOperator villagePolygonTopologicalOperator = villagePolygon as ITopologicalOperator;
            IPolyline villageBoundaryPolyline = villagePolygonTopologicalOperator.Boundary as IPolyline;
            ITopologicalOperator villageBoundaryPolylineTopologicalOperator = villageBoundaryPolyline as ITopologicalOperator;
            IPointCollection pointCollection = villageBoundaryPolylineTopologicalOperator.Intersect(innerRoadPolyline, esriGeometryDimension.esriGeometry0Dimension) as IPointCollection;
            if (pointCollection.PointCount < 2)
            {
                Ut.M("内部路必须穿过小区");
                mainWindow.unmask();
                return;
            }
            innerRoadPolyline = villagePolygonTopologicalOperator.Intersect(innerRoadPolyline, esriGeometryDimension.esriGeometry1Dimension) as IPolyline;

            if (village.innerRoad.lineElement != null)
            {
                GisUtil.ErasePolylineElement(village.innerRoad.lineElement, mapControl);
            }
            ILineElement innerRoadLineElement = new LineElementClass();
            IElement element = innerRoadLineElement as IElement;
            element.Geometry = innerRoadPolyline;
            village.innerRoad.lineElement = innerRoadLineElement;
            village.innerRoad.updatePath();
            GisUtil.DrawPolylineElement(innerRoadLineElement, mapControl);
            mainWindow.unmask();
        }
        public bool isDirty()
        {
            ObservableCollection<Village> tempVillageList = program.getAllRelatedVillage();
            if (villageList.Count != tempVillageList.Count)
                return true;

            foreach (Village village in villageList)
            {
                int villageID = village.id;
                Village villageCopy = new Village();
                villageCopy.id = villageID;
                villageCopy.select();
                if (!village.compare(villageCopy))
                {
                    return true;
                }

                int innerRoadID = village.innerRoad.id;
                InnerRoad innerRoadCopy = new InnerRoad();
                innerRoadCopy.id = innerRoadID;
                innerRoadCopy.select();
                if (!village.innerRoad.compare(innerRoadCopy))
                {
                    return true;
                }
            }

            return false;
        }
Example #6
0
 public bool compare(Village village)
 {
     if (id != village.id)
         return false;
     if (prID != village.programID)
         return false;
     if (vName != village.name)
         return false;
     if (vBoundary != village.boundary)
         return false;
     if (vInUse != village.inUse)
         return false;
     return true;
 }
Example #7
0
        public ObservableCollection<Village> getAllRelatedVillage()
        {
            if (!isValid(new List<string>() { "prName", "pID" }))
                return null;

            ObservableCollection<Village> villageList = new ObservableCollection<Village>();
            string sqlCommand = String.Format(@"select vID from Village where prID={0}", prID);
            Sql sql = new Sql();
            SqlDataReader reader = sql.selectAllVillageByPrID(sqlCommand);
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    int vID = Int32.Parse(reader[0].ToString());
                    Village village = new Village();
                    village.id = vID;
                    village.select();
                    villageList.Add(village);
                }
                sql.closeConnection();
                return villageList;
            }
            else
            {
                sql.closeConnection();
                return null;
            }
        }