How Do I Customize the Microsoft Office 2007 Ribbon?

Have you wondered whether you could do more to the new Office 2007 menu system than add buttons to the quick launch toolbar?

Here are two addins that may help you further customize the Ribbon in Office 2007. I’ve not used either of them.

You can also download a trial version of Office 2007.

Students can get a deep discount on Office Ultimate 2007.

How to I modify my ASP.NET website look and feel?

I do a reasonable amount of ASP.NET website or web application construction and have not found many websites that post sample ASP.NET masterpages or themes or skins. Generally, I end up modifying a sample css template. Here are some of the sites I have found useful.

One major difference about the templates is in how they utilize screen space. Some templates use only the center of the screen and would use, say only 50%, of a widescreen monitor.

These templates are free. Some require attribution.

Starter Kits

Open Source Templates

Open Web Design

Open Source Web Design

Free CSS Templates

Good Luck!

Redirect with ASP.NET

On several occasions I have needed to redirect a user from one place to another in ASP.NET. I like to do this with code similar to the following, which doesn’t require code-behind.

<%@ Page Language="C#" AutoEventWireup="true" %><!DOCTYPE html>
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","/public/Default.aspx");
}
</script>

<html>
<head runat="server">
    <title>Redirecting...</title>
</head>
<body>
</body>
</html>

What does a website cost?

Don’t forget that growing an online business requires more than a website. You need to get online, attract customers, and manage your growing business.  Don’t forget the time it takes to continue to add new content to your website.

For those simpler informational websites, here’s what I would consider necessary

  • Buy a domain name ($10/yr)
  • Buy a hosting package ($77/yr)
  • Design your website ($2500-$8000)

For a commercial website you also need to consider

  • A merchant account for online orders (around $30 per month plus 3% of each transaction)
  • A security certificate for secure transactions ($50/yr and up)
  • Depending on your market, you may wish to add additional features that require licensing third-party web services.

Set DefaultButton for Enter KeyPress in ASP.NET

Have you ever tried to set the default focus and default submit button on an ASP.NET 2.0 Password Recovery Control? It takes some work, yet I was able to put this example together thanks to Spannjaars.com, Ellipse in the asp.net forums, and Google.

Aspx page

<asp:PasswordRecovery ID="PasswordRecovery1" runat="server"OnVerifyingUser="PasswordRecovery1_VerifyingUser" />

Code behind (.cs)

protected void Page_Load(object sender, EventArgs e)
{
   // The first time our page loads we place the cursor in the
   // User Name textbox and make the Submit button the default button 
   if (!IsPostBack)
   {
      Page.Form.DefaultButton = PasswordRecovery1
         .FindControl("UserNameContainerID$SubmitButton").UniqueID;
      Page.Form.DefaultFocus = PasswordRecovery1
         .FindControl("UserNameContainerID$UserName").ClientID;
   }
}

protected void PasswordRecovery1_VerifyingUser
                  (object sender, LoginCancelEventArgs e)
{
   // This event fires after the User Name is entered; Place the cursor 
   // in the answer textbox and make the Submit button the default button 
   Page.Form.DefaultButton = PasswordRecovery1
      .FindControl("QuestionContainerID$SubmitButton").UniqueID;
   Page.Form.DefaultFocus = PasswordRecovery1
      .FindControl("QuestionContainerID$Answer").ClientID;
}

Using Parameterized SQL Queries

I sure am glad that LINQ-to-SQL has simplified my data access scenarios.

Here’s an example of some otherwise useful insert statements.

        /// <summary>
        /// Inserts a row of data 
        /// </summary>
        /// <param name="statement">An SQL insert statement</param>
        /// <returns>True for success, false for failure</returns>
        public static bool InsertStatement(string statement)
        {
            SqlConnection connection = connectToDatabase();
            SqlCommand command;

            command = new SqlCommand( statement, connection );

            // executes command
            if (command.ExecuteNonQuery() > 0)
                return true;
            else
                return false;
        }

        /// <summary>
        /// Inserts a Patient Encounter into the Database
        /// Specifically a non-simulated encounter
        /// </summary>
        /// <param name="date">The Date of the Encounter</param>
        /// <param name="location">The ID of the location</param>
        /// <param name="gender">The gender of the patient</param>
        /// <param name="comments">Additional comments entered by the student</param>
        /// <param name="site">The ID of the site for the encounter</param>
        /// <param name="level">The ID of the level of participation</param>
        /// <param name="program">The ProgramID for the program of the student</param>
        /// <param name="age">The age of the patient</param>
        /// <param name="entry1">ItemID of Selected Diagnosis</param>
        /// <param name="entry2">ItemID of another diagnosis or null</param>
        /// <param name="entry3">ItemID of a third diagnosis or null</param>
        /// <param name="ageType">The type of age (Years, Months, Days, Weeks)</param>
        private static void InsertPatientEncounter(string date, string location, string gender,
                    string comments, string site, string level, int ProgramID,
                    string age, string ageType, string entry1, string entry2, string entry3, string personID, string courseId)
        {
            SqlConnection connection = connectToDatabase();

            // enter patient encounter except for entries
            string statement = @"INSERT INTO ED2PatientEncounter 

            (DateOfEncounter,LocationID,PatientGender,AdditionalComments,SiteTypeID,LevelOfInvolvementID,ProgramID,PatientAge,AgeType,PersonID,DateOfSubmission,CourseId)
            VALUES (@DateOfEncounter,@LocationID,@PatientGender,@AdditionalComments,@SiteTypeID,@LevelOfInvolvementID,@ProgramID,@PatientAge,@AgeType,@PersonID,@DateOfSubmission,@CourseId)";
            SqlCommand command = new SqlCommand( statement, connection );
            command.Parameters.Add( new SqlParameter( "@DateOfEncounter", date ) );
            command.Parameters.Add( new SqlParameter( "@LocationID", location ) );
            command.Parameters.Add( new SqlParameter( "@PatientGender", gender ) );
            command.Parameters.Add( new SqlParameter( "@AdditionalComments", comments ) );
            command.Parameters.Add( new SqlParameter( "@SiteTypeID", site ) );
            command.Parameters.Add( new SqlParameter( "@LevelOfInvolvementID", level ) );
            command.Parameters.Add( new SqlParameter( "@ProgramID", ProgramID ) );
            command.Parameters.Add( new SqlParameter( "@PatientAge", age ) );
            command.Parameters.Add( new SqlParameter( "@AgeType", ageType ) );
            command.Parameters.Add( new SqlParameter( "@PersonID", personID ) );
            command.Parameters.Add( new SqlParameter( "@DateOfSubmission", DateTime.Now.ToString() ) );
            command.Parameters.Add( new SqlParameter( "@CourseId", courseId ) );

            //Execute Query
            command.ExecuteNonQuery();

            //Pull the ID of the Last Insert
            string statementForID = "SELECT @@Identity";
            SqlCommand commandForID = new SqlCommand( statementForID, connection );
            string id = commandForID.ExecuteScalar().ToString();

            //Insert Entries

            //Entry 1
            InsertPatientEncounterDiagnosis( id, entry1, connection );

            //Entry 2
            if (entry2 != null)
            {
                InsertPatientEncounterDiagnosis( id, entry2, connection );
            }

            //Entry 3
            if (entry3 != null)
            {
                InsertPatientEncounterDiagnosis( id, entry3, connection );
            }

            connection.Close();

        }

        /// <summary>
        /// For each Patient Encounter there are Entries of Items.  We store The EncounterID and the ItemID
        /// </summary>
        /// <param name="PatientEncounterID">The Encounter to document</param>
        /// <param name="ItemID">The Entry (ItemID) added</param>
        /// <param name="connection">The Connection to the Database</param>
        private static void InsertPatientEncounterDiagnosis(string PatientEncounterID, string ItemID, SqlConnection connection)
        {
            SqlCommand commandForEntries = new SqlCommand( "INSERT INTO ED2HasEntry (PatientEncounterID,ItemID) VALUES (@PatientEncounterID,@ItemID)", connection );
            commandForEntries.Parameters.Add( new SqlParameter( "@PatientEncounterID", PatientEncounterID ) );
            commandForEntries.Parameters.Add( new SqlParameter( "@ItemID", ItemID ) );
            commandForEntries.ExecuteNonQuery();
        }

        /// <summary>
        /// Insert a Patient Encounter into the Database
        /// Specifically inserts a Simulated Encounter
        /// </summary>
        /// <param name="date">The date of the encounter</param>
        /// <param name="location">The ID of the location of the encounter</param>
        /// <param name="comments">Additional comments entered by the student</param>
        /// <param name="program">The ProgramID of the student's program</param>
        private static void InsertPatientEncounter(string date, string locationID, string simulationTypeID, string comments, int ProgramID, string entry1, string entry2, string entry3, string personID, string courseId)
        {
            SqlConnection connection = connectToDatabase();

            // enter patient encounter except for entries
            string statement = @"INSERT INTO ED2PatientEncounter 

                    (DateOfEncounter,LocationID,SimulatedEncounterTypeID,AdditionalComments,ProgramID,PersonID,DateOfSubmission,CourseId)
            VALUES (@DateOfEncounter,@LocationID,@SimulatedEncounterTypeID,@AdditionalComments,@ProgramID,@PersonID,@DateOfSubmission,@CourseId)";
            SqlCommand command = new SqlCommand( statement, connection );
            command.Parameters.Add( new SqlParameter( "@DateOfEncounter", date ) );
            command.Parameters.Add( new SqlParameter( "@LocationID", locationID ) );
            command.Parameters.Add( new SqlParameter( "@SimulatedEncounterTypeID", simulationTypeID ) );
            command.Parameters.Add( new SqlParameter( "@AdditionalComments", comments ) );
            command.Parameters.Add( new SqlParameter( "@ProgramID", ProgramID ) );
            command.Parameters.Add( new SqlParameter( "@PersonID", personID ) );
            command.Parameters.Add( new SqlParameter( "@DateOfSubmission", DateTime.Now.ToString() ) );
            command.Parameters.Add( new SqlParameter( "@CourseId", courseId ) );

            //Execute Query
            command.ExecuteNonQuery();

            //Pull the ID of the Last Insert
            string statementForID = "SELECT @@Identity";
            SqlCommand commandForID = new SqlCommand( statementForID, connection );
            string id = commandForID.ExecuteScalar().ToString();

            //Insert Entries

            InsertPatientEncounterDiagnosis( id, entry1, connection );

            if (entry2 != null)
                InsertPatientEncounterDiagnosis( id, entry2, connection );

            if (entry3 != null)
                InsertPatientEncounterDiagnosis( id, entry3, connection );

            connection.Close();

        }