/// <summary> /// Fills the <see cref="UnitHolder"/> with all the data from database. /// </summary> public static void FillUnitHolder(UnitHolder unitHolder) { string sql = "SELECT * FROM units"; try { using (SQLiteConnection cnt = new SQLiteConnection(dbPath)) using (SQLiteCommand cmd = new SQLiteCommand(sql, cnt)) { cnt.Open(); using (SQLiteDataReader rdr = cmd.ExecuteReader()) { while (rdr.Read()) { unitHolder.Add(rdr.GetInt32(0), rdr.GetString(1)); } } cnt.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// Fills the <see cref="WordHolder"/> with words in the given Units. /// </summary> public static void FillWordHolder(WordHolder wordHolder, UnitHolder unitHolder) { string sql = DbManager.GenerateSql(unitHolder); try { using (SQLiteConnection cnt = new SQLiteConnection(dbPath)) using (SQLiteCommand cmd = new SQLiteCommand(sql, cnt)) { cnt.Open(); using (SQLiteDataReader rdr = cmd.ExecuteReader()) { while (rdr.Read()) { wordHolder.Add(rdr.GetString(1), rdr.GetString(2), rdr.GetInt32(3)); } } cnt.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// Clears <see cref="selectedUnits"/> and sets it to given <see cref="UnitHolder"/> /// </summary> public static void UpdateSelectedUnits(UnitHolder units) { if (Current.selectedUnits != null) { Current.selectedUnits.Clear(); } Current.selectedUnits = units; }
/// <summary> /// Returns a <see cref="UnitHolder"/> containing currently checked <see cref="Unit"/>s. /// </summary> public static UnitHolder CheckedUnits(this CheckedListBox clb) { UnitHolder units = new UnitHolder(); foreach (Unit unit in clb.CheckedItems) { units.Add(unit); } return(units); }
/// <summary> /// Populates <see cref="CheckedListBox"/> with all units from database. /// </summary> public static void Populate(this CheckedListBox clb) { UnitHolder units = new UnitHolder(); units.FillEverythingFromDatabase(); foreach (Unit unit in units) { clb.Items.Add(unit); } }
/// <summary> /// Generates an SQL command to SELECT words in units given as <see cref="UnitHolder"/>. /// </summary> /// <returns>An SQL command as a <see cref="string"/>.</returns> public static string GenerateSql(UnitHolder units) { string sql = "SELECT * FROM words WHERE wrd_unitId = "; sql += units.GetUnit(0).UnitId; if (units.Count == 1) { return(sql); } else { for (int i = 1; i < units.Count; i++) { sql += " or " + units.GetUnit(i).UnitId; } } return(sql); }
/// <summary> /// Updates <see cref="selectedUnits"/> and <see cref="selectedWords"/> according to given <see cref="UnitHolder"/>. /// </summary> public static void UpdateGameHolders(UnitHolder units) { UpdateSelectedUnits(units); UpdateSelectedWords(); }
public void Fill(UnitHolder units) { DbManager.FillWordHolder(this, units); }