/// <summary> /// Insert advanced Reminder properties into the database /// </summary> /// <param name="avr">The avr object</param> /// <returns></returns> public static long InsertAVRProperties(AdvancedReminderProperties avr) { using (RemindMeDbEntities db = new RemindMeDbEntities()) { if (db.AdvancedReminderProperties.Where(r => r.Remid == avr.Remid).Count() > 0) { //Exists already. update. db.AdvancedReminderProperties.Attach(avr); var entry = db.Entry(avr); entry.State = System.Data.Entity.EntityState.Modified; //Mark it for update db.SaveChanges(); db.Dispose(); } else { if (db.AdvancedReminderProperties.Count() > 0) { avr.Id = db.AdvancedReminderProperties.Max(i => i.Id) + 1; } db.AdvancedReminderProperties.Add(avr); db.SaveChanges(); db.Dispose(); } } return(avr.Id); }
private void TooltipAdvancedReminder_Draw(object sender, DrawToolTipEventArgs e) { Graphics g = e.Graphics; SolidBrush b; AdvancedReminderProperties props = BLLocalDatabase.AVRProperty.GetAVRProperties(rem.Id); if (MaterialSkin.MaterialSkinManager.Instance.Theme == MaterialSkin.MaterialSkinManager.Themes.DARK) { b = new SolidBrush(BACKGROUND_DARK); g.FillRectangle(b, e.Bounds); TextRenderer.DrawText(e.Graphics, e.ToolTipText, new Font(pfc.Families[0], 13f, FontStyle.Regular, GraphicsUnit.Pixel), new Point(e.Bounds.X + 5, e.Bounds.Y + 5), TEXT_HIGH_EMPHASIS_LIGHT); } else { b = new SolidBrush(BACKGROUND_LIGHT); g.FillRectangle(b, e.Bounds); TextRenderer.DrawText(e.Graphics, e.ToolTipText, new Font(pfc.Families[0], 13f, FontStyle.Regular, GraphicsUnit.Pixel), new Point(e.Bounds.X + 5, e.Bounds.Y + 5), TEXT_HIGH_EMPHASIS_DARK); } b.Dispose(); g.Dispose(); }
private void SetTooltips() { if (this.Reminder == null) { return; } tooltipReminderNote.SetToolTip(this, this.Reminder.Note.Replace("\\n", Environment.NewLine)); //Unsubscribe to make sure you dont subscribe twice tooltipReminderNote.Draw -= TooltipReminderNote_Draw; tooltipReminderNote.Popup -= TooltipReminderNote_Popup; tooltipReminderNote.Draw += TooltipReminderNote_Draw; tooltipReminderNote.Popup += TooltipReminderNote_Popup; AdvancedReminderProperties props = BLLocalDatabase.AVRProperty.GetAVRProperties(rem.Id); if (props != null && !string.IsNullOrWhiteSpace(props.BatchScript)) { tooltipAdvancedReminder.SetToolTip(pbDate, "This reminder has been configured to\r\nRun code on popup:\r\n\r\n" + props.BatchScript); //Unsubscribe to make sure you dont subscribe twice tooltipAdvancedReminder.Popup -= TooltipAdvancedReminder_Popup; tooltipAdvancedReminder.Draw -= TooltipAdvancedReminder_Draw; tooltipAdvancedReminder.Popup += TooltipAdvancedReminder_Popup; tooltipAdvancedReminder.Draw += TooltipAdvancedReminder_Draw; } else { tooltipAdvancedReminder.SetToolTip(pbDate, ""); } }
private void TooltipAdvancedReminder_Popup(object sender, PopupEventArgs e) { AdvancedReminderProperties props = BLLocalDatabase.AVRProperty.GetAVRProperties(rem.Id); e.ToolTipSize = TextRenderer.MeasureText("This reminder has been configured to\r\nRun code on popup:\r\n\r\n" + props.BatchScript, new Font(pfc.Families[0], 13f, FontStyle.Regular, GraphicsUnit.Pixel)); e.ToolTipSize = new Size(e.ToolTipSize.Width + 8, e.ToolTipSize.Height + 10); }
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(); }
/// <summary> /// Inserts Advanced reminder properties into the database, with a link to the reminder by it's ID /// </summary> /// <param name="avr"></param> /// <returns>The id of the newly inserted row. -1 if something went wrong</returns> public static long InsertAVRProperties(AdvancedReminderProperties avr) { //First check if the reminder exists if (DLReminders.GetReminderById(avr.Remid) == null) { return(-1); } return(DLLocalDatabase.AVRProperty.InsertAVRProperties(avr)); }
/// <summary> /// Get the advanced Reminder properties for a reminder /// </summary> /// <param name="remId">The id of the reminder</param> /// <returns></returns> public static AdvancedReminderProperties GetAVRProperties(long remId) { AdvancedReminderProperties avr = null; using (RemindMeDbEntities db = new RemindMeDbEntities()) { avr = (from g in db.AdvancedReminderProperties select g).Where(r => r.Remid == remId).SingleOrDefault(); db.Dispose(); } return(avr); }
public static void DeleteAvrProperties(AdvancedReminderProperties prop) { using (RemindMeDbEntities db = new RemindMeDbEntities()) { db.AdvancedReminderProperties.Attach(prop); db.AdvancedReminderProperties.Remove(prop); db.SaveChanges(); db.Dispose(); } }
/// <summary> /// Delete Avr properties of a specific reminder /// </summary> /// <param name="id">Id of the avr properties record in the SQLite database</param> public static void DeleteAvrProperties(long id) { AdvancedReminderProperties prop = GetAVRProperties(id); if (prop == null) { return; } using (RemindMeDbEntities db = new RemindMeDbEntities()) { db.AdvancedReminderProperties.Attach(prop); db.AdvancedReminderProperties.Remove(prop); db.SaveChanges(); db.Dispose(); } }
private void Popup2_Load(object sender, EventArgs e) { BLIO.Log("Popup_load"); AdvancedReminderProperties avrProps = BLAVRProperties.GetAVRProperties(rem.Id); List <AdvancedReminderFilesFolders> avrFF = BLAVRProperties.GetAVRFilesFolders(rem.Id); if (avrProps != null) //Not null? this reminder has advanced properties. { BLIO.Log("Reminder " + rem.Id + " has advanced reminder properties!"); if (!string.IsNullOrWhiteSpace(avrProps.BatchScript)) { BLIO.ExecuteBatch(avrProps.BatchScript); } this.Visible = avrProps.ShowReminder == 1; } if (avrFF != null && avrFF.Count > 0) { //Go through each action, for example c:\test , delete. c:\sometest\testFile.txt , open foreach (AdvancedReminderFilesFolders avr in avrFF) { if (avr.Action.ToString() == "Open") { if (File.Exists(avr.Path) || Directory.Exists(avr.Path)) { System.Diagnostics.Process.Start(avr.Path); } } else if (avr.Action.ToString() == "Delete") { FileAttributes attr = File.GetAttributes(avr.Path); //Check if it's a file or a directory if (File.Exists(avr.Path)) { File.Delete(avr.Path); } else if (Directory.Exists(avr.Path)) { Directory.Delete(avr.Path, true); } } } } if (this.Visible) { tmrFadeIn.Start(); } else { btnOk_Click(sender, e); return; } DateTime date = Convert.ToDateTime(rem.Date.Split(',')[0]); lblSmallDate.Text = date.ToShortDateString() + " " + date.ToShortTimeString(); lblRepeat.Text = BLReminder.GetRepeatTypeText(rem); if (!String.IsNullOrWhiteSpace(rem.PostponeDate)) { pbDate.BackgroundImage = Properties.Resources.RemindMeZzz; lblSmallDate.Text = Convert.ToDateTime(rem.PostponeDate) + " (Postponed)"; } //If some country has a longer date string, move the repeat icon/text more to the right so it doesnt overlap while (lblSmallDate.Bounds.IntersectsWith(pbRepeat.Bounds)) { pbRepeat.Location = new Point(pbRepeat.Location.X + 5, pbRepeat.Location.Y); lblRepeat.Location = new Point(lblRepeat.Location.X + 5, lblRepeat.Location.Y); } //Play the sound if (rem.SoundFilePath != null && rem.SoundFilePath != "") { if (System.IO.File.Exists(rem.SoundFilePath)) { BLIO.Log("SoundFilePath not null / empty and exists on the hard drive!"); myPlayer.URL = rem.SoundFilePath; myPlayer.controls.play(); BLIO.Log("Playing sound"); } else { BLIO.Log("SoundFilePath not null / empty but doesn't exist on the hard drive!"); RemindMeBox.Show("Could not play " + Path.GetFileNameWithoutExtension(rem.SoundFilePath) + " located at \"" + rem.SoundFilePath + "\" \r\nDid you move,rename or delete the file ?\r\nThe sound effect has been removed from this reminder. If you wish to re-add it, select it from the drop-down list.", RemindMeBoxReason.OK); //make sure its removed from the reminder rem.SoundFilePath = ""; } } FlashWindowHelper.Start(this); //this.MaximumSize = this.Size; if (BLSettings.IsAlwaysOnTop()) { this.TopMost = true; //Popup will be always on top. no matter what you are doing, playing a game, watching a video, you will ALWAYS see the popup. this.TopLevel = true; } else { this.TopMost = false; this.WindowState = FormWindowState.Minimized; } lblTitle.Text = rem.Name; if (rem.Note != null) { lblNoteText.Text = rem.Note.Replace("\\n", Environment.NewLine); } if (rem.Note == "") { lblNoteText.Text = "( No text set )"; } lblNoteText.Text = Environment.NewLine + Environment.NewLine + lblNoteText.Text; if (rem.Date == null) { rem.Date = DateTime.Now.ToString(); } }
/// <summary> /// Checks if there is anything wrong with the reminder that might cause an exception /// </summary> /// <param name="rem">The reminder you want to check on</param> /// <returns>True if this reminder could cause an exception, false if not</returns> public static Exception IsValidReminder(Reminder rem) { try { DateTime date; //Check all possible dates foreach (string stringDate in rem.Date.Split(',')) { date = Convert.ToDateTime(stringDate); } if (rem.PostponeDate != null) { date = Convert.ToDateTime(rem.PostponeDate.Split(',')[0]); } if (rem.Enabled > 1 || rem.Enabled < 0) { throw new Exception("Enabled is not 0 or 1"); } if (rem.Deleted > 2 || rem.Deleted < 0) { throw new Exception("Deleted is not between 0 and 2"); } if (rem.Hide > 1 || rem.Hide < 0) { throw new Exception("Hide is not 0 or 1"); } if (rem.Corrupted > 1 || rem.Corrupted < 0) { throw new Exception("Corrupted is not 0 or 1"); } if (rem.EnableAdvancedReminder > 1 || rem.EnableAdvancedReminder < 0) { throw new Exception("EnableAdvancedReminder is not 0 or 1"); } if (rem.UpdateTime > 1 || rem.UpdateTime < 0) { throw new Exception("UpdateTime is not 0 or 1"); } //If the reminder is weekdays, check if there are more than 0 days if (rem.RepeatType == ReminderRepeatType.MULTIPLE_DAYS.ToString()) { string[] days = rem.RepeatDays.Split(','); if (days.Length <= 0) { throw new Exception("RepeatType is MULTIPLE_DAYS and there are are no RepeatDays"); } } if (rem.RepeatType == ReminderRepeatType.CUSTOM.ToString()) { if (rem.EveryXCustom <= 0) { throw new Exception("RepeatType is CUSTOM and EveryXCustom is not set"); } } string test = GetRepeatTypeText(rem); AdvancedReminderProperties avrProps = DLLocalDatabase.AVRProperty.GetAVRProperties(rem.Id); List <AdvancedReminderFilesFolders> avrFF = DLLocalDatabase.AVRProperty.GetAVRFilesFolders(rem.Id); } catch (Exception ex) { return(ex); } return(null); }
private void Popup_Load(object sender, EventArgs e) { try { BLIO.Log("Popup_load"); if (BLLocalDatabase.Setting.Settings.PopupType == "SoundOnly") { //Dont initialize, just play sound PlayReminderSound(); if (rem.Id != -1) //Dont stop logic when the user is previewing an reminder { btnOk_Click(sender, e); return; } } string reminderText = rem.Note != null?rem.Note.Replace("\n", "<br>") : "( No text set )"; //White font if dark theme, Black text if light theme string color = MaterialSkin.MaterialSkinManager.Instance.Theme == MaterialSkin.MaterialSkinManager.Themes.DARK ? "#e6e6e6" : "#323232"; if (rem.Note.Contains("API{")) { TransformAPITextToValue(color, reminderText); } else { htmlLblText.Text = GetPopupHTMLText(color, reminderText); } AdvancedReminderProperties avrProps = BLLocalDatabase.AVRProperty.GetAVRProperties(rem.Id); List <AdvancedReminderFilesFolders> avrFF = BLLocalDatabase.AVRProperty.GetAVRFilesFolders(rem.Id); if (avrProps != null) //Not null? this reminder has advanced properties. { BLIO.Log("Reminder " + rem.Id + " has advanced reminder properties!"); this.Visible = avrProps.ShowReminder == 1; if (!string.IsNullOrWhiteSpace(avrProps.BatchScript)) { //if (!this.Visible) MaterialMessageFormManager.MakeMessagePopup("Activating script of Reminder:\r\n \"" + rem.Name + "\"", 3); BLIO.ExecuteBatch(avrProps.BatchScript); } } else { BLIO.Log("Reminder " + rem.Id + " does not have advanced reminder properties"); } if (avrFF != null && avrFF.Count > 0) { //Go through each action, for example c:\test , delete. c:\sometest\testFile.txt , open foreach (AdvancedReminderFilesFolders avr in avrFF) { if (avr.Action.ToString() == "Open") { BLIO.Log("Executing advanced reminder action \"Open\""); if (File.Exists(avr.Path) || Directory.Exists(avr.Path)) { System.Diagnostics.Process.Start(avr.Path); } } else if (avr.Action.ToString() == "Delete") { BLIO.Log("Executing advanced reminder action \"Delete\""); FileAttributes attr = File.GetAttributes(avr.Path); //Check if it's a file or a directory if (File.Exists(avr.Path)) { File.Delete(avr.Path); } else if (Directory.Exists(avr.Path)) { Directory.Delete(avr.Path, true); } } } } if (this.Visible) { tmrFadeIn.Start(); } else { btnOk_Click(sender, e); return; } if (rem.HttpId == null) { BLIO.Log("Attempting to parse date..."); DateTime date = Convert.ToDateTime(rem.Date.Split(',')[0]); BLIO.Log("Date succesfully converted (" + date + ")"); lblSmallDate.Text = date.ToShortDateString() + " " + date.ToShortTimeString(); } else { lblSmallDate.Text = "Conditional"; } lblRepeat.Text = BLReminder.GetRepeatTypeText(rem); if (!string.IsNullOrWhiteSpace(rem.PostponeDate)) { BLIO.Log("Reminder has a postpone date."); pbDate.BackgroundImage = Properties.Resources.RemindMeZzz; lblSmallDate.Text = Convert.ToDateTime(rem.PostponeDate) + ""; } //If some country has a longer date string, move the repeat icon/text more to the right so it doesnt overlap while (lblSmallDate.Bounds.IntersectsWith(pbRepeat.Bounds)) { pbRepeat.Location = new Point(pbRepeat.Location.X + 5, pbRepeat.Location.Y); lblRepeat.Location = new Point(lblRepeat.Location.X + 5, lblRepeat.Location.Y); } PlayReminderSound(); FlashWindowHelper.Start(this); //this.MaximumSize = this.Size; if (BLLocalDatabase.Setting.Settings.PopupType == "AlwaysOnTop") { this.TopMost = true; //Popup will be always on top. no matter what you are doing, playing a game, watching a video, you will ALWAYS see the popup. this.TopLevel = true; } else { if (rem.Id != -1) //previewreminders should be topmost { this.TopMost = false; this.WindowState = FormWindowState.Minimized; } } this.Text = rem.Name; string hexColor = ColorToHex(MaterialSkin.MaterialSkinManager.Instance.ColorScheme.AccentColor); foreach (string link in GetLinks(htmlLblText.Text)) //Add <a href> to make it into an actual link { htmlLblText.Text = htmlLblText.Text.Replace(link, "<a href=\"" + link + "\" style=\"color: " + hexColor + "\"> " + link + "</a>"); } if (rem.Date == null && rem.HttpId == null) { rem.Date = DateTime.Now.ToString(); } } catch (Exception ex) { ReminderException remEx = new ReminderException(BLReminder.ToString(rem), rem); remEx.StackTrace = ex.StackTrace; //Copy the stacktrace BLIO.WriteError(remEx, "Error loading reminder popup"); BLIO.Log("Popup_load FAILED. Exception -> " + ex.Message); } }
//Loads reminder data into the controls private void Enable() { MaterialSkin.MaterialSkinManager.Themes theme = MaterialSkin.MaterialSkinManager.Instance.Theme; lblReminderName.Visible = true; lblReminderNameDisabled.Visible = false; lblRepeat.FontType = MaterialSkin.MaterialSkinManager.fontType.Subtitle2; lblDate.FontType = MaterialSkin.MaterialSkinManager.fontType.Subtitle2; //Enabled icons if (theme == MaterialSkin.MaterialSkinManager.Themes.DARK) { btnDelete.Image = Properties.Resources.Bin_white; btnEdit.Image = Properties.Resources.EditPenWhite; btnSettings.Image = Properties.Resources.gearWhite; btnDisable.Image = Properties.Resources.disableWhite; pbConditionalReminder.Image = Properties.Resources.wwwLight; } else { btnDelete.Image = Properties.Resources.binDark; btnEdit.Image = Properties.Resources.editPenDark; btnSettings.Image = Properties.Resources.gearDark; btnDisable.Image = Properties.Resources.disableDark; pbConditionalReminder.Image = Properties.Resources.wwwDark; } BLFormLogic.SetImageAlpha(pbConditionalReminder, 50); //if the reminder is disabled, use this icon instead if (rem.Enabled == 0) { btnDisable.Image = Properties.Resources.turnedOffTwo; lblReminderName.Visible = false; lblReminderNameDisabled.Visible = true; lblDate.FontType = MaterialSkin.MaterialSkinManager.fontType.Body2; lblRepeat.FontType = MaterialSkin.MaterialSkinManager.fontType.Body2; } //Reset location pbRepeat.Location = new Point(168, pbRepeat.Location.Y); lblRepeat.Location = new Point(195, lblRepeat.Location.Y); if (rem.HttpId == null) { pbConditionalReminder.Visible = false; DateTime date = Convert.ToDateTime(rem.Date.Split(',')[0]); if (date.ToShortDateString() == DateTime.Now.ToShortDateString()) { lblDate.Text = "Today " + date.ToShortTimeString(); } else { lblDate.Text = date.ToShortDateString() + " " + date.ToShortTimeString(); } //Postpone logic if (rem.PostponeDate != null && !string.IsNullOrWhiteSpace(rem.PostponeDate)) { pbDate.BackgroundImage = Properties.Resources.RemindMeZzz; Font font = new Font(lblRepeat.Font, FontStyle.Bold | FontStyle.Italic); lblDate.Font = font; if (Convert.ToDateTime(rem.PostponeDate).ToShortDateString() == DateTime.Now.ToShortDateString()) { lblDate.Text = "Today " + Convert.ToDateTime(rem.PostponeDate).ToShortTimeString(); } else { lblDate.Text = Convert.ToDateTime(rem.PostponeDate).ToShortDateString() + " " + Convert.ToDateTime(rem.PostponeDate).ToShortTimeString(); } } else { pbDate.BackgroundImage = Properties.Resources.RemindMe; Font font = new Font(lblRepeat.Font, FontStyle.Bold); lblDate.Font = font; } } else { pbConditionalReminder.Visible = true; lblDate.Text = "Conditional"; pbDate.BackgroundImage = Properties.Resources.RemindMe; } AdvancedReminderProperties props = BLLocalDatabase.AVRProperty.GetAVRProperties(rem.Id); if (props != null && !string.IsNullOrWhiteSpace(props.BatchScript)) { pbDate.BackgroundImage = Properties.Resources.terminal1; } //If some country has a longer date string, move the repeat icon/text more to the right so it doesnt overlap while (lblDate.Bounds.IntersectsWith(pbRepeat.Bounds)) { pbRepeat.Location = new Point(pbRepeat.Location.X + 5, pbRepeat.Location.Y); lblRepeat.Location = new Point(lblRepeat.Location.X + 5, lblRepeat.Location.Y); } lblReminderName.Text = rem.Name; lblRepeat.Text = BLReminder.GetRepeatTypeText(rem); SetTooltips(); /*if (rem.Enabled == 1) * { * btnDisable.Image = Properties.Resources.turnedOn; * lblReminderName.ForeColor = Color.White; * lblDate.ForeColor = Color.White; * lblRepeat.ForeColor = Color.White; * } * else * { * //Disabled reminder, make text gray * * lblReminderName.ForeColor = Color.Silver; * lblDate.ForeColor = Color.Silver; * lblRepeat.ForeColor = Color.Silver; * }*/ btnSettings.Enabled = true; btnDelete.Enabled = true; btnEdit.Enabled = true; btnDisable.Enabled = true; }