<%@ Language=VBScript %>
<!--#INCLUDE file="ADOVBS.inc"-->
<%

dim int_folio, str_proceso
dim STR_CONSULTA, RES_DATOS, Cnn, int_res(20), STR_SALIR


str_bd= application("bd_sieps")

set Cnn = server.CreateObject ("ADODB.Connection")
set RES_DATOS = server.CreateObject ("ADODB.Recordset")

Cnn.Open str_bd
   
int_folio = Request.QueryString("folio")
str_proceso = Request.QueryString("proceso")
STR_SALIR= Request.Form("SALIR")

for i=1 to 20
	int_numero=0
	for j=1 to 2
		if Request.Form("r"&i&"-"&j)="on" then
			int_numero =J	
		end if
	next
	int_res(i)=int_numero
next



if str_proceso="alta" then ' si es una alta
	STR_CONSULTA = "SELECT * FROM dat_terman WHERE soli_folio =" & int_folio
	RES_DATOS.Open STR_CONSULTA, Cnn,adOpenForwardOnly,adLockReadOnly,1
	IF RES_DATOS.EOF = true then ' si no existe
		Cnn.BeginTrans
		STR_CONSULTA = "INSERT INTO dat_terman (soli_folio, RF1, RF2, RF3, RF4, RF5, RF6, RF7, RF8, RF9, RF10, RF11, RF12, RF13, RF14, RF15, RF16, RF17, RF18, RF19, RF20)"_ 
		&" VALUES(" & int_folio & "," &  int_res(1) & "," &  int_res(2) & "," &  int_res(3) & "," &  int_res(4) & "," &  int_res(5) & "," &  int_res(6) & "," &  int_res(7) & "," &  int_res(8) & "," &  int_res(9) & "," &  int_res(10) & ", "_
		&" " &  int_res(11) & "," &  int_res(12) & "," &  int_res(13) & "," &  int_res(14) & "," &  int_res(15) & "," &  int_res(16) & "," &  int_res(17) & "," &  int_res(18) & "," &  int_res(19) & "," &  int_res(20) & ")"
		Cnn.Execute STR_CONSULTA,,1
		Cnn.CommitTrans
	END IF
	RES_DATOS.Close
elseif str_proceso="cambio" then  ' si es un cambio
	Cnn.BeginTrans
	STR_CONSULTA = "SELECT * FROM dat_terman WHERE soli_folio =" & int_folio
	RES_DATOS.Open STR_CONSULTA, Cnn,adOpenForwardOnly,adLockReadOnly,1
	IF RES_DATOS.EOF = false then
		STR_CONSULTA = "UPDATE dat_terman SET RF1 =" & int_res(1) & ", RF2 =" & int_res(2) & ", RF3 =" & int_res(3) & ", RF4 =" & int_res(4) & ","_
		& " RF5 =" & int_res(5) & ", RF6 =" & int_res(6) & ", RF7 =" & int_res(7) & ", RF8 =" & int_res(8) & ", RF9 =" & int_res(9) & ", RF10 =" & int_res(10) & ", RF11 =" & int_res(11) & ","_
		& " RF12 =" & int_res(12) & ", RF13 =" & int_res(13) & ", RF14 =" & int_res(14) & ", RF15 =" & int_res(15) & ", RF16 =" & int_res(16) & ", RF17 =" & int_res(17) & ", RF18 =" & int_res(18) & ", RF19 =" & int_res(19) & ", RF20 =" & int_res(20)& " WHERE soli_folio =" & int_folio
		Cnn.Execute STR_CONSULTA,,1
	END IF
	RES_DATOS.Close
	Cnn.CommitTrans
end if
Cnn.Close
IF STR_SALIR ="SALIR" then
	Response.Redirect("aplicacion_termina.asp")
else
	Response.Redirect("term7_instruccion.asp")
end if
%>
