Tuesday, April 9, 2013

C# Tips and Tricks: Checking for empty strings

When checking to see if a string is empty I got tired of checking for null and then seeing if it was empty now I only use the following method.

Tuesday, April 2, 2013

C# Tips and Tricks: Setting default DateTime values

Here is the standard way that I set default values for a DateTime field. I like to set defaults for my DateTime fields whenever it makes sense. In this example I am setting the values so that it will return all the data for the last month, including the current day.

Monday, March 18, 2013

Filter DDL items using javascript and a Dictionary<string, string> object in the ViewBag

I had a need to modify the options on a DDL based on different selections the user had made on the page.  I did this at runtime by passing in a list of menu items in the ViewBag and using javascript to add and remove items based on the users selections.
Step 1: Create a ViewBag Dictionary <string, string> object that contains the full list of possible menu items.

Step 2: Create a javascript function that will insert an item into the DDL Step 3: Create a method that will filter the options based on the users selection

Friday, October 26, 2012

On Being a Senior Enginner/Egoless Programming

Today I read one of the best articles ever about being a Senior Software Engineer.  So much of the article was spot on and made perfect sense.  I have copied the below part of the article so that I have it for easy reference.  Here is the link to the rest of it.

"On being a senior engineer" by Kitchen Soap


The Ten Commandments of Egoless Programming

Appropriate, even if old…I’ve seen it referenced as coming from The Psychology of Computer Programming, written in 1971, but I don’t actually see it in the text. Regardless, here are The Ten Commandments of Egoless Programming, found on @wyattdanger‘s blog post on receiving advice from his dad:
  1. Understand and accept that you will make mistakes. The point is to find them early, before they make it into production. Fortunately, except for the few of us developing rocket guidance software at JPL, mistakes are rarely fatal in our industry. We can, and should, learn, laugh, and move on.
  2. You are not your code. Remember that the entire point of a review is to find problems, and problems will be found. Don’t take it personally when one is uncovered. 
  3. No matter how much “karate” you know, someone else will always know more. Such an individual can teach you some new moves if you ask. Seek and accept input from others, especially when you think it’s not needed.
  4. Don’t rewrite code without consultation. There’s a fine line between “fixing code” and “rewriting code.” Know the difference, and pursue stylistic changes within the framework of a code review, not as a lone enforcer.
  5. Treat people who know less than you with respect, deference, and patience. Non-technical people who deal with developers on a regular basis almost universally hold the opinion that we are prima donnas at best and crybabies at worst. Don’t reinforce this stereotype with anger and impatience.
  6. The only constant in the world is change. Be open to it and accept it with a smile. Look at each change to your requirements, platform, or tool as a new challenge, rather than some serious inconvenience to be fought.
  7. The only true authority stems from knowledge, not from position. Knowledge engenders authority, and authority engenders respect – so if you want respect in an egoless environment, cultivate knowledge.
  8. Fight for what you believe, but gracefully accept defeat. Understand that sometimes your ideas will be overruled. Even if you are right, don’t take revenge or say “I told you so.” Never make your dearly departed idea a martyr or rallying cry.
  9. Don’t be “the coder in the corner.” Don’t be the person in the dark office emerging only for soda. The coder in the corner is out of sight, out of touch, and out of control. This person has no voice in an open, collaborative environment. Get involved in conversations, and be a participant in your office community.
  10. Critique code instead of people – be kind to the coder, not to the code. As much as possible, make all of your comments positive and oriented to improving the code. Relate comments to local standards, program specs, increased performance, etc.

Friday, October 19, 2012

SQL Tool: Search all table columns for specific value.

There are times when I am doing some research or refactoring and I need to find all instances of a value in a database. Things like "remove all instances of a person with id 123" or fix all instances of "The Misspelled Cumpany Name". To do this I use the following SQL tool that searches all columns in all tables of a database for matching instances of the value passed in.  It takes a while but will find all instances you are looking for.

Monday, October 15, 2012

ReportViewer: Displaying an empty row on a table

We use Microsoft's ReportViewer for our reporting needs.  It isn't the most elegant but it does the job.

Recently I needed to display a table on a report with an empty row if there was no data in the data source.  This is a visual indicator on the report that there is no data for that item.  Here are the instructions on the way that I found to do this.

1.  Right click on the data row in the table
2.  Add a new row below it, outside of the group.
3.  Right click on the row and select row visibility
4.  Click the radio button for "Show or hide based on expression"
5.  Enter code similar to the following as the expression:
=IIF(Sum(Fields!Id.Value, "DataSetName") > 0, true, false)
This will show the row empty if there is no data and hide it if there is data.  Not very elegant but will do the job.

Friday, October 12, 2012

SQL Tool: Find all columns, by name, in database.

We have some pretty large databases in our system and at times I need to find all columns in a database that have the same name.

Here are my results for all columns that have "cert" in the name.