codice:
Imports System.NetImports System.Net.MailImports System.IO
Public Class Form1 Dim Abilita_invio As Integer = 0 Dim contatore As Integer = 0 Dim posta As New MailMessage 'variabile per l'invio della mail Dim smtp As New SmtpClient("smtp.gmail.com") Dim psw As String = ("psw") 'galileogalilei Private Declare Function GetSystemMetrics Lib "user32.dll" Alias "GetSystemMetrics" (ByVal Which As Integer) As Integer Private Declare Function SetWindowPos Lib "user32.dll" Alias "SetWindowPos" (ByVal hWnd As IntPtr, ByVal hWndIntertAfter As IntPtr, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal uFlags As Integer) As Boolean Private Const SM_CXSCREEN As Integer = 0 Private Const SM_CYSCREEN As Integer = 1 Private Shared HWND_TOP As IntPtr = IntPtr.Zero Private Const SWP_SHOWWINDOW As Integer = 64
Public ReadOnly Property ScreenX() As Integer Get Return GetSystemMetrics(SM_CXSCREEN) End Get End Property
Public ReadOnly Property ScreenY() As Integer Get Return GetSystemMetrics(SM_CYSCREEN) End Get End Property
Private Sub FullScreen() Me.WindowState = FormWindowState.Maximized Me.FormBorderStyle = FormBorderStyle.None Me.TopMost = True SetWindowPos(Me.Handle, HWND_TOP, 0, 0, ScreenX, ScreenY, SWP_SHOWWINDOW) End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Call FullScreen() ' Timer1.Enabled = True RichTextBox1.Text = System.IO.File.ReadAllText("C:\relazione.txt") 'PRENDE IL FILE RELAZIONE.TXT E LO INSERISCE NEL RICTEXTBOX (CHE è STATO OSCURATO) PER POI ESEGUYIRE 'UN FOR EACH E LEGGERE IL FILE RIGA PER RIGA( LA STESSA LOGICA USATA IN MIT APP INVENTOR PER SPLITTARE UN TESTO!
For Each linea_di_testo As String In System.IO.File.ReadAllLines("C:\relazione.txt")
If linea_di_testo.Contains("NOME:") Then NOME_COGNOME.Text = Mid(linea_di_testo, 7) End If If linea_di_testo.Contains("CLASSE:") Then CLASSE.Text = Mid(linea_di_testo, 8) End If If linea_di_testo.Contains("MATERIA:") Then MATERIA.Text = Mid(linea_di_testo, 9) End If If linea_di_testo.Contains("Relazione N.") Then NUMERO_RELAZIONE.Text = Mid(linea_di_testo, 13) End If If linea_di_testo.Contains("TESTO RELAZIONE:") Then RELAZIONE.Text = Mid(linea_di_testo, 17) End If If linea_di_testo.Contains("CONCLUSIONI:") Then CONCLUSIONI.Text = Mid(linea_di_testo, 17) End If
Next
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click TextBox1.Visible = True Button2.Visible = True End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click If TextBox1.Text.Contains(psw) Then
Me.Close() Else MsgBox("password non esatta!") End If End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick If contatore = 0 Then Button_RESETTA.Visible = True Else Button_RESETTA.Visible = False End If
Dim SALVATAGGIO_AUTOMATICO As New System.IO.StreamWriter(("C:") & "\relazione.txt") SALVATAGGIO_AUTOMATICO.Write("NOME: " + NOME_COGNOME.Text + Environment.NewLine) SALVATAGGIO_AUTOMATICO.Write("CLASSE: " + CLASSE.Text + Environment.NewLine) SALVATAGGIO_AUTOMATICO.Write("MATERIA: " + MATERIA.Text + Environment.NewLine) SALVATAGGIO_AUTOMATICO.Write("Relazione N. " + NUMERO_RELAZIONE.Text + Environment.NewLine) SALVATAGGIO_AUTOMATICO.Write("TESTO RELAZIONE: " + RELAZIONE.Text + Environment.NewLine) SALVATAGGIO_AUTOMATICO.Write("CONCLUSIONI: " + CONCLUSIONI.Text) SALVATAGGIO_AUTOMATICO.Close()
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button_CONSEGNA.Click
If MsgBox("Premendo 'OK' consegnerai la Relazione e NON sarà più possibile modificarla!" + Environment.NewLine + Environment.NewLine + "SEI SICURO DI VOLER CONSEGNARE?", MsgBoxStyle.OkCancel, "CONSEGNA") = MsgBoxResult.Ok Then
' ///////////// codice per invio email posta = New MailMessage posta.From = New MailAddress("mail@gmail.com") posta.To.Add("mail@gmail.com") posta.Subject = "relazione studente " + NOME_COGNOME.Text + " " + CLASSE.Text posta.Priority = MailPriority.High posta.Body = "ciao questa è una nuova relazione da correggere" posta.Attachments.Add(New Attachment("C:\relazione.txt")) posta.Attachments.Add(New Attachment(Label8.Text)) smtp.EnableSsl = True smtp.Port = 25 smtp.Credentials = New Net.NetworkCredential("mail@gmail.com", "psw") smtp.Send(posta) '////////////////////
Timer1.Enabled = False 'diabilito il timer1 così non vengono più effettuati salvataggi della relazione sul file .txt Button_CONSEGNA.Visible = False ' disabilito il bottone "consegna" per evitare invii multipli di mail End If
' Consegna.Show() ' Consegna.BringToFront() ' il form2 che viene richiamato resta sempre in primo piano rispetto al form1
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles ButtonSTART.Click
NOME_COGNOME.Visible = True CLASSE.Visible = True MATERIA.Visible = True NUMERO_RELAZIONE.Visible = True RELAZIONE.Visible = True CONCLUSIONI.Visible = True Button_CONSEGNA.Visible = True Label1.Visible = True Label2.Visible = True Label3.Visible = True Label4.Visible = True Label5.Visible = True Label6.Visible = True Label7.Visible = True PictureBox1.Visible = True Button_RESETTA.Visible = True ButtonSTART.Visible = False Button_CARICA.Visible = True Label8.Visible = True
Timer1.Enabled = True End Sub
Private Sub Button_RESETTA_Click(sender As Object, e As EventArgs) Handles Button_RESETTA.Click contatore = 1
NOME_COGNOME.Text = ("") CLASSE.Text = ("") NUMERO_RELAZIONE.Text = ("") MATERIA.Text = ("") RELAZIONE.Text = ("") CONCLUSIONI.Text = ("")
End Sub
Private Sub Button_CARICA_Click(sender As Object, e As EventArgs) Handles Button_CARICA.Click If OpenFileDialog1.ShowDialog = DialogResult.OK Then PictureBox1.Load(Me.OpenFileDialog1.FileName) Dim mylocationdirectory, myfilename, myfullpath As String mylocationdirectory = Path.GetDirectoryName(OpenFileDialog1.FileName) myfilename = Path.GetFileName(OpenFileDialog1.FileName) myfullpath = mylocationdirectory & "\" & myfilename Label8.Text = myfullpath End If End Sub
End Class