Ejemplo n.º 1
0
 /// <summary>
 /// Checks wether the table x has column x
 /// </summary>
 /// <param name="columnName">The column you want to check on</param>
 /// <param name="table">The table you want to check on</param>
 /// <returns></returns>
 public static bool HasColumn(string columnName, string table)
 {
     using (RemindMeDbEntities db = new RemindMeDbEntities())
     {
         try
         {
             var t = db.Database.SqlQuery <object>("SELECT " + columnName + " FROM " + table).ToList();
             db.Dispose();
             return(true);
         }
         catch (SQLiteException)
         {
             db.Dispose();
             //if (ex.Message.ToLower().Contains("no such column"))
             //{
             return(false);
             //}
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Deletes multiple reminders from the database.
        /// </summary>
        /// <param name="rems"></param>
        public static void PermanentelyDeleteReminders(List <Reminder> rems)
        {
            //We use this method so we can attach and remove the reminders in a foreach loop, and save changes to the database after the loop.
            //If you use the DeleteReminder method in a foreach loop, it will open and close the database each time
            using (RemindMeDbEntities db = new RemindMeDbEntities())
            {
                foreach (Reminder rem in rems)
                {
                    if (GetReminderById(rem.Id) != null) //Check if the reminder exists
                    {
                        db.Reminder.Attach(rem);
                        db.Reminder.Remove(rem);
                    }

                    DLAVRProperties.DeleteAvrFilesFoldersById(rem.Id);
                    DLAVRProperties.DeleteAvrProperties(rem.Id);
                }
                SaveAndCloseDataBase(db);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Update an existing hotkey combination in the SQLite database
 /// </summary>
 /// <param name="hotkey">The hotkey object</param>
 private static void UpdateHotkey(Hotkeys hotkey)
 {
     using (RemindMeDbEntities db = new RemindMeDbEntities())
     {
         var count = db.Hotkeys.Where(o => o.Id >= hotkey.Id).Count();
         if (count == 1)
         {
             db.Hotkeys.Attach(hotkey);
             var entry = db.Entry(hotkey);
             entry.State = System.Data.Entity.EntityState.Modified; //Mark it for update
             db.SaveChanges();                                      //push to database
             db.Dispose();
         }
         else
         {//The settings table is still empty
             db.Hotkeys.Add(hotkey);
             db.SaveChanges();
             db.Dispose();
         }
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Permanentely deletes a single reminder from the database
        /// </summary>
        /// <param name="rem">The reminder you wish to remove</param>
        public static void PermanentelyDeleteReminder(Reminder rem)
        {
            using (RemindMeDbEntities db = new RemindMeDbEntities())
            {
                db.Reminder.Attach(rem);
                db.Reminder.Remove(rem);

                //Remove attached foreign properties
                DLLocalDatabase.AVRProperty.DeleteAvrFilesFoldersById(rem.Id);
                DLLocalDatabase.AVRProperty.DeleteAvrProperties(rem.Id);
                DLLocalDatabase.HttpRequest.DeleteHttpRequestByReminderId(rem.Id);

                if (rem.HttpId != null)
                {
                    DLLocalDatabase.HttpRequestConditions.DeleteConditionsForHttpRequest((long)rem.HttpId);
                }


                SaveAndCloseDataBase(db);
            }
        }
Ejemplo n.º 5
0
 public static void UpdateButtonSpacing(ButtonSpaces btn)
 {
     using (RemindMeDbEntities db = new RemindMeDbEntities())
     {
         var count = db.ButtonSpaces.Where(o => o.Id >= 0).Count();
         if (count == 1)
         {
             db.ButtonSpaces.Attach(btn);
             var entry = db.Entry(btn);
             entry.State = System.Data.Entity.EntityState.Modified; //Mark it for update
             db.SaveChanges();                                      //push to database
             db.Dispose();
         }
         else
         {//The settings table is still empty
             db.ButtonSpaces.Add(btn);
             db.SaveChanges();
             db.Dispose();
         }
     }
 }
Ejemplo n.º 6
0
 private static void RefreshSettings()
 {
     using (RemindMeDbEntities db = new RemindMeDbEntities())
     {
         int count = db.Settings.Where(o => o.Id >= 0).Count();
         if (count == 0)
         {
             settings             = new Settings();
             settings.AlwaysOnTop = 1;
             settings.StickyForm  = 0;
             settings.EnableReminderCountPopup = 1;
             settings.EnableHourBeforeReminder = 1;
             UpdateSettings(settings);
         }
         else
         {
             settings = (from s in db.Settings select s).ToList().FirstOrDefault();
         }
         db.Dispose();
     }
 }
Ejemplo n.º 7
0
 public static void UpdateHttpRequest(HttpRequestCondition cond)
 {
     using (RemindMeDbEntities db = new RemindMeDbEntities())
     {
         var count = db.HttpRequestCondition.Where(o => o.Id >= 0).Count();
         if (count > 0)
         {
             db.HttpRequestCondition.Attach(cond);
             var entry = db.Entry(cond);
             entry.State = System.Data.Entity.EntityState.Modified; //Mark it for update
             db.SaveChanges();                                      //push to database
             db.Dispose();
         }
         else
         {//The settings table is still empty
             db.HttpRequestCondition.Add(cond);
             db.SaveChanges();
             db.Dispose();
         }
     }
 }
Ejemplo n.º 8
0
            /// <summary>
            /// Insert a new Request condition into the db
            /// </summary>
            /// <param name="condition"></param>
            /// <returns></returns>
            public static long InsertCondition(HttpRequestCondition condition)
            {
                using (RemindMeDbEntities db = new RemindMeDbEntities())
                {
                    /*if (db.HttpRequestCondition.Where(r => r.Id == condition.Id).Count() > 0)
                     * {
                     *  throw new ArgumentException("Could not insert HttpRequestCondition with ID " + condition.Id + " because it already exists");
                     * }
                     * else*/
                    {
                        if (db.HttpRequestCondition.Count() > 0)
                        {
                            condition.Id = db.HttpRequests.Max(i => i.Id) + 1;
                        }

                        db.HttpRequestCondition.Add(condition);
                        db.SaveChanges();
                        db.Dispose();
                    }
                }
                return(condition.Id);
            }
Ejemplo n.º 9
0
            private static void RefreshThemes()
            {
                using (RemindMeDbEntities db = new RemindMeDbEntities())
                {
                    int count = db.Themes.Where(o => o.Id >= 0).Count();
                    if (count == 0)
                    {
                        theme              = new Themes();
                        theme.Primary      = 0;
                        theme.DarkPrimary  = 0;
                        theme.LightPrimary = 0;
                        theme.Accent       = 0;
                        theme.TextShade    = 0;
                        UpdateTheme(theme);
                    }
                    else
                    {
                        theme = (from s in db.Themes select s).ToList().FirstOrDefault();
                    }

                    db.Dispose();
                }
            }
Ejemplo n.º 10
0
        private static void RefreshDimensions()
        {
            using (RemindMeDbEntities db = new RemindMeDbEntities())
            {
                int count = db.ListviewColumnSizes.Where(o => o.Id >= 0).Count();
                if (count == 0) //no dimensions yet.
                {
                    sizes           = new ListviewColumnSizes();
                    sizes.Title     = DEFAULT_TITLE_WIDTH;
                    sizes.Date      = DEFAULT_DATE_WIDTH;
                    sizes.Repeating = DEFAULT_REPEAT_WIDTH;
                    sizes.Enabled   = DEFAULT_ENABLED_WIDTH;

                    UpdateListviewSizes(sizes);
                }
                else
                {
                    sizes = (from s in db.ListviewColumnSizes select s).ToList().FirstOrDefault();
                }

                db.SaveChanges();
                db.Dispose();
            }
        }
Ejemplo n.º 11
0
            private static void RefreshDimensions()
            {
                using (RemindMeDbEntities db = new RemindMeDbEntities())
                {
                    int count = db.PopupDimensions.Where(o => o.Id >= 0).Count();
                    if (count == 0) //no dimensions yet.
                    {
                        dimensions               = new PopupDimensions();
                        dimensions.FormWidth     = DEFAULT_FORM_WIDTH;
                        dimensions.FormHeight    = DEFAULT_FORM_HEIGHT;
                        dimensions.FontTitleSize = DEFAULT_FONT_TITLE_SIZE;
                        dimensions.FontNoteSize  = DEFAULT_FONT_NOTE_SIZE;

                        UpdatePopupDimensions(dimensions);
                    }
                    else
                    {
                        dimensions = (from s in db.PopupDimensions select s).ToList().FirstOrDefault();
                    }

                    db.SaveChanges();
                    db.Dispose();
                }
            }
Ejemplo n.º 12
0
 /// <summary>
 /// Saves pending changes to the database, disposes it, and refreshes the local cache list
 /// </summary>
 /// <param name="db"></param>
 private static void SaveAndCloseDataBase(RemindMeDbEntities db)
 {
     db.SaveChanges();
     RefreshCacheList();
     db.Dispose();
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Inserts all missing tables into the user's .db file
        /// </summary>
        public static void InsertMissingTables()
        {
            using (RemindMeDbEntities db = new RemindMeDbEntities())
            {
                SQLiteConnection conn = new SQLiteConnection();
                conn.ConnectionString = "data source = " + DB_FILE;
                conn.Open();

                SQLiteCommand tableReminder            = new SQLiteCommand();
                SQLiteCommand tableSettings            = new SQLiteCommand();
                SQLiteCommand tableSongs               = new SQLiteCommand();
                SQLiteCommand tablePopupDimensions     = new SQLiteCommand();
                SQLiteCommand tableListviewColumnSizes = new SQLiteCommand();
                SQLiteCommand tableHotkeys             = new SQLiteCommand();
                SQLiteCommand tableAvrProperties       = new SQLiteCommand();
                SQLiteCommand tableAvrFilesFolders     = new SQLiteCommand();


                tableReminder.CommandText            = TABLE_REMINDER;
                tableSettings.CommandText            = TABLE_SETTINGS;
                tableSongs.CommandText               = TABLE_SONGS;
                tablePopupDimensions.CommandText     = TABLE_POPUP_DIMENSIONS;
                tableListviewColumnSizes.CommandText = TABLE_LISTVIEW_COLUMN_SIZES;
                tableHotkeys.CommandText             = TABLE_HOTKEYS;
                tableAvrProperties.CommandText       = TABLE_AVR_PROPERTIES;
                tableAvrFilesFolders.CommandText     = TABLE_AVR_FILES_FOLDERS;

                tableReminder.Connection            = conn;
                tableSettings.Connection            = conn;
                tableSongs.Connection               = conn;
                tablePopupDimensions.Connection     = conn;
                tableListviewColumnSizes.Connection = conn;
                tableHotkeys.Connection             = conn;
                tableAvrProperties.Connection       = conn;
                tableAvrFilesFolders.Connection     = conn;

                if (!HasTable("Reminder", db))
                {
                    tableReminder.ExecuteNonQuery();
                }

                if (!HasTable("Settings", db))
                {
                    tableSettings.ExecuteNonQuery();
                }

                if (!HasTable("Songs", db))
                {
                    tableSongs.ExecuteNonQuery();
                }

                if (!HasTable("Popupdimensions", db))
                {
                    tablePopupDimensions.ExecuteNonQuery();
                }

                if (!HasTable("ListviewColumnSizes", db))
                {
                    tableListviewColumnSizes.ExecuteNonQuery();
                }

                if (!HasTable("Hotkeys", db))
                {
                    tableHotkeys.ExecuteNonQuery();
                }

                if (!HasTable("AdvancedReminderProperties", db))
                {
                    tableHotkeys.ExecuteNonQuery();
                }

                if (!HasTable("AdvancedReminderFilesFolders", db))
                {
                    tableHotkeys.ExecuteNonQuery();
                }


                conn.Close();
                conn.Dispose();
                db.Dispose();
            }
        }
Ejemplo n.º 14
0
            public static void InsertDefaultThemes()
            {
                using (RemindMeDbEntities db = new RemindMeDbEntities())
                {
                    Themes theme = new Themes();
                    theme.Mode      = 1;
                    theme.ThemeName = "Dark-Red";
                    theme.IsDefault = 0;
                    theme.TextShade = (long)TextShade.WHITE;

                    theme.Primary      = (long)Primary.Red700;
                    theme.DarkPrimary  = (long)Primary.Red900;
                    theme.LightPrimary = (long)Primary.Red200;
                    theme.Accent       = (long)Accent.Red100;

                    if (db.Themes.Count() > 0)
                    {
                        theme.Id = db.Themes.Max(i => i.Id) + 1;
                    }
                    else
                    {
                        theme.Id = 0;
                    }

                    db.Themes.Add(theme);
                    db.SaveChanges();

                    //----
                    theme           = new Themes();
                    theme.Mode      = 0;
                    theme.ThemeName = "(Default) Blue-Light";
                    theme.IsDefault = 1;
                    theme.TextShade = (long)TextShade.WHITE;

                    theme.Primary      = (long)Primary.Indigo500;
                    theme.DarkPrimary  = (long)Primary.Indigo700;
                    theme.LightPrimary = (long)Primary.Indigo100;
                    theme.Accent       = (long)Accent.Pink200;

                    theme.Id = db.Themes.Max(i => i.Id) + 1;

                    db.Themes.Add(theme);
                    db.SaveChanges();

                    //----
                    theme           = new Themes();
                    theme.Mode      = 0;
                    theme.ThemeName = "(Default) Green-Light";
                    theme.IsDefault = 1;
                    theme.TextShade = (long)TextShade.WHITE;

                    theme.Primary      = (long)Primary.Green600;
                    theme.DarkPrimary  = (long)Primary.Green700;
                    theme.LightPrimary = (long)Primary.Green200;
                    theme.Accent       = (long)Accent.Red100;

                    theme.Id = db.Themes.Max(i => i.Id) + 1;

                    db.Themes.Add(theme);
                    db.SaveChanges();


                    //----
                    theme           = new Themes();
                    theme.Mode      = 0;
                    theme.ThemeName = "(Default) BlueGrey-Light";
                    theme.IsDefault = 1;
                    theme.TextShade = (long)TextShade.WHITE;

                    theme.Primary      = (long)Primary.BlueGrey800;
                    theme.DarkPrimary  = (long)Primary.BlueGrey900;
                    theme.LightPrimary = (long)Primary.BlueGrey500;
                    theme.Accent       = (long)Accent.LightBlue200;

                    theme.Id = db.Themes.Max(i => i.Id) + 1;

                    db.Themes.Add(theme);
                    db.SaveChanges();

                    //lastly, dispose
                    db.Dispose();
                }
            }
Ejemplo n.º 15
0
        /// <summary>
        /// Inserts all missing tables into the user's .db file
        /// </summary>
        public static void InsertMissingTables()
        {
            using (RemindMeDbEntities db = new RemindMeDbEntities())
            {
                SQLiteConnection conn = new SQLiteConnection();
                conn.ConnectionString = "data source = " + DB_FILE;
                conn.Open();

                SQLiteCommand tableReminder            = new SQLiteCommand();
                SQLiteCommand tableSettings            = new SQLiteCommand();
                SQLiteCommand tableSongs               = new SQLiteCommand();
                SQLiteCommand tablePopupDimensions     = new SQLiteCommand();
                SQLiteCommand tableListviewColumnSizes = new SQLiteCommand();
                SQLiteCommand tableHotkeys             = new SQLiteCommand();
                SQLiteCommand tableAvrProperties       = new SQLiteCommand();
                SQLiteCommand tableAvrFilesFolders     = new SQLiteCommand();
                SQLiteCommand tableReadMessages        = new SQLiteCommand();
                SQLiteCommand tableButtonSpaces        = new SQLiteCommand();
                SQLiteCommand tableThemes              = new SQLiteCommand();
                SQLiteCommand tableHttp    = new SQLiteCommand();
                SQLiteCommand tableHttpCon = new SQLiteCommand();
                //SQLiteCommand tableRemindMeColorSchemes = new SQLiteCommand();


                tableReminder.CommandText            = TABLE_REMINDER;
                tableSettings.CommandText            = TABLE_SETTINGS;
                tableSongs.CommandText               = TABLE_SONGS;
                tablePopupDimensions.CommandText     = TABLE_POPUP_DIMENSIONS;
                tableListviewColumnSizes.CommandText = TABLE_LISTVIEW_COLUMN_SIZES;
                tableHotkeys.CommandText             = TABLE_HOTKEYS;
                tableAvrProperties.CommandText       = TABLE_AVR_PROPERTIES;
                tableAvrFilesFolders.CommandText     = TABLE_AVR_FILES_FOLDERS;
                tableReadMessages.CommandText        = TABLE_READ_MESSAGES;
                tableButtonSpaces.CommandText        = TABLE_BUTTONSPACES;
                tableThemes.CommandText              = TABLE_THEMES;
                tableHttp.CommandText    = TABLE_HTTP;
                tableHttpCon.CommandText = TABLE_HTTP_CONDITION;
                //tableRemindMeColorSchemes.CommandText = TABLE_REMINDME_COLOR_SCHEMES;

                tableReminder.Connection            = conn;
                tableSettings.Connection            = conn;
                tableSongs.Connection               = conn;
                tablePopupDimensions.Connection     = conn;
                tableListviewColumnSizes.Connection = conn;
                tableHotkeys.Connection             = conn;
                tableAvrProperties.Connection       = conn;
                tableAvrFilesFolders.Connection     = conn;
                tableReadMessages.Connection        = conn;
                tableButtonSpaces.Connection        = conn;
                tableThemes.Connection              = conn;
                tableHttp.Connection    = conn;
                tableHttpCon.Connection = conn;
                //tableRemindMeColorSchemes.Connection = conn;


                if (!HasTable("Reminder", db))
                {
                    tableReminder.ExecuteNonQuery();
                }

                if (!HasTable("Settings", db))
                {
                    tableSettings.ExecuteNonQuery();
                }

                if (!HasTable("Songs", db))
                {
                    tableSongs.ExecuteNonQuery();
                }

                if (!HasTable("Popupdimensions", db))
                {
                    tablePopupDimensions.ExecuteNonQuery();
                }

                if (!HasTable("ListviewColumnSizes", db))
                {
                    tableListviewColumnSizes.ExecuteNonQuery();
                }

                if (!HasTable("Hotkeys", db))
                {
                    tableHotkeys.ExecuteNonQuery();
                }

                if (!HasTable("AdvancedReminderProperties", db))
                {
                    tableAvrProperties.ExecuteNonQuery();
                }

                if (!HasTable("AdvancedReminderFilesFolders", db))
                {
                    tableAvrFilesFolders.ExecuteNonQuery();
                }

                if (!HasTable("ReadMessages", db))
                {
                    tableReadMessages.ExecuteNonQuery();
                }

                if (!HasTable("ButtonSpaces", db))
                {
                    tableButtonSpaces.ExecuteNonQuery();
                }

                if (!HasTable("Themes", db))
                {
                    tableThemes.ExecuteNonQuery();
                }

                if (!HasTable("HttpRequests", db))
                {
                    tableHttp.ExecuteNonQuery();
                }

                if (!HasTable("HttpRequestCondition", db))
                {
                    tableHttpCon.ExecuteNonQuery();
                }

                conn.Close();
                conn.Dispose();
                db.Dispose();
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// This method will insert every missing column for each table into the database. Will only be called if HasallColumns() returns false. This means the user has an outdated .db file
        /// </summary>
        public static void InsertNewColumns()
        {
            using (RemindMeDbEntities db = new RemindMeDbEntities())
            {
                //every column that SHOULD exist
                var reminderNames        = typeof(Reminder).GetProperties().Select(property => property.Name).ToArray();
                var settingNames         = typeof(Settings).GetProperties().Select(property => property.Name).ToArray();
                var songNames            = typeof(Songs).GetProperties().Select(property => property.Name).ToArray();
                var popupDimensionsNames = typeof(PopupDimensions).GetProperties().Select(property => property.Name).ToArray();
                var lvColumnSizes        = typeof(ListviewColumnSizes).GetProperties().Select(property => property.Name).ToArray();
                var hotkeys         = typeof(Hotkeys).GetProperties().Select(property => property.Name).ToArray();
                var avrProperties   = typeof(AdvancedReminderProperties).GetProperties().Select(property => property.Name).ToArray();
                var avrFilesFolders = typeof(AdvancedReminderFilesFolders).GetProperties().Select(property => property.Name).ToArray();
                var readMessages    = typeof(ReadMessages).GetProperties().Select(property => property.Name).ToArray();
                var buttonSpaces    = typeof(ButtonSpaces).GetProperties().Select(property => property.Name).ToArray();
                var themes          = typeof(Themes).GetProperties().Select(property => property.Name).ToArray();
                var http            = typeof(HttpRequests).GetProperties().Select(property => property.Name).ToArray();
                var httpCon         = typeof(HttpRequestCondition).GetProperties().Select(property => property.Name).ToArray();
                //var remindMeColorSchemes = typeof(RemindMeColorScheme).GetProperties().Select(property => property.Name).ToArray();

                foreach (string column in reminderNames)
                {
                    if (!HasColumn(column, "reminder"))
                    {
                        db.Database.ExecuteSqlCommand("ALTER TABLE REMINDER ADD COLUMN " + column + " " + GetReminderColumnSqlType(column));
                    }
                }

                foreach (string column in settingNames)
                {
                    if (!HasColumn(column, "settings"))
                    {
                        db.Database.ExecuteSqlCommand("ALTER TABLE SETTINGS ADD COLUMN " + column + " " + GetSettingColumnSqlType(column));
                    }
                }

                foreach (string column in songNames)
                {
                    if (!HasColumn(column, "songs"))
                    {
                        db.Database.ExecuteSqlCommand("ALTER TABLE SONGS ADD COLUMN " + column + " " + GetSongColumnSqlType(column));
                    }
                }

                foreach (string column in popupDimensionsNames)
                {
                    if (!HasColumn(column, "PopupDimensions"))
                    {
                        db.Database.ExecuteSqlCommand("ALTER TABLE POPUPDIMENSIONS ADD COLUMN " + column + " " + GetPopupDimensionsColumnSqlType(column));
                    }
                }

                foreach (string column in lvColumnSizes)
                {
                    if (!HasColumn(column, "ListviewColumnSizes"))
                    {
                        db.Database.ExecuteSqlCommand("ALTER TABLE ListviewColumnSizes ADD COLUMN " + column + " " + GetLvColumnSizesColumnSqlType(column));
                    }
                }

                foreach (string column in hotkeys)
                {
                    if (!HasColumn(column, "Hotkeys"))
                    {
                        db.Database.ExecuteSqlCommand("ALTER TABLE Hotkeys ADD COLUMN " + column + " " + GetHotkeysColumnSqlType(column));
                    }
                }

                foreach (string column in avrProperties)
                {
                    if (!HasColumn(column, "AdvancedReminderProperties"))
                    {
                        db.Database.ExecuteSqlCommand("ALTER TABLE AdvancedReminderProperties ADD COLUMN " + column + " " + GetAvrPropertiesColumnSqlType(column));
                    }
                }

                foreach (string column in avrFilesFolders)
                {
                    if (!HasColumn(column, "AdvancedReminderFilesFolders"))
                    {
                        db.Database.ExecuteSqlCommand("ALTER TABLE AdvancedReminderFilesFolders ADD COLUMN " + column + " " + GetAvrFilesFoldersColumnSqlType(column));
                    }
                }

                foreach (string column in readMessages)
                {
                    if (!HasColumn(column, "ReadMessages"))
                    {
                        db.Database.ExecuteSqlCommand("ALTER TABLE ReadMessages ADD COLUMN " + column + " " + GetReadMessagesColumnSqlType(column));
                    }
                }

                foreach (string column in buttonSpaces)
                {
                    if (!HasColumn(column, "ButtonSpaces"))
                    {
                        db.Database.ExecuteSqlCommand("ALTER TABLE ButtonSpaces ADD COLUMN " + column + " " + GetButtonSpacesColumnSqlType(column));
                    }
                }

                foreach (string column in themes)
                {
                    try
                    {
                        if (!HasColumn("[" + column + "]", "Themes"))
                        {
                            db.Database.ExecuteSqlCommand("ALTER TABLE Themes ADD COLUMN [" + column + "] " + GetThemesColumnSqlType(column));
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ex.Message == "SQL logic error\r\nnear \"Primary\": syntax error")
                        {
                        }                                                                         //not important. Not sure why this error is thrown, but everything works.
                        else
                        {
                            throw ex;
                        }
                    }
                }

                foreach (string column in http)
                {
                    if (!HasColumn(column, "HttpRequests"))
                    {
                        db.Database.ExecuteSqlCommand("ALTER TABLE HttpRequests ADD COLUMN " + column + " " + GetHttpColumnSqlType(column));
                    }
                }

                foreach (string column in httpCon)
                {
                    if (!HasColumn(column, "HttpRequestCondition"))
                    {
                        db.Database.ExecuteSqlCommand("ALTER TABLE HttpRequestCondition ADD COLUMN " + column + " " + GetHttpConditionColumnSqlType(column));
                    }
                }

                db.SaveChanges();
                db.Dispose();
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// This method will insert every missing column for each table into the database. Will only be called if HasallColumns() returns false. This means the user has an outdated .db file
        /// </summary>
        public static void InsertNewColumns()
        {
            using (RemindMeDbEntities db = new RemindMeDbEntities())
            {
                //every column that SHOULD exist
                var reminderNames        = typeof(Reminder).GetProperties().Select(property => property.Name).ToArray();
                var settingNames         = typeof(Settings).GetProperties().Select(property => property.Name).ToArray();
                var songNames            = typeof(Songs).GetProperties().Select(property => property.Name).ToArray();
                var popupDimensionsNames = typeof(PopupDimensions).GetProperties().Select(property => property.Name).ToArray();
                var lvColumnSizes        = typeof(ListviewColumnSizes).GetProperties().Select(property => property.Name).ToArray();
                var hotkeys         = typeof(Hotkeys).GetProperties().Select(property => property.Name).ToArray();
                var avrProperties   = typeof(AdvancedReminderProperties).GetProperties().Select(property => property.Name).ToArray();
                var avrFilesFolders = typeof(AdvancedReminderFilesFolders).GetProperties().Select(property => property.Name).ToArray();
                var readMessages    = typeof(ReadMessages).GetProperties().Select(property => property.Name).ToArray();
                var buttonSpaces    = typeof(ButtonSpaces).GetProperties().Select(property => property.Name).ToArray();
                //var remindMeColorSchemes = typeof(RemindMeColorScheme).GetProperties().Select(property => property.Name).ToArray();

                foreach (string column in reminderNames)
                {
                    if (!HasColumn(column, "reminder"))
                    {
                        db.Database.ExecuteSqlCommand("ALTER TABLE REMINDER ADD COLUMN " + column + " " + GetReminderColumnSqlType(column));
                    }
                }

                foreach (string column in settingNames)
                {
                    if (!HasColumn(column, "settings"))
                    {
                        db.Database.ExecuteSqlCommand("ALTER TABLE SETTINGS ADD COLUMN " + column + " " + GetSettingColumnSqlType(column));
                    }
                }

                foreach (string column in songNames)
                {
                    if (!HasColumn(column, "songs"))
                    {
                        db.Database.ExecuteSqlCommand("ALTER TABLE SONGS ADD COLUMN " + column + " " + GetSongColumnSqlType(column));
                    }
                }

                foreach (string column in popupDimensionsNames)
                {
                    if (!HasColumn(column, "PopupDimensions"))
                    {
                        db.Database.ExecuteSqlCommand("ALTER TABLE POPUPDIMENSIONS ADD COLUMN " + column + " " + GetPopupDimensionsColumnSqlType(column));
                    }
                }

                foreach (string column in lvColumnSizes)
                {
                    if (!HasColumn(column, "ListviewColumnSizes"))
                    {
                        db.Database.ExecuteSqlCommand("ALTER TABLE ListviewColumnSizes ADD COLUMN " + column + " " + GetLvColumnSizesColumnSqlType(column));
                    }
                }

                foreach (string column in hotkeys)
                {
                    if (!HasColumn(column, "Hotkeys"))
                    {
                        db.Database.ExecuteSqlCommand("ALTER TABLE Hotkeys ADD COLUMN " + column + " " + GetHotkeysColumnSqlType(column));
                    }
                }

                foreach (string column in avrProperties)
                {
                    if (!HasColumn(column, "AdvancedReminderProperties"))
                    {
                        db.Database.ExecuteSqlCommand("ALTER TABLE AdvancedReminderProperties ADD COLUMN " + column + " " + GetAvrPropertiesColumnSqlType(column));
                    }
                }

                foreach (string column in avrFilesFolders)
                {
                    if (!HasColumn(column, "AdvancedReminderFilesFolders"))
                    {
                        db.Database.ExecuteSqlCommand("ALTER TABLE AdvancedReminderFilesFolders ADD COLUMN " + column + " " + GetAvrFilesFoldersColumnSqlType(column));
                    }
                }

                foreach (string column in readMessages)
                {
                    if (!HasColumn(column, "ReadMessages"))
                    {
                        db.Database.ExecuteSqlCommand("ALTER TABLE ReadMessages ADD COLUMN " + column + " " + GetReadMessagesColumnSqlType(column));
                    }
                }

                foreach (string column in buttonSpaces)
                {
                    if (!HasColumn(column, "ButtonSpaces"))
                    {
                        db.Database.ExecuteSqlCommand("ALTER TABLE ButtonSpaces ADD COLUMN " + column + " " + GetButtonSpacesColumnSqlType(column));
                    }
                }

                /*This was testing a custom color scheme
                 * foreach (string column in remindMeColorSchemes)
                 * {
                 *  if (!HasColumn(column, "RemindMeColorScheme"))
                 *      db.Database.ExecuteSqlCommand("ALTER TABLE RemindMeColorScheme ADD COLUMN " + column + " " + GetRemindMeColorSchemesColumnSqlType(column));
                 * }*/


                db.SaveChanges();
                db.Dispose();
            }
        }