Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Imports System
Imports System.IO
Imports System.Text
Imports System.Runtime.InteropServices
Imports Microsoft.Win32
Imports Ras
Imports TAPI3Lib
Imports System.Data.SqlClient
Module UpgradeSupport
Friend AccessApplication_definst As New Access.Application
Friend DAODBEngine_definst As New DAO.DBEngine
End Module
Public Sub Template_Picker(ByRef pChannelID As Short, ByRef pChannelType As Short, ByRef pMaxVersionOnly As Boolean)
On Error GoTo Template_Picker_ERROR
Dim MySQL As String
Dim MyCommand As SqlCommand
Dim MyCommandExec As SqlCommand
Dim MyAdaptor1 As SqlDataAdapter
Dim MyDataset1 As DataSet
Dim MyDataRow1 As DataRow
Dim MyAdaptor2 As SqlDataAdapter
Dim MyDataset2 As DataSet
Dim MyDataRow2 As DataRow
Dim MyAdaptor3 As SqlDataAdapter
Dim MyDataset3 As DataSet
Dim MyDataRow3 As DataRow
Dim MyLockedAdaptor As SqlDataAdapter
Dim MyLockedDataset As DataSet
Dim MyLockedDataRow As DataRow
Dim mDay As Short 'DOW Sunday = 1
Dim mHour As Short 'hour of the day
Dim mSlot As Short 'slot for the day
Dim mRecCount As Short
Dim mArrayPos As Short 'where to insert next record into array
Dim mTry As Short
Dim mRevNum As Integer
Dim i As Short
Dim varNeedToPick As Boolean
Dim varLibCount As Short
Dim mTemplateHour As Short 'hour of template
Dim mGotOne As Boolean
'Dim mContentArray(3, 16, 1, 5) 'Holds Content Info for Template Slots
'3 = Hours
'16 = Slots
'1 = Content (redimensioned below based on library totals)
'4 = Properties
'Index
'0 = Content
'1 = Artist
'2 = Rating
'3 = Audio Rating
'4 = template_playback_category_id
'5 = Has it been considered
'Dim mBinArray(6, 2687) 'will hold an entire week's detail
'0 = day
'1 = hour
'2 = slot
'3 = content_id
'4 = artist_id
'5 = rating_id
'6 = audio_rating_id
If pMaxVersionOnly = True Then
MySQL = ""
MySQL = MySQL & " SELECT max(version_number) As version_number, primary_bin_group_id, library_id"
MySQL = MySQL & " FROM tbl_channel_bin_group_versions, tbl_channel_bin_groups"
MySQL = MySQL & " WHERE tbl_channel_bin_group_versions.channel_id = tbl_channel_bin_groups.channel_id"
MySQL = MySQL & " AND tbl_channel_bin_group_versions.channel_id = " & pChannelID
MySQL = MySQL & " GROUP BY primary_bin_group_id, library_id"
Else
MySQL = ""
MySQL = MySQL & " SELECT version_number, primary_bin_group_id, library_id"
MySQL = MySQL & " FROM tbl_channel_bin_group_versions, tbl_channel_bin_groups"
MySQL = MySQL & " WHERE tbl_channel_bin_group_versions.channel_id = tbl_channel_bin_groups.channel_id"
MySQL = MySQL & " AND tbl_channel_bin_group_versions.channel_id = " & pChannelID
MySQL = MySQL & " ORDER BY version_number DESC"
End If
'MyRST1.Open(MySQL, gDB, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
MyCommand = New SqlCommand(MySQL, gDBCon)
MyAdaptor1 = New SqlDataAdapter(MyCommand)
MyDataset1 = New DataSet
MyAdaptor1.Fill(MyDataset1, "DataTable")
MyCommand.Dispose()
For Each MyDataRow1 In MyDataset1.Tables("DataTable").Rows 'Do While Not MyRST1.EOF
mDay = 1
mHour = 0
mArrayPos = 0
'See if there are any clubs at or below this version, to see if it needs picked
If pMaxVersionOnly = True Then
varNeedToPick = True
Else
MySQL = ""
MySQL = MySQL & " SELECT server_install_id"
MySQL = MySQL & " FROM tbl_server_installs"
MySQL = MySQL & " WHERE base_library_id = " & MyDataRow1("library_id") 'MyRST1.Fields("library_id").Value
MySQL = MySQL & " AND base_version_number <= " & MyDataRow1("version_number") 'MyRST1.Fields("version_number").Value
MySQL = MySQL & " AND status_id In (1,2,10,13)"
MyCommand = New SqlCommand(MySQL, gDBCon)
MyAdaptor2 = New SqlDataAdapter(MyCommand)
MyDataset2 = New DataSet
MyAdaptor2.Fill(MyDataset2, "DataTable")
MyCommand.Dispose()
'MyRST2.Open(MySQL, gDB, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
If MyDataset2.Tables("DataTable").Rows.Count = 0 Then 'If MyRST2.EOF Then
varNeedToPick = False
Else
varNeedToPick = True
End If
MyDataset2.Dispose() 'MyRST2.Close()
MyAdaptor2.Dispose()
End If
If varNeedToPick = True Then
MySQL = ""
MySQL = MySQL & " SELECT MAX(revision_number) as MaxRev"
MySQL = MySQL & " FROM tbl_bin_group_versions"
MySQL = MySQL & " WHERE bin_group_id = " & MyDataRow1("primary_bin_group_id") 'MyRST1.Fields("primary_bin_group_id").Value
MySQL = MySQL & " AND library_id = " & MyDataRow1("library_id") 'MyRST1.Fields("library_id").Value
MySQL = MySQL & " AND version_number = " & MyDataRow1("version_number") 'MyRST1.Fields("version_number").Value
MyCommand = New SqlCommand(MySQL, gDBCon)
MyAdaptor2 = New SqlDataAdapter(MyCommand)
MyDataset2 = New DataSet
MyAdaptor2.Fill(MyDataset2, "DataTable")
MyCommand.Dispose()
'MyRST2.Open(MySQL, gDB, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
If MyDataset2.Tables("DataTable").Rows.Count = 0 Then 'If MyRST2.EOF Then
'Create Rev Zero, then Pick Rev One
MySQL = ""
MySQL = MySQL & " INSERT INTO tbl_bin_group_versions"
MySQL = MySQL & " (bin_group_id, library_id, version_number, revision_number, bin_group_type_id, picked)"
MySQL = MySQL & " VALUES"
MySQL = MySQL & " (" & MyDataRow1("primary_bin_group_id") & "," 'MyRST1.Fields("primary_bin_group_id").Value & ", "
MySQL = MySQL & MyDataRow1("library_id") & "," 'MyRST1.Fields("library_id").Value & ", "
MySQL = MySQL & MyDataRow1("version_number") & "," 'MyRST1.Fields("version_number").Value & ", "
MySQL = MySQL & "0,1,0)"
MyCommandExec = New SqlCommand(MySQL, gDBCon)
MyCommandExec.ExecuteNonQuery()
MyCommandExec.Dispose()
'MyRSTExec.Open(MySQL, gDB, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
mRevNum = 1
Else
MyDataRow2 = MyDataset2.Tables("DataTable").Rows(0)
If IsDBNull(MyDataRow2("MaxRev")) Then 'MyRST2.Fields("MaxRev").Value) Then
'Create Rev Zero, then Pick Rev One
MySQL = ""
MySQL = MySQL & " INSERT INTO tbl_bin_group_versions"
MySQL = MySQL & " (bin_group_id, library_id, version_number, revision_number, bin_group_type_id, picked)"
MySQL = MySQL & " VALUES"
MySQL = MySQL & " (" & MyDataRow1("primary_bin_group_id") & "," 'MyRST1.Fields("primary_bin_group_id").Value & ", "
MySQL = MySQL & MyDataRow1("library_id") & "," 'MyRST1.Fields("library_id").Value & ", "
MySQL = MySQL & MyDataRow1("version_number") & "," 'MyRST1.Fields("version_number").Value & ", "
MySQL = MySQL & "0,1,0)"
MyCommandExec = New SqlCommand(MySQL, gDBCon)
MyCommandExec.ExecuteNonQuery()
MyCommandExec.Dispose()
'MyRSTExec.Open(MySQL, gDB, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
mRevNum = 1
Else
mRevNum = AccessApplication_definst.Nz(MyDataRow2("MaxRev") + 1) 'MyRST2.Fields("MaxRev").Value + 1)
End If
End If
MyDataset2.Dispose() 'MyRST2.Close()
MyAdaptor2.Dispose()
MySQL = ""
MySQL = MySQL & " INSERT INTO tbl_bin_group_versions"
MySQL = MySQL & " (bin_group_id, library_id, version_number, revision_number, bin_group_type_id, picked)"
MySQL = MySQL & " VALUES"
MySQL = MySQL & " (" & MyDataRow1("primary_bin_group_id") & "," 'MyRST1.Fields("primary_bin_group_id").Value & ", "
MySQL = MySQL & MyDataRow1("library_id") & "," 'MyRST1.Fields("library_id").Value & ", "
MySQL = MySQL & MyDataRow1("version_number") & "," 'MyRST1.Fields("version_number").Value & ", "
MySQL = MySQL & mRevNum & ",1,1)"
MyCommandExec = New SqlCommand(MySQL, gDBCon)
MyCommandExec.ExecuteNonQuery()
MyCommandExec.Dispose()
'MyRSTExec.Open(MySQL, gDB, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
'Determine how large to make the array for storing the template content
MySQL = ""
MySQL = MySQL & " SELECT count(entertainment_id) As LibCount"
MySQL = MySQL & " FROM tbl_library_content"
MySQL = MySQL & " WHERE library_id = " & MyDataRow1("library_id") 'MyRST1.Fields("library_id").Value
MySQL = MySQL & " AND version_number = " & MyDataRow1("version_number") 'MyRST1.Fields("version_number").Value
MyCommand = New SqlCommand(MySQL, gDBCon)
MyAdaptor2 = New SqlDataAdapter(MyCommand)
MyDataset2 = New DataSet
MyAdaptor2.Fill(MyDataset2, "DataTable")
MyCommand.Dispose()
'MyRST2.Open(MySQL, gDB, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
MyDataRow2 = MyDataset2.Tables("DataTable").Rows(0)
varLibCount = MyDataRow2("LibCount") 'MyRST2.Fields("LibCount").Value
MyDataset2.Dispose() 'MyRST2.Close()
MyAdaptor2.Dispose()
Dim mContentArray(3, 16, varLibCount, 5) As Object 'will hold all content for the template
Dim mBinArray(6, 2687) As Object 'Clear out Bin Array
CType(fMainForm, frmPLUpload).pgBar.Value = 0
CType(fMainForm, frmPLUpload).pgBar.Max = 48
For mTemplateHour = 1 To 3
For mSlot = 1 To 16
CType(fMainForm, frmPLUpload).sbStatus.Panels(1).Text = "Picking: Channel - " & pChannelID & " | Library - " & MyDataRow1("library_id") & " | Version - " & MyDataRow1("version_number") & " | ContentArray - Hour:" & mTemplateHour & " Slot:" & mSlot
CType(fMainForm, frmPLUpload).pgBar.Value = CType(fMainForm, frmPLUpload).pgBar.Value + 1
CType(fMainForm, frmPLUpload).Refresh()
'Get The Criteria For the Given Slot
Select Case pChannelType
Case 2 'Template
MySQL = ""
MySQL = MySQL & " SELECT tbl_channel_templates.genre_id, tbl_template_playback_category_def.template_playback_category_id,"
MySQL = MySQL & " tbl_template_playback_category_def.template_playback_category_sql,"
MySQL = MySQL & " tbl_template_energy_def.template_energy_sql,"
MySQL = MySQL & " tbl_template_age_def.template_age_sql,"
MySQL = MySQL & " tbl_template_audio_rating_def.template_audio_rating_sql,"
MySQL = MySQL & " tbl_template_video_rating_def.template_video_rating_sql"
MySQL = MySQL & " FROM tbl_channel_templates, tbl_template_playback_category_def,"
MySQL = MySQL & " tbl_template_energy_def, tbl_template_age_def,"
MySQL = MySQL & " tbl_template_audio_rating_def, tbl_template_video_rating_def"
MySQL = MySQL & " WHERE tbl_channel_templates.template_playback_category_id = tbl_template_playback_category_def.template_playback_category_id"
MySQL = MySQL & " AND tbl_channel_templates.template_energy_id = tbl_template_energy_def.template_energy_id"
MySQL = MySQL & " AND tbl_channel_templates.template_age_id = tbl_template_age_def.template_age_id"
MySQL = MySQL & " AND tbl_channel_templates.template_audio_rating_id = tbl_template_audio_rating_def.template_audio_rating_id"
MySQL = MySQL & " AND tbl_channel_templates.template_video_rating_id = tbl_template_video_rating_def.template_video_rating_id"
MySQL = MySQL & " AND tbl_channel_templates.channel_id = " & pChannelID
MySQL = MySQL & " AND tbl_channel_templates.version_number = " & MyDataRow1("version_number") ' MyRST1.Fields("version_number").Value
MySQL = MySQL & " AND tbl_channel_templates.ch_hour = " & mTemplateHour
MySQL = MySQL & " AND tbl_channel_templates.ch_slot = " & mSlot
Case 3, 4 'Facility Specific or User Defined
MySQL = ""
MySQL = MySQL & " SELECT tbl_template_playback_category_def.user_template_playback_category_sql"
MySQL = MySQL & " FROM tbl_channel_user_templates, tbl_template_playback_category_def"
MySQL = MySQL & " WHERE tbl_channel_user_templates.template_playback_category_id = tbl_template_playback_category_def.template_playback_category_id"
MySQL = MySQL & " AND tbl_channel_user_templates.channel_id = " & pChannelID
MySQL = MySQL & " AND tbl_channel_user_templates.version_number = " & MyDataRow1("version_number") 'MyRST1.Fields("version_number").Value
MySQL = MySQL & " AND tbl_channel_user_templates.ch_hour = " & mTemplateHour
MySQL = MySQL & " AND tbl_channel_user_templates.ch_slot = " & mSlot
End Select
MyCommand = New SqlCommand(MySQL, gDBCon)
MyAdaptor2 = New SqlDataAdapter(MyCommand)
MyDataset2 = New DataSet
MyAdaptor2.Fill(MyDataset2, "DataTable")
MyCommand.Dispose()
'MyRST2.Open(MySQL, gDB, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
If MyDataset2.Tables("DataTable").Rows.Count > 0 Then 'If Not MyRST2.EOF Then
MyDataRow2 = MyDataset2.Tables("DataTable").Rows(0)
'Get The Content That Meets the Criteria
Select Case pChannelType
Case 2 'Template
MySQL = ""
MySQL = MySQL & " SELECT tbl_entertainment.content_id, tbl_entertainment.artist_id, "
MySQL = MySQL & " tbl_entertainment.rating_id , tbl_entertainment.audio_rating_id"
MySQL = MySQL & " FROM tbl_channel_templates"
MySQL = MySQL & " INNER JOIN tbl_channel_bin_groups"
MySQL = MySQL & " ON tbl_channel_templates.channel_id = tbl_channel_bin_groups.channel_id"
MySQL = MySQL & " INNER JOIN tbl_library_content"
MySQL = MySQL & " ON tbl_channel_bin_groups.library_id = tbl_library_content.library_id"
MySQL = MySQL & " AND tbl_channel_templates.version_number = tbl_library_content.version_number"
MySQL = MySQL & " INNER JOIN tbl_entertainment"
MySQL = MySQL & " ON tbl_library_content.entertainment_id = tbl_entertainment.entertainment_id"
If Not IsDBNull(MyDataRow2("genre_id")) Then
MySQL = MySQL & " AND tbl_channel_templates.genre_id = tbl_library_content.genre_id"
End If
MySQL = MySQL & " AND tbl_channel_templates.channel_id = " & pChannelID
MySQL = MySQL & " AND tbl_channel_templates.version_number = " & MyDataRow1("version_number")
MySQL = MySQL & " AND tbl_channel_templates.ch_hour = " & mTemplateHour
MySQL = MySQL & " AND tbl_channel_templates.ch_slot = " & mSlot
MySQL = MySQL & " AND tbl_library_content.suppress = 0" 'non suppressed songs
MySQL = MySQL & " AND tbl_entertainment.no_play = 0" 'not disabled songs
If Not IsDBNull(MyDataRow2("template_playback_category_sql")) Then
MySQL = MySQL & " " & MyDataRow2("template_playback_category_sql")
End If
If Not IsDBNull(MyDataRow2("template_energy_sql")) Then
MySQL = MySQL & " " & MyDataRow2("template_energy_sql")
End If
If Not IsDBNull(MyDataRow2("template_age_sql")) Then
MySQL = MySQL & " " & MyDataRow2("template_age_sql")
End If
If Not IsDBNull(MyDataRow2("template_audio_rating_sql")) Then
MySQL = MySQL & " " & MyDataRow2("template_audio_rating_sql")
End If
If Not IsDBNull(MyDataRow2("template_video_rating_sql")) Then
MySQL = MySQL & " " & MyDataRow2("template_video_rating_sql")
End If
Case 3, 4 'Facility Specific or User Defined
MySQL = ""
MySQL = MySQL & " SELECT tbl_entertainment.content_id, tbl_entertainment.artist_id, tbl_entertainment.rating_id, tbl_entertainment.audio_rating_id"
MySQL = MySQL & " FROM tbl_channel_user_templates, tbl_channel_bin_groups, tbl_library_content, tbl_entertainment, tbl_channel_user_categorization"
MySQL = MySQL & " WHERE tbl_channel_user_templates.channel_id = tbl_channel_bin_groups.channel_id"
MySQL = MySQL & " AND tbl_channel_user_templates.version_number = tbl_library_content.version_number"
MySQL = MySQL & " AND tbl_channel_bin_groups.library_id = tbl_library_content.library_id"
MySQL = MySQL & " AND tbl_library_content.entertainment_id = tbl_entertainment.entertainment_id"
MySQL = MySQL & " AND tbl_channel_user_categorization.channel_id = tbl_channel_user_templates.channel_id"
MySQL = MySQL & " AND tbl_channel_user_categorization.version_number = tbl_channel_user_templates.version_number"
MySQL = MySQL & " AND tbl_channel_user_categorization.content_id = tbl_entertainment.content_id"
MySQL = MySQL & " AND tbl_channel_user_templates.channel_id = " & pChannelID
MySQL = MySQL & " AND tbl_channel_user_templates.version_number = " & MyDataRow1("version_number") 'MyRST1.Fields("version_number").Value
MySQL = MySQL & " AND tbl_channel_user_templates.ch_hour = " & mTemplateHour
MySQL = MySQL & " AND tbl_channel_user_templates.ch_slot = " & mSlot
MySQL = MySQL & " AND tbl_library_content.suppress = 0" 'non suppressed songs
MySQL = MySQL & " AND tbl_entertainment.no_play = 0" 'not disabled songs
If Not IsDBNull(MyDataRow2("user_template_playback_category_sql")) Then
MySQL = MySQL & " " & MyDataRow2("user_template_playback_category_sql")
End If
End Select
MyCommand = New SqlCommand(MySQL, gDBCon)
MyAdaptor3 = New SqlDataAdapter(MyCommand)
MyDataset3 = New DataSet
MyAdaptor3.Fill(MyDataset3, "DataTable")
MyCommand.Dispose()
'MyRST3.Open(MySQL, gDB, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
If MyDataset3.Tables("DataTable").Rows.Count = 0 Then 'If MyRST3.EOF Then
'No content found for template
varFromDisplay = "Playlist Server"
varFrom = "playlist@clubcom.com"
varTo = "brandonmurray@clubcom.com,aljones@clubcom.com"
varCC = "blakekercovich@clubcom.com,georgedumaine@clubcom.com,victorwashy@clubcom.com"
varBCC = ""
varSubject = "Template Picker Failure"
varMessage = ""
varMessage = varMessage & "Template Picking has failed for the following:"
varMessage = varMessage & vbCrLf
varMessage = varMessage & "Channel ID# " & pChannelID
varMessage = varMessage & vbCrLf
varMessage = varMessage & "Library ID# " & MyDataRow1("library_id") 'MyRST1.Fields("library_id").Value
varMessage = varMessage & vbCrLf
varMessage = varMessage & "Version # " & MyDataRow1("version_number") 'MyRST1.Fields("version_number").Value
varMessage = varMessage & vbCrLf
varMessage = varMessage & "Revision # " & mRevNum
varMessage = varMessage & vbCrLf
varMessage = varMessage & "Bin Group ID # " & MyDataRow1("primary_bin_group_id") 'MyRST1.Fields("primary_bin_group_id").Value
varMessage = varMessage & vbCrLf
varMessage = varMessage & vbCrLf
varMessage = varMessage & "No valid content was found for template hour #" & mTemplateHour & " and slot #" & mSlot
varMessage = varMessage & vbCrLf
varMessage = varMessage & vbCrLf
varMessage = varMessage & gPLServer
Call SMTPMail.SendMail(varFromDisplay, varFrom, varTo, varCC, varBCC, varSubject, varMessage)
gLogFile.WriteLine(CStr(Now) & Chr(9) & "Template_Picker" & Chr(9) & "Template picking failed for Channel ID# " & pChannelID & " Library ID# " & MyDataRow1("library_id") & " Version # " & MyDataRow1("version_number") & " Revision # " & mRevNum & " Bin Group ID # " & MyDataRow1("primary_bin_group_id"))
gLogFile.Flush()
MyDataset3.Dispose()
MyAdaptor3.Dispose()
MyDataset2.Dispose()
MyAdaptor2.Dispose()
MyDataset1.Dispose()
MyAdaptor1.Dispose()
'MyRST3.Close()
'MyRST2.Close()
'MyRST1.Close()
Exit Sub
End If
'MyRST3.MoveLast()
'mRecCount = MyRST3.RecordCount
'MyRST3.MoveFirst()
mRecCount = MyDataset3.Tables("DataTable").Rows.Count
mContentArray(mTemplateHour, mSlot, 0, 0) = mRecCount
i = 1
For Each MyDataRow3 In MyDataset3.Tables("DataTable").Rows 'Do While Not MyRST3.EOF
mContentArray(mTemplateHour, mSlot, i, 0) = MyDataRow3("content_id") 'MyRST3.Fields("content_id").Value
mContentArray(mTemplateHour, mSlot, i, 1) = MyDataRow3("artist_id") 'MyRST3.Fields("artist_id").Value
mContentArray(mTemplateHour, mSlot, i, 2) = MyDataRow3("rating_id") 'MyRST3.Fields("rating_id").Value
mContentArray(mTemplateHour, mSlot, i, 3) = MyDataRow3("audio_rating_id") 'MyRST3.Fields("audio_rating_id").Value
mContentArray(mTemplateHour, mSlot, i, 4) = False 'used to keep track of what songs have been tested for validity
If pChannelType = 2 Then
mContentArray(mTemplateHour, mSlot, i, 5) = MyDataRow2("template_playback_category_id") 'MyRST2.Fields("template_playback_category_id").Value
Else
mContentArray(mTemplateHour, mSlot, i, 5) = 0
End If
i = i + 1
'MyRST3.MoveNext()
Next MyDataRow3
MyDataset3.Dispose()
MyAdaptor3.Dispose()
'MyRST3.Close()
Else
'No template defined
varFromDisplay = "Playlist Server"
varFrom = "playlist@clubcom.com"
varTo = "brandonmurray@clubcom.com,aljones@clubcom.com"
varCC = "blakekercovich@clubcom.com,georgedumaine@clubcom.com,victorwashy@clubcom.com"
varBCC = ""
varSubject = "Template Picker Failure"
varMessage = ""
varMessage = varMessage & "Template Picking has failed for the following:"
varMessage = varMessage & vbCrLf
varMessage = varMessage & "Channel ID# " & pChannelID
varMessage = varMessage & vbCrLf
varMessage = varMessage & "Library ID# " & MyDataRow1("library_id") 'MyRST1.Fields("library_id").Value
varMessage = varMessage & vbCrLf
varMessage = varMessage & "Version # " & MyDataRow1("version_number") 'MyRST1.Fields("version_number").Value
varMessage = varMessage & vbCrLf
varMessage = varMessage & "Revision # " & mRevNum
varMessage = varMessage & vbCrLf
varMessage = varMessage & "Bin Group ID # " & MyDataRow1("primary_bin_group_id") 'MyRST1.Fields("primary_bin_group_id").Value
varMessage = varMessage & vbCrLf
varMessage = varMessage & vbCrLf
varMessage = varMessage & "No template defined for hour #" & mTemplateHour & " and slot #" & mSlot
varMessage = varMessage & vbCrLf
varMessage = varMessage & vbCrLf
varMessage = varMessage & gPLServer
Call SMTPMail.SendMail(varFromDisplay, varFrom, varTo, varCC, varBCC, varSubject, varMessage)
gLogFile.WriteLine(CStr(Now) & Chr(9) & "Template_Picker" & Chr(9) & "Template picking failed for Channel ID# " & pChannelID & " Library ID# " & MyDataRow1("library_id") & " Version # " & MyDataRow1("version_number") & " Revision # " & mRevNum & " Bin Group ID # " & MyDataRow1("primary_bin_group_id"))
gLogFile.Flush()
MyDataset2.Dispose()
MyAdaptor2.Dispose()
MyDataset1.Dispose()
MyAdaptor1.Dispose()
'MyRST2.Close()
'MyRST1.Close()
Exit Sub
End If
MyDataset2.Dispose()
MyAdaptor2.Dispose()
'MyRST2.Close()
Next mSlot
Next mTemplateHour
CType(fMainForm, frmPLUpload).pgBar.Value = 0
CType(fMainForm, frmPLUpload).pgBar.Max = 168
For mDay = 1 To 7
mHour = 0
Do While mHour <= 23
CType(fMainForm, frmPLUpload).sbStatus.Panels(1).Text = "Picking: Channel - " & pChannelID & " | Library - " & MyDataRow1("library_id") & " | Version - " & MyDataRow1("version_number") & " | BinArray - Day:" & mDay & " Hour:" & mHour
CType(fMainForm, frmPLUpload).pgBar.Value = CType(fMainForm, frmPLUpload).pgBar.Value + 1
CType(fMainForm, frmPLUpload).Refresh()
Select Case mHour
Case 0, 3, 6, 9, 12, 15, 18, 21
mTemplateHour = 1
Case 1, 4, 7, 10, 13, 16, 19, 22
mTemplateHour = 2
Case 2, 5, 8, 11, 14, 17, 20, 23
mTemplateHour = 3
End Select
For mSlot = 1 To 16
mRecCount = mContentArray(mTemplateHour, mSlot, 0, 0) 'contains the number of songs in this hour/slot
Randomize() 'initialize seed with current time
mTry = 0
Do While True
i = Int((mRecCount - 1 + 1) * Rnd() + 1)
' Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
If mContentArray(mTemplateHour, mSlot, i, 4) = False Then 'We have not already tried this item, so try it
If IsValidTemplateContent(mBinArray, mArrayPos, mDay, mHour, mSlot, mContentArray(mTemplateHour, mSlot, i, 0), mContentArray(mTemplateHour, mSlot, i, 1)) Then 'add it
Exit Do
End If
End If
mContentArray(mTemplateHour, mSlot, i, 4) = True 'tested this item for validity
mTry = mTry + 1
If mTry = mRecCount * 2 Then
mGotOne = False
For i = 1 To mRecCount
If mContentArray(mTemplateHour, mSlot, i, 4) = False Then 'Check ones that we have not tried yet if there are any
If IsValidTemplateContent(mBinArray, mArrayPos, mDay, mHour, mSlot, mContentArray(mTemplateHour, mSlot, i, 0), mContentArray(mTemplateHour, mSlot, i, 1)) Then 'add it
mGotOne = True
Exit For 'becase we found one that works which wasn't randomly picked
End If
'mContentArray(mTemplateHour, mSlot, i, 4) = True 'tested this item for validity
'Don't really need to update this since I checked it once and won't check it again because "i" gets incremented in the FOR loop
End If
Next i
If mGotOne Then Exit Do 'else we didn't get one randomly AND we didn't get one stepping through the array so give up
If pChannelType <> 4 And mContentArray(mTemplateHour, mSlot, 1, 5) <> 8 Then 'If the 1st song's template playback category is D then ignore the rules
'No content found for template
varFromDisplay = "Playlist Server"
varFrom = "playlist@clubcom.com"
varTo = "brandonmurray@clubcom.com,aljones@clubcom.com"
varCC = "blakekercovich@clubcom.com,georgedumaine@clubcom.com,victorwashy@clubcom.com"
varBCC = ""
varSubject = "Template Picker Failure"
varMessage = ""
varMessage = varMessage & "Template Picking has failed for the following:"
varMessage = varMessage & vbCrLf
varMessage = varMessage & "Channel ID# " & pChannelID
varMessage = varMessage & vbCrLf
varMessage = varMessage & "Library ID# " & MyDataRow1("library_id")
varMessage = varMessage & vbCrLf
varMessage = varMessage & "Version # " & MyDataRow1("version_number")
varMessage = varMessage & vbCrLf
varMessage = varMessage & "Revision # " & mRevNum
varMessage = varMessage & vbCrLf
varMessage = varMessage & "Bin Group ID # " & MyDataRow1("primary_bin_group_id")
varMessage = varMessage & vbCrLf
varMessage = varMessage & vbCrLf
varMessage = varMessage & "No valid content was found for template hour #" & mTemplateHour & " and slot #" & mSlot & "."
varMessage = varMessage & vbCrLf
varMessage = varMessage & vbCrLf
varMessage = varMessage & gPLServer
Call SMTPMail.SendMail(varFromDisplay, varFrom, varTo, varCC, varBCC, varSubject, varMessage)
Exit Sub
Else
i = Int((mRecCount - 1 + 1) * Rnd() + 1)
' Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
Exit Do
'This is because pChannelType of 4 (user defined) might not have enough songs classified
'to pick using our standard rules
'NOTE: This may take a long time because we'll try mRecCount*2 and then fail
End If
End If
Loop
'we have a Valid Content_Id to add to the bin array
mBinArray(0, mArrayPos) = mDay
mBinArray(1, mArrayPos) = mHour
mBinArray(2, mArrayPos) = mSlot
If IsDBNull(mContentArray(mTemplateHour, mSlot, i, 0)) Then
Call MsgBox("No Content ID, something is very wrong!")
ElseIf mContentArray(mTemplateHour, mSlot, i, 0) Is Nothing Then
Call MsgBox("No Content ID, something is very wrong!")
Else
mBinArray(3, mArrayPos) = mContentArray(mTemplateHour, mSlot, i, 0)
End If
mBinArray(4, mArrayPos) = mContentArray(mTemplateHour, mSlot, i, 1)
mBinArray(5, mArrayPos) = mContentArray(mTemplateHour, mSlot, i, 2)
mBinArray(6, mArrayPos) = mContentArray(mTemplateHour, mSlot, i, 3)
mArrayPos = mArrayPos + 1
Next mSlot
mHour = mHour + 1
Loop
Next mDay
If mArrayPos > 0 Then 'Insert Array Data into tbl_bin_group_detail
CType(fMainForm, frmPLUpload).pgBar.Value = 0
CType(fMainForm, frmPLUpload).pgBar.Max = 2688
For i = 0 To 2687
CType(fMainForm, frmPLUpload).pgBar.Value = CType(fMainForm, frmPLUpload).pgBar.Value + 1
CType(fMainForm, frmPLUpload).sbStatus.Panels(1).Text = "Picking: Channel - " & pChannelID & " | Library - " & MyDataRow1("library_id") & " | Version - " & MyDataRow1("version_number") & " | Table - " & i
CType(fMainForm, frmPLUpload).Refresh()
MySQL = ""
MySQL = MySQL & " INSERT INTO tbl_bin_group_detail"
MySQL = MySQL & " (bin_group_id, library_id, version_number, revision_number,"
MySQL = MySQL & " schedule_day, schedule_hour, schedule_slot, content_id, rating_id, audio_rating_id,"
MySQL = MySQL & " scheduled_type_id, scheduled_date, scheduled_user)"
MySQL = MySQL & " VALUES"
MySQL = MySQL & " (" & MyDataRow1("primary_bin_group_id") & ", "
MySQL = MySQL & MyDataRow1("library_id") & ", "
MySQL = MySQL & MyDataRow1("version_number") & ", "
MySQL = MySQL & mRevNum & ", "
MySQL = MySQL & mBinArray(0, i) & ", " 'Day
MySQL = MySQL & mBinArray(1, i) & ", " 'Hour
MySQL = MySQL & mBinArray(2, i) & ", " 'Slot
MySQL = MySQL & mBinArray(3, i) & ", " 'Content_id
MySQL = MySQL & mBinArray(5, i) & ", " 'Rating
MySQL = MySQL & mBinArray(6, i) & ", " 'Audio_Rating
MySQL = MySQL & "2, '" & Today & "', '" & gPLServer & "')"
MyCommandExec = New SqlCommand(MySQL, gDBCon)
MyCommandExec.ExecuteNonQuery()
MyCommandExec.Dispose()
'MyRSTExec.Open(MySQL, gDB, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
mBinArray(0, i) = 0
mBinArray(1, i) = 0
mBinArray(2, i) = 0
mBinArray(3, i) = 0
mBinArray(4, i) = 0
mBinArray(5, i) = 0
mBinArray(6, i) = 0
Next i
End If
MySQL = ""
MySQL = MySQL & " SELECT Count(content_id) AS ContentCount"
MySQL = MySQL & " FROM tbl_bin_group_detail"
MySQL = MySQL & " WHERE bin_group_id = " & MyDataRow1("primary_bin_group_id")
MySQL = MySQL & " AND library_id = " & MyDataRow1("library_id")
MySQL = MySQL & " AND version_number = " & MyDataRow1("version_number")
MySQL = MySQL & " AND revision_number = " & mRevNum
MyCommand = New SqlCommand(MySQL, gDBCon)
MyAdaptor2 = New SqlDataAdapter(MyCommand)
MyDataset2 = New DataSet
MyAdaptor2.Fill(MyDataset2, "DataTable")
MyCommand.Dispose()
'MyRST2.Open(MySQL, gDB, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
If MyDataset2.Tables("DataTable").Rows.Count = 0 Then 'If MyRST2.EOF Then
varFromDisplay = "Playlist Server"
varFrom = "playlist@clubcom.com"
varTo = "brandonmurray@clubcom.com,aljones@clubcom.com"
varCC = "blakekercovich@clubcom.com,georgedumaine@clubcom.com,victorwashy@clubcom.com"
varBCC = ""
varSubject = "Template Picker Failure"
varMessage = ""
varMessage = varMessage & "Template Picking has failed for the following:"
varMessage = varMessage & vbCrLf
varMessage = varMessage & "Channel ID# " & pChannelID
varMessage = varMessage & vbCrLf
varMessage = varMessage & "Library ID# " & MyDataRow1("library_id")
varMessage = varMessage & vbCrLf
varMessage = varMessage & "Version # " & MyDataRow1("version_number")
varMessage = varMessage & vbCrLf
varMessage = varMessage & "Revision # " & mRevNum
varMessage = varMessage & vbCrLf
varMessage = varMessage & "Bin Group ID # " & MyDataRow1("primary_bin_group_id")
varMessage = varMessage & vbCrLf
varMessage = varMessage & vbCrLf
varMessage = varMessage & gPLServer
Call SMTPMail.SendMail(varFromDisplay, varFrom, varTo, varCC, varBCC, varSubject, varMessage)
gLogFile.WriteLine(CStr(Now) & Chr(9) & "Template_Picker" & Chr(9) & "Template picking failed for Channel ID# " & pChannelID & " Library ID# " & MyDataRow1("library_id") & " Version # " & MyDataRow1("version_number") & " Revision # " & mRevNum & " Bin Group ID # " & MyDataRow1("primary_bin_group_id"))
gLogFile.Flush()
Else
MyDataRow2 = MyDataset2.Tables("DataTable").Rows(0)
If MyDataRow2("ContentCount") = 2688 Then 'If MyRST2.Fields("ContentCount").Value = 2688 Then
MySQL = ""
MySQL = MySQL & " UPDATE tbl_bin_group_versions"
MySQL = MySQL & " SET approved = 1, approved_by = 'TemplatePicker', approved_date = '" & Today & "'"
MySQL = MySQL & " WHERE bin_group_id = " & MyDataRow1("primary_bin_group_id")
MySQL = MySQL & " AND library_id = " & MyDataRow1("library_id")
MySQL = MySQL & " AND version_number = " & MyDataRow1("version_number")
MySQL = MySQL & " AND revision_number = " & mRevNum
MyCommandExec = New SqlCommand(MySQL, gDBCon)
MyCommandExec.ExecuteNonQuery()
'MyRSTExec.Open(MySQL, gDB, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
Else
varFromDisplay = "Playlist Server"
varFrom = "playlist@clubcom.com"
varTo = "brandonmurray@clubcom.com,aljones@clubcom.com"
varCC = "blakekercovich@clubcom.com,georgedumaine@clubcom.com,victorwashy@clubcom.com"
varBCC = ""
varSubject = "Template Picker Failure"
varMessage = ""
varMessage = varMessage & "Template Picking has failed for the following:"
varMessage = varMessage & vbCrLf
varMessage = varMessage & "Channel ID# " & pChannelID
varMessage = varMessage & vbCrLf
varMessage = varMessage & "Library ID# " & MyDataRow1("library_id")
varMessage = varMessage & vbCrLf
varMessage = varMessage & "Version # " & MyDataRow1("version_number")
varMessage = varMessage & vbCrLf
varMessage = varMessage & "Revision # " & mRevNum
varMessage = varMessage & vbCrLf
varMessage = varMessage & "Bin Group ID # " & MyDataRow1("primary_bin_group_id")
varMessage = varMessage & vbCrLf
varMessage = varMessage & vbCrLf
varMessage = varMessage & gPLServer
Call SMTPMail.SendMail(varFromDisplay, varFrom, varTo, varCC, varBCC, varSubject, varMessage)
gLogFile.WriteLine(CStr(Now) & Chr(9) & "Template_Picker" & Chr(9) & "Template picking failed for Channel ID# " & pChannelID & " Library ID# " & MyDataRow1("library_id") & " Version # " & MyDataRow1("version_number") & " Revision # " & mRevNum & " Bin Group ID # " & MyDataRow1("primary_bin_group_id"))
gLogFile.Flush()
End If
End If
MyDataset2.Dispose()
MyAdaptor2.Dispose()
'MyRST2.Close()
End If 'End NeedToPick
'MyRST1.MoveNext()
Next MyDataRow1 'while not myRst1.eof
MyDataset1.Dispose()
MyAdaptor1.Dispose()
'MyRST1.Close()
varFromDisplay = "Playlist Server"
varFrom = "playlist@clubcom.com"
varTo = "brandonmurray@clubcom.com,aljones@clubcom.com"
varCC = "blakekercovich@clubcom.com,georgedumaine@clubcom.com,victorwashy@clubcom.com"
varBCC = ""
varSubject = "Template Picker Notification"
varMessage = ""
varMessage = varMessage & "Channel Templates have been picked for Channel ID# " & pChannelID
varMessage = varMessage & vbCrLf
varMessage = varMessage & vbCrLf
varMessage = varMessage & gPLServer
[b]Call SMTPMail.SendMail(varFromDisplay, varFrom, varTo, varCC, varBCC, varSubject, varMessage)[/b]
gLogFile.WriteLine(CStr(Now) & Chr(9) & "Template_Picker" & Chr(9) & "Channel Templates have been picked for Channel ID# " & pChannelID)
gLogFile.Flush()
CType(fMainForm, frmPLUpload).pgBar.Value = 0
CType(fMainForm, frmPLUpload).sbStatus.Panels(1).Text = "RUNNING..."
CType(fMainForm, frmPLUpload).Refresh()
GoTo Template_Picker_EXIT
Template_Picker_ERROR:
If File.Exists("C:\SERVER_ALIVE") = True Then
Kill("C:\SERVER_ALIVE")
End If
gLogFile.WriteLine(CStr(Now) & Chr(9) & "Template_Picker" & Chr(9) & "ERROR: " & Err.Number & " - " & Err.Description)
gLogFile.Flush()
Call MsgBox("ERROR: " & Err.Number & " - " & Err.Description, MsgBoxStyle.Critical)
Resume
Template_Picker_EXIT:
End Sub