Beispiel #1
0
 public bool CompactPersonalGeodatabase(string sPGDBFile)
 {
     try
     {
         if (string.IsNullOrEmpty(sPGDBFile) | !File.Exists(sPGDBFile))
         {
             MessageBox.Show("数据文件 " + sPGDBFile + " 丢失。", "压缩数据错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             return(false);
         }
         bool flag = false;
         IWorkspaceFactory factory = null;
         factory = new AccessWorkspaceFactoryClass();
         IWorkspace workspace = null;
         workspace = factory.OpenFromFile(sPGDBFile, 0);
         if ((workspace != null) && (workspace is IDatabaseCompact))
         {
             IDatabaseCompact compact = null;
             compact = workspace as IDatabaseCompact;
             if (compact.CanCompact())
             {
                 compact.Compact();
                 flag = true;
             }
         }
         workspace = null;
         factory   = null;
         return(flag);
     }
     catch (Exception exception)
     {
         this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.WorkspaceFun", "CompactPersonalGeodatabase", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
         return(false);
     }
 }
Beispiel #2
0
        private void btnOpen_Click(object sender, EventArgs e)
        {
            frmOpenFile file = new frmOpenFile();

            if (this.int_0 == 0)
            {
                file.AddFilter(new MyGxFilterGeoDatabases(), true);
            }
            else
            {
                file.AddFilter(new MyGxFilterPersonalGeodatabases(), true);
            }
            if ((file.DoModalOpen() == DialogResult.OK) && (file.Items.Count > 0))
            {
                IGxObject obj2 = file.Items.get_Element(0) as IGxObject;
                if (obj2 is IGxDatabase)
                {
                    if (this.int_0 == 0)
                    {
                        this.iversionedWorkspace_0 = (obj2 as IGxDatabase).Workspace as IVersionedWorkspace;
                        if (this.iversionedWorkspace_0 == null)
                        {
                            MessageBox.Show("请选择企业数据库!");
                            this.textEdit1.Text = "";
                            this.btnOK.Enabled  = false;
                        }
                        else
                        {
                            this.textEdit1.Text = obj2.FullName;
                            this.btnOK.Enabled  = true;
                        }
                    }
                    else
                    {
                        this.textEdit1.Text     = obj2.FullName;
                        this.idatabaseCompact_0 = (obj2 as IGxDatabase).Workspace as IDatabaseCompact;
                        this.btnOK.Enabled      = this.idatabaseCompact_0 != null;
                    }
                }
            }
        }
Beispiel #3
0
 /// <summary>
 /// 压缩数据库工作空间
 /// </summary>
 public static void CompactWorkspace(IWorkspace workspace)
 {
     try
     {
         IDatabaseCompact databaseCompact = workspace as IDatabaseCompact;
         if (databaseCompact != null)
         {
             if (databaseCompact.CanCompact())
             {
                 databaseCompact.Compact();
             }
         }
     }
     catch (Exception exp)
     {
         Hy.Common.Utility.Log.OperationalLogManager.AppendMessage(exp.ToString());
     }
     finally
     {
     }
 }
Beispiel #4
0
        private string strSrcFiled       = null; //源图层的字段名
        public override bool Check(ref List <Error> checkResult)
        {
            IFeatureClass  pResultFc  = null;
            IFeatureCursor pResultCur = null;

            try{
                string path = string.Format("{0}\\{1}", System.IO.Path.GetDirectoryName(m_QueryWorkspace.PathName), COMMONCONST.DB_Name_Temp);
                //创建临时操作tempdist.mdb,防止把所有结果库数据存储到query库,引起query库超限
                if (File.Exists(path))
                {
                    Hy.Common.Utility.Esri.AEAccessFactory.OpenPGDB(ref TempWorkspace, path);
                }
                else
                {
                    Hy.Common.Utility.Esri.AEAccessFactory.CreatePGDB(System.IO.Path.GetDirectoryName(m_QueryWorkspace.PathName), COMMONCONST.DB_Name_Temp, ref TempWorkspace);
                }
                if (TempWorkspace == null)
                {
                    SendMessage(enumMessageType.RuleError, "创建临时操作数据库失败!无法执行检查!");
                    return(false);
                }
                // 生成中间结果图层
                // 线物不能穿越地类图斑的检查使用Identity进行,其余都使用Intersect
                // 仅适用于二调质检
                string     Resultlayer = strSrcLayer + "_Intersect";
                IGPProcess gpProcess   = null;
                string     strKey      = strSrcLayer.ToUpper();
                string     inputtables = string.Format(@"""{0}\{1}\{2}"";""{0}\{1}\{3}""", m_BaseWorkspace.PathName, "Dataset", strSrcLayer, strRelLayer);
                Intersect  spIntersect = new Intersect();
                spIntersect.in_features       = inputtables;
                spIntersect.cluster_tolerance = "0.001 Meters";
                spIntersect.join_attributes   = "ALL";
                spIntersect.out_feature_class = TempWorkspace.PathName + "\\" + Resultlayer;
                spIntersect.output_type       = "INPUT";

                gpProcess = spIntersect;
                m_gp      = new Geoprocessor();
                Execute(gpProcess);

                // 等待gp
                int counter = 0;
                while (counter++ < 100)
                {
                    if ((TempWorkspace as IWorkspace2).get_NameExists(esriDatasetType.esriDTFeatureClass, Resultlayer))
                    {
                        break;
                    }

                    System.Threading.Thread.Sleep(100);
                }
                if (m_gp != null)
                {
                    gpProcess = null;
                    m_gp      = null;
                    GC.Collect();
                }
                // 从结果图层中取出错误
                pResultFc = ((IFeatureWorkspace)TempWorkspace).OpenFeatureClass(Resultlayer);
                IQueryFilter pQry = new QueryFilterClass();

                switch (strKey)
                {
                case "LXDW":
                    pQry.WhereClause = "ZLTBBH<>TBBH";
                    break;

                case "XZDW":        //线物不能穿越地类图斑、线物要素的扣除检查
                    if (m_pPara.strAlias.IndexOf("线物不能穿越地类图斑") > -1)
                    {
                        string strClause = " and Avg(len_dist)-sum(shape_length)< " + (1 * this.m_UnitScale).ToString("N7");
                        TempWorkspace.ExecuteSQL(string.Format("delete from XZDW_Intersect where  fid_XZDW in (SELECT fid_xzdw FROM xzdw_Intersect GROUP BY fid_xzdw,fid_dltb having count(0)>1 {0}) and fid_dltb in (SELECT fid_dltb FROM xzdw_Intersect GROUP BY fid_xzdw,fid_dltb having count(0)>1 {0})", strClause));

                        pQry.SubFields   = " Distinct BSM,FID_XZDW,BSM_1";
                        pQry.WhereClause = "len_dist-shape_length>" + (1 * this.m_UnitScale).ToString("N7") + " and shape_length>" + (0.2 * this.m_UnitScale).ToString("N7");
//                            pQry.WhereClause = "len_dist-shape_length>" + (1 * this.m_UnitScale).ToString("N7") + " and shape_length>" + (0.2 * this.m_UnitScale).ToString("N7") + @" and
//                                                    fid_xzdw in
//                                                    (
//                                                    select a.fid_xzdw from
//                                                    (select fid_xzdw from xzdw_Intersect group by fid_xzdw having count(0)>1) as a,
//                                                    (SELECT fid_xzdw FROM xzdw_Intersect GROUP BY fid_xzdw,fid_dltb having count(0)=1) as b
//                                                    where a.fid_xzd9w=b.fid_xzdw
//                                                    )";
                    }
                    else
                    {
                        if (m_pPara.strAlias.IndexOf("线物要素的扣除检查") > -1)
                        {
                            pQry.WhereClause = getkcblsql();
                        }
                    }
                    break;

                default:
                    pQry.WhereClause = "left(ZLDWDM,12)<>XZQDM and shape_Area>" + (400 * this.m_UnitScale).ToString("N7");
                    break;
                }
                pResultCur  = pResultFc.Search(pQry, true);
                checkResult = GetResult(pResultCur as ICursor);

                // 更新状态
                string _strSql = "update LR_ResultEntryRule set TargetFeatClass1= '" + m_pPara.strGeographyObject +
                                 "',TargetFeatClass2='" + m_pPara.strGraphSpeckle +
                                 "|' where RuleInstID='" + this.m_InstanceID + "'";

                Hy.Common.Utility.Data.AdoDbHelper.ExecuteSql(this.m_ResultConnection, _strSql);
                // 释放资源,删除中间结果
                if (pResultCur != null)
                {
                    Marshal.ReleaseComObject(pResultCur);
                    pResultCur = null;
                }
                ((IDataset)pResultFc).Delete();

                return(true);
            }
            catch (Exception ex)
            {
                SendMessage(enumMessageType.Exception, ex.ToString());
                return(false);
            }
            finally
            {
                if (m_gp != null)
                {
                    m_gp = null;
                }
                // 释放资源,删除中间结果
                if (pResultCur != null)
                {
                    Marshal.ReleaseComObject(pResultCur);
                    pResultCur = null;
                }
                if (pResultFc != null)
                {
                    Marshal.ReleaseComObject(pResultFc);
                    pResultFc = null;
                }
                //压缩临时数据库
                IDatabaseCompact databaseCompact = TempWorkspace as IDatabaseCompact;
                if (databaseCompact != null)
                {
                    if (databaseCompact.CanCompact())
                    {
                        databaseCompact.Compact();
                    }
                }
                if (TempWorkspace != null)
                {
                    Marshal.ReleaseComObject(TempWorkspace);
                    TempWorkspace = null;
                }
                GC.Collect();
            }
        }