/// <summary> /// Form that indicate progress in deleting. /// </summary> /// <param name="count">Total count of deleting events.</param> /// <param name="eventsForDelete">Events that should be deleted.</param> internal DeletingForm(Database db, int count, TimeEvent[] eventsToDelete) { deleter = new TimeEventDeleter(db, count, eventsToDelete); InitializeComponent(); progressBar.Minimum = 0; progressBar.Maximum = count; }
/// <summary> /// Set local values for labels by TimeEvent. /// </summary> /// <param name="localTe">Local TimeEvent.</param> private void setLocaleValues(TimeEvent localTe) { labelLocalName.Text = localTe.Name; labelLocalDescription.Text = localTe.Description; labelLocalStartDate.Text = localTe.StartDate.ToString(Constants.UserFriendlyDateTimeFormat); labelLocalEndDate.Text = localTe.EndDate.ToString(Constants.UserFriendlyDateTimeFormat); labelLocalNotification.Text = localTe.Notification ? localTe.NotificationDate.ToString(Constants.UserFriendlyDateTimeFormat) : "žádné"; }
/// <summary> /// Standart Constructor for easy data set. /// </summary> /// <param name="te">TimeEvent that will be shown.</param> internal TimeEventForm(TimeEvent te) { InitializeComponent(); this.Text = "Událost: " + te.Name; labelName.Text = te.Name; labelDescription.Text = te.Description; labelStartDate.Text = te.StartDate.ToString(Constants.UserFriendlyDateTimeFormat); labelEndDate.Text = te.EndDate.ToString(Constants.UserFriendlyDateTimeFormat); labelNotification.Text = te.Notification ? te.NotificationDate.ToString(Constants.UserFriendlyDateTimeFormat) : "žádné"; }
/// <summary> /// Start deleting given events. /// </summary> /// <param name="eventsToDelete">Events that will be deleted.</param> public TimeEventDeleter(Database db, int totalCount, TimeEvent[] eventsToDelete) { this.db = db; this.eventsToDelete = eventsToDelete; this.totalCount = totalCount; DeletedCount = 0; Thread t = new Thread(deleteEventsParallel); t.IsBackground = true; t.Name = " - TimeEvent Deleter"; t.Start(); }
/// <summary> /// Determine if this instance and instance given in parameter has same data values. /// </summary> /// <param name="te">Second TimeEvent, which this instance should be compared to equality.</param> /// <returns>True if has same data, false otherwise.</returns> public bool HasSameDataAs(TimeEvent te) { if (te == null) return false; if (this.Name == te.Name && this.Description == te.Description && this.StartDate == te.StartDate && this.EndDate == te.EndDate && this.Notification == te.Notification && this.NotificationDate == te.NotificationDate) return true; else return false; }
/// <summary> /// Calculate new hash and return new <see cref="TimeEvent"/> with same data but newly generated hash. /// </summary> /// <param name="te">Already existing TimeEvent with good datas, but wrong hash.</param> /// <returns></returns> public static TimeEvent CreateTimeEventWithDuplicitHash(TimeEvent te) { Random rand = new Random(); string hash = SupportMethods.GetMd5Hash(DateTime.Now + rand.NextDouble().ToString() + te.Name + te.Description + te.StartDate + te.EndDate + te.Notification + te.NotificationDate); return new TimeEvent(hash, te.Name, te.Description, te.StartDate, te.EndDate, te.Notification, te.NotificationDate); }
//----------------------------------- End of Preview --------------------------------- #endregion #region Add/Edit Tab //----------------------------------- Add/Edit Tab --------------------------------- /// <summary> /// Set Add values by the given TimeEvent. It set all textBoxes and labels by that event. /// </summary> /// <param name="te">Event with datas, that should be showed as values.</param> private void setValuesByTimeEvent(TimeEvent te) { labelAddHash.Text = te.Hash; textBoxAddName.Text = te.Name; textBoxAddDescription.Text = te.Description; dateTimePickerAddStartDate.Value = te.StartDate; dateTimePickerAddEndDate.Value = te.EndDate; checkBoxAddNotification.Checked = te.Notification; if (te.NotificationDate == DateTime.MinValue) dateTimePickerAddNotificationDate.Value = DateTime.Now; else dateTimePickerAddNotificationDate.Value = te.NotificationDate; }
/// <summary> /// This should be called when Button Delete Event in Prewiew page has been clicked. /// </summary> /// <param name="sender">Standart sender of event.</param> /// <param name="e">Standart EventArgs of event.</param> private void buttonPreviewDelEvent_Click(object sender, EventArgs e) { DialogResult dr; if (listBoxPreview.SelectedItems.Count != 1) { dr = MessageBox.Show("Opravdu si přejete smazat " + listBoxPreview.SelectedItems.Count + " událostí ?" + Environment.NewLine + "Tuto akci nelze vzít zpět. Všechny data z označených událostí budou navždy ztraceny.", "Smazat události", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr.Equals(DialogResult.No)) return; TimeEvent[] eventsToDelete = new TimeEvent[listBoxPreview.SelectedItems.Count]; listBoxPreview.SelectedItems.CopyTo(eventsToDelete, 0); timerPreviewListbox.Enabled = false; timerPreviewBoldedDates.Enabled = false; using (DeletingForm form = new DeletingForm(db, listBoxPreview.SelectedItems.Count, eventsToDelete)) { Stopwatch sw = new Stopwatch(); sw.Start(); form.ShowDialog(); Console.WriteLine(sw.Elapsed); } timerPreviewListbox.Enabled = true; timerPreviewBoldedDates.Enabled = true; resetSearchSearching(); resetPreviewSearching(); previewBoldedDates.Clear(); searchBoldedDates.Clear(); previewWorker.PreviewShowEvents(dateTimePickerPreviewFrom.Value, dateTimePickerPreviewTo.Value); } else { TimeEvent te = (TimeEvent)listBoxPreview.SelectedItem; dr = MessageBox.Show("Přejete si opravdu smazat událost: " + te.Name + " (ID: " + te.Hash + ") ?", "Smazat událost", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr.Equals(DialogResult.No)) return; db.DeleteTimeEvent(te.Hash); resetSearchSearching(); resetPreviewSearching(); previewBoldedDates.Clear(); searchBoldedDates.Clear(); previewWorker.PreviewShowEvents(dateTimePickerPreviewFrom.Value, dateTimePickerPreviewTo.Value); } }
//----------------------------------- Notification --------------------------------- /// <summary> /// This should be called when Notification short Period Timer tick happened. /// </summary> /// <param name="sender">Standart sender of event.</param> /// <param name="e">Standart EventArgs of event.</param> private void timerNotification_Tick(object sender, EventArgs e) { lock (notificationEvents) { if (notificationEvents.Count == 0) return; TimeEvent te = notificationEvents.Peek(); if (te.NotificationDate < DateTime.Now) { notificationEvents.Dequeue(); lastShownEvent = te; if (checkBoxPreviewGlobalNotification.Checked) notifyIcon.ShowBalloonTip(10000, "Eventer: " + te.Name, "Čas: " + te.NotificationDate.ToString(Constants.UserFriendlyDateTimeFormat) + Environment.NewLine + "Popis: " + te.Description, ToolTipIcon.Info); } } }
/// <summary> /// Set Remote values by TimeEvent. /// </summary> /// <param name="remoteTe">Remote TimeEvent</param> private void setRemoteValues(TimeEvent remoteTe) { labelRemoteName.Text = remoteTe.Name; labelRemoteDescription.Text = remoteTe.Description; labelRemoteStartDate.Text = remoteTe.StartDate.ToString(Constants.UserFriendlyDateTimeFormat); labelRemoteEndDate.Text = remoteTe.EndDate.ToString(Constants.UserFriendlyDateTimeFormat); labelRemoteNotification.Text = remoteTe.Notification ? remoteTe.NotificationDate.ToString(Constants.UserFriendlyDateTimeFormat) : "žádné"; }
/// <summary> /// Write content of change cache into Database. /// </summary> public void WriteCaches(Queue<TimeEvent> newTimeEvents, Queue<Change> newChanges) { lock (newTimeEvents) { TimeEvent[] timeEvents = new TimeEvent[newTimeEvents.Count]; int i = 0; while (true) { if (newTimeEvents.Count == 0) break; timeEvents[i] = newTimeEvents.Dequeue(); i++; } lock (db) if (timeEvents.Length != 0) db.ExecuteAddEditChanges(timeEvents); newTimeEvents.Clear(); } lock (newChanges) { Change[] changes = new Change[newChanges.Count]; int i = 0; while (true) { if (newChanges.Count == 0) break; Change c = newChanges.Dequeue(); c.ChangeDate = DateTime.Now; changes[i] = c; i++; } lock (db) if (changes.Length != 0) db.InsertChange(changes); newChanges.Clear(); } }
/// <summary> /// Parse Record received by connection into Chnage and TimeEvent. /// </summary> /// <param name="record">String that should be parsed.</param> /// <param name="c">Change, that was parsed.</param> /// <param name="te">TimeEvent, that was parsed</param> public void ParseRecord(string record, out Change c, out TimeEvent te) { var items = record.Split('*'); c = Change.Parse(items[0]); if (items[1] == "null") te = null; else te = TimeEvent.Parse(items[1]); }
/// <summary> /// Send Changes to writer. /// </summary> /// <param name="writer">Where should be chnage send through.</param> /// <param name="c">Which change should be send.</param> /// <param name="te">Which TimeEvent should be send.</param> public void SendChange(TextWriter writer, Change c, TimeEvent te) { if (c.Type == Change.ChangeType.Del) writer.WriteLine(c.GetSynchronizationString() + "*" + "null" + "*?"); else writer.WriteLine(c.GetSynchronizationString() + "*" + te.GetSynchronizationString() + "*?"); }
/// <summary> /// Update event and Log that change. It is not necessary more info. <seealso cref="TimeEvent"/> already contain hash of event. /// </summary> /// <param name="te">Event that has been changed. It contain old hash and new datas.</param> /// <returns>True if datas has been updated, false otherwise.</returns> internal bool UpdateTimeEvent(TimeEvent te) { ChangeEdit(te); return(updateTimeEvent(te)); }
/// <summary> /// Update event with specific hash and Log that change. It change all datas of event. /// </summary> /// <param name="hash">Original hash of event.</param> /// <param name="name">New name for event.</param> /// <param name="description">New description of event.</param> /// <param name="startDate">New starting date of this event.</param> /// <param name="endDate">New eding date of this event.</param> /// <param name="notification">New notification boolean.</param> /// <param name="notificationDate">New date for notification.</param> /// <returns>True if datas has been updated, false otherwise.</returns> internal bool UpdateTimeEvent(string hash, string name, string description, DateTime startDate, DateTime endDate, bool notification, DateTime notificationDate) { ChangeEdit(hash); return(updateTimeEvent(TimeEvent.LoadTimeEvent(hash, name, description, startDate, endDate, notification, notificationDate))); }