Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. Imports System.IO
  2.  
  3. Public Class Form1
  4.  
  5. Private Sub btnExportar_Click(sender As Object, e As EventArgs) Handles btnExportar.Click
  6. Dim desde As Date = dtpDesde.Value
  7. Dim hasta As Date = dtpHasta.Value
  8.  
  9. Dim dtGenerarTxt As DataTable = fGenerarTxt(desde, hasta)
  10.  
  11.  
  12. MessageBox.Show(String.Format("Desde: {0}, Hasta {1}", desde, hasta))
  13. End Sub
  14.  
  15. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  16. dtpDesde.MinDate = New Date(2003, 1, 1)
  17. dtpDesde.MaxDate = Date.Now
  18. End Sub
  19.  
  20. Public Function fGenerarTxt(ByVal vDesde As Date, ByVal vHasta As Date) As DataTable
  21. 'Dim cCapaDatos As clsCapaDatos = New clsCapaDatos
  22. Dim dtTable As DataTable = New DataTable
  23. 'Try
  24. ' cCapaDatos.sConectarSQL()
  25. ' Dim sTextoSQL As String = "Tesoreria.obd_conusltar_ruc"
  26. ' cCapaDatos.sComandoSQL(sTextoSQL, CommandType.StoredProcedure)
  27. ' cCapaDatos.sParametroSQL("@min_date", DbType.Date, 10, vDesde)
  28. ' cCapaDatos.sParametroSQL("@max_date", DbType.Date, 10, vHasta)
  29. ' cCapaDatos.sAdaptadorSQL("R")
  30. ' dtTable = cCapaDatos.fListarTabla()
  31. ' Dim iNroRegistros As Integer = Convert.ToInt32(cCapaDatos.fListarTabla.DefaultView.Count)
  32. 'Catch ex As Exception
  33. ' cTempo.sMensaje(Convert.ToString(ex.Message))
  34. 'Finally
  35. ' cCapaDatos.sDesconectarSQL()
  36. 'End Try
  37. Return dtTable
  38. End Function
  39.  
  40. Private Sub ExportarArchivos(ByVal dtGenerarTxt As DataTable)
  41. Dim cad As String = ""
  42.  
  43. Dim maxRows As Integer = 100
  44. Dim contador As Integer
  45. Dim numArchivo As Integer = 1
  46. Dim ruta As String = "C:/ususario/carpeta/"
  47.  
  48. If dtGenerarTxt.Rows.Count > 0 Then
  49. For i As Integer = 0 To dtGenerarTxt.Rows.Count - 1
  50. contador = contador + 1
  51. cad += dtGenerarTxt.Rows(i)("RUC").ToString & "|" & vbNewLine
  52.  
  53. If contador = maxRows Or i = dtGenerarTxt.Rows.Count - 1 Then
  54. numArchivo += 1
  55. File.WriteAllText(ruta & "ruc_proveedor_" & dtGenerarTxt.Rows(0)("PERIODO").ToString & "_" & numArchivo & ".txt", cad)
  56. contador = 0
  57. End If
  58. Next
  59.  
  60. MessageBox.Show("Se generó correctamente el archivo. ", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Information)
  61. End If
  62. End Sub
  63.  
  64. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement