He can drink, but can he code?
There was a time where I was known for being able to write some kick ass code. When I was 23 years old I use to stay up all night coding and then write an article about it. Id like to think that I am older and wiser. Now I am more concerned with my 10K splits in the 40K bike event. But it seems that my old age is catching up with me, because now I have more of a reputation for partying and drinking. First Eileen Crain put me in charge of the party at TechED in Dallas and now Scott Hanselman today called me his hero, not because I can code, but because I can drink (just click on his name and see what I am talking about). So I feel that I have to rebut a little, I mean come on cut me some slack, I HAVE written code that BillG has demoed!
First of all, my internal clock is screwed up. As you all know I am in training for some triathlons. I have been getting up way too early to run in the park to run with a new running partner. She has to be back home at, yes, so I get up at 5:20 to start running at 5:45 with her. (Kathleen please quit your job so we can run later in the day.) Why do I run with her? Well she is FAST but also very motivated and it is hard to find a partner willing to run in the rain and such (ok, ok she is pretty damn cute too.) But this presents a problem for me. I am not an early bird. But I am also a light sleeper so I can't go back to sleep. So I spent from to aboutjust coding my brains out (no email or IM); then burnt out and did nothing but eat, IM people and rollerblade in the park all day. (Also had a huge 9oz Wyoming juicy burger with my lead dev, Al Cadalzo (who paid!), for lunch at Jackson Hole,). But I digress, so let's review my Monday morning:
I started with a few thousand lines of TSQL code (like every Monday nowadays it seems) and automated my company's data push of some new data. Basically I have to grab some data, compare it to other data, generate mathematical factors and then apply those factors and transform the data for the transformation to the web. Because my pal Richard Campbell is such a pain in the ass, I could not use a cursor. So basically I had to use some temp tables and local variables. I got something in the end that looks like this (after all the temp tables and such), the damn casting really stole about 15 minutes of my life that I can never get back:
Select @CBFactor = @CBTotal_Factor/@CBTotal_UnFactor
Select @HJFactor = @HotJobsTotal_Factor/@HotJobsTotal_UnFactor
SET RPT_RCMS13_Detail.CareerBuilder = [CareerBuilder]*@CBFactor,
RPT_RCMS13_Detail.HotJobs = [HotJobs]*@HJFactor
Insert Into dbo.RPT_RCMS14_Detail
Select Weekending_ID, Weekending_DT, Location_ID, WebSubLocation_ID,Location_NM, WebSubLocation_NM, CAST(CAST(CareerBuilder AS real) / CAST(TotalAmt
AS real) AS decimal(6, 3)) * 100 as CareerBuilderPer,
CAST(CAST(HotJobs AS real) / CAST(TotalAmt AS real) AS decimal(6, 3)) * 100 AS HotJobsPer, CAST(CAST(Monster AS real) / CAST(TotalAmt AS real) AS decimal(6, 3)) * 100 AS MonsterPer, CAST(CAST(LocalNewsPaper1 AS real) / CAST(TotalAmt AS real) AS decimal(6, 3)) * 100 AS LocalNewsPaperPer1, LP1_Name, CAST(CAST(LocalNewsPaper2
AS real) / CAST(TotalAmt AS real) AS decimal(6, 3)) * 100 AS LocalNewsPaperPer2, LP2_Name
Ok, enough with the damn TSQL. TSQL is for babies. That was just to wake me up after my 8 mile run (yes 8 miles, 1.5 miles to meet Kathleen, 5 miles with her and 1.5 miles back home-how long until the Ironman?). Here was what grew some hair on my chest:
Jonathan Zuck drafted me to help ACT get their website online (like a friggin year ago). I could not say no since ACT has put me before Congress at least 4 or 5 times and introduced me to Heather Davisson, a DAR to my SAR as well as a fellow Scott and she likes to splurge and take me to lunch at Jean-Georges to the envy of all my friends (but I once had to take photos of Mike Piazzas butt for her).
Anyway, I did the site in C# and so far so good. We went live today. So I had to use a data repeater on this page on the left nav (well it is a user control so I can take advantage of fragmented caching since the data is loaded dynamically and the data is not that dynamic). But the problem is that the SQL returns repeating information for each row and we dont want it to repeat in the nav hierarchy. I was way too lazy to do some funky TSQL (I know for wimps), so I decided to take the C# approach on the server. I have to use a data repeater and hide the title for each repeating row. So I would have to programmatically make invisible some client side HTML code on the server. I had to play with the data repeater template and basically make the HTML <tr> element that I want to conditionally hide run on the server (runat=server) so I can manipulate it programmatically on the server ItemEvent. It is real easy once you figure it all out. You set the HTML table row <tr> up with a unique ID (trheader ) and a runat=server. Then on the ItemEvent handler (my method RepeaterSkip) I grab the current data row by intercepting the binding and then compare that to the module level static variable, if they are the same, I make the row (<tr>) invisible, if not, I live and let live and stuff the current value to skip on the next row into the module variable for comparison on the next fireing of the event.
Here is my repeater:
<asp:repeater id="Repeater1" runat="server">
<tr id="testid" runat=server>
<td width="126" colSpan="2" height="9"><b>"><%# DataBinder.Eval(Container.DataItem, "IssueCat") %></font></b></td>
<td width="2" height="9"></td>
<td width="6" height="9"><IMG height="1" src="images/onepixel.gif" width="6"></td>
<td width="116" height="9"><A class="toc" href='issue.aspx?IssueID=<%#DataBinder.Eval(Container.DataItem, "Issue_ID") %>'>
<%# DataBinder.Eval(Container.DataItem, "Issue_DS") %></A></td>
<td width="2" height="9"></td>
So the event that fires is handled by the RepeaterSkip (inside a user control) method I wrote:
private void RepeaterSkip(Object sender, RepeaterItemEventArgs e)
//This is going to fire for the <ItemTemplate> items only
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
//get the data that is in the current record
//and stuff it into a DataRecord
DbDataRecord dbr = (DbDataRecord) e.Item.DataItem;
//Get the current value of the item being databound
strCatID = dbr["Cat_ID"].ToString();
//compare to the module static variable and if the same
//make the HTML invisible
//My HTML has this in it: <tr id="testid" runat=server>
((System.Web.UI.HtmlControls.HtmlTableRow)e.Item.FindControl("trheader")).Visible = false;
//now make the module variable the same as the current item
m_strCatID = strCatID;
private void LoadLeftNav ()
//fill the repeater
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand cmd = new SqlCommand("usp_SEL_IssueMenu",conn);
//get the issue information
Lastly, my pal Tom Halligan (who is stuck in Access-land) emailed me asking: "Hey is there a command I can use to close all open forms at once?"
He wanted to use an Access macro! God forbid! He wants to understand VBA, so I had to write it for him. So I wrote this in-between thinking about my datarepeater and wishing I were asleep, VBA is so much fun sometimes:
'why the f**k do you need a macro silly boy?
'remember that i am harmless!
Dim frm As Form
'loop through all open forms
For Each frm In Application.Forms
'close the current form
DoCmd.Close acForm, frm.Name, acSaveYes
'check out my new car: http://autos.yahoo.com/newcars/details/porsche03911turbo/model_overview.html?refsrc=autos/home
He responded (I think mostly to my calling my insurance company to price how much the new Porsche 911 Turbo I am buying will cost me in insurance):
Thanks. You have issues
Maybe I do.