Torna al Thread
Protected Sub YesButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles YesButton.Click
Dim MySQLConnStringName, MySQLstrConnection, FileNome, Tipologia As String
Dim MySQLConn As MySqlConnection
Dim MySQLSelectCmd, MySQLInsertCmd As MySqlCommand
Dim MySQLDr As MySqlDataReader
Dim UltimoOdgOds, NuovoOdgOds, Anno As Integer
Dim Oggi As Date
'esegue la connessione al database
MySQLConnStringName = "odg-odsConnectionString"
MySQLstrConnection = ConfigurationManager.ConnectionStrings(MySQLConnStringName).ConnectionString
MySQLConn = New MySqlConnection(MySQLstrConnection)
'stringa sql per ricavare il nuovo numero
MySQLSelectCmd = New MySqlCommand("SELECT MAX(Numero_odg_ods) AS Ultimo FROM(tbl_odg_ods)WHERE (Anno_competenza = YEAR(NOW())) AND (Tipo = ?OdgOdsTipo)", MySQLConn)
MySQLSelectCmd.Parameters.AddWithValue("?OdgOdsTipo", AddTipoDropDownList.SelectedValue)
'apertura della connessione al database
MySQLConn.Open()
MySQLDr = MySQLSelectCmd.ExecuteReader
MySQLDr.Read()
'valorizzazione di alcune variabili necessarie all'accodamento
Oggi = DateValue(Now())
Anno = Year(Oggi)
Select Case AddTipoDropDownList.SelectedValue
Case 1
Tipologia = "Odg"
Case 2
Tipologia = "Ods"
Case Else
Tipologia = ""
End Select
'Accodamento del nuovo odg/ods
If Not (MySQLDr.IsDBNull(0)) Then
UltimoOdgOds = MySQLDr.GetInt32("Ultimo")
NuovoOdgOds = UltimoOdgOds + 1
Else
NuovoOdgOds = 1
End If
MySQLDr.Close()
FileNome = Tipologia & "-" & NuovoOdgOds.ToString & "-" & Anno.ToString & ".pdf"
MySQLInsertCmd = New MySqlCommand("INSERT INTO tbl_odg_ods(Numero_odg_ods, Anno_competenza, Oggetto_odg_ods, Tipo, data_pubblicazione, Argomento_odg_ods, NomeFile)" & _
" VALUES (?Numero_odg_ods, ?Anno_competenza, ?Oggetto_odg_ods, ?Tipo, ?data_pubblicazione, ?Argomento_odg_ods, ?NomeFile)", MySQLConn)
MySQLInsertCmd.Parameters.AddWithValue("?Numero_odg_ods", NuovoOdgOds)
MySQLInsertCmd.Parameters.AddWithValue("?Anno_competenza", Anno)
MySQLInsertCmd.Parameters.AddWithValue("?Oggetto_odg_ods", AddOggettoTextBox.Text)
MySQLInsertCmd.Parameters.AddWithValue("?Tipo", AddTipoDropDownList.SelectedValue)
MySQLInsertCmd.Parameters.AddWithValue("?data_pubblicazione", Oggi)
MySQLInsertCmd.Parameters.AddWithValue("?Argomento_odg_ods", AddArgomentoDropDownList.SelectedValue)
MySQLInsertCmd.Parameters.AddWithValue("?NomeFile", FileNome)
MySQLInsertCmd.ExecuteNonQuery()
'Chiusura della connessione al database e ritorno alla pagina di modifica
MySQLConn.Close()
OdgOdsMultiView.ActiveViewIndex = 0
EditOdgOdsUpdatePanel.Update()
NewDocLabel.text = "Hai appena inserito l'" & Tipologia & " numero " & NuovoOdgOds & " del " & Oggi
End Sub