
Imports System.IO

Public Class frmIntroducere
    Private Const NUME_FISIER As String = "studenti.txt"

    Private Sub SalvareInFisierTextToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SalvareInFisierTextToolStripMenuItem.Click
        Dim raspuns As MsgBoxResult

        If File.Exists(NUME_FISIER) Then
            raspuns = MsgBox("Fisierul '" & NUME_FISIER & "' exista. Doriti sa suprascrieti?", MsgBoxStyle.YesNo)
            If raspuns = MsgBoxResult.No Then
                Return
            End If
        End If


        If lstNume.Items.Count = 0 Then
            raspuns = MsgBox("Lista nu contine nici un nume. Continuati operatia de salvare? ", MsgBoxStyle.YesNo)
            If raspuns = MsgBoxResult.No Then
                Return
            End If
        End If

        Dim oWrite As StreamWriter
        oWrite = File.CreateText(NUME_FISIER)

        For Each item As String In lstNume.Items
            oWrite.WriteLine(item.ToString())
        Next
        oWrite.Close()
        lstNume.Items.Clear()
        MsgBox("Salvare efectuata")
    End Sub





    Private Sub btnAdauga_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdauga.Click
        If String.IsNullOrEmpty(txtNume.Text) Then
            MsgBox("Introduceti un nume")
        Else
            lstNume.Items.Add(txtNume.Text)
            txtNume.Text = ""
        End If
    End Sub

    Private Sub CitireDinFisierTextToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CitireDinFisierTextToolStripMenuItem.Click

        If Not File.Exists(NUME_FISIER) Then
            MsgBox("Fisierul '" & NUME_FISIER & "' nu exista")
            Return
        End If

        Dim oRead As StreamReader
        Dim input As String

        oRead = File.OpenText(NUME_FISIER)

        input = oRead.ReadLine()
        While Not input Is Nothing
            lstNume.Items.Add(input)
            input = oRead.ReadLine()
        End While

        oRead.Close()

    End Sub

    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        Application.Exit()
    End Sub

    
End Class
