Cash for Clunkers - FAIL

June 24, 2009 09:16 by bjones

Starting in July, you can trade in your old "clunker" for a new car and receive a $3500 or even $4500 voucher. The purpose of this bill is to put more fuel efficient vehicles on the road and get rid of guzzlers. It sounds like a good idea but their oversites have failed to make it a great idea and therefore have failed completely.

What would have made it better?

  • Why just improve gas mileage? Why not improve emissions too? A car from 1990 has a higher emissions standard than a 2010 model. Why not get rid of the 1990 car and get a cleaner burning car on the road?
  • Why not use this as a time to help stimulate the economy and help the failing car manufactures? Since it’s the US tax dollars that are paying for the vouchers, why not have given an extra bonus for buying a GM, Ford or Chrysler?

 

There are so many problems with the implementation that the program is worthless. First, you have to trade in your old car for a new one that improves the combined fuel economy by at least 2 MPG for light duty trucks and 4 MPG for passenger cars. If you improve your truck or car by 5 or 10 MPG, respectively, you will get the full $4,500 voucher. Why is the 2/4/5/10 MPG a problem? Because, in 2008, they changed the way they rate MPGs of cars. Starting in 2008 the EPA changed the rating to be at a faster speed, faster acceleration, air conditioner on and colder outside temperatures. This means that the new car ratings are more accurate but what it really means is that the MPG rating for your "clunker" is going to be inflated and makes it almost impossible to achieve the improvements needed for the voucher.

My dad has a 1993 GMC Sonoma truck. It’s considered a light-duty truck and therefore requires a 2/5 MPG improvement for the vouchers. The best way to describe his 16 year old truck is to call it a clunker. The EPA says it gets a combined 18 MPG. In order for him to qualify for the $3,500 voucher, he will have to buy a vehicle that gets 20MPG or better. Good luck finding that in a truck. After calling the NHTSA, they recommended he buy a sedan or a hybrid truck. Get real! A GMC Sierra Hybrid starts at $39,365 and it’s rated at 21/22 MPG for a combined 21 MPG. The non-hybrid GMC Sierra starts at $20,350 and is rated at 15/21 MPG for a combined 18 MPG. That means a 3 MPG improvement costs $20,000. The improvement in emissions and gas mileage are virtually nil. The improvement over a 18 MPG GMC Sierra and his 1993 GMC Sonoma are a real 3 MPG improvement (real, not over inflated EPA ratings) and a huge improvement in emissions.

The government is not encouraging my dad to buy a new truck. Therefore they are not:

  • Getting rid of a large polluting vehicle
  • Improving real gas mileage
  • Stimulating the economy.  For a bankrupt American car manufacture!



-FAIL-

 

 


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories: op ed | Politics | Rant
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Prepoulate a form with data from a DataTable in .net

June 3, 2009 05:42 by bjones

Abstract

A simple .net class that will prepopulate form data on a page.  My requirements were to be able to find a control anywhere on a page (with or without a masterpage) and still be able to control the look of the form.  I did not want to dynamically create the controls because I want to easily control the look of the form without adding any metadata in to the database.

 

Meat and Potatoes

Inevitably when building a website I will have a page (or multiple) that should display information about an item, account, person, etc.  For example, I always have a "My Account" page where I will show the user data we have collected that could be everything from their name and email address to their shoe or ring size.  There could be a dozen or more fields displayed.  Some fields may be read-only (Label) and some may be editable (TextBox).  I start out building the page in the designer with a table and then adding all of my fields as either a TextBox or Label.  Then, I switch to the code behind and poulate a DataTable with the information I need.  The DataTable is always a single row with all that person's data.  I then have to type all the fields names and set their Text value to the DataTable's records.  Rinse and repeat, ice the wrist, rinse and repeat, etc.

In the .aspx page I may have:

[code:c#]

<table border="0" cellpadding="10" cellspacing="0">
    <tr>
        <td align="left">First Name</td>
        <td align="left"><asp:Label ID="aFName" runat="server" /></td>
    </tr>
    <tr>
        <td align="left">Last Name</td>
        <td align="left"><asp:Label ID="aLName" runat="server" /></td>
    </tr>
    .
    .
    .
</table>

[/code]

In the code behind I would then have to do this:

[code:c#]

aFName.Text = dt.Rows[0]["aFName"].ToString();
aLName.Text = dt.Rows[0]["aLName"].ToString();
aEmail.Text = dt.Rows[0]["aEmail"].ToString();
aDisplayName.Text = dt.Rows[0]["aDisplayName"].ToString();
aCellPhone.Text = dt.Rows[0]["aCellPhone"].ToString();
aSignUpDate.Text = dt.Rows[0]["aSignUpDate"].ToString();
atDesc.Text = dt.Rows[0]["atDesc"].ToString();
.
.
.

[/code]

 

This is an inefficient use of time and caffeine.  Since I do this all the time, I decided to write a class that does this in a more efficient way.  When you create the page design you have to name the controls the exact same name (case sensitive) as the column in your DataTable.  We loop through the DataTable and do a FindControl to then populate the data.  This worked fine until I created a page with a MasterPage - ugh!  FindControl isn't recursive so I hunted online and found a recursive FindControl and included it in my class.  Now it works on all pages.  I have cut my time (not caffeine intake) down considerably.  Now I can use that found time to blog :)

 

Here's the class (webhelper.cs):

[code:c#]

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Form functions
/// </summary>
public class webhelper
{
    /// <summary>
    /// Finds a control recursively.  Works in a page that has a masterpage, otherwise FindControl will return a null.
    /// </summary>
    /// <param name="root">Parent to search for - use "this"</param>
    /// <param name="id">Name of control you are searching for</param>
    /// <returns>Control - control you are searching for or a null if it's not found</returns>
    public static Control FindControlRecursive(Control root, string id)
    {
        if (root.ID == id)
        {
            return root;
        }

        foreach (Control c in root.Controls)
        {
            Control t = FindControlRecursive(c, id);
            if (t != null)
            {
                return t;
            }
        }

        return null;
    }

    /// <summary>
    /// Will pre-populate textbox and labels on a page with information from the first row of the DataTable. 
    /// Common use would be an account information page where you only have one row returned.
    /// TextBox and Label ID's must match the column name in the DataTable.
    /// </summary>
    /// <param name="root">Send "this" as the page root.</param>
    /// <param name="dt">DataTable with a single row.  If there are multiple rows it will only prepopulate the form with the first row.</param>
    public static void populateForm(Control root, DataTable dt)
    {
        for (int i = 0; i < dt.Columns.Count; i++)
        {
            Control c = FindControlRecursive(root, dt.Columns[i].ToString());
            if (c != null)
            {
                if (c.GetType() == typeof(TextBox))
                {
                    TextBox myBox = (TextBox)c;
                    myBox.Text = dt.Rows[0][i].ToString();
                }
                else if (c.GetType() == typeof(Label))
                {
                    Label myLabel = (Label)c;
                    myLabel.Text = dt.Rows[0][i].ToString();
                }
            }
        }


    }
}
[/code]

 

And here is how you use it on a page (dt has been defined as a DataTable and is populated with account information):

[code:c#]

webhelper.populateForm(this, dt);

[/code]

 

Wow, what an improvement in typing, huh?  In a future blog I'll show you how to do the same thing for saving the page.

You can download the class here.

 


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories: .net | Code Monkey
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed