Wednesday, June 07, 2006

using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;
using System.Data.SqlClient;
using System.Collections.Specialized;
using System.Web.Caching;

public partial class modules_EditCircuitOrder : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("Page is loading...");

if (!IsPostBack)
{
Response.Write("!IsPostBack");
// GET Request
SqlConnection cn = new SqlConnection(
ConfigurationManager.AppSettings.Get("SOMConnectionString"));

// SqlCommand cmd = new SqlCommand(query,cn);
// SqlDataReader sdr = cmd.ExecuteReader();
Response.Write("Before Data Execute");

DataTable dtCityCoord;
dtCityCoord = (DataTable)Cache["cityCoordinates"];

if (dtCityCoord == null)
{
// we don't have the table in cache so load it now
string query = @"SELECT cityName + ', ' + UPPER(state) AS cityState, CityCoordID
FROM som.dbo.tblCityCoord
ORDER BY cityState"
;

using (SqlCommand cmd = new SqlCommand(query, cn))
{
cn.Open();

Response.Write("<br/><br/>NO CACHE<br/><br/>");

SqlDataAdapter adapter = new SqlDataAdapter(cmd);
dtCityCoord = new DataTable();

adapter.Fill(dtCityCoord); // Just pass the DataTable into the SqlDataAdapters Fill Method
//this.DgMethodOne.DataSource = dtAuthors;

SqlCacheDependency cityCoordDepends =
new SqlCacheDependency("SOM", "tblCityCoord");
Cache.Insert("cityCoordinates", dtCityCoord, cityCoordDepends);
cn.Close();
}
}

LocA.DataSource = dtCityCoord;
LocA.DataTextField = "cityState";
LocA.DataValueField = "CityCoordID";
LocA.DataBind();

LocZ.DataSource = dtCityCoord;
LocZ.DataTextField = "cityState";
LocZ.DataValueField = "CityCoordID";
LocZ.DataBind();


DataTable dtCircuitOrderLookups;
dtCircuitOrderLookups = (DataTable)Cache["circuitOrderLookups"];

if (dtCircuitOrderLookups == null)
{
// we don't have the table in cache so load it now
string query = @"SELECT CircuitOrderLookUpID AS Value, Text, Field
FROM som.dbo.tblCircuitOrderLookups"
;

using (SqlCommand cmd = new SqlCommand(query, cn))
{
cn.Open();

Response.Write("<br/><br/>NO CACHE<br/><br/>");

SqlDataAdapter adapter = new SqlDataAdapter(cmd);
dtCircuitOrderLookups = new DataTable();

adapter.Fill(dtCircuitOrderLookups);

SqlCacheDependency circuitOrderLookupsDepends =
new SqlCacheDependency("SOM", "tblCircuitOrderLookups");
Cache.Insert("circuitOrderLookups", dtCircuitOrderLookups, circuitOrderLookupsDepends);
cn.Close();
}
}

LoadDropDownList(FRRPAUsage, dtCircuitOrderLookups, "FRRPAUsage");

LoadDropDownList(OrderType, dtCircuitOrderLookups, "OrderType");

LoadDropDownList(Net, dtCircuitOrderLookups, "Net");

Response.Write("After Data Execute");

RequiredFieldValidator rfv = new RequiredFieldValidator();
rfv.ControlToValidate = "CircuitID";
this.Controls.Add(rfv);
}
CircuitId.Focus();

Response.Write("Page Load Finished.");
}

private void LoadDropDownList(DropDownList ddl, DataTable source, string fieldName)
{
DataRow[] lookups =
source.Select("Field = '|REPLACE|'".Replace("|REPLACE|", fieldName));

foreach (DataRow row in lookups)
{
ListItem item = new ListItem();
item.Text = row["Text"].ToString();
item.Value = row["Value"].ToString();
ddl.Items.Add(item);
}

}
}

 |  | 
Wednesday, June 07, 2006 5:12:56 PM (Central Standard Time, UTC-06:00)  #    Comments [0]

The caching mechanism in ASP.NET 2.0 has been extended (very logically) to include SQL cache invalidation.  If you have SQL 2005 then your are ready to go, however if you are using SQL 7 or SQL 2000 then a bit of configuration is in order.

Step one must be executed for each database and step two must be executed for each table.  Execute these commands from the Visual Studio.NET 2005 command line.

1.  Activate the database.  If you are using SQL security use A, if you are using Windows security use B.

   A.  aspnet_regsql.exe -S server -U user -P password -d database -ed
   B.  aspnet_regsql.exe -S server -E -d database -ed
 

2.  Activate the table.  If you are using SQL security use A, if you are using Windows security use B.        

   A.  aspnet_regsql.exe -S server -U user -P password -d database -t table -et
   B.  aspnet_regsql.exe -S server -E -d database -t table -et

That's it.  You should be ready to rolll.  In the next post I will show you what you need to do in ASP.NET to make this work for you.

Wednesday, June 07, 2006 1:50:50 PM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Tuesday, June 06, 2006
I've downloaded the RC1 of Windows PowerShell and I'm fairly impressed.  Why should you use this?  Imagine being able to access .NET assemblies and programming constructs from the command line or in batch files.  Also imagine a more "scripty" vbscript.  That's what powershell is.  It's about damn time too after spending a few years in a Unix shop and seeing what can be done in scripts I was getting a little tired of batch files.  PowerShell blows away any current scripting environment.  There's real error handling using Trap.  Where other shells pass and parse text, PowerShell passes objects and you can reference object properties by name.   I've been spending the last week  getting aquainted  with the features and will be posting a few scripts soon.  I've seen about a billion WMI scripts but very few showing basic interaction with existing executables.  Once you get the hang of it however, it's simply great. 

Tuesday, June 06, 2006 8:21:41 PM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Monday, May 29, 2006
The wife and I just got back from Vegas.  It's pretty much the same as last year.  The Wynn is open and its pretty nice.  The MGM Grand buffet is still one of the best places to eat.  I had a mound of California rolls on one side of  my plate and bacon on the other side.  How great is that? 

We sat by the pool a lot.  We went to a comedy show.  Other then that we pretty much just bummed around the Strip and watched people.  Vegas is the definition of an international city.  You can hear several different languages around the pool at any one time. 

Anyway, it is good to be back home. 

Monday, May 29, 2006 6:43:19 PM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Wednesday, May 24, 2006

This one is not so obvious.  I was curious one day after using several utilities that wrote a percent complete to the command line.  I had never done this in C# so I went searching.  Here it is:

using System;
using System.Collections.Generic;
using System.Threading;

public class MyClass
{
    public static void Main()
    {
        for(int i = 0; i < 100;i++) {
            Console.Write("{0}% Complete\r", i);
            Thread.Sleep(100);
        
        }
    }
}

Running this code will produce an output like this:

 

Trick originally came from here:

http://www.dotnet247.com/247reference/msgs/6/31315.aspx

Wednesday, May 24, 2006 1:39:57 PM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Friday, May 19, 2006
This is a multipart series on backing up your computer (at home or the office). 

Part 1 - Decide what needs to be backed up.

First you need to figure out what actually needs to be backed up.  This may be an easy step if everything you work on goes in your "My Documents" folder.  However, if you have stuff scattered across your hardrive it may be a bit more of a chore.  Many programs store your files in default locations.  Let's look at each type of application and see where the files we need to back up are located.

Email
Email is probably one of the most important applications.  Some people (for better or worse) store everything in their email box.  I use Outlook at home and the office.  At the office your information is probably backed up by your server administrator so you shouldn't have to worry.  You may want to double check just in case.  Let's concentrate on the none corporate environment, i.e. home, home office and small office.  You either have a dedicated email client like Outlook, Outlook Express, Thunderbird, etc or you use a hosted service like Hotmail, Yahoo Mail, Google Mail, etc.  If you use the hosted service this should be fairly safe.  Let's focus on the email clients. 

Email Clients
So you use Outlook or another email reader.  These typically download messages from the email server to your local desktop and store them in a file.  In the case of Outlook these are stored in a file ending with a .pst extension.  You can find this file by clicking the file menu then Data File Management.  The dialog box that comes up will display the path to your Outlook data file.  You may have more then one.



You can either leave the file where it is or move it to a more convenient spot.  I will talk about this in Part 2.  So now that we have found our data file we need to make a note of the location and include it in our backup plans. 

Your Documents
A large number of people store their documents in the "My Documents" folder simply because it is the default save folder in many applications.  If all your documents are here then you are in luck.  Otherwise you need to find all of your documents and either organize them or keep track of them.  More about this in Part 2.

Personal Finance Files
Do you use Microsoft Money or Quicken?  If so you have a file that contains all of your financial information lurking on your computer somewhere.  You need to find this.  In Microsoft Money you can click the File menu and then Backup and this should open up in the default backup folder.  Money is smart enough to make a backup of of it's data file.  So you should see a file with the extensions .mny and some files with the extension .mbf.  Make a note of this location as you need to back these up.  You can also change this location.  More about this in Part 2.

Media
Here's where it gets messy.  Media files are photographs, movies, audio files, etc.  In other words these are your vacation photos, your wedding videos and your Itunes music files.  So these files are one of a kind so they should be backed up.  The problem?  They are usually gi-normous (really big).  You need to find all of your media files and these can be difficult to track down because your camera stores photos in one directory, your video software in another and your mp3 collection is in another location.  You need to find all of these files and note the location (more on this in Part 2). 


Friday, May 19, 2006 9:59:26 AM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Wednesday, May 17, 2006
Theory:  I should increase my 401(k) contributions to the maximum to minimize taxable income and maximize retirement funds.

Supporting Facts:

  1. TMND (The Millionaire Next Door) states that the wealthy realize less of their income as a percentage of their wealth compared to the non affluent.
  2. 401(k) contributions are taken out before taxes thus lowering taxeable income.
Contra
  1. Oppurtunity cost of your money being tied up until 59.5 years of age.  What else could I do with this money?
  2. Unknown tax burden at age 59.5.  This would be during prime earning years so it's likey that income may be higher at that time.  Of course I would not need to take that money during that time.
 

Wednesday, May 17, 2006 10:13:55 AM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Monday, May 15, 2006
Monday, May 15, 2006 3:49:51 PM (Central Standard Time, UTC-06:00)  #    Comments [0]
So I had a project where I need to have pretty good uptime (.99999) or something like that.  My first thought was to write a Window's Service to house my code.  I had built the prototype as a Console Application and it wouldn't be that hard to move the logic into a Service.  I was planning on using the customizable failure handlers in Windows (right click any service in the services manager MMC and then click on the Recovery Tab to see what I am referring to) to restart the service and possible do some other stuff.  Window's services also have built in support for writing to the event log.

However, I had already added log4net logging and used the email logging to send notifications on failures, all I really needed was the restart-ability that services provide.  Then I had a flash back to my Tech Services days when I used to supported many automated batch type applications that were managed with the Window's Task Scheduler.  I decided to rely on one not so known feature which I will describe in a moment.   Most tasks are scheduled once a day or week,  month, etc.  I scheduled my tasks to run starting now and then repeat every one minute ad infinitum (forever, basically).  Here's the magic: the Window's task schedule won't start a task that is already running!  So now if my task fails it will restart in <= a minute without any of the pains of a Window's Service (installation and configuration, etc).

One day I will find a reason to write a Window's Service but every time I think I need to, I find some way around it.

 |  | 
Monday, May 15, 2006 3:29:47 PM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Sunday, May 14, 2006
I've been using the backup software that came with my external USB Hard Drive to backup my work, outlook, etc but I've noticed some limitations.  I am currently using Dantz Retrospect Express Version 6.5 and it does a good job as far as it goes.

Good:
  • Easy to use
  • Reliable - it has been running well for several months
  • Conserves disk space by using incremental backup solution to only grab updated files.
Bad:
  • Can't handle open files (The notorius *.pst problem, where Outlook has it's .pst files locked when it's running.)
  • No remote support (ftp, webdav, etc)
  • Closed format - one of the good points is also a weakness.  Consider needing to get information of a backup device but not having the software to get it.  What happens when I don't use Retrospect any more but I need to grab something off one of these backups?  The closed nature of the system means I always have to use this software. 
  • To upgrade to 7.5 professional the cost is $45.00, not bad but this license only covers one machine. 
The problem is I don't want to be on the upgrade treadmill, constantly tied to one vendor.  So the search for backup solutions begins...

Sunday, May 14, 2006 11:07:40 AM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Saturday, May 13, 2006
Foxmarks is a Firefox extension that allows you to keep your Firefox bookmarks in sync.  It works by keeping a copy of your bookmarks out on the Foxcloud server at http://www.foxcloud.com.  Every minute it checks for any changes and then synchronizes your local copy to the copy on the server.  This is very handy if, like me, you use firefox on multiple machines (I have 4 I use frequently) and have a large number of bookmarks.  Because you information is stored on the Foxcloud server you can access your bookmarks from any place you have internet access.

Just one more reason to love Firefox.

Download the extension here: https://addons.mozilla.org/firefox/2410/

Homepage:  http://www.foxcloud.com/wiki/Main_Page

Personal Bookmarks page:  http://my.foxcloud.com/


Saturday, May 13, 2006 10:46:53 AM (Central Standard Time, UTC-06:00)  #    Comments [0]