' gambas class file
Public Function validacnpj(cnpj As String) As Boolean
Dim cgc As String
Dim resto As Integer
Dim resto2 As Integer
Dim nVal As New Integer[15]
Dim nval1 As New Integer[15]
Dim total As Integer
Dim total2, total3, total4 As Integer
Dim totaldig1, totaldig2 As Integer
Dim conta, i As Integer
Dim texto As New String[15]
conta = Len(cnpj)
'cmdlimpa.Visible = True
'txtcgc.Enabled = False
'If conta = 14
texto[1] = Mid(cnpj, 1, 1)
Texto[2] = Mid(cnpj, 2, 1)
texto[3] = Mid(cnpj, 3, 1)
Texto[4] = Mid(cnpj, 4, 1)
Texto[5] = Mid(cnpj, 5, 1)
Texto[6] = Mid(cnpj, 6, 1)
Texto[7] = Mid(cnpj, 7, 1)
Texto[8] = Mid(cnpj, 8, 1)
Texto[9] = Mid(cnpj, 9, 1)
Texto[10] = Mid(cnpj, 10, 1)
Texto[11] = Mid(cnpj, 11, 1)
Texto[12] = Mid(cnpj, 12, 1)
Texto[13] = Mid(cnpj, 13, 1)
Texto[14] = Mid(cnpj, 14, 1)
nVal[0] = Texto[12] * 2
nVal[1] = Texto[11] * 3
nVal[2] = Texto[10] * 4
nVal[3] = Texto[9] * 5
nVal[4] = Texto[8] * 6
nVal[5] = Texto[7] * 7
nVal[6] = Texto[6] * 8
nVal[7] = Texto[5] * 9
nVal[8] = Texto[4] * 2
nVal[9] = Texto[3] * 3
nVal[10] = Texto[2] * 4
nVal[11] = Texto[1] * 5
total = nVal[0] + nVal[1] + nVal[2] + nVal[3] + nVal[4] + nVal[5] + nVal[6] + nVal[7] + nVal[8] + nVal[9] + nVal[10] + nVal[11]
total2 = total Mod 11
If total2 <= 1
totaldig1 = 0
Else
totaldig1 = 11 - total2
Endif
nval1[0] = Texto[12] * 3
nval1[1] = Texto[11] * 4
nval1[2] = Texto[10] * 5
nval1[3] = Texto[9] * 6
nval1[4] = Texto[8] * 7
nval1[5] = Texto[7] * 8
nval1[6] = Texto[6] * 9
nval1[7] = Texto[5] * 2
nval1[8] = Texto[4] * 3
nval1[9] = Texto[3] * 4
nval1[10] = Texto[2] * 5
nval1[11] = Texto[1] * 6
nval1[12] = Texto[13] * 2
total3 = nval1[0] + nval1[1] + nval1[2] + nval1[3] + nval1[4] + nval1[5] + nval1[6] + nval1[7] + nval1[8] + nval1[9] + nval1[10] + nval1[11] + nval1[12]
total4 = total3 Mod 11
If total4 <= 1 Then
totaldig2 = 0
Else
totaldig2 = 11 - total4
Endif
If Texto[13] = totaldig1
If Texto[14] = totaldig2
Return True
Else
Return False
Endif
Else
Return False
Endif
End
Public Function calculacpf(CPF As String) As Boolean
Dim d1 As Integer
Dim d2 As Integer
Dim d3 As Integer
Dim d4 As Integer
Dim d5 As Integer
Dim d6 As Integer
Dim d7 As Integer
Dim d8 As Integer
Dim d9 As Integer
Dim d10 As Integer
Dim d11 As Integer
Dim DV1 As Integer
Dim DV2 As Integer
Dim UltDig As Integer
Dim VerificarCPF As String
Dim t_cpf As String
t_cpf = String$(11 - Len(cpf), "0") & CPF
cpf = t_cpf
UltDig = Len(CPF) 'Pega a posição do último dígito
d1 = CInt(Mid(CPF, UltDig - 10, 1))
d2 = CInt(Mid(CPF, UltDig - 9, 1))
d3 = CInt(Mid(CPF, UltDig - 8, 1))
d4 = CInt(Mid(CPF, UltDig - 7, 1))
d5 = CInt(Mid(CPF, UltDig - 6, 1))
d6 = CInt(Mid(CPF, UltDig - 5, 1))
d7 = CInt(Mid(CPF, UltDig - 4, 1))
d8 = CInt(Mid(CPF, UltDig - 3, 1))
d9 = CInt(Mid(CPF, UltDig - 2, 1))
d10 = CInt(Mid(CPF, UltDig - 1, 1)) '<----- Aqui são os DVs informados
d11 = CInt(Mid(CPF, UltDig, 1)) '<----- no CPF analizado
DV1 = d1 + (d2 * 2) + (d3 * 3) + (d4 * 4) + (d5 * 5) + (d6 * 6) + (d7 * 7) + (d8 * 8) + (d9 * 9)
DV1 = DV1 Mod 11 'Obtem o resto
'se o resto for igual a 10 altera pra 0
If DV1 = 10 Then
DV1 = 0
Endif
DV2 = d2 + (d3 * 2) + (d4 * 3) + (d5 * 4) + (d6 * 5) + (d7 * 6) + (d8 * 7) + (d9 * 8) + (DV1 * 9)
DV2 = DV2 Mod 11 'Obtem o resto
If DV2 = 10 Then 'se o resto for igual a 10 altera pra 0
DV2 = 0
Endif
'---------- Fazendo a comparação dos dvs informados -------
If d10 = DV1 And d11 = DV2 Then
Return True
Else
Return False
Endif
End
Public Sub Form_Open()
Dim $res As Result
Dim $res_cpf As Result
Dim $n_nota As Integer
Dim $b_nota As String
Dim $busca_cpf As String
Dim ok1 As String
$busca_cpf = "select * from cliente where cnpj_cpf="
ok1 = 0
$b_nota = "select * from cliente order by cod_cli"
$res = cnx.bd.Exec($b_nota)
$res.MoveLast
$n_nota = $res!cod_cli
Print $n_nota
ValueBox1.Value = $n_nota + 1
Form.Refresh
End
Public Sub TextBox1_KeyPress()
TextBox1.Text = Upper(TextBox1.Text)
End
Public Sub ComboBox1_LostFocus()
If ComboBox1.text = "F" Or ComboBox1.Text = "J"
Return
Else
Print Message(" Escola o tipo de cadastro")
Endif
End
Public Sub Maskcpfcgc_LostFocus()
If Maskcpfcgc.text = ""
Return
Endif
If ComboBox1.Text = "F"
If Not calculacpf(Maskcpfcgc.Text)
Print Message("CPF INVÁLIDO", "Ok")
Maskcpfcgc.Text = ""
Maskcpfcgc.SetFocus
' ' ' $res_cpf = cnx.bd.Exec($busca_cpf & Maskcpfcgc.Text)
Endif
Endif
If ComboBox1.text = "J"
If Not validacnpj(Maskcpfcgc.Text)
Print Message("CNPJ INVÁLIDO", "OK")
Maskcpfcgc.Text = ""
Maskcpfcgc.SetFocus
Endif
Endif
End
Public Sub Maskcpfcgc_KeyPress()
If Key.Text = "1" Or Key.text = "2" Or Key.text = "3" Or Key.text = "4" Or Key.text = "5" Or Key.text = "6" Or Key.text = "7" Or Key.text = "8" Or Key.text = "9" Or Key.text = "0" Or Key.text = "\r" Or Key.text = "\t" Or Key.text = "\x08" Or Key.text = "\x1b"
Return
Else
Maskcpfcgc.text = ""
Print Message("Apenas números", "Ok")
ComboBox1.SetFocus
Form.Refresh
Return
Endif
If ComboBox1.text = "F"
Maskcpfcgc.MaxLength = 11
If Len(Maskcpfcgc.Text) <> 11
Return
Else
Print Maskcpfcgc.Text
Endif
Else
Maskcpfcgc.MaxLength = 14
' Print Maskcpfcgc.text.format = "##.###.###/####-##0"
Endif
End
Public Sub botao_inclui_Click()
Dim $busca_cpf As String
Dim $res_cpf As Result
$busca_cpf = "select * from cliente where cnpj_cpf = " & Maskcpfcgc.text
If Message.Warning("Confirma ação", "Inclui", "cancela") = 1
$res_cpf = cnx.bd.Exec($busca_cpf)
If $res_cpf.Available = True
Print Message("CPF ou CNPJ JÁ CADASTRASDO", "Ok")
Return
Else
Print "sim"
Endif
Endif
End
Public Sub TextBox2_KeyPress()
TextBox2.text = Upper(TextBox2.text)
End
Public Sub TextBox4_KeyPress()
TextBox4.MaxLength = 2
TextBox4.text = Upper(TextBox4.text)
End
Public Sub Editor1_LostFocus()
Editor1.text = Upper(Editor1.Text)
End
Public Function validacnpj(cnpj As String) As Boolean
Dim cgc As String
Dim resto As Integer
Dim resto2 As Integer
Dim nVal As New Integer[15]
Dim nval1 As New Integer[15]
Dim total As Integer
Dim total2, total3, total4 As Integer
Dim totaldig1, totaldig2 As Integer
Dim conta, i As Integer
Dim texto As New String[15]
conta = Len(cnpj)
'cmdlimpa.Visible = True
'txtcgc.Enabled = False
'If conta = 14
texto[1] = Mid(cnpj, 1, 1)
Texto[2] = Mid(cnpj, 2, 1)
texto[3] = Mid(cnpj, 3, 1)
Texto[4] = Mid(cnpj, 4, 1)
Texto[5] = Mid(cnpj, 5, 1)
Texto[6] = Mid(cnpj, 6, 1)
Texto[7] = Mid(cnpj, 7, 1)
Texto[8] = Mid(cnpj, 8, 1)
Texto[9] = Mid(cnpj, 9, 1)
Texto[10] = Mid(cnpj, 10, 1)
Texto[11] = Mid(cnpj, 11, 1)
Texto[12] = Mid(cnpj, 12, 1)
Texto[13] = Mid(cnpj, 13, 1)
Texto[14] = Mid(cnpj, 14, 1)
nVal[0] = Texto[12] * 2
nVal[1] = Texto[11] * 3
nVal[2] = Texto[10] * 4
nVal[3] = Texto[9] * 5
nVal[4] = Texto[8] * 6
nVal[5] = Texto[7] * 7
nVal[6] = Texto[6] * 8
nVal[7] = Texto[5] * 9
nVal[8] = Texto[4] * 2
nVal[9] = Texto[3] * 3
nVal[10] = Texto[2] * 4
nVal[11] = Texto[1] * 5
total = nVal[0] + nVal[1] + nVal[2] + nVal[3] + nVal[4] + nVal[5] + nVal[6] + nVal[7] + nVal[8] + nVal[9] + nVal[10] + nVal[11]
total2 = total Mod 11
If total2 <= 1
totaldig1 = 0
Else
totaldig1 = 11 - total2
Endif
nval1[0] = Texto[12] * 3
nval1[1] = Texto[11] * 4
nval1[2] = Texto[10] * 5
nval1[3] = Texto[9] * 6
nval1[4] = Texto[8] * 7
nval1[5] = Texto[7] * 8
nval1[6] = Texto[6] * 9
nval1[7] = Texto[5] * 2
nval1[8] = Texto[4] * 3
nval1[9] = Texto[3] * 4
nval1[10] = Texto[2] * 5
nval1[11] = Texto[1] * 6
nval1[12] = Texto[13] * 2
total3 = nval1[0] + nval1[1] + nval1[2] + nval1[3] + nval1[4] + nval1[5] + nval1[6] + nval1[7] + nval1[8] + nval1[9] + nval1[10] + nval1[11] + nval1[12]
total4 = total3 Mod 11
If total4 <= 1 Then
totaldig2 = 0
Else
totaldig2 = 11 - total4
Endif
If Texto[13] = totaldig1
If Texto[14] = totaldig2
Return True
Else
Return False
Endif
Else
Return False
Endif
End
Public Function calculacpf(CPF As String) As Boolean
Dim d1 As Integer
Dim d2 As Integer
Dim d3 As Integer
Dim d4 As Integer
Dim d5 As Integer
Dim d6 As Integer
Dim d7 As Integer
Dim d8 As Integer
Dim d9 As Integer
Dim d10 As Integer
Dim d11 As Integer
Dim DV1 As Integer
Dim DV2 As Integer
Dim UltDig As Integer
Dim VerificarCPF As String
Dim t_cpf As String
t_cpf = String$(11 - Len(cpf), "0") & CPF
cpf = t_cpf
UltDig = Len(CPF) 'Pega a posição do último dígito
d1 = CInt(Mid(CPF, UltDig - 10, 1))
d2 = CInt(Mid(CPF, UltDig - 9, 1))
d3 = CInt(Mid(CPF, UltDig - 8, 1))
d4 = CInt(Mid(CPF, UltDig - 7, 1))
d5 = CInt(Mid(CPF, UltDig - 6, 1))
d6 = CInt(Mid(CPF, UltDig - 5, 1))
d7 = CInt(Mid(CPF, UltDig - 4, 1))
d8 = CInt(Mid(CPF, UltDig - 3, 1))
d9 = CInt(Mid(CPF, UltDig - 2, 1))
d10 = CInt(Mid(CPF, UltDig - 1, 1)) '<----- Aqui são os DVs informados
d11 = CInt(Mid(CPF, UltDig, 1)) '<----- no CPF analizado
DV1 = d1 + (d2 * 2) + (d3 * 3) + (d4 * 4) + (d5 * 5) + (d6 * 6) + (d7 * 7) + (d8 * 8) + (d9 * 9)
DV1 = DV1 Mod 11 'Obtem o resto
'se o resto for igual a 10 altera pra 0
If DV1 = 10 Then
DV1 = 0
Endif
DV2 = d2 + (d3 * 2) + (d4 * 3) + (d5 * 4) + (d6 * 5) + (d7 * 6) + (d8 * 7) + (d9 * 8) + (DV1 * 9)
DV2 = DV2 Mod 11 'Obtem o resto
If DV2 = 10 Then 'se o resto for igual a 10 altera pra 0
DV2 = 0
Endif
'---------- Fazendo a comparação dos dvs informados -------
If d10 = DV1 And d11 = DV2 Then
Return True
Else
Return False
Endif
End
Public Sub Form_Open()
Dim $res As Result
Dim $res_cpf As Result
Dim $n_nota As Integer
Dim $b_nota As String
Dim $busca_cpf As String
Dim ok1 As String
$busca_cpf = "select * from cliente where cnpj_cpf="
ok1 = 0
$b_nota = "select * from cliente order by cod_cli"
$res = cnx.bd.Exec($b_nota)
$res.MoveLast
$n_nota = $res!cod_cli
Print $n_nota
ValueBox1.Value = $n_nota + 1
Form.Refresh
End
Public Sub TextBox1_KeyPress()
TextBox1.Text = Upper(TextBox1.Text)
End
Public Sub ComboBox1_LostFocus()
If ComboBox1.text = "F" Or ComboBox1.Text = "J"
Return
Else
Print Message(" Escola o tipo de cadastro")
Endif
End
Public Sub Maskcpfcgc_LostFocus()
If Maskcpfcgc.text = ""
Return
Endif
If ComboBox1.Text = "F"
If Not calculacpf(Maskcpfcgc.Text)
Print Message("CPF INVÁLIDO", "Ok")
Maskcpfcgc.Text = ""
Maskcpfcgc.SetFocus
' ' ' $res_cpf = cnx.bd.Exec($busca_cpf & Maskcpfcgc.Text)
Endif
Endif
If ComboBox1.text = "J"
If Not validacnpj(Maskcpfcgc.Text)
Print Message("CNPJ INVÁLIDO", "OK")
Maskcpfcgc.Text = ""
Maskcpfcgc.SetFocus
Endif
Endif
End
Public Sub Maskcpfcgc_KeyPress()
If Key.Text = "1" Or Key.text = "2" Or Key.text = "3" Or Key.text = "4" Or Key.text = "5" Or Key.text = "6" Or Key.text = "7" Or Key.text = "8" Or Key.text = "9" Or Key.text = "0" Or Key.text = "\r" Or Key.text = "\t" Or Key.text = "\x08" Or Key.text = "\x1b"
Return
Else
Maskcpfcgc.text = ""
Print Message("Apenas números", "Ok")
ComboBox1.SetFocus
Form.Refresh
Return
Endif
If ComboBox1.text = "F"
Maskcpfcgc.MaxLength = 11
If Len(Maskcpfcgc.Text) <> 11
Return
Else
Print Maskcpfcgc.Text
Endif
Else
Maskcpfcgc.MaxLength = 14
' Print Maskcpfcgc.text.format = "##.###.###/####-##0"
Endif
End
Public Sub botao_inclui_Click()
Dim $busca_cpf As String
Dim $res_cpf As Result
$busca_cpf = "select * from cliente where cnpj_cpf = " & Maskcpfcgc.text
If Message.Warning("Confirma ação", "Inclui", "cancela") = 1
$res_cpf = cnx.bd.Exec($busca_cpf)
If $res_cpf.Available = True
Print Message("CPF ou CNPJ JÁ CADASTRASDO", "Ok")
Return
Else
Print "sim"
Endif
Endif
End
Public Sub TextBox2_KeyPress()
TextBox2.text = Upper(TextBox2.text)
End
Public Sub TextBox4_KeyPress()
TextBox4.MaxLength = 2
TextBox4.text = Upper(TextBox4.text)
End
Public Sub Editor1_LostFocus()
Editor1.text = Upper(Editor1.Text)
End