miércoles, 7 de octubre de 2015

Recta Final

Actualmente se crearon diferentes SP para hacer la conexion con la capa lógica mas sencilla.
Algunos códigos hechos para la conexión sencilla fueron:

El SP Addposition ayuda a que el usuario pueda ingresar de manera fácil la posición que quedo en la carrera, a su vez, facilmente se puede determinar el corredor y la carrera.
En la aplicación no se debe ingresar la posición del corredor ya que lo va auto incrementando
CREATE procedure [dbo].[addposition]
@Email varchar(50),
@Race varchar(50),
@time datetimeoffset(7)
as
begin
declare @ID int;
declare @IDRace int;
declare @IDRunner int;
declare @position int;
select @ID=max(P.ID)+1 from Positions P
select @IDRace=R.ID from Races R where R.Name=@Race
select @IDRunner=Ru.ID from Runners Ru where Ru.Email=@Email
select  @position=ISNULL(Max(P.Position),0)+1 from Positions P
inner join Races R on P.FK_Races=R.ID where R.ID=@IDRace

 INSERT INTO dbo.Positions(ID,ET_Time,FK_Races,FK_Runners,Position)
VALUES (@ID,@time,@IDRace,@IDRunner,@position)

end

GO
Tiempo de trabajo: 20 minutos

SP para determinar si un corredor esta descalificado:
CREATE PROCEDURE [dbo].[SP_Disqualify]
-- Add the parameters for the stored procedure here
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

    UPDATE RunnersXChallenge
SET FK_Status = 1
WHERE AcumPunishPts > 30
END

GO
Tiempo de trabajo: 10 minutos

El Stored Procedure que muestra que concursante no asiste a diferentes carreras

CREATE procedure [dbo].[SP_ReportNotParticipate]
@Email varchar(50),
@Challenge varchar(50)
as
begin
declare @IDChallenge int;
select  @IDChallenge=C.ID from Challenge C where C.Name=@Challenge

select R.Name from Races R inner join Challenge C on R.FK_Challenge=C.ID where C.ID=@IDChallenge
EXCEPT
select   R.Name  from Races R inner join Positions P on R.ID=P.FK_Races
inner join Runners Ru on Ru.ID=P.FK_Runners where Ru.Email=@Email
end
GO
Tiempo de trabajo: 15 minutos
Link de referencia: https://msdn.microsoft.com/es-es/library/ms188055(v=sql.120).aspx

Stored Procedure el cual agrega un castigo a los corredores:
Create Procedure [dbo].[SP_PunishmentsADD]
 @NameRaces varchar(50),
 @NamePunish varchar(50),
 @Email varchar(50),
 @Points int
 as
 begin
 declare @ID int;
 declare @IDRace int;
 declare @IDRunner int;
 declare @IDPunish int;
 select @ID=max(Pu.ID)+1 from Punishments Pu
 select @IDRace=R.ID from Races R
 where R.Name=@NameRaces
 select @IDPunish=PuT.ID from PunishmentType PuT
 where PuT.Name=@NamePunish
 select @IDRunner=Ru.ID from Runners Ru
 where Ru.Email=@Email
 insert into Punishments (ID,Points,FK_Races,FK_PunishmentType,FK_Runners)
 Values (@ID,@Points,@IDRace,@IDPunish,@IDRunner)
 end
GO
Tiempo de trabajo: 20 minutos

Stored Procedure que determinaba que carreras podía acceder el corredor:

CREATE procedure [dbo].[SP_whatRace]
@Email varchar(50)
as
begin
select distinct R.name from Runners RU
inner join RunnersXChallenge RXC on RU.ID=RXC.FK_Runners
inner join Challenge C on C.ID=RXC.FK_Challenge
inner join Races R on R.FK_Challenge=C.ID
where RU.Email=@Email
end

GO
Tiempo de trabajo: 15 minutos

Stored Procedure el cual permitia inscribir a un corredor a los campeonatos:

CREATE procedure [dbo].[SP_enrollinChallenge]
 @Email varchar(50),
 @challenge varchar(50)
 as
 begin
declare @FK_Challenges int;
declare @FK_Runner int;
declare @MaxNumber int;
declare @MaxID int;

select DISTINCT @FK_Runner=R.ID from Runners R where R.Email=@Email
select DISTINCT @FK_Challenges=C.ID from Challenge C where C.Name=@challenge
select @MaxNumber=max(CONVERT(INT, RxC.Number))+1 from RunnersXChallenge RxC where RxC.FK_Challenge=@FK_Challenges
select @MaxID=MAX(RxC.ID)+1 from RunnersXChallenge RxC
INSERT INTO dbo.RunnersXChallenge(ID,Number,AcumTime,AcumPoints,AcumPunishPts,FK_Challenge,FK_Runners,FK_Status,AcumPointsAuthorized,AcumPunishPtsAuthorized)
VALUES (@MaxID,@MaxNumber,default,0,0, @FK_Challenges, @FK_Runner,0,0,0)
end

GO

Tiempo de trabajo: 20 minutos


No hay comentarios:

Publicar un comentario