Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Imports Microsoft.VisualBasic.PowerPacks
Friend Class frmNovaUnid
	Inherits System.Windows.Forms.Form
	Public unid As String 'Controla se vai ser a tabela unidb ou unida
	Private glngUnid_id As Integer 'Variável de controle do Id da unidade consumidora
	Private glngCons_id As Integer 'Variável de controle do Id do consumidor
	Private ilngConsidO As Integer 'Variável de controle do Id do consumidor
	Private gstrModoConsEnd As String 'controla qual é o tipo de endereço localiza (do consumidor ou da unidade)
	Private istrGrupo As String 'Controla se vai ser a tabela unidb ou unida
	Private gintModoCons As Short '0 = novo consumidor, 1 = consumidor existente
	Private gblnContinua As Boolean
	Private iblnJaVerificou As Boolean
	Private gstrSiteCPF As String
	Private gstrSiteCNPJ As String
	Private istrLocaliza As String
	Private istrEndCodC As String
	Private istrEndCodUC As String
	Private istrEndCodEn As String
	Private ifrmCargaInstalada As frmCargaInstalada
	Private ifrmCadNis As frmCadNis
	Private ifrmPreencherEnde As FrmPreencherEnde
	Private ifrmLocalizaCnae As frmLocalizaCnae
	Private iintTab As Short
	Private istrCpfCnpj As String
	
	'UPGRADE_WARNING: Event cmbGrupo.SelectedIndexChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub cmbGrupo_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmbGrupo.SelectedIndexChanged
		If Me.cmbGrupo.SelectedIndex >= 0 Then
			istrGrupo = Trim(UCase(VB6.GetItemString(Me.cmbGrupo, Me.cmbGrupo.SelectedIndex)))
			If istrGrupo = "B" Then
				With Me.cmbTarifa
					Call .Items.Clear()
					.Items.Add("B1 - Residencial e Baixa Renda")
					.Items.Add("B2 - Rural, Cooperativa de Eletrificação Rural e Serviço Público de Irrigação")
					.Items.Add("B3 - Demais Classes")
					.Items.Add("B4 - Iluminação Pública")
				End With
			Else
				With Me.cmbTarifa
					Call .Items.Clear()
					.Items.Add("A4 - Convencional")
					.Items.Add("AS - Convencional Suprimento")
					.Items.Add("AA - Horo Sazonal Azul")
					.Items.Add("AV - Horo Sazonal Verde")
					.Items.Add("AL - Consumidor Livre")
					.Items.Add("AP - Auto Produtor")
				End With
			End If
		Else
			istrGrupo = "B"
			With Me.cmbTarifa
				Call .Items.Clear()
				.Items.Add("B1 - Residencial e Baixa Renda")
				.Items.Add("B2 - Rural, Cooperativa de Eletrificação Rural e Serviço Público de Irrigação")
				.Items.Add("B3 - Demais Classes")
				.Items.Add("B4 - Iluminação Pública")
			End With
		End If
	End Sub
	
	Private Sub cmdCancelImp_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdCancelImp.Click
		istrLocaliza = "U"
		Me.fmeReimpressao.Enabled = False
		Me.fmeReimpressao.Visible = False
	End Sub
	
	Private Sub cmdLimparAgrupamento_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdLimparAgrupamento.Click
		Me.txtAgrupaZona.Text = ""
		Me.txtAgrupaLivro.Text = ""
		Me.txtAgrupaConta.Text = ""
		Me.txtAgrupaNome.Text = ""
		Me.txtAgrupaRota.Text = ""
	End Sub
	
	Private Sub cmdLocalizaReimpressao_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdLocalizaReimpressao.Click
		istrLocaliza = "R"
		Call frmLocalizaUnidade.Show()
		Call frmLocalizaUnidade.SetaLocalizaUnidade("U", Me)
	End Sub
	
	Private Sub cmdLocCnae_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdLocCnae.Click
		Call frmLocalizaCnae.SetaLocalizaCnae(Me)
		Call frmLocalizaCnae.Show()
	End Sub
	
	Private Sub cmdLocZlcAgrupa_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdLocZlcAgrupa.Click
		istrLocaliza = "A"
		Call frmLocalizaUnidade.Show()
		Call frmLocalizaUnidade.SetaLocalizaUnidade("U", Me)
	End Sub
	
	Private Sub cmdOkEscolha_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdOkEscolha.Click
		Me.fmeEscolha.Visible = False
		Call Me.cmdLocaliza.Focus()
	End Sub
	
	Private Sub cmdOKImp_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdOKImp.Click
		Dim lstrProtocolo As String
		Dim lstrSql As String
		Dim lrstConsulta As ADODB.Recordset
		lrstConsulta = New ADODB.Recordset
		
		If Me.chkTermo.CheckState = 1 Then
			Call ImprimeTermoLigacao(glngUnid_id)
		End If
		If Me.opbLigacao.Checked Then
			lstrSql = ""
			lstrSql = lstrSql & "SELECT `solserv`.`protocolo` "
			lstrSql = lstrSql & "  FROM `solserv` "
			lstrSql = lstrSql & " WHERE LEFT(`solserv`.`protocolo`,2) = ""NO"" "
			lstrSql = lstrSql & "   AND `solserv`.`unid_id` = " & glngUnid_id & " "
			lstrSql = lstrSql & "   AND `solserv`.`unid`    = """ & UCase(istrGrupo) & """ "
			lstrSql = lstrSql & "   AND `solserv`.`sit`     = ""A"" "
			lstrSql = lstrSql & " ORDER BY `solserv`.`data_soli` DESC,`solserv`.`hora_soli` DESC LIMIT 0, 1 "
			Call Conectar(lstrSql, lrstConsulta)
			With lrstConsulta
				If .State > 0 Then
					If .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"'
						lstrProtocolo = IIf(IsDbNull(.Fields("protocolo").value), "NO000000000000", .Fields("protocolo").value)
					End If
					If .State = 1 Then Call .Close()
					
				End If
			End With
			If Len(Trim(lstrProtocolo)) > 0 Then
				Call ImprimeSolicitacao(glngCons_id, glngUnid_id, lstrProtocolo)
			Else
				Call MsgBox("Não existe ordem de serviço para este consumidor!", MsgBoxStyle.Exclamation, gstrTituloMensagem)
			End If
		Else
			Call ImprimeAlteracao(0, 0, glngCons_id, glngUnid_id)
		End If
		'UPGRADE_NOTE: Object lrstConsulta may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstConsulta = Nothing
	End Sub
	
	Private Sub cmdReimpressao_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdReimpressao.Click
		Me.fmeReimpressao.Enabled = True
		Me.fmeReimpressao.Visible = True
		Call Me.cmdLocalizaReimpressao.Focus()
	End Sub
	
	Private Sub lblAuxC_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles lblAuxC.Click
		Dim Index As Short = lblAuxC.GetIndex(eventSender)
		Select Case Index
			Case 2
				Call ShellExecute(Handle.ToInt32, "open", gstrSiteCPF, vbNullString, vbNullString, SW_SHOWNORMAL)
			Case 3
				Call ShellExecute(Handle.ToInt32, "open", gstrSiteCNPJ, vbNullString, vbNullString, SW_SHOWNORMAL)
		End Select
	End Sub
	
	Private Sub LigDesEntrega(ByVal ablnModo As Boolean)
		Me.txtEndEntrega.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(ablnModo, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
		Me.txtNumEntrega.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(ablnModo, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
		Me.txtBaiEntrega.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(ablnModo, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
		Me.txtCidEntrega.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(ablnModo, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
		Me.txtCepEntrega.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(ablnModo, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
		Me.txtUfEntrega.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(ablnModo, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
		
		Me.txtEndEntrega.ReadOnly = Not ablnModo
		Me.txtNumEntrega.ReadOnly = Not ablnModo
		Me.txtBaiEntrega.ReadOnly = Not ablnModo
		Me.txtCidEntrega.ReadOnly = Not ablnModo
		Me.txtCepEntrega.ReadOnly = Not ablnModo
		Me.txtUfEntrega.ReadOnly = Not ablnModo
	End Sub
	
	Private Sub frmNovaUnid_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		ifrmCargaInstalada = New frmCargaInstalada
		ifrmCadNis = New frmCadNis
		ifrmPreencherEnde = New FrmPreencherEnde
		ifrmLocalizaCnae = New frmLocalizaCnae
		iblnJaVerificou = False
		istrGrupo = "B"
		unid = "unidb"
		Me.cmbGrupo.SelectedIndex = 1
		Me.sstCadastros.SelectedIndex = 0 'Seleciona a guia Dados do Consumidor
		Me.sstCadastros.TabPages.Item(1).Enabled = False 'desabilita a guia Dados da Unidade Consumidora
		Me.sstCadastros.TabPages.Item(2).Enabled = False 'desabilita a guia Dados da Unidade Consumidora
		Me.cmdNis.Enabled = False
		istrLocaliza = "U"
		Call LigDesEntrega(False)
		Call EnchemfgEndereco()
		
		Call CarregaTabelaComboBox((Me.cmbClasse), "`classe`", " CONCAT(`codigo`,' - ', `descricao`) ", "`codigo`", "`codigo`",  , 0, "`codigo` <> '9100'")
		Call CarregaTabelaComboBox((Me.cmbAgrupa), "`agrupa`", " `descricao` ", "`codigo`", "`codigo` ASC")
		Call CarregaTabelaComboBox((Me.cmbTensao), "`tensao`", " `valor` ", "`id`", "`id`",  , 0)
		
		Call EncheComboDtVecto()
		Call EncheComboBanco()
		
		With Me.cmbRegiao
			Call .Items.Clear()
			Call .Items.Add("Urbana")
			Call .Items.Add("Rural")
			.SelectedIndex = 0
		End With
		With Me.cmbTipoLigacao
			Call .Items.Clear()
			Call .Items.Add("Aéreo")
			Call .Items.Add("Subterrâneo")
			.SelectedIndex = 0
		End With
		With Me.cmbFase
			Call .Items.Clear()
			Call .Items.Add("MONOFÁSICO")
			Call .Items.Add("BIFÁSICO")
			Call .Items.Add("TRIFÁSICO")
			.SelectedIndex = -1
		End With
		With Me.cmbFaseLigU
			Call .Items.Clear()
			Call .Items.Add("AN")
			Call .Items.Add("BN")
			Call .Items.Add("CN")
			Call .Items.Add("ABN")
			Call .Items.Add("ACN")
			Call .Items.Add("BCN")
			Call .Items.Add("ABCN")
			Call .Items.Add("AB")
			Call .Items.Add("AC")
			Call .Items.Add("BC")
			Call .Items.Add("ABC")
		End With
		
		
		
		Call cmbGrupo_SelectedIndexChanged(cmbGrupo, New System.EventArgs())
		gstrSiteCPF = LeConfig("RCF_CPF_SITE")
		gstrSiteCNPJ = LeConfig("RCF_CNPJ_SITE")
	End Sub
	
	Private Sub frmNovaUnid_KeyDown(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
		Dim KeyCode As Short = eventArgs.KeyCode
		Dim Shift As Short = eventArgs.KeyData \ &H10000
		If KeyCode = System.Windows.Forms.Keys.Return Or KeyCode = System.Windows.Forms.Keys.Tab Then
			'UPGRADE_ISSUE: Control TabIndex could not be resolved because it was within the generic namespace ActiveControl. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="084D22AD-ECB1-400F-B4C7-418ECEC5E36E"'
			If VB6.GetActiveControl().TabIndex = 56 Then 'Ultimo campo da guia de consumidor
				If Me.sstCadastros.TabPages.Item(1).Enabled Then
					Me.sstCadastros.SelectedIndex = 1
				End If
			End If
		End If
	End Sub
	
	Private Sub frmNovaUnid_KeyUp(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
		Dim KeyCode As Short = eventArgs.KeyCode
		Dim Shift As Short = eventArgs.KeyData \ &H10000
		If KeyCode = System.Windows.Forms.Keys.Return Or KeyCode = System.Windows.Forms.Keys.ShiftKey Or KeyCode = System.Windows.Forms.Keys.Tab Then
			If TypeOf VB6.GetActiveControl() Is System.Windows.Forms.TextBox Then
				Call SelTodoCampo(VB6.GetActiveControl(), True)
			End If
		End If
		Call validaCamposConsumidor()
		Call validaCamposUnidade()
	End Sub
	
	Private Sub frmNovaUnid_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
		Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
		Dim lstrCampo As String
		
		If KeyAscii = System.Windows.Forms.Keys.Escape Then
			Call cmdFechar_Click(cmdFechar, New System.EventArgs())
		Else
			'UPGRADE_ISSUE: Control Name could not be resolved because it was within the generic namespace ActiveControl. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="084D22AD-ECB1-400F-B4C7-418ECEC5E36E"'
			lstrCampo = VB6.GetActiveControl().Name
			Select Case lstrCampo
				Case "txtDddFone", "txtDddCel", "txtArea", "txtDisjuntor"
					Call ControleTecla(KeyAscii, "N")
				Case Else
					Call ControleTecla(KeyAscii, "A")
			End Select
		End If
		eventArgs.KeyChar = Chr(KeyAscii)
		If KeyAscii = 0 Then
			eventArgs.Handled = True
		End If
	End Sub
	
	Private Sub MontaGrid()
		With Me.mfgEndereco
			.Rows = 1
			Call .Clear()
			.set_ColWidth(0, 900)
			.set_TextMatrix(0, 0, "Código")
			.set_ColWidth(1, 3700)
			.set_TextMatrix(0, 1, "Endereço")
			.set_ColWidth(2, 700)
			.set_TextMatrix(0, 2, "Número")
			.set_ColWidth(3, 1500)
			.set_TextMatrix(0, 3, "Complemento")
			.set_ColWidth(4, 1000)
			.set_TextMatrix(0, 4, "Bairro")
			.set_ColWidth(5, 1000)
			.set_TextMatrix(0, 5, "Cidade ")
			.set_ColWidth(6, 1000)
			.set_TextMatrix(0, 6, "U.F.")
			.set_ColWidth(7, 1000)
			.set_TextMatrix(0, 7, "C.E.P.")
		End With
	End Sub
	
	Private Sub EnchemfgEndereco()
		Dim lstrSql As String
		Dim lrstEnd As ADODB.Recordset
		lrstEnd = New ADODB.Recordset
		Call MontaGrid()
		lstrSql = ""
		lstrSql = lstrSql & "SELECT `codendereco`.`codigo`, "
		lstrSql = lstrSql & "       `codendereco`.`endereco`, "
		lstrSql = lstrSql & "       `codendereco`.`numero`, "
		lstrSql = lstrSql & "       `codendereco`.`complemento`, "
		lstrSql = lstrSql & "       `codendereco`.`bairro`, "
		lstrSql = lstrSql & "       `codendereco`.`cidade`, "
		lstrSql = lstrSql & "       `codendereco`.`uf`, "
		lstrSql = lstrSql & "       `codendereco`.`cep` "
		lstrSql = lstrSql & "  FROM `codendereco` "
		lstrSql = lstrSql & " ORDER BY `codendereco`.`complemento` ASC "
		Call Conectar(lstrSql, lrstEnd)
		With lrstEnd
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				If .RecordCount > 0 Then
					While Not .EOF
						mfgEndereco.Rows = mfgEndereco.Rows + 1
						'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"'
						mfgEndereco.set_TextMatrix(mfgEndereco.Rows - 1, 0, IIf(IsDbNull(.Fields("codigo").value), "", .Fields("codigo").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"'
						mfgEndereco.set_TextMatrix(mfgEndereco.Rows - 1, 1, IIf(IsDbNull(.Fields("endereco").value), "", .Fields("endereco").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"'
						mfgEndereco.set_TextMatrix(mfgEndereco.Rows - 1, 2, IIf(IsDbNull(.Fields("numero").value), "", .Fields("numero").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"'
						mfgEndereco.set_TextMatrix(mfgEndereco.Rows - 1, 3, IIf(IsDbNull(.Fields("complemento").value), "", .Fields("complemento").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"'
						mfgEndereco.set_TextMatrix(mfgEndereco.Rows - 1, 4, IIf(IsDbNull(.Fields("bairro").value), "", .Fields("bairro").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"'
						mfgEndereco.set_TextMatrix(mfgEndereco.Rows - 1, 5, IIf(IsDbNull(.Fields("cidade").value), "", .Fields("cidade").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"'
						mfgEndereco.set_TextMatrix(mfgEndereco.Rows - 1, 6, IIf(IsDbNull(.Fields("uf").value), "", .Fields("uf").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"'
						mfgEndereco.set_TextMatrix(mfgEndereco.Rows - 1, 7, IIf(IsDbNull(.Fields("cep").value), "", .Fields("cep").value))
						Call .MoveNext()
					End While
				End If
				Call .Close()
			End If
		End With
		'UPGRADE_NOTE: Object lrstEnd may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstEnd = Nothing
	End Sub
	
	Private Sub EncheComboDtVecto()
		Dim lstrDatas As String
		Dim lstrAux As String
		Dim lintPos As Short
		
		lstrDatas = LeConfig("DATAS_VENCIMENTO") 'função que retorna as datas de vencimento em uma string
		lstrAux = ""
		lintPos = 1
		With Me.cmbDiaVenc
			Call .Items.Clear()
			Call .Refresh()
			While lintPos <= Len(lstrDatas)
				If Mid(lstrDatas, lintPos, 1) <> ";" Then
					lstrAux = lstrAux & Mid(lstrDatas, lintPos, 1)
				ElseIf Mid(lstrDatas, lintPos, 1) = ";" Then 
					Call .Items.Add(lstrAux)
					lstrAux = ""
				End If
				lintPos = lintPos + 1
			End While
			If Len(Trim(lstrDatas)) = 0 Then Call .Items.Add("00")
		End With
	End Sub
	
	Private Sub EncheComboBanco()
		Dim lstrSql As String
		Dim lstrNrBco As String
		Dim lstrNmBco As String
		Dim lstrTpMov As String
		Dim llngBanId As Integer
		Dim llngLinha As Integer
		Dim lrstBanco As ADODB.Recordset
		lrstBanco = New ADODB.Recordset
		Call Me.cmbBanco.Items.Clear()
		lstrSql = ""
		lstrSql = lstrSql & "SELECT `ban_id`, `nrbco`, `nmbco`, `tpmovto` "
		lstrSql = lstrSql & "  FROM `bancos` "
		lstrSql = lstrSql & " WHERE `grupo` = 'C' "
		lstrSql = lstrSql & " ORDER BY `nrbco` ASC, `ban_id` ASC "
		Call Conectar(lstrSql, lrstBanco)
		With lrstBanco
			If .RecordCount > 0 Then
				While Not .EOF
					'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"'
					lstrNrBco = VB6.Format(Trim(IIf(IsDbNull(.Fields("nrbco").value), "0", .Fields("nrbco").value)), "000")
					'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"'
					lstrNmBco = Trim(IIf(IsDbNull(.Fields("nmbco").value), "SEM NOME", .Fields("nmbco").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"'
					llngBanId = IIf(IsDbNull(.Fields("ban_id").value), 0, .Fields("ban_id").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"'
					lstrTpMov = Trim(IIf(IsDbNull(.Fields("tpmovto").value), "N", .Fields("tpmovto").value))
					Call Me.cmbBanco.Items.Add(lstrNrBco & " - " & IIf(lstrTpMov = "D", "(DÉBITO) ", "") & lstrNmBco)
					'UPGRADE_ISSUE: ComboBox property cmbBanco.NewIndex was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="F649E068-7137-45E5-AC20-4D80A3CC70AC"'
					VB6.SetItemData(Me.cmbBanco, Me.cmbBanco.NewIndex, llngBanId)
					Call .MoveNext()
				End While
			Else
				Call Me.cmbBanco.Items.Add("000 - (nenhum)")
				'UPGRADE_ISSUE: ComboBox property cmbBanco.NewIndex was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="F649E068-7137-45E5-AC20-4D80A3CC70AC"'
				VB6.SetItemData(Me.cmbBanco, Me.cmbBanco.NewIndex, 0)
			End If
			If .State = 1 Then Call .Close()
		End With
		Me.cmbBanco.SelectedIndex = 0
		'UPGRADE_NOTE: Object lrstBanco may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstBanco = Nothing
		llngBanId = CInt(LeConfig("COD_BANCO_PRINCIPAL"))
		llngLinha = 0
		While llngLinha < Me.cmbBanco.Items.Count
			If VB6.GetItemData(Me.cmbBanco, llngLinha) = llngBanId Then
				Me.cmbBanco.SelectedIndex = llngLinha
				llngLinha = Me.cmbBanco.Items.Count
			End If
			llngLinha = llngLinha + 1
		End While
	End Sub
	
	'UPGRADE_WARNING: Event opbAlteraCad.CheckedChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub opbAlteraCad_CheckedChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles opbAlteraCad.CheckedChanged
		If eventSender.Checked Then
			With opbAlteraCad
				Me.txtZona.ReadOnly = .Checked
				Me.txtLivro.ReadOnly = .Checked
				Me.txtConta.ReadOnly = .Checked
				Me.cmbGrupo.Enabled = Not .Checked
			End With
		End If
	End Sub
	
	Private Sub sstCadastros_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles sstCadastros.SelectedIndexChanged
		Static PreviousTab As Short = sstCadastros.SelectedIndex()
		If PreviousTab = 0 Then
			If Me.sstCadastros.SelectedIndex = 1 Then
				Me.fmeEscolha.Visible = True
				Me.fmeEscolha.Enabled = True
			End If
		End If
		PreviousTab = sstCadastros.SelectedIndex()
	End Sub
	
	Private Sub txtCdCnae_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtCdCnae.Leave
		Call SetaCnae(0, Me.txtCdCnae.Text)
	End Sub
	
	Private Sub txtConta_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtConta.Leave
		With Me.txtConta
			.Text = VB6.Format(.Text, "000000")
			If Len(Trim(.Text)) = 0 Or Trim(.Text) = "000000" Then
				.Text = "999999"
			End If
		End With
	End Sub
	
	'UPGRADE_WARNING: Event txtCpf.TextChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub txtCpf_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtCpf.TextChanged
		istrCpfCnpj = ""
		iblnJaVerificou = False
	End Sub
	
	Private Sub txtCpf_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtCpf.KeyPress
		Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
		If KeyAscii = System.Windows.Forms.Keys.Return Or KeyAscii = System.Windows.Forms.Keys.Tab Then
			If iblnJaVerificou = False Then Call VerificaPendencias()
		End If
		eventArgs.KeyChar = Chr(KeyAscii)
		If KeyAscii = 0 Then
			eventArgs.Handled = True
		End If
	End Sub
	
	Private Sub txtCPF_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtCPF.Leave
		If istrCpfCnpj <> Str_Retira(Me.txtCPF.Text, ".-/ ") Then Call VerificaPendencias()
	End Sub
	
	Private Sub VerificaPendencias()
		Dim lstrPedZLCs As String
		Dim lstrSql As String
		Dim lrstConsumidor As ADODB.Recordset
		Dim lrstFaturas As ADODB.Recordset
		Dim lstrNome As String
		Dim lstrCpfCnpj As String
		
		lrstConsumidor = New ADODB.Recordset
		lrstFaturas = New ADODB.Recordset
		lstrPedZLCs = ""
		glngCons_id = 0
		glngUnid_id = 0
		gintModoCons = 0
		If Trim(Me.txtCPF.Text) <> "" Then
			lstrCpfCnpj = Str_Retira(Me.txtCPF.Text, ".-/ ")
			istrCpfCnpj = lstrCpfCnpj
			If Valida_CPF_CGC(lstrCpfCnpj) Then
				Me.txtCPF.Text = gstrDocumentoCpfCnpj
				lstrCpfCnpj = Str_Retira(Me.txtCPF.Text, ".-/ ")
				gstrDocumentoCpfCnpj = ""
				lstrSql = ""
				lstrSql = lstrSql & "SELECT * "
				lstrSql = lstrSql & "  FROM `consum` "
				lstrSql = lstrSql & " WHERE `consum`.`cgc` = """ & lstrCpfCnpj & """ "
				Call Conectar(lstrSql, lrstConsumidor)
				With lrstConsumidor
					If .RecordCount > 0 Then
						If .RecordCount > 1 Then
							Call MsgBox("O " & IIf(Len(lstrCpfCnpj) = 11, "CPF", "CNPJ") & " digitado consta em mais de um consumidor!" & vbCrLf & vbCrLf & "Por favor, verifique na tela de consulta.", MsgBoxStyle.Exclamation, gstrTituloMensagem)
						Else
							'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"'
							lstrNome = IIf(IsDbNull(.Fields("nome").value), "", .Fields("nome").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"'
							Me.txtIe.Text = IIf(IsDbNull(.Fields("insc").value), "", .Fields("insc").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"'
							Me.txtRG.Text = IIf(IsDbNull(.Fields("rg").value), "", .Fields("rg").value)
							Me.txtNome.Text = lstrNome
							Me.txtSolic.Text = lstrNome
							'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"'
							Me.txtDtNasc.Text = IIf(IsDbNull(.Fields("dt_nascto").value), "", .Fields("dt_nascto").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"'
							istrEndCodC = IIf(IsDbNull(.Fields("codend").value), "", .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"'
							Me.lblEndC.Text = IIf(IsDbNull(.Fields("end").value), "", .Fields("end").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"'
							Me.txtNrC.Text = IIf(IsDbNull(.Fields("numero").value), "", .Fields("numero").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"'
							Me.lblBairroC.Text = IIf(IsDbNull(.Fields("bairro").value), "", .Fields("bairro").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"'
							Me.lblMunicipioC.Text = IIf(IsDbNull(.Fields("cidade").value), "", .Fields("cidade").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"'
							Me.txtLoteC.Text = IIf(IsDbNull(.Fields("lote").value), "", .Fields("lote").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"'
							Me.lblCepC.Text = IIf(IsDbNull(.Fields("cep").value), "", .Fields("cep").value)
							Me.lblCepC.Text = IIf(Len(Me.lblCepC.Text) = 8, VB.Left(Me.lblCepC.Text, 5) & "-" & VB.Right(Me.lblCepC.Text, 3), Me.lblCepC.Text)
							'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"'
							Me.lblUfC.Text = IIf(IsDbNull(.Fields("uf").value), "", .Fields("uf").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"'
							Me.lblDistritoC.Text = IIf(IsDbNull(.Fields("distrito").value), "", .Fields("distrito").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"'
							Me.txtQuadraC.Text = IIf(IsDbNull(.Fields("quadra").value), "", .Fields("quadra").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"'
							Me.txtEmail.Text = IIf(IsDbNull(.Fields("email").value), "", .Fields("email").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"'
							Me.txtNomePai.Text = IIf(IsDbNull(.Fields("nomepai").value), "", .Fields("nomepai").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"'
							Me.txtNomeMae.Text = IIf(IsDbNull(.Fields("nomemae").value), "", .Fields("nomemae").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"'
							Me.txtDddFone.Text = IIf(IsDbNull(.Fields("dddtel").value), "", .Fields("dddtel").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"'
							Me.txtFone.Text = IIf(IsDbNull(.Fields("telefone").value), "", .Fields("telefone").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"'
							Me.txtDddCel.Text = IIf(IsDbNull(.Fields("dddcel").value), "", .Fields("dddcel").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"'
							Me.txtCelular.Text = IIf(IsDbNull(.Fields("cel").value), "", .Fields("cel").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"'
							glngCons_id = IIf(IsDbNull(.Fields("consreg").value), 0, .Fields("consreg").value)
							gintModoCons = 1
						End If
					Else
						If MsgBox("Não há consumidores com este " & IIf(Len(lstrCpfCnpj) = 11, "CPF", "CNPJ") & ". Deseja Cadastrar um novo consumidor?", MsgBoxStyle.YesNo + MsgBoxStyle.DefaultButton1 + MsgBoxStyle.Question, gstrTituloMensagem) = MsgBoxResult.No Then
							Call LimpaCampos((Me.fmeCons))
							Call Me.txtCPF.Focus()
							glngCons_id = 0
							glngUnid_id = 0
							gintModoCons = 0
						Else
							
						End If
					End If
				End With
				If glngCons_id > 0 Then
					lstrSql = ""
					lstrSql = lstrSql & "SELECT DISTINCT `nf`.`zona`, `nf`.`livro`, `nf`.`conta`, `nf`.`cons_id`, `nf`.`flgst` "
					lstrSql = lstrSql & "  FROM `nf` USE INDEX(KeyCons) "
					lstrSql = lstrSql & " WHERE `nf`.`cons_id` = " & glngCons_id & " "
					lstrSql = lstrSql & "   AND (TRIM(`nf`.`flgst`) = """" OR `nf`.`flgst` IS NULL) "
					lstrSql = lstrSql & "   AND `nf`.`datavenc` < '" & VB6.Format(BuscaDataBD, "yyyy-MM-dd") & "' "
					Call Conectar(lstrSql, lrstFaturas)
					With lrstFaturas
						If .State = ADODB.ObjectStateEnum.adStateOpen Then
							If .RecordCount > 0 Then
								While Not .EOF
									lstrPedZLCs = lstrPedZLCs & "("
									'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"'
									lstrPedZLCs = lstrPedZLCs & IIf(IsDbNull(.Fields("zona").value), "", .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"'
									lstrPedZLCs = lstrPedZLCs & IIf(IsDbNull(.Fields("livro").value), "", .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"'
									lstrPedZLCs = lstrPedZLCs & IIf(IsDbNull(.Fields("conta").value), "", .Fields("conta").value) & ", "
									Call .MoveNext()
								End While
								lstrPedZLCs = VB.Left(lstrPedZLCs, Len(lstrPedZLCs) - 2) & ")"
								Call MsgBox("Nome no cadastro: " & lstrNome & "." & vbCrLf & vbCrLf & "Constam pendências para o consumidor. Por favor, verifique!" & vbCrLf & lstrPedZLCs, MsgBoxStyle.Information, gstrTituloMensagem)
							Else
								Call MsgBox("Nome no cadastro: " & lstrNome & "." & vbCrLf & vbCrLf & "Não constam pendências!", MsgBoxStyle.Information, gstrTituloMensagem)
								Call SendKeysA(System.Windows.Forms.Keys.Tab, True)
							End If
						End If
					End With
					Call validaCamposConsumidor()
				End If
			Else
				Select Case Len(lstrCpfCnpj)
					Case Is <= 11
						Me.txtCPF.Text = FormataCPF(lstrCpfCnpj)
						Call MsgBox("O CPF não é válido!", MsgBoxStyle.Exclamation, gstrTituloMensagem)
					Case Is >= 11
						Me.txtCPF.Text = FormataCNPJ(lstrCpfCnpj)
						Call MsgBox("O CNPJ não é válido!", MsgBoxStyle.Exclamation, gstrTituloMensagem)
					Case Else
						Call MsgBox("O número digitado não é um CPF ou CNPJ válido!", MsgBoxStyle.Exclamation, gstrTituloMensagem)
				End Select
				Me.txtCPF.Focus()
			End If
		Else
			Call MsgBox("Faltou informar um CPF ou CNPJ válido!", MsgBoxStyle.Exclamation, gstrTituloMensagem)
			Me.txtCPF.Focus()
		End If
		If lrstConsumidor.State = 1 Then Call lrstConsumidor.Close()
		If lrstFaturas.State = 1 Then Call lrstFaturas.Close()
		'UPGRADE_NOTE: Object lrstConsumidor may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstConsumidor = Nothing
		'UPGRADE_NOTE: Object lrstFaturas may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstFaturas = Nothing
		iblnJaVerificou = True
	End Sub
	
	Private Sub txtDtNasc_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtDtNasc.Leave
		Me.txtDtNasc.Text = FormataData(Me.txtDtNasc, 2)
	End Sub
	
	Private Sub txtLivro_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLivro.Leave
		With Me.txtLivro
			.Text = VB6.Format(.Text, "00")
			If Len(Trim(.Text)) = 0 Or Trim(.Text) = "00" Then
				.Text = "99"
			End If
		End With
	End Sub
	
	Private Sub txtNome_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtNome.Leave
		Me.txtNome.Text = UCase(Me.txtNome.Text)
	End Sub
	
	Private Sub cmdEndereco_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdEndereco.Click
		gstrModoConsEnd = "C"
		Call ifrmPreencherEnde.Show()
		Call ifrmPreencherEnde.SetaPreencherEnde(Me, False)
	End Sub
	
	Private Sub txtNomePai_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtNomePai.Leave
		Me.txtNomePai.Text = UCase(Me.txtNomePai.Text)
	End Sub
	
	Private Sub txtNomeMae_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtNomeMae.Leave
		Me.txtNomeMae.Text = UCase(Me.txtNomeMae.Text)
	End Sub
	
	'UPGRADE_WARNING: Event opbNLiga.CheckedChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub opbNLiga_CheckedChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles opbNLiga.CheckedChanged
		If eventSender.Checked Then
			With opbNLiga
				Me.txtZona.ReadOnly = Not .Checked
				Me.txtLivro.ReadOnly = Not .Checked
				Me.txtConta.ReadOnly = Not .Checked
				Me.cmdNis.Enabled = Not .Checked
				Me.cmbGrupo.Enabled = .Checked
			End With
			glngUnid_id = 0
			'Me.txtZona.Text = "999"
			'Me.txtLivro.Text = "99"
			'Me.txtConta.Text = "999999"
			If Trim(Me.txtNomeUC.Text) = "" Then Me.txtNomeUC.Text = Me.txtNome.Text
			'Me.cmbTipoLigacao.ListIndex = 0
		End If
	End Sub
	
	Private Sub cmdLocaliza_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdLocaliza.Click
		istrLocaliza = "U"
		Call frmLocalizaUnidade.Show()
		Call frmLocalizaUnidade.SetaLocalizaUnidade("U", Me)
	End Sub
	
	'UPGRADE_WARNING: Event cmbDiaVenc.SelectedIndexChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub cmbDiaVenc_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmbDiaVenc.SelectedIndexChanged
		Call validaCamposConsumidor()
		Call validaCamposUnidade()
	End Sub
	
	'Versão: 001 Desenvolvedor: Ricardo Inacio Data: 08/04/2008 Descrição: Rotina que iguala ou não os endereços da unidade consumidora com o do consumidor
	'UPGRADE_WARNING: Event chkMesmoEnd.CheckStateChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub chkMesmoEnd_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles chkMesmoEnd.CheckStateChanged
		With Me.chkMesmoEnd
			Me.lblEndUc.Text = IIf(.CheckState = 1, Me.lblEndC.Text, "")
			Me.txtNrUc.Text = IIf(.CheckState = 1, Me.txtNrC.Text, "")
			Me.txtComplemUC.Text = IIf(.CheckState = 1, Me.txtCompleC.Text, "")
			Me.lblBairroUc.Text = IIf(.CheckState = 1, Me.lblBairroC.Text, "")
			Me.lblMunicipioUc.Text = IIf(.CheckState = 1, Me.lblMunicipioC.Text, "")
			Me.lblCepUc.Text = IIf(.CheckState = 1, Me.lblCepC.Text, "")
			Me.lblUfUc.Text = IIf(.CheckState = 1, Me.lblUfC.Text, "")
			Me.lblDistritoUc.Text = IIf(.CheckState = 1, Me.lblDistritoC.Text, "")
			Me.txtLoteUc.Text = IIf(.CheckState = 1, Me.txtLoteC.Text, "")
			Me.txtQuadraUc.Text = IIf(.CheckState = 1, Me.txtQuadraC.Text, "")
			istrEndCodUC = istrEndCodC
		End With
		Call opbEndPadrao_CheckedChanged(opbEndPadrao, New System.EventArgs())
	End Sub
	
	Private Sub txtNomeUC_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtNomeUC.Leave
		Me.txtNomeUC.Text = UCase(Me.txtNomeUC.Text)
	End Sub
	
	Private Sub cmdEnderecoUC_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdEnderecoUC.Click
		gstrModoConsEnd = "UC"
		Call ifrmPreencherEnde.Show()
		Call ifrmPreencherEnde.SetaPreencherEnde(Me, False)
	End Sub
	
	'UPGRADE_WARNING: Event cmbClasse.SelectedIndexChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub cmbClasse_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmbClasse.SelectedIndexChanged
		Dim lstrClas As String
		Call validaCamposConsumidor()
		Call validaCamposUnidade()
		If Me.cmbClasse.SelectedIndex >= 0 And Me.cmbGrupo.SelectedIndex >= 0 Then
			If Trim(VB6.GetItemString(Me.cmbGrupo, Me.cmbGrupo.SelectedIndex)) = "B" Then
				lstrClas = VB6.Format(VB6.GetItemData(Me.cmbClasse, Me.cmbClasse.SelectedIndex), "0000")
				If CDbl(VB.Left(lstrClas, 1)) = 9 Then
					Me.cmbTarifa.SelectedIndex = 0
				ElseIf CDbl(VB.Left(lstrClas, 1)) = 5 Then 
					Me.cmbTarifa.SelectedIndex = 1
				ElseIf CDbl(VB.Left(lstrClas, 2)) = 64 Then 
					Me.cmbTarifa.SelectedIndex = 3
				Else
					Me.cmbTarifa.SelectedIndex = 2
				End If
			End If
		End If
	End Sub
	
	'UPGRADE_WARNING: Event cmbTarifa.SelectedIndexChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub cmbTarifa_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmbTarifa.SelectedIndexChanged
		Call validaCamposConsumidor()
		Call validaCamposUnidade()
		Me.cmdNis.Enabled = (Me.cmbFase.SelectedIndex = 0 And Me.cmbTarifa.SelectedIndex = 0 And Me.opbNLiga.Checked = False)
	End Sub
	
	'UPGRADE_WARNING: Event cmbFase.SelectedIndexChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub cmbFase_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmbFase.SelectedIndexChanged
		Call validaCamposConsumidor()
		Call validaCamposUnidade()
		If cmbFase.SelectedIndex = 0 Or cmbFase.SelectedIndex = 1 Then
			Me.cmbTensao.SelectedIndex = 1
		Else
			Me.cmbTensao.SelectedIndex = 2
		End If
		Me.cmdNis.Enabled = (Me.cmbFase.SelectedIndex = 0 And Me.cmbTarifa.SelectedIndex = 0 And Me.opbNLiga.Checked = False)
	End Sub
	
	Private Sub cmdCargaInstalada_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdCargaInstalada.Click
		If glngUnid_id = 0 Then
			Call MsgBox("Impossível cadastrar a carga instalada desta unidade consumidora.", MsgBoxStyle.Information, gstrTituloMensagem)
		Else
			Call ifrmCargaInstalada.Show()
			Call ifrmCargaInstalada.SetaCarga(Me.txtZona.Text, Me.txtLivro.Text, Me.txtConta.Text, Me.txtNome.Text, glngUnid_id, "B", Me)
		End If
	End Sub
	
	'UPGRADE_WARNING: Event opbPreCad.CheckedChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub opbPreCad_CheckedChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles opbPreCad.CheckedChanged
		If eventSender.Checked Then
			Me.mfgEndereco.Visible = True
			Call LigDesEntrega(False)
			Me.mfgEndereco.Focus()
			Me.fmeEntrega.Visible = False
		End If
	End Sub
	
	Private Sub mfgEndereco_DblClick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles mfgEndereco.DblClick
		With Me.mfgEndereco
			If .Rows > 1 Then
				Me.fmeEntrega.Visible = True
				Me.txtEndEntrega.Text = .get_TextMatrix(.Row, 1)
				Me.txtNumEntrega.Text = .get_TextMatrix(.Row, 2)
				Me.txtBaiEntrega.Text = .get_TextMatrix(.Row, 4)
				Me.txtCidEntrega.Text = .get_TextMatrix(.Row, 5)
				Me.txtCepEntrega.Text = .get_TextMatrix(.Row, 7)
				Me.txtUfEntrega.Text = .get_TextMatrix(.Row, 6)
				.Visible = False
				Me.opbPreCad.Checked = False
			End If
		End With
	End Sub
	
	'UPGRADE_WARNING: Event opbEndPadrao.CheckedChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub opbEndPadrao_CheckedChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles opbEndPadrao.CheckedChanged
		If eventSender.Checked Then
			Me.mfgEndereco.Visible = False
			Call LigDesEntrega(False)
			
			' ----- Iguala ao endereço da UC
			Me.txtEndEntrega.Text = Me.lblEndUc.Text
			Me.txtNumEntrega.Text = Me.txtNrUc.Text
			Me.txtComplEntrega.Text = Me.txtComplemUC.Text
			Me.txtBaiEntrega.Text = Me.lblBairroUc.Text
			Me.txtCidEntrega.Text = Me.lblMunicipioUc.Text
			Me.txtCepEntrega.Text = Me.lblCepUc.Text
			Me.txtUfEntrega.Text = Me.lblUfUc.Text
			Me.txtDisEntrega.Text = Me.lblDistritoUc.Text
			istrEndCodEn = istrEndCodUC
		End If
	End Sub
	
	'UPGRADE_WARNING: Event opbEndOutro.CheckedChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub opbEndOutro_CheckedChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles opbEndOutro.CheckedChanged
		If eventSender.Checked Then
			Me.mfgEndereco.Visible = False
			Call LigDesEntrega(True)
			Me.txtEndEntrega.Text = ""
			Me.txtNumEntrega.Text = ""
			Me.txtComplEntrega.Text = ""
			Me.txtBaiEntrega.Text = ""
			Me.txtCidEntrega.Text = ""
			Me.txtCepEntrega.Text = ""
			Me.txtUfEntrega.Text = ""
			Me.txtDisEntrega.Text = ""
		End If
	End Sub
	
	Private Sub cmdEnderecoE_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdEnderecoE.Click
		Me.opbEndOutro.Checked = True
		Me.opbEndPadrao.Checked = False
		gstrModoConsEnd = "E"
		Call ifrmPreencherEnde.Show()
		Call ifrmPreencherEnde.SetaPreencherEnde(Me, True)
	End Sub
	
	Private Sub cmdNis_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdNis.Click
		Dim lintTamanho As Short
		Dim lstrCdClasse As String
		If Me.cmbClasse.SelectedIndex >= 0 Then
			lintTamanho = Len(Trim(Me.txtCPF.Text))
			lstrCdClasse = VB6.Format(VB6.GetItemData(Me.cmbClasse, Me.cmbClasse.SelectedIndex), "0000")
			If VB.Left(lstrCdClasse, 1) = "9" Then
				If lintTamanho = 0 Or lintTamanho > 14 Then
					Call MsgBox("Você precisa cadastrar o C.P.F. da unidade consumidora para ter acesso ao cadastro de NIS!!!", MsgBoxStyle.Information, gstrTituloMensagem)
					Me.sstCadastros.SelectedIndex = 0
				Else
					Call ifrmCadNis.Show()
					Call ifrmCadNis.SetaNis(Me.txtCPF.Text, Me.txtNome.Text, Me.txtRG.Text, Me.txtZona.Text, Me.txtLivro.Text, Me.txtConta.Text, glngUnid_id, Me)
				End If
			Else
				Call MsgBox("A classe desta unidade consumidora não é residencial!!!", MsgBoxStyle.Information, gstrTituloMensagem)
				Me.sstCadastros.SelectedIndex = 0
			End If
		End If
	End Sub
	
	Public Sub SetaCodigo(ByVal alngUnidId As Integer, ByVal astrZona As String, ByVal astrLivro As String, ByVal astrConta As String, ByVal astrGrupo As String)
		Dim lstrSql As String
		Dim llngBanId As Integer
		Dim llngClasse As Integer
		Dim lstrGrTar As String
		Dim lstrFase As String
		Dim lstrFaseLig As String
		Dim lstrTipoLig As String
		Dim lstrDiaVcto As String
		Dim llngAgrupa As Integer
		Dim llngLinha As Integer
		Dim lstrCip As String
		Dim lstrApSaude As String
		Dim lstrEstufa As String
		Dim lstrTensao As String
		Dim lstrRegiao As String
		Dim lrstAgr As ADODB.Recordset
		Dim lrstUnidade As ADODB.Recordset
		lrstAgr = New ADODB.Recordset
		lrstUnidade = New ADODB.Recordset
		'----- Dados da Unidade Consumidora ----------------------------------------------------------------------
		istrGrupo = astrGrupo
		Me.cmbGrupo.SelectedIndex = IIf(istrGrupo = "B", 1, 0)
		Me.cmbGrupo.Enabled = False
		lstrSql = ""
		lstrSql = lstrSql & "SELECT * "
		lstrSql = lstrSql & "  FROM `unid" & LCase(istrGrupo) & "` AS `uc` "
		lstrSql = lstrSql & " WHERE `uc`.`zona`    = """ & astrZona & """ "
		lstrSql = lstrSql & "   AND `uc`.`livro`   = """ & astrLivro & """ "
		lstrSql = lstrSql & "   AND `uc`.`conta`   = """ & astrConta & """ "
		lstrSql = lstrSql & "   AND `uc`.`unid_id` = """ & alngUnidId & """ "
		Call Conectar(lstrSql, lrstUnidade)
		With lrstUnidade
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				If .RecordCount > 0 Then
					If istrLocaliza = "R" 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"'
						Me.txtZonaReimp.Text = IIf(IsDbNull(.Fields("zona").value), astrZona, .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"'
						Me.txtLivroReimp.Text = IIf(IsDbNull(.Fields("livro").value), astrZona, .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"'
						Me.txtContaReimp.Text = IIf(IsDbNull(.Fields("conta").value), astrZona, .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"'
						Me.txtNomeReimp.Text = IIf(IsDbNull(.Fields("nome").value), "", .Fields("nome").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"'
						Me.txtNomeReimp.Text = IIf(IsDbNull(.Fields("nome").value), "", .Fields("nome").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"'
						glngUnid_id = IIf(IsDbNull(.Fields("unid_id").value), alngUnidId, .Fields("unid_id").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"'
						glngCons_id = IIf(IsDbNull(.Fields("cons_id").value), 0, .Fields("cons_id").value)
					ElseIf istrLocaliza = "A" 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"'
						Me.txtAgrupaZona.Text = VB6.Format(Trim(IIf(IsDbNull(.Fields("zona").value), "0", .Fields("zona").value)), "000")
						'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"'
						Me.txtAgrupaLivro.Text = VB6.Format(Trim(IIf(IsDbNull(.Fields("livro").value), "0", .Fields("livro").value)), "00")
						'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"'
						Me.txtAgrupaConta.Text = VB6.Format(Trim(IIf(IsDbNull(.Fields("conta").value), "0", .Fields("conta").value)), "000000")
						'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"'
						Me.txtAgrupaRota.Text = VB6.Format(Trim(IIf(IsDbNull(.Fields("rota").value), "0", .Fields("rota").value)), "00000000")
						'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"'
						Me.txtAgrupaNome.Text = UCase(Trim(IIf(IsDbNull(.Fields("nome").value), "", .Fields("nome").value)))
					Else
						'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"'
						glngUnid_id = IIf(IsDbNull(.Fields("unid_id").value), alngUnidId, .Fields("unid_id").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"'
						Me.txtZona.Text = IIf(IsDbNull(.Fields("zona").value), astrZona, .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"'
						Me.txtLivro.Text = IIf(IsDbNull(.Fields("livro").value), astrLivro, .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"'
						Me.txtConta.Text = IIf(IsDbNull(.Fields("conta").value), astrConta, .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"'
						Me.txtRota.Text = IIf(IsDbNull(.Fields("rota").value), "99999999", .Fields("rota").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"'
						Me.txtNomeUC.Text = IIf(IsDbNull(.Fields("nome").value), "", .Fields("nome").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"'
						istrEndCodUC = IIf(IsDbNull(.Fields("codend").value), "0", .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"'
						Me.lblEndUc.Text = IIf(IsDbNull(.Fields("end").value), "", .Fields("end").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"'
						Me.txtNrUc.Text = IIf(IsDbNull(.Fields("numero").value), "", .Fields("numero").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"'
						Me.txtComplemUC.Text = IIf(IsDbNull(.Fields("complement").value), "", .Fields("complement").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"'
						Me.lblBairroUc.Text = IIf(IsDbNull(.Fields("bairro").value), "", .Fields("bairro").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"'
						Me.lblMunicipioUc.Text = IIf(IsDbNull(.Fields("cidade").value), "", .Fields("cidade").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"'
						Me.lblCepUc.Text = Trim(IIf(IsDbNull(.Fields("cep").value), "", .Fields("cep").value))
						If Len(Me.lblCepUc.Text) = 8 Then
							Me.lblCepUc.Text = VB.Left(Me.lblCepUc.Text, 5) & "-" & VB.Right(Me.lblCepUc.Text, 3)
						Else
							Me.lblCepUc.Text = Me.lblCepUc.Text
						End If
						'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"'
						Me.lblUfUc.Text = IIf(IsDbNull(.Fields("uf").value), "", .Fields("uf").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"'
						Me.lblDistritoUc.Text = IIf(IsDbNull(.Fields("distrito").value), "", .Fields("distrito").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"'
						Me.txtLoteUc.Text = IIf(IsDbNull(.Fields("lote").value), "", .Fields("lote").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"'
						Me.txtQuadraUc.Text = IIf(IsDbNull(.Fields("quadra").value), "", .Fields("quadra").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"'
						istrEndCodEn = IIf(IsDbNull(.Fields("codend_entrega").value), "0", .Fields("codend_entrega").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"'
						Me.txtEndEntrega.Text = IIf(IsDbNull(.Fields("end_entrega").value), "", .Fields("end_entrega").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"'
						Me.txtNumEntrega.Text = IIf(IsDbNull(.Fields("num_entrega").value), "", .Fields("num_entrega").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"'
						Me.txtComplEntrega.Text = IIf(IsDbNull(.Fields("compl_entrega").value), "", .Fields("compl_entrega").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"'
						Me.txtBaiEntrega.Text = IIf(IsDbNull(.Fields("bai_entrega").value), "", .Fields("bai_entrega").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"'
						Me.txtCidEntrega.Text = IIf(IsDbNull(.Fields("cid_entrega").value), "", .Fields("cid_entrega").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"'
						Me.txtCepEntrega.Text = Trim(IIf(IsDbNull(.Fields("cep_entrega").value), "", .Fields("cep_entrega").value))
						If Len(Me.txtCepEntrega.Text) = 8 Then
							Me.txtCepEntrega.Text = VB.Left(Me.txtCepEntrega.Text, 5) & "-" & VB.Right(Me.txtCepEntrega.Text, 3)
						Else
							Me.txtCepEntrega.Text = Me.txtCepEntrega.Text
						End If
						'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"'
						Me.txtUfEntrega.Text = IIf(IsDbNull(.Fields("uf_entrega").value), "", .Fields("uf_entrega").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"'
						Me.txtDisEntrega.Text = IIf(IsDbNull(.Fields("dis_entrega").value), "", .Fields("dis_entrega").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"'
						Me.txtLotEntrega.Text = IIf(IsDbNull(.Fields("lot_entrega").value), "", .Fields("lot_entrega").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"'
						Me.txtQuaEntrega.Text = IIf(IsDbNull(.Fields("qua_entrega").value), "", .Fields("qua_entrega").value)
						If istrGrupo = "B" 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"'
							Me.txtDisjuntor.Text = IIf(IsDbNull(.Fields("disjuntor").value), "", .Fields("disjuntor").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"'
							Me.txtArea.Text = IIf(IsDbNull(.Fields("area").value), "", .Fields("area").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"'
							Me.txtAgrupaZona.Text = VB6.Format(Trim(IIf(IsDbNull(.Fields("agrupa_zona").value), "", .Fields("agrupa_zona").value)), "000")
							'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"'
							Me.txtAgrupaLivro.Text = VB6.Format(Trim(IIf(IsDbNull(.Fields("agrupa_livro").value), "", .Fields("agrupa_livro").value)), "00")
							'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"'
							Me.txtAgrupaConta.Text = VB6.Format(Trim(IIf(IsDbNull(.Fields("agrupa_conta").value), "", .Fields("agrupa_conta").value)), "000000")
							If Len(Me.txtAgrupaZona.Text) > 0 Then
								lstrSql = ""
								lstrSql = lstrSql & "SELECT `zona`, `livro`, `conta`, `rota`, `nome` "
								lstrSql = lstrSql & "  FROM `unidb` "
								lstrSql = lstrSql & " WHERE `zona` = '" & Me.txtAgrupaZona.Text & "' "
								lstrSql = lstrSql & "   AND `livro` = '" & Me.txtAgrupaLivro.Text & "' "
								lstrSql = lstrSql & "   AND `conta` = '" & Me.txtAgrupaConta.Text & "' "
								Call Conectar(lstrSql, lrstAgr)
								With lrstAgr
									If .State = ADODB.ObjectStateEnum.adStateOpen Then
										If .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"'
											Me.txtAgrupaRota.Text = VB6.Format(Trim(IIf(IsDbNull(.Fields("rota").value), "0", .Fields("rota").value)), "00000000")
											'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"'
											Me.txtAgrupaNome.Text = UCase(Trim(IIf(IsDbNull(.Fields("nome").value), "", .Fields("nome").value)))
										End If
										Call .Close()
									End If
								End With
							End If
							'Agrupa
							'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"'
							llngAgrupa = CInt(IIf(IsDbNull(.Fields("agrupa").value), 1, .Fields("agrupa").value))
							llngLinha = 0
							With Me.cmbAgrupa
								For llngLinha = 0 To .Items.Count - 1
									If VB6.GetItemData(Me.cmbAgrupa, llngLinha) = llngAgrupa Then
										.SelectedIndex = llngLinha
										llngLinha = .Items.Count
									End If
								Next llngLinha
							End With
							
						End If
						'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"'
						Me.txtCargaU.Text = IIf(IsDbNull(.Fields("carga").value), "", .Fields("carga").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"'
						lstrEstufa = IIf(IsDbNull(.Fields("estufa").value), "N", .Fields("estufa").value)
						Me.chkEstufa.CheckState = IIf(lstrEstufa = "S", 1, 0)
						If istrGrupo = "B" 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"'
							lstrApSaude = IIf(IsDbNull(.Fields("ap_saude").value), "N", .Fields("ap_saude").value)
							Me.chkApSaude.CheckState = IIf(lstrApSaude = "S", 1, 0)
						End If
						'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"'
						lstrCip = IIf(IsDbNull(.Fields("ilum").value), "N", .Fields("ilum").value)
						Me.chkIlumU.CheckState = IIf(lstrCip = "S", 1, 0)
						'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"'
						Me.txtAg.Text = IIf(IsDbNull(.Fields("agenc").value), "", .Fields("agenc").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"'
						Me.txtCC.Text = IIf(IsDbNull(.Fields("cc").value), "", .Fields("cc").value)
						'
						' -- Setando as combobox
						'
						'-- Dia de Vencimento
						'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"'
						lstrDiaVcto = VB6.Format(Trim(IIf(IsDbNull(.Fields("diavenc").value), "0", .Fields("diavenc").value)), "00")
						With Me.cmbDiaVenc
							.Enabled = True
							llngLinha = 0
							While llngLinha < .Items.Count
								If VB.Left(VB6.GetItemString(Me.cmbDiaVenc, llngLinha), 2) = lstrDiaVcto Then
									.SelectedIndex = llngLinha
									llngLinha = .Items.Count
									.Enabled = Me.opbAlteraCad.Checked
								End If
								llngLinha = llngLinha + 1
							End While
						End With
						'
						'-- Banco
						'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"'
						llngBanId = CInt(IIf(IsDbNull(.Fields("banco").value), "0", .Fields("banco").value))
						With Me.cmbBanco
							.Enabled = True
							llngLinha = 0
							While llngLinha < .Items.Count
								If VB6.GetItemData(Me.cmbBanco, llngLinha) = llngBanId Then
									.SelectedIndex = llngLinha
									llngLinha = .Items.Count
									'.Enabled = Me.opbAlteraCad.Value
								End If
								llngLinha = llngLinha + 1
							End While
						End With
						'
						'-- Classe
						'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"'
						llngClasse = CInt(IIf(IsDbNull(.Fields("clas").value), "0", .Fields("clas").value))
						With Me.cmbClasse
							.Enabled = True
							llngLinha = 0
							While llngLinha < .Items.Count
								If VB6.GetItemData(Me.cmbClasse, llngLinha) = llngClasse Then
									.SelectedIndex = llngLinha
									llngLinha = .Items.Count
									'.Enabled = Me.opbAlteraCad.Value
								End If
								llngLinha = llngLinha + 1
							End While
						End With
						'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"'
						Me.txtIdCnae.Text = IIf(IsDbNull(.Fields("idcnae").value), 0, .Fields("idcnae").value)
						Call SetaCnae(CInt(IIf(IsNumeric(Me.txtIdCnae.Text), Me.txtIdCnae.Text, 0)), "")
						'
						'-- Tarifa
						'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"'
						lstrGrTar = Mid(UCase(IIf(IsDbNull(.Fields("ta").value), "01B1", .Fields("ta").value)), 3, 2)
						With Me.cmbTarifa
							.Enabled = True
							llngLinha = 0
							While llngLinha < .Items.Count
								If VB.Left(VB6.GetItemString(Me.cmbTarifa, llngLinha), 2) = lstrGrTar Then
									.SelectedIndex = llngLinha
									llngLinha = .Items.Count
									'.Enabled = Me.opbAlteraCad.Value
								End If
								llngLinha = llngLinha + 1
							End While
						End With
						'
						'-- Fase
						'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"'
						lstrFase = IIf(IsDbNull(.Fields("fase").value), "", .Fields("fase").value)
						With Me.cmbFase
							.Enabled = True
							llngLinha = 0
							While llngLinha < .Items.Count
								If VB.Left(VB6.GetItemString(Me.cmbFase, llngLinha), 1) = lstrFase Then
									.SelectedIndex = llngLinha
									llngLinha = .Items.Count
									'.Enabled = Me.opbAlteraCad.Value
								End If
								llngLinha = llngLinha + 1
							End While
						End With
						'
						'-- Fase de ligação
						If istrGrupo = "B" 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"'
							lstrFaseLig = IIf(IsDbNull(.Fields("faselig").value), "ABCN", .Fields("faselig").value)
						Else
							lstrFaseLig = "ABCN"
						End If
						With Me.cmbFaseLigU
							.Enabled = True
							llngLinha = 0
							While llngLinha < .Items.Count
								If VB.Left(VB6.GetItemString(Me.cmbFaseLigU, llngLinha), 1) = lstrFaseLig Then
									.SelectedIndex = llngLinha
									llngLinha = .Items.Count
									'.Enabled = Me.opbAlteraCad.Value
								End If
								llngLinha = llngLinha + 1
							End While
						End With
						'
						'-- Tipo de ligação
						'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"'
						lstrTipoLig = IIf(IsDbNull(.Fields("tp_ligacao").value), "A", .Fields("tp_ligacao").value)
						With Me.cmbTipoLigacao
							.Enabled = True
							llngLinha = 0
							While llngLinha < .Items.Count
								If VB.Left(VB6.GetItemString(Me.cmbTipoLigacao, llngLinha), 1) = lstrTipoLig Then
									.SelectedIndex = llngLinha
									llngLinha = .Items.Count
									'.Enabled = Me.opbAlteraCad.Value
								End If
								llngLinha = llngLinha + 1
							End While
						End With
						'
						'-- Região
						'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"'
						lstrRegiao = IIf(IsDbNull(.Fields("regiao").value), "U", .Fields("regiao").value)
						With Me.cmbRegiao
							.Enabled = True
							llngLinha = 0
							While llngLinha < .Items.Count
								If VB.Left(VB6.GetItemString(Me.cmbRegiao, llngLinha), 1) = lstrRegiao Then
									.SelectedIndex = llngLinha
									llngLinha = .Items.Count
									'.Enabled = Me.opbAlteraCad.Value
								End If
								llngLinha = llngLinha + 1
							End While
						End With
						'
						'-- Tensão
						'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"'
						lstrTensao = IIf(IsDbNull(.Fields("tensao").value), "", .Fields("tensao").value)
						With Me.cmbTensao
							.Enabled = True
							llngLinha = 0
							If Len(Trim(lstrTensao)) > 0 Then
								llngLinha = 0
								While llngLinha < .Items.Count
									If Replace(VB6.GetItemString(Me.cmbTensao, llngLinha), ".", "") = lstrTensao Then
										.SelectedIndex = llngLinha
										llngLinha = .Items.Count
										'.Enabled = Me.opbAlteraCad.Value
									End If
									llngLinha = llngLinha + 1
								End While
							Else
								.SelectedIndex = 0
							End If
						End With
					End If
				End If
				Call .Close()
			End If
		End With
		'UPGRADE_NOTE: Object lrstUnidade may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstUnidade = Nothing
	End Sub
	
	'Versão: 001 Desenvolvedor: Ricardo Inacio Data: 18/07/2008 Descrição: Rotina para atualizar a carga da unidade consumidora
	Public Sub AtualizaCargaInstalada(ByVal alngUnidId As Integer, ByVal adblCarga As Double, ByVal ablnGravou As Boolean)
		Dim lstrSql As String
		
		If ablnGravou Then
			Me.txtCargaU.Text = CStr(adblCarga)
			lstrSql = ""
			lstrSql = lstrSql & "UPDATE `unid" & LCase(istrGrupo) & "` AS `uc` "
			lstrSql = lstrSql & "   SET `uc`.`carga` = " & adblCarga & " "
			lstrSql = lstrSql & " WHERE `uc`.`unid_id` = " & alngUnidId & " "
			Call Executar(lstrSql)
			Call RetornaCarga()
		End If
	End Sub
	
	Private Sub cmdSalvar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdSalvar.Click
		Dim lblnContinua As Boolean
		lblnContinua = True
		If Me.cmbFase.SelectedIndex = -1 Then
			Call MsgBox("Faltou informar a fase do medidor!", MsgBoxStyle.Exclamation, gstrTituloMensagem)
			Call Me.cmbFase.Focus()
		Else
			If Me.opbNLiga.Checked Then
				If Trim(Me.txtZona.Text) = "" Or Trim(Me.txtZona.Text) = "999" Then
					If MsgBox("Esta Ligação Nova é de uma NOVA UNIDADE CONSUMIDORA?", MsgBoxStyle.YesNo + MsgBoxStyle.DefaultButton1, gstrTituloMensagem) = MsgBoxResult.Yes Then
						lblnContinua = True
					Else
						lblnContinua = False
					End If
				End If
			End If
			If lblnContinua Then
				If Len(Trim(Me.lblEndC.Text)) > 0 Then
					If Len(Trim(Me.lblEndUc.Text)) > 0 Then
						' ----- Se for um novo consumidor...
						If glngCons_id = 0 Then
							' ----- Insere um novo consumidor...
							Call GravaNovoConsumidor("Novo")
						Else
							Call GravaNovoConsumidor("Atualiza")
						End If
						' ----- Se for uma nova ligacao...
						If Me.opbNLiga.Checked Then
							' ----- Insere uma nova unidade consumidora...
							Call GravaNovaUnidade()
							If Me.cmbFase.SelectedIndex = 0 And Me.cmbTarifa.SelectedIndex = 0 Then
								If MsgBox("Deseja informar o NIS?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, gstrTituloMensagem) = MsgBoxResult.Yes Then
									Call cmdNis_Click(cmdNis, New System.EventArgs())
								End If
							End If
						Else
							If ChecaZonaLivroConta(Me.txtZona.Text, Me.txtLivro.Text, Me.txtConta.Text, glngUnid_id) Then
								Call TranfereUnidade(glngUnid_id)
							End If
							If gblnContinua = False Then
								Exit Sub
							End If
						End If
						If ChamaCarga = False Then
							Call RetornaCarga()
						End If
					Else
						Call MsgBox("Faltou informar o endereço da unidade consumidora", MsgBoxStyle.Information, gstrTituloMensagem)
						Me.sstCadastros.SelectedIndex = 1
						System.Windows.Forms.Application.DoEvents()
						Call cmdEnderecoUC_Click(cmdEnderecoUC, New System.EventArgs())
					End If
				Else
					Call MsgBox("Faltou informar o endereço do consumidor", MsgBoxStyle.Information, gstrTituloMensagem)
					Me.sstCadastros.SelectedIndex = 0
					System.Windows.Forms.Application.DoEvents()
					Call cmdEndereco_Click(cmdEndereco, New System.EventArgs())
				End If
			Else
				Me.cmdLocaliza.Focus()
				Call cmdLocaliza_Click(cmdLocaliza, New System.EventArgs())
			End If
		End If
		istrCpfCnpj = ""
	End Sub
	
	Private Function ChamaCarga() As Boolean
		Dim blnResposta As Boolean
		
		blnResposta = MsgBox("Deseja cadastrar a carga instalada da unidade consumidora?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, gstrTituloMensagem) = MsgBoxResult.Yes
		If blnResposta Then
			Call cmdCargaInstalada_Click(cmdCargaInstalada, New System.EventArgs())
		End If
		ChamaCarga = blnResposta
		System.Windows.Forms.Application.DoEvents()
	End Function
	
	Private Function RetornaCarga() As Boolean
		Dim lstrProtocolo As String
		Dim ldteSolicitacao As Date
		Dim lstrHora As String
		Dim lstrSolicit As String
		Dim lstrCpfCnpj As String
		Dim lstrDocSolic As String
		Dim lstrTpServico As String
		Dim lstrGrTar As String
		Dim lstrZonaSol As String
		Dim lstrPadrao As String
		Dim lstrZLC As String
		Dim lstrTelefone As String
		Dim lstrSql As String
		If Me.opbNLiga.Checked Then
			'Insere um O.S de Nova ligação
			ldteSolicitacao = BuscaDataBD
			lstrProtocolo = "NO" & VB6.Format(ldteSolicitacao, "YYMMDD")
			lstrHora = VB6.Format(ldteSolicitacao, "HH:MM:SS")
			lstrProtocolo = lstrProtocolo & VB6.Format(lstrHora, "HHMMSS")
			lstrSolicit = IIf(Len(Me.txtSolic.Text) > 0, Me.txtSolic.Text, Me.txtNomeUC.Text)
			lstrCpfCnpj = Str_Retira(Me.txtCPF.Text, ".-/ ")
			lstrDocSolic = IIf(Len(txtSolic.Text) > 0, " ", txtRG.Text)
			lstrTpServico = "SOLICITAÇÃO DE LIGAÇÃO " & IIf(Me.chkLigDefinitiva.CheckState = 1, "DEFINITIVA", "PROVISÓRIA") & " DE ENERGIA ELETRICA "
			If Me.cmbTarifa.SelectedIndex >= 0 Then
				lstrGrTar = VB6.GetItemString(Me.cmbTarifa, Me.cmbTarifa.SelectedIndex)
			Else
				lstrGrTar = VB6.GetItemString(Me.cmbTarifa, 0)
			End If
			lstrZonaSol = IIf(VB.Left(lstrGrTar, 2) = "B2", "R", "U")
			lstrPadrao = IIf(Me.chkLigDefinitiva.CheckState = 1, "Padrão", "Provisório")
			lstrZLC = Trim(Me.txtZona.Text) & Trim(Me.txtLivro.Text) & Trim(Me.txtConta.Text)
			lstrTelefone = Me.txtDddFone.Text & "-" & Me.txtFone.Text
			If Len(Trim(Replace(lstrTelefone, "-", ""))) = 0 Then
				lstrTelefone = ""
			End If
			lstrSql = ""
			lstrSql = lstrSql & "INSERT INTO `solserv` SET "
			lstrSql = lstrSql & "            `solserv`.`protocolo`    = """ & lstrProtocolo & """, "
			lstrSql = lstrSql & "            `solserv`.`data_soli`    = """ & VB6.Format(gDtBcoDados, "yyyy-MM-dd") & """, "
			lstrSql = lstrSql & "            `solserv`.`hora_soli`    = """ & lstrHora & """, "
			lstrSql = lstrSql & "            `solserv`.`zlc`          = """ & lstrZLC & """, "
			lstrSql = lstrSql & "            `solserv`.`nomesol`      = """ & lstrSolicit & """, "
			lstrSql = lstrSql & "            `solserv`.`cpf`          = """ & lstrCpfCnpj & """, "
			lstrSql = lstrSql & "            `solserv`.`docsol`       = """ & lstrDocSolic & """, "
			lstrSql = lstrSql & "            `solserv`.`telsol`       = """ & lstrTelefone & """, "
			lstrSql = lstrSql & "            `solserv`.`itensserv`    = """ & "9050000002" & "?" & "0" & ";"", "
			lstrSql = lstrSql & "            `solserv`.`ponto_refer`  = """ & " " & """, "
			lstrSql = lstrSql & "            `solserv`.`atendente`    = """ & gstrUsuario_Login & ""","
			lstrSql = lstrSql & "            `solserv`.`descr_serv`   = """ & lstrTpServico & """, "
			lstrSql = lstrSql & "            `solserv`.`prioridade`   = """ & "N" & """, "
			lstrSql = lstrSql & "            `solserv`.`solicit_meio` = ""P"", "
			lstrSql = lstrSql & "            `solserv`.`zona_solic`   = """ & lstrZonaSol & """, "
			lstrSql = lstrSql & "            `solserv`.`unid_id`      = """ & glngUnid_id & """, "
			lstrSql = lstrSql & "            `solserv`.`unid`         = """ & UCase(istrGrupo) & """, "
			lstrSql = lstrSql & "            `solserv`.`sit`          = ""A"", "
			lstrSql = lstrSql & "            `solserv`.`cod_executor` = """ & glngUsuario_Id & """, "
			lstrSql = lstrSql & "            `solserv`.`padrao`       = """ & lstrPadrao & """, "
			lstrSql = lstrSql & "            `solserv`.`sgdenvio`     = ""P"" "
			Call Executar(lstrSql)
			Call ImprimeSolicitacao(glngCons_id, glngUnid_id, lstrProtocolo)
		End If
		If istrGrupo = "B" Then
			If MsgBox("Deseja imprimir o Contrato de Ligação?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, gstrTituloMensagem) = MsgBoxResult.Yes Then
				Call ImprimeTermoLigacao(glngUnid_id)
			End If
		End If
		Call LimpaCampos((Me.fmeCons))
		Call LimpaCampos((Me.fmeUC))
		Call LimpaCampos((Me.fmeEntrega))
		Me.sstCadastros.SelectedIndex = 0
		Me.cmdNis.Enabled = False
		Call LigDesEntrega(False)
		Me.sstCadastros.TabPages.Item(1).Enabled = False
		Me.sstCadastros.TabPages.Item(2).Enabled = False
		glngUnid_id = 0
		glngCons_id = 0
		Me.txtCPF.Focus()
	End Function
	
	'Versão: 001 Desenvolvedor: Ricardo Inacio Data: 08/04/2008 Descrição: Rotina insere um consumidor novo no banco de dados
	Private Sub GravaNovoConsumidor(ByVal astrTipo As String)
		Dim lstrSql As String
		Dim lstrCpfCnpj As String
		Dim llngConsId As Integer
		Dim lrstConsumidor As ADODB.Recordset
		
		lrstConsumidor = New ADODB.Recordset
		lstrCpfCnpj = Str_Retira(Me.txtCPF.Text, ".-/ ")
		lstrSql = ""
		If astrTipo = "Novo" Then
			lstrSql = lstrSql & "INSERT INTO "
		Else
			lstrSql = lstrSql & "UPDATE "
		End If
		lstrSql = lstrSql & "             `consum` SET "
		If astrTipo = "Novo" Then
			lstrSql = lstrSql & "             `consum`.`consreg`     = 0, "
			lstrSql = lstrSql & "             `consum`.`cgc`         = """ & lstrCpfCnpj & """, "
			lstrSql = lstrSql & "             `consum`.`insc`        = """ & Me.txtIe.Text & """, "
			lstrSql = lstrSql & "             `consum`.`rg`          = """ & Me.txtRG.Text & """, "
			lstrSql = lstrSql & "             `consum`.`nome`        = """ & Trim(Me.txtNome.Text) & """, "
			lstrSql = lstrSql & "             `consum`.`codend`      = """ & istrEndCodC & """, "
			lstrSql = lstrSql & "             `consum`.`dt_cadastro` = """ & VB6.Format(gDtBcoDados, "yyyy-MM-dd") & """, "
		End If
		lstrSql = lstrSql & "             `consum`.`dt_nascto`   = """ & VB6.Format(IIf(Len(Trim(Me.txtDtNasc.Text)) = 0, "0000-00-00", Me.txtDtNasc.Text), "yyyy-MM-dd") & """, "
		lstrSql = lstrSql & "             `consum`.`end`         = """ & Me.lblEndC.Text & """, "
		lstrSql = lstrSql & "             `consum`.`numero`      = """ & Trim(Me.txtNrC.Text) & """, "
		lstrSql = lstrSql & "             `consum`.`complement`  = """ & Trim(Me.txtCompleC.Text) & """, "
		lstrSql = lstrSql & "             `consum`.`bairro`      = """ & Me.lblBairroC.Text & """, "
		lstrSql = lstrSql & "             `consum`.`cidade`      = """ & Me.lblMunicipioC.Text & """, "
		lstrSql = lstrSql & "             `consum`.`cep`         = """ & Str_Retira(Me.lblCepC.Text, ".-/ ") & """, "
		lstrSql = lstrSql & "             `consum`.`uf`          = """ & Me.lblUfC.Text & """, "
		lstrSql = lstrSql & "             `consum`.`distrito`    = """ & Me.lblDistritoC.Text & """, "
		lstrSql = lstrSql & "             `consum`.`lote`        = """ & Me.txtLoteC.Text & """, "
		lstrSql = lstrSql & "             `consum`.`quadra`      = """ & Me.txtQuadraC.Text & """, "
		lstrSql = lstrSql & "             `consum`.`email`       = """ & Me.txtEmail.Text & """, "
		lstrSql = lstrSql & "             `consum`.`nomepai`     = """ & Me.txtNomePai.Text & """, "
		lstrSql = lstrSql & "             `consum`.`nomemae`     = """ & Me.txtNomeMae.Text & """, "
		lstrSql = lstrSql & "             `consum`.`dddtel`      = """ & Me.txtDddFone.Text & """, "
		lstrSql = lstrSql & "             `consum`.`telefone`    = """ & Str_Retira(Me.txtFone.Text, ".-/ ") & """, "
		lstrSql = lstrSql & "             `consum`.`dddcel`      = """ & Me.txtDddCel.Text & """, "
		lstrSql = lstrSql & "             `consum`.`cel`         = """ & Str_Retira(Me.txtCelular.Text, ".-/ ") & """ "
		If astrTipo <> "Novo" Then
			lstrSql = lstrSql & " WHERE `consum`.`consreg` = " & glngCons_id
		End If
		Call Executar(lstrSql)
		If astrTipo = "Novo" Then
			'... e pega o código do consumidor.
			lstrSql = "SELECT LAST_INSERT_ID() "
			Call Conectar(lstrSql, lrstConsumidor)
			With lrstConsumidor
				If .State > 0 Then
					If .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"'
						glngCons_id = IIf(IsDbNull(.Fields(0).value), 0, .Fields(0).value)
					End If
					Call .Close()
				End If
			End With
		End If
		'UPGRADE_NOTE: Object lrstConsumidor may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstConsumidor = Nothing
	End Sub
	
	Private Sub GravaNovaUnidade()
		Dim lstrZona As String
		Dim lstrLivro As String
		Dim lstrConta As String
		Dim lstrRota As String
		Dim lstrNome As String
		Dim llngBanId As Integer
		Dim lstrAgenc As String
		Dim lstrCc As String
		Dim lstrClasse As String
		Dim lstrFase As String
		Dim lstrTensao As String
		Dim ldteEntrada As Date
		Dim lstrIsentoCip As String
		Dim lstrApSaude As String
		Dim lstrEstufa As String
		Dim lstrGrTar As String
		Dim lstrDiaVenc As String
		Dim lstrCpfCnpj As String
		Dim lstrRegGeral As String
		Dim lstrInscrEst As String
		Dim lstrTpPessoa As String
		Dim lstrDisjuntor As String
		Dim lstrArea As String
		Dim lstrEndUc As String
		Dim lstrNumUc As String
		Dim lstrComUc As String
		Dim lstrBaiUc As String
		Dim lstrCidUc As String
		Dim lstrCepUc As String
		Dim lstrUfUc As String
		Dim lstrDisUc As String
		Dim lstrQuadra As String
		Dim lstrLote As String
		Dim lstrEndEnt As String
		Dim lstrNumEnt As String
		Dim lstrComEnt As String
		Dim lstrBaiEnt As String
		Dim lstrCidEnt As String
		Dim lstrCepEnt As String
		Dim lstrUfEnt As String
		Dim lstrDisEnt As String
		Dim lstrQuaEnt As String
		Dim lstrLotEnt As String
		Dim llngIdCnae As Integer
		
		Dim llngUnidId As Integer
		Dim lstrSql As String
		Dim lblnContinua As String
		Dim lrstUnidade As ADODB.Recordset
		
		lrstUnidade = New ADODB.Recordset
		'Prepara dados da nova unidade
		
		If Trim(Me.txtZona.Text) = "" Then
			Me.txtZona.Text = "999"
			If Trim(Me.txtLivro.Text) = "" Then
				Me.txtLivro.Text = "99"
			End If
			If Trim(Me.txtConta.Text) = "" Then
				Me.txtConta.Text = "999999"
			End If
		End If
		lstrZona = Me.txtZona.Text
		lstrLivro = Me.txtLivro.Text
		lstrConta = Me.txtConta.Text
		lstrRota = Me.txtRota.Text
		lstrNome = Me.txtNomeUC.Text
		lstrAgenc = Me.txtAg.Text
		lstrCc = Me.txtCC.Text
		ldteEntrada = CDate(VB6.Format(gDtBcoDados, "dd/mm/yyyy"))
		lstrIsentoCip = IIf(Me.chkIlumU.CheckState = 1, "S", "N")
		lstrApSaude = IIf(Me.chkApSaude.CheckState = 1, "S", "N")
		lstrEstufa = IIf(Me.chkEstufa.CheckState = 1, "S", "N")
		lstrCpfCnpj = Str_Retira(Me.txtCPF.Text, ".-/ ")
		lstrRegGeral = Me.txtRG.Text
		lstrInscrEst = Me.txtIe.Text
		lstrTpPessoa = IIf(Len(lstrCpfCnpj) = 14, "J", "F")
		lstrDisjuntor = Trim(Str_Retira(Me.txtDisjuntor.Text, ".-/ "))
		lstrArea = Str_Retira(txtArea.Text, ".-/ ")
		lstrEndUc = Me.lblEndUc.Text
		lstrNumUc = Me.txtNrUc.Text
		lstrComUc = Me.txtComplemUC.Text
		lstrBaiUc = Me.lblBairroUc.Text
		lstrCidUc = Me.lblMunicipioUc.Text
		lstrCepUc = Str_Retira(Me.lblCepUc.Text, ".-/ ")
		lstrUfUc = Me.lblUfUc.Text
		lstrDisUc = Me.lblDistritoUc.Text
		lstrQuadra = Me.txtQuadraUc.Text
		lstrLote = Me.txtLoteUc.Text
		If Len(Trim(Me.txtEndEntrega.Text)) > 0 Then
			lstrEndEnt = Me.txtEndEntrega.Text
			lstrNumEnt = Me.txtNumEntrega.Text
			lstrComEnt = Me.txtComplEntrega.Text
			lstrBaiEnt = Me.txtBaiEntrega.Text
			lstrCidEnt = Me.txtCidEntrega.Text
			lstrCepEnt = Str_Retira(Me.txtCepEntrega.Text, ".-/ ")
			lstrUfEnt = Me.txtUfEntrega.Text
			lstrDisEnt = Me.txtDisEntrega.Text
			lstrQuaEnt = Me.txtQuaEntrega.Text
			lstrLotEnt = Me.txtLotEntrega.Text
		Else
			istrEndCodEn = istrEndCodUC
			lstrEndEnt = lstrEndUc
			lstrNumEnt = lstrNumUc
			lstrComEnt = lstrComUc
			lstrBaiEnt = lstrBaiUc
			lstrCidEnt = lstrCidUc
			lstrCepEnt = lstrCepUc
			lstrUfEnt = lstrUfUc
			lstrDisEnt = lstrDisUc
			lstrQuaEnt = lstrQuadra
			lstrLotEnt = lstrLote
		End If
		'
		'-- Banco
		With Me.cmbBanco
			If .SelectedIndex >= 0 Then
				llngBanId = VB6.GetItemData(Me.cmbBanco, .SelectedIndex)
			Else
				llngBanId = VB6.GetItemData(Me.cmbBanco, 0)
			End If
		End With
		'
		'-- Classe
		With Me.cmbClasse
			If .SelectedIndex >= 0 Then
				lstrClasse = IIf(CDbl(VB.Left(CStr(VB6.GetItemData(Me.cmbClasse, .SelectedIndex)), 1)) = 9, "9101", VB6.GetItemData(Me.cmbClasse, .SelectedIndex))
			Else
				lstrClasse = "9101"
			End If
		End With
		llngIdCnae = CInt(IIf(IsNumeric(Me.txtIdCnae.Text), Me.txtIdCnae.Text, 0))
		'
		'-- Fase
		With Me.cmbFase
			If .SelectedIndex >= 0 Then
				lstrFase = VB.Left(VB6.GetItemString(Me.cmbFase, .SelectedIndex), 1)
			Else
				lstrFase = VB.Left(VB6.GetItemString(Me.cmbFase, 0), 1)
			End If
		End With
		'
		'-- Tensao
		With Me.cmbTensao
			If .SelectedIndex >= 0 Then
				lstrTensao = Replace(VB6.GetItemString(Me.cmbTensao, .SelectedIndex), ".", "")
			Else
				lstrTensao = Replace(VB6.GetItemString(Me.cmbTensao, 0), ".", "")
			End If
		End With
		'
		'-- Tarifa
		With Me.cmbTarifa
			If .SelectedIndex >= 0 Then
				lstrGrTar = "01" & VB.Left(VB6.GetItemString(Me.cmbTarifa, .SelectedIndex), 2) & "00"
			Else
				lstrGrTar = "01" & VB.Left(VB6.GetItemString(Me.cmbTarifa, 0), 2) & "00"
			End If
		End With
		'
		'-- Dia Vencimento
		With Me.cmbDiaVenc
			If .SelectedIndex >= 0 Then
				lstrDiaVenc = VB6.GetItemString(Me.cmbDiaVenc, .SelectedIndex)
			Else
				lstrDiaVenc = VB6.GetItemString(Me.cmbDiaVenc, 0)
			End If
		End With
		lblnContinua = CStr(False)
		If lstrZona <> "999" And lstrConta <> "999999" Then
			lblnContinua = CStr(ChecaZonaLivroConta(lstrZona, lstrLivro, lstrConta, glngUnid_id))
		End If
		If CBool(lblnContinua) = False Then
			lstrSql = ""
			lstrSql = lstrSql & "INSERT INTO  `unid" & LCase(istrGrupo) & "` "
			lstrSql = lstrSql & "        SET `zona`           = """ & lstrZona & """, "
			lstrSql = lstrSql & "            `livro`          = """ & lstrLivro & """, "
			lstrSql = lstrSql & "            `conta`          = """ & lstrConta & """, "
			lstrSql = lstrSql & "            `rota`           = """ & lstrRota & """, "
			lstrSql = lstrSql & "            `nome`           = """ & lstrNome & """, "
			lstrSql = lstrSql & "            `cpf_cnpj`       = """ & lstrCpfCnpj & """, "
			lstrSql = lstrSql & "            `insc`           = """ & lstrInscrEst & """, "
			lstrSql = lstrSql & "            `rg`             = """ & lstrRegGeral & """, "
			lstrSql = lstrSql & "            `clas`           = """ & lstrClasse & """, "
			lstrSql = lstrSql & "            `idcnae`         = " & llngIdCnae & ", "
			lstrSql = lstrSql & "            `ta`             = """ & lstrGrTar & """, "
			lstrSql = lstrSql & "            `fase`           = """ & lstrFase & """, "
			lstrSql = lstrSql & "            `diavenc`        = """ & lstrDiaVenc & """, "
			lstrSql = lstrSql & "            `tensao`         = """ & lstrTensao & """, "
			lstrSql = lstrSql & "            `solicitante`    = """ & Me.txtSolic.Text & """, "
			lstrSql = lstrSql & "            `unid_id`        = 0, "
			lstrSql = lstrSql & "            `cons_id`        = " & glngCons_id & ", "
			lstrSql = lstrSql & "            `situacao`       = ""N"", "
			lstrSql = lstrSql & "            `grupo`          = """ & Mid(lstrGrTar, 3, 2) & """, "
			lstrSql = lstrSql & "            `ilum`           = """ & lstrIsentoCip & """, "
			lstrSql = lstrSql & "            `codend`         = """ & istrEndCodUC & """, "
			lstrSql = lstrSql & "            `end`            = """ & lstrEndUc & """, "
			lstrSql = lstrSql & "            `numero`         = """ & lstrNumUc & """, "
			lstrSql = lstrSql & "            `complement`     = """ & lstrComUc & """, "
			lstrSql = lstrSql & "            `bairro`         = """ & lstrBaiUc & """, "
			lstrSql = lstrSql & "            `cidade`         = """ & lstrCidUc & """, "
			lstrSql = lstrSql & "            `cep`            = """ & lstrCepUc & """, "
			lstrSql = lstrSql & "            `uf`             = """ & lstrUfUc & """, "
			lstrSql = lstrSql & "            `distrito`       = """ & lstrDisUc & """, "
			lstrSql = lstrSql & "            `lote`           = """ & lstrLote & """, "
			lstrSql = lstrSql & "            `quadra`         = """ & lstrQuadra & """, "
			lstrSql = lstrSql & "            `codend_entrega` = """ & istrEndCodEn & """, "
			lstrSql = lstrSql & "            `end_entrega`    = """ & lstrEndEnt & """, "
			lstrSql = lstrSql & "            `num_entrega`    = """ & lstrNumEnt & """, "
			lstrSql = lstrSql & "            `compl_entrega`  = """ & lstrComEnt & """, "
			lstrSql = lstrSql & "            `bai_entrega`    = """ & lstrBaiEnt & """, "
			lstrSql = lstrSql & "            `cid_entrega`    = """ & lstrCidEnt & """, "
			lstrSql = lstrSql & "            `cep_entrega`    = """ & lstrCepEnt & """, "
			lstrSql = lstrSql & "            `uf_entrega`     = """ & lstrUfEnt & """, "
			lstrSql = lstrSql & "            `dis_entrega`    = """ & lstrDisEnt & """, "
			lstrSql = lstrSql & "            `lot_entrega`    = """ & lstrLotEnt & """, "
			lstrSql = lstrSql & "            `qua_entrega`    = """ & lstrQuaEnt & """, "
			lstrSql = lstrSql & "            `banco`          = """ & VB6.Format(llngBanId, "000") & """, "
			lstrSql = lstrSql & "            `agenc`          = """ & lstrAgenc & """, "
			lstrSql = lstrSql & "            `cc`             = """ & lstrCc & """, "
			If istrGrupo = "B" Then
				lstrSql = lstrSql & "            `disjuntor`      = """ & IIf(Len(Trim(lstrDisjuntor)) = 0, "0", lstrDisjuntor) & """, "
				lstrSql = lstrSql & "            `area`           = """ & IIf(Len(Trim(lstrArea)) = 0, "0", lstrArea) & """, "
				lstrSql = lstrSql & "            `ap_saude`       = """ & lstrApSaude & """, "
				lstrSql = lstrSql & "            `agrupa`         = " & VB6.GetItemData(Me.cmbAgrupa, Me.cmbAgrupa.SelectedIndex) & ", "
				lstrSql = lstrSql & "            `agrupa_zona`    = '" & Me.txtAgrupaZona.Text & "', "
				lstrSql = lstrSql & "            `agrupa_livro`   = '" & Me.txtAgrupaLivro.Text & "', "
				lstrSql = lstrSql & "            `agrupa_conta`   = '" & Me.txtAgrupaConta.Text & "', "
			End If
			lstrSql = lstrSql & "            `estufa`         = """ & lstrEstufa & """, "
			lstrSql = lstrSql & "            `pessoa`         = """ & lstrTpPessoa & """ "
			Call Executar(lstrSql)
			'... e pega o código da nova unidade consumidora.
			lstrSql = "SELECT LAST_INSERT_ID() "
			Call Conectar(lstrSql, lrstUnidade)
			With lrstUnidade
				If .State > 0 Then
					If .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"'
						glngUnid_id = IIf(IsDbNull(.Fields(0).value), 0, .Fields(0).value)
					End If
					Call .Close()
				End If
			End With
			'UPGRADE_NOTE: Object lrstUnidade may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
			lrstUnidade = Nothing
			Call MsgBox("Nova unidade consumidora cadastrada com sucesso!", MsgBoxStyle.Information, gstrTituloMensagem)
		Else
			Call TranfereUnidade(glngUnid_id)
			'Call MsgBox("Unidade consumidora já existe!", vbInformation, gstrTituloMensagem)
		End If
	End Sub
	
	Private Sub TranfereUnidade(ByVal alngUnidId As Integer)
		'Versão: 001 Desenvolvedor: Ricardo Inacio Data: 08/04/2008 Descrição: Rotina para transferir a unidade consumidora para outro consumidor
		Dim llngLinha As Integer
		Dim lstrDescrAgrupa As String
		Dim llngBancPadrao As Integer
		'UPGRADE_WARNING: Lower bound of array lstrZona was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrZona(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrLivro was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrLivro(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrConta was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrConta(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrRota was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrRota(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrNome was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrNome(2) As String
		'UPGRADE_WARNING: Lower bound of array llngBanId was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim llngBanId(2) As Integer
		'UPGRADE_WARNING: Lower bound of array lstrAgenc was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrAgenc(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrCc was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrCc(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrClasse was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrClasse(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrFase was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrFase(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrTensao was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrTensao(2) As String
		'UPGRADE_WARNING: Lower bound of array ldteEntrada was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim ldteEntrada(2) As Date
		'UPGRADE_WARNING: Lower bound of array lstrIsentoCip was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrIsentoCip(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrApSaude was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrApSaude(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrEstufa was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrEstufa(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrGrTar was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrGrTar(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrDiaVenc was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrDiaVenc(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrCpf was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrCpf(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrRg was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrRg(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrInscr was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrInscr(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrTpPessoa was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrTpPessoa(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrDisjuntor was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrDisjuntor(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrArea was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrArea(2) As String
		Dim lstrEndCodUc As String
		'UPGRADE_WARNING: Lower bound of array lstrEnd was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrEnd(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrNumero was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrNumero(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrComplement was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrComplement(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrBairro was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrBairro(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrCidade was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrCidade(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrCep was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrCep(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrUf was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrUf(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrDistrito was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrDistrito(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrQuadra was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrQuadra(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrLote was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrLote(2) As String
		Dim lstrEndCodEnt As String
		'UPGRADE_WARNING: Lower bound of array lstrEndEnt was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrEndEnt(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrNumEnt was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrNumEnt(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrComplEnt was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrComplEnt(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrBaiEnt was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrBaiEnt(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrCidEnt was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrCidEnt(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrCepEnt was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrCepEnt(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrUfEnt was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrUfEnt(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrDisEnt was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrDisEnt(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrQuaEnt was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrQuaEnt(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrLotEnt was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrLotEnt(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrHistorico was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrHistorico(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrMedidor was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrMedidor(2) As String
		'UPGRADE_WARNING: Lower bound of array llngUnidId was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim llngUnidId(2) As Integer
		'UPGRADE_WARNING: Lower bound of array llngConsId was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim llngConsId(2) As Integer
		'UPGRADE_WARNING: Lower bound of array llngAgrupa was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim llngAgrupa(2) As Integer
		'UPGRADE_WARNING: Lower bound of array lstrAgrupaZona was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrAgrupaZona(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrAgrupaLivro was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrAgrupaLivro(2) As String
		'UPGRADE_WARNING: Lower bound of array lstrAgrupaConta was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrAgrupaConta(2) As String
		Dim lstrSql As String
		Dim lrstConsulta As ADODB.Recordset
		Dim lrstUnid As ADODB.Recordset
		Dim lstrZonaNis As String
		Dim lstrLivroNis As String
		Dim lstrContaNis As String
		Dim llngUnidIdNis As Integer
		Dim lblnTrasferiu As Boolean
		llngBancPadrao = CInt(LeConfig("COD_BANCO_PRINCIPAL"))
		lrstConsulta = New ADODB.Recordset
		lrstUnid = New ADODB.Recordset
		lblnTrasferiu = False
		lstrSql = ""
		lstrSql = lstrSql & "SELECT * "
		lstrSql = lstrSql & "  FROM `unid" & LCase(istrGrupo) & "` AS `uc`"
		lstrSql = lstrSql & " WHERE `uc`.`zona`  = """ & Me.txtZona.Text & """ "
		lstrSql = lstrSql & "   AND `uc`.`livro` = """ & Me.txtLivro.Text & """ "
		lstrSql = lstrSql & "   AND `uc`.`conta` = """ & Me.txtConta.Text & """ "
		If alngUnidId > 0 Then
			lstrSql = lstrSql & " AND `uc`.`unid_id` = " & alngUnidId
		End If
		Call Conectar(lstrSql, lrstConsulta)
		With lrstConsulta
			If .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"'
				lstrNome(1) = IIf(IsDbNull(.Fields("nome").value), "", .Fields("nome").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"'
				llngUnidId(1) = IIf(IsDbNull(.Fields("unid_id").value), 0, .Fields("unid_id").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"'
				llngConsId(1) = IIf(IsDbNull(.Fields("cons_id").value), 0, .Fields("cons_id").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"'
				lstrRota(1) = IIf(IsDbNull(.Fields("rota").value), 0, .Fields("rota").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"'
				lstrHistorico(1) = IIf(IsDbNull(.Fields("historico").value), "", .Fields("historico").value)
				lstrHistorico(2) = Trim(lstrHistorico(1)) & "\r\n" & "TRANS DE: " & lstrNome(1) & " EM " & VB6.Format(gDtBcoDados, "dd/mm/yyyy")
				
				gblnContinua = False
				lstrNome(2) = Me.txtNomeUC.Text
				If llngConsId(1) <> glngCons_id Then
					If MsgBox("A unidade consumidora está no nome de " & lstrNome(1) & "." & vbCrLf & vbCrLf & "Tem certeza de que deseja transferir a UC para " & Me.txtNome.Text & "?", MsgBoxStyle.YesNoCancel + MsgBoxStyle.DefaultButton1) = MsgBoxResult.Yes Then
						gblnContinua = True
						lstrNome(2) = Me.txtNome.Text
						lblnTrasferiu = True
						Call AtualizaHistoricoUnidade(llngUnidId(1), istrGrupo, "TRANS DE: " & lstrNome(1) & " EM " & VB6.Format(gDtBcoDados, "dd/mm/yyyy"))
					Else
						gblnContinua = False
					End If
				Else
					gblnContinua = True
				End If
			Else
				If MsgBox("Não foi encontrada nenhuma unidade consumidora sob essa identificação." & vbCrLf & vbCrLf & "Deseja criar uma nova?", MsgBoxStyle.YesNo + MsgBoxStyle.Question) = MsgBoxResult.Yes Then
					Me.opbNLiga.Checked = True
					Call opbNLiga_CheckedChanged(opbNLiga, New System.EventArgs())
					gblnContinua = False
				End If
			End If
			If .State = 1 Then Call .Close()
		End With
		If gblnContinua = True Then
			If glngCons_id = 0 Then
				Call GravaNovoConsumidor("Novo") 'insere um novo consumidor...
			End If
			'Prepara dados da nova unidade
			lstrZona(2) = Me.txtZona.Text
			lstrLivro(2) = Me.txtLivro.Text
			lstrConta(2) = Me.txtConta.Text
			lstrRota(2) = lstrRota(1)
			If llngConsId(1) <> glngCons_id And VB6.GetItemData(Me.cmbBanco, Me.cmbBanco.SelectedIndex) <> llngBancPadrao Then
				If MsgBox("A unidade consumidora encontra-se em débito." & vbCrLf & vbCrLf & "Tem certeza de que deseja tirar do débito?", MsgBoxStyle.YesNoCancel + MsgBoxStyle.DefaultButton1, gstrTituloMensagem) = MsgBoxResult.Yes Then
					llngBanId(2) = CInt(LeConfig("COD_BANCO_PRINCIPAL"))
					lstrAgenc(2) = ""
					lstrCc(2) = ""
				Else
					llngBanId(2) = VB6.GetItemData(Me.cmbBanco, Me.cmbBanco.SelectedIndex)
					lstrAgenc(2) = Me.txtAg.Text
					lstrCc(2) = Me.txtCC.Text
				End If
			Else
				llngBanId(2) = VB6.GetItemData(Me.cmbBanco, Me.cmbBanco.SelectedIndex)
				lstrAgenc(2) = Me.txtAg.Text
				lstrCc(2) = Me.txtCC.Text
			End If
			If CDbl(VB.Left(CStr(VB6.GetItemData(Me.cmbClasse, Me.cmbClasse.SelectedIndex)), 1)) = 9 Then
				lstrClasse(2) = "9101"
			Else
				lstrClasse(2) = CStr(VB6.GetItemData(Me.cmbClasse, Me.cmbClasse.SelectedIndex))
			End If
			lstrFase(2) = VB.Left(VB6.GetItemString(Me.cmbFase, Me.cmbFase.SelectedIndex), 1)
			lstrTensao(2) = Replace(VB6.GetItemString(Me.cmbTensao, Me.cmbTensao.SelectedIndex), ".", "")
			ldteEntrada(2) = CDate(VB6.Format(gDtBcoDados, "dd/mm/yyyy"))
			lstrIsentoCip(2) = IIf(Me.chkIlumU.CheckState = 1, "S", "N")
			lstrApSaude(2) = IIf(Me.chkApSaude.CheckState = 1, "S", "N")
			lstrEstufa(2) = IIf(Me.chkEstufa.CheckState = 1, "S", "N")
			lstrGrTar(2) = "01" & VB.Left(VB6.GetItemString(Me.cmbTarifa, Me.cmbTarifa.SelectedIndex), 2) & "00"
			lstrDiaVenc(2) = VB6.GetItemString(Me.cmbDiaVenc, Me.cmbDiaVenc.SelectedIndex)
			lstrCpf(2) = Str_Retira(Me.txtCPF.Text, ".-/ ")
			Select Case Len(lstrCpf(2))
				Case 14
					lstrInscr(2) = Me.txtIe.Text
					lstrRg(2) = ""
				Case Else
					lstrRg(2) = Me.txtRG.Text
					lstrInscr(2) = ""
			End Select
			lstrTpPessoa(2) = IIf(Len(lstrCpf(2)) = 14, "J", "F")
			lstrDisjuntor(2) = Trim(Str_Retira(Me.txtDisjuntor.Text, ".-/ "))
			lstrArea(2) = Str_Retira(txtArea.Text, ".-/ ")
			lstrEnd(2) = Me.lblEndUc.Text
			lstrNumero(2) = Me.txtNrUc.Text
			lstrComplement(2) = Me.txtComplemUC.Text
			lstrBairro(2) = Me.lblBairroUc.Text
			lstrCidade(2) = Me.lblMunicipioUc.Text
			lstrCep(2) = Str_Retira(Me.lblCepUc.Text, ".-/ ")
			lstrUf(2) = Me.lblUfUc.Text
			lstrDistrito(2) = Me.lblDistritoUc.Text
			lstrQuadra(2) = Me.txtQuadraUc.Text
			lstrLote(2) = Me.txtLoteUc.Text
			lstrEndEnt(2) = Me.txtEndEntrega.Text
			lstrNumEnt(2) = Me.txtNumEntrega.Text
			lstrComplEnt(2) = Me.txtComplEntrega.Text
			lstrBaiEnt(2) = Me.txtBaiEntrega.Text
			lstrCidEnt(2) = Me.txtCidEntrega.Text
			lstrCepEnt(2) = Str_Retira(Me.txtCepEntrega.Text, ".-/ ")
			lstrUfEnt(2) = Me.txtUfEntrega.Text
			lstrDisEnt(2) = Me.txtDisEntrega.Text
			lstrQuaEnt(2) = Me.txtQuaEntrega.Text
			lstrLotEnt(2) = Me.txtLotEntrega.Text
			llngConsId(2) = glngCons_id
			llngUnidId(2) = llngUnidId(1)
			llngAgrupa(2) = VB6.GetItemData(Me.cmbAgrupa, Me.cmbAgrupa.SelectedIndex)
			lstrAgrupaZona(2) = Me.txtAgrupaZona.Text
			lstrAgrupaLivro(2) = Me.txtAgrupaLivro.Text
			lstrAgrupaConta(2) = Me.txtAgrupaConta.Text
			'prepara os dados anteriores da unidade
			lstrSql = ""
			lstrSql = lstrSql & "SELECT * "
			lstrSql = lstrSql & "  FROM `unid" & LCase(istrGrupo) & "` AS `uc` "
			lstrSql = lstrSql & " WHERE `uc`.`unid_id` = " & llngUnidId(1) & " "
			Call Conectar(lstrSql, lrstUnid)
			With lrstUnid
				If .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"'
					lstrZona(1) = IIf(IsDbNull(.Fields("zona").value), "000", .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"'
					lstrLivro(1) = IIf(IsDbNull(.Fields("livro").value), "00", .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"'
					lstrConta(1) = IIf(IsDbNull(.Fields("conta").value), "000000", .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"'
					lstrRota(1) = IIf(IsDbNull(.Fields("rota").value), "00000000", .Fields("rota").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"'
					lstrNome(1) = IIf(IsDbNull(.Fields("nome").value), "000", .Fields("nome").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"'
					llngBanId(1) = IIf(IsDbNull(.Fields("banco").value), "000", .Fields("banco").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"'
					lstrAgenc(1) = IIf(IsDbNull(.Fields("agenc").value), "", .Fields("agenc").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"'
					lstrCc(1) = IIf(IsDbNull(.Fields("cc").value), "", .Fields("cc").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"'
					lstrClasse(1) = IIf(IsDbNull(.Fields("clas").value), "0000", .Fields("clas").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"'
					lstrFase(1) = IIf(IsDbNull(.Fields("fase").value), "M", .Fields("fase").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"'
					lstrTensao(1) = IIf(IsDbNull(.Fields("tensao").value), "", .Fields("tensao").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"'
					ldteEntrada(1) = CDate(VB6.Format(IIf(IsDbNull(.Fields("data_entrada").value), gDtBcoDados, .Fields("data_entrada").value), "dd/mm/yyyy"))
					If lblnTrasferiu = False Then
						ldteEntrada(2) = ldteEntrada(1)
					End If
					'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"'
					lstrIsentoCip(1) = IIf(IsDbNull(.Fields("ilum").value), "N", .Fields("ilum").value)
					If istrGrupo = "B" 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"'
						lstrApSaude(1) = IIf(IsDbNull(.Fields("ap_saude").value), "N", .Fields("ap_saude").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"'
						lstrDisjuntor(1) = IIf(IsDbNull(.Fields("disjuntor").value), "", .Fields("disjuntor").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"'
						lstrArea(1) = IIf(IsDbNull(.Fields("area").value), "", .Fields("area").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"'
						lstrMedidor(1) = IIf(IsDbNull(.Fields("num").value), 0, .Fields("num").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"'
						llngAgrupa(1) = IIf(IsDbNull(.Fields("agrupa").value), 0, .Fields("agrupa").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"'
						lstrAgrupaZona(1) = IIf(IsDbNull(.Fields("agrupa_zona").value), 0, .Fields("agrupa_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"'
						lstrAgrupaLivro(1) = IIf(IsDbNull(.Fields("agrupa_livro").value), 0, .Fields("agrupa_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"'
						lstrAgrupaConta(1) = IIf(IsDbNull(.Fields("agrupa_conta").value), 0, .Fields("agrupa_conta").value)
					End If
					'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"'
					lstrEstufa(1) = IIf(IsDbNull(.Fields("estufa").value), "N", .Fields("estufa").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"'
					lstrGrTar(1) = IIf(IsDbNull(.Fields("ta").value), "01B1", .Fields("ta").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"'
					lstrDiaVenc(1) = IIf(IsDbNull(.Fields("diavenc").value), "00", .Fields("diavenc").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"'
					lstrCpf(1) = IIf(IsDbNull(.Fields("cpf_cnpj").value), "", .Fields("cpf_cnpj").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"'
					lstrRg(1) = IIf(IsDbNull(.Fields("rg").value), "", .Fields("rg").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"'
					lstrInscr(1) = IIf(IsDbNull(.Fields("insc").value), "", .Fields("insc").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"'
					lstrTpPessoa(1) = IIf(IsDbNull(.Fields("pessoa").value), IIf(Len(lstrCpf(1)) = 14, "J", "F"), .Fields("pessoa").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"'
					lstrEndCodUc = IIf(IsDbNull(.Fields("codend").value), "", .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"'
					lstrEnd(1) = IIf(IsDbNull(.Fields("end").value), "", .Fields("end").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"'
					lstrNumero(1) = IIf(IsDbNull(.Fields("numero").value), "", .Fields("numero").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"'
					lstrComplement(1) = IIf(IsDbNull(.Fields("complement").value), "", .Fields("complement").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"'
					lstrBairro(1) = IIf(IsDbNull(.Fields("bairro").value), "", .Fields("bairro").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"'
					lstrCidade(1) = IIf(IsDbNull(.Fields("cidade").value), "", .Fields("cidade").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"'
					lstrCep(1) = IIf(IsDbNull(.Fields("cep").value), "", .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"'
					lstrUf(1) = IIf(IsDbNull(.Fields("uf").value), "", .Fields("uf").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"'
					lstrDistrito(1) = IIf(IsDbNull(.Fields("distrito").value), "", .Fields("distrito").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"'
					lstrQuadra(1) = IIf(IsDbNull(.Fields("quadra").value), "", .Fields("quadra").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"'
					lstrLote(1) = IIf(IsDbNull(.Fields("lote").value), "", .Fields("lote").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"'
					lstrEndCodEnt = IIf(IsDbNull(.Fields("codend_entrega").value), "", .Fields("codend_entrega").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"'
					lstrEndEnt(1) = IIf(IsDbNull(.Fields("end_entrega").value), "", .Fields("end_entrega").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"'
					lstrNumEnt(1) = IIf(IsDbNull(.Fields("num_entrega").value), "", .Fields("num_entrega").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"'
					lstrComplEnt(1) = IIf(IsDbNull(.Fields("compl_entrega").value), "", .Fields("compl_entrega").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"'
					lstrBaiEnt(1) = IIf(IsDbNull(.Fields("bai_entrega").value), "", .Fields("bai_entrega").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"'
					lstrCidEnt(1) = IIf(IsDbNull(.Fields("cid_entrega").value), "", .Fields("cid_entrega").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"'
					lstrCepEnt(1) = IIf(IsDbNull(.Fields("cep_entrega").value), "", .Fields("cep_entrega").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"'
					lstrUfEnt(1) = IIf(IsDbNull(.Fields("uf_entrega").value), "", .Fields("uf_entrega").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"'
					lstrDisEnt(1) = IIf(IsDbNull(.Fields("dis_entrega").value), "", .Fields("dis_entrega").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"'
					lstrQuaEnt(1) = IIf(IsDbNull(.Fields("qua_entrega").value), "", .Fields("qua_entrega").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"'
					lstrLotEnt(1) = IIf(IsDbNull(.Fields("lot_entrega").value), "", .Fields("lot_entrega").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"'
					llngConsId(1) = IIf(IsDbNull(.Fields("cons_id").value), 0, .Fields("cons_id").value)
					If istrGrupo = "A" 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"'
						lstrMedidor(1) = IIf(IsDbNull(.Fields("eletr").value), 0, .Fields("eletr").value)
					End If
					lstrSql = ""
					lstrSql = lstrSql & "INSERT INTO unid" & LCase(istrGrupo) & "_alt SET "
					lstrSql = lstrSql & "zona_old = """ & lstrZona(1) & """, "
					lstrSql = lstrSql & "livro_old = """ & lstrLivro(1) & """, "
					lstrSql = lstrSql & "conta_old = """ & lstrConta(1) & """, "
					lstrSql = lstrSql & "rota_old = """ & lstrRota(1) & """, "
					lstrSql = lstrSql & "nome_old = """ & lstrNome(1) & """, "
					lstrSql = lstrSql & "banco_old = """ & VB6.Format(llngBanId(1), "000") & """, "
					lstrSql = lstrSql & "agenc_old = """ & lstrAgenc(1) & """, "
					lstrSql = lstrSql & "cc_old = """ & lstrCc(1) & """, "
					lstrSql = lstrSql & "clas_old = """ & lstrClasse(1) & """, "
					lstrSql = lstrSql & "fase_old = """ & lstrFase(1) & """, "
					lstrSql = lstrSql & "tensao_old = """ & lstrTensao(1) & """, "
					lstrSql = lstrSql & "data_entrada_old = """ & VB6.Format(ldteEntrada(1), "yyyy-MM-dd") & """, "
					lstrSql = lstrSql & "ilum_old = """ & lstrIsentoCip(1) & """, "
					lstrSql = lstrSql & "ap_saude_old = """ & lstrApSaude(1) & """, "
					lstrSql = lstrSql & "estufa_old = """ & lstrEstufa(1) & """, "
					lstrSql = lstrSql & "ta_old = """ & lstrGrTar(1) & """, "
					lstrSql = lstrSql & "diavenc_old = """ & lstrDiaVenc(1) & """, "
					lstrSql = lstrSql & "cpf_cnpj_old = """ & lstrCpf(1) & """, "
					lstrSql = lstrSql & "rg_old = """ & lstrRg(1) & """, "
					lstrSql = lstrSql & "insc_old = """ & lstrInscr(1) & """, "
					lstrSql = lstrSql & "pessoa_old = """ & lstrTpPessoa(1) & """, "
					If lstrDisjuntor(1) = "" Then
						lstrSql = lstrSql & "disjuntor_old = null, "
					Else
						lstrSql = lstrSql & "disjuntor_old = '" & lstrDisjuntor(1) & "', "
					End If
					lstrSql = lstrSql & "area_old = " & IIf(lstrArea(1) = "", "null", lstrArea(1)) & ", "
					lstrSql = lstrSql & "codend_old = """ & lstrEndCodUc & """, "
					lstrSql = lstrSql & "end_old = """ & lstrEnd(1) & """, "
					lstrSql = lstrSql & "numero_old = """ & lstrNumero(1) & """, "
					lstrSql = lstrSql & "complement_old = """ & lstrComplement(1) & """, "
					lstrSql = lstrSql & "bairro_old = """ & lstrBairro(1) & """, "
					lstrSql = lstrSql & "cidade_old = """ & lstrCidade(1) & """, "
					lstrSql = lstrSql & "cep_old = """ & lstrCep(1) & """, "
					lstrSql = lstrSql & "uf_old = """ & lstrUf(1) & """, "
					lstrSql = lstrSql & "distrito_old = """ & lstrDistrito(1) & """, "
					lstrSql = lstrSql & "quadra_old = """ & lstrQuadra(1) & """, "
					lstrSql = lstrSql & "lote_old = """ & lstrLote(1) & """, "
					lstrSql = lstrSql & "codend_entrega_old = """ & lstrEndCodEnt & """, "
					lstrSql = lstrSql & "end_entrega_old = """ & lstrEndEnt(1) & """, "
					lstrSql = lstrSql & "num_entrega_old = """ & lstrNumEnt(1) & """, "
					lstrSql = lstrSql & "compl_entrega_old = """ & lstrComplEnt(1) & """, "
					lstrSql = lstrSql & "bai_entrega_old = """ & lstrBaiEnt(1) & """, "
					lstrSql = lstrSql & "cid_entrega_old = """ & lstrCidEnt(1) & """, "
					lstrSql = lstrSql & "cep_entrega_old = """ & lstrCepEnt(1) & """, "
					lstrSql = lstrSql & "uf_entrega_old = """ & lstrUfEnt(1) & """, "
					lstrSql = lstrSql & "dis_entrega_old = """ & lstrDisEnt(1) & """, "
					lstrSql = lstrSql & "qua_entrega_old = """ & lstrQuaEnt(1) & """, "
					lstrSql = lstrSql & "lot_entrega_old = """ & lstrLotEnt(1) & """, "
					lstrSql = lstrSql & "medidor_old = """ & "" & """, "
					lstrSql = lstrSql & "cons_id_old = """ & llngConsId(1) & """, "
					lstrSql = lstrSql & "unid_id_old = """ & llngUnidId(1) & """, "
					
					lstrSql = lstrSql & "zona_new = """ & lstrZona(2) & """, "
					lstrSql = lstrSql & "livro_new = """ & lstrLivro(2) & """, "
					lstrSql = lstrSql & "conta_new = """ & lstrConta(2) & """, "
					lstrSql = lstrSql & "rota_new = """ & lstrRota(2) & """, "
					lstrSql = lstrSql & "nome_new = """ & lstrNome(2) & """, "
					lstrSql = lstrSql & "banco_new = """ & VB6.Format(llngBanId(2), "000") & """, "
					lstrSql = lstrSql & "agenc_new = """ & lstrAgenc(2) & """, "
					lstrSql = lstrSql & "cc_new = """ & lstrCc(2) & """, "
					lstrSql = lstrSql & "clas_new = """ & lstrClasse(2) & """, "
					lstrSql = lstrSql & "fase_new = """ & lstrFase(2) & """, "
					lstrSql = lstrSql & "tensao_new = """ & lstrTensao(2) & """, "
					lstrSql = lstrSql & "data_entrada_new = """ & VB6.Format(ldteEntrada(2), "yyyy-MM-dd") & """, "
					lstrSql = lstrSql & "ilum_new = """ & lstrIsentoCip(2) & """, "
					lstrSql = lstrSql & "ap_saude_new = """ & lstrApSaude(2) & """, "
					lstrSql = lstrSql & "estufa_new = """ & lstrEstufa(2) & """, "
					lstrSql = lstrSql & "ta_new = """ & lstrGrTar(2) & """, "
					lstrSql = lstrSql & "diavenc_new = """ & lstrDiaVenc(2) & """, "
					lstrSql = lstrSql & "cpf_cnpj_new = """ & lstrCpf(2) & """, "
					lstrSql = lstrSql & "rg_new = """ & lstrRg(2) & """, "
					lstrSql = lstrSql & "insc_new = """ & lstrInscr(2) & """, "
					lstrSql = lstrSql & "pessoa_new = """ & lstrTpPessoa(2) & """, "
					If lstrDisjuntor(2) = "" Then
						lstrSql = lstrSql & "disjuntor_new = null, "
					Else
						lstrSql = lstrSql & "disjuntor_new = '" & lstrDisjuntor(2) & "', "
					End If
					lstrSql = lstrSql & "area_new = " & IIf(lstrArea(2) = "", "null", lstrArea(2)) & ", "
					lstrSql = lstrSql & "codend_new = """ & istrEndCodUC & """, "
					lstrSql = lstrSql & "end_new = """ & lstrEnd(2) & """, "
					lstrSql = lstrSql & "numero_new = """ & lstrNumero(2) & """, "
					lstrSql = lstrSql & "complement_new = """ & lstrComplement(2) & """, "
					lstrSql = lstrSql & "bairro_new = """ & lstrBairro(2) & """, "
					lstrSql = lstrSql & "cidade_new = """ & lstrCidade(2) & """, "
					lstrSql = lstrSql & "cep_new = """ & lstrCep(2) & """, "
					lstrSql = lstrSql & "uf_new = """ & lstrUf(2) & """, "
					lstrSql = lstrSql & "distrito_new = """ & lstrDistrito(2) & """, "
					lstrSql = lstrSql & "quadra_new = """ & lstrQuadra(2) & """, "
					lstrSql = lstrSql & "lote_new = """ & lstrLote(2) & """, "
					lstrSql = lstrSql & "codend_entrega_new = """ & istrEndCodEn & """, "
					lstrSql = lstrSql & "end_entrega_new = """ & lstrEndEnt(2) & """, "
					lstrSql = lstrSql & "num_entrega_new = """ & lstrNumEnt(2) & """, "
					lstrSql = lstrSql & "compl_entrega_new = """ & lstrComplEnt(2) & """, "
					lstrSql = lstrSql & "bai_entrega_new = """ & lstrBaiEnt(2) & """, "
					lstrSql = lstrSql & "cid_entrega_new = """ & lstrCidEnt(2) & """, "
					lstrSql = lstrSql & "cep_entrega_new = """ & lstrCepEnt(2) & """, "
					lstrSql = lstrSql & "uf_entrega_new = """ & lstrUfEnt(2) & """, "
					lstrSql = lstrSql & "dis_entrega_new = """ & lstrDisEnt(2) & """, "
					lstrSql = lstrSql & "qua_entrega_new = """ & lstrQuaEnt(2) & """, "
					lstrSql = lstrSql & "lot_entrega_new = """ & lstrLotEnt(2) & """, "
					lstrSql = lstrSql & "medidor_new = """ & "" & """, "
					lstrSql = lstrSql & "cons_id_new = """ & llngConsId(2) & """, "
					lstrSql = lstrSql & "unid_id_new = """ & llngUnidId(2) & """ "
					Call Executar(lstrSql)
				End If
				If .State = 1 Then Call .Close()
			End With
			'*************************************************************************************
			lstrDescrAgrupa = ""
			With Me.cmbAgrupa
				'
				'Pega a descrição do agrupamento atual da Unidade Consumidora
				For llngLinha = 0 To .Items.Count - 1
					If VB6.GetItemData(Me.cmbAgrupa, llngLinha) = llngAgrupa(1) Then
						lstrDescrAgrupa = VB6.GetItemString(Me.cmbAgrupa, llngLinha)
						llngLinha = .Items.Count
					End If
				Next llngLinha
				'
				If llngAgrupa(1) = llngAgrupa(2) And InStr(lstrDescrAgrupa, "DOMICÍLIO") = 0 Then
					If MsgBox("Existe o agrupamento " & lstrDescrAgrupa & " definido para esta U.C.! Deseja manter este agrupamento?", MsgBoxStyle.YesNo + MsgBoxStyle.DefaultButton2, gstrTituloMensagem) = MsgBoxResult.No Then
						For llngLinha = 0 To .Items.Count - 1
							If InStr(VB6.GetItemString(Me.cmbAgrupa, llngLinha), "DOMICÍLIO") > 0 Then
								llngAgrupa(2) = VB6.GetItemData(Me.cmbAgrupa, llngLinha)
								llngLinha = .Items.Count
							End If
						Next llngLinha
					End If
				End If
			End With
			If lstrAgrupaZona(1) <> "" Then
				If lstrAgrupaZona(1) = lstrAgrupaZona(2) And lstrAgrupaLivro(1) = lstrAgrupaLivro(2) And lstrAgrupaConta(1) = lstrAgrupaConta(2) Then
					If MsgBox("Esta U.C. esta agrupada com " & lstrAgrupaZona(1) & "." & lstrAgrupaLivro(1) & "." & lstrAgrupaConta(1) & "! Deseja manter este agrupamento?", MsgBoxStyle.YesNo + MsgBoxStyle.DefaultButton2, gstrTituloMensagem) = MsgBoxResult.No Then
						lstrAgrupaZona(2) = ""
						lstrAgrupaLivro(2) = ""
						lstrAgrupaConta(2) = ""
					End If
				End If
			End If
			'*************************************************************************************
			
			' ----- Atualiza Unidb
			lstrSql = ""
			lstrSql = lstrSql & "UPDATE unid" & LCase(istrGrupo) & " SET "
			lstrSql = lstrSql & "       zona = """ & lstrZona(2) & """, "
			lstrSql = lstrSql & "       livro = """ & lstrLivro(2) & """, "
			lstrSql = lstrSql & "       conta = """ & lstrConta(2) & """, "
			lstrSql = lstrSql & "       rota = """ & lstrRota(2) & """, "
			lstrSql = lstrSql & "       nome = """ & lstrNome(2) & """, "
			lstrSql = lstrSql & "       banco = """ & VB6.Format(llngBanId(2), "000") & """, "
			lstrSql = lstrSql & "       agenc = """ & lstrAgenc(2) & """, "
			lstrSql = lstrSql & "       cc = """ & lstrCc(2) & """, "
			lstrSql = lstrSql & "       clas = """ & lstrClasse(2) & """, "
			lstrSql = lstrSql & "       fase = """ & lstrFase(2) & """, "
			lstrSql = lstrSql & "       tensao = """ & lstrTensao(2) & """, "
			lstrSql = lstrSql & "       data_entrada = """ & VB6.Format(ldteEntrada(2), "yyyy-MM-dd") & """, "
			lstrSql = lstrSql & "       ilum = """ & lstrIsentoCip(2) & """, "
			If istrGrupo = "B" Then
				lstrSql = lstrSql & "       ap_saude = """ & lstrApSaude(2) & """, "
				If lstrDisjuntor(2) = "" Then
					lstrSql = lstrSql & "       disjuntor = null, "
				Else
					lstrSql = lstrSql & "       disjuntor = " & lstrDisjuntor(2) & ", "
				End If
				lstrSql = lstrSql & "       area = " & IIf(lstrArea(2) = "", "null", lstrArea(2)) & ", "
				lstrSql = lstrSql & "       `agrupa`         = " & llngAgrupa(2) & ", "
				lstrSql = lstrSql & "       `agrupa_zona`    = '" & lstrAgrupaZona(2) & "', "
				lstrSql = lstrSql & "       `agrupa_livro`   = '" & lstrAgrupaLivro(2) & "', "
				lstrSql = lstrSql & "       `agrupa_conta`   = '" & lstrAgrupaConta(2) & "', "
				If lblnTrasferiu Then
					lstrSql = lstrSql & "       residuo_consumo = 0,"
				End If
			End If
			lstrSql = lstrSql & "       estufa = """ & lstrEstufa(2) & """, "
			lstrSql = lstrSql & "       ta = """ & lstrGrTar(2) & """, "
			lstrSql = lstrSql & "       diavenc = """ & lstrDiaVenc(2) & """, "
			lstrSql = lstrSql & "       cpf_cnpj = """ & lstrCpf(2) & """, "
			lstrSql = lstrSql & "       rg = """ & lstrRg(2) & """, "
			lstrSql = lstrSql & "       insc = """ & lstrInscr(2) & """, "
			lstrSql = lstrSql & "       pessoa = """ & lstrTpPessoa(2) & """, "
			lstrSql = lstrSql & "       codend = """ & istrEndCodUC & """, "
			lstrSql = lstrSql & "       end = """ & lstrEnd(2) & """, "
			lstrSql = lstrSql & "       numero = """ & lstrNumero(2) & """, "
			lstrSql = lstrSql & "       complement = """ & lstrComplement(2) & """, "
			lstrSql = lstrSql & "       bairro = """ & lstrBairro(2) & """, "
			lstrSql = lstrSql & "       cidade = """ & lstrCidade(2) & """, "
			lstrSql = lstrSql & "       cep = """ & lstrCep(2) & """, "
			lstrSql = lstrSql & "       uf = """ & lstrUf(2) & """, "
			lstrSql = lstrSql & "       distrito = """ & lstrDistrito(2) & """, "
			lstrSql = lstrSql & "       quadra = """ & lstrQuadra(2) & """, "
			lstrSql = lstrSql & "       lote = """ & lstrLote(2) & """, "
			lstrSql = lstrSql & "       codend_entrega = """ & istrEndCodEn & """, "
			lstrSql = lstrSql & "       end_entrega = """ & lstrEndEnt(2) & """, "
			lstrSql = lstrSql & "       num_entrega = """ & lstrNumEnt(2) & """, "
			lstrSql = lstrSql & "       compl_entrega = """ & lstrComplEnt(2) & """, "
			lstrSql = lstrSql & "       bai_entrega = """ & lstrBaiEnt(2) & """, "
			lstrSql = lstrSql & "       cid_entrega = """ & lstrCidEnt(2) & """, "
			lstrSql = lstrSql & "       cep_entrega = """ & lstrCepEnt(2) & """, "
			lstrSql = lstrSql & "       uf_entrega = """ & lstrUfEnt(2) & """, "
			lstrSql = lstrSql & "       dis_entrega = """ & lstrDisEnt(2) & """, "
			lstrSql = lstrSql & "       qua_entrega = """ & lstrQuaEnt(2) & """, "
			lstrSql = lstrSql & "       lot_entrega = """ & lstrLotEnt(2) & """, "
			lstrSql = lstrSql & "       cons_id = """ & llngConsId(2) & """ "
			lstrSql = lstrSql & " WHERE unid_id = " & llngUnidId(2) & " "
			Call Executar(lstrSql)
			glngUnid_id = llngUnidId(2)
			
			If istrGrupo = "B" Then
				'Verifica se precisa trocar a unidade consumidora do NIS
				lstrSql = "SELECT * " & "  FROM nis " & " WHERE cpf = """ & lstrCpf(2) & """ " & " LIMIT 1 "
				Call Conectar(lstrSql, lrstConsulta)
				With lrstConsulta
					If .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"'
						lstrZonaNis = IIf(IsDbNull(.Fields("zona").value), "", .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"'
						lstrLivroNis = IIf(IsDbNull(.Fields("livro").value), "", .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"'
						lstrContaNis = IIf(IsDbNull(.Fields("conta").value), "", .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"'
						llngUnidIdNis = IIf(IsDbNull(.Fields("unid_id").value), 0, .Fields("unid_id").value)
					Else
						lstrZonaNis = lstrZona(2)
						lstrLivroNis = lstrLivro(2)
						lstrContaNis = lstrConta(2)
						llngUnidIdNis = llngUnidId(2)
					End If
					If .State = 1 Then Call .Close()
				End With
				If (lstrZonaNis <> lstrZona(2)) Or (lstrLivroNis <> lstrLivro(2)) Or (lstrContaNis <> lstrConta(2)) Or (llngUnidIdNis <> llngUnidId(2)) Then
					lstrSql = "SELECT * " & "  FROM unid" & LCase(istrGrupo) & " WHERE unid_id = " & llngUnidIdNis & "   AND situacao = ""L"" " & " LIMIT 1 "
					Call Conectar(lstrSql, lrstConsulta)
					With lrstConsulta
						If .RecordCount < 1 Then
							lstrSql = "UPDATE nis SET " & "       zona = """ & lstrZona(2) & """, " & "       livro = """ & lstrLivro(2) & """, " & "       conta = """ & lstrConta(2) & """, " & "       unid_id = " & llngUnidId(2) & " WHERE cpf = """ & lstrCpf(2) & """ "
							Call Executar(lstrSql)
						End If
						If .State = 1 Then Call .Close()
					End With
				End If
			End If
			' ----- Atualiza tabelas: taxas, leitmensal e nftransicao
			ilngConsidO = llngConsId(1)
			Call AtualizaTabelas()
			
			Call MsgBox("Unidade consumidora atualizada com sucesso!", MsgBoxStyle.Information, gstrTituloMensagem)
			Call ImprimeAlteracao(llngConsId(1), llngUnidId(1), llngConsId(2), llngUnidId(2))
		End If
		'UPGRADE_NOTE: Object lrstConsulta may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstConsulta = Nothing
		'UPGRADE_NOTE: Object lrstUnid may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstUnid = Nothing
	End Sub
	
	Private Sub ImprimeAlteracao(ByVal alngConsIdO As Integer, ByVal alngUnidIdO As Integer, ByVal alngConsIdN As Integer, ByVal alngUnidIdN As Integer)
		Dim lstrSql As String
		Dim lstrCriterio As String
		
		' ----- Apaga os dados da tabela temporária
		lstrSql = "DELETE FROM temp_alt_cadastro WHERE nm_usuario = """ & gstrNmEstacao & """ "
		Call Executar(lstrSql)
		lstrSql = ""
		lstrSql = lstrSql & "INSERT INTO temp_alt_cadastro ("
		lstrSql = lstrSql & "     SELECT """ & gstrNmEstacao & """, "
		lstrSql = lstrSql & "           `unidade`.`zona_old`, "
		lstrSql = lstrSql & "           `unidade`.`livro_old`, "
		lstrSql = lstrSql & "           `unidade`.`conta_old`, "
		lstrSql = lstrSql & "           `unidade`.`rota_old`, "
		lstrSql = lstrSql & "           `unidade`.`nome_old`, "
		lstrSql = lstrSql & "           `unidade`.`banco_old`, "
		lstrSql = lstrSql & "           `unidade`.`agenc_old`, "
		lstrSql = lstrSql & "           `unidade`.`cc_old`, "
		lstrSql = lstrSql & "           `unidade`.`clas_old`, "
		lstrSql = lstrSql & "           `unidade`.`fase_old`, "
		lstrSql = lstrSql & "           `unidade`.`tensao_old`, "
		lstrSql = lstrSql & "           `unidade`.`data_entrada_old`, "
		lstrSql = lstrSql & "           `unidade`.`ilum_old`, "
		lstrSql = lstrSql & "           `unidade`.`ap_saude_old`, "
		lstrSql = lstrSql & "           `unidade`.`ta_old`, "
		lstrSql = lstrSql & "           `unidade`.`diavenc_old`, "
		lstrSql = lstrSql & "           `unidade`.`cpf_cnpj_old`, "
		lstrSql = lstrSql & "           `unidade`.`rg_old`, "
		lstrSql = lstrSql & "           `unidade`.`insc_old`, "
		lstrSql = lstrSql & "           `unidade`.`pessoa_old`, "
		lstrSql = lstrSql & "           `unidade`.`disjuntor_old`, "
		lstrSql = lstrSql & "           `unidade`.`area_old`, "
		lstrSql = lstrSql & "           `unidade`.`end_old`, "
		lstrSql = lstrSql & "           `unidade`.`numero_old`, "
		lstrSql = lstrSql & "           `unidade`.`complement_old`, "
		lstrSql = lstrSql & "           `unidade`.`bairro_old`, "
		lstrSql = lstrSql & "           `unidade`.`cidade_old`, "
		lstrSql = lstrSql & "           `unidade`.`cep_old`, "
		lstrSql = lstrSql & "           `unidade`.`uf_old`, "
		lstrSql = lstrSql & "           `unidade`.`distrito_old`, "
		lstrSql = lstrSql & "           `unidade`.`quadra_old`, "
		lstrSql = lstrSql & "           `unidade`.`lote_old`, "
		lstrSql = lstrSql & "           `unidade`.`end_entrega_old`, "
		lstrSql = lstrSql & "           `unidade`.`num_entrega_old`, "
		lstrSql = lstrSql & "           `unidade`.`compl_entrega_old`, "
		lstrSql = lstrSql & "           `unidade`.`bai_entrega_old`, "
		lstrSql = lstrSql & "           `unidade`.`cid_entrega_old`, "
		lstrSql = lstrSql & "           `unidade`.`cep_entrega_old`, "
		lstrSql = lstrSql & "           `unidade`.`uf_entrega_old`, "
		lstrSql = lstrSql & "           `unidade`.`dis_entrega_old`, "
		lstrSql = lstrSql & "           `unidade`.`medidor_old`, "
		lstrSql = lstrSql & "           `unidade`.`cons_id_old`, "
		lstrSql = lstrSql & "           `unidade`.`unid_id_old`, "
		lstrSql = lstrSql & "           `unidade`.`zona_new`, "
		lstrSql = lstrSql & "           `unidade`.`livro_new`, "
		lstrSql = lstrSql & "           `unidade`.`conta_new`, "
		lstrSql = lstrSql & "           `unidade`.`rota_new`, "
		lstrSql = lstrSql & "           `unidade`.`nome_new`, "
		lstrSql = lstrSql & "           `unidade`.`banco_new`, "
		lstrSql = lstrSql & "           `unidade`.`agenc_new`, "
		lstrSql = lstrSql & "           `unidade`.`cc_new`, "
		lstrSql = lstrSql & "           `unidade`.`clas_new`, "
		lstrSql = lstrSql & "           `unidade`.`fase_new`, "
		lstrSql = lstrSql & "           `unidade`.`tensao_new`, "
		lstrSql = lstrSql & "           `unidade`.`data_entrada_new`, "
		lstrSql = lstrSql & "           `unidade`.`ilum_new`, "
		lstrSql = lstrSql & "           `unidade`.`ap_saude_new`, "
		lstrSql = lstrSql & "           `unidade`.`ta_new`, "
		lstrSql = lstrSql & "           `unidade`.`diavenc_new`, "
		lstrSql = lstrSql & "           `unidade`.`cpf_cnpj_new`, "
		lstrSql = lstrSql & "           `unidade`.`rg_new`, "
		lstrSql = lstrSql & "           `unidade`.`insc_new`, "
		lstrSql = lstrSql & "           `unidade`.`pessoa_new`, "
		lstrSql = lstrSql & "           `unidade`.`disjuntor_new`, "
		lstrSql = lstrSql & "           `unidade`.`area_new`, "
		lstrSql = lstrSql & "           `unidade`.`end_new`, "
		lstrSql = lstrSql & "           `unidade`.`numero_new`, "
		lstrSql = lstrSql & "           `unidade`.`complement_new`, "
		lstrSql = lstrSql & "           `unidade`.`bairro_new`, "
		lstrSql = lstrSql & "           `unidade`.`cidade_new`, "
		lstrSql = lstrSql & "           `unidade`.`cep_new`, "
		lstrSql = lstrSql & "           `unidade`.`uf_new`, "
		lstrSql = lstrSql & "           `unidade`.`distrito_new`, "
		lstrSql = lstrSql & "           `unidade`.`quadra_new`, "
		lstrSql = lstrSql & "           `unidade`.`lote_new`, "
		lstrSql = lstrSql & "           `unidade`.`end_entrega_new`, "
		lstrSql = lstrSql & "           `unidade`.`num_entrega_new`, "
		lstrSql = lstrSql & "           `unidade`.`compl_entrega_new`, "
		lstrSql = lstrSql & "           `unidade`.`bai_entrega_new`, "
		lstrSql = lstrSql & "           `unidade`.`cid_entrega_new`, "
		lstrSql = lstrSql & "           `unidade`.`cep_entrega_new`, "
		lstrSql = lstrSql & "           `unidade`.`uf_entrega_new`, "
		lstrSql = lstrSql & "           `unidade`.`dis_entrega_new`, "
		lstrSql = lstrSql & "           `unidade`.`medidor_new`, "
		lstrSql = lstrSql & "           `unidade`.`cons_id_new`, "
		lstrSql = lstrSql & "           `unidade`.`unid_id_new` "
		lstrSql = lstrSql & "  FROM unid" & LCase(istrGrupo) & "_alt as `unidade` "
		lstrSql = lstrSql & " WHERE `unidade`.`cons_id_new` = " & alngConsIdN
		lstrSql = lstrSql & "   AND `unidade`.`unid_id_new` = " & alngUnidIdN
		If alngConsIdO > 0 Then lstrSql = lstrSql & "   AND `unidade`.`cons_id_old` = " & alngConsIdO
		If alngUnidIdO > 0 Then lstrSql = lstrSql & "   AND `unidade`.`unid_id_old` = " & alngUnidIdO
		lstrSql = lstrSql & " ORDER BY `unidade`.`codigo_alt` DESC "
		lstrSql = lstrSql & " LIMIT 1 " & ")"
		Call Executar(lstrSql)
		' ----- Chama o Report de alteraçao de cadastro
		lstrCriterio = "{temp_alt_cadastro.nm_usuario} = """ & gstrNmEstacao & """"
		With Me.crpAlteracao
			.ReportFileName = My.Application.Info.DirectoryPath & "\" & LeConfig("DIR_RPT") & "AlteracaoCadastro.rpt"
			.DiscardSavedData = True
			.WindowState = Crystal.WindowStateConstants.crptMaximized
			.WindowControlBox = True
			.WindowControls = True
			.SelectionFormula = lstrCriterio
			.WindowShowPrintSetupBtn = True
			.WindowShowCloseBtn = True
			.WindowShowSearchBtn = True
			.WindowTitle = "Alteração Cadastral"
			.Destination = Crystal.DestinationConstants.crptToWindow
			.Action = 0
		End With
		
	End Sub
	Private Sub AtualizaTabelas()
		Dim ldteBase As Date
		Dim lstrSql As String
		Dim lstrMesAno As String
		Dim lstrAnoMes As String
		Dim lrstConsulta As ADODB.Recordset
		
		lrstConsulta = New ADODB.Recordset
		
		lstrMesAno = LeConfig("MESANOFATURAMENTO")
		lstrAnoMes = VB.Right(lstrMesAno, 4) & VB.Left(lstrMesAno, 2)
		ldteBase = CDate(VB6.Format(VB6.Format(gDtBcoDados, "yyyy-mm") & "-01", "yyyy-MM-dd"))
		lstrSql = ""
		lstrSql = lstrSql & "UPDATE taxas  "
		lstrSql = lstrSql & "   SET cons_id  = " & glngCons_id & " "
		lstrSql = lstrSql & " WHERE dt_ini  > """ & VB6.Format(ldteBase, "yyyy-MM-dd") & """ "
		lstrSql = lstrSql & "   AND unid_id  = " & glngUnid_id & " and cons_id = " & ilngConsidO
		Call Executar(lstrSql)
		If istrGrupo = "B" Then
			lstrSql = "SELECT * " & "  FROM leitmensal" & " WHERE dt_leit >= """ & VB6.Format(ldteBase, "yyyy-MM-dd") & """ " & "   AND unid_id = " & glngUnid_id & " " & " LIMIT 1 "
		Else
			lstrSql = ""
			lstrSql = lstrSql & "SELECT * "
			lstrSql = lstrSql & "  FROM leitura "
			lstrSql = lstrSql & " WHERE dt_leit_atual >= '" & VB6.Format(ldteBase, "yyyy-MM-dd") & "' "
			lstrSql = lstrSql & "   AND id_unid = " & glngUnid_id & " "
		End If
		Call Conectar(lstrSql, lrstConsulta)
		If lrstConsulta.RecordCount > 0 Then
			If lrstConsulta.State = 1 Then Call lrstConsulta.Close()
			lstrSql = "SELECT * " & "  FROM nf " & " WHERE CONCAT(RIGHT(mesano,4),'-',LEFT(mesano,2),'-01') >= """ & VB6.Format(ldteBase, "yyyy-MM-dd") & """ " & "   AND unid_id = " & glngUnid_id & " and cons_id = " & ilngConsidO & " LIMIT 1 "
			Call Conectar(lstrSql, lrstConsulta)
			If lrstConsulta.RecordCount < 1 Then
				lstrSql = "UPDATE taxas  " & "   SET cons_id  = " & glngCons_id & " " & " WHERE dt_ini  = """ & VB6.Format(ldteBase, "yyyy-MM-dd") & """ " & "   AND unid_id  = " & glngUnid_id & " and cons_id = " & ilngConsidO
				Call Executar(lstrSql)
				If istrGrupo = "B" Then
					lstrSql = "UPDATE leitmensal  " & "   SET cons_id = " & glngCons_id & " " & " WHERE dt_leit >= """ & VB6.Format(ldteBase, "yyyy-MM-dd") & """ " & "   AND unid_id = " & glngUnid_id & " "
				Else
					lstrSql = ""
					lstrSql = lstrSql & "UPDATE leitura "
					lstrSql = lstrSql & "   SET id_consumidor = " & glngCons_id & " "
					lstrSql = lstrSql & " WHERE dt_leit_atual >= '" & VB6.Format(ldteBase, "yyyy-MM-dd") & "' "
					lstrSql = lstrSql & "   AND id_unid = " & glngUnid_id & " "
				End If
				Call Executar(lstrSql)
				
				lstrSql = "UPDATE nftransicao  " & "   SET cons_id = " & glngCons_id & " " & " WHERE concat(right(mesano,4),'-',left(mesano,2),'-01') >= """ & VB6.Format(ldteBase, "yyyy-MM-dd") & """ " & "   AND unid_id = " & glngUnid_id & " and cons_id = " & ilngConsidO
				Call Executar(lstrSql)
			End If
		End If
		If lrstConsulta.State = 1 Then Call lrstConsulta.Close()
	End Sub
	
	Private Sub cmdFechar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdFechar.Click
		Call Me.Close()
	End Sub
	
	'Versão: 001 Desenvolvedor: Ricardo Inacio Data: 18/07/2008 Descrição: Rotina usada pelo frmPreencheEnde para devolver para este os dados de endereço
	Public Sub SetaCamposEndereco(ByVal astrUf As String, ByVal astrCidade As String, ByVal astrDistrito As String, ByVal astrBairro As String, ByVal astrEnd As String, ByVal astrCep As String, ByVal astrCodigo As String)
		Call FrmPreencherEnde.Close()
		If gstrModoConsEnd = "C" Then
			Me.lblEndC.Text = astrEnd
			Me.lblBairroC.Text = astrBairro
			Me.lblDistritoC.Text = astrDistrito
			Me.lblMunicipioC.Text = astrCidade
			Me.lblUfC.Text = astrUf
			Me.lblCepC.Text = Mid(astrCep, 1, 5) & "-" & Mid(astrCep, 6, 3)
			istrEndCodC = astrCodigo
		ElseIf gstrModoConsEnd = "UC" Then 
			Me.lblEndUc.Text = astrEnd
			Me.lblBairroUc.Text = astrBairro
			Me.lblDistritoC.Text = astrDistrito
			Me.lblMunicipioUc.Text = astrCidade
			Me.lblUfUc.Text = astrUf
			Me.lblCepUc.Text = Mid(astrCep, 1, 5) & "-" & Mid(astrCep, 6, 3)
			istrEndCodUC = astrCodigo
		ElseIf gstrModoConsEnd = "E" Then 
			Me.txtEndEntrega.Text = astrEnd
			Me.txtBaiEntrega.Text = astrBairro
			Me.txtDisEntrega.Text = astrDistrito
			Me.txtCidEntrega.Text = astrCidade
			Me.txtUfEntrega.Text = astrUf
			Me.txtCepEntrega.Text = Mid(astrCep, 1, 5) & "-" & Mid(astrCep, 6, 3)
			istrEndCodEn = astrCodigo
		End If
		If gstrModoConsEnd <> "E" And gstrEmpresa_Sigla = "EFLJCL" Then
			'Preenche o mesmo endereço da unidade por padrão
			opbEndPadrao.Checked = True
			Call opbEndPadrao_CheckedChanged(opbEndPadrao, New System.EventArgs())
		End If
	End Sub
	
	Private Sub validaCamposConsumidor()
		If Trim(Me.txtCPF.Text) <> "" And Trim(Me.txtNome.Text) <> "" Then
			If Valida_CPF_CGC(Str_Retira(Me.txtCPF.Text, ".-/ ")) Then
				Me.sstCadastros.TabPages.Item(1).Enabled = True
				Me.sstCadastros.TabPages.Item(2).Enabled = True
			Else
				Me.sstCadastros.TabPages.Item(1).Enabled = False
				Me.sstCadastros.TabPages.Item(2).Enabled = False
			End If
		Else
			Me.sstCadastros.TabPages.Item(1).Enabled = False
			Me.sstCadastros.TabPages.Item(2).Enabled = False
		End If
	End Sub
	
	Private Sub validaCamposUnidade()
		Me.cmdSalvar.Enabled = Me.cmbClasse.SelectedIndex <> -1 And Me.cmbTarifa.SelectedIndex <> -1 And Me.cmbDiaVenc.SelectedIndex <> -1
		Me.cmdCargaInstalada.Enabled = glngUnid_id > 0
		Me.txtCargaU.ReadOnly = Not glngUnid_id > 0
	End Sub
	
	'Versão: 001 Desenvolvedor: Ricardo Inacio Data: 08/04/2008 Descrição: Função que retorna se existe ou não a zona livro e conta informada
	Private Function ChecaZonaLivroConta(ByVal astrZona As String, ByVal astrLivro As String, ByVal astrConta As String, ByVal alngUnidId As Integer) As Boolean
		Dim lstrSql As String
		Dim lrstUnidade As ADODB.Recordset
		lrstUnidade = New ADODB.Recordset
		If Len(Trim(astrZona)) > 0 And Len(Trim(astrLivro)) > 0 And Len(Trim(astrConta)) > 0 Then
			lstrSql = ""
			lstrSql = lstrSql & "SELECT `uc`.`zona`, `uc`.`livro`, `uc`.`conta` "
			lstrSql = lstrSql & "  FROM `unid" & LCase(istrGrupo) & "` AS `uc` "
			lstrSql = lstrSql & " WHERE `uc`.`zona`  = """ & astrZona & """ "
			lstrSql = lstrSql & "   AND `uc`.`livro` = """ & astrLivro & """ "
			lstrSql = lstrSql & "   AND `uc`.`conta` = """ & astrConta & """ "
			If alngUnidId > 0 Then
				lstrSql = lstrSql & " AND `uc`.`unid_id` = " & alngUnidId
			End If
			Call Conectar(lstrSql, lrstUnidade)
			With lrstUnidade
				ChecaZonaLivroConta = .RecordCount > 0
				If .State = 1 Then Call .Close()
			End With
		Else
			ChecaZonaLivroConta = False
		End If
		'UPGRADE_NOTE: Object lrstUnidade may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstUnidade = Nothing
	End Function
	
	Private Sub ImprimeTermoLigacao(ByVal alngUnidId As Integer)
		Dim lstrCriterio As String
		lstrCriterio = "{unidb.unid_id} = " & alngUnidId
		' ----- Chama o Report de Termo de nova ligação
		With Me.crpTermo
			.ReportFileName = My.Application.Info.DirectoryPath & "\" & LeConfig("DIR_RPT") & LeConfig("TERMO_LIGACAO")
			.DiscardSavedData = True
			.WindowState = Crystal.WindowStateConstants.crptMaximized
			.WindowControlBox = True
			.WindowControls = True
			.SelectionFormula = lstrCriterio
			.WindowShowPrintSetupBtn = True
			.WindowShowCloseBtn = True
			.WindowShowSearchBtn = True
			.WindowTitle = "Termo de Fornecimento de Energia Elétrica"
			.Destination = Crystal.DestinationConstants.crptToWindow
			.Action = 0
		End With
	End Sub
	
	Private Sub ImprimeSolicitacao(ByVal alngConsId As Integer, ByVal alngUnidId As Integer, ByVal astrProtocolo As String)
		'Consumidor e UC
		Dim lstrZona As String
		Dim lstrLivro As String
		Dim lstrConta As String
		Dim lstrNome As String
		Dim lstrClasse As String
		Dim lstrNmClasse As String
		Dim lstrSubclasse As String
		Dim lstrGrTar As String
		Dim lstrFase As String
		Dim lstrDiaVenc As String
		Dim lstrTensao As String
		Dim lstrDisjuntor As String
		Dim lstrArea As String
		Dim lstrNascto As String
		Dim lstrCip As String
		Dim ldblCarga As Double
		Dim lstrTelefone As String
		Dim lstrDDDTel As String
		Dim lstrCelular As String
		Dim lstrDDDCel As String
		Dim lstrCpfCnpj As String
		Dim lstrRg As String
		Dim lstrInsc As String
		Dim lstrNmPai As String
		Dim lstrNmMae As String
		Dim lstrEndUc As String
		Dim lstrNumUc As String
		Dim lstrComUc As String
		Dim lstrBaiUc As String
		Dim lstrCidUc As String
		Dim lstrCepUc As String
		Dim lstrUfUc As String
		Dim lstrDisUc As String
		Dim lstrQuaUc As String
		Dim lstrLotUc As String
		Dim lstrEndEnt As String
		Dim lstrNumEnt As String
		Dim lstrComEnt As String
		Dim lstrBaiEnt As String
		Dim lstrCidEnt As String
		Dim lstrCepEnt As String
		Dim lstrUfEnt As String
		Dim lstrDisEnt As String
		Dim lstrMedidor As String
		Dim llngMedidor As Integer
		Dim lstrTrafo As String
		'OS
		Dim ldteSolicit As Date
		Dim ldteHoraSol As Date
		Dim lstrTpServico As String
		Dim lstrAtendente As String
		Dim lstrNmSolicit As String
		Dim lstrDocSolic As String
		Dim lstrSitSolic As String
		Dim llngSequencia As Integer
		'Regras de ICMS
		Dim ldblAliq1 As Double
		Dim ldblAliq2 As Double
		Dim ldblLimResid As Double
		Dim ldblLimRural As Double
		Dim lstrRegrasIcm As String
		'Carga
		Dim lstrLinCarga As String
		'Consultas
		Dim lstrSql As String
		Dim lstrCriterio As String
		Dim lrstConsum As ADODB.Recordset
		Dim lrstUnidade As ADODB.Recordset
		Dim lrstSolServ As ADODB.Recordset
		
		lrstConsum = New ADODB.Recordset
		lrstUnidade = New ADODB.Recordset
		lrstSolServ = New ADODB.Recordset
		
		ldblLimResid = CDbl(LeConfig("LIMITE_RESIDENCIAL"))
		ldblLimRural = CDbl(LeConfig("LIMITE_RURAL"))
		
		lstrSql = "SELECT * " & "  FROM consum " & " WHERE consreg = " & alngConsId & " " & " LIMIT 1 "
		Call Conectar(lstrSql, lrstConsum)
		If lrstConsum.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"'
			lstrDDDTel = IIf(IsDbNull(lrstConsum.Fields("dddtel").value), "", lrstConsum.Fields("dddtel").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"'
			lstrTelefone = IIf(IsDbNull(lrstConsum.Fields("telefone").value), "", lrstConsum.Fields("telefone").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"'
			lstrDDDCel = IIf(IsDbNull(lrstConsum.Fields("dddcel").value), "", lrstConsum.Fields("dddcel").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"'
			lstrCelular = IIf(IsDbNull(lrstConsum.Fields("cel").value), "", lrstConsum.Fields("cel").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"'
			lstrNascto = IIf(IsDbNull(lrstConsum.Fields("dt_nascto").value), "", lrstConsum.Fields("dt_nascto").value)
			lstrSql = "SELECT * " & "  FROM unid" & LCase(istrGrupo) & " WHERE cons_id = " & alngConsId & " " & "   AND unid_id = " & alngUnidId & " " & " LIMIT 1 "
			Call Conectar(lstrSql, lrstUnidade)
			If lrstUnidade.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"'
				lstrZona = IIf(IsDbNull(lrstUnidade.Fields("zona").value), "000", lrstUnidade.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"'
				lstrLivro = IIf(IsDbNull(lrstUnidade.Fields("livro").value), "00", lrstUnidade.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"'
				lstrConta = IIf(IsDbNull(lrstUnidade.Fields("conta").value), "000000", lrstUnidade.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"'
				lstrNome = IIf(IsDbNull(lrstUnidade.Fields("nome").value), "", lrstUnidade.Fields("nome").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"'
				lstrEndUc = IIf(IsDbNull(lrstUnidade.Fields("end").value), "", lrstUnidade.Fields("end").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"'
				lstrNumUc = IIf(IsDbNull(lrstUnidade.Fields("numero").value), "", lrstUnidade.Fields("numero").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"'
				lstrComUc = IIf(IsDbNull(lrstUnidade.Fields("complement").value), "", lrstUnidade.Fields("complement").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"'
				lstrBaiUc = IIf(IsDbNull(lrstUnidade.Fields("bairro").value), "", lrstUnidade.Fields("bairro").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"'
				lstrCidUc = IIf(IsDbNull(lrstUnidade.Fields("cidade").value), "", lrstUnidade.Fields("cidade").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"'
				lstrCepUc = IIf(IsDbNull(lrstUnidade.Fields("cep").value), "", lrstUnidade.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"'
				lstrUfUc = IIf(IsDbNull(lrstUnidade.Fields("uf").value), "", lrstUnidade.Fields("uf").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"'
				lstrDisUc = IIf(IsDbNull(lrstUnidade.Fields("distrito").value), "", lrstUnidade.Fields("distrito").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"'
				lstrQuaUc = IIf(IsDbNull(lrstUnidade.Fields("quadra").value), "", lrstUnidade.Fields("quadra").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"'
				lstrLotUc = IIf(IsDbNull(lrstUnidade.Fields("lote").value), "", lrstUnidade.Fields("lote").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"'
				lstrEndEnt = IIf(IsDbNull(lrstUnidade.Fields("end_entrega").value), "", lrstUnidade.Fields("end_entrega").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"'
				lstrNumEnt = IIf(IsDbNull(lrstUnidade.Fields("num_entrega").value), "", lrstUnidade.Fields("num_entrega").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"'
				lstrComEnt = IIf(IsDbNull(lrstUnidade.Fields("compl_entrega").value), "", lrstUnidade.Fields("compl_entrega").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"'
				lstrBaiEnt = IIf(IsDbNull(lrstUnidade.Fields("bai_entrega").value), "", lrstUnidade.Fields("bai_entrega").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"'
				lstrCidEnt = IIf(IsDbNull(lrstUnidade.Fields("cid_entrega").value), "", lrstUnidade.Fields("cid_entrega").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"'
				lstrCepEnt = IIf(IsDbNull(lrstUnidade.Fields("cep_entrega").value), "", lrstUnidade.Fields("cep_entrega").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"'
				lstrUfEnt = IIf(IsDbNull(lrstUnidade.Fields("uf_entrega").value), "", lrstUnidade.Fields("uf_entrega").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"'
				lstrDisEnt = IIf(IsDbNull(lrstUnidade.Fields("dis_entrega").value), "", lrstUnidade.Fields("dis_entrega").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"'
				lstrCpfCnpj = IIf(IsDbNull(lrstConsum.Fields("cgc").value), "", lrstConsum.Fields("cgc").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"'
				lstrRg = IIf(IsDbNull(lrstConsum.Fields("rg").value), "", lrstConsum.Fields("rg").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"'
				lstrInsc = IIf(IsDbNull(lrstConsum.Fields("insc").value), "", lrstConsum.Fields("insc").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"'
				lstrNmPai = IIf(IsDbNull(lrstConsum.Fields("nomepai").value), "", lrstConsum.Fields("nomepai").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"'
				lstrNmMae = IIf(IsDbNull(lrstConsum.Fields("nomemae").value), "", lrstConsum.Fields("nomemae").value)
				If istrGrupo = "B" 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"'
					lstrMedidor = IIf(IsDbNull(lrstUnidade.Fields("num").value), "", lrstUnidade.Fields("num").value)
				Else
					'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"'
					lstrMedidor = IIf(IsDbNull(lrstUnidade.Fields("eletr").value), "", lrstUnidade.Fields("eletr").value)
				End If
				'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"'
				llngMedidor = CInt(IIf(IsDbNull(lrstUnidade.Fields("idmedidor").value), 0, lrstUnidade.Fields("idmedidor").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"'
				lstrTrafo = IIf(IsDbNull(lrstUnidade.Fields("instal").value), "0000", lrstUnidade.Fields("instal").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"'
				lstrClasse = IIf(IsDbNull(lrstUnidade.Fields("clas").value), "0000", lrstUnidade.Fields("clas").value)
				ldblAliq2 = MdCalculosGrupoB.Aliquota_ICMS(gstrEmpresa_UF, 9999999, lstrClasse, gDtBcoDados)
				Select Case VB.Left(lstrClasse, 1)
					Case Is < CStr(4)
						lstrNmClasse = "INDUSTRIAL"
						lstrRegrasIcm = "Industrial " & ldblAliq2 & "%"
					Case Is = CStr(4)
						lstrNmClasse = "COMERCIAL"
						lstrRegrasIcm = "Comercial " & ldblAliq2 & "%"
					Case Is = CStr(5)
						lstrNmClasse = "RURAL"
						ldblAliq1 = MdCalculosGrupoB.Aliquota_ICMS(gstrEmpresa_UF, ldblLimRural, lstrClasse, gDtBcoDados)
						lstrRegrasIcm = "Rural até " & ldblLimRural & " kWh: " & ldblAliq1 & "%, Acima : " & ldblAliq2 & "%."
					Case Is = CStr(6)
						If CDbl(VB.Left(lstrClasse, 2)) = 61 Then
							lstrNmClasse = "PODER PÚBLICO MUNICIPAL"
							lstrRegrasIcm = "Poder Publico Municipal: " & ldblAliq2 & "%"
						ElseIf CDbl(VB.Left(lstrClasse, 2)) = 62 Then 
							lstrNmClasse = "PODER PÚBLICO ESTADUAL"
							lstrRegrasIcm = "Poder Publico Estdual: Isento "
						ElseIf CDbl(VB.Left(lstrClasse, 2)) = 63 Then 
							lstrNmClasse = "PODER PÚBLICO FEDERAL"
							lstrRegrasIcm = "Poder Publico Federal: " & ldblAliq2 & "%"
						ElseIf CDbl(VB.Left(lstrClasse, 2)) = 64 Then 
							lstrNmClasse = "ILUMINAÇÃO PÚBLICA"
							lstrRegrasIcm = "Iluminação  " & ldblAliq2 & "%"
						End If
					Case Is = CStr(7)
						lstrNmClasse = "SERVIÇO PÚBLICO"
						lstrRegrasIcm = "Serviço Publico " & ldblAliq2 & "%"
					Case Is = CStr(8)
						lstrNmClasse = "CONSUMO PRÓPRIO"
						lstrRegrasIcm = "Consumo Próprio " & ldblAliq2 & "%"
					Case Is = CStr(9)
						lstrNmClasse = "RESIDENCIAL"
						ldblAliq1 = MdCalculosGrupoB.Aliquota_ICMS(gstrEmpresa_UF, ldblLimResid, lstrClasse, gDtBcoDados)
						lstrRegrasIcm = "Residencial até " & ldblLimResid & " kWh: " & ldblAliq1 & "%, Acima : " & ldblAliq2 & "%."
				End Select
				lstrSubclasse = BuscaClasse(lstrClasse)
				'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"'
				lstrGrTar = Mid(IIf(IsDbNull(lrstUnidade.Fields("ta").value), "01B1", lrstUnidade.Fields("ta").value), 3, 2)
				'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"'
				lstrFase = IIf(IsDbNull(lrstUnidade.Fields("fase").value), "M", lrstUnidade.Fields("fase").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"'
				lstrDiaVenc = VB6.Format(IIf(IsDbNull(lrstUnidade.Fields("diavenc").value), "0", lrstUnidade.Fields("diavenc").value), "00")
				'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"'
				lstrTensao = IIf(IsDbNull(lrstUnidade.Fields("tensao").value), "", lrstUnidade.Fields("tensao").value)
				If istrGrupo = "B" 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"'
					lstrDisjuntor = IIf(IsDbNull(lrstUnidade.Fields("disjuntor").value), "", lrstUnidade.Fields("disjuntor").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"'
					lstrArea = IIf(IsDbNull(lrstUnidade.Fields("area").value), "", lrstUnidade.Fields("area").value)
				Else
					lstrDisjuntor = ""
					lstrArea = ""
				End If
				'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"'
				lstrCip = IIf(IsDbNull(lrstUnidade.Fields("ilum").value), "N", lrstUnidade.Fields("ilum").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"'
				ldblCarga = IIf(IsDbNull(lrstUnidade.Fields("carga").value), 0, lrstUnidade.Fields("carga").value)
				lstrSql = "SELECT * " & "  FROM solserv " & " WHERE protocolo = """ & astrProtocolo & """ " & " LIMIT 1 "
				Call Conectar(lstrSql, lrstSolServ)
				If lrstSolServ.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"'
					llngSequencia = IIf(IsDbNull(lrstSolServ.Fields("cod").value), 0, lrstSolServ.Fields("cod").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"'
					ldteSolicit = IIf(IsDbNull(lrstSolServ.Fields("data_soli").value), "", lrstSolServ.Fields("data_soli").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"'
					ldteHoraSol = IIf(IsDbNull(lrstSolServ.Fields("hora_soli").value), "", lrstSolServ.Fields("hora_soli").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"'
					lstrTpServico = IIf(IsDbNull(lrstSolServ.Fields("descr_serv").value), "", lrstSolServ.Fields("descr_serv").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"'
					lstrAtendente = IIf(IsDbNull(lrstSolServ.Fields("atendente").value), "", lrstSolServ.Fields("atendente").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"'
					lstrNmSolicit = IIf(IsDbNull(lrstSolServ.Fields("nomesol").value), "", lrstSolServ.Fields("nomesol").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"'
					lstrDocSolic = IIf(IsDbNull(lrstSolServ.Fields("docsol").value), "", lrstSolServ.Fields("docsol").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"'
					lstrSitSolic = IIf(IsDbNull(lrstSolServ.Fields("sit").value), "A", lrstSolServ.Fields("sit").value)
					lstrLinCarga = MontaCarga(alngUnidId)
					lstrSql = "DELETE FROM temp_ligacao WHERE nm_usuario     = """ & gstrNmEstacao & """ "
					Call Executar(lstrSql)
					lstrSql = ""
					lstrSql = lstrSql & "INSERT INTO temp_ligacao "
					lstrSql = lstrSql & "        SET nm_usuario     = """ & gstrNmEstacao & """, "
					lstrSql = lstrSql & "            zona           = """ & lstrZona & """, "
					lstrSql = lstrSql & "            livro          = """ & lstrLivro & """, "
					lstrSql = lstrSql & "            conta          = """ & lstrConta & """, "
					lstrSql = lstrSql & "            unid_id        = """ & alngUnidId & """, "
					lstrSql = lstrSql & "            nome           = """ & lstrNome & """, "
					lstrSql = lstrSql & "            endereco       = """ & lstrEndUc & """, "
					lstrSql = lstrSql & "            numero         = """ & lstrNumUc & """, "
					lstrSql = lstrSql & "            complem        = """ & lstrComUc & ""","
					lstrSql = lstrSql & "            bairro         = """ & lstrBaiUc & """, "
					lstrSql = lstrSql & "            cidade         = """ & lstrCidUc & """, "
					lstrSql = lstrSql & "            cep            = """ & lstrCepUc & """, "
					lstrSql = lstrSql & "            telefone       = """ & lstrDDDTel & "-" & lstrTelefone & "     " & lstrDDDCel & "-" & lstrCelular & """, "
					lstrSql = lstrSql & "            cpf            = """ & lstrCpfCnpj & ""","
					lstrSql = lstrSql & "            ie             = """ & IIf(Len(lstrCpfCnpj) = 14, lstrInsc, lstrRg) & """, "
					lstrSql = lstrSql & "            filiacao       = """ & lstrNmPai & " - " & lstrNmMae & """, "
					lstrSql = lstrSql & "            datanasc       = """ & VB6.Format(IIf(Len(lstrNascto) > 0, lstrNascto, "0000-00-00"), "yyyy-MM-dd") & """, "
					lstrSql = lstrSql & "            classe         = """ & lstrNmClasse & """, "
					lstrSql = lstrSql & "            subclasse      = """ & lstrSubclasse & """, "
					lstrSql = lstrSql & "            ta             = """ & lstrGrTar & """, "
					lstrSql = lstrSql & "            fase           = """ & lstrFase & """, "
					lstrSql = lstrSql & "            tensao         = """ & lstrTensao & """, "
					lstrSql = lstrSql & "            diavenc        = """ & lstrDiaVenc & """, "
					lstrSql = lstrSql & "            disjuntor      = """ & lstrDisjuntor & """, "
					lstrSql = lstrSql & "            area           = """ & lstrArea & """, "
					lstrSql = lstrSql & "            aliqicms       = """ & lstrRegrasIcm & """, "
					lstrSql = lstrSql & "            ilumpublica    = """ & IIf(lstrCip = "N", "NORMAL", "NÃO COBRAR ") & """, "
					lstrSql = lstrSql & "            nrnis          = """ & " " & """, "
					lstrSql = lstrSql & "            equip_instalado = """ & lstrLinCarga & """, "
					lstrSql = lstrSql & "            carga           = """ & Replace(CStr(ldblCarga), ",", ".") & """, "
					lstrSql = lstrSql & "            endent         = """ & lstrEndEnt & """, "
					lstrSql = lstrSql & "            nrent          = """ & lstrNumEnt & """, "
					lstrSql = lstrSql & "            bairroent      = """ & lstrBaiEnt & """, "
					lstrSql = lstrSql & "            cidadeent      = """ & lstrCidEnt & """, "
					lstrSql = lstrSql & "            cepent         = """ & lstrCepEnt & """, "
					lstrSql = lstrSql & "            complement     = """ & lstrComEnt & ""","
					lstrSql = lstrSql & "            seq            = """ & llngSequencia & """, "
					lstrSql = lstrSql & "            protocolo      = """ & astrProtocolo & """, "
					lstrSql = lstrSql & "            data_soli      = """ & VB6.Format(ldteSolicit, "yyyy-MM-dd") & """, "
					lstrSql = lstrSql & "            horapedido     = """ & VB6.Format(ldteHoraSol, "HH:MM:SS") & """, "
					lstrSql = lstrSql & "            servsol        = """ & lstrTpServico & """, "
					lstrSql = lstrSql & "            descr_serv     = """ & "---" & """, "
					lstrSql = lstrSql & "            nome_soli      = """ & IIf(Len(lstrNmSolicit) > 0, lstrNmSolicit, lstrNome) & """, "
					lstrSql = lstrSql & "            rg_soli        = """ & IIf(Len(lstrNmSolicit) > 0, " ", lstrDocSolic) & """, "
					lstrSql = lstrSql & "            situacao       = """ & lstrSitSolic & """, "
					lstrSql = lstrSql & "            medidor       = """ & lstrMedidor & """, "
					lstrSql = lstrSql & "            instal        = """ & lstrTrafo & """, "
					lstrSql = lstrSql & "            idmedidor     = """ & llngMedidor & """, "
					lstrSql = lstrSql & "            atendente      = """ & gstrUsuario_Nome & """ "
					Call Executar(lstrSql)
				End If
				If lrstSolServ.State = 1 Then lrstSolServ.Close()
			End If
			If lrstUnidade.State = 1 Then lrstUnidade.Close()
		End If
		If lrstConsum.State = 1 Then lrstConsum.Close()
		' ----- Chama o report de movimentaçao de cadastro
		lstrCriterio = "{temp_ligacao.nm_usuario} = """ & gstrNmEstacao & """"
		With Me.crpMovimento
			.ReportFileName = My.Application.Info.DirectoryPath & "\" & LeConfig("DIR_RPT") & LeConfig("MOVIMENTACAO_CAD")
			.DiscardSavedData = True
			.WindowState = Crystal.WindowStateConstants.crptMaximized
			.WindowControlBox = True
			.WindowControls = True
			.SelectionFormula = lstrCriterio
			.WindowShowPrintSetupBtn = True
			.WindowShowCloseBtn = True
			.WindowShowSearchBtn = True
			.WindowTitle = "Movimentação de cadastro"
			.Destination = Crystal.DestinationConstants.crptToWindow
			.Action = 0
		End With
		' ----- Chama o report de movimentaçao de cadastro
		lstrCriterio = "{temp_ligacao.nm_usuario} = """ & gstrNmEstacao & """"
		With Me.crpCarga
			.ReportFileName = My.Application.Info.DirectoryPath & "\" & LeConfig("DIR_RPT") & LeConfig("MOVIMENTACAO_CAD_CARGA")
			.DiscardSavedData = True
			.WindowState = Crystal.WindowStateConstants.crptMaximized
			.WindowControlBox = True
			.WindowControls = True
			.SelectionFormula = lstrCriterio
			.WindowShowPrintSetupBtn = True
			.WindowShowCloseBtn = True
			.WindowShowSearchBtn = True
			.WindowTitle = "Carga Instalada"
			.Destination = Crystal.DestinationConstants.crptToWindow
			.Action = 0
		End With
		With Me.crpCroqui
			.ReportFileName = My.Application.Info.DirectoryPath & "\" & LeConfig("DIR_RPT") & LeConfig("FICHA_MEDIDOR")
			.DiscardSavedData = True
			.WindowState = Crystal.WindowStateConstants.crptMaximized
			.WindowControlBox = True
			.WindowControls = True
			.SelectionFormula = "{solserv.protocolo} = """ & astrProtocolo & """ AND {solserv.cod} = " & llngSequencia & " "
			.WindowShowPrintSetupBtn = True
			.WindowShowCloseBtn = True
			.WindowShowSearchBtn = True
			.WindowTitle = "Dados do Medidor"
			.Destination = Crystal.DestinationConstants.crptToWindow
			.Action = 0
		End With
		
		'UPGRADE_NOTE: Object lrstSolServ may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstSolServ = Nothing
		'UPGRADE_NOTE: Object lrstUnidade may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstUnidade = Nothing
		'UPGRADE_NOTE: Object lrstConsum may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstConsum = Nothing
	End Sub
	
	Private Sub LimpaCampos(ByRef afmeBastidor As System.Windows.Forms.GroupBox)
		Dim lintCampos As Short
		
		With afmeBastidor
			'UPGRADE_WARNING: Control property afmeBastidor.Parent was upgraded to afmeBastidor.FindForm which has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="DFCDE711-9694-47D7-9C50-45A99CD8E91E"'
			'UPGRADE_WARNING: Controls method Parent.Controls.Count has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'
			For lintCampos = 0 To .FindForm.Controls.Count() - 1
				'UPGRADE_WARNING: Control property afmeBastidor.Parent was upgraded to afmeBastidor.FindForm which has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="DFCDE711-9694-47D7-9C50-45A99CD8E91E"'
				'UPGRADE_WARNING: TypeOf has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
				If TypeOf CType(.FindForm.Controls(lintCampos), Object) Is System.Windows.Forms.TextBox Then
					'UPGRADE_WARNING: Control property afmeBastidor.Parent was upgraded to afmeBastidor.FindForm which has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="DFCDE711-9694-47D7-9C50-45A99CD8E91E"'
					CType(.FindForm.Controls(lintCampos), Object).Text = ""
					'UPGRADE_WARNING: Control property afmeBastidor.Parent was upgraded to afmeBastidor.FindForm which has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="DFCDE711-9694-47D7-9C50-45A99CD8E91E"'
					'UPGRADE_WARNING: TypeOf has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
				ElseIf TypeOf CType(.FindForm.Controls(lintCampos), Object) Is System.Windows.Forms.CheckBox Then 
					'UPGRADE_WARNING: Control property afmeBastidor.Parent was upgraded to afmeBastidor.FindForm which has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="DFCDE711-9694-47D7-9C50-45A99CD8E91E"'
					'UPGRADE_WARNING: Couldn't resolve default property of object afmeBastidor.Parent.Controls().value. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
					CType(.FindForm.Controls(lintCampos), Object).value = False
					'UPGRADE_WARNING: Control property afmeBastidor.Parent was upgraded to afmeBastidor.FindForm which has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="DFCDE711-9694-47D7-9C50-45A99CD8E91E"'
					'UPGRADE_WARNING: TypeOf has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
				ElseIf TypeOf CType(.FindForm.Controls(lintCampos), Object) Is System.Windows.Forms.ComboBox Then 
					'UPGRADE_WARNING: Control property afmeBastidor.Parent was upgraded to afmeBastidor.FindForm which has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="DFCDE711-9694-47D7-9C50-45A99CD8E91E"'
					'UPGRADE_WARNING: Couldn't resolve default property of object afmeBastidor.Parent.Controls().ListIndex. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
					CType(.FindForm.Controls(lintCampos), Object).ListIndex = -1
				End If
			Next lintCampos
		End With
		If afmeBastidor.Name = "fmeCons" Then
			Me.lblEndC.Text = ""
			Me.lblBairroC.Text = ""
			Me.lblMunicipioC.Text = ""
			Me.lblCepC.Text = ""
			Me.lblUfC.Text = ""
			Me.lblDistritoC.Text = ""
			istrEndCodC = ""
		ElseIf afmeBastidor.Name = "fmeUC" Then 
			Me.lblEndUc.Text = ""
			Me.lblBairroUc.Text = ""
			Me.lblMunicipioUc.Text = ""
			Me.lblCepUc.Text = ""
			Me.lblUfUc.Text = ""
			Me.lblDistritoUc.Text = ""
			istrEndCodUC = ""
		End If
	End Sub
	
	Private Function ControleTecla(ByRef aKeyAscii As Short, ByRef astrTipo As String) As Object
		If astrTipo = "N" Then
			If aKeyAscii = System.Windows.Forms.Keys.Return Then
				Call SendKeysA(System.Windows.Forms.Keys.Tab, True)
			ElseIf aKeyAscii <> 8 And (aKeyAscii <> 44 And (aKeyAscii < 48 Or aKeyAscii > 57)) Then 
				aKeyAscii = 0
			End If
		ElseIf astrTipo = "A" Then 
			If aKeyAscii = System.Windows.Forms.Keys.Return Then
				Call SendKeysA(System.Windows.Forms.Keys.Tab, True)
			End If
		End If
	End Function
	
	Private Function SelTodoCampo(ByRef aObjeto As System.Windows.Forms.TextBox, ByRef abTira As Boolean) As Object
		With aObjeto
			.Text = Trim(IIf(abTira = True, Str_Retira(.Text, ".-/"), .Text))
			.SelectionStart = 0
			.SelectionLength = Len(.Text)
		End With
	End Function
	
	Private Sub txtZona_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtZona.Leave
		With Me.txtZona
			.Text = VB6.Format(.Text, "000")
			If Len(Trim(.Text)) = 0 Or Trim(.Text) = "000" Then
				.Text = "999"
			End If
		End With
	End Sub
	
	Private Function BuscaClasse(ByVal astrCdClasse As String) As String
		Dim lstrSql As String
		Dim lstrCdClasse As String
		Dim lstrNmClasse As String
		Dim lrstClasse As ADODB.Recordset
		
		lrstClasse = New ADODB.Recordset
		lstrCdClasse = VB6.Format(astrCdClasse, "0000")
		lstrNmClasse = ""
		lstrSql = "SELECT * " & "  FROM classe " & " WHERE codigo = """ & lstrCdClasse & """ "
		Call Conectar(lstrSql, lrstClasse)
		If lrstClasse.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"'
			lstrNmClasse = IIf(IsDbNull(lrstClasse.Fields("descricao").value), "", lrstClasse.Fields("descricao").value)
		End If
		BuscaClasse = lstrNmClasse
		If lrstClasse.State = 1 Then Call lrstClasse.Close()
		'UPGRADE_NOTE: Object lrstClasse may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstClasse = Nothing
	End Function
	
	Private Function MontaCarga(ByVal alngUnidId As Integer) As String
		Dim lstrSql As String
		Dim lintQtdeLinha As Short
		Dim llngCdEquip As Integer
		Dim lstrNmEquip As String
		Dim llngQtde As Integer
		Dim lstrQtde As String
		Dim ldblCarga As Double
		Dim lstrCarga As String
		Dim ldblCargaTot As Double
		Dim lstrCargaTot As String
		Dim lstrLinAux As String
		Dim lstrLinCarga As String
		Dim llngTamanho As Integer
		Dim lrstCarga As ADODB.Recordset
		Dim lrstEquip As ADODB.Recordset
		
		lrstCarga = New ADODB.Recordset
		lrstEquip = New ADODB.Recordset
		
		lintQtdeLinha = 0
		lstrLinCarga = ""
		'----- Dados da carga unidade consumidora  ----------------------------------------------------------------------
		lstrSql = "SELECT * " & "  FROM cargaunid  " & " WHERE  unid_id = " & alngUnidId & ""
		Call Conectar(lstrSql, lrstCarga)
		If lrstCarga.RecordCount > 0 Then
			While Not lrstCarga.EOF
				'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"'
				llngCdEquip = IIf(IsDbNull(lrstCarga.Fields("cod_equipamento").value), 0, lrstCarga.Fields("cod_equipamento").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"'
				llngQtde = IIf(IsDbNull(lrstCarga.Fields("qtd").value), 0, lrstCarga.Fields("qtd").value)
				lstrSql = "SELECT * " & "  FROM cargaequip " & " WHERE cod_equipamento = " & llngCdEquip & " " & " LIMIT 1 "
				Call Conectar(lstrSql, lrstEquip)
				ldblCargaTot = 0
				If lrstEquip.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"'
					lstrNmEquip = IIf(IsDbNull(lrstEquip.Fields("equipamento").value), "", lrstEquip.Fields("equipamento").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"'
					ldblCarga = IIf(IsDbNull(lrstEquip.Fields("carga").value), 0, lrstEquip.Fields("carga").value)
					ldblCargaTot = (ldblCarga * llngQtde)
					
					lstrCarga = Str(ldblCarga)
					lstrQtde = Str(llngQtde)
					lstrCargaTot = Str(ldblCargaTot)
					
					lstrNmEquip = PreparaCampo(lstrNmEquip, ALFANUMERICO, 24, " ")
					lstrCarga = PreparaCampo(lstrCarga, NUMERICO, 5, "0")
					lstrQtde = PreparaCampo(lstrQtde, NUMERICO, 3, "0")
					lstrCargaTot = PreparaCampo(lstrCargaTot, NUMERICO, 5, "0")
					
					lstrLinAux = lstrNmEquip & " " & lstrCarga & " " & lstrQtde & " " & lstrCargaTot & " "
					lintQtdeLinha = lintQtdeLinha + 1
				End If
				If lrstEquip.State = 1 Then Call lrstEquip.Close()
				If lintQtdeLinha = 3 Then
					lstrLinCarga = lstrLinCarga & lstrLinAux & Chr(10)
					lintQtdeLinha = 0
				Else
					lstrLinCarga = lstrLinCarga & lstrLinAux
				End If
				Call lrstCarga.MoveNext()
			End While
		End If
		If lrstCarga.State = 1 Then lrstCarga.Close()
		MontaCarga = lstrLinCarga
		'UPGRADE_NOTE: Object lrstCarga may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstCarga = Nothing
		'UPGRADE_NOTE: Object lrstEquip may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstEquip = Nothing
	End Function
	
	Private Sub LigDesGrupo()
		Me.fmeAgrupa(0).Enabled = (istrGrupo = "B")
		Me.fmeAgrupa(1).Enabled = (istrGrupo = "B")
	End Sub
	
	Public Sub SetaCnae(ByVal alngId As Integer, ByVal astrCd As String)
		Dim lstrDes As String
		Dim lstrCod As String
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		If alngId > 0 Or astrCd <> "" Then
			lstrSql = ""
			lstrSql = lstrSql & "SELECT * "
			lstrSql = lstrSql & "  FROM `cnae` "
			If alngId > 0 Then
				lstrSql = lstrSql & " WHERE `id` = " & alngId & " "
			Else
				lstrSql = lstrSql & " WHERE MID(`codigo`, 2) = '" & astrCd & "' "
			End If
			Call Conectar(lstrSql, lrstAux)
			With lrstAux
				If .State = ADODB.ObjectStateEnum.adStateOpen Then
					If .RecordCount > 0 Then
						If alngId = 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"'
							'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							alngId = CInt(IIf(IsDbNull(.Fields("id").value), "0", .Fields("id").value))
						End If
						'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"'
						'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
						lstrDes = Trim(IIf(IsDbNull(.Fields("descricao").value), "", .Fields("descricao").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"'
						'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
						lstrCod = Trim(IIf(IsDbNull(.Fields("codigo").value), "", .Fields("codigo").value))
						Me.txtIdCnae.Text = CStr(alngId)
						Me.txtCdCnae.Text = lstrCod
						Me.txtNmCnae.Text = lstrDes
					End If
					Call .Close()
				End If
			End With
		Else
			Me.txtNmCnae.Text = ""
		End If
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
	End Sub
End Class