Attribute VB_Name = "Ini"
Option Explicit

   
'----------------------------------------------------------
'nacteni cesty k souborum z cfg
'----------------------------------------------------------

Public Sub CteniCfg()

    Dim i As Integer
    Dim kam As String

    Bafr = Space(100)
            
    Delka = GetPrivateProfileString _
        ("Config", "CestaSoubory", "C:\", Bafr, 100, (Cesta & "\RDSEdit.cfg"))
        CestaSoubory = Left(Bafr, Delka)
        
End Sub
    
    
'----------------------------------------------------------
'nacteni setupu z ini
'----------------------------------------------------------
    
Public Sub CteniIni()

    Dim i As Integer
    Dim kam As String
    
    Bafr = Space(100)
        
    Delka = GetPrivateProfileString _
        ("Config", "Maska", "%yyy-%m-%d", Bafr, 100, (CestaSoubory & "\RDSEdit.ini"))
        Maska = Left(Bafr, Delka)
        
    Delka = GetPrivateProfileString _
        ("Spravce", "Heslo", "0", Bafr, 100, (CestaSoubory & "\RDSEdit.ini"))
        HesloSpravce = DEKrypt(Left(Bafr, Delka))
    
    For i = 0 To 9

        Select Case i:
        
            Case 0: kam = "User1"
            Case 1: kam = "User2"
            Case 2: kam = "User3"
            Case 3: kam = "User4"
            Case 4: kam = "User5"
            Case 5: kam = "User6"
            Case 6: kam = "User7"
            Case 7: kam = "User8"
            Case 8: kam = "User9"
            Case 9: kam = "User10"
            
        End Select
        
        Delka = GetPrivateProfileString _
            (kam, "Jmeno", "0", Bafr, 100, (CestaSoubory & "\RDSEdit.ini"))
            Jmeno(i) = Left(Bafr, Delka)
            
        Form1.TxtName(i).Text = Jmeno(i)
        
        Delka = GetPrivateProfileString _
            (kam, "Heslo", "0", Bafr, 100, (CestaSoubory & "\RDSEdit.ini"))
            Heslo(i) = Left(Bafr, Delka)
        
        If (Heslo(i) <> "") Then
            Heslo(i) = DEKrypt(Heslo(i))
        End If
        
        Form1.TxtUHeslo(i).Text = Heslo(i)
        Form1.TxtUHesloP(i).Text = Heslo(i)
        
        Delka = GetPrivateProfileString _
            (kam, "Prava", "0", Bafr, 100, (CestaSoubory & "\RDSEdit.ini"))
            Prava(i) = Left(Bafr, Delka)
            
        If (Mid(Prava(i), 1, 1) <> "A") Then
            Form1.ChckFlash(i).Value = 0
        Else: Form1.ChckFlash(i).Value = 1
        End If
    
        If (Mid(Prava(i), 2, 1) <> "A") Then
            Form1.ChckText(i).Value = 0
        Else: Form1.ChckText(i).Value = 1
        End If
               
        If (Mid(Prava(i), 3, 1) <> "A") Then
            Form1.ChckPromo(i).Value = 0
        Else: Form1.ChckPromo(i).Value = 1
        End If
        
    Next i
        
End Sub


'----------------------------------------------------------
'ulozeni setupu do ini
'----------------------------------------------------------

 Public Sub ZapisIni()
 
    Dim Stav As Integer
            
    Stav = WritePrivateProfileString _
      ("Config", "CestaSoubory", CestaSoubory, (Cesta & "\RDSEdit.cfg"))
     
End Sub


'----------------------------------------------------------
'ulozeni hesla do ini
'----------------------------------------------------------

 Public Sub ZapisHeslo()
 
    Dim i As Integer
    Dim kam As String
    Dim Stav As Integer
    
    For i = 0 To 9
    
        Select Case i:
        
            Case 0: kam = "User1"
            Case 1: kam = "User2"
            Case 2: kam = "User3"
            Case 3: kam = "User4"
            Case 4: kam = "User5"
            Case 5: kam = "User6"
            Case 6: kam = "User7"
            Case 7: kam = "User8"
            Case 8: kam = "User9"
            Case 9: kam = "User10"
        
        End Select
        
        Stav = WritePrivateProfileString _
                (kam, "Jmeno", Jmeno(i), (CestaSoubory & "\RDSEdit.ini"))
        
        Stav = WritePrivateProfileString _
                (kam, "Heslo", Heslo(i), (CestaSoubory & "\RDSEdit.ini"))
        
        Stav = WritePrivateProfileString _
                (kam, "Prava", Prava(i), (CestaSoubory & "\RDSEdit.ini"))
    
    Next i
                 
 End Sub
 
 
'----------------------------------------------------------
'zapsani proma do ini
'----------------------------------------------------------
 
Public Sub ZapisPromoDoIni(ind As Integer)

    Dim Stav As Integer
    Dim pom As String
    Dim i As Integer
    Dim kam As String
           
    Select Case ind:
        
        Case 0: kam = "Promo1"
        Case 1: kam = "Promo2"
        Case 2: kam = "Promo3"
        Case 3: kam = "Promo4"
        Case 4: kam = "Promo5"
         
    End Select
    
    pom = Form1.TxtProPoznamka(ind).Text
         Stav = WritePrivateProfileString _
             (kam, "Poznamka", pom, (CestaSoubory & "\RDSEdit.ini"))

     pom = Form1.TxtProText(ind).Text
         Stav = WritePrivateProfileString _
             (kam, "Text", pom, (CestaSoubory & "\RDSEdit.ini"))
                    
    Ovladani(ind) = "NNNNNNNNN"
    
    If (Form1.ChckProPo(ind).Value = 1) Then
        Mid(Ovladani(ind), 1) = "A"
    End If
    If (Form1.ChckProUt(ind).Value = 1) Then
        Mid(Ovladani(ind), 2) = "A"
    End If
    If (Form1.ChckProSt(ind).Value = 1) Then
        Mid(Ovladani(ind), 3) = "A"
    End If
    If (Form1.ChckProCt(ind).Value = 1) Then
        Mid(Ovladani(ind), 4) = "A"
    End If
    If (Form1.ChckProPa(ind).Value = 1) Then
        Mid(Ovladani(ind), 5) = "A"
    End If
    If (Form1.ChckProSo(ind).Value = 1) Then
        Mid(Ovladani(ind), 6) = "A"
    End If
    If (Form1.ChckProNe(ind).Value = 1) Then
        Mid(Ovladani(ind), 7) = "A"
    End If

    Stav = WritePrivateProfileString _
            (kam, "Ovladani", Ovladani(ind), (CestaSoubory & "\RDSEdit.ini"))
    
    pom = Prevod(Form1.TxtProOdDen(ind).Text)
        Stav = WritePrivateProfileString _
            (kam, "Txt1", pom, (CestaSoubory & "\RDSEdit.ini"))
    pom = Prevod(Form1.TxtProDoDen(ind).Text)
        Stav = WritePrivateProfileString _
            (kam, "Txt2", pom, (CestaSoubory & "\RDSEdit.ini"))
    pom = Prevod(Form1.TxtProOdMes(ind).Text)
        Stav = WritePrivateProfileString _
            (kam, "Txt3", pom, (CestaSoubory & "\RDSEdit.ini"))
    pom = Prevod(Form1.TxtProDoMes(ind).Text)
        Stav = WritePrivateProfileString _
            (kam, "Txt4", pom, (CestaSoubory & "\RDSEdit.ini"))
    pom = Form1.TxtProOdRok(ind).Text
        Stav = WritePrivateProfileString _
            (kam, "Txt5", pom, (CestaSoubory & "\RDSEdit.ini"))
    pom = Form1.TxtProDoRok(ind).Text
        Stav = WritePrivateProfileString _
            (kam, "Txt6", pom, (CestaSoubory & "\RDSEdit.ini"))
    pom = Form1.TxtProPCHod(ind).Text
        Stav = WritePrivateProfileString _
            (kam, "Txt7", pom, (CestaSoubory & "\RDSEdit.ini"))
    pom = Form1.TxtProPCMin(ind).Text
        Stav = WritePrivateProfileString _
            (kam, "Txt8", pom, (CestaSoubory & "\RDSEdit.ini"))
    pom = Form1.TxtProOdHod(ind).Text
        Stav = WritePrivateProfileString _
            (kam, "Txt9", pom, (CestaSoubory & "\RDSEdit.ini"))
    pom = Form1.TxtProDoHod(ind).Text
        Stav = WritePrivateProfileString _
            (kam, "Txt10", pom, (CestaSoubory & "\RDSEdit.ini"))
    pom = Form1.TxtProOdMin(ind).Text
        Stav = WritePrivateProfileString _
            (kam, "Txt11", pom, (CestaSoubory & "\RDSEdit.ini"))
    pom = Form1.TxtProDoMin(ind).Text
        Stav = WritePrivateProfileString _
            (kam, "Txt12", pom, (CestaSoubory & "\RDSEdit.ini"))
    pom = Form1.TxtProPocOpak(ind).Text
        Stav = WritePrivateProfileString _
            (kam, "Txt13", pom, (CestaSoubory & "\RDSEdit.ini"))
            
            
   List = CStr(Prevod(Form1.LstPromoCasy(ind).ListCount)) & "-"
    
   For i = 1 To Form1.LstPromoCasy(ind).ListCount
        List = List & PromoCas(i, (ind)) & ","
   Next i
        
        Stav = WritePrivateProfileString _
            (kam, "List", List, (CestaSoubory & "\RDSEdit.ini"))
        
    
End Sub


'----------------------------------------------------------
'nacteni proma z ini
'----------------------------------------------------------

Public Sub CteniPromozIni()

    Dim Stav As Integer
    Dim pom As String
    Dim poc As Integer
    Dim a As Integer
    Dim i As Integer
    Dim j As Integer
    Dim kam As String
    Dim dat As String
    
    Bafr = Space(200)
    
    For j = 0 To 4

        List = ""
    
        Select Case j:
        
            Case 0: kam = "Promo1"
            Case 1: kam = "Promo2"
            Case 2: kam = "Promo3"
            Case 3: kam = "Promo4"
            Case 4: kam = "Promo5"
         
        End Select
    
    
        Delka = GetPrivateProfileString _
            (kam, "Text", "", Bafr, 100, (CestaSoubory & "\RDSEdit.ini"))
            PromoText(j) = Left(Bafr, Delka)
            Form1.TxtProText(j).Text = PromoText(j)
            
        Delka = GetPrivateProfileString _
            (kam, "Ovladani", "", Bafr, 100, (CestaSoubory & "\RDSEdit.ini"))
            Ovladani(j) = Left(Bafr, Delka)
            
        Delka = GetPrivateProfileString _
            (kam, "Poznamka", "", Bafr, 100, (CestaSoubory & "\RDSEdit.ini"))
            PromoPozn(j) = Left(Bafr, Delka)
            Form1.TxtProPoznamka(j).Text = PromoPozn(j)
            
        If (Left(Ovladani(j), 1) = "A") Then
            Form1.ChckProPo(j).Value = 1
        Else: Form1.ChckProPo(j).Value = 0
        End If
        
        If (Mid(Ovladani(j), 2, 1) = "A") Then
            Form1.ChckProUt(j).Value = 1
        Else: Form1.ChckProUt(j).Value = 0
        End If
    
        If (Mid(Ovladani(j), 3, 1) = "A") Then
            Form1.ChckProSt(j).Value = 1
        Else: Form1.ChckProSt(j).Value = 0
        End If
        
        If (Mid(Ovladani(j), 4, 1) = "A") Then
            Form1.ChckProCt(j).Value = 1
        Else: Form1.ChckProCt(j).Value = 0
        End If
        
        If (Mid(Ovladani(j), 5, 1) = "A") Then
            Form1.ChckProPa(j).Value = 1
        Else: Form1.ChckProPa(j).Value = 0
        End If
        
        If (Mid(Ovladani(j), 6, 1) = "A") Then
            Form1.ChckProSo(j).Value = 1
        Else: Form1.ChckProSo(j).Value = 0
        End If
        
        If (Mid(Ovladani(j), 7, 1) = "A") Then
            Form1.ChckProNe(j).Value = 1
        Else: Form1.ChckProNe(j).Value = 0
        End If
            
        Delka = GetPrivateProfileString _
            (kam, "Txt1", "", Bafr, 100, (CestaSoubory & "\RDSEdit.ini"))
            dat = Left(Bafr, Delka)
        PromoDatum(j, 1) = dat
        Form1.TxtProOdDen(j).Text = dat
        
        Delka = GetPrivateProfileString _
            (kam, "Txt2", "", Bafr, 100, (CestaSoubory & "\RDSEdit.ini"))
            dat = Left(Bafr, Delka)
        PromoDatum(j, 2) = dat
        Form1.TxtProDoDen(j).Text = dat
            
        Delka = GetPrivateProfileString _
            (kam, "Txt3", "", Bafr, 100, (CestaSoubory & "\RDSEdit.ini"))
            dat = Left(Bafr, Delka)
        PromoDatum(j, 1) = PromoDatum(j, 1) & dat
        Form1.TxtProOdMes(j).Text = dat
            
        Delka = GetPrivateProfileString _
            (kam, "Txt4", "", Bafr, 100, (CestaSoubory & "\RDSEdit.ini"))
            dat = Left(Bafr, Delka)
        PromoDatum(j, 2) = PromoDatum(j, 2) & dat
        Form1.TxtProDoMes(j).Text = dat
            
        Delka = GetPrivateProfileString _
            (kam, "Txt5", "", Bafr, 100, (CestaSoubory & "\RDSEdit.ini"))
            dat = Left(Bafr, Delka)
        PromoDatum(j, 1) = PromoDatum(j, 1) & dat
        Form1.TxtProOdRok(j).Text = dat
            
        Delka = GetPrivateProfileString _
            (kam, "Txt6", "", Bafr, 100, (CestaSoubory & "\RDSEdit.ini"))
            dat = Left(Bafr, Delka)
        PromoDatum(j, 2) = PromoDatum(j, 2) & dat
        Form1.TxtProDoRok(j).Text = dat
            
        Delka = GetPrivateProfileString _
            (kam, "Txt7", "", Bafr, 100, (CestaSoubory & "\RDSEdit.ini"))
            Form1.TxtProPCHod(j).Text = Left(Bafr, Delka)
        Delka = GetPrivateProfileString _
            (kam, "Txt8", "", Bafr, 100, (CestaSoubory & "\RDSEdit.ini"))
            Form1.TxtProPCMin(j).Text = Left(Bafr, Delka)
        Delka = GetPrivateProfileString _
            (kam, "Txt9", "", Bafr, 100, (CestaSoubory & "\RDSEdit.ini"))
            Form1.TxtProOdHod(j).Text = Left(Bafr, Delka)
        Delka = GetPrivateProfileString _
            (kam, "Txt10", "", Bafr, 100, (CestaSoubory & "\RDSEdit.ini"))
            Form1.TxtProDoHod(j).Text = Left(Bafr, Delka)
        Delka = GetPrivateProfileString _
            (kam, "Txt11", "", Bafr, 100, (CestaSoubory & "\RDSEdit.ini"))
            Form1.TxtProOdMin(j).Text = Left(Bafr, Delka)
        Delka = GetPrivateProfileString _
            (kam, "Txt12", "", Bafr, 100, (CestaSoubory & "\RDSEdit.ini"))
            Form1.TxtProDoMin(j).Text = Left(Bafr, Delka)
        Delka = GetPrivateProfileString _
            (kam, "Txt13", "", Bafr, 100, (CestaSoubory & "\RDSEdit.ini"))
            Form1.TxtProPocOpak(j).Text = Left(Bafr, Delka)
            
        Delka = GetPrivateProfileString _
            (kam, "List", "0", Bafr, 200, (CestaSoubory & "\RDSEdit.ini"))
            List = Left(Bafr, Delka)
        
    
        PromoI(j) = CInt(Left(List, 2))
        
        a = InStr(List, "-") + 1
        
        For i = 1 To PromoI(j)
            PromoCas(i, (j)) = Mid(List, a, 5)
            a = a + 6
        Next i
                 
        Form1.LstPromoCasy(j).Clear
                
        For i = 1 To PromoI(j)
             Form1.LstPromoCasy(j).AddItem PromoCas(i, j), i - 1
        Next i
        
        Form1.LblPromoPocet(j).Caption = "Počet časů: " & Form1.LstPromoCasy(j).ListCount
            
    Next j
        
End Sub


'----------------------------------------------------------
'kryptovani hesel
'----------------------------------------------------------

Public Function Krypt(ss As String) As String

    Dim i As Integer
    Dim l As Integer
    Dim X As Integer
    Dim Y As Integer
    Dim Kr As String
    
    l = Len(ss)
    Y = Asc(ss)
    X = (l + 150) / Y
    
    For i = 1 To l
       Kr = Mid(ss, i, 1)
       Mid(ss, i, 1) = Chr(Asc(Kr) + ((-1) ^ i * i * X))
    Next i
    Krypt = ss & Chr(Y)

End Function


'----------------------------------------------------------
'dekryptovani hesel
'----------------------------------------------------------

Public Function DEKrypt(ss As String) As String

    Dim i As Integer
    Dim l As Integer
    Dim X As Integer
    Dim Y As Integer
    Dim Kr As String
    Dim ss1 As String
    
    l = Len(ss) - 1
    Y = Asc(Right(ss, 1))
    X = (l + 150) / Y
    
    For i = 1 To l
       Kr = Mid(ss, i, 1)
       ss1 = ss1 & Chr(Asc(Kr) - ((-1) ^ i * i * X))
    Next i
    DEKrypt = ss1

End Function
