Posts

Sql Server Reporting Services export to PDF in Landscape

So I have found a need to create ssrs reports in pdf format. Some of these reports contain a lot of data. So I needed to layout the page in landscape format. Sadly there is no page layout settings in srrs (once again Crystal wins but that is another story). So to achieve the same thing you will need to change the settings of the page. Open the properties of the report and set the width=29cm and height=21cm. These are the settings for landscape. Now you have a lot of extra room to move things around. I also found to maximize the report you can get the width of the report to about 22.86cm. So to summarize width=29cm (11.41") height=21cm (8.27") report data=27.30cm (10.75")

C# Finding all tables in access file

I recently found a need to access table names found in an access file dynamically. I found some code on the net to do this. But I discovered a bug, the code I was using would only read static tables. The files I was getting could contain linked and pass-through tables. So after some more searching I found the best way was to get all the tables (system, access) etc and then filter out only what I needed. So after some coding here is the solution. This is sitting in a function public static DataTable GetTableNames( string accessFile ) { OleDbConnection con = null; try { // create a connection string String connect = String.Format( "Provider=Microsoft.JET.OLEDB.4.0;data source={0}", accessFile ); // open the connection con = new OleDbConnection( connect ); con.Open(); // get all the tables in the file, system, etc DataTable dtAllTables = con.GetOleDbSchemaTable( OleDbSchemaGuid.Tables, new object[] { null, null, null, null } ); DataTable filterTable...

String.Replace vs Regex.Replace

Image
I recently ran into a situation where I had to do some string manipulation. I had to replace some bad text with valid text. All this had to do with creating valid xml element names. So we had to string white space and some other invalid characters and replace them with valid xml element formatting. To do this we ended up using the Regex.Replace static method. Simply because there was some complexity involved that would have entailed using more then 1 String.Replace call when we can do it all with one regular expression. This caused some discussion about how heavy the regex class is and when to use it. I decided to do some testing and these are my results. First the code static void Main( string[] args ) { // this is our test value string testValue = "This is a test string"; int count; // run the regex replace DateTime regexStart = DateTime.Now; for( count = 0; count < 10000000; count++ ) { string newValue = Regex.Replace( testValue, ...

Your code sucks and I hate you

It's been a while since I posted any code. I've been very very busy actually working and haven't had a chance to update the 'ol blog. Today we're getting away from straight code and getting more into the soft side of programming. I read an interesting article on code reviews. You should take a look at it over here: Your code sucks and I hate you Code reviews are something we do every time code gets checked into the main base line. They are important and help ensure high quality of code. However if you don't take some care they can quite easily get out of hand and develop into a personality/pissing contest between people. If you follow some decent guidelines you will find yourself amazed by the results. I know I hated code reviews in the past but have found them very helpful in uncovering bugs before they went into production. It does take some letting go of the ego but if you go in with the right attitude they will make you a better programmer/engineer/...

MFC reading from a .ini file

Recently I came across a need to read from an .ini file for an MFC application I'm working on. Now some might say why even bother using an .ini file, that's what the registry is for douchebag! Well I need something that a user can easily edit and store 3 small values and creating screens/forms to read/write to the registry doesn't interest me too much. So a simple ini file will do the trick. I found the perfect function is GetPrivatProfileString I however ran into some issues using this function. It's a win32 function and I'm using it in an MFC based application with CStrings. The function itself is expecting LPWSTR parameters so I thought by using the CString.GetBuffer method this would work. But I found this eventually will run you out of stack memory and cause exceptions. This even after using the ReleaseBuffer method that MSDN tells us to call after using GetBuffer. So in order to read all the values I needed from the file I found I had to read in LPWST...

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 search...

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 );