'
' Created by SharpDevelop.
' User: Jano
' Date: 7.8.2017
' Time: 12:09
' 
' To change this template use Tools | Options | Coding | Edit Standard Headers.
'
Imports System.IO
Public Partial Class FVytvorKurz
	Dim te As Integer = 1
	Dim ot As Integer = 1
	Dim abc As New Module1
	Dim pridane As New ArrayList
	Public Sub New()
		' The Me.InitializeComponent call is required for Windows Forms designer support.
		Me.InitializeComponent()
		
		'
		' TODO : Add constructor code after InitializeComponents
		'
		For h As Integer = 1 To 36
			comboBox1.Items.Add(h.ToString)	
		Next
		For h As Integer = 1 To 27
			comboBox2.Items.Add(h.ToString)	
		Next
		comboBox1.SelectedIndex=0 'nastavim standardnu na prvu
		comboBox2.SelectedIndex=0
		'MsgBox(comboBox1.Text) 'vybrata hodnota
		If ot<16 Then
			PictureBox1.ImageLocation = (System.Windows.Forms.Application.StartupPath & "/data/znackyobr/nopicture.png")
			PictureBox1.Load()
			richTextBox1.Text = abc.citajOt(ot,te)
			richTextBox1.Text = richTextBox1.Text & " Odpoveď: " & abc.citajOd(ot,te).ToString().ToUpper() & ")"
		End If		
	End Sub
	
	Sub FVytvorKurzFormClosed(sender As Object, e As FormClosedEventArgs)
		MainForm.okno=0
	End Sub
	
	Sub ComboBox1SelectedIndexChanged(sender As Object, e As EventArgs)
		Try
		te = Integer.Parse(comboBox1.Text)
		If ot<16 Then
			PictureBox1.ImageLocation = (System.Windows.Forms.Application.StartupPath & "/data/znackyobr/nopicture.png")
			PictureBox1.Load()
			richTextBox1.Text = abc.citajOt(ot,te)
			richTextBox1.Text = richTextBox1.Text & " Odpoveď: " & abc.citajOd(ot,te).ToString().ToUpper() & ")"
		End If
		If ot > 15 Then
			PictureBox1.ImageLocation = (System.Windows.Forms.Application.StartupPath & "/data/znackyobr/t" & te & "o" & ot & ".jpg")
			PictureBox1.Load()
			richTextBox1.Text = abc.citajOt(ot,te)
			richTextBox1.Text = richTextBox1.Text & " Odpoveď: " & abc.citajOd(ot,te).ToString().ToUpper() & ")"
		End If
		Catch ex As Exception
			MsgBox(ex.Message)	
		End Try
	End Sub
	
	Sub ComboBox2SelectedIndexChanged(sender As Object, e As EventArgs)
		Try
		ot = Integer.Parse(comboBox2.Text)
		If ot<16 Then
			PictureBox1.ImageLocation = (System.Windows.Forms.Application.StartupPath & "/data/znackyobr/nopicture.png")
			PictureBox1.Load()
			richTextBox1.Text = abc.citajOt(ot,te)
			richTextBox1.Text = richTextBox1.Text & " Odpoveď: " & abc.citajOd(ot,te).ToString().ToUpper() & ")"
		End If
		If ot > 15 Then
			PictureBox1.ImageLocation = (System.Windows.Forms.Application.StartupPath & "/data/znackyobr/t" & te & "o" & ot & ".jpg")
			PictureBox1.Load()
			richTextBox1.Text = abc.citajOt(ot,te)
			richTextBox1.Text = richTextBox1.Text & " Odpoveď: " & abc.citajOd(ot,te).ToString().ToUpper() & ")"
		End If
		Catch ex As Exception
			MsgBox(ex.Message)	
		End Try
	End Sub
	
	Sub Button4Click(sender As Object, e As EventArgs)
		'klikol pridaj túto otázku do kurzu
		Dim pridat As String = ""
		pridat = "t" & comboBox1.Text & "o" & comboBox2.Text & " "
		If Not pridane.Contains(pridat) Then
			pridane.Add(pridat) 'najskor len pridavam, az potom zapisujem
			MsgBox("Pridal som zvolenú otázku " & pridat & " do kurzu. Nezabudnite si ho potom uložiť pod menom.")
		Else
			MsgBox("Tento kurz už obsahuje zvolenú otázku. Pridajte inú alebo uložte svoj kurz pod menom.")
		End If
	End Sub
	
	Sub Button3Click(sender As Object, e As EventArgs)
		'klikol ulozit tento kurz
		Try
			Dim o As New Module1
			If pridane.Count()=0 Then
				MsgBox("Do kurzu nie je pridaná ani jedna otázka. Pridajte prosím nejakú.")
				Return
			End If
			
			If File.Exists(My.Computer.FileSystem.SpecialDirectories.MyDocuments & "/kurz"& textBox1.Text.Trim() &".txt") Then
				MsgBox("Kurz s týmto menom už existuje. Zvoľte prosím iné meno.")
				textBox1.Text=""
				Return
			End If			
			If textBox1.Text.Trim = "" Then
				MsgBox("Musíte zvoliť nejaké meno kurz A-Z a-z 0-9!")
				Return
			End If
			If Not System.Text.RegularExpressions.Regex.IsMatch(TextBox1.Text, "^[A-Za-z0-9]+$") Then			
				o.showMessage("Prezývka môžu byť iba znaky A-Z a-z 0-9")
				textBox1.Text=""
				Return
			End If
			Dim pridaneOtazky As String = ""
			For Each st In pridane
				pridaneOtazky = pridaneOtazky & st & " "
			Next					
			o.pridajKurzy(textBox1.Text.Trim(),pridaneOtazky,o.readKtojeprihl())
			o.showMessage("Uložil som zvolený kurz s otázkami.")
			Me.Close()
		Catch ex As Exception
			MsgBox(ex.Message)	
		End Try
	End Sub
End Class
