WPF: Right Aligning Textblocks in a Gridview 

No Comments

If you are trying to get a TextBlock to right align, in ListView inside Windows Presentation Foundation  take a look at this.  I was using a GridViewColumn.CellTemplate to define a column with some monetary values in it.

privatePlus - WordPress Plugin 

Comments Off

By default, WordPress only allows administrators and editors to view private posts. This WordPress plugin will allow you to determine which groups are able to see private posts by default. It will allow other authenticated users to view ‘private’ posts.

View more details on the privatePlus page.

Benefits of using the StringBuilder Class 

No Comments

The old phrase, ‘Work Smarter, Not Harder’ is a good one to live by. As software developers, we often find ourselves writing code that build strings. We start out simple, with a few lines of code that concatenates different text together to create a new variable. It’s easy, quick and dirty.

string myString = “Counting to ten: “;
for (int i = 1; i < = 10; i++) myString += i + " ";

Later, this small string gets more complicated, becoming larger during each step of the software. Often we create clever loops and logic that dynamically builds long complicated strings. At the end of the day, it’s a ‘Bread and Butter’ activity for us.

You may be surprised to find out that this simple activity could be a major cause of a slow web application. Fortunately, a very simple fix can help you to gain back the performance and resources that you lost.

Read the rest of this entry »

Using While Statements inside MSSQL Stored Procedures 

No Comments

This was a bit more complicated than the IF statements, but extremely useful.  I was able to

Procedure [dbo].[deleteParticipant]
@ParticipantID int

as

– Declare the variables to store the values returned by FETCH.
DECLARE @GroupID int
DECLARE group_cursor CURSOR FOR
SELECT GroupID FROM Participants
WHERE ParticipantID = @ParticipantID

OPEN county_cursor

– Perform the first fetch and store the values in variables.
– Note: The variables are in the same order as the columns
– in the SELECT statement.
–FETCH NEXT FROM group_cursor
–INTO @GroupID

– Check @@FETCH_STATUS to see if there are any more rows to fetch.
WHILE @@FETCH_STATUS = 0
BEGIN

IF (SELECT COUNT(*) FROM Participants WHERE GroupID = @GroupID) = 1
BEGIN
DELETE FROM Groups WHERE GroupID = @GroupID
END

– This is executed as long as the previous fetch succeeds.
FETCH NEXT FROM group_cursor
INTO @GroupID
END

CLOSE group_cursor
DEALLOCATE group_cursor

–delete all group affiliations
Delete From  [dbo].[Groups]
WHERE ParticipantID = @ParticipantID

–delete The Participant
Delete From  [dbo].[Participant]
Where ParticipantID =  @ParticipantID

Using If Statements inside MSSQL Stored Procedures 

No Comments

Adding IF statements to a MSSQL Stored Procedure can help make a query more dynamic. For instance, if we had are deleting a participants from a group and wanted to remove a group after the last person was removed, we would do the following:

DELETE FROM Participants
WHERE ParticipantID = @ParticipantID AND GroupID = @GroupID

IF NOT EXISTS (SELECT ParticipantID FROM Participants WHERE GroupID = @GroupID)
DELETE FROM Groups WHERE GroupID = @GroupID
RETURN

.Net Replacement for PHP’s str_replace 

1 Comment

Here is a quick and dirty function that I grabbed from ( http://support.microsoft.com/kb/251354/ ). It does a nice job of replacing PHP’s convenient str_replace.

Private Function str_replace(ByVal strSource As String, _
ByVal strSearchFor As String, ByVal strReplace As String) As String
Dim lngPointer As Long, strNew As String
lngPointer = InStr(strSource, strSearchFor)
If lngPointer = 0 Then
ReplaceEntXMLSpecChar = strSource
Else
strNew = Left$(strSource, lngPointer - 1) & strReplace _
& Mid(strSource, lngPointer + 1, Len(strSource))
ReplaceEntXMLSpecChar = strNew
End If
End Function

Time and Date Formatting in .Net 

No Comments

I always find myself hunting for a quick reference on formatting various strings, including time and dates in .Net.  Here is a great reference.

.NET Format String 102: DateTime Format String

http://blogs.msdn.com/kathykam/archive/2006/09/29/773041.aspx 

Submitting the SiteMap Protocol to Search Engines 

No Comments

The Sitemap Protocol allows us to inform search engines when a page has been changed and is ready for crawling. The Sitemap file is a dynamically generated XML file that lists the URLs for a site. It allows search engines to crawl the site more intelligently.

You can get a more complete description of Google Sitemaps here:
http://www.sitemaps.org/faq.php
http://en.wikipedia.org/wiki/Google_Sitemaps

Submit your SiteMap through the robots.txt file

Search engines can automatically discover the SiteMap file by adding the following line to the robots.txt file.

SITEMAP: http://www.brandonpetersen.com/sitemap.xml

Submit your SiteMap to Google

Go to http://www.google.com/webmasters/

Submit your SiteMap to Yahoo

http://siteexplorer.search.yahoo.com/

Submit Your SiteMap to MSN

http://api.moreover.com/ping?u=http://www.brandonpetersen.com/sitemap.xml

Submit your SiteMap to Ask.com

http://submissions.ask.com/ping?sitemap=http%3A//www.brandonpetersen.com/sitemap.xml

Kerning inside Photoshop 

No Comments

Kerning is the process of adjusting letter spacing in a proportional font. In a well-kerned font, the two-dimensional blank spaces between each pair of letters all have similar area. Wikipedia.

To add kerning between each letter in Photoshop you place the cursor between the letters and press Option+RightArrow on a Mac (or Alt+RightArrow in Windows). To remove kerning between each letter in Photoshop you place the cursor between the letters and press Option+LeftArrow on a Mac (or Alt+LeftArrow in Windows).

If you need an entire word or sentence kerned the same way, just select the group of letters and repeat the process above.

Changing the Ownership on Database Object 

No Comments

I have to move databases between servers recently, doing a backup and restore. I had some issues arise from improper ownership of tables and store procedures in Microsoft SQL Server (MSSQL). I fixed the issue quickly through the following query:

sp_changeobjectowner ‘object’, ‘new_owner’