Public Class frmDiary
Public Modified As Boolean = False
Private Sub dtpDay_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtpDay.ValueChanged
If Modified Then
If MsgBox("Aggiornare gli impegni di " + dtpDay.Value.Date.ToLongDateString + "?", MsgBoxStyle.Question + vbYesNo) Then
Dim W As New IO.StreamWriter(Application.StartupPath + "\Imps\" + dtpDay.Value.Date.ToLongDateString + ".app")
W.Write(txtImp.Text)
W.Close()
Modified = False
End If
End If
Try
Dim R As New IO.StreamReader(Application.StartupPath + "\Imps\" + dtpDay.Value.Date.ToLongDateString + ".app")
txtImp.Text = R.ReadToEnd
R.Close()
Catch FNFE As IO.FileNotFoundException
txtImp.Text = "[Nessun impegno per questo giorno]"
Catch DNFE As IO.DirectoryNotFoundException
IO.Directory.CreateDirectory(Application.StartupPath + "\Imps")
txtImp.Text = "[Nessun impegno per questo giorno]"
End Try
Modified = False
End Sub
Private Sub cmdRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRefresh.Click
Dim W As New IO.StreamWriter(Application.StartupPath + "\Imps\" + dtpDay.Value.Date.ToLongDateString + ".app")
W.Write(txtImp.Text)
W.Close()
Modified = False
End Sub
Private Sub txtImp_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtImp.TextChanged
Modified = True
End Sub
Private Sub cmdDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDelete.Click
If MsgBox("L'eliminazione dei file associati a " + dtpDay.Value.Date.ToLongDateString + " sarà permanente. Procedere?", MsgBoxStyle.Question + vbYesNo) = MsgBoxResult.No Then
Exit Sub
End If
Kill(Application.StartupPath + "\Imps\" + dtpDay.Value.Date.ToLongDateString + ".app")
txtImp.Text = "[Nessun impegno per questo giorno]"
End Sub
End Class