by Risser » Tue Mar 20, 2007 9:43 am
Code: Select all
' Version 20070320
Option Explicit
Dim res
Public hold
Set hold = CreateObject("Scripting.Dictionary")
Const mmAnchorRight = 4
Const mmAnchorBottom = 8
Const mmAlignTop = 1
Const mmAlignBottom = 2
Const mmAlignClient = 5
Const mmListDropdown = 2
Const mmFormScreenCenter = 4
Dim trackList
Function fixit(s)
fixit = Replace(s, "'", "''")
End Function
Function match_clause(original)
match_clause = " artists.artist = '"&fixit(original.artistName)&"' AND " & _
" songs.IdArtist = artists.id AND songs.songtitle = '"&fixit(original.title)&"'" & _
" AND NOT (songs.id = "&original.id&")"
End Function
Sub CloseDown
Set hold = nothing
SDB.Objects("StatusThingy") = Nothing
SDB.Objects("original") = Nothing
End Sub
Sub OnCancel(Btn)
CloseDown
End Sub
Sub OnOK(Btn)
Set hold = SDB.Objects("hold")
Dim original : Set original = SDB.Objects("original")
Dim itm
For Each itm In hold
itm.artistName = original.artistName
itm.title = original.title
itm.albumName = original.albumName
itm.albumArtistName = original.albumArtistName
itm.year = original.year
itm.trackOrder = original.trackOrder
itm.genre = original.genre
itm.rating = original.rating
itm.involvedPeople = original.involvedPeople
itm.originalArtist = original.originalArtist
itm.originalTitle = original.originalTitle
itm.originalYear = original.originalYear
itm.lyricist = original.lyricist
itm.originalLyricist = original.originalLyricist
itm.bpm = original.bpm
itm.isrc = original.isrc
itm.publisher = original.publisher
itm.copyright = original.copyright
itm.encoder = original.encoder
itm.author = original.author
itm.comment = original.comment
itm.lyrics = original.lyrics
itm.custom1 = original.custom1
itm.custom2 = original.custom2
itm.custom3 = original.custom3
itm.tempo = original.tempo
itm.occasion = original.occasion
itm.mood = original.mood
itm.quality = original.quality
If itm.ID>-1 Then
itm.UpdateDB
End If
itm.WriteTags
Next 'itm
CloseDown
End Sub
Function MapXML(original)
Dim out
out = Replace(original, "&", "&")
out = Replace(out, " ", " ")
out = Replace(out, "<", "<")
out = Replace(out, ">", ">")
Dim i
i=1
While i<=Len(out)
If (AscW(Mid(out, i, 1))>127) Then
out = Mid(out, 1, i-1)+"&#"+CStr(AscW(Mid(out, i, 1)))+";"+Mid(out, i+1)
End If
i=i+1
WEnd
MapXML = out
End Function
Function tooBig(s)
If (Len(s) > 50) Then
tooBig = Left(s,47) & "..."
Else
tooBig = s
End If
End Function
Function outField (fixed, normal)
If fixed = normal Then
outField = "<td>" & MapXML(tooBig(normal)) & "</td>" & vbcrlf
Else
outField = "<td class=""highlight"">" & MapXML(tooBig(normal)) & "</td>" & vbcrlf
End If
'res = SDB.MessageBox(fixed&"->"&normal&"="&outField, mtError, Array(mbOk))
End Function
Sub CopyToOthers
Dim UI, Form, Foot, Btn, Btn2, WB, doc
Dim writeChanges
Set trackList = SDB.SelectedSongList
If trackList.count=0 Then
Set trackList = SDB.AllVisibleSongList
End If
Set trackList = SDB.SelectedSongList
If trackList.count = 0 Then
res = SDB.MessageBox("Select a track.", mtError, Array(mbOk))
Exit Sub
End If
If trackList.count > 1 Then
res = SDB.MessageBox("Select only a single track.", mtError, Array(mbOk))
Exit Sub
End If
dim original : Set original = trackList.Item(0)
dim SELECT_Clause, FROM_Clause, WHERE_Clause, SQL, Iter
SELECT_Clause = " SELECT Songs.Id "
FROM_Clause = " FROM Songs, Artists "
WHERE_Clause = " WHERE " & match_clause(original)
' WHERE_Clause = " WHERE artists.artist = '"&fixit(original.artistName)&"' AND " & _
' " songs.IdArtist = artists.id AND songs.songtitle = '"&fixit(original.title)&"'" & _
' " AND NOT (songs.id = "&original.id&")"
SQL = SELECT_Clause & FROM_Clause & WHERE_Clause
Set Iter = SDB.Database.OpenSQL(SQL)
If Iter.EOF Then
res = SDB.MessageBox("No other matches were found for this song.", mtError, Array(mbOk))
Exit Sub
End If
Set UI = SDB.UI
' Create the window to be shown
Set Form = UI.NewForm
Form.Common.SetRect 50, 50, 500, 400
Form.Common.MinWidth = 200
Form.Common.MinHeight = 150
Form.FormPosition = mmFormScreenCenter
Form.SavePositionName = "CaseWindow"
Form.Caption = SDB.Localize("Copy To Others")
Form.StayOnTop = True
' Create a panel at the bottom of the window
Set Foot = UI.NewPanel(Form)
Foot.Common.Align = mmAlignBottom
Foot.Common.Height = 35
' Create a button that closes the window
Set Btn = UI.NewButton(Foot)
Btn.Caption = SDB.Localize("&Cancel")
Btn.Common.SetRect (Foot.Common.Width - 180)/2+95, 9, 85, 24
Btn.Common.Anchors = mmAnchorRight + mmAnchorBottom
Btn.UseScript = Script.ScriptPath
Btn.OnClickFunc = "OnCancel"
' Create a button that saves the report
Set Btn2 = UI.NewButton(Foot)
Btn2.Caption = SDB.Localize("&OK")
Btn2.Common.SetRect (Foot.Common.Width - 180)/2, 9, 85, 24
Btn2.Common.Anchors = mmAnchorRight + mmAnchorBottom
Btn2.UseScript = Script.ScriptPath
Btn2.OnClickFunc = "OnOK"
Set WB = UI.NewActiveX(Form, "Shell.Explorer")
WB.Common.Align = mmAlignClient ' Fill all client rectangle
WB.Common.ControlName = "WB"
Set doc = WB.Interf.Document
Form.Common.Visible = True ' Only show the form, don't wait for user input
SDB.Objects("StatusThingy") = Form ' Save reference to the form somewhere, otherwise it would simply disappear
doc.write BuildReport
doc.close
SDB.Objects("original") = original
End Sub
Function showRow(original, itm)
dim strOut
dim firstLine
If original.id = itm.id Then
firstLine = "ORIGINAL:<br>"
Else
firstLine = "<br>"
End If
strOut = strOut & "<tr class=dark><td colspan=1000><font size=""1""><b>"&firstLine&itm.path & "</b></font></td></tr>" & vbcrlf
strOut = strOut & " <tr>" & vbcrlf
strOut = strOut & outField(original.artistName, itm.artistName)
strOut = strOut & outField(original.title, itm.title)
strOut = strOut & outField(original.albumName, itm.albumName)
strOut = strOut & outField(original.albumArtistName, itm.albumArtistName)
strOut = strOut & outField(original.year, itm.year)
strOut = strOut & outField(original.trackOrder, itm.trackOrder)
strOut = strOut & outField(original.genre, itm.genre)
strOut = strOut & outField(original.rating, itm.rating)
strOut = strOut & outField(original.involvedPeople, itm.involvedPeople)
strOut = strOut & outField(original.originalArtist, itm.originalArtist)
strOut = strOut & outField(original.originalTitle, itm.originalTitle)
strOut = strOut & outField(original.originalYear, itm.originalYear)
strOut = strOut & outField(original.lyricist, itm.lyricist)
strOut = strOut & outField(original.originalLyricist, itm.originalLyricist)
strOut = strOut & outField(original.bpm, itm.bpm)
strOut = strOut & outField(original.isrc, itm.isrc)
strOut = strOut & outField(original.publisher, itm.publisher)
strOut = strOut & outField(original.copyright, itm.copyright)
strOut = strOut & outField(original.encoder, itm.encoder)
strOut = strOut & outField(original.author, itm.author)
strOut = strOut & outField(original.comment, itm.comment)
strOut = strOut & outField(original.lyrics, itm.lyrics)
strOut = strOut & outField(original.custom1, itm.custom1)
strOut = strOut & outField(original.custom2, itm.custom2)
strOut = strOut & outField(original.custom3, itm.custom3)
strOut = strOut & outField(original.tempo, itm.tempo)
strOut = strOut & outField(original.occasion, itm.occasion)
strOut = strOut & outField(original.mood, itm.mood)
strOut = strOut & outField(original.quality, itm.quality)
strOut = strOut & " </tr>" & vbcrlf
showRow = strOut
End Function
Function BuildReport
Dim original : Set original = trackList.Item(0)
Dim strOut : strOut = ""
strOut = strOut & "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">" & vbcrlf
strOut = strOut & "<html>" & vbcrlf
strOut = strOut & " <head>" & vbcrlf
strOut = strOut & " <title>" & SDB.Localize("Copy To Others") & "</title>" & vbcrlf
strOut = strOut & " </head>" & vbcrlf
strOut = strOut & "<STYLE TYPE=text/css>" & vbcrlf
strOut = strOut & "body{font-family:'Verdana',sans-serif; background-color:#FFFFFF; font-size:9pt; color:#000000;}" & vbcrlf
strOut = strOut & "H1{font-family:'Verdana',sans-serif; font-size:13pt; font-weight:bold; color:#AAAAAA; text-align:left}" & vbcrlf
strOut = strOut & "P{font-family:'Verdana',sans-serif; font-size:8pt; color:#000000;}" & vbcrlf
strOut = strOut & "TH{font-family:'Verdana',sans-serif; font-size:9pt; font-weight:bold; color:#000000; border-color:#000000; border-style: solid; border-left-width:0px; border-right-width:0px; border-top-width:0px; border-bottom-width:3px;}" & vbcrlf
strOut = strOut & "TD{font-family:'Verdana',sans-serif; font-size:8pt; color:#000000; border-color:#000000; border-style: solid; border-left-width:1px; border-right-width:0px; border-top-width:1px; border-bottom-width:1px;}" & vbcrlf
strOut = strOut & "TD.highlight{font-family:'Verdana',sans-serif; font-size:8pt; background-color:#FFFF77; color:#000000; border-color:#000000; border-style: solid; border-left-width:1px; border-right-width:0px; border-top-width:1px; border-bottom-width:1px;}" & vbcrlf
strOut = strOut & "TD.highlighter{font-family:'Verdana',sans-serif; font-size:8pt; background-color:#FFFFCC; color:#000000; border-color:#000000; border-style: solid; border-left-width:1px; border-right-width:0px; border-top-width:1px; border-bottom-width:1px;}" & vbcrlf
strOut = strOut & "TR.dark{background-color:#EEEEEE}" & vbcrlf
strOut = strOut & "TR.aleft TH{text-align:left}" & vbcrlf
strOut = strOut & "</STYLE>" & vbcrlf
strOut = strOut & " <body>" & vbcrlf
strOut = strOut & " <H1>" & SDB.Localize("Copy To Others:") & "</H1>" & vbcrlf
strOut = strOut & " <table border=""1"" cellspacing=""0"" cellpadding=""4"" width=""2400"">" & vbcrlf
strOut = strOut & showRow(original, original)
dim Iter, itm
Set Iter = SDB.Database.QuerySongs(" AND "&match_clause(original))
While Not Iter.EOF
Set itm = Iter.Item
strOut = strOut & showRow(original, itm)
hold.add itm, itm
Iter.Next
Wend
SDB.Objects("hold") = hold
strOut = strOut & " </table>" & vbcrlf
strOut = strOut & " </body>" & vbcrlf
strOut = strOut & "</html>" & vbcrlf
BuildReport = strOut
End Function
[code]' Version 20070320
Option Explicit
Dim res
Public hold
Set hold = CreateObject("Scripting.Dictionary")
Const mmAnchorRight = 4
Const mmAnchorBottom = 8
Const mmAlignTop = 1
Const mmAlignBottom = 2
Const mmAlignClient = 5
Const mmListDropdown = 2
Const mmFormScreenCenter = 4
Dim trackList
Function fixit(s)
fixit = Replace(s, "'", "''")
End Function
Function match_clause(original)
match_clause = " artists.artist = '"&fixit(original.artistName)&"' AND " & _
" songs.IdArtist = artists.id AND songs.songtitle = '"&fixit(original.title)&"'" & _
" AND NOT (songs.id = "&original.id&")"
End Function
Sub CloseDown
Set hold = nothing
SDB.Objects("StatusThingy") = Nothing
SDB.Objects("original") = Nothing
End Sub
Sub OnCancel(Btn)
CloseDown
End Sub
Sub OnOK(Btn)
Set hold = SDB.Objects("hold")
Dim original : Set original = SDB.Objects("original")
Dim itm
For Each itm In hold
itm.artistName = original.artistName
itm.title = original.title
itm.albumName = original.albumName
itm.albumArtistName = original.albumArtistName
itm.year = original.year
itm.trackOrder = original.trackOrder
itm.genre = original.genre
itm.rating = original.rating
itm.involvedPeople = original.involvedPeople
itm.originalArtist = original.originalArtist
itm.originalTitle = original.originalTitle
itm.originalYear = original.originalYear
itm.lyricist = original.lyricist
itm.originalLyricist = original.originalLyricist
itm.bpm = original.bpm
itm.isrc = original.isrc
itm.publisher = original.publisher
itm.copyright = original.copyright
itm.encoder = original.encoder
itm.author = original.author
itm.comment = original.comment
itm.lyrics = original.lyrics
itm.custom1 = original.custom1
itm.custom2 = original.custom2
itm.custom3 = original.custom3
itm.tempo = original.tempo
itm.occasion = original.occasion
itm.mood = original.mood
itm.quality = original.quality
If itm.ID>-1 Then
itm.UpdateDB
End If
itm.WriteTags
Next 'itm
CloseDown
End Sub
Function MapXML(original)
Dim out
out = Replace(original, "&", "&")
out = Replace(out, " ", " ")
out = Replace(out, "<", "<")
out = Replace(out, ">", ">")
Dim i
i=1
While i<=Len(out)
If (AscW(Mid(out, i, 1))>127) Then
out = Mid(out, 1, i-1)+"&#"+CStr(AscW(Mid(out, i, 1)))+";"+Mid(out, i+1)
End If
i=i+1
WEnd
MapXML = out
End Function
Function tooBig(s)
If (Len(s) > 50) Then
tooBig = Left(s,47) & "..."
Else
tooBig = s
End If
End Function
Function outField (fixed, normal)
If fixed = normal Then
outField = "<td>" & MapXML(tooBig(normal)) & "</td>" & vbcrlf
Else
outField = "<td class=""highlight"">" & MapXML(tooBig(normal)) & "</td>" & vbcrlf
End If
'res = SDB.MessageBox(fixed&"->"&normal&"="&outField, mtError, Array(mbOk))
End Function
Sub CopyToOthers
Dim UI, Form, Foot, Btn, Btn2, WB, doc
Dim writeChanges
Set trackList = SDB.SelectedSongList
If trackList.count=0 Then
Set trackList = SDB.AllVisibleSongList
End If
Set trackList = SDB.SelectedSongList
If trackList.count = 0 Then
res = SDB.MessageBox("Select a track.", mtError, Array(mbOk))
Exit Sub
End If
If trackList.count > 1 Then
res = SDB.MessageBox("Select only a single track.", mtError, Array(mbOk))
Exit Sub
End If
dim original : Set original = trackList.Item(0)
dim SELECT_Clause, FROM_Clause, WHERE_Clause, SQL, Iter
SELECT_Clause = " SELECT Songs.Id "
FROM_Clause = " FROM Songs, Artists "
WHERE_Clause = " WHERE " & match_clause(original)
' WHERE_Clause = " WHERE artists.artist = '"&fixit(original.artistName)&"' AND " & _
' " songs.IdArtist = artists.id AND songs.songtitle = '"&fixit(original.title)&"'" & _
' " AND NOT (songs.id = "&original.id&")"
SQL = SELECT_Clause & FROM_Clause & WHERE_Clause
Set Iter = SDB.Database.OpenSQL(SQL)
If Iter.EOF Then
res = SDB.MessageBox("No other matches were found for this song.", mtError, Array(mbOk))
Exit Sub
End If
Set UI = SDB.UI
' Create the window to be shown
Set Form = UI.NewForm
Form.Common.SetRect 50, 50, 500, 400
Form.Common.MinWidth = 200
Form.Common.MinHeight = 150
Form.FormPosition = mmFormScreenCenter
Form.SavePositionName = "CaseWindow"
Form.Caption = SDB.Localize("Copy To Others")
Form.StayOnTop = True
' Create a panel at the bottom of the window
Set Foot = UI.NewPanel(Form)
Foot.Common.Align = mmAlignBottom
Foot.Common.Height = 35
' Create a button that closes the window
Set Btn = UI.NewButton(Foot)
Btn.Caption = SDB.Localize("&Cancel")
Btn.Common.SetRect (Foot.Common.Width - 180)/2+95, 9, 85, 24
Btn.Common.Anchors = mmAnchorRight + mmAnchorBottom
Btn.UseScript = Script.ScriptPath
Btn.OnClickFunc = "OnCancel"
' Create a button that saves the report
Set Btn2 = UI.NewButton(Foot)
Btn2.Caption = SDB.Localize("&OK")
Btn2.Common.SetRect (Foot.Common.Width - 180)/2, 9, 85, 24
Btn2.Common.Anchors = mmAnchorRight + mmAnchorBottom
Btn2.UseScript = Script.ScriptPath
Btn2.OnClickFunc = "OnOK"
Set WB = UI.NewActiveX(Form, "Shell.Explorer")
WB.Common.Align = mmAlignClient ' Fill all client rectangle
WB.Common.ControlName = "WB"
Set doc = WB.Interf.Document
Form.Common.Visible = True ' Only show the form, don't wait for user input
SDB.Objects("StatusThingy") = Form ' Save reference to the form somewhere, otherwise it would simply disappear
doc.write BuildReport
doc.close
SDB.Objects("original") = original
End Sub
Function showRow(original, itm)
dim strOut
dim firstLine
If original.id = itm.id Then
firstLine = "ORIGINAL:<br>"
Else
firstLine = "<br>"
End If
strOut = strOut & "<tr class=dark><td colspan=1000><font size=""1""><b>"&firstLine&itm.path & "</b></font></td></tr>" & vbcrlf
strOut = strOut & " <tr>" & vbcrlf
strOut = strOut & outField(original.artistName, itm.artistName)
strOut = strOut & outField(original.title, itm.title)
strOut = strOut & outField(original.albumName, itm.albumName)
strOut = strOut & outField(original.albumArtistName, itm.albumArtistName)
strOut = strOut & outField(original.year, itm.year)
strOut = strOut & outField(original.trackOrder, itm.trackOrder)
strOut = strOut & outField(original.genre, itm.genre)
strOut = strOut & outField(original.rating, itm.rating)
strOut = strOut & outField(original.involvedPeople, itm.involvedPeople)
strOut = strOut & outField(original.originalArtist, itm.originalArtist)
strOut = strOut & outField(original.originalTitle, itm.originalTitle)
strOut = strOut & outField(original.originalYear, itm.originalYear)
strOut = strOut & outField(original.lyricist, itm.lyricist)
strOut = strOut & outField(original.originalLyricist, itm.originalLyricist)
strOut = strOut & outField(original.bpm, itm.bpm)
strOut = strOut & outField(original.isrc, itm.isrc)
strOut = strOut & outField(original.publisher, itm.publisher)
strOut = strOut & outField(original.copyright, itm.copyright)
strOut = strOut & outField(original.encoder, itm.encoder)
strOut = strOut & outField(original.author, itm.author)
strOut = strOut & outField(original.comment, itm.comment)
strOut = strOut & outField(original.lyrics, itm.lyrics)
strOut = strOut & outField(original.custom1, itm.custom1)
strOut = strOut & outField(original.custom2, itm.custom2)
strOut = strOut & outField(original.custom3, itm.custom3)
strOut = strOut & outField(original.tempo, itm.tempo)
strOut = strOut & outField(original.occasion, itm.occasion)
strOut = strOut & outField(original.mood, itm.mood)
strOut = strOut & outField(original.quality, itm.quality)
strOut = strOut & " </tr>" & vbcrlf
showRow = strOut
End Function
Function BuildReport
Dim original : Set original = trackList.Item(0)
Dim strOut : strOut = ""
strOut = strOut & "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">" & vbcrlf
strOut = strOut & "<html>" & vbcrlf
strOut = strOut & " <head>" & vbcrlf
strOut = strOut & " <title>" & SDB.Localize("Copy To Others") & "</title>" & vbcrlf
strOut = strOut & " </head>" & vbcrlf
strOut = strOut & "<STYLE TYPE=text/css>" & vbcrlf
strOut = strOut & "body{font-family:'Verdana',sans-serif; background-color:#FFFFFF; font-size:9pt; color:#000000;}" & vbcrlf
strOut = strOut & "H1{font-family:'Verdana',sans-serif; font-size:13pt; font-weight:bold; color:#AAAAAA; text-align:left}" & vbcrlf
strOut = strOut & "P{font-family:'Verdana',sans-serif; font-size:8pt; color:#000000;}" & vbcrlf
strOut = strOut & "TH{font-family:'Verdana',sans-serif; font-size:9pt; font-weight:bold; color:#000000; border-color:#000000; border-style: solid; border-left-width:0px; border-right-width:0px; border-top-width:0px; border-bottom-width:3px;}" & vbcrlf
strOut = strOut & "TD{font-family:'Verdana',sans-serif; font-size:8pt; color:#000000; border-color:#000000; border-style: solid; border-left-width:1px; border-right-width:0px; border-top-width:1px; border-bottom-width:1px;}" & vbcrlf
strOut = strOut & "TD.highlight{font-family:'Verdana',sans-serif; font-size:8pt; background-color:#FFFF77; color:#000000; border-color:#000000; border-style: solid; border-left-width:1px; border-right-width:0px; border-top-width:1px; border-bottom-width:1px;}" & vbcrlf
strOut = strOut & "TD.highlighter{font-family:'Verdana',sans-serif; font-size:8pt; background-color:#FFFFCC; color:#000000; border-color:#000000; border-style: solid; border-left-width:1px; border-right-width:0px; border-top-width:1px; border-bottom-width:1px;}" & vbcrlf
strOut = strOut & "TR.dark{background-color:#EEEEEE}" & vbcrlf
strOut = strOut & "TR.aleft TH{text-align:left}" & vbcrlf
strOut = strOut & "</STYLE>" & vbcrlf
strOut = strOut & " <body>" & vbcrlf
strOut = strOut & " <H1>" & SDB.Localize("Copy To Others:") & "</H1>" & vbcrlf
strOut = strOut & " <table border=""1"" cellspacing=""0"" cellpadding=""4"" width=""2400"">" & vbcrlf
strOut = strOut & showRow(original, original)
dim Iter, itm
Set Iter = SDB.Database.QuerySongs(" AND "&match_clause(original))
While Not Iter.EOF
Set itm = Iter.Item
strOut = strOut & showRow(original, itm)
hold.add itm, itm
Iter.Next
Wend
SDB.Objects("hold") = hold
strOut = strOut & " </table>" & vbcrlf
strOut = strOut & " </body>" & vbcrlf
strOut = strOut & "</html>" & vbcrlf
BuildReport = strOut
End Function
[/code]