예제 #1
0
    private bool UpdateActive(AppState appState, string mapId)
    {
        string dataId = "";

        Configuration.QueryRow query = Configuration.Query.First(o => o.QueryID == appState.Query);

        using (OleDbCommand command = query.GetDatabaseCommand())
        {
            command.Parameters[0].Value = mapId;

            if (command.Parameters.Count > 1)
            {
                command.Parameters[1].Value = AppUser.GetRole();
            }

            try
            {
                using (OleDbDataReader reader = command.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        try
                        {
                            int dataIdColumn = reader.GetOrdinal("DataID");
                            dataId = reader.GetValue(dataIdColumn).ToString();
                        }
                        catch
                        {
                            dataId = mapId;
                        }
                    }
                    else
                    {
                        mapId  = "";
                        dataId = "";
                    }
                }
            }
            catch
            {
                mapId  = "";
                dataId = "";
            }

            command.Connection.Close();
        }

        bool updated = mapId != appState.ActiveMapId || dataId != appState.ActiveDataId;

        if (updated)
        {
            appState.ActiveMapId  = mapId;
            appState.ActiveDataId = dataId;
        }

        return(updated);
    }
예제 #2
0
파일: MapMaker.cs 프로젝트: ClaireBrill/GPV
    private void PrepareIds(out StringCollection targetIds, out StringCollection filteredIds, out StringCollection selectionIds)
    {
        targetIds    = _appState.TargetIds.Clone();
        selectionIds = _appState.SelectionIds.Clone();

        // segregate the target IDs that pass through the query from
        // those that do not

        if (String.IsNullOrEmpty(_appState.Query))
        {
            filteredIds = new StringCollection();
        }
        else
        {
            Configuration          config = AppContext.GetConfiguration();
            Configuration.QueryRow query  = config.Query.FindByQueryID(_appState.Query);

            using (OleDbCommand command = query.GetDatabaseCommand())
            {
                command.Parameters[0].Value = _appState.TargetIds.Join(",");

                if (command.Parameters.Count > 1)
                {
                    command.Parameters[1].Value = AppUser.GetRole();
                }

                using (OleDbDataReader reader = command.ExecuteReader())
                {
                    int mapIdColumn = reader.GetOrdinal("MapID");

                    filteredIds = targetIds;
                    targetIds   = new StringCollection();

                    while (reader.Read())
                    {
                        if (!reader.IsDBNull(mapIdColumn))
                        {
                            string mapId = reader.GetValue(mapIdColumn).ToString();

                            filteredIds.Remove(mapId);

                            if (!targetIds.Contains(mapId))
                            {
                                targetIds.Add(mapId);
                            }
                        }
                    }
                }

                command.Connection.Dispose();
            }
        }

        if (targetIds.Count > 0)
        {
            // remove the active ID from the targets

            if (_appState.ActiveMapId.Length > 0)
            {
                targetIds.Remove(_appState.ActiveMapId);
            }

            // remove the selection IDs from the targets if necessary

            if (_appState.TargetLayer == _appState.SelectionLayer && _appState.SelectionIds.Count > 0)
            {
                if (_appState.ActiveMapId.Length > 0)
                {
                    selectionIds.Remove(_appState.ActiveMapId);
                }

                foreach (string selectionId in _appState.SelectionIds)
                {
                    targetIds.Remove(selectionId);
                }
            }
        }
    }
예제 #3
0
    private void GetQueryGridData()
    {
        AppState appState = AppState.FromJson(Request.Form["state"]);

        Configuration.ApplicationRow application = Configuration.Application.First(o => o.ApplicationID == appState.Application);
        Configuration.QueryRow       query       = Configuration.Query.First(o => o.QueryID == appState.Query);

        List <String> zones  = new List <String>();
        List <String> levels = new List <String>();

        if (!application.IsZoneLevelIDNull())
        {
            zones  = application.ZoneLevelRow.GetZoneRows().Select(o => o.ZoneID).ToList();
            levels = application.ZoneLevelRow.GetLevelRows().Select(o => o.LevelID).ToList();
        }

        Dictionary <String, Object> result = new Dictionary <String, Object>();

        using (OleDbCommand command = query.GetDatabaseCommand())
        {
            command.Parameters[0].Value = appState.TargetIds.Join(",");

            if (command.Parameters.Count > 1)
            {
                command.Parameters[1].Value = AppUser.GetRole();
            }

            using (OleDbDataReader reader = command.ExecuteReader())
            {
                // get the indexes of the ID columns

                int mapIdColumn   = reader.GetColumnIndex("MapID");
                int dataIdColumn  = reader.GetColumnIndex("DataID");
                int zoneIdColumn  = zones.Count > 0 ? reader.GetColumnIndex("ZoneID") : -1;
                int levelIdColumn = levels.Count > 0 ? reader.GetColumnIndex("LevelID") : -1;

                // write the column headers

                List <String> headers = new List <String>();

                for (int i = 0; i < reader.FieldCount; ++i)
                {
                    if (i != mapIdColumn && i != dataIdColumn && i != zoneIdColumn && i != levelIdColumn)
                    {
                        headers.Add(reader.GetName(i));
                    }
                }

                result.Add("headers", headers);

                // write the data

                List <Dictionary <String, Object> > rows = new List <Dictionary <String, Object> >();

                while (reader.Read())
                {
                    if (!reader.IsDBNull(mapIdColumn) && !reader.IsDBNull(dataIdColumn))
                    {
                        Dictionary <String, String> id = new Dictionary <String, String>();

                        id.Add("m", reader.GetValue(mapIdColumn).ToString());

                        if (dataIdColumn > -1 && !reader.IsDBNull(dataIdColumn))
                        {
                            id.Add("d", reader.GetValue(dataIdColumn).ToString());
                        }

                        if (zoneIdColumn > -1 && !reader.IsDBNull(zoneIdColumn))
                        {
                            string zoneId = reader.GetValue(zoneIdColumn).ToString();

                            if (zones.Contains(zoneId))
                            {
                                id.Add("z", zoneId);
                            }
                        }

                        if (levelIdColumn > -1 && !reader.IsDBNull(levelIdColumn))
                        {
                            string levelId = reader.GetValue(levelIdColumn).ToString();

                            if (levels.Contains(levelId))
                            {
                                id.Add("l", levelId);
                            }
                        }

                        List <Object> values = new List <Object>();

                        for (int i = 0; i < reader.FieldCount; ++i)
                        {
                            if (i != mapIdColumn && i != dataIdColumn && i != zoneIdColumn && i != levelIdColumn)
                            {
                                values.Add(reader.IsDBNull(i) ? null : reader.GetValue(i));
                            }
                        }

                        Dictionary <String, Object> row = new Dictionary <String, Object>();
                        row.Add("id", id);
                        row.Add("v", values);

                        rows.Add(row);
                    }
                }

                result.Add("rows", rows);
            }

            command.Connection.Dispose();
        }

        ReturnJson(result);
    }