'
' Created by SharpDevelop.
' User: Jan
' Date: 21.07.2017
' Time: 18:23
' 
' To change this template use Tools | Options | Coding | Edit Standard Headers.
'
Imports System.IO
Public Partial Class MainForm
	Public Shared okno As Short = 0	
	Public shared verzia As Integer = 7000
	Public Sub New()
		' The Me.InitializeComponent call is required for Windows Forms designer support.
		Me.InitializeComponent()
		'Dim pokus As CXMLhandling
		'pokus = New CXMLhandling()
		'MsgBox(pokus.vypisZakOdp("1"))
		'
		' TODO : Add constructor code after InitializeComponents
		'
		Try
			Dim obrazovka As Module1
			obrazovka =New Module1()		
			obrazovka.ScreenResolution()
			obrazovka.zapisNobody() 'zapisem si momentalne prihlaseneho pouzivatela
			Dim ktojeprihl As String = obrazovka.readKtojeprihl()
			Dim filePath As String = ""
			filePath = System.IO.Path.Combine(
		    My.Computer.FileSystem.SpecialDirectories.MyDocuments, "nevedel" & ktojeprihl & ".txt")
			If File.Exists(filePath) Then
				Dim ktneved As String = obrazovka.citajNevedel(ktojeprihl)
				Dim kons As String=obrazovka.konsolidujOtazky(ktneved)
				obrazovka.prepisNevedene(kons,ktojeprihl)
			End If
		Catch ex As Exception
			MsgBox(ex.Message)
		End Try
	End Sub
	
	Sub PrihlásMaToolStripMenuItemClick(sender As Object, e As EventArgs)
		
	End Sub
	
	Sub TestToolStripMenuItemClick(sender As Object, e As EventArgs)
		Dim fn As New FNahTest("znackynahodne")
		If okno = 0 Then
			fn.Show	
			okno = 1
		End If					
	End Sub
	
		
	Sub MainFormLoad(sender As Object, e As EventArgs)
		Try
		Dim rserver As String=""
		Dim verzia As String=""
		Dim modul As New Module1
		label1.Visible=False
		If modul.CheckForInternetConnection("http://www.autoskola-free.szm.sk/rserver.txt") Then
			rserver=modul.readRemote("http://www.autoskola-free.szm.sk/rserver.txt")
			verzia=modul.readRemote(rserver & "/verzia.txt")
			If Integer.Parse(verzia)<>MainForm.verzia Then
				MsgBox("There is available newer edition of the program. Update automatically clicking to About program -> Update...")
			End If
			
			webBrowser1.Navigate(rserver.ToString() & "/reklama.php")
		Else			
			MsgBox("Server on the internet is inaccessible. Try again later or contact lesna.vevericka@gmail.com")
		End If
		Catch ex As Exception
			'ziadnu vynimku nevypisujem, ticha kontrola	
			label1.Visible=True
			MsgBox("Error in connection with server: " & ex.Message)
		End Try
		
	End Sub
	
	Sub VýukaToolStripMenuItemClick(sender As Object, e As EventArgs)
		
	End Sub
	
	Sub InfoOProgrameAutoškola7ToolStripMenuItemClick(sender As Object, e As EventArgs)
		Dim sprava As Module1
		sprava =New Module1()
		sprava.showMessage("Created by www.autoskola-free.szm.sk" &Constants.vbNewLine &"This is freeware."&Constants.vbNewLine &"License FREEWARE.")
	End Sub
	
	Sub PošliReakciuToolStripMenuItemClick(sender As Object, e As EventArgs)
		Dim webAddress As String = "http://miniaplikace.blueboard.cz/kniha/262fco54ofe5dojvu2svjcm8jvmbmn"
		Process.Start(webAddress)		
	End Sub
	
	Sub KtoJeAktuálnePrihlásenýToolStripMenuItemClick(sender As Object, e As EventArgs)
		Try
			Dim m As New Module1
			Dim i As Short
			m.showMessage("Logged in user is "& m.readKtojeprihl())
			
		Catch ex As Exception
			MsgBox(ex.Message)
		End Try
	End Sub
	
	Sub PridaťNovéhoUžívateľaToolStripMenuItemClick(sender As Object, e As EventArgs)
		Dim f As New FPridajPouziv
		If okno = 0 Then
			f.Show()
			okno=1
		End If
		
	End Sub
	
	Sub ZmazaťUžívateľaToolStripMenuItemClick(sender As Object, e As EventArgs)
		Dim f As New FPridajPouziv
		If okno = 0 Then
			f.Show()
			okno=1
		End If
	End Sub
	
	Sub PrihlásenieNaSedenieToolStripMenuItemClick(sender As Object, e As EventArgs)
		Dim f As New FPrihlasSedenie
		If okno = 0 Then
			f.Show()
			okno=1
		End If	
	End Sub
	
	Sub OdhlásenieZoSedeniaToolStripMenuItemClick(sender As Object, e As EventArgs)
		Dim m As New Module1
		m.zapisNobody()
		m.showMessage("User has been logged off. Setting up standard nobody.")
	End Sub
	
	Sub SpustiNáhodnýTestToolStripMenuItemClick(sender As Object, e As EventArgs)
		Dim fn As New FNahTest("nahtest")
		If okno = 0 Then
			fn.Show	
			okno = 1
		End If
		
	End Sub
	
	Sub TestLenOtázkyKtoréSomNevedelToolStripMenuItemClick(sender As Object, e As EventArgs)
		'spusti test len s otazkami, ktore som nevedel	
		Dim fn As New FNahTest("nevedenetest")
		If okno = 0 Then
			fn.Show	
			okno = 1
		End If
	End Sub
	
	Sub SpustiTestZdravotnáPrípravaToolStripMenuItemClick(sender As Object, e As EventArgs)
		Dim fn As New FNahTest("zdravotnatest")
		If okno = 0 Then
			fn.Show	
			okno = 1
		End If	
	End Sub
	
	Sub TestZákonyNáhodneToolStripMenuItemClick(sender As Object, e As EventArgs)
		Dim fn As New FNahTest("zakonynahodne")
		If okno = 0 Then
			fn.Show	
			okno = 1
		End If		
	End Sub
	
	Sub TestDopravnéSituácieNáhodneToolStripMenuItemClick(sender As Object, e As EventArgs)
		Dim fn As New FNahTest("krizovatkynahodne")
		If okno = 0 Then
			fn.Show	
			okno = 1
		End If	
	End Sub
	
	Sub TestZákonyKtoréSomNevedelToolStripMenuItemClick(sender As Object, e As EventArgs)
		Dim fn As New FNahTest("zakonynevedel")
		If okno = 0 Then
			fn.Show	
			okno = 1
		End If	
	End Sub
	
	Sub TestDopravnéZnačkyKtoréSomNevedelToolStripMenuItemClick(sender As Object, e As EventArgs)
		Dim fn As New FNahTest("znackynevedel")
		If okno = 0 Then
			fn.Show	
			okno = 1
		End If		
	End Sub
	
	Sub TestDopravnéSituácieKtoréSomNevedelToolStripMenuItemClick(sender As Object, e As EventArgs)
		Dim fn As New FNahTest("krizovatkynevedel")
		If okno = 0 Then
			fn.Show	
			okno = 1
		End If		
	End Sub
	
	Sub PrechádzaťVšetkyZákonyPostupneToolStripMenuItemClick(sender As Object, e As EventArgs)
		Dim fn As New FVyuka("zakonypostupne")
		If okno = 0 Then
			fn.Show	
			okno = 1
		End If	
	End Sub
	
	Sub PrechádzaťVšetkyZákonyNáhodneToolStripMenuItemClick(sender As Object, e As EventArgs)
		Dim fn As New FVyuka("zakonynahodne")
		If okno = 0 Then
			fn.Show	
			okno = 1
		End If		
	End Sub
	
	Sub PrechádzaťLenZákonyKtoréSomNevedelToolStripMenuItemClick(sender As Object, e As EventArgs)
		Dim fn As New FVyuka("zakonynevedel")
		If okno = 0 Then
			fn.Show	
			okno = 1
		End If		
	End Sub
	
	Sub PrechádzaťVšetkyxZnačkyPostupneToolStripMenuItemClick(sender As Object, e As EventArgs)
		Dim fn As New FVyuka("znackypostupne")
		If okno = 0 Then
			fn.Show	
			okno = 1
		End If
	End Sub
	
	Sub PrechádzaťVšetkyZnačkyNáhodneToolStripMenuItemClick(sender As Object, e As EventArgs)
		Dim fn As New FVyuka("znackynahodne")
		If okno = 0 Then
			fn.Show	
			okno = 1
		End If
	End Sub
	
	Sub PrechádzaťLenZnačkyKtoréSomNevedelToolStripMenuItemClick(sender As Object, e As EventArgs)
		Dim fn As New FVyuka("znackynevedel")
		If okno = 0 Then
			fn.Show	
			okno = 1
		End If		
	End Sub
	
	Sub PrechádzaťVšetkyKrižovatkyPostupneToolStripMenuItemClick(sender As Object, e As EventArgs)
		Dim fn As New FVyuka("krizovatkypostupne")
		If okno = 0 Then
			fn.Show	
			okno = 1
		End If		
	End Sub
	
	Sub PrechádzaťVšetkyKrižovatkyNádhodneToolStripMenuItemClick(sender As Object, e As EventArgs)
		Dim fn As New FVyuka("krizovatkynahodne")
		If okno = 0 Then
			fn.Show	
			okno = 1
		End If	
	End Sub
	
	Sub PrechádzaťLenKrižovatkyKtoréSomNevedelToolStripMenuItemClick(sender As Object, e As EventArgs)
		Dim fn As New FVyuka("krizovatkynevedel")
		If okno = 0 Then
			fn.Show	
			okno = 1
		End If		
	End Sub
	
	Sub VytvorKurzToolStripMenuItemClick(sender As Object, e As EventArgs)
		Dim fn As New FVytvorKurz()
		If okno = 0 Then
			fn.Show	
			okno = 1
		End If	
	End Sub
	
	Sub SpustiKurzToolStripMenuItemClick(sender As Object, e As EventArgs)
		
			Dim fn As New FSZKurz()
			If okno = 0 Then
				fn.Show	
				okno = 1
			End If
	End Sub
	
	Sub ZmažKurzToolStripMenuItemClick(sender As Object, e As EventArgs)
		Dim fn As New FSZKurz()
		If okno = 0 Then
			fn.Show	
			okno = 1
		End If		
	End Sub
	
	Sub KnihaJázdToolStripMenuItemClick(sender As Object, e As EventArgs)
		Dim fn As New FKnihaJazd()
		If okno = 0 Then
			fn.Show	
			okno = 1
		End If	
	End Sub
	
	Sub ZmazaťZapamätanéÚdajeUžívateľaToolStripMenuItemClick(sender As Object, e As EventArgs)
		'klikol zmazat zapamatane data
		'zapamatane su kniha jazd, kurzy, ak nejake ma a otazky, ktore nevedel ak nejake ma
		'problem je len s kurzami, ak existuje subor kurzypouzivatel.txt, tak ich nacitam a mazem
		Dim filePath As String
		Dim modul As New Module1
		filePath = System.IO.Path.Combine(
		    My.Computer.FileSystem.SpecialDirectories.MyDocuments, "kj" & modul.readKtojeprihl() & ".txt")
		    If File.Exists(filePath) Then
		    	My.Computer.FileSystem.DeleteFile(filePath)
		    End If
		    
		filePath = System.IO.Path.Combine(
		    My.Computer.FileSystem.SpecialDirectories.MyDocuments, "nevedel" & modul.readKtojeprihl() & ".txt")
		    If File.Exists(filePath) Then
		    	My.Computer.FileSystem.DeleteFile(filePath)
		    End If
		    
		    Dim kurzy As String = ""
		    kurzy=modul.citajKurzy(modul.readKtojeprihl())
		    Dim kurzyp As String() = kurzy.Split(New Char() {" "c})
		    For Each k In kurzyp
		    	
		    filePath = System.IO.Path.Combine(
		    My.Computer.FileSystem.SpecialDirectories.MyDocuments, "kurz" & k & ".txt")
		    If File.Exists(filePath) Then
		    	My.Computer.FileSystem.DeleteFile(filePath)
		    End If
		    	
		    Next
		    
		    filePath = System.IO.Path.Combine(
		    My.Computer.FileSystem.SpecialDirectories.MyDocuments, "kurzy" & modul.readKtojeprihl() & ".txt")
		    If File.Exists(filePath) Then
		    	My.Computer.FileSystem.DeleteFile(filePath)
		    End If
		    
		    MsgBox("Try run of remebered files.")
		    
	End Sub
	
	Sub NájdiReťazecToolStripMenuItemClick(sender As Object, e As EventArgs)
		Dim fn As New FNajdiRetazec()
		If okno = 0 Then
			fn.Show	
			okno = 1
		End If	
	End Sub
	
	Sub WebBrowser1DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs)
		
	End Sub
	
	Sub AktualizujNaNajnovšiuVerziuZInternetuToolStripMenuItemClick(sender As Object, e As EventArgs)
		'klikol na aktualizuj na najnovšiu verziu
		'len stiahnem aktualizátor a spustím ho
		'moze to postahovat potom sam alebo len ukaze odkaz odkial stiahnut a otvori ho
		'v prehliadaci
		Dim app As String = My.Application.Info.DirectoryPath & "/aktualizujautoskola.exe" 
		Dim AppParam As String = "none"
		System.Diagnostics.Process.Start(app, AppParam)
	End Sub
End Class
