Start a new topic

Change the "Favourite" status of selected tracks

It only works with MySQL databases. 


The script change the "Favourite" status of selected tracks (if already favourite, will mark as not favourite)


**********************************************

using NeonScripting;

using System.Linq;

namespace Neon

{

 public class Script

 {

  public bool Run(INeonScriptHost host)

  {

   

   var cadsql = "";

   var idx = host.Tracks.Count();

   

   if (idx == 0)

    {

    host.RemoteCalls.ShowMessage("You have not selected any item.");

     return false;

    }

   else

    {

    ///warns if you have selected more than 5 items

                if (idx >= 6)

     if (!host.RemoteCalls.ConfirmationDialog("You want to mark/unmark "+idx+" items?"))

       return false;

     

     idx = 1;

     foreach(var track in host.Tracks)

     {

      host.UpdateProgress(string.Format("Track/s: {0}", idx));

     

      if (track.IsFavourite)

       cadsql="UPDATE musica.tblrating SET isfavourite = 0 WHERE Detail_ID= ";

      else

       cadsql="UPDATE musica.tblrating SET isfavourite = 1 WHERE Detail_ID= ";

     

      host.RemoteCalls.ExecSql(cadsql+track.DetailId);

      idx++;

     }

     host.RemoteCalls.CommitAllChanges(host.Tracks);

    }

   

   return true;

  }

 }

}

json
(327 Bytes)
cs
(1.04 KB)

Clarification: in the SQL string must be changed "music" by the name of your database:


cadsql="UPDATE your_database.tblrating SET isfavourite = 0 WHERE Detail_ID= "

Doesn't "UPDATE tblrating SET isfavourite = 0 WHERE Detail_ID=" work?


Selecting a database shouldn't be necessary, should it?


1 person likes this

It's true, you're right. Upload the modified script

json
(217 Bytes)
cs
(1.05 KB)
Login or Signup to post a comment