Option Strict Off
Option Explicit On
Imports fatd_faturamento.BLL.Repositorio
Imports fatd_faturamento.ENTIDADE
Imports CrystalDecisions.CrystalReports.Engine
Friend Class frmRelReclamacao
	Inherits System.Windows.Forms.Form

	'Private ifrmRelReclamacao As FrmRelatorio
	Private istrTamCol As String
	Private objAtualizaBancoDados As New entidadeAtualizaBancoDados
	Private repositorioAtualizaBancoDados As New repositorioAtualizaBancoDados

	Private objExecAtualizaBancoDados As New entidadeAtualizaBancoDados
	Private repositorioExecAtualizaBancoDados As New repositorioAtualizaBancoDados
	Private dt, dt1, dt2, dt3, dt4 As DataTable
	Private dtInterno As DataTable

	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 & "\Reclamacao_" & VB6.Format(BuscaDataBD, "YYYYMMDDHHNNSS") & "." & Me.dialArqOpen.DefaultExt
		Me.dialArqOpen.Title = "Arquivo de exportação do reclamações"
		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:\Reclamacao_" & VB6.Format(BuscaDataBD, "YYYYMMDDHHNNSS") & ".CSV", MsgBoxStyle.Critical, gstrTituloMensagem)
		Else
			Call LigDes(False)
			'Export para CSV
			If Trim(Me.txtArquivo.Text) <> "" Then
				lintARQ = FreeFile
				FileOpen(lintARQ, Me.txtArquivo.Text, OpenMode.Output)
				PrintLine(lintARQ, "Numero de Consumidores;" & VB6.Format(Me.txtNumCons.Text, "#,##0") & ";01/" & VB6.Format(Me.dtpMesAno.value, "MM/YYYY"))
				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
				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 LigDes(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 cmdImprimir_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdImprimir.Click
		Call Imprime()
	End Sub
	
	Private Sub frmRelReclamacao_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
		Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
		If KeyAscii = System.Windows.Forms.Keys.Escape Then
			Call cmdFechar_Click(cmdFechar, New System.EventArgs())
		ElseIf KeyAscii = System.Windows.Forms.Keys.Return Then
			'Call SendKeysA(System.Windows.Forms.Keys.Tab, True)
		End If
		eventArgs.KeyChar = Chr(KeyAscii)
		If KeyAscii = 0 Then
			eventArgs.Handled = True
		End If
	End Sub
	
	Private Sub frmRelReclamacao_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		'Call CenterForm(Me)
		Me.dtpMesAno.Value = Date.Now()
		'ifrmRelReclamacao = New FrmRelatorio
		Call MontaGrade()
	End Sub
	
	Private Sub cmdProcessar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdProcessar.Click
		Dim llngIdR As Integer
		Dim ldteCon As Date
		Dim ldteSol As Date
		Dim lblnPro As Boolean
		Dim lblnAdd As Boolean
		Dim lintSit As Short
		Dim llngQPr As Integer
		Dim llngQIm As Integer
		Dim ldblMed As Double
		Dim ldteFxIni As Date
		Dim ldteFxFim As Date
		Dim lstrTip As String
		Dim lstrNom As String
		Dim lstrZon As String
		Dim lstrLiv As String
		Dim lstrCon As String
		Dim lstrGru As String
		Dim llngSeq As Integer
		Dim lstrPro As String
		
		Dim lstrSql As String
		'Dim lrstAux As ADODB.Recordset
		'lrstAux = New ADODB.Recordset
		Call MontaGrade()
		If Not VerificaMesAnoFaturamento Then
			Call LigDes(False)
			Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
			Me.txtNumCons.Text = VB6.Format(BuscaQtdeUc, "#,##0")
			System.Windows.Forms.Application.DoEvents()
			ldteFxIni = CDate("01/" & VB6.Format(Me.dtpMesAno.value, "mm/yyyy") & " 00:00:00")
			ldteFxFim = CDate(UltimoDiaMes(Month(ldteFxIni), Year(ldteFxIni)) & "/" & VB6.Format(ldteFxIni, "mm/yyyy") & " 23:59:59")
			lstrSql = ""
			lstrSql = lstrSql & "    SELECT `reclamacao`.*, "
			lstrSql = lstrSql & "           `tipo_reclamacao`.`id` `codigo_servico`, "
			lstrSql = lstrSql & "           `tipo_reclamacao`.`nome` `tipo_atendimento`, "
			lstrSql = lstrSql & "           `uc_faturamento`.`nome`,  "
			lstrSql = lstrSql & "           `uc_faturamento`.`zona`, "
			lstrSql = lstrSql & "           `uc_faturamento`.`livro`, "
			lstrSql = lstrSql & "           `uc_faturamento`.`conta`  "
			lstrSql = lstrSql & "      FROM `reclamacao` "
			lstrSql = lstrSql & " LEFT JOIN `uc_faturamento` ON(`uc_faturamento`.`id` = `reclamacao`.`unid_id` AND `reclamacao`.`unid` in ('A','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 `avulsa` = 0 " & vbCrLf
			lstrSql = lstrSql & "       AND `resolvida` <> 2 " & vbCrLf
			lstrSql = lstrSql & "       AND ((`dt_conclusao` BETWEEN '" & VB6.Format(ldteFxIni, "yyyy-MM-dd") & "' AND '" & VB6.Format(ldteFxFim, "yyyy-MM-dd") & "') OR " & vbCrLf
			lstrSql = lstrSql & "            (`dt_solicitacao` BETWEEN '" & VB6.Format(ldteFxIni, "yyyy-MM-dd") & "' AND '" & VB6.Format(ldteFxFim, "yyyy-MM-dd") & "') "
			lstrSql = lstrSql & "           )"
			'Call Conectar(lstrSql, lrstAux)
			objAtualizaBancoDados.QUERY_NAME = lstrSql
			dt1 = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)

			If dt1.Rows.Count > 0 Then
				Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, dt1.Rows.Count)
				For Each row As DataRow In dt1.Rows

					Dim sHoraConclusao

					llngIdR = CInt(IIf(IsDBNull(row.Item("tipo_reclamacao")), "0", row.Item("tipo_reclamacao")))
					'Tipo =1, 2 e 3 não entra no DER e FER

					lblnPro = (IIf(IsDBNull(row.Item("procedente")), "N", row.Item("procedente")) = "S")
					ldteCon = CDate(IIf(IsDBNull(row.Item("dt_conclusao")), "1900-01-01", row.Item("dt_conclusao")))

					sHoraConclusao = CStr(Format(IIf(IsDBNull(row.Item("hr_conclusao")), "00:00:00", row.Item("hr_conclusao")), "HH:MM:SS"))

					ldteCon = CDate(ldteCon & " " & VB6.Format(IIf(IsDBNull(row.Item("hr_conclusao")), "00:00:00", row.Item("hr_conclusao")), "HH:NN:SS"))
					ldteSol = CDate(IIf(IsDBNull(row.Item("dt_solicitacao")), "1900-01-01", row.Item("dt_solicitacao")))
					ldteSol = CDate(ldteSol & " " & VB6.Format(IIf(IsDBNull(row.Item("hr_solicitacao")), "00:00:00", row.Item("hr_solicitacao")), "HH:NN:SS"))
					lintSit = CShort(IIf(IsDBNull(row.Item("resolvida")), "0", row.Item("resolvida"))) '0=aberta; 3=estornada; 1=finalizada; 2=cancelada
					'Dados para exportar
					lstrTip = Trim(IIf(IsDBNull(row.Item("tipo_atendimento")), "", row.Item("tipo_atendimento")))
					lstrNom = Trim(IIf(IsDBNull(row.Item("nome")), "", row.Item("nome")))
					lstrZon = Trim(IIf(IsDBNull(row.Item("zona")), "", row.Item("zona")))
					lstrLiv = Trim(IIf(IsDBNull(row.Item("livro")), "", row.Item("livro")))
					lstrCon = Trim(IIf(IsDBNull(row.Item("conta")), "", row.Item("conta")))
					lstrGru = Trim(IIf(IsDBNull(row.Item("unid")), "B", row.Item("unid")))
					'As recebidas dentro da faixa
					ldblMed = 0
					lblnAdd = False
					If ldteSol >= ldteFxIni And ldteSol <= ldteFxFim Then
						Call AdicionaGrade(llngIdR, 1, 0, 0, 0)
						lblnAdd = True
					End If
					'As concluidas dentro da faixa
					If ldteCon >= ldteFxIni And ldteCon <= ldteFxFim Then
						If lintSit = 1 Then
							'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"'
							ldblMed = Arredondar(DateDiff(Microsoft.VisualBasic.DateInterval.Second, ldteSol, ldteCon) / 3600, 2)
							If Me.chkEmDias.CheckState = System.Windows.Forms.CheckState.Checked Then ldblMed = Arredondar(ldblMed / 24, 2)
							'Call AdicionaGrade(llngIdR, 0, IIf(lblnPro, 1, 0), IIf(lblnPro, 0, 1), IIf(lblnPro, ldblMed, IIf(Me.chkSomenteImprocedentes.value = CheckBoxConstants.vbChecked, ldblMed, 0)))
							Call AdicionaGrade(llngIdR, 0, IIf(lblnPro, 1, 0), IIf(lblnPro, 0, 1), IIf(lblnPro, ldblMed, ldblMed))
							lblnAdd = True
						End If
					End If
					If lblnAdd Then
						'Dados para exportar
						With Me.mfgReclamacao
							.Rows = .Rows + 1
							.set_TextMatrix(.Rows - 1, 0, llngIdR)
							.set_TextMatrix(.Rows - 1, 1, lstrTip)
							.set_TextMatrix(.Rows - 1, 2, VB6.Format(ldblMed, "#,##0.00"))
							If ldteCon >= ldteFxIni And ldteCon <= ldteFxFim Then
								.set_TextMatrix(.Rows - 1, 3, IIf(lblnPro, "Sim", "Nao"))
							Else
								.set_TextMatrix(.Rows - 1, 3, "")
							End If
							.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, VB6.Format(ldteSol, "DD/MM/YYYY HH:NN:SS"))
							If ldteCon >= ldteFxIni And ldteCon <= ldteFxFim Then
								.set_TextMatrix(.Rows - 1, 12, VB6.Format(ldteCon, "DD/MM/YYYY HH:NN:SS"))
							Else
								.set_TextMatrix(.Rows - 1, 12, "")
							End If
						End With
					End If

					Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1)
				Next
			End If

			Call TotalizaGrade()

					''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 LigDes(True)
			Me.Cursor = System.Windows.Forms.Cursors.Default
		Else
			Call MsgBox("O mês e ano selecionado ainda não foram encerrados, impossibilitando retirar esse relatório!", MsgBoxStyle.Critical, gstrTituloMensagem)
		End If
	End Sub
	
	Private Sub TotalizaGrade()
		Dim llngAux As Integer
		With Me.mfgDados
			For llngAux = 1 To .Rows - 2
				.set_TextMatrix(.Rows - 1, 2, VB6.Format(CShort(IIf(IsNumeric(.get_TextMatrix(.Rows - 1, 2)), .get_TextMatrix(.Rows - 1, 2), 0)) + CShort(IIf(IsNumeric(.get_TextMatrix(llngAux, 2)), .get_TextMatrix(llngAux, 2), 0)), "#,##0"))
				.set_TextMatrix(.Rows - 1, 3, VB6.Format(CShort(IIf(IsNumeric(.get_TextMatrix(.Rows - 1, 3)), .get_TextMatrix(.Rows - 1, 3), 0)) + CShort(IIf(IsNumeric(.get_TextMatrix(llngAux, 3)), .get_TextMatrix(llngAux, 3), 0)), "#,##0"))
				.set_TextMatrix(.Rows - 1, 4, VB6.Format(CShort(IIf(IsNumeric(.get_TextMatrix(.Rows - 1, 4)), .get_TextMatrix(.Rows - 1, 4), 0)) + CShort(IIf(IsNumeric(.get_TextMatrix(llngAux, 4)), .get_TextMatrix(llngAux, 4), 0)), "#,##0"))
				.set_TextMatrix(.Rows - 1, 5, VB6.Format(CDbl(IIf(IsNumeric(.get_TextMatrix(.Rows - 1, 5)), .get_TextMatrix(.Rows - 1, 5), 0)) + CDbl(IIf(IsNumeric(.get_TextMatrix(llngAux, 5)), .get_TextMatrix(llngAux, 5), 0)), "#,##0.00"))
				.set_TextMatrix(.Rows - 1, 6, VB6.Format(CDbl(IIf(IsNumeric(.get_TextMatrix(.Rows - 1, 6)), .get_TextMatrix(.Rows - 1, 6), 0)) + CDbl(IIf(IsNumeric(.get_TextMatrix(llngAux, 6)), .get_TextMatrix(llngAux, 6), 0)), "#,##0.00"))
				.set_TextMatrix(.Rows - 1, 7, VB6.Format(CDbl(IIf(IsNumeric(.get_TextMatrix(.Rows - 1, 7)), .get_TextMatrix(.Rows - 1, 7), 0)) + CDbl(IIf(IsNumeric(.get_TextMatrix(llngAux, 7)), .get_TextMatrix(llngAux, 7), 0)), "#,##0.00"))
				.set_TextMatrix(.Rows - 1, 8, VB6.Format(CDbl(IIf(IsNumeric(.get_TextMatrix(.Rows - 1, 8)), .get_TextMatrix(.Rows - 1, 8), 0)) + CDbl(IIf(IsNumeric(.get_TextMatrix(llngAux, 8)), .get_TextMatrix(llngAux, 8), 0)), "#,##0.00"))
			Next llngAux
		End With
	End Sub
	
	Private Sub AdicionaGrade(ByVal aintTipoReclamacao As Short, ByVal alngQRec As Integer, ByVal alngQPro As Integer, ByVal alngQImp As Integer, ByVal adblMedia As Double)
		Dim llngAux As Integer
		Dim llngRow As Integer
		llngRow = 0
		With Me.mfgDados
			For llngAux = 1 To .Rows - 1
				'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
				If CShort(IIf(IsNumeric(.get_TextMatrix(llngAux, 0)), .get_TextMatrix(llngAux, 0), 0)) = aintTipoReclamacao Then
					llngRow = llngAux
					llngAux = .Rows - 1
				End If
			Next llngAux
			If llngRow = 0 Then llngRow = .Rows - 2 'Indefinido (se não achou nenhum código de reclamação
			'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			.set_TextMatrix(llngRow, 2, VB6.Format(CShort(IIf(IsNumeric(.get_TextMatrix(llngRow, 2)), .get_TextMatrix(llngRow, 2), 0)) + alngQRec, "#,##0"))
			'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			.set_TextMatrix(llngRow, 3, VB6.Format(CShort(IIf(IsNumeric(.get_TextMatrix(llngRow, 3)), .get_TextMatrix(llngRow, 3), 0)) + alngQPro, "#,##0"))
			'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			.set_TextMatrix(llngRow, 4, VB6.Format(CShort(IIf(IsNumeric(.get_TextMatrix(llngRow, 4)), .get_TextMatrix(llngRow, 4), 0)) + alngQImp, "#,##0"))
			'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			.set_TextMatrix(llngRow, 5, VB6.Format(CDbl(IIf(IsNumeric(.get_TextMatrix(llngRow, 5)), .get_TextMatrix(llngRow, 5), 0)) + adblMedia, "#,##0.00"))
			'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			If CShort(IIf(IsNumeric(.get_TextMatrix(llngRow, 3)), .get_TextMatrix(llngRow, 3), 0)) > 0 Then
				'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
				.set_TextMatrix(llngRow, 6, VB6.Format(Arredondar(CDbl(IIf(IsNumeric(.get_TextMatrix(llngRow, 5)), .get_TextMatrix(llngRow, 5), 0)) / (CShort(IIf(IsNumeric(.get_TextMatrix(llngRow, 3)), .get_TextMatrix(llngRow, 3), 0)) + CShort(IIf(IsNumeric(.get_TextMatrix(llngRow, 4)), .get_TextMatrix(llngRow, 4), 0))), 2), "#,##0.00"))
			ElseIf Me.chkSomenteImprocedentes.CheckState = System.Windows.Forms.CheckState.Checked Then 
				'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
				If CShort(IIf(IsNumeric(.get_TextMatrix(llngRow, 4)), .get_TextMatrix(llngRow, 4), 0)) > 0 Then
					'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
					.set_TextMatrix(llngRow, 6, VB6.Format(Arredondar(CDbl(IIf(IsNumeric(.get_TextMatrix(llngRow, 5)), .get_TextMatrix(llngRow, 5), 0)) / (CShort(IIf(IsNumeric(.get_TextMatrix(llngRow, 3)), .get_TextMatrix(llngRow, 3), 0)) + CShort(IIf(IsNumeric(.get_TextMatrix(llngRow, 4)), .get_TextMatrix(llngRow, 4), 0))), 2), "#,##0.00"))
				End If
			End If
			If aintTipoReclamacao > 3 Then
				'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
				If CShort(IIf(IsNumeric(.get_TextMatrix(llngRow, 3)), .get_TextMatrix(llngRow, 3), 0)) > 0 Then
					'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
					.set_TextMatrix(llngRow, 7, VB6.Format((CShort(IIf(IsNumeric(.get_TextMatrix(llngRow, 3)), .get_TextMatrix(llngRow, 3), 0)) * CDbl(IIf(IsNumeric(.get_TextMatrix(llngRow, 6)), .get_TextMatrix(llngRow, 6), 0))) / CShort(IIf(IsNumeric(.get_TextMatrix(llngRow, 3)), .get_TextMatrix(llngRow, 3), 0)), "#,##0.00"))
					'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
					.set_TextMatrix(llngRow, 8, VB6.Format(Arredondar((CShort(IIf(IsNumeric(.get_TextMatrix(llngRow, 3)), .get_TextMatrix(llngRow, 3), 0)) / CInt(IIf(IsNumeric(Me.txtNumCons.Text), Me.txtNumCons.Text, 0))) * 1000, 2), "#,##0.00"))
				ElseIf Me.chkSomenteImprocedentes.CheckState = System.Windows.Forms.CheckState.Checked Then 
					'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
					If CShort(IIf(IsNumeric(.get_TextMatrix(llngRow, 4)), .get_TextMatrix(llngRow, 4), 0)) > 0 Then
						'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
						.set_TextMatrix(llngRow, 7, VB6.Format((CShort(IIf(IsNumeric(.get_TextMatrix(llngRow, 4)), .get_TextMatrix(llngRow, 4), 0)) * CDbl(IIf(IsNumeric(.get_TextMatrix(llngRow, 6)), .get_TextMatrix(llngRow, 6), 0))) / CShort(IIf(IsNumeric(.get_TextMatrix(llngRow, 4)), .get_TextMatrix(llngRow, 4), 0)), "#,##0.00"))
						'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
						.set_TextMatrix(llngRow, 8, VB6.Format(Arredondar((CShort(IIf(IsNumeric(.get_TextMatrix(llngRow, 4)), .get_TextMatrix(llngRow, 4), 0)) / CInt(IIf(IsNumeric(Me.txtNumCons.Text), Me.txtNumCons.Text, 0))) * 1000, 2), "#,##0.00"))
					End If
				End If
				
			End If
		End With
	End Sub
	
	Private Sub Imprime()
		Dim lstrTab As String
		Dim llngRow As Integer
		Dim ldteFxIni As Date
		Dim ldteFxFim As Date
		ldteFxIni = CDate("01/" & VB6.Format(Me.dtpMesAno.value, "mm/yyyy"))
		ldteFxFim = CDate(UltimoDiaMes(Month(ldteFxIni), Year(ldteFxIni)) & "/" & VB6.Format(ldteFxIni, "mm/yyyy"))
		istrTamCol = "<0mm|^80mm|^50mm|^50mm|^50mm|^50mm|>0mm;|"
		'With ifrmRelReclamacao
		'	.quem_chama = Me
		'	.VS.Font = VB6.FontChangeName(.VS.Font, "Arial")
		'	.VS.TableBorder = VSVIEW6.TableBorderSettings.tbAll
		'	.VS.PageBorder = VSVIEW6.TableBorderSettings.tbNone
		'	.VS.Orientation = VSVIEW6.OrientationSettings.orLandscape
		'	.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 de Reclamações", "Período: " & ldteFxIni & " até " & ldteFxFim, "3")
		'	.VS.Font = VB6.FontChangeBold(.VS.Font, True)
		'	Call LineFeed(.VS, 2)
		'	.VS.TableBorder = VSVIEW6.TableBorderSettings.tbAll
		'	lstrTab = ""
		'	lstrTab = lstrTab & istrTamCol
		'	lstrTab = lstrTab & "RECLAMAÇÃO|"
		'	lstrTab = lstrTab & "QTDE RECLAMAÇÕES RECEBIDAS|"
		'	lstrTab = lstrTab & "QTDE RECLAMAÇÕES PROCEDENTES|"
		'	lstrTab = lstrTab & "PRAZO MÉDIO DE SOLUÇÕES DAS RECLAMAÇÕES PROCEDENTES|"
		'	lstrTab = lstrTab & "QTDE RECLAMAÇÕES IMPROCEDENTES"
		'	.VS.Table = lstrTab
		'	.VS.Font = VB6.FontChangeBold(.VS.Font, False)
		'End With
		'With Me.mfgDados
		'	For llngRow = 1 To .Rows - 1
		'		lstrTab = "<0mm|^80mm|^50mm|^50mm|^50mm|^50mm|>0mm;|" & .get_TextMatrix(llngRow, 1) & "|" & .get_TextMatrix(llngRow, 2) & "|" & .get_TextMatrix(llngRow, 3) & "|" & .get_TextMatrix(llngRow, 6) & "|" & .get_TextMatrix(llngRow, 4)
		'		ifrmRelReclamacao.VS.Table = lstrTab
		'	Next llngRow
		'End With
		'With ifrmRelReclamacao
		'	.VS.TableBorder = VSVIEW6.TableBorderSettings.tbNone
		'	Call LineFeed(.VS, 2)
		'	.VS.Table = "<0mm|<270mm|>0mm;|" & Me.lblAux(2).Text & " "
		'	Call LineFeed(.VS, 2)
		'	.VS.Table = "<0mm|<80mm|^80mm|^80mm|>0mm;|" & Me.lblAux(1).Text & " " & Me.txtNumCons.Text & "|DER = " & Me.mfgDados.get_TextMatrix(Me.mfgDados.Rows - 1, 7) & "|FER = " & Me.mfgDados.get_TextMatrix(Me.mfgDados.Rows - 1, 8)
		'	Call .VS.EndDoc()
		'	Call VB6.ShowForm(ifrmRelReclamacao, False)
		'End With
	End Sub
	
	Private Sub MontaGrade()
		Dim llngId As Integer
		Dim lstrNome As String
		Dim lstrSql As String
		'Dim lrstAux As ADODB.Recordset
		'lrstAux = New ADODB.Recordset
		With Me.mfgReclamacao
			.Redraw = False
			Call .Clear()
			.Rows = 1
			.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")
			.Redraw = True
		End With
		
		With Me.mfgDados
			.Redraw = False
			Call .Clear()
			.Rows = 1
			.set_TextMatrix(0, 0, "Código")
			.set_TextMatrix(0, 1, "Descrição")
			.set_TextMatrix(0, 2, "Recebidas")
			.set_TextMatrix(0, 3, "Procedentes")
			.set_TextMatrix(0, 4, "Improcedentes")
			.set_TextMatrix(0, 5, "Prazo Proced.")
			.set_TextMatrix(0, 6, "Média Proced.")
			.set_TextMatrix(0, 7, "DER")
			.set_TextMatrix(0, 8, "FER")
			.set_ColWidth(0, 800)
			.set_ColWidth(1, 4150)
			.set_ColWidth(2, 1345)
			.set_ColWidth(3, 1345)
			.set_ColWidth(4, 1345)
			.set_ColWidth(5, 1345)
			.set_ColWidth(6, 1345)
			.set_ColWidth(7, 1345)
			.set_ColWidth(8, 1345)
		End With
		lstrSql = "SELECT * FROM `tipo_reclamacao` "
		objAtualizaBancoDados.QUERY_NAME = lstrSql
		dt = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)
		'Call Conectar(lstrSql, lrstAux)


		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")))
				lstrNome = Trim(IIf(IsDBNull(row.Item("nome")), "em branco", row.Item("nome")))
				With Me.mfgDados
					.Rows = .Rows + 1
					.set_TextMatrix(.Rows - 1, 0, llngId)
					.set_TextMatrix(.Rows - 1, 1, lstrNome)
				End With
			Next
			With Me.mfgDados
				.Rows = .Rows + 1
				.set_TextMatrix(.Rows - 1, 0, "")
				.set_TextMatrix(.Rows - 1, 1, "Indefinido")
				.Rows = .Rows + 1
				.set_TextMatrix(.Rows - 1, 0, "")
				.set_TextMatrix(.Rows - 1, 1, "Total")
			End With
		End If

		Me.mfgDados.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
		System.Windows.Forms.Application.DoEvents()
	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 Function VerificaMesAnoFaturamento() As Boolean
		Dim lblnRet As Boolean
		Dim lstrMes As String
		lstrMes = GetConfig("mes.ano.faturamento")
		lblnRet = False
		If VB6.Format(Me.dtpMesAno.value, "mm/yyyy") = lstrMes Then
			lblnRet = True
		End If
		VerificaMesAnoFaturamento = lblnRet
	End Function
	
	Private Function BuscaQtdeUc() As Integer
		Dim llngRet As Integer
		Dim lstrSql As String
		'Dim lrstAux As ADODB.Recordset
		'lrstAux = New ADODB.Recordset
		Me.lblInfo.Text = " Buscando quantidade de consumidores faturados no mês selecionado. Aguarde..."
		Call Me.lblInfo.Refresh()
		System.Windows.Forms.Application.DoEvents()
		lstrSql = ""
		lstrSql = lstrSql & "SELECT * "
		lstrSql = lstrSql & "  FROM `nf` "
		lstrSql = lstrSql & " WHERE `mesano_ref` = " & CInt(VB6.Format(Me.dtpMesAno.Value, "yyyymm"))
		objAtualizaBancoDados.QUERY_NAME = lstrSql
		dtInterno = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)

		llngRet = dtInterno.Rows.Count

		BuscaQtdeUc = llngRet
	End Function
	
	Private Sub LigDes(ByVal ablnModo As Boolean)
		Me.dtpMesAno.Enabled = ablnModo
		Me.mfgDados.Enabled = ablnModo
		Me.mfgReclamacao.Enabled = ablnModo
		Me.cmdProcessar.Enabled = ablnModo
		Me.cmdImprimir.Enabled = ablnModo
		Me.cmdFechar.Enabled = ablnModo
		Me.cmdExporta.Enabled = ablnModo
		Me.mfgDados.Redraw = Me.mfgDados.Enabled
		Me.mfgReclamacao.Redraw = Me.mfgReclamacao.Enabled
	End Sub
End Class