Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Friend Class frmBdgd
	Inherits System.Windows.Forms.Form
	Private ifrmDir As frmDir
	Private istrProdistUserSgd As String
	Private istrProdistPassSgd As String
	Private istrProdistUserBdgd As String
	Private istrProdistPassBdgd As String
	Private istrProdistTnsNames As String
	Private istrBDVida As String
	'UPGRADE_WARNING: Lower bound of array idblEne 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"'
	Private idblEne(12) As Double
	'UPGRADE_WARNING: Lower bound of array idblDem 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"'
	Private idblDem(12) As Double
	Private icnxDbf As ADODB.Connection
	
	Private Sub cmdFechar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdFechar.Click
		Call Me.Close()
	End Sub
	
	Private Sub cmdPasta_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdPasta.Click
		With Me.cmdPasta
			Me.Enabled = False
			ifrmDir.frmQuemChama = Me
			ifrmDir.intTipo = 1
			Call ifrmDir.SetBounds(VB6.TwipsToPixelsX(VB6.PixelsToTwipsX(Me.Left) + VB6.PixelsToTwipsX(.Left) + 400), VB6.TwipsToPixelsY(VB6.PixelsToTwipsY(Me.Top) + VB6.PixelsToTwipsY(.Top) + 400), 0, 0, Windows.Forms.BoundsSpecified.X Or Windows.Forms.BoundsSpecified.Y)
			Call ifrmDir.ShowDialog()
		End With
	End Sub
	
	Private Sub cmdProcessar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdProcessar.Click
		Call LigDes(False)
		If Me.chkDbf.CheckState = System.Windows.Forms.CheckState.Checked Then
			Call BarraProgresso((Me.ProgressBarProc), (Me.lblPercProc), (Me.lblInfoProc), 0, 4, " Dados DBF ")
			If CarregaDbfIndra Then
				If CriaDbf Then
					If PreencheDadosUnidades Then
						If InsereDbf Then
							Call MsgBox("Processo finalizado.", MsgBoxStyle.Information, gstrTituloMensagem)
						End If
					End If
				End If
			End If
		Else
			Call BarraProgresso((Me.ProgressBarProc), (Me.lblPercProc), (Me.lblInfoProc), 0, 3, " Dados SGD ")
			If BuscaDadosdoSgd Then
				If PreencheDadosUnidades Then
					If InsereAtualizaOracleBDGB Then
						Call MsgBox("Processo finalizado.", MsgBoxStyle.Information, gstrTituloMensagem)
					End If
				End If
			End If
		End If
		Call LigDes(True)
	End Sub
	
	Private Sub frmBdgd_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		Dim lstrSql As String
		Call CenterForm(Me)
		ifrmDir = New frmDir
		icnxDbf = CreateObject("ADODB.Connection")
		Me.dtpBase.value = BuscaDataBD
		istrBDVida = "vida_" & LCase(gstrEmpresa_Sigla)
		'
		istrProdistUserSgd = Trim(LeConfig("PRODIST_USUARIO_SGD"))
		If istrProdistUserSgd = "-1" Then
			istrProdistUserSgd = LCase(gstrEmpresa_Sigla) & "flx_sgd"
			Call CriaParConfig("PRODIST_USUARIO_SGD", istrProdistUserSgd, False, "Usuário do banco de dados do SGD")
		ElseIf istrProdistUserSgd = "" Then 
			istrProdistUserSgd = UCase(gstrEmpresa_Sigla) & "flx_sgd"
			Call GravaConfig("PRODIST_USUARIO_SGD", istrProdistUserSgd)
		End If
		'
		istrProdistPassSgd = Trim(LeConfig("PRODIST_SENHA_SGD"))
		If istrProdistPassSgd = "-1" Then
			istrProdistPassSgd = "brutal"
			Call CriaParConfig("PRODIST_SENHA_SGD", istrProdistPassSgd, False, "Senha do usuário do banco de dados do SGD")
		ElseIf istrProdistPassSgd = "" Then 
			istrProdistPassSgd = "brutal"
			Call GravaConfig("PRODIST_SENHA_SGD", istrProdistPassSgd)
		End If
		'
		istrProdistUserBdgd = Trim(LeConfig("PRODIST_USUARIO_BDGD"))
		If istrProdistUserBdgd = "-1" Then
			istrProdistUserBdgd = "prodist_aux"
			Call CriaParConfig("PRODIST_USUARIO_BDGD", istrProdistUserBdgd, False, "Usuário do banco de dados do BDGD")
		ElseIf istrProdistUserBdgd = "" Then 
			istrProdistUserBdgd = "prodist_aux"
			Call GravaConfig("PRODIST_USUARIO_BDGD", istrProdistUserBdgd)
		End If
		'
		istrProdistPassBdgd = Trim(LeConfig("PRODIST_SENHA_BDGD"))
		If istrProdistPassBdgd = "-1" Then
			istrProdistPassBdgd = "brutal"
			Call CriaParConfig("PRODIST_SENHA_BDGD", istrProdistPassBdgd, False, "Senha do usuário do banco de dados do BDGD")
		ElseIf istrProdistPassBdgd = "" Then 
			istrProdistPassBdgd = "brutal"
			Call GravaConfig("PRODIST_SENHA_BDGD", istrProdistPassBdgd)
		End If
		'
		istrProdistTnsNames = Trim(LeConfig("PRODIST_CAMINHO_TNSNAMES"))
		If istrProdistTnsNames = "-1" Then
			istrProdistTnsNames = ""
			Call CriaParConfig("PRODIST_CAMINHO_TNSNAMES", istrProdistTnsNames, False, "Caminho do TNSNAMES.ORA")
		ElseIf istrProdistTnsNames = "" Then 
			istrProdistTnsNames = ""
			Call GravaConfig("PRODIST_CAMINHO_TNSNAMES", istrProdistTnsNames)
		End If
		'
		Me.txtUserSgd.Text = istrProdistUserSgd
		Me.txtPassSgd.Text = istrProdistPassSgd
		Me.txtUserBdgd.Text = istrProdistUserBdgd
		Me.txtPassBdgd.Text = istrProdistPassBdgd
		If istrProdistTnsNames <> "" Then
			Me.txtDir.Text = istrProdistTnsNames
		End If
		'
		lstrSql = ""
		lstrSql = lstrSql & "CREATE TABLE IF NOT EXISTS " & gstrDataBase & ".`prodist_consumidor_bt`( " & vbCrLf
		lstrSql = lstrSql & "`zona` varchar(3) NOT NULL DEFAULT '000', " & vbCrLf
		lstrSql = lstrSql & "`livro` varchar(2) NOT NULL DEFAULT '00', " & vbCrLf
		lstrSql = lstrSql & "`conta` varchar(6) NOT NULL DEFAULT '000000', " & vbCrLf
		lstrSql = lstrSql & "`ramal` varchar(20) NOT NULL DEFAULT '', " & vbCrLf
		lstrSql = lstrSql & "`medidor` varchar(20) NOT NULL DEFAULT '', " & vbCrLf
		lstrSql = lstrSql & "`dist` varchar(2) NOT NULL DEFAULT '00', " & vbCrLf
		lstrSql = lstrSql & "`clas_sub` varchar(20) NOT NULL DEFAULT 'RE1', " & vbCrLf
		lstrSql = lstrSql & "`fas_con` varchar(4) NOT NULL DEFAULT 'ABCN', " & vbCrLf
		lstrSql = lstrSql & "`gru_ten` varchar(2) NOT NULL DEFAULT '00', " & vbCrLf
		lstrSql = lstrSql & "`ten_forn` varchar(2) NOT NULL DEFAULT '00', " & vbCrLf
		lstrSql = lstrSql & "`gru_tar` varchar(20) NOT NULL DEFAULT 'B1', " & vbCrLf
		lstrSql = lstrSql & "`sit_ativ` varchar(20) NOT NULL DEFAULT 'SM', " & vbCrLf
		lstrSql = lstrSql & "`dat_con` date NOT NULL DEFAULT '1900-01-01', " & vbCrLf
		lstrSql = lstrSql & "`pot_inst` double NOT NULL DEFAULT '0.001', " & vbCrLf
		lstrSql = lstrSql & "`ene_01` double(14,3) NOT NULL DEFAULT '0.000', " & vbCrLf
		lstrSql = lstrSql & "`ene_02` double(14,3) NOT NULL DEFAULT '0.000', " & vbCrLf
		lstrSql = lstrSql & "`ene_03` double(14,3) NOT NULL DEFAULT '0.000', " & vbCrLf
		lstrSql = lstrSql & "`ene_04` double(14,3) NOT NULL DEFAULT '0.000', " & vbCrLf
		lstrSql = lstrSql & "`ene_05` double(14,3) NOT NULL DEFAULT '0.000', " & vbCrLf
		lstrSql = lstrSql & "`ene_06` double(14,3) NOT NULL DEFAULT '0.000', " & vbCrLf
		lstrSql = lstrSql & "`ene_07` double(14,3) NOT NULL DEFAULT '0.000', " & vbCrLf
		lstrSql = lstrSql & "`ene_08` double(14,3) NOT NULL DEFAULT '0.000', " & vbCrLf
		lstrSql = lstrSql & "`ene_09` double(14,3) NOT NULL DEFAULT '0.000', " & vbCrLf
		lstrSql = lstrSql & "`ene_10` double(14,3) NOT NULL DEFAULT '0.000', " & vbCrLf
		lstrSql = lstrSql & "`ene_11` double(14,3) NOT NULL DEFAULT '0.000', " & vbCrLf
		lstrSql = lstrSql & "`ene_12` double(14,3) NOT NULL DEFAULT '0.000', " & vbCrLf
		lstrSql = lstrSql & "`atualizado` tinyint(1) NOT NULL DEFAULT '0', " & vbCrLf
		lstrSql = lstrSql & " KEY `keyconta` (`zona`,`livro`,`conta`), "
		lstrSql = lstrSql & " KEY `keyatualizado` (`atualizado`)) "
		Call Executar(lstrSql, True)
		'
		lstrSql = ""
		lstrSql = lstrSql & "CREATE TABLE IF NOT EXISTS " & gstrDataBase & ".`prodist_consumidor_mt`( "
		lstrSql = lstrSql & "`zona` varchar(3) NOT NULL DEFAULT '000', " & vbCrLf
		lstrSql = lstrSql & "`livro` varchar(2) NOT NULL DEFAULT '00', " & vbCrLf
		lstrSql = lstrSql & "`conta` varchar(6) NOT NULL DEFAULT '000000', " & vbCrLf
		lstrSql = lstrSql & "`pn_con` varchar(20) NOT NULL DEFAULT '', "
		lstrSql = lstrSql & "`sdmt_con` varchar(20) NOT NULL DEFAULT '', "
		lstrSql = lstrSql & "`med_01` varchar(20) NOT NULL DEFAULT '', "
		lstrSql = lstrSql & "`med_02` varchar(20) NOT NULL DEFAULT '', "
		lstrSql = lstrSql & "`tc` varchar(20) NOT NULL DEFAULT '0', "
		lstrSql = lstrSql & "`tp` varchar(20) NOT NULL DEFAULT '0', "
		lstrSql = lstrSql & "`dist` varchar(2) NOT NULL DEFAULT '00', "
		lstrSql = lstrSql & "`clas_sub` varchar(20) NOT NULL DEFAULT 'RE1', "
		lstrSql = lstrSql & "`fas_con` varchar(4) NOT NULL DEFAULT 'ABCN', "
		lstrSql = lstrSql & "`gru_ten` varchar(2) NOT NULL DEFAULT '00', "
		lstrSql = lstrSql & "`ten_forn` varchar(2) NOT NULL DEFAULT '00', "
		lstrSql = lstrSql & "`gru_tar` varchar(20) NOT NULL DEFAULT 'B1', "
		lstrSql = lstrSql & "`sit_ativ` varchar(20) NOT NULL DEFAULT 'SM', "
		lstrSql = lstrSql & "`dat_con` date NOT NULL DEFAULT '1900-01-01', "
		lstrSql = lstrSql & "`pot_inst` double NOT NULL DEFAULT '0.001', "
		lstrSql = lstrSql & "`liv` varchar(1) NOT NULL DEFAULT 'F', "
		lstrSql = lstrSql & "`dem_01` double(14,3) NOT NULL DEFAULT 0.000, "
		lstrSql = lstrSql & "`dem_02` double(14,3) NOT NULL DEFAULT 0.000, "
		lstrSql = lstrSql & "`dem_03` double(14,3) NOT NULL DEFAULT 0.000, "
		lstrSql = lstrSql & "`dem_04` double(14,3) NOT NULL DEFAULT 0.000, "
		lstrSql = lstrSql & "`dem_05` double(14,3) NOT NULL DEFAULT 0.000, "
		lstrSql = lstrSql & "`dem_06` double(14,3) NOT NULL DEFAULT 0.000, "
		lstrSql = lstrSql & "`dem_07` double(14,3) NOT NULL DEFAULT 0.000, "
		lstrSql = lstrSql & "`dem_08` double(14,3) NOT NULL DEFAULT 0.000, "
		lstrSql = lstrSql & "`dem_09` double(14,3) NOT NULL DEFAULT 0.000, "
		lstrSql = lstrSql & "`dem_10` double(14,3) NOT NULL DEFAULT 0.000, "
		lstrSql = lstrSql & "`dem_11` double(14,3) NOT NULL DEFAULT 0.000, "
		lstrSql = lstrSql & "`dem_12` double(14,3) NOT NULL DEFAULT 0.000, "
		lstrSql = lstrSql & "`ene_01` double(14,3) NOT NULL DEFAULT 0.000, "
		lstrSql = lstrSql & "`ene_02` double(14,3) NOT NULL DEFAULT 0.000, "
		lstrSql = lstrSql & "`ene_03` double(14,3) NOT NULL DEFAULT 0.000, "
		lstrSql = lstrSql & "`ene_04` double(14,3) NOT NULL DEFAULT 0.000, "
		lstrSql = lstrSql & "`ene_05` double(14,3) NOT NULL DEFAULT 0.000, "
		lstrSql = lstrSql & "`ene_06` double(14,3) NOT NULL DEFAULT 0.000, "
		lstrSql = lstrSql & "`ene_07` double(14,3) NOT NULL DEFAULT 0.000, "
		lstrSql = lstrSql & "`ene_08` double(14,3) NOT NULL DEFAULT 0.000, "
		lstrSql = lstrSql & "`ene_09` double(14,3) NOT NULL DEFAULT 0.000, "
		lstrSql = lstrSql & "`ene_10` double(14,3) NOT NULL DEFAULT 0.000, "
		lstrSql = lstrSql & "`ene_11` double(14,3) NOT NULL DEFAULT 0.000, "
		lstrSql = lstrSql & "`ene_12` double(14,3) NOT NULL DEFAULT 0.000, "
		lstrSql = lstrSql & "`atualizado` tinyint(1) NOT NULL DEFAULT '0', " & vbCrLf
		lstrSql = lstrSql & " KEY `keyconta` (`zona`,`livro`,`conta`), "
		lstrSql = lstrSql & " KEY `keyatualizado` (`atualizado`)) "
		Call Executar(lstrSql, True)
		'
		lstrSql = ""
		lstrSql = lstrSql & "CREATE TABLE IF NOT EXISTS " & gstrDataBase & ".`prodist_medidor`( "
		lstrSql = lstrSql & "`cod_id` varchar(20) NOT NULL DEFAULT '', "
		lstrSql = lstrSql & "`dist` varchar(5) NOT NULL DEFAULT '', "
		lstrSql = lstrSql & "`tip_unid` varchar(5) NOT NULL DEFAULT '', "
		lstrSql = lstrSql & "`quan_fas` varchar(4) NOT NULL DEFAULT '', "
		lstrSql = lstrSql & "`odi` varchar(99) NOT NULL DEFAULT '', "
		lstrSql = lstrSql & "`ti` varchar(2) NOT NULL DEFAULT '', "
		lstrSql = lstrSql & "`cm` varchar(3) NOT NULL DEFAULT '', "
		lstrSql = lstrSql & "`tuc` varchar(3) NOT NULL DEFAULT '', "
		lstrSql = lstrSql & "`a1` varchar(2) NOT NULL DEFAULT '', "
		lstrSql = lstrSql & "`a2` varchar(2) NOT NULL DEFAULT '', "
		lstrSql = lstrSql & "`a3` varchar(2) NOT NULL DEFAULT '', "
		lstrSql = lstrSql & "`a4` varchar(2) NOT NULL DEFAULT '', "
		lstrSql = lstrSql & "`a5` varchar(2) NOT NULL DEFAULT '', "
		lstrSql = lstrSql & "`a6` varchar(2) NOT NULL DEFAULT '', "
		lstrSql = lstrSql & "`iduc` varchar(99) NOT NULL DEFAULT '', "
		lstrSql = lstrSql & "`uar` varchar(99) NOT NULL DEFAULT '', "
		lstrSql = lstrSql & "`dat_imo` date NOT NULL DEFAULT '1900-01-01', "
		lstrSql = lstrSql & "`descr` varchar(255) NOT NULL DEFAULT '', "
		lstrSql = lstrSql & "`atualizado` tinyint(1) NOT NULL DEFAULT '0', " & vbCrLf
		lstrSql = lstrSql & " KEY `keycod_id` (`cod_id`), "
		lstrSql = lstrSql & " KEY `keyatualizado` (`atualizado`)) "
		Call Executar(lstrSql, True)
	End Sub
	
	Private Sub AbreConexaoDBF(ByVal astrCaminhoDBF As String)
		Call icnxDbf.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & astrCaminhoDBF & ";Extended Properties=""DBASE IV;"";")
	End Sub
	
	Private Function CarregaDbfIndra() As Boolean
		Dim lstrArq As String
		Dim lstrZon As String
		Dim lstrLiv As String
		Dim lstrCon As String
		Dim lstrCod As String
		Dim lstrRam As String
		Dim lstrDis As String
		Dim lstrFas As String
		Dim lstrGru As String
		Dim lstrSit As String
		Dim ldblPot As Double
		Dim lstrPnc As String
		Dim lstrSdm As String
		Dim lstrMed As String
		Dim lblnRet As Boolean
		Dim lstrSql As String
		Dim lstrDbf As String
		Dim llngRec As Integer
		Dim lrstAux As ADODB.Recordset
		lblnRet = True
		On Error GoTo ErroCarregaDbfIndra
		If Me.chkMedidor.CheckState = System.Windows.Forms.CheckState.Checked Then Call Executar("DELETE FROM " & gstrDataBase & ".`prodist_medidor` ")
		Call BarraProgresso((Me.ProgressBarProc), (Me.lblPercProc), (Me.lblInfoProc), 1,  , " Dados DBF ")
		'
		'Abre Conexão para pastas DBF ex: C:\[Nome do Directorio]
		'
		Call AbreConexaoDBF(Me.txtDir.Text)
		'
		'Valida se existe na pasta selecionada o arquivo UC_BT.DBF
		'
		If Me.chkBt.CheckState = System.Windows.Forms.CheckState.Checked Then
			lstrArq = Me.txtDir.Text & IIf(VB.Right(Trim(Me.txtDir.Text), 1) <> "\", "\", "") & "UC_BT_I.DBF"
			'UPGRADE_WARNING: Dir has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
			If Trim(Dir(lstrArq)) <> "" Then
				lstrDbf = "SELECT * FROM [UC_BT_I#DBF] ORDER BY COD_ID ASC"
				lrstAux = icnxDbf.Execute(lstrDbf)
				With lrstAux
					If .State = ADODB.ObjectStateEnum.adStateOpen Then
						'
						'Conta os registros pois arquivo DBF não tem suporte ao RecordCount
						'
						Call .MoveFirst()
						While Not .EOF
							llngRec = llngRec + 1
							Call .MoveNext()
						End While
						Call .MoveFirst()
						If llngRec > 0 Then
							Call Executar("DELETE FROM " & gstrDataBase & ".`prodist_consumidor_bt` ")
							Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, llngRec, " Carregando DBF Indra UC_BT ")
							Call Executar("START TRANSACTION", False,  , False)
							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"'
								lstrCod = Trim(IIf(IsDbNull(.Fields("COD_ID").value), "", .Fields("COD_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"'
								lstrRam = Trim(IIf(IsDbNull(.Fields("RAMAL").value), "", .Fields("RAMAL").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"'
								lstrDis = Trim(IIf(IsDbNull(.Fields("DIST").value), "", .Fields("DIST").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"'
								lstrFas = Trim(IIf(IsDbNull(.Fields("FAS_CON").value), "", .Fields("FAS_CON").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"'
								lstrGru = Trim(IIf(IsDbNull(.Fields("GRU_TEN").value), "", .Fields("GRU_TEN").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"'
								lstrSit = Trim(IIf(IsDbNull(.Fields("SIT_ATIV").value), "", .Fields("SIT_ATIV").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"'
								ldblPot = CDbl(IIf(IsDbNull(.Fields("POT_INST").value), 0, .Fields("POT_INST").value))
								lstrZon = "001"
								lstrLiv = VB.Left(lstrCod, 2)
								lstrCon = "00" & VB.Right(lstrCod, 4)
								lstrMed = BuscaNumeroMedidor(IIf(lstrLiv <> "99", "B", "A"), lstrZon, lstrLiv, lstrCon)
								lstrSql = ""
								lstrSql = lstrSql & "INSERT INTO " & gstrDataBase & ".`prodist_consumidor_bt` "
								lstrSql = lstrSql & " (`zona`,`livro`,`conta`,`ramal`,`dist`,`fas_con`,`gru_ten`,`sit_ativ`,`pot_inst`,`medidor`) VALUES("
								lstrSql = lstrSql & "'" & lstrZon & "','" & lstrLiv & "','" & lstrCon & "','" & lstrRam & "','" & lstrDis & "','" & lstrFas & "','BT','" & lstrSit & "',"
								lstrSql = lstrSql & Replace(CStr(ldblPot), ",", ".") & ","
								lstrSql = lstrSql & "'" & lstrMed & "') "
								Call Executar(lstrSql, False,  , False)
								If Me.chkMedidor.CheckState = System.Windows.Forms.CheckState.Checked Then
									Call Executar("INSERT INTO " & gstrDataBase & ".`prodist_medidor` (`cod_id`) VALUES('" & lstrMed & "') ", False,  , False)
								End If
								Call .MoveNext()
								Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1,  , " Carregando DBF Indra UC_BT ")
							End While
							Call Executar("COMMIT", False,  , False)
						End If
						Call .Close()
					End If
				End With
			Else
				Call MsgBox("O arquivo UC_BT.DBF da Indra não se encontra no local especificado!", MsgBoxStyle.Critical, gstrTituloMensagem)
			End If
		End If
		'
		'Valida se existe na pasta selecionada o arquivo UC_MT.DBF
		'
		If Me.chkMt.CheckState = System.Windows.Forms.CheckState.Checked Then
			lstrArq = Me.txtDir.Text & IIf(VB.Right(Trim(Me.txtDir.Text), 1) <> "\", "\", "") & "UC_MT_I.DBF"
			llngRec = 0
			'UPGRADE_WARNING: Dir has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
			If Trim(Dir(lstrArq)) <> "" Then
				lstrDbf = "SELECT * FROM [UC_MT_I#DBF] ORDER BY COD_ID ASC"
				lrstAux = icnxDbf.Execute(lstrDbf)
				With lrstAux
					If .State = ADODB.ObjectStateEnum.adStateOpen Then
						'
						'Conta os registros pois arquivo DBF não tem suporte ao RecordCount
						'
						Call .MoveFirst()
						While Not .EOF
							llngRec = llngRec + 1
							Call .MoveNext()
						End While
						Call .MoveFirst()
						If llngRec > 0 Then
							Call Executar("DELETE FROM " & gstrDataBase & ".`prodist_consumidor_mt` ")
							Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, llngRec, " Carregando DBF Indra UC_MT ")
							Call Executar("START TRANSACTION", False,  , False)
							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"'
								lstrCod = Trim(IIf(IsDbNull(.Fields("COD_ID").value), "", .Fields("COD_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"'
								lstrPnc = Trim(IIf(IsDbNull(.Fields("PN_CON").value), "", .Fields("PN_CON").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"'
								lstrSdm = Trim(IIf(IsDbNull(.Fields("SDMT_CON").value), "", .Fields("SDMT_CON").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"'
								lstrDis = Trim(IIf(IsDbNull(.Fields("DIST").value), "", .Fields("DIST").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"'
								lstrFas = Trim(IIf(IsDbNull(.Fields("FAS_CON").value), "", .Fields("FAS_CON").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"'
								lstrGru = Trim(IIf(IsDbNull(.Fields("GRU_TEN").value), "", .Fields("GRU_TEN").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"'
								lstrSit = Trim(IIf(IsDbNull(.Fields("SIT_ATIV").value), "", .Fields("SIT_ATIV").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"'
								ldblPot = System.Math.Abs(IIf(IsDbNull(.Fields("POT_INST").value), 0, .Fields("POT_INST").value))
								lstrZon = "001"
								lstrLiv = VB.Left(lstrCod, 2)
								lstrCon = "00" & VB.Right(lstrCod, 4)
								lstrMed = BuscaNumeroMedidor("A", lstrZon, lstrLiv, lstrCon)
								lstrSql = ""
								lstrSql = lstrSql & "INSERT INTO " & gstrDataBase & ".`prodist_consumidor_mt` "
								lstrSql = lstrSql & " (`zona`,`livro`,`conta`,`pn_con`,`sdmt_con`,`dist`,`fas_con`,`gru_ten`,`sit_ativ`,`pot_inst`,`med_01`) VALUES("
								lstrSql = lstrSql & "'" & lstrZon & "','" & lstrLiv & "','" & lstrCon & "','" & lstrPnc & "','" & lstrSdm & "','" & lstrDis & "','" & lstrFas & "','MT','" & lstrSit & "',"
								lstrSql = lstrSql & Replace(CStr(ldblPot), ",", ".") & ", "
								lstrSql = lstrSql & "'" & lstrMed & "') "
								Call Executar(lstrSql, False,  , False)
								If Me.chkMedidor.CheckState = System.Windows.Forms.CheckState.Checked Then
									Call Executar("INSERT INTO " & gstrDataBase & ".`prodist_medidor` (`cod_id`) VALUES('" & lstrMed & "') ", False,  , False)
								End If
								Call .MoveNext()
								Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1,  , " Carregando DBF Indra UC_MT ")
							End While
							Call Executar("COMMIT", False,  , False)
						End If
						Call .Close()
					End If
				End With
			Else
				Call MsgBox("O arquivo UC_MT.DBF da Indra não se encontra no local especificado!", MsgBoxStyle.Critical, gstrTituloMensagem)
			End If
		End If
ErroCarregaDbfIndra: 
		If icnxDbf.Errors.Count > 0 Then
			Call MsgBox(icnxDbf.Errors.Item(0).Number & " - " & icnxDbf.Errors.Item(0).NativeError & " - " & icnxDbf.Errors.Item(0).Description, MsgBoxStyle.Exclamation, gstrTituloMensagem)
			lblnRet = False
		Else
			If Err.Number > 0 Then
				Call MsgBox(Err.Number & " - " & Err.Description, MsgBoxStyle.Exclamation, gstrTituloMensagem)
				lblnRet = False
			End If
		End If
		If Not lblnRet Then
			Call Executar("ROLLBACK", False,  , False)
		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
		If icnxDbf.State = ADODB.ObjectStateEnum.adStateOpen Then icnxDbf.Close()
		CarregaDbfIndra = lblnRet
	End Function
	
	Private Function BuscaDadosdoSgd() As Boolean
		Dim lstrZona As String
		Dim lstrLivro As String
		Dim lstrConta As String
		Dim lstrContaGD As String
		Dim lstrGrupo As String
		Dim lstrMedidor As String
		Dim lblnRet As Boolean
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		On Error GoTo ErroBuscaDadoSGD
		lblnRet = True
		Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
		Call BarraProgresso((Me.ProgressBarProc), (Me.lblPercProc), (Me.lblInfoProc), 1,  , " Dados SGD ")
		Me.lblInfo.Text = " Aguarde, limpandp as tabelas..."
		Call Me.lblInfo.Refresh()
		If Me.chkBt.CheckState = System.Windows.Forms.CheckState.Checked Then
			Call Executar("DELETE FROM " & gstrDataBase & ".`prodist_consumidor_bt` ")
		End If
		If Me.chkMt.CheckState = System.Windows.Forms.CheckState.Checked Then
			Call Executar("DELETE FROM " & gstrDataBase & ".`prodist_consumidor_mt` ")
		End If
		If Me.chkMedidor.CheckState = System.Windows.Forms.CheckState.Checked Then
			Call Executar("DELETE FROM " & gstrDataBase & ".`prodist_medidor` ")
		End If
		'
		Me.lblInfo.Text = " Aguarde, conectando no oracle para buscar os consumidores LT"
		Call Me.lblInfo.Refresh()
		'
		Call CarregaOracleProvider(VB6.GetItemString(Me.cmbBaseDados, Me.cmbBaseDados.SelectedIndex), UCase(Me.txtUserSgd.Text), Me.txtPassSgd.Text)
		'
		lstrSql = ""
		lstrSql = lstrSql & "SELECT * FROM " & UCase(Me.txtUserSgd.Text) & ".CONSUMIDOR_LT "
		Call ConectarOrcl(lstrSql, lrstAux)
		With lrstAux
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				If .RecordCount > 0 Then
					Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, .RecordCount, " (SGD) ")
					Call Executar("START TRANSACTION",  ,  , False)
					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"'
						lstrContaGD = IIf(IsDbNull(.Fields("CONTA").value), "", .Fields("CONTA").value)
						If gstrEmpresa_Sigla = "CERGAL" Then
							lstrZona = VB.Left(lstrContaGD, 3)
							lstrLivro = Mid(lstrContaGD, 4, 2)
							lstrConta = "0" & VB.Right(lstrContaGD, 5)
						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"'
						lstrGrupo = IIf(IsDbNull(.Fields("GRUPO").value), "", .Fields("GRUPO").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 = IIf(IsDbNull(.Fields("MEDIDOR").value), "", .Fields("MEDIDOR").value)
						If lstrGrupo = "B" Then
							If Me.chkBt.CheckState = System.Windows.Forms.CheckState.Checked Then
								Call Executar("INSERT INTO " & gstrDataBase & ".`prodist_consumidor_bt` (`zona`,`livro`,`conta`) VALUES('" & lstrZona & "','" & lstrLivro & "','" & lstrConta & "') ", False,  , False)
							End If
						Else
							If Me.chkMt.CheckState = System.Windows.Forms.CheckState.Checked Then
								Call Executar("INSERT INTO " & gstrDataBase & ".`prodist_consumidor_mt` (`zona`,`livro`,`conta`) VALUES('" & lstrZona & "','" & lstrLivro & "','" & lstrConta & "') ", False,  , False)
							End If
						End If
						If Me.chkMedidor.CheckState = System.Windows.Forms.CheckState.Checked Then
							Call Executar("INSERT INTO " & gstrDataBase & ".`prodist_medidor` (`cod_id`) VALUES('" & lstrMedidor & "') ", False,  , False)
						End If
						Call .MoveNext()
						Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1,  , " (SGD) ")
					End While
				End If
				Call Executar("COMMIT",  ,  , False)
				Call .Close()
			End If
		End With
ErroBuscaDadoSGD: 
		If Err.Number > 0 Then
			Call Executar("ROLLBACK",  ,  , False)
			lblnRet = False
		End If
		If gadoOraclCx.State = ADODB.ObjectStateEnum.adStateOpen Then gadoOraclCx.Close()
		'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
		Me.Cursor = System.Windows.Forms.Cursors.Default
		BuscaDadosdoSgd = lblnRet
	End Function
	
	Private Sub frmBdgd_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
		'UPGRADE_NOTE: Object ifrmDir 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"'
		ifrmDir = Nothing
		'UPGRADE_NOTE: Object icnxDbf 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"'
		icnxDbf = Nothing
	End Sub
	
	'UPGRADE_WARNING: Event txtDir.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 txtDir_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtDir.TextChanged
		Dim lstrArq As String
		Dim lstrCam As String
		lstrCam = Me.txtDir.Text & IIf(VB.Right(Trim(Me.txtDir.Text), 1) <> "\", "\", "")
		'lstrArq = lstrCam & "tnsnames.ora"
		'If Strings.Trim(FileSystem.Dir(lstrArq)) <> "" Then
		'Call CarregaArquivo(lstrArq, Me.cmbBaseDados)
		Call GravaConfig("PRODIST_CAMINHO_TNSNAMES", Replace(Me.txtDir.Text & IIf(VB.Right(Trim(Me.txtDir.Text), 1) <> "\", "\", ""), "\", "\\"))
		'Else
		'  Call MsgBox("Caminho do TNSNAME.ORA inválido!", vbExclamation, gstrTituloMensagem)
		'End If
	End Sub
	
	Private Sub CarregaArquivo(ByVal astrArq As String, ByRef acmbAux As System.Windows.Forms.ComboBox)
		Dim lstrLin As String
		Dim lintARQ As Short
		Dim lintAux As Short
		Dim larrIte() As String
		Dim llngTotLin As Integer
		Dim lintLin As Short
		Dim lstrAux As String
		'
		On Error GoTo ErrorCarregaArquivo
		llngTotLin = 0
		lintLin = 0
		'
		'Conta quantidade de linhas do arquivo
		lintARQ = FreeFile
		FileOpen(lintARQ, astrArq, OpenMode.Input)
		While Not EOF(lintARQ)
			lstrLin = LineInput(lintARQ)
			llngTotLin = llngTotLin + 1
			System.Windows.Forms.Application.DoEvents()
		End While
		FileClose(lintARQ)
		With acmbAux
			Call .Items.Clear()
		End With
		lintARQ = FreeFile
		FileOpen(lintARQ, astrArq, OpenMode.Input)
		Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, llngTotLin)
		While Not EOF(lintARQ)
			lstrLin = LineInput(lintARQ)
			If InStr(1, lstrLin, "SERVICE_NAME") > 0 Then
				lstrAux = Replace(Replace(Replace(Replace(Trim(lstrLin), "(", ""), ")", ""), "SERVICE_NAME", ""), "=", "")
				With acmbAux
					Call .Items.Add(Trim(lstrAux))
				End With
			End If
			lintLin = lintLin + 1
			Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1)
		End While
		With acmbAux
			If .Items.Count > 1 Then
				.SelectedIndex = 0
			Else
				.SelectedIndex = -1
			End If
		End With
ErrorCarregaArquivo: 
		FileClose(lintARQ)
		If Err.Number > 0 Then
			Call MsgBox(Err.Number & " - " & Err.Description, MsgBoxStyle.Exclamation, gstrTituloMensagem)
		End If
	End Sub
	
	Private Function PreencheDadosUnidades() As Boolean
		'
		Dim lstrGrA As String
		Dim lstrGru As String
		Dim lstrZon As String
		Dim lstrLiv As String
		Dim lstrCon As String
		Dim llngUid As Integer
		Dim llngCId As Integer
		Dim lstrSit As String
		Dim llngIdM As Integer
		Dim lstrMed As String
		Dim lstrFLi As String
		Dim lstrTen As String
		Dim lstrCla As String
		Dim lstrFCl As String
		Dim ldblCrg As Double
		Dim lstrIte As String
		Dim ldteLig As Date
		Dim ldteRel As Date
		Dim ldteEnt As Date
		Dim lstrRam As String
		Dim lstrPnc As String
		Dim lstrSdm As String
		Dim lblnFat As Boolean
		Dim lblnCon As Boolean
		Dim lstrCod As String
		'UPGRADE_WARNING: Lower bound of array ldblDem 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 ldblDem(12) As Double
		'
		Dim lintTiF As Short
		Dim lstrFas As String
		Dim lstrA1 As String
		Dim lstrA2 As String
		Dim lstrA3 As String
		Dim lstrA4 As String
		Dim lstrA5 As String
		Dim lstrA6 As String
		Dim ldteIns As Date
		'
		Dim lintAux As Short
		Dim lblnRet As Boolean
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		On Error GoTo ErroPreencheDadosUnidades
		Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
		Call BarraProgresso((Me.ProgressBarProc), (Me.lblPercProc), (Me.lblInfoProc), 1,  , " Dados SGD ")
		lblnRet = True
		'
		'Grupo B
		'
		If Me.chkBt.CheckState = System.Windows.Forms.CheckState.Checked Then
			Me.lblInfo.Text = " Aguarde, buscando os dados do Grupo B."
			Call Me.lblInfo.Refresh()
			lstrSql = ""
			lstrSql = lstrSql & "SELECT IFNULL(IFNULL(unida.zona,unidb.zona),prodist_consumidor_bt.zona) zona, "
			lstrSql = lstrSql & "       IFNULL(IFNULL(unida.livro,unidb.livro),prodist_consumidor_bt.livro) livro, "
			lstrSql = lstrSql & "       IFNULL(IFNULL(unida.conta,unidb.conta),prodist_consumidor_bt.conta) conta, "
			lstrSql = lstrSql & "       IFNULL(unida.unid_id,unidb.unid_id) unid_id, "
			lstrSql = lstrSql & "       IFNULL(unida.cons_id,unidb.cons_id) cons_id, "
			lstrSql = lstrSql & "       IFNULL(unida.eletr,unidb.num) num, "
			lstrSql = lstrSql & "       IFNULL(unida.situacao,unidb.situacao) situacao, "
			lstrSql = lstrSql & "       IFNULL(unida.faselig,unidb.faselig) faselig, "
			lstrSql = lstrSql & "       IFNULL(unida.tensao,unidb.tensao) tensao, "
			lstrSql = lstrSql & "       IFNULL(unida.clas,unidb.clas) clas, "
			lstrSql = lstrSql & "       IFNULL(unida.carga,unidb.carga) carga, "
			lstrSql = lstrSql & "       IFNULL(unida.data_ligacao,unidb.data_ligacao) data_ligacao, "
			lstrSql = lstrSql & "       IFNULL(unida.data_religacao,unidb.data_religacao) data_religacao, "
			lstrSql = lstrSql & "       IFNULL(unida.data_entrada,unidb.data_entrada) data_entrada "
			lstrSql = lstrSql & "  FROM " & gstrDataBase & ".`prodist_consumidor_bt` "
			lstrSql = lstrSql & " LEFT JOIN `unidb` ON(`unidb`.`situacao` <> 'N' AND `unidb`.`zona` = `prodist_consumidor_bt`.`zona` AND `unidb`.`livro` = `prodist_consumidor_bt`.`livro` AND `unidb`.`conta` = `prodist_consumidor_bt`.`conta`) "
			lstrSql = lstrSql & " LEFT JOIN `unida` ON(`unida`.`situacao` <> 'N' AND `unida`.`zona` = `prodist_consumidor_bt`.`zona` AND `unida`.`livro` = `prodist_consumidor_bt`.`livro` AND `unida`.`conta` = `prodist_consumidor_bt`.`conta`) "
			'    lstrSql = ""
			'    lstrSql = lstrSql & "SELECT * "
			'    lstrSql = lstrSql & "  FROM " & gstrDataBase & ".`unidb`, " & gstrDataBase & ".`prodist_consumidor_bt` "
			'    lstrSql = lstrSql & " WHERE `unidb`.`situacao` <> 'N' "
			'    lstrSql = lstrSql & "   AND `unidb`.`zona` = `prodist_consumidor_bt`.`zona` "
			'    lstrSql = lstrSql & "   AND `unidb`.`livro` = `prodist_consumidor_bt`.`livro` "
			'    lstrSql = lstrSql & "   AND `unidb`.`conta` = `prodist_consumidor_bt`.`conta` "
			Call Conectar(lstrSql, lrstAux, False)
			'Call toClip(lstrSql)
			With lrstAux
				If .State = ADODB.ObjectStateEnum.adStateOpen Then
					If .RecordCount > 0 Then
						Call Executar("START TRANSACTION", False,  , False)
						Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, .RecordCount, " (Grupo B) ")
						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"'
							lstrZon = 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"'
							lstrLiv = 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"'
							lstrCon = 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"'
							llngUid = 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"'
							llngCId = CInt(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"'
							lstrMed = Trim(IIf(IsDbNull(.Fields("num").value), "", .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"'
							lstrSit = Trim(IIf(IsDbNull(.Fields("situacao").value), "L", .Fields("situacao").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"'
							lstrFLi = Trim(IIf(IsDbNull(.Fields("faselig").value), "0", .Fields("faselig").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"'
							lstrTen = Trim(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"'
							lstrCla = Trim(IIf(IsDbNull(.Fields("clas").value), "", .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"'
							ldblCrg = CDbl(IIf(IsDbNull(.Fields("carga").value), "0", .Fields("carga").value))
							ldblCrg = ldblCrg / 1000
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							ldteLig = CDate(IIf(IsDbNull(.Fields("data_ligacao").value), "1900-01-01", .Fields("data_ligacao").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"'
							ldteRel = CDate(IIf(IsDbNull(.Fields("data_religacao").value), "1900-01-01", .Fields("data_religacao").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"'
							ldteEnt = CDate(IIf(IsDbNull(.Fields("data_entrada").value), "1900-01-01", .Fields("data_entrada").value))
							If ldteLig > Me.dtpBase.value Then
								lblnFat = VerificaSeExisteFatura(lstrZon, lstrLiv, lstrCon, llngUid, "B")
							Else
								lblnFat = True
							End If
							'            If lstrLiv = "01" And lstrCon = "000015" Then
							'              Clipboard.Clear
							'            End If
							If ldteLig <= Me.dtpBase.value Or lblnFat Then
								lstrGrA = "B"
								If lstrLiv = "99" Then
									If lstrCon = "000055" Or lstrCon = "003500" Then
										lstrGrA = "A"
									End If
								End If
								Call BuscaConsumoUnidades("B", llngUid, CInt(VB6.Format(Me.dtpBase.value, "yyyyMM")),  , 0, lstrFCl, lstrGrA)
								lstrSql = ""
								lstrSql = lstrSql & "UPDATE " & gstrDataBase & ".`prodist_consumidor_bt` SET " & vbCrLf
								lstrSql = lstrSql & "`clas_sub` = '" & BuscaTCLA_SUBCLA(lstrCla) & "', " & vbCrLf
								lstrSql = lstrSql & "`ten_forn` = '" & BuscaTTEN(lstrTen) & "', " & vbCrLf
								lstrSql = lstrSql & "`gru_tar` = '" & BuscaTGRU_TAR(lstrCla, "B", lstrFCl) & "', " & vbCrLf
								If (lstrSit = "L" Or lstrSit = "C") Then
									lstrSql = lstrSql & "`sit_ativ` = 'SM', " & vbCrLf
								Else
									lstrSql = lstrSql & "`sit_ativ` = 'NO', " & vbCrLf
								End If
								If ldteLig > Me.dtpBase.value And ldteEnt <= Me.dtpBase.value Then
									lstrSql = lstrSql & "`dat_con` = '" & VB6.Format(ldteEnt, "yyyy-MM-dd") & "', " & vbCrLf
								ElseIf ldteLig > Me.dtpBase.value And ldteRel <= Me.dtpBase.value Then 
									lstrSql = lstrSql & "`dat_con` = '" & VB6.Format(ldteRel, "yyyy-MM-dd") & "', " & vbCrLf
								Else
									lstrSql = lstrSql & "`dat_con` = '" & VB6.Format(ldteLig, "yyyy-MM-dd") & "', " & vbCrLf
								End If
								If ldblCrg > 0 Then
									lstrSql = lstrSql & "`pot_inst` = '" & Replace(Replace(VB6.Format(ldblCrg, "#,#####0.00000"), ".", ""), ",", ".") & "', " & vbCrLf
								Else
									lstrSql = lstrSql & "`pot_inst` = '" & Replace(Replace(VB6.Format(1, "#,#####0.00000"), ".", ""), ",", ".") & "', " & vbCrLf
								End If
								lstrSql = lstrSql & "`ene_01` = '" & Replace(Replace(VB6.Format(idblEne(1), "#,###0.000"), ".", ""), ",", ".") & "', " & vbCrLf
								lstrSql = lstrSql & "`ene_02` = '" & Replace(Replace(VB6.Format(idblEne(2), "#,###0.000"), ".", ""), ",", ".") & "', " & vbCrLf
								lstrSql = lstrSql & "`ene_03` = '" & Replace(Replace(VB6.Format(idblEne(3), "#,###0.000"), ".", ""), ",", ".") & "', " & vbCrLf
								lstrSql = lstrSql & "`ene_04` = '" & Replace(Replace(VB6.Format(idblEne(4), "#,###0.000"), ".", ""), ",", ".") & "', " & vbCrLf
								lstrSql = lstrSql & "`ene_05` = '" & Replace(Replace(VB6.Format(idblEne(5), "#,###0.000"), ".", ""), ",", ".") & "', " & vbCrLf
								lstrSql = lstrSql & "`ene_06` = '" & Replace(Replace(VB6.Format(idblEne(6), "#,###0.000"), ".", ""), ",", ".") & "', " & vbCrLf
								lstrSql = lstrSql & "`ene_07` = '" & Replace(Replace(VB6.Format(idblEne(7), "#,###0.000"), ".", ""), ",", ".") & "', " & vbCrLf
								lstrSql = lstrSql & "`ene_08` = '" & Replace(Replace(VB6.Format(idblEne(8), "#,###0.000"), ".", ""), ",", ".") & "', " & vbCrLf
								lstrSql = lstrSql & "`ene_09` = '" & Replace(Replace(VB6.Format(idblEne(9), "#,###0.000"), ".", ""), ",", ".") & "', " & vbCrLf
								lstrSql = lstrSql & "`ene_10` = '" & Replace(Replace(VB6.Format(idblEne(10), "#,###0.000"), ".", ""), ",", ".") & "', " & vbCrLf
								lstrSql = lstrSql & "`ene_11` = '" & Replace(Replace(VB6.Format(idblEne(11), "#,###0.000"), ".", ""), ",", ".") & "', " & vbCrLf
								lstrSql = lstrSql & "`ene_12` = '" & Replace(Replace(VB6.Format(idblEne(12), "#,###0.000"), ".", ""), ",", ".") & "', " & vbCrLf
								lstrSql = lstrSql & "`atualizado` = 1 "
								lstrSql = lstrSql & "WHERE `zona` = '" & lstrZon & "' " & vbCrLf
								lstrSql = lstrSql & "  AND `livro` = '" & lstrLiv & "' " & vbCrLf
								lstrSql = lstrSql & "  AND `conta` = '" & lstrCon & "' "
								Call Executar(lstrSql, True,  , False)
							End If
							
							Call .MoveNext()
							Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1,  , " (Grupo B) ")
						End While
					End If
					Call .Close()
					Call Executar("COMMIT", False,  , False)
				End If
			End With
		End If
		'
		'Grupo A
		'
		If Me.chkMt.CheckState = System.Windows.Forms.CheckState.Checked Then
			Me.lblInfo.Text = " Aguarde, buscando os dados do Grupo A."
			Call Me.lblInfo.Refresh()
			lstrSql = ""
			lstrSql = lstrSql & "SELECT * "
			lstrSql = lstrSql & "  FROM " & gstrDataBase & ".`unida`, " & gstrDataBase & ".`prodist_consumidor_mt` "
			lstrSql = lstrSql & " WHERE `unida`.`situacao` <> 'N' "
			lstrSql = lstrSql & "   AND `unida`.`zona` = `prodist_consumidor_mt`.`zona` "
			lstrSql = lstrSql & "   AND `unida`.`livro` = `prodist_consumidor_mt`.`livro` "
			lstrSql = lstrSql & "   AND `unida`.`conta` = `prodist_consumidor_mt`.`conta` "
			Call Conectar(lstrSql, lrstAux, False)
			With lrstAux
				If .State = ADODB.ObjectStateEnum.adStateOpen Then
					If .RecordCount > 0 Then
						Call Executar("START TRANSACTION", False,  , False)
						Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, .RecordCount, " (Grupo A) ")
						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"'
							lstrZon = 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"'
							lstrLiv = 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"'
							lstrCon = 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"'
							llngUid = 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"'
							llngCId = CInt(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"'
							lstrMed = Trim(IIf(IsDbNull(.Fields("eletr").value), "", .Fields("eletr").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"'
							lstrSit = Trim(IIf(IsDbNull(.Fields("situacao").value), "L", .Fields("situacao").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"'
							lstrFLi = Trim(IIf(IsDbNull(.Fields("faselig").value), "0", .Fields("faselig").value))
							If lstrFLi = "" Or lstrFLi = "0" Then lstrFLi = "ABCN"
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							lstrTen = Trim(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"'
							lstrCla = Trim(IIf(IsDbNull(.Fields("clas").value), "", .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"'
							ldblCrg = CDbl(IIf(IsDbNull(.Fields("carga").value), "0", .Fields("carga").value))
							ldblCrg = ldblCrg / 1000
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							ldteLig = CDate(IIf(IsDbNull(.Fields("data_ligacao").value), "1900-01-01", .Fields("data_ligacao").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"'
							ldteRel = CDate(IIf(IsDbNull(.Fields("data_religacao").value), "1900-01-01", .Fields("data_religacao").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"'
							ldteEnt = CDate(IIf(IsDbNull(.Fields("data_entrada").value), "1900-01-01", .Fields("data_entrada").value))
							If ldteLig > Me.dtpBase.value Then
								lblnFat = VerificaSeExisteFatura(lstrZon, lstrLiv, lstrCon, llngUid, "A")
							Else
								lblnFat = True
							End If
							If ldteLig <= Me.dtpBase.value Or lblnFat Then
								Call BuscaConsumoUnidades("A", llngUid, CInt(VB6.Format(Me.dtpBase.value, "yyyyMM")),  , 0, lstrFCl, "A")
							End If
							lstrSql = ""
							lstrSql = lstrSql & "UPDATE " & gstrDataBase & ".`prodist_consumidor_mt` SET " & vbCrLf
							lstrSql = lstrSql & "`clas_sub` = '" & BuscaTCLA_SUBCLA(lstrCla) & "', " & vbCrLf
							lstrSql = lstrSql & "`ten_forn` = '" & BuscaTTEN(lstrTen) & "', " & vbCrLf
							lstrSql = lstrSql & "`gru_tar` = '" & BuscaTGRU_TAR(lstrCla, "A", lstrFCl) & "', " & vbCrLf
							If (lstrSit = "L" Or lstrSit = "C") Then
								lstrSql = lstrSql & "`sit_ativ` = 'SM', " & vbCrLf
							Else
								lstrSql = lstrSql & "`sit_ativ` = 'NO', " & vbCrLf
							End If
							If ldteLig > Me.dtpBase.value And ldteEnt <= Me.dtpBase.value Then
								lstrSql = lstrSql & "`dat_con` = '" & VB6.Format(ldteEnt, "yyyy-MM-dd") & "', " & vbCrLf
							ElseIf ldteLig > Me.dtpBase.value And ldteRel <= Me.dtpBase.value Then 
								lstrSql = lstrSql & "`dat_con` = '" & VB6.Format(ldteRel, "yyyy-MM-dd") & "', " & vbCrLf
							Else
								lstrSql = lstrSql & "`dat_con` = '" & VB6.Format(ldteLig, "yyyy-MM-dd") & "', " & vbCrLf
							End If
							If ldblCrg > 0 Then
								lstrSql = lstrSql & "`pot_inst` = '" & Replace(Replace(VB6.Format(ldblCrg, "#,#####0.00000"), ".", ""), ",", ".") & "', " & vbCrLf
							Else
								lstrSql = lstrSql & "`pot_inst` = '" & Replace(Replace(VB6.Format(1, "#,#####0.00000"), ".", ""), ",", ".") & "', " & vbCrLf
							End If
							
							lstrSql = lstrSql & "`liv` = '" & IIf(lstrFCl = "01AL00", "V", "F") & "', " & vbCrLf
							lstrSql = lstrSql & "`dem_01` = '" & Replace(Replace(VB6.Format(idblDem(1), "#,###0.000"), ".", ""), ",", ".") & "', " & vbCrLf
							lstrSql = lstrSql & "`dem_02` = '" & Replace(Replace(VB6.Format(idblDem(2), "#,###0.000"), ".", ""), ",", ".") & "', " & vbCrLf
							lstrSql = lstrSql & "`dem_03` = '" & Replace(Replace(VB6.Format(idblDem(3), "#,###0.000"), ".", ""), ",", ".") & "', " & vbCrLf
							lstrSql = lstrSql & "`dem_04` = '" & Replace(Replace(VB6.Format(idblDem(4), "#,###0.000"), ".", ""), ",", ".") & "', " & vbCrLf
							lstrSql = lstrSql & "`dem_05` = '" & Replace(Replace(VB6.Format(idblDem(5), "#,###0.000"), ".", ""), ",", ".") & "', " & vbCrLf
							lstrSql = lstrSql & "`dem_06` = '" & Replace(Replace(VB6.Format(idblDem(6), "#,###0.000"), ".", ""), ",", ".") & "', " & vbCrLf
							lstrSql = lstrSql & "`dem_07` = '" & Replace(Replace(VB6.Format(idblDem(7), "#,###0.000"), ".", ""), ",", ".") & "', " & vbCrLf
							lstrSql = lstrSql & "`dem_08` = '" & Replace(Replace(VB6.Format(idblDem(8), "#,###0.000"), ".", ""), ",", ".") & "', " & vbCrLf
							lstrSql = lstrSql & "`dem_09` = '" & Replace(Replace(VB6.Format(idblDem(9), "#,###0.000"), ".", ""), ",", ".") & "', " & vbCrLf
							lstrSql = lstrSql & "`dem_10` = '" & Replace(Replace(VB6.Format(idblDem(10), "#,###0.000"), ".", ""), ",", ".") & "', " & vbCrLf
							lstrSql = lstrSql & "`dem_11` = '" & Replace(Replace(VB6.Format(idblDem(11), "#,###0.000"), ".", ""), ",", ".") & "', " & vbCrLf
							lstrSql = lstrSql & "`dem_12` = '" & Replace(Replace(VB6.Format(idblDem(12), "#,###0.000"), ".", ""), ",", ".") & "', " & vbCrLf
							lstrSql = lstrSql & "`ene_01` = '" & Replace(Replace(VB6.Format(idblEne(1), "#,###0.000"), ".", ""), ",", ".") & "', " & vbCrLf
							lstrSql = lstrSql & "`ene_02` = '" & Replace(Replace(VB6.Format(idblEne(2), "#,###0.000"), ".", ""), ",", ".") & "', " & vbCrLf
							lstrSql = lstrSql & "`ene_03` = '" & Replace(Replace(VB6.Format(idblEne(3), "#,###0.000"), ".", ""), ",", ".") & "', " & vbCrLf
							lstrSql = lstrSql & "`ene_04` = '" & Replace(Replace(VB6.Format(idblEne(4), "#,###0.000"), ".", ""), ",", ".") & "', " & vbCrLf
							lstrSql = lstrSql & "`ene_05` = '" & Replace(Replace(VB6.Format(idblEne(5), "#,###0.000"), ".", ""), ",", ".") & "', " & vbCrLf
							lstrSql = lstrSql & "`ene_06` = '" & Replace(Replace(VB6.Format(idblEne(6), "#,###0.000"), ".", ""), ",", ".") & "', " & vbCrLf
							lstrSql = lstrSql & "`ene_07` = '" & Replace(Replace(VB6.Format(idblEne(7), "#,###0.000"), ".", ""), ",", ".") & "', " & vbCrLf
							lstrSql = lstrSql & "`ene_08` = '" & Replace(Replace(VB6.Format(idblEne(8), "#,###0.000"), ".", ""), ",", ".") & "', " & vbCrLf
							lstrSql = lstrSql & "`ene_09` = '" & Replace(Replace(VB6.Format(idblEne(9), "#,###0.000"), ".", ""), ",", ".") & "', " & vbCrLf
							lstrSql = lstrSql & "`ene_10` = '" & Replace(Replace(VB6.Format(idblEne(10), "#,###0.000"), ".", ""), ",", ".") & "', " & vbCrLf
							lstrSql = lstrSql & "`ene_11` = '" & Replace(Replace(VB6.Format(idblEne(11), "#,###0.000"), ".", ""), ",", ".") & "', " & vbCrLf
							lstrSql = lstrSql & "`ene_12` = '" & Replace(Replace(VB6.Format(idblEne(12), "#,###0.000"), ".", ""), ",", ".") & "', " & vbCrLf
							lstrSql = lstrSql & "`atualizado` = 1 " & vbCrLf
							lstrSql = lstrSql & "WHERE `zona` = '" & lstrZon & "' " & vbCrLf
							lstrSql = lstrSql & "  AND `livro` = '" & lstrLiv & "' " & vbCrLf
							lstrSql = lstrSql & "  AND `conta` = '" & lstrCon & "' "
							Call Executar(lstrSql, True,  , False)
							Call .MoveNext()
							Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1,  , " (Grupo A) ")
						End While
					End If
					Call .Close()
					Call Executar("COMMIT", False,  , False)
				End If
			End With
		End If
		'
		'Medidor
		'
		If Me.chkMedidor.CheckState = System.Windows.Forms.CheckState.Checked Then
			Me.lblInfo.Text = " Aguarde, buscando os dados dos medidores."
			Call Me.lblInfo.Refresh()
			lstrSql = ""
			lstrSql = lstrSql & "SELECT DISTINCT "
			lstrSql = lstrSql & " `medidor`.`id`, "
			lstrSql = lstrSql & " `medidor`.`numero`, "
			lstrSql = lstrSql & " `medidor`.`id_tipo_fase`, "
			lstrSql = lstrSql & " `medidor`.`fase_ligacao`, "
			lstrSql = lstrSql & " `medidor`.`data_instalacao`, "
			lstrSql = lstrSql & " `material`.`tipo_bem`, "
			lstrSql = lstrSql & " `material`.`a2`, "
			lstrSql = lstrSql & " `material`.`a3`, "
			lstrSql = lstrSql & " `material`.`a4`, "
			lstrSql = lstrSql & " `material`.`a5`, "
			lstrSql = lstrSql & " `material`.`a6` "
			lstrSql = lstrSql & "  FROM " & gstrBDMLinkCenter & ".`medidor` "
			lstrSql = lstrSql & " LEFT JOIN " & istrBDVida & ".`material` on(`material`.`id` = `medidor`.`id_almox`), " & gstrDataBase & ".`prodist_medidor` "
			lstrSql = lstrSql & " WHERE `medidor`.`numero` = `prodist_medidor`.`cod_id` "
			Call Conectar(lstrSql, lrstAux, False)
			With lrstAux
				If .State = ADODB.ObjectStateEnum.adStateOpen Then
					If .RecordCount > 0 Then
						Call Executar("START TRANSACTION", False,  , False)
						Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, .RecordCount, " (Medidores) ")
						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"'
							llngIdM = CInt(IIf(IsDbNull(.Fields("id").value), "", .Fields("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"'
							lstrMed = Trim(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"'
							lintTiF = CShort(IIf(IsDbNull(.Fields("id_tipo_fase").value), 1, .Fields("id_tipo_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"'
							lstrFas = Trim(IIf(IsDbNull(.Fields("fase_ligacao").value), "", .Fields("fase_ligacao").value))
							If lstrFas = "" Then lstrFas = BuscaFaseLigacaoUc(lstrMed, CStr(lintTiF))
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							lstrA1 = Trim(IIf(IsDbNull(.Fields("tipo_bem").value), "0", .Fields("tipo_bem").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"'
							lstrA2 = Trim(IIf(IsDbNull(.Fields("a2").value), "0", .Fields("a2").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"'
							lstrA3 = Trim(IIf(IsDbNull(.Fields("a3").value), "0", .Fields("a3").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"'
							lstrA4 = Trim(IIf(IsDbNull(.Fields("a4").value), "0", .Fields("a4").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"'
							lstrA5 = Trim(IIf(IsDbNull(.Fields("a5").value), "0", .Fields("a5").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"'
							lstrA6 = Trim(IIf(IsDbNull(.Fields("a6").value), "0", .Fields("a6").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"'
							ldteIns = CDate(IIf(IsDbNull(.Fields("data_instalacao").value), "1900-01-01", .Fields("data_instalacao").value))
							
							If lstrA1 = "" Then lstrA1 = "00"
							If lstrA2 = "" Then lstrA2 = "00"
							If lstrA3 = "" Then lstrA3 = "00"
							If lstrA4 = "" Then lstrA4 = "00"
							If lstrA5 = "" Then lstrA5 = "00"
							If lstrA6 = "" Then lstrA6 = "00"
							lstrA1 = VB6.Format(lstrA1, "00")
							lstrA2 = VB6.Format(lstrA2, "00")
							lstrA3 = VB6.Format(lstrA3, "00")
							lstrA4 = VB6.Format(lstrA4, "00")
							lstrA5 = VB6.Format(lstrA5, "00")
							lstrA6 = VB6.Format(lstrA6, "00")
							lstrSql = ""
							lstrSql = lstrSql & "UPDATE " & gstrDataBase & ".`prodist_medidor` SET "
							lstrSql = lstrSql & "`dist` = '" & Trim(BuscaTDIST) & "', "
							lstrSql = lstrSql & "`tip_unid` = '" & Trim(CStr(lintTiF)) & "', "
							lstrSql = lstrSql & "`quan_fas` = '" & Trim(lstrFas) & "', "
							lstrSql = lstrSql & "`odi` = '7001', "
							lstrSql = lstrSql & "`ti` = '93', "
							lstrSql = lstrSql & "`cm` = '000', "
							lstrSql = lstrSql & "`tuc` = '295', "
							lstrSql = lstrSql & "`a1` = '" & lstrA1 & "', "
							lstrSql = lstrSql & "`a2` = '" & lstrA2 & "', "
							lstrSql = lstrSql & "`a3` = '" & lstrA3 & "', "
							lstrSql = lstrSql & "`a4` = '" & lstrA4 & "', "
							lstrSql = lstrSql & "`a5` = '" & lstrA5 & "', "
							lstrSql = lstrSql & "`a6` = '" & lstrA6 & "', "
							lstrSql = lstrSql & "`iduc` = '0', "
							lstrSql = lstrSql & "`uar` = '1', "
							lstrSql = lstrSql & "`dat_imo` = '" & VB6.Format(ldteIns, "yyyy-MM-dd") & "', "
							lstrSql = lstrSql & "`descr` = '', "
							lstrSql = lstrSql & "`atualizado` = 1 "
							lstrSql = lstrSql & "WHERE `cod_id` = '" & lstrMed & "' "
							Call Executar(lstrSql, True,  , False)
							Call .MoveNext()
							Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1,  , " (Medidores) ")
						End While
					End If
					Call .Close()
					Call Executar("COMMIT", False,  , False)
				End If
			End With
		End If
ErroPreencheDadosUnidades: 
		If Err.Number > 0 Then
			Call MsgBox(Err.Number & " - " & Err.Description, MsgBoxStyle.Exclamation, gstrTituloMensagem)
			lblnRet = False
			Call Executar("ROLLBACK", False,  , False)
		End If
		Me.Cursor = System.Windows.Forms.Cursors.Default
		'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
		PreencheDadosUnidades = lblnRet
	End Function
	
	Private Function VerificaSeExisteFatura(ByVal astrZona As String, ByVal astrLivro As String, ByVal astrConta As String, ByVal alngUnidId As Integer, ByVal astrGrupo As String) As Boolean
		Dim lblnRet As Boolean
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		On Error GoTo ErroVerificaSeExisteFatura
		lblnRet = False
		lstrSql = ""
		lstrSql = lstrSql & "SELECT * "
		lstrSql = lstrSql & "  FROM " & gstrDataBase & "`nf` "
		lstrSql = lstrSql & " WHERE (`mesano_ref`<= " & VB6.Format(Me.dtpBase.value, "yyyyMM")
		lstrSql = lstrSql & "   AND `grupo`   = '" & astrGrupo & "' "
		lstrSql = lstrSql & "   AND `zona`    = '" & astrZona & "' "
		lstrSql = lstrSql & "   AND `livro`   = '" & astrLivro & "' "
		lstrSql = lstrSql & "   AND `conta`   = '" & astrConta & "' "
		lstrSql = lstrSql & "   AND `unid_id` =  " & alngUnidId & " "
		lstrSql = lstrSql & " LIMIT 0, 1 "
		Call Conectar(lstrSql, lrstAux, False)
		With lrstAux
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				lblnRet = (.RecordCount > 0)
				Call .Close()
			End If
		End With
ErroVerificaSeExisteFatura: 
		If Err.Number > 0 Then
			Call MsgBox(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
		VerificaSeExisteFatura = lblnRet
	End Function
	
	Private Function BuscaTCLA_SUBCLA(ByVal astrCodClasse As String) As String
		Dim lstrRet As String
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		On Error GoTo ErroBuscaTCLA_SUBCLA
		lstrRet = ""
		lstrSql = ""
		lstrSql = lstrSql & "SELECT * "
		lstrSql = lstrSql & "  FROM `classe` "
		lstrSql = lstrSql & " WHERE `codigo` = '" & astrCodClasse & "' "
		Call Conectar(lstrSql, lrstAux, False)
		With lrstAux
			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"'
					lstrRet = Trim(IIf(IsDbNull(.Fields("tcla_subcla").value), "", .Fields("tcla_subcla").value))
				End If
				Call .Close()
			End If
		End With
ErroBuscaTCLA_SUBCLA: 
		If Err.Number > 0 Then
			Call MsgBox(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
		BuscaTCLA_SUBCLA = lstrRet
	End Function
	
	Private Function BuscaTDIST() As String
		Dim lstrAux As String
		Dim lstrRet As String
		Dim lstrDad As String
		lstrDad = "AES-SUL?1;ADESA?2;AMPLA?3;BANDEIRANTE?4;BOA VISTA ENERGIA?5;CAIUÁ?6;CEA?7;CEAL?8;CEB?9;CEEE?10;CELESC?11;CELG?12;CELPA?13;CELPE?14;CELTINS?15;CEMAR?16;CEMAT?17;CEMIG?18;CEPISA?19;CERON?20;CER?21;CFLO?22;CHESP?23;CJE?24;CLFM?25;CNEE?26;COCEL?27;COELBA?28;COELCE?29;COOPERALIANÇA?30;COPEL?31;COSERN?32;CPEE?33;CPFL SANTA CRUZ?34;CPFL PAULISTA?35;CPFL PIRATININGA?36;CSPE?37;DEMEI?38;DME-PC?39;EBO?40;EEB?41;EEVP?42;EFLJCL?43;EFLUL?44;ELEKTRO?45;ELETROACRE?46;ELETROCAR?47;ELETROPAULO?48;ELFSM?49;EMG?50;ENERSUL?51;ENF?52;EPB?53;ESCELSA?54;ESE?55;FORCEL?56;HIDROPAN?57;IENERGIA?58;LIGHT?59;MUX ENERGIA?60;RGE?61;SULGIPE?62;UHENPAL?63;CEREJ?64;CERAL?65;COORSEL?66;CERBRANORTE?67;CERAÇÁ?68;CERPALO?69;CERGRAL?70;CEJAMA?71;CERSUL?72;COOPERA?73;COOPERMILA?74;CERGAL?75;CERTAJA ENERGIA?76;CERAL-DIS?77;CERRP?78;CERNHE?79;CERES?80;CERCOS?81;CETRIL?82;CERPRO?83;CERMEC?84;CERIS?85;CERIPA?86;CERIM?87;CEDRI?88;CEDRAP?89;"
		If CInt(InStr(1, lstrDad, gstrEmpresa_Sigla)) > 0 Then
			lstrAux = Mid(lstrDad, CInt(InStr(1, lstrDad, gstrEmpresa_Sigla)))
			lstrRet = Mid(lstrAux, CInt(InStr(1, lstrAux, "?")) + 1, CInt(InStr(1, lstrAux, ";")) - (CInt(InStr(1, lstrAux, "?")) + 1))
		Else
			lstrRet = ""
		End If
		BuscaTDIST = lstrRet
	End Function
	
	Private Function BuscaTGRU_TAR(ByVal astrCodClasse As String, ByVal astrGrupo As String, ByVal astrCodClaBx As String) As String
		Dim lstrRet As String
		If astrGrupo = "B" Then
			If VB.Left(astrCodClasse, 2) = "64" Then
				lstrRet = "B4A"
				If VB.Left(astrCodClasse, 4) = "6402" Then
					lstrRet = "B4B"
				End If
			ElseIf VB.Left(astrCodClasse, 1) = "5" Then 
				lstrRet = "B2RU"
				If VB.Left(astrCodClasse, 2) = "52" Then
					lstrRet = "B2CO"
				ElseIf VB.Left(astrCodClasse, 2) = "54" Then 
					lstrRet = "B2SP"
				ElseIf VB.Left(astrCodClasse, 2) = "55" Then 
					lstrRet = "B2SP"
				End If
			ElseIf VB.Left(astrCodClasse, 1) = "9" Then 
				lstrRet = "B1"
				If astrCodClaBx = "9102" Or astrCodClaBx = "9104" Or astrCodClaBx = "9105" Or astrCodClaBx = "9106" Then
					lstrRet = "B1BR"
				End If
			Else
				lstrRet = "B3"
			End If
		Else
			lstrRet = "A4"
		End If
		BuscaTGRU_TAR = lstrRet
	End Function
	
	Private Function BuscaFaseLigacaoUc(ByVal astrMedidor As String, ByVal aintTipoFase As String) As String
		Dim lstrFas As String
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		On Error GoTo ErroBuscaFaseLigacaoUc
		lstrSql = ""
		lstrSql = lstrSql & "SELECT `uc`.`fase_ligacao` "
		lstrSql = lstrSql & "  FROM " & gstrBDCLinkCenter & ".`uc`, " & gstrBDMLinkCenter & ".`medidor` "
		lstrSql = lstrSql & " WHERE `uc`.`id_medidor` = `medidor`.`id` "
		lstrSql = lstrSql & "   AND `medidor`.`numero` = '" & Trim(astrMedidor) & "' "
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			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"'
					lstrFas = Trim(IIf(IsDbNull(.Fields("fase_ligacao").value), "", .Fields("fase_ligacao").value))
				End If
				Call .Close()
			End If
		End With
		If lstrFas = "" Then
			If CDbl(aintTipoFase) = 1 Then
				lstrFas = "AN"
			ElseIf CDbl(aintTipoFase) = 2 Then 
				lstrFas = "ABN"
			ElseIf CDbl(aintTipoFase) = 3 Then 
				lstrFas = "ABCN"
			End If
		End If
ErroBuscaFaseLigacaoUc: 
		If Err.Number > 0 Then
			Call MsgBox(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
		BuscaFaseLigacaoUc = lstrFas
	End Function
	
	Private Sub LigDes(ByVal ablnModo As Boolean)
		Me.dtpBase.Enabled = ablnModo
		Me.cmdPasta.Enabled = ablnModo
		Me.txtUserSgd.Enabled = ablnModo
		Me.txtPassSgd.Enabled = ablnModo
		Me.txtUserBdgd.Enabled = ablnModo
		Me.txtPassBdgd.Enabled = ablnModo
		Me.cmbBaseDados.Enabled = ablnModo
		Me.chkBt.Enabled = ablnModo
		Me.chkMedidor.Enabled = ablnModo
		Me.chkMt.Enabled = ablnModo
		Me.chkDbf.Enabled = ablnModo
		Me.cmdProcessar.Enabled = ablnModo
		Me.cmdFechar.Enabled = ablnModo
	End Sub
	
	Public Sub BuscaConsumoUnidades(ByVal astrGrupo As String, ByVal alngUnidId As Integer, ByVal alngAnoMes As Integer, Optional ByVal alngConsId As Integer = 0, Optional ByVal aintTipo As Short = 0, Optional ByRef astrCodClas As String = "", Optional ByVal astrGruAux As String = "")
		Dim lstrLiv As String
		Dim lstrCon As String
		Dim lintAux As Short
		Dim lstrIte As String
		Dim lstrGTa As String
		Dim ldblAux As Double
		Dim ldblDem As Double
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		'
		For lintAux = 1 To 12
			idblEne(lintAux) = 0
			idblDem(lintAux) = 0
		Next lintAux
		'
		lstrSql = ""
		lstrSql = lstrSql & "SELECT * "
		lstrSql = lstrSql & "  FROM " & gstrDataBase & ".`nf` "
		lstrSql = lstrSql & " WHERE `unid_id` = " & alngUnidId & " "
		lstrSql = lstrSql & "   AND `grupo` = '" & VB.Left(IIf(astrGrupo <> astrGruAux, astrGruAux, astrGrupo), 1) & "' "
		If alngConsId > 0 Then
			lstrSql = lstrSql & "   AND `cons_id` = " & alngConsId & " "
		End If
		lstrSql = lstrSql & "   AND `mesano_ref`  <= " & alngAnoMes & " "
		lstrSql = lstrSql & " ORDER BY mesano_ref DESC LIMIT 0, 12"
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				If .RecordCount > 0 Then
					lintAux = 1
					While Not .EOF
						If VB.Left(astrGrupo, 1) = "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"'
							astrCodClas = Trim(IIf(IsDbNull(.Fields("ta").value), "01A400", .Fields("ta").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"'
							astrCodClas = Trim(IIf(IsDbNull(.Fields("codclas").value), "", .Fields("codclas").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"'
						lstrIte = Trim(IIf(IsDbNull(.Fields("itensserv").value), "0", .Fields("itensserv").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"'
						lstrGTa = Mid(Trim(IIf(IsDbNull(.Fields("ta").value), "01B100", .Fields("ta").value)), 3, 2)
						If aintTipo = 1 Then 'Consumo faturado
							idblEne(lintAux) = BuscaVlrItem(lstrIte, "030201009") + BuscaVlrItem(lstrIte, "0302010009") + BuscaVlrItem(lstrIte, "0302010010") + BuscaVlrItem(lstrIte, "0302010011")
						ElseIf aintTipo = 0 Then  'Consumo lido
							idblEne(lintAux) = BuscaVlrItem(lstrIte, "030201008") + BuscaVlrItem(lstrIte, "0302010008") + BuscaVlrItem(lstrIte, "0302010010") + BuscaVlrItem(lstrIte, "0302010011")
						End If
						If lstrGTa = "AA" Or lstrGTa = "AV" Or lstrGTa = "AL" Or lstrGTa = "AX" Then
							ldblAux = BuscaVlrItem(lstrIte, "0302010019")
							ldblDem = BuscaVlrItem(lstrIte, "0302010023")
							If ldblAux > ldblDem Then
								ldblDem = ldblAux
							End If
						Else
							ldblDem = BuscaVlrItem(lstrIte, "0302010015")
						End If
						idblDem(lintAux) = ldblDem
						Call .MoveNext()
						lintAux = lintAux + 1
					End While
				End If
				Call .Close()
			End If
		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
	End Sub
	
	Private Function InsereAtualizaOracleBDGB() As Boolean
		Dim lstrConta As String
		Dim lstrZon As String
		Dim lstrLiv As String
		Dim lstrCon As String
		Dim lstrCla As String
		Dim lstrGru As String
		Dim lstrSit As String
		Dim ldteDat As Date
		'UPGRADE_WARNING: Lower bound of array ldblEne 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 ldblEne(12) As Double
		'UPGRADE_WARNING: Lower bound of array ldblDem 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 ldblDem(12) As Double
		'
		Dim lstrCodId As String
		Dim lstrDist As String
		Dim lstrTipUnid As String
		Dim lstrQuanFas As String
		Dim lstrOdi As String
		Dim lstrTi As String
		Dim lstrCm As String
		Dim lstrTuc As String
		Dim lstrA1 As String
		Dim lstrA2 As String
		Dim lstrA3 As String
		Dim lstrA4 As String
		Dim lstrA5 As String
		Dim lstrA6 As String
		Dim llngIdUc As Integer
		Dim llngUar As Integer
		Dim ldteImo As Date
		Dim lstrDescr As String
		'
		Dim lblnRet As String
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		On Error GoTo ErroInsereAtualizaOracleBDGB
		lblnRet = CStr(True)
		Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
		Call BarraProgresso((Me.ProgressBarProc), (Me.lblPercProc), (Me.lblInfoProc), 1,  , " Dados SGD ")
		'
		Me.lblInfo.Text = " Aguarde, conectando no oracle..."
		Call Me.lblInfo.Refresh()
		'
		Call CarregaOracleProvider(VB6.GetItemString(Me.cmbBaseDados, Me.cmbBaseDados.SelectedIndex), UCase(Me.txtUserBdgd.Text), Me.txtPassBdgd.Text)
		'
		Call gadoOraclCx.BeginTrans()
		If Me.chkBt.CheckState = System.Windows.Forms.CheckState.Checked Then
			Call gadoOraclCx.Execute("DELETE FROM " & UCase(Me.txtUserBdgd.Text) & ".CONSUMIDOR_BT ")
		End If
		If Me.chkMt.CheckState = System.Windows.Forms.CheckState.Checked Then
			Call gadoOraclCx.Execute("DELETE FROM " & UCase(Me.txtUserBdgd.Text) & ".CONSUMIDOR_MT ")
		End If
		If Me.chkMedidor.CheckState = System.Windows.Forms.CheckState.Checked Then
			Call gadoOraclCx.Execute("DELETE FROM " & UCase(Me.txtUserBdgd.Text) & ".MEDIDOR ")
		End If
		Call gadoOraclCx.CommitTrans()
		'
		'BT
		If Me.chkBt.CheckState = System.Windows.Forms.CheckState.Checked Then
			Me.lblInfo.Text = " Aguarde, buscando os dados dos consumidores BT..."
			Call Me.lblInfo.Refresh()
			lstrSql = ""
			lstrSql = lstrSql & "SELECT * FROM " & gstrDataBase & ".`prodist_consumidor_bt` WHERE `atualizado` = 1 "
			Call Conectar(lstrSql, lrstAux)
			With lrstAux
				If .State = ADODB.ObjectStateEnum.adStateOpen Then
					If .RecordCount > 0 Then
						Call gadoOraclCx.BeginTrans()
						Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, .RecordCount, " (BDGD - BT )")
						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"'
							lstrZon = 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"'
							lstrLiv = 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"'
							lstrCon = IIf(IsDbNull(.Fields("conta").value), "000000", .Fields("conta").value)
							If gstrEmpresa_Sigla = "CERGAL" Then
								lstrConta = lstrZon & lstrLiv & VB.Right(lstrCon, 5)
							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"'
							lstrCla = IIf(IsDbNull(.Fields("clas_sub").value), "RE1", .Fields("clas_sub").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"'
							lstrGru = IIf(IsDbNull(.Fields("gru_tar").value), "B1", .Fields("gru_tar").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"'
							lstrSit = IIf(IsDbNull(.Fields("sit_ativ").value), "SM", .Fields("sit_ativ").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"'
							ldteDat = IIf(IsDbNull(.Fields("dat_con").value), "1900-01-01", .Fields("dat_con").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"'
							ldblEne(1) = IIf(IsDbNull(.Fields("ene_01").value), 0, .Fields("ene_01").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"'
							ldblEne(2) = IIf(IsDbNull(.Fields("ene_02").value), 0, .Fields("ene_02").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"'
							ldblEne(3) = IIf(IsDbNull(.Fields("ene_03").value), 0, .Fields("ene_03").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"'
							ldblEne(4) = IIf(IsDbNull(.Fields("ene_04").value), 0, .Fields("ene_04").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"'
							ldblEne(5) = IIf(IsDbNull(.Fields("ene_05").value), 0, .Fields("ene_05").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"'
							ldblEne(6) = IIf(IsDbNull(.Fields("ene_06").value), 0, .Fields("ene_06").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"'
							ldblEne(7) = IIf(IsDbNull(.Fields("ene_07").value), 0, .Fields("ene_07").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"'
							ldblEne(8) = IIf(IsDbNull(.Fields("ene_08").value), 0, .Fields("ene_08").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"'
							ldblEne(9) = IIf(IsDbNull(.Fields("ene_09").value), 0, .Fields("ene_09").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"'
							ldblEne(10) = IIf(IsDbNull(.Fields("ene_10").value), 0, .Fields("ene_10").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"'
							ldblEne(11) = IIf(IsDbNull(.Fields("ene_11").value), 0, .Fields("ene_11").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"'
							ldblEne(12) = IIf(IsDbNull(.Fields("ene_12").value), 0, .Fields("ene_12").value)
							If VB.Left(lstrGru, 1) = "B" Then
								lstrSql = ""
								lstrSql = lstrSql & "INSERT INTO " & UCase(Me.txtUserBdgd.Text) & ".CONSUMIDOR_BT ( "
								lstrSql = lstrSql & " CONTA, "
								lstrSql = lstrSql & " CLAS_SUB, "
								lstrSql = lstrSql & " GRU_TAR, "
								lstrSql = lstrSql & " SIT_ATIV, "
								lstrSql = lstrSql & " DAT_CON, "
								lstrSql = lstrSql & " ENE_01, "
								lstrSql = lstrSql & " ENE_02, "
								lstrSql = lstrSql & " ENE_03, "
								lstrSql = lstrSql & " ENE_04, "
								lstrSql = lstrSql & " ENE_05, "
								lstrSql = lstrSql & " ENE_06, "
								lstrSql = lstrSql & " ENE_07, "
								lstrSql = lstrSql & " ENE_08, "
								lstrSql = lstrSql & " ENE_09, "
								lstrSql = lstrSql & " ENE_10, "
								lstrSql = lstrSql & " ENE_11, "
								lstrSql = lstrSql & " ENE_12  "
								lstrSql = lstrSql & ") VALUES ("
								lstrSql = lstrSql & "'" & lstrConta & "', " 'CONTA
								lstrSql = lstrSql & "'" & lstrCla & "', " 'CLAS_SUB
								lstrSql = lstrSql & "'" & lstrGru & "', " 'GRU_TAR
								lstrSql = lstrSql & "'" & lstrSit & "', " 'SIT_ATIV
								lstrSql = lstrSql & "'" & VB6.Format(ldteDat, "yyyy-MM-dd") & "', " 'DAT_CON
								lstrSql = lstrSql & "" & Replace(CStr(ldblEne(1)), ",", ".") & ", " 'ENE_01
								lstrSql = lstrSql & "" & Replace(CStr(ldblEne(2)), ",", ".") & ", " 'ENE_02
								lstrSql = lstrSql & "" & Replace(CStr(ldblEne(3)), ",", ".") & ", " 'ENE_03
								lstrSql = lstrSql & "" & Replace(CStr(ldblEne(4)), ",", ".") & ", " 'ENE_04
								lstrSql = lstrSql & "" & Replace(CStr(ldblEne(5)), ",", ".") & ", " 'ENE_05
								lstrSql = lstrSql & "" & Replace(CStr(ldblEne(6)), ",", ".") & ", " 'ENE_06
								lstrSql = lstrSql & "" & Replace(CStr(ldblEne(7)), ",", ".") & ", " 'ENE_07
								lstrSql = lstrSql & "" & Replace(CStr(ldblEne(8)), ",", ".") & ", " 'ENE_08
								lstrSql = lstrSql & "" & Replace(CStr(ldblEne(9)), ",", ".") & ", " 'ENE_09
								lstrSql = lstrSql & "" & Replace(CStr(ldblEne(10)), ",", ".") & ", " 'ENE_10
								lstrSql = lstrSql & "" & Replace(CStr(ldblEne(11)), ",", ".") & ", " 'ENE_11
								lstrSql = lstrSql & "" & Replace(CStr(ldblEne(12)), ",", ".") & " " 'ENE_12
								lstrSql = lstrSql & ")"
								'Call gadoOraclCx.BeginTrans
								Call gadoOraclCx.Execute(lstrSql)
								'Call gadoOraclCx.CommitTrans
							End If
							Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1,  , "(BDGD - BT)")
							Call .MoveNext()
						End While
						Call gadoOraclCx.CommitTrans()
					End If
					Call .Close()
				End If
			End With
		End If
		'MT
		If Me.chkMt.CheckState = System.Windows.Forms.CheckState.Checked Then
			Me.lblInfo.Text = " Aguarde, buscando os dados dos consumidores MT..."
			Call Me.lblInfo.Refresh()
			lstrSql = ""
			lstrSql = lstrSql & "SELECT * FROM " & gstrDataBase & ".`prodist_consumidor_mt` WHERE `atualizado` = 1 "
			Call Conectar(lstrSql, lrstAux)
			With lrstAux
				If .State = ADODB.ObjectStateEnum.adStateOpen Then
					If .RecordCount > 0 Then
						Call gadoOraclCx.BeginTrans()
						Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, .RecordCount, "(BDGD - MT )")
						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"'
							lstrZon = 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"'
							lstrLiv = 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"'
							lstrCon = IIf(IsDbNull(.Fields("conta").value), "", .Fields("conta").value)
							If gstrEmpresa_Sigla = "CERGAL" Then
								lstrConta = lstrZon & lstrLiv & VB.Right(lstrCon, 5)
							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"'
							lstrCla = IIf(IsDbNull(.Fields("clas_sub").value), "", .Fields("clas_sub").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"'
							lstrGru = IIf(IsDbNull(.Fields("gru_tar").value), "", .Fields("gru_tar").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"'
							lstrSit = IIf(IsDbNull(.Fields("sit_ativ").value), "SM", .Fields("sit_ativ").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"'
							ldteDat = IIf(IsDbNull(.Fields("dat_con").value), "1900-01-01", .Fields("dat_con").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"'
							ldblDem(1) = IIf(IsDbNull(.Fields("dem_01").value), 0, .Fields("dem_01").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"'
							ldblDem(2) = IIf(IsDbNull(.Fields("dem_02").value), 0, .Fields("dem_02").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"'
							ldblDem(3) = IIf(IsDbNull(.Fields("dem_03").value), 0, .Fields("dem_03").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"'
							ldblDem(4) = IIf(IsDbNull(.Fields("dem_04").value), 0, .Fields("dem_04").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"'
							ldblDem(5) = IIf(IsDbNull(.Fields("dem_05").value), 0, .Fields("dem_05").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"'
							ldblDem(6) = IIf(IsDbNull(.Fields("dem_06").value), 0, .Fields("dem_06").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"'
							ldblDem(7) = IIf(IsDbNull(.Fields("dem_07").value), 0, .Fields("dem_07").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"'
							ldblDem(8) = IIf(IsDbNull(.Fields("dem_08").value), 0, .Fields("dem_08").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"'
							ldblDem(9) = IIf(IsDbNull(.Fields("dem_09").value), 0, .Fields("dem_09").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"'
							ldblDem(10) = IIf(IsDbNull(.Fields("dem_10").value), 0, .Fields("dem_10").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"'
							ldblDem(11) = IIf(IsDbNull(.Fields("dem_11").value), 0, .Fields("dem_11").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"'
							ldblDem(12) = IIf(IsDbNull(.Fields("dem_12").value), 0, .Fields("dem_12").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"'
							ldblEne(1) = IIf(IsDbNull(.Fields("ene_01").value), 0, .Fields("ene_01").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"'
							ldblEne(2) = IIf(IsDbNull(.Fields("ene_02").value), 0, .Fields("ene_02").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"'
							ldblEne(3) = IIf(IsDbNull(.Fields("ene_03").value), 0, .Fields("ene_03").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"'
							ldblEne(4) = IIf(IsDbNull(.Fields("ene_04").value), 0, .Fields("ene_04").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"'
							ldblEne(5) = IIf(IsDbNull(.Fields("ene_05").value), 0, .Fields("ene_05").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"'
							ldblEne(6) = IIf(IsDbNull(.Fields("ene_06").value), 0, .Fields("ene_06").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"'
							ldblEne(7) = IIf(IsDbNull(.Fields("ene_07").value), 0, .Fields("ene_07").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"'
							ldblEne(8) = IIf(IsDbNull(.Fields("ene_08").value), 0, .Fields("ene_08").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"'
							ldblEne(9) = IIf(IsDbNull(.Fields("ene_09").value), 0, .Fields("ene_09").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"'
							ldblEne(10) = IIf(IsDbNull(.Fields("ene_10").value), 0, .Fields("ene_10").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"'
							ldblEne(11) = IIf(IsDbNull(.Fields("ene_11").value), 0, .Fields("ene_11").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"'
							ldblEne(12) = IIf(IsDbNull(.Fields("ene_12").value), 0, .Fields("ene_12").value)
							If VB.Left(lstrGru, 1) = "A" Then
								lstrSql = ""
								lstrSql = lstrSql & "INSERT INTO " & UCase(Me.txtUserBdgd.Text) & ".CONSUMIDOR_MT ( "
								lstrSql = lstrSql & " CONTA, "
								lstrSql = lstrSql & " CLAS_SUB, "
								lstrSql = lstrSql & " GRU_TAR, "
								lstrSql = lstrSql & " SIT_ATIV, "
								lstrSql = lstrSql & " DAT_CON, "
								lstrSql = lstrSql & " DEM_01, "
								lstrSql = lstrSql & " DEM_02, "
								lstrSql = lstrSql & " DEM_03, "
								lstrSql = lstrSql & " DEM_04, "
								lstrSql = lstrSql & " DEM_05, "
								lstrSql = lstrSql & " DEM_06, "
								lstrSql = lstrSql & " DEM_07, "
								lstrSql = lstrSql & " DEM_08, "
								lstrSql = lstrSql & " DEM_09, "
								lstrSql = lstrSql & " DEM_10, "
								lstrSql = lstrSql & " DEM_11, "
								lstrSql = lstrSql & " DEM_12,  "
								lstrSql = lstrSql & " ENE_01, "
								lstrSql = lstrSql & " ENE_02, "
								lstrSql = lstrSql & " ENE_03, "
								lstrSql = lstrSql & " ENE_04, "
								lstrSql = lstrSql & " ENE_05, "
								lstrSql = lstrSql & " ENE_06, "
								lstrSql = lstrSql & " ENE_07, "
								lstrSql = lstrSql & " ENE_08, "
								lstrSql = lstrSql & " ENE_09, "
								lstrSql = lstrSql & " ENE_10, "
								lstrSql = lstrSql & " ENE_11, "
								lstrSql = lstrSql & " ENE_12  "
								lstrSql = lstrSql & ") VALUES ("
								lstrSql = lstrSql & "'" & lstrConta & "', " 'CONTA
								lstrSql = lstrSql & "'" & lstrCla & "', " 'CLAS_SUB
								lstrSql = lstrSql & "'" & lstrGru & "', " 'GRU_TAR
								lstrSql = lstrSql & "'" & lstrSit & "', " 'SIT_ATIV
								lstrSql = lstrSql & "'" & VB6.Format(ldteDat, "yyyy-MM-dd") & "', " 'DAT_CON
								lstrSql = lstrSql & "" & Replace(CStr(ldblDem(1)), ",", ".") & ", " 'DEM_01
								lstrSql = lstrSql & "" & Replace(CStr(ldblDem(2)), ",", ".") & ", " 'DEM_02
								lstrSql = lstrSql & "" & Replace(CStr(ldblDem(3)), ",", ".") & ", " 'DEM_03
								lstrSql = lstrSql & "" & Replace(CStr(ldblDem(4)), ",", ".") & ", " 'DEM_04
								lstrSql = lstrSql & "" & Replace(CStr(ldblDem(5)), ",", ".") & ", " 'DEM_05
								lstrSql = lstrSql & "" & Replace(CStr(ldblDem(6)), ",", ".") & ", " 'DEM_06
								lstrSql = lstrSql & "" & Replace(CStr(ldblDem(7)), ",", ".") & ", " 'DEM_07
								lstrSql = lstrSql & "" & Replace(CStr(ldblDem(8)), ",", ".") & ", " 'DEM_08
								lstrSql = lstrSql & "" & Replace(CStr(ldblDem(9)), ",", ".") & ", " 'DEM_09
								lstrSql = lstrSql & "" & Replace(CStr(ldblDem(10)), ",", ".") & ", " 'DEM_10
								lstrSql = lstrSql & "" & Replace(CStr(ldblDem(11)), ",", ".") & ", " 'DEM_11
								lstrSql = lstrSql & "" & Replace(CStr(ldblDem(12)), ",", ".") & ", " 'DEM_12
								lstrSql = lstrSql & "" & Replace(CStr(ldblEne(1)), ",", ".") & ", " 'ENE_01
								lstrSql = lstrSql & "" & Replace(CStr(ldblEne(2)), ",", ".") & ", " 'ENE_02
								lstrSql = lstrSql & "" & Replace(CStr(ldblEne(3)), ",", ".") & ", " 'ENE_03
								lstrSql = lstrSql & "" & Replace(CStr(ldblEne(4)), ",", ".") & ", " 'ENE_04
								lstrSql = lstrSql & "" & Replace(CStr(ldblEne(5)), ",", ".") & ", " 'ENE_05
								lstrSql = lstrSql & "" & Replace(CStr(ldblEne(6)), ",", ".") & ", " 'ENE_06
								lstrSql = lstrSql & "" & Replace(CStr(ldblEne(7)), ",", ".") & ", " 'ENE_07
								lstrSql = lstrSql & "" & Replace(CStr(ldblEne(8)), ",", ".") & ", " 'ENE_08
								lstrSql = lstrSql & "" & Replace(CStr(ldblEne(9)), ",", ".") & ", " 'ENE_09
								lstrSql = lstrSql & "" & Replace(CStr(ldblEne(10)), ",", ".") & ", " 'ENE_10
								lstrSql = lstrSql & "" & Replace(CStr(ldblEne(11)), ",", ".") & ", " 'ENE_11
								lstrSql = lstrSql & "" & Replace(CStr(ldblEne(12)), ",", ".") & " " 'ENE_12
								lstrSql = lstrSql & ")"
								'Call gadoOraclCx.BeginTrans
								Call gadoOraclCx.Execute(lstrSql)
								'Call gadoOraclCx.CommitTrans
							End If
							Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1,  , "(BDGD - MT )")
							Call .MoveNext()
						End While
						Call gadoOraclCx.CommitTrans()
					End If
					Call .Close()
				End If
			End With
		End If
		'MEDIDOR
		If Me.chkMedidor.CheckState = System.Windows.Forms.CheckState.Checked Then
			Me.lblInfo.Text = " Aguarde, buscando os dados dos medidores...."
			Call Me.lblInfo.Refresh()
			lstrSql = ""
			lstrSql = lstrSql & "SELECT DISTINCT * FROM " & gstrDataBase & ".`prodist_medidor` WHERE `atualizado` = 1 "
			Call Conectar(lstrSql, lrstAux)
			With lrstAux
				If .State = ADODB.ObjectStateEnum.adStateOpen Then
					If .RecordCount > 0 Then
						Call gadoOraclCx.BeginTrans()
						Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, .RecordCount, " (BDGD - MEDIDOR) ")
						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"'
							lstrCodId = IIf(IsDbNull(.Fields("cod_id").value), "", .Fields("cod_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"'
							lstrDist = IIf(IsDbNull(.Fields("dist").value), "", .Fields("dist").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"'
							lstrTipUnid = IIf(IsDbNull(.Fields("tip_unid").value), "", .Fields("tip_unid").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"'
							lstrQuanFas = IIf(IsDbNull(.Fields("quan_fas").value), "", .Fields("quan_fas").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"'
							lstrOdi = IIf(IsDbNull(.Fields("odi").value), "", .Fields("odi").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"'
							lstrTi = IIf(IsDbNull(.Fields("ti").value), "", .Fields("ti").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"'
							lstrCm = IIf(IsDbNull(.Fields("cm").value), "", .Fields("cm").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"'
							lstrTuc = IIf(IsDbNull(.Fields("tuc").value), "", .Fields("tuc").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"'
							lstrA1 = IIf(IsDbNull(.Fields("a1").value), "", .Fields("a1").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"'
							lstrA2 = IIf(IsDbNull(.Fields("a2").value), "", .Fields("a2").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"'
							lstrA3 = IIf(IsDbNull(.Fields("a3").value), "", .Fields("a3").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"'
							lstrA4 = IIf(IsDbNull(.Fields("a4").value), "", .Fields("a4").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"'
							lstrA5 = IIf(IsDbNull(.Fields("a5").value), "", .Fields("a5").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"'
							lstrA6 = IIf(IsDbNull(.Fields("a6").value), "", .Fields("a6").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"'
							llngIdUc = IIf(IsDbNull(.Fields("iduc").value), 0, .Fields("iduc").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"'
							llngUar = IIf(IsDbNull(.Fields("uar").value), 0, .Fields("uar").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"'
							ldteImo = IIf(IsDbNull(.Fields("dat_imo").value), "1900-01-01", .Fields("dat_imo").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"'
							lstrDescr = IIf(IsDbNull(.Fields("descr").value), "", .Fields("descr").value)
							'
							lstrSql = ""
							lstrSql = lstrSql & "INSERT INTO " & UCase(Me.txtUserBdgd.Text) & ".MEDIDOR ( "
							lstrSql = lstrSql & " COD_ID, "
							lstrSql = lstrSql & " DIST, "
							lstrSql = lstrSql & " TIP_UNID, "
							lstrSql = lstrSql & " QUAN_FAS, "
							lstrSql = lstrSql & " ODI, "
							lstrSql = lstrSql & " TI, "
							lstrSql = lstrSql & " CM, "
							lstrSql = lstrSql & " TUC, "
							lstrSql = lstrSql & " A1, "
							lstrSql = lstrSql & " A2, "
							lstrSql = lstrSql & " A3, "
							lstrSql = lstrSql & " A4, "
							lstrSql = lstrSql & " A5, "
							lstrSql = lstrSql & " A6, "
							lstrSql = lstrSql & " IDUC, "
							lstrSql = lstrSql & " UAR, "
							lstrSql = lstrSql & " DAT_IMO,  "
							lstrSql = lstrSql & " DESCR "
							lstrSql = lstrSql & ") VALUES ("
							lstrSql = lstrSql & "'" & lstrCodId & "', " 'COD_ID
							lstrSql = lstrSql & "'" & lstrDist & "', " 'DIST
							lstrSql = lstrSql & "'" & lstrTipUnid & "', " 'TIP_UNID
							lstrSql = lstrSql & "'" & lstrQuanFas & "', " 'QUAN_FAS
							lstrSql = lstrSql & "'" & lstrOdi & "', " 'ODI
							lstrSql = lstrSql & "'" & lstrTi & "', " 'TI
							lstrSql = lstrSql & "'" & lstrCm & "', " 'CM
							lstrSql = lstrSql & "'" & lstrTuc & "', " 'TUC
							lstrSql = lstrSql & "'" & lstrA1 & "', " 'A1
							lstrSql = lstrSql & "'" & lstrA2 & "', " 'A2
							lstrSql = lstrSql & "'" & lstrA3 & "', " 'A3
							lstrSql = lstrSql & "'" & lstrA4 & "', " 'A4
							lstrSql = lstrSql & "'" & lstrA5 & "', " 'A5
							lstrSql = lstrSql & "'" & lstrA6 & "', " 'A6
							lstrSql = lstrSql & "'" & llngIdUc & "', " 'IDUC
							lstrSql = lstrSql & "'" & llngUar & "', " 'UAR
							lstrSql = lstrSql & "'" & VB6.Format(ldteImo, "yyyy-MM-dd") & "', " 'DAT_CON
							lstrSql = lstrSql & "'" & lstrDescr & "' " 'DESC
							lstrSql = lstrSql & ")"
							'Call gadoOraclCx.BeginTrans
							Call gadoOraclCx.Execute(lstrSql)
							'Call gadoOraclCx.CommitTrans
							Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1,  , " (BDGD - MEDIDOR) ")
							Call .MoveNext()
						End While
						Call gadoOraclCx.CommitTrans()
					End If
					Call .Close()
				End If
			End With
		End If
ErroInsereAtualizaOracleBDGB: 
		If gadoOraclCx.Errors.Count > 0 Then
			Call MsgBox(gadoOraclCx.Errors.Item(0).Number & " - " & gadoOraclCx.Errors.Item(0).NativeError & " - " & gadoOraclCx.Errors.Item(0).Description, MsgBoxStyle.Exclamation, gstrTituloMensagem)
			lblnRet = CStr(False)
			If gadoOraclCx.State = ADODB.ObjectStateEnum.adStateOpen Then Call gadoOraclCx.RollbackTrans()
		Else
			If Err.Number > 0 Then
				Call MsgBox(Err.Number & " - " & Err.Description, MsgBoxStyle.Exclamation, gstrTituloMensagem)
				lblnRet = CStr(False)
			End If
		End If
		If gadoOraclCx.State = ADODB.ObjectStateEnum.adStateOpen Then gadoOraclCx.Close()
		Me.Cursor = System.Windows.Forms.Cursors.Default
		InsereAtualizaOracleBDGB = CBool(lblnRet)
	End Function
	
	Private Function BuscaNumeroMedidor(ByVal astrGrupo As String, ByVal astrZona As String, ByVal astrLivro As String, ByVal astrConta As String) As String
		Dim lstrRet As String
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		On Error GoTo ErroBuscaNumeroMedidor
		lstrSql = ""
		lstrSql = lstrSql & "SELECT * "
		lstrSql = lstrSql & "  FROM " & gstrDataBase & ".`unid" & LCase(astrGrupo) & "` "
		lstrSql = lstrSql & " WHERE `zona` = '" & astrZona & "' "
		lstrSql = lstrSql & "   AND `livro` = '" & astrLivro & "' "
		lstrSql = lstrSql & "   AND `conta` = '" & astrConta & "' "
		lstrSql = lstrSql & " LIMIT 0,1 "
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				If .RecordCount > 0 Then
					If astrGrupo = "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"'
						lstrRet = IIf(IsDbNull(.Fields("num").value), "", .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"'
						lstrRet = IIf(IsDbNull(.Fields("eletr").value), "", .Fields("eletr").value)
					End If
				End If
				Call .Close()
			End If
		End With
		If lstrRet = "" Then
			lstrSql = ""
			lstrSql = lstrSql & "SELECT `medidor` "
			lstrSql = lstrSql & "  FROM " & gstrDataBase & ".`unidade_consumidora_auditoria` "
			lstrSql = lstrSql & " WHERE `zona` = '" & astrZona & "' "
			lstrSql = lstrSql & "   AND `livro` = '" & astrLivro & "' "
			lstrSql = lstrSql & "   AND `conta` = '" & astrConta & "' "
			lstrSql = lstrSql & "   AND `grupo` = '" & UCase(astrGrupo) & "' "
			lstrSql = lstrSql & "   AND `idmedidor` > 0 "
			lstrSql = lstrSql & " ORDER BY `movimento` DESC "
			lstrSql = lstrSql & " LIMIT 0,1 "
			Call Conectar(lstrSql, lrstAux)
			With lrstAux
				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"'
						lstrRet = IIf(IsDbNull(.Fields("medidor").value), "", .Fields("medidor").value)
					End If
					Call .Close()
				End If
			End With
		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
		BuscaNumeroMedidor = lstrRet
ErroBuscaNumeroMedidor: 
		If Err.Number > 0 Then
			Call MsgBox(Err.Number & " - " & Err.Description, MsgBoxStyle.Exclamation, gstrTituloMensagem)
		End If
		
	End Function
	
	Private Function BuscaTTEN(ByVal astrTensao As Object) As String
		Dim lstrAux As String
		Dim lstrRet As String
		Dim lstrDad As String
		lstrDad = "216?47;220?48;127?49;230?50;240?51;254?52;380?53;400?54;440?55;500?56;1000?1;2200?2;3600?3;3785?4;4160?5;5000?6;6000?7;7960?8;8670?9;11400?10;12000?11;12600?12;13200?13;13800?14;14400?15;15000?16;19053?17;19919?18;21000?19;23000?20;24200?21;25000?22;27000?23;30000?24;33000?25;34500?26;36000?27;38000?28;40000?29;45000?30;45400?31;48000?32;60000?33;69000?34;72500?35;88000?36;120000?37;123000?38;138000?39;145000?40;230000?41;500000?42;750000?43;1000000?44;"
		'UPGRADE_WARNING: Couldn't resolve default property of object astrTensao. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
		If CInt(InStr(1, lstrDad, astrTensao)) > 0 Then
			'UPGRADE_WARNING: Couldn't resolve default property of object astrTensao. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			lstrAux = Mid(lstrDad, CInt(InStr(1, lstrDad, astrTensao)))
			lstrRet = Mid(lstrAux, CInt(InStr(1, lstrAux, "?")) + 1, CInt(InStr(1, lstrAux, ";")) - (CInt(InStr(1, lstrAux, "?")) + 1))
		Else
			lstrRet = "0"
		End If
		BuscaTTEN = lstrRet
	End Function
	
	Private Function InsereDbf() As Boolean
		Dim lblnRet As Boolean
		Dim llngRow As Integer
		Dim llngCol As Integer
		Dim lstrDbf As String
		Dim ldblAux As Double
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		On Error GoTo ErroInsereDbf
		Call BarraProgresso((Me.ProgressBarProc), (Me.lblPercProc), (Me.lblInfoProc), 1,  , " Dados DBF ")
		lblnRet = True
		''Inserir alguns registos na Tabela Persons
		Call AbreConexaoDBF(Me.txtDir.Text)
		If Me.chkBt.CheckState = System.Windows.Forms.CheckState.Checked Then
			lstrSql = ""
			lstrSql = lstrSql & "SELECT * FROM " & gstrDataBase & ".`prodist_consumidor_bt` "
			Call Conectar(lstrSql, lrstAux)
			With lrstAux
				If .State = ADODB.ObjectStateEnum.adStateOpen Then
					If .RecordCount > 0 Then
						Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, .RecordCount, " exportação B ")
						While Not .EOF
							lstrDbf = ""
							lstrDbf = lstrDbf & "insert into UC_BT values("
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("livro").value), "00", .Fields("livro").value) & VB.Right(IIf(IsDbNull(.Fields("conta").value), "000000", .Fields("conta").value), 4) & "', "
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("ramal").value), "", .Fields("ramal").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"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("medidor").value), "", .Fields("medidor").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"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("dist").value), "00", .Fields("dist").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"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("clas_sub").value), "00", .Fields("clas_sub").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"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("fas_con").value), "ABCN", .Fields("fas_con").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"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("gru_ten").value), "BT", .Fields("gru_ten").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"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("ten_forn").value), "00", .Fields("ten_forn").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"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("gru_tar").value), "B1", .Fields("gru_tar").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"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("sit_ativ").value), "SM", .Fields("sit_ativ").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"'
							lstrDbf = lstrDbf & "'" & VB6.Format(IIf(IsDbNull(.Fields("dat_con").value), "01/01/1900", .Fields("dat_con").value), "dd/MM/yy") & "', "
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							lstrDbf = lstrDbf & "'" & Replace(Replace(VB6.Format(IIf(IsDbNull(.Fields("pot_inst").value), "0.001", .Fields("pot_inst").value), "#,#####0.00000"), ".", ""), ".", ",") & "', "
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							lstrDbf = lstrDbf & "'" & Replace(Replace(VB6.Format(IIf(IsDbNull(.Fields("ene_01").value), "0.000", .Fields("ene_01").value), "#,###0.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"'
							lstrDbf = lstrDbf & "'" & Replace(Replace(VB6.Format(IIf(IsDbNull(.Fields("ene_02").value), "0.000", .Fields("ene_02").value), "#,###0.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"'
							lstrDbf = lstrDbf & "'" & Replace(Replace(VB6.Format(IIf(IsDbNull(.Fields("ene_03").value), "0.000", .Fields("ene_03").value), "#,###0.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"'
							lstrDbf = lstrDbf & "'" & Replace(Replace(VB6.Format(IIf(IsDbNull(.Fields("ene_04").value), "0.000", .Fields("ene_04").value), "#,###0.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"'
							lstrDbf = lstrDbf & "'" & Replace(Replace(VB6.Format(IIf(IsDbNull(.Fields("ene_05").value), "0.000", .Fields("ene_05").value), "#,###0.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"'
							lstrDbf = lstrDbf & "'" & Replace(Replace(VB6.Format(IIf(IsDbNull(.Fields("ene_06").value), "0.000", .Fields("ene_06").value), "#,###0.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"'
							lstrDbf = lstrDbf & "'" & Replace(Replace(VB6.Format(IIf(IsDbNull(.Fields("ene_07").value), "0.000", .Fields("ene_07").value), "#,###0.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"'
							lstrDbf = lstrDbf & "'" & Replace(Replace(VB6.Format(IIf(IsDbNull(.Fields("ene_08").value), "0.000", .Fields("ene_08").value), "#,###0.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"'
							lstrDbf = lstrDbf & "'" & Replace(Replace(VB6.Format(IIf(IsDbNull(.Fields("ene_09").value), "0.000", .Fields("ene_09").value), "#,###0.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"'
							lstrDbf = lstrDbf & "'" & Replace(Replace(VB6.Format(IIf(IsDbNull(.Fields("ene_10").value), "0.000", .Fields("ene_10").value), "#,###0.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"'
							lstrDbf = lstrDbf & "'" & Replace(Replace(VB6.Format(IIf(IsDbNull(.Fields("ene_11").value), "0.000", .Fields("ene_11").value), "#,###0.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"'
							lstrDbf = lstrDbf & "'" & Replace(Replace(VB6.Format(IIf(IsDbNull(.Fields("ene_12").value), "0.000", .Fields("ene_12").value), "#,###0.000"), ".", ""), ".", ",") & "', "
							lstrDbf = lstrDbf & "'')"
							Call icnxDbf.Execute(lstrDbf)
							Call .MoveNext()
							Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1,  , " exportação B ")
						End While
					End If
					Call .Close()
				End If
			End With
		End If
		If Me.chkMt.CheckState = System.Windows.Forms.CheckState.Checked Then
			lstrSql = ""
			lstrSql = lstrSql & "SELECT * FROM " & gstrDataBase & ".`prodist_consumidor_mt` "
			Call Conectar(lstrSql, lrstAux)
			With lrstAux
				If .State = ADODB.ObjectStateEnum.adStateOpen Then
					If .RecordCount > 0 Then
						''Inserir alguns registos na Tabela Persons
						Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, .RecordCount, " exportação A ")
						While Not .EOF
							lstrDbf = ""
							lstrDbf = lstrDbf & "insert into UC_MT values("
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("livro").value), "00", .Fields("livro").value) & VB.Right(IIf(IsDbNull(.Fields("conta").value), "000000", .Fields("conta").value), 4) & "', "
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("pn_con").value), "", .Fields("pn_con").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"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("sdmt_con").value), "", .Fields("sdmt_con").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"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("med_01").value), "", .Fields("med_01").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"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("med_02").value), "", .Fields("med_02").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"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("tc").value), "", .Fields("tc").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"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("tp").value), "", .Fields("tp").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"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("dist").value), "00", .Fields("dist").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"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("clas_sub").value), "00", .Fields("clas_sub").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"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("fas_con").value), "ABCN", .Fields("fas_con").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"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("gru_ten").value), "BT", .Fields("gru_ten").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"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("ten_forn").value), "00", .Fields("ten_forn").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"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("gru_tar").value), "B1", .Fields("gru_tar").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"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("sit_ativ").value), "SM", .Fields("sit_ativ").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"'
							lstrDbf = lstrDbf & "'" & VB6.Format(IIf(IsDbNull(.Fields("dat_con").value), "01/01/1900", .Fields("dat_con").value), "dd/MM/yy") & "', "
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							lstrDbf = lstrDbf & "'" & Replace(Replace(VB6.Format(IIf(IsDbNull(.Fields("pot_inst").value), "0.001", .Fields("pot_inst").value), "#,#####0.00000"), ".", ""), ".", ",") & "', "
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("liv").value), "F", .Fields("liv").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"'
							lstrDbf = lstrDbf & "'" & Replace(Replace(VB6.Format(IIf(IsDbNull(.Fields("dem_01").value), "0.000", .Fields("dem_01").value), "#,###0.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"'
							lstrDbf = lstrDbf & "'" & Replace(Replace(VB6.Format(IIf(IsDbNull(.Fields("dem_02").value), "0.000", .Fields("dem_02").value), "#,###0.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"'
							lstrDbf = lstrDbf & "'" & Replace(Replace(VB6.Format(IIf(IsDbNull(.Fields("dem_03").value), "0.000", .Fields("dem_03").value), "#,###0.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"'
							lstrDbf = lstrDbf & "'" & Replace(Replace(VB6.Format(IIf(IsDbNull(.Fields("dem_04").value), "0.000", .Fields("dem_04").value), "#,###0.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"'
							lstrDbf = lstrDbf & "'" & Replace(Replace(VB6.Format(IIf(IsDbNull(.Fields("dem_05").value), "0.000", .Fields("dem_05").value), "#,###0.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"'
							lstrDbf = lstrDbf & "'" & Replace(Replace(VB6.Format(IIf(IsDbNull(.Fields("dem_06").value), "0.000", .Fields("dem_06").value), "#,###0.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"'
							lstrDbf = lstrDbf & "'" & Replace(Replace(VB6.Format(IIf(IsDbNull(.Fields("dem_07").value), "0.000", .Fields("dem_07").value), "#,###0.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"'
							lstrDbf = lstrDbf & "'" & Replace(Replace(VB6.Format(IIf(IsDbNull(.Fields("dem_08").value), "0.000", .Fields("dem_08").value), "#,###0.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"'
							lstrDbf = lstrDbf & "'" & Replace(Replace(VB6.Format(IIf(IsDbNull(.Fields("dem_09").value), "0.000", .Fields("dem_09").value), "#,###0.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"'
							lstrDbf = lstrDbf & "'" & Replace(Replace(VB6.Format(IIf(IsDbNull(.Fields("dem_10").value), "0.000", .Fields("dem_10").value), "#,###0.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"'
							lstrDbf = lstrDbf & "'" & Replace(Replace(VB6.Format(IIf(IsDbNull(.Fields("dem_11").value), "0.000", .Fields("dem_11").value), "#,###0.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"'
							lstrDbf = lstrDbf & "'" & Replace(Replace(VB6.Format(IIf(IsDbNull(.Fields("dem_12").value), "0.000", .Fields("dem_12").value), "#,###0.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"'
							lstrDbf = lstrDbf & "'" & Replace(Replace(VB6.Format(IIf(IsDbNull(.Fields("ene_01").value), "0.000", .Fields("ene_01").value), "#,###0.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"'
							lstrDbf = lstrDbf & "'" & Replace(Replace(VB6.Format(IIf(IsDbNull(.Fields("ene_02").value), "0.000", .Fields("ene_02").value), "#,###0.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"'
							lstrDbf = lstrDbf & "'" & Replace(Replace(VB6.Format(IIf(IsDbNull(.Fields("ene_03").value), "0.000", .Fields("ene_03").value), "#,###0.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"'
							lstrDbf = lstrDbf & "'" & Replace(Replace(VB6.Format(IIf(IsDbNull(.Fields("ene_04").value), "0.000", .Fields("ene_04").value), "#,###0.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"'
							lstrDbf = lstrDbf & "'" & Replace(Replace(VB6.Format(IIf(IsDbNull(.Fields("ene_05").value), "0.000", .Fields("ene_05").value), "#,###0.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"'
							lstrDbf = lstrDbf & "'" & Replace(Replace(VB6.Format(IIf(IsDbNull(.Fields("ene_06").value), "0.000", .Fields("ene_06").value), "#,###0.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"'
							lstrDbf = lstrDbf & "'" & Replace(Replace(VB6.Format(IIf(IsDbNull(.Fields("ene_07").value), "0.000", .Fields("ene_07").value), "#,###0.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"'
							lstrDbf = lstrDbf & "'" & Replace(Replace(VB6.Format(IIf(IsDbNull(.Fields("ene_08").value), "0.000", .Fields("ene_08").value), "#,###0.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"'
							lstrDbf = lstrDbf & "'" & Replace(Replace(VB6.Format(IIf(IsDbNull(.Fields("ene_09").value), "0.000", .Fields("ene_09").value), "#,###0.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"'
							lstrDbf = lstrDbf & "'" & Replace(Replace(VB6.Format(IIf(IsDbNull(.Fields("ene_10").value), "0.000", .Fields("ene_10").value), "#,###0.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"'
							lstrDbf = lstrDbf & "'" & Replace(Replace(VB6.Format(IIf(IsDbNull(.Fields("ene_11").value), "0.000", .Fields("ene_11").value), "#,###0.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"'
							lstrDbf = lstrDbf & "'" & Replace(Replace(VB6.Format(IIf(IsDbNull(.Fields("ene_12").value), "0.000", .Fields("ene_12").value), "#,###0.000"), ".", ""), ".", ",") & "', "
							lstrDbf = lstrDbf & "'')"
							Call icnxDbf.Execute(lstrDbf)
							Call .MoveNext()
							Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1,  , " exportação A ")
						End While
					End If
					Call .Close()
				End If
			End With
		End If
		If Me.chkMedidor.CheckState = System.Windows.Forms.CheckState.Checked Then
			lstrSql = ""
			lstrSql = lstrSql & "SELECT * FROM " & gstrDataBase & ".`prodist_medidor` "
			Call Conectar(lstrSql, lrstAux)
			With lrstAux
				If .State = ADODB.ObjectStateEnum.adStateOpen Then
					If .RecordCount > 0 Then
						''Inserir alguns registos na Tabela Persons
						Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, .RecordCount, " exportação Medidor ")
						While Not .EOF
							lstrDbf = ""
							lstrDbf = lstrDbf & "insert into EQU_MED values("
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("cod_id").value), "00", .Fields("cod_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"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("dist").value), "00", .Fields("dist").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"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("tip_unid").value), "", .Fields("tip_unid").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"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("quan_fas").value), "", .Fields("quan_fas").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"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("odi").value), "", .Fields("odi").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"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("ti").value), "", .Fields("ti").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"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("cm").value), "", .Fields("cm").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"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("tuc").value), "", .Fields("tuc").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"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("a1").value), "00", .Fields("a1").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"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("a2").value), "00", .Fields("a2").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"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("a3").value), "00", .Fields("a3").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"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("a4").value), "00", .Fields("a4").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"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("a5").value), "00", .Fields("a5").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"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("a6").value), "00", .Fields("a6").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"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("iduc").value), "0", .Fields("iduc").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"'
							lstrDbf = lstrDbf & "'" & IIf(IsDbNull(.Fields("uar").value), "0", .Fields("uar").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"'
							lstrDbf = lstrDbf & "'" & VB6.Format(IIf(IsDbNull(.Fields("dat_imo").value), "01/01/1900", .Fields("dat_imo").value), "dd/MM/yy") & "', "
							lstrDbf = lstrDbf & "'')"
							Call icnxDbf.Execute(lstrDbf)
							Call .MoveNext()
							Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1,  , " exportação medidores ")
						End While
					End If
					Call .Close()
				End If
			End With
		End If
ErroInsereDbf: 
		If icnxDbf.Errors.Count > 0 Then
			Call MsgBox(icnxDbf.Errors.Item(0).Number & " - " & icnxDbf.Errors.Item(0).NativeError & " - " & icnxDbf.Errors.Item(0).Description, MsgBoxStyle.Exclamation, gstrTituloMensagem)
			lblnRet = False
		Else
			If Err.Number > 0 Then
				Call MsgBox(Err.Number & " - " & Err.Description, MsgBoxStyle.Exclamation, gstrTituloMensagem)
				lblnRet = False
			End If
		End If
		If icnxDbf.State = ADODB.ObjectStateEnum.adStateOpen Then icnxDbf.Close()
		InsereDbf = lblnRet
	End Function
	
	Private Function CriaDbf() As Boolean
		Dim lblnRet As Boolean
		Dim lstrDbf As String
		Dim lstrArq As String
		On Error GoTo ErroCriaDbf
		lblnRet = True
		Call BarraProgresso((Me.ProgressBarProc), (Me.lblPercProc), (Me.lblInfoProc), 1,  , " Dados DBF ")
		'
		'Abre Conexão para pastas DBF ex: C:\[Nome do Directorio]
		'
		Call AbreConexaoDBF(Me.txtDir.Text)
		If Me.chkBt.CheckState = System.Windows.Forms.CheckState.Checked Then
			'
			'Valida se existe na pasta selecionada o arquivo UC_BT.DBF
			'
			lstrArq = Me.txtDir.Text & IIf(VB.Right(Trim(Me.txtDir.Text), 1) <> "\", "\", "") & "UC_BT.DBF"
			'UPGRADE_WARNING: Dir has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
			If Trim(Dir(lstrArq)) <> "" Then
				If MsgBox("Deseja sobrescrever o arquivo UC_BT?", MsgBoxStyle.YesNo, gstrTituloMensagem) = MsgBoxResult.Yes Then
					'
					'Apaga o arquivo
					'
					Call Kill(lstrArq)
				End If
			End If
			'UPGRADE_WARNING: Dir has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
			If Trim(Dir(lstrArq)) = "" Then
				'
				'Cria o arquivo UC_BT.DBF na pasta selecionada
				'
				lstrDbf = ""
				lstrDbf = lstrDbf & "create table `UC_BT` ("
				lstrDbf = lstrDbf & "`COD_ID` char(20), "
				lstrDbf = lstrDbf & "`RAMAL` char(20), "
				lstrDbf = lstrDbf & "`MED` char(20), "
				lstrDbf = lstrDbf & "`DIST` char(2), "
				lstrDbf = lstrDbf & "`CLAS_SUB` char(4), "
				lstrDbf = lstrDbf & "`FAS_CON` char(4), "
				lstrDbf = lstrDbf & "`GRU_TEN` char(2), "
				lstrDbf = lstrDbf & "`TEN_FORN` char(2), "
				lstrDbf = lstrDbf & "`GRU_TAR` char(4), "
				lstrDbf = lstrDbf & "`SIT_ATIV` char(2), "
				lstrDbf = lstrDbf & "`DAT_CON` date, "
				lstrDbf = lstrDbf & "`POT_INST` decimal(5), "
				lstrDbf = lstrDbf & "`ENE_01` decimal(5), "
				lstrDbf = lstrDbf & "`ENE_02` decimal(5), "
				lstrDbf = lstrDbf & "`ENE_03` decimal(5), "
				lstrDbf = lstrDbf & "`ENE_04` decimal(5), "
				lstrDbf = lstrDbf & "`ENE_05` decimal(5), "
				lstrDbf = lstrDbf & "`ENE_06` decimal(5), "
				lstrDbf = lstrDbf & "`ENE_07` decimal(5), "
				lstrDbf = lstrDbf & "`ENE_08` decimal(5), "
				lstrDbf = lstrDbf & "`ENE_09` decimal(5), "
				lstrDbf = lstrDbf & "`ENE_10` decimal(5), "
				lstrDbf = lstrDbf & "`ENE_11` decimal(5), "
				lstrDbf = lstrDbf & "`ENE_12` decimal(5), "
				lstrDbf = lstrDbf & "`DESC` char(254))"
				Call icnxDbf.Execute(lstrDbf)
			End If
		End If
		If Me.chkMt.CheckState = System.Windows.Forms.CheckState.Checked Then
			'
			'Valida se existe na pasta selecionada o arquivo UC_MT.DBF
			'
			lstrArq = Me.txtDir.Text & IIf(VB.Right(Trim(Me.txtDir.Text), 1) <> "\", "\", "") & "UC_MT.DBF"
			'UPGRADE_WARNING: Dir has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
			If Trim(Dir(lstrArq)) <> "" Then
				If MsgBox("Deseja sobrescrever o arquivo UC_MT?", MsgBoxStyle.YesNo, gstrTituloMensagem) = MsgBoxResult.Yes Then
					'
					'Apaga o arquivo
					'
					Call Kill(lstrArq)
				End If
			End If
			'UPGRADE_WARNING: Dir has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
			If Trim(Dir(lstrArq)) = "" Then
				lstrDbf = ""
				lstrDbf = lstrDbf & "create table `UC_MT` ("
				lstrDbf = lstrDbf & "`COD_ID` char(20), "
				lstrDbf = lstrDbf & "`PN_CON` char(20), "
				lstrDbf = lstrDbf & "`SDMT_CON` char(20), "
				lstrDbf = lstrDbf & "`MED_01` char(20), "
				lstrDbf = lstrDbf & "`MED_02` char(20), "
				lstrDbf = lstrDbf & "`TP` char(20), "
				lstrDbf = lstrDbf & "`TC` char(20), "
				lstrDbf = lstrDbf & "`DIST` char(2), "
				lstrDbf = lstrDbf & "`CLAS_SUB` char(4), "
				lstrDbf = lstrDbf & "`FAS_CON` char(4), "
				lstrDbf = lstrDbf & "`GRU_TEN` char(2), "
				lstrDbf = lstrDbf & "`TEN_FORN` char(2), "
				lstrDbf = lstrDbf & "`GRU_TAR` char(4), "
				lstrDbf = lstrDbf & "`SIT_ATIV` char(2), "
				lstrDbf = lstrDbf & "`DAT_CON` Date, "
				lstrDbf = lstrDbf & "`POT_INST` decimal(5), "
				lstrDbf = lstrDbf & "`LIV` char(1), "
				lstrDbf = lstrDbf & "`DEM_01` decimal(5), "
				lstrDbf = lstrDbf & "`DEM_02` decimal(5), "
				lstrDbf = lstrDbf & "`DEM_03` decimal(5), "
				lstrDbf = lstrDbf & "`DEM_04` decimal(5), "
				lstrDbf = lstrDbf & "`DEM_05` decimal(5), "
				lstrDbf = lstrDbf & "`DEM_06` decimal(5), "
				lstrDbf = lstrDbf & "`DEM_07` decimal(5), "
				lstrDbf = lstrDbf & "`DEM_08` decimal(5), "
				lstrDbf = lstrDbf & "`DEM_09` decimal(5), "
				lstrDbf = lstrDbf & "`DEM_10` decimal(5), "
				lstrDbf = lstrDbf & "`DEM_11` decimal(5), "
				lstrDbf = lstrDbf & "`DEM_12` decimal(5), "
				lstrDbf = lstrDbf & "`ENE_01` decimal(5), "
				lstrDbf = lstrDbf & "`ENE_02` decimal(5), "
				lstrDbf = lstrDbf & "`ENE_03` decimal(5), "
				lstrDbf = lstrDbf & "`ENE_04` decimal(5), "
				lstrDbf = lstrDbf & "`ENE_05` decimal(5), "
				lstrDbf = lstrDbf & "`ENE_06` decimal(5), "
				lstrDbf = lstrDbf & "`ENE_07` decimal(5), "
				lstrDbf = lstrDbf & "`ENE_08` decimal(5), "
				lstrDbf = lstrDbf & "`ENE_09` decimal(5), "
				lstrDbf = lstrDbf & "`ENE_10` decimal(5), "
				lstrDbf = lstrDbf & "`ENE_11` decimal(5), "
				lstrDbf = lstrDbf & "`ENE_12` decimal(5), "
				lstrDbf = lstrDbf & "`DESC` char(254))"
				Call icnxDbf.Execute(lstrDbf)
			End If
		End If
		If Me.chkMedidor.CheckState = System.Windows.Forms.CheckState.Checked Then
			'
			'Valida se existe na pasta selecionada o arquivo EQU_MED.DBF
			'
			lstrArq = Me.txtDir.Text & IIf(VB.Right(Trim(Me.txtDir.Text), 1) <> "\", "\", "") & "EQU_MED.DBF"
			'UPGRADE_WARNING: Dir has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
			If Trim(Dir(lstrArq)) <> "" Then
				If MsgBox("Deseja sobrescrever o arquivo EQU_MED?", MsgBoxStyle.YesNo, gstrTituloMensagem) = MsgBoxResult.Yes Then
					'
					'Apaga o arquivo
					'
					Call Kill(lstrArq)
				End If
			End If
			'UPGRADE_WARNING: Dir has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
			If Trim(Dir(lstrArq)) = "" Then
				'
				'Cria o arquivo EQU_MED.DBF na pasta selecionada
				'
				lstrDbf = ""
				lstrDbf = lstrDbf & "create table `EQU_MED` ("
				lstrDbf = lstrDbf & "`COD_ID` char(20), "
				lstrDbf = lstrDbf & "`DIST` char(2), "
				lstrDbf = lstrDbf & "`TIP_UNID` char(2), "
				lstrDbf = lstrDbf & "`QUAN_FAS` char(4), "
				lstrDbf = lstrDbf & "`ODI` char(99), "
				lstrDbf = lstrDbf & "`TI` char(3), "
				lstrDbf = lstrDbf & "`CM` char(3), "
				lstrDbf = lstrDbf & "`TUC` char(3), "
				lstrDbf = lstrDbf & "`A1` char(2), "
				lstrDbf = lstrDbf & "`A2` char(2), "
				lstrDbf = lstrDbf & "`A3` char(2), "
				lstrDbf = lstrDbf & "`A4` char(2), "
				lstrDbf = lstrDbf & "`A5` char(2), "
				lstrDbf = lstrDbf & "`A6` char(2), "
				lstrDbf = lstrDbf & "`IDUC` char(99), "
				lstrDbf = lstrDbf & "`UAR` char(99), "
				lstrDbf = lstrDbf & "`DAT_IMO` date, "
				lstrDbf = lstrDbf & "`DESC` char(254))"
				Call icnxDbf.Execute(lstrDbf)
			End If
		End If
ErroCriaDbf: 
		If icnxDbf.Errors.Count > 0 Then
			Call MsgBox(icnxDbf.Errors.Item(0).Number & " - " & icnxDbf.Errors.Item(0).NativeError & " - " & icnxDbf.Errors.Item(0).Description, MsgBoxStyle.Exclamation, gstrTituloMensagem)
			lblnRet = False
		Else
			If Err.Number > 0 Then
				Call MsgBox(Err.Number & " - " & Err.Description, MsgBoxStyle.Exclamation, gstrTituloMensagem)
				lblnRet = False
			End If
		End If
		If icnxDbf.State = ADODB.ObjectStateEnum.adStateOpen Then icnxDbf.Close()
		CriaDbf = lblnRet
	End Function
End Class