Showing posts from January, 2009

MFC search tree view based on label (name)

So I recently came across a need to use a tree view in an MFC based application. I also found I needed to search that tree based on the label (text displayed to the user). After some research I found an old link here at MSDN . However the article is almost 6 years old. MFC has changed a bit since then. So I had to change the code a bit to use all the new MFC macros for tree view usage. All these macros are also defined as functions on the CTreeCtrl class but doing it this way allows you to traverse any tree you want instead of being tied to a single instance. You can read more about the macros and treeviews here . All items are passed in except for MAXTEXTLEN which needs to be defined somewhere and included for reference. Mine is set to 100 since we can get fairly long long names in our application. The function: HTREEITEM GetItemByName( HWND hWnd, HTREEITEM hItem, LPCTSTR szItemName ) { try { // If hItem is NULL, start se

C# get current fiscal year stop and end dates

The following two functions can be used to determine the start and stop dates of the current fiscal year. They assume a standard FY of 10/1 - 9/30. The same logic applies if you want to modify them with different start dates. You will just need to use whatever DateTime values you want instead of the current. Get the start date // get the current month and year int month = DateTime.Now.Month; int year = DateTime.Now.Year; // if month is october or later, the FY started 10-1 of this year // else it started 10-1 of last year return month > 9 ? new DateTime( year, 10, 1 ) : new DateTime( year - 1, 10, 1 ); Get the stop date // get the current month and year int month = DateTime.Now.Month; int year = DateTime.Now.Year; // if month is october or later, the FY ends 9/30 next year // else it ends 9-30 of this year return month > 9 ? new DateTime( year + 1, 9, 30 ) : new DateTime( year, 9, 30 );

C# send email with .net framework

So I have come across a need to send some email via the .net framework to report status to a disto list we have for a product we support. The following code below shows the basics of sending a simple text email with 1 attachment. The values being assigned to the message are parameters coming from a function. You can assign any string value you want to them. All this can be found in the using System.Net.Mail namespace. // build the mail message MailMessage mailMessage = new MailMessage(); mailMessage.From = new MailAddress( From ); // this can be one at a time, or a , delimited list foreach( string toAddress in ToAddresses ) { try { mailMessage.To.Add( new MailAddress( toAddress ) ); }//end try catch( Exception ) { // do something with your error }//end catch }//end foreach mailMessage.Subject = SubjectLine; mailMessage.Body = Body; // add the attachment mailMessage.Attachments.Add( new Attachment( AttachmentLocation ) ); // send the message vi