Example #1
0
        public override void Run(object sender, EventArgs e)
        {
            int            i = 0, k;
            string         strDicValue;
            string         strPntID;
            IFeatureClass  Pntfc;
            IFeatureClass  Arcfc;
            IFeatureCursor pFeaCursor;
            IQueryFilter   pFilter = new QueryFilterClass();
            IFeature       pFea;

            string[] arrFc2DId;

            mapView = UCService.GetContent(typeof(Map2DView)) as Map2DView;
            if (mapView == null)
            {
                return;
            }
            bool bBind = mapView.Bind(this);

            if (!bBind)
            {
                return;
            }
            app = (DF2DApplication)this.Hook;
            if (app == null || app.Current2DMapControl == null)
            {
                return;
            }
            m_pMapControl = app.Current2DMapControl;
            frmSelType frmType = new frmSelType();

            if (frmType.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    List <DF2DFeatureClass> pPntlist = new List <DF2DFeatureClass>();
                    List <DF2DFeatureClass> pArclist = new List <DF2DFeatureClass>();

                    m_arrPipeType = frmType.PipeType;
                    for (i = 0; i < m_arrPipeType.Count; i++)
                    {
                        MajorClass mc = m_arrPipeType[i] as MajorClass;
                        arrFc2DId = mc.Fc2D.Split(';');
                        if (arrFc2DId == null)
                        {
                            continue;
                        }
                        foreach (string fc2DId in arrFc2DId)
                        {
                            DF2DFeatureClass dffc = DF2DFeatureClassManager.Instance.GetFeatureClassByID(fc2DId);
                            if (dffc == null)
                            {
                                continue;
                            }
                            IFeatureClass fc = dffc.GetFeatureClass();
                            if (fc == null)
                            {
                                continue;
                            }
                            if (dffc.GetFacilityClassName() == "PipeNode")
                            {
                                pPntlist.Add(dffc);
                                continue;
                            }
                            if (dffc.GetFacilityClassName() == "PipeLine")
                            {
                                pArclist.Add(dffc);
                                continue;
                            }
                        }
                    }
                    if ((pPntlist == null) || (pArclist == null))
                    {
                        return;
                    }
                    Dictionary <IFeatureClass, DataTable> dict = new Dictionary <IFeatureClass, DataTable>();
                    WaitForm.Start("开始数据一致性检查..", "请稍候");
                    int count = 0;
                    foreach (DF2DFeatureClass Pntdfcc in pPntlist)
                    {
                        DataTable        dt      = GetDataTableByStruture();
                        DF2DFeatureClass Arcdfcc = pArclist[count];
                        Pntfc = Pntdfcc.GetFeatureClass();
                        Arcfc = Arcdfcc.GetFeatureClass();
                        if (Pntfc == null && Arcfc == null)
                        {
                            return;
                        }
                        WaitForm.SetCaption("正在检查图层:" + " " + Pntfc.AliasName);
                        FacilityClass fac = Pntdfcc.GetFacilityClass();
                        if (fac == null)
                        {
                            continue;
                        }
                        FacilityClass facc = Arcdfcc.GetFacilityClass();
                        if (facc == null)
                        {
                            continue;
                        }
                        //List<DFDataConfig.Class.FieldInfo> listField = fac.FieldInfoCollection;
                        DFDataConfig.Class.FieldInfo fi = fac.GetFieldInfoBySystemName("LinkType");
                        if (fi == null)
                        {
                            continue;
                        }
                        DFDataConfig.Class.FieldInfo fi1 = fac.GetFieldInfoBySystemName("Detectid");
                        if (fi1 == null)
                        {
                            continue;
                        }
                        DFDataConfig.Class.FieldInfo fi2 = facc.GetFieldInfoBySystemName("StartNo");
                        if (fi2 == null)
                        {
                            continue;
                        }
                        DFDataConfig.Class.FieldInfo fi3 = facc.GetFieldInfoBySystemName("EndNo");
                        if (fi3 == null)
                        {
                            continue;
                        }
                        DFDataConfig.Class.FieldInfo fi4 = fac.GetFieldInfoBySystemName("UState");
                        if (fi4 == null)
                        {
                            continue;
                        }
                        //                 DFDataConfig.Class.FieldInfo fi5 = facc.GetFieldInfoBySystemName("source");
                        //                 if (fi5 == null) continue;
                        pFeaCursor = Pntfc.Search(null, true);

                        while ((pFea = pFeaCursor.NextFeature()) != null)
                        {
                            bool b1 = false, b2 = false;

                            strPntID    = pFea.get_Value(Pntfc.FindField(fi1.Name)).ToString();
                            strDicValue = pFea.get_Value(Pntfc.FindField(fi.Name)).ToString();


                            if (strDicValue == "三通" || strDicValue == "三分支")
                            {
                                k = 3;
                            }
                            else if (strDicValue == "四通" || strDicValue == "四分支")
                            {
                                k = 4;
                            }
                            else if (strDicValue == "五通" || strDicValue == "五分支")
                            {
                                k = 5;
                            }
                            else if (strDicValue == "六通" || strDicValue == "六分支")
                            {
                                k = 6;
                            }
                            else if (strDicValue == "七通" || strDicValue == "七分支")
                            {
                                k = 7;
                            }
                            else if (strDicValue == "八通" || strDicValue == "八分支")
                            {
                                k = 8;
                            }
                            else
                            {
                                k = 2;
                            }
                            pFilter.WhereClause = fi2.Name + " = '" + strPntID + "' or " + fi3.Name + " = '" + strPntID + "'";
                            if (Arcfc.FeatureCount(pFilter) != k)
                            {
                                b1 = true;
                            }
                            if (Pntfc.FindField(fi4.Name) != -1 && Arcfc.FindField(fi4.Name) != -1)
                            {
                                pFilter.WhereClause = "(" + fi2.Name + " = '" + strPntID + "' or " + fi3.Name + " = '" + strPntID + "') and " + fi4.Name + " <> '" + strDicValue + "'";
                                if (Arcfc.FeatureCount(pFilter) > 0)
                                {
                                    b2 = true;
                                }
                            }



                            DataRow dr = dt.NewRow();
                            dr["ErrorFeatureID"] = pFea.OID;
                            dr["FeatureofClass"] = Pntfc.AliasName;
                            dr["FeatureofLayer"] = (Pntfc as IDataset).Name;
                            dr["FeatureClass"]   = Pntfc;

                            if (b1 && b2)
                            {
                                dr["ErrorType"] = "多通多分支与管点连接管线数量不一致;管点与相连接管线的使用状态不一致";
                            }
                            else if (b1 && !b2)
                            {
                                dr["ErrorType"] = "多通多分支与管点连接管线数量不一致";
                            }
                            else if (!b1 && b2)
                            {
                                dr["ErrorType"] = "管点与相连接管线的使用状态不一致";
                            }
                            dt.Rows.Add(dr);
                            //Console.WriteLine(pFea.OID + " " + Pntfc.AliasName);
                        }

                        if (dt.Rows.Count > 0)
                        {
                            dict[Pntfc] = dt;
                        }
                        count++;
                    }
                    WaitForm.Stop();
                    FormCheckResult dlg = new FormCheckResult(dict, m_pMapControl);
                    dlg.Text = this.CommandName;
                    dlg.Show();
                }
                catch (System.Exception ex)
                {
                }
            }
        }
        public override void OnMouseDown(int button, int shift, int x, int y, double mapX, double mapY)
        {
            DF2DApplication app = DF2DApplication.Application;

            m_ActiveView = app.Current2DMapControl.ActiveView;
            IGraphicsContainer pGC = m_ActiveView.GraphicsContainer;

            if (this.m_ActiveView.FocusMap.FeatureSelection != null)
            {
                this.m_ActiveView.FocusMap.ClearSelection();
            }
            bool ready = false;

            if (app == null || app.Current2DMapControl == null)
            {
                return;
            }
            IGeometry pGeo = null;

            try
            {
                if (button == 1)
                {
                    PointClass searchPoint = new PointClass();
                    searchPoint.PutCoords(mapX, mapY);
                    pGeo = PublicFunction.DoBuffer(searchPoint,
                                                   PublicFunction.ConvertPixelsToMapUnits(m_ActiveView, GlobalValue.System_Selection_Option().Tolerate));
                    if (pGeo == null)
                    {
                        return;
                    }
                    ready = true;
                    if (ready)
                    {
                        bool haveone = false;

                        foreach (LogicGroup lg in LogicDataStructureManage2D.Instance.RootLogicGroups)
                        {
                            foreach (MajorClass mc in lg.MajorClasses)
                            {
                                string[] arrFc2DId = mc.Fc2D.Split(';');
                                if (arrFc2DId == null)
                                {
                                    continue;
                                }
                                IFeatureCursor pFeatureCursor = null;
                                IFeature       pFeature       = null;

                                foreach (string fc2DId in arrFc2DId)
                                {
                                    DF2DFeatureClass dffc = DF2DFeatureClassManager.Instance.GetFeatureClassByID(fc2DId);
                                    if (dffc == null)
                                    {
                                        continue;
                                    }
                                    IFeatureClass fc   = dffc.GetFeatureClass();
                                    FacilityClass facc = dffc.GetFacilityClass();
                                    if (facc.Name != "PipeNode")
                                    {
                                        continue;
                                    }
                                    IFeatureLayer fl = dffc.GetFeatureLayer();
                                    if (fc == null || pGeo == null || fl == null)
                                    {
                                        continue;
                                    }
                                    if (!fl.Visible)
                                    {
                                        continue;
                                    }

                                    ISpatialFilter pSpatialFilter = new SpatialFilter();
                                    pSpatialFilter.Geometry   = pGeo;
                                    pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                                    pFeatureCursor            = fc.Search(pSpatialFilter, false);
                                    if (pFeatureCursor == null)
                                    {
                                        continue;
                                    }
                                    pFeature = pFeatureCursor.NextFeature();
                                    if (pFeature == null)
                                    {
                                        continue;
                                    }
                                    haveone = true;

                                    IGeometry pGeometry = pFeature.Shape as IGeometry;
                                    if (pGeometry.GeometryType == esriGeometryType.esriGeometryPoint)
                                    {
                                        IPoint pPoint = pGeometry as IPoint;
                                        if (this._bFinished)
                                        {
                                            this._bFinished = false;
                                            this._startFCID = fc.FeatureClassID.ToString();
                                            this._startOid  = pFeature.OID;
                                            AddCallout(pPoint, "起点");
                                            app.Current2DMapControl.ActiveView.Refresh();
                                        }
                                        else
                                        {
                                            if (this._startFCID == fc.FeatureClassID.ToString() && this._startOid == pFeature.OID)
                                            {
                                                XtraMessageBox.Show("您选中的是同一个管点设施。", "提示");
                                                return;
                                            }
                                            this._bFinished = true;
                                            AddCallout(pPoint, "终点");
                                            app.Current2DMapControl.ActiveView.Refresh();
                                            if (this._startFCID != fc.FeatureClassID.ToString())
                                            {
                                                XtraMessageBox.Show("您选中的不是同一类管点设施。", "提示");
                                                return;
                                            }
                                            else
                                            {
                                                WaitForm.Start("正在分析...", "请稍后");
                                                TopoClass2D tc = FacilityInfoService2D.GetTopoClassByFeatureClassID(fc.FeatureClassID.ToString());
                                                if (tc == null)
                                                {
                                                    return;
                                                }
                                                TopoNetwork net = tc.GetNetwork();
                                                if (net == null)
                                                {
                                                    WaitForm.Stop();
                                                    XtraMessageBox.Show("构建拓扑网络失败!", "提示");
                                                    return;
                                                }
                                                else
                                                {
                                                    string        startId = this._startFCID + "_" + this._startOid.ToString();
                                                    string        endId   = fc.FeatureClassID.ToString() + "_" + pFeature.OID.ToString();
                                                    List <string> path;
                                                    double        shortestLength = net.SPFA(startId, endId, out path);
                                                    if ((shortestLength > 0.0 && shortestLength != double.MaxValue) || (path != null && path.Count > 0))
                                                    {
                                                        List <IPoint>    listPt   = new List <IPoint>();
                                                        IPointCollection pointCol = new PolylineClass();
                                                        foreach (string nodeId in path)
                                                        {
                                                            int              index    = nodeId.LastIndexOf("_");
                                                            string           fcID     = nodeId.Substring(0, index);
                                                            string           oid      = nodeId.Substring(index + 1, nodeId.Length - index - 1);
                                                            DF2DFeatureClass dffcTemp = DF2DFeatureClassManager.Instance.GetFeatureClassByID(fcID);
                                                            if (dffcTemp == null || dffcTemp.GetFeatureClass() == null)
                                                            {
                                                                continue;
                                                            }
                                                            if (dffcTemp.GetFacilityClassName() != "PipeNode")
                                                            {
                                                                continue;
                                                            }
                                                            IQueryFilter filter = new QueryFilter();
                                                            filter.WhereClause = "OBJECTID =" + oid;
                                                            filter.SubFields   = "OBJECTID ,SHAPE";
                                                            IFeature       feature = null;
                                                            IFeatureCursor cursor  = null;
                                                            try
                                                            {
                                                                cursor = dffcTemp.GetFeatureClass().Search(filter, false);
                                                                while ((feature = cursor.NextFeature()) != null)
                                                                {
                                                                    if (feature.Shape != null && feature.Shape is IGeometry)
                                                                    {
                                                                        IGeometry geo = feature.Shape as IGeometry;
                                                                        switch (geo.GeometryType)
                                                                        {
                                                                        case esriGeometryType.esriGeometryPoint:
                                                                            IPoint pt = geo as IPoint;
                                                                            //pt.Z = pt.Z + 1;
                                                                            listPt.Add(pt);
                                                                            pointCol.AddPoint(pt);
                                                                            break;
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                            catch (System.Exception ex)
                                                            {
                                                            }
                                                            finally
                                                            {
                                                                if (cursor != null)
                                                                {
                                                                    System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor);
                                                                    cursor = null;
                                                                }
                                                                if (feature != null)
                                                                {
                                                                    System.Runtime.InteropServices.Marshal.ReleaseComObject(feature);
                                                                    feature = null;
                                                                }
                                                            }
                                                        }
                                                        if (listPt.Count > 0)
                                                        {
                                                            IPolyline         polyline    = pointCol as IPolyline;
                                                            ISimpleLineSymbol pLineSymbol = new SimpleLineSymbol();
                                                            pLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid;
                                                            pLineSymbol.Width = 5;
                                                            pLineSymbol.Color = GetRGBColor(0, 230, 240);
                                                            IElement elementL = new LineElement();
                                                            elementL.Geometry = polyline;
                                                            ILineElement pLineElement = elementL as ILineElement;
                                                            pLineElement.Symbol = pLineSymbol;
                                                            pGC.AddElement(elementL, 0);

                                                            ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbol();
                                                            simpleMarkerSymbol.Color   = GetRGBColor(255, 0, 0);
                                                            simpleMarkerSymbol.Outline = false;
                                                            simpleMarkerSymbol.Size    = 5;
                                                            simpleMarkerSymbol.Style   = esriSimpleMarkerStyle.esriSMSCircle;

                                                            foreach (IPoint pt in listPt)
                                                            {
                                                                try
                                                                {
                                                                    IMarkerElement pMarkerElement = new MarkerElementClass();
                                                                    pMarkerElement.Symbol = simpleMarkerSymbol;
                                                                    IElement pElement = pMarkerElement as IElement;
                                                                    pElement.Geometry = pt;
                                                                    pGC.AddElement(pElement, 0);
                                                                }
                                                                catch (System.Exception ex)
                                                                {
                                                                    continue;
                                                                }
                                                            }
                                                        }

                                                        app.Current2DMapControl.ActiveView.Refresh();
                                                    }
                                                    else
                                                    {
                                                        WaitForm.Stop();
                                                        XtraMessageBox.Show("两点不连通!", "提示");
                                                        pGC.DeleteAllElements();
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                if (haveone)
                                {
                                    break;
                                }
                            }
                            if (haveone)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                XtraMessageBox.Show("分析出错!", "提示");
            }
            finally
            {
                WaitForm.Stop();
            }
        }
Example #3
0
        public override void Run(object sender, EventArgs e)
        {
            string[] arrFc2DId;
            mapView = UCService.GetContent(typeof(Map2DView)) as Map2DView;
            if (mapView == null)
            {
                return;
            }
            bool bBind = mapView.Bind(this);

            if (!bBind)
            {
                return;
            }
            app = (DF2DApplication)this.Hook;
            if (app == null || app.Current2DMapControl == null)
            {
                return;
            }
            m_pMapControl = app.Current2DMapControl;

            frmSelType frmType = new frmSelType();

            if (frmType.ShowDialog() == DialogResult.OK)
            {
                List <DF2DFeatureClass> list = new List <DF2DFeatureClass>();
                m_arrPipeType = frmType.PipeType;
                for (int i = 0; i < m_arrPipeType.Count; i++)
                {
                    MajorClass mc = m_arrPipeType[i] as MajorClass;
                    arrFc2DId = mc.Fc2D.Split(';');
                    if (arrFc2DId == null)
                    {
                        continue;
                    }
                    foreach (string fc2DId in arrFc2DId)
                    {
                        DF2DFeatureClass dffc = DF2DFeatureClassManager.Instance.GetFeatureClassByID(fc2DId);
                        if (dffc == null || dffc.GetFacilityClassName() != "PipeLine")
                        {
                            continue;
                        }
                        IFeatureClass fc = dffc.GetFeatureClass();
                        if (fc == null)
                        {
                            continue;
                        }
                        //if (fc.ShapeType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline)
                        //{
                        list.Add(dffc);
                        //}
                    }
                }
                Dictionary <IFeatureClass, DataTable> dict = new Dictionary <IFeatureClass, DataTable>();
                WaitForm.Start("开始拓扑检查..", "请稍候");
                foreach (DF2DFeatureClass dffc in list)
                {
                    IFeatureClass fc = dffc.GetFeatureClass();
                    if (fc == null)
                    {
                        continue;
                    }
                    FacilityClass fac = dffc.GetFacilityClass();
                    if (fac == null)
                    {
                        continue;
                    }
                    List <DFDataConfig.Class.FieldInfo> listField = fac.FieldInfoCollection;
                    DFDataConfig.Class.FieldInfo        fi        = fac.GetFieldInfoBySystemName("StartHeight2D");
                    int index = fc.FindField(fi.Name);
                    WaitForm.SetCaption("正在检查图层:" + " " + fc.AliasName);
                    if (fi == null || index == -1)
                    {
                        continue;
                    }

                    DFDataConfig.Class.FieldInfo fi1 = fac.GetFieldInfoBySystemName("EndHeight");
                    int index1 = fc.FindField(fi1.Name);
                    if (fi1 == null || index1 == -1)
                    {
                        continue;
                    }

                    DFDataConfig.Class.FieldInfo fi2 = fac.GetFieldInfoBySystemName("StartDep");
                    int index2 = fc.FindField(fi2.Name);
                    if (fi2 == null || index2 == -1)
                    {
                        continue;
                    }

                    DFDataConfig.Class.FieldInfo fi3 = fac.GetFieldInfoBySystemName("EndDep");
                    int index3 = fc.FindField(fi3.Name);
                    if (fi3 == null || index3 == -1)
                    {
                        continue;
                    }

                    DataTable      dt         = GetDataTableByStruture();
                    IFeatureCursor pFeaCursor = fc.Search(null, true);
                    IFeature       pFea       = pFeaCursor.NextFeature();
                    while (pFea != null)
                    {
                        //Console.WriteLine(pFea.OID + " " + fc.AliasName);
                        bool   b1 = false, b2 = false;
                        string obj  = pFea.get_Value(index).ToString();
                        string obj1 = pFea.get_Value(index1).ToString();
                        if (obj != "" && obj1 != "")
                        {
                            double d;
                            if (!double.TryParse(obj1, out d))
                            {
                                d = 0.0;
                            }

                            if (Math.Abs(double.Parse(obj) - double.Parse(obj1)) > 1)
                            {
                                b1 = true;
                            }
                        }
                        string obj2 = pFea.get_Value(index2).ToString();
                        string obj3 = pFea.get_Value(index3).ToString();
                        /* if (obj3 != null) continue;*/
                        if ((obj2 != "") && (obj3 != ""))
                        {
                            double d;
                            if (!double.TryParse(obj2, out d))
                            {
                                d = 0.0;
                            }

                            if (Math.Abs(double.Parse(obj2) - double.Parse(obj3)) > 0.5)
                            {
                                b2 = true;
                            }
                        }
                        if (b1 && b2)
                        {
                            DataRow dr = dt.NewRow();
                            dr["ErrorFeatureID"] = pFea.OID;
                            dr["FeatureofClass"] = fc.AliasName;
                            dr["FeatureofLayer"] = (fc as IDataset).Name;
                            dr["FeatureClass"]   = fc;
                            if (b1 && b2)
                            {
                                dr["ErrorType"] = "管线起止点高程差值超出规范值;管线起止点埋深差值超出规范值";
                            }
                            else if (b1 && !b2)
                            {
                                dr["ErrorType"] = "管线起止点高程差值超出规范值";
                            }
                            else if (b2 && !b1)
                            {
                                dr["ErrorType"] = "管线起止点埋深差值超出规范值";
                            }
                            dt.Rows.Add(dr);
                        }
                        pFea = pFeaCursor.NextFeature();
                    }
                    if (dt.Rows.Count > 0)
                    {
                        dict[fc] = dt;
                    }
                }
                WaitForm.Stop();
                FormCheckResult dlg = new FormCheckResult(dict, m_pMapControl);
                dlg.Text = this.CommandName;
                dlg.Show();
            }
        }
Example #4
0
        private void DataArcCheck()
        {
            //管线线表数据规范性检查
            int            i, j, k;
            string         strFld;
            string         strDicValue;
            IFeatureClass  pFeaClass;
            IFeatureCursor pFeaCursor;
            IQueryFilter   pFilter = new QueryFilterClass();
            //Dictionary<IFeatureClass, DataTable> dict = new Dictionary<IFeatureClass, DataTable>();
            IFeature pFea;

            string[] arrFc2DId;
            List <DF2DFeatureClass> List = new List <DF2DFeatureClass>();

            for (i = 0; i < m_arrPipeType.Count; i++)
            {
                MajorClass mc = m_arrPipeType[i] as MajorClass;
                arrFc2DId = mc.Fc2D.Split(';');
                if (arrFc2DId == null)
                {
                    continue;
                }
                foreach (string fc2DId in arrFc2DId)
                {
                    DF2DFeatureClass dffc = DF2DFeatureClassManager.Instance.GetFeatureClassByID(fc2DId);
                    if (dffc == null || dffc.GetFacilityClassName() != "PipeLine")
                    {
                        continue;
                    }
                    IFeatureClass fc = dffc.GetFeatureClass();
                    if (fc == null)
                    {
                        continue;
                    }
                    //if (fc.ShapeType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline)
                    //{
                    List.Add(dffc);
                    //}
                }
            }

            //List<DF2DFeatureClass> List = Dictionary2DTable.Instance.GetFeatureClassByFacilityClassName("PipeLine");
            if (List == null)
            {
                return;
            }
            WaitForm.Start("开始检查..", "请稍后");
            foreach (DF2DFeatureClass dfcc in List)
            {
                bool   b1 = false, b2 = false, b3 = false, b4 = false;
                string strPipeClass;
                pFeaClass = dfcc.GetFeatureClass();
                if (pFeaClass == null)
                {
                    continue;
                }
                WaitForm.SetCaption("正在检查:" + pFeaClass.AliasName);
                FacilityClass fac = dfcc.GetFacilityClass();
                if (fac == null)
                {
                    continue;
                }
                List <DFDataConfig.Class.FieldInfo> listField = fac.FieldInfoCollection;
                DFDataConfig.Class.FieldInfo        fi        = fac.GetFieldInfoBySystemName("StartHeight2D");
                if (fi == null)
                {
                    continue;
                }
                DFDataConfig.Class.FieldInfo fi1 = fac.GetFieldInfoBySystemName("EndHeight");
                if (fi1 == null)
                {
                    continue;
                }
                DFDataConfig.Class.FieldInfo fi2 = fac.GetFieldInfoBySystemName("StartDep");
                if (fi2 == null)
                {
                    continue;
                }
                DFDataConfig.Class.FieldInfo fi3 = fac.GetFieldInfoBySystemName("EndDep");
                if (fi3 == null)
                {
                    continue;
                }
                DFDataConfig.Class.FieldInfo fi4 = fac.GetFieldInfoBySystemName("CoverStyle");
                if (fi4 == null)
                {
                    continue;
                }
                DFDataConfig.Class.FieldInfo fi5 = fac.GetFieldInfoBySystemName("Diameter");
                if (fi5 == null)
                {
                    continue;
                }
                if (pFeaClass.AliasName.Contains("燃气"))
                {
                    strPipeClass = "BP";
                }
                else if (pFeaClass.AliasName.Contains("下水"))
                {
                    strPipeClass = "DP";
                }
                else if (pFeaClass.AliasName.Contains("电力"))
                {
                    strPipeClass = "EP";
                }
                else if (pFeaClass.AliasName.Contains("上水") || pFeaClass.AliasName.Contains("给水"))
                {
                    strPipeClass = "FP";
                }
                else if (pFeaClass.AliasName.Contains("热力"))
                {
                    strPipeClass = "HP";
                }
                else if (pFeaClass.AliasName.Contains("通信"))
                {
                    strPipeClass = "TP";
                }
                else if (pFeaClass.AliasName.Contains("工业"))
                {
                    strPipeClass = "IOP";
                }
                else
                {
                    strPipeClass = "";
                }
                //数据字典字段值检查
                DataTable dt = GetDataTableByStruture();
                //遍历字段
                for (j = 0; j < ArcField.Length; j++)
                {
                    if (fac.GetFieldInfoBySystemName(ArcField[j]) == null)
                    {
                        continue;
                    }
                    //获取数据字典中的对应值
                    strFld      = fac.GetFieldInfoNameBySystemName(ArcField[j]);
                    strDicValue = GetValueFromDictionary(strPipeClass, strFld);

                    if (strDicValue != "空")
                    {
                        if (strDicValue.Contains(","))
                        {
                            string   strWhere = "(";
                            string[] s        = strDicValue.Split(new char[] { ',' });
                            for (k = 0; k < s.Length; k++)
                            {
                                strWhere += "'" + s[k] + "',";
                            }
                            strWhere.Remove(strWhere.LastIndexOf(","));
                            strWhere           += ")";
                            pFilter.WhereClause = strFld + " not in" + strWhere;
                        }
                        else
                        {
                            pFilter.WhereClause = strFld + "<>'" + strDicValue + "'";
                        }

                        pFeaCursor = pFeaClass.Search(pFilter, true);
                        while ((pFea = pFeaCursor.NextFeature()) != null)
                        {
                            DataRow dr = dt.NewRow();
                            dr["ErrorFeatureID"] = pFea.OID;
                            dr["FeatureofClass"] = pFeaClass.AliasName;
                            dr["FeatureofLayer"] = (pFeaClass as IDataset).Name;
                            dr["FeatureClass"]   = pFeaClass;
                            dr["ErrorType"]      = "【" + strFld + "】字段值不属于数据字典";
                            dt.Rows.Add(dr);
                            //Console.WriteLine(pFea.OID + " " + pFeaClass.AliasName);
                        }
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeaCursor);
                    }
                    //if (dt.Rows.Count > 0) dict[pFeaClass] = dt;
                }
                //if (dt.Rows.Count > 0) dict[pFeaClass] = dt;

                pFilter.WhereClause = fi.Name + "= -999 or " + fi1.Name + "= -999";
                pFeaCursor          = pFeaClass.Search(pFilter, true);
                while ((pFea = pFeaCursor.NextFeature()) != null)
                {
                    DataRow dr = dt.NewRow();
                    dr["ErrorFeatureID"] = pFea.OID;
                    dr["FeatureofClass"] = pFeaClass.AliasName;
                    dr["FeatureofLayer"] = (pFeaClass as IDataset).Name;
                    dr["ErrorType"]      = "【管线高程】字段值不能为-999";
                    dr["FeatureClass"]   = pFeaClass;
                    dt.Rows.Add(dr);
                    //Console.WriteLine(pFea.OID + " " + pFeaClass.AliasName);
                }
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeaCursor);
                //if (dt.Rows.Count > 0) dict[pFeaClass] = dt;

                //管线埋深(只针对管线,管点不需要检查)
                if (strPipeClass == "BP")
                {
                    pFilter.WhereClause = "(" + fi2.Name + "< 0 or " + fi2.Name + "> 3) or (" + fi3.Name + "< 0 or " + fi3.Name + "> 3)";
                    pFeaCursor          = pFeaClass.Search(pFilter, true);
                    while ((pFea = pFeaCursor.NextFeature()) != null)
                    {
                        DataRow dr = dt.NewRow();
                        dr["ErrorFeatureID"] = pFea.OID;
                        dr["FeatureofClass"] = pFeaClass.AliasName;
                        dr["FeatureofLayer"] = (pFeaClass as IDataset).Name;
                        dr["FeatureClass"]   = pFeaClass;
                        dr["ErrorType"]      = "【管线埋深】字段值不在规范值范围内";
                        dt.Rows.Add(dr);
                        //Console.WriteLine(pFea.OID + " " + pFeaClass.AliasName);
                    }
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeaCursor);
                    //if (dt.Rows.Count > 0) dict[pFeaClass] = dt;
                }
                else
                {
                    //'直埋', '管埋', '管块'
                    pFilter.WhereClause = fi4.Name + " in ('直埋','管埋','管块') and (" + fi2.Name + "< 0 or " + fi2.Name + "> 10) or (" + fi3.Name + "< 0 or " + fi3.Name + "> 10)";
                    pFeaCursor          = pFeaClass.Search(pFilter, true);
                    while ((pFea = pFeaCursor.NextFeature()) != null)
                    {
                        DataRow dr = dt.NewRow();
                        dr["ErrorFeatureID"] = pFea.OID;
                        dr["FeatureofClass"] = pFeaClass.AliasName;
                        dr["FeatureofLayer"] = (pFeaClass as IDataset).Name;
                        dr["FeatureClass"]   = pFeaClass;
                        dr["ErrorType"]      = "【管线埋深】字段值不在规范值范围内";
                        dt.Rows.Add(dr);
                        //Console.WriteLine(pFea.OID + " " + pFeaClass.AliasName);
                    }
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeaCursor);
                    //if (dt.Rows.Count > 0) dict[pFeaClass] = dt;
                }
                //'架空'

                pFilter.WhereClause = fi4.Name + "='架空' and (" + fi2.Name + ">0 or " + fi3.Name + ">0)";
                pFeaCursor          = pFeaClass.Search(pFilter, true);
                while ((pFea = pFeaCursor.NextFeature()) != null)
                {
                    DataRow dr = dt.NewRow();
                    dr["ErrorFeatureID"] = pFea.OID;
                    dr["FeatureofClass"] = pFeaClass.AliasName;
                    dr["FeatureofLayer"] = (pFeaClass as IDataset).Name;
                    dr["FeatureClass"]   = pFeaClass;
                    dr["ErrorType"]      = "【管线埋深】字段值不在规范值范围内";
                    dt.Rows.Add(dr);
                    //Console.WriteLine(pFea.OID + " " + pFeaClass.AliasName);
                }
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeaCursor);
                //if (dt.Rows.Count > 0) dict[pFeaClass] = dt;

                pFilter.WhereClause = fi4.Name + "='管沟'";
                pFeaCursor          = pFeaClass.Search(pFilter, true);
                while ((pFea = pFeaCursor.NextFeature()) != null)
                {
                    string s = pFea.get_Value(pFeaClass.FindField(fi5.Name)).ToString();
                    if (s.Contains("*"))
                    {
                        if (s.Contains("*"))
                        {
                            double d  = Convert.ToDouble(s.Substring(s.IndexOf("*") + 1));
                            double d1 = Convert.ToDouble(pFea.get_Value(pFeaClass.FindField(fi2.Name)).ToString());
                            double d2 = Convert.ToDouble(pFea.get_Value(pFeaClass.FindField(fi3.Name)).ToString());
                            if (d1 < d || d2 < d)
                            {
                                DataRow dr = dt.NewRow();
                                dr["ErrorFeatureID"] = pFea.OID;
                                dr["FeatureofClass"] = pFeaClass.AliasName;
                                dr["FeatureofLayer"] = (pFeaClass as IDataset).Name;
                                dr["FeatureClass"]   = pFeaClass;
                                dr["ErrorType"]      = "【管线埋深】字段值不在规范值范围内";
                                dt.Rows.Add(dr);
                                //Console.WriteLine(pFea.OID + " " + pFeaClass.AliasName);
                            }
                        }
                    }
                }
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeaCursor);
                //if (dt.Rows.Count > 0) dict[pFeaClass] = dt;

                //管径
                if (strPipeClass == "BP" || strPipeClass == "FP")
                {
                    pFilter.WhereClause = "ISNUMERIC(" + fi5.Name + ")=1";
                }
                else
                {
                    //直埋、管埋
                    pFilter.WhereClause = fi4.Name + " in ('直埋','管埋') and " + "ISNUMERIC(" + fi5.Name + ")=1";
                    pFeaCursor          = pFeaClass.Search(pFilter, true);
                    while ((pFea = pFeaCursor.NextFeature()) != null)
                    {
                        DataRow dr = dt.NewRow();
                        dr["ErrorFeatureID"] = pFea.OID;
                        dr["FeatureofClass"] = pFeaClass.AliasName;
                        dr["FeatureofLayer"] = (pFeaClass as IDataset).Name;
                        dr["FeatureClass"]   = pFeaClass;
                        dr["ErrorType"]      = "【管线规格】字段值不在规范值范围内";
                        dt.Rows.Add(dr);
                        //Console.WriteLine(pFea.OID + " " + pFeaClass.AliasName);
                    }

                    System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeaCursor);
                    //if (dt.Rows.Count > 0) dict[pFeaClass] = dt;
                }

                pFilter.WhereClause = fi4.Name + " in ('管块','管沟') and " + fi5.Name + " like '%*%'";
                pFeaCursor          = pFeaClass.Search(pFilter, true);
                while ((pFea = pFeaCursor.NextFeature()) != null)
                {
                    DataRow dr = dt.NewRow();
                    dr["ErrorFeatureID"] = pFea.OID;
                    dr["FeatureofClass"] = pFeaClass.AliasName;
                    dr["FeatureofLayer"] = (pFeaClass as IDataset).Name;
                    dr["FeatureClass"]   = pFeaClass;
                    dr["ErrorType"]      = "【管线规格】字段值不在规范值范围内";
                    dt.Rows.Add(dr);
                    //Console.WriteLine(pFea.OID + " " + pFeaClass.AliasName);
                }
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeaCursor);

                dt = ReturnMergeData(dt);
                if (dt.Rows.Count > 0)
                {
                    dict[pFeaClass] = dt;
                }
            }
        }
Example #5
0
        private void DataPntCheck()
        {
            //管线点表数据规范性检查

            int            i, j, k;
            string         strFld;
            string         strDicValue;
            IFeatureClass  pFeaClass;
            IFeatureCursor pFeaCursor;
            IQueryFilter   pFilter = new QueryFilterClass();
            IFeature       pFea;

            string[] arrFc2DId;

            //Dictionary<IFeatureClass, DataTable> dict = new Dictionary<IFeatureClass, DataTable>();

            List <DF2DFeatureClass> list = new List <DF2DFeatureClass>();

            for (i = 0; i < m_arrPipeType.Count; i++)
            {
                MajorClass mc = m_arrPipeType[i] as MajorClass;
                arrFc2DId = mc.Fc2D.Split(';');
                if (arrFc2DId == null)
                {
                    continue;
                }
                foreach (string fc2DId in arrFc2DId)
                {
                    DF2DFeatureClass dffc = DF2DFeatureClassManager.Instance.GetFeatureClassByID(fc2DId);
                    if (dffc == null || dffc.GetFacilityClassName() != "PipeNode")
                    {
                        continue;
                    }
                    IFeatureClass fc = dffc.GetFeatureClass();
                    if (fc == null)
                    {
                        continue;
                    }
                    //if (fc.ShapeType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint)
                    //{
                    list.Add(dffc);
                    //}
                }
            }

            //List<DF2DFeatureClass> list = Dictionary2DTable.Instance.GetFeatureClassByFacilityClassName("PipeNode");
            if (list == null)
            {
                return;
            }
            WaitForm.Start("开始数据规范性检查..", "请稍候");
            foreach (DF2DFeatureClass dfcc in list)
            {
                bool   b1 = false, b2 = false, b3 = false, b4 = false;
                string strPipeClass;
                pFeaClass = dfcc.GetFeatureClass();
                if (pFeaClass == null)
                {
                    continue;
                }
                WaitForm.SetCaption("正在检查图层:" + " " + pFeaClass.AliasName);
                FacilityClass fac = dfcc.GetFacilityClass();
                if (fac == null)
                {
                    continue;
                }

                DFDataConfig.Class.FieldInfo fi = fac.GetFieldInfoBySystemName("SurfHeight2D");
                if (fi == null)
                {
                    continue;
                }
                DFDataConfig.Class.FieldInfo fi1 = fac.GetFieldInfoBySystemName("WellDep");
                if (fi1 == null)
                {
                    continue;
                }
                DFDataConfig.Class.FieldInfo fi2 = fac.GetFieldInfoBySystemName("Additional");
                if (fi2 == null)
                {
                    continue;
                }

                if (pFeaClass.AliasName.Contains("燃气"))
                {
                    strPipeClass = "BP";
                }
                else if (pFeaClass.AliasName.Contains("下水"))
                {
                    strPipeClass = "DP";
                }
                else if (pFeaClass.AliasName.Contains("电力"))
                {
                    strPipeClass = "EP";
                }
                else if (pFeaClass.AliasName.Contains("上水"))
                {
                    strPipeClass = "FP";
                }
                else if (pFeaClass.AliasName.Contains("热力"))
                {
                    strPipeClass = "HP";
                }
                else if (pFeaClass.AliasName.Contains("通信"))
                {
                    strPipeClass = "TP";
                }
                else if (pFeaClass.AliasName.Contains("工业"))
                {
                    strPipeClass = "IOP";
                }
                else
                {
                    strPipeClass = "";
                }
                // 数据字典字段值检查
                DataTable dt = GetDataTableByStruture();

                //遍历字段
                for (j = 0; j < PntField.Length; j++)
                {
                    if (fac.GetFieldInfoBySystemName(PntField[j]) == null)
                    {
                        continue;
                    }

                    //获取数据字典中的对应值
                    strFld      = fac.GetFieldInfoNameBySystemName(PntField[j]);
                    strDicValue = GetValueFromDictionary(strPipeClass, strFld);

                    if (strDicValue != "空")
                    {
                        if (strDicValue.Contains(","))
                        {
                            string   strWhere = "(";
                            string[] s        = strDicValue.Split(new char[] { ',' });
                            for (k = 0; k < s.Length; k++)
                            {
                                strWhere += "'" + s[k] + "',";
                            }
                            strWhere.Remove(strWhere.LastIndexOf(","));
                            strWhere           += ")";
                            pFilter.WhereClause = strFld + " not in" + strWhere;
                        }
                        else
                        {
                            pFilter.WhereClause = strFld + "<>'" + strDicValue + "'";
                        }
                        pFeaCursor = pFeaClass.Search(pFilter, true);
                        pFea       = null;

                        while ((pFea = pFeaCursor.NextFeature()) != null)
                        {
                            b1 = true;
                            DataRow dr = dt.NewRow();
                            dr["ErrorFeatureID"] = pFea.OID;
                            dr["FeatureofClass"] = pFeaClass.AliasName;
                            dr["FeatureofLayer"] = (pFeaClass as IDataset).Name;
                            dr["FeatureClass"]   = pFeaClass;
                            dr["ErrorType"]      = "【" + strFld + "】字段值不属于数据字典";
                            dt.Rows.Add(dr);
                            //Console.WriteLine(pFea.OID + " " + pFeaClass.AliasName);
                        }
                    }
                    if (dt.Rows.Count > 0)
                    {
                        dict[pFeaClass] = dt;
                    }
                }
                pFilter.WhereClause = fi.Name + "=-999";
                pFeaCursor          = pFeaClass.Search(pFilter, true);
                pFea = pFeaCursor.NextFeature();
                while (pFea != null)
                {
                    b2 = true;
                    DataRow dr = dt.NewRow();
                    dr["ErrorFeatureID"] = pFea.OID;
                    dr["FeatureofClass"] = pFeaClass.AliasName;
                    dr["FeatureofLayer"] = (pFeaClass as IDataset).Name;
                    dr["FeatureClass"]   = pFeaClass;
                    dr["ErrorType"]      = "【地面高程】字段值不能为-999";
                    dt.Rows.Add(dr);
                    pFea = pFeaCursor.NextFeature();
                }

                //if (dt.Rows.Count > 0) dict[pFeaClass] = dt;

                if (strPipeClass == "BP")
                {
                    pFilter.WhereClause = fi1.Name + "< 0 or " + fi1.Name + "> 3";
                }
                else if (strPipeClass == "IOP")
                {
                    pFilter.WhereClause = fi1.Name + "< 0 or " + fi1.Name + "> 5";
                }
                else
                {
                    pFilter.WhereClause = fi1.Name + "< 0 or " + fi1.Name + "> 10";
                }
                pFeaCursor = pFeaClass.Search(pFilter, true);
                while ((pFea = pFeaCursor.NextFeature()) != null)
                {
                    b3 = true;
                    DataRow dr = dt.NewRow();
                    dr["ErrorFeatureID"] = pFea.OID;
                    dr["FeatureofClass"] = pFeaClass.AliasName;
                    dr["FeatureofLayer"] = (pFeaClass as IDataset).Name;
                    dr["FeatureClass"]   = pFeaClass;
                    dr["ErrorType"]      = "【井底深】字段值不在规范值范围内";
                    dt.Rows.Add(dr);
                }

                //if (dt.Rows.Count > 0) dict[pFeaClass] = dt;

                pFilter.WhereClause = fi2.Name + " in ('阀门井','水表井','消防井','水源井','净水池','检修井','清水池','雨水检修井','污水检修井','跌水井','雨水篦',"
                                      + "'测试井','人孔','手孔','排气井','凝水井','通风井') and len(" + fi1.Name + ")=0";

                pFeaCursor = pFeaClass.Search(pFilter, true);
                while ((pFea = pFeaCursor.NextFeature()) != null)
                {
                    b4 = true;
                    DataRow dr = dt.NewRow();
                    dr["ErrorFeatureID"] = pFea.OID;
                    dr["FeatureofClass"] = pFeaClass.AliasName;
                    dr["FeatureofLayer"] = (pFeaClass as IDataset).Name;
                    dr["FeatureClass"]   = pFeaClass;
                    dr["ErrorType"]      = "【井底深】字段值不应为空";
                    dt.Rows.Add(dr);
                }

                dt = ReturnMergeData(dt);
                if (dt.Rows.Count > 0)
                {
                    dict[pFeaClass] = dt;
                }
            }
        }
        //程序检查
        private void DataIntegrityCheck()
        {
            int    i, j, n;
            string strFieldName;

            string[] arrFc2DId;
            object   val;
            IFeature pFea;
            //IFeatureClass pFeaClass;
            IFeatureCursor pCur;

            List <DF2DFeatureClass> listPnt = new List <DF2DFeatureClass>();
            List <DF2DFeatureClass> listArc = new List <DF2DFeatureClass>();

            for (i = 0; i < m_arrPipeType.Count; i++)
            {
                MajorClass mc = m_arrPipeType[i] as MajorClass;
                arrFc2DId = mc.Fc2D.Split(';');
                if (arrFc2DId == null)
                {
                    continue;
                }
                foreach (string fc2DId in arrFc2DId)
                {
                    DF2DFeatureClass dffc = DF2DFeatureClassManager.Instance.GetFeatureClassByID(fc2DId);
                    if (dffc == null)
                    {
                        continue;
                    }
                    IFeatureClass fc = dffc.GetFeatureClass();
                    if (fc == null)
                    {
                        continue;
                    }
                    if (dffc.GetFacilityClassName() == "PipeNode")
                    {
                        listPnt.Add(dffc);
                    }
                    if (dffc.GetFacilityClassName() == "PipeLine")
                    {
                        listArc.Add(dffc);
                    }
                }
            }
            //遍历所有点表检查
            if (m_arrPntField.Count > 0)
            {
                //List<DF2DFeatureClass> list = Dictionary2DTable.Instance.GetFeatureClassByFacilityClassName("PipeNode");
                if (listPnt == null)
                {
                    return;
                }
                WaitForm.Start("开始数据完整性检查..", "请稍候");
                foreach (DF2DFeatureClass dffc in listPnt)
                {
                    DataTable     dt = GetDataTableByStruture();
                    IFeatureClass fc = dffc.GetFeatureClass();
                    if (fc == null)
                    {
                        continue;
                    }
                    WaitForm.SetCaption("正在检查图层:" + " " + fc.AliasName);
                    pCur = fc.Search(null, true);
                    while ((pFea = pCur.NextFeature()) != null)
                    {
                        for (j = 0; j < m_arrPntField.Count; j++)
                        {
                            strFieldName = m_arrPntField[j].ToString();
                            if (fc.FindField(strFieldName) > 0)
                            {
                                val = pFea.get_Value(fc.FindField(strFieldName));
                                if (val.ToString() == "" || val == DBNull.Value)
                                {
                                    DataRow dr = dt.NewRow();
                                    dr["ErrorFeatureID"] = pFea.OID;
                                    dr["FeatureofClass"] = fc.AliasName;
                                    dr["FeatureofLayer"] = (fc as IDataset).Name;
                                    dr["FeatureClass"]   = fc;
                                    dr["ErrorType"]      = "【" + strFieldName + "】字段为空";
                                    dt.Rows.Add(dr);
                                }
                            }
                        }
                    }
                    if (dt.Rows.Count > 0)
                    {
                        dict[fc] = dt;
                    }
                }

                //if (dict.Count == 0)
                //{

                //    XtraMessageBox.Show("提示表格数据为空!");

                //}
            }

            //遍历所有线表检查
            if (m_arrArcField.Count > 0)
            {
                //List<DF2DFeatureClass> list = Dictionary2DTable.Instance.GetFeatureClassByFacilityClassName("PipeLine");
                if (listArc == null)
                {
                    return;
                }

                foreach (DF2DFeatureClass dfcc in listArc)
                {
                    DataTable     dt = GetDataTableByStruture();
                    IFeatureClass fc = dfcc.GetFeatureClass();
                    if (fc == null)
                    {
                        return;
                    }
                    WaitForm.SetCaption(fc.AliasName);
                    pCur = fc.Search(null, true);
                    while ((pFea = pCur.NextFeature()) != null)
                    {
                        for (j = 0; j < m_arrArcField.Count; j++)
                        {
                            strFieldName = m_arrArcField[j].ToString();
                            if (fc.FindField(strFieldName) > 0)
                            {
                                val = pFea.get_Value(fc.FindField(strFieldName));
                                if (val.ToString() == "" || val == DBNull.Value)
                                {
                                    DataRow dr = dt.NewRow();
                                    dr["ErrorFeatureID"] = pFea.OID;
                                    dr["FeatureofClass"] = fc.AliasName;
                                    dr["FeatureofLayer"] = (fc as IDataset).Name;
                                    dr["FeatureClass"]   = fc;
                                    dr["ErrorType"]      = "【" + strFieldName + "】字段为空";
                                    dt.Rows.Add(dr);
                                }
                            }
                        }
                    }
                    if (dt.Rows.Count > 0)
                    {
                        dict[fc] = dt;
                    }
                }

                //if (dict.Count == 0)
                //{

                //    XtraMessageBox.Show("提示表格数据为空!");

                //}
            }
        }