== Descripción ==
== Biblioteca ==
== Composición ==
== Código ==
<small><pre>
</pre></small>
== Bitácora ==
*20120914
**Cambio por rediseño [[FORM:Presupuesto]]
<small><pre>
Sub EventoBRCDetallePresupuesto (oEvent as Object)

Dim oDocument as Object
Dim oForm as Object
Dim oSubForm as Object
Dim oSubSubForm as Object
Dim oSubSubFormGrid as Object
Dim SQLStatement as Variant
Dim oNombreImpControlador as String
Dim oNombreImpFormularios as String
Dim oVidQuoteProdID as String
Dim aVidQuoteProdID as String
Dim oMensaje as String
Dim verifica
Dim strSQLSearch as String
Dim oContadorRegistros as Double

	'MsgBox("EventoBRCDetallePresupuesto: Inicio")
	oDocument = ThisComponent
	oForm = ThisComponent.Drawpage.Forms.getByName("Cabecera")  
	oSubForm = oForm.getByName("CabeceraAmpliada").getByName("DetallePresupuesto")
	oSubSubForm = oSubForm.getByName("DetalleProducto")
	oSubSubFormGrid = oSubSubForm.getByName("DetalleProductoGrid")  
	oNombreImpControlador="org.openoffice.comp.svx.FormController"
	oNombreImpFormularios="com.sun.star.comp.forms.ODatabaseForm"

	If (oEvent.Source.ImplementationName=oNombreImpFormularios) Then
	  	'MsgBox("oEvent.Source.ImplementationName=oNombreImpFormularios")
		'if oEvent.Source.Row = 0 Then
	    if oEvent.Source.RowCount = 0 Then
		    oMensaje="First Time Call in Loading: "
		    oMensaje=oMensaje & oEvent.Source.ImplementationName
		    'MsgBox(oMensaje)
	    else
	    	'MsgBox("oEvent.Source.RowCount != 0")
			if oEvent.Source.RowCount > 0 Then
			   
				'Read of current RowSet from DetallePresupuesto
				if oEvent.Source.Row <> 0 Then 'First Read of Data
					'MRI oSubForm
					oVidQuoteID=oSubForm.Columns.getByName("VidQuoteID").getInt()
					oVidQuoteLPre=oSubForm.Columns.getByName("VidQuoteLPre").getInt()
					oVidQuoteItem=oSubForm.Columns.getByName("VidQuoteItem").getInt()
					oVidQuoteProdID=oSubForm.Columns.getByName("VidQuoteProdID").getString()
					oVidQuoteProdCantidad=oSubForm.Columns.getByName("VidQuoteProdCantidad").getInt()
					oVidQuoteAncho=oSubForm.Columns.getByName("VidQuoteAncho").getInt()
					oVidQuoteAlto=oSubForm.Columns.getByName("VidQuoteAlto").getInt()
			
					Select Case oEstadoRegistroDetallePresupuesto
					    Case 1		'It is an Elements massive insert
							'VidQuoteN3	massive insert
							'MsgBox("BP001")
							oConnection = oEvent.Source.ActiveConnection
							SQLStatement = oConnection.preparestatement("CALL AltaItemPresupuesto (?,?,?,?,?,?,?)")
							SQLStatement.setint(1,oVidQuoteID)
							SQLStatement.setint(2,oVidQuoteLPre)
							SQLStatement.setint(3,oVidQuoteItem)
							SQLStatement.setstring(4,oVidQuoteProdID)
							SQLStatement.setstring(5,oVidQuoteProdCantidad)	    
							SQLStatement.setint(6,oVidQuoteAncho)
							SQLStatement.setint(7,oVidQuoteAlto)
							SQLStatement.execute()
							SQLStatement.close()
							
							'VidQuoteN4 massive insert
							oMensaje = ""
							oMensaje = oMensaje & "BP002"
							oMensaje = oMensaje & "Presupuesto: " & CStr(oVidQuoteID) & Chr(13)
							oMensaje = oMensaje & "Item       : " & CStr(oVidQuoteItem) & Chr(13)
							oMensaje = oMensaje & "Producto   : " & oVidQuoteProdID & Chr(13)
							oMensaje = oMensaje & "Elemento   : " & "12345678" & Chr(13)
							'MsgBox(oMensaje)
							
							SQLStatement = oConnection.preparestatement("CALL AltaParamItemPresupuesto (?,?,?,?,?)")
							SQLStatement.setint(1,oVidQuoteID)
							SQLStatement.setint(2,oVidQuoteItem)
							SQLStatement.setstring(3,oVidQuoteProdID)
							SQLStatement.setstring(4,"12345678")
							'Set pCondicion for Procedure Inheritance depending on previous REM	    
							SQLStatement.setint(5,2)
							'
							SQLStatement.execute()
							'MsgBox("BP003")
							SQLStatement.close()
				
						Case 2		'It is an Product Quote Data update
							strSQLSearch = "SELECT Count(*) FROM vidquoten3 WHERE "
							strSQLSearch = strSQLSearch & "VidQuoteID=" & CStr(oVidQuoteID)
							strSQLSearch = strSQLSearch & " AND "
							strSQLSearch = strSQLSearch & "VidQuoteItem=" & CStr(oVidQuoteItem)
							
							oConnection = oEvent.Source.ActiveConnection       
							SQLStatement = oConnection.createStatement()
							verifica = SQLStatement.executeQuery(strSQLSearch)
							verifica.Next()						'Lee la primera línea del query
							oContadorRegistros=verifica.GetDouble(1)			'Valor Anterior
							SQLStatement.close()
				
							if oContadorRegistros > 0 Then
							
								strSQLSearch = "SELECT VidQuoteProdID FROM vidquoten3 WHERE "
								strSQLSearch = strSQLSearch & "VidQuoteID=" & CStr(oVidQuoteID)
								strSQLSearch = strSQLSearch & " AND "
								strSQLSearch = strSQLSearch & "VidQuoteItem=" & CStr(oVidQuoteItem)
								strSQLSearch = strSQLSearch & " GROUP BY VidQuoteID,VidQuoteItem"
							
								oConnection = oEvent.Source.ActiveConnection        
							    SQLStatement = oConnection.createStatement()
							    verifica = SQLStatement.executeQuery(strSQLSearch)
							    verifica.Next()						'Lee la primera línea del query
							    aVidQuoteProdID=verifica.GetString(1)			'Valor Anterior
							    SQLStatement.close()		 
							 
							    if aVidQuoteProdID <> oVidQuoteProdID Then 	'Check if the same product code
							    
									'Delete previous records due to change product code
								  			
									strSQLSearch = "DELETE FROM vidquoten3 WHERE "
									strSQLSearch = strSQLSearch & "VidQuoteID=" & CStr(oVidQuoteID)
									strSQLSearch = strSQLSearch & " AND "
									strSQLSearch = strSQLSearch & "VidQuoteItem=" & CStr(oVidQuoteItem)
									oConnection = oEvent.Source.ActiveConnection
									SQLStatement = oConnection.createStatement()
									SQLStatement.executeUpdate(strSQLSearch)
									SQLStatement.close()
									
									'Insert New records -Elements- with new Quote Product Code
									
									oConnection = oEvent.Source.ActiveConnection
									SQLStatement = oConnection.preparestatement("CALL AltaItemPresupuesto (?,?,?,?,?,?,?)")
									SQLStatement.setint(1,oVidQuoteID)
									SQLStatement.setint(2,oVidQuoteLPre)
									SQLStatement.setint(3,oVidQuoteItem)
									SQLStatement.setstring(4,oVidQuoteProdID)
									SQLStatement.setstring(5,oVidQuoteProdCantidad)
									SQLStatement.setint(6,oVidQuoteAncho)
									SQLStatement.setint(7,oVidQuoteAlto)
									SQLStatement.execute()
									SQLStatement.close()
									
									'VidQuoteN4 massive insert with new Quote Product Code
									
									SQLStatement = oConnection.preparestatement("CALL AltaParamItemPresupuesto (?,?,?,?,?)")
									SQLStatement.setint(1,oVidQuoteID)
									SQLStatement.setint(2,oVidQuoteItem)
									SQLStatement.setstring(3,oVidQuoteProdID)
									SQLStatement.setstring(4,"12345678")	    
									SQLStatement.setint(5,2)
									SQLStatement.execute()
									SQLStatement.close()
							
							    else
							   		'It is the same Product Code. Update VidQuoten3 Columns except Product Code
							   		
									'strSQLSearch = ""
									'strSQLSearch = strSQLSearch & "UPDATE vidquoten3 AS T3 SET "
									'strSQLSearch = strSQLSearch & "T3.VidQuoteProdCantidad = " & CStr(oVidQuoteProdCantidad) & ","			
									'strSQLSearch = strSQLSearch & "T3.VidQuoteAncho = " & CStr(oVidQuoteAncho) & ","
									'strSQLSearch = strSQLSearch & "T3.VidQuoteAlto = "  & CStr(oVidQuoteAlto) & ","
									'strSQLSearch = strSQLSearch & "T3.VidQuotePrecio = CalculaPrecioBase(T3.VidQuoteProdID,T3.VidQuoteElementoID,"&CStr(oVidQuoteAncho)&","&CStr(oVidQuoteAlto)&",T3.VidQuoteLPre),"
									'strSQLSearch = strSQLSearch & "T3.VidQuotePrecioP = CalculaPrecioBase(T3.VidQuoteProdID,T3.VidQuoteElementoID,"&CStr(oVidQuoteAncho)&","&CStr(oVidQuoteAlto)&",T3.VidQuoteLPre) * "&CStr(oVidQuoteProdCantidad)
									'strSQLSearch = strSQLSearch & " WHERE "
									'strSQLSearch = strSQLSearch & "VidQuoteID=" & CStr(oVidQuoteID)
									'strSQLSearch = strSQLSearch & " AND "
									'strSQLSearch = strSQLSearch & "VidQuoteItem=" & CStr(oVidQuoteItem)
									
									oConnection = oEvent.Source.ActiveConnection
									SQLStatement = oConnection.createStatement()
									SQLStatement = oConnection.preparestatement("CALL ActualizaPreciosProductoProposal(?,?,?,?,?,?,?)")
									SQLStatement.setint(1,oVidQuoteID)
									SQLStatement.setint(2,oVidQuoteLPre)
									SQLStatement.setint(3,oVidQuoteItem)
									SQLStatement.setstring(4,oVidQuoteProdID)
									SQLStatement.setint(5,oVidQuoteProdCantidad)
									SQLStatement.setint(6,oVidQuoteAncho)
									SQLStatement.setint(7,oVidQuoteAlto)
									SQLStatement.execute()
									'SQLStatement.executeUpdate(strSQLSearch)
									SQLStatement.close()
								end if
								MsgBox("Recuerde revisar/actualizar valores adicionales")
							end if
							'MsgBox("Fin IF Nº4")
						Case 3
							'MsgBox("Elimina"). Design and Complete MakingUp by TriggerTiger
					end Select
				end if
				oEstadoRegistroDetallePresupuesto=0
				'MsgBox("Fin Case")
			end if
			'MsgBox("Fin IF Nº3")
		end if
		'MsgBox("Fin IF Nº2")
	end if
	'MsgBox("EventoBRCDetallePresupuesto: Fin")
end Sub
</pre></small>
== Uso ==
*[[FORM:Presupuesto]]