Archive

Archive for the ‘Software’ Category

Happy Camper

March 4th, 2010 digital No comments

There are days when I reeeeeeally like dealing with Microsoft. Today is one of those days. Under the terms of my BizSpark license, I can legally install Microsoft Dynamics GP. It’s a huge accounting package if you didn’t know. The point is that we can use a fully featured accounting package for $0 instead of having to deal with the small business offerings from PeachTree or Intuit.

We are currently using Quick Book Business something 2009 blah, blah, blah… I loath Intuit and their pricing policies.

“Why does Quick Books 2009 complain every time I fire it up?”
“The 2009 version doesn’t support Win7. You’ll have to buy the upgrade.”

“What’s the deal with this rounding error? There are posts all over your support site about a bug adding a penny to transactions”
“We have a fix for that but you’re not paying for support so we can’t help you.”
“So you have a known defect in your product. You have a patch for the defect and you will not release it without a $80 annual fee.”
“That’s correct sir. There are two other ways to resolve the problem. Re-enter all of your transactions, by hand or purchase the latest version of our product. Sorry”.

No thanks. I’ll find something else. Maybe something from Microsoft.

I’ll be the first to admit no application is perfect. I am sure there are weaknesses in GP, but service packs are FREE from Microsoft. And if you do think there is a bug, they have a process to report it and get it fixed for all users. If I request support and the issue is found to be a defect, I pay nothing for the support ticket. If I screwed something up, then I pay the fee to get help getting it fixed. This seems a lot more up front and honest than what Intuit is doing.

Remove items from a list.

December 9th, 2009 digital No comments

You have a list of “something” and you want to remove items from the list. I can think of a couple ways to do this.

Remove Items V1:
List myList = new List() { “one”, “two”, “three” };
// print out the original list
foreach (string item in myList)
Console.WriteLine(item); // one two three

myList.Remove(”two”);

// print out the new list
foreach (string item in myList)
Console.WriteLine(item); // one three

Remove Items V2:
List myList = new List() { “one”, “two”, “three” };
// print out the original list
foreach (string item in myList)
Console.WriteLine(item); // one two three

myList = myList.Expect(i => i == “two”);

// print out the new list
foreach (string item in myList)
Console.WriteLine(item); // one three

Notes:
The rules for a foreach loop don’t allow you to delete or nullify an object in the collection during the looping, so you need to remove items more directly. For complete objects, this can be a bit harder. Leveraging LINQ can make the task much easier. With the second example, you could use any property/method within the complex object for your comparison. E.G.: IsDirty or ItemFlaggedForDelete().

Categories: Software Tags: ,

Figuring out where you are in an Excel 2007 range.

December 9th, 2009 digital No comments

Ever tried to debug a loop inside a listObject.Range? Use get_Address(). It makes the process a lot easier.

Code: Read more…

Categories: Software Tags: ,

Setting an Excel cell background color

December 9th, 2009 digital No comments

Description:
Set a cell’s solid background color using a single user-defined color.

Code: Read more…

Categories: Software Tags: , ,

Setting an Excel 2007 gradient background

December 9th, 2009 digital No comments

Description:
Set a cell’s background color to a vertical gradient using two user-defined colors.

Code: Read more…

Categories: Software Tags: , , ,

Formating a list of items into a sentence with commas and the ampersand.

December 9th, 2009 digital No comments

Description:
I need to link an list of (string) items into a sentence at runtime. Here’s a short and simple method to handle the commas and ampersand.

Code: Read more…

Categories: Software Tags: ,

Scaling an Excel worksheet

December 9th, 2009 digital No comments

Description:
WinForm controls placed in a worksheet while it is not at 100% will be positioned incorrectly. Here’s a simple workaround to change the zoom to 100% then revert to the previous setting.

Code: Read more…

Categories: Software Tags: , ,

Examing an assembly through reflection

December 9th, 2009 digital No comments

Below is code loading and examining an assembly.

Problem:
You want to open an assembly to see what’s inside with as little effort as possible.

Solution:
I’m sure there are easier ways but this works…

Code: Read more…

Testing execution timeout in Visual Studio 2008 Team System

December 9th, 2009 digital No comments

With Visual Studio Team System, the LocalTestRun.testrunconfig file controls execution parameters for running tests. The default timeout on individual tests is 30 minutes. Ouch!

Solution:

  • Double click on the ‘Solution Items\LocalTestRun.testrunconfig’ file.
  • Select ‘Test Timeouts’
  • Set the individual test time to your preference or set a total time abort if you prefer.

List embedded resources

November 24th, 2009 digital No comments

You can embed items into your WinForm app. So how to do you figure out what you have and the correct path to retreive the items? Here’s a method to show you what’s an embedded resource in your application.

Code:

using System.Diagnostics;
using System.Reflection;

private void ExposeResources()
{
	Assembly assembly = Assembly.GetExecutingAssembly();
	foreach ( string resource in assembly.GetManifestResourceNames() )
		Debug.WriteLine(resource);
}

Usage:

ExposeResources();

Reference:
http://msdn.microsoft.com/en-us/library/aa287526(VS.71).aspx

Categories: Software Tags: , ,

Load an embedded resource

November 24th, 2009 digital No comments

I’ve embedded images into my app. Now I need to retrieve those images. Here’s code to do it.

Code:

using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Windows.Forms;

...

Image workingImage;

private void LoadImages()
{

	Assembly assembly = Assembly.GetExecutingAssembly();
	Stream file;

	if ( workingImage == null )
	{
		file = assembly.GetManifestResourceStream(".WorkingAni_32x32.gif");
		if (file != null)
		{
			workingImage = Image.FromStream(file);
		}
	}
}

Usage:

Change the <AssemblyName> to match your environment.  If you can't find the embedded resouce, use my "List Embedded Resources" snippet to find the correct path to your image.

The build action for the image properties must be set to 'Embedded Resource'.  

If you are adding a new image, the project MUST BE REBUILT before the image is embedded.  Rebuilding the entire solution is an easy way to ensure this gets done.
Categories: Software Tags: ,

Reflection within a method

November 24th, 2009 digital No comments
string callingAssemblyName = System.Reflection.Assembly.GetCallingAssembly().FullName;
string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
string className = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString();

Usage:

using System.Diagnostics;

Debug.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.ToString() + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "() called.");

or 

string methodName = System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.ToString() + "." + System.Reflection.MethodBase.GetCurrentMethod().Name;
Debug.WriteLine(methodName + "(" +  + ") called.");
...
Debug.WriteLine(methodName + "() ending.");

Categories: Software Tags:

One way to manage an ‘OK’ button with WPF / MVVM

November 20th, 2009 digital 1 comment

I am using the M-V-VM pattern on a WPF app. The rules that we are following on my team state that the View only knows about the ViewModel via the DataContext. The ViewModel has no explicit knowledge of the View.

BTW: I created the project using the WPF M-V-VM template available on CodePlex (I think?). It already contains the DelegateCommand classes.

I have an “OK” button.

In WPF, a button does nothing. If you want to do do “something” you have to wire up a command that resides in the ViewModel.

View:

<Button Command="{Binding UserClickedOkButtonCommand}" Content="OK" />

ViewModel:

public ICommand UserClickedOkButtonCommand { get { return new DelegateCommand( UserClickedOkButton); } }

public void UserClickedOkButton()
{
// do something
}

If you put a break point on the UserClickedOkButton, you will see the event is correctly mapped to the delegate method. So how do I close the View?

It takes a couple extra steps to get all of your ducks in a row.

First, add an x:Name=”ThisWindowName” to your View header.
Second, add a command parameter that refers back to your new window name.
Third, update the Command in the ViewModel to use a Window as it’s argument.
Fourth, use the input window argument to close the window.

Here’s the code.

View:

<Window
	...
	x:Name="ThisWindowName"
>
...
<Button Command="{Binding UserClickedOkButtonCommand}" CommandParameter="{Binding ElementName=ThisWindowName, Path=.}" Content="OK" />

ViewModel:

public ICommand UserClickedOkButtonCommand { get { return new DelegateCommand( UserClickedOkButton); } }

public void UserClickedOkButton(Window window)
{
	// Do Something
	window.Close();
}

The window is closed. Concerns are separated. MVVM rules are followed.

Works on my machine.

Categories: Software Tags: