예제 #1
0
파일: Popup.cs 프로젝트: zozolaw/RemindMe
        private void btnOk_Click(object sender, EventArgs e)
        {
            rem = BLReminder.GetReminderById(rem.Id);

            if (rem == null)
            {
                goto close;
            }

            if (rem.Id != -1 && rem.Deleted == 0) //Don't do stuff if the id is -1, invalid. the id is set to -1 when the user previews an reminder
            {
                if (BLReminder.GetReminderById(rem.Id) == null)
                {
                    //The reminder popped up, it existed, but when pressing OK it doesn't exist anymore (maybe the user deleted it or tempered with the .db file)
                    BLIO.Log("DETECTED NONEXISTING REMINDER WITH ID " + rem.Id + ", Attempted to press OK on a reminder that somehow doesn't exist");
                    goto close;
                }

                if (cbPostpone.Checked)
                {
                    BLIO.Log("Postponing reminder with id " + rem.Id);
                    if (numPostponeTime.Value == 0)
                    {
                        return;
                    }

                    DateTime newReminderTime = new DateTime();

                    if (cbPostpone.Checked && tbtime.ForeColor == Color.White && !string.IsNullOrWhiteSpace(tbtime.Text)) //postpone option is x minutes
                    {
                        newReminderTime  = DateTime.Now.AddMinutes(BLFormLogic.GetTextboxMinutes(tbtime));
                        rem.PostponeDate = newReminderTime.ToString();
                    }
                    else
                    {
                        rem.PostponeDate = null;
                        BLReminder.UpdateReminder(rem);
                    }



                    BLIO.Log("Postpone date assigned to reminder");
                    rem.Enabled = 1;
                    BLReminder.EditReminder(rem);
                    BLIO.Log("Reminder postponed!");
                }
                else
                {
                    rem.PostponeDate = null;
                    BLReminder.UpdateReminder(rem);
                }
            }

close:
            UCReminders.GetInstance().UpdateCurrentPage();
            BLIO.Log("Stopping media player & Closing popup");
            myPlayer.controls.stop();
            btnOk.Enabled = false;
            this.Close();
        }
예제 #2
0
 public void EditReminder(Reminder rem)
 {
     newReminderUc.Reminder = BLReminder.GetReminderById(rem.Id);
     BLIO.Log("Filling form with details of reminder with id " + rem.Id + " to edit");
     Form1.Instance.ucNewReminder = newReminderUc;
     this.Visible          = false;
     newReminderUc.Visible = true;
 }
예제 #3
0
        private void duplicateToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BLIO.Log("Toolstrip option clicked: Duplicate (" + rem.Id + ")");
            BLIO.Log("Setting up the duplicating process...");
            BLIO.Log("duplicating reminder with id " + rem.Id);
            long oldRemId = rem.Id;
            long newRemId = BLReminder.PushReminderToDatabase(rem);

            AdvancedReminderProperties props = BLLocalDatabase.AVRProperty.GetAVRProperties(rem.Id);

            if (props != null)
            {
                props.Remid = newRemId;
                BLLocalDatabase.AVRProperty.InsertAVRProperties(props);
            }

            HttpRequests req = BLLocalDatabase.HttpRequest.GetHttpRequestById(oldRemId);

            if (req != null)
            {
                long oldHttpId = req.Id;
                req.reminderId = newRemId;
                long newHttpId = BLLocalDatabase.HttpRequest.InsertHttpRequest(req);
                List <HttpRequestCondition> conditions = BLLocalDatabase.HttpRequestConditions.GetConditions(oldHttpId);
                foreach (HttpRequestCondition cond in conditions)
                {
                    cond.RequestId = newHttpId;
                    BLLocalDatabase.HttpRequestConditions.InsertCondition(cond);
                }

                //Now update the duplicated reminder with the httprequest
                Reminder dup = BLReminder.GetReminderById(newRemId);
                dup.HttpId = req.Id;
                BLReminder.EditReminder(dup);
            }

            BLIO.Log("reminder duplicated.");
            MUCReminders.Instance.UpdateCurrentPage();

            new Thread(() =>
            {
                //Log an entry to the database, for data!
                try
                {
                    BLOnlineDatabase.DuplicateCount++;
                }
                catch (ArgumentException ex)
                {
                    BLIO.Log("Exception at BLOnlineDatabase.DuplicateCount++. -> " + ex.Message);
                    BLIO.WriteError(ex, ex.Message, true);
                }
                finally
                {
                    GC.Collect();
                }
            }).Start();
        }
예제 #4
0
 public void EditReminder(Reminder rem)
 {
     if (rem != null)
     {
         BLIO.Log("Edit button clicked on reminder item (" + rem.Id + ")");
         newReminderUc.Reminder = BLReminder.GetReminderById(rem.Id);
         BLIO.Log("Filling form with details of reminder with id " + rem.Id + " to edit");
         //MaterialForm1.Instance.mucReminders = newReminderUc;
         this.Visible          = false;
         newReminderUc.Visible = true;
     }
 }
예제 #5
0
        private void btnDisable_Click(object sender, EventArgs e)
        {
            BLIO.Log("btnDisable clicked on reminder " + rem.Id);
            if (xClose)
            {
                xClose = false;
            }

            if (rem != null)
            {
                rem = BLReminder.GetReminderById(rem.Id);
            }

            if (rem == null)
            {
                goto close;
            }

            if (rem.Id != -1 && rem.Deleted == 0) //Don't do stuff if the id is -1, invalid. the id is set to -1 when the user previews an reminder
            {
                if (BLReminder.GetReminderById(rem.Id) == null)
                {
                    //The reminder popped up, it existed, but when pressing disable it doesn't exist anymore (maybe the user deleted it or tempered with the .db file)
                    BLIO.Log("DETECTED NONEXISTING REMINDER WITH ID " + rem.Id + ", Attempted to press OK on a reminder that somehow doesn't exist");
                    goto close;
                }

                rem.Enabled = 0;
                BLIO.Log("Reminder marked as disabled");
                BLReminder.EditReminder(rem);
                BLIO.Log("Disabled succesfully.");
            }


close:
            MUCReminders.Instance.UpdateCurrentPage();
            BLIO.Log("Stopping media player & Closing popup");
            myPlayer.controls.stop();
            this.Close();

            GC.Collect();
        }
예제 #6
0
        private List <Reminder> OrderPostponedReminders()
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            List <Reminder> reminders          = BLReminder.GetReminders().Where(r => r.Enabled == 1).Where(r => r.Hide == 0).Where(r => string.IsNullOrWhiteSpace(r.PostponeDate)).ToList();
            List <Reminder> postPonedReminders = BLReminder.GetReminders().Where(r => r.Enabled == 1).Where(r => r.Hide == 0).Where(r => !string.IsNullOrWhiteSpace(r.PostponeDate)).ToList();

            Dictionary <long, DateTime> orderedReminders = new Dictionary <long, DateTime>();

            foreach (Reminder rem in reminders)
            {
                orderedReminders.Add(rem.Id, Convert.ToDateTime(rem.Date.Split(',')[0]));
            }

            foreach (Reminder rem in postPonedReminders)
            {
                orderedReminders.Add(rem.Id, Convert.ToDateTime(rem.PostponeDate));
            }


            //now we have both normal dates and postpone dates


            List <Reminder> returnValue = new List <Reminder>();

            foreach (KeyValuePair <long, DateTime> entry in orderedReminders.OrderBy(x => x.Value))
            {
                returnValue.Add(BLReminder.GetReminderById(entry.Key));
            }

            stopwatch.Stop();
            BLIO.Log("OrderPostponedReminders() took " + stopwatch.ElapsedMilliseconds + " ms");

            return(returnValue);
        }
예제 #7
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.");
        }
예제 #8
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (xClose)
            {
                xClose = false;
            }

            if (rem != null)
            {
                rem = BLReminder.GetReminderById(rem.Id);
            }

            if (rem == null)
            {
                goto close;
            }

            if (rem.HttpId != null)
            {
                //Conditional reminder
                HttpRequests req = BLLocalDatabase.HttpRequest.GetHttpRequestById(rem.Id);
                if (req.AfterPopup == "Stop")
                {
                    rem.Deleted = 1;
                    BLReminder.EditReminder(rem);
                    goto close;
                }
                else if (req.AfterPopup == "Repeat")
                {
                    goto close;
                }
                //else .... ?
            }

            if (rem.Id != -1 && rem.Deleted == 0) //Don't do stuff if the id is -1, invalid. the id is set to -1 when the user previews an reminder
            {
                if (BLReminder.GetReminderById(rem.Id) == null)
                {
                    //The reminder popped up, it existed, but when pressing OK it doesn't exist anymore (maybe the user deleted it or tempered with the .db file)
                    BLIO.Log("DETECTED NONEXISTING REMINDER WITH ID " + rem.Id + ", Attempted to press OK on a reminder that somehow doesn't exist");
                    goto close;
                }

                if (cbPostpone.Checked)
                {
                    BLIO.Log("Postponing reminder with id " + rem.Id);
                    if (BLFormLogic.GetTextboxMinutes(tbPostpone) <= 0)
                    {
                        return;
                    }

                    DateTime newReminderTime = new DateTime();

                    if (!string.IsNullOrWhiteSpace(tbPostpone.Text)) //postpone option is x minutes
                    {
                        newReminderTime  = DateTime.Now.AddMinutes(BLFormLogic.GetTextboxMinutes(tbPostpone));
                        rem.PostponeDate = newReminderTime.ToString();
                    }
                    else
                    {
                        rem.PostponeDate = null;
                        BLReminder.UpdateReminder(rem);
                    }



                    BLIO.Log("Postpone date assigned to reminder");
                    rem.Enabled = 1;
                    BLReminder.EditReminder(rem);
                    new Thread(() =>
                    {
                        //Log an entry to the database, for data!
                        try
                        {
                            BLOnlineDatabase.PostponeCount++;
                        }
                        catch (ArgumentException ex)
                        {
                            BLIO.Log("Exception at BLOnlineDatabase.PostponeCount++. -> " + ex.Message);
                            BLIO.WriteError(ex, ex.Message, true);
                        }
                    }).Start();
                    BLIO.Log("Reminder postponed!");
                }
                else
                {
                    rem.PostponeDate = null;
                    BLReminder.UpdateReminder(rem);
                }
            }

close:
            MUCReminders.Instance.UpdateCurrentPage(rem);
            BLIO.Log("Stopping media player & Closing popup");

            if (BLLocalDatabase.Setting.Settings.PopupType != "SoundOnly")
            {
                myPlayer.controls.stop();
            }

            this.Close();

            GC.Collect();
        }