Example #1
0
        public void alertDialog(Alert alert)
        {
            while (true)
            {
                //Make sure it's time to show the dialog
                DateTime wakeup = alert.getWakeUpTime();
                DateTime now = DateTime.Now;
                if( !alert.getValid() && !alert.getSnoozed() )
                {
                    if (alertsListView.IsHandleCreated == true)
                    {
                        alertsListView.Invoke(new UpdateListBoxCallback(UpdateManagerAlert), new object[] { alert });
                    }
                    return;
                }
                else if (wakeup > now)
                {
                    double msDifference = wakeup.Subtract(now).TotalMilliseconds;
                    while (msDifference >= int.MaxValue)
                    {
                        Thread.Sleep(int.MaxValue);
                        msDifference = wakeup.Subtract(now).TotalMilliseconds;
                    }
                    Thread.Sleep((int)msDifference);
                }

                //Take care of color, positioning, command execution, and sound
                AlertDialog alertDialog = new AlertDialog(alert, getBackground(alert), getSound(alert));
                string positionType = controller.getSetting("WindowsPositioning");
                if (positionType.Equals("center"))
                {
                    alertDialog.center();
                }
                else if (positionType.Equals("custom"))
                {
                    Dictionary<string, int> settings = controller.getAlertSettings();
                    alertDialog.Location = new Point(settings["xpos"], settings["ypos"]);
                    alertDialog.Size = new Size(settings["width"], settings["height"]);
                }

                //Show Dialog
                if (alertDialog.ShowDialog() == DialogResult.OK)
                {
                    positionType = controller.getSetting("WindowsPositioning");
                    if (positionType.Equals("custom"))
                    {
                        controller.updateAlertSettings(alertDialog.Location.X, alertDialog.Location.Y,
                            alertDialog.Size.Width, alertDialog.Size.Height);
                    }
                    alert = alertDialog.getCurrentAlert();
                    if (alertsListView.IsHandleCreated == true)
                    {
                        alertsListView.Invoke(new UpdateListBoxCallback(UpdateManagerAlert), new object[] { alert });
                    }
                    if (alert.getRemoved())
                    {
                        controller.deleteAlert(alert);
                        return;
                    }
                    else if (!alert.getValid() && !alert.getSnoozed())
                    {
                        controller.updateAlert(alert);
                        return;
                    }
                    else
                    {
                        controller.updateAlert(alert);
                        continue;
                    }
                }
            }
        }
Example #2
0
 //Adds the alert list view item
 private void addAlertListViewItem(Alert alert)
 {
     ListViewItem lvi = new ListViewItem(new string[4] { "", "" + alert.getAlertId(),
         alert.getTitle(), "" + alert.getWakeUpTime() });
     if (alert.getValid()) lvi.Checked = true;
     alertsListView.Items.Add(lvi);
 }
Example #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;
        }
Example #4
0
        //Called from the worker threads, don't need to worry about thread's updating
        //because the thread has taken care of itself by the time this is called.
        //This is the thread telling the main app to update itself.
        public void UpdateManagerAlert(Alert alert)
        {
            string alertId = ""+alert.getAlertId();

            //Reset Alert in hashtable
            try
            {
                htAlerts.Remove(alertId);
                if (!alert.getRemoved())
                {
                    htAlerts.Add(alertId, alert);
                }
            }
            catch (Exception)
            {
                //ignore
            }

            //Updated List View Record
            foreach( ListViewItem lvi in alertsListView.Items )
            {
                if( lvi.SubItems[1].Text.Equals( alertId ) )
                {
                    if (!alert.getRemoved())
                    {
                        if (alert.getValid()) lvi.Checked = true;
                        else lvi.Checked = false;
                        lvi.SubItems[1].Text = "" + alert.getAlertId();
                        lvi.SubItems[2].Text = alert.getTitle();
                        lvi.SubItems[3].Text = "" + alert.getWakeUpTime();
                        sortAlertListView();
                    }
                    else
                    {
                        alertsListView.Items[lvi.Index].Remove();
                    }
                    return;
                }
            }
        }
Example #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();
        }