Posts

Showing posts from 2007

Microsoft LINQ

Ok so I'm working on a fairly large ASP.NET project for the federalies (I really can't say which agency). Right now we're pumping data to the app using datasets and saving with direct SP calls. This was fine when the app was in it's infancy. But we're rapidly hitting large scale volumes of users and this approach is limiting us in scope and scalability. Most people suggest going a pure OOD route and turning result sets from your DB into .net classes. This has to be done via an O/R (object relation) mapper that can take a number of tables, rows, columns into the correct collection of classes. I looked into some 3rd party solutions and most people suggest NHibernate. However NHibernate doesn't work with 100% stored procs for data access. And guess what we use nothing but stored procs to get data to/from the DB. So that option goes down the chute. Low and behold I find some references to LINQ from MS. I do some reading and found it's pretty bad ass.

I was a little hard on FF the other day

Ok so I was on a rant the other day about FF 3 beta. Yes it still sucks memory and it killed almost all of my extensions but after trying to use IE 7 fulltime, well urg. 300 MB with 2 tabs is still not good but well they're working on it I think. It's still a pretty good browser and I find myself using it. For those running 2.x I think you should stick with it until they get 3.0 ready to rock for the prime time. Also some guy from Mozilla posted on the blog and gave some links to look at. That's pretty cool and let's me know they care about issues with the browser. Pretty rad if you ask me.

FireFox 3 is still a memory whore

Image
So I installed the FF 3 beta the other day to see what coolio replacements it had. I was really hoping it would stop the annoying tendency of FF 2 to whore memory like no other. FF 2 would routinely grab 300 MB with 1 or two tabs open. I've read storied about it taking up to a gig but I've never see that on my machine. So after install almost all my extensions got killed. 2 made it through adblock and noscript. Not a good start, so I open like 10 tabs browse to various sites and then close back down to two tabs. The memory sucking is still there and it evens beats my visual studio! Overall it's been a pretty blah experience browsing with this new version of FF. I haven't noticed any new and great things from my upgrade to 3. I might actually go back to IE 7 if the memory whoring continues. I think FF hit its stide in 1.5 and has just gotten more and more bloated. Come on guys fix the memory whoring!

New software in unleashed!!!

Well it had to happen sooner or later. I have released a new version of the IP Viewer tool. It now hides from the alt-tab menu and runs quite a bit faster. For some reason it was hitting the .config file way to much. Now it keeps those values in memory until the settings get updated and then it re-reads them. Also Tile Puzzle 1.0 has been released. You can take an image from your PC and turn it into a tile puzzle game. It took me about a week of hard coding to get it working. It's pretty cool actually, it uses GDI+ to cut an image, and uses collections, and sorting methodology to manage the puzzle pieces. No source yet but the game is working pretty bad ass. Head on over to: JRL Software and check out the goods.

Cutting an image into sections

Ok so I'm working on an app that takes an image and cuts it into 16 pieces for a small puzzle game. The problem is how to do this. The solution is GDI+ to the rescue! I found some help on MSDN to eventually get this code. My puzzle needs to be 16 pieces and each piece is a small section of a larger bitmap. // get the piece width and height pieceWidth = _originalImage.Width / 4; pieceHeight = _originalImage.Height / 4; // clear the existing puzzle _puzzle.Clear(); for( int i = 0; i < 4; i++ ) { for( int j = 0; j < 4; j++ ) { Rectangle srcRect = new Rectangle( i * pieceWidth, j * pieceHeight, pieceWidth, pieceHeight ); // Create the new bitmap and associated graphics object Bitmap bmp = new Bitmap( pieceWidth, pieceHeight ); Graphics g = Graphics.FromImage( bmp );

.NET vs Native Win32 code

Ok so I've been writing apps using C# for a couple of years now. I had done some work in MFC but not much. Mostly console stuff very little GUI work. Well I recently thought how hard could it be to work in win32? The answer is mixed of course. I should give some background on how this came about. I recently published a ip viewer tool written in C# that monitors your ip address. It sits in the system tray and when double clicked shows a dialog form. It took me about 8 hours of coding to put together. It runs and works and does its job well. However it takes the .net framework v2 which as much as MS wants to say isn't standard on pc desktops across the world yet. And while it's not slow, on first load it sure as hell ain't fast. After first load it's pretty snappy but damn it looks like hell until it does. And this app isn't very large a 72KB exe is all. 3 forms and 1 support dll that really could be in the exe. So I decided to write the exact same t

Copying data to the clipboard using C#

So you need to copy data to the clipboard using .net. Usually Ctl-C, Ctl-V is good enough for me. But there arose a need to copy data from a context menu. Microsoft has actually made it pretty easy to get data to/from the clipboard. They have conveniently created a class to do this and called it Clipboard. For my uses I just needed to copy some basic text to the clipboard. To achieve this I simply use the method SetText. Easy as pie! so a qucik and dirty example is Clipboard.SetText( "Hello World!"); Will put the text Hello World in your clipboard. There are of course different methods for copying all sorts of data into the clipboard. Read the MSDN for the complete breakdown. Read the MSDN article

I am a published shareware author!

Woot! I am now officially a published shareware author! I released IP Viewer to the masses on topshareware.com. 19 suckers , I mean users have downloaded my software so far. I even released it under the GPL 3.0 so if any of you cave dwellers wants to use it feel free. I have pushed it to version 1.1 already to include the host name as well. Now let's hope I don't get sued by some douche who beat me to the punch! So go to the site or visit my website and download the thing.

Creating an app that can minimize to the tray

So for a long time I've wanted to create an app that can minimize to the system tray. MFC could do it but you had to call some compilcated win32 routines. I've found .net 2.0 makes this easy! Yay for .net. What you need to do is add a NotifyIcon control to your application. This will display an icon in the system tray with an icon of your choice. For my app I simply set the initial Visible property to false so you can't see the icon and then when the user minimizes the application I set the main forms ShowInTaskbar property to false and set the NotifyIcon Visible propety to true. And instantly you get no app and an icon in the taskbar. To get it back add a DoubleClick event to the NotifyIcon and restore the main form. Now users can minimize my app to the tray and double click it to get it back. The program is done and is now ready for download at Link to the site

Awesmome pics

Linky Link . Seriously I don't know if they're all real or not but they kick ass none the less.

String.Empty vs ""

Image
So I've always heard you should use String.Empty vs "" the dreaded blank string in C#. So I decided to write a little test program to find out. It simply takes a string variable and assigns it to "" or String.Empty. I do this 1 million times each and time how many milliseconds it takes to do that assignment. My system is a p4 1.5 GHz RAM running .net 2.0. Source code can be sent upon request. The results are surprising and can be seen below. Other then the first run the String.Empty beat the "" by a few milliseconds. Hardly the creaming I've read about. But perhaps if you were doing some severe number crunching you would notice a difference. However this test is hardly definitive and should probably be run several more times and had the numbers aggregated. I've run the app a lot more since yesterday but only added one more screenshot. I may just post the screen UI and then keep track of the results in a spreadsheet or modify the app

Nested Repeaters in ASP.NET

Ok so you may want to show some hierarchical data using repeaters. This means nesting a repeater in a repeater. This is fine but it takes some work in the code behind. First off create the main repeaters ItemDataBound event. In that event use the following code. I am old school so forgive me any syntax. For this code to work you must originally bind a DataSet to the parent repeater with a data relation connecting the parent/child tables. So somewhere (I do mine in page load) bind the entire dataset to the repeater: RepeaterCapabilities.DataSource = someDataSet; RepeaterCapabilities.DataBind(); Then put the following code in the repeaters ItemDataBound event protected void RepeaterCapabilities_ItemDataBound( object sender, RepeaterItemEventArgs e ) { Repeater rptActivities; DataRowView drv; // get the row behind the databind drv = e.Item.DataItem as DataRowView; if( drv != null ) { // get the nested repeater r

Reading & writing connection strings to an app.config file in C# 2.0

Ok after working on this for a bit this morning I am sharing my experience with the world. I needed to read and write some connection strings found in an app.config file I was using in a small C# .NET 2.0 application. First you must have a reference to the System.configuration dll in your project and use the System.Configuration namespace in any C# files you want to do this stuff in. This sample assumes you have your connection strings in a connectionString section of an app.config file. Reading the connection string: ConfigurationManager.ConnectionStrings["Connection Name"].ConnectionString Writing the connection string: // get the config file for this application Configuration config = ConfigurationManager.OpenExeConfiguration( ConfigurationUserLevel.None ); // set the new values config.ConnectionStrings.ConnectionStrings["Connection Name"].ConnectionString = "Connection String Value"; // save and refresh the config file config.Save( Confi

Javascript numeric only text box

So working on an asp.net page I found I needed a numeric only text box that allowed numbers from 0-100 with no decimals. I found a range validator would do most of the work but I wanted to keep users from typing in bad values. So after some searching I found javascript has a good solution. I like whitespace so shrink if you're one of those white space freaks. Update: someone was kind enough to point out an error in my JS! So I went through and made sure it works. And it did need a minor tweak to be correct. So thanks to the poster the corrected script and usage are below. Update Again: This is the new and improved function to allow for the tab key to tab out of the text box. IE allows this by default however Firefox really tightens down the text box and doesn't allow anything you don't specify. So I had to add the tab key press. I also cleaned up the code so it isn't a huge chunk of if blocks and is now much more succinct. Please feel free to test and us

Welcome jrl-software

Well the end has started. I finally got jrl-software.com up and running. Clickity Click The main reason is to pimp my recently released utility called filesort. It sorts a file alphabetically in a pretty quick amount of time. So check out the site and send me feedback!

Convert HTML color to System.Drawing.Color

Ok so I have an HTML color I need to use in an asp.net web app. Problem is most of the asp.net controls use System.Drawing.Color. So I can't just go TextControl.BackColor = "FFFFFF"; or whatever you have to convert the HTML to a System.Drawing.Color like so: TextControl.BackColor = System.Drawing.ColorTranslator.FromHtml("FFFFFF"); And voila! HTML colors are now System.Drawing.Colors

Task bar shuffle

I've always hated I couldn't move programs around in the taskbar. Well some dude has come up with the answer! Praise Jebus! Clicky Clicky

Converting an ArrayList to a String[] Array

ArrayList fileArrayList = new ArrayList(); //Populate fileArrayList ... string[] files = fileArrayList.ToArray( typeof( string ) ) as string[]; I prefer the as command versus the old style boxing methods.

Format string array to character seperated list

Ok so I've been needing a way to take an array of strings and make a list of comma or whatever character and turn it into one big string of items. Today I finally found a quick and painless (to the coder, maybe not the compiler) solution.  string[] ids = {"2343","2344","2345"};  string idString = String.Join(",",ids);  Response.Write(idString); After this code you get one string with all the items in the array seperated by a comma. Of course just chaning the char in the String.Join methods gives you different results.

VS 05 Formatting

Good God, I have always hated the default code formatting of visual studio 2005. It drives me up the wall. For some reason I could never figure out how to change it. Now due to the grace of God and Jebus I have discovered the light. Some dude's blog You go dude, I'm finally glad to be able to get rid of that shitty auto formatting and get my code to look right. Some guys like compact code, I prefer more whitespace for ease of reading. So hopefully I can pass this information on to other people who are looking for it.