Attribute VB_Name = "Status"
Option Explicit


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

Sub Indikator()

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

End Sub


'----------------------------------------------------------
'vytvoreni flash textu
'----------------------------------------------------------

Public Sub DoFlash()

    Form1.TxtStFlas.Enabled = False
    Form1.CmdStFlasOdeslat.BackColor = &H80FF80
    Form1.CmdStFlasOdeslat.Caption = "Odesláno a připraveno k odvysilani"
    Form1.CmdStFlasOdeslat.Enabled = False
    
    Open CestaSoubory & "/Flash.rds" For Output As #1 Len = 64
        Print #1, Form1.TxtStFlas.Text
    Close #1

End Sub


'----------------------------------------------------------
'zjisteni existence flash textu
'----------------------------------------------------------

Public Sub KontrolaFlash()

    If (anno = True) Then
        
        If (Dir(CestaSoubory & "/Flash.rds") <> "") Then
        Else
            Form1.CmdStFlasOdeslat.Enabled = True
            Form1.CmdStFlasOdeslat.BackColor = &HE9A952
            Form1.CmdStFlasOdeslat.Caption = "Odeslat a připravit k odvysílání"
            Form1.TxtStFlas.Enabled = True
        End If
          
    End If

End Sub


'----------------------------------------------------------
'nacteni prave vysilaneho textu
'----------------------------------------------------------

Public Sub PraveVysilame()

    Dim fl As File
    

    If (Dir(CestaSoubory & "/PraveVysilame.rds") <> "") Then
        Set fl = fso.GetFile(CestaSoubory & "/PraveVysilame.rds")

            If (FLPosledniZmena <> fl.DateLastModified) Then
                FLpom = 0
                Form1.LblStatusKdy.BackColor = &HFBC695
                Form1.LblStatusErr.Visible = False
                FLPosledniZmena = fl.DateLastModified
                
                Open CestaSoubory & "/PraveVysilame.rds" For Input As #2
                    Line Input #2, PomRetez
                    Indik = CInt(Left(PomRetez, 2))
                    Kpom = Mid(PomRetez, 3, 17)
                    PomRetez = Mid(PomRetez, 20, 64)
                    Form1.LblStStat.ForeColor = &H800000
                Close #2
    
            Else
                FLpom = FLpom + 1
        
                If (FLpom > 3) Then
                    Form1.LblStatusKdy.BackColor = &H8080FF
                    Form1.LblStatusErr.Visible = True
                End If
        
            End If

    Else
        PomRetez = "**** NEBYLO MOŽNO NAČÍST INFORMACE O VYSÍLANÉM TEXTU!!!! ****"
        Form1.LblStStat.ForeColor = &H2248FF
        Indik = 5

    End If

End Sub


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

Public Sub PraveVysilameZobr()
    
    Form1.LblStatusKdy.Caption = Kpom
    Form1.LblStStat = PomRetez
    Indikator
    
End Sub


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

Public Sub VysilaciPlanZobr()

    Form1.LblVysCas7.Caption = LabelCas(-3)
    Form1.LblVysCas6.Caption = LabelCas(-2)
    Form1.LblVysCas5.Caption = LabelCas(-1)
    Form1.LblVysCas4.Caption = LabelCas(0)
    Form1.LblVysCas3.Caption = LabelCas(1)
    Form1.LblVysCas2.Caption = LabelCas(2)
    Form1.LblVysCas1.Caption = LabelCas(3)
    Form1.LblVysCas0.Caption = LabelCas(4)
    Form1.LblVysCas01.Caption = LabelCas(5)
    Form1.LblVysCas02.Caption = LabelCas(6)
    Form1.LblVysCas03.Caption = LabelCas(7)
    
    Form1.LblStVys7.Caption = VysPlan(Vypocet)
    Form1.LblStVys6.Caption = VysPlan(Vypocet + 1)
    Form1.LblStVys5.Caption = VysPlan(Vypocet + 2)
    Form1.LblStVys4.Caption = VysPlan(Vypocet + 3)
    Form1.LblStVys3.Caption = VysPlan(Vypocet + 4)
    Form1.LblStVys2.Caption = VysPlan(Vypocet + 5)
    Form1.LblStVys1.Caption = VysPlan(Vypocet + 6)
    Form1.LblStVys0.Caption = VysPlan(Vypocet + 7)
    Form1.LblStVys01.Caption = VysPlan(Vypocet + 8)
    Form1.LblStVys02.Caption = VysPlan(Vypocet + 9)
    Form1.LblStVys03.Caption = VysPlan(Vypocet + 10)
    
    Form1.LblStPromo7.Caption = VysPromo(Vypocet)
    Form1.LblStPromo6.Caption = VysPromo(Vypocet + 1)
    Form1.LblStPromo5.Caption = VysPromo(Vypocet + 2)
    Form1.LblStPromo4.Caption = VysPromo(Vypocet + 3)
    Form1.LblStPromo3.Caption = VysPromo(Vypocet + 4)
    Form1.LblStPromo2.Caption = VysPromo(Vypocet + 5)
    Form1.LblStPromo1.Caption = VysPromo(Vypocet + 6)
    Form1.LblStPromo0.Caption = VysPromo(Vypocet + 7)
    Form1.LblStPromo01.Caption = VysPromo(Vypocet + 8)
    Form1.LblStPromo02.Caption = VysPromo(Vypocet + 9)
    Form1.LblStPromo03.Caption = VysPromo(Vypocet + 10)

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

End Sub


'----------------------------------------------------------
'nacteni vysilaciho planu
'----------------------------------------------------------

Public Sub VysilaciPlan(dat As Date)

 Dim i As Integer
 Dim nazev As String

    On Error GoTo ChybaVP

        For i = 0 To 1450
            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
        
        Form1.LblStaNH.Caption = dat

    Exit Sub

ChybaVP:
    
    Select Case Weekday(Date, vbMonday)
        
        Case 1: nazev = "PondelniText"
                If (Dir(CestaSoubory & "/RDS-Texty/" & nazev & ".rds") <> "") Then
                    Form1.LblStaNH.Caption = "Pondělní text"
                Else
                    nazev = "NahradniText"
                    Form1.LblStaNH.Caption = "Náhradní text"
                End If
        Case 2: nazev = "UterniText"
                If (Dir(CestaSoubory & "/RDS-Texty/" & nazev & ".rds") <> "") Then
                    Form1.LblStaNH.Caption = "Úterní text"
                Else
                    nazev = "NahradniText"
                    Form1.LblStaNH.Caption = "Náhradní text"
                End If
        Case 3: nazev = "StredecniText"
                If (Dir(CestaSoubory & "/RDS-Texty/" & nazev & ".rds") <> "") Then
                    Form1.LblStaNH.Caption = "Středeční text"
                Else
                    nazev = "NahradniText"
                    Form1.LblStaNH.Caption = "Náhradní text"
                End If
        Case 4: nazev = "CtvrtecniText"
                If (Dir(CestaSoubory & "/RDS-Texty/" & nazev & ".rds") <> "") Then
                    Form1.LblStaNH.Caption = "Čtvrteční text"
                Else
                    nazev = "NahradniText"
                    Form1.LblStaNH.Caption = "Náhradní text"
                End If
        Case 5: nazev = "PatecniText"
                If (Dir(CestaSoubory & "/RDS-Texty/" & nazev & ".rds") <> "") Then
                    Form1.LblStaNH.Caption = "Páteční text"
                Else
                    nazev = "NahradniText"
                    Form1.LblStaNH.Caption = "Náhradní text"
                End If
        Case 6: nazev = "SobotniText"
                If (Dir(CestaSoubory & "/RDS-Texty/" & nazev & ".rds") <> "") Then
                    Form1.LblStaNH.Caption = "Sobotní text"
                Else
                    nazev = "NahradniText"
                    Form1.LblStaNH.Caption = "Náhradní text"
                End If
        Case 7: nazev = "NedelniText"
                If (Dir(CestaSoubory & "/RDS-Texty/" & nazev & ".rds") <> "") Then
                    Form1.LblStaNH.Caption = "Nedělní text"
                Else
                    nazev = "NahradniText"
                    Form1.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
        Form1.LblStaNH.Caption = " "
    End If
        
End Sub


'----------------------------------------------------------
'nacteni proma
'----------------------------------------------------------

Public Sub PlanProma(dat As Date)

    Dim i As Integer
    Dim j As Integer

    For i = 0 To 1451
        VysPromo(i) = ""
    Next i
    
    j = 5
        
    Do While (j > 0)
        NacteniPlanuProma j, dat
        j = j - 1
    Loop

End Sub


'----------------------------------------------------------
'kompletace proma
'----------------------------------------------------------

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 As Integer
    Dim nazev 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
            DenniProgram dat
            SouborDenniTextCasModifikace = fl.DateLastModified
        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
            DenniProgram dat
            SouborTextNaDnyCasModifikace = flDen.DateLastModified
        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
                DenniProgram dat
            End If
            
        End If

    Next i

End Sub

