Example #1
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 #2
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();
        }