Sunday, September 16, 2007

Dermine Windows OS Version

I recently had the need to determine what OS the user is running on the client PC.

After performing a quick Google search, I arrived at the answer to my quest. Here are the results:

It turns out that the System.Environment namespace houses a lot of useful items. One of them is the OSVersion class. The OSVersion.Version property contains the version number which is what I wanted to determine which OS the user host computer is running. The other properties referenced are merely eye-candy.

Using Windows XP:


Using Windows Vista:

Notice how the version number changes from Windows XP to Windows Vista.

To obtain the data shown above, the Environment.OSVersion class is used:


string osVStr = Environment.OSVersion.VersionString;
labelOSVStr.Text = osVStr;
string osVPlatform = Environment.OSVersion.Platform.ToString();
labelOSVPlatform.Text = osVPlatform;
string osVSvcPack = Environment.OSVersion.ServicePack.ToString();
labelOSVSvcPack.Text = osVServicePack;
string osV = Environment.OSVersion.Version.ToString();
labelOSVersion.Text = osV;

From here, it is a simple step to compare version numbers against a desired level, verify that service packs have been applied, etc.

GUIDs and C#

I've started using GUIDs (pronounced "goo-id") which are globally unique 128-bit integers (displayed as HEX). I created a small program to generate and display a GUID using the System.Guid.NewGuid() method in C#.



Here's the opening screen:



After clicking the 'Create GUID' button, the new GUID is displayed:

The code used to generate the GUID is as follows:


Guid myGUID = System.Guid.NewGuid();
labelGUID.Text = myGUID.ToString();



I'm starting to prefer this method of creating ID values for data tables more than the indexing values I currently use. This should make maintaining disconnected databases on handheld devices much simpler and more effective.

Intermec CN3 With Imager

I just returned from the Interemec DevCon in Boston and wanted to put together a Windows Mobile application that uses some of the things I learned while there.

First, the CN3 is a very capable Windows Mobile device manufactured by a company called Intermec http://www.intermec.com/. It has hardware specific to Intermec devices, such as the bar code reader (Imager) and uses the Intermec Development Libraries (IDL).

So, I created the application and ran it. Here's a screenshot:





Next, I modified the program and added a list of images:



From here, I see this being used to document labels that cannot be scanned, possibly damaged goods reporting, etc.

There are other options for obtaining pictures for reporting damaged goods, such as using a cell phone or digital camera, in addition to the the CN3. The CN3 also comes with an optional digital camera, but a CN3 cannot have both an Imager and a digital camera. At DevCon, this seemed to be the biggest complaint with the CN3.

The significant code sections for this application are as follows:




private Imager myImager;

...

myImager = new Imager(pbxImager, Imager.PictureResolutionSize.Full);
myImager.VideoRunning = true;
myImager.OnScreenCaption = "Imager Example";
myImager.OnScreenCaptionPosition = Imager.OnscreenCaptionPos.LowerLeft;


and then to capture the images:

ImageCount++;
string imageName = "\\JPGImager_" + ImageCount.ToString() + ".jpg";
myImager.SnapShot(imageName, Imager.PictureResolutionSize.Full, Imager.FileModeType.JPG);
imageList1.Images.Add(new Bitmap("\\JPGImager_" + ImageCount.ToString() + ".jpg"));
listView1.LargeImageList = imageList1;
listView1.View = View.LargeIcon;
ListViewItem lvi = new ListViewItem(ImageCount.ToString());
lvi.ImageIndex = ImageCount - 1;
listView1.Items.Add(lvi);

Connecting to SQL 2005

Well, I've noticed a few things since converting my desktop to Vista and using SQL Server 2005...

First thing I noticed is that SQL 2005 does not like remote TCP connections. Instead, use Named Pipes by prefixing the server name/ip address with the prefix 'np:'.

Note: This does not appear to work with SQL 2000, so I have created an app setting in the App.Config file to set the database server type:



<configuration>
<appsettings>
<add value="localhost" key="QueueServerName">
<add value="localhost" key="CacheServerName">
<add value="SQL2005" key="DBType">
</appsettings>
</configuration>


Then, in the code, I use the ConfigurationManager as follows:

string dbType = ConfigurationManager.AppSettings["DBType"].ToString();