示例#1
0
        private void PostEditProcess(FeatureLayerEditResult[] editResults, List <SpatialObject> adds, string action)
        {
            if (editResults != null && editResults.Length > 0)
            {
                int    countFailed  = 0;
                int    countSuccess = 0;
                string errFailed    = "";

                for (int i = 0; i < editResults.Length; i++)
                {
                    if (Boolean.Parse(editResults[i].success))
                    {
                        countSuccess++;

                        if (action.Equals("Add"))
                        {
                            adds[i].objectId = editResults[i].objectId;
                            adds[i].globalId = editResults[i].globalId;
                            SpatialObject feature = loadedRows.SingleOrDefault(row => row.uniqueId == adds[i].uniqueId);

                            if (feature != null)
                            {
                                feature.objectId = adds[i].objectId;
                                feature.globalId = adds[i].globalId;
                            }
                        }
                    }
                    else if (editResults[i].error != null)
                    {
                        countFailed++;
                        errFailed = editResults[i].error.description;
                    }
                }

                if (logCallback != null)
                {
                    logCallback(string.Format("Succeeded to {0} {1} {2} feature(s)", action, countSuccess, this.FeatureLayer.Name), EventLogEntryType.Information);
                }
                if (logCallback != null && countFailed > 0)
                {
                    logCallback(string.Format("Failed to {0} {1} {2} feature(s) - {3}", action, countFailed, this.FeatureLayer.Name, errFailed), EventLogEntryType.Error);
                }
            }
        }
示例#2
0
        protected bool LoadTableRows()
        {
            bool isDone = false;

            List <SpatialObject> addedRows   = new List <SpatialObject>();
            List <SpatialObject> updatedRows = new List <SpatialObject>();
            List <SpatialObject> deletedRows = new List <SpatialObject>();
            List <SpatialObject> currentRows = new List <SpatialObject>();

            using (OdbcConnection connection = new OdbcConnection(this.ConnectionString))
            {
                using (OdbcCommand command = new OdbcCommand(this.FeatureLayer.SelectSQL, connection))
                {
                    try
                    {
                        connection.Open();
                        using (OdbcDataReader dr = command.ExecuteReader())
                        {
                            if (dr.HasRows)
                            {
                                int count = 0;
                                while (dr.Read())
                                {
                                    count++;
                                    SpatialObject obj = new SpatialObject();
                                    obj.uniqueId    = ((int)this.UpdateMode == 4) ? Convert.ToString(dr.GetValue(0)) : count.ToString();
                                    obj.x           = ((int)this.UpdateMode < 3) ? Convert.ToDecimal(dr.GetValue(1)) : -1;
                                    obj.y           = ((int)this.UpdateMode < 3) ? Convert.ToDecimal(dr.GetValue(2)) : -1;
                                    obj.fieldValues = new FieldValueList();

                                    for (int i = 0; i < dr.FieldCount; i++)
                                    {
                                        obj.fieldValues.Add(dr.GetName(i), dr.GetFieldType(i), dr.GetValue(i));
                                    }

                                    currentRows.Add(obj);
                                }
                            }

                            if (isLoaded && loadedRows != null)
                            {
                                currentRows.ForEach(current =>
                                {
                                    SpatialObject loaded = loadedRows.FirstOrDefault(existed => existed.uniqueId == current.uniqueId);
                                    if (loaded == null)
                                    {
                                        addedRows.Add(current);
                                        loadedRows.Add(current);
                                    }
                                    else if (!loaded.Equals(current, this.UpdateMode, true))
                                    {
                                        updatedRows.Add(loaded);
                                    }
                                });

                                deletedRows = loadedRows.Where(existed => !currentRows.Any(current => existed.uniqueId == current.uniqueId)).ToList();
                                deletedRows.ForEach(item => loadedRows.Remove(item));
                                isDone = ApplyEdits(addedRows, updatedRows, deletedRows);
                            }
                            else
                            {
                                this.isLoaded = true;
                                loadedRows    = currentRows.ToList();
                                isDone        = ApplyEdits(currentRows, null, null);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        isDone        = true;
                        isErrorLogged = true;
                        if (logCallback != null)
                        {
                            logCallback(string.Format("Query {0} Table Error - {1}", this.FeatureLayer.Name, ex.Message), EventLogEntryType.Error);
                        }
                    }

                    if (connection.State == System.Data.ConnectionState.Open)
                    {
                        connection.Close();
                    }
                }
            }

            return(isDone);
        }