I ran into an issue using NHibernate + domain objects with the Syncfusion grid.
I am using an auto incremented [generated identity] integer primary key that NHibernate expects to be null when creating a new item.

With the syncfusion grid, the primary key is a required field on the “add new” form/dialog by default.
To avoid the requirement of supplying a value in the “add new” form, you can hide the parent div of the primary key input item by using the “OnActionSuccess” client event.

@(Html.Syncfusion().Grid("GenericListGrid")
        .ClientSideEvents(events =>
        {
            events.OnActionSuccess("HideOnAdd");
        });
)

Then the javascript function to hide the field from validation…
In this case, the field mapping is “Id”.

        
            function HideOnAdd(sender, args) {
                alert(args.RequestType);
                if (args.RequestType == 'AddNew') {
                    var gridObj = $('#GenericListGridEditDialog');
                    gridObj.find('#Id').parent().css('display', 'none');
                }
            }
        

If you are using a different edit method, the name of the form or dialog could be a different format.

SQL table for US States

Posted: August 31, 2013 in SQL
Tags:

I saw a script here…

http://www.webcosmoforums.com/databases/21515-insert-script-us-states-abbreviation-ms-sql.html

But changed it to better suit my needs –

CREATE TABLE [dbo].[USStates](
 [StateID] [int] IDENTITY(1,1) NOT NULL,
 [Name] [varchar](50) NULL,
 [Abbrev] [varchar](3) NULL
 CONSTRAINT [PK_USStates] PRIMARY KEY CLUSTERED 
(
 [StateID] ASC
 )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
 ) ON [PRIMARY]
 
 insert into USStates (Name,Abbrev)
 Select 'Alabama', 'AL' UNION ALL
 Select 'Alaska', 'AK' UNION ALL
 Select 'Arizona', 'AZ' UNION ALL
 Select 'Arkansas', 'AR' UNION ALL
 Select 'California', 'CA' UNION ALL
 Select 'Colorado', 'CO' UNION ALL
 Select 'Connecticut', 'CT' UNION ALL
 Select 'Delaware', 'DE' UNION ALL
 Select 'District of Columbia', 'DC' UNION ALL
 Select 'Florida', 'FL' UNION ALL
 Select 'Georgia', 'GA' UNION ALL
 Select 'Hawaii', 'HI' UNION ALL
 Select 'Idaho', 'ID' UNION ALL
 Select 'Illinois', 'IL' UNION ALL
 Select 'Indiana', 'IN' UNION ALL
 Select 'Iowa', 'IA' UNION ALL
 Select 'Kansas', 'KS' UNION ALL
 Select 'Kentucky', 'KY' UNION ALL
 Select 'Louisiana', 'LA' UNION ALL
 Select 'Maine', 'ME' UNION ALL
 Select 'Maryland', 'MD' UNION ALL
 Select 'Massachusetts', 'MA' UNION ALL
 Select 'Michigan', 'MI' UNION ALL
 Select 'Minnesota', 'MN' UNION ALL
 Select 'Mississippi', 'MS' UNION ALL
 Select 'Missouri', 'MO' UNION ALL
 Select 'Montana', 'MT' UNION ALL
 Select 'Nebraska', 'NE' UNION ALL
 Select 'Nevada', 'NV' UNION ALL
 Select 'New Hampshire', 'NH' UNION ALL
 Select 'New Jersey', 'NJ' UNION ALL
 Select 'New Mexico', 'NM' UNION ALL
 Select 'New York', 'NY' UNION ALL
 Select 'North Carolina', 'NC' UNION ALL
 Select 'North Dakota', 'ND' UNION ALL
 Select 'Ohio', 'OH' UNION ALL
 Select 'Oklahoma', 'OK' UNION ALL
 Select 'Oregon', 'OR' UNION ALL
 Select 'Pennsylvania', 'PA' UNION ALL
 Select 'Rhode Island', 'RI' UNION ALL
 Select 'South Carolina', 'SC' UNION ALL
 Select 'South Dakota', 'SD' UNION ALL
 Select 'Tennessee', 'TN' UNION ALL
 Select 'Texas', 'TX' UNION ALL
 Select 'Utah', 'UT' UNION ALL
 Select 'Vermont', 'VT' UNION ALL
 Select 'Virginia', 'VA' UNION ALL
 Select 'Washington', 'WA' UNION ALL
 Select 'West Virginia', 'WV' UNION ALL
 Select 'Wisconsin', 'WI' UNION ALL
 Select 'Wyoming', 'WY' 

[Regarding Game Salad version 0.10.0]

It took me a little bit to realize you can’t just type the name of the table in the tableCellValue().

You need to use the attribute browser to insert the table as a parameter.

GameSaladTableCellValue

I’ve constructed a primitive batch based on the Microsoft and Farseer examples that can apply a texture to a 2D polygon.

Texture configuration properties are stored in the ‘user data’ property in the Farseer Body and Fixture objects.

I use the body position to determine the texture coordinates. This allows you to apply rotation and translation to the texture coordinates based on the body, in addition to the stored properties.

As you can see, the textures can be applied across multiple sub fixtures.

alphaEditor_03

XNA Development – Turnip Toss

Posted: December 27, 2012 in .NET, XNA
Tags: , ,

Working on a XNA game I am currently calling “Turnip Toss” using the Farseer physics engine.

The editor is in early alpha stages now.
2 dimensional “bodies” and simple shapes can be created by right clicking a position on the editing surface.

alphaEditor_01

alphaEditor_02

Converting a Frequency to a Midi Note

Posted: December 3, 2012 in .NET

This is a C# method to convert a pitch or frequency to a midi note.
I am shifting detected frequencies to the nearest semi-tone before using this formula.


private double GetMidiNote(float freq)
{
return Math.Ceiling(69 + 12 * (Math.Log(freq/440, 2)));
}

Introduction to Umbraco

Posted: August 27, 2012 in .NET, Umbraco
Tags: ,

I recently hosted the first Fort Worth .NET User’s Group first SIG.

The topic was Umbraco CMS. Here is the deck –

 

(using MVC4 beta)

In some cases it is not easy to alter the header values to negotiate the content type returned from WEBAPI.

There is a QueryStringMapper object you can add to the Media Type Formatter objects that allow you to use a query string to negotiate the content format.

In the example below,  I am adding a query string parameter ‘format’ to the mapping. When ‘format’ == ‘xml’, the content type is ‘text/xml’ and the XmlMediaTypeFormatter is used.

I run this in the ‘Application_Start’ method of the Global.asax 

            foreach (var item in GlobalConfiguration.Configuration.Formatters)
            {
                if (typeof(XmlMediaTypeFormatter) == item.GetType())
                {
                    item.AddQueryStringMapping("format", "xml", "text/xml");
                }
            }

Example api call – http://localhost/api/foo?format=xml

Here is an example of aggregation using LINQ to a collection –

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GroupByExampleLinq
{
    public class Person
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Email { get; set; }
        public string AccountNumber { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Example();
            Console.ReadKey();
        }

        static void Example()
        {
            // Creating new List of Person
            List personCollection = new List()
            {
                //Adding a new Person
                new Person(){
                    AccountNumber = "123123 634566",
                    Email = "qwerty@qwerty.com",
                    FirstName = "John",
                    LastName = "Doe"
                },
                //Adding a new Person
                new Person(){
                    AccountNumber = "123123 678879",
                    Email = "qwerty@qwerty.com",
                    FirstName = "John",
                    LastName = "Doe"
                },
                //Adding a new Person
                new Person(){
                    AccountNumber = "123123 122134",
                    Email = "qwerty@qwerty.com",
                    FirstName = "John",
                    LastName = "Doe"
                },
                //Adding a new Person
                new Person(){
                    AccountNumber = "123123 890980",
                    Email = "asdf@asdf.com",
                    FirstName = "Jane",
                    LastName = "Doe"
                }
            };

            // Using LINQ to query the collection and group them by the email address
            var personQuery = from p in personCollection
                              group p by p.Email into g
                              select new { Email = g.Key, Accounts = g };

            // Output the email address and the count of records for each group
            foreach (var item in personQuery)
            {
                Console.WriteLine("{0} has {1} accounts.", item.Email, item.Accounts.Count());
            }
        }
    }
}

I use this function to send debugging information to the console in Firefox and IEDeveloper.

Using a query string parameter [debug=1] to enable logging, to save some cycles when its not needed.

I am sure there are better ways to write this…


// Logging Function
function log(msg){
if(!getParameterByName("debug") == 1) { return; }
if (window.console && console.log) {
console.log(msg); // Valid in Firebug and IEDeveloper
}
}

To get the query string parameter, I am using a snippet found on the net a while back. I would give credit, but I have no idea where the original source was.


function getParameterByName( name )
{
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return "";
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
}