'
' 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 & " Answer: " & 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 & " Answer: " & 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 & " Answer: " & 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 & " Answer: " & 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("I added selected question " & pridat & " to the course. Do not forget to save course with name.")
		Else
			MsgBox("This course already contains selected question. Add other question or save course with name.")
		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("There is no question added to course. Add some question.")
				Return
			End If
			
			If File.Exists(My.Computer.FileSystem.SpecialDirectories.MyDocuments & "/kurz"& textBox1.Text.Trim() &".txt") Then
				MsgBox("The course with this name aready exists. Please select other name.")
				textBox1.Text=""
				Return
			End If			
			If textBox1.Text.Trim = "" Then
				MsgBox("You must select some name of the course 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("Nickname can be only characters 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("I saved selected course with questions.")
			Me.Close()
		Catch ex As Exception
			MsgBox(ex.Message)	
		End Try
	End Sub
End Class
