I know, really??? In a programming blog??? Yes.
Blogs are intended for the writer to post information they are passionate about and, while they normally are grouped by subject matter, they don’t have to be.
Being a Canton, Ohio, native and an avid Cleveland sports fan, I’ve read and followed the whole LeBron story since its inception – back before Shaq showed up in Canton to watch LBJ play a high school game. I truly hope that LeBron finds this, reads it and understands the message.
LeBron’s ultimate goal is to be the best player ever in his sport. It is the underlying goal of any athlete but is not verbalized by most athletes that participate in a team sport because that is not what team players do. LeBron had all of the pieces falling into place to dethrone Michael Jordan – a rabid fan base, an owner that didn’t mind spending capital, an organization that functioned like a family, etc. Many already considered him better than Jordan but a lot of critics pointed to the absence of rings as a key determination of “greatness”. With this in mind, LBJ made his decision to chase the rings and, therefore, has sealed his fate of never being able to escape Jordan’s shadow.
Why? A true student of the game wouldn’t need to ask that question. LBJ can 5-peat with the Heat and even go 5 years undefeated and still never be considered better than Jordan in any serious basketball circle because now the determination of “greatness” will be “…Jordan didn’t have to chase his rings – he was great enough to bring them to him.”
The Bulls in the early Jordan years were terrible but Jordan didn’t leave Chicago to get his rings when critics claimed he wasn’t the greatest because he didn’t have any. He stayed in Chicago and did it with less star power than the 2009 Cavaliers had given LBJ. While I am not a fan of Kobe, I have to admit that he has a chance to dethrone Jordan because he has the numbers, the rings and the talent because he brought the titles back to LA after Shaq left.
Another key fact that most true students of the game will point out – it was Jordan’s Bulls. Miami will always be Wade’s. And the “King”? Just a Jester now.
While Dan Gilbert should have slept on his letter to the fans before releasing it, he did hit the nail on the head and state the obvious fact that all Cavalier fans were afraid to verbalize publically – LBJ quit in the Boston series. His teammates knew it, too, which is why everyone gave up in the 6th game. Before anyone tries to argue that fact, watch the games again; listen to the post game comments by LeBron.
This whole thing was determined at least 2 years ago when all 3 “superstars” signed their short term contracts. Since that time, the only thing unknown by them was which team would host them. If you come to that conclusion as well, then you can also argue LBJ tried to throw the Bulls series with the mysterious “elbow injury” that could never be proven. If you get there, then the next logical step is to call out David Stern to investigate.
I came across an interesting scenario: I needed to email a datatable, or rather, the contents of one.
I thought it would be a common task so I googled it, and googled it, and googled it. There were a lot of solutions that centered around saving the datatable’s information to an external file – which I didn’t want to do. I mean, it should be easy to do it in memory! To me, creating a temporary file to resolve an issue is a crutch plus it adds to the cleanup code because the temporary file *should* be removed when the operation is complete.
So I started thinking about it and looking in the Object Explorer to see what I could cook up. I knew I could take the datatable and export it but that goes to the file system – or does it? I could export it to a MemoryStream. Ok, but now I lose the table look – the column and row lines. If this were an HTML page, I could use a style sheet…or, how about doing that and using an HTML-formatted email message! To do that, I could save out the datatable contents as XML and then use an XSL file to transform the datatable’s contents to an HTML format. But now how do I get the transformed XML to HTML without generating the temporary file? I looked at the XslCompiledTransform and I can write it to a physical file or a StringWriter. The StringWriter, in turn, can be used to populate the email’s body.
To summarize the steps:
Sounds a little complicated but it’s actually quite easy to code. Here is the code, with comments, on how to accomplish this:
1: If myDataTable.Rows.Count > 0 Then
2: Dim sw As New StringWriter()
3: Dim strm As New MemoryStream()
4: 'save the datatable contents to the memory stream
5: myDataTable.WriteXml(strm)
6: strm.Position = 0
7: 'load the style sheet
8: Dim xslt As New XslCompiledTransform()
9: xslt.Load("dataset.xsl")
10: 'execute the transformation and output the results
11: 'to the string writer
12: Using xrdr As XmlReader = XmlReader.Create(strm)
13: xslt.Transform(xrdr, Nothing, sw)
14: End Using
15: 'create the mail message
16: Dim mail As New MailMessage()
17: 'set the addresses
18: mail.From = New MailAddress("mike.tuersley@mtuersley.com")
19: mail.To.Add("someone@hotmail.com")
20: 'set the content
21: mail.Subject = "Testing DataTable in Email"
22: mail.Body = sw.ToString
23: mail.IsBodyHtml = True
24: 'email it
25: Dim emailClient As New SmtpClient(MyEmailServerName)
26: emailClient.Send(mail)
27: End If
The key points here are lines 5 (WriteXml to MemoryStream], 13 [transform the XML to a StringWriter] and 22 [using the StringWriter to populate the email message.
Consult www.w3.org for details on creating an XSL file if you are not familiar with them. As seen below, the XSL file looks just like an HTML page:
1: <?xml version="1.0" encoding="UTF-8"?>
2: <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
3: <xsl:output method="html" encoding="UTF-8"/>
4: <xsl:template match="/">
5: <html>
6: <head><title>FREIGHT CLAIMS</title>
7: </head>
8: <body>
9: <table width="100%" border="1">
10: <THEAD>
11: <TR>
12: <TD width="20%"><B>Customer</B></TD>
13: <TD width="20%"><B>Carrier</B></TD>
14: <TD width="6%"><B>Bill of Lading</B></TD>
15: <TD width="6%"><B>Pro No.</B></TD>
16: <TD width="6%"><B>Billing Date</B></TD>
17: <TD width="6%"><B>Est. Charge</B></TD>
18: <TD width="6%"><B>Freight Charge</B></TD>
19: <TD width="6%"><B>Actual Charge</B></TD>
20: <TD width="25%"><B>Reason</B></TD>
21: </TR>
22: </THEAD>
23: <TBODY>
24: <xsl:for-each select="//Claims">
25: <TR>
26: <TD width="10%"><xsl:value-of select="Customer" /></TD>
27: <TD width="10%"><xsl:value-of select="Carrier" /></TD>
28: <TD width="10%"><xsl:value-of select="BillOfLading" /></TD>
29: <TD width="10%"><xsl:value-of select="ProNo" /></TD>
30: <TD width="10%"><xsl:value-of select="BillDate" /></TD>
31: <TD width="10%"><xsl:value-of select="EstimatedCharge" /></TD>
32: <TD width="10%"><xsl:value-of select="FreightCharge" /></TD>
33: <TD width="10%"><xsl:value-of select="ActualCharge" /></TD>
34: <TD width="10%"><xsl:value-of select="Reason" /></TD>
35: </TR>
36: </xsl:for-each>
37: </TBODY>
38: </table>
39: </body>
40: </html>
41: </xsl:template>
42: </xsl:stylesheet>
Sorry it's been a while but work and end-of-summer tasks around the home have kept me very busy.
I was working on one of my classes for Autodesk University 2008, CP319-4: Adding Settings to the AutoCAD® Options Dialog with VB.NET this weekend. It has been a while since I've written any .NET managed code that used the Options dialog box so whenever my app first appeared in the Options dialog, I was surprised to find that the Apply button was still disabled. I briefly looked through the Object Browser [not too thoroughly] and didn't see a way to adjust it. I decided to ping ADN support and let them help me out. Unfortunately, most of their better techs are away working on their classes, too, so the reply I received was straight from Helpdesk 101 - read message, search database, send reply. The reply was that it was not possible to enable the Apply button but had been submitted as a change request, etc., etc., etc.
Now before I go any further, I was okay with the ADN tech's reply! I knew he wasn't the one of the normal techs I hear from whenever I submit help tickets. I just wish he had looked a little deeper.
Since I'm not about to step out in front of a bunch of programmers with no answer, I decided to poke around a bit more and see if I could write a workaround. So I started playing around and went back to the Object Browser and viola! There is was - a method off the TabbedDialogExtension called SetDirty [but, of course, there is no visible IsDirty hanging off of a TabbedDialogExtension object ;)]. I added the following line to the Load event to see what would happen:
Autodesk.AutoCAD.ApplicationServices.TabbedDialogExtension.SetDirty(Me, True)
and then
Now the Apply button is there and functioning. The SetDirty method needs to be called after any other code runs that needs the Apply button available.
Some times it's your methodology that gets you, not your code.
I was working on an ASP2 application using VB.NET. I was adding code, compiling, testing, etc. for quite some time when suddenly my app refused to compile. Of course, the error message was one of the Microsoft catch alls that led to nowhere. I searched the 'net for a solution and tried all the suggestions that seemed relevant without success.
After stepping away from my laptop for a bit, an idea formed. Typically, I use the latest coding fad of using an underscore as a prefix to a global variable. This works great in VB but causes problems in C# - it just doesn't like it! I do something similar in my file naming - I'll use the following format: My_Form. So on a whim, I removed the underscores from my file names and tried to recompile. What do you know? It worked! Go figure.