public static List<JournalDescriptionItem> GetDistinctDescriptions() { var result = new List<JournalDescriptionItem>(); try { string query = "SELECT DISTINCT TOP (1000) StateType, Description FROM Journal ORDER BY Description"; using (var sqlCeConnection = new SqlCeConnection(ConnectionString)) { sqlCeConnection.ConnectionString = ConnectionString; var sqlCeCommand = new SqlCeCommand(query, sqlCeConnection); sqlCeConnection.Open(); var reader = sqlCeCommand.ExecuteReader(); while (reader.Read()) { var journalDescriptionItem = new JournalDescriptionItem(); journalDescriptionItem.Description = reader.GetString(reader.GetOrdinal("Description")); journalDescriptionItem.StateType = (StateType)reader.GetInt32(reader.GetOrdinal("StateType")); result.Add(journalDescriptionItem); } sqlCeConnection.Close(); } } catch (Exception e) { Logger.Error(e, "Исключение при вызове FiresecService.GetDistinctDescriptions"); throw new FS2Exception(e.Message); } return result; }
public static OperationResult<List<JournalDescriptionItem>> GetDistinctDescriptions() { var operationResult = new OperationResult<List<JournalDescriptionItem>>(); operationResult.Result = new List<JournalDescriptionItem>(); try { string query = "SELECT DISTINCT TOP (1000) StateType, Description FROM Journal ORDER BY Description"; using (var DataBaseContext = new SqlCeConnection(ConnectionString)) { DataBaseContext.ConnectionString = ConnectionString; var result = new SqlCeCommand(query, DataBaseContext); DataBaseContext.Open(); var reader = result.ExecuteReader(); while (reader.Read()) { var journalDescriptionItem = new JournalDescriptionItem(); journalDescriptionItem.Description = reader.GetString(reader.GetOrdinal("Description")); journalDescriptionItem.StateType = (StateType)reader.GetInt32(reader.GetOrdinal("StateType")); operationResult.Result.Add(journalDescriptionItem); } DataBaseContext.Close(); } } catch (Exception e) { Logger.Error(e, "Исключение при вызове FiresecService.GetDistinctDescriptions"); operationResult.HasError = true; operationResult.Error = e.Message.ToString(); } return operationResult; }