Exemple #1
0
        public void init( Alert alert, string defaultColor )
        {
            if (!Registration.isValid())
            {
                label7.Visible = false;
                soundField.Visible = false;
                browseButton.Visible = false;
                messageBox.ShowStamp = false;
            }

            backgroundChanged = false;

            currentAlert = alert;
            soundField.Text = alert.getSound();
            try
            {
                string background = alert.getBackground();
                if (background.ToUpper().Equals("DEFAULT"))
                {
                    background = defaultColor;
                }
                else
                {
                    backgroundChanged = true;
                }
                messageBox.RichTextBox.BackColor = Color.FromArgb(System.Convert.ToInt32(background));
            }
            catch
            {
                messageBox.RichTextBox.BackColor = Color.FromName("Window");
            }

            titleField.Text = alert.getTitle();
            messageBox.RichTextBox.Rtf = alert.getMessage();

            advancedField1.Text = alert.getSchedule();
            oneTimeField3.SelectedIndex = 0;
            timeDelayField2.SelectedIndex = 0;
            dayOfMonthField1.SelectedIndex = 0;
            dayOfMonthField3.SelectedIndex = 0;
            dayOfMonthField4.SelectedIndex = 0;
            dayOfWeekField1.SelectedIndex = 0;
            dayOfWeekField3.SelectedIndex = 0;
            positionalDayOfWeekField1.SelectedIndex = 0;
            positionalDayOfWeekField2.SelectedIndex = 0;
            positionalDayOfWeekField4.SelectedIndex = 0;
            positionalDayOfWeekField6.SelectedIndex = 0;
            this.setRadioButton();

            if (alert.getSnoozed())
            {
                MsgBox.Show("If you save, this alert will no longer be on snooze.",
                    "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Exemple #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;
        }
Exemple #3
0
        public Alert createNewAlert( Alert alert )
        {
            SQLiteCommand cmd;

            //Create a new Entry
            cmd = conn.CreateCommand();
            cmd.CommandText = "INSERT INTO Alerts (Title, Message, Year, DayOfMonth, Month, DayOfWeek, Hour, " +
                "Minute, Snoozed, Valid, WakeUpTime, Background, Sound, Command) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
            cmd.Parameters.Add(cmd.CreateParameter()); cmd.Parameters.Add(cmd.CreateParameter()); cmd.Parameters.Add(cmd.CreateParameter());
            cmd.Parameters.Add(cmd.CreateParameter()); cmd.Parameters.Add(cmd.CreateParameter()); cmd.Parameters.Add(cmd.CreateParameter());
            cmd.Parameters.Add(cmd.CreateParameter()); cmd.Parameters.Add(cmd.CreateParameter()); cmd.Parameters.Add(cmd.CreateParameter());
            cmd.Parameters.Add(cmd.CreateParameter()); cmd.Parameters.Add(cmd.CreateParameter()); cmd.Parameters.Add(cmd.CreateParameter());
            cmd.Parameters.Add(cmd.CreateParameter()); cmd.Parameters.Add(cmd.CreateParameter());
            cmd.Parameters[0].Value = alert.getTitle();
            cmd.Parameters[1].Value = alert.getMessage();
            cmd.Parameters[2].Value = alert.getYear();
            cmd.Parameters[3].Value = alert.getDayOfMonth();
            cmd.Parameters[4].Value = alert.getMonth();
            cmd.Parameters[5].Value = alert.getDayOfWeek();
            cmd.Parameters[6].Value = alert.getHour();
            cmd.Parameters[7].Value = alert.getMinute();
            cmd.Parameters[8].Value = alert.getSnoozed();
            cmd.Parameters[9].Value = alert.getValid();
            cmd.Parameters[10].Value = alert.getWakeUpTime();
            cmd.Parameters[11].Value = alert.getBackground();
            cmd.Parameters[12].Value = alert.getSound();
            cmd.Parameters[13].Value = alert.getCommand();
            cmd.ExecuteNonQuery();
            cmd.Dispose();

            //Get the newly created AlertId.  Rely on sqlite, hope for no multiple access of the table.
            cmd = conn.CreateCommand();
            cmd.CommandText = "SELECT last_insert_rowid()";
            int newAlertId = Convert.ToInt32(cmd.ExecuteScalar());
            cmd.Dispose();
            alert.setAlertId(newAlertId);

            return alert;
        }
Exemple #4
0
 private String getSound(Alert alert)
 {
     string soundFile = alert.getSound();
     if (soundFile.ToUpper().Equals("USE DEFAULT"))
     {
         soundFile = controller.getSetting("AlertSound");
     }
     return soundFile;
 }
Exemple #5
0
        public void updateAlert( Alert alert )
        {
            if (alert.getAlertId() < 0)
            {
                throw new Exception("Invalid Alert Id");
            }

            SQLiteCommand cmd = conn.CreateCommand();
            cmd.CommandText = "UPDATE Alerts SET Title = ?, Message = ?, Year = ?, DayOfMonth = ?, Month = ?, " +
                "DayOfWeek = ?, Hour = ?, Minute = ?, Snoozed = ?, Valid = ?, WakeUpTime = ?, Background = ?, " +
                "Sound = ?, Command = ? WHERE AlertId = ?";
            cmd.Parameters.Add(cmd.CreateParameter()); cmd.Parameters.Add(cmd.CreateParameter()); cmd.Parameters.Add(cmd.CreateParameter());
            cmd.Parameters.Add(cmd.CreateParameter()); cmd.Parameters.Add(cmd.CreateParameter()); cmd.Parameters.Add(cmd.CreateParameter());
            cmd.Parameters.Add(cmd.CreateParameter()); cmd.Parameters.Add(cmd.CreateParameter()); cmd.Parameters.Add(cmd.CreateParameter());
            cmd.Parameters.Add(cmd.CreateParameter()); cmd.Parameters.Add(cmd.CreateParameter()); cmd.Parameters.Add(cmd.CreateParameter());
            cmd.Parameters.Add(cmd.CreateParameter()); cmd.Parameters.Add(cmd.CreateParameter()); cmd.Parameters.Add(cmd.CreateParameter());
            cmd.Parameters[0].Value = alert.getTitle();
            cmd.Parameters[1].Value = alert.getMessage();
            cmd.Parameters[2].Value = alert.getYear();
            cmd.Parameters[3].Value = alert.getDayOfMonth();
            cmd.Parameters[4].Value = alert.getMonth();
            cmd.Parameters[5].Value = alert.getDayOfWeek();
            cmd.Parameters[6].Value = alert.getHour();
            cmd.Parameters[7].Value = alert.getMinute();
            cmd.Parameters[8].Value = alert.getSnoozed();
            cmd.Parameters[9].Value = alert.getValid();
            cmd.Parameters[10].Value = alert.getWakeUpTime();
            cmd.Parameters[11].Value = alert.getBackground();
            cmd.Parameters[12].Value = alert.getSound();
            cmd.Parameters[13].Value = alert.getCommand();
            cmd.Parameters[14].Value = alert.getAlertId();
            cmd.ExecuteNonQuery();
            cmd.Dispose();
        }