Muchísimas gracias Eleкtro! No me esperaba una explicación tan detallada
Voy a modificar el código siguiendo tu ejemplo.
Saludos! y nuevamente gracias!
Voy a modificar el código siguiendo tu ejemplo.
Saludos! y nuevamente gracias!
Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes Menú
Dim html As String = String.Empty
Dim html2 As String = String.Empty
Dim html3 As String = String.Empty
Dim Mail As New MailMessage
Mail.Subject = My.Settings.oggetto
Mail.To.Add(My.Settings.destinatario)
Mail.From = New MailAddress(My.Settings.mittente)
Mail.IsBodyHtml = True
Dim tipo, nome, tipo_appuntamento, scadenza, note As String
Dim strMailBody As String
Dim i As Integer
html = html & "<B>Buongiorno, " & " <BR> "
html = html & "Queste sono le scadenze per i prossimi " & My.Settings.allert & " giorno/i " & " <BR><BR> </B>"
html = html & "<TABLE cellpadding=""1"" COLS=""1"" SIZE=""1"" border=""1"" BORDERCOLOR= ""black"">"
html3 = html3 & "</FONT></TABLE><BR><BR>"
html3 = html3 & "Cordiali saluti"
For i = 0 To DataGridView1.Rows.Count - 1
tipo = DataGridView1.Item(0, i).Value.ToString
nome = DataGridView1.Item(1, i).Value.ToString
tipo_appuntamento = DataGridView1.Item(2, i).Value.ToString
scadenza = DataGridView1.Item(3, i).Value.ToString
note = DataGridView1.Item(4, i).Value.ToString
html2 = html2 & "<TR><TH>"
html2 = html2 & tipo & " </TH>"
html2 = html2 & "<TH>"
html2 = html2 & nome & "</TH>"
html2 = html2 & "<TH>"
html2 = html2 & tipo_appuntamento & " </TH>"
html2 = html2 & "<TH>"
html2 = html2 & scadenza & "</TH>"
html2 = html2 & "<TH>"
html2 = html2 & note & "</TH>"
html2 = html2 & "</TR>"
Next
strMailBody += html & html2 & html3 & vbCrLf
Mail.Body = strMailBody
Dim SMTP As New SmtpClient(My.Settings.server_email)
SMTP.EnableSsl = True
SMTP.Credentials = New System.Net.NetworkCredential(My.Settings.utente_email, My.Settings.password_email)
SMTP.Port = My.Settings.porta_email
SMTP.Send(Mail)
MsgBox("Email inviata!")
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
Dim html As String = String.Empty
Dim Mail As New MailMessage
Mail.Subject = My.Settings.oggetto
Mail.To.Add(My.Settings.destinatario)
Mail.From = New MailAddress(My.Settings.mittente)
Mail.IsBodyHtml = True
Dim tipo, nome, tipo_appuntamento, scadenza, note As String
Dim strMailBody As String
Dim i As Integer
For i = 0 To DataGridView1.Rows.Count - 1
tipo = DataGridView1.Item(0, i).Value.ToString
nome = DataGridView1.Item(1, i).Value.ToString
tipo_appuntamento = DataGridView1.Item(2, i).Value.ToString
scadenza = DataGridView1.Item(3, i).Value.ToString
note = DataGridView1.Item(4, i).Value.ToString
html = html & "<HTML>"
html = html & "<HEAD>"
html = html & "<TITLE>Avvisi Sicurezza</TITLE>"
html = html & "</HEAD>"
html = html & "<BODY bgcolor=""lightyellow"">"
html = html & " " & Now() & " <BR> <BR> "
html = html & "<B>Buongiorno, " & DataGridView1.Rows.Count & " <BR> "
html = html & "Queste sono le scadenze per i prossimi " & My.Settings.allert & " giorno/i " & " <BR><BR> </B>"
html = html & "<TABLE cellpadding=""1"" COLS=""1"" SIZE=""1"" border=""1"" BORDERCOLOR= ""black"">"
html = html & "<TR><TH>"
html = html & tipo & " </TH>"
html = html & "<TH>"
html = html & nome & "</TH>"
html = html & "<TH>"
html = html & tipo_appuntamento & " </TH>"
html = html & "<TH>"
html = html & scadenza & "</TH>"
html = html & "<TH>"
html = html & note & "</TH>"
html = html & "</TR>"
html = html & "</FONT></TABLE><BR>"
html = html & "</BODY>"
html = html & "</HTML>"
Next
Mail.Body = html
Dim SMTP As New SmtpClient(My.Settings.server_email)
SMTP.EnableSsl = True
SMTP.Credentials = New System.Net.NetworkCredential(My.Settings.utente_email, My.Settings.password_email)
SMTP.Port = My.Settings.porta_email
SMTP.Send(Mail)
MsgBox("Email inviata!")
End Sub
Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button18.Click
Dim conn As New MySqlConnection
Dim cmd As New MySqlCommand
Dim myData As MySqlDataReader
Dim SQL As String
Dim rawData() As Byte
Dim FileSize As UInt32
Dim fs As FileStream
conn.ConnectionString = "Server=8.8.8.8;User Id=xxx;Password=xxxx;Database=sicurezza"
SQL = "select allegato, file_size, nome_file from dipendenti_allegati where nome_file=" _
& """Licenze Kaspersky 2014.pdf"""
Try
conn.Open()
cmd.Connection = conn
cmd.CommandText = SQL
myData = cmd.ExecuteReader
If Not myData.HasRows Then Throw New Exception("There are no BLOBs to save")
myData.Read()
FileSize = myData.GetUInt32(myData.GetOrdinal("file_size"))
rawData = New Byte(FileSize) {}
myData.GetBytes(myData.GetOrdinal("allegato"), 0, rawData, 0, FileSize)
fs = New FileStream("C:\Users\yo\Desktop\" & myData.GetString(myData.GetOrdinal("nome_file")), FileMode.OpenOrCreate, FileAccess.Write)
fs.Write(rawData, 0, FileSize)
fs.Close()
MessageBox.Show("Archivo guardado!", "OK!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
myData.Close()
conn.Close()
Catch ex As Exception
MessageBox.Show("Error: " & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Dim Query As New MySqlCommand
Dim Conexion As MySqlConnection
Dim Consultar As MySqlDataReader
Dim Sql As String = "Server=172.XX.XX.XX;User Id=XXX;Password=XXX;Database=sicurezza"
Dim query_Adapter2 As String
If ComboBox7.Text = "matricola_old" Then
query_Adapter2 = "SELECT dipendenti_allegati.nome_file, dipendenti_allegati.data, dipendenti_allegati.allegato As Allegato FROM dipendenti_allegati INNER JOIN dipendenti ON dipendenti_allegati.matricola = dipendenti.matricola WHERE dipendenti." & ComboBox7.Text & " = " & TextBox17.Text & ""
Else
query_Adapter2 = "SELECT dipendenti_allegati.nome_file, dipendenti_allegati.data, dipendenti_allegati.allegato As Allegato FROM dipendenti_allegati INNER JOIN dipendenti ON dipendenti_allegati.matricola = dipendenti.matricola WHERE dipendenti." & ComboBox7.Text & " LIKE '%" & TextBox17.Text & "%'"
End If
Conexion = New MySqlConnection()
Conexion.ConnectionString = Sql
Conexion.Open()
Query.CommandText = query_Adapter2
Query.Connection = Conexion
Consultar = Query.ExecuteReader
While Consultar.Read
Dim File As String = Consultar(0).ToString
Dim Data As String = Consultar(1).ToString
Dim texto As String = Consultar(2).ToString
Dim Allegato As String = Consultar(3).ToString
DataGridView4.Rows.Add(File, texto, Data, Allegato)
DataGridView4.Refresh()
End While
Dim i As Integer
For i = 0 To ListBox2.Items.Count()
Try
ds = New DataSet
adapter = New MySqlDataAdapter("INSERT INTO assegnazione_dpi (matricola, matricola_old, nome, cognome, tipo_rischio, attrezzature) VALUES " _
& "('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & ComboBox6.Text & "','" & ListBox2.Items(i) & "')" & Environment.NewLine, conn)
adapter.Fill(ds, "assegnazione_dpi")
Catch ex As Exception
MsgBox(ex.Message)
End Try
Next