Option Strict Off
Option Explicit On
Imports fatd_faturamento.BLL.Repositorio
Imports fatd_faturamento.ENTIDADE
Friend Class frmAtualizaLeituras
	Inherits System.Windows.Forms.Form
	Private ifrmQuemChama As System.Windows.Forms.Form
	Private iblnMontaGrade As Boolean
	Private dt, dt1, dt2, dt3 As DataTable
	Private objAtualizaBancoDados As New entidadeAtualizaBancoDados
	Private repositorioAtualizaBancoDados As New repositorioAtualizaBancoDados
	Private objExecAtualizaBancoDados As New entidadeAtualizaBancoDados
	Private repositorioExecAtualizaBancoDados As New repositorioAtualizaBancoDados

	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

		Call MontaGrade()
		Me.mfgDados.Redraw = False

		Try

			lstrsql = "SELECT * "
			lstrsql = lstrsql & "  FROM `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)
			objAtualizaBancoDados.QUERY_NAME = lstrsql
			dt = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)

			If dt.Rows.Count > 0 Then
				Me.mfgDados.Rows = Me.mfgDados.Rows - 1
				Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, dt.Rows.Count)
				For Each row As DataRow In dt.Rows

					ldblId = IIf(IsDBNull(row.Item("id")), 0, row.Item("id"))
					llngUnid_id = IIf(IsDBNull(row.Item("unid_id")), 0, row.Item("unid_id"))
					llngCons_id = IIf(IsDBNull(row.Item("cons_id")), 0, row.Item("cons_id"))
					lstrGrupo = IIf(IsDBNull(row.Item("grupo")), "", row.Item("grupo"))
					lstrZona = IIf(IsDBNull(row.Item("zona")), "", row.Item("zona"))
					lstrLivro = IIf(IsDBNull(row.Item("livro")), "", row.Item("livro"))
					lstrConta = IIf(IsDBNull(row.Item("conta")), "", row.Item("conta"))
					lstrSituacao = IIf(IsDBNull(row.Item("situacao")), "L", row.Item("situacao"))
					lstrCaderno_leit_atual = IIf(IsDBNull(row.Item("caderno_leit_atual")), "", row.Item("caderno_leit_atual"))
					lstrCaderno_leit_anterior = IIf(IsDBNull(row.Item("caderno_leit_anterior")), "", row.Item("caderno_leit_anterior"))
					ldblUltleit = IIf(IsDBNull(row.Item("ultleit")), 0, row.Item("ultleit"))
					ldblUltleit_desligamento = IIf(IsDBNull(row.Item("ultleit_desligamento")), 0, row.Item("ultleit_desligamento"))
					ldblLeitura_lc = IIf(IsDBNull(row.Item("leitura_lc")), 0, row.Item("leitura_lc"))
					ldblUltiLei_lc = IIf(IsDBNull(row.Item("ultimaleit_lc")), 0, row.Item("ultimaleit_lc"))
					ldblResiduo = IIf(IsDBNull(row.Item("residuo")), 0, row.Item("residuo"))
					ldblSequencia_os = IIf(IsDBNull(row.Item("sequencia_os")), 0, row.Item("sequencia_os"))
					ldblProtocolo = IIf(IsDBNull(row.Item("protocolo")), 0, row.Item("protocolo"))
					llngProtocolo_sub = IIf(IsDBNull(row.Item("protocolo_sub")), 0, row.Item("protocolo_sub"))
					lstrId_class_comercial = IIf(IsDBNull(row.Item("id_class_comercial")), "", row.Item("id_class_comercial"))
					lstrDescr_class_comercial = IIf(IsDBNull(row.Item("descr_class_comercial")), "", row.Item("descr_class_comercial"))
					ldteMovimento = IIf(IsDBNull(row.Item("movimento")), "1900-01-01 00:00:00", row.Item("movimento"))
					ldteAtualizacao = IIf(IsDBNull(row.Item("atualizacao")), "1900-01-01 00:00:00", row.Item("atualizacao"))
					lblnAtualizado = IIf(IsDBNull(row.Item("atualizado")), 0, row.Item("atualizado"))
					lblnUsa_desligamento = IIf(IsDBNull(row.Item("usa_desligamento")), 0, row.Item("usa_desligamento"))
					lblnAtualiza_uc = IIf(IsDBNull(row.Item("atualiza_uc")), 0, row.Item("atualiza_uc"))
					lblnAtualiza_caderno_lat = IIf(IsDBNull(row.Item("atualiza_caderno_lat")), 0, row.Item("atualiza_caderno_lat"))
					lblnAtualiza_caderno_lan = IIf(IsDBNull(row.Item("atualiza_caderno_lan")), 0, row.Item("atualiza_caderno_lan"))
					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 BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1)
				Next
				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

			Me.mfgDados.Redraw = True

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

	End Sub

	Private Sub 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

		Try
			objExecAtualizaBancoDados.QUERY_NAME = "START TRANSACTION"
			repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)

			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 `uc_faturamento` 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 `id` = " & llngUnid_id & " "
							lstrSql = lstrSql & "   AND `cons_id` = " & llngCons_id & " "
							objExecAtualizaBancoDados.QUERY_NAME = lstrSql
							repositorioExecAtualizaBancoDados.Consultar(objExecAtualizaBancoDados)

							lblnAux = True
						End If
						'
						If lblnAtualiza_caderno_lan Or lblnAtualiza_caderno_lat Then
							lstrSql = "UPDATE `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 & " "
							objExecAtualizaBancoDados.QUERY_NAME = lstrSql
							repositorioExecAtualizaBancoDados.Consultar(objExecAtualizaBancoDados)

							lblnAux = True
						End If
						'
						If lblnAux Then
							lstrSql = "UPDATE `leituras_unidb_lc` SET "
							'lstrSql = lstrSql & "`atualizacao` = CONVERT(DATE_FORMAT(localtime(),'%Y-%m-%d %T') USING Latin1), "
							lstrSql = lstrSql & "`atualizacao` = '" & VB6.Format(Date.Now, "yyyy-mm-dd hh:mm:ss") & "', "
							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 & " "
							objExecAtualizaBancoDados.QUERY_NAME = lstrSql
							repositorioExecAtualizaBancoDados.Consultar(objExecAtualizaBancoDados)
						End If

					End If
				Next llngRow
			End With
			objExecAtualizaBancoDados.QUERY_NAME = "COMMIT"
			repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)

			Call MsgBox("Registro(s) gravado(s) com sucesso.", MsgBoxStyle.Information, gstrTituloMensagem)

		Catch ex As Exception

			If UCase(Err.Source) = "MYSQL.DATA" Then
				objExecAtualizaBancoDados.QUERY_NAME = "ROLLBACK"
				repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)
			End If
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: cmdSalvar_Click" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	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)
		Try
			If KeyAscii = System.Windows.Forms.Keys.Escape Then
				Call cmdFechar_Click(cmdFechar, New System.EventArgs())
			ElseIf KeyAscii = System.Windows.Forms.Keys.Return Then
				TabEnter(KeyAscii, eventArgs)
			End If
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: frmAtualizaLeituras_KeyPress" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub
	
	Private Sub frmAtualizaLeituras_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		Dim ldteBase As Date
		ldteBase = Date.Now
		Try
			Me.dtpIni.Value = CDate("01/" & VB6.Format(ldteBase, "MM/yyyy"))
			Me.dtpFim.Value = CDate(UltimoDiaMes(Month(Me.dtpIni.Value), Year(Me.dtpIni.Value)) & "/" & VB6.Format(ldteBase, "MM/yyyy"))
			'If Not ifrmQuemChama Is Nothing Then
			''    Call CenterFormQuemChama(Me, ifrmQuemChama)
			''  Else
			'Call CenterForm(Me)
			'  End If
			Call MontaGrade()
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: frmAtualizaLeituras_Load" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub frmAtualizaLeituras_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
		Try
			If Not ifrmQuemChama Is Nothing Then
				ifrmQuemChama.Enabled = True
			End If
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: frmAtualizaLeituras_FormClosed" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub dtpIni_ValueChanged(sender As Object, e As EventArgs) Handles dtpIni.ValueChanged
		Try
			Me.dtpFim.Value = UltimoDiaMes(Month(Me.dtpIni.Value), Year(dtpIni.Value)) & "/" & Month(Me.dtpIni.Value) & "/" & Year(Me.dtpIni.Value)
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: dtpIni_ValueChanged" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub MontaGrade()
		'
		Dim lintRow As Short
		Dim lintCol As Short
		iblnMontaGrade = False
		Try
			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
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: MontaGrade" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Public Sub SetaParametros(ByRef afrmQuemChama As System.Windows.Forms.Form)
		Try
			ifrmQuemChama = afrmQuemChama
			ifrmQuemChama.Enabled = False
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: SetaParametros" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub mfgDados_DblClick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles mfgDados.DblClick
		Try
			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
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: mfgDados_DblClick" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub
End Class