Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Friend Class frmEnvioConsSGD
	Inherits System.Windows.Forms.Form
	
	Private Sub cmdGerar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdGerar.Click
		'Controle do Arquivo externo
		Dim strArquivo As String
		Dim intARQ As Short
		Dim strLinha As String
		Dim lngConta As Integer
		Dim strSql As Integer
		Dim rsUnidade As ADODB.Recordset
		rsUnidade = New ADODB.Recordset
		Dim strCodEnd As String
		Dim strZona As String
		Dim strLivro As String
		Dim strConta As String
		Dim strNome As String
		Dim strEnd As String
		Dim strNumero As String
		Dim strCep As String
		Dim strComplemento As String
		Dim strBairro As String
		Dim strMedidor As String
		Dim strDDDTel As String
		Dim strTel As String
		Dim strDDDCel As String
		Dim strCel As String
		Dim strEmail As String
		Dim strBranco As String
		Dim strTensao As String
		For lngConta = 0 To chkOpcao.Count - 1
			If chkOpcao(lngConta).CheckState Then
				If lngConta = 0 Then strArquivo = "SGD.txt"
				If lngConta = 1 Then strArquivo = "CONSGD.txt"
				
				intARQ = FreeFile
				FileOpen(intARQ, strArquivo, OpenMode.Output)
				
				strSql = CInt("SELECT * FROM unidb, consum WHERE consum.consreg = unidb.cons_id ")
				Call Conectar(CStr(strSql), rsUnidade)
				
				If rsUnidade.RecordCount > 0 Then
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					strCodEnd = IIf(IsDbNull(rsUnidade.Fields("codend").Value), "", rsUnidade.Fields("codend").Value)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					strZona = IIf(IsDbNull(rsUnidade.Fields("Zona").Value), "", rsUnidade.Fields("Zona").Value)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					strLivro = IIf(IsDbNull(rsUnidade.Fields("Livro").Value), "", rsUnidade.Fields("Livro").Value)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					strConta = IIf(IsDbNull(rsUnidade.Fields("Conta").Value), "", rsUnidade.Fields("Conta").Value)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					strNome = VB.Left(Trim(IIf(IsDbNull(rsUnidade.Fields("nome").Value), "", rsUnidade.Fields("nome").Value)) & New String(" ", 70), 70)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					strEnd = VB.Left(Trim(IIf(IsDbNull(rsUnidade.Fields("End").Value), "", rsUnidade.Fields("End").Value)) & New String(" ", 80), 80)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					strNumero = VB.Right(New String(" ", 10) & Trim(IIf(IsDbNull(rsUnidade.Fields("numero").Value), "", rsUnidade.Fields("numero").Value)), 10)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					strCep = Replace(Trim(IIf(IsDbNull(rsUnidade.Fields("cep").Value), "", rsUnidade.Fields("cep").Value)), "-", "")
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					strComplemento = VB.Left(Trim(IIf(IsDbNull(rsUnidade.Fields("complement").Value), "", rsUnidade.Fields("complement").Value)) & New String(" ", 40), 40)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					strBairro = VB.Left(Trim(IIf(IsDbNull(rsUnidade.Fields("bairro").Value), "", rsUnidade.Fields("bairro").Value)) & New String(" ", 40), 40)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					strMedidor = VB.Right(New String(" ", 20) & Trim(IIf(IsDbNull(rsUnidade.Fields("Num").Value), "", rsUnidade.Fields("Num").Value)), 20)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					strDDDTel = VB.Left(VB6.Format(Trim(IIf(IsDbNull(rsUnidade.Fields("dddtel").Value), "", rsUnidade.Fields("dddtel").Value)), "000") & New String(" ", 6), 6)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					strTel = VB.Left(Trim(IIf(IsDbNull(rsUnidade.Fields("telefone").Value), "", rsUnidade.Fields("telefone").Value)) & New String(" ", 30), 30)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					strDDDCel = VB.Left(VB6.Format(Trim(IIf(IsDbNull(rsUnidade.Fields("dddcel").Value), "", rsUnidade.Fields("dddcel").Value)), "000") & New String(" ", 6), 6)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					strCel = VB.Left(Trim(IIf(IsDbNull(rsUnidade.Fields("celular").Value), "", rsUnidade.Fields("celular").Value)) & New String(" ", 30), 30)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					strEmail = VB.Left(Trim(IIf(IsDbNull(rsUnidade.Fields("email").Value), "", rsUnidade.Fields("email").Value)) & New String(" ", 40), 40)
					strBranco = New String(" ", 20)
					strTensao = "00"
					
					
					strLinha = VB6.Format(VB.Right(Mid(strCodEnd, 9, 3), 3), "000") 'Local(Bairro)
					strLinha = strLinha & VB.Left(strLivro & VB.Right(strConta, 4) & New String(" ", 20), 20) 'Conta
					strLinha = strLinha & strNome 'Nome
					strLinha = strLinha & VB6.Format(VB.Right(Mid(strCodEnd, 12, 4), 3), "0000") 'Codigo Logradouro
					strLinha = strLinha & New String(" ", 22) 'Tipo Log
					strLinha = strLinha & strEnd 'Nome Log
					strLinha = strLinha & New String(" ", 6) 'TituloLog
					strLinha = strLinha & strNumero 'Numero
					strLinha = strLinha & strCep 'Cep
					strLinha = strLinha & strComplemento 'Complemento
					strLinha = strLinha & strBairro 'Bairro
					strLinha = strLinha & strMedidor 'Medidor
					
					
					
					PrintLine(intARQ, strLinha)
				End If
				If rsUnidade.State = 1 Then rsUnidade.Close()
				FileClose(intARQ)
			End If
		Next lngConta
	End Sub
End Class