Option Strict Off
Option Explicit On
Friend Class frmAtualizaLeituras
	Inherits System.Windows.Forms.Form
	Private ifrmQuemChama As System.Windows.Forms.Form
	Private iblnMontaGrade As Boolean
	
	Private Sub cmdFechar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdFechar.Click
		Call Me.Close()
	End Sub
	
	Private Sub cmdLocalizar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdLocalizar.Click
		Dim lintRow As Short
		Dim lintCol As Short
		Dim ldblId As Double
		Dim llngUnid_id As Integer
		Dim llngCons_id As Integer
		Dim lstrGrupo As String
		Dim lstrZona As String
		Dim lstrLivro As String
		Dim lstrConta As String
		Dim lstrSituacao As String
		Dim lstrCaderno_leit_atual As String
		Dim lstrCaderno_leit_anterior As String
		Dim ldblUltleit As Double
		Dim ldblUltleit_desligamento As Double
		Dim ldblLeitura_lc As Double
		Dim ldblUltiLei_lc As Double
		Dim ldblResiduo As Double
		Dim ldblSequencia_os As Double
		Dim ldblProtocolo As Double
		Dim llngProtocolo_sub As Integer
		Dim lstrId_class_comercial As String
		Dim lstrDescr_class_comercial As String
		Dim ldteMovimento As Date
		Dim ldteAtualizacao As Date
		Dim lblnAtualizado As Boolean
		Dim lblnUsa_desligamento As Boolean
		Dim lblnAtualiza_uc As Boolean
		Dim lblnAtualiza_caderno_lat As Boolean
		Dim lblnAtualiza_caderno_lan As Boolean
		'
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		Call MontaGrade()
		Me.mfgDados.Redraw = False
		lstrSql = "SELECT * "
		lstrSql = lstrSql & "  FROM " & gstrDataBase & ".`leituras_unidb_lc` "
		If Me.opbNaoAtualizados.Checked Then
			lstrSql = lstrSql & " WHERE atualizado = 0 "
		ElseIf Me.opbAtualizados.Checked Then 
			lstrSql = lstrSql & " WHERE atualizado = 1 "
		End If
		My.Computer.Clipboard.Clear()
		My.Computer.Clipboard.SetText(lstrSql)
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				If .RecordCount > 0 Then
					Me.mfgDados.Rows = Me.mfgDados.Rows - 1
					Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, .RecordCount)
					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"'
						ldblId = IIf(IsDbNull(.Fields("id").value), 0, .Fields("id").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						llngUnid_id = IIf(IsDbNull(.Fields("unid_id").value), 0, .Fields("unid_id").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						llngCons_id = 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"'
						lstrGrupo = IIf(IsDbNull(.Fields("grupo").value), "", .Fields("grupo").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrZona = 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"'
						lstrLivro = 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"'
						lstrConta = 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"'
						lstrSituacao = IIf(IsDbNull(.Fields("situacao").value), "L", .Fields("situacao").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrCaderno_leit_atual = IIf(IsDbNull(.Fields("caderno_leit_atual").value), "", .Fields("caderno_leit_atual").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"'
						lstrCaderno_leit_anterior = IIf(IsDbNull(.Fields("caderno_leit_anterior").value), "", .Fields("caderno_leit_anterior").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"'
						ldblUltleit = IIf(IsDbNull(.Fields("ultleit").value), 0, .Fields("ultleit").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"'
						ldblUltleit_desligamento = IIf(IsDbNull(.Fields("ultleit_desligamento").value), 0, .Fields("ultleit_desligamento").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"'
						ldblLeitura_lc = IIf(IsDbNull(.Fields("leitura_lc").value), 0, .Fields("leitura_lc").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"'
						ldblUltiLei_lc = IIf(IsDbNull(.Fields("ultimaleit_lc").value), 0, .Fields("ultimaleit_lc").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"'
						ldblResiduo = IIf(IsDbNull(.Fields("residuo").value), 0, .Fields("residuo").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"'
						ldblSequencia_os = IIf(IsDbNull(.Fields("sequencia_os").value), 0, .Fields("sequencia_os").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"'
						ldblProtocolo = IIf(IsDbNull(.Fields("protocolo").value), 0, .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"'
						llngProtocolo_sub = IIf(IsDbNull(.Fields("protocolo_sub").value), 0, .Fields("protocolo_sub").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrId_class_comercial = IIf(IsDbNull(.Fields("id_class_comercial").value), "", .Fields("id_class_comercial").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrDescr_class_comercial = IIf(IsDbNull(.Fields("descr_class_comercial").value), "", .Fields("descr_class_comercial").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"'
						ldteMovimento = IIf(IsDbNull(.Fields("movimento").value), "1900-01-01 00:00:00", .Fields("movimento").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"'
						ldteAtualizacao = IIf(IsDbNull(.Fields("atualizacao").value), "1900-01-01 00:00:00", .Fields("atualizacao").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"'
						lblnAtualizado = IIf(IsDbNull(.Fields("atualizado").value), 0, .Fields("atualizado").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"'
						lblnUsa_desligamento = IIf(IsDbNull(.Fields("usa_desligamento").value), 0, .Fields("usa_desligamento").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"'
						lblnAtualiza_uc = IIf(IsDbNull(.Fields("atualiza_uc").value), 0, .Fields("atualiza_uc").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"'
						lblnAtualiza_caderno_lat = IIf(IsDbNull(.Fields("atualiza_caderno_lat").value), 0, .Fields("atualiza_caderno_lat").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"'
						lblnAtualiza_caderno_lan = IIf(IsDbNull(.Fields("atualiza_caderno_lan").value), 0, .Fields("atualiza_caderno_lan").value)
						Select Case lstrSituacao
							Case Is = "L"
								lstrSituacao = "LIGADO"
							Case Is = "D"
								lstrSituacao = "DESLIGADO"
							Case Is = "I"
								lstrSituacao = "DESATIVADO"
							Case Is = "C"
								lstrSituacao = "SUSPENDIDO"
							Case Is = "N"
								lstrSituacao = "N.LIG."
						End Select
						With Me.mfgDados
							.Rows = .Rows + 1
							.set_TextMatrix(.Rows - 1, 0, lstrZona & "." & lstrLivro & "." & lstrConta)
							.set_TextMatrix(.Rows - 1, 1, lstrSituacao)
							.set_TextMatrix(.Rows - 1, 2, lstrCaderno_leit_atual)
							.set_TextMatrix(.Rows - 1, 3, lstrCaderno_leit_anterior)
							.set_TextMatrix(.Rows - 1, 4, ldblUltleit)
							.set_TextMatrix(.Rows - 1, 5, ldblUltleit_desligamento)
							.set_TextMatrix(.Rows - 1, 6, ldblLeitura_lc)
							.set_TextMatrix(.Rows - 1, 7, ldblUltiLei_lc)
							.set_TextMatrix(.Rows - 1, 8, ldblResiduo)
							.set_TextMatrix(.Rows - 1, 9, IIf(lblnUsa_desligamento, "X", ""))
							.set_TextMatrix(.Rows - 1, 10, IIf(lblnAtualiza_uc, "X", ""))
							.set_TextMatrix(.Rows - 1, 11, IIf(lblnAtualiza_caderno_lat, "X", ""))
							.set_TextMatrix(.Rows - 1, 12, IIf(lblnAtualiza_caderno_lan, "X", ""))
							.set_TextMatrix(.Rows - 1, 13, ldblProtocolo & "-" & llngProtocolo_sub & "/" & ldblSequencia_os)
							.set_TextMatrix(.Rows - 1, 14, lstrId_class_comercial & " - " & lstrDescr_class_comercial)
							.set_TextMatrix(.Rows - 1, 15, VB6.Format(ldteMovimento, "dd/MM/yyyy hh:mm:ss"))
							.set_TextMatrix(.Rows - 1, 16, VB6.Format(ldteAtualizacao, "dd/MM/yyyy hh:mm:ss"))
							.set_TextMatrix(.Rows - 1, 17, ldblId)
							.set_TextMatrix(.Rows - 1, 18, llngUnid_id)
							.set_TextMatrix(.Rows - 1, 19, llngCons_id)
							.set_TextMatrix(.Rows - 1, 20, lstrGrupo)
							.set_TextMatrix(.Rows - 1, 21, IIf(lblnAtualizado, "1", "0"))
						End With
						Call .MoveNext()
						Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1)
					End While
					With Me.mfgDados
						
						For lintRow = 5 To .Rows - 1
							For lintCol = 9 To 21
								.Col = lintCol
								.Row = lintRow
								.MergeCells = MSFlexGridLib.MergeCellsSettings.flexMergeRestrictRows
								'.MergeCol(lintCol) = False
								'.MergeRow(lintRow) = False
								
								'.CellAlignment = MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter
							Next lintCol
						Next lintRow
					End With
				Else
					Call MsgBox("Não foi encontrado nenhum registro, tente outros filtros!", MsgBoxStyle.Exclamation, gstrTituloMensagem)
				End If
				Call .Close()
			End If
		End With
		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
	End Sub
	
	Private Sub cmdSalvar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdSalvar.Click
		Dim ldblReg As Double
		Dim llngRow As Integer
		Dim lblnAux As Boolean
		Dim ldblId As Double
		Dim llngUnid_id As Integer
		Dim llngCons_id As Integer
		Dim ldblLeitura_lc As Double
		Dim ldblUltiLei_lc As Double
		Dim ldblResiduo As Double
		Dim lblnAtualizado As Boolean
		Dim lblnUsa_desligamento As Boolean
		Dim lblnAtualiza_uc As Boolean
		Dim lblnAtualiza_caderno_lat As Boolean
		Dim lblnAtualiza_caderno_lan As Boolean
		
		Dim lstrSql As String
		lblnAux = False
		On Error GoTo ErroSalvar
		Call myConC.Execute("START TRANSACTION")
		With Me.mfgDados
			For llngRow = 4 To .Rows - 1
				lblnAux = False
				If .get_TextMatrix(llngRow, 17) <> "" Then
					ldblId = CDbl(.get_TextMatrix(llngRow, 17))
					llngUnid_id = CInt(.get_TextMatrix(llngRow, 18))
					llngCons_id = CInt(.get_TextMatrix(llngRow, 19))
					ldblLeitura_lc = CDbl(.get_TextMatrix(llngRow, 6))
					ldblUltiLei_lc = CDbl(.get_TextMatrix(llngRow, 7))
					ldblResiduo = CDbl(.get_TextMatrix(llngRow, 8))
					lblnUsa_desligamento = IIf(.get_TextMatrix(llngRow, 9) = "X", True, False)
					lblnAtualiza_uc = IIf(.get_TextMatrix(llngRow, 10) = "X", True, False)
					lblnAtualiza_caderno_lat = IIf(.get_TextMatrix(llngRow, 11) = "X", True, False)
					lblnAtualiza_caderno_lan = IIf(.get_TextMatrix(llngRow, 12) = "X", True, False)
					lblnAtualizado = IIf(.get_TextMatrix(llngRow, 21) = "1", True, False)
					'
					If lblnUsa_desligamento Or lblnAtualiza_uc Then
						lstrSql = "UPDATE " & gstrDataBase & ".`unidb` SET "
						If lblnUsa_desligamento Then
							lstrSql = lstrSql & "`ultleit_desligamento` = " & Replace(CStr(ldblLeitura_lc), ",", ".") & " "
						ElseIf lblnAtualiza_uc Then 
							lstrSql = lstrSql & "`ultleit` = " & Replace(CStr(ldblLeitura_lc), ",", ".") & " "
						End If
						If ldblResiduo > 0 Then
							lstrSql = lstrSql & ", `residuo_consumo` = " & Replace(CStr(ldblResiduo), ",", ".") & " "
						End If
						lstrSql = lstrSql & " WHERE `unid_id` = " & llngUnid_id & " "
						lstrSql = lstrSql & "   AND `cons_id` = " & llngCons_id & " "
						Call myConC.Execute(lstrSql)
						lblnAux = True
					End If
					'
					If lblnAtualiza_caderno_lan Or lblnAtualiza_caderno_lat Then
						lstrSql = "UPDATE " & gstrDataBase & ".`leitmensal` SET "
						If lblnAtualiza_caderno_lan Then
							lstrSql = lstrSql & "`leit_ant` = " & Replace(CStr(ldblLeitura_lc), ",", ".") & " "
						ElseIf lblnAtualiza_caderno_lat Then 
							lstrSql = lstrSql & "`leit_atual` = " & Replace(CStr(ldblLeitura_lc), ",", ".") & " "
						End If
						lstrSql = lstrSql & " WHERE `unid_id` = " & llngUnid_id & " "
						lstrSql = lstrSql & "   AND `cons_id` = " & llngCons_id & " "
						Call myConC.Execute(lstrSql)
						lblnAux = True
					End If
					'
					If lblnAux Then
						lstrSql = "UPDATE " & gstrDataBase & ".`leituras_unidb_lc` SET "
						lstrSql = lstrSql & "`atualizacao` = CONVERT(DATE_FORMAT(localtime(),'%Y-%m-%d %T') USING Latin1), "
						lstrSql = lstrSql & "`atualizado` = 1, "
						lstrSql = lstrSql & "`usa_desligamento` = " & IIf(lblnUsa_desligamento, 1, 0) & ", "
						lstrSql = lstrSql & "`atualiza_uc` = " & IIf(lblnAtualiza_uc, 1, 0) & ", "
						lstrSql = lstrSql & "`atualiza_caderno_lat` = " & IIf(lblnAtualiza_caderno_lat, 1, 0) & ", "
						lstrSql = lstrSql & "`atualiza_caderno_lan` = " & IIf(lblnAtualiza_caderno_lan, 1, 0) & " "
						lstrSql = lstrSql & " WHERE `id` = " & ldblId & " "
						Call myConC.Execute(lstrSql)
					End If
				End If
			Next llngRow
		End With
		Call myConC.Execute("COMMIT", ldblReg)
		'If ldblReg > 0 Then
		Call MsgBox("Registro(s) gravado(s) com sucesso.", MsgBoxStyle.Information, gstrTituloMensagem)
		'End If
ErroSalvar: 
		If myConC.Errors.Count > 0 Then
			Call myConC.Execute("ROLLBACK")
			Call MsgBox("Código: " & myConC.Errors.Item(myConC.Errors.Count - 1).NativeError & vbCrLf & "Descrição:" & myConC.Errors.Item(myConC.Errors.Count - 1).Description, MsgBoxStyle.Exclamation, gstrTituloMensagem)
		ElseIf Err.Number > 0 Then 
			Call myConC.Execute("ROLLBACK")
			Call MsgBox(Err.Number & " - " & Err.Description, MsgBoxStyle.Critical, gstrTituloMensagem)
		End If
	End Sub
	
	Private Sub dtpIni_Change(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles dtpIni.Change
		Me.dtpFim.value = UltimoDiaMes((Me.dtpIni.Month), (dtpIni.Year)) & "/" & Me.dtpIni.Month & "/" & Me.dtpIni.Year
	End Sub
	
	Private Sub frmAtualizaLeituras_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 frmAtualizaLeituras_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		Dim ldteBase As Date
		ldteBase = BuscaDataBD
		Me.dtpIni.value = CDate("01/" & VB6.Format(ldteBase, "MM/yyyy"))
		Me.dtpFim.value = CDate(UltimoDiaMes((Me.dtpIni.Month), (Me.dtpIni.Year)) & "/" & VB6.Format(ldteBase, "MM/yyyy"))
		'  If Not ifrmQuemChama Is Nothing Then
		'    Call CenterFormQuemChama(Me, ifrmQuemChama)
		'  Else
		Call CenterForm(Me)
		'  End If
		Call MontaGrade()
	End Sub
	
	Private Sub frmAtualizaLeituras_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
		If Not ifrmQuemChama Is Nothing Then
			ifrmQuemChama.Enabled = True
		End If
	End Sub
	
	Private Sub MontaGrade()
		'
		Dim lintRow As Short
		Dim lintCol As Short
		iblnMontaGrade = False
		With Me.mfgDados
			Call .Clear()
			.Redraw = False
			.Rows = 5
			.Cols = 22
			.FixedRows = 4
			.FixedCols = 9
			.MergeCells = MSFlexGridLib.MergeCellsSettings.flexMergeRestrictColumns
			.set_TextMatrix(0, 0, "Identificador") 'zona.livro.conta
			.set_TextMatrix(1, 0, .get_TextMatrix(0, 0))
			.set_TextMatrix(2, 0, .get_TextMatrix(0, 0))
			.set_TextMatrix(3, 0, .get_TextMatrix(0, 0))
			.set_TextMatrix(0, 1, "Situação")
			.set_TextMatrix(1, 1, .get_TextMatrix(0, 1))
			.set_TextMatrix(2, 1, .get_TextMatrix(0, 1))
			.set_TextMatrix(3, 1, .get_TextMatrix(0, 1))
			'
			.set_TextMatrix(0, 2, "Leitura")
			.set_TextMatrix(0, 3, .get_TextMatrix(0, 2))
			.set_TextMatrix(0, 4, .get_TextMatrix(0, 2))
			.set_TextMatrix(0, 5, .get_TextMatrix(0, 2))
			.set_TextMatrix(0, 6, .get_TextMatrix(0, 2))
			.set_TextMatrix(0, 7, .get_TextMatrix(0, 2))
			.set_TextMatrix(0, 8, .get_TextMatrix(0, 2))
			'
			.set_TextMatrix(1, 2, "Caderno")
			.set_TextMatrix(1, 3, .get_TextMatrix(1, 2))
			.set_TextMatrix(2, 2, "Atual")
			.set_TextMatrix(3, 2, .get_TextMatrix(2, 2))
			.set_TextMatrix(2, 3, "Anterior")
			.set_TextMatrix(3, 3, .get_TextMatrix(2, 3))
			'
			.set_TextMatrix(1, 4, "Unidade Consumidora")
			.set_TextMatrix(1, 5, .get_TextMatrix(1, 4))
			.set_TextMatrix(2, 4, "Última")
			.set_TextMatrix(3, 4, .get_TextMatrix(2, 4))
			.set_TextMatrix(2, 5, "Desligado")
			.set_TextMatrix(3, 5, .get_TextMatrix(2, 5))
			'
			.set_TextMatrix(1, 6, "Link Center")
			.set_TextMatrix(1, 7, "Link Center")
			.set_TextMatrix(2, 6, "Leitura")
			.set_TextMatrix(3, 6, .get_TextMatrix(2, 6))
			.set_TextMatrix(2, 7, "Retirado")
			.set_TextMatrix(3, 7, .get_TextMatrix(2, 7))
			.set_TextMatrix(1, 8, "kWh")
			.set_TextMatrix(2, 8, "Residuo")
			.set_TextMatrix(3, 8, .get_TextMatrix(2, 8))
			'
			.set_TextMatrix(0, 9, "Atualizar Leitura")
			.set_TextMatrix(0, 10, .get_TextMatrix(0, 9))
			.set_TextMatrix(0, 11, .get_TextMatrix(0, 10))
			.set_TextMatrix(0, 12, .get_TextMatrix(0, 11))
			'
			.set_TextMatrix(1, 9, "U.C.")
			.set_TextMatrix(1, 10, .get_TextMatrix(1, 9))
			.set_TextMatrix(2, 9, "Deslig.")
			.set_TextMatrix(3, 9, .get_TextMatrix(2, 9))
			.set_TextMatrix(2, 10, "Última")
			.set_TextMatrix(3, 10, .get_TextMatrix(2, 10))
			'
			.set_TextMatrix(1, 11, "Caderno")
			.set_TextMatrix(1, 12, .get_TextMatrix(1, 11))
			.set_TextMatrix(2, 11, "Atual")
			.set_TextMatrix(3, 11, .get_TextMatrix(2, 11))
			.set_TextMatrix(2, 12, "Anter.")
			.set_TextMatrix(3, 12, .get_TextMatrix(2, 12))
			'
			.set_TextMatrix(0, 13, "Protocolo") 'Protocolo-sub/sequencia os
			.set_TextMatrix(1, 13, "de atendimento")
			.set_TextMatrix(2, 13, "comercial")
			.set_TextMatrix(3, 13, "do Link Center")
			.set_TextMatrix(0, 14, "Classificação") 'id-descrição
			.set_TextMatrix(1, 14, "Comercial")
			.set_TextMatrix(2, 14, "do atendimento")
			.set_TextMatrix(3, 14, "do protocolo")
			
			.set_TextMatrix(0, 15, "Data")
			.set_TextMatrix(1, 15, "da importação")
			.set_TextMatrix(2, 15, "registro")
			.set_TextMatrix(3, 15, "protocolo")
			
			.set_TextMatrix(0, 16, "Data")
			.set_TextMatrix(1, 16, "da atualização")
			.set_TextMatrix(2, 16, "na U.C. do ")
			.set_TextMatrix(3, 16, "faturamento")
			'
			.set_TextMatrix(0, 17, "id")
			.set_TextMatrix(1, 17, .get_TextMatrix(0, 17))
			.set_TextMatrix(2, 17, .get_TextMatrix(0, 17))
			.set_TextMatrix(3, 17, .get_TextMatrix(0, 17))
			.set_TextMatrix(0, 18, "unid_id")
			.set_TextMatrix(1, 18, .get_TextMatrix(0, 18))
			.set_TextMatrix(2, 18, .get_TextMatrix(0, 18))
			.set_TextMatrix(3, 18, .get_TextMatrix(0, 18))
			.set_TextMatrix(0, 19, "cons_id")
			.set_TextMatrix(1, 19, .get_TextMatrix(0, 19))
			.set_TextMatrix(2, 19, .get_TextMatrix(0, 19))
			.set_TextMatrix(3, 19, .get_TextMatrix(0, 19))
			.set_TextMatrix(0, 20, "grupo")
			.set_TextMatrix(1, 20, .get_TextMatrix(0, 20))
			.set_TextMatrix(2, 20, .get_TextMatrix(0, 20))
			.set_TextMatrix(3, 20, .get_TextMatrix(0, 20))
			.set_TextMatrix(0, 21, "atualizado")
			.set_TextMatrix(1, 21, .get_TextMatrix(0, 21))
			.set_TextMatrix(2, 21, .get_TextMatrix(0, 21))
			.set_TextMatrix(3, 21, .get_TextMatrix(0, 21))
			'
			For lintRow = 0 To 3
				For lintCol = 0 To 21
					.set_MergeCol(lintCol, True)
					.set_MergeRow(lintRow, True)
					.Col = lintCol
					.Row = lintRow
					.CellAlignment = MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter
				Next lintCol
			Next lintRow
			.set_ColWidth(0, 1200)
			.set_ColWidth(1, 1115)
			.set_ColWidth(2, 950)
			.set_ColWidth(3, 950)
			.set_ColWidth(4, 950)
			.set_ColWidth(5, 950)
			.set_ColWidth(6, 950)
			.set_ColWidth(7, 950)
			.set_ColWidth(8, 950)
			.set_ColWidth(9, 600)
			.set_ColWidth(10, 600)
			.set_ColWidth(11, 600)
			.set_ColWidth(12, 600)
			.set_ColWidth(13, 2300)
			.set_ColWidth(14, 4500)
			.set_ColWidth(15, 1200)
			.set_ColWidth(16, 1200)
			.set_ColWidth(17, 0)
			.set_ColWidth(18, 0)
			.set_ColWidth(19, 0)
			.set_ColWidth(20, 0)
			.set_ColWidth(21, 0)
			.set_ColAlignment(9, MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter)
			.set_ColAlignment(10, MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter)
			.set_ColAlignment(11, MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter)
			.set_ColAlignment(12, MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter)
			.set_ColAlignment(14, MSFlexGridLib.AlignmentSettings.flexAlignLeftCenter)
			.Redraw = True
		End With
		iblnMontaGrade = True
	End Sub
	
	Public Sub SetaParametros(ByRef afrmQuemChama As System.Windows.Forms.Form)
		ifrmQuemChama = afrmQuemChama
		ifrmQuemChama.Enabled = False
	End Sub
	
	Private Sub mfgDados_DblClick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles mfgDados.DblClick
		With Me.mfgDados
			If .Rows > 4 Then
				If .RowSel > 0 Then
					If .ColSel > 0 Then
						Select Case .ColSel
							Case Is = 9
								If .get_TextMatrix(.RowSel, .ColSel) = "X" Then
									.set_TextMatrix(.RowSel, .ColSel, "")
								Else
									.set_TextMatrix(.RowSel, .ColSel, "X")
								End If
								.set_TextMatrix(.RowSel, 10, "")
							Case Is = 10
								If .get_TextMatrix(.RowSel, .ColSel) = "X" Then
									.set_TextMatrix(.RowSel, .ColSel, "")
								Else
									.set_TextMatrix(.RowSel, .ColSel, "X")
								End If
								.set_TextMatrix(.RowSel, 9, "")
							Case Is = 11
								If .get_TextMatrix(.RowSel, .ColSel) = "X" Then
									.set_TextMatrix(.RowSel, .ColSel, "")
								Else
									.set_TextMatrix(.RowSel, .ColSel, "X")
								End If
								.set_TextMatrix(.RowSel, 12, "")
							Case Is = 12
								If .get_TextMatrix(.RowSel, .ColSel) = "X" Then
									.set_TextMatrix(.RowSel, .ColSel, "")
								Else
									.set_TextMatrix(.RowSel, .ColSel, "X")
								End If
								.set_TextMatrix(.RowSel, 11, "")
						End Select
					End If
				End If
			End If
		End With
	End Sub
End Class