Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Friend Class frmRelOrdemServico
	Inherits System.Windows.Forms.Form
	
	'UPGRADE_WARNING: Event chkAbertas.CheckStateChanged 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 chkAbertas_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles chkAbertas.CheckStateChanged
		If Me.chkAbertas.CheckState = 0 Then
			If Me.chkFinalizadas.CheckState = 0 Then
				Me.chkCanceladas.CheckState = System.Windows.Forms.CheckState.Checked
			End If
		End If
	End Sub
	
	'UPGRADE_WARNING: Event chkCanceladas.CheckStateChanged 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 chkCanceladas_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles chkCanceladas.CheckStateChanged
		If Me.chkCanceladas.CheckState = 0 Then
			If Me.chkAbertas.CheckState = 0 Then
				Me.chkFinalizadas.CheckState = System.Windows.Forms.CheckState.Checked
			End If
		End If
	End Sub
	
	'UPGRADE_WARNING: Event chkFinalizadas.CheckStateChanged 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 chkFinalizadas_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles chkFinalizadas.CheckStateChanged
		If Me.chkFinalizadas.CheckState = 0 Then
			If Me.chkAbertas.CheckState = 0 Then
				Me.chkCanceladas.CheckState = System.Windows.Forms.CheckState.Checked
			End If
		End If
	End Sub
	
	Private Sub cmdImprimir_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdImprimir.Click
		Dim lstrCriterio As String
		lstrCriterio = "{temp_listagem_os.nomemaquina} = """ & gstrNmEstacao & """"
		With Me.crpAux
			.ReportFileName = My.Application.Info.DirectoryPath & "\" & LeConfig("DIR_RPT") & "relpercentuaisordensservico.rpt"
			.DiscardSavedData = True
			.WindowState = Crystal.WindowStateConstants.crptMaximized
			.WindowControlBox = True
			.WindowControls = True
			.WindowShowPrintSetupBtn = True
			.WindowShowCloseBtn = True
			.WindowShowSearchBtn = True
			.SelectionFormula = lstrCriterio
			.WindowTitle = "Relatório dos percentuais das ordem de serviço"
			.Destination = Crystal.DestinationConstants.crptToWindow
			.Action = 0
		End With
	End Sub
	
	Private Sub cmdProcessar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdProcessar.Click
		Dim lstrProtocolo As String
		Dim llngSequencia As Integer
		Dim ldteSol As Date
		Dim lstrHorSol As String
		Dim ldteCon As Date
		Dim lstrHorCon As String
		Dim lstrItensserv As String
		Dim lstrSituacao As String
		Dim lstrTipoOS As String
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		Call MontaGrade()
		lstrSql = ""
		lstrSql = lstrSql & "SELECT "
		lstrSql = lstrSql & "       `protocolo`, "
		lstrSql = lstrSql & "       `cod`, "
		lstrSql = lstrSql & "       `zlc`, "
		lstrSql = lstrSql & "       `data_soli`, "
		lstrSql = lstrSql & "       `hora_soli`, "
		lstrSql = lstrSql & "       `datasolu`, "
		lstrSql = lstrSql & "       `horasolu`, "
		lstrSql = lstrSql & "       `itensserv`, "
		lstrSql = lstrSql & "       `sit` "
		lstrSql = lstrSql & "  FROM `solserv` "
		If Me.opbSolicitacao.Checked Then
			lstrSql = lstrSql & " WHERE `data_soli` BETWEEN '" & VB6.Format(Me.dtpSolIni.value, "yyyy-MM-dd") & "' AND '" & VB6.Format(Me.dtpSolFim.value, "yyyy-MM-dd") & "' "
		ElseIf Me.opbConclusao.Checked Then 
			lstrSql = lstrSql & " WHERE `datasolu` BETWEEN '" & VB6.Format(Me.dtpSolIni.value, "yyyy-MM-dd") & "' AND '" & VB6.Format(Me.dtpSolFim.value, "yyyy-MM-dd") & "' "
		End If
		lstrSql = lstrSql & "   AND `sit` IN( "
		If Me.chkAbertas.CheckState = 1 Then
			lstrSql = lstrSql & "'A',"
		End If
		If Me.chkFinalizadas.CheckState = 1 Then
			lstrSql = lstrSql & "'F',"
		End If
		If Me.chkCanceladas.CheckState = 1 Then
			lstrSql = lstrSql & "'C',"
		End If
		lstrSql = VB.Left(lstrSql, Len(lstrSql) - 1)
		lstrSql = lstrSql & ")"
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				If .RecordCount > 0 Then
					Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, .RecordCount)
					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"'
						'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"'
						lstrProtocolo = Trim(IIf(IsDbNull(.Fields("protocolo").value), "", .Fields("protocolo").value))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						'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"'
						llngSequencia = CInt(IIf(IsDbNull(.Fields("cod").value), 0, .Fields("cod").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"'
						'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"'
						ldteSol = CDate(IIf(IsDbNull(.Fields("data_soli").value), "1900-01-01", .Fields("data_soli").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"'
						'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"'
						lstrHorSol = Trim(IIf(IsDbNull(.Fields("hora_soli").value), "", .Fields("hora_soli").value))
						ldteSol = CDate(ldteSol & " " & VB6.Format(lstrHorSol, "hh:MM:ss"))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						'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"'
						ldteCon = CDate(IIf(IsDbNull(.Fields("datasolu").value), "1900-01-01", .Fields("datasolu").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"'
						'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"'
						lstrHorCon = Trim(IIf(IsDbNull(.Fields("horasolu").value), "1900-01-01 00:00:00", .Fields("horasolu").value))
						ldteCon = CDate(ldteCon & " " & VB6.Format(lstrHorCon, "hh:MM:ss"))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						'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"'
						lstrItensserv = Trim(IIf(IsDbNull(.Fields("itensserv").value), "", .Fields("itensserv").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"'
						'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"'
						lstrSituacao = Trim(IIf(IsDbNull(.Fields("sit").value), "A", .Fields("sit").value))
						lstrTipoOS = VB.Left(lstrItensserv, 10)
						If VB.Left(lstrTipoOS, 4) = "9040" Then
							lstrTipoOS = VB.Left(lstrTipoOS, 9) & "1"
						End If
						Call AdicionaGrade(lstrTipoOS, IIf(lstrSituacao = "A", 1, 0), IIf(lstrSituacao = "F", 1, 0), IIf(lstrSituacao = "C", 1, 0))
						Call .MoveNext()
						Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1)
					End While
				End If
				Call .Close()
			End If
		End With
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
		Call PercentualizaGrade()
		Call GravaGrade()
	End Sub
	
	Private Sub AdicionaGrade(ByVal astrTipo As String, ByVal aintAbertas As Short, ByVal aintFinalizadas As Short, ByVal aintCanceladas As Short)
		Dim llngAux As Integer
		Dim llngRow As Integer
		llngRow = 0
		With Me.mfgDados
			For llngAux = 1 To .Rows - 1
				If .get_TextMatrix(llngAux, 0) = astrTipo Then
					llngRow = llngAux
					llngAux = .Rows - 1
				End If
			Next llngAux
			If llngRow = 0 Then llngRow = .Rows - 2
			'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, CShort(IIf(IsNumeric(.get_TextMatrix(llngRow, 2)), .get_TextMatrix(llngRow, 2), 0)) + 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"'
			.set_TextMatrix(llngRow, 4, CShort(IIf(IsNumeric(.get_TextMatrix(llngRow, 4)), .get_TextMatrix(llngRow, 4), 0)) + aintAbertas)
			'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, CShort(IIf(IsNumeric(.get_TextMatrix(llngRow, 6)), .get_TextMatrix(llngRow, 6), 0)) + aintFinalizadas)
			'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, CShort(IIf(IsNumeric(.get_TextMatrix(llngRow, 8)), .get_TextMatrix(llngRow, 8), 0)) + aintCanceladas)
			'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(.Rows - 1, 2, CShort(IIf(IsNumeric(.get_TextMatrix(.Rows - 1, 2)), .get_TextMatrix(.Rows - 1, 2), 0)) + 1)
		End With
	End Sub
	
	Private Sub PercentualizaGrade()
		Dim llngRow As Integer
		Dim lintQtd As Short
		With Me.mfgDados
			For llngRow = 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"'
				lintQtd = CShort(IIf(IsNumeric(.get_TextMatrix(llngRow, 2)), .get_TextMatrix(llngRow, 2), 0))
				If lintQtd > 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, 3, FormatNumber((lintQtd / CShort(IIf(IsNumeric(.get_TextMatrix(.Rows - 1, 2)), .get_TextMatrix(.Rows - 1, 2), 0))) * 100, 2))
				End If
				'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"'
				lintQtd = CShort(IIf(IsNumeric(.get_TextMatrix(llngRow, 4)), .get_TextMatrix(llngRow, 4), 0))
				If lintQtd > 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, 5, FormatNumber((lintQtd / CShort(IIf(IsNumeric(.get_TextMatrix(.Rows - 1, 2)), .get_TextMatrix(.Rows - 1, 2), 0))) * 100, 2))
				End If
				'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"'
				lintQtd = CShort(IIf(IsNumeric(.get_TextMatrix(llngRow, 6)), .get_TextMatrix(llngRow, 6), 0))
				If lintQtd > 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, FormatNumber((lintQtd / CShort(IIf(IsNumeric(.get_TextMatrix(.Rows - 1, 2)), .get_TextMatrix(.Rows - 1, 2), 0))) * 100, 2))
				End If
				'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"'
				lintQtd = CShort(IIf(IsNumeric(.get_TextMatrix(llngRow, 8)), .get_TextMatrix(llngRow, 8), 0))
				If lintQtd > 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, 9, FormatNumber((lintQtd / CShort(IIf(IsNumeric(.get_TextMatrix(.Rows - 1, 2)), .get_TextMatrix(.Rows - 1, 2), 0))) * 100, 2))
				End If
			Next llngRow
		End With
	End Sub
	
	Private Sub GravaGrade()
		Dim lstrSql As String
		Dim llngRow As Integer
		Call Executar("DELETE FROM `temp_listagem_os` WHERE `nomemaquina` = '" & gstrNmEstacao & "' ")
		lstrSql = ""
		With Me.mfgDados
			lstrSql = "INSERT INTO `temp_listagem_os` VALUES"
			For llngRow = 1 To .Rows - 1
				If .get_TextMatrix(llngRow, 1) <> "Total" Then
					lstrSql = lstrSql & "(""" & gstrNmEstacao & ""","
					lstrSql = lstrSql & " """ & VB6.Format(Me.dtpSolIni.value, "yyyy-MM-dd") & ""","
					lstrSql = lstrSql & " """ & VB6.Format(Me.dtpSolFim.value, "yyyy-MM-dd") & ""","
					lstrSql = lstrSql & " """ & IIf(Me.opbSolicitacao.Checked, "pela data da solicitação", "pela data da conclusão") & ""","
					lstrSql = lstrSql & " """ & .get_TextMatrix(llngRow, 1) & ""","
					'Qtde
					'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"'
					lstrSql = lstrSql & " " & IIf(IsNumeric(.get_TextMatrix(llngRow, 2)), .get_TextMatrix(llngRow, 2), 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"'
					lstrSql = lstrSql & " " & Replace(IIf(IsNumeric(.get_TextMatrix(llngRow, 3)), .get_TextMatrix(llngRow, 3), 0), ",", ".") & ","
					'Abertas
					'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"'
					lstrSql = lstrSql & " " & IIf(IsNumeric(.get_TextMatrix(llngRow, 4)), .get_TextMatrix(llngRow, 4), 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"'
					lstrSql = lstrSql & " " & Replace(IIf(IsNumeric(.get_TextMatrix(llngRow, 5)), .get_TextMatrix(llngRow, 5), 0), ",", ".") & ","
					'Finalizadas
					'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"'
					lstrSql = lstrSql & " " & IIf(IsNumeric(.get_TextMatrix(llngRow, 6)), .get_TextMatrix(llngRow, 6), 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"'
					lstrSql = lstrSql & " " & Replace(IIf(IsNumeric(.get_TextMatrix(llngRow, 7)), .get_TextMatrix(llngRow, 7), 0), ",", ".") & ","
					'Canceladas
					'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"'
					lstrSql = lstrSql & " " & IIf(IsNumeric(.get_TextMatrix(llngRow, 8)), .get_TextMatrix(llngRow, 8), 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"'
					lstrSql = lstrSql & " " & Replace(IIf(IsNumeric(.get_TextMatrix(llngRow, 9)), .get_TextMatrix(llngRow, 9), 0), ",", ".") & "),"
				End If
			Next llngRow
		End With
		lstrSql = VB.Left(lstrSql, Len(lstrSql) - 1)
		Call Executar(lstrSql)
	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 dtpSolIni_Change(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles dtpSolIni.Change
		Me.dtpSolFim.value = CDate(UltimoDiaMes((Me.dtpSolIni.Month), (Me.dtpSolIni.Year)) & "/" & VB6.Format(Me.dtpSolIni.value, "mm/yyyy"))
	End Sub
	
	Private Sub frmRelOrdemServico_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.Return Then
			Call SendKeysA(System.Windows.Forms.Keys.Tab, True)
		ElseIf KeyAscii = System.Windows.Forms.Keys.Escape Then 
			Call cmdFechar_Click(cmdFechar, New System.EventArgs())
		End If
		eventArgs.KeyChar = Chr(KeyAscii)
		If KeyAscii = 0 Then
			eventArgs.Handled = True
		End If
	End Sub
	
	Private Sub frmRelOrdemServico_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		Dim lstrSql As String
		Call CenterForm(Me)
		Me.dtpSolIni.value = BuscaDataBD
		Me.dtpSolFim.value = CDate(UltimoDiaMes((Me.dtpSolIni.Month), (Me.dtpSolIni.Year)) & "/" & VB6.Format(Me.dtpSolIni.value, "mm/yyyy"))
		Call MontaGrade()
		lstrSql = ""
		lstrSql = lstrSql & "CREATE TABLE IF NOT EXISTS `temp_listagem_os`(" & vbCrLf
		lstrSql = lstrSql & "  `nomemaquina`        varchar(255)  default '',          " & vbCrLf
		lstrSql = lstrSql & "  `inicial`            date          default '0000-00-00'," & vbCrLf
		lstrSql = lstrSql & "  `final`              date          default '0000-00-00'," & vbCrLf
		lstrSql = lstrSql & "  `tipo_rel`           varchar(30)   default '',          " & vbCrLf
		lstrSql = lstrSql & "  `tipo_ordem_servico` varchar(70)   default '',          " & vbCrLf
		lstrSql = lstrSql & "  `total`              int(11)       default 0,           " & vbCrLf
		lstrSql = lstrSql & "  `percentual`         double        default 0,           " & vbCrLf
		lstrSql = lstrSql & "  `abertas`            int(11)       default 0,           " & vbCrLf
		lstrSql = lstrSql & "  `perabertas`         double        default 0,           " & vbCrLf
		lstrSql = lstrSql & "  `finalizadas`        int(11)       default 0,           " & vbCrLf
		lstrSql = lstrSql & "  `perfinalizadas`     double        default 0,           " & vbCrLf
		lstrSql = lstrSql & "  `canceladas`         int(11)       default 0,           " & vbCrLf
		lstrSql = lstrSql & "  `percanceladas`      double        default 0)           " & vbCrLf
		Call Executar(lstrSql)
	End Sub
	
	Private Sub MontaGrade()
		Dim lstrId As String
		Dim lstrAx As String
		Dim lstrNome As String
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		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, "Total")
			.set_TextMatrix(0, 3, "%")
			.set_TextMatrix(0, 4, "Abertas")
			.set_TextMatrix(0, 5, "%")
			.set_TextMatrix(0, 6, "Finalizadas")
			.set_TextMatrix(0, 7, "%")
			.set_TextMatrix(0, 8, "Canceladas")
			.set_TextMatrix(0, 9, "%")
			.set_ColWidth(0, 1000)
			.set_ColWidth(1, 4150)
			.set_ColWidth(2, 900)
			.set_ColWidth(3, 900)
			.set_ColWidth(4, 900)
			.set_ColWidth(5, 900)
			.set_ColWidth(6, 900)
			.set_ColWidth(7, 900)
			.set_ColWidth(8, 900)
			.set_ColWidth(9, 900)
		End With
		lstrAx = ""
		lstrSql = "SELECT * FROM `codigos` WHERE ((num BETWEEN 9040000000 AND 9040999999) OR (num BETWEEN 9050000000 AND 9050999999)) ORDER BY num ASC "
		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"'
						'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"'
						lstrId = Trim(IIf(IsDbNull(.Fields("num").value), "0000000000", .Fields("num").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"'
						'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"'
						lstrNome = Trim(IIf(IsDbNull(.Fields("descri").value), "em branco", .Fields("descri").value))
						If VB.Left(lstrId, 4) = "9040" Then
							lstrId = VB.Left(lstrId, 9) & "1"
						End If
						If lstrAx <> lstrId Then
							With Me.mfgDados
								.Rows = .Rows + 1
								.set_TextMatrix(.Rows - 1, 0, lstrId)
								.set_TextMatrix(.Rows - 1, 1, lstrNome)
							End With
							lstrAx = lstrId
						End If
						Call .MoveNext()
					End While
					With Me.mfgDados
						.Rows = .Rows + 1
						.set_TextMatrix(.Rows - 1, 0, "")
						.set_TextMatrix(.Rows - 1, 1, "Total")
					End With
				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
End Class