clsEPAPatterns.cls
4.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "clsEPAPatterns"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
Option Explicit
Private mvarID As Long
Private mvarDESCRICAO As String
Private mvarPADRAO As String
Public Property Let ID(ByVal vData As Long)
mvarID = vData
End Property
Public Property Get ID() As Long
ID = mvarID
End Property
Public Property Let DESCRICAO(ByVal vData As String)
mvarDESCRICAO = vData
End Property
Public Property Get DESCRICAO() As String
DESCRICAO = mvarDESCRICAO
End Property
Public Property Let PADRAO(ByVal vData As String)
mvarPADRAO = vData
End Property
Public Property Get PADRAO() As String
PADRAO = mvarPADRAO
End Property
Public Function Inserir_Padrao() As Boolean
Inserir_Padrao = False
On Error GoTo InsereDado_err
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
'rs.Open "x_patterns", Conn, adOpenKeyset, adLockOptimistic, adCmdTable
rs.Open "x_patterns", Conn, adOpenDynamic, adLockOptimistic
rs.AddNew
rs.Fields("ID").value = ID
rs.Fields("DESCRICAO").value = IIf(DESCRICAO = "", Null, DESCRICAO)
rs.Fields("PADRAO").value = IIf(PADRAO = "", Null, PADRAO)
rs.Update
Inserir_Padrao = True
rs.Close
Set rs = Nothing
Exit Function
InsereDado_err:
If Err.Number <> 0 Then
MsgBox "Número da curva já existe", vbExclamation
End If
End Function
'/// Atualiza a padrao da instancia para o Banco
'/// ou do banco para instancia.
'/// Atualiza/carrega a instancia com o id
'/// fornecido.
Public Function Atualizar_Padrao(Padrao_id As Long, Optional Banco As Boolean = False) As Boolean
Atualizar_Padrao = False
On Error GoTo Atualizar_Padrao_err
Dim rs As New ADODB.Recordset
If frmCanvas.TipoConexao <> 4 Then
rs.Open "SELECT * from x_patterns where id = " & Padrao_id, Conn, adOpenKeyset, adLockOptimistic
Else
Dim p As String
Dim k As String
p = "X_PATTERNS"
k = "ID"
rs.Open "SELECT * from " + """" + p + """" + " where " + """" + k + """" + " = '" & Padrao_id & "'", Conn, adOpenDynamic, adLockOptimistic
End If
If rs.EOF Then
MsgBox "Número da curva não cadastrada", vbExclamation
Else
If Banco Then
rs.Fields("DESCRICAO").value = IIf(DESCRICAO = "", Null, DESCRICAO)
rs.Fields("PADRAO").value = IIf(PADRAO = "", Null, PADRAO)
rs.Update
Else
ID = rs.Fields("id").value
DESCRICAO = rs.Fields("DESCRICAO").value
PADRAO = rs.Fields("PADRAO").value
End If
Atualizar_Padrao = True
End If
rs.Close
Set rs = Nothing
Exit Function
Atualizar_Padrao_err:
If Err.Number <> 0 Then
MsgBox "Número da curva já existe", vbExclamation
End If
End Function
'/// Retorna um cursor com todas as padroes cadastrados
Public Function Retorna_Padroes(rsCurvas As ADODB.Recordset) As Boolean
Retorna_Padroes = False
On Error GoTo Retorna_Padroes_err
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Dim a As String
Dim b As String
a = "X_PATTERNS"
b = "ID"
If frmCanvas.TipoConexao <> 4 Then
rs.Open "SELECT * from x_patterns order by id", Conn
Else
rs.Open "SELECT * from " + """" + a + """" + " order by" + """" + b + """", Conn, adOpenDynamic, adLockOptimistic
End If
If rs.EOF Then
rs.Close
Else
Set rsCurvas = rs
Retorna_Padroes = True
End If
Set rs = Nothing
Exit Function
Retorna_Padroes_err:
If Err.Number <> 0 Then
MsgBox Err.Description & vbCrLf & "Classe:Padrões EPA - Método: Retorna_Padroes", vbExclamation
End If
End Function
'/// Exclui um curva existente no database
Public Function Excluir_Padrao(Padrao_id As Long) As Boolean
Excluir_Padrao = False
On Error GoTo Delete_Curva_err
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
If frmCanvas.TipoConexao <> 4 Then
rs.Open "SELECT * from x_patterns where id = " & Padrao_id, Conn, adOpenKeyset, adLockOptimistic
Else
Dim p As String
Dim k As String
p = "X_PATTERNS"
k = "ID"
rs.Open "SELECT * from " + """" + p + """" + " where " + """" + k + """" + " = '" & Padrao_id & "', Conn, adOpenDynamic, adLockOptimistic"
End If
If rs.EOF Then
MsgBox "Padrão não cadastrada", vbExclamation
Else
rs.Delete
rs.Update
rs.Close
Excluir_Padrao = True
End If
Set rs = Nothing
Exit Function
Delete_Curva_err:
If Err.Number <> 0 Then
MsgBox "Padrão não encontrado", vbExclamation
End If
End Function