Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Friend Class frmCadNis
	Inherits System.Windows.Forms.Form
	Private istrNis As String
	Private istrCodFamiliar As String
	Private idteValidade As Date
	Private idteNascimento As Date
	Private istrUFNaciment As String
	Private idteCadbf As Date
	Private idteCadastro As Date
	Private istrCodmunic As String
	Private istrNomeNis As String
	Private istrCpfNis As String
	Private istrRgNis As String
	Private istrBpc As String
	Private istrApS As String
	Private ifrmQuemChama As System.Windows.Forms.Form
	
	Private Sub frmCadNis_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
		Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
		If KeyAscii = System.Windows.Forms.Keys.Escape Then
			Call Me.Close()
		ElseIf KeyAscii = System.Windows.Forms.Keys.Return Then 
			Call SendKeysA(System.Windows.Forms.Keys.Tab, True)
		End If
		eventArgs.KeyChar = Chr(KeyAscii)
		If KeyAscii = 0 Then
			eventArgs.Handled = True
		End If
	End Sub
	
	Private Sub frmCadNis_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		Call CenterForm(Me)
		Me.dtpCadastro.value = CDate(VB6.Format(BuscaDataBD, "dd/mm/yyyy"))
		'UPGRADE_WARNING: Couldn't resolve default property of object Me.dtpCadastro.value. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
		Me.dtpNascimento.value = Me.dtpCadastro.value
		'UPGRADE_WARNING: Couldn't resolve default property of object Me.dtpCadastro.value. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
		Me.dtpCadbf.value = Me.dtpCadastro.value
	End Sub
	
	Private Sub frmCadNis_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
		ifrmQuemChama.Enabled = True
	End Sub
	
	Private Sub txtCodFamiliar_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtCodFamiliar.Enter
		With Me.txtCodFamiliar
			.SelectionStart = 0
			.SelectionLength = Len(.Text)
		End With
	End Sub
	
	Private Sub txtCodFamiliar_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtCodFamiliar.KeyPress
		Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
		If KeyAscii <> System.Windows.Forms.Keys.Back And (KeyAscii < System.Windows.Forms.Keys.D0 Or KeyAscii > System.Windows.Forms.Keys.D9) Then
			KeyAscii = 0
		End If
		eventArgs.KeyChar = Chr(KeyAscii)
		If KeyAscii = 0 Then
			eventArgs.Handled = True
		End If
	End Sub
	
	
	Private Sub txtCpfNis_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtCpfNis.KeyPress
		Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
		If KeyAscii <> System.Windows.Forms.Keys.Back And (KeyAscii < System.Windows.Forms.Keys.D0 Or KeyAscii > System.Windows.Forms.Keys.D9) Then
			KeyAscii = 0
		End If
		eventArgs.KeyChar = Chr(KeyAscii)
		If KeyAscii = 0 Then
			eventArgs.Handled = True
		End If
	End Sub
	
	Private Sub txtCpfNis_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtCpfNis.Leave
		Dim lstrMsgAux As String
		Me.txtCpfNis.Text = FormataCPF(Me.txtCpfNis.Text)
		If ValidaNisCpfNis(lstrMsgAux) Then
			Call MsgBox(lstrMsgAux & Chr(10) & " se você continuar este registro será desativado! ")
		End If
	End Sub
	
	Private Sub txtNIS_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtNIS.Enter
		With Me.txtNis
			.SelectionStart = 0
			.SelectionLength = Len(.Text)
		End With
	End Sub
	
	Private Sub txtNis_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtNis.KeyPress
		Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
		If KeyAscii <> System.Windows.Forms.Keys.Back And (KeyAscii < System.Windows.Forms.Keys.D0 Or KeyAscii > System.Windows.Forms.Keys.D9) Then
			KeyAscii = 0
		End If
		eventArgs.KeyChar = Chr(KeyAscii)
		If KeyAscii = 0 Then
			eventArgs.Handled = True
		End If
	End Sub
	
	Private Sub txtNis_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtNis.Leave
		If Trim(Me.txtNis.Text) <> "" Then
			Call BuscaNis()
		End If
	End Sub
	
	Private Sub txtNomeNis_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtNomeNis.Enter
		With Me.txtNomeNis
			.SelectionStart = 0
			.SelectionLength = Len(.Text)
		End With
	End Sub
	
	Private Sub txtCpfNis_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtCpfNis.Enter
		With Me.txtCpfNis
			.Text = Str_Retira(.Text, " /-.")
			.SelectionStart = 0
			.SelectionLength = Len(.Text)
		End With
	End Sub
	
	Private Sub txtNomeNis_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtNomeNis.Leave
		Me.txtNomeNis.Text = UCase(Trim(Me.txtNomeNis.Text))
	End Sub
	
	Private Sub txtRgNis_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtRgNis.Enter
		With Me.txtRgNis
			.SelectionStart = 0
			.SelectionLength = Len(.Text)
		End With
	End Sub
	
	Private Sub txtCodMunic_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtCodMunic.Enter
		With Me.txtCodMunic
			.SelectionStart = 0
			.SelectionLength = Len(.Text)
		End With
	End Sub
	
	Public Sub SetaNis(ByVal astrCpf As String, ByVal astrNome As String, ByVal astrNrRg As String, ByVal astrZona As String, ByVal astrLivro As String, ByVal astrConta As String, ByVal alngUnidId As Integer, ByVal afrmQuemChama As System.Windows.Forms.Form)
		Dim lstrTip As String
		Dim ldteAux As Date
		Dim lstrSql As String
		Dim lrstNis As ADODB.Recordset
		
		On Error GoTo ErroAbrir
		ifrmQuemChama = afrmQuemChama
		ifrmQuemChama.Enabled = False
		lrstNis = New ADODB.Recordset
		ldteAux = BuscaDataBD
		'Seta as propriedades da unidade consumidora que esta chamando a tela NIS
		Me.lblNomeConsumidor.Text = astrNome
		Me.lblNumCpf.Text = astrCpf
		Me.lblNumRg.Text = astrNrRg
		Me.lblZonaUC.Text = astrZona
		Me.lblLivroUC.Text = astrLivro
		Me.lblContaUC.Text = astrConta
		Me.lblUnidId.Text = CStr(alngUnidId)
		'Busca o nis da U.C.
		lstrTip = ""
		lstrSql = ""
		lstrSql = lstrSql & "SELECT `nis`.`id` "
		lstrSql = lstrSql & "  FROM `nis`"
		lstrSql = lstrSql & " WHERE `nis`.`cpf` = """ & Str_Retira(Me.lblNumCpf.Text, ".-/ ") & """ "
		lstrSql = lstrSql & "   AND `nis`.`unid_id` = " & CInt(Me.lblUnidId.Text)
		lstrSql = lstrSql & "   AND `nis`.`evento` = 'I' "
		lstrSql = lstrSql & " ORDER BY `id` DESC LIMIT 0, 1 "
		Call Conectar(lstrSql, lrstNis)
		With lrstNis
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				lstrTip = IIf(.RecordCount > 0, "I", "")
				Call .Close()
			End If
		End With
		If Trim(lstrTip) = "" Then
			lstrSql = ""
			lstrSql = lstrSql & "SELECT `nis`.`id` "
			lstrSql = lstrSql & "  FROM `nis`"
			lstrSql = lstrSql & " WHERE `nis`.`cpf` = """ & Str_Retira(Me.lblNumCpf.Text, ".-/ ") & """ "
			lstrSql = lstrSql & "   AND `nis`.`unid_id` = " & CInt(Me.lblUnidId.Text)
			lstrSql = lstrSql & "   AND `nis`.`evento` = 'A' "
			lstrSql = lstrSql & " ORDER BY `id` DESC LIMIT 0, 1 "
			Call Conectar(lstrSql, lrstNis)
			With lrstNis
				If .State = ADODB.ObjectStateEnum.adStateOpen Then
					lstrTip = IIf(.RecordCount > 0, "A", "")
					Call .Close()
				End If
			End With
		End If
		lstrSql = ""
		lstrSql = lstrSql & "SELECT "
		lstrSql = lstrSql & "       `nis`.`evento`,"
		lstrSql = lstrSql & "       `nis`.`nis`, "
		lstrSql = lstrSql & "       `nis`.`data_cadastro`, "
		lstrSql = lstrSql & "       `nis`.`data_alteracao`, "
		lstrSql = lstrSql & "       `nis`.`data_nascimento`, "
		lstrSql = lstrSql & "       `nis`.`uf_nascimento`, "
		lstrSql = lstrSql & "       `nis`.`dtcadbf`, "
		lstrSql = lstrSql & "       `nis`.`codmunic`, "
		lstrSql = lstrSql & "       `nis`.`zona`, "
		lstrSql = lstrSql & "       `nis`.`livro`, "
		lstrSql = lstrSql & "       `nis`.`conta`, "
		lstrSql = lstrSql & "       `nis`.`evento`, "
		lstrSql = lstrSql & "       `nis`.`nome_nis`, "
		lstrSql = lstrSql & "       `nis`.`cpf_nis`, "
		lstrSql = lstrSql & "       `nis`.`rg_nis`, "
		lstrSql = lstrSql & "       `nis`.`unid_id`, "
		lstrSql = lstrSql & "       `nis`.`validade`, "
		lstrSql = lstrSql & "       `nis`.`ap_saude`, "
		lstrSql = lstrSql & "       `nis`.`bpc`, "
		lstrSql = lstrSql & "       `nis`.`cod_familiar_fam` "
		lstrSql = lstrSql & "  FROM `nis` "
		lstrSql = lstrSql & " WHERE (`nis`.`cpf` = """ & Str_Retira(Me.lblNumCpf.Text, ".-/ ") & """ OR  `nis`.`cpf_nis` = """ & Str_Retira(Me.lblNumCpf.Text, ".-/ ") & """ )"
		lstrSql = lstrSql & "   AND `nis`.`unid_id` = " & CInt(Me.lblUnidId.Text)
		If Trim(lstrTip) <> "" Then
			lstrSql = lstrSql & "   AND `nis`.`evento` = '" & lstrTip & "' "
		End If
		Call Conectar(lstrSql, lrstNis)
		With lrstNis
			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"'
					istrNis = VB.Left(Replace(Trim(IIf(IsDbNull(.Fields("nis").value), "", .Fields("nis").value)), "-", ""), 11)
					Me.txtNis.Text = VB.Left(istrNis, 11)
					'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.txtCodFamiliar.Text = VB.Left(Trim(IIf(IsDbNull(.Fields("cod_familiar_fam").value), "", .Fields("cod_familiar_fam").value)), 11)
					'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.dtpNascimento.value = CDate(IIf(IsDbNull(.Fields("data_nascimento").value), "1900-01-01", .Fields("data_nascimento").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.dtpCadastro.value = CDate(IIf(IsDbNull(.Fields("data_cadastro").value), ldteAux, .Fields("data_cadastro").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.dtpAlteracao.value = CDate(IIf(IsDbNull(.Fields("data_alteracao").value), ldteAux, .Fields("data_alteracao").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.dtpCadbf.value = CDate(IIf(IsDbNull(.Fields("dtcadbf").value), "1900-01-01", .Fields("dtcadbf").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.txtCodMunic.Text = Trim(IIf(IsDbNull(.Fields("codmunic").value), "", .Fields("codmunic").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.lblZonaNis.Text = Trim(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"'
					Me.lblLivroNis.Text = Trim(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"'
					Me.lblContaNis.Text = Trim(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"'
					Me.lblCodEvento.Text = Trim(IIf(IsDbNull(.Fields("evento").value), "", .Fields("evento").value))
					Me.lblCodEvento.Text = IIf(Me.lblCodEvento.Text = "I", "Incluído", IIf(Me.lblCodEvento.Text = "A", "Alterado", "Desativado"))
					'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"'
					Call SetUf(UCase(Trim(IIf(IsDbNull(.Fields("uf_nascimento").value) Or .Fields("uf_nascimento").value = "", gstrEmpresa_UF, .Fields("uf_nascimento").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.txtNomeNis.Text = Trim(IIf(IsDbNull(.Fields("nome_nis").value), "", .Fields("nome_nis").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.txtCpfNis.Text = Trim(IIf(IsDbNull(.Fields("cpf_nis").value), "", .Fields("cpf_nis").value))
					Me.txtCpfNis.Text = FormataCPF(Me.txtCpfNis.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.txtRgNis.Text = Trim(IIf(IsDbNull(.Fields("rg_nis").value), "", .Fields("rg_nis").value))
					If gintUsuario_NivelCaixa <> 0 Then
						Me.dtpCadbf.Enabled = True
						Me.dtpCadastro.Enabled = True
						Me.dtpAlteracao.Enabled = True
					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.lblUnidIdNis.Text = CStr(CInt(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"'
					istrApS = IIf(IsDbNull(.Fields("ap_saude").value), "N", .Fields("ap_saude").value)
					Me.chkApSaude.CheckState = IIf(istrApS = "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"'
					istrBpc = IIf(IsDbNull(.Fields("bpc").value), "N", .Fields("bpc").value)
					Me.chkBPC.CheckState = IIf(istrBpc = "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.dtpValidade.value = CDate(IIf(IsDbNull(.Fields("validade").value), ldteAux, .Fields("validade").value))
					'UPGRADE_WARNING: Couldn't resolve default property of object Me.dtpValidade.value. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
					idteValidade = Me.dtpValidade.value
					'UPGRADE_WARNING: Couldn't resolve default property of object Me.dtpNascimento.value. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
					idteNascimento = Me.dtpNascimento.value
					istrUFNaciment = VB6.GetItemString(Me.cmbUf, Me.cmbUf.SelectedIndex)
					'UPGRADE_WARNING: Couldn't resolve default property of object Me.dtpCadbf.value. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
					idteCadbf = Me.dtpCadbf.value
					'UPGRADE_WARNING: Couldn't resolve default property of object Me.dtpCadastro.value. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
					idteCadastro = Me.dtpCadastro.value
					istrCodmunic = Me.txtCodMunic.Text
					istrNomeNis = Me.txtNomeNis.Text
					istrCpfNis = Me.txtCpfNis.Text
					istrRgNis = Me.txtRgNis.Text
					istrCodFamiliar = Me.txtCodFamiliar.Text
					Call PopulaGridHistorico()
				End If
				Call .Close()
			End If
		End With
ErroAbrir: 
		If Err.Number > 0 Then
			Call MsgBox(Err.Number & " - " & GetErrosVB(Err.Number, Err.Description), MsgBoxStyle.Exclamation, gstrTituloMensagem)
			Resume Next
		End If
		'UPGRADE_NOTE: Object lrstNis 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"'
		lrstNis = Nothing
		Call Me.txtNis.Focus()
	End Sub
	
	Private Sub cmdDesativar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdDesativar.Click
		Dim lstrSql As String
		
		On Error GoTo ErroDesativar
		If MsgBox("Deseja desativar as informações do NIS do " & UCase(Trim(Me.txtNomeNis.Text)) & "?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, gstrTituloMensagem) = MsgBoxResult.Yes Then
			Call DesativaNis(Me.lblNumCpf.Text)
			Call cmdFechar_Click(cmdFechar, New System.EventArgs())
		End If
ErroDesativar: 
		If Err.Number > 0 Then
			Call MsgBox(Err.Number & " - " & GetErrosVB(Err.Number, Err.Description), MsgBoxStyle.Exclamation, gstrTituloMensagem)
		End If
	End Sub
	
	Private Sub DesativaNis(ByVal astrCpf As String)
		Dim lstrSql As String
		lstrSql = ""
		lstrSql = lstrSql & "UPDATE `nis` "
		lstrSql = lstrSql & "   SET `evento`          = ""D"", "
		lstrSql = lstrSql & "       `data_alteracao`  = """ & VB6.Format(BuscaDataBD, "yyyy-MM-dd") & """, "
		lstrSql = lstrSql & "       `flgst`           = ""*"" "
		lstrSql = lstrSql & " WHERE `nis`.`cpf`     = """ & Str_Retira(astrCpf, " /.-") & """ "
		lstrSql = lstrSql & "   AND `nis`.`nis`     = """ & Trim(Me.txtNis.Text) & """ "
		lstrSql = lstrSql & "   AND `nis`.`evento` IN ('I','A') "
		Call Executar(lstrSql)
		Call MsgBox("N.I.S. desativado com sucesso!", MsgBoxStyle.Information, gstrTituloMensagem)
	End Sub
	
	Private Sub DesativaNisPeloCpf(ByVal astrCpf As String)
		Dim lstrSql As String
		lstrSql = ""
		lstrSql = lstrSql & "UPDATE `nis` "
		lstrSql = lstrSql & "   SET `evento`          = ""D"", "
		lstrSql = lstrSql & "       `data_alteracao`  = """ & VB6.Format(BuscaDataBD, "yyyy-MM-dd") & """, "
		lstrSql = lstrSql & "       `flgst`           = ""*"" "
		lstrSql = lstrSql & " WHERE `nis`.`cpf_nis`     = """ & Str_Retira(astrCpf, " /.-") & """ "
		lstrSql = lstrSql & "   AND `nis`.`evento` IN ('I','A') "
		Call Executar(lstrSql)
		Call MsgBox("N.I.S. desativado com sucesso!", MsgBoxStyle.Information, gstrTituloMensagem)
	End Sub
	
	Private Sub cmdReativar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdReativar.Click
		Dim lstrSql As String
		
		On Error GoTo ErroReativar
		If MsgBox("Deseja reativar as informações do NIS do consumidor " & UCase(Trim(Me.txtNomeNis.Text)) & "?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, gstrTituloMensagem) = MsgBoxResult.Yes Then
			lstrSql = ""
			lstrSql = lstrSql & "UPDATE `nis` "
			lstrSql = lstrSql & "   SET `evento`          = ""A"", "
			lstrSql = lstrSql & "       `data_alteracao`  = """ & VB6.Format(BuscaDataBD, "yyyy-MM-dd") & """, "
			lstrSql = lstrSql & "       `data_cadastro`  = """ & VB6.Format(Me.dtpCadastro.value, "yyyy-MM-dd") & """, "
			lstrSql = lstrSql & "       `flgst`           = ""*"" "
			lstrSql = lstrSql & " WHERE `nis`.`cpf`     = """ & Str_Retira(Me.lblNumCpf.Text, " /.-") & """ "
			lstrSql = lstrSql & "   AND `nis`.`nis`     = """ & Trim(Me.txtNis.Text) & """ "
			lstrSql = lstrSql & "   AND `nis`.`evento`  = 'D' "
			Call Executar(lstrSql)
			Call MsgBox("N.I.S. reativado com sucesso!", MsgBoxStyle.Information, gstrTituloMensagem)
			Call cmdFechar_Click(cmdFechar, New System.EventArgs())
		End If
ErroReativar: 
		If Err.Number > 0 Then
			Call MsgBox(Err.Number & " - " & GetErrosVB(Err.Number, Err.Description), MsgBoxStyle.Exclamation, gstrTituloMensagem)
		End If
	End Sub
	
	Private Sub cmdGravar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdGravar.Click
		Dim llngUnidId As Integer
		Dim lstrCpfAux As String
		'Dim lstrEvento As String
		Dim ldteAux As Date
		Dim lstrNisAux As String
		Dim lstrAuxMsg As String
		Dim lstrSql As String
		Dim lrstNis As ADODB.Recordset
		Dim lblnNovo As Boolean
		
		On Error GoTo ErroGravar
		lstrAuxMsg = ""
		lrstNis = New ADODB.Recordset
		lblnNovo = False
		lstrNisAux = VB6.Format(Trim(Me.txtNis.Text), "00000000000")
		ldteAux = BuscaDataBD
		If (CInt(IIf(IsNumeric(Me.lblUnidId.Text), Me.lblUnidId.Text, 0)) > 0 And CInt(IIf(IsNumeric(Me.lblUnidIdNis.Text), Me.lblUnidIdNis.Text, 0)) > 0) And (CInt(IIf(IsNumeric(Me.lblUnidId.Text), Me.lblUnidId.Text, 0)) <> CInt(IIf(IsNumeric(Me.lblUnidIdNis.Text), Me.lblUnidIdNis.Text, 0))) Then
			lblnNovo = False
		Else
			lstrSql = ""
			lstrSql = lstrSql & "SELECT * "
			lstrSql = lstrSql & "  FROM `nis` "
			lstrSql = lstrSql & " WHERE `nis`.`cpf` = """ & Str_Retira(Me.lblNumCpf.Text, ".-/ ") & """ "
			lstrSql = lstrSql & "   AND `nis`.`unid_id` = " & CInt(Me.lblUnidId.Text)
			lstrSql = lstrSql & "   AND `nis`.`nis` = '" & Me.txtNis.Text & "' "
			Call Conectar(lstrSql, lrstNis)
			With lrstNis
				If .State = ADODB.ObjectStateEnum.adStateOpen Then
					lblnNovo = (.RecordCount = 0)
					Call .Close()
				End If
			End With
		End If
		If MsgBox("Confirma a " & IIf(lblnNovo, "inclusão", "alteração") & " do cadastro do nis ", MsgBoxStyle.Question + MsgBoxStyle.YesNo, gstrTituloMensagem) = MsgBoxResult.Yes Then
			If lblnNovo = True Then
				If ValidaNisCpfNis(lstrAuxMsg) Then
					Call MsgBox(lstrAuxMsg & Chr(10) & " este registro será desativado! ", MsgBoxStyle.Exclamation, gstrTituloMensagem)
					Call DesativaNisPeloCpf(Me.txtCpfNis.Text)
				End If
				lstrAuxMsg = ""
				If ValidaNisCpf(lstrAuxMsg, lstrNisAux) Then
					Call MsgBox(lstrAuxMsg, MsgBoxStyle.Exclamation, gstrTituloMensagem)
					Call DesativaNis(lstrCpfAux)
				End If
				lstrSql = ""
				lstrSql = lstrSql & "INSERT INTO `nis` " & vbCrLf
				lstrSql = lstrSql & "        SET `cpf`             = """ & Str_Retira(Me.lblNumCpf.Text, ".-/ ") & """, " & vbCrLf
				lstrSql = lstrSql & "            `nis`             = """ & lstrNisAux & """, " & vbCrLf
				lstrSql = lstrSql & "            `cod_familiar_fam`= " & IIf(CDbl(Me.txtCodFamiliar.Text) > 0, Me.txtCodFamiliar.Text, "0") & ", " & vbCrLf
				lstrSql = lstrSql & "            `data_cadastro`   = """ & VB6.Format(ldteAux, "yyyy-MM-dd") & """, " & vbCrLf
				lstrSql = lstrSql & "            `data_alteracao`  = """ & VB6.Format(ldteAux, "yyyy-MM-dd") & """, " & vbCrLf
				lstrSql = lstrSql & "            `data_nascimento` = """ & VB6.Format(Me.dtpNascimento.value, "yyyy-MM-dd") & """, " & vbCrLf
				lstrSql = lstrSql & "            `validade`        = """ & VB6.Format(Me.dtpValidade.value, "yyyy-MM-dd") & """, " & vbCrLf
				lstrSql = lstrSql & "            `uf_nascimento`   = """ & VB6.GetItemString(Me.cmbUf, Me.cmbUf.SelectedIndex) & """, " & vbCrLf
				lstrSql = lstrSql & "            `evento`          = ""I"", " & vbCrLf
				lstrSql = lstrSql & "            `unid_id`         = " & CInt(Me.lblUnidId.Text) & ", " & vbCrLf
				lstrSql = lstrSql & "            `zona`            = """ & Me.lblZonaUC.Text & """, " & vbCrLf
				lstrSql = lstrSql & "            `livro`           = """ & Me.lblLivroUC.Text & """, " & vbCrLf
				lstrSql = lstrSql & "            `conta`           = """ & Me.lblContaUC.Text & """, " & vbCrLf
				lstrSql = lstrSql & "            `flgst`           = ""*"", " & vbCrLf
				lstrSql = lstrSql & "            `dtcadbf`         = """ & VB6.Format(Me.dtpCadbf.value, "yyyy-MM-dd") & """, " & vbCrLf
				lstrSql = lstrSql & "            `codmunic`        = """ & Trim(Me.txtCodMunic.Text) & """, " & vbCrLf
				lstrSql = lstrSql & "            `nome_nis`        = """ & Trim(Me.txtNomeNis.Text) & """, " & vbCrLf
				lstrSql = lstrSql & "            `cpf_nis`         = """ & Str_Retira(Trim(Me.txtCpfNis.Text), ".-/ ") & """, " & vbCrLf
				lstrSql = lstrSql & "            `rg_nis`          = """ & Trim(Me.txtRgNis.Text) & """, "
				lstrSql = lstrSql & "            `bpc`             = """ & IIf(Me.chkBPC.CheckState = 1, "S", "N") & """, "
				lstrSql = lstrSql & "            `ap_saude`        = """ & IIf(Me.chkApSaude.CheckState = 1, "S", "N") & """ "
				Call Executar(lstrSql)
				Call AtualizaHistoricoUnidade(CInt(Me.lblUnidId.Text), "B", "[" & VB6.Format(ldteAux, "dd/mm/yyyy") & "]: INCLUIDO NIS: " & lstrNisAux)
			Else
				If CInt(Me.lblUnidId.Text) <> CInt(Me.lblUnidIdNis.Text) Then
					If MsgBox("Deseja transferir o NIS para esta Unidade Consumidora " & Me.lblZonaUC.Text & "." & Me.lblLivroUC.Text & "." & Me.lblContaUC.Text & "?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, gstrTituloMensagem) = MsgBoxResult.Yes Then
						lstrSql = ""
						lstrSql = lstrSql & "UPDATE `nis` " & vbCrLf
						lstrSql = lstrSql & "   SET `unid_id`   = """ & Me.lblUnidId.Text & """, " & vbCrLf
						lstrSql = lstrSql & "       `cpf`      = """ & Str_Retira(Me.lblNumCpf.Text, ".-/ ") & """, " & vbCrLf
						lstrSql = lstrSql & "       `zona`      = """ & Me.lblZonaUC.Text & """, " & vbCrLf
						lstrSql = lstrSql & "       `livro`     = """ & Me.lblLivroUC.Text & """, " & vbCrLf
						lstrSql = lstrSql & "       `conta`     = """ & Me.lblContaUC.Text & """ " & vbCrLf
						lstrSql = lstrSql & " WHERE `nis`.`cpf_nis` = """ & Str_Retira(Me.txtCpfNis.Text, ".-/ ") & """ " & vbCrLf
						lstrSql = lstrSql & "   AND `nis`.`unid_id` = " & CInt(Me.lblUnidIdNis.Text)
						lstrSql = lstrSql & "   AND `nis`.`nis` = """ & lstrNisAux & """ " & vbCrLf
						Call Executar(lstrSql)
						Call AtualizaHistoricoUnidade(CInt(Me.lblUnidId.Text), "B", "[" & VB6.Format(ldteAux, "dd/mm/yyyy") & "]: TRANSF. NIS: " & lstrNisAux & " DE " & Me.lblZonaNis.Text & "." & Me.lblLivroNis.Text & "." & Me.lblContaNis.Text)
						Call AtualizaHistoricoUnidade(CInt(Me.lblUnidIdNis.Text), "B", "[" & VB6.Format(ldteAux, "dd/mm/yyyy") & "]: TRANSF. NIS: " & lstrNisAux & " PARA " & Me.lblZonaUC.Text & "." & Me.lblLivroUC.Text & "." & Me.lblContaUC.Text)
					End If
				End If
				If Trim(istrNis) <> Trim(lstrNisAux) Or idteNascimento <> Me.dtpNascimento.value Or istrUFNaciment <> VB6.GetItemString(Me.cmbUf, Me.cmbUf.SelectedIndex) Or idteCadbf <> Me.dtpCadbf.value Or istrCodmunic <> Me.txtCodMunic.Text Or istrNomeNis <> Me.txtNomeNis.Text Or istrCpfNis <> Me.txtCpfNis.Text Or istrRgNis <> Me.txtRgNis.Text Or istrBpc <> IIf(Me.chkBPC.CheckState = 1, "S", "N") Or istrApS <> IIf(Me.chkApSaude.CheckState = 1, "S", "N") Or idteValidade <> Me.dtpValidade.value Or idteCadastro <> Me.dtpCadastro.value Or istrCodFamiliar <> Me.txtCodFamiliar.Text Then
					lstrSql = ""
					lstrSql = lstrSql & "UPDATE `nis` " & vbCrLf
					lstrSql = lstrSql & "   SET `nis`             = """ & lstrNisAux & """, " & vbCrLf
					lstrSql = lstrSql & "       `cod_familiar_fam`= " & IIf(CDbl(Me.txtCodFamiliar.Text) > 0, Me.txtCodFamiliar.Text, "0") & ", " & vbCrLf
					lstrSql = lstrSql & "       `data_alteracao`  = """ & VB6.Format(ldteAux, "yyyy-MM-dd") & """, " & vbCrLf
					lstrSql = lstrSql & "       `data_nascimento` = """ & VB6.Format(Me.dtpNascimento.value, "yyyy-MM-dd") & """, " & vbCrLf
					lstrSql = lstrSql & "       `data_cadastro`   = """ & VB6.Format(Me.dtpCadastro.value, "yyyy-MM-dd") & """, " & vbCrLf
					lstrSql = lstrSql & "       `validade`        = """ & VB6.Format(Me.dtpValidade.value, "yyyy-MM-dd") & """, " & vbCrLf
					lstrSql = lstrSql & "       `uf_nascimento`   = """ & VB6.GetItemString(Me.cmbUf, Me.cmbUf.SelectedIndex) & """, " & vbCrLf
					lstrSql = lstrSql & "       `evento`          = ""A"", " & vbCrLf
					lstrSql = lstrSql & "       `flgst`           = ""*"", " & vbCrLf
					lstrSql = lstrSql & "       `dtcadbf`         = """ & VB6.Format(Me.dtpCadbf.value, "yyyy-MM-dd") & """, " & vbCrLf
					lstrSql = lstrSql & "       `codmunic`        = """ & Trim(Me.txtCodMunic.Text) & """, " & vbCrLf
					lstrSql = lstrSql & "       `nome_nis`        = """ & Trim(Me.txtNomeNis.Text) & """, " & vbCrLf
					lstrSql = lstrSql & "       `cpf_nis`         = """ & Str_Retira(Trim(Me.txtCpfNis.Text), ".-/ ") & """, " & vbCrLf
					lstrSql = lstrSql & "       `rg_nis`          = """ & Trim(Me.txtRgNis.Text) & """, " & vbCrLf
					lstrSql = lstrSql & "       `bpc`             = """ & IIf(Me.chkBPC.CheckState = 1, "S", "N") & """, "
					lstrSql = lstrSql & "       `ap_saude`        = """ & IIf(Me.chkApSaude.CheckState = 1, "S", "N") & """ "
					lstrSql = lstrSql & " WHERE `nis`.`cpf` = """ & Str_Retira(Me.lblNumCpf.Text, ".-/ ") & """ " & vbCrLf
					lstrSql = lstrSql & "   AND `nis`.`unid_id` = " & CInt(Me.lblUnidIdNis.Text)
					Call Executar(lstrSql)
					Call AtualizaHistoricoUnidade(CInt(Me.lblUnidIdNis.Text), "B", "[" & VB6.Format(ldteAux, "dd/mm/yyyy") & "]: ATUALIZADO NIS: " & lstrNisAux)
				End If
			End If
			Call MsgBox("Gravação concluída!", MsgBoxStyle.Information, gstrTituloMensagem)
			Call cmdFechar_Click(cmdFechar, New System.EventArgs())
		End If
ErroGravar: 
		If Err.Number > 0 Then
			Call MsgBox(Err.Number & " - " & GetErrosVB(Err.Number, Err.Description), MsgBoxStyle.Exclamation, gstrTituloMensagem)
		ElseIf myConC.Errors.Count > 0 Then 
			Call MsgBox("Código: " & myConC.Errors.Item(myConC.Errors.Count - 1).NativeError & vbCrLf & "Descrição:" & myConC.Errors.Item(myConC.Errors.Count - 1).Description)
		End If
		'UPGRADE_NOTE: Object lrstNis 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"'
		lrstNis = Nothing
	End Sub
	
	Private Sub cmdFechar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdFechar.Click
		Call Me.Close()
	End Sub
	
	Private Sub SetUf(ByVal astrUf As String)
		Dim llngIdx As Integer
		
		If Len(Trim(astrUf)) > 0 Then
			llngIdx = 0
			With Me.cmbUf
				While llngIdx < .Items.Count
					If VB6.GetItemString(Me.cmbUf, llngIdx) = astrUf Then
						.SelectedIndex = llngIdx
						llngIdx = .Items.Count
					End If
					llngIdx = llngIdx + 1
				End While
			End With
		End If
	End Sub
	
	Private Sub PopulaGridHistorico()
		Dim lstrZona As String
		Dim lstrLivro As String
		Dim lstrConta As String
		Dim lstrEvento As String
		Dim ldteCadastro As Date
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		On Error GoTo ErroPopulaGridHistorico
		lrstAux = New ADODB.Recordset
		With Me.mfgDados
			.Cols = 5
			.Rows = 1
			Call .Clear()
			.set_TextMatrix(0, 0, "Zona")
			.set_TextMatrix(0, 1, "Livro")
			.set_TextMatrix(0, 2, "Conta")
			.set_TextMatrix(0, 3, "Evento")
			.set_TextMatrix(0, 4, "Cadastro")
		End With
		lstrSql = ""
		lstrSql = lstrSql & "SELECT `nis`.`id`, "
		lstrSql = lstrSql & "       `nis`.`zona`, "
		lstrSql = lstrSql & "       `nis`.`livro`, "
		lstrSql = lstrSql & "       `nis`.`conta`, "
		lstrSql = lstrSql & "       `nis`.`evento`, "
		lstrSql = lstrSql & "       `nis`.`data_cadastro` "
		lstrSql = lstrSql & "  FROM `nis` "
		lstrSql = lstrSql & " WHERE `nis`.`nis` = '" & VB.Left(istrNis, 11) & "' "
		lstrSql = lstrSql & " ORDER BY `id` ASC "
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				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"'
						lstrZona = Trim(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"'
						lstrLivro = Trim(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"'
						lstrConta = Trim(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"'
						lstrEvento = Trim(IIf(IsDbNull(.Fields("evento").value), "I", .Fields("evento").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"'
						ldteCadastro = CDate(IIf(IsDbNull(.Fields("data_cadastro").value), BuscaDataBD, .Fields("data_cadastro").value))
						With Me.mfgDados
							.Rows = .Rows + 1
							.set_TextMatrix(.Rows - 1, 0, lstrZona)
							.set_TextMatrix(.Rows - 1, 1, lstrLivro)
							.set_TextMatrix(.Rows - 1, 2, lstrConta)
							.set_TextMatrix(.Rows - 1, 3, lstrEvento)
							.set_TextMatrix(.Rows - 1, 4, ldteCadastro)
						End With
						Call .MoveNext()
					End While
				End If
				Call .Close()
			End If
		End With
ErroPopulaGridHistorico: 
		If Err.Number > 0 Then
			Call MsgBox(Err.Number & " - " & GetErrosVB(Err.Number, Err.Description), MsgBoxStyle.Exclamation, gstrTituloMensagem)
		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
	
	Private Sub BuscaNis()
		Dim lstrAux As String
		Dim lstrSql As String
		Dim ldteAux As Date
		Dim lrstNis As ADODB.Recordset
		lrstNis = New ADODB.Recordset
		ldteAux = BuscaDataBD
		
		lstrSql = ""
		lstrSql = lstrSql & "SELECT "
		lstrSql = lstrSql & "       `nis`.`evento`,"
		lstrSql = lstrSql & "       `nis`.`nis`, "
		lstrSql = lstrSql & "       `nis`.`data_cadastro`, "
		lstrSql = lstrSql & "       `nis`.`data_alteracao`, "
		lstrSql = lstrSql & "       `nis`.`data_nascimento`, "
		lstrSql = lstrSql & "       `nis`.`uf_nascimento`, "
		lstrSql = lstrSql & "       `nis`.`dtcadbf`, "
		lstrSql = lstrSql & "       `nis`.`codmunic`, "
		lstrSql = lstrSql & "       `nis`.`zona`, "
		lstrSql = lstrSql & "       `nis`.`livro`, "
		lstrSql = lstrSql & "       `nis`.`conta`, "
		lstrSql = lstrSql & "       `nis`.`evento`, "
		lstrSql = lstrSql & "       `nis`.`nome_nis`, "
		lstrSql = lstrSql & "       `nis`.`cpf_nis`, "
		lstrSql = lstrSql & "       `nis`.`rg_nis`, "
		lstrSql = lstrSql & "       `nis`.`unid_id`, "
		lstrSql = lstrSql & "       `nis`.`cod_familiar_fam` "
		lstrSql = lstrSql & "  FROM `nis` "
		lstrSql = lstrSql & " WHERE `nis`.`nis` = '" & Me.txtNis.Text & "' "
		lstrSql = lstrSql & "   AND `nis`.`evento` NOT IN ('D') "
		Call Conectar(lstrSql, lrstNis)
		With lrstNis
			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.txtCodFamiliar.Text = VB.Left(Trim(IIf(IsDbNull(.Fields("cod_familiar_fam").value), "", .Fields("cod_familiar_fam").value)), 11)
					'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.dtpNascimento.value = CDate(IIf(IsDbNull(.Fields("data_nascimento").value), "1900-01-01", .Fields("data_nascimento").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.dtpCadastro.value = CDate(IIf(IsDbNull(.Fields("data_cadastro").value), ldteAux, .Fields("data_cadastro").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.dtpAlteracao.value = CDate(IIf(IsDbNull(.Fields("data_alteracao").value), ldteAux, .Fields("data_alteracao").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.dtpCadbf.value = CDate(IIf(IsDbNull(.Fields("dtcadbf").value), "1900-01-01", .Fields("dtcadbf").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.txtCodMunic.Text = Trim(IIf(IsDbNull(.Fields("codmunic").value), "", .Fields("codmunic").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.lblZonaNis.Text = Trim(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"'
					Me.lblLivroNis.Text = Trim(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"'
					Me.lblContaNis.Text = Trim(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"'
					Me.lblCodEvento.Text = Trim(IIf(IsDbNull(.Fields("evento").value), "", .Fields("evento").value))
					Me.lblCodEvento.Text = IIf(Me.lblCodEvento.Text = "I", "Incluído", IIf(Me.lblCodEvento.Text = "A", "Alterado", "Desativado"))
					'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"'
					Call SetUf(UCase(Trim(IIf(IsDbNull(.Fields("uf_nascimento").value) Or .Fields("uf_nascimento").value = "", gstrEmpresa_UF, .Fields("uf_nascimento").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.txtNomeNis.Text = Trim(IIf(IsDbNull(.Fields("nome_nis").value), "", .Fields("nome_nis").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.txtCpfNis.Text = Trim(IIf(IsDbNull(.Fields("cpf_nis").value), "", .Fields("cpf_nis").value))
					Me.txtCpfNis.Text = FormataCPF(Me.txtCpfNis.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.txtRgNis.Text = Trim(IIf(IsDbNull(.Fields("rg_nis").value), "", .Fields("rg_nis").value))
					Me.dtpCadbf.Enabled = True
					Me.dtpCadastro.Enabled = True
					Me.dtpAlteracao.Enabled = True
					'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.lblUnidIdNis.Text = CStr(CInt(IIf(IsDbNull(.Fields("unid_id").value), 0, .Fields("unid_id").value)))
					'UPGRADE_WARNING: Couldn't resolve default property of object Me.dtpNascimento.value. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
					idteNascimento = Me.dtpNascimento.value
					istrUFNaciment = VB6.GetItemString(Me.cmbUf, Me.cmbUf.SelectedIndex)
					'UPGRADE_WARNING: Couldn't resolve default property of object Me.dtpCadbf.value. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
					idteCadbf = Me.dtpCadbf.value
					istrCodmunic = Me.txtCodMunic.Text
					istrNomeNis = Me.txtNomeNis.Text
					istrCpfNis = Me.txtCpfNis.Text
					istrRgNis = Me.txtRgNis.Text
					istrNis = Me.txtNis.Text
					istrCodFamiliar = Me.txtCodFamiliar.Text
					Call PopulaGridHistorico()
				End If
			End If
			Call .Close()
		End With
		'UPGRADE_NOTE: Object lrstNis 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"'
		lrstNis = Nothing
	End Sub
	
	Private Function ValidaNisCpfNis(ByRef astrMsgAux As String) As Boolean
		Dim lblnRet As Boolean
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lblnRet = False
		astrMsgAux = ""
		lstrSql = ""
		lstrSql = lstrSql & "SELECT `nis`.`cpf`, "
		lstrSql = lstrSql & "       `nis`.`zona`, "
		lstrSql = lstrSql & "       `nis`.`livro`, "
		lstrSql = lstrSql & "       `nis`.`conta`, "
		lstrSql = lstrSql & "       `nis`.`nis` "
		lstrSql = lstrSql & "  FROM `nis` "
		lstrSql = lstrSql & " WHERE `nis`.`cpf_nis` = """ & Str_Retira(Trim(Me.txtCpfNis.Text), ".-/ ") & """ "
		lstrSql = lstrSql & "   AND `nis`.`evento` IN ('I','A') "
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			lblnRet = .RecordCount > 0
			If lblnRet 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"'
				astrMsgAux = "Este CPF possui o nis " & IIf(IsDbNull(.Fields("nis").value), "", .Fields("nis").value) & Chr(10) & " na unidade " & IIf(IsDbNull(.Fields("zona").value), "", .Fields("zona").value) & "." & IIf(IsDbNull(.Fields("livro").value), "", .Fields("livro").value) & "." & IIf(IsDbNull(.Fields("conta").value), "", .Fields("conta").value)
			End If
			Call .Close()
		End With
		'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
		ValidaNisCpfNis = lblnRet
	End Function
	
	Private Function ValidaNisCpf(ByRef astrMsgAux As String, ByVal astrNisAux As String) As Boolean
		Dim lblnRet As Boolean
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lblnRet = False
		astrMsgAux = ""
		lstrSql = ""
		lstrSql = lstrSql & "SELECT `nis`.`cpf`, "
		lstrSql = lstrSql & "       `nis`.`zona`, "
		lstrSql = lstrSql & "       `nis`.`livro`, "
		lstrSql = lstrSql & "       `nis`.`conta` "
		lstrSql = lstrSql & "  FROM `nis` "
		lstrSql = lstrSql & " WHERE `nis`.`nis`  = """ & astrNisAux & """ "
		lstrSql = lstrSql & "   AND `nis`.`cpf` <> """ & Str_Retira(Me.lblNumCpf.Text, ".-/ ") & """ "
		lstrSql = lstrSql & "   AND `nis`.`evento` IN ('I','A') "
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			lblnRet = .RecordCount > 0
			If lblnRet 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"'
				astrMsgAux = "Este NIS já está cadastrado!" & Chr(10) & "no CPF " & IIf(IsDbNull(.Fields("cpf").value), "", .Fields("cpf").value) & Chr(10) & " este registro será desativado! "
			Else
				astrMsgAux = ""
			End If
			Call .Close()
		End With
		'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
		ValidaNisCpf = lblnRet
	End Function
End Class