ASP.Net formview – gripe of the day

I upgraded an asp.net project today to switch from a DetailsView control to a FormView control. Obviously I needed editing capabilities, thus the reason.

The upgrade reminded me of a major gripe I have with the FormView control. When you associate the control with a datasource, it will auto-generate a tabular form view of your data, in a list of Name: Value format. Really what it is doing is just creating a quicky view of the fields in your datasource and throwing the generated fields into the 3 templates needed (ItemTemplate, EditTemplate, and InsertTemplate) so you can have them handy for all that extra formatting you are expected to want to perform.

One formatting difference between the auto-generated code this control produces versus the format of the simpler DetailsView is, the DetailsView produces table elements so that all the “Name” elements show up in a single table column followed by the “Values” column. This is a nice formatted and is usually pretty close to what you would want to create in a list of values.

The FormView however assumes you are going to do a lot of editing of the templates, and so doesnt include any layout except the basics- Just the Name, “:” , and the bound feld value.  This results in the Name and Value getting bunched together up on the left side and results in a truly ugly form.

Not too difficult to format these into a table if you want to, right? Well sure… but after building a few apps using this, it can drive you nuts. Some of the apps Ive worked on have, say, an average of 30 fields to present on the screen. After I generate the FormView from the datasource, I then have to go add table TR/TD code around every element… 3 times. So those 30 elements are tripled to 90 elements. Each of the 90 elements has to have an opening TR/TD, then a middle TD/TD, then a finished TD/TR. So we are now looking at having to cut n paste about 270 items and try to make sure you didnt fubar anything.

To make things worse, if you make a schema change in your database (and who doesnt), you pretty much need to regen the thing and start over. 

AND: This is just ONE FormView. One app I recently finished had at least 20 FormViews in it. Neglecting any rebuilds, this is around 5000 elements I had to hand edit. Deadline? You talk funny.

I understand MS’es thinking in this, and I would probably be much worse off if I were in the other boat and had to *remove* all these unwanted table elements every time a Formview is generated… but why not offer an option to include a basic table formatting? Or even allow for custom formatting of the generated code so we can include our own tags or whatever markup is desired. I even researched to see if it’s possible to create my own generator for this to override or replace the one Visual Studio uses… found some obscure stuff but nothing really useful.

I’d like to hear if anyone has any pointers on this.

Advertisements

Linq and Sql Server Timestamp Columns – Why Binary?

As explained a bazillion times before on the net, the timestamp column in sql server is not a datetime or anything to do with time.  It is a binary(8) column which contains a big number which is incremented on every edit of any row of any table in the database. It is also identical to the rowversion column.

Now for my gripe. I’ve used strongly typed datatables in past projects and with some manipulation, you can get the datatable to treat the timestamp column as a bitint (Int64). Why does this matter? Because I’ve used it for some simple version tracking in the past, and this requires I perform range checking on these versions. A simplified explanation:

-Use the largest timestamp in my cached table
-Query the database table for any timestamps larger than this one
-Retrieve these new or updated items to be merged back into the original dataset

This normally is not useful for 2 or N tier apps, but in my instance I am transferring data over the net via a webservice so would like to only retrieve the new or changed records to the client.

Gripe time: why are these columns Binary? The only way I was historically able to query on them is to force sql server to cast them as a bigint, through some magic in the typed datatable. But now Im using Linq as my data access layer. I love linq so far, but I have tried every trick I can think of and it will not make this work- Linq will always fail with a illegal cast type error when it attempts to load the record.

So, whyt exactly are these binary? Wouldnt it be much easier to make use of rowversion and timestamps if they were represented as a real datatype like int64/bigint? I know I wouldnt have wasted half a day yesterday on this if this were the case.

So now it looks like Ill switch to using a datetime column that I hope is udpated with every edit or insert. Should work ok, but not my preference.

Fined for Handicapped Parking

Noticed at the park yesterday, a handicapped parking sign for a parking spot (I was stretching in front of it, no I didn’t park there.) In the smaller print, it said “Fine $50 – $200”. You’ve probably seen these around as well, and I know I’ve seen them for years.  

But then I thought… What determines whether the fine is on the $50 or the $200 end of the spectrum? Should I be glad or upset if I get a $50 fine? Imagining the cop’s train of thought: “Yeah, this guy is in violation, but since he seems a bit mentally handicapped I’ll just give him the minimum fine.”

And what the heck are you to think if you got off with a warning?

Solar AC System?

One I was thinking of yesterday – a vented ridge cap on the top of a house’s roof will let hot air in your attic flow upward and out the top, drawing in cooler air along the eaves. So was wondering if home AC systems could use this airflow to draw air over the exterior coil and reduce the energy needed to run a fan. But a bad side effect would be adding extra heat to you your attic.

So the next thought was, just build either a series of “chimney” tubes, or even just join the tubes together to form a large thin chimney which could cover an entire wall of a house, and would let the hot air entering it from the bottom out of the AC coil to flow upward and pull more air through the system, thus again eliminating or reducing the need for a fan. This could also act as a sunshield for one side of a house, and the funny thing is sunlight would even enhance the effect (heating the chimney causes extra airflow).

So i did a quick search and confirmed my suspicion that this is old news..Patent 4706471 for a “Solar Chimney” uses solar energy to heat a chimney and produce airflow to aid in cooling an AC system, though this particular one seems to be focused on geothermal. (See http://www.google.com/patents?id=NsAwAAAAEBAJ&dq=4706471 ). This is after a 15 second search, so Im sure there is lots of other related tech out there. I may add more here as I find time to look into it.

 

The patented solution to the world’s energy problems (hint: not really)

This one has amazed me for a while, figured I would post it here.

Following is a patent, number 7095126, which was issued in 2006 for an energy creation device… first, take a look at some pictures:

 

What a great idea! In fact, I remember trying this one when I was a (really young) kid. I had a motor connected to the rear tire of my bicycle, and a generator hooked up to one of the tires (maybe it was the front tire, you know, since that might make it work better). The generator had gearing to spin it much faster than the motor, thus the bike should generate its own electricity and power itself.

It’s a barely genius idea, except of course it doesn’t work. It is a classical example of a free energy machine, also known as a perpetual motion machine.

So let’s review patent number 7095126. Electric motor, check. Generator, check. Gearbox to make the motor spin the generator faster. A battery to get things started. And a load to use all that extra electricity you will generate. A truly bare bones implementation of a perpetual motion machine, minus the usual clutter of obfuscation in an attempt to fool yourself or others into believing it really works.

Iv’e expressed frustration for years over what the patent office has become and the level of incompetence it has reached. It appears they will grant a patent on just about anything, unlike the rigorous and difficult path that washistorically required to obtain one. But even the PTO has specific rules regarding perpetual motion machines, specically that NO PATENTS BE GRANTED FOR THEM.

So, this means that the patent examiners either a. knew this was perpetual motion, and accepted it anyway, or even worse b. accepted it because they didnt recognize this as perpetual motion.

I propose that any future discussions or debates about the quality of work being produced by the US Patent Office, simple state “7095126” followed by a “QED”. Nothing more need be said.

 

A more efficient refrigeration compressor?

This is the weird stuff I wake up thinking about. Last week I woke thinking (dreaming maybe) of a system that would recycle some of the energy wasted in compressing refrigerant in an air conditioning system.

If you recall how the refrigeration cycle works, you basically run a compressor that smashes a gas to a high pressure, which causes it to get hot. Since it is now hotter than ambient air, blow ambient air over the hot gas to cool it off, while staying at the high pressure. Then move this high pressure, slightly cooled gas back  to where you want to be cool (inside your house), and let it rapidly expand thus causing it to cool off a bunch. Use this coldness to cool your house (blow house air over it to cool it), and then repeat this process with the gas which now contains the heat taken from your house.

I had read recently about a generator being used in the oilfield to generate electricity by replacing the choke in the gas well with a generator. A choke is just a smaller opening through which the gas has to slow as it flows out the well, since many gas wells would flow to quickly without one. So this generator replaced this simple choke with a turbine that would provide the same flow slowing effect, but with the benefit of using this pressure drop to spin a turbine and produce electricity– energy that would otherwise just be lost.

So, do you see the applicability to the AC system? The compressor in this system is pressurizing gas to a high pressure, but then this energy stored as pressure is “lost” as the gas simply expands across an orifice, just like the gas well choke. Why couldn’t the compressor benefit from some form of turbine attached to the outlet which would recover at least a portion of the energy used in compression? It should still provide the refrigeration benefits as the gas is still expanding and thus cooling.

So, I did a quick search and sure enough it looks like the Japanese have a colleciton of patents on this technology. This one is pretty much it exactly: http://www.google.com/patents?id=2qAMAAAAEBAJ&dq=6543238

Strangely, it seems a US patent was issued in 2007, quite a bit newer than the japanese ones: http://www.google.com/patents?id=IGCEAAAAEBAJ&dq=7272932 (although it does seem more broadly defined).

So now I’m only curious if A. this is being used at all and B. I’m pretty sure it isn’t, so I wonder why not? I know with many ideas like this, the benefit just doesn’t justify the addional cost, so I’ll have to assume this is the case. Let me know if you have any comments on this one.

This whole discussion got me thinking about resonant refrigeration and what the current state of the art is in this arena, but I’ll save that for another day. Some quick searching didnt turn up much, but I’m sure there has to be more info out there on this topic.