Esempio n. 1
0
        /// <summary>
        /// Change this user controls's icons based on the theme
        /// </summary>
        /// <param name="theme"></param>
        public void UpdateTheme(MaterialSkin.MaterialSkinManager.Themes theme)
        {
            if (theme == MaterialSkin.MaterialSkinManager.Themes.DARK)
            {
                btnAddReminder.Icon     = Properties.Resources.Plus_white;
                btnPreviousPage.Icon    = Properties.Resources.PreviousWhite;
                btnNextPage.Icon        = Properties.Resources.NextWhite;
                btnUnhideReminders.Icon = Properties.Resources.eyeWhite;
            }
            else
            {//Light
                btnAddReminder.Icon     = Properties.Resources.plusDark;
                btnPreviousPage.Icon    = Properties.Resources.previousDark;
                btnNextPage.Icon        = Properties.Resources.nextDark;
                btnUnhideReminders.Icon = Properties.Resources.eyeDark;
            }

            //also update each uc in pnlreminders
            foreach (Control c in pnlReminders.Controls)
            {
                if (c is MUCReminderItem)
                {
                    MUCReminderItem m = (MUCReminderItem)c;
                    m.UpdateTheme(null);
                }
            }

            SetPageButtonIcons(BLReminder.GetReminders());
        }
Esempio n. 2
0
        private void btnPreviousPage_Click(object sender, EventArgs e)
        {
            BLIO.Log("btnPreviousPage_Click");


            if (pageNumber <= 1) //Can't go to the previous page if we're on the first one
            {
                return;
            }

            List <Reminder> reminders = BLReminder.GetOrderedReminders();

            int reminderItemCounter = 0;

            for (int i = (pageNumber - 2) * 7; i < ((pageNumber - 2) * 7) + 7; i++)
            {
                if (reminders.Count - 1 >= i) //Safely within index numbers
                {
                    //Get the user control item from the panel. There's 7 user controls in the panel, so we have another counter for those
                    MUCReminderItem itm = (MUCReminderItem)pnlReminders.Controls[reminderItemCounter];
                    itm.Visible = true;
                    //Update the reminder object inside the user control, that's waay faster than removing and re-drawing a new control.
                    itm.Reminder = reminders[i];
                }

                reminderItemCounter++;

                if (reminderItemCounter == 7)
                {
                    break;
                }
            }

            pageNumber--;

            SetPageButtonIcons(reminders);
            foreach (MUCReminderItem itm in pnlReminders.Controls)
            {
                itm.RefreshLabelFont();
            }

            GC.Collect();
        }
Esempio n. 3
0
        private void btnNextPage_Click(object sender, EventArgs e)
        {
            BLIO.Log("btnNextPage_Click");


            List <Reminder> reminders = BLReminder.GetOrderedReminders();


            if ((pageNumber * 7) + 1 > reminders.Count)
            {
                return; //No reminders left
            }
            int reminderItemCounter = 0;

            for (int i = pageNumber * 7; i < (pageNumber * 7) + 7; i++)
            {
                if (reminders.Count - 1 >= i) //Safely within index numbers
                {
                    //Get the user control item from the panel. There's 7 user controls in the panel, so we have another counter for those
                    MUCReminderItem itm = (MUCReminderItem)pnlReminders.Controls[reminderItemCounter];
                    itm.Visible = true;
                    //Update the reminder object inside the user control, that's waay faster than removing and re-drawing a new control.
                    itm.Reminder = reminders[i];
                }
                else //Fill all remaining controls that can't be filled with reminders with "empty", since there are no reminders left
                {
                    for (int ii = reminderItemCounter; ii < 7; ii++)
                    {
                        ((MUCReminderItem)pnlReminders.Controls[ii]).Reminder = null;
                    }
                }
                reminderItemCounter++;
            }

            MaterialSkin.MaterialSkinManager.Themes theme = MaterialSkin.MaterialSkinManager.Instance.Theme;

            pageNumber++;
            if ((pageNumber * 7) + 1 > reminders.Count)
            {
                btnNextPage.Icon = Properties.Resources.nextDisabledDark;
            }
            else
            {
                if (theme == MaterialSkin.MaterialSkinManager.Themes.DARK)
                {
                    btnNextPage.Icon = Properties.Resources.NextWhite;
                }
                else
                {
                    btnNextPage.Icon = Properties.Resources.nextDark;
                }
            }

            if (pageNumber > 1)
            {
                if (theme == MaterialSkin.MaterialSkinManager.Themes.DARK)
                {
                    btnPreviousPage.Icon = Properties.Resources.PreviousWhite;
                }
                else
                {
                    btnPreviousPage.Icon = Properties.Resources.previousDark;
                }
            }

            MaterialForm1.Instance.UpdatePageNumber(pageNumber);
            foreach (MUCReminderItem itm in pnlReminders.Controls)
            {
                itm.RefreshLabelFont();
            }

            GC.Collect();
        }
Esempio n. 4
0
        /// <summary>
        /// Display changes on the current page. (For example a deleted or enabled/disabled reminder)
        /// </summary>
        /// <param name="editedReminder">If a reminder has been edited, this object will contain that reminder</param>
        public void UpdateCurrentPage(Reminder editedReminder = null)
        {
            MaterialSkin.MaterialSkinManager.Themes theme = MaterialSkin.MaterialSkinManager.Instance.Theme;

            BLIO.Log("Starting UpdateCurrentPage()...");

            //Reminder list containing normal reminders and conditional reminders, enabled and disabled
            List <Reminder> reminders = BLReminder.GetOrderedReminders();

            //^ All reminders in one list with the disabled ones at the end of the list
            BLIO.Log(reminders.Count + " reminders loaded");

startMethod:
            if ((pageNumber * 7) + 1 > reminders.Count)
            {
                if (theme == MaterialSkin.MaterialSkinManager.Themes.DARK)
                {
                    btnNextPage.Icon = Properties.Resources.nextDisabledDark;
                }
                else
                {
                    btnNextPage.Icon = Properties.Resources.nextDisabledDark;
                }
            }
            else
            {
                if (theme == MaterialSkin.MaterialSkinManager.Themes.DARK)
                {
                    btnNextPage.Icon = Properties.Resources.NextWhite;
                }
                else
                {
                    btnNextPage.Icon = Properties.Resources.nextDark;
                }
            }

            int reminderItemCounter = 0;

            for (int i = (pageNumber - 1) * 7; i < ((pageNumber) * 7); i++)
            {
                if (reminders.Count - 1 >= i) //Safely within index numbers
                {
                    if (reminderItemCounter >= pnlReminders.Controls.Count)
                    {
                        return;
                    }

                    //Get the user control item from the panel. There's 7 user controls in the panel, so we have another counter for those
                    MUCReminderItem itm = (MUCReminderItem)pnlReminders.Controls[reminderItemCounter];
                    //Update the reminder object inside the user control, that's waay faster than removing and re-drawing a new control.
                    itm.Reminder = reminders[i];
                    itm.RefreshLabelFont();
                }
                else
                {
                    //User deleted a reminder, which was the last one out of the list from that page. Navigate to the previous page.
                    if (i % 7 == 0 && pageNumber > 1)
                    {
                        BLIO.Log("navigating to the previous page after deletion of an reminder...");
                        pageNumber--;
                        goto startMethod;
                    }

                    for (int ii = i; ii < 7; ii++)
                    {
                        if (ii >= pnlReminders.Controls.Count)
                        {
                            break;
                        }

                        MUCReminderItem itm = (MUCReminderItem)pnlReminders.Controls[ii];
                        itm.Reminder = null;
                    }

                    //This happens when an reminder has been deleted, and there are less than 7 reminders on that page. Empty out the remaining reminder items.
                    while (reminderItemCounter <= 6)
                    {
                        BLIO.Log("Detected the deletion of an reminder on the current page.");
                        //Get the user control item from the panel. There's 7 user controls in the panel, so we have another counter for those
                        try
                        {
                            MUCReminderItem itm = (MUCReminderItem)pnlReminders.Controls[reminderItemCounter];

                            if (itm.Reminder != null)
                            {
                                BLIO.Log("Emptying ReminderItem with ID " + itm.Reminder.Id);
                            }
                            //Update the reminder object inside the user control, that's waay faster than removing and re-drawing a new control.
                            itm.Reminder = null;

                            reminderItemCounter++;
                        }
                        catch (Exception ex)
                        {
                            BLIO.Log("Setting new Reminder value failed. -> " + ex.GetType().ToString());
                        }
                    }

                    break;
                }

                reminderItemCounter++;

                if (reminderItemCounter == 7)
                {
                    break;
                }
            }



            if (reminders.Count <= 7)
            {
                MaterialForm1.Instance.UpdatePageNumber(-1);
            }
            else
            {
                MaterialForm1.Instance.UpdatePageNumber(pageNumber);
            }

            if (Instance != null)
            {
                Instance.tmrCheckReminder.Start();
            }


            if (editedReminder != null && editedReminder.HttpId != null)
            {
                //This object has been altered. Deleted, Perma-deleted, edited OR disabled
                if (BLReminder.GetReminderById(editedReminder.Id) == null || editedReminder.Deleted > 0 || editedReminder.Enabled == 0)
                {
                    //perma-deleted, soft-deleted or turned off
                    if (GetTimer(editedReminder) != null)
                    {
                        GetTimer(editedReminder).Stop();
                    }
                    RemoveTimer(editedReminder);
                }
                else //Reminder is still active, so it probably has been edited
                {
                    HttpRequests httpObj = BLLocalDatabase.HttpRequest.GetHttpRequestById((long)editedReminder.Id);
                    var          kvp     = httpTimers.Where(r => r.Key.Id == editedReminder.Id).FirstOrDefault();
                    if (kvp.Key != null)
                    {
                        //Already exist, stop timer, change & restart
                        RemoveTimer(editedReminder);
                        var timer = new System.Windows.Forms.Timer();
                        timer.Interval = Convert.ToInt32(httpObj.Interval * 60000);
                        timer.Tick    += (object s, EventArgs a) => ExecuteHttpRequest(s, a, httpObj, editedReminder);
                        timer.Start();
                        httpTimers.Add(editedReminder, timer);
                    }
                    else if (editedReminder.Enabled == 1) //Reminder has been re-enabled
                    {
                        System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
                        httpTimers.Add(editedReminder, timer);
                        timer.Interval = Convert.ToInt32(httpObj.Interval * 60000);
                        timer.Tick    += (object s, EventArgs a) => ExecuteHttpRequest(s, a, httpObj, editedReminder);
                        timer.Start();
                    }
                }
            }
            else
            {
                //Http requests
                foreach (Reminder rem in BLReminder.GetReminders(true).Where(r => r.HttpId != null).Where(r => r.Enabled == 1))
                {
                    HttpRequests httpObj = BLLocalDatabase.HttpRequest.GetHttpRequestById((long)rem.Id);

                    if (GetTimer(rem) == null)
                    {
                        //Don't add duplicates
                        System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
                        httpTimers.Add(rem, timer);
                        timer.Interval = Convert.ToInt32(httpObj.Interval * 60000);
                        timer.Tick    += (object s, EventArgs a) => ExecuteHttpRequest(s, a, httpObj, rem);
                        timer.Start();
                    }
                }
            }



            BLIO.Log("UpdateCurrentPage() completed.");
        }
Esempio n. 5
0
        public void Initialize()
        {
            try
            {
                MaterialSkin.MaterialSkinManager.Themes theme = MaterialSkin.MaterialSkinManager.Instance.Theme;

                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();

                List <Reminder> corruptedReminders = BLReminder.CheckForCorruptedReminders();

                if (corruptedReminders != null)
                {
                    string message = "RemindMe has detected";
                    if (corruptedReminders.Count > 1)
                    {
                        message += " problems with the following reminders: \r\n";

                        foreach (Reminder rem in corruptedReminders)
                        {
                            message += "- " + rem.Name + "\r\n";
                        }

                        message += "\r\nThey have been removed from your list of reminders.";
                    }
                    else
                    {
                        message += " a problem with the reminder:\r\n\"" + corruptedReminders[0].Name + "\". \r\nIt has been removed from your list of reminders.";
                    }

                    MaterialMessageFormManager.MakeMessagePopup(message, 0);
                }

                BLIO.Log("Loading reminders from database");
                //Give initial value to newReminderUc
                newReminderUc           = new MUCNewReminder(this);
                newReminderUc.Visible   = false;
                newReminderUc.saveState = false;
                this.Parent.Controls.Add(newReminderUc);


                //MaterialForm1.Instance.ucNewReminder = newReminderUc;
                //BLFormLogic.AddRemindersToListview(lvReminders, BLReminder.GetReminders().Where(r => r.Hide == 0).ToList()); //Get all "active" reminders);

                BLIO.Log("Starting the reminder timer");
                tmrCheckReminder.Start();

                pnlReminders.Visible = true;

                pnlReminders.DragDrop  += MUCReminders_DragDrop;
                pnlReminders.DragEnter += MUCReminders_DragEnter;


                int counter = 0;
                //List<Reminder> reminders = BLReminder.GetOrderedReminders();
                List <Reminder> conditionalReminders = BLReminder.GetReminders(true).Where(r => r.HttpId != null).Where(r => r.Hide == 0).Where(r => r.Enabled == 1).ToList();
                List <Reminder> activeReminders      = BLReminder.GetReminders().Where(r => r.Hide == 0).OrderBy(r => Convert.ToDateTime(r.Date.Split(',')[0])).Where(r => r.Enabled == 1).ToList();
                List <Reminder> disabledReminders    = BLReminder.GetReminders().Where(r => r.Hide == 0).OrderBy(r => Convert.ToDateTime(r.Date.Split(',')[0])).Where(r => r.Enabled == 0).ToList();

                //we've got postponed reminders, now do this
                if (BLReminder.GetReminders().Where(r => !string.IsNullOrWhiteSpace(r.PostponeDate)).ToList().Count > 0)
                {
                    activeReminders = OrderPostponedReminders();
                }

                foreach (Reminder rem in activeReminders)
                {
                    if (pnlReminders.Controls.Count >= 7)
                    {
                        break;                                   //Only 7 reminders on 1 page
                    }
                    pnlReminders.Controls.Add(new MUCReminderItem(rem));

                    if (counter > 0)
                    {
                        pnlReminders.Controls[counter].Location = new Point(0, pnlReminders.Controls[counter - 1].Location.Y + pnlReminders.Controls[counter - 1].Size.Height);
                    }

                    counter++;
                }
                foreach (Reminder rem in conditionalReminders)
                {
                    if (pnlReminders.Controls.Count >= 7)
                    {
                        break;                                   //Only 7 reminders on 1 page
                    }
                    pnlReminders.Controls.Add(new MUCReminderItem(rem));

                    if (counter > 0)
                    {
                        pnlReminders.Controls[counter].Location = new Point(0, pnlReminders.Controls[counter - 1].Location.Y + pnlReminders.Controls[counter - 1].Size.Height);
                    }

                    counter++;
                }
                foreach (Reminder rem in disabledReminders)
                {
                    if (pnlReminders.Controls.Count >= 7)
                    {
                        break;
                    }

                    pnlReminders.Controls.Add(new MUCReminderItem(rem));

                    if (counter > 0)
                    {
                        pnlReminders.Controls[counter].Location = new Point(0, pnlReminders.Controls[counter - 1].Location.Y + pnlReminders.Controls[counter - 1].Size.Height);
                    }

                    counter++;
                }

                if (activeReminders.Count + disabledReminders.Count < 7) //Less than 7 reminders, let's fit in some empty MUCReminderItem 's
                {
                    for (int i = (activeReminders.Count + disabledReminders.Count); i < 7; i++)
                    {
                        pnlReminders.Controls.Add(new MUCReminderItem(null));

                        if (counter > 0)
                        {
                            pnlReminders.Controls[counter].Location = new Point(0, pnlReminders.Controls[counter - 1].Location.Y + pnlReminders.Controls[counter - 1].Size.Height);
                        }

                        counter++;
                    }
                }

                if (BLReminder.GetReminders().Where(r => r.Hide == 0).ToList().Count <= 7)
                {
                    MaterialForm1.Instance.UpdatePageNumber(-1); //Tell MaterialForm1 that there are not more than 1 pages
                }
                else
                {
                    if (theme == MaterialSkin.MaterialSkinManager.Themes.DARK)
                    {
                        btnNextPage.Icon = Properties.Resources.NextWhite;
                    }
                    else
                    {
                        btnNextPage.Icon = Properties.Resources.nextDark;
                    }

                    MaterialForm1.Instance.UpdatePageNumber(pageNumber);
                }

                //Just design, no logic here. Drags the color panel a bit down and shrink it so it doesnt overlap over the shadow
                MUCReminderItem itm = (MUCReminderItem)pnlReminders.Controls[0];
                itm.pnlSideColor.Size     = new Size(itm.pnlSideColor.Width, itm.pnlSideColor.Height - 4);
                itm.pnlSideColor.Location = new Point(itm.pnlSideColor.Location.X, itm.pnlSideColor.Location.Y + 4);


                //Http requests
                foreach (Reminder rem in conditionalReminders)
                {
                    HttpRequests httpObj = BLLocalDatabase.HttpRequest.GetHttpRequestById((long)rem.Id);

                    System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
                    timer.Interval = Convert.ToInt32(httpObj.Interval * 60000);
                    timer.Tick    += (object s, EventArgs a) => ExecuteHttpRequest(s, a, httpObj, rem);

                    httpTimers.Add(rem, timer);
                    timer.Start();
                }

                stopwatch.Stop();
                BLIO.Log("MUCReminders Initialize took " + stopwatch.ElapsedMilliseconds + " ms");
            }
            catch (Exception ex)
            {
                BLIO.Log("MUCReminders.Initialize() FAILED. Type -> " + ex.GetType().ToString());
                BLIO.Log("Message -> " + ex.Message);
            }
        }