Generazione fatture - Slato di numeri

martedì 30 novembre 2010 - 12.38
Tag Elenco Tags  VB.NET  |  .NET 1.0  |  Windows XP  |  Visual Studio 2005  |  SQL Server 2000  |  Internet Explorer 7.0

nandonando Profilo | Senior Member

MI spigo meglio il mio prog genera delle fatture ovviamente con una numerazione progressiva, le tabelle sono 2,per altri problemi legati alla vecchiacreazione, comunque da queste 2 tabelle entrambe contenenti fattu, prenede da ciascuna il numero massimo di fattura dell'anno in corso e fa +1 e poi ovviamente faccio l'update(che non scrivo), ogni tanto succede che salta qualche numero come mai?
O come potrei risolvere?
Vi scrivo il codice:
'''''''RECUPERO IL MASSIMO NUMERO Fattura ELETTRICO
If cnELETTRICO.State = ConnectionState.Open Then
cnELETTRICO.Close()
End If

Dim sqlCommandELETTRICO As New SqlCommand("SELECT MAX(Numero) AS MaSSIMO FROM tblFatture WHERE (YEAR(DataFattura) = " & Year(data_fattura.Text) & ")", cnELETTRICO)
Try
cnELETTRICO.Open()
Dim rdrRATA As SqlDataReader = sqlCommandELETTRICO.ExecuteReader(CommandBehavior.KeyInfo)

If rdrRATA.Read() Then
If rdrRATA.Item("MaSSIMO").ToString = "" Then
txt_numero_fattura_ELETTRICO.Text = 1
Else
txt_numero_fattura_ELETTRICO.Text = rdrRATA.Item("MaSSIMO").ToString + 1
End If

Else
txt_numero_fattura_ELETTRICO.Text = 1
End If
cnELETTRICO.Close()
Catch ex As Exception
cnELETTRICO.Close()
End Try


'''''''RECUPERO IL MASSIMO NUMERO Fattura ASCENSORI
If cn.State = ConnectionState.Open Then
cn.Close()
End If

Dim sqlCommand1 As New SqlCommand("SELECT MAX(Numero) AS MaSSIMO FROM tblFatture WHERE (YEAR(DataFattura) = " & Year(data_fattura.Text) & ")", cn)
Try
cn.Open()
Dim rdrRATA As SqlDataReader = sqlCommand1.ExecuteReader(CommandBehavior.KeyInfo)

If rdrRATA.Read() Then
If rdrRATA.Item("MaSSIMO").ToString = "" Then
txt_numero_fattura.Text = 1
Else
txt_numero_fattura.Text = rdrRATA.Item("MaSSIMO").ToString + 1
End If

Else
txt_numero_fattura.Text = 1
End If
cn.Close()
Catch ex As Exception
cn.Close()
End Try

''''MASSIMO NUMERO FATTURE ENTRAMBI DATABASE
If Int(txt_numero_fattura.Text) > Int(txt_numero_fattura_ELETTRICO.Text) Then
txt_numero_fattura.Text = txt_numero_fattura.Text
ElseIf Int(txt_numero_fattura_ELETTRICO.Text) > Int(txt_numero_fattura.Text) Then
txt_numero_fattura.Text = txt_numero_fattura_ELETTRICO.Text
End If
http://www.gustoroma.it

aabruzzese Profilo | Junior Member


Ciao,

Perché non fai una tabella di controllo con i dati next_invoice_nbr ...

Non sarebbe pui facile e poi anche pui sicuro dei numeri de fatture?


Angelo Abruzzese
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5