コード例 #1
0
        public void EmptyGeometriesUnversioned(IWorkspace TheWorkSpace, IFeatureClass inTable, IFIDSet pFIDSet)
        {
            IMouseCursor pMouseCursor = new MouseCursorClass();
              pMouseCursor.SetCursor(2);

              IQueryFilter pQF = new QueryFilterClass();

              ISQLSyntax pSQLSyntax = (ISQLSyntax)TheWorkSpace;
              string sPref = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierPrefix);
              string sSuff = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierSuffix);

              ICursor ipCursor = null;
              IRow pRow = null;
              //make sure that there are no more then 999 tokens for the in clause(ORA- query will otherwise error on an Oracle database)
              int iTokenLimit = 995;
              int iTokenSet = 0; //the index of the set of 995 tokens
              string sWhereClauseLHS = sPref + inTable.OIDFieldName + sSuff + " in (";
              string[] ids = { sWhereClauseLHS };

              try
              {
            ITableWrite pTableWr = (ITableWrite)inTable;
            pFIDSet.Reset();
            bool bCont = true;
            Int32 iID;

            Int32 count = pFIDSet.Count();
            int j = 0; //inner count for each set of IDs
            for (int k = 0; k < count; k++)
            {
              if (j > iTokenLimit)
              {//over the limit for this Token set, time to create a new set
            ids[iTokenSet] += ")";//close the previous set
            RedimPreserveString(ref ids, 1);//make space in the string array for the next token set
            iTokenSet++;//increment the index
            ids[iTokenSet] = sWhereClauseLHS; //left-hand side of the where clause
            j = 0;//reset the inner count back to zero
              }

              pFIDSet.Next(out iID);
              if (j > 0) //write a comma if this is not the first ID
            ids[iTokenSet] += ",";
              ids[iTokenSet] += iID.ToString();
              j++; //increment the inner count
            }
            ids[iTokenSet] += ")";

            if (count > 0)
            {
              IFeature pFeat = null;
              ISet pRowSet = new SetClass();
              for (int k = 0; k <= iTokenSet; k++)
              {
            pRowSet.RemoveAll();
            pQF.WhereClause = ids[k];
            ipCursor = pTableWr.UpdateRows(pQF, false);
            pRow = ipCursor.NextRow();
            while (pRow != null)
            {
              pFeat = (IFeature)pRow;
              IGeometry pGeo = pFeat.ShapeCopy;
              pGeo.SetEmpty();
              pFeat.Shape = pGeo;
              ipCursor.UpdateRow(pRow);
              Marshal.ReleaseComObject(pRow);
              pRow = ipCursor.NextRow();
            }
            if (!bCont)
            {
              AbortEditing(TheWorkSpace);
              if (ipCursor != null)
                Marshal.ReleaseComObject(ipCursor);
              if (pRow != null)
                Marshal.ReleaseComObject(pRow);
              //if (pQF != null)
              //  Marshal.ReleaseComObject(pQF);
              return;
            }
              }
              Marshal.ReleaseComObject(ipCursor);
              //Marshal.ReleaseComObject(pQF);
            }
            return;
              }

              catch (COMException ex)
              {
            if (ipCursor != null)
              Marshal.ReleaseComObject(ipCursor);
            if (pRow != null)
              Marshal.ReleaseComObject(pRow);
            //if (pQF != null)
            //  Marshal.ReleaseComObject(pQF);
            MessageBox.Show(Convert.ToString(ex.ErrorCode));
            return;
              }
        }