Torna al Thread

Try Dim dataelaborazione As String = String.Format("{0:dd-MM-yyyy}", data.SelectedDate) Dim sFileName As String = "Questura_" & dataelaborazione Dim sgetname As String = "Questura_" & dataelaborazione + ".txt" REM elimino il file se è già esistente If IO.File.Exists(Server.MapPath((Convert.ToString("FileQuestura/") & sFileName) + ".txt")) Then Try IO.File.Delete(Server.MapPath((Convert.ToString("FileQuestura/") & sFileName) + ".txt")) Catch ex As Exception RadWindowManager1.RadAlert(ex.Message, 300, 120, "Messaggio di avviso", Nothing) Exit Sub End Try End If REM creo il file ascii Using SW As New System.IO.StreamWriter(Server.MapPath((Convert.ToString("FileQuestura/") & sFileName) + ".txt")) Using Context As New touristEntities Dim query = (From c In Context.Tab_clienti Join m In Context.Tab_movimenti On c.clie_idrecord Equals m.m_idcliente Order By m.m_idrecordconnesso, m.m_Idalloggiato Where c.clie_idstruttura = idstruttura And m.m_arrivo = dataarrivo Select m.m_Idalloggiato, m.m_arrivo, m.m_nrpresenze, c.clie_cognome, c.clie_nome, c.clie_sesso, c.clie_datanascita, luogonascita = c.Tab_comuni_nazioni.c_codquestura, c.Tab_comuni_nazioni.c_siglaprov, c.Tab_comuni_nazioni.c_tipo, cittadinanza = c.Tab_cittadinanza.cit_codquestura, m.Tab_documenti.d_codquestura, m.m_nrdocumento, luogodocumento = m.Tab_comuni_nazioni_documento.c_codquestura).ToList Dim maxrighe As Integer = query.Count Dim contarighe As Integer = 1 REM elaboro tutta la lista dati per generare il file ascii For Each dati In query Dim cognome, nome As String cognome = dati.clie_cognome.Replace("à", "a") cognome = cognome.Replace("è", "e") cognome = cognome.Replace("é", "e") cognome = cognome.Replace("ì", "i") cognome = cognome.Replace("ò", "o") cognome = cognome.Replace("ù", "u") nome = dati.clie_nome.Replace("à", "a") nome = nome.Replace("è", "e") nome = nome.Replace("é", "e") nome = nome.Replace("ì", "i") nome = nome.Replace("ò", "o") nome = nome.Replace("ù", "u") Dim comunenascita As String Dim statonascita As String Dim siglaprov As String If dati.c_tipo = "ITA" Then comunenascita = dati.luogonascita siglaprov = dati.c_siglaprov statonascita = 100000100 Else comunenascita = "" siglaprov = "" statonascita = dati.luogonascita End If Dim tipodoc As String Dim numdoc As String Dim statodoc As String Dim presenze As String presenze = dati.m_nrpresenze If presenze.Length = 1 Then presenze = "0" & presenze End If If dati.m_Idalloggiato = 16 Or dati.m_Idalloggiato = 17 Or dati.m_Idalloggiato = 18 Then tipodoc = dati.d_codquestura numdoc = dati.m_nrdocumento statodoc = dati.luogodocumento Else tipodoc = "" numdoc = "" statodoc = "" End If If contarighe = maxrighe Then SW.Write(LSet(dati.m_Idalloggiato, 2) & _ LSet(dati.m_arrivo, 10) & _ RSet(presenze, 2) & _ LSet(cognome, 50) & _ LSet(nome, 30) & _ LSet(dati.clie_sesso, 1) & _ LSet(dati.clie_datanascita, 10) & _ LSet(comunenascita, 9) & _ LSet(siglaprov, 2) & _ LSet(statonascita, 9) & _ LSet(dati.cittadinanza, 9) & _ LSet(tipodoc, 5) & _ LSet(numdoc, 20) & _ LSet(statodoc, 9)) Else SW.Write(LSet(dati.m_Idalloggiato, 2) & _ LSet(dati.m_arrivo, 10) & _ LSet(presenze, 2) & _ LSet(cognome, 50) & _ LSet(nome, 30) & _ LSet(dati.clie_sesso, 1) & _ LSet(dati.clie_datanascita, 10) & _ LSet(comunenascita, 9) & _ LSet(siglaprov, 2) & _ LSet(statonascita, 9) & _ LSet(dati.cittadinanza, 9) & _ LSet(tipodoc, 5) & _ LSet(numdoc, 20) & _ LSet(statodoc, 9) & _ Chr(13) & Chr(10)) End If contarighe += 1 Next SW.Close() lbnrschedineyes.Text = "Schedine elaborate nr.: " & maxrighe Dim fs As System.IO.FileStream = Nothing fs = System.IO.File.Open(Server.MapPath("FileQuestura/" + sFileName + ".txt"), System.IO.FileMode.Open) Dim btFile(fs.Length) As Byte fs.Read(btFile, 0, fs.Length) fs.Close() With Response .Clear() .AddHeader("Content-disposition", "attachment;filename=" & sgetname) .ContentType = "application/octet-stream" .BinaryWrite(btFile) .End() End With End Using End Using Catch ex As Exception End Try
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5