I am FOUND on YouTube

clock October 26, 2008 07:59 by author csmith12

To all my friends, I have been spotted on YouTube in the following video;



I am the second one in the sparring section of the video. And good job Travis. Congrats.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Cleaning up Web Form Binding to Entity Objects

clock October 26, 2008 05:27 by author csmith12

How many lines of code have we all written to set properties from a web form to a business object. 1000's of lines of code and countless wasted hours developing and debugging typos in field names. After years it gets old.

I found a article (http://msdn.microsoft.com/en-us/library/aa478957.aspx) on Microsoft's site about doing just what my goal was. My goal was to turn the hundreds of lines of code in application setting UI properties into business object properties.

For example;

Normal code;

// create entity
Person p = new Person(1, "John", "Doe");

p.FirstName = FirstName.Text;
p.LastName = LastName.Text;

// more code...
Goal code;

// create entity
Person p = new Person(1, "John", "Doe");

// bind
Binder.BindToControl(p, Page);

Enter the Binder class that I have so far after about 2 hours of R&D and playing around with different setups.

using System;
using System.Reflection;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Pixelect.Example.Web
{
    public static class Binder
    {
        public static void BindToControl(object entity, Control control)
        {
            // ensure objects
            if (entity == null || control == null) return;

            // get properties
            PropertyInfo[] infos = entity.GetType().GetProperties();

            // loop through each property info object
            foreach (PropertyInfo info in infos)
            {
                // if can read property
                if (info.CanRead)
                {
                    // find matching control
                    Control matchingControl = control.FindControl(info.Name);

                    // check for match
                    if (matchingControl == null) continue;

                    // process type
                    if (matchingControl is TextBox)
                        ((TextBox) matchingControl).Text = Convert.ChangeType(info.GetValue(entity, null), typeof(string)).ToString();

                    if (matchingControl is Literal)
                        ((Literal)matchingControl).Text = Convert.ChangeType(info.GetValue(entity, null), typeof(string)).ToString();

                    if (matchingControl is Label)
                        ((Label)matchingControl).Text = Convert.ChangeType(info.GetValue(entity, null), typeof(string)).ToString();

                    if (matchingControl is ListControl)
                    {
                        ListItem li = ((ListControl)matchingControl).Items.FindByValue(info.GetValue(entity, null).ToString());
                        if (li != null)
                        {
                            foreach (ListItem item in ((ListControl)matchingControl).Items)
                                item.Selected = false;

                            li.Selected = true;
                        }
                    }
                }
            }
        }
        public static void BindToObject(Control control, object entity)
        {
            // ensure objects
            if (entity == null || control == null) return;

            // get properties
            PropertyInfo[] infos = entity.GetType().GetProperties();

            // loop through each property info object
            foreach (PropertyInfo info in infos)
            {
                // if can read property
                if (info.CanWrite)
                {
                    // find matching control
                    Control matchingControl = control.FindControl(info.Name);

                    // check for match
                    if (matchingControl == null) continue;

                    // process type
                    if (matchingControl is TextBox)
                        info.SetValue(entity, Convert.ChangeType(((TextBox)matchingControl).Text, info.PropertyType), null);

                    if (matchingControl is ListControl)
                    {
                        if (((ListControl)matchingControl).SelectedItem != null)
                            info.SetValue(entity, Convert.ChangeType(((ListControl)matchingControl).SelectedItem.Value,  info.PropertyType), null);
                    }
                }
            }
        }
    }
}

This class allows easy binding between web form UI elements and entity objects where the UI control ID is equal to the entity property name. This is just a first draft of the class and I will be updating the class to support the bulk of the toolbox items in visual studio. I will also integrate the code from the Microsoft article to support known properties on unknown UI object types.

Then hopefully.... we can cut down on all that error prone and boring code that we all must type to bind UI elements to back end objects.

Enjoy

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


.Net with SMO, Triggers, Tables and the Modified (Last Updated Date)

clock October 4, 2008 04:12 by author csmith12

Have you ever had a lot of tables in a database that needed to have the timestamp of the record updated on insert or update? I know I have. I wish I could find a really good tool for automating some of the database development tasks that I perform. Until then, I end up writing my own scripts or code.

This code utilizes the .Net SMO object model to automatically create triggers for tables that have an Modified datetime column.

Below you will see my code for adding triggers to a MS SQL server database. These triggers will update the "Modified" column in the table when a record is inserted or updated. Feel free to modify the code to fit your specific needs as it is common for the "Modified" column to be named differently per database/project.

Limits:

1. Table can only have one primary key column

Enjoy!

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;

namespace Pixelect.MsSql
{
    public class ModifiedDateTriggerGenerator
    {
        public void Process(string database)
        {
            // get connection string
            string conString = ConfigurationManager.ConnectionStrings["SqlServerConnectionString"].ConnectionString;

            // create sql connection
            SqlConnection sqlConnection = new SqlConnection(conString);

            // create server connection
            ServerConnection serverConnection = new ServerConnection(sqlConnection);

            // create server
            Server server = new Server(serverConnection);    

            // 
            if (server.Databases.Contains(database))
                AddModifiedTriggerToTables(server.Databases[database]);
            else
                throw new Exception("Database not found.");
        }

        private static void AddModifiedTriggerToTables(Database database)
        {
            foreach (Table table in database.Tables)
            {
                if(table.Columns.Contains("ModifiedDate"))
                {
                    // check if table already had trigger, drop it
                    if (table.Triggers.Contains(string.Format("trg{0}SetModifiedDate", table.Name)))
                        table.Triggers[string.Format("trg{0}SetModifiedDate", table.Name)].Drop();
                    
                    // set up trigger
                    Trigger trigger = new Trigger(table, string.Format("trg{0}SetModifiedDate", table.Name));
                    trigger.TextMode = false;
                    trigger.Insert = true;
                    trigger.Update = true;

                    // get trigger resource
                    string textBody = TriggerTemplate.ResourceManager.GetString("ModifiedDateTrigger");

                    // get template
                    if(string.IsNullOrEmpty(textBody))
                        throw new Exception("Unable to get Modified trigger template from resource.");

                    // swap values
                    textBody = textBody.Replace("[table]", string.Format("[{0}]", table.Name));
                    textBody = textBody.Replace("[schema]", string.Format("[{0}]", table.Schema));

                    // get primary key of table
                    List<Column> keys = GetPrimaryKeys(table);

                    // i.[primaryKey] = [schema].[table].[primaryKey]
                    string keyChain = string.Empty;
                    foreach (Column col in keys)
                        keyChain += string.Format("i.{0} = [{1}].[{2}].[{3}] AND ", col.Name, table.Schema, table.Name, col.Name);
                    
                    // replace body
                    keyChain = keyChain.Substring(0, keyChain.Length - 5);
                    textBody = textBody.Replace("[keys]", keyChain);
                    
                    // update body
                    trigger.TextBody = textBody;

                    // create trigger
                    trigger.Create();
                }
            }
        }

        private static List<Column> GetPrimaryKeys(Table table)
        {
            List<Column> keys = new List<Column>();

            foreach (Column c in table.Columns)
                if (c.InPrimaryKey) keys.Add(c);

            return keys;
        }
    }
}

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


More Taekwondo Results

clock September 25, 2008 02:28 by author csmith12

We went to another tournament this year in Lexington KY. Just wanted to post the results for my buddies.

1st place sparring
2nd place forms

My son competed in a tough group and didn't place, but he had a blast anyway. And that is what is all about. He has the best attitude for an 8 yr old.

I will update this post with some pictures or movies when I get time to come up for air.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Common User Mistake

clock September 25, 2008 02:20 by author csmith12

After developing web pages for so long, and as a web user for a long time.... Sometimes we start to overlook the simple things.

For example;
A user sent me a screen shot stating the colors were messed up on a set of textboxes on a web form. After a few minutes confirming the CSS, I looked at the screen shot again. All the text boxes had a yellow background.

The answer was also right there in front of me as well, but as complacent as I was, it didn't hit me until the 2nd look. The Google toolbar was also installed and the autofill button was lit up. Ah the answer to my question is there in the options.

The fix is to have the user turn off the yellow color highlighting as shown below.

google yellow highlight

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Cincinnati Bell Phone Settings

clock July 11, 2008 00:23 by author csmith12

Recently, my wife and kids :( got new cell phones. Along with that came a new cell provider. As the title of this post indicates, Cincinnati Bell. Although the services has been good and their support has been helpful so far. I found myself configuring various phones until my wife found the one she wanted.

I though I would post the settings here for anyone else going through the same issues.

GPRS
----
Connects to: The Internet
Access Point: wap.gocbw.com
Username: (blank)
Password: (blank)
Primary DNS: (blank)
Secondary DNS: (blank)
IP Address: (blank)
PROXY
-----
Description: CBW Proxy
Connects From: WAP Network
Connects To: The Internet
Proxy: 216.68.79.202:80
Type: HTTP
User name: (blank)
Password: (blank)
MMSC Settings
-------------
Name: CBW
MMSC Url: http://mms.gocbw.com:8088/mms
WAP Gateway: 216.68.79.202
Port: 80
Connect Via: The Internet
Max. Sending Size: 300k

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Enabling Membership, Roles and Personalization in ASP.Net

clock April 8, 2008 16:12 by author csmith12

How to configure the ASP.NET 2.0 Membership/Roles Provider to use SQL 2000 or SQL 2005?

The information in this article applies to:

  • ASP.NET 2.0
  • MS SQL 2000
  • MS SQL 2005
  • Membership/Roles Provider

    SUMMARY

    How to set up the new ASP.NET 2.0 Membership, Role Management, and Personalization services to use a regular hosted SQL Server 2005 or SQL 2000 instead of MicroSoft SQL Server Express.

    DETAILS

    The following steps create the full Application Services database schema on our SQL Server database.

    1. Open the command prompt on your local computer, and navigate to:
      C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
    2. Execute the command:
      aspnet_regsql.exe -S [DB Server Name] -U [DB login] -P [Password] -A all -d [Database name]

    Below is an example of how to configure Visual Web Developer to manage the membership database.

    1. Create a web application in Visual Web Developer or Visual Studio 2005.
    2. Open the web.config.
    3. The default membership provider uses a connection string called "LocalSqlServer".          

    Replace:

    <connectionStrings/>

    with

    <connectionStrings><remove name="LocalSqlServer" />
    	<add name="LocalSqlServer" connectionString="Data Source=<DB_Server>;Integrated Security=false;Initial 
    		Catalog=<DB_Name>;User ID=<DB_User>;Password=<DB_password>" providerName="System.Data.SqlClient" />
    </connectionStrings>
     Save and close the web.config. 
    1. Go to Website menu, and run the ASP.NET Configuration tool. This will open the Web Site Administration tool in a browser window.
    2. Next.. In the Web Site Administration browser, go to the Security tab.
    3. Click on "Select authentication type".
    4. Select "From the internet".  Then click the "Done" button.
    5. Create your admin roles and users.
    6. Then create access rules.
    7. Create a rule that applies to the "Anonymous users" with "Deny" permissions.
    8. Create another rule that applies to the admin role you created with "Allow" permissions.
    9. Your application is now ready to use the membership provider.
  • Copied for ease of access. Credit given to: http://support.re-invent.com/article.aspx?id=10353

    Be the first to rate this post

    • Currently 0/5 Stars.
    • 1
    • 2
    • 3
    • 4
    • 5


    Fun with JetBrains TeamCity

    clock March 9, 2008 16:34 by author csmith12

    A friend and I have been working with TeamCity from JetBrains for the past week. I must say that I am impressed with the application so far. I do have a couple of issues I am still working out, but all and all, its a killer continuous integration server for free. Here are just a few of the questions that I have not been able to figure out from reading the documentation so far;

    1. How do I get the build agents to build applications that contain 3rd party project references without installing them on the build server or where the build agent is installed? Am I missing something that is taken for granted here?
    2. Is there any plug-ins/add-on's that will deploy the compiled output (artifacts) to a staging server automatically?

    If any experienced TeamCity users read this, please point me in the right direction.

    Be the first to rate this post

    • Currently 0/5 Stars.
    • 1
    • 2
    • 3
    • 4
    • 5


    An Idea For Old Computer Case

    clock February 29, 2008 14:04 by author csmith12

    I got this in email today and though it was funny. Also went well with the subject matter in the IRC channel I hang out in.

     

    clip_image001

    Be the first to rate this post

    • Currently 0/5 Stars.
    • 1
    • 2
    • 3
    • 4
    • 5


    Adding Glass Effect to Images

    clock February 28, 2008 11:27 by author csmith12

    I found a very nice article on Code Project that shows a simple implementation of a glass effect applied to an image. I thought I would credit the developer and link his code here for my future reference.

            public static Image DrawReflection(Image _Image, Color _BackgroundColor, int _Reflectivity)
            {
                // Calculate the size of the new image
                int height = (int)(_Image.Height + (_Image.Height * ((float)_Reflectivity / 255)));
                Bitmap newImage = new Bitmap(_Image.Width, height, PixelFormat.Format24bppRgb);
                newImage.SetResolution(_Image.HorizontalResolution, _Image.VerticalResolution);
    
                using (Graphics graphics = Graphics.FromImage(newImage))
                {
                    // Initialize main graphics buffer
                    graphics.Clear(_BackgroundColor);
                    graphics.DrawImage(_Image, new Point(0, 0));
                    graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    Rectangle destinationRectangle = new Rectangle(0, _Image.Size.Height, _Image.Size.Width, _Image.Size.Height);
    
                    // Prepare the reflected image
                    int reflectionHeight = (_Image.Height * _Reflectivity) / 255;
                    Image reflectedImage = new Bitmap(_Image.Width, reflectionHeight);
    
                    // Draw just the reflection on a second graphics buffer
                    using (Graphics gReflection = Graphics.FromImage(reflectedImage))
                    {
                        gReflection.DrawImage(_Image, new Rectangle(0, 0, reflectedImage.Width, reflectedImage.Height),
                        0, _Image.Height - reflectedImage.Height, reflectedImage.Width, reflectedImage.Height, GraphicsUnit.Pixel);
                    }
                    reflectedImage.RotateFlip(RotateFlipType.RotateNoneFlipY);
                    Rectangle imageRectangle = new Rectangle(destinationRectangle.X, destinationRectangle.Y,
                        destinationRectangle.Width, (destinationRectangle.Height * _Reflectivity) / 255);
    
                    // Draw the image on the original graphics
                    graphics.DrawImage(reflectedImage, imageRectangle);
    
                    // Finish the reflection using a gradiend brush
                    LinearGradientBrush brush = new LinearGradientBrush(imageRectangle,
                           Color.FromArgb(255 - _Reflectivity, _BackgroundColor),
                            _BackgroundColor, 90, false);
                    graphics.FillRectangle(brush, imageRectangle);
                }
    
                return newImage;
            }
    
    Link to the original article. http://www.codeproject.com/KB/GDI-plus/Image-Glass-Reflection.aspx

    Be the first to rate this post

    • Currently 0/5 Stars.
    • 1
    • 2
    • 3
    • 4
    • 5


    QOTD

    Your br a i n Is fas t er t han your fing e rs alot of the time.

    - Reactor

    Calendar

    <<  November 2008  >>
    MoTuWeThFrSaSu
    272829303112
    3456789
    10111213141516
    17181920212223
    24252627282930
    1234567

    View posts in large calendar

    Sign in