Beispiel #1
0
        /// <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);
            }
        }
Beispiel #2
0
        /// <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);
            }
        }
Beispiel #3
0
 /// <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;
 }
Beispiel #4
0
        /// <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);
        }
Beispiel #5
0
        /// <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);
            }
        }
Beispiel #6
0
        /// <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);
        }
Beispiel #7
0
 /// <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();
 }
Beispiel #8
0
 public void Fill(UnitHolder units)
 {
     DbManager.FillWordHolder(this, units);
 }