Example #1
0
        /** ArrayList contains Alert objects */
        private ArrayList getAlerts( String query )
        {
            ArrayList alerts = new ArrayList();

            SQLiteCommand cmd = conn.CreateCommand();
            cmd.CommandText = query;
            SQLiteDataReader results = cmd.ExecuteReader();
            while (results.Read())
            {
                int alertId = results.GetInt32(0);
                string title = results.GetString(1);
                string message = results.GetString(2);
                string year = results.GetString(3);
                string dayOfMonth = results.GetString(4);
                string month = results.GetString(5);
                string dayOfWeek = results.GetString(6);
                string hour = results.GetString(7);
                string minute = results.GetString(8);
                bool snoozed = results.GetBoolean(9);
                bool valid = results.GetBoolean(10);
                DateTime wakeUpTime = results.GetDateTime(11);
                string background = results.GetString(12);
                string sound = results.GetString(13);
                string command = results.GetString(14);

                //Do not change the order of the following block,
                //otherwise snoozed and valid values may be set
                //incorrectly.
                Alert alert = new Alert();
                alert.setAlertId(alertId);
                alert.setTitle(title);
                alert.setMessage(message);
                alert.setSchedule(year, month, dayOfMonth, dayOfWeek, hour, minute, false);
                alert.setWakeUpTime(wakeUpTime);
                alert.setSnoozed(snoozed);
                alert.setValid(valid);
                alert.setBackground(background);
                alert.setSound(sound);
                alert.setCommand(command);

                alerts.Add(alert);
            }
            cmd.Dispose();

            return alerts;
        }
Example #2
0
        private bool save()
        {
            bool returnValue = false;
            Alert alert = new Alert();
            int alertId = currentAlert.getAlertId();
            alert.setAlertId(alertId);
            alert.setTitle(titleField.Text);
            alert.setMessage(messageBox.RichTextBox.Rtf);
            alert.setValid(currentAlert.getValid());
            alert.setCommand(currentAlert.getCommand());
            if (!soundField.Text.Equals(alert.getSound()))
            {
                alert.setSound(soundField.Text);
            }
            if (backgroundChanged)
            {
                alert.setBackground(""+messageBox.RichTextBox.BackColor.ToArgb());
            }

            //Determine the schedule
            if (oneTimeRadio.Checked)
            {
                DateTime dt = oneTimeField1.Value;
                string[] time = extractTime(oneTimeField2.Text, oneTimeField3.Text);
                dt = new DateTime(dt.Year, dt.Month, dt.Day, System.Convert.ToInt32(time[0]),
                    System.Convert.ToInt32(time[1]), 0);
                returnValue = alert.setSchedule(dt);
            }
            else if (timeDelayRadio.Checked)
            {
                DateTime dt = DateTime.Now;
                double howMuch = 0;
                try
                {
                    howMuch = double.Parse(timeDelayField1.Text);
                }
                catch (Exception)
                {
                    throw new Exception("Time Delay Field must be a number!");
                }
                string howMany = timeDelayField2.Text;

                if (howMany.Equals("Minute(s)"))
                {
                    dt = dt.AddMinutes(howMuch);
                }
                else if (howMany.Equals("Hour(s)"))
                {
                    dt = dt.AddHours(howMuch);
                }
                else if (howMany.Equals("Day(s)"))
                {
                    dt = dt.AddDays(howMuch);
                    //Zero out the hours and minutes
                    dt = new DateTime(dt.Year, dt.Month, dt.Day, 0, 0, 0);
                }
                else if (howMany.Equals("Week(s)"))
                {
                    dt = dt.AddDays(howMuch*7);
                    //Zero out the hours and minutes
                    dt = new DateTime(dt.Year, dt.Month, dt.Day, 0, 0, 0);
                }
                returnValue = alert.setSchedule(dt);
            }
            else if (dayOfMonthRadio.Checked)
            {
                string dayOfMonth = "" + (dayOfMonthField1.SelectedIndex + 1);
                string[] time = extractTime(dayOfMonthField2.Text, dayOfMonthField3.Text);
                string month = "" + (dayOfMonthField4.SelectedIndex);
                if (month.Equals("0")) month = "*";
                if (System.Convert.ToInt32(dayOfMonth) > 28)
                    MsgBox.Show("Warning!  No alert will be shown for months without the specified day!",
                        "Warning", MessageBoxButtons.OK, MessageBoxIcon.Information);
                returnValue = alert.setSchedule("*", month, dayOfMonth, "*", time[0], time[1]);
            }
            else if (dayOfWeekRadio.Checked)
            {
                string dayOfWeek = "" + dayOfWeekField1.SelectedIndex;
                if (dayOfWeek.Equals("0"))
                    dayOfWeek = "*";
                else if (dayOfWeek.Equals("7"))
                    dayOfWeek = "0";
                string[] time = extractTime(dayOfWeekField2.Text, dayOfWeekField3.Text);
                returnValue = alert.setSchedule("*", "*", "*", dayOfWeek, time[0], time[1]);
            }
            else if (advancedRadio.Checked)
            {
                returnValue = alert.setSchedule(advancedField1.Text);
            }
            else if (positionalDayOfWeekRadio.Checked)
            {
                int position = positionalDayOfWeekField1.SelectedIndex + 1;
                int dayOfWeek = ((positionalDayOfWeekField2.SelectedIndex+1) % 7);
                string month = "" + (positionalDayOfWeekField6.SelectedIndex);
                if (month.Equals("0")) month = "*";
                string positionalDayOfWeek = ""+((position * 10) + dayOfWeek);
                string[] time = extractTime(positionalDayOfWeekField3.Text, positionalDayOfWeekField4.Text);
                returnValue = alert.setSchedule("*", month, "*", positionalDayOfWeek, time[0], time[1]);
            }
            else
            {
                throw new Exception("Nothing Selected");
            }

            if (!returnValue)
                return false;

            alert.setValid(true);

            currentAlert = alert;

            return true;
        }
Example #3
0
        /** ArrayList contains Alert objects */
        public Alert getUpdatedAlert( Alert alert )
        {
            SQLiteCommand cmd = conn.CreateCommand();
            cmd.CommandText = "SELECT AlertId, Title, Message, Year, DayOfMonth, Month, " +
                "DayOfWeek, Hour, Minute, Snoozed, Valid, WakeUpTime Background, " +
                "Sound, Command FROM Alerts WHERE AlertID = ?";
            cmd.Parameters.Add(cmd.CreateParameter());
            cmd.Parameters[0].Value = alert.getAlertId();
            SQLiteDataReader results = cmd.ExecuteReader();
            if (results.Read())
            {
                int alertId = results.GetInt32(0);
                string title = results.GetString(1);
                string message = results.GetString(2);
                string year = results.GetString(3);
                string dayOfMonth = results.GetString(4);
                string month = results.GetString(5);
                string dayOfWeek = results.GetString(6);
                string hour = results.GetString(7);
                string minute = results.GetString(8);
                bool snoozed = results.GetBoolean(9);
                bool valid = results.GetBoolean(10);
                DateTime wakeUpTime = results.GetDateTime(11);
                string background = results.GetString(12);
                string sound = results.GetString(13);
                string command = results.GetString(14);

                //Do not change the order of the following block,
                //otherwise snoozed and valid values may be set
                //incorrectly.
                alert.setAlertId(alertId);
                alert.setTitle(title);
                alert.setMessage(message);
                alert.setSchedule(year, month, dayOfMonth, dayOfWeek, hour, minute, false);
                alert.setWakeUpTime(wakeUpTime);
                alert.setSnoozed(snoozed);
                alert.setValid(valid);
                alert.setBackground(background);
                alert.setSound(sound);
                alert.setCommand(command);
            }
            cmd.Dispose();

            return alert;
        }