Esempio n. 1
0
 // This clears the dialog for a new item
 public void Clear()
 {
     result   = new AgendaItem();
     assigned = 0;
     pascalbutton.StopInfoFlash();
     marliesbutton.StopInfoFlash();
     birthdaybutton.StopInfoFlash();
     description.Clear();
     startday.Clear();
     startmonth.Clear();
     startyear.Clear();
     starthour.Clear();
     startminute.Clear();
     durdays.Clear();
     durhours.Clear();
     durminutes.Clear();
     endday.Clear();
     endmonth.Clear();
     endyear.Clear();
     endhour.Clear();
     endminute.Clear();
     alarmminutes.Clear();
     alarmbutton.StopInfoFlash();
     recurbutton.Text = AgendaItemRecur.None.ToString();
 }
Esempio n. 2
0
 // This adds an agenda item or updates an existing one
 public bool AddOrUpdateItem(AgendaItem i)
 {
     if(i.id <= 0)
         return i.SqlInsert();
     else
         return i.SqlUpdate();
 }
 // This clears the dialog for a new item
 public void Clear()
 {
     result = new AgendaItem();
     assigned = 0;
     pascalbutton.StopInfoFlash();
     marliesbutton.StopInfoFlash();
     birthdaybutton.StopInfoFlash();
     description.Clear();
     startday.Clear();
     startmonth.Clear();
     startyear.Clear();
     starthour.Clear();
     startminute.Clear();
     durdays.Clear();
     durhours.Clear();
     durminutes.Clear();
     endday.Clear();
     endmonth.Clear();
     endyear.Clear();
     endhour.Clear();
     endminute.Clear();
     alarmminutes.Clear();
     alarmbutton.StopInfoFlash();
     recurbutton.Text = AgendaItemRecur.None.ToString();
 }
Esempio n. 4
0
        // This fills the dialog with info about an item
        public void SetupItem(AgendaItem item)
        {
            Clear();

            result = item;

            // Assigned
            if (item.color == ColorIndex.ControlColorPascal)
            {
                assigned = 1;
                pascalbutton.StartInfoFlash();
            }
            else if (item.color == ColorIndex.ControlColorMarlies)
            {
                assigned = 2;
                marliesbutton.StartInfoFlash();
            }
            else if (item.color == ColorIndex.ControlColorAffirmative)
            {
                assigned = 3;
                birthdaybutton.StartInfoFlash();
            }

            // Description
            description.Text = item.description;

            // Start
            startday.Text    = item.originstartdate.Day.ToString();
            startmonth.Text  = item.originstartdate.Month.ToString();
            startyear.Text   = item.originstartdate.Year.ToString();
            starthour.Text   = item.originstartdate.Hour.ToString();
            startminute.Text = item.originstartdate.Minute.ToString("00");

            // Duration
            int days = (int)Math.Floor(item.duration.TotalDays);

            durdays.Text    = days.ToString();
            durhours.Text   = item.duration.Hours.ToString();
            durminutes.Text = item.duration.Minutes.ToString("00");

            // End
            CalculateEndDateFromDuration();

            // Alarm
            TimeSpan alarmdur = item.startdate - item.alarmdate;

            alarmdur = alarmdur.Duration();
            int alarmmin = (int)alarmdur.TotalMinutes;

            alarmminutes.Text = alarmmin.ToString();
            if (item.alarm)
            {
                alarmbutton.StartInfoFlash();
            }

            // Recurring
            recurbutton.Text = item.recur.ToString();
        }
Esempio n. 5
0
        // Delete clicked
        private void deletebutton_Click(object sender, EventArgs e)
        {
            AgendaItem item = (AgendaItem)itembuttons[selectedindex].Tag;

            General.Sounds.Play("208");
            General.Agenda.RemoveItem(item);
            General.MainWindow.OverviewPanel.UpdateAgenda();
            RefreshDay();
        }
Esempio n. 6
0
        // Edit clicked
        private void editbutton_Click(object sender, EventArgs e)
        {
            AgendaItem item = (AgendaItem)itembuttons[selectedindex].Tag;

            itemeditor.ReturnPanel  = "agendaday";
            itemeditor.AcceptEvent += RefreshDay;
            itemeditor.SetupItem(item);
            General.MainWindow.ShowTaggedPanel("agendaitem");
        }
Esempio n. 7
0
 // This adds an agenda item or updates an existing one
 public bool AddOrUpdateItem(AgendaItem i)
 {
     if (i.id <= 0)
     {
         return(i.SqlInsert());
     }
     else
     {
         return(i.SqlUpdate());
     }
 }
Esempio n. 8
0
 // This reads from a data row
 public static AgendaItem FromDataRow(DataTableRow r)
 {
     AgendaItem i = new AgendaItem();
     i.id = r.GetLong("id");
     i.color = (ColorIndex)r.GetInt("color");
     i.description = r.GetString("description");
     i.startdate = new DateTime(r.GetLong("startdate"));
     i.originstartdate = i.startdate;
     i.duration = new TimeSpan(r.GetLong("duration"));
     i.alarm = r.GetBool("alarm");
     i.alarmdate = new DateTime(r.GetLong("alarmdate"));
     i.recur = (AgendaItemRecur)r.GetInt("recur");
     i.recursions = 0;
     return i;
 }
Esempio n. 9
0
        // This reads from a data row
        public static AgendaItem FromDataRow(DataTableRow r)
        {
            AgendaItem i = new AgendaItem();

            i.id              = r.GetLong("id");
            i.color           = (ColorIndex)r.GetInt("color");
            i.description     = r.GetString("description");
            i.startdate       = new DateTime(r.GetLong("startdate"));
            i.originstartdate = i.startdate;
            i.duration        = new TimeSpan(r.GetLong("duration"));
            i.alarm           = r.GetBool("alarm");
            i.alarmdate       = new DateTime(r.GetLong("alarmdate"));
            i.recur           = (AgendaItemRecur)r.GetInt("recur");
            i.recursions      = 0;
            return(i);
        }
Esempio n. 10
0
        // This sets up the panel for a specific day
        public void SetupDay(DateTime day)
        {
            thisday = day;

            string datestr = day.ToLongDateString();

            datelabel.Text = datestr.Replace(",", " ").ToUpper();
            Deselect();

            // Determine begin and end date for this day
            DateTime dstart = new DateTime(day.Year, day.Month, day.Day);
            DateTime dend   = new DateTime(dstart.Year, dstart.Month, dstart.Day);

            dend = dend.AddDays(1);
            dend = dend.AddTicks(-1);

            // Setup items
            List <AgendaItem> items = General.Agenda.GetItems(dstart, dend);

            for (int i = 0; i < NUM_ITEMS; i++)
            {
                // Within range of items or this day?
                if (i < items.Count)
                {
                    AgendaItem ditem   = items[i];
                    DateTime   itemend = ditem.startdate + ditem.duration;
                    itemlabels[i].Text       = ditem.startdate.Hour + ":" + ditem.startdate.Minute.ToString("00") + "      -";
                    itemlabels[i].Visible    = true;
                    itemends[i].Text         = itemend.Hour + ":" + itemend.Minute.ToString("00");
                    itemends[i].Visible      = true;
                    itembuttons[i].Text      = ditem.ToString();
                    itembuttons[i].ColorText = ditem.color;
                    itembuttons[i].SetupColors(General.Colors);
                    itembuttons[i].Tag     = ditem;
                    itembuttons[i].Visible = true;
                }
                else
                {
                    itembuttons[i].Tag     = null;
                    itemlabels[i].Visible  = false;
                    itembuttons[i].Visible = false;
                    itemends[i].Visible    = false;
                }
            }
        }
Esempio n. 11
0
        // Update and animate items at the top
        private void animatetoptimer_Tick(object sender, EventArgs e)
        {
            animatetoptimer.Stop();

            if (agendaupdateneeded)
            {
                UpdateAgenda();
            }

            if (notesupdateneeded)
            {
                UpdateNotes();
            }

            // A negative value means we must clear the list
            if (agendadisplayindex < 0)
            {
                agendaitemindex   = 0;
                lastagendaitemday = 0;
                for (int i = 0; i < NUM_AGENDA_ITEMS; i++)
                {
                    agendaitems[i].Visible = false;
                    agendatimes[i].Visible = false;
                }
            }

            // A negative value means we must clear the list
            if (notesitemindex < 0)
            {
                for (int i = 0; i < NUM_NOTES_ITEMS; i++)
                {
                    notesitems[i].Visible = false;
                }
            }

            // We animate in sequence: We do the agenda items first, then the notes.
            if ((agendadata != null) && (agendadisplayindex < NUM_AGENDA_ITEMS))
            {
                // Show next item?
                if (agendadisplayindex >= 0)
                {
                    if (agendaitemindex < agendadata.Count)
                    {
                        // Setup time
                        AgendaItem itemdata = agendadata[agendaitemindex];
                        if (itemdata.startdate.Day != lastagendaitemday)
                        {
                            // Use an item for the date
                            if (agendadisplayindex < (NUM_AGENDA_ITEMS - 1))
                            {
                                lastagendaitemday = itemdata.startdate.Day;

                                // Time
                                agendatimes[agendadisplayindex].Text      = " ";
                                agendatimes[agendadisplayindex].ColorText = ColorIndex.ControlColor4;
                                agendatimes[agendadisplayindex].SetupColors(General.Colors);
                                agendatimes[agendadisplayindex].Visible = true;

                                // Description
                                if (lastagendaitemday == DateTime.Today.Day)
                                {
                                    agendaitems[agendadisplayindex].Text = "Today";
                                }
                                else
                                {
                                    agendaitems[agendadisplayindex].Text = itemdata.startdate.ToString("dddd, MMMM d");
                                }
                                agendaitems[agendadisplayindex].ColorText = ColorIndex.ControlColor4;
                                agendaitems[agendadisplayindex].SetupColors(General.Colors);
                                agendaitems[agendadisplayindex].Visible = true;
                            }

                            agendadisplayindex++;
                        }

                        if (agendadisplayindex < NUM_AGENDA_ITEMS)
                        {
                            // Time
                            if (itemdata.recur == AgendaItemRecur.Annually)
                            {
                                agendatimes[agendadisplayindex].Text = "-";
                            }
                            else
                            {
                                agendatimes[agendadisplayindex].Text = itemdata.startdate.Hour + ":" + itemdata.startdate.Minute.ToString("00");
                            }
                            agendatimes[agendadisplayindex].ColorText = ColorIndex.ControlColor3;
                            agendatimes[agendadisplayindex].SetupColors(General.Colors);
                            agendatimes[agendadisplayindex].Visible = true;

                            // Description
                            agendaitems[agendadisplayindex].Text      = itemdata.ToString();
                            agendaitems[agendadisplayindex].ColorText = itemdata.color;
                            agendaitems[agendadisplayindex].SetupColors(General.Colors);
                            agendaitems[agendadisplayindex].Visible = true;
                        }
                    }
                    else
                    {
                        // No item
                        agendaitems[agendadisplayindex].Visible = false;
                        agendatimes[agendadisplayindex].Visible = false;
                    }

                    agendaitemindex++;
                }

                agendadisplayindex++;
                animatetoptimer.Interval = 100;
            }
            else if ((notesdata != null) && (notesitemindex < notesdata.Count) && (notesitemindex < NUM_NOTES_ITEMS))
            {
                // Show next item?
                if (notesitemindex >= 0)
                {
                    int toppos;
                    if (notesitemindex == 0)
                    {
                        toppos = noteitem1.Top;
                    }
                    else
                    {
                        toppos = notesitems[notesitemindex - 1].Bottom + noteitemspacing;
                    }

                    if (toppos - noteitemspacing < noteitem10.Bottom)
                    {
                        string text = notesdata[notesitemindex].note;
                        text = text.Replace("\n", "\n    ");
                        notesitems[notesitemindex].AutoSizeHeight = true;
                        notesitems[notesitemindex].Top            = toppos;
                        notesitems[notesitemindex].Text           = "•  " + text;
                        notesitems[notesitemindex].Visible        = true;
                        if (notesitems[notesitemindex].Bottom > noteitem10.Bottom)
                        {
                            notesitems[notesitemindex].AutoSizeHeight = false;
                            notesitems[notesitemindex].Height         = noteitem10.Bottom - notesitems[notesitemindex].Top;

                            // End animation
                            notesitemindex += 999999;
                        }
                    }
                    else
                    {
                        // End animation
                        notesitemindex += 999999;
                    }
                }

                notesitemindex++;
                animatetoptimer.Interval = 100;
            }
            // Animation ended?
            else
            {
                // Set the timer to restart later
                agendadisplayindex       = -5;
                notesitemindex           = -1;
                animatetoptimer.Interval = 10000;
            }

            animatetoptimer.Start();
        }
Esempio n. 12
0
        // This adds a recurring item to the list as many times as needed (and with proper dates)
        private void AddRecurringItem(ICollection<AgendaItem> list, AgendaItem item, DateTime from, DateTime to)
        {
            GregorianCalendar calendar = new GregorianCalendar();
            TimeSpan alarmoffset = item.startdate - item.alarmdate;
            DateTime d = from;

            // Advance d to the first occurence of the item within this time period
            switch(item.recur)
            {
                case AgendaItemRecur.Weekly:
                    if((int)d.DayOfWeek < (int)item.startdate.DayOfWeek)
                        d = d.AddDays((int)item.startdate.DayOfWeek - (int)d.DayOfWeek);
                    else if((int)d.DayOfWeek > (int)item.startdate.DayOfWeek)
                        d = d.AddDays((7 - (int)d.DayOfWeek) + (int)item.startdate.DayOfWeek);

                    break;

                case AgendaItemRecur.Monthly:
                    if(d.Day < item.startdate.Day)
                        d = d.AddDays(item.startdate.Day - d.Day);
                    else if(d.Day > item.startdate.Day)
                        d = d.AddDays((calendar.GetDaysInMonth(d.Year, d.Month) - d.Day) + item.startdate.Day);

                    break;

                case AgendaItemRecur.Annually:
                    // First advance to the correct day in the month
                    // so that we don't skip over the day when advancing by months
                    if(d.Day < item.startdate.Day)
                        d = d.AddDays(item.startdate.Day - d.Day);
                    else if(d.Day > item.startdate.Day)
                        d = d.AddDays((calendar.GetDaysInMonth(d.Year, d.Month) - d.Day) + item.startdate.Day);

                    // Now advance by months
                    if(d.Month < item.startdate.Month)
                        d = d.AddMonths(item.startdate.Month - d.Month);
                    else if(d.Month > item.startdate.Month)
                        d = d.AddMonths((12 - d.Month) + item.startdate.Month);

                    break;
            }

            // We check how many times we can repeat the item within the
            // given timespan and add the item repeatedly
            while(d.Ticks <= to.Ticks)
            {
                // Add item with proper dates
                AgendaItem newitem = item;
                newitem.startdate = d.AddHours(item.startdate.Hour).AddMinutes(item.startdate.Minute);
                newitem.alarmdate = newitem.startdate.Subtract(alarmoffset);
                TimeSpan span = newitem.startdate - newitem.originstartdate;
                switch(item.recur)
                {
                    case AgendaItemRecur.Weekly: newitem.recursions = (int)Math.Round(span.TotalDays / 7.0d); break;
                    case AgendaItemRecur.Monthly: newitem.recursions = (int)Math.Round(span.TotalDays / 30.4375d); break;
                    case AgendaItemRecur.Annually: newitem.recursions = (int)Math.Round(span.TotalDays / 365.25d); break;
                }
                list.Add(newitem);

                // Advance date to the next date when the item recurs
                switch(item.recur)
                {
                    case AgendaItemRecur.Weekly:
                        d = d.AddDays(7);
                        break;

                    case AgendaItemRecur.Monthly:
                        //d = d.AddDays(calendar.GetDaysInMonth(d.Year, d.Month));
                        d = d.AddMonths(1);
                        break;

                    case AgendaItemRecur.Annually:
                        d = d.AddYears(1);
                        break;
                }
            }
        }
Esempio n. 13
0
 // This removes an agenda item
 public bool RemoveItem(AgendaItem i)
 {
     return i.SqlDelete();
 }
Esempio n. 14
0
        // This adds a recurring item to the list as many times as needed (and with proper dates)
        private void AddRecurringItem(ICollection <AgendaItem> list, AgendaItem item, DateTime from, DateTime to)
        {
            GregorianCalendar calendar    = new GregorianCalendar();
            TimeSpan          alarmoffset = item.startdate - item.alarmdate;
            DateTime          d           = from;

            // Advance d to the first occurence of the item within this time period
            switch (item.recur)
            {
            case AgendaItemRecur.Weekly:
                if ((int)d.DayOfWeek < (int)item.startdate.DayOfWeek)
                {
                    d = d.AddDays((int)item.startdate.DayOfWeek - (int)d.DayOfWeek);
                }
                else if ((int)d.DayOfWeek > (int)item.startdate.DayOfWeek)
                {
                    d = d.AddDays((7 - (int)d.DayOfWeek) + (int)item.startdate.DayOfWeek);
                }

                break;

            case AgendaItemRecur.Monthly:
                if (d.Day < item.startdate.Day)
                {
                    d = d.AddDays(item.startdate.Day - d.Day);
                }
                else if (d.Day > item.startdate.Day)
                {
                    d = d.AddDays((calendar.GetDaysInMonth(d.Year, d.Month) - d.Day) + item.startdate.Day);
                }

                break;

            case AgendaItemRecur.Annually:
                // First advance to the correct day in the month
                // so that we don't skip over the day when advancing by months
                if (d.Day < item.startdate.Day)
                {
                    d = d.AddDays(item.startdate.Day - d.Day);
                }
                else if (d.Day > item.startdate.Day)
                {
                    d = d.AddDays((calendar.GetDaysInMonth(d.Year, d.Month) - d.Day) + item.startdate.Day);
                }

                // Now advance by months
                if (d.Month < item.startdate.Month)
                {
                    d = d.AddMonths(item.startdate.Month - d.Month);
                }
                else if (d.Month > item.startdate.Month)
                {
                    d = d.AddMonths((12 - d.Month) + item.startdate.Month);
                }

                break;
            }

            // We check how many times we can repeat the item within the
            // given timespan and add the item repeatedly
            while (d.Ticks <= to.Ticks)
            {
                // Add item with proper dates
                AgendaItem newitem = item;
                newitem.startdate = d.AddHours(item.startdate.Hour).AddMinutes(item.startdate.Minute);
                newitem.alarmdate = newitem.startdate.Subtract(alarmoffset);
                TimeSpan span = newitem.startdate - newitem.originstartdate;
                switch (item.recur)
                {
                case AgendaItemRecur.Weekly: newitem.recursions = (int)Math.Round(span.TotalDays / 7.0d); break;

                case AgendaItemRecur.Monthly: newitem.recursions = (int)Math.Round(span.TotalDays / 30.4375d); break;

                case AgendaItemRecur.Annually: newitem.recursions = (int)Math.Round(span.TotalDays / 365.25d); break;
                }
                list.Add(newitem);

                // Advance date to the next date when the item recurs
                switch (item.recur)
                {
                case AgendaItemRecur.Weekly:
                    d = d.AddDays(7);
                    break;

                case AgendaItemRecur.Monthly:
                    //d = d.AddDays(calendar.GetDaysInMonth(d.Year, d.Month));
                    d = d.AddMonths(1);
                    break;

                case AgendaItemRecur.Annually:
                    d = d.AddYears(1);
                    break;
                }
            }
        }
        // This fills the dialog with info about an item
        public void SetupItem(AgendaItem item)
        {
            Clear();

            result = item;

            // Assigned
            if(item.color == ColorIndex.ControlColorPascal)
            {
                assigned = 1;
                pascalbutton.StartInfoFlash();
            }
            else if(item.color == ColorIndex.ControlColorMarlies)
            {
                assigned = 2;
                marliesbutton.StartInfoFlash();
            }
            else if(item.color == ColorIndex.ControlColorAffirmative)
            {
                assigned = 3;
                birthdaybutton.StartInfoFlash();
            }

            // Description
            description.Text = item.description;

            // Start
            startday.Text = item.originstartdate.Day.ToString();
            startmonth.Text = item.originstartdate.Month.ToString();
            startyear.Text = item.originstartdate.Year.ToString();
            starthour.Text = item.originstartdate.Hour.ToString();
            startminute.Text = item.originstartdate.Minute.ToString("00");

            // Duration
            int days = (int)Math.Floor(item.duration.TotalDays);
            durdays.Text = days.ToString();
            durhours.Text = item.duration.Hours.ToString();
            durminutes.Text = item.duration.Minutes.ToString("00");

            // End
            CalculateEndDateFromDuration();

            // Alarm
            TimeSpan alarmdur = item.startdate - item.alarmdate;
            alarmdur = alarmdur.Duration();
            int alarmmin = (int)alarmdur.TotalMinutes;
            alarmminutes.Text = alarmmin.ToString();
            if(item.alarm) alarmbutton.StartInfoFlash();

            // Recurring
            recurbutton.Text = item.recur.ToString();
        }
Esempio n. 16
0
        // This returns all agenda items in the given range
        // Returns null on database error
        public List <AgendaItem> GetItems(DateTime from, DateTime to)
        {
            TimeSpan span = to - from;

            General.DB.ConnectSafe();

            // Make the WHERE clause for weekly recurring items
            string ww = "(`recur` = '" + (int)AgendaItemRecur.Weekly + "')";

            if (span.Days < 7)
            {
                // Add limitations for the days of the weeks between 'from' and 'to'
                if (to.DayOfWeek >= from.DayOfWeek)
                {
                    // Range within a single week
                    ww += " AND (`dayofweek` >= '" + from.DayOfWeek + "' AND `dayofweek` <= '" + to.DayOfWeek + "')";
                }
                else
                {
                    // Range crossing into the next week
                    ww += " AND (`dayofweek` >= '" + to.DayOfWeek + "' OR `dayofweek` <= '" + from.DayOfWeek + "')";
                }
            }

            // Make the WHERE clause for monthly recurring items
            string wm = "(`recur` = '" + (int)AgendaItemRecur.Monthly + "')";

            if (span.Days < 31)
            {
                // Add limitations for the days of the month between 'from' and 'to'
                if (to.Day >= from.Day)
                {
                    // Range within a single month
                    wm += " AND (`dayofmonth` >= '" + from.Day + "' AND `dayofmonth` <= '" + to.Day + "')";
                }
                else
                {
                    // Range crossing into the next month
                    wm += " AND (`dayofmonth` >= '" + to.Day + "' OR `dayofmonth` <= '" + from.Day + "')";
                }
            }

            // Make the WHERE clause for annually recurring items
            string wa = "(`recur` = '" + (int)AgendaItemRecur.Annually + "')";

            if (span.Days < 366)
            {
                // Add limitations for the months of the year between 'from' and 'to'
                if (to.Month >= from.Month)
                {
                    // Range within a single year
                    wa += " AND (`month` >= '" + from.Month + "' AND `month` <= '" + to.Month + "')";
                }
                else
                {
                    // Range crossing into the next year
                    wa += " AND (`month` >= '" + to.Month + "' OR `month` <= '" + from.Month + "')";
                }

                // Shorter than a month? Add limitations for the day of the month.
                if (span.Days < 31)
                {
                    // Add limitations for the days of the month between 'from' and 'to'
                    if (to.Day >= from.Day)
                    {
                        // Range within a single month
                        wa += " AND (`dayofmonth` >= '" + from.Day + "' AND `dayofmonth` <= '" + to.Day + "')";
                    }
                    else
                    {
                        // Range crossing into the next month
                        wa += " AND (`dayofmonth` >= '" + to.Day + "' OR `dayofmonth` <= '" + from.Day + "')";
                    }
                }
            }


            string q = "SELECT * FROM `agenda` WHERE " +
                       "((`startdate` + `duration`) >= '" + from.Ticks + "') AND " +
                       "(`startdate` <= '" + to.Ticks + "') AND ((`recur` = '0') OR (" + ww + ") OR (" + wm + ") OR (" + wa + "));";

            DataTable t = General.DB.Query(q);

            if (t != null)
            {
                List <AgendaItem> list = new List <AgendaItem>(t.Count);

                // Make the full list (expand recurring items)
                foreach (DataTableRow r in t)
                {
                    AgendaItem item = AgendaItem.FromDataRow(r);
                    if (item.recur != AgendaItemRecur.None)
                    {
                        AddRecurringItem(list, item, from, to);
                    }
                    else
                    {
                        list.Add(item);
                    }
                }

                // Sort by startdate
                AgendaItemSorter sorter = new AgendaItemSorter();
                list.Sort(sorter);

                General.DB.Disconnect();
                return(list);
            }
            else
            {
                // Failed!
                General.DB.Disconnect();
                return(null);
            }
        }
Esempio n. 17
0
 // This removes an agenda item
 public bool RemoveItem(AgendaItem i)
 {
     return(i.SqlDelete());
 }