Option Strict Off
Option Explicit On
Friend Class frmGerencialLinkCenter
	Inherits System.Windows.Forms.Form
	Private iintIdx As Short
	Private ilngTempoD As Integer
	Private ilngTempo As Integer
	Private ilngTime As Integer
	Private iblnAutoSize As Boolean
	Private iblnLigacaoNovaAberta As Boolean
	Private ifrmImportaLinkCenter As frmImportaLinkCenter
	
	Private Sub cmdCarrega_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdCarrega.Click
		Call CarregaDadosGerecial_LC()
	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 dtpIni_Change(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles dtpIni.Change
		Me.dtpFim.value = CDate(UltimoDiaMes((Me.dtpIni.Month), (dtpIni.Year)) & "/" & VB6.Format(Me.dtpIni.value, "MM/YYYY"))
	End Sub
	
	Private Sub dtpIni_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles dtpIni.ClickEvent
		Call dtpIni_Change(dtpIni, New System.EventArgs())
	End Sub
	
	Private Sub frmGerencialLinkCenter_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		iblnLigacaoNovaAberta = False
		ilngTime = 1
		Me.dtpIni.value = BuscaDataBD
		Me.dtpIni.value = CDate("01/" & VB6.Format(Me.dtpIni.value, "MM/YYYY"))
		Me.dtpFim.value = CDate(UltimoDiaMes((Me.dtpIni.Month), (dtpIni.Year)) & "/" & VB6.Format(Me.dtpIni.value, "MM/YYYY"))
		Call CenterForm(Me)
		Call MapeamentoTabelas()
		Call LigaDes()
		iblnAutoSize = True
		ifrmImportaLinkCenter = New frmImportaLinkCenter
	End Sub
	
	Private Sub frmGerencialLinkCenter_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
		'
		'UPGRADE_NOTE: Object ifrmImportaLinkCenter 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"'
		ifrmImportaLinkCenter = Nothing
	End Sub
	
	Private Sub MapeamentoTabelas()
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		Dim lstrNmColLc As String
		Dim lstrNmColFwb As String
		Dim lstrNmColFwa As String
		Dim lstrNmColCon As String
		Dim lstrTipoCol As String
		
		Dim lstrLcTab As String
		Dim lstrLcTabCol As String
		Dim lstrLcTabKey As String
		Dim lstrLcTabDes As String
		
		Dim lstrFwTab As String
		Dim lstrFwTabCol As String
		Dim lstrFwTabKey As String
		Dim lstrFwTabDes As String
		
		lrstAux = New ADODB.Recordset
		With Me.lsvFiltros
			Call .Items.Clear()
			Call .Columns.Clear()
			If .Columns.Count <= 1 Then
				Call .Columns.Add("", "Filtros", CInt(VB6.TwipsToPixelsX(2100)))
			End If
		End With
		With Me.mfgMapa
			.Cols = 14
			.Rows = 1
		End With
		lstrSql = ""
		lstrSql = lstrSql & "SELECT * "
		lstrSql = lstrSql & "  FROM " & gstrDataBase & ".`ger_linkcenter`"
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				If .RecordCount > 0 Then
					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"'
						lstrNmColLc = Trim(IIf(IsDbNull(.Fields("col_lc").value), "", .Fields("col_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"'
						lstrNmColFwb = Trim(IIf(IsDbNull(.Fields("col_fw_b").value), "", .Fields("col_fw_b").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"'
						lstrNmColFwa = Trim(IIf(IsDbNull(.Fields("col_fw_a").value), "", .Fields("col_fw_a").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"'
						lstrNmColCon = Trim(IIf(IsDbNull(.Fields("nome_comun").value), "", .Fields("nome_comun").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"'
						lstrTipoCol = Trim(IIf(IsDbNull(.Fields("tipo").value), "A", .Fields("tipo").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"'
						lstrLcTab = Trim(IIf(IsDbNull(.Fields("tabela_lc").value), "", .Fields("tabela_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"'
						lstrLcTabCol = Trim(IIf(IsDbNull(.Fields("tabela_coluna_lc").value), "", .Fields("tabela_coluna_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"'
						lstrLcTabKey = Trim(IIf(IsDbNull(.Fields("tabela_chave_lc").value), "", .Fields("tabela_chave_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"'
						lstrLcTabDes = Trim(IIf(IsDbNull(.Fields("tabela_nome_lc").value), "", .Fields("tabela_nome_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"'
						lstrFwTab = Trim(IIf(IsDbNull(.Fields("tabela_fw").value), "", .Fields("tabela_fw").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"'
						lstrFwTabCol = Trim(IIf(IsDbNull(.Fields("tabela_coluna_fw").value), "", .Fields("tabela_coluna_fw").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"'
						lstrFwTabKey = Trim(IIf(IsDbNull(.Fields("tabela_chave_fw").value), "", .Fields("tabela_chave_fw").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"'
						lstrFwTabDes = Trim(IIf(IsDbNull(.Fields("tabela_nome_fw").value), "", .Fields("tabela_nome_fw").value))
						'
						'Monta Filtros amigáveis
						Call Me.lsvFiltros.Items.Add(IIf(lstrNmColCon <> "", lstrNmColCon, IIf(lstrNmColFwb <> "", lstrNmColFwb, lstrNmColFwa)))
						With Me.mfgMapa
							.Rows = .Rows + 1
							.set_TextMatrix(.Rows - 1, 0, Me.lsvFiltros.Items.Count)
							.set_TextMatrix(.Rows - 1, 1, lstrNmColLc)
							.set_TextMatrix(.Rows - 1, 2, lstrNmColFwb)
							.set_TextMatrix(.Rows - 1, 3, lstrNmColFwa)
							.set_TextMatrix(.Rows - 1, 4, IIf(lstrNmColCon <> "", lstrNmColCon, IIf(lstrNmColFwb <> "", lstrNmColFwb, lstrNmColFwa)))
							.set_TextMatrix(.Rows - 1, 5, lstrTipoCol)
							.set_TextMatrix(.Rows - 1, 6, lstrLcTab)
							.set_TextMatrix(.Rows - 1, 7, lstrLcTabCol)
							.set_TextMatrix(.Rows - 1, 8, lstrLcTabKey)
							.set_TextMatrix(.Rows - 1, 9, lstrLcTabDes)
							.set_TextMatrix(.Rows - 1, 10, lstrFwTab)
							.set_TextMatrix(.Rows - 1, 11, lstrFwTabCol)
							.set_TextMatrix(.Rows - 1, 12, lstrFwTabKey)
							.set_TextMatrix(.Rows - 1, 13, lstrFwTabDes)
						End With
						Call .MoveNext()
					End While
				End If
				Call .Close()
			End If
		End With
		If Me.mfgMapa.Rows > 1 Then Me.mfgMapa.FixedRows = 1
		'UPGRADE_WARNING: Lower bound of collection Me.lsvFiltros.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
		If Me.lsvFiltros.Items.Count > 0 Then Me.lsvFiltros.Items.Item(1).Checked = 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 EncheGradeUnidadeConsumidora()
		'fazer rotina para colocar o id_medidor na tabela unidb e unida pegando pelo num ou eletr no data base medicao_empresa na tabela medidor o id e numero
		Dim lstrLcTab As String
		Dim lstrLcCol As String
		Dim lstrLcKey As String
		Dim lstrLcDes As String
		Dim lstrFwTab As String
		Dim lstrFwCol As String
		Dim lstrFwKey As String
		Dim lstrFwDes As String
		Dim lintRet As Short
		Dim lintIdx As Short
		Dim llngRow As Integer
		Dim llngCol As Integer
		Dim lblnLgN As Boolean 'Ligação Nova
		Dim lblnMed As Boolean 'Medidor
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		Call InicializaGrades(mshDados, lblLog)
		Call InicializaGrades(mshOs, lblLogOs)
		lblnLgN = False
		lblnMed = False
		lintRet = 0
		With Me.lsvFiltros
			For lintIdx = 1 To .Items.Count
				'UPGRADE_WARNING: Lower bound of collection Me.lsvFiltros.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
				If .Items.Item(lintIdx).Checked Then
					lintRet = lintIdx
					'UPGRADE_WARNING: Lower bound of collection Me.lsvFiltros.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
					lblnLgN = (.Items.Item(lintIdx).Text = "Ligação Nova")
					'UPGRADE_WARNING: Lower bound of collection Me.lsvFiltros.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
					lblnMed = (.Items.Item(lintIdx).Text = "Medidor")
				End If
			Next lintIdx
		End With
		With Me.mfgMapa
			lstrLcTab = .get_TextMatrix(lintRet, 6)
			lstrLcCol = .get_TextMatrix(lintRet, 7)
			lstrLcKey = .get_TextMatrix(lintRet, 8)
			lstrLcDes = .get_TextMatrix(lintRet, 9)
			lstrFwTab = .get_TextMatrix(lintRet, 10)
			lstrFwCol = .get_TextMatrix(lintRet, 11)
			lstrFwKey = .get_TextMatrix(lintRet, 12)
			lstrFwDes = .get_TextMatrix(lintRet, 13)
		End With
		lstrSql = ""
		lstrSql = lstrSql & "SELECT " & vbCrLf
		lstrSql = lstrSql & "       lc_uc.id 'LC. Cod.' " & vbCrLf
		lstrSql = lstrSql & "       ,lc_uc.nome 'LC. Nome' " & vbCrLf
		lstrSql = lstrSql & "       ,CONCAT(LEFT(lc_uc.zlc, 3),'.',MID(lc_uc.zlc, 4, 2),'.',RIGHT(lc_uc.zlc, 6)) 'LC. Ident.' " & vbCrLf
		lstrSql = lstrSql & "       ,lc_uc.situacao 'LC. Sit.' " & vbCrLf
		If lblnLgN Then
			lstrSql = lstrSql & "       ,lc_uc.cpf_cnpj 'LC. Cpf/Cnpj' " & vbCrLf
			lstrSql = lstrSql & "       ,lc_c.id 'LC.C.Cod.' " & vbCrLf
			lstrSql = lstrSql & "       ,lc_c.nome 'LC.C.Nome' " & vbCrLf
			lstrSql = lstrSql & "       ,lc_c.cpf_cnpj 'LC.C.Cpf/Cnpj' " & vbCrLf
		ElseIf lblnMed Then 
			lstrSql = lstrSql & "       ,lc_me.id 'LC. Cód.Med.' " & vbCrLf
			lstrSql = lstrSql & "       ,lc_me.numero 'LC. Medidor' " & vbCrLf
			lstrSql = lstrSql & "       ,fw_uc.unid_id 'FW. Cod.' " & vbCrLf
			lstrSql = lstrSql & "       ,fw_uc.nome 'FW. Nome' " & vbCrLf
			lstrSql = lstrSql & "       ,CONCAT(fw_uc.zona,'.',fw_uc.livro,'.',fw_uc.conta) 'FW. Ident.' " & vbCrLf
			lstrSql = lstrSql & "       ,fw_uc.situacao 'FW. Sit.' " & vbCrLf
			lstrSql = lstrSql & "       ,fw_uc.idmedidor 'FW. Cód.Med.' " & vbCrLf
			lstrSql = lstrSql & "       ,fw_uc." & Me.mfgMapa.get_TextMatrix(lintRet, IIf(Me.opbGrB.Checked, 2, 3)) & " 'FW. " & Me.mfgMapa.get_TextMatrix(lintRet, 4) & "' " & vbCrLf
		Else
			If lstrLcTab <> "" Then
				lstrSql = lstrSql & "       " & IIf(lintRet > 2, ", " & lstrLcTab & "." & lstrLcCol & " 'LC. " & Me.mfgMapa.get_TextMatrix(lintRet, 4) & "' ", "") & vbCrLf
				If lstrLcDes <> "" Then
					lstrSql = lstrSql & "       " & IIf(lintRet > 2, ", " & lstrLcTab & "." & lstrLcDes & " 'LC. " & Me.mfgMapa.get_TextMatrix(lintRet, 4) & "' ", "") & vbCrLf
				End If
			Else
				If InStr(1, Me.mfgMapa.get_TextMatrix(lintRet, 1), "cpf_cnpj") > 0 Then
					lstrSql = lstrSql & "       " & IIf(lintRet > 2, ",REPLACE(REPLACE(REPLACE(lc_uc." & Me.mfgMapa.get_TextMatrix(lintRet, 1) & ",'.',''),'-',''),'/','') 'LC. " & Me.mfgMapa.get_TextMatrix(lintRet, 4) & "' ", "") & vbCrLf
				Else
					lstrSql = lstrSql & "       " & IIf(lintRet > 2, ",lc_uc." & Me.mfgMapa.get_TextMatrix(lintRet, 1) & " 'LC. " & Me.mfgMapa.get_TextMatrix(lintRet, 4) & "' ", "") & vbCrLf
				End If
			End If
			lstrSql = lstrSql & "       ,fw_uc.unid_id 'FW.  Cod.' " & vbCrLf
			lstrSql = lstrSql & "       ,fw_uc.nome 'FW. Nome' " & vbCrLf
			lstrSql = lstrSql & "       ,CONCAT(fw_uc.zona,'.',fw_uc.livro,'.',fw_uc.conta) 'FW. Ident.' " & vbCrLf
			lstrSql = lstrSql & "       ,fw_uc.situacao 'FW. Sit.' " & vbCrLf
			If lstrFwTab <> "" Then
				lstrSql = lstrSql & "       " & IIf(lintRet > 2, ", " & lstrFwTab & "." & IIf(lstrFwCol <> "", lstrFwCol, lstrFwKey) & " 'FW. " & Me.mfgMapa.get_TextMatrix(lintRet, 4) & "' ", "") & vbCrLf
				If lstrFwDes <> "" Then
					lstrSql = lstrSql & "       " & IIf(lintRet > 2, ", " & lstrFwTab & "." & lstrFwDes & " 'FW. " & Me.mfgMapa.get_TextMatrix(lintRet, 4) & "' ", "") & vbCrLf
				End If
			Else
				lstrSql = lstrSql & "       " & IIf(lintRet > 2, ", fw_uc." & Me.mfgMapa.get_TextMatrix(lintRet, IIf(Me.opbGrB.Checked, 2, 3)) & " 'FW. " & Me.mfgMapa.get_TextMatrix(lintRet, 4) & "' ", "") & vbCrLf
			End If
		End If
		lstrSql = lstrSql & "  FROM " & gstrBDCLinkCenter & ".`uc` lc_uc " & vbCrLf
		If lblnLgN Then
			lstrSql = lstrSql & "     , " & gstrBDCLinkCenter & ".`consumidor` lc_c" & vbCrLf
			lstrSql = lstrSql & " WHERE NOT EXISTS(SELECT * " & vbCrLf
			lstrSql = lstrSql & "                    FROM " & gstrDataBase & ".`unid" & IIf(Me.opbGrB.Checked, "b", "a") & "` fw_uc " & vbCrLf
			lstrSql = lstrSql & "                   WHERE `fw_uc`.`unid_id` = `lc_uc`.`unid_id_fatwin`)" & vbCrLf
			lstrSql = lstrSql & "   AND (`lc_uc`.`id_consumidor` > 0 AND `lc_uc`.`id_consumidor` IS NOT NULL) " & vbCrLf
			lstrSql = lstrSql & "   AND `lc_uc`.`grupo` = '" & IIf(Me.opbGrB.Checked, "B", "A") & "' "
			lstrSql = lstrSql & "   AND `lc_uc`.`id_consumidor` = `lc_c`.`id`"
		ElseIf lblnMed Then 
			lstrSql = lstrSql & "     , " & gstrBDMLinkCenter & ".`medidor` lc_me" & vbCrLf
			lstrSql = lstrSql & "     , " & gstrDataBase & ".`unid" & IIf(Me.opbGrB.Checked, "b", "a") & "` fw_uc" & vbCrLf
			lstrSql = lstrSql & " WHERE lc_uc.unid_id_fatwin = fw_uc.unid_id " & vbCrLf
			lstrSql = lstrSql & "   AND lc_uc.grupo = '" & IIf(Me.opbGrB.Checked, "B", "A") & "' " & vbCrLf
			lstrSql = lstrSql & "   AND lc_uc.id_medidor = lc_me.id " & vbCrLf
			lstrSql = lstrSql & "   AND lc_me.numero <> IFNULL(fw_uc." & Me.mfgMapa.get_TextMatrix(lintRet, IIf(Me.opbGrB.Checked, 2, 3)) & ",'') "
		Else
			If lstrLcTab <> "" Then
				lstrSql = lstrSql & " LEFT JOIN " & gstrBDCLinkCenter & "." & lstrLcTab & " ON(" & lstrLcTab & "." & lstrLcKey & " = lc_uc." & Me.mfgMapa.get_TextMatrix(lintRet, 1) & ") "
			End If
			lstrSql = lstrSql & "     , " & gstrDataBase & ".`unid" & IIf(Me.opbGrB.Checked, "b", "a") & "` fw_uc" & vbCrLf
			If lstrFwTab <> "" Then
				lstrSql = lstrSql & " LEFT JOIN " & gstrDataBase & "." & lstrFwTab & " ON(" & lstrFwTab & "." & lstrFwKey & " = fw_uc." & Me.mfgMapa.get_TextMatrix(lintRet, 2) & IIf(Me.mfgMapa.get_TextMatrix(lintRet, 4) = "N", "+0", "") & ") "
			End If
			lstrSql = lstrSql & " WHERE lc_uc.unid_id_fatwin = fw_uc.unid_id AND lc_uc.grupo = '" & IIf(Me.opbGrB.Checked, "B", "A") & "' " & vbCrLf
			lstrSql = lstrSql & PegaFiltros
		End If
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				If .RecordCount > 0 Then
					Me.mshDados.DataSource = lrstAux.DataSource
					Me.lblLog.Text = " Registros encontrados " & .RecordCount
					Me.lblLogOs.Text = ""
				End If
				Call .Close()
			End If
		End With
		If iblnAutoSize Then
			With Me.mshDados
				.Redraw = False
				For llngCol = 0 To .get_Cols() - 1
					.set_ColWidth(llngCol,  , 95)
				Next llngCol
				For llngRow = 0 To .Rows - 1
					For llngCol = 0 To .get_Cols() - 1
						If (95 * CInt(Len(.get_TextMatrix(llngRow, llngCol)))) > .get_ColWidth(llngCol) Then
							.set_ColWidth(llngCol,  , 95 * CInt(Len(.get_TextMatrix(llngRow, llngCol))))
						End If
					Next llngCol
				Next llngRow
				.Redraw = True
			End With
			iblnAutoSize = False
		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 lsvFiltros_ItemCheck(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.ItemCheckEventArgs) Handles lsvFiltros.ItemCheck
		Dim aItem As System.Windows.Forms.ListViewItem = lsvFiltros.Items(eventArgs.Index)
		Dim lintIdx As Short
		With Me.lsvFiltros
			For lintIdx = 1 To .Items.Count
				If aItem.Checked Then
					If aItem.Index <> lintIdx Then
						'UPGRADE_WARNING: Lower bound of collection Me.lsvFiltros.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
						If .Items.Item(lintIdx).Checked Then
							'UPGRADE_WARNING: Lower bound of collection Me.lsvFiltros.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
							.Items.Item(lintIdx).Checked = False
							iblnAutoSize = True
						End If
						'UPGRADE_WARNING: Lower bound of collection Me.lsvFiltros.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
						If .Items.Item(lintIdx).Selected Then
							'UPGRADE_WARNING: Lower bound of collection Me.lsvFiltros.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
							.Items.Item(lintIdx).Selected = False
						End If
					End If
				End If
			Next lintIdx
		End With
		aItem.Selected = True
	End Sub
	
	'UPGRADE_ISSUE: MSComctlLib.ListView event lsvFiltros.ItemClick was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="ABD9AF39-7E24-4AFF-AD8D-3675C1AA3054"'
	Private Sub lsvFiltros_ItemClick(ByVal Item As System.Windows.Forms.ListViewItem)
		Item.Checked = True
		Call lsvFiltros_ItemCheck(lsvFiltros, New System.Windows.Forms.ItemCheckEventArgs(Item.Index, System.Windows.Forms.CheckState.Indeterminate, Item.Checked))
	End Sub
	
	Private Function PegaFiltros() As String
		Dim lstrRet As String
		Dim lintIdx As Short
		Dim lstrTab As String
		Dim lstrCol As String
		Dim lstrKey As String
		lstrRet = ""
		With Me.lsvFiltros
			For lintIdx = 1 To .Items.Count
				'UPGRADE_WARNING: Lower bound of collection Me.lsvFiltros.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
				If .Items.Item(lintIdx).Checked = True Then
					With Me.mfgMapa
						If Trim(.get_TextMatrix(lintIdx, 6)) <> "" Then
							lstrTab = Trim(.get_TextMatrix(lintIdx, 6))
							lstrCol = Trim(.get_TextMatrix(lintIdx, 7))
							lstrKey = Trim(.get_TextMatrix(lintIdx, 8))
							lstrRet = ""
							lstrRet = lstrRet & "AND ("
							lstrRet = lstrRet & " SELECT " & lstrCol
							lstrRet = lstrRet & "   FROM " & gstrBDCLinkCenter & "." & lstrTab
							lstrRet = lstrRet & "  WHERE " & lstrTab & "." & lstrKey & " = lc_uc." & .get_TextMatrix(lintIdx, 1)
							lstrRet = lstrRet & " ) <> fw_uc." & .get_TextMatrix(lintIdx, IIf(Me.opbGrB.Checked, 2, 3)) & IIf(.get_TextMatrix(lintIdx, 5) = "N", "+0", "")
						Else
							If InStr(1, .get_TextMatrix(lintIdx, 1), "cpf_cnpj") > 0 Then
								lstrRet = "AND REPLACE(REPLACE(REPLACE(lc_uc." & .get_TextMatrix(lintIdx, 1) & IIf(.get_TextMatrix(lintIdx, 5) = "N", "+0", "") & ",'.',''),'-',''),'/','') <> fw_uc." & .get_TextMatrix(lintIdx, IIf(Me.opbGrB.Checked, 2, 3)) & IIf(.get_TextMatrix(lintIdx, 5) = "N", "+0", "")
							Else
								lstrRet = "AND lc_uc." & .get_TextMatrix(lintIdx, 1) & IIf(.get_TextMatrix(lintIdx, 5) = "N", "+0", "") & " <> fw_uc." & .get_TextMatrix(lintIdx, IIf(Me.opbGrB.Checked, 2, 3)) & IIf(.get_TextMatrix(lintIdx, 5) = "N", "+0", "")
							End If
						End If
					End With
				End If
			Next lintIdx
		End With
		PegaFiltros = lstrRet
	End Function
	
	Private Sub mshDados_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles mshDados.ClickEvent
		Dim llngRow As Integer
		Dim llngCol As Integer
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		Dim llngIdUc As Integer
		Dim ldteIni As Date
		Dim ldteFim As Date
		lrstAux = New ADODB.Recordset
		ldteIni = CDate(Me.dtpIni.value & " 00:00:01")
		ldteFim = CDate(Me.dtpFim.value & " 23:59:59")
		With Me.mshDados
			llngIdUc = CInt(IIf(IsNumeric(.get_TextMatrix(.RowSel, 0)), .get_TextMatrix(.RowSel, 0), 0))
		End With
		Call InicializaGrades(mshOs, lblLogOs)
		lstrSql = ""
		lstrSql = lstrSql & "SELECT "
		lstrSql = lstrSql & "       lc_os.sequencia_os 'Seq.O.S.', "
		lstrSql = lstrSql & "       lc_os.id 'Protocolo', "
		lstrSql = lstrSql & "       lc_os.id_sub 'Sub Item', "
		lstrSql = lstrSql & "       lc_os.id_sub_parent 'Sub Ger.', "
		lstrSql = lstrSql & "       lc_os.data 'Solicitação', "
		lstrSql = lstrSql & "       lc_os.data_conclusao 'Conclusão', "
		lstrSql = lstrSql & "       lc_os.id_class_comercial 'Cód.Com.', "
		lstrSql = lstrSql & "       lc_os.descr_class_comercial 'Desc.Com.' "
		lstrSql = lstrSql & "  FROM " & gstrBDCLinkCenter & ".`os` lc_os"
		lstrSql = lstrSql & " WHERE lc_os.id_uc = " & llngIdUc & " "
		If Me.opbSelecOs.Checked Then
			If Me.opbConclusao.Checked Then
				lstrSql = lstrSql & " AND lc_os.data_conclusao BETWEEN '" & VB6.Format(ldteIni, "yyyy-MM-dd HH:NN:SS") & "' AND '" & VB6.Format(ldteFim, "yyyy-MM-dd HH:NN:SS") & "' "
			ElseIf Me.opbSolicitacao.Checked Then 
				lstrSql = lstrSql & " AND lc_os.data BETWEEN '" & VB6.Format(ldteIni, "yyyy-MM-dd HH:NN:SS") & "' AND '" & VB6.Format(ldteFim, "yyyy-MM-dd HH:NN:SS") & "' "
			End If
		End If
		lstrSql = lstrSql & "ORDER BY lc_os.data_conclusao DESC "
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				If .RecordCount > 0 Then
					Me.mshOs.DataSource = lrstAux.DataSource
					Me.lblLogOs.Text = " Registros encontrados " & .RecordCount
				End If
				Call .Close()
			End If
		End With
		With Me.mshOs
			.Redraw = False
			For llngCol = 0 To .get_Cols() - 1
				.set_ColWidth(llngCol,  , 95)
			Next llngCol
			For llngRow = 0 To .Rows - 1
				For llngCol = 0 To .get_Cols() - 1
					If (95 * CInt(Len(.get_TextMatrix(llngRow, llngCol)))) > .get_ColWidth(llngCol) Then
						.set_ColWidth(llngCol,  , 95 * CInt(Len(.get_TextMatrix(llngRow, llngCol))))
						If IsDate(.get_TextMatrix(llngRow, llngCol)) Then
							.set_TextMatrix(llngRow, llngCol, VB6.Format(.get_TextMatrix(llngRow, llngCol), "DD/MM/YYYY" & IIf(CInt(Len(Trim(.get_TextMatrix(llngRow, llngCol)))) > 10, " HH:NN:SS", "")))
						End If
					End If
				Next llngCol
			Next llngRow
			.Redraw = True
		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
	End Sub
	
	Private Sub mshOs_DblClick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles mshOs.DblClick
		With mshOs
			If .Rows > 1 Then
				Me.chkAutoRefresh.CheckState = System.Windows.Forms.CheckState.Unchecked
				If IsDate(.get_TextMatrix(.RowSel, 5)) Then
					If Not VerificaSeExisteOsLigNovaAberta Then
						Call ifrmImportaLinkCenter.SetaDados(.get_TextMatrix(.RowSel, 0), CDate(.get_TextMatrix(.RowSel, 5)), Me)
						Call ifrmImportaLinkCenter.Show()
					Else
						Call MsgBox("Existe uma O.S. de Ligação Nova não concluída!", MsgBoxStyle.Information, gstrTituloMensagem)
					End If
				Else
					Call MsgBox("Não possui data de conclusão!", MsgBoxStyle.Information, gstrTituloMensagem)
				End If
			End If
		End With
	End Sub
	
	Private Function VerificaSeExisteOsLigNovaAberta() As Boolean
		Dim lblnRet As Boolean
		Dim ldblRow As Double
		lblnRet = False
		With Me.mshOs
			If .Rows > 1 Then
				For ldblRow = 1 To .Rows - 1
					If Trim(.get_TextMatrix(ldblRow, 6)) = "30.01" Then
						If IsDate(.get_TextMatrix(.RowSel, 5)) Then
							lblnRet = False
						Else
							lblnRet = True
						End If
					Else
						lblnRet = False
					End If
				Next ldblRow
			End If
		End With
		VerificaSeExisteOsLigNovaAberta = lblnRet
	End Function
	'UPGRADE_WARNING: Event opbSelecOs.CheckedChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub opbSelecOs_CheckedChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles opbSelecOs.CheckedChanged
		If eventSender.Checked Then
			Call LigaDes()
		End If
	End Sub
	
	'UPGRADE_WARNING: Event opbTodasOS.CheckedChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub opbTodasOS_CheckedChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles opbTodasOS.CheckedChanged
		If eventSender.Checked Then
			Call LigaDes()
		End If
	End Sub
	
	Private Sub tmrTempo_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles tmrTempo.Tick
		Dim llngHor As Integer
		Dim llngMin As Integer
		Dim llngSeg As Integer
		Dim lintConta As Short
		
		ilngTempoD = ilngTempoD + 1
		llngHor = Fix(ilngTempoD / 3600)
		llngMin = Fix((ilngTempoD Mod 3600) / 60)
		llngSeg = Fix((ilngTempoD Mod 3600) Mod 60)
		'Me.txtTempoDecorrido.Text = Format(TimeSerial(llngHor, llngMin, llngSeg), "hh:mm:ss")
		llngHor = Fix(ilngTempo / 60)
		llngMin = Fix(ilngTempo Mod 60)
		llngHor = Fix(ilngTime / 60)
		llngMin = Fix((ilngTime Mod 60) Mod 60)
		'Me.txtTempoLimite.Text = Format(TimeSerial(llngHor, llngMin, 0), "hh:mm")
		System.Windows.Forms.Application.DoEvents()
	End Sub
	
	Private Sub tmrDecorrido_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles tmrDecorrido.Tick
		Dim llngHor As Integer
		Dim llngMin As Integer
		Dim llngSeg As Integer
		Dim lintConta As Short
		
		ilngTempo = ilngTempo + 1
		If ilngTempo >= ilngTime Then
			ilngTempo = 0
			If Me.chkAutoRefresh.CheckState = System.Windows.Forms.CheckState.Checked Then
				Call cmdCarrega_Click(cmdCarrega, New System.EventArgs())
			End If
		End If
		llngHor = Fix(ilngTempo / 60)
		llngMin = Fix(ilngTempo Mod 60)
		llngHor = Fix(ilngTime / 60)
		llngMin = Fix((ilngTime Mod 60) Mod 60)
		'Me.txtTempoLimite.Text = Format(TimeSerial(llngHor, llngMin, 0), "hh:mm")
		System.Windows.Forms.Application.DoEvents()
	End Sub
	
	Private Sub InicializaGrades(ByRef amshAux As AxMSHierarchicalFlexGridLib.AxMSHFlexGrid, ByRef alblAux As System.Windows.Forms.Label)
		With amshAux
			.AllowUserResizing = MSFlexGridLib.AllowUserResizeSettings.flexResizeBoth
			.set_Cols( , 2)
			.Rows = 2
			Call .Clear()
		End With
		alblAux.Text = ""
	End Sub
	
	Private Sub LigaDes()
		Me.opbSolicitacao.Enabled = Me.opbSelecOs.Checked
		Me.opbConclusao.Enabled = Me.opbSelecOs.Checked
		Me.dtpIni.Enabled = Me.opbSelecOs.Checked
		Me.dtpFim.Enabled = Me.opbSelecOs.Checked
	End Sub
	
	Public Sub CarregaDadosGerecial_LC()
		Call EncheGradeUnidadeConsumidora()
		If Me.mshDados.Rows <= 2 And Me.mshDados.get_TextMatrix(1, 0) = "" Then
			Me.lblLog.Text = " Não foi encontrando nenhum registro."
			Me.lblLog.Refresh()
			Me.lblLogOs.Text = ""
			Me.lblLogOs.Refresh()
		End If
	End Sub
End Class