Friday, November 21st, 2008
Shopping carts are basically a dime a dozen. But there’s always some component of them that doesn’t quite fit into your current model. So what do you do when you are up against a deadline and need to quickly produce a basic front end of a shopping cart to hold items and quantities in .NET using on Session Variables?
I came up with this solution after thinking about a quick way to avoid having to read and write to a database, but not storing elaborate arrays and such to try and accomplish a very simple shopping cart structure.
// Get the Item We're Going to Add to the Cart
int itemID = Convert.ToInt32(Request.QueryString["itemid"]);
// Get the Item (I use a Business Logic here, but you could easily grab the item information from your //database call or items from a grid, etc.
item m = new item();
itemAssembler ma = new itemAssembler();
m = ma.ReadSingleByKey(itemID);
// Now grab a random number so we can track the items in the cart individually
Random rand = new Random();
int x;
x = rand.Next(100000, 999999);
// Check and see....Do we have a cart already?
if (Session["cart"] == null)
{
// Add the item to the cart
NameValueConfigurationCollection cart = new NameValueConfigurationCollection();
//Add an Item to the cart ("ITEM",Variance, ItemID,Quantity)
NameValueConfigurationElement nvc = new NameValueConfigurationElement("ITEM," + x.ToString() + "," + "1", m.id.ToString());
cart.Add(nvc);
Session["cart"] = cart;
}
else
{
NameValueConfigurationCollection cart = Session["cart"] as NameValueConfigurationCollection;
//Add an Item to the cart ("ITEM",ItemID,Quantity)
NameValueConfigurationElement nvc2 = new NameValueConfigurationElement("ITEM," + x.ToString() + "," + "1", m.id.ToString());
cart.Add(nvc2);
Session["cart"] = cart;
}
// Now take your user to the cart view page you'd create
Response.Redirect("your_cart.aspx");
Now on our “your_cart” page, you can now loop through the items in the cart and display them however you’d like.
// Let's load the items from the shopping cart into the table
NameValueConfigurationCollection cart = Session["cart"] as NameValueConfigurationCollection;
foreach (NameValueConfigurationElement n in cart)
{
//Now split the value for the Item Type, the ID, and the Quantity
String typelist = n.Name;
char[] sep = { ' ', ',', '.', ':', '\t' };
String[] typeitems = typelist.Split(sep);
//Hold these values in some String Variables
String type = typeitems[0];
String cartitem = typeitems[1];
String qty = typeitems[2];
//Now set up our currency display
System.Globalization.NumberFormatInfo nfi = new System.Globalization.NumberFormatInfo();
nfi.CurrencyDecimalDigits = 2;
nfi.CurrencySymbol = "$";
//Take your business/data logic and grab the information
item i = new item();
itemAssembler ia = new itemAssembler();
itemCriteria ic = new itemCriteria();
if(ia.ReadSingleByKey(Convert.ToInt32(n.Value)) != null)
{
i = ia.ReadSingleByKey(Convert.ToInt32(n.Value));
// Get the Retail Price
int productid = i.id;
pricing pps = new pricing();
decimal retailprices = Convert.ToDecimal(i.retail);// +Convert.ToDecimal(i.shipping);
//Now take the Table you have on your display page and add rows to it...
HtmlTableRow mainrow = new HtmlTableRow();
HtmlTableCell maincell = new HtmlTableCell();
maincell.InnerHtml = "
| " + i.name + " |
Remove Item |
";
mainrow.Cells.Add(maincell);
tblCase.Rows.Add(mainrow);
}
System.Globalization.NumberFormatInfo tnfi = new System.Globalization.NumberFormatInfo();
tnfi.CurrencyDecimalDigits = 2;
tnfi.CurrencySymbol = "$";
// Now populate the items on the Total Costs Table
lblSubtotal.Text = String.Format(tnfi, "{0:c}", subtotal);
lblTax.Text = String.Format(tnfi, "{0:c}", tax);
lblShipping.Text = String.Format(tnfi, "{0:c}", shipping);
total = subtotal + shipping + tax;
lblTotal.Text = String.Format(tnfi, "{0:c}", total);
}
You now have a simple shopping cart in just a few lines of code since most of the code is used to get the information about your particular item and can be streamlined even more if you wanted to store all of that into the string as well. Ok, so now that you have a way to put together a quick cart for your client before morning….happy coding
Posted in Shopping Carts, Web Development, Web Programming, asp.NET | No Comments »
Wednesday, November 19th, 2008

Windows Server 2003
At some point in your web development or web programming career, you will find yourself faced with the task of having to go on to a web server, perhaps Linux Apache or Microsoft IIS, and need to do some system tasks such as adjust some security settings, etc.
But what if you’ve never read or taken any education in regards to a web server? You could find yourself in a situation where you can cause more harm than good.
Here’s an example. A client of mine had a stack of servers co-hosted at a location. The servers were delivered pretty much as-is with some basic virus software on it and Windows Server 2003. I took over one of the three servers and the other developer took on the other. We discovered tonight after a hack attempt, that the other developer had never disabled the local Admin account…big whoops.
So for those of you who would like to pass Networking/Server Support 101…here’s what you do. Go to Computer Management under the Administrative Tasks location on the Start menu. Next, click on users, and then you’ll see in the right hand pane a list of users. Now this is very important, make certain you have created a new user or updated an existing one…let’s say johnsmith, and added her/him to the Administrators Group. If you don’t do this you could find yourself in a heap of trouble. Ok, now that you’ve done/verified that, right click on the Administrator user and click Properties. In the dialogue, check the “User is Disabled” checkbox. This will essentially disable this user and you may avoid a low level attack on your web server as a result.
Be careful though, there’s a lot to networking and support in these systems, so be very sure to double check everything you do not only with a site like this one, but others as well…there’s always new information coming out every day about hack attempts and you’ll want to make sure that you are up to date with the information that will keep your information safe and secure as possible.
Until next time…happy coding.
Doug.
Posted in Networking Support, Web Development, Web Programming, Web Server | No Comments »
Monday, November 17th, 2008
Ok…did you ever have one of those days where at the end of the day you’re sitting there going….man I wish I would have known that earlier…I could have saved myself a lot of time and heartache. Well that was me today.
You would think with all of the databases I work with I would have had this come up, but surprisingly enough I’ve never had to migrate or transfer an entire database structure from MS SQL 2005 to MySQL. I googled just about every combination out there and came up with all of these programs from overseas that claimed to

MySQL Migration Toolkit is Just What You Need!
work perfectly, but even in their trial modes they failed miserably.
The Solution…MySQL Migration Toolkit
I tried one more google which happened me on to an article which was written by a colleague who wanted to let people know about turning on TCP/IP addressing in MSSQL 2005 if they were having trouble using the MySQL Migration Toolkit. I quickly clicked on the link for the MySQL Migration Toolkit (which is a part of the MySQL
GUI Tools) and in almost 5-10 minutes later I had my entire MSSQL database moved to MySQL.
Now it seems a little bit more complex than it actually is. Literally all you really need are the username/passwords for the respective databases and the name of the database you will need to connect to and obviously transfer to MySQL. The only pitfall I ran into was during the creation of one of the tables in the database where it didn’t like the default of a 1 or “true” value in a boolean field. I went ahead and clicked the “Advanced” button at the bottom, looked at the SQL statement, took out the DEFAULT (1), and then clicked the “Recreate Objects” button. It worked like a charm after that.
Don’t Have “One of those Days”
So hopefully someone will also google this and if I’ve been taught well by my SEO expert friend Mat Siltala has taught me correctly….you’ll have found this article and will already be moving on to your next task of the day. Happy Migrating!
Doug.
Posted in Databases, Web Development, Web Programming | No Comments »
Friday, November 14th, 2008
Many times this question comes up from both potential clients and fellow web programmers. “Should I or Could I get a Flat Fee for this Job?”. The answer isn’t so simple in many cases and can get you into a lot of problems as far as what to provide for your client, how to handle change requests, and more.
Why You as an Employer Shouldn’t Ask for a Flat Fee
As a business owner who is ready to get their idea going on the web, the first thing you need obviously is a product or service to sell/offer, and then get a website to do just that. You would love to have a fixed cost associated with developing the website idea and know that when all is said and done…that’s the price you pay. However you’ll find in many situations, that this creates a strain on the relationship between you and the devleopment company you choose.
Changes…They’re Inevitable.
We all believe that as good business people, we spec out a plan, spec out a website, know all of the drop downs we want, the pages, the look, the feel, etc. I can tell you from over 18 years of experience of designing webpages I have yet to have a project where a client hasn’t wanted to change something. In many cases I’ll hear, “This is just a small change.”. But because of the backend programming…it may not be. Here’s where the trouble of a fixed cost project comes in.
But that’s more than I wanted to spend!
So the client changes their mind, I tell them that according to our Flat Fee project agreement, this is different than what was agreed to and hence a change fee is now going to be charged because now the hours I thought the project was going to take is now going to be longer than expected, which means other projects coming up may need to be shifted back some, or I may have to get another developer to work on it which may be a higher cost, etc. You see where this is going. Now we’re into an argument over why its a change request when it’s just a small change. Now the relationship is experiencing strain.
Hourly Rates to Save the Day
Now, if we took that same scenario, and placed it into an hourly contract. We see it is much more manageable. The client makes a change…no problem…we say that change is about 2 hours worth of work, and we do it. Everyone is happy…no change fees, etc.
Real Desires vs. Lofty Desires
When a project is hourly, the client has direct control over the final cost of the project. When bidding, we give them a range of what we feel the project will take to complete it. So they know the top end, and try to stay under it. So you find those “creative changes” are kept to a minimum and thus…so does the project’s cost.
Web Developers Nickle and Diming Clients
Now, I’m not saying the hourly projects don’t have their drawbacks. You need to really feel good about working with the development company you choose, and don’t be afraid to ask for references. I personally do not charge my clients for every single email I answer and every phone call I get. Now, if the phone call ends up taking 30 minutes, or the email requires me to research some items to get back with the client…certainly….but ask your company how they bill. If they say in houly or half-hour increments…that could be pretty expensive. Justice Solutions personally bills in 15 minute increments since usually an email that required research or a phone call takes in total at least 15 minutes to do.
Ask for a Weekly Time Sheet
Also don’t be afraid to ask for a time sheet showing the hours for the week. If you know where the project is every week, the final bill or quarterly bill won’t be so shocking.
Conclusion
Flat fee projects sound great at first, but can very quickly strain a relationship between you and the developer. Ask for an hourly contract and then have them put into the agreement a guide to give you an idea as to what the project will ultimately cost. Now if you change the way the website will behave, you can do so without worry, but make sure to get an estimate on the hours the change will cost. It will help you decide if you should make that change now, or maybe wait until a future phase of the project.
Thanks for reading and hopefully this will help you keep a good relationship between you and your clients, or you and your developers.
Doug.
Posted in Project Management, Web Development, Web Programming, Website Bidding | No Comments »