public KanjiMessage GetKanjiForToday(KanjiForTodayRequest request) { var result = new KanjiMessage(); using (IDatabaseClient client = OpenDatabaseClient()) { client.SelectCommand = String.Format(SQL_KANJI_JLPT_SELECT, GetJlptString(request.JlptLevels)); DataTable data = client.Read(); if (data.Rows.Count > 0) { int rowNumber = (DateTime.Today.Year * 365 + DateTime.Today.DayOfYear) % data.Rows.Count; var row = data.Rows[rowNumber]; result.Id = Convert.ToInt32(row["Id"]); result.Literal = row["Literal"].ToString(); result.OnYomi = row["OnYomi"].ToString(); result.KunYomi = row["KunYomi"].ToString(); result.Meaning = row["Meaning"].ToString(); result.Jlpt = (JLPT)Enum.Parse(typeof(JLPT), row["JLPT"].ToString()); result.StrokeCount = Convert.ToInt32(row["StrokeCount"]); } } return result; }
public KanjiMessage GetKanjiForId(KanjiForIdRequest request) { var result = new KanjiMessage(); using (IDatabaseClient client = OpenDatabaseClient()) { client.SelectCommand = String.Format(SQL_KANJI_ID_SELECT, request.Id.ToString()); DataTable data = client.Read(); if (data.Rows.Count > 0) { var row = data.Rows[0]; result.Id = Convert.ToInt32(row["Id"]); result.Literal = row["Literal"].ToString(); result.OnYomi = row["OnYomi"].ToString(); result.KunYomi = row["KunYomi"].ToString(); result.Meaning = row["Meaning"].ToString(); result.Jlpt = (JLPT)Enum.Parse(typeof(JLPT), row["JLPT"].ToString()); result.StrokeCount = Convert.ToInt32(row["StrokeCount"]); } else { result.Id = 0; result.Jlpt = JLPT.Undefined; } } return result; }
public List<KanjiMessage> GetAllKanji() { var result = new List<KanjiMessage>(); using (IDatabaseClient client = OpenDatabaseClient()) { client.SelectCommand = SQL_KANJI_ALL_SELECT; DataTable data = client.Read(); for (int i = 0; i < data.Rows.Count; i++) { var row = data.Rows[i]; var kanji = new KanjiMessage(); kanji.Id = Convert.ToInt32(row["Id"]); kanji.Literal = row["Literal"].ToString(); kanji.OnYomi = row["OnYomi"].ToString(); kanji.KunYomi = row["KunYomi"].ToString(); kanji.Meaning = row["Meaning"].ToString(); kanji.Jlpt = (JLPT)Enum.Parse(typeof(JLPT), row["JLPT"].ToString()); kanji.StrokeCount = Convert.ToInt32(row["StrokeCount"]); result.Add(kanji); } } return result; }