# Thursday, May 28, 2009

Maine Quality Forum

As owner of Develop-One I’m proud to announce that the Maine Quality Forum is now being hosted and serviced by Develop-One.

Visit the Maine Quality Forum site here.

#    Comments [0] |
# Wednesday, May 27, 2009

Rounding decimals to X positions

Another little extension method. This one allows easy rounding to a specific number of decimals:

double d = 0.66782423;
string s = d.ToString(3);  // s = “0.668”

This is done by the following method:

 

public static class DoubleExtension

{

    public static string ToString( this double value, int decimals )

    {

        StringBuilder format = new StringBuilder( "0" );

        if ( decimals > 0 )

        {

            format.Append( "." );

        }

        for ( int i = 0; i < decimals; i++ )

        {

            format.Append( "0" );

        }

        return value.ToString( format.ToString() );

    }

}

#    Comments [0] |

ReportViewer Control in Visual Studio 2008

I’ve been working a lot with the ReportViewer Control in Visual Studio 2008. The greatest part of the control is that you can implement reporting without using a database!

ReportViewer Control in Visual Studio 2008

ReportViewer is a freely redistributable control that enables embedding reports in applications developed using the .NET Framework. Reports are designed with drag-and-drop simplicity using Report Designer included in Visual Studio 2008 (Standard editon and above.)

See screenshots of some applications that have ReportViewer control embedded in them.

The ReportViewer control offers the following benefits:

  • Processes data efficiently. The reporting engine built into ReportViewer can perform operations such as filtering, sorting, grouping and aggregation.
  • Supports a variety of ways in which to present data. You can present data as lists, tables, charts and matrices (also known as crosstabs.)
  • Adds visual appeal. You can specify fonts, colors, border styles, background images etc to make your report visually appealing.
  • Enables interactivity in reports. You can have collapsible sections, document map, bookmarks, interactive sorting etc in your report.
  • Supports conditional formatting. You can embed expressions in the report to change display style dynamically based on data values.
  • Supports printing and print preview.
  • Supports export to Excel and PDF.

The control can process and render reports independently using a built-in engine ('local mode') or it can display reports that are processed and rendered on a Report Server ('remote mode').

There is a WinForms and a WebForms version of the control.

 

Excellent tutorials on ReportViewer can be found at: http://www.gotreportviewer.com/

#    Comments [0] |

Convert DateTime to DateTime?

Back when .NET 1.1 was cool people would often use DateTime.MinValue to indicate that a date was actually empty. With .NET 2.0 can the Nullable<T> which allows you to create a nullable datetime. Ofcourse there is still plenty of old code out there, so when adding new code you may need to convert DateTime.MinValue to null. With extensions methods (.NET 3.5) you can implement an elegant solution.

The code below will allow you to write this:

DateTime old = DateTime.MinValue;

DateTime? current = old.ToNullable();

This is achieved with the following extension method:

public static class DateTimeExtension
{
    /// <summary>
    /// Examine the value of the DateTime, if the value is equal to DateTime.MinValue
    /// then the result is null, otherwise the supplied value is returned.
    /// </summary>
    /// <param name="value"></param>
    /// <returns></returns>
    public static DateTime? ToNullableDateTime( this DateTime value )
    {
        if ( value == DateTime.MinValue )
        {
            return null;
        }
        else
        {
            return value;
        }
    }
}

#    Comments [0] |
# Tuesday, May 26, 2009

Registration for SDN Conference 2009 | OpenForce ’09 Europe is now open!

The leading event for C#, VB.Net, ASP.NET, DotNetNuke and Delphi developers is now open for registration!

 

For the 18th year running the Software Development Network will organize this 2 day event (on October 19th and 20th, 2009) with sessions about :

  • .NET (C#, VB.Net, F#, etc.)
  • User eXperience (ASP.Net, Silverlight, Expressions, Flash, etc.)
  • Information Worker (MOSS, BizTalk, OBA, etc.)
  • DotNetNuke (OpenForce Europe ’09 conference)
  • Delphi
  • Architecture
  • Core Systems (C, Cobol, NonStop, IDMS, PL/1, DB2, CICS, TSO, ISPF, etc.)
  • Databases

Don’t miss out! Click here to register.

#    Comments [0] |
# Monday, May 18, 2009

Visual Studio 2010 and .NET FX 4 Beta 1 available for download

hero_2010_v3

Visual Studio 2010 and .NET FX 4 Beta 1 are available for download from the MSDN Subscriber Downloads as of today.

Go to: VS2010 Beta 1 Download for MSDN

The 5 page factsheet for VS2010 can be found here.

#    Comments [0] |
# Wednesday, April 29, 2009

Ireland Environmental Services is now online

Here is a shameless plug for my friend Mike who now has his own website at www.ireland-environmental.com.

If you need environmental services or help with getting the right permits to do construction and such, then Ireland Environmental Services is the place to go.
Mike is running a blog on environmental issues too, visit it here.

#    Comments [0] |
# Friday, April 24, 2009

Random filename

Today I had to fix a bug in some code involving a program creating multiple files where each file needed to have a unique machine generated filename. I was building my own unique name using the DateTime.Now.Ticks().ToString() as part of the name. Apparently on some machines the Ticks are not going to be unique. So I looked at the Path.GetTempFile() method, but I needed to control the location of the temporary files. Next stop: Path.GetRandomFileName().

Documentation:
The GetRandomFileName method returns a cryptographically strong, random string that can be used as either a folder name or a file name. Unlike GetTempFileName, GetRandomFileName does not create a file. When the security of your file system is paramount, this method should be used instead of GetTempFileName.

Works great!

#    Comments [0] |
# Tuesday, April 21, 2009

Windows Live Groups and Time Zones

We (the Maine Microsoft Certification Study Group) has been using Windows Live Groups as our virtual place to hang out. Out weekly meeting is posted on the group calendar, but the times kept showing up wrong on the overview page. As it turns out (thanks to Winston Natoli) there are three places where you can set the timezone:

Group Time Zone
- <Select Group or Access via Group Url>/ Options / Group Options/ General
Calendar Time Zone
<calendar.live.com>/ Options/ More Options / Time Zone
Live ID
<account.live.com>/ Registered Information/ Home Location/ Time Zone

 

After setting all of them to EST I’m now getting the right information.

#    Comments [0] |
# Monday, April 06, 2009

Training Kit now on sale at Amazon.com

Yeah, my last Training Kit is shipping!

Get a copy now at Amazon: http://tinyurl.com/dxwdz5

#    Comments [0] |
# Monday, March 23, 2009

Entity Framework: ObjectContext.SaveChanges is transactional

The documentation doesn't specifiy it but in the Entity Framework when you call ObjectContext.SaveChanges the update is 'wrapped' in a transaction.

NorthwindIBModel model = new NorthwindIBModel();

Guid id = Guid.NewGuid();

model.AddToCustomer(new Customer() { CustomerID = id, ContactName = "Andrew", CompanyName = "Northwind Traders" });
model.AddToCustomer(new Customer() { CustomerID = id, ContactName = "Aikido", CompanyName = "Northwind Traders " });

model.SaveChanges(); // exception duplicate key - transactional -> no changes to the database

#    Comments [0] |

Resetting Visual Studio

Today I ran into a problem where apparently the registry settings for Visual Studio got messed up since I was no longer able to add a data connection in my Server Explorer, nor create an Entity Framework model from a database. Time to reset Visual Studio command(o) style.

To reset Visual Studio you open the Visual Studio Command Prompt and type:

devenv /resetsettings

And life is good...

#    Comments [0] |
# Tuesday, March 17, 2009

Code Camp 11: Developer Stimulus Package

CodeCamp

Just a quick reminder to all that Code Camp 11: Developer Stimulus Package will be held on March 28th, 2009. The Boston code camp will be held at the Microsoft Waltham, MA office and the session lineup is looking great!

More info: http://www.thedevcommunity.org/Events/PresentationList.aspx?id=11

#    Comments [0] |
# Thursday, March 12, 2009

Upcoming BAND Gig: A Look at a Real World .NET MVC Implementation

On March 24th the Bangor .NET Developers will host an Ineta sponsored event where Steve Andrews will do a talk about the ASP.NET MVC Framework.

The ASP.NET MVC Framework provides a powerful Model View Controller (MVC) approach to building web applications, and provides separation of concerns, increased testability, control over HTML output, and intuitive URLs. We will start by looking at building a model framework with LINQ to SQL, including validation and model binding. Then, we'll explore a custom generics-based repository and services implementation. Finally, we'll tie it all together with a look at Views and jQuery.

 

Steve Andrews is a Team System MVP and INETA speaker, and has been working as a developer for more than 9 years. During this time, he has designed and developed applications in such widely varying areas as trust accounting, medical information management, supply chain management, and retail systems. Steve is also a MCTS, ICSOO, and community fanatic.

 

Go to www.bangordevelopers.com to sign up now.

#    Comments [2] |
# Monday, March 09, 2009

SDN Event on March 30th in Hotel & Congrescentrum "De Bergse Bossen" (The Netherlands)

The combined user groups of the SDN are putting together a terrific one day event with great sessions for software developers, architects, information workers and database professionals. Don't miss it!

Here is an overview of the sessions:

image

Go to www.sdn.nl/sde to sign up!

#    Comments [0] |

developer.Equals( otherDeveloper );

It often seems that management believes developers are highly exchangeable. Is an experienced developer leaving the team?

Then just new up a new .NET developer and you're done. This Dilbert episode reminded me of that attitude.


From www.dilbert.com

#    Comments [0] |
# Monday, February 16, 2009

MSDN Roadshow is coming to Augusta

Roadshow.pngOnce again the Maine Developer Network (thanks to John, Shawn and the State of Maine Government) is happy to help out Chris, Bob and Jim with finding a location to hold the MSDN Northeast Roadshow.

On March 19th the Roadshow will hit the Central Maine Commerce Center in Augusta. Go here to sign up today!

Location
Central Main Commerce Center
Florian Auditorium
500 Civic Center Drive Augusta Maine 04330
United States

Date
Thursday, March 19, 2009 8:30 AM - Thursday, March 19, 2009 4:00 PM Eastern Time (US & Canada)
Welcome Time: 8:00 AM

#    Comments [0] |

How about those code comments?

I just read Daniel's post on 'The Value of Commenting'. Food for thought people :-)

I like to use the following rules of thumb:

a) Code should be self explanatory. This means using well named variables, properties and objects in order to make code as easy to read as possible. It should be obvious from the code what it is that it is trying to do.

b) Code should be easy to read. By easy I mean that you need to be able to scan it pretty fast. Sometimes comments can help make code easier to read by describing what is going on. I find this especially true in if/else constructions where a short comment can guide the reader of the code.

c) If more that one line of code is needed to describe a code block, consider refactoring the code to a private method and put comments on the method. A useful name for the method should help in achieving point (a).

d) Comments should describe why you're trying to do something, but this has limits. Extensive explanations on why the purchase amount of an order should never exceed $10000 should not be in the code. A list of rules should be maintained as part of the documentation and a reference to the rule should be made from the code comments.
Note: I have been known to document a list of rules as an enumerator, where the documentation of the rule is documented as the description of the enumerated value.

Actually (d) is the hardest one. When is it necessary to describe the 'why' of an operation?
The code is readable, the original programmer put it there for a reason. Are the comments there because the presence of the code needs to be justified? No! The 'why' comments are to facilitate (b).

As always, it's easy to spot useless comments, but hard describe a fixed set of rules to describe good comments. Use your brain!

#    Comments [2] |
# Tuesday, February 10, 2009

It's sleek, it's cool, it's got gadget power!

But it is not the same as having a book that sits on your shelve and collects dust.

The Amazon Kindle 2 is here:

Kindle2

 

 

 

 

 

Lighter, better display, more storage and longer battery seem to be the improvements in the second generation Kindle.

I want one, but part of buying books and novels is the feel of collecting and adding to my library... I'm not sure I want to miss that feeling. I must be getting old fashioned ;-)

More info here.

#    Comments [0] |
# Monday, February 02, 2009

.NET Framework platform availability

I had to find out which platform supports which version of the .NET Framework. The information is a little fragmented, but here is the overview I came up with.

Windows 95
The .NET Framework cannot be installed on Windows 95.

Windows 98
.NET 1.0, .NET 1.1, .NET 2.0, .NET 3.0

Windows 98 SE
.NET 1.0, .NET 1.1, .NET 2.0, .NET 3.0

Windows ME
.NET 1.0, .NET 1.1, .NET 2.0, .NET 3.0

Windows NT 4.0 SP6a
.NET 1.0, .NET 1.1

Windows XP
.NET 1.0, .NET 1.1

Windows XP SP2
.NET 1.0, .NET 1.1, .NET 2.0, .NET 3.0, .NET 3.5

Windows 2000
.NET 1.0, .NET 1.1

Windows 2000 SP4
.NET 1.0, .NET 1.1, .NET 2.0

Windows Vista
.NET 2.0, .NET 3.0, .NET 3.5

Windows 2000 Server SP2
.NET 1.0, .NET 1.1

Windows Server 2003
.NET 1.1, .NET 2.0, .NET 3.0

Windows Server 2003 SP1
.NET 1.1, .NET 2.0, .NET 3.0, .NET 3.5

Windows Server 2003 R2
.NET 2.0, .NET 3.0, .NET 3.5

Windows Server 2008
.NET 2.0, .NET 3.0, .NET 3.5

 

Just to be clear, .NET 3.5 cannot be installed on:

  • Microsoft Windows 95
  • Microsoft Windows 98
  • Microsoft Windows Millennium Edition
  • Microsoft Windows NT Server
  • Windows NT Workstation
  • Windows NT Server Enterprise Edition
  • Microsoft Windows 2000 Professional
  • Windows 2000 Server
  • Windows 2000 Advanced Server
  • Windows 2000 Datacenter Server
  • Windows Server 2003, Enterprise Edition for Itanium-based Systems
  • Windows Server 2003, Datacenter Edition for Itanium-based Systems

 

References:

[UPDATE: .NET 3.0 will not run on Windows 2000 or Windows 200o SP4]

#    Comments [4] |