Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Friend Class frmRelAnexoIII
	Inherits System.Windows.Forms.Form
	Private ifrmRelAnexoII As FrmRelatorio
	Private istrTamCol As String
	Private iintMesIniPerSeco As Short
	Private iintMesFimPerSeco As Short
	Private idteIni As Date
	Private idteFim As Date
	
	Private Sub cmdArquivo_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdArquivo.Click
		Me.dialArqOpen.DefaultExt = "CSV"
		'UPGRADE_WARNING: Filter has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
		Me.dialArqOpen.Filter = "*." & Me.dialArqOpen.DefaultExt
		Me.dialArqOpen.FileName = My.Application.Info.DirectoryPath & "\AnexoIII_" & VB6.Format(BuscaDataBD, "YYYYMMDDHHNNSS") & "." & Me.dialArqOpen.DefaultExt
		Me.dialArqOpen.Title = "Arquivo de exportação do Anexo III"
		Me.dialArqOpen.ShowDialog()
		Me.txtArquivo.Text = Me.dialArqOpen.FileName
	End Sub
	
	Private Sub cmdExporta_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdExporta.Click
		'Controle Arquivo
		Dim lstrLin As String
		Dim lintARQ As Short
		Dim llngRow As Integer
		Dim llngCol As Integer
		'Controle de Query
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		If Trim(Me.txtArquivo.Text) = "" Then
			Call MsgBox("Você deve selecionar um local e o nome do arquivo que deseja gravar!" & vbCrLf & "Ex: C:\ANEXOIII_" & VB6.Format(BuscaDataBD, "YYYYMMDDHHNNSS") & ".CSV", MsgBoxStyle.Critical, gstrTituloMensagem)
		Else
			Call LigDesBotoes(False)
			'Export para CSV
			If Trim(Me.txtArquivo.Text) <> "" Then
				lintARQ = FreeFile
				FileOpen(lintARQ, Me.txtArquivo.Text, OpenMode.Output)
				If Me.opbAuditoria.Checked Then
					With Me.mfgSolServ
						If .Rows > 1 Then
							Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, .Rows - 1, " Gerando Arquivo ")
							For llngRow = 0 To .Rows - 1
								lstrLin = ""
								For llngCol = 0 To .Cols - 1
									lstrLin = lstrLin & .get_TextMatrix(llngRow, llngCol) & ";"
								Next llngCol
								PrintLine(lintARQ, lstrLin)
								Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1,  , " Gerando Arquivo ")
							Next llngRow
						End If
					End With
					PrintLine(lintARQ, ";")
					With Me.mfgReclamacao
						If .Rows > 1 Then
							Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, .Rows - 1, " Gerando Arquivo ")
							For llngRow = 0 To .Rows - 1
								lstrLin = ""
								For llngCol = 0 To .Cols - 1
									lstrLin = lstrLin & .get_TextMatrix(llngRow, llngCol) & ";"
								Next llngCol
								PrintLine(lintARQ, lstrLin)
								Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1,  , " Gerando Arquivo ")
							Next llngRow
						End If
					End With
				ElseIf Me.opbEspelho.Checked Then 
					With Me.mfgAnexoIII
						If .Rows > 1 Then
							Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, .Rows - 1, " Gerando Arquivo ")
							For llngRow = 0 To .Rows - 1
								lstrLin = ""
								For llngCol = 0 To .Cols - 1
									lstrLin = lstrLin & .get_TextMatrix(llngRow, llngCol) & ";"
								Next llngCol
								PrintLine(lintARQ, lstrLin)
								Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1,  , " Gerando Arquivo ")
							Next llngRow
						End If
					End With
					PrintLine(lintARQ, ";")
				End If
				FileClose(lintARQ)
				Call MsgBox("Arquivo gerado com sucesso!", MsgBoxStyle.Information, gstrTituloMensagem)
			Else
				Call MsgBox("Você precisa selecionar o caminho e o arquivo para exportação!", MsgBoxStyle.Information, gstrTituloMensagem)
			End If
			Call LigDesBotoes(True)
		End If
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
	End Sub
	
	Private Sub cmdFechar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdFechar.Click
		Call Me.Close()
	End Sub
	
	Private Sub cmdFecharExplode_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdFecharExplode.Click
		Me.fmeExplode.Visible = False
		Call LigDesBotoes(True)
	End Sub
	
	Private Sub cmdGerarRessarcimento_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdGerarRessarcimento.Click
		Dim lstrSql As String
		Dim llngRow As Integer
		Dim lstrZon As String
		Dim lstrLiv As String
		Dim lstrCon As String
		Dim lstrGru As String
		Dim llngIdC As Integer
		Dim llngIdU As Integer
		Dim ldteIni As Date
		Dim ldteFim As Date
		Dim ldteAux As Date
		Dim ldteBas As Date
		Dim ldblRes As Double
		Dim lblnGra As Boolean
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lblnGra = False
		ldteBas = BuscaDataBD
		ldteAux = CDate("01/" & LeConfig("MESANOFATURAMENTO"))
		ldteIni = CDate("01/" & VB6.Format(Me.dtpCredMesAno.value, "MM/YYYY"))
		ldteFim = CDate(UltimoDiaMes(Month(ldteIni), Year(ldteIni)) & "/" & VB6.Format(ldteIni, "MM/YYYY"))
		If ldteAux >= System.Date.FromOADate(ldteIni.ToOADate + 360) Then
			Call MsgBox("Você não pode lançar um ressarcimento por violação de prazo de atendimento no período igual ou inferior ao do faturamento!", MsgBoxStyle.Critical, gstrTituloMensagem)
		Else
			With Me.mfgSolServ
				If .Rows > 1 Then
					For llngRow = 1 To .Rows - 1
						lstrZon = .get_TextMatrix(llngRow, 7)
						lstrLiv = .get_TextMatrix(llngRow, 8)
						lstrCon = .get_TextMatrix(llngRow, 9)
						lstrGru = .get_TextMatrix(llngRow, 10)
						ldblRes = CDbl(IIf(IsNumeric(.get_TextMatrix(llngRow, 19)), .get_TextMatrix(llngRow, 19), 0))
						If ldblRes <> 0 Then
							lstrSql = ""
							lstrSql = lstrSql & "SELECT * "
							lstrSql = lstrSql & "  FROM `unid" & LCase(lstrGru) & "` "
							lstrSql = lstrSql & " WHERE `zona` = '" & lstrZon & "' "
							lstrSql = lstrSql & "   AND `livro` = '" & lstrLiv & "' "
							lstrSql = lstrSql & "   AND `conta` = '" & lstrCon & "' "
							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"'
										llngIdC = 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"'
										llngIdU = CInt(IIf(IsDbNull(.Fields("unid_id").value), 0, .Fields("unid_id").value))
										lstrSql = ""
										lstrSql = lstrSql & "INSERT INTO `convenios` SET "
										lstrSql = lstrSql & "            `zona`     = '" & lstrZon & "', "
										lstrSql = lstrSql & "            `livro`    = '" & lstrLiv & "', "
										lstrSql = lstrSql & "            `conta`    = '" & lstrCon & "', "
										lstrSql = lstrSql & "            `cons_id`  =  " & llngIdC & ", "
										lstrSql = lstrSql & "            `unid_id`  =  " & llngIdU & ", "
										lstrSql = lstrSql & "            `convenio` = '9070000041', "
										lstrSql = lstrSql & "            `sit` = 'Novo', "
										lstrSql = lstrSql & "            `dt_cadastro` = '" & VB6.Format(ldteBas, "yyyy-MM-dd") & "', "
										lstrSql = lstrSql & "            `valor`    =  " & Replace(CStr(ldblRes), ",", ".") & ", "
										lstrSql = lstrSql & "            `dt_ini`   = '" & VB6.Format(ldteIni, "yyyy-MM-dd") & "', "
										lstrSql = lstrSql & "            `dt_fim`   = '" & VB6.Format(ldteFim, "yyyy-MM-dd") & "', "
										lstrSql = lstrSql & "            `ref`      = '" & VB6.Format(Me.dtpMesAno.value, "MM/YYYY") & "' "
										lblnGra = Executar(lstrSql)
									End If
									Call .Close()
								End If
							End With
						End If
					Next llngRow
				End If
			End With
			With Me.mfgReclamacao
				If .Rows > 1 Then
					For llngRow = 1 To .Rows - 1
						lstrZon = .get_TextMatrix(llngRow, 7)
						lstrLiv = .get_TextMatrix(llngRow, 8)
						lstrCon = .get_TextMatrix(llngRow, 9)
						lstrGru = .get_TextMatrix(llngRow, 10)
						ldblRes = CDbl(IIf(IsNumeric(.get_TextMatrix(llngRow, 20)), .get_TextMatrix(llngRow, 20), 0))
						If ldblRes <> 0 Then
							lstrSql = ""
							lstrSql = lstrSql & "SELECT * "
							lstrSql = lstrSql & "  FROM `unid" & LCase(lstrGru) & "` "
							lstrSql = lstrSql & " WHERE `zona` = '" & lstrZon & "' "
							lstrSql = lstrSql & "   AND `livro` = '" & lstrLiv & "' "
							lstrSql = lstrSql & "   AND `conta` = '" & lstrCon & "' "
							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"'
										llngIdC = 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"'
										llngIdU = CInt(IIf(IsDbNull(.Fields("unid_id").value), 0, .Fields("unid_id").value))
										lstrSql = ""
										lstrSql = lstrSql & "INSERT INTO `convenios` SET "
										lstrSql = lstrSql & "            `zona`     = '" & lstrZon & "', "
										lstrSql = lstrSql & "            `livro`    = '" & lstrLiv & "', "
										lstrSql = lstrSql & "            `conta`    = '" & lstrCon & "', "
										lstrSql = lstrSql & "            `cons_id`  =  " & llngIdC & ", "
										lstrSql = lstrSql & "            `unid_id`  =  " & llngIdU & ", "
										lstrSql = lstrSql & "            `convenio` = '9070000041', "
										lstrSql = lstrSql & "            `sit` = 'Novo', "
										lstrSql = lstrSql & "            `dt_cadastro` = '" & VB6.Format(ldteBas, "yyyy-MM-dd") & "', "
										lstrSql = lstrSql & "            `valor`    =  " & Replace(CStr(ldblRes), ",", ".") & ", "
										lstrSql = lstrSql & "            `dt_ini`   = '" & VB6.Format(ldteIni, "yyyy-MM-dd") & "', "
										lstrSql = lstrSql & "            `dt_fim`   = '" & VB6.Format(ldteFim, "yyyy-MM-dd") & "', "
										lstrSql = lstrSql & "            `ref`      = '" & VB6.Format(Me.dtpMesAno.value) & "' "
										lblnGra = Executar(lstrSql)
									End If
									Call .Close()
								End If
							End With
						End If
					Next llngRow
				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
		If lblnGra Then
			Call MsgBox("Geração de crédito concluída com sucesso!", MsgBoxStyle.Information, gstrTituloMensagem)
		End If
	End Sub
	
	Private Sub cmdImprimir_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdImprimir.Click
		Call Imprime()
	End Sub
	
	Private Sub cmdProcessar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdProcessar.Click
		Call LigDesBotoes(False)
		idteIni = CDate("01/" & VB6.Format(Me.dtpMesAno.value, "MM/YYYY"))
		idteFim = CDate(UltimoDiaMes(Month(idteIni), Year(idteIni)) & "/" & VB6.Format(idteIni, "MM/YYYY"))
		Call MontaGrade()
		Call ProcessaOs()
		Call ProcessaRe()
		Call LigDesBotoes(True)
	End Sub
	
	Private Sub LigDesBotoes(ByVal ablnModo As Boolean)
		Me.cmdProcessar.Enabled = ablnModo
		Me.cmdExporta.Enabled = ablnModo
		Me.cmdArquivo.Enabled = ablnModo
		Me.dtpMesAno.Enabled = ablnModo
		Me.cmdFechar.Enabled = ablnModo
		Me.cmdGerarRessarcimento.Enabled = ablnModo
		Me.dtpCredMesAno.Enabled = ablnModo
	End Sub
	
	Private Sub ProcessaOs()
		Dim lstrTip As String
		Dim lstrSer As String
		Dim ldblPra As Double
		Dim lstrReg As String
		Dim lstrNom As String
		Dim llngSeq As Integer
		Dim lstrPro As String
		Dim lstrZon As String
		Dim lstrLiv As String
		Dim lstrCon As String
		Dim lstrGru As String
		Dim ldteSol As Date
		Dim ldteCon As Date
		Dim ldteLoo As Date
		Dim ldteAux As Date
		Dim ldblPrazoPriVist As Double
		Dim ldblPrazoLigacao As Double
		Dim ldblPrazoSegVist As Double
		Dim llngRowPrazo As Integer
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		Me.mfgSolServ.Redraw = False
		lstrSql = ""
		lstrSql = lstrSql & "    SELECT `codigos`.`num` `codigo_servico`, "
		lstrSql = lstrSql & "           `codigos`.`descri` `tipo_atendimento`, "
		lstrSql = lstrSql & "           IFNULL(`unidb`.`regiao`, `unida`.`regiao`) `regiao`,"
		lstrSql = lstrSql & "           `solserv`.`data_soli`, "
		lstrSql = lstrSql & "           `solserv`.`hora_soli`, "
		lstrSql = lstrSql & "           `solserv`.`datasolu`, "
		lstrSql = lstrSql & "           `solserv`.`horasolu`, "
		lstrSql = lstrSql & "           IFNULL(`unidb`.`nome`, `unida`.`nome`) `nome`, "
		lstrSql = lstrSql & "           `solserv`.`cod` `seq`, "
		lstrSql = lstrSql & "           `solserv`.`protocolo` `protocolo`, "
		lstrSql = lstrSql & "           IFNULL(`unidb`.`zona`, `unida`.`zona`) `zona`, "
		lstrSql = lstrSql & "           IFNULL(`unidb`.`livro`, `unida`.`livro`) `livro`, "
		lstrSql = lstrSql & "           IFNULL(`unidb`.`conta`, `unida`.`conta`) `conta`, "
		lstrSql = lstrSql & "           `solserv`.`unid` `grupo` "
		lstrSql = lstrSql & "      FROM `solserv` "
		lstrSql = lstrSql & " LEFT JOIN `unidb` ON(`unidb`.`unid_id` = `solserv`.`unid_id` AND `solserv`.`unid` = 'B') "
		lstrSql = lstrSql & " LEFT JOIN `unida` ON(`unida`.`unid_id` = `solserv`.`unid_id` AND `solserv`.`unid` = 'A') "
		lstrSql = lstrSql & " LEFT JOIN `codigos` ON(`codigos`.`num` = LEFT(`solserv`.`itensserv`, 10)) "
		lstrSql = lstrSql & "     WHERE (`solserv`.`datasolu` BETWEEN '" & VB6.Format(idteIni, "yyyy-MM-dd") & "' AND '" & VB6.Format(idteFim, "yyyy-MM-dd") & "') "
		lstrSql = lstrSql & "       AND (LEFT(`solserv`.`itensserv`, 10) = '9050000002' OR LEFT(`solserv`.`itensserv`, 9) IN('904000002','904000004','904000005')) " ''904000001' vistoria 2 afericao 4 relig normal 5 relig urgencia
		lstrSql = lstrSql & "       AND `solserv`.`sit` <> 'C' "
		lstrSql = lstrSql & "  ORDER BY 1 ASC, 3 ASC, 6 ASC, 7 ASC, 4 ASC, 5 ASC, 9 ASC, 10 ASC"
		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, " Ordem de Serviços ")
					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"'
						lstrTip = IIf(IsDbNull(.Fields("tipo_atendimento").value), "", .Fields("tipo_atendimento").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"'
						lstrSer = IIf(IsDbNull(.Fields("codigo_servico").value), "", .Fields("codigo_servico").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"'
						lstrReg = IIf(IsDbNull(.Fields("regiao").value), "U", .Fields("regiao").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"'
						lstrNom = IIf(IsDbNull(.Fields("nome").value), "", .Fields("nome").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"'
						llngSeq = IIf(IsDbNull(.Fields("seq").value), "0", .Fields("seq").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"'
						lstrPro = IIf(IsDbNull(.Fields("protocolo").value), "", .Fields("protocolo").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"'
						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)
						'UPGRADE_WARNING: 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("grupo").value), "B", .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"'
						ldteSol = CDate(IIf(IsDbNull(.Fields("data_soli").value), "1900-01-01", .Fields("data_soli").value) & " " & VB6.Format(IIf(IsDbNull(.Fields("hora_soli").value), "00:00:00", .Fields("hora_soli").value), "HH:NN:SS"))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldteCon = CDate(IIf(IsDbNull(.Fields("datasolu").value), "1900-01-01", .Fields("datasolu").value) & " " & VB6.Format(IIf(IsDbNull(.Fields("horasolu").value), "00:00:00", .Fields("horasolu").value), "HH:NN:SS"))
						'Calcula Dias
						ldteLoo = CDate(VB6.Format(ldteSol, "DD/MM/YYYY"))
						ldteAux = CDate(VB6.Format(ldteCon, "DD/MM/YYYY"))
						ldblPra = 0
						While ldteLoo <= ldteAux
							If VerificaDiaUtil(ldteLoo) Then
								ldblPra = ldblPra + 1
							End If
							ldteLoo = System.Date.FromOADate(DateSerial(Year(ldteLoo), Month(ldteLoo), VB.Day(ldteLoo)).ToOADate + 1)
						End While
						ldblPrazoPriVist = 0
						ldblPrazoLigacao = 0
						ldblPrazoSegVist = 0
						If VB.Left(lstrSer, 9) = "904000001" Then 'Vistoria
							' Por enquanto não irá fazer
						ElseIf VB.Left(lstrSer, 9) = "904000002" Then  'Aferição 30 dias corridos
							'UPGRADE_WARNING: DateDiff behavior may be different. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6B38EC3F-686D-4B2E-B5A5-9E8E7A762E32"'
							ldblPra = Arredondar(DateDiff(Microsoft.VisualBasic.DateInterval.Day, ldteSol, ldteCon, FirstDayOfWeek.Saturday, FirstWeekOfYear.Jan1), 0) 'Dia Corrido
							llngRowPrazo = 12
						ElseIf VB.Left(lstrSer, 9) = "904000004" Then  'Religação Normal 24/48
							'UPGRADE_WARNING: DateDiff behavior may be different. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6B38EC3F-686D-4B2E-B5A5-9E8E7A762E32"'
							ldblPra = Arredondar(DateDiff(Microsoft.VisualBasic.DateInterval.Second, ldteSol, ldteCon, FirstDayOfWeek.Saturday, FirstWeekOfYear.Jan1) / 3600, 2)
							If lstrReg = "U" Then llngRowPrazo = 14
							If lstrReg = "R" Then llngRowPrazo = 15
						ElseIf VB.Left(lstrSer, 9) = "904000005" Then  'Religação Urgencia 4/8
							'UPGRADE_WARNING: DateDiff behavior may be different. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6B38EC3F-686D-4B2E-B5A5-9E8E7A762E32"'
							ldblPra = Arredondar(DateDiff(Microsoft.VisualBasic.DateInterval.Second, ldteSol, ldteCon, FirstDayOfWeek.Saturday, FirstWeekOfYear.Jan1) / 3600, 2)
							If lstrReg = "U" Then llngRowPrazo = 16
							If lstrReg = "R" Then llngRowPrazo = 17
						ElseIf VB.Left(lstrSer, 10) = "9050000002" Then  'Ligação Nova Marretada para nunca ultrapassar
							If lstrReg = "U" Then '2 L / 3 V
								llngRowPrazo = 3
								If ldblPra > 2 Then
									If ldblPra > 5 Then
										ldblPrazoPriVist = 3
										ldblPrazoLigacao = 2
										ldblPrazoSegVist = 1
									Else
										If ldblPra > 3 Then
											ldblPrazoPriVist = 3
											ldblPrazoLigacao = (ldblPra - ldblPrazoPriVist)
										Else
											ldblPrazoPriVist = 2
											ldblPrazoLigacao = (ldblPra - ldblPrazoPriVist)
										End If
									End If
								Else
									ldblPrazoPriVist = 1
									ldblPrazoLigacao = 1
								End If
							ElseIf lstrReg = "R" Then  '5 L / 5 V
								llngRowPrazo = 4
								If ldblPra > 5 Then
									If ldblPra > 10 Then
										ldblPrazoPriVist = 5
										ldblPrazoLigacao = 5
										ldblPrazoSegVist = 1
									Else
										'6,7,8,9,10
										ldblPrazoPriVist = 5
										ldblPrazoLigacao = (ldblPra - ldblPrazoPriVist)
									End If
								Else
									'1,2,3,4,5
									If ldblPra > 4 Then
										ldblPrazoPriVist = 3
										ldblPrazoLigacao = (ldblPra - ldblPrazoPriVist)
									ElseIf ldblPra > 3 Then 
										ldblPrazoPriVist = 2
										ldblPrazoLigacao = (ldblPra - ldblPrazoPriVist)
									ElseIf ldblPra > 2 Then 
										ldblPrazoPriVist = 2
										ldblPrazoLigacao = (ldblPra - ldblPrazoPriVist)
									Else
										ldblPrazoPriVist = 1
										ldblPrazoLigacao = 1
									End If
								End If
							End If
						End If
						With Me.mfgSolServ
							.Rows = .Rows + 1
							.set_TextMatrix(.Rows - 1, 0, lstrSer)
							.set_TextMatrix(.Rows - 1, 1, lstrTip)
							.set_TextMatrix(.Rows - 1, 2, VB6.Format(ldblPra, "#,##0.00"))
							.set_TextMatrix(.Rows - 1, 3, lstrReg)
							.set_TextMatrix(.Rows - 1, 4, lstrNom)
							.set_TextMatrix(.Rows - 1, 5, llngSeq)
							.set_TextMatrix(.Rows - 1, 6, lstrPro)
							.set_TextMatrix(.Rows - 1, 7, lstrZon)
							.set_TextMatrix(.Rows - 1, 8, lstrLiv)
							.set_TextMatrix(.Rows - 1, 9, lstrCon)
							.set_TextMatrix(.Rows - 1, 10, lstrGru)
							.set_TextMatrix(.Rows - 1, 11, ldteSol)
							.set_TextMatrix(.Rows - 1, 12, ldteCon)
							.set_TextMatrix(.Rows - 1, 13, ldblPrazoLigacao)
							.set_TextMatrix(.Rows - 1, 14, ldblPrazoPriVist)
							.set_TextMatrix(.Rows - 1, 15, ldblPrazoSegVist)
							
							If llngRowPrazo <= 4 Then
								.set_TextMatrix(.Rows - 1, 17, VB6.Format(CInt(VB.Left(Me.mfgAnexoIII.get_TextMatrix(llngRowPrazo, 2), 2)) + CInt(VB.Left(Me.mfgAnexoIII.get_TextMatrix(llngRowPrazo - 2, 2), 2)), "#,##0.00"))
								.set_TextMatrix(.Rows - 1, 18, VB6.Format(IIf(ldblPra > 1, ldblPrazoLigacao + ldblPrazoPriVist, ldblPra), "#,##0.00"))
							Else
								.set_TextMatrix(.Rows - 1, 17, VB6.Format(CInt(VB.Left(Me.mfgAnexoIII.get_TextMatrix(llngRowPrazo, 2), 2)), "#,##0.00"))
								.set_TextMatrix(.Rows - 1, 18, VB6.Format(ldblPra, "#,##0.00"))
							End If
							If CDbl(IIf(IsNumeric(.get_TextMatrix(.Rows - 1, 18)), .get_TextMatrix(.Rows - 1, 18), 0)) > CDbl(IIf(IsNumeric(.get_TextMatrix(.Rows - 1, 17)), .get_TextMatrix(.Rows - 1, 17), 0)) Then
								.set_TextMatrix(.Rows - 1, 16, VB6.Format(CalcCM(VB6.Format(ldteCon, "MM/YYYY"), lstrZon, lstrLiv, lstrCon, lstrGru, 1, iintMesIniPerSeco, iintMesFimPerSeco, 1), "#,##0.00"))
								.set_TextMatrix(.Rows - 1, 19, VB6.Format(Arredondar(((CDbl(.get_TextMatrix(.Rows - 1, 16)) / 730) * (CDbl(.get_TextMatrix(.Rows - 1, 18)) / CDbl(.get_TextMatrix(.Rows - 1, 17)))) * 100, 2), "#,##0.00"))
								If CDbl(IIf(IsNumeric(.get_TextMatrix(.Rows - 1, 19)), .get_TextMatrix(.Rows - 1, 19), 0)) > 0 Then
									If (CDbl(IIf(IsNumeric(.get_TextMatrix(.Rows - 1, 16)), .get_TextMatrix(.Rows - 1, 16), 0)) * 10) < CDbl(IIf(IsNumeric(.get_TextMatrix(.Rows - 1, 19)), .get_TextMatrix(.Rows - 1, 19), 0)) Then
										.set_TextMatrix(.Rows - 1, 19, VB6.Format(CDbl(IIf(IsNumeric(.get_TextMatrix(.Rows - 1, 16)), .get_TextMatrix(.Rows - 1, 16), 0)) * 10, "#,##0.00"))
									End If
								End If
							Else
								.set_TextMatrix(.Rows - 1, 16, "")
								.set_TextMatrix(.Rows - 1, 19, "")
							End If
						End With
						Call .MoveNext()
						Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1,  , " Ordem de Serviços ")
					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
		Me.mfgSolServ.Redraw = True
		Call TotalizaOS()
	End Sub
	
	Private Sub ProcessaRe()
		Dim lstrTip As String
		Dim llngSer As Integer
		Dim ldblPra As Double
		Dim lstrPrc As String
		Dim lstrNom As String
		Dim llngSeq As Integer
		Dim lstrPro As String
		Dim lstrZon As String
		Dim lstrLiv As String
		Dim lstrCon As String
		Dim lstrGru As String
		Dim ldteSol As Date
		Dim ldteCon As Date
		Dim lstrVis As String
		Dim ldteLoo As Date
		Dim ldteAux As Date
		Dim ldblVer As Double
		Dim ldblLau As Double
		Dim ldblRes As Double
		Dim llngRowPrazo As Integer
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		Me.mfgReclamacao.Redraw = False
		lstrSql = ""
		lstrSql = lstrSql & "     SELECT `tipo_reclamacao`.`id` `codigo_servico`, "
		lstrSql = lstrSql & "           tipo_reclamacao.nome `tipo_atendimento`, "
		lstrSql = lstrSql & "           `reclamacao`.`procedente` `procedente`, "
		lstrSql = lstrSql & "           `reclamacao`.`dt_solicitacao`, "
		lstrSql = lstrSql & "           `reclamacao`.`hr_solicitacao`, "
		lstrSql = lstrSql & "           `reclamacao`.`dt_conclusao`, "
		lstrSql = lstrSql & "           `reclamacao`.`hr_conclusao`, "
		lstrSql = lstrSql & "           IFNULL(`unidb`.`nome`, `unida`.`nome`) `nome`, "
		lstrSql = lstrSql & "           `reclamacao`.`cod` `seq`, "
		lstrSql = lstrSql & "           `reclamacao`.`protocolo` `protocolo`, "
		lstrSql = lstrSql & "           IFNULL(`unidb`.`zona`, `unida`.`zona`) `zona`, "
		lstrSql = lstrSql & "           IFNULL(`unidb`.`livro`, `unida`.`livro`) `livro`, "
		lstrSql = lstrSql & "           IFNULL(`unidb`.`conta`, `unida`.`conta`) `conta`, "
		lstrSql = lstrSql & "           `reclamacao`.`unid` `grupo`, "
		lstrSql = lstrSql & "           `reclamacao`.`visita_tecnica` "
		lstrSql = lstrSql & "      FROM `reclamacao` "
		lstrSql = lstrSql & " LEFT JOIN `unidb` ON(`unidb`.`unid_id` = `reclamacao`.`unid_id` AND `reclamacao`.`unid` = 'B') "
		lstrSql = lstrSql & " LEFT JOIN `unida` ON(`unida`.`unid_id` = `reclamacao`.`unid_id` AND `reclamacao`.`unid` = 'A') "
		lstrSql = lstrSql & " LEFT JOIN `consum` ON(`consum`.`consreg` = `reclamacao`.`cons_id`) "
		lstrSql = lstrSql & " LEFT JOIN `tipo_reclamacao` ON(`tipo_reclamacao`.`id` = `reclamacao`.`tipo_reclamacao`) "
		lstrSql = lstrSql & "     WHERE (`reclamacao`.`dt_conclusao` BETWEEN '" & VB6.Format(idteIni, "yyyy-MM-dd") & "' AND '" & VB6.Format(idteFim, "yyyy-MM-dd") & "') "
		lstrSql = lstrSql & "       AND `reclamacao`.`tipo_reclamacao` > 2 "
		lstrSql = lstrSql & "       AND `reclamacao`.`resolvida` = 1 "
		lstrSql = lstrSql & "  ORDER BY 1 ASC, 3 ASC, 6 ASC, 7 ASC, 4 ASC, 5 ASC, 9 ASC, 10 ASC "
		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, " Reclamação ")
					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"'
						lstrTip = IIf(IsDbNull(.Fields("tipo_atendimento").value), "", .Fields("tipo_atendimento").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"'
						llngSer = IIf(IsDbNull(.Fields("codigo_servico").value), "0", .Fields("codigo_servico").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"'
						lstrPrc = IIf(IsDbNull(.Fields("procedente").value), "P", .Fields("procedente").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"'
						lstrNom = IIf(IsDbNull(.Fields("nome").value), "", .Fields("nome").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"'
						llngSeq = IIf(IsDbNull(.Fields("seq").value), "0", .Fields("seq").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"'
						lstrPro = IIf(IsDbNull(.Fields("protocolo").value), "", .Fields("protocolo").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"'
						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)
						'UPGRADE_WARNING: 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("grupo").value), "B", .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"'
						ldteSol = CDate(IIf(IsDbNull(.Fields("dt_solicitacao").value), "1900-01-01", .Fields("dt_solicitacao").value) & " " & VB6.Format(IIf(IsDbNull(.Fields("hr_solicitacao").value), "00:00:00", .Fields("hr_solicitacao").value), "HH:NN:SS"))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldteCon = CDate(IIf(IsDbNull(.Fields("dt_conclusao").value), "1900-01-01", .Fields("dt_conclusao").value) & " " & VB6.Format(IIf(IsDbNull(.Fields("hr_conclusao").value), "00:00:00", .Fields("hr_conclusao").value), "HH:NN:SS"))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrVis = IIf(IsDbNull(.Fields("visita_tecnica").value), "N", .Fields("visita_tecnica").value)
						'Calcula Dias
						ldteLoo = CDate(VB6.Format(ldteSol, "DD/MM/YYYY"))
						ldteAux = CDate(VB6.Format(ldteCon, "DD/MM/YYYY"))
						ldblPra = 0
						While ldteLoo <= ldteAux
							If VerificaDiaUtil(ldteLoo) Then
								ldblPra = ldblPra + 1
							End If
							ldteLoo = System.Date.FromOADate(DateSerial(Year(ldteLoo), Month(ldteLoo), VB.Day(ldteLoo)).ToOADate + 1)
						End While
						ldblVer = 0
						ldblLau = 0
						ldblRes = 0
						If (llngSer > 3 And lstrVis = "N") Or (llngSer = 3 And lstrPrc = "S") Then
							With Me.mfgReclamacao
								.Rows = .Rows + 1
								.set_TextMatrix(.Rows - 1, 0, llngSer)
								.set_TextMatrix(.Rows - 1, 1, lstrTip)
								.set_TextMatrix(.Rows - 1, 2, VB6.Format(ldblPra, "#,##0.00"))
								.set_TextMatrix(.Rows - 1, 3, lstrPrc)
								.set_TextMatrix(.Rows - 1, 4, lstrNom)
								.set_TextMatrix(.Rows - 1, 5, llngSeq)
								.set_TextMatrix(.Rows - 1, 6, lstrPro)
								.set_TextMatrix(.Rows - 1, 7, lstrZon)
								.set_TextMatrix(.Rows - 1, 8, lstrLiv)
								.set_TextMatrix(.Rows - 1, 9, lstrCon)
								.set_TextMatrix(.Rows - 1, 10, lstrGru)
								.set_TextMatrix(.Rows - 1, 11, ldteSol)
								.set_TextMatrix(.Rows - 1, 12, ldteCon)
								If llngSer = 3 Then 'Danos eletricos Marretado para não dar crédito ao consumidor
									ldblVer = Arredondar(ldblPra * 0.22, 0)
									ldblLau = Arredondar(ldblPra * 0.33, 0)
									ldblRes = ldblPra - (ldblVer + ldblLau)
								End If
								.set_TextMatrix(.Rows - 1, 13, ldblVer)
								.set_TextMatrix(.Rows - 1, 14, 0)
								.set_TextMatrix(.Rows - 1, 15, ldblLau)
								.set_TextMatrix(.Rows - 1, 16, ldblRes)
								If llngSer = 3 Then
									.set_TextMatrix(.Rows - 1, 18, VB6.Format(CInt(VB.Left(Me.mfgAnexoIII.get_TextMatrix(23, 2), 2)) + CInt(VB.Left(Me.mfgAnexoIII.get_TextMatrix(22, 2), 2)) + CInt(VB.Left(Me.mfgAnexoIII.get_TextMatrix(20, 2), 2)), "#,##0.00"))
								Else
									.set_TextMatrix(.Rows - 1, 18, VB6.Format(CInt(VB.Left(Me.mfgAnexoIII.get_TextMatrix(18, 2), 2)), "#,##0.00"))
								End If
								.set_TextMatrix(.Rows - 1, 19, VB6.Format(ldblPra, "#,##0.00"))
								If CDbl(IIf(IsNumeric(.get_TextMatrix(.Rows - 1, 19)), .get_TextMatrix(.Rows - 1, 19), 0)) > CDbl(IIf(IsNumeric(.get_TextMatrix(.Rows - 1, 18)), .get_TextMatrix(.Rows - 1, 18), 0)) Then
									.set_TextMatrix(.Rows - 1, 17, VB6.Format(CalcCM(VB6.Format(ldteCon, "MM/YYYY"), lstrZon, lstrLiv, lstrCon, lstrGru, 1, iintMesIniPerSeco, iintMesFimPerSeco, 1), "#,##0.00"))
									.set_TextMatrix(.Rows - 1, 20, VB6.Format(Arredondar(((CDbl(.get_TextMatrix(.Rows - 1, 17)) / 730) * (CDbl(.get_TextMatrix(.Rows - 1, 19)) / CDbl(.get_TextMatrix(.Rows - 1, 18)))) * 100, 2), "#,##0.00"))
									If CDbl(IIf(IsNumeric(.get_TextMatrix(.Rows - 1, 20)), .get_TextMatrix(.Rows - 1, 20), 0)) > 0 Then
										If (CDbl(IIf(IsNumeric(.get_TextMatrix(.Rows - 1, 17)), .get_TextMatrix(.Rows - 1, 17), 0)) * 10) < CDbl(IIf(IsNumeric(.get_TextMatrix(.Rows - 1, 20)), .get_TextMatrix(.Rows - 1, 20), 0)) Then
											.set_TextMatrix(.Rows - 1, 20, VB6.Format(CDbl(IIf(IsNumeric(.get_TextMatrix(.Rows - 1, 17)), .get_TextMatrix(.Rows - 1, 17), 0)) * 10, "#,##0.00"))
										End If
									End If
								Else
									.set_TextMatrix(.Rows - 1, 17, "")
									.set_TextMatrix(.Rows - 1, 20, "")
								End If
							End With
						End If
						Call .MoveNext()
						Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1,  , " Reclamação ")
					End While
				End If
				Call .Close()
			End If
		End With
		Me.mfgReclamacao.Redraw = True
		'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
		Call TotalizaRe()
	End Sub
	
	Private Sub TotalizaRe()
		Dim llngRow As Integer
		Dim llngTip As Integer
		Dim ldblTot As Double
		Dim llngQtd As Double
		Dim llngQtdFora As Double
		Dim llngQtdDanos As Double
		Dim ldblValorFora As Double
		Dim llngQtdDanosFora As Double
		Dim ldblVer As Double
		Dim ldblLau As Double
		Dim ldblRes As Double
		Dim lstrPrc As String
		llngQtd = 0
		ldblTot = 0
		llngQtdDanos = 0
		ldblVer = 0
		ldblLau = 0
		ldblRes = 0
		With Me.mfgReclamacao
			For llngRow = 1 To .Rows - 1
				llngTip = CInt(.get_TextMatrix(llngRow, 0))
				lstrPrc = .get_TextMatrix(llngRow, 3)
				If llngTip > 3 Then
					llngQtd = llngQtd + 1
					ldblTot = ldblTot + CDbl(IIf(IsNumeric(.get_TextMatrix(llngRow, 2)), .get_TextMatrix(llngRow, 2), 0))
					'Se tiver fora do Prazo
					If Trim(.get_TextMatrix(llngRow, 20)) <> "" Then 'If Conversion.CDbl(IIf(IsNumeric(.TextMatrix(llngRow, 20)), .TextMatrix(llngRow, 20), 0)) > 0 Then
						llngQtdFora = llngQtdFora + 1
						ldblValorFora = ldblValorFora + CDbl(IIf(IsNumeric(.get_TextMatrix(llngRow, 20)), .get_TextMatrix(llngRow, 20), 0))
					End If
					.set_TextMatrix(llngRow, 21, 18)
				Else
					llngQtdDanos = llngQtdDanos + 1
					ldblVer = ldblVer + CDbl(IIf(IsNumeric(.get_TextMatrix(llngRow, 13)), .get_TextMatrix(llngRow, 13), 0))
					ldblLau = ldblLau + CDbl(IIf(IsNumeric(.get_TextMatrix(llngRow, 15)), .get_TextMatrix(llngRow, 15), 0))
					ldblRes = ldblRes + CDbl(IIf(IsNumeric(.get_TextMatrix(llngRow, 16)), .get_TextMatrix(llngRow, 16), 0))
					.set_TextMatrix(llngRow, 21, 23)
				End If
			Next llngRow
		End With
		With Me.mfgAnexoIII
			.set_TextMatrix(18, 3, VB6.Format(llngQtd, "#,##0")) 'qtde
			.set_TextMatrix(18, 4, VB6.Format(Arredondar(ldblTot / IIf(llngQtd > 0, llngQtd, 1), 2), "#,##0.00")) 'prazo médio
			.set_TextMatrix(18, 5, VB6.Format(llngQtdFora, "#,##0")) 'qtde
			.set_TextMatrix(18, 6, VB6.Format(Arredondar(ldblValorFora, 2), "#,##0.00")) 'valor
			'
			'Verificação
			.set_TextMatrix(20, 3, VB6.Format(llngQtdDanos, "#,##0")) 'qtde
			.set_TextMatrix(20, 4, VB6.Format(Arredondar(ldblVer / IIf(llngQtdDanos > 0, llngQtdDanos, 1), 2), "#,##0.00")) 'prazo médio
			.set_TextMatrix(20, 5, "0")
			.set_TextMatrix(20, 6, "0,00")
			'Perecível
			.set_TextMatrix(21, 3, VB6.Format(0, "#,##0")) 'qtde
			.set_TextMatrix(21, 4, VB6.Format(Arredondar(0 / IIf(llngQtdDanos > 0, llngQtdDanos, 1), 2), "#,##0.00")) 'prazo médio
			.set_TextMatrix(21, 5, "0")
			.set_TextMatrix(21, 6, "0,00")
			'Laudo
			.set_TextMatrix(22, 3, VB6.Format(llngQtdDanos, "#,##0")) 'qtde
			.set_TextMatrix(22, 4, VB6.Format(Arredondar(ldblLau / IIf(llngQtdDanos > 0, llngQtdDanos, 1), 2), "#,##0.00")) 'prazo médio
			.set_TextMatrix(22, 5, "0")
			.set_TextMatrix(22, 6, "0,00")
			'Ressarcimento
			.set_TextMatrix(23, 3, VB6.Format(llngQtdDanos, "#,##0")) 'qtde
			.set_TextMatrix(23, 4, VB6.Format(Arredondar(ldblRes / IIf(llngQtdDanos > 0, llngQtdDanos, 1), 2), "#,##0.00")) 'prazo médio
			.set_TextMatrix(23, 5, "0")
			.set_TextMatrix(23, 6, "0,00")
		End With
	End Sub
	
	Private Sub TotalizaOS()
		Dim llngRow As Integer
		
		Dim lstrCodServico As String
		Dim lstrRegiao As String
		
		Dim ldblPrazoRealizado As Double
		Dim ldblQtdeSegVistoria As Double
		'Ligação Nova
		Dim ldblDiasVistoria As Double
		Dim ldblDiasLigacao As Double
		'
		Dim llngQtdeLigacaoNovaUrbano As Integer
		Dim ldblDiasLigacaoNovaUrbano As Double
		Dim llngQtdeLigacaoNovaVistoriaUrbano As Integer
		Dim ldblDiasLigacaoNovaVistoriaUrbano As Double
		'
		Dim llngQtdeLigacaoNovaRural As Integer
		Dim ldblDiasLigacaoNovaRural As Double
		Dim llngQtdeLigacaoNovaVistoriaRural As Integer
		Dim ldblDiasLigacaoNovaVistoriaRural As Double
		'Religação
		'Normal
		'Urbano
		Dim llngQtdeReligacaoNormalUrbano As Integer
		Dim ldblDiasReligacaoNormalUrbano As Double
		Dim llngQtdeReligacaoNormalUrbanoFora As Integer
		Dim ldblValorReligacaoNormalUrbanoFora As Double
		'Rural
		Dim llngQtdeReligacaoNormalRural As Integer
		Dim ldblDiasReligacaoNormalRural As Double
		Dim llngQtdeReligacaoNormalRuralFora As Integer
		Dim ldblValorReligacaoNormalRuralFora As Double
		'Urgencia
		'Urbano
		Dim llngQtdeReligacaoUrgenciaUrbano As Integer
		Dim ldblDiasReligacaoUrgenciaUrbano As Double
		Dim llngQtdeReligacaoUrgenciaUrbanoFora As Integer
		Dim ldblValorReligacaoUrgenciaUrbanoFora As Double
		'Rural
		Dim llngQtdeReligacaoUrgenciaRural As Integer
		Dim ldblDiasReligacaoUrgenciaRural As Double
		Dim llngQtdeReligacaoUrgenciaRuralFora As Integer
		Dim ldblValorReligacaoUrgenciaRuralFora As Double
		'Vistoria
		Dim llngQtdeVistoriaUrbano As Integer
		Dim llngQtdeVistoriaRural As Integer
		Dim ldblDiasVistoriaUrbano As Double
		Dim ldblDiasVistoriaRural As Double
		'Aferição
		Dim llngQtdeAfericao As Integer
		Dim ldblDiasAfericao As Double
		Dim llngQtdeAfericaoFora As Integer
		Dim ldblValorAfericaoFora As Double
		'
		'Religação
		'Normal
		'Urbano
		llngQtdeReligacaoNormalUrbano = 0
		ldblDiasReligacaoNormalUrbano = 0
		llngQtdeReligacaoNormalUrbanoFora = 0
		ldblValorReligacaoNormalUrbanoFora = 0
		'Rural
		llngQtdeReligacaoNormalRural = 0
		ldblDiasReligacaoNormalRural = 0
		llngQtdeReligacaoNormalRuralFora = 0
		ldblValorReligacaoNormalRuralFora = 0
		'Urgencia
		'Urbano
		llngQtdeReligacaoUrgenciaUrbano = 0
		ldblDiasReligacaoUrgenciaUrbano = 0
		llngQtdeReligacaoUrgenciaUrbanoFora = 0
		ldblValorReligacaoUrgenciaUrbanoFora = 0
		'Rural
		llngQtdeReligacaoUrgenciaRural = 0
		ldblDiasReligacaoUrgenciaRural = 0
		llngQtdeReligacaoUrgenciaRuralFora = 0
		ldblValorReligacaoUrgenciaRuralFora = 0
		'Vistoria
		llngQtdeVistoriaUrbano = 0
		ldblDiasVistoriaUrbano = 0
		llngQtdeVistoriaRural = 0
		ldblDiasVistoriaRural = 0
		'Aferição
		llngQtdeAfericao = 0
		ldblDiasAfericao = 0
		llngQtdeAfericaoFora = 0
		ldblValorAfericaoFora = 0
		'Ligação Nova
		llngQtdeLigacaoNovaUrbano = 0
		ldblDiasLigacaoNovaUrbano = 0
		llngQtdeLigacaoNovaRural = 0
		ldblDiasLigacaoNovaRural = 0
		llngQtdeLigacaoNovaVistoriaUrbano = 0
		ldblDiasLigacaoNovaVistoriaUrbano = 0
		llngQtdeLigacaoNovaVistoriaRural = 0
		ldblDiasLigacaoNovaVistoriaRural = 0
		'
		With Me.mfgSolServ
			For llngRow = 1 To .Rows - 1
				'9050000002' '904000001','904000002','904000004','904000005')) " '1 vistoria 2 afericao 4 relig normal 5 relig urgencia
				lstrCodServico = .get_TextMatrix(llngRow, 0)
				lstrRegiao = .get_TextMatrix(llngRow, 3)
				ldblPrazoRealizado = CDbl(IIf(IsNumeric(.get_TextMatrix(llngRow, 2)), .get_TextMatrix(llngRow, 2), 0))
				ldblDiasLigacao = CDbl(IIf(IsNumeric(.get_TextMatrix(llngRow, 13)), .get_TextMatrix(llngRow, 13), 0))
				ldblDiasVistoria = CDbl(IIf(IsNumeric(.get_TextMatrix(llngRow, 14)), .get_TextMatrix(llngRow, 14), 0))
				ldblQtdeSegVistoria = CInt(IIf(IsNumeric(.get_TextMatrix(llngRow, 15)), .get_TextMatrix(llngRow, 15), 0))
				If VB.Left(lstrCodServico, 9) = "904000001" Then 'Vistoria
					'        If lstrRegiao = "U" Then
					'          llngQtdeVistoriaUrbano = llngQtdeVistoriaUrbano + 1
					'        ElseIf lstrRegiao = "R" Then
					'          llngQtdeVistoriaRural = llngQtdeVistoriaRural + 1
					'        End If
				ElseIf VB.Left(lstrCodServico, 9) = "904000002" Then  'Aferição
					llngQtdeAfericao = llngQtdeAfericao + 1
					ldblDiasAfericao = ldblDiasAfericao + ldblPrazoRealizado
					'Se tiver fora do Prazo
					If Trim(.get_TextMatrix(llngRow, 19)) <> "" Then 'If Conversion.CDbl(IIf(IsNumeric(.TextMatrix(llngRow, 19)), .TextMatrix(llngRow, 19), 0)) > 0 Then
						llngQtdeAfericaoFora = llngQtdeAfericaoFora + 1
						ldblValorAfericaoFora = ldblValorAfericaoFora + CDbl(IIf(IsNumeric(.get_TextMatrix(llngRow, 19)), .get_TextMatrix(llngRow, 19), 0))
					End If
					.set_TextMatrix(llngRow, 20, 12)
				ElseIf VB.Left(lstrCodServico, 9) = "904000004" Then  'Religação Normal
					If lstrRegiao = "U" Then
						llngQtdeReligacaoNormalUrbano = llngQtdeReligacaoNormalUrbano + 1
						ldblDiasReligacaoNormalUrbano = ldblDiasReligacaoNormalUrbano + ldblPrazoRealizado
						'Se tiver fora do Prazo
						If Trim(.get_TextMatrix(llngRow, 19)) <> "" Then 'If Conversion.CDbl(IIf(IsNumeric(.TextMatrix(llngRow, 19)), .TextMatrix(llngRow, 19), 0)) > 0 Then
							llngQtdeReligacaoNormalUrbanoFora = llngQtdeReligacaoNormalUrbanoFora + 1
							ldblValorReligacaoNormalUrbanoFora = ldblValorReligacaoNormalUrbanoFora + CDbl(IIf(IsNumeric(.get_TextMatrix(llngRow, 19)), .get_TextMatrix(llngRow, 19), 0))
						End If
						.set_TextMatrix(llngRow, 20, 14)
					ElseIf lstrRegiao = "R" Then 
						llngQtdeReligacaoNormalRural = llngQtdeReligacaoNormalRural + 1
						ldblDiasReligacaoNormalRural = ldblDiasReligacaoNormalRural + ldblPrazoRealizado
						'Se tiver fora do Prazo
						If Trim(.get_TextMatrix(llngRow, 19)) <> "" Then 'If Conversion.CDbl(IIf(IsNumeric(.TextMatrix(llngRow, 19)), .TextMatrix(llngRow, 19), 0)) > 0 Then
							llngQtdeReligacaoNormalRuralFora = llngQtdeReligacaoNormalRuralFora + 1
							ldblValorReligacaoNormalRuralFora = ldblValorReligacaoNormalRuralFora + CDbl(IIf(IsNumeric(.get_TextMatrix(llngRow, 19)), .get_TextMatrix(llngRow, 19), 0))
						End If
						.set_TextMatrix(llngRow, 20, 15)
					End If
				ElseIf VB.Left(lstrCodServico, 9) = "904000005" Then  'Religação Urgencia
					If lstrRegiao = "U" Then
						llngQtdeReligacaoUrgenciaUrbano = llngQtdeReligacaoUrgenciaUrbano + 1
						ldblDiasReligacaoUrgenciaUrbano = ldblDiasReligacaoUrgenciaUrbano + ldblPrazoRealizado
						'Se tiver fora do Prazo
						If Trim(.get_TextMatrix(llngRow, 19)) <> "" Then 'If Conversion.CDbl(IIf(IsNumeric(.TextMatrix(llngRow, 19)), .TextMatrix(llngRow, 19), 0)) > 0 Then
							llngQtdeReligacaoUrgenciaUrbanoFora = llngQtdeReligacaoUrgenciaUrbanoFora + 1
							ldblValorReligacaoUrgenciaUrbanoFora = ldblValorReligacaoUrgenciaUrbanoFora + CDbl(IIf(IsNumeric(.get_TextMatrix(llngRow, 19)), .get_TextMatrix(llngRow, 19), 0))
						End If
						.set_TextMatrix(llngRow, 20, 16)
					ElseIf lstrRegiao = "R" Then 
						llngQtdeReligacaoUrgenciaRural = llngQtdeReligacaoUrgenciaRural + 1
						ldblDiasReligacaoUrgenciaRural = ldblDiasReligacaoUrgenciaRural + ldblPrazoRealizado
						'Se tiver fora do Prazo
						If Trim(.get_TextMatrix(llngRow, 19)) <> "" Then 'If Conversion.CDbl(IIf(IsNumeric(.TextMatrix(llngRow, 19)), .TextMatrix(llngRow, 19), 0)) > 0 Then
							llngQtdeReligacaoUrgenciaRuralFora = llngQtdeReligacaoUrgenciaRuralFora + 1
							ldblValorReligacaoUrgenciaRuralFora = ldblValorReligacaoUrgenciaRuralFora + CDbl(IIf(IsNumeric(.get_TextMatrix(llngRow, 19)), .get_TextMatrix(llngRow, 19), 0))
						End If
						.set_TextMatrix(llngRow, 20, 17)
					End If
				ElseIf VB.Left(lstrCodServico, 10) = "9050000002" Then  'Ligação Nova
					If lstrRegiao = "U" Then
						'vistoria
						llngQtdeLigacaoNovaVistoriaUrbano = llngQtdeLigacaoNovaVistoriaUrbano + IIf(ldblQtdeSegVistoria > 0, 1, 0)
						ldblDiasLigacaoNovaVistoriaUrbano = ldblDiasLigacaoNovaVistoriaUrbano + (ldblDiasVistoria + ldblQtdeSegVistoria)
						'Ligacao
						llngQtdeLigacaoNovaUrbano = llngQtdeLigacaoNovaUrbano + 1
						ldblDiasLigacaoNovaUrbano = ldblDiasLigacaoNovaUrbano + ldblDiasLigacao
						.set_TextMatrix(llngRow, 20, 3)
					ElseIf lstrRegiao = "R" Then 
						'Vistoria
						llngQtdeLigacaoNovaVistoriaRural = llngQtdeLigacaoNovaVistoriaRural + IIf(ldblQtdeSegVistoria > 0, 1, 0)
						ldblDiasLigacaoNovaVistoriaRural = ldblDiasLigacaoNovaVistoriaRural + (ldblDiasVistoria + ldblQtdeSegVistoria)
						'Ligacao
						llngQtdeLigacaoNovaRural = llngQtdeLigacaoNovaRural + 1
						ldblDiasLigacaoNovaRural = ldblDiasLigacaoNovaRural + ldblDiasLigacao
						.set_TextMatrix(llngRow, 20, 4)
					End If
				End If
			Next llngRow
		End With
		llngQtdeLigacaoNovaVistoriaUrbano = llngQtdeLigacaoNovaVistoriaUrbano + llngQtdeLigacaoNovaUrbano
		llngQtdeLigacaoNovaVistoriaRural = llngQtdeLigacaoNovaVistoriaRural + llngQtdeLigacaoNovaRural
		With Me.mfgAnexoIII
			.Redraw = False
			'Ligação Nova
			'Vistoria
			'Urbana
			.set_TextMatrix(1, 3, VB6.Format(llngQtdeLigacaoNovaVistoriaUrbano, "#,##0")) 'qtde
			.set_TextMatrix(1, 4, VB6.Format(Arredondar(ldblDiasLigacaoNovaVistoriaUrbano / IIf(llngQtdeLigacaoNovaVistoriaUrbano > 0, llngQtdeLigacaoNovaVistoriaUrbano, 1), 2), "#,##0.00")) 'prazo médio
			.set_TextMatrix(1, 5, "0")
			.set_TextMatrix(1, 6, "0,00")
			'Rural
			.set_TextMatrix(2, 3, VB6.Format(llngQtdeLigacaoNovaVistoriaRural, "#,##0")) 'qtde
			.set_TextMatrix(2, 4, VB6.Format(Arredondar(ldblDiasLigacaoNovaVistoriaRural / IIf(llngQtdeLigacaoNovaVistoriaRural > 0, llngQtdeLigacaoNovaVistoriaRural, 1), 2), "#,##0.00")) 'prazo médio
			.set_TextMatrix(2, 5, "0")
			.set_TextMatrix(2, 6, "0,00")
			'Ligação Nova
			'Urbana
			.set_TextMatrix(3, 3, VB6.Format(llngQtdeLigacaoNovaUrbano, "#,##0")) 'qtde
			.set_TextMatrix(3, 4, VB6.Format(Arredondar(ldblDiasLigacaoNovaUrbano / IIf(llngQtdeLigacaoNovaUrbano > 0, llngQtdeLigacaoNovaUrbano, 1), 2), "#,##0.00")) 'prazo médio
			.set_TextMatrix(3, 5, "0")
			.set_TextMatrix(3, 6, "0,00")
			'Rural
			.set_TextMatrix(4, 3, VB6.Format(llngQtdeLigacaoNovaRural, "#,##0")) 'qtde
			.set_TextMatrix(4, 4, VB6.Format(Arredondar(ldblDiasLigacaoNovaRural / IIf(llngQtdeLigacaoNovaRural > 0, llngQtdeLigacaoNovaRural, 1), 2), "#,##0.00")) 'prazo médio
			.set_TextMatrix(4, 5, "0")
			.set_TextMatrix(4, 6, "0,00")
			'Aferição
			.set_TextMatrix(12, 3, VB6.Format(llngQtdeAfericao, "#,##0")) 'qtde
			.set_TextMatrix(12, 4, VB6.Format(Arredondar(ldblDiasAfericao / IIf(llngQtdeAfericao > 0, IIf(llngQtdeAfericao > 0, llngQtdeAfericao, 1), 1), 2), "#,##0.00")) 'prazo médio
			.set_TextMatrix(12, 5, VB6.Format(llngQtdeAfericaoFora, "#,##0")) 'qtde
			.set_TextMatrix(12, 6, VB6.Format(Arredondar(ldblValorAfericaoFora, 2), "#,##0.00")) 'valor
			'Religacao normal
			'Urbana
			.set_TextMatrix(14, 3, VB6.Format(llngQtdeReligacaoNormalUrbano, "#,##0")) 'qtde
			.set_TextMatrix(14, 4, VB6.Format(Arredondar(ldblDiasReligacaoNormalUrbano / IIf(llngQtdeReligacaoNormalUrbano > 0, llngQtdeReligacaoNormalUrbano, 1), 2), "#,##0.00")) 'prazo médio
			.set_TextMatrix(14, 5, VB6.Format(llngQtdeReligacaoNormalUrbanoFora, "#,##0")) 'qtde
			.set_TextMatrix(14, 6, VB6.Format(Arredondar(ldblValorReligacaoNormalUrbanoFora, 2), "#,##0.00")) 'valor
			'Rural
			.set_TextMatrix(15, 3, VB6.Format(llngQtdeReligacaoNormalRural, "#,##0")) 'qtde
			.set_TextMatrix(15, 4, VB6.Format(Arredondar(ldblDiasReligacaoNormalRural / IIf(llngQtdeReligacaoNormalRural > 0, llngQtdeReligacaoNormalRural, 1), 2), "#,##0.00")) 'prazo médio
			.set_TextMatrix(15, 5, VB6.Format(llngQtdeReligacaoNormalRuralFora, "#,##0")) 'qtde
			.set_TextMatrix(15, 6, VB6.Format(Arredondar(ldblValorReligacaoNormalRuralFora, 2), "#,##0.00")) 'valor
			'Religacao urgencia
			'Urbana
			.set_TextMatrix(16, 3, VB6.Format(llngQtdeReligacaoUrgenciaUrbano, "#,##0")) 'qtde
			.set_TextMatrix(16, 4, VB6.Format(Arredondar(ldblDiasReligacaoUrgenciaUrbano / IIf(llngQtdeReligacaoUrgenciaUrbano > 0, llngQtdeReligacaoUrgenciaUrbano, 1), 2), "#,##0.00")) 'prazo médio
			.set_TextMatrix(16, 5, VB6.Format(llngQtdeReligacaoUrgenciaUrbanoFora, "#,##0")) 'qtde
			.set_TextMatrix(16, 6, VB6.Format(Arredondar(ldblValorReligacaoUrgenciaUrbanoFora, 2), "#,##0.00")) 'valor
			'Rural
			.set_TextMatrix(17, 3, VB6.Format(llngQtdeReligacaoUrgenciaRural, "#,##0")) 'qtde
			.set_TextMatrix(17, 4, VB6.Format(Arredondar(ldblDiasReligacaoUrgenciaRural / IIf(llngQtdeReligacaoUrgenciaRural > 0, llngQtdeReligacaoUrgenciaRural, 1), 2), "#,##0.00")) 'prazo médio
			.set_TextMatrix(17, 5, VB6.Format(llngQtdeReligacaoUrgenciaRuralFora, "#,##0")) 'qtde
			.set_TextMatrix(17, 6, VB6.Format(Arredondar(ldblValorReligacaoUrgenciaRuralFora, 2), "#,##0.00")) 'valor
			.Redraw = True
		End With
	End Sub
	
	Private Sub dtpMesAno_Change(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles dtpMesAno.Change
		Me.dtpCredMesAno.value = CDate(UltimoDiaMes((Me.dtpMesAno.Month), (Me.dtpMesAno.Year)) & "/" & VB6.Format(Me.dtpMesAno.value, "MM/YYYY"))
		Me.dtpCredMesAno.value = CDate(System.Date.FromOADate(DateSerial(Me.dtpCredMesAno.Year, Me.dtpCredMesAno.Month, Me.dtpCredMesAno.Day).ToOADate + 1))
	End Sub
	
	Private Sub dtpMesAno_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles dtpMesAno.ClickEvent
		Call dtpMesAno_Change(dtpMesAno, New System.EventArgs())
	End Sub
	
	Private Sub frmRelAnexoIII_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		ifrmRelAnexoII = New FrmRelatorio
		iintMesIniPerSeco = Val(LeConfig("MES_INI_PERIODO_SECO"))
		iintMesFimPerSeco = iintMesIniPerSeco + 6
		Me.dtpMesAno.value = BuscaDataBD
		'UPGRADE_WARNING: Couldn't resolve default property of object Me.dtpMesAno.value. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
		Me.dtpCredMesAno.value = Me.dtpMesAno.value
		Call MontaGrade()
	End Sub
	
	Private Sub MontaGrade()
		'Prepara a Grade
		Dim llngRow As Integer
		Dim llngCol As Integer
		Dim llngTam As Integer
		With Me.mfgSolServ
			.Redraw = False
			.Rows = 1
			Call .Clear()
			.set_ColWidth(0, 0)
			.set_ColWidth(1, 2000)
			.set_ColWidth(2, 800)
			.set_ColWidth(3, 600)
			.set_ColWidth(4, 1200)
			.set_ColWidth(5, 900)
			.set_ColWidth(6, 1420)
			.set_ColWidth(7, 500)
			.set_ColWidth(8, 460)
			.set_ColWidth(9, 900)
			.set_ColWidth(10, 660)
			.set_ColWidth(11, 1700)
			.set_ColWidth(12, 1700)
			.set_ColWidth(13, 700)
			.set_ColWidth(14, 700)
			.set_ColWidth(15, 700)
			.set_ColWidth(20, 0)
			.set_TextMatrix(0, 0, "Código")
			.set_TextMatrix(0, 1, "Tipo")
			.set_TextMatrix(0, 2, "Prazo")
			.set_TextMatrix(0, 3, "Região")
			.set_TextMatrix(0, 4, "Nome")
			.set_TextMatrix(0, 5, "Seqüência")
			.set_TextMatrix(0, 6, "Protocolo")
			.set_TextMatrix(0, 7, "Zona")
			.set_TextMatrix(0, 8, "Livro")
			.set_TextMatrix(0, 9, "Conta")
			.set_TextMatrix(0, 10, "Grupo")
			.set_TextMatrix(0, 11, "Solicitação")
			.set_TextMatrix(0, 12, "Conclusão")
			.set_TextMatrix(0, 13, "Dia Rea")
			.set_TextMatrix(0, 14, "Pri Vis")
			.set_TextMatrix(0, 15, "Seg Vis")
			.set_TextMatrix(0, 16, "EUSD")
			.set_TextMatrix(0, 17, "PP")
			.set_TextMatrix(0, 18, "PV")
			.set_TextMatrix(0, 19, "((EUSD / 730) * (PV / PP)) * 100")
			.set_TextMatrix(0, 20, "Linha Anexo III")
			.Redraw = True
		End With
		With Me.mfgReclamacao
			.Redraw = False
			.Rows = 1
			Call .Clear()
			.set_ColWidth(0, 0)
			.set_ColWidth(1, 2000)
			.set_ColWidth(2, 800)
			.set_ColWidth(3, 600)
			.set_ColWidth(4, 1200)
			.set_ColWidth(5, 900)
			.set_ColWidth(6, 1420)
			.set_ColWidth(7, 500)
			.set_ColWidth(8, 460)
			.set_ColWidth(9, 460)
			.set_ColWidth(10, 660)
			.set_ColWidth(11, 1700)
			.set_ColWidth(12, 1700)
			.set_ColWidth(13, 700)
			.set_ColWidth(14, 700)
			.set_ColWidth(15, 700)
			.set_ColWidth(16, 700)
			.set_ColWidth(21, 0)
			.set_TextMatrix(0, 0, "Código")
			.set_TextMatrix(0, 1, "Tipo")
			.set_TextMatrix(0, 2, "Prazo")
			.set_TextMatrix(0, 3, "Procedente")
			.set_TextMatrix(0, 4, "Nome")
			.set_TextMatrix(0, 5, "Seqüência")
			.set_TextMatrix(0, 6, "Protocolo")
			.set_TextMatrix(0, 7, "Zona")
			.set_TextMatrix(0, 8, "Livro")
			.set_TextMatrix(0, 9, "Conta")
			.set_TextMatrix(0, 10, "Grupo")
			.set_TextMatrix(0, 11, "Solicitação")
			.set_TextMatrix(0, 12, "Conclusão")
			.set_TextMatrix(0, 13, "Verificação")
			.set_TextMatrix(0, 14, "Perecível")
			.set_TextMatrix(0, 15, "Resultado")
			.set_TextMatrix(0, 16, "Ressarcimento")
			.set_TextMatrix(0, 17, "EUSD")
			.set_TextMatrix(0, 18, "PP")
			.set_TextMatrix(0, 19, "PV")
			.set_TextMatrix(0, 20, "((EUSD / 730) * (PV / PP)) * 100")
			.set_TextMatrix(0, 21, "Linha Anexo III")
			.Redraw = True
		End With
		With Me.mfgAnexoIII
			.Redraw = False
			.Rows = 24
			Call .Clear()
			.set_ColWidth(0, 5250)
			.set_ColWidth(1, 900)
			.set_ColWidth(2, 1200)
			.set_ColWidth(3, 1700)
			.set_ColWidth(4, 1700)
			.set_ColWidth(5, 1700)
			.set_ColWidth(6, 1700)
			.set_ColAlignment(0, MSFlexGridLib.AlignmentSettings.flexAlignLeftTop)
			.set_ColAlignment(1, MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter)
			.set_ColAlignment(2, MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter)
			.set_ColAlignment(3, MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter)
			.set_ColAlignment(4, MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter)
			.set_ColAlignment(5, MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter)
			.set_ColAlignment(6, MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter)
			.set_TextMatrix(0, 0, "DESCRIÇÃO")
			.set_TextMatrix(0, 1, "Art")
			.set_TextMatrix(0, 2, "Padrão")
			.set_TextMatrix(0, 3, "Qtde(I)")
			.set_TextMatrix(0, 4, "Prazo Médio (II)")
			.set_TextMatrix(0, 5, "Qtde > (III)")
			.set_TextMatrix(0, 6, "R$ (IV)")
			.set_TextMatrix(1, 0, "Prazo máximo de vistoria de unidade consumidora, localizada em área urbana.")
			.set_TextMatrix(1, 1, "Art. 30")
			.set_TextMatrix(1, 2, "03 dias úteis")
			.set_TextMatrix(2, 0, "Prazo máximo de vistoria de unidade consumidora, localizada em área rural.")
			.set_TextMatrix(2, 1, "Art. 30")
			.set_TextMatrix(2, 2, "05 dias úteis")
			.set_TextMatrix(3, 0, "Prazo máximo de ligação de unidade consumidora do grupo B, localizada em área urbana, a partir da data da aprovação das instalações.")
			.set_TextMatrix(3, 1, "Art. 31")
			.set_TextMatrix(3, 2, "02 dias úteis")
			.set_TextMatrix(4, 0, "Prazo máximo de ligação de unidade consumidora do grupo B, localizada em área rural, a partir da data da aprovação das instalações.")
			.set_TextMatrix(4, 1, "Art. 31")
			.set_TextMatrix(4, 2, "05 dias úteis")
			.set_TextMatrix(5, 0, "Prazo máximo de ligação de unidade consumidora do grupo A, a partir da data da aprovação das instalações.")
			.set_TextMatrix(5, 1, "Art. 31")
			.set_TextMatrix(5, 2, "07 dias úteis")
			.set_TextMatrix(6, 0, "Prazo máximo para elaborar os estudos, orçamentos e projetos e informar ao interessado, por escrito, quando da necessidade de realização de obras para viabilização do fornecimento.")
			.set_TextMatrix(6, 1, "Art. 32")
			.set_TextMatrix(6, 2, "30 dias")
			.set_TextMatrix(7, 0, "Prazo máximo de Início das Obras, satisfeitas, pelo interessado, as condições estabelecidas na legislação e normas aplicáveis.")
			.set_TextMatrix(7, 1, "Art. 34")
			.set_TextMatrix(7, 2, "45 dias")
			.set_TextMatrix(8, 0, "Prazo máximo para informar ao interessado o resultado da análise do projeto após sua apresentação.")
			.set_TextMatrix(8, 1, "Art. 37")
			.set_TextMatrix(8, 2, "30 dias")
			.set_TextMatrix(9, 0, "Prazo máximo para reanálise do projeto quando de reprovação por falta de informação da distribuidora na análise anterior.")
			.set_TextMatrix(9, 1, "Art. 37")
			.set_TextMatrix(9, 2, "10 dias")
			.set_TextMatrix(10, 0, "Prazo máximo para substituição do medidor e demais equipamentos de medição após a data de constatação da deficiência, com exceção para os casos previstos no art. 72.")
			.set_TextMatrix(10, 1, "Art. 115")
			.set_TextMatrix(10, 2, "30 dias")
			.set_TextMatrix(11, 0, "Prazo máximo para comunicar, por escrito, o resultado da reclamação ao consumidor referente à discordância em relação à cobrança ou devolução de diferenças apuradas.")
			.set_TextMatrix(11, 1, "Art. 133")
			.set_TextMatrix(11, 2, "10 dias")
			.set_TextMatrix(12, 0, "Prazo máximo para o atendimento de solicitações de aferição dos medidores e demais equipamentos de medição.")
			.set_TextMatrix(12, 1, "Art. 137")
			.set_TextMatrix(12, 2, "30 dias")
			.set_TextMatrix(13, 0, "Prazo máximo para religação, sem ônus para o consumidor, quando constatada a suspensão indevida do fornecimento.")
			.set_TextMatrix(13, 1, "Art. 176")
			.set_TextMatrix(13, 2, "04 horas")
			.set_TextMatrix(14, 0, "Prazo máximo de atendimento a pedidos de religação para unidade consumidora localizada em área urbana, quando cessado o motivo da suspensão.")
			.set_TextMatrix(14, 1, "Art. 176")
			.set_TextMatrix(14, 2, "24 horas")
			.set_TextMatrix(15, 0, "Prazo máximo de atendimento a pedidos de religação para unidade consumidora localizada em área rural, quando cessado o motivo da suspensão.")
			.set_TextMatrix(15, 1, "Art. 176")
			.set_TextMatrix(15, 2, "48 horas")
			.set_TextMatrix(16, 0, "Prazo máximo de atendimento a pedidos de religação de urgência em área urbana, quando cessado o motivo da suspensão.")
			.set_TextMatrix(16, 1, "Art. 176")
			.set_TextMatrix(16, 2, "04 horas")
			.set_TextMatrix(17, 0, "Prazo máximo de atendimento a pedidos de religação de urgência em área rural, quando cessado o motivo da suspensão.")
			.set_TextMatrix(17, 1, "Art. 176")
			.set_TextMatrix(17, 2, "08 horas")
			.set_TextMatrix(18, 0, "Prazo máximo para solução de reclamação do consumidor, observando-se as condições específicas e os prazos de execução de cada situação, sempre que previstos em normas e regulamentos editados pelo Poder Concedente e pela ANEEL, com exceção das reclamações que implicarem realização de visita técnica ao consumidor ou avaliação referente à danos não elétricos reclamados.")
			.set_TextMatrix(18, 1, "Art. 197")
			.set_TextMatrix(18, 2, "05 dias úteis")
			.set_TextMatrix(19, 0, "Prazo máximo para informar por escrito ao consumidor a relação de todos os seus atendimentos comerciais.")
			.set_TextMatrix(19, 1, "Art. 199")
			.set_TextMatrix(19, 2, "30 dias")
			.set_TextMatrix(20, 0, "Prazo máximo para verificação de equipamento em processo de ressarcimento de dano elétrico.")
			.set_TextMatrix(20, 1, "Art. 206")
			.set_TextMatrix(20, 2, "10 dias")
			.set_TextMatrix(21, 0, "Prazo máximo para verificação de equipamento utilizado no acondicionamento de alimentos perecíveis ou de medicamentos em processo de ressarcimento de dano elétrico.")
			.set_TextMatrix(21, 1, "Art. 206")
			.set_TextMatrix(21, 2, "01 dia útil")
			.set_TextMatrix(22, 0, "Prazo máximo para informar por escrito ao consumidor o resultado da solicitação de ressarcimento de dano elétrico, contados a partir da data da verificação ou, na falta desta, a partir da data da solicitação de ressarcimento.")
			.set_TextMatrix(22, 1, "Art. 207")
			.set_TextMatrix(22, 2, "15 dias ")
			.set_TextMatrix(23, 0, "Prazo máximo para efetuar o ressarcimento de dano elétrico ao consumidor por meio do pagamento em moeda corrente, ou o conserto ou substituição do equipamento danificado, após a informação ao consumidor do resultado da solicitação de ressarcimento de dano elétrico.")
			.set_TextMatrix(23, 1, "Art. 208")
			.set_TextMatrix(23, 2, "20 dias")
			For llngRow = 1 To .Rows - 1
				llngTam = CInt(Len(.get_TextMatrix(llngRow, 0)))
				.set_RowHeight(llngRow, IIf(llngTam <= 70, 250, IIf((llngTam > 70 And llngTam < 115), 500, IIf((llngTam >= 115 And llngTam < 200), 650, IIf((llngTam >= 200 And llngTam < 350), 1050, 1200)))))
				.set_TextMatrix(llngRow, 3, "0")
				.set_TextMatrix(llngRow, 4, "0,00")
				.set_TextMatrix(llngRow, 5, "0")
				.set_TextMatrix(llngRow, 6, "0,00")
			Next llngRow
			.Redraw = True
		End With
	End Sub
	
	Private Sub Imprime()
		Dim lstrTab As String
		Dim llngRow As Integer
		istrTamCol = "<0mm|<90mm|^13mm|^13mm|^15mm|^25mm|^15mm|^25mm|>0mm;|"
		With ifrmRelAnexoII
			.quem_chama = Me
			.VS.Font = VB6.FontChangeName(.VS.Font, "Arial")
			.VS.TableBorder = VSVIEW6.TableBorderSettings.tbAll
			.VS.PageBorder = VSVIEW6.TableBorderSettings.tbNone
			.VS.Orientation = VSVIEW6.OrientationSettings.orPortrait
			.VS.PhysicalPage = True
			.VS.PaperSize = VSVIEW6.PaperSizeSettings.pprA4
			.VS.MarginTop = "7mm"
			.VS.MarginRight = "7mm"
			.VS.MarginLeft = "7mm"
			.VS.MarginBottom = "5mm"
			.VS.TextColor = System.Drawing.Color.Black
			.VS.BrushStyle = VSVIEW6.BrushStyleSettings.bsSolid
			.VS.Font = VB6.FontChangeBold(.VS.Font, False)
			.VS.StartDoc()
			.VS.CurrentLine = 0
			.VS.Font = VB6.FontChangeSize(.VS.Font, 9)
			Call Cabecalho_Relatorio(.VS, "Relatório da qualidade do atendimento comercial", "Resolução Normativa ANEEL no. 414 - ANEXO III", "4",  , "Período: " & idteIni & " até " & idteFim)
			.VS.Font = VB6.FontChangeBold(.VS.Font, True)
			Call LineFeed(.VS, 2)
			.VS.TableBorder = VSVIEW6.TableBorderSettings.tbAll
			.VS.Font = VB6.FontChangeSize(.VS.Font, 8)
			lstrTab = ""
			lstrTab = lstrTab & istrTamCol
			lstrTab = lstrTab & "DESCRIÇÃO|"
			lstrTab = lstrTab & "Art.|"
			lstrTab = lstrTab & "Padrão|"
			lstrTab = lstrTab & "Qtde (I)|"
			lstrTab = lstrTab & "Prazo Médio (II)|"
			lstrTab = lstrTab & "Qtde > (III)|"
			lstrTab = lstrTab & "R$ (IV)|"
			.VS.Table = lstrTab
			.VS.Font = VB6.FontChangeBold(.VS.Font, False)
			.VS.Font = VB6.FontChangeSize(.VS.Font, 8)
		End With
		With Me.mfgAnexoIII
			For llngRow = 1 To .Rows - 1
				lstrTab = istrTamCol & .get_TextMatrix(llngRow, 0) & "|" & .get_TextMatrix(llngRow, 1) & "|" & .get_TextMatrix(llngRow, 2) & "|" & .get_TextMatrix(llngRow, 3) & "|" & .get_TextMatrix(llngRow, 4) & "|" & .get_TextMatrix(llngRow, 5) & "|" & .get_TextMatrix(llngRow, 6) & "|"
				ifrmRelAnexoII.VS.Table = lstrTab
			Next llngRow
		End With
		With ifrmRelAnexoII
			.VS.TableBorder = VSVIEW6.TableBorderSettings.tbNone
			Call LineFeed(.VS, 2)
			.VS.Table = "<0mm|<270mm|>0mm;|(I) Número de atendimento realizados no período de apuração."
			.VS.Table = "<0mm|<270mm|>0mm;|(II) Prazo médio de atendimento."
			.VS.Table = "<0mm|<270mm|>0mm;|(III) Número de atendimentos realizados acima dos prazos regulamentares."
			.VS.Table = "<0mm|<270mm|>0mm;|(IV) Valores creditados aos consumidores."
			Call .VS.EndDoc()
			Call VB6.ShowForm(ifrmRelAnexoII, False)
		End With
	End Sub
	
	Private Sub frmRelAnexoIII_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
		'UPGRADE_NOTE: Object ifrmRelAnexoII 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"'
		ifrmRelAnexoII = Nothing
	End Sub
	
	Private Sub mfgAnexoIII_DblClick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles mfgAnexoIII.DblClick
		Dim llngLin As Integer
		Dim llngCol As Integer
		Dim llngRow As Integer
		Call Me.fmeExplode.SetBounds(Me.cmdProcessar.Left, 0, 0, 0, Windows.Forms.BoundsSpecified.X)
		Me.fmeExplode.Visible = True
		Call LigDesBotoes(False)
		'Montar rotina pra transferir OS e RE para a mfgexplode
		'18,20,21,22,23 RE
		'1,2,3,4,5
		Me.mfgExplode.Rows = 1
		Me.mfgExplode.Cols = 22
		Call Me.mfgExplode.Clear()
		Me.mfgExplode.Redraw = False
		With Me.mfgAnexoIII
			llngLin = .RowSel
			Select Case llngLin
				Case Is = 1
					llngLin = 3
				Case Is = 2
					llngLin = 4
				Case Is = 20
					llngLin = 23
				Case Is = 21
					llngLin = 23
				Case Is = 22
					llngLin = 23
			End Select
			Me.lblExplode.Text = .get_TextMatrix(.RowSel, 0)
		End With
		If llngLin < 18 Then
			With Me.mfgSolServ
				For llngCol = 0 To .Cols - 1
					Me.mfgExplode.set_TextMatrix(0, llngCol, .get_TextMatrix(0, llngCol))
					Me.mfgExplode.set_ColWidth(llngCol, .get_ColWidth(llngCol))
				Next llngCol
				Me.mfgExplode.set_ColWidth(21, 0)
				If .Rows > 1 Then
					For llngRow = 1 To .Rows - 1
						If CDbl(.get_TextMatrix(llngRow, 20)) = llngLin Then
							Me.mfgExplode.Rows = Me.mfgExplode.Rows + 1
							For llngCol = 0 To .Cols - 1
								Me.mfgExplode.set_TextMatrix(Me.mfgExplode.Rows - 1, llngCol, .get_TextMatrix(llngRow, llngCol))
								Me.mfgExplode.FillStyle = MSFlexGridLib.FillStyleSettings.flexFillRepeat
								If llngCol = 19 Then
									If CDbl(IIf(IsNumeric(.get_TextMatrix(llngRow, llngCol)), .get_TextMatrix(llngRow, llngCol), 0)) <> 0 Then
										Me.mfgExplode.Row = Me.mfgExplode.Rows - 1
										Me.mfgExplode.Col = 0
										Me.mfgExplode.ColSel = .Cols - 1
										Me.mfgExplode.CellForeColor = System.Drawing.ColorTranslator.FromOle(&HFF) 'Vermelho
									Else
										Me.mfgExplode.Row = Me.mfgExplode.Rows - 1
										Me.mfgExplode.Col = 0
										Me.mfgExplode.ColSel = .Cols - 1
										Me.mfgExplode.CellForeColor = System.Drawing.ColorTranslator.FromOle(&H80000008) 'Normal
									End If
								End If
								Me.mfgExplode.FillStyle = MSFlexGridLib.FillStyleSettings.flexFillSingle
							Next llngCol
						End If
					Next llngRow
				End If
			End With
		Else
			With Me.mfgReclamacao
				For llngCol = 0 To .Cols - 1
					Me.mfgExplode.set_TextMatrix(0, llngCol, .get_TextMatrix(0, llngCol))
					Me.mfgExplode.set_ColWidth(llngCol, .get_ColWidth(llngCol))
				Next llngCol
				If .Rows > 1 Then
					For llngRow = 1 To .Rows - 1
						If CDbl(.get_TextMatrix(llngRow, 21)) = llngLin Then
							Me.mfgExplode.Rows = Me.mfgExplode.Rows + 1
							For llngCol = 0 To .Cols - 1
								Me.mfgExplode.set_TextMatrix(Me.mfgExplode.Rows - 1, llngCol, .get_TextMatrix(llngRow, llngCol))
								Me.mfgExplode.FillStyle = MSFlexGridLib.FillStyleSettings.flexFillRepeat
								If llngCol = 20 Then
									If CDbl(IIf(IsNumeric(.get_TextMatrix(llngRow, llngCol)), .get_TextMatrix(llngRow, llngCol), 0)) <> 0 Then
										Me.mfgExplode.Row = Me.mfgExplode.Rows - 1
										Me.mfgExplode.Col = 0
										Me.mfgExplode.ColSel = .Cols - 1
										Me.mfgExplode.CellForeColor = System.Drawing.ColorTranslator.FromOle(&HFF) 'Vermelho
									Else
										Me.mfgExplode.Row = Me.mfgExplode.Rows - 1
										Me.mfgExplode.Col = 0
										Me.mfgExplode.ColSel = .Cols - 1
										Me.mfgExplode.CellForeColor = System.Drawing.ColorTranslator.FromOle(&H80000008) 'Normal
									End If
								End If
								Me.mfgExplode.FillStyle = MSFlexGridLib.FillStyleSettings.flexFillSingle
							Next llngCol
						End If
					Next llngRow
				End If
			End With
		End If
		With Me.mfgExplode
			.Redraw = True
			If .Rows > 1 Then
				.Enabled = True
				.Col = 0
				.Row = 1
				Call .Focus()
			Else
				.Enabled = False
			End If
		End With
	End Sub
End Class