Пример #1
0
        private void updateLogEntry(string layer_key, string[] keys, IFeature srcFeature, IsdutEditEventType type)
        {
            if (!layer_key.ToLower().Equals("data_errors"))
            {
                IFeatureClass editFC = null;
                try
                {
                    editFC = this.transactionDB.OpenFeatureClass("E_" + layer_key);
                }
                catch (Exception e)
                {
                    MessageBox.Show("Edit Feature Class For " + layer_key + " Not Found in Transaction",
                        "EXCEPTION", MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                    throw new HandledException(e);
                }

                IQueryFilter query = setupOIDFilter(srcFeature);

                IFeatureCursor cursor = null;
                try
                {
                    cursor = editFC.Update(query, false);
                    IFeature updFeature = cursor.NextFeature();
                    if (updFeature != null)
                    {
                        // update

                        // shp
                        IGeometry geom = srcFeature.ShapeCopy;

                        if (geom is ITopologicalOperator2)
                        {
                            ITopologicalOperator2 geomtopo = (ITopologicalOperator2)geom;
                            geomtopo.IsKnownSimple_2 = false;
                            try
                            {
                                geomtopo.Simplify();
                            }
                            catch (Exception e)
                            {
                                Logger.Warn(e);
                            }
                        }

                        // need to reproject here!
                        geom.Project(((IGeoDataset)editFC).SpatialReference);
                        geom.SnapToSpatialReference();

                        updFeature.Shape = geom;

                        // edit fields
                        updFeature.set_Value(cursor.FindField(EDIT_UPDATE_TIMESTAMP), DateTime.Now);
                        string tp = null;
                        switch (type)
                        {
                            case IsdutEditEventType.Delete:
                                tp = DEL;
                                break;
                            case IsdutEditEventType.Insert:
                                tp = INS;
                                break;
                            case IsdutEditEventType.Update:
                                tp = UPD;
                                break;
                            case IsdutEditEventType.Retired:
                                tp = RET;
                                break;
                        }
                        updFeature.set_Value(cursor.FindField(EDIT_STATE), tp);

                        for (int i = 0; i < keys.Length; i++)
                        {
                            string val = srcFeature.get_Value(srcFeature.Fields.FindField(keys[i])).ToString();
                            int fieldIndex = updFeature.Fields.FindField(keys[i]);

                            // if we have a null primary key, we need to set the value to null as well, not empty string
                            if (string.IsNullOrEmpty(val))
                            {
                                val = null;
                            }

                            updFeature.set_Value(fieldIndex, val);
                        }

                        cursor.UpdateFeature(updFeature);
                        cursor.Flush();
                    }
                    else
                    {
                        Utils.Release(cursor);
                        cursor = editFC.Insert(false);
                        IFeatureBuffer buffer = editFC.CreateFeatureBuffer();

                        // keys
                        for (int i = 0; i < keys.Length; i++)
                        {
                            buffer.set_Value(cursor.FindField(keys[i]), srcFeature.get_Value(srcFeature.Fields.FindField(keys[i])));
                        }

                        // shp
                        IGeometry geom = srcFeature.ShapeCopy;

                        if (geom is ITopologicalOperator2)
                        {
                            ITopologicalOperator2 geomtopo = (ITopologicalOperator2)geom;
                            geomtopo.IsKnownSimple_2 = false;
                            try
                            {
                                geomtopo.Simplify();
                            }
                            catch (Exception e)
                            {
                                Logger.Warn(e);
                            }
                        }

                        // need to reproject here!
                        geom.Project(((IGeoDataset)editFC).SpatialReference);
                        geom.SnapToSpatialReference();

                        buffer.Shape = geom;

                        // edit fields
                        buffer.set_Value(cursor.FindField(EDIT_UPDATE_TIMESTAMP), DateTime.Now);
                        string tp = null;
                        switch (type)
                        {
                            case IsdutEditEventType.Delete:
                                tp = "DEL";
                                break;
                            case IsdutEditEventType.Insert:
                                tp = "INS";
                                break;
                            case IsdutEditEventType.Update:
                                tp = "UPD";
                                break;
                            case IsdutEditEventType.Retired:
                                tp = RET;
                                break;
                        }
                        buffer.set_Value(cursor.FindField(EDIT_STATE), tp);
                        buffer.set_Value(cursor.FindField(EDIT_OID_LOG), srcFeature.OID + "");

                        cursor.InsertFeature(buffer);
                    }
                }
                finally
                {
                    if (query != null)
                    {
                        Utils.Release(query);
                    }
                    if (cursor != null)
                    {
                        Utils.Release(cursor);
                    }
                }
            }
        }
Пример #2
0
        public void log(IFeature feature, IsdutEditEventType type)
        {
            // is this an original feature? if yes cannot be inserted, if no cannot be deleted
            // is this update really an extention of an insert? if yes update Time

            string name = ((IDataset)feature.Table).Name;

            string[] primary_keys = new string[1] { feature.Fields.get_Field(0).Name };

            try
            {
                bool original_exists = checkPristine(name, primary_keys, feature);

                if( original_exists )
                {
                    if ( type == IsdutEditEventType.Insert )
                    {
                        // an undo from a delete?
                        type = IsdutEditEventType.Update;
                    }
                }
                else
                {
                    if ( type == IsdutEditEventType.Delete )
                    {
                        // same as an undo after an insert
                        deleteLogEntry(name, primary_keys, feature);
                        return;
                    }
                    // always
                    type = IsdutEditEventType.Insert;
                }

                updateLogEntry(name,primary_keys,feature,type);
            }
            catch(HandledException e)
            {
                throw new HandledException(e.Exception);
            }
            catch(Exception e)
            {
                MessageBox.Show("Unexpected Error Logging Edit",
                    "EXCEPTION", MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                throw new HandledException(e);
            }
        }