Skip to main content

Posts

Showing posts from 2008

PMP, Agile and a true development process

Over the last couple of years, the PMP title has become the latest fashion accessory. Unfortunately, most of the people I've dealt with have tried to enforce every facet of PMP on even the smallest of projects. They've also mostly been freshly minted so they really don't have any experience. All this has lead to projects mired in paperwork, behind schedule and ticked-off users.Over the years, I'd developed my own style that seemed to work and got a few requests to teach my style to some of the other developers. Problem was, I'd never really formalized anything. I just kinda did things. So over the last couple of months, I've been working on formalizing some things. I spent some time looking into the PMP and can see where it would bring extensive value to lots of projects, especially construction or manufacturing. There are pieces that I can see would be beneficial to the contractual side of software development. The main thought I had was that PMP would never d…

Why I switched to C# (or How I Became Darth Vader)

Made the decision to switch to C# recently. The main reason: I got tired of finding code written in C# and then having to convert it to VB. It really wasn't that painful except when I'd forget the parenthesis that VB so nicely takes care of (this should be the first thing you check when you get an error). Maybe it's just because it's new but I actually like it better in most respects.If you're going to make the same switch, here's some resources:Julia Lerman's talk on C# for VB DevelopersC# Essentials, 2nd Edition is a great book that assumes you are an experienced developer and quickly shows all of the basic functionality you need.Technorati Tags: ,,

Regular expressions for passwords

This is a link post for some of the regular expressions that can be used for passwords.  Specifically, you can use them for asp.net's passwordStrengthRegularExpression. Note: Be sure to test them *before* you use them in a production app. The table indicates the minimum length, if it requires at least one upper, lower, digit or special character.ExpressionLenUpperLowerDigitSpecial^.*(?=.{10,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*$10YYYY^.*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*$8YYYN^.*(?=.{10,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*$10YYYY

Links for Linq Joins

Some articles on joins for Linq. This one is basic, just to grok the concept. This post from CodeGuru is a little more detailed and explains things a little better. Multiple join conditions are shown here. This post uses extension methods to handle a date. I can definitely see some uses for this.There are some interesting things you can do like finding all of the overlapping date ranges in a table.

Windows Live Toolbar broke my Shift+Tab

Finally!!!!!! For months my shift+tab in forms didn't work. IE or Firefox. Drove me crazy!!!!! Google a little this morning and found an entry that said uninstall Windows Live Toolbar. Thought "what the heck". It worked!!! Not only did fix IE but it also fixed FF. Don't understand. Don't care. Problem solved.Technorati Tags:

Adding commas to numbers with JavaScript

I recently went to add commas to a number on entry. Found a nice script here. Only thing I changed was to make it set the value in the function. I also liked his solution for adding separators other than commas.The code:function addCommas(obj) { nStr = obj.value; nStr += ''; x = nStr.split('.'); x1 = x[0]; x2 = x.length > 1 ? '.' + x[1] : ''; var rgx = /(\d+)(\d{3})/; while (rgx.test(x1)) { x1 = x1.replace(rgx, '$1' + ',' + '$2'); } obj.value = x1 + x2; }

Parse CSV or other separated strings

I had to work with Comma Separated Values (CSV) files the last few days and updated some code to make it easier to use with LINQ. Quick review, a CSV file is a file that has all of the values separated by a comma. Values that contain a comma are typically qualified with double quotes. For example:Abraham, Lincoln, 03/4/1861, 04/15/1865, "Republican, National Union"Basically, I created a class called SeparatedString that performs all the functionality of parsing the data so that I can retrieve it later. When the Text property is set it figures out the location of all relevant commas and loads them into a List. The GetValue method then uses the index to grab the occurrence of the comma that precedes the value to be retrieved.PublicClass SeparatedString ''' <summary>''' Contains the position of all separator characters in the string''' </summary>''' <remarks></remarks>Private _Separators AsNew List(Of I…

Simple Age Calculation

I was helping someone with some SQL stuff and needed to give them a function to calculate someone's age.  Rooted around a bunch of places and finally just ended up re-writing it. So this is mostly to have it on hand. This function is needed because DateDiff doesn't check if they've had their birthday this year.CREATEFUNCTION CalculateAge ( @Start smalldatetime , @End smalldatetime ) RETURNSintASBEGIN-- Declare the return variable hereDECLARE @Age intSET @Age = DateDiff(year, @Start, @End) IF DateAdd(year, @Age, @Start) > @EndSET @Age = @Age - 1 RETURN @Age END GO VB VersionPublicFunction Age(ByVal value AsDate, ByVal d AsDate) AsInteger Age = DateDiff(DateInterval.Year, value, d) If value.AddYears(Age) > d Then Age = Age - 1 Return Age EndFunction Technorati Tags: ,,,,

Use JavaScript on Controls in a GridView, DetailsView or FormView (even in a MasterPage with an UpdatePanel)

Ever want to use JavaScript on a Textbox inside a DetailsView? It can be done, you just need to overcome two issues. The first is that .Net will change the ID from "MyTextBox" to something like "ct100_ContentPlaceholder1_DetailsView1_MyTextBox". The second is that these controls may exist only in Edit or Insert mode.The first thing we want to do is get the ID of MyTextbox that gets sent to the browser. Since MyTextbox only exists when we're editing or inserting, we need to use the PreRender event. We check to make sure we are in Edit/Insert mode and then use FindControl to get a handle on the textbox. Next we use the ScriptManager RegisterHiddenField method to register a hidden control that has the ClientID as its value. ProtectedSub DetailsView1_PreRender(ByVal sender AsObject, ByVal e As System.EventArgs) Handles DetailsView1.PreRender If DetailsView1.CurrentMode = DetailsViewMode.Edit Or DetailsView1.CurrentMode = DetailsViewMode.Insert ThenDim txt As Te…

LINQ To SQL Row not found or changed

LINQ To SQL likes to use TimeStamp columns for version tracking and makes it really easy to do so. However, in a lot of the apps I work on, we need to keep track of when the last change was made so we have a DateTime column titled LastUpdated. Using Steve Michelotti's post, I was able to use this column for row version control.Everything was fine until I was using a DetailsView and got the message "Row not found or changed". This message is LINQ's way of telling you that the row has been changed and you now have a concurrence conflict. Since I was working on my local box, I knew this wasn't the case. Pulling up SQL Profiler, I was able to see that LINQ was sending the LastUpdated date back without milliseconds. Since this isn't the same as the value on the row, it thinks a change has occurred.I was displaying the LastUpdated field in a readonly column so it shouldn't have been getting changed. I also had it as DataKey and could see that it was getting pas…

JavaScript DateDiff Functions

Here's some JavaScript functions that I use like VB's DateDiff function. I've seen some other functions but most take the number of days and end up close but not quite. They also don't correctly handle leap years.DateDiffYears will return the number of years between two dates while DateDiffMonths will return the number of months. Couple of things to remember. DateDiffYears is often used to determine age so it won't go negative but will return zero. Thus, if the end date precedes the start date you'll get zero as the result. Also, pass start and end as date objects rather than strings. LAstly, you need DateDiffYears to use DateDiffMonths.// Calcuates the number of years between two dates.// start - a date object that defines the beginning of the range// end - a date object that defines the end of the rangefunction DateDiffYears(start, end) { var years = end.getFullYear() - start.getFullYear(); var month1 = start.getMonth() var month2 = end.getMonth()…

Use a Web.Config connection string in your Data Access Layer with LINQ To SQL

My applications have the Business and Data Access Layers in a separate DLL from the presentation. This makes it so that everything that wants to do a certain function uses the same library. I also like to pre-compile my web sites which means that I can't get at the app.config if I need to make changes to the connection string (moving around dev, test, prod, etc). I found this from Jason Gaylord that worked quite well. As I worked with it, I began to think that there might be a better way to handle it. My answer was a simple factory pattern class to create my datacontext. I'd like to claim the idea but I really got it from the Enterprise Application Block's DatabaseFactory.Instead of adding an additional constructor I simply create a class that has the responsibility for creating the datacontext. The CreateDataContext method determines the correct connection string and then uses the predefined constructors. I place this class in the code file for the LINQ To SQL since I con…

Silverlight Master Page

Since I'm old school and so are most of my users, I wanted to create a simple Silverlight app that had a title bar across the top, nav menu on the left side and a content area on the right. You can modify this for mutiple zones and do some pretty slick stuff. Note: This is Silverlight 2 Beta 2 and VS 2008.The key is to create a Canvas that gets changed when you want to make changes. Here's the code for the above -- notice the Canvas named ContentHolder.<UserControlx:Class="SilverLightMasterPageTest.Page"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:local="clr-namespace:SilverLightMasterPageTest"><Gridx:Name="LayoutRoot"Background="#FF5C7590"><Grid.RowDefinitions><RowDefinitionHeight="30"/><RowDefinitionHeight="*"/></Grid.RowDefinitions><BorderGrid.Row="0"CornerRadius=&quo…

Det. Eddie Ibarra -- Hero of the Week

Det. Eddie Ibarra is my hero of the week. Because he solved a homicide in the First 48? No. Because he's a Steelers fan living in Dallas. He was featured on the show the other night and his cube was covered in Steelers stuff. There was even a picture of his kid in a Big Ben jersey. Way to go Eddie!!!!How long is it until the first game.

Easy Way To Maintain Div Scroll Position On Postback

There are numerous ways to maintain scroll position on a postback that all involve javascript coding. Unfortuantely, it always seems like they don't work in the situation I need. Well, the other day, I found a solution that had been right in front of my nose.I was working on a page where I wanted a list of people on the left and the details for the selected person on the right. The list was inside a scrolling div so they'd be able to scroll the list to find the individual.  Everything was wrapped in an UpdatePanel  and I had everything set up right. However, when a postback occurred -- boom -- back to the top of the div.My solution was two UpdatePanels. One inside my scrolling div and the other holding the DetailsView. The UpdateMode is set to Always for both so when the update fires in one, it also fires in the other. Since UpdatePanel is inside the scolling div, the div (and its current scroll position don't update).Viola, a scrolling div that maintains position without …

Custom Classes and LINQ To SQL Group By

I spent a good part of my morning trying to get LTS to return my custom class as a result of a group by instead of an anonymous type. Most of the samples I found on the web for Group By returned anonymous types and the ones that didn't were from early versions and I couldn't get them to work.The problem I was having was getting the column I was grouping on mapped. I created a class called DescriptionCounts that had two properties Description (string) and Count (integer). The following code will correctly map a group by query to this class.Dim i = From b In dc.Barriers _ Group By b.BarrierType.Description Into g = Group _ SelectNew DescriptionCounts _ With {.Description = Description, .Count = g.Count} The main thing to notice is that when the Description property gets mapped, it is mapped to a variable named Description (.Description = Description -- notice that there is no prefix) and not to a property of b.All of the aggregate functions require that you use the Grou…

LINQ To SQL Attach

The Attach method allows updating with a disconnected object that has been updated. The easiest version to use is:Public Sub UpdateCustomer(updatedCustomer As Customer) 
  Dim dc As New MyDataContext() 
  dc.Customers.Attach(updatedCustomer, True) 
  dc.SubmitChanges
End Sub The only problem is that this generates a SQL statement that updates all columns rather than just the on that has changed. In other words, we used a little extra bandwidth.The reason this happens is because when we disconnected the object, we lost all the built in change tracking provided by LINQ (for now).Option 2 is to get a new copy of the object and update it.Public Sub UpdateCustomer(updatedCustomer as customer)

  Dim dc as New MyDataContext
  Dim originalCustomer as Customer = from c in
    dc.Customers Where c.PrimaryKey =
    updatedCustomer.PrimaryKey

  originalCustomer.CustomerName =
    updatedCustomer.CustomerName
  originalCustomer.CustomerAddress =
    updatedCustome…

Visual Studio 2008 & SPAN tags

Visual Studio doesn't seem to like SPAN tags. I've already reported a bug where it adds duplicates SPAN tags to templated fields in a GridView or DetailsView that is within a span tags. Now, it's moving my span tags around.I had two span tags to define left and right columns with inline-block. They were contained within the same div. Somehow, VS decided that the left span belonged to the div above and moved it all on it's own. If it keeps happening, I'll see if I can narrow the circumstances down and get a bug report filed.Technorati Tags: ,,

VS 2008 GridView Rendering Bug

Found an annoying bug in VS today. If you have a GridView contained in a Span tag on a ContentPage and edit the fields, VS will add span tags around the fields you change. Of course, when your done making your changes and click OK, you'll get a rendering error. Simply edit the source and remove the spurious span tags. Technorati Tags: ,,,,

LINQ To SQL OnValidate doesn't fire

Technorati Tags: I spent half an hour tracking this down today and couldn't find it based a google search of the blog title. So.....If your OnValidate code isn't firing in your LINQ to SQL, your probably working with an out-of-date signature. Somewhere between Beta 2 and RTM, they snuck in a slight change by adding a parameter to indicate what kicked off the method.Make your signature similar to:Private Sub OnValidate(ByVal action as ChangeAction)The ChangeAction enumeration values are Insert, Update, Delete and None. So if you need special code for the insert versus the update, you can code an IF statement appropriately.You can find all of the breaking changes here.

Steelers out, rooting for anybody but the Pats

They just have gotten so arrogant. They're good but I don't they're that good. They did beat some good teams but usually when those teams were struggling (SD in particular). I might feel differently if they were a little humble about it.On the other hand, I'd love to Favre get another ring. He's been a great player and stayed with the team/town that made him. Can he beat NE? If they played in the frozen tundra, definitely yes. Neutral field, maybe.

LINQ To SQL, Business Layer and LinqDataSource (Round 2)

Played around with the LDS and can really only see using the LDS for really thin apps where you don't want a lot of structure (maintenance tools, prototypes, etc.) Of course, this is the same time I get my Visual Studio magazine and it covers the topic very well. Read Roger Jennings article on what's missing in VS 2008, the LINQ to SQL section talks about this issue in depth.Meanwhile, I found this great blog from Rick Strahl on returning IQueryable that will do a lot of what I want and still get the benefit of only pulling back what I want.

LINQ To SQL, Business Layer and LinqDataSource

In playing with LTS I keep coming back to the question "Should the DataContext be exposed to the presentation so that you can use the LinqDataSource?" Does this violate the separation of layers by moving business (domain) logic into the presentation tier?Dinesh and Scott Guthrie seem to advocate exposure but I could be interpreting them wrong. On the flip side, Rick Strahl posted some stuff that would seem to say no. Note: I do see that he is more concerned with a disconnected state than with the datacontext).My current thoughts are that this is a six of one/half dozen issue. Seems like I get the business rules (validation, etc) I want separated from the data. Should be maintainable. So for now, I'm going to use it on some legacy applications that are well defined where this would be a definite time saver. We'll see....