Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Imports fatd_faturamento.BLL.Repositorio
Imports fatd_faturamento.ENTIDADE
Imports CrystalDecisions.CrystalReports.Engine
Friend Class frmSolServ
	Inherits System.Windows.Forms.Form
	Private istrSitUc As String
	Private istrGrupo As String
	Private ilngUnidId As Integer
	Private istrNumCodigo As String
	Private ifrmQuemChama As System.Windows.Forms.Form
	Private iblnCargaSimNao As Boolean
	Private iblnCroquiSimNao As Boolean
	Private istrProtocolo As String
	Private ilngSequencia As Integer
	Private sNomeEmpresa As String
	Private sEnderecoEmpresa As String
	Private sCepEmpresa As String
	Private sCidadeEmpresa As String
	Private sUFempresa As String
	Private sBairroEmpresa As String
	Private sFoneEmpresa As String
	Private sWebEmpresa As String
	Private LImagem As Byte()
	Private lstrProto As String
	Private ifrmCargaInstalada As frmCargaInstalada
	Private dt, dt2, dt3, dt4, dt5, dt6 As DataTable
	Private objAtualizaBancoDados As New entidadeAtualizaBancoDados
	Private repositorioAtualizaBancoDados As New repositorioAtualizaBancoDados
	Private objExecAtualizaBancoDados As New entidadeAtualizaBancoDados
	Private repositorioExecAtualizaBancoDados As New repositorioAtualizaBancoDados

	Private Sub frmSolServ_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		Try
			ifrmCargaInstalada = New frmCargaInstalada
			With Me.cmbPriori
				Call .Items.Add("Urgente")
				Call .Items.Add("Normal")
				.SelectedIndex = 1
			End With
			With Me.cmbSolicit
				Call .Items.Add("Pessoalmente")
				Call .Items.Add("Fone")
				Call .Items.Add("E -mail")
				Call .Items.Add("Site")
				Call .Items.Add("Outro")
				.SelectedIndex = 0
			End With
			With Me.cmbRegiao
				Call .Items.Add("Urbana")
				Call .Items.Add("Rural")
				.SelectedIndex = 0
			End With
			With cmbPadrao
				Call .Items.Add("Padrão")
				Call .Items.Add("Provisório")
				Call .Items.Add("Temporário")
				.SelectedIndex = 0
			End With
			With cmbTpLigacao
				Call .Items.Add("Aéreo")
				Call .Items.Add("Subterrâneo")
				.SelectedIndex = 0
			End With

			Call sCriaTabelaAuxiliares()

		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: frmSolServ_Load" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub
	Private Sub frmSolServ_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
		Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
		Try
			If KeyAscii = System.Windows.Forms.Keys.Escape Then
				Call cmdFechar_Click(cmdFechar, New System.EventArgs())
			ElseIf KeyAscii = System.Windows.Forms.Keys.Return Then
				TabEnter(KeyAscii, eventArgs)
			End If
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: frmSolServ_KeyPress" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub
	Private Sub EncheComboExecutor()
		Dim llngCod As Integer
		Dim lstrDes As String
		Dim lstrSql As String

		Try

			lstrSql = ""
			lstrSql = lstrSql & "  SELECT `executor`.`cod`, "
			lstrSql = lstrSql & "         `executor`.`descricao` "
			lstrSql = lstrSql & "    FROM `executor` "
			lstrSql = lstrSql & "ORDER BY `descricao` ASC"
			objAtualizaBancoDados.QUERY_NAME = lstrSql
			dt = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)

			If dt.Rows.Count > 0 Then
				For Each row As DataRow In dt.Rows
					llngCod = CInt(IIf(IsDBNull(row.Item("cod")), 0, row.Item("cod")))
					lstrDes = Trim(IIf(IsDBNull(row.Item("descricao")), "", row.Item("descricao")))
					With Me.cmbExecutor
						Call .Items.Add(llngCod & " - " & lstrDes)
						VB6.SetItemData(Me.cmbExecutor, Me.cmbExecutor.Items.Count - 1, llngCod)
					End With
				Next
			End If

		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: EncheComboExecutor" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try

	End Sub

	Private Sub encheComboServicos()
		Dim lblnAux As Boolean
		Dim lstrSUc As String
		Dim lstrCod As String
		Dim lstrDes As String
		Dim lstrSql As String

		Try

			lstrSql = ""
			lstrSql = lstrSql & "  SELECT `codigos`.`num`, "
			lstrSql = lstrSql & "         `codigos`.`descri`, "
			lstrSql = lstrSql & "         `codigos`.`situacao`, "
			lstrSql = lstrSql & "         `codigos`.`flgsituc` "
			lstrSql = lstrSql & "    FROM `codigos` "
			lstrSql = lstrSql & "   WHERE (LEFT(`codigos`.`num`, 4) = '9040' OR LEFT(`codigos`.`num`, 4) = '9050') AND `codigos`.`num` <> '9050000002' "
			lstrSql = lstrSql & "     AND (`codigos`.`num` <> '9040000000' OR `codigos`.`num` <> '9050000000') "
			lstrSql = lstrSql & "     AND `situacao` = 'A' AND `flgproc` = 'O' "
			lstrSql = lstrSql & "GROUP BY `descri` "
			lstrSql = lstrSql & "ORDER BY `descri` ASC, LEFT(`num`, 4) ASC "
			objAtualizaBancoDados.QUERY_NAME = lstrSql
			dt = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)

			If dt.Rows.Count > 0 Then
				For Each row As DataRow In dt.Rows
					lblnAux = True
					lstrCod = IIf(IsDBNull(row.Item("num")), "", row.Item("num"))
					lstrDes = Trim(IIf(IsDBNull(row.Item("descri")), "", row.Item("descri")))
					lstrSUc = Trim(IIf(IsDBNull(row.Item("flgsituc")), "L", row.Item("flgsituc")))
					If InStr(1, lstrSUc, VB.Left(istrSitUc, 1)) = 0 Then
						lblnAux = False
					End If
					If lblnAux Then
						With Me.cmbServDescri
							Call .Items.Add(lstrDes & " - " & VB.Left(lstrCod, 4))
							VB6.SetItemData(Me.cmbServDescri, Me.cmbServDescri.Items.Count - 1, Val(VB.Right(lstrCod, 6)))
						End With
					End If
				Next
			End If
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: encheComboServicos" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try

	End Sub
	Private Sub cmbServDescri_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmbServDescri.TextChanged
		Call cmbServDescri_SelectedIndexChanged(cmbServDescri, New System.EventArgs())
	End Sub
	Private Sub cmbServDescri_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmbServDescri.SelectedIndexChanged
		Try

			With Me.cmbServDescri
				istrNumCodigo = VB.Right(VB6.GetItemString(Me.cmbServDescri, .SelectedIndex), 4) & VB6.Format(VB6.GetItemData(Me.cmbServDescri, .SelectedIndex), "000000")
				If CDbl(VB.Right(VB6.GetItemString(Me.cmbServDescri, .SelectedIndex), 4)) = 9040 Then
					Me.txtValor.Enabled = False
					Me.txtValor.Text = PegaValorServicoFixo(istrNumCodigo)
				ElseIf CDbl(VB.Right(VB6.GetItemString(Me.cmbServDescri, .SelectedIndex), 4)) = 9050 Then
					Me.txtValor.Enabled = True
					Me.txtValor.Text = PegaValorServicoVariavel(istrNumCodigo)
				Else
					Me.txtValor.Text = ""
					Me.txtValor.Enabled = True
				End If
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: cmbServDescri_SelectedIndexChanged" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Function PegaValorServicoFixo(ByVal astrCodServico As String) As String
		Dim lstrSql As String
		Dim lstrCod As String
		Dim lstrFas As String
		Dim ldblVlr As Double

		Try

			lstrFas = checaFase(Me.txtZona.Text, Me.txtLivro.Text, Me.txtConta.Text)
			lstrCod = VB.Left(astrCodServico, 9)
			lstrSql = ""
			lstrSql = lstrSql & "SELECT `codigos`.`valor` "
			lstrSql = lstrSql & "  FROM `codigos` "
			lstrSql = lstrSql & " WHERE `codigos`.`num` = '" & lstrCod '& "'"
			If UCase(istrGrupo) = "A" Then
				lstrSql = lstrSql & "4'"
			ElseIf UCase(istrGrupo) = "B" Then
				If lstrFas = "M" Then
					lstrSql = lstrSql & "1'"
				ElseIf lstrFas = "B" Then
					lstrSql = lstrSql & "2'"
				ElseIf lstrFas = "T" Then
					lstrSql = lstrSql & "3'"
				End If
			End If
			objAtualizaBancoDados.QUERY_NAME = lstrSql
			dt = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)

			If dt.Rows.Count > 0 Then
				For Each row As DataRow In dt.Rows
					ldblVlr = CDbl(IIf(IsDBNull(row.Item("valor")), 0, row.Item("valor")))
					PegaValorServicoFixo = VB6.Format(ldblVlr, "standard")
				Next
			Else
				PegaValorServicoFixo = "0,00"
			End If
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: PegaValorServicoFixo" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Function
		End Try

	End Function

	Private Function checaFase(ByVal astrZona As String, ByVal astrLivro As String, ByVal astrConta As String) As String
		Dim lstrSql As String
		Try

			lstrSql = ""
			lstrSql = lstrSql & "SELECT `uc`.`fase` "
			lstrSql = lstrSql & "  FROM `uc_faturamento` as `uc` "
			lstrSql = lstrSql & " WHERE `uc`.`zona`  = '" & astrZona & "' "
			lstrSql = lstrSql & "   AND `uc`.`livro` = '" & astrLivro & "' "
			lstrSql = lstrSql & "   AND `uc`.`conta` = '" & astrConta & "' "
			lstrSql = lstrSql & "   AND `uc`.`Grupo` = '" & UCase(istrGrupo) & "' "
			objAtualizaBancoDados.QUERY_NAME = lstrSql
			dt = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)

			If dt.Rows.Count > 0 Then
				For Each row As DataRow In dt.Rows
					checaFase = Trim(IIf(IsDBNull(row.Item("fase")), "M", row.Item("fase")))
				Next
			Else
				checaFase = "M"
			End If
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: checaFase" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Function
		End Try

	End Function
	Private Function PegaValorServicoVariavel(ByVal astrCodServico As String) As String
		Dim lstrSql As String
		Dim lstrCod As String
		Dim ldblVlr As Double

		Try

			lstrCod = astrCodServico
			lstrSql = ""
			lstrSql = lstrSql & "SELECT `codigos`.`valor` "
			lstrSql = lstrSql & "  FROM `codigos` "
			lstrSql = lstrSql & " WHERE `codigos`.`num` = '" & lstrCod & "' "
			objAtualizaBancoDados.QUERY_NAME = lstrSql
			dt = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)

			If dt.Rows.Count > 0 Then
				For Each row As DataRow In dt.Rows
					ldblVlr = CDbl(IIf(IsDBNull(row.Item("valor")), 0, row.Item("valor")))
					PegaValorServicoVariavel = VB6.Format(ldblVlr, "Standard")
				Next
			Else
				PegaValorServicoVariavel = "0,00"
			End If

		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: PegaValorServicoVariavel" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Function
		End Try

	End Function
	Private Sub opbGrupoA_CheckedChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles opbGrupoA.CheckedChanged
		Try
			If eventSender.Checked Then
				istrGrupo = "A"
			End If
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: opbGrupoA_CheckedChanged" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub
	Private Sub opbGrupoB_CheckedChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles opbGrupoB.CheckedChanged
		Try
			If eventSender.Checked Then
				istrGrupo = "B"
			End If
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: opbGrupoB_CheckedChanged" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub cmdLocalizar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdLocalizar.Click
		Try
			Call frmLocalizaUnidade.Show()
			Call frmLocalizaUnidade.SetaLocalizaUnidade("U", Me)
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: cmdLocalizar_Click" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub cmdFiltrar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdFiltrar.Click
		Try
			If Len(Trim(Me.txtZona.Text)) > 0 And Len(Trim(Me.txtLivro.Text)) > 0 And Len(Trim(Me.txtConta.Text)) > 0 Then
				Call encheConsulta()
			Else
				Call MsgBox("Falta informar o identificador da unidade consumidora!", MsgBoxStyle.Exclamation, gstrTituloMensagem)
			End If
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: cmdFiltrar_Click" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try

	End Sub

	Public Sub SetaCodigo(ByVal alngUnidId As Integer, ByVal astrZona As String, ByVal astrLivro As String, ByVal astrConta As String, ByVal astrGrupo As String, Optional ByVal astrSituacao As String = "")
		Try
			'ifrmQuemChama = afrmQuemChama
			'icrpOs = acrpOS
			'icrpCarga = acrpCarga
			'icrpCroqui = acrpCroqui
			'ifrmQuemChama.Enabled = False
			ilngUnidId = alngUnidId
			Me.txtZona.Text = astrZona
			Me.txtLivro.Text = astrLivro
			Me.txtConta.Text = astrConta

			If UCase(astrGrupo) = "A" Then
				istrGrupo = "A"
				Me.opbGrupoA.Checked = True
			ElseIf UCase(astrGrupo) = "B" Then
				istrGrupo = "B"
				Me.opbGrupoB.Checked = True
			End If
			istrSitUc = astrSituacao
			Me.txtDataSol.Text = VB6.Format(Date.Now, "dd/mm/yyyy")
			Me.txtHoraSol.Text = VB6.Format(Date.Now, "HH:MM")
			Call EncheComboExecutor()
			Call encheComboServicos()

			If cmbExecutor.Items.Count > 0 Then cmbExecutor.SelectedIndex = 0
			If cmbServDescri.Items.Count > 0 Then cmbServDescri.SelectedIndex = 0
			Call cmbServDescri_SelectedIndexChanged(cmbServDescri, New System.EventArgs())

			Call encheConsulta()
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: SetaCodigo" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub encheConsulta()
		Dim llngConsId As Integer
		Dim lstrRegiao As String
		Dim lstrTpLiga As String
		Dim lstrSql As String

		Try

			Me.txtDivTot.Text = "0,00"
			' ----- Dados do Consumidor
			lstrSql = ""
			lstrSql = lstrSql & "SELECT `uc`.`cons_id`, "
			lstrSql = lstrSql & "       `uc`.`end`, "
			lstrSql = lstrSql & "       `uc`.`bairro`, "
			lstrSql = lstrSql & "       `uc`.`cidade`, "
			lstrSql = lstrSql & "       `uc`.`nome`, "
			lstrSql = lstrSql & "       `uc`.`regiao`, "
			lstrSql = lstrSql & "       `uc`.`tp_ligacao` "
			'lstrSql = lstrSql & "  FROM `unid" & LCase(istrGrupo) & "` as `uc` "
			'lstrSql = lstrSql & " WHERE `uc`.`unid_id` = " & ilngUnidId & " "
			lstrSql = lstrSql & "  FROM `uc_faturamento` as `uc` "
			lstrSql = lstrSql & " WHERE `uc`.`id` = " & ilngUnidId & " AND left(`uc`.`grupo`,1) = '" & UCase(istrGrupo) & "' "

			objAtualizaBancoDados.QUERY_NAME = lstrSql
			dt = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)


			If dt.Rows.Count > 0 Then
				For Each row As DataRow In dt.Rows

					llngConsId = CInt(IIf(IsDBNull(row.Item("cons_id")), 0, row.Item("cons_id")))
					lblEndereco.Text = Trim(IIf(IsDBNull(row.Item("end")), "", row.Item("end")))
					lblBairro.Text = Trim(IIf(IsDBNull(row.Item("bairro")), "", row.Item("bairro")))
					lblCidade.Text = Trim(IIf(IsDBNull(row.Item("cidade")), "", row.Item("cidade")))
					Me.txtNomeSol.Text = Trim(IIf(IsDBNull(row.Item("nome")), "", row.Item("nome")))
					lstrRegiao = Trim(IIf(IsDBNull(row.Item("regiao")), "U", row.Item("regiao")))
					lstrTpLiga = Trim(IIf(IsDBNull(row.Item("tp_ligacao")), "A", row.Item("tp_ligacao")))

					If lstrRegiao = "U" Then
						If cmbRegiao.Items.Count > 0 Then
							Me.cmbRegiao.SelectedIndex = 0
						End If
					Else
							If cmbRegiao.Items.Count > 0 Then
							Me.cmbRegiao.SelectedIndex = 1
						End If
					End If

					Me.cmbRegiao.Enabled = False

					If lstrTpLiga = "A" Then
						If cmbTpLigacao.Items.Count > 0 Then
							Me.cmbTpLigacao.SelectedIndex = 0
						End If
					Else
						If cmbTpLigacao.Items.Count > 0 Then
							Me.cmbTpLigacao.SelectedIndex = 1
						End If
					End If

					Me.cmbTpLigacao.Enabled = False

				Next
			Else
				Call MsgBox("Unidade Consumidora não encontrada!", MsgBoxStyle.Exclamation, gstrTituloMensagem)
			End If

			' ----- Início da leitura dos serviços solicitados
			Call MontaGridAndamento()
			Call EncheGridAndamento()
			' ----- Inicio da leitura da dívida ativa
			Call MontaGridDivida()
			Call EncheGridDivida()
			If llngConsId > 0 Then
				lstrSql = ""
				lstrSql = lstrSql & "SELECT `consum`.`nome`, "
				lstrSql = lstrSql & "       `consum`.`cgc`, "
				lstrSql = lstrSql & "       `consum`.`rg`, "
				lstrSql = lstrSql & "       `consum`.`dddtel`, "
				lstrSql = lstrSql & "       `consum`.`telefone`, "
				lstrSql = lstrSql & "       `consum`.`dddcel`, "
				lstrSql = lstrSql & "       `consum`.`cel` "
				lstrSql = lstrSql & "  FROM `consum` "
				lstrSql = lstrSql & " WHERE `consum`.`consreg` = " & llngConsId
				objAtualizaBancoDados.QUERY_NAME = lstrSql
				dt2 = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)

				If dt2.Rows.Count > 0 Then
					For Each row2 As DataRow In dt2.Rows
						Me.lblMorador.Text = Trim(IIf(IsDBNull(row2.Item("nome")), "", row2.Item("nome")))
						Me.txtCpfCgc.Text = Trim(IIf(IsDBNull(row2.Item("cgc")), "", row2.Item("cgc")))
						If Len(Trim(txtCpfCgc.Text)) = 11 Then
							txtCpfCgc.Text = Mid(txtCpfCgc.Text, 1, 3) & "." & Mid(txtCpfCgc.Text, 4, 3) & "." & Mid(txtCpfCgc.Text, 7, 3) & "-" & Mid(txtCpfCgc.Text, 10, 2)
						ElseIf Len(Trim(txtCpfCgc.Text)) = 14 Then
							txtCpfCgc.Text = Mid(txtCpfCgc.Text, 1, 2) & "." & Mid(txtCpfCgc.Text, 3, 3) & "." & Mid(txtCpfCgc.Text, 6, 3) & "/" & Mid(txtCpfCgc.Text, 9, 4) & "-" & Mid(txtCpfCgc.Text, 13, 2)
						End If
						Me.txtRg.Text = Trim(IIf(IsDBNull(row2.Item("rg")), "", row2.Item("rg")))
						Me.txtDDDTel.Text = Trim(IIf(IsDBNull(row2.Item("dddtel")), "", row2.Item("dddtel")))
						Me.txtTel.Text = Trim(IIf(IsDBNull(row2.Item("telefone")), "", row2.Item("telefone")))
						Me.txtDDDCel.Text = Trim(IIf(IsDBNull(row2.Item("dddcel")), "", row2.Item("dddcel")))
						Me.txtCelular.Text = Trim(IIf(IsDBNull(row2.Item("cel")), "", row2.Item("cel")))
						If Len(Trim(Me.txtTel.Text)) = 8 Then
							Me.txtTel.Text = VB.Left(Me.txtTel.Text, 4) & "-" & VB.Right(Me.txtTel.Text, 4)
						ElseIf Len(Trim(Me.txtTel.Text)) = 10 Then
							Me.txtTel.Text = "(" & VB.Left(Me.txtTel.Text, 2) & ") " & Mid(Me.txtTel.Text, 3, 4) & "-" & VB.Right(Me.txtTel.Text, 4)
						End If
					Next
				Else
					Call MsgBox("Consumidor não encontrado!", MsgBoxStyle.Exclamation, gstrTituloMensagem)
				End If

			End If
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: encheConsulta" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try

	End Sub

	Private Sub MontaGridAndamento()
		Try

			With gridAndamento
				.Redraw = False
				.Rows = 1
				Call .Clear()
				.set_ColWidth(0, 1200)
				.set_TextMatrix(0, 0, "Protocolo")
				.set_ColWidth(1, 1000)
				.set_TextMatrix(0, 1, "Data Solic.")
				.set_ColWidth(2, 1000)
				.set_TextMatrix(0, 2, "Hora Solic")
				.set_ColWidth(3, 4180)
				.set_TextMatrix(0, 3, "Descrição do Serviço")
				.set_ColWidth(4, 1000)
				.set_TextMatrix(0, 4, "Prioridade")
				.set_ColWidth(5, 1000)
				.set_TextMatrix(0, 5, "Situação")
				.set_ColWidth(6, 1000)
				.set_TextMatrix(0, 6, "Valor (R$)")
				.set_ColWidth(7, 1000)
				.set_TextMatrix(0, 7, "ITENSSERV")
				.Redraw = True
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: MontaGridAndamento" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub EncheGridAndamento()
		Dim lstrPro As String
		Dim ldteSol As Date
		Dim lstrHor As String
		Dim lstrCod As String
		Dim lstrDes As String
		Dim lstrIte As String
		Dim lstrPri As String
		Dim lstrSit As String
		Dim ldblVlr As Double
		Dim lstrSql As String
		Dim sHoraSoli

		Try

			Me.gridAndamento.Redraw = False
			lstrSql = ""
			lstrSql = lstrSql & "SELECT `solserv`.`protocolo`, "
			lstrSql = lstrSql & "       `solserv`.`data_soli`, "
			lstrSql = lstrSql & "       `solserv`.`hora_soli`, "
			lstrSql = lstrSql & "       `solserv`.`itensserv`, "
			lstrSql = lstrSql & "       `solserv`.`prioridade`,"
			lstrSql = lstrSql & "       `solserv`.`sit` "
			lstrSql = lstrSql & "  FROM `solserv` "
			lstrSql = lstrSql & " WHERE `solserv`.`sit` = 'A' "
			'lstrSql = lstrSql & "   AND `solserv`.`unid` = '" & UCase(istrGrupo) & "' "
			lstrSql = lstrSql & "   AND `solserv`.`unid_id` = " & ilngUnidId
			objAtualizaBancoDados.QUERY_NAME = lstrSql
			dt = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)

			If dt.Rows.Count > 0 Then
				For Each row As DataRow In dt.Rows
					lstrPro = Trim(IIf(IsDBNull(row.Item("protocolo")), "", row.Item("protocolo")))
					ldteSol = CDate(IIf(IsDBNull(row.Item("data_soli")), Date.Now, row.Item("data_soli")))
					'lstrHor = VB6.Format(IIf(IsDBNull(row.Item("hora_soli")), Date.Now, row.Item("hora_soli")), "HH:MM")
					sHoraSoli = IIf(IsDBNull(row.Item("hora_soli")), Date.Now, row.Item("hora_soli"))
					lstrIte = Trim(IIf(IsDBNull(row.Item("itensserv")), "", row.Item("itensserv")))
					lstrCod = VB.Left(lstrIte, 10)
					lstrDes = pegaDescrServ(lstrCod)
					lstrPri = Trim(IIf(IsDBNull(row.Item("prioridade")), "N", row.Item("prioridade")))
					lstrSit = Trim(IIf(IsDBNull(row.Item("sit")), "A", row.Item("sit")))
					ldblVlr = BuscaVlrItem(lstrIte, lstrCod)

					sHoraSoli = Convert.ToString(sHoraSoli)

					With gridAndamento
						.Rows = .Rows + 1
						.set_TextMatrix(.Rows - 1, 0, lstrPro)
						.set_TextMatrix(.Rows - 1, 1, ldteSol)
						.set_TextMatrix(.Rows - 1, 2, sHoraSoli)
						.set_TextMatrix(.Rows - 1, 3, lstrDes)
						.set_TextMatrix(.Rows - 1, 4, lstrPri)
						.set_TextMatrix(.Rows - 1, 5, lstrSit)
						.set_TextMatrix(.Rows - 1, 6, VB6.Format(ldblVlr, "Standard"))
						.set_TextMatrix(.Rows - 1, 7, lstrCod)
					End With

				Next
			End If
			Me.gridAndamento.Redraw = True
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: EncheGridAndamento" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Function pegaDescrServ(ByVal astrCodserv As String) As String
		Dim lstrDes As String
		Dim lstrSql As String
		Try

			lstrSql = ""
			lstrSql = lstrSql & "SELECT `codigos`.`descri` "
			lstrSql = lstrSql & "  FROM `codigos` "
			lstrSql = lstrSql & " WHERE `codigos`.`num` = '" & astrCodserv & "' "

			objAtualizaBancoDados.QUERY_NAME = lstrSql
			dt = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)

			If dt.Rows.Count > 0 Then
				For Each row As DataRow In dt.Rows
					lstrDes = Trim(IIf(IsDBNull(row.Item("descri")), "", row.Item("descri")))
				Next
			Else
				lstrDes = ""
			End If
			pegaDescrServ = lstrDes

		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: pegaDescrServ" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Function
		End Try
	End Function

	Private Sub MontaGridDivida()
		Try
			With gridDivida
				.Redraw = False
				.Rows = 1
				Call .Clear()
				.set_ColWidth(0, 500)
				.set_TextMatrix(0, 0, "Id")
				.set_ColWidth(1, 6500)
				.set_TextMatrix(0, 1, "Descrição")
				.set_ColWidth(2, 1000)
				.set_TextMatrix(0, 2, "Valor (R$)")
				.set_ColWidth(3, 1200)
				.set_TextMatrix(0, 3, "Data Inicial")
				.set_ColWidth(4, 1200)
				.set_TextMatrix(0, 4, "Data Final")
				.Redraw = True
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: MontaGridDivida" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub EncheGridDivida()
		Dim llngId As Integer
		Dim lstrCod As String
		Dim lstrDes As String
		Dim ldblVlr As Double
		Dim ldblTot As Double
		Dim ldteIni As Date
		Dim ldteFim As Date
		Dim ldteBas As Date
		Dim lstrSql As String

		Try

			Me.gridDivida.Redraw = False
			ldteBas = CDate("01/" & GetConfig("mes.ano.faturamento"))
			ldblTot = 0
			lstrSql = ""
			lstrSql = lstrSql & "SELECT * "
			lstrSql = lstrSql & "  FROM `taxas` "
			lstrSql = lstrSql & " WHERE `zona` = """ & Trim(txtZona.Text) & """ "
			lstrSql = lstrSql & "   AND `livro` = """ & Trim(txtLivro.Text) & """ "
			lstrSql = lstrSql & "   AND `conta` = """ & Trim(txtConta.Text) & """ "
			lstrSql = lstrSql & "   AND """ & VB6.Format(ldteBas, "yyyy-MM-dd") & """ BETWEEN `dt_ini` AND `dt_fim` "
			objAtualizaBancoDados.QUERY_NAME = lstrSql
			dt = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)

			If dt.Rows.Count > 0 Then
				For Each row As DataRow In dt.Rows
					llngId = CInt(IIf(IsDBNull(row.Item("id")), 0, row.Item("id")))
					lstrCod = Trim(IIf(IsDBNull(row.Item("codigo")), "", row.Item("codigo")))
					lstrDes = pegaDescrServ(lstrCod)
					ldblVlr = CDbl(IIf(IsDBNull(row.Item("valor")), "", row.Item("valor")))
					ldteIni = CDate(IIf(IsDBNull(row.Item("dt_ini")), Date.Now, row.Item("dt_ini")))
					ldteFim = CDate(IIf(IsDBNull(row.Item("dt_fim")), Date.Now, row.Item("dt_fim")))
					With gridDivida
						.Rows = .Rows + 1
						.set_TextMatrix(.Rows - 1, 0, llngId)
						.set_TextMatrix(.Rows - 1, 1, lstrDes)
						.set_TextMatrix(.Rows - 1, 2, VB6.Format(ldblVlr, "Standard"))
						.set_TextMatrix(.Rows - 1, 3, ldteIni)
						.set_TextMatrix(.Rows - 1, 4, ldteFim)
					End With
					ldblTot = ldblTot + ldblVlr
				Next
			End If
			Me.txtDivTot.Text = VB6.Format(ldblTot, "Standard")
			Me.gridDivida.Redraw = True
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: EncheGridDivida" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtRg_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtRg.Enter
		Try
			With Me.txtRg
				.SelectionStart = 0
				.SelectionLength = Len(.Text)
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtRg_Enter" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtNomeSol_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtNomeSol.Enter
		Try
			With Me.txtNomeSol
				.SelectionStart = 0
				.SelectionLength = Len(.Text)
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtNomeSol_Enter" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtCpfCgc_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtCpfCgc.Enter
		Try
			With Me.txtCpfCgc
				.SelectionStart = 0
				.SelectionLength = Len(.Text)
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtCpfCgc_Enter" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtTel_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtTel.Enter
		Try
			With Me.txtTel
				.SelectionStart = 0
				.SelectionLength = Len(.Text)
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtTel_Enter" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub
	Private Sub txtDataSol_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtDataSol.Enter
		Try
			With Me.txtDataSol
				.SelectionStart = 0
				.SelectionLength = Len(.Text)
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtDataSol_Enter" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtDataSol_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtDataSol.Leave
		txtDataSol.Text = FData(txtDataSol.Text)
	End Sub

	Private Sub txtHoraSol_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtHoraSol.Enter
		Try
			With Me.txtHoraSol
				.SelectionStart = 0
				.SelectionLength = Len(.Text)
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtHoraSol_Enter" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtDescrServ_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtDescrServ.Enter
		Try
			With Me.txtDescrServ
				.SelectionStart = 0
				.SelectionLength = Len(.Text)
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtDescrServ_Enter" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtPontoRefer_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtPontoRefer.Enter
		Try
			With Me.txtPontoRefer
				.SelectionStart = 0
				.SelectionLength = Len(.Text)
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtPontoRefer_Enter" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub cbtReg_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cbtReg.Click
		'Dim lstrProto As String
		Dim lstrSolMeio As String
		Dim lstrRota As String
		Dim lstrNome As String
		Dim lstrCpfCgc As String
		Dim lstrIE As String
		Dim lstrEndereco As String
		Dim lstrBairro As String
		Dim lstrMunicip As String
		Dim lstrMedidor As String
		Dim llngMedidor As Integer
		Dim lstrTransf As String
		Dim llngTpMedid As Integer
		Dim lstrFase As String
		Dim lstrFaseLig As String
		Dim lstrClasse As String
		Dim lstrTa As String
		Dim lstrSituacao As String
		Dim lstrAtividade As String
		Dim lstrNomeAnt As String
		Dim lstrMedAnt As String
		Dim lstrNomePos As String
		Dim lstrMedPos As String
		Dim lstrTpLigacao As String
		Dim lstrRg As String
		Dim lstrInscr As String
		Dim llngSeq As Integer
		Dim lblnContinua As Boolean
		Dim lstrSql As String
		Dim iCount As Integer

		Try

			iblnCargaSimNao = False
			iblnCroquiSimNao = False
			istrNumCodigo = VB.Right(cmbServDescri.Text, 4) & VB6.Format(VB6.GetItemData(Me.cmbServDescri, Me.cmbServDescri.SelectedIndex), "000000")

			lblnContinua = True
			If Trim(Me.txtNomeSol.Text) <> "" Then
				' Insert dos serviços
				Select Case cmbSolicit.SelectedIndex
					Case 0
						lstrSolMeio = "P"
					Case 1
						lstrSolMeio = "F"
					Case 2
						lstrSolMeio = "E"
					Case 3
						lstrSolMeio = "S"
					Case 4
						lstrSolMeio = "O"
					Case Else
						lstrSolMeio = "X"
				End Select

				lstrProto = "OS" & VB6.Format(Date.Now, "YYMMDDHHMMSS")
				lstrSql = ""
				lstrSql = lstrSql & "INSERT INTO `solserv` SET "
				lstrSql = lstrSql & "            `protocolo`    = """ & lstrProto & """, "
				lstrSql = lstrSql & "            `data_soli`    = """ & VB6.Format(Me.txtDataSol.Text, "yyyy-MM-dd") & """, "
				lstrSql = lstrSql & "            `hora_soli`    = """ & VB6.Format(Me.txtHoraSol.Text, "HH:MM:SS") & """, "
				lstrSql = lstrSql & "            `zlc`          = """ & Trim(Me.txtZona.Text) & Trim(Me.txtLivro.Text) & Trim(Me.txtConta.Text) & """, "
				lstrSql = lstrSql & "            `nomesol`      = """ & Trim(Me.txtNomeSol.Text) & """, "
				lstrSql = lstrSql & "            `cpf`          = """ & Me.txtCpfCgc.Text & """, "
				lstrSql = lstrSql & "            `docsol`       = """ & Me.txtRg.Text & """, "
				lstrSql = lstrSql & "            `dddtelsol`    = """ & Me.txtDDDTel.Text & """, "
				lstrSql = lstrSql & "            `telsol`       = """ & Me.txtTel.Text & """, "
				lstrSql = lstrSql & "            `dddcelsol`    = """ & Me.txtDDDCel.Text & """, "
				lstrSql = lstrSql & "            `celsol`       = """ & Me.txtCelular.Text & """, "
				lstrSql = lstrSql & "            `itensserv`    = """ & istrNumCodigo & "?" & Me.txtValor.Text & ";"", "
				lstrSql = lstrSql & "            `ponto_refer`  = """ & Trim(Me.txtPontoRefer.Text) & """, "
				lstrSql = lstrSql & "            `atendente`    = """ & vUsuario.LOGIN & ""","
				lstrSql = lstrSql & "            `descr_serv`   = """ & Trim(Me.txtDescrServ.Text) & """, "
				lstrSql = lstrSql & "            `prioridade`   = """ & UCase(VB.Left(VB6.GetItemString(Me.cmbPriori, Me.cmbPriori.SelectedIndex), 1)) & """, "
				lstrSql = lstrSql & "            `solicit_meio` = """ & lstrSolMeio & """, "
				lstrSql = lstrSql & "            `zona_solic`   = """ & UCase(VB.Left(VB6.GetItemString(Me.cmbRegiao, Me.cmbRegiao.SelectedIndex), 1)) & """, "
				lstrSql = lstrSql & "            `tp_ligacao`   = """ & UCase(VB.Left(VB6.GetItemString(Me.cmbTpLigacao, Me.cmbTpLigacao.SelectedIndex), 1)) & """, "
				lstrSql = lstrSql & "            `unid_id`      = """ & ilngUnidId & """, "
				lstrSql = lstrSql & "            `unid`         = """ & UCase(istrGrupo) & """, "
				lstrSql = lstrSql & "            `padrao`       = """ & VB6.GetItemString(Me.cmbPadrao, Me.cmbPadrao.SelectedIndex) & """, "
				lstrSql = lstrSql & "            `cod_executor` = """ & VB6.GetItemData(Me.cmbExecutor, Me.cmbExecutor.SelectedIndex) & """, "
				lstrSql = lstrSql & "            `sgdenvio`     = """ & IIf(VB.Left(istrNumCodigo, 9) = "904000004" Or VB.Left(istrNumCodigo, 9) = "904000005", "P", "E") & """ "
				objExecAtualizaBancoDados.QUERY_NAME = lstrSql
				repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)

				Call sCarregaTabelaAuxiliar()

				iblnCroquiSimNao = PegaFlgMedidorServico(istrNumCodigo)
				ilngSequencia = llngSeq
				istrProtocolo = lstrProto
				If ilngUnidId <> 0 Then
					If MsgBox("Deseja cadastrar a carga instalada da unidade consumidora?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, gstrTituloMensagem) = MsgBoxResult.Yes Then
						iblnCargaSimNao = True
						Call ifrmCargaInstalada.Show()
						Call ifrmCargaInstalada.SetaCarga(Me.txtZona.Text, Me.txtLivro.Text, Me.txtConta.Text, lstrNome, ilngUnidId, UCase(istrGrupo), Me)
					Else
						Call RetornaCarga()
					End If
				Else
					Call RetornaCarga()
				End If
			Else
				Call MsgBox("Nome do solicitante da UC não preenchido!", MsgBoxStyle.Exclamation, gstrTituloMensagem)
				lblnContinua = False
			End If

			If lblnContinua Then
				Call cmdFechar_Click(cmdFechar, New System.EventArgs())
			End If

		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: cbtReg_Click" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub
	
	Public Sub AtualizaCargaInstalada(ByVal alngUnidId As Integer, ByVal adblCarga As Double, ByVal ablnGravou As Boolean)
		Dim lstrSql As String

		Try
			If ablnGravou Then
				lstrSql = ""
				lstrSql = lstrSql & "UPDATE `uc_faturamento` AS `uc` "
				lstrSql = lstrSql & "   SET `uc`.`carga` = " & adblCarga & " "
				lstrSql = lstrSql & " WHERE `uc`.`id` = " & alngUnidId & " AND `uc`.`grupo` = '" & UCase(istrGrupo) & "' "
				objExecAtualizaBancoDados.QUERY_NAME = lstrSql
				repositorioExecAtualizaBancoDados.Execute(objAtualizaBancoDados)

				Call RetornaCarga()
			End If
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: AtualizaCargaInstalada" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try

	End Sub

	Private Sub RetornaCarga()
		Try
			Call EmiteRel()
			Call limpaDados()
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: RetornaCarga" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Function limpaDados() As Object
		Try
			'Call LimpaCampos((Me.FrameZLC))
			'Call LimpaCampos((Me.FrameSol))
			Call MontaGridDivida()
			Call MontaGridAndamento()
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: limpaDados" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Function
		End Try
	End Function

	Private Sub cmdImprimir_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdImprimir.Click

		Try

			If gridAndamento.Rows > 0 Then

				iblnCroquiSimNao = False
				iblnCargaSimNao = False

				istrNumCodigo = gridAndamento.get_TextMatrix(gridAndamento.RowSel, 7) 'VB.Right(cmbServDescri.Text, 4) & VB6.Format(VB6.GetItemData(Me.cmbServDescri, Me.cmbServDescri.SelectedIndex), "000000")
				iblnCroquiSimNao = PegaFlgMedidorServico(istrNumCodigo)
				lstrProto = gridAndamento.get_TextMatrix(gridAndamento.RowSel, 0)
				If MsgBox("Deseja imprimir o Relatório de carga instalada da unidade consumidora?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, gstrTituloMensagem) = MsgBoxResult.Yes Then
					iblnCargaSimNao = True
				End If
				Call sCarregaTabelaAuxiliar()
				Call EmiteRel()

			End If
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: cmdImprimir_Click" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try

	End Sub

	Private Sub EmiteRel()
		Dim lstrCriterio As String
		Dim sNomeRelatorio As String
		Try

			sNomeRelatorio = "rptOS_EFLUL"
			Call lPrint(sNomeRelatorio)

			If iblnCargaSimNao Then
				sNomeRelatorio = "rptOS_EFLULCarga"
				Call lPrint(sNomeRelatorio)
			End If

			If iblnCroquiSimNao Then
				sNomeRelatorio = "rptcroquiOS"
				Call lPrint(sNomeRelatorio)
			End If

		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: EmiteRel" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try

	End Sub
	
	Private Sub cmdFechar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdFechar.Click
		Call Me.Close()
		'ifrmQuemChama.Enabled = True
	End Sub

	Private Sub txtValor_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtValor.Enter
		Try
			With Me.txtValor
				.SelectionStart = 0
				.SelectionLength = CInt(Len(.Text))
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtValor_Enter" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub
	Private Sub txtValor_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtValor.KeyPress
		Try
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = System.Windows.Forms.Keys.Return Then
				TabEnter(KeyAscii, eventArgs)
			ElseIf KeyAscii <> System.Windows.Forms.Keys.Back And (KeyAscii < System.Windows.Forms.Keys.D0 Or KeyAscii > System.Windows.Forms.Keys.D9) Then
				If KeyAscii = System.Windows.Forms.Keys.Delete Then
					KeyAscii = System.Windows.Forms.Keys.Snapshot
				End If
				If KeyAscii <> System.Windows.Forms.Keys.Snapshot Then
					KeyAscii = 0
				Else
					If InStr(1, Me.txtValor.Text, ",") > 0 Then
						KeyAscii = 0
					End If
				End If
			End If
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtValor_KeyPress" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtValor_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtValor.Leave
		Try
			With Me.txtValor
				.Text = VB6.Format(CDbl(IIf(IsNumeric(.Text), .Text, 0)), "#,##0.00")
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtValor_Leave" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub
	'Public Sub SetaCodigo2(ByVal alngUnidId As Integer, ByVal astrZona As String, ByVal astrLivro As String, ByVal astrConta As String, ByVal astrGrupo As String, ByRef afrmQuemChama As System.Windows.Forms.Form, ByVal astrSituacao As String)

	'	Try
	'		ifrmQuemChama = afrmQuemChama
	'		'ifrmQuemChama.Enabled = False
	'		ilngUnidId = alngUnidId
	'		Me.txtZona.Text = astrZona
	'		Me.txtLivro.Text = astrLivro
	'		Me.txtConta.Text = astrConta

	'		If UCase(astrGrupo) = "A" Then
	'			istrGrupo = "A"
	'			Me.opbGrupoA.Checked = True
	'		ElseIf UCase(astrGrupo) = "B" Then
	'			istrGrupo = "B"
	'			Me.opbGrupoB.Checked = True
	'		End If

	'		istrSitUc = astrSituacao
	'		Me.txtDataSol.Text = VB6.Format(Date.Now, "dd/mm/yyyy")
	'		Me.txtHoraSol.Text = VB6.Format(Date.Now, "HH:MM")
	'		Call EncheComboExecutor()
	'		Call encheComboServicos()

	'		If cmbExecutor.Items.Count > 0 Then cmbExecutor.SelectedIndex = 0
	'		If cmbServDescri.Items.Count > 0 Then cmbServDescri.SelectedIndex = 0
	'		Call cmbServDescri_SelectedIndexChanged(cmbServDescri, New System.EventArgs())

	'		Call encheConsulta()
	'	Catch ex As Exception
	'		MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: SetaCodigo2" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
	'		Exit Sub
	'	End Try
	'End Sub
	Private Sub sCriaTabelaAuxiliares()

		Dim lstrsql As String

		Try

			lstrsql = ""
			lstrsql = "DROP TABLE IF EXISTS `AUX_REL_OS_ARREC`"
			objExecAtualizaBancoDados.QUERY_NAME = lstrsql
			repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)

			lstrsql = ""
			lstrsql = lstrsql & "CREATE TABLE IF NOT EXISTS `AUX_REL_OS_ARREC` (" & vbCrLf
			lstrsql = lstrsql & "  `NM_USUARIO`      varchar(50) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `PROTOCOLO`       varchar(50) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `ZONA`            varchar(10) DEFAULT NULL,  " & vbCrLf
			lstrsql = lstrsql & "  `LIVRO`           varchar(10) DEFAULT NULL,  " & vbCrLf
			lstrsql = lstrsql & "  `CONTA`           varchar(10) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `ROTA`            varchar(10) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `UNID_ID`         varchar(10) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `NOME`            varchar(100) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `ENDERECO`        varchar(100) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `BAIRRO`          varchar(50) DEFAULT NULL,  " & vbCrLf
			lstrsql = lstrsql & "  `CIDADE`          varchar(50) DEFAULT NULL,  " & vbCrLf
			lstrsql = lstrsql & "  `TELEFONE`        varchar(30) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `CPF`             varchar(50) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `IE`              varchar(30) DEFAULT NULL,  " & vbCrLf
			lstrsql = lstrsql & "  `PONTO_REFER`     varchar(100) DEFAULT NULL,  " & vbCrLf
			lstrsql = lstrsql & "  `MEDIDOR`         varchar(20) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `CLASSE`          varchar(50) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `TA`              varchar(10) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `FASE`            varchar(50) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `FASELIG`         varchar(50) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `ATIVIDADE`       varchar(50) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `SERVSOL`         varchar(50) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `DESCR_SERV`      varchar(50) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `PRIORIDADE`      varchar(30) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `ZONA_SERV`       varchar(30) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `ATENDENTE`       varchar(50) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `DATA_SOLI`       varchar(10) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `HORA_SOLI`       varchar(10) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `NOME_SOLI`       varchar(50) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `RG_SOLI`         varchar(20) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `SITUACAO`        varchar(30) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `NOMEANT`         varchar(50) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `MEDANT`          varchar(50) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `NOMEPOS`         varchar(50) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `MEDPOS`          varchar(50) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `PADRAO`          varchar(30) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `TP_LIGACAO`      varchar(20) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `TELEFONE_DDD`    varchar(15) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `CELULAR`         varchar(15) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `CELULAR_DDD`     varchar(15) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `SEQ`             varchar(10) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `TIPO_MEDIDOR`    varchar(30) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `INSTAL`          varchar(30) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `IDMEDIDOR`       varchar(10) DEFAULT NULL) "
			objExecAtualizaBancoDados.QUERY_NAME = lstrsql
			repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)


			lstrsql = ""
			lstrsql = lstrsql & "CREATE TABLE IF NOT EXISTS `AUX_REL_OS_CARGA` (" & vbCrLf
			lstrsql = lstrsql & "  `CODEQUIPAMENTO`      varchar(10) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `EQUIPAMENTO`         varchar(50) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `CARGA`               varchar(10) DEFAULT NULL,  " & vbCrLf
			lstrsql = lstrsql & "  `UNID_ID`             varchar(10) DEFAULT NULL,  " & vbCrLf
			lstrsql = lstrsql & "  `GRUPO`               varchar(10) DEFAULT NULL,  " & vbCrLf
			lstrsql = lstrsql & "  `QTD`                 varchar(10) DEFAULT NULL) "
			objExecAtualizaBancoDados.QUERY_NAME = lstrsql
			repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)


			lstrsql = ""
			lstrsql = lstrsql & "CREATE TABLE IF NOT EXISTS `AUX_REL_SOLSERV` (" & vbCrLf
			lstrsql = lstrsql & "  `COD`            varchar(10) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `PROTOCOLO`      varchar(50) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `DATA_SOLI`      varchar(10) DEFAULT NULL,  " & vbCrLf
			lstrsql = lstrsql & "  `HORA_SOLI`      varchar(10) DEFAULT NULL,  " & vbCrLf
			lstrsql = lstrsql & "  `ZLC`            varchar(10) DEFAULT NULL,  " & vbCrLf
			lstrsql = lstrsql & "  `NOMESOL`        varchar(10) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `DOCSOL`         varchar(50) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `DDDTELSOL`      varchar(10) DEFAULT NULL,  " & vbCrLf
			lstrsql = lstrsql & "  `TELSOL`         varchar(10) DEFAULT NULL,  " & vbCrLf
			lstrsql = lstrsql & "  `DDDCELSOL`      varchar(10) DEFAULT NULL,  " & vbCrLf
			lstrsql = lstrsql & "  `CELSOL`         varchar(10) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `ITENSSERV`      varchar(50) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `DATASOLU`       varchar(10) DEFAULT NULL,  " & vbCrLf
			lstrsql = lstrsql & "  `HORASOLU`       varchar(10) DEFAULT NULL,  " & vbCrLf
			lstrsql = lstrsql & "  `PARCELAS`       varchar(10) DEFAULT NULL,  " & vbCrLf
			lstrsql = lstrsql & "  `PONTO_REFER`    varchar(10) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `ATENDENTE`      varchar(50) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `EXECUTADO`      varchar(10) DEFAULT NULL,  " & vbCrLf
			lstrsql = lstrsql & "  `DESCR_SERV`     varchar(10) DEFAULT NULL,  " & vbCrLf
			lstrsql = lstrsql & "  `PRIORIDADE`     varchar(10) DEFAULT NULL,  " & vbCrLf
			lstrsql = lstrsql & "  `SOLICIT_MEIO`   varchar(10) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `ZONA_SOLIC`     varchar(50) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `UNID_ID`        varchar(10) DEFAULT NULL,  " & vbCrLf
			lstrsql = lstrsql & "  `UNID`           varchar(10) DEFAULT NULL,  " & vbCrLf
			lstrsql = lstrsql & "  `SIT`            varchar(10) DEFAULT NULL,  " & vbCrLf
			lstrsql = lstrsql & "  `CPF`            varchar(10) DEFAULT NULL,  " & vbCrLf
			lstrsql = lstrsql & "  `COD_EXECUTOR`   varchar(10) DEFAULT NULL,  " & vbCrLf
			lstrsql = lstrsql & "  `PADRAO`         varchar(10) DEFAULT NULL) "
			objExecAtualizaBancoDados.QUERY_NAME = lstrsql
			repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)

			lstrsql = ""
			lstrsql = lstrsql & "CREATE TABLE IF NOT EXISTS `AUX_REL_TIPO_FASES` (" & vbCrLf
			lstrsql = lstrsql & "  `ID`                        varchar(10) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `DESCRICAO`                 varchar(50) DEFAULT NULL) "
			objExecAtualizaBancoDados.QUERY_NAME = lstrsql
			repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)

			lstrsql = ""
			lstrsql = lstrsql & "CREATE TABLE IF NOT EXISTS `AUX_REL_TIPO_MEDIDOR` (" & vbCrLf
			lstrsql = lstrsql & "  `ID`                        varchar(10) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `DESCRICAO`                 varchar(50) DEFAULT NULL) "
			objExecAtualizaBancoDados.QUERY_NAME = lstrsql
			repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)

			lstrsql = ""
			lstrsql = lstrsql & "CREATE TABLE IF NOT EXISTS `AUX_REL_TIPO_GRANDEZA_MEDIDA` (" & vbCrLf
			lstrsql = lstrsql & "  `ID`                        varchar(10) DEFAULT NULL, " & vbCrLf
			lstrsql = lstrsql & "  `DESCRICAO`                 varchar(50) DEFAULT NULL) "
			objExecAtualizaBancoDados.QUERY_NAME = lstrsql
			repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)


		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: sCriaTabelaAuxiliares" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try

	End Sub

	Private Sub sCarregaTabelaAuxiliar()
		'Dim lstrProto As String
		'Dim lstrSolMeio As String
		Dim lstrRota As String
		Dim lstrNome As String
		Dim lstrCpfCgc As String
		Dim lstrIE As String
		Dim lstrEndereco As String
		Dim lstrBairro As String
		Dim lstrMunicip As String
		Dim lstrMedidor As String
		Dim llngMedidor As Integer
		Dim lstrTransf As String
		Dim llngTpMedid As Integer
		Dim lstrFase As String
		Dim lstrFaseLig As String
		Dim lstrClasse As String
		Dim lstrTa As String
		Dim lstrSituacao As String
		Dim lstrAtividade As String
		Dim lstrNomeAnt As String
		Dim lstrMedAnt As String
		Dim lstrNomePos As String
		Dim lstrMedPos As String
		Dim lstrTpLigacao As String
		Dim lstrRg As String
		Dim lstrInscr As String


		Dim lstrDescrServ As String
		Dim lstrTelefone As String
		Dim lstrdddTelefone As String
		Dim lstrCelular As String
		Dim lstrdddCelular As String

		Dim lstrEquipamento As String
		Dim lstrCodEquipamento As String
		Dim lstrqtd As String
		Dim lstrCarga As String
		Dim lstrPontoRefer As String
		Dim lstrPadrao As String
		Dim lstrZLC As String
		Dim lstrZona, lstrLivro, lstrConta As String
		Dim lstrNomeSol As String
		Dim lstrServSol As String
		Dim lstrCodServ As String
		Dim lstrDataSoli, lstrHoraSoli
		Dim lstrPrioridade As String
		Dim lstrZonaSolic As String
		Dim lstrDocSol As String

		Dim llngSeq As Integer
		'Dim lblnContinua As Boolean
		Dim lstrSql As String
		Dim iCount As Integer

		Try
			'	' ----- Pega o sequencial da OS
			lstrSql = ""
			lstrSql = lstrSql & "SELECT `solserv`.`cod`, `solserv`.`descr_serv`, `solserv`.`telsol`, `solserv`.`padrao`,`solserv`.`ZLC`, "
			lstrSql = lstrSql & " `solserv`.`dddtelsol`, `solserv`.`celsol`, `solserv`.`dddcelsol` , `solserv`.`ponto_refer`,`solserv`.`nomesol`, "
			lstrSql = lstrSql & " `solserv`.`itensserv`, `solserv`.`data_soli`, `solserv`.`hora_soli` , `solserv`.`prioridade`,`solserv`.`zona_solic`, `solserv`.`docsol`"
			lstrSql = lstrSql & "  FROM `solserv` "
			lstrSql = lstrSql & " WHERE `protocolo` = """ & lstrProto & """ "
			objAtualizaBancoDados.QUERY_NAME = lstrSql
			dt = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)



			If dt.Rows.Count > 0 Then
				For Each row As DataRow In dt.Rows
					llngSeq = IIf(IsDBNull(row.Item("cod")), 0, row.Item("cod"))
					lstrDescrServ = IIf(IsDBNull(row.Item("descr_serv")), 0, row.Item("descr_serv"))
					lstrZLC = IIf(IsDBNull(row.Item("ZLC")), 0, row.Item("ZLC"))
					lstrZona = Mid(lstrZLC, 1, 3)
					lstrLivro = Mid(lstrZLC, 4, 2)
					lstrConta = Mid(lstrZLC, 6, 10)
					lstrPontoRefer = IIf(IsDBNull(row.Item("ponto_refer")), 0, row.Item("ponto_refer"))
					lstrNomeSol = IIf(IsDBNull(row.Item("nomesol")), 0, row.Item("nomesol"))
					lstrCodServ = IIf(IsDBNull(row.Item("itensserv")), 0, row.Item("itensserv"))
					lstrCodServ = VB.Left(lstrCodServ, 10)
					lstrServSol = pegaDescrServ(lstrCodServ)
					lstrDataSoli = IIf(IsDBNull(row.Item("data_soli")), 0, row.Item("data_soli"))
					lstrHoraSoli = IIf(IsDBNull(row.Item("hora_soli")), 0, row.Item("hora_soli"))
					lstrHoraSoli = Convert.ToString(lstrHoraSoli)
					lstrPrioridade = IIf(IsDBNull(row.Item("prioridade")), 0, row.Item("prioridade"))
					lstrZonaSolic = IIf(IsDBNull(row.Item("zona_solic")), 0, row.Item("zona_solic"))
					lstrDocSol = IIf(IsDBNull(row.Item("docsol")), 0, row.Item("docsol"))
				Next
			Else
				llngSeq = 0
			End If

			' ----- Apaga os dados da tabela auxiliares
			lstrSql = "DELETE FROM `AUX_REL_OS_ARREC` WHERE `nm_usuario` = """ & My.Computer.Name & """ "
			objExecAtualizaBancoDados.QUERY_NAME = lstrSql
			repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)

			lstrSql = "DELETE FROM `AUX_REL_OS_CARGA`"
			objExecAtualizaBancoDados.QUERY_NAME = lstrSql
			repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)

			lstrSql = "DELETE FROM `AUX_REL_SOLSERV`"
			objExecAtualizaBancoDados.QUERY_NAME = lstrSql
			repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)

			Call sDadosEmpresa(LImagem, sNomeEmpresa, sEnderecoEmpresa, sCepEmpresa, sCidadeEmpresa, sUFempresa, sBairroEmpresa, sFoneEmpresa, sWebEmpresa)

			lstrSql = ""
			lstrSql = lstrSql & "SELECT * "
			lstrSql = lstrSql & "  FROM `uc_faturamento` "
			lstrSql = lstrSql & " WHERE `id` = " & ilngUnidId & " AND left(`grupo`,1) = '" & UCase(istrGrupo) & "'"
			objAtualizaBancoDados.QUERY_NAME = lstrSql
			dt2 = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)


			If dt2.Rows.Count > 0 Then
				For Each row2 As DataRow In dt2.Rows

					lstrRg = Trim(IIf(IsDBNull(row2.Item("rg")), "", row2.Item("rg")))
					lstrInscr = Trim(IIf(IsDBNull(row2.Item("insc")), "", row2.Item("insc")))
					lstrIE = IIf(Len(lstrInscr) = 0, lstrRg, lstrInscr)
					lstrRota = VB6.Format(Trim(IIf(IsDBNull(row2.Item("rota")), "0", row2.Item("rota"))), "00000000")
					lstrNome = Trim(IIf(IsDBNull(row2.Item("nome")), "", row2.Item("nome")))
					lstrCpfCgc = Trim(IIf(IsDBNull(row2.Item("cpf_cnpj")), "", row2.Item("cpf_cnpj")))
					lstrEndereco = IIf(IsDBNull(row2.Item("end")), "", row2.Item("end")) & " - " & IIf(IsDBNull(row2.Item("numero")), "", row2.Item("numero")) & " " & IIf(IsDBNull(row2.Item("complement")), "", row2.Item("complement"))
					lstrBairro = Trim(IIf(IsDBNull(row2.Item("bairro")), "", row2.Item("bairro")))
					lstrMunicip = Trim(IIf(IsDBNull(row2.Item("cidade")), "", row2.Item("cidade")))

					' ----- Verifica Se e UnidA ou B porque o campo do numero do medidor é diferente nas tabelas
					If UCase(istrGrupo) = "A" Then
						lstrMedidor = Trim(IIf(IsDBNull(row2.Item("eletr")), "", row2.Item("eletr")))
					Else
						lstrMedidor = Trim(IIf(IsDBNull(row2.Item("num")), "", row2.Item("num")))
						lstrFaseLig = Trim(IIf(IsDBNull(row2.Item("faselig")), "ABCN", row2.Item("faselig")))
					End If
					llngMedidor = CInt(IIf(IsDBNull(row2.Item("idmedidor")), 0, row2.Item("idmedidor")))
					lstrTransf = Trim(IIf(IsDBNull(row2.Item("instal")), "0000", row2.Item("instal")))
					llngTpMedid = CInt(IIf(IsDBNull(row2.Item("idtipo_medidor")), 0, row2.Item("idtipo_medidor")))
					lstrFase = Trim(IIf(IsDBNull(row2.Item("fase")), "M", row2.Item("fase")))
					lstrClasse = Trim(IIf(IsDBNull(row2.Item("clas")), "0", row2.Item("clas")))
					lstrTa = Trim(IIf(IsDBNull(row2.Item("ta")), "01B1", row2.Item("ta")))
					lstrSituacao = Trim(IIf(IsDBNull(row2.Item("situacao")), "L", row2.Item("situacao")))
					lstrTpLigacao = Trim(IIf(IsDBNull(row2.Item("tp_ligacao")), "A", row2.Item("tp_ligacao")))
				Next
			End If


			' ----- Busca a descrição da classe
			lstrSql = ""
			lstrSql = lstrSql & "SELECT * "
			lstrSql = lstrSql & "  FROM `classe` "
			lstrSql = lstrSql & " WHERE `codigo` = """ & lstrClasse & """ "

			objAtualizaBancoDados.QUERY_NAME = lstrSql
			dt3 = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)

			If dt3.Rows.Count > 0 Then
				For Each row3 As DataRow In dt3.Rows
					lstrAtividade = Trim(IIf(IsDBNull(row3.Item("descricao")), "Atividade não encontrada", row3.Item("descricao")))
				Next
			End If

			' ----- Busca Consumidor Anterior e Posterior
			lstrSql = ""
			lstrSql = lstrSql & "   SELECT `uc_faturamento`.`cons_id`, `uc_faturamento`.`id`, `uc_faturamento`.`zona`, `uc_faturamento`.`livro`, `uc_faturamento`.`conta`, `uc_faturamento`.`rota`, `uc_faturamento`.`nome`, "
			lstrSql = lstrSql & "          `uc_faturamento`.`eletr` AS `medidor` "
			lstrSql = lstrSql & "     FROM `uc_faturamento` "
			lstrSql = lstrSql & "    WHERE RIGHT(`uc_faturamento`.`rota`, 6) IN(" & CDbl(VB.Right(lstrRota, 6)) - 1 & " , " & CDbl(VB.Right(lstrRota, 6)) + 1 & ") AND left(Grupo,1) = '" & UCase(istrGrupo) & "'"
			lstrSql = lstrSql & " ORDER BY RIGHT(`uc_faturamento`.`rota`, 6) ASC"
			objAtualizaBancoDados.QUERY_NAME = lstrSql
			dt4 = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)

			If dt4.Rows.Count > 0 Then
				iCount = 1
				For Each row4 As DataRow In dt4.Rows
					If iCount = 1 Then
						lstrNomeAnt = Trim(IIf(IsDBNull(row4.Item("nome")), "", row4.Item("nome")))
						lstrMedAnt = Trim(IIf(IsDBNull(row4.Item("medidor")), "", row4.Item("medidor")))
					ElseIf iCount = 2 Then
						lstrNomePos = Trim(IIf(IsDBNull(row4.Item("nome")), "", row4.Item("nome")))
						lstrMedPos = Trim(IIf(IsDBNull(row4.Item("medidor")), "", row4.Item("medidor")))
						Exit For
					End If
					iCount = iCount + 1
				Next
			End If

			' ----- Fim Busca Consumidor Anterior e Posterior
			lstrSql = "INSERT INTO `AUX_REL_OS_ARREC` SET "
			lstrSql = lstrSql & "            `nm_usuario`     = """ & My.Computer.Name & """, "
			lstrSql = lstrSql & "            `protocolo`      = """ & lstrProto & """, "
			lstrSql = lstrSql & "            `zona`           = """ & Trim(lstrZona) & """, "
			lstrSql = lstrSql & "            `livro`          = """ & Trim(lstrLivro) & """, "
			lstrSql = lstrSql & "            `conta`          = """ & Trim(lstrConta) & """, "
			lstrSql = lstrSql & "            `rota`           = """ & lstrRota & """, "
			lstrSql = lstrSql & "            `unid_id`        = """ & ilngUnidId & """, "
			lstrSql = lstrSql & "            `nome`           = """ & lstrNome & """, "
			lstrSql = lstrSql & "            `endereco`       = """ & lstrEndereco & """, "
			lstrSql = lstrSql & "            `bairro`         = """ & lstrBairro & """, "
			lstrSql = lstrSql & "            `cidade`         = """ & lstrMunicip & """, "
			lstrSql = lstrSql & "            `telefone`       = """ & Trim(lstrTelefone) & """, "
			lstrSql = lstrSql & "            `telefone_ddd`   = """ & Trim(lstrdddTelefone) & """, "
			lstrSql = lstrSql & "            `celular`        = """ & Trim(lstrCelular) & """, "
			lstrSql = lstrSql & "            `celular_ddd`    = """ & Trim(lstrdddCelular) & """, "
			lstrSql = lstrSql & "            `cpf`            = """ & lstrCpfCgc & ""","
			lstrSql = lstrSql & "            `ie`             = """ & lstrIE & """, "
			lstrSql = lstrSql & "            `ponto_refer`    = """ & Trim(lstrPontoRefer) & """, "
			lstrSql = lstrSql & "            `medidor`        = """ & IIf(lstrMedidor = "", 0, lstrMedidor) & """, "
			lstrSql = lstrSql & "            `tipo_medidor`   = """ & IIf(llngTpMedid = 1, "Eletromecânico", IIf(llngTpMedid = 11, "Eletrônico", "")) & """, "
			lstrSql = lstrSql & "            `classe`         = """ & lstrClasse & """, "
			lstrSql = lstrSql & "            `ta`             = """ & lstrTa & """, "
			lstrSql = lstrSql & "            `fase`           = """ & lstrFase & """, "
			lstrSql = lstrSql & "            `faselig`        = """ & lstrFaseLig & """, "
			lstrSql = lstrSql & "            `atividade`      = """ & lstrAtividade & """, "
			lstrSql = lstrSql & "            `servsol`        = """ & Trim(lstrServSol) & """, "
			lstrSql = lstrSql & "            `descr_serv`     = """ & Trim(lstrDescrServ) & """, "
			lstrSql = lstrSql & "            `prioridade`     = """ & Trim(lstrPrioridade) & """, "
			lstrSql = lstrSql & "            `zona_serv`      = """ & UCase(lstrZonaSolic) & """, "
			lstrSql = lstrSql & "            `atendente`      = """ & UCase(vUsuario.NOME) & """, "
			lstrSql = lstrSql & "            `data_soli`      = """ & VB6.Format(Trim(lstrDataSoli), "yyyy-MM-dd") & """, "
			lstrSql = lstrSql & "            `hora_soli`      = """ & VB6.Format(Trim(lstrHoraSoli), "hh:mm:ss") & """, "
			lstrSql = lstrSql & "            `nome_soli`      = """ & Trim(lstrNomeSol) & """, "
			lstrSql = lstrSql & "            `rg_soli`        = """ & Trim(lstrDocSol) & """, "
			lstrSql = lstrSql & "            `situacao`       = """ & lstrSituacao & """, "
			lstrSql = lstrSql & "            `nomeant`        = """ & lstrNomeAnt & """, "
			lstrSql = lstrSql & "            `medant`         = """ & lstrMedAnt & """, "
			lstrSql = lstrSql & "            `nomepos`        = """ & lstrNomePos & """, "
			lstrSql = lstrSql & "            `medpos`         = """ & lstrMedPos & """, "
			lstrSql = lstrSql & "            `padrao`         = """ & Trim(lstrPadrao) & """, "
			lstrSql = lstrSql & "            `tp_ligacao`     = """ & lstrTpLigacao & """, "
			lstrSql = lstrSql & "            `instal`         = """ & lstrTransf & """, "
			lstrSql = lstrSql & "            `idmedidor`      = """ & llngMedidor & """, "
			lstrSql = lstrSql & "            `seq`            = """ & llngSeq & """ "
			objExecAtualizaBancoDados.QUERY_NAME = lstrSql
			repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)

			lstrSql = ""
			lstrSql = lstrSql & "   SELECT B.COD_EQUIPAMENTO, B.EQUIPAMENTO, B.CARGA, A.QTD "
			lstrSql = lstrSql & "   FROM CARGAUNID A INNER JOIN CARGAEQUIP B ON(A.COD_EQUIPAMENTO = B.COD_EQUIPAMENTO) "
			lstrSql = lstrSql & "   WHERE A.UNID_ID = '" & ilngUnidId & "' AND left(A.GRUPO,1) = '" & UCase(istrGrupo) & "'"
			lstrSql = lstrSql & "   ORDER BY B.`COD_EQUIPAMENTO` ASC"
			objAtualizaBancoDados.QUERY_NAME = lstrSql
			dt5 = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)

			If dt5.Rows.Count > 0 Then
				For Each row As DataRow In dt5.Rows

					lstrEquipamento = Trim(IIf(IsDBNull(row.Item("EQUIPAMENTO")), "", row.Item("EQUIPAMENTO")))
					lstrCodEquipamento = Trim(IIf(IsDBNull(row.Item("COD_EQUIPAMENTO")), "", row.Item("COD_EQUIPAMENTO")))
					lstrCarga = Trim(IIf(IsDBNull(row.Item("CARGA")), "", row.Item("CARGA")))
					lstrqtd = Trim(IIf(IsDBNull(row.Item("QTD")), "", row.Item("QTD")))


					lstrSql = "INSERT INTO `AUX_REL_OS_CARGA` SET "
					lstrSql = lstrSql & "            `CODEQUIPAMENTO`     = """ & lstrCodEquipamento & """, "
					lstrSql = lstrSql & "            `EQUIPAMENTO`        = """ & lstrEquipamento & """, "
					lstrSql = lstrSql & "            `CARGA`              = """ & lstrCarga & """, "
					lstrSql = lstrSql & "            `QTD`                = """ & lstrqtd & """, "
					lstrSql = lstrSql & "            `GRUPO`              = """ & UCase(istrGrupo) & """, "
					lstrSql = lstrSql & "            `UNID_ID`            = """ & ilngUnidId & """ "
					objExecAtualizaBancoDados.QUERY_NAME = lstrSql
					repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)

				Next
			End If

		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: sCarregaTabelaAuxiliar" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try

	End Sub

	Private Sub lPrint(ByVal vNomeRPT As String)

		Dim dt As DataTable
		Dim dt2 As DataTable

		Dim dt_1 As DataTable
		Dim dt_2 As DataTable
		Dim dt_3 As DataTable
		Dim dt_4 As DataTable
		Dim dt_5 As DataTable
		Dim dt_6 As DataTable
		Dim dt_7 As DataTable

		Dim dc As DataColumn
		Dim ds As DataSet
		Dim ds2 As DataSet
		Dim bReg As Boolean

		Dim lstrsql As String


		Try
			Dim rpt As New ReportDocument()

			'RELATÓRIO PRINCIPAL E CARGA
			If vNomeRPT = "rptOS_EFLUL" Or vNomeRPT = "rptOS_EFLULCarga" Then

				dt_2 = New DataTable()
				dt_2.Columns.Add("NM_USUARIO", GetType(String))
				dt_2.Columns.Add("PROTOCOLO", GetType(String))
				dt_2.Columns.Add("ZONA", GetType(String))
				dt_2.Columns.Add("LIVRO", GetType(String))
				dt_2.Columns.Add("CONTA", GetType(String))
				dt_2.Columns.Add("ROTA", GetType(String))
				dt_2.Columns.Add("UNID_ID", GetType(String))
				dt_2.Columns.Add("NOME", GetType(String))
				dt_2.Columns.Add("ENDERECO", GetType(String))
				dt_2.Columns.Add("BAIRRO", GetType(String))
				dt_2.Columns.Add("CIDADE", GetType(String))
				dt_2.Columns.Add("IE", GetType(String))
				dt_2.Columns.Add("PONTO_REFER", GetType(String))
				dt_2.Columns.Add("MEDIDOR", GetType(String))
				dt_2.Columns.Add("CLASSE", GetType(String))
				dt_2.Columns.Add("TA", GetType(String))
				dt_2.Columns.Add("FASE", GetType(String))
				dt_2.Columns.Add("FASELIG", GetType(String))
				dt_2.Columns.Add("ATIVIDADE", GetType(String))
				dt_2.Columns.Add("SERVSOL", GetType(String))
				dt_2.Columns.Add("DESCR_SERV", GetType(String))
				dt_2.Columns.Add("PRIORIDADE", GetType(String))
				dt_2.Columns.Add("ZONA_SERV", GetType(String))
				dt_2.Columns.Add("ATENDENTE", GetType(String))
				dt_2.Columns.Add("DATA_SOLI", GetType(String))
				dt_2.Columns.Add("HORA_SOLI", GetType(String))
				dt_2.Columns.Add("NOME_SOLI", GetType(String))
				dt_2.Columns.Add("RG_SOLI", GetType(String))
				dt_2.Columns.Add("SITUACAO", GetType(String))
				dt_2.Columns.Add("NOMEANT", GetType(String))
				dt_2.Columns.Add("MEDANT", GetType(String))
				dt_2.Columns.Add("NOMEPOS", GetType(String))
				dt_2.Columns.Add("MEDPOS", GetType(String))
				dt_2.Columns.Add("PADRAO", GetType(String))
				dt_2.Columns.Add("TP_LIGACAO", GetType(String))
				dt_2.Columns.Add("TELEFONE_DDD", GetType(String))
				dt_2.Columns.Add("CELULAR", GetType(String))
				dt_2.Columns.Add("CELULAR_DDD", GetType(String))
				dt_2.Columns.Add("SEQ", GetType(String))
				dt_2.Columns.Add("TIPO_MEDIDOR", GetType(String))
				dt_2.Columns.Add("INSTAL", GetType(String))
				dt_2.Columns.Add("IDMEDIDOR", GetType(String))
				dt_2.Columns.Add("IMAGEM", GetType(Byte()))

				ds = New DataSet

				lstrsql = ""
				lstrsql = "SELECT * FROM AUX_REL_OS_ARREC WHERE NM_USUARIO = '" & My.Computer.Name & "'"
				objAtualizaBancoDados.QUERY_NAME = lstrsql
				dt = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)

				If dt.Rows.Count > 0 Then
					For Each dr_1 As DataRow In dt.Rows

						dt_2.Rows.Add(dr_1("NM_USUARIO"),
										  dr_1("PROTOCOLO"),
										  dr_1("ZONA"),
										  dr_1("LIVRO"),
										  dr_1("CONTA"),
										  dr_1("ROTA"),
										  dr_1("UNID_ID"),
										  dr_1("NOME"),
										  dr_1("ENDERECO"),
										  dr_1("BAIRRO"),
										  dr_1("CIDADE"),
										  dr_1("IE"),
										  dr_1("PONTO_REFER"),
										  dr_1("MEDIDOR"),
										  dr_1("CLASSE"),
										  dr_1("TA"),
										  dr_1("FASE"),
										  dr_1("FASELIG"),
										  dr_1("ATIVIDADE"),
										  dr_1("SERVSOL"),
										  dr_1("DESCR_SERV"),
										  dr_1("PRIORIDADE"),
										  dr_1("ZONA_SERV"),
										  dr_1("ATENDENTE"),
										  dr_1("DATA_SOLI"),
										  dr_1("HORA_SOLI"),
										  dr_1("NOME_SOLI"),
										  dr_1("RG_SOLI"),
										  dr_1("SITUACAO"),
										  dr_1("NOMEANT"),
										  dr_1("MEDANT"),
										  dr_1("TP_LIGACAO"),
										  dr_1("MEDPOS"),
										  dr_1("PADRAO"),
										  dr_1("TELEFONE_DDD"),
										  dr_1("CELULAR"),
										  dr_1("CELULAR_DDD"),
										  dr_1("SEQ"),
										  dr_1("TIPO_MEDIDOR"),
										  dr_1("INSTAL"),
										  dr_1("IDMEDIDOR"),
										  Limagem)
					Next dr_1
				End If

				ds.Tables.Add(dt)
				ds.Tables(0).TableName = "REL_OS_ARREC"

				' Impressão do relatório de cargas instaladas
				If vNomeRPT = "rptOS_EFLULCarga" Then

					dt_3 = New DataTable()
					dt_3.Columns.Add("CODEQUIPAMENTO", GetType(String))
					dt_3.Columns.Add("EQUIPAMENTO", GetType(String))
					dt_3.Columns.Add("CARGA", GetType(String))
					dt_3.Columns.Add("UNID_ID", GetType(String))
					dt_3.Columns.Add("GRUPO", GetType(String))
					dt_3.Columns.Add("QTD", GetType(String))

					lstrsql = ""
					lstrsql = "SELECT * FROM AUX_REL_OS_CARGA WHERE UNID_ID = '" & ilngUnidId & "' AND GRUPO = '" & UCase(istrGrupo) & "'"
					objAtualizaBancoDados.QUERY_NAME = lstrsql
					dt2 = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)

					If dt2.Rows.Count > 0 Then
						For Each dr_1 As DataRow In dt2.Rows

							dt_3.Rows.Add(dr_1("CODEQUIPAMENTO"),
										  dr_1("EQUIPAMENTO"),
										  dr_1("CARGA"),
										  dr_1("UNID_ID"),
										  dr_1("GRUPO"),
										  dr_1("QTD"))
						Next
					End If

					ds.Tables.Add(dt2)
					ds.Tables(1).TableName = "REL_OS_CARGA"

				End If

				If ds.Tables(0).Rows.Count = 0 Then
					bReg = True
				End If

				' CROQUI  
			ElseIf vNomeRPT = "rptcroquiOS" Then


				'TIPO_FASES
				dt_4 = New DataTable()
				dt_4.Columns.Add("ID", GetType(String))
				dt_4.Columns.Add("DESCRICAO", GetType(String))

				'TIPO_MEDIDOR
				dt_5 = New DataTable()
				dt_5.Columns.Add("ID", GetType(String))
				dt_5.Columns.Add("DESCRICAO", GetType(String))

				'TIPO_GRANDEZA_MEDIDA
				dt_6 = New DataTable()
				dt_6.Columns.Add("ID", GetType(String))
				dt_6.Columns.Add("DESCRICAO", GetType(String))

				'SOL. SERV
				dt_7 = New DataTable
				dt_7.Columns.Add("COD", GetType(String))
				dt_7.Columns.Add("PROTOCOLO", GetType(String))
				dt_7.Columns.Add("DATA_SOLI", GetType(String))
				dt_7.Columns.Add("HORA_SOLI", GetType(String))
				dt_7.Columns.Add("ZLC", GetType(String))
				dt_7.Columns.Add("NOMESOL", GetType(String))
				dt_7.Columns.Add("DOCSOL", GetType(String))
				dt_7.Columns.Add("DDDTELSOL", GetType(String))
				dt_7.Columns.Add("TELSOL", GetType(String))
				dt_7.Columns.Add("DDDCELSOL", GetType(String))
				dt_7.Columns.Add("CELSOL", GetType(String))
				dt_7.Columns.Add("ITENSSERV", GetType(String))
				dt_7.Columns.Add("DATASOLU", GetType(String))
				dt_7.Columns.Add("HORASOLU", GetType(String))
				dt_7.Columns.Add("PARCELAS", GetType(String))
				dt_7.Columns.Add("PONTO_REFER", GetType(String))
				dt_7.Columns.Add("ATENDENTE", GetType(String))
				dt_7.Columns.Add("EXECUTADO", GetType(String))
				dt_7.Columns.Add("DESCR_SERV", GetType(String))
				dt_7.Columns.Add("PRIORIDADE", GetType(String))
				dt_7.Columns.Add("SOLICIT_MEIO", GetType(String))
				dt_7.Columns.Add("ZONA_SOLIC", GetType(String))
				dt_7.Columns.Add("UNID_ID", GetType(String))
				dt_7.Columns.Add("UNID", GetType(String))
				dt_7.Columns.Add("SIT", GetType(String))
				dt_7.Columns.Add("CPF", GetType(String))
				dt_7.Columns.Add("COD_EXECUTOR", GetType(String))
				dt_7.Columns.Add("PADRAO", GetType(String))

				ds = New DataSet

				lstrsql = ""
				lstrsql = "SELECT * FROM TIPO_FASES"
				objAtualizaBancoDados.QUERY_NAME = lstrsql
				dt = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)

				If dt.Rows.Count > 0 Then
					For Each dr_1 As DataRow In dt.Rows
						dt_4.Rows.Add(dr_1("ID"),
									  dr_1("DESCRICAO"))

					Next
				End If

				lstrsql = ""
				lstrsql = "SELECT * FROM TIPO_MEDIDOR"
				objAtualizaBancoDados.QUERY_NAME = lstrsql
				dt2 = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)

				If dt2.Rows.Count > 0 Then
					For Each dr_1 As DataRow In dt2.Rows
						dt_5.Rows.Add(dr_1("ID"),
									  dr_1("DESCRICAO"))

					Next
				End If

				lstrsql = ""
				lstrsql = "SELECT * FROM TIPO_GRANDEZA_MEDIDA"
				objAtualizaBancoDados.QUERY_NAME = lstrsql
				dt3 = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)

				If dt3.Rows.Count > 0 Then
					For Each dr_1 As DataRow In dt3.Rows
						dt_6.Rows.Add(dr_1("ID"),
									  dr_1("DESCRICAO"))

					Next
				End If


				lstrsql = ""
				lstrsql = "SELECT * FROM solserv WHERE PROTOCOLO = '" & lstrProto & "'"
				objAtualizaBancoDados.QUERY_NAME = lstrsql
				dt4 = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)

				If dt4.Rows.Count > 0 Then
					For Each dr_1 As DataRow In dt4.Rows
						dt_7.Rows.Add(dr_1("COD"),
									   dr_1("PROTOCOLO"),
										  dr_1("DATA_SOLI"),
										  dr_1("HORA_SOLI"),
										  dr_1("ZLC"),
										  dr_1("NOMESOL"),
										  dr_1("DOCSOL"),
										  dr_1("DDDTELSOL"),
										  dr_1("TELSOL"),
										  dr_1("DDDCELSOL"),
										  dr_1("CELSOL"),
										  dr_1("ITENSSERV"),
										  dr_1("DATASOLU"),
										  dr_1("HORASOLU"),
										  dr_1("PARCELAS"),
										  dr_1("PONTO_REFER"),
										  dr_1("ATENDENTE"),
										  dr_1("EXECUTADO"),
										  dr_1("DESCR_SERV"),
										  dr_1("PRIORIDADE"),
										  dr_1("SOLICIT_MEIO"),
										  dr_1("ZONA_SOLIC"),
										  dr_1("UNID_ID"),
										  dr_1("UNID"),
										  dr_1("SIT"),
										  dr_1("CPF"),
										  dr_1("COD_EXECUTOR"),
										  dr_1("PADRAO"))
					Next
				End If


				ds.Tables.Add(dt)
				ds.Tables(0).TableName = "REL_TIPO_FASES"

				ds.Tables.Add(dt2)
				ds.Tables(1).TableName = "REL_TIPO_MEDIDOR"

				ds.Tables.Add(dt3)
				ds.Tables(2).TableName = "REL_TIPO_GRANDEZA_MEDIDA"

				ds.Tables.Add(dt4)
				ds.Tables(3).TableName = "REL_SOLSERV"


				If ds.Tables(3).Rows.Count = 0 Then
					bReg = True
				End If

			End If


			If bReg Then
				MessageBox.Show("Não há registros para o relatório escolhido! ", "Informação", MessageBoxButtons.OK, MessageBoxIcon.Information)
				Exit Sub
			Else

				If vNomeRPT = "rptOS_EFLUL" Then
					rpt = New rptOS_EFLUL
				ElseIf vNomeRPT = "rptOS_EFLULCarga" Then
					rpt = New rptOS_EFLULCarga
				ElseIf vNomeRPT = "rptcroquiOS" Then
					rpt = New rptcroquiOS
				End If


				rpt.SetDataSource(ds)

				If vNomeRPT <> "rptcroquiOS" Then
					rpt.SetParameterValue("nomeempresa", sNomeEmpresa)
					rpt.SetParameterValue("enderecoempresa", sEnderecoEmpresa)
					rpt.SetParameterValue("cepempresa", sCepEmpresa)
					rpt.SetParameterValue("ufempresa", sUFempresa)
					rpt.SetParameterValue("cidadeempresa", sCidadeEmpresa)
					rpt.SetParameterValue("bairroempresa", sBairroEmpresa)
					rpt.SetParameterValue("foneempresa", sFoneEmpresa)
					rpt.SetParameterValue("websiteempresa", sWebEmpresa)
				End If

				frmViewRelatorios.rpt = rpt

				frmViewRelatorios.CRViewer.Zoom((100))
				frmViewRelatorios.Text = "Relatório Solicitação de Serviço"
				frmViewRelatorios.ShowDialog()

			End If

		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: Lprint" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try

	End Sub

End Class