Erich Peterson

Bio and Blog

Archive for the ‘Tech’ Category

Calculating Next Invoice Date

Have you have every needed to calculate the date of the next invoice for a customer given their frequency of payment (e.g. monthly or yearly), the day of the month the first invoice was sent out (e.g. 29th, 30th, etc…), and the date of their last invoice? This can be a little complicated. For example, let’s say your invoice for a customer who pays monthly, and signed up for service on the 30th of January. Well you cannot simply take their last invoice 1/30/2007 and add one month using LastInvoice.AddMonths(1) (which will give you 2/28/2007), for instance, becuase when you do the same the following month it will be 3/28/2007 instead of 3/30/2007 like it should be.

Other issues arise when it comes to leap years. The following code takes care of all the problems mentioned above:

VB .NET

Public Enum LicensePaymentType As Integer
  Monthly = 1
  Annual = 2
End Enum   

Private Function determineNextInvoice(ByVal LicType As LicensePaymentType, _
          ByVal InvoiceDay As Integer, ByVal LastInvoice As DateTime) As DateTime
  If LicType = LicensePaymentType.Monthly Then
     If LastInvoice.Day < InvoiceDay Then
        Dim Temp As Integer = InvoiceDay - LastInvoice.Day
        Dim NewInvDate As DateTime = LastInvoice.AddMonths(1)
        Return NewInvDate.AddDays(Temp)
     Else
        Return LastInvoice.AddMonths(1)
     End If
  ElseIf LicType = LicensePaymentType.Annual Then
     Dim NumDaysNextYearsMonth As Integer = _
           DateTime.DaysInMonth(LastInvoice.AddYears(1).Year, LastInvoice.AddYears(1).Month)
     If LastInvoice.Day < InvoiceDay AndAlso NumDaysNextYearsMonth >= InvoiceDay Then
        Dim Temp As Integer = InvoiceDay - LastInvoice.Day
        Dim NewInvDate As DateTime = LastInvoice.AddYears(1)
        Return NewInvDate.AddDays(Temp)
     Else
     Return LastInvoice.AddYears(1)
     End If
  End If
End Function

  • 0 Comments
  • Filed under: .Net General, Tech
  • Personalizing Feeds RSS with ASP .NET 2.0

    I just wanted to invite everyone to go over to 4GuysFromRolla and read my latest article entitled, “Personalizing RSS Feeds with ASP .NET 2.0“.

  • 0 Comments
  • Filed under: ASP .Net 2.0, Tech
  • Want to get replace those “smart quotes” that MS Word uses in your .NET code? This will do it:

    VB .NET

    Dim newstr As String
    newstr = oldstr.Replace(Chr(147), "& quot;") ' take out extra space b/w & and quot;
    newstr = newstr.Replace(Chr(148), "& quot;") ' take out extra space b/w & and quot;

    C#

    string newstr;
    newstr = oldstr.Replace((char)147, "& quot;") // take out extra space b/w & and quot;
    newstr = newstr.Replace((char)148, "& quot;") // take out extra space b/w & and quot;

  • 1 Comment
  • Filed under: .Net General, Tech
  • It has been my honor to have another article published on 4GuysFromRolla.com. Entitled “An Overview of Cryptographic Systems and Encrypting Database Data” and is the first of a two three part series.

    The first part (published today) gives an overview of what exactly is encryption, what are its properties, how can it be used, and what facilities SQL Server 2005 offers to help one create a cryptosystem.

    In part two, we go over SQL Server 2005’s key hierarchy, and T-SQL functions and statements that can be used with symmetric keys to encrypt/decrypt data.

    Part three, will introduce asymmetric encryption in SQL Server 2005, and how one can retrieve and send ecrypted data to/from an ASP .NET v2.0 web page.
    Hope you enjoy them!

    Update 2/28/2007: The final and third part of this article series has been posted entitled, “Using Asymmetric Encryption and Digital Signatures in a SQL Server 2005 Database“.

    Update 2/21/2007: The second part of the three part series has been been posted entitled, “Using Symmetric Encryption in a SQL Server 2005 Database“.

    Meebo: Free Online IM’ing

    Jiang told me about this one and thought I would share it. It’s called Meebo and with it you can IM on all the popular instant messaging services though an AJAX-ladan web page!

  • 0 Comments
  • Filed under: Tech
  • The Wii Has Arrived

    Finally got a Wii after wanting one for a while, and is it worth every stinking penny. Bian, Jiang and I, went half and half on one and he purchased Zelda: The Twilight Princess (which is fantastic).  The last gaming console I bought was the Turbo Graphix 16/Turbo Express! So, I’ve been away from the console gaming thing for a while, and I forgot how great it can be. Wish me luck catching those virtual fish in Zelda…

  • 2 Comments
  • Filed under: Tech
  • Firebug

    Firebug has to be one of the best Firefox add-ons for web developer’s I’ve seen in a very long time. See HTTP headers, edit CSS on-the-fly, see network activity (i.e. see what is taking the most time to download), debug Javascript, editHTML, and on and on. Check it out for yourself by following the link above.

  • 0 Comments
  • Filed under: Tech
  • ASP .NET AJAX v1.0 Released

    Microsoft’s AJAX Framework, formaly code-named “Atlas” has now come out of Beta status and is now available in version 1.0. Now known as ASP .NET AJAX; it can be downloaded here, and there are some good tutorial videos on the ASP .Net site as well.

    OpenID

    OpenID provides a way in which you can log into multiple site, without having to create a seperate account on each one. It uses a decentralized achitectual model, and you can even setup your own OpenID server or even use your own domain name as part of your login.

    Pretty neat stuff. I hope this catches on with a lot of existing and new sites. Check out this video for a preview on how it works.

  • 0 Comments
  • Filed under: Tech
  • Apple iPhone + Nintendo Wii

    Three words: “I want one!” Oh yeah, I want this too.

  • 0 Comments
  • Filed under: Tech