Updating an ASP.NET website without the source code
March 6, 2012 Leave a comment
I went back into the website of a girls lacrosse team to update it for the 2012 season. The problem is that the source code is gone – it got deleted when I moved my TFS machine to Win7 and the backup failed (another good reason to use an on-line repro).
I thought I would have to recreate the entire solution/project when I realized that the code I need to change is the markup for the .aspx pages themselves. For example, here is 1 SqlDataSource (SDS) that I used:
<asp:SqlDataSource ID="SqlDataSourcePlayers" runat="server" ConnectionString="<%$ ConnectionStrings:DB_15641_mpmslaxConnectionString %>" SelectCommand="Girls_SelectActivityPlayers" SelectCommandType="StoredProcedure"> <SelectParameters> <asp:Parameter DefaultValue="8" Name="ActivityId" Type="Int32" /> </SelectParameters>
Note the DefaultValue of the ActivityId Parameter – it was 6 for last spring season, I had to change it to 8 for this season. So all I did was open up the .aspx file in notepad via my FTPProgram, change the Parameter and voila, the data is correct.
I then hit a roadblock when I went to another page. In that page, I used an ObjectDataSource that referenced a factory class that I created to do so data flattening – taking all of the girls in a single carpool and putting their names into a single string, for example. Instead of re-creating that Factory, I swopped out the ODS for a SDS and mimicked the factory’s functionality a stored procedure. Heck, I even mirrored the misspellings in the output parameters so I wouldn’t have to change the grid view. I haven’t done much TSQL in the last couple of years, but it is amazing how fast it comes back:
Create procedure Girls_SelectCarpoolSummary @carpoolId int As declare @riders varchar(1000) set @riders = '' select @riders = @riders + FirstName + ' ' + LastName + ', ' from [Girls.Player] as P inner join [Girls.CarpoolLegPlayer] as CLP on P.PlayerId = CLP.PlayerId inner join [Girls.CarpoolLeg] as CL on CLP.CarpoolLegId = CL.CarpoolLegId where CL.CarpoolId = @carpoolId and CL.CarpoolLegTypeId = 1 declare @leaveTime varchar(7) set @leaveTime = '' select @leaveTime = Right(CONVERT(varchar(100), CL.CarpoolLegStartTime, 100),7) from [Girls.CarpoolLeg] as CL where CL.CarpoolId = @carpoolId and CL.CarpoolLegTypeId = 1 declare @returnTime varchar(7) set @returnTime = '' select @returnTime = Right(CONVERT(varchar(100), DateAdd(hh,3,CL.CarpoolLegStartTime), 100),7) from [Girls.CarpoolLeg] as CL where CL.CarpoolId = @carpoolId and CL.CarpoolLegTypeId = 1 Select C.CarpoolId, TE.EventDescription + ' ' + CONVERT(varchar(100), C.CarpoolDate, 101) as CarpoolDescription, T.FirstName + ' ' + LastName as Drivers, @riders as Riders, @leaveTime as LeaveTime, @returnTime as ReturnTime From [Girls.Carpool] as C inner join [Girls.TeamEvent] as TE on C.TeamEventId = TE.TeamEventId inner join [Girls.CarpoolLeg] as CL on C.CarpoolId = CL.CarpoolId inner join [Girls.Parent] as T on CL.ParentId = T.ParentId Where C.CarpoolId = @carpoolId and CL.CarpoolLegTypeId = 1 GO
Notice the flattening for the @riders variable.
I then had to update the summary page to show ALL of the upcoming carpools in a single grid – so I needed a stored procedure to call this one many times (I thought about changing this sp to a function but I didn’t). Temp tables to the rescue:
Create procedure Girls_SelectUpcommingCarpoolSummaries As Select * into #UpcommingCarpools From [Girls.Carpool] as C Where DateDiff(d,getdate(),CarpoolDate) >= 0 CREATE TABLE #UpcommingCarpoolSummaries ( CarpoolId int, CarpoolDescrpition varchar(8000), Drivers varchar(1000), Riders varchar(8000), LeaveTime varchar(10), ReturnTime varchar(10) ) Declare @carpoolId int While (Select Count(*) From #UpcommingCarpools) > 0 Begin Select Top 1 @carpoolId = carpoolId From #UpcommingCarpools INSERT INTO #UpcommingCarpoolSummaries Exec Girls_SelectCarpoolSummary @carpoolId Delete #UpcommingCarpools Where carpoolId = @carpoolId End Select * from #UpcommingCarpoolSummaries GO
The thing is, it worked. I have no covering unit tests. I used about 85 lines of TSQL when 15 lines of C# would have done the trick. But it worked. I feel so dirty…..