コード例 #1
0
 internal static bool AddTrigger(DeviceTrigger trigger)
 {
     lock (DBAdmin.padlock)
     {
         int updatedRows = 0;
         using (SQLiteConnection dbConnection = DBAdmin.GetSQLConnection())
         {
             dbConnection.Open();
             using (SQLiteCommand cmd = new SQLiteCommand(dbConnection))
             {
                 SQLiteTransaction trans = dbConnection.BeginTransaction();
                 cmd.CommandText = "INSERT INTO [TRIGGERS] ([DeviceName], [Category], " +
                                   "[Label], [TimeTrigger], [TriggerText], [Recurrence], [TriggerAudioFile], " +
                                   "[TriggerAudioFileExists], [Tooltip]) " +
                                   "VALUES(@deviceName, @category, @label,  @timeTrigger, " +
                                   "@triggerText, @recurrence, @triggerAudioFile, @triggerAudioFileExists, @tooltip);";
                 cmd.Parameters.Add(new SQLiteParameter("@deviceName", DbType.String)
                 {
                     Value = trigger.DeviceName
                 });
                 cmd.Parameters.Add(new SQLiteParameter("@category", DbType.String)
                 {
                     Value = trigger.Category
                 });
                 cmd.Parameters.Add(new SQLiteParameter("@label", DbType.String)
                 {
                     Value = trigger.Label
                 });
                 cmd.Parameters.Add(new SQLiteParameter("@timeTrigger", DbType.Int32)
                 {
                     Value = trigger.TimeTrigger ? 1 : 0
                 });
                 cmd.Parameters.Add(new SQLiteParameter("@triggerText", DbType.String)
                 {
                     Value = trigger.TriggerText
                 });
                 cmd.Parameters.Add(new SQLiteParameter("@recurrence", DbType.String)
                 {
                     Value = trigger.Recurrence
                 });
                 cmd.Parameters.Add(new SQLiteParameter("@triggerAudioFile", DbType.String)
                 {
                     Value = trigger.TriggerAudioFile
                 });
                 cmd.Parameters.Add(new SQLiteParameter("@triggerAudioFileExists", DbType.Int32)
                 {
                     Value = trigger.TriggerAudioFileExists ? 1 : 0
                 });
                 cmd.Parameters.Add(new SQLiteParameter("@tooltip", DbType.String)
                 {
                     Value = trigger.Tooltip
                 });
                 updatedRows = cmd.ExecuteNonQuery();
                 trans.Commit();
             }
         }
         return(updatedRows == 1);
     }
 }
コード例 #2
0
 public static bool AddTrigger(DeviceTrigger newTrigger, out string outcome, bool updateDB = true)
 {
     if (Triggers.FirstOrDefault(x => x.Label.Equals(newTrigger.Label)) == null)
     {
         newTrigger.TriggerAudioFileExists = File.Exists(Path.Combine(DirectoryMgr.AudioClipsDirectory, newTrigger.TriggerAudioFile + ".mp3"));
         Triggers.Add(newTrigger);
         if (updateDB)
         {
             if (TriggersTableMgr.AddTrigger(newTrigger))
             {
                 outcome = "DeviceTrigger added";
                 return(true);
             }
             else
             {
                 outcome = "Error adding DeviceTrigger to database";
                 Logger.AddLogEntry(LogCategory.ERROR, "Error adding DeviceTrigger to database: " + newTrigger.Label);
                 return(false);
             }
         }
     }
     outcome = "DeviceTrigger name \'" + newTrigger.Label + "\' already exits.\nPlease choose another name.";
     return(false);
 }