Exemplo n.º 1
0
        //---------------------------------------------------------------------
        // CHANGED: CR10 (Attribute updates for incid subsets)
        // The old incid number is passed together with the new incid
        // number so that only features belonging to the old incid are
        // updated.
        public override DataTable SplitFeaturesLogically(string oldIncid, string newIncid, DataColumn[] historyColumns)
        {
            try
            {
                if (!TableExists(_selName)) return null;

                DataTable historyTable = CreateHistoryTable(_selName, true, historyColumns);

                int ixGeom1 = historyColumns.Length;
                int ixGeom2 = historyColumns.Length + 1;

                //---------------------------------------------------------------------
                // FIXED: KI107 (GIS layer column names)
                // Ignore case when comparing column names so that GIS layer names may be mixed/upper case
                string[] historyColumnNames = historyTable.Columns.Cast<DataColumn>()
                    .Select(c => _hluFieldNames.ToList().Contains(c.ColumnName, StringComparer.OrdinalIgnoreCase) ?
                    GetFieldName(_hluLayerStructure.Columns[c.ColumnName].Ordinal).ToLower() : c.ColumnName.ToLower()).ToArray();

                var q = historyColumns.Where(c => !_hluFieldNames.ToList().Contains(c.ColumnName, StringComparer.OrdinalIgnoreCase));
                string newToidFragmentColumnName = q.Count() == 1 ?
                    q.ElementAt(0).ColumnName.Replace(GISApp.HistoryAdditionalFieldsDelimiter, String.Empty) : null;
                //---------------------------------------------------------------------

                int numRows = Int32.Parse(_mapInfoApp.Eval(String.Format("TableInfo({0}, {1})",
                    _selName, (int)MapInfoConstants.TableInfo.TAB_INFO_NROWS)));

                string numFormat = String.Format("D{0}", _hluLayerStructure.toid_fragment_idColumn.MaxLength);

                string fetchCommand = String.Format("Fetch Rec {0} From {1}", "{0}", _selName);
                string incidCommand = String.Format("{0}.{1}", _selName,
                    GetFieldName(_hluLayerStructure.incidColumn.Ordinal));
                string fragCommand = String.Format("{0}.{1}", _selName,
                    GetFieldName(_hluLayerStructure.toid_fragment_idColumn.Ordinal));
                string toidFragmentCommand = String.Format("{0}.{1}", _selName,
                    GetFieldName(_hluLayerStructure.toid_fragment_idColumn.Ordinal));
                string readCommandTemplate = String.Format("{0}.{1}", _selName, "{0}");
                string updateCommandTemplate = String.Format("Update {0} Set {1} = {2} Where RowID = {3}",
                    _selName, GetFieldName(_hluLayerStructure.incidColumn.Ordinal), QuoteValue(newIncid), "{0}");

                for (int i = 1; i <= numRows; i++)
                {
                    _mapInfoApp.RunCommand(String.Format(fetchCommand, i));
                    //---------------------------------------------------------------------
                    // CHANGED: CR10 (Attribute updates for incid subsets)
                    // Only collect the history details and update the incid number if
                    // the each feature belongs to the old incid.
                    if (_mapInfoApp.Eval(incidCommand) == oldIncid)
                    {
                        CollectHistory(ixGeom1, ixGeom2, readCommandTemplate, historyColumnNames, ref historyTable);
                        if (!String.IsNullOrEmpty(newToidFragmentColumnName))
                            historyTable.Rows[historyTable.Rows.Count - 1][newToidFragmentColumnName] = _mapInfoApp.Eval(fragCommand);
                        _mapInfoApp.Do(String.Format(updateCommandTemplate, i));
                    }
                    //---------------------------------------------------------------------
                }

                if ((historyTable != null) && !CommitChanges())
                    historyTable = null;

                return historyTable;
            }
            catch
            {
                _mapInfoApp.Do(String.Format("Rollback Table {0}", _hluLayer));
                return null;
            }
        }
Exemplo n.º 2
0
        private DataTable SqlSelect(bool replaceSelection, bool closePreviousSelection, DataColumn[] targetList, string tableName,
            bool addGeometryInfo, bool negateWhereClause, List<SqlFilterCondition> whereConds, DataColumn[] orderBy)
        {
            if ((_mapInfoApp == null) || (targetList == null) || (targetList.Length == 0))
                return new DataTable();

            try
            {
                bool qualifyColumns = false;
                bool additionalTables;
                DataTable resultTable = null;

                StringBuilder sbCommandText = new StringBuilder("SELECT ");
                sbCommandText.Append(TargetList(targetList, true, true, ref qualifyColumns, out resultTable));

                sbCommandText.Append(FromList(true, targetList, true, ref whereConds, out additionalTables));

                if (negateWhereClause)
                    sbCommandText.Append(" WHERE NOT (").Append(WhereClause(false, true, qualifyColumns,
                        MapWhereClauseFields(_hluLayerStructure, whereConds))).Append(")");
                else
                    sbCommandText.Append(WhereClause(true, true, qualifyColumns,
                        MapWhereClauseFields(_hluLayerStructure, whereConds)));

                if ((orderBy != null) && (orderBy.Length > 0))
                {
                    StringBuilder orderByColNames = orderBy.Where(c => _hluLayerStructure.Columns.Contains(c.ColumnName))
                        .Aggregate(new StringBuilder(), (sb, c) => sb.Append(",").Append(qualifyColumns ?
                            QuoteIdentifier(c.Table.TableName) + "." : String.Empty).Append(
                            QuoteIdentifier(GetFieldName(_hluLayerStructure.Columns[c.ColumnName].Ordinal))));

                    if (orderByColNames.Length > 0)
                        sbCommandText.Append(String.Format(" ORDER BY {0}", orderByColNames.Remove(0, 1)));
                }

                _mapInfoApp.Do(sbCommandText.ToString());
                ReadSelectedRows(replaceSelection, closePreviousSelection, qualifyColumns, addGeometryInfo, tableName, ref resultTable);

                return resultTable;
            }
            catch { return null; }
        }
Exemplo n.º 3
0
        public override DataTable SplitFeaturesLogically(string newIncid, DataColumn[] historyColumns)
        {
            try
            {
                if (String.IsNullOrEmpty(_selName) || !TableExists(_selName)) return null;

                DataTable historyTable = CreateHistoryTable(_selName, true, historyColumns);

                int ixGeom1 = historyColumns.Length;
                int ixGeom2 = historyColumns.Length + 1;

                string[] historyColumnNames = historyTable.Columns.Cast<DataColumn>()
                    .Select(c => _hluFieldNames.Contains(c.ColumnName) ?
                    GetFieldName(_hluLayerStructure.Columns[c.ColumnName].Ordinal) : c.ColumnName).ToArray();

                var q = historyColumns.Where(c => !_hluFieldNames.Contains(c.ColumnName));
                string newToidFragmentColumnName = q.Count() == 1 ?
                    q.ElementAt(0).ColumnName.Replace(GISApp.HistoryAdditionalFieldsDelimiter, String.Empty) : null;

                int numRows = Int32.Parse(_mapInfoApp.Eval(String.Format("TableInfo({0}, {1})",
                    _selName, (int)MapInfoConstants.TableInfo.TAB_INFO_NROWS)));

                string numFormat = String.Format("D{0}", _hluLayerStructure.toid_fragment_idColumn.MaxLength);

                string fetchCommand = String.Format("Fetch Rec {0} From {1}", "{0}", _selName);
                string fragCommand = String.Format("{0}.{1}", _selName,
                    GetFieldName(_hluLayerStructure.toid_fragment_idColumn.Ordinal));
                string toidFragmentCommand = String.Format("{0}.{1}", _selName,
                    GetFieldName(_hluLayerStructure.toid_fragment_idColumn.Ordinal));
                string readCommandTemplate = String.Format("{0}.{1}", _selName, "{0}");
                string updateCommandTemplate = String.Format("Update {0} Set {1} = {2} Where RowID = {3}",
                    _selName, GetFieldName(_hluLayerStructure.incidColumn.Ordinal), QuoteValue(newIncid), "{0}");

                for (int i = 1; i <= numRows; i++)
                {
                    _mapInfoApp.RunCommand(String.Format(fetchCommand, i));
                    CollectHistory(ixGeom1, ixGeom2, readCommandTemplate, historyColumnNames, ref historyTable);
                    if (!String.IsNullOrEmpty(newToidFragmentColumnName))
                        historyTable.Rows[historyTable.Rows.Count - 1][newToidFragmentColumnName] = _mapInfoApp.Eval(fragCommand);
                    _mapInfoApp.Do(String.Format(updateCommandTemplate, i));
                }

                if ((historyTable != null) && !CommitChanges())
                    historyTable = null;

                return historyTable;
            }
            catch
            {
                _mapInfoApp.Do(String.Format("Rollback Table {0}", _hluLayer));
                return null;
            }
        }