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

dim int_folio, str_proceso
dim STR_CONSULTA, RES_DATOS, Cnn, int_res(30), 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 30
	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, RC1, RC2, RC3, RC4, RC5, RC6, RC7, RC8, RC9, RC10, RC11, RC12, RC13, RC14, RC15, RC16, RC17, RC18, RC19, RC20, RC21, RC22, RC23, RC24, RC25, RC26, RC27, RC28, RC29, RC30)"_ 
		&" 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) & ", "_
		&" " &  int_res(21) & "," &  int_res(22) & "," &  int_res(23) & "," &  int_res(24) & "," &  int_res(25) & "," &  int_res(26) & "," &  int_res(27) & "," &  int_res(28) & "," &  int_res(29) & "," &  int_res(30) & ")"
		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 RC1 =" & int_res(1) & ", RC2 =" & int_res(2) & ", RC3 =" & int_res(3) & ", RC4 =" & int_res(4) & ","_
		& " RC5 =" & int_res(5) & ", RC6 =" & int_res(6) & ", RC7 =" & int_res(7) & ", RC8 =" & int_res(8) & ", RC9 =" & int_res(9) & ", RC10 =" & int_res(10) & ", RC11 =" & int_res(11) & ","_
		& " RC12 =" & int_res(12) & ", RC13 =" & int_res(13) & ", RC14 =" & int_res(14) & ", RC15 =" & int_res(15) & ", RC16 =" & int_res(16) & ", RC17 =" & int_res(17) & ", RC18 =" & int_res(18) & ", RC19 =" & int_res(19) & ", RC20 =" & int_res(20)& ","_
		& " RC21 =" & int_res(21) & ", RC22 =" & int_res(22) & ", RC23 =" & int_res(23) & ", RC24 =" & int_res(24) & ", RC25 =" & int_res(25) & ", RC26 =" & int_res(26) & ", RC27 =" & int_res(27) & ", RC28 =" & int_res(28) & ", RC29 =" & int_res(29) & ", RC30 =" & int_res(30) & " 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("term4_instruccion.asp")
end if
%>
