Программирование мобильных устройств на платформе .NET Compact Framework
Шрифт:
Public Shared ReadOnly Property _
isGameDataInitialized As Boolean
Get
'Инициализация данных игры, если слова загружены
Return Not (m_vocabularyWords_All Is Nothing)
End Get
End Property
'Возвращает коллекцию всех имеющихся слов
Public Shared ReadOnly Property _
AllWords As System.Collections.ArrayList
Get
'Загрузить
данные, если они не были инициализированы
If (m_vocabularyWords_All Is Nothing) Then
InitializeGameVocabulary
End If
Return m_vocabularyWords_All
End Get
End property
'Возвращает коллекцию всех имеющихся имен существительных
Public Shared ReadOnly Property _
Nouns As System.Collections.ArrayList
Get
'Загрузить данные, если они не были инициализированы
If (m_vocabularyWords_Nouns Is Nothing) Then
InitializeGameVocabulary
End If
Return m_vocabularyWords_Nouns
End Get
End Property
'==========================================================
'Загружает данные из нашей базы данных
'==========================================================
Public Shared Sub InitializeGameVocabulary
'Создать новый массив списков для хранения наших слов
m_vocabularyWords_All = New System.Collections.ArrayList
m_vocabularyWords_Nouns = New System.Collections.ArrayList
m_vocabularyWords_Verbs = New System.Collections.ArrayList
m_vocabularyWords_Adjectives = _
New System.Collections.ArrayList
m_vocabularyWords Adverbs = _
New System.Collections.ArrayList
m_vocabularyWords_Prepositions = _
New System.Collections.ArrayList
Dim dataReader As System.Data.IDataReader
dataReader = DatabaseAccess.GetListOfWords
Dim newWord As VocabularyWord
'Обойти все записи
While (dataReader.Read)
Dim thisword_gender As VocabularyWord.WordGender
Dim thisword_function As VocabularyWord.WordFunction
thisword_gender = CType(dataReader.GetInt32( _
DatabaseAccess.DS_WORDS_COLUMNINDEX_GERMANGENDER), _
VocabularyWord.WordGender)
thisword_function = CType(dataReader.GetInt32( _
DatabaseAccess.DS_WORDS_COLUMNINDEX_WORDFUNCTION), _
VocabularyWord.WordFunction)
'Поместить
данные для только что считанного слова в класс
newWord = New VocabularyWord(dataReader.GetString( _
DatabaseAccess.DS_WORDS_COLUMNINDEX_ENGLISHWORD), dataReader.GetString( _
DatabaseAccess.DS_WORDS_COLUMNINDEX_GERMANWORD), _
thisword_gender, thisword_function)
'Добавить новое слово в массив списков
m_vocabularyWords_All.Add(newWord)
'Слова могут принадлежать нескольким группам, поэтому
'необходимо выполнить проверку с использованием операции логического И
'для проверки того, что слово относится к данной категории
If ((newWord.getWordFunction And _
VocabularyWord.WordFunction.Noun) <> 0) Then
m_vocabularyWords_Nouns.Add(newWord)
End If
If ((newWord.getWordFunction And _
VocabularyWord.WordFunction.Verb) <> 0)
Then m_vocabularyWords_Verbs.Add(newWord)
End If
If ((newWord.getWordFunction And _
VocabularyWord.WordFunction.Adjective) <> 0) Then
m_vocabularyWords_Adjectives.Add(newWord)
End If
If ((newWord.getWordFunction And _
VocabularyWord.WordFunction.Adverb) <> 0) Then
m_vocabularyWords_Adverbs.Add(newWord)
End If
If ((newWord.getWordFunction And _
VocabularyWord.WordFunction.Preposition) <> 0) Then
m_vocabularyWords_Prepositions.Add(newWord)
End If
End While
'Закрыть объект DataReader
dataReader.Close
End Sub
End Class
Листинг 14.8. Пример кода управления данными для VocabularyWord.cs
Option Strict On
Imports System
'------------------------------
'Хранит данные слова из словаря
'------------------------------
Friend Class VocabularyWord
Поделиться с друзьями: