August 2009 Entries

community-credit I am proud to announce, that I won a prize from Community-Credit in July. If you speak in the community, blog, help organize things or just attend meetings, go to their website and sign up and get your chance to win some stupid prizes. :0)

OK. I am not a designer. However, a few years ago I was forced to get good at CSS and have gotten to the point that I feel confident I could create almost ANY look and feel using CSS and table-less design. There are some things that I do regularly to help me out.

1. Start at the top. Start with your master page and style that up really good. That will be your base.designer

2. Start with * { font-family: Arial, Helvetica, Sans-Serif; Margin: 0px; Padding: 0px; font-size: 1.0em; } It is at the top of almost every style sheet I do. The font-family may change (like Verdana, Helvetica, Sans-Serif) but the margin and padding set to zero and the base font size set, means your starting from a known state.

3. Name your classes by function and leave any hint of appearance out of it. This is ESPECIALLY important. I recently saw a class called “.SmallColoredLabel” the style? { font-size: large; } Chances are it started out as a small colored label. but as the clients reviewed and changed their minds, they decided they wanted them black and a bit larger. If the class had been “.SubHeader” then you could change the style of that without ever confusing anyone.

4. Use fluid designs when you can. Sometimes the design is so specific that you can’t make the alterations necessary to create a good fluid design. Maybe a designer could, but I can’t. But a fluid design (one that stretches with the browser window, will be much more useable to people.

5. Use web-safe colors whenever possible. Sometimes the demand for a specific branding color makes this impossible, but using web-safe colors will ensure that your site looks the same across most machines. using the three-letter short hands for the colors (#CCC {light grey} or #369 {grey blue}) helps.

6. Use ids for things you can, when you know it will only be used once. Like the Main Page Div, the Master Page header div, etc.

7. Remember you can use more than one class on every element. So a text box might have class=”Input PhoneNumber CustomerPhone” letting me set a style for all Inputs, shorten it for PhonNumber text boxes and setting any specific styles for the customer phone number in particular.

OK, kiddies these are the rules I generally follow to start with when styling a site. Again, I am not a designer, but these rules have helped me quite a bit and some have been hard-learned lessons.

Hope this helps.

Well, I crashed and burned tonight. I knew the information, but I had one small problem, that kept my demo from working.stupid-people

I added the SchemaNameConvention to the Data project for handling database schemas, and added it to the Fluent NHibernate conventions list. I SHOULD NOT, however, have changed the code for getting the Id of the domain objects. What this does, is it looks at the object and determines, by domain signature attributes, which property mappings need to be mapped as an Id not a property.

Anyway, I STILL had a great time tonight. The KCDNUGgers are an awesome bunch and we had a great time talking about the future of our group. We got some good feedback, and I’d expect to see some changes upcoming.

Thanks again to all the attendees tonight for hanging in there with me and I hope, despite the problems, you got some good information and have decided to give Sharp Architecture a try. Also a HUGE thanks to Jimmy Smith from Aureus Group for bringing Pizza Oven pizza tonight, I will definitely be visiting them again.

To all those who are interested in ASP.NET MVC et al, check me out Wednesday night, August 26th at the KC Web Pros group.  I will be comparing and contrasting MVC and MVP in ASP.NET. Plus, my [new] employer (Adventure Tech Group) will be sponsoring the meeting tonight as well.

The Demo code and the presentations are available in my demo code repository on Google Code.

http://code.google.com/p/leebrandt/ the presentations are in the docs folder.

As always, the SVN connection instructions are on the source tab.

The three links that helped the most are:

http://www.sharparchitecture.net/

http://wiki.sharparchitecture.net/Default.aspx?Page=VSTemplatesAndCodeGen&AspxAutoDetectCookieSupport=1

http://www.viddler.com/explore/virtualaltnet/videos/25

Thanks!

Speaker

Lee Brandt is a Senior Consultant with Adventure Tech Group, Inc. in Overland Park, Kansas. He has been programming professionally for over 10 years and developing solutions in .NET and C# since the early beta releases. He is an advocate for behavior-driven development, design patterns and agile methodologies.

Topic

Getting Started with S#arp Architecture

ASP.NET MVC is all the rage lately. There are also several peripheral projects that compliment ASP.NET MVC development (MVCContrib, NHibernate, Fluent NHibernate, etc). Sharp Architecture is an opinionated framework that brings a lot of the best practices of ASP.NET MVC development together and can get you producing useful ASP.NET MVC applications quickly. We will create an application using Sharp Architecture and examine what it does for use and how to leverage its capabilities.

Hope to see you all there!

Tuesday, August 25th, 2009 6:00PM – 8:00PM
Centriq Training
8700 State Line Rd
Leawood, KS 66206

Food Provided By Aureus Group

Prizes Provided By Microsoft

I have been using the Expression Studio 3 for only a day or two, but I have played with Expression Studio 2 before and was frustrated with Expression Design. Let me first say, I am NOT a designer, so I am not familiar with Adobe Photoshop for image editing either. The limited image manipulation I have done has been in Paint.NET.

I’ve never had a problem putting a drop shadow on some text, until I tried to do it in Expression Design. Last night, however, I figured it out. So I put some text on an image.

design_1

 

If you collapse the “Appearance” box, you’ll see the “Effects” box below.

design_2

And the little “fx” button with an arrow next to it.

design_3

When you click on the arrow, choose “Effects” –> “Drop Shadow”.

design_4

 

And viola!

 

design_5

 

I hope this helps someone get past a small hump in learning curve for Expression Design 3. I am now able to use it for most of the stuff I do (which ain’t much, let me tell you).

I didn’t leave work until 8PM this evening. I was wrestling with a JavaScript/JQuery problem and it became a personal battle to bend this application to my will. (Maybe in some future post I’ll talk about how horrible that is.) So I didn’t get it before I left, but I came home and started hitting it here on a test project. There seems like there are probably some scripting conflicts in our project (we have the JQuery stuff and prototype in there), so it didn’t take be but about a half-hour at home to come up with a working prototype. Then I fought with browser compatibilities a bit. But I thought I would post my solution here for two main reasons: There might be a better solution that eluded my Google-fu today, and if not, I may need to refer back to the solution in the future.

The Problem

The page I am working, needs to allow users to select their favorites from a list of item’s (via checkbox) and then print them. The approach I chose (Thanks Nidal!) was to load a page using an iframe and print the iframe. Easy, right? Not quite. The problem was not loading the iframe or getting all the checked items, it was actually printing the content in an iframe. At first, I thought I’d put a script on the iframe content page something like:

The Trial

   1: $(document).ready(function() { 
   2:   window.print(); 
   3: });

The Errors

No such luck. I did a little Google-ing (I mean.. um .. Bing-ing? Bang-ing?) and saw that most of the solutions for “print iframe JQuery JavaScript” were using some form of:

   1: window.frames['PrintFrame'].focus();
   2: window.frames['PrintFrame'].print();

A straight-up JavaScript solution. So I tried it. But my print() was happening so fast that my content in my iframe hadn’t loaded, so I kept printing blank pages. (NOTE: When developing something like this where you need to print, switch your default printer to Microsoft XPS Document Writer first. You’ll save on paper.) So i needed a way to make sure that the print didn’t get called until the iframe was loaded, and luckily JQuery has events to wire into:

   1: var frame = $("#PrintFrame")
   2: frame.load(function() {
   3:   window.frames['PrintFrame'].focus();
   4:   window.frames['PrintFrame'].print();
   6: });

Now you’ll notice the JQuery on the outside of the load call and the regular JavaScript call on the inside. For some reason, the calls to the frame object do not give me the object I need to call print(). Now this worked fine, with the exception that if I tried to unload the frame content (just for cleanliness sake) the load fires again. I had come across a Stack Overflow question that talked about a dynamic iframe, and it got me to thinking, “what about an iframe that I create programmatically, load, print and then destroy?” Which led me to this:

   1: $(document.createElement("iframe"))
   2: .attr('style', 'height:0px;width:0px;position:absolute;top:-500px;left:-500px;')
   3: .attr("id", "PrintFrame")
   4: .attr('name', 'PrintFrame')
   5: .attr('src', url)
   6: .prependTo("body")
   7:  
   8: var frame = $("#PrintFrame")
   9: frame.load(function() {
  10:   window.frames['PrintFrame'].focus();
  11:   window.frames['PrintFrame'].print();
  13: });

 

My Solution (‘til a better one comes along)

Firefox, using this solution created and destroyed the iframe so fast it was unable to print, so i changed it slightly:

   1: $(document.createElement("iframe"))
   2: .attr('style', 'height:0px;width:0px;position:absolute;top:-500px;left:-500px;')
   3: .attr("id", "PrintFrame")
   4: .attr('name', 'PrintFrame')
   5: .attr('src', url)
   6: .prependTo("body")
   7:  
   8: var frame = $("#PrintFrame")
   9: frame.load(function() {
  10:   window.frames['PrintFrame'].focus();
  11:   window.frames['PrintFrame'].print();
  12:   setTimeout(function() { frame.remove(); }, 1000);
  13: });

This worked marvelously in IE, and printed and destroyed as it should in Firefox, but I noticed that Firefox kept spinning after the create/print/destroy sequence was over. If you tried to reload the page, you’d get a client-side error: “The document cannot change while Printing or in Print Preview.” A quick Google led me here. Seems to be a bug in Firefox. Fine. I tried increasing the setTimeout interval to 5000, this did the trick. After some monkeying with it, 4 seconds is the ideal length of time to keep the iframe alive so that Firefox can reclaim the browser from the print process. I get the sinking feeling, however, that this will vary from client-to-client. Some people’s printers are faster or slower to spool than others (or than XPS Writer). So the solution feels a little fragile to me, but I am at the end of my JS/JQuery knowledge.

So if you happen to be a JS/JQuery expert, or you’ve done this before, drop me an email. There’s not a lot on the ‘net I could find, which leads me to believe that not a lot of people need to do this; or I am totally spacing on the obvious easy solution (like iframe.printContent()) or something.

I realize I have been quite quiet lately. This is due to three main things: busy_person

One, I started a new job with AdventureTech Group, Inc.. I am consulting again, and I am liking it much more this time around. AdventureTech is an awesome company and everyone I’ve met has been outstanding. All the developers are top-notch and I can’t wait to get a chance to learn from all of them.

Second, I’ve been preparing my presentations for the St. Louis Day of Dot Net. I am totally excited about going to St. Louis and meeting all the St. Louis Developer, and seeing some people I haven’t seen in a bit.

Third, I’ve been working on a screen cast series about Behavior-Driven Development. I really liked the Hibernating Rhinos and Summer of NHibernate series and thought I might be able to put together a small series of doing context-specification style BDD. I have really underestimated what goes into doing a screen cast and have a new respect for Oren and Steve.

I have also been digging into ASP.NET MVC, Sharp Architecture (LOVE IT), SubSonic and JQuery. I am also scheduled to do a lightning round about BDD at HDC in October. All in all, it hasn’t left much time.

I would say look for more posts to come about all of this. Until then keep learning!

We’ve all done it at one point or another. We’ve all looked at some code we were left by another developer and thought, “WTF was this guy thinking?!?” We tend to  automatically assume that the developer before us was a complete amateur. These kind of developers give us all a bad name. It’s absolutely no wonder that clients don’t trust us. With code like this, who could blame them for thinking we are all hacks.

The problem is, the customer never reads our (or their) code. If the customer has any inkling that our predecessors were incompetent, it’s because we GAVE them that idea. Most customers would know good code from keyboard knuckle-banging. All too often in our field, we are quick to judge someone else’s code. We judge code that ispartyondudes left behind without any thought given to the context that the code was written in. The problem is, without context, there is no way to judge accurately.

There have been several times in my career, that I have looked at code developed by a previous coder and decided it was crap and I was going to rewrite it. But after a major refactor or re-develop, I discover the REASON the code looked like crap. There was some strange requirement or hurdle that caused an otherwise competent developer to do something wholly terrible. I’ve done it myself. I’ve felt the crunch of deadline and thought, “This is really crappy, but I’ll have to come back and fix it later, when I have time.” It never gets fixed. I never have time. If I DO have time, I am usually thinking about the future rather than reworking something that I was less than pleased with.

Sometimes it IS plain inexperience. The previous developer came across a situation she had never encountered before and she did what she had to do to make it work and deliver on the customer’s requirements. Sometimes it’s our inexperience. Sometimes that code that looks totally crappy is quite elegant and beyond our experience level, and our inexperience leads us to assume that the code is poorly written.It’s easy to judge an athlete the day after the game, but I am on the sidelines and I don’t have all the facts. We must remember when looking at others’ code, that we do not have all the facts. We must remember that we have the benefit of hindsight, and usually much more information than the developer who originally made that call had when they made it.

We must also remember that our customer gets their impression of our competency as a profession, by how we conduct ourselves professionally. Accusing previous developers of being amateurs or stupid, only makes our profession look bad. Look at code left to you by previous developer with soft eyes.

“Be excellent to each other, and.. PARTY ON DUDES!!!” ~ Abraham Lincoln in Bill & Ted’s Excellent Adventure.