Attribute VB_Name = "Status"
Option Explicit


'----------------------------------------------------------
'zmena barvy a napisu u prave vysilaneho textu, podle druhu
'----------------------------------------------------------

Sub Indikator()

    Select Case Indik
    
        Case 0:
            Frm1.LblStIndik.ForeColor = &H7D1A&
            Frm1.LblStIndik.Caption = GenerujNazevSouboru(Date) & ".rds"
        Case 1:
            Frm1.LblStIndik.ForeColor = &HFF00FF
            Frm1.LblStIndik.Caption = "Promo"
        Case 2:
            Frm1.LblStIndik.ForeColor = &H80FF&
            Frm1.LblStIndik.Caption = "Flash"
        Case 3:
            Frm1.LblStIndik.ForeColor = &HFF&
            Frm1.LblStIndik.Caption = "Náhradní Text"
        Case 4:
            Frm1.LblStIndik.ForeColor = &H80FF&
            Frm1.LblStIndik.Caption = "Testovací text"
        Case 5:
            Frm1.LblStIndik.ForeColor = &HFF&
            Frm1.LblStIndik.Caption = "Pondělní text"
        Case 6:
            Frm1.LblStIndik.ForeColor = &HFF&
            Frm1.LblStIndik.Caption = "Úterní text"
        Case 7:
            Frm1.LblStIndik.ForeColor = &HFF&
            Frm1.LblStIndik.Caption = "Středeční text"
        Case 8:
            Frm1.LblStIndik.ForeColor = &HFF&
            Frm1.LblStIndik.Caption = "Čtvrteční text"
        Case 9:
            Frm1.LblStIndik.ForeColor = &HFF&
            Frm1.LblStIndik.Caption = "Pátečni text"
        Case 10:
            Frm1.LblStIndik.ForeColor = &HFF&
            Frm1.LblStIndik.Caption = "Sobotní text"
        Case 11:
            Frm1.LblStIndik.ForeColor = &HFF&
            Frm1.LblStIndik.Caption = "Nedělni Text"
  
    End Select

End Sub


'----------------------------------------------------------
'vytvoreni testovaciho textu
'----------------------------------------------------------

Public Sub DoTest()

    If ((Second(Time) > 10) And (Second(Time) < 50)) Then

        Frm1.Timer2.Enabled = True
        OutString = Frm1.TxtStFlas.Text
        OutTyp = "POKUSNY TEXT  "
        OutStringStary = OutString
        Odeslat
    
    End If

End Sub


'----------------------------------------------------------
'zobrazeni prave vysilaneho textu
'----------------------------------------------------------

Public Sub PraveVysilameZobr(KK As String)
    
    Frm1.LblStStat.ForeColor = &H0&
    Frm1.LblStStat = Left(OutString, 64)
    Frm1.LblStatusKdy.Caption = KK
    Indikator
    
End Sub


'----------------------------------------------------------
'zobrazeni vysilaciho planu
'----------------------------------------------------------

Public Sub VysilaciPlanZobr()
    
    Frm1.LblVysCas7.Caption = LabelCas(-3)
    Frm1.LblVysCas6.Caption = LabelCas(-2)
    Frm1.LblVysCas5.Caption = LabelCas(-1)
    Frm1.LblVysCas4.Caption = LabelCas(0)
    Frm1.LblVysCas3.Caption = LabelCas(1)
    Frm1.LblVysCas2.Caption = LabelCas(2)
    Frm1.LblVysCas1.Caption = LabelCas(3)

    Frm1.TxtStVys7.Text = VysPlan(CisloRadku)
    Frm1.TxtStVys6.Text = VysPlan(CisloRadku + 1)
    Frm1.TxtStVys5.Text = VysPlan(CisloRadku + 2)
    Frm1.TxtStVys4.Text = VysPlan(CisloRadku + 3)
    Frm1.TxtStVys3.Text = VysPlan(CisloRadku + 4)
    Frm1.TxtStVys2.Text = VysPlan(CisloRadku + 5)
    Frm1.TxtStVys1.Text = VysPlan(CisloRadku + 6)

    Frm1.TxtStPromo7.Text = VysPromo(CisloRadku)
    Frm1.TxtStPromo6.Text = VysPromo(CisloRadku + 1)
    Frm1.TxtStPromo5.Text = VysPromo(CisloRadku + 2)
    Frm1.TxtStPromo4.Text = VysPromo(CisloRadku + 3)
    Frm1.TxtStPromo3.Text = VysPromo(CisloRadku + 4)
    Frm1.TxtStPromo2.Text = VysPromo(CisloRadku + 5)
    Frm1.TxtStPromo1.Text = VysPromo(CisloRadku + 6)
    
    DoEvents

End Sub


'----------------------------------------------------------
'fce pro spravne zobrazeni aktualnich casu u vysilaciho planu
'----------------------------------------------------------

Public Function LabelCas(ByVal InCas As Integer) As String

    Dim poc As Integer

    poc = Minute(Time) + InCas

    If (poc < 0) Then
    
        If ((Prevod(Hour(Time) - 1) + ":" + Prevod(60 + poc)) > "0:00") Then
            LabelCas = Prevod(Hour(Time) - 1) + ":" + Prevod(60 + poc)
        Else
            LabelCas = ""
        End If

    ElseIf (poc > 59) Then
        
        If ((Prevod(Hour(Time) + 1) + ":" + Prevod(poc - 60)) < "23:59") Then
            LabelCas = Prevod(Hour(Time) + 1) + ":" + Prevod(poc - 60)
        Else
            LabelCas = ""
        End If
               
    Else
    
        LabelCas = Prevod(Hour(Time)) + ":" + Prevod(poc)

    End If

End Function


'----------------------------------------------------------
'nacteni proma a vysilaciho planu
'----------------------------------------------------------

Public Sub DenniProgram(Dat As Date)

    VysilaciPlan Dat
    PlanProma Dat
    DoEvents

End Sub


'----------------------------------------------------------
'nacteni denniho vysilaciho planu na konktretni den
'----------------------------------------------------------

Public Sub VysilaciPlan(Dat As Date)

    Dim i As Integer
    Dim nazev As String

On Error GoTo ChybaVP

    For i = 0 To 1445
        VysPlan(i) = ""
    Next i

    Open CestaSoubory & "/RDS-Texty/" & GenerujNazevSouboru(Dat) & ".rds" For Input As #3
  
        For i = 3 To 1442
            Line Input #3, VysPlan(i)
        Next i

    Close #3
    
    Frm1.LblStaNH.Caption = GenerujNazevSouboru(Dat) & ".rds"

Exit Sub

ChybaVP:
    
    Select Case Weekday(Date, vbMonday)
        
        Case 1: nazev = "PondelniText"
                If (Dir(CestaSoubory & "/RDS-Texty/" & nazev & ".rds") <> "") Then
                    Frm1.LblStaNH.Caption = "Pondělní text"
                Else
                    nazev = "NahradniText"
                    Frm1.LblStaNH.Caption = "Náhradní text"
                End If
        Case 2: nazev = "UterniText"
                If (Dir(CestaSoubory & "/RDS-Texty/" & nazev & ".rds") <> "") Then
                    Frm1.LblStaNH.Caption = "Úterní text"
                Else
                    nazev = "NahradniText"
                    Frm1.LblStaNH.Caption = "Náhradní text"
                End If
        Case 3: nazev = "StredecniText"
                If (Dir(CestaSoubory & "/RDS-Texty/" & nazev & ".rds") <> "") Then
                    Frm1.LblStaNH.Caption = "Středeční text"
                Else
                    nazev = "NahradniText"
                    Frm1.LblStaNH.Caption = "Náhradní text"
                End If
        Case 4: nazev = "CtvrtecniText"
                If (Dir(CestaSoubory & "/RDS-Texty/" & nazev & ".rds") <> "") Then
                    Frm1.LblStaNH.Caption = "Čtvrteční text"
                Else
                    nazev = "NahradniText"
                    Frm1.LblStaNH.Caption = "Náhradní text"
                End If
        Case 5: nazev = "PatecniText"
                If (Dir(CestaSoubory & "/RDS-Texty/" & nazev & ".rds") <> "") Then
                    Frm1.LblStaNH.Caption = "Páteční text"
                Else
                    nazev = "NahradniText"
                    Frm1.LblStaNH.Caption = "Náhradní text"
                End If
        Case 6: nazev = "SobotniText"
                If (Dir(CestaSoubory & "/RDS-Texty/" & nazev & ".rds") <> "") Then
                    Frm1.LblStaNH.Caption = "Sobotní text"
                Else
                    nazev = "NahradniText"
                    Frm1.LblStaNH.Caption = "Náhradní text"
                End If
        Case 7: nazev = "NedelniText"
                If (Dir(CestaSoubory & "/RDS-Texty/" & nazev & ".rds") <> "") Then
                    Frm1.LblStaNH.Caption = "Nedělní text"
                Else
                    nazev = "NahradniText"
                    Frm1.LblStaNH.Caption = "Náhradní text"
                End If
        
            
    End Select
        
    If (Dir(CestaSoubory & "/RDS-Texty/" & nazev & ".rds") <> "") Then
            
        Open CestaSoubory & "/RDS-Texty/" & nazev & ".rds" For Input As #3
            For i = 3 To 1442
                Line Input #3, VysPlan(i)
            Next i
        Close #3
    Else
        For i = 0 To 1450
            VysPlan(i) = "******************** CHYBA ********************"
        Next i
        Frm1.LblStaNH.Caption = " "
        ZapisSystemLog "NAHRADNI TEXT ERROR", "Nepodarilo se nacist soubor nahradniho textu"
        OdesliEmail "RDSManager Error", 1, "Nepodarilo se nacist soubor nahradniho textu!!"
    End If

End Sub


'----------------------------------------------------------
'kompletace prom
'----------------------------------------------------------

Public Sub PlanProma(Dat As Date)
    
    Dim i As Integer
    Dim j As Integer

    For i = 0 To 1446
        VysPromo(i) = ""
    Next i

    j = 5
    
    Do While (j > 0)
        NacteniPlanuProma j, Dat
        j = j - 1
    Loop

End Sub


'----------------------------------------------------------
'nacteni jednotlivych prom na konkretni den
'----------------------------------------------------------

Public Sub NacteniPlanuProma(ind As Integer, Dat As Date)
    
    Dim i As Integer
    Dim Ppom As String

    If (Dir(CestaSoubory & "/RDS-Promo/RDS-Promo" & CStr(ind) & "/" & GenerujNazevSouboru(Dat) & "Promo" & CStr(ind) & ".rds") <> "") Then

        Open CestaSoubory & "/RDS-Promo/RDS-Promo" & CStr(ind) & "/" & GenerujNazevSouboru(Dat) & "Promo" & CStr(ind) & ".rds" For Input As #5
   
            For i = 4 To 1443
  
                Line Input #5, Ppom
                    
                    If (Ppom <> "") Then
                        VysPromo(i) = "Promo" & CStr(ind)
                    End If
            Next i

        Close #5

    End If

End Sub


'----------------------------------------------------------
'kontrola zmen v dennim textu nebo v promu
'----------------------------------------------------------

Public Sub KonZmeny(Dat As Date)
    
    Dim fl As File
    Dim fil As File
    Dim flDen As File
    Dim i, j As Integer
    Dim nazev As String
    Dim PomPole(1442) As String

    If (Dir(CestaSoubory & "/RDS-Texty/" & GenerujNazevSouboru(Date) & ".rds") <> "") Then
        Set fl = fso.GetFile(CestaSoubory & "/RDS-Texty/" & GenerujNazevSouboru(Date) & ".rds")

        If (SouborDenniTextCasModifikace <> fl.DateLastModified) Then
        
            Open CestaSoubory & "/RDS-Texty/" & GenerujNazevSouboru(Date) & ".rds" For Input As #9
                For i = 0 To 1442
                    Line Input #9, PomPole(i)
                Next i
            Close #9
            
            If (PomPole(1440) = "") Then
                DataDoPole Dat
                DenniProgram Dat
                SouborDenniTextCasModifikace = fl.DateLastModified
            End If
    
        End If
        
    End If
    
    Select Case Weekday(Date, vbMonday)
        
        Case 1: nazev = "PondelniText"
        Case 2: nazev = "UterniText"
        Case 3: nazev = "StredecniText"
        Case 4: nazev = "CtvrtecniText"
        Case 5: nazev = "PatecniText"
        Case 6: nazev = "SobotniText"
        Case 7: nazev = "NedelniText"
  
    End Select
    
    If (Dir(CestaSoubory & "/RDS-Texty/" & nazev & ".rds") <> "") Then
        Set flDen = fso.GetFile(CestaSoubory & "/RDS-Texty/" & nazev & ".rds")

        If (SouborTextNaDnyCasModifikace <> flDen.DateLastModified) Then
        
            Open CestaSoubory & "/RDS-Texty/" & nazev & ".rds" For Input As #9
                For i = 0 To 1442
                    Line Input #9, PomPole(i)
                Next i
            Close #9
            
            If (PomPole(1440) = "") Then
                DenniProgram Dat
                SouborTextNaDnyCasModifikace = flDen.DateLastModified
            End If
            
        End If
        
    End If

    For i = 0 To 5

        If (Dir(CestaSoubory & "/RDS-Promo/RDS-Promo" & CStr(i) & "/" & GenerujNazevSouboru(Dat) & "Promo" & CStr(i) & ".rds") <> "") Then
            Set fil = fso.GetFile(CestaSoubory & "/RDS-Promo/RDS-Promo" & CStr(i) & "/" & GenerujNazevSouboru(Dat) & "Promo" & CStr(i) & ".rds")

            If (SouborPromoCasModifikace(i) <> fil.DateLastModified) Then
                
                Open CestaSoubory & "/RDS-Texty/" & nazev & ".rds" For Input As #9
                    For j = 0 To 1442
                        Line Input #9, PomPole(j)
                    Next j
                Close #9

                If (PomPole(1440) = "") Then
                    DataDoPole Dat
                    DenniProgram Dat
                End If
    
            End If
            
        End If

    Next i

End Sub
