private ShiftsEntry GetStoredShiftsEntry(ICursor c, Dictionary <string, Dictionary <int, SortedList <int, EntryAttachment> > > dictAttachments) { int ID_sql_id = c.GetColumnIndex(DatabaseHelper.SHIFT_TABLE_COL_ID); int ID_key = c.GetColumnIndex(DatabaseHelper.SHIFT_TABLE_COL_KEY); int ID_month = c.GetColumnIndex(DatabaseHelper.SHIFT_TABLE_COL_MONTH); int ID_year = c.GetColumnIndex(DatabaseHelper.SHIFT_TABLE_COL_YEAR); int ID_title = c.GetColumnIndex(DatabaseHelper.SHIFT_TABLE_COL_TITLE); int ID_update = c.GetColumnIndex(DatabaseHelper.SHIFT_TABLE_COL_UPDATE); int ID_version = c.GetColumnIndex(DatabaseHelper.SHIFT_TABLE_COL_VERSION); int ID_read = c.GetColumnIndex(DatabaseHelper.SHIFT_TABLE_COL_READ); int sql_id = c.GetInt(ID_sql_id); _ = c.GetString(ID_key); _ = c.GetString(ID_title); int month = c.GetInt(ID_month); int year = c.GetInt(ID_year); DateTime update = TBL.DecodeStringToDate(c.GetString(ID_update), DateTime.Now.AddMonths(-TBL.PREF_FEED_AUTOREMOVE)); string version = c.GetString(ID_version); string read = c.GetString(ID_read); var listAttachments = dictAttachments[DatabaseHelper.OWNER_SHIFTS][sql_id]; ShiftsEntry result = new ShiftsEntry(month, year, update, version, listAttachments.Last().Value) { MarkedRead = (read == DatabaseHelper.BOOL_TRUE), ID = sql_id }; return(result); }
private FeedEntry GetStoredFeedEntry(ICursor c, Dictionary <string, Dictionary <int, SortedList <int, EntryAttachment> > > dictAttachments) { int ID_sql_id = c.GetColumnIndex(DatabaseHelper.FEED_TABLE_COL_ID); int ID_key = c.GetColumnIndex(DatabaseHelper.FEED_TABLE_COL_KEY); int ID_title = c.GetColumnIndex(DatabaseHelper.FEED_TABLE_COL_TITLE); int ID_date = c.GetColumnIndex(DatabaseHelper.FEED_TABLE_COL_DATE); int ID_author = c.GetColumnIndex(DatabaseHelper.FEED_TABLE_COL_AUTHOR); int ID_body = c.GetColumnIndex(DatabaseHelper.FEED_TABLE_COL_BODY); int ID_read = c.GetColumnIndex(DatabaseHelper.FEED_TABLE_COL_READ); int sql_id = c.GetInt(ID_sql_id); string key = c.GetString(ID_key); string title = c.GetString(ID_title); DateTime date = TBL.DecodeStringToDate(c.GetString(ID_date), DateTime.Now.AddMonths(-TBL.PREF_FEED_AUTOREMOVE)); string author = c.GetString(ID_author); string body = c.GetString(ID_body); string read = c.GetString(ID_read); var listAttachments = new SortedList <int, EntryAttachment>(); if (dictAttachments.ContainsKey(DatabaseHelper.OWNER_FEED) && dictAttachments[DatabaseHelper.OWNER_FEED].ContainsKey(sql_id)) { listAttachments = dictAttachments[DatabaseHelper.OWNER_FEED][sql_id]; } FeedEntry result = new FeedEntry(key, title, date, author, body, listAttachments.Values.ToList()) { MarkedRead = (read == DatabaseHelper.BOOL_TRUE), ID = sql_id }; return(result); }
//############################################################################### public void SaveFeedEntry(FeedEntry item) { //Datensatz erstellen string read = DatabaseHelper.BOOL_FALSE; if (item.MarkedRead) { read = DatabaseHelper.BOOL_TRUE; } ContentValues values = new ContentValues(); values.Put(DatabaseHelper.FEED_TABLE_COL_KEY, item.Key); values.Put(DatabaseHelper.FEED_TABLE_COL_TITLE, item.Title); values.Put(DatabaseHelper.FEED_TABLE_COL_DATE, TBL.EncodeDateToString(item.Date)); values.Put(DatabaseHelper.FEED_TABLE_COL_AUTHOR, item.Author); values.Put(DatabaseHelper.FEED_TABLE_COL_BODY, item.BodyText); values.Put(DatabaseHelper.FEED_TABLE_COL_READ, read); //Datenbank aktualisieren //Neuen Eintrag anlegen int ID = (int)database.Insert(DatabaseHelper.FEED_TABLE, null, values); item.ID = ID; //Feed-Anhänge aktualisieren foreach (var attachment in item.Attachments) { SaveAttachment(attachment, DatabaseHelper.OWNER_FEED, item.ID, false); } }
public void SaveShiftsEntry(ShiftsEntry item, bool overwrite) { //Datensatz erstellen string read = DatabaseHelper.BOOL_FALSE; if (item.MarkedRead) { read = DatabaseHelper.BOOL_TRUE; } ContentValues values = new ContentValues(); values.Put(DatabaseHelper.SHIFT_TABLE_COL_KEY, item.Key); values.Put(DatabaseHelper.SHIFT_TABLE_COL_TITLE, item.Title); values.Put(DatabaseHelper.SHIFT_TABLE_COL_MONTH, item.Month); values.Put(DatabaseHelper.SHIFT_TABLE_COL_YEAR, item.Year); values.Put(DatabaseHelper.SHIFT_TABLE_COL_UPDATE, TBL.EncodeDateToString(item.LastUpdate)); values.Put(DatabaseHelper.SHIFT_TABLE_COL_VERSION, item.LastVersion); values.Put(DatabaseHelper.SHIFT_TABLE_COL_READ, read); //Datenbank aktualisieren if (item.ID < 0) { //Neuen Eintrag anlegen int ID = (int)database.Insert(DatabaseHelper.SHIFT_TABLE, null, values); item.ID = ID; } else { if (overwrite) { //Bestehenden Eintrag überschreiben string id_filter = DatabaseHelper.SHIFT_TABLE_COL_ID + "='" + item.ID + "'"; database.Update(DatabaseHelper.SHIFT_TABLE, values, id_filter, null); } } //Feed-Anhänge aktualisieren SaveAttachment(item.ShiftAttachment, DatabaseHelper.OWNER_SHIFTS, item.ID, overwrite); }
//############################################################################### public void LoadDatabase() { //Datenbank öffnen & Listen erstellen if (!Open()) { return; } List <FeedEntry> listFeed = new List <FeedEntry>(); List <ShiftsEntry> listShifts = new List <ShiftsEntry>(); List <int> oldFeed = new List <int>(); List <int> oldShift = new List <int>(); DateTime oldOffset = DateTime.Now.AddMonths(-TBL.PREF_FEED_AUTOREMOVE); var dictAttachments = GetStoredAttachments(); //Feed laden ICursor c = database.Query(DatabaseHelper.FEED_TABLE, FEED_COLUMNS, null, null, null, null, null); c.MoveToFirst(); while (!c.IsAfterLast) { FeedEntry fE = GetStoredFeedEntry(c, dictAttachments); if (fE.Date <= oldOffset) { oldFeed.Add(fE.ID); } else { listFeed.Add(fE); } c.MoveToNext(); } c.Close(); //Shifts laden c = database.Query(DatabaseHelper.SHIFT_TABLE, SHIFTS_COLUMNS, null, null, null, null, null); c.MoveToFirst(); while (!c.IsAfterLast) { ShiftsEntry sE = GetStoredShiftsEntry(c, dictAttachments); if (sE.LastUpdate <= oldOffset) { oldShift.Add(sE.ID); } else { listShifts.Add(sE); } c.MoveToNext(); } c.Close(); //Datenbank bereinigen RemoveOldEntries(oldFeed, oldShift); //Datenbank schließen Close(); //Statischen Speicher befüllen TBL.UpdateEntries(listFeed, listShifts); }