Archive for October 27th, 2009

Modal Dialog Development With SimpleModal jQuery Plugin

SimpleModal is a lightweight jQuery plugin that provides a simple interface to create a modal dialog. The goal of SimpleModal is to provide developers with a cross-browser overlay and container that will be populated with content provided.

Because SimpleModal is more of a modal dialog framework; by default it will create very basic, unstyled, modal dialogs. Styling can be done through external CSS or through properties in the options object. It also provides 3 callback options: onOpen, onShow and onClose; allowing you to completely customize the behavior and functionality of the modal dialog.

Developed by Eric Martin; SimpleModal jQuery Plugin is available for download under GPL & MIT License.  You can find further information, demos & download on SimpleModal Website.

Similar Posts:

You can also stay updated by following us on Twitter, becoming a fan on Facebook or by subscribing to our FriendFeed.


Using T4 Templates for Simple DTOs

I’m looking at 5-7 files of data in CSV format. The columns and format can change every 3 to 6 months. What I wanted was a strongly type wrapper / data transfer object for all the CSV file formats I had to work with, and I thought this would be a good opportunity to try a T4 template.

If you haven’t heard of T4 templates before, then it is a technology that is worth your time to investigate. Hanselman has a pile of links in his post T4 (Text Template Transformation Toolkit) Code Generation – Best Kept Visual Studio Secret.

Each CSV file I’m working with has a header row:

PID,CaseID,BirthDate,DischargeDate,Status …
1001,2001,1/1/1970,6/1/2009,Foo …

… and so on for ~ 100 columns.

I wanted a template that could look at every CSV file it finds in the same directory as itself and create a class with a string property for each column. The template would derive the name of the class from the filename. Here’s a starting point:

<#@ template language="c#v3.5" hostspecific="true" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Collections.Generic" #>

using System;
namespace Acme.Foo.CsvImport {
                
<#
    foreach(var fileName in GetCsvFileNames())
    {
        var fields = GetFields(fileName);
        var className = GenerateClassName(fileName);
#>
    public class <#= className #> : ImportRecord
    { 
        public <#= className #>(string data)
        {
            var fields = data.Split(',');
            <# for(int i = 0; i < fields.Length; i++) { #>
              <#= fields[i] #> = (fields[<#= i #>]);
            <# } #>
        }
    
       <#
       foreach(var field in fields) { #>        
        public string <#= field #> { get; set; } <#
      } #>                        
    }
    
<# } #>
    
} // end namespace

<#+
    private string GenerateClassName(string fileName)
    {
        return Path.GetFileName(fileName).Substring(0,2) 
                          + "_ImportRecord";
    }
    
    private string[] GetFields(string fileName)
    {
        using (var stream = new StreamReader(
                                  File.OpenRead(fileName)))
        {
            return stream.ReadLine().Split(',');
        }
    }
    
    private IEnumerable<string> GetCsvFileNames()
    {
        var path = Host.ResolvePath("");
        return Directory.GetFiles(path, "*.csv");        
    }
#>

The template itself needs some polishing, and the generated code needs some error handling, but this was enough to prove how easy it is to spit out type definitions from a CSV header:

public class AA_ImportRecord
{
    public AA_ImportRecord(string data)
    {
        var fields = data.Split(',');
        ID = fields[0];
        CaseID = fields[1];
        BirthDate = fields[2];           
    }

    public string ID { get; set; }
    public string CaseID { get; set; }
    public string BirthDate { get; set; }

    // ...
}

What I Learned

  1. If you want to use the C# 3.5 compiler and LINQ features, make sure to use the correct template and assembly directives. Oleg Sych has the details: Understanding T4: <#@ template #> directive.
  2. When the template runs it is an object derived from the TextTransformation class. Oleg’s post that I linked to above also has details on this magic. Use the <#+ #> syntax to add members (a.k.a helper functions) to the class definition for this object.
  3. The Host property is of type ITextEngineTemplatingHost. You can use the Host to log errors, find referenced assemblies, and more. In the template I had to use Host.ResolvePath to get the absolute path to the directory where the template file lives. 
  4. The biggest issue I had was using <# and #> instead of <% and %>, and <#= #> instead of <%= %>. I created at least 100 errors because my fingers are trained for ASP.NET views instead of text templates. 

Using Microsoft’s Chart Controls In An ASP.NET Application: Creating Drill Down Reports

Each series in a chart is composed of a set of data points, which are modeled via the DataPoint class. For most chart types, the two key attributes of a data point are its X and Y value. For example, in a line chart the X value indicates the position of the data point along the X axis, while the Y value represents the position of the data point along the Y axis. Ditto for a column chart, although it may help to think of the Y value as the height of the column.

In addition to X and Y values, data points can include additional bits of information, including an associated URL. As you would expect, when a data point has an associated URL it becomes click-able in the rendered chart image, and clicking the data point whisks the user to the specified URL. By specifying URLs, it's possible to create drill down reports, which are reports that let the user click a particular data point in a chart to explore its details.

This article examines how to build drill down reports. Specifically, we'll walk through two demos that display the same data using a column chart. The charts' X axes list the categories in the Northwind database's Categories table, with the height of each category's column indicating the number of products associated with said category. Clicking on one of these columns in the chart takes the user to a second web page, which displays a grid showing the products that belong to the selected category. The second demo enhances the chart to display the corresponding category's products when hovering the mouse over the category column. Read on to learn more!
Read More >


Video: CodeRush Metric Shader Plugin

Check out the CodeRush Metric Shader plugin video with Rory Becker. Rory’s created for you another useful plugin that helps you visualize code metrics!

Check out the video to see what I mean:

Video: CodeRush Metric Shader Plugin

Then, be sure to leave us a comment below with your thoughts, questions or just praise for Rory.

DevExpress PDC 2009 Platinum SponsorDXperience? What's That?

DXperience is a royalty-free tool suite for rapid business application development for WinForms and ASP.NET apps.

Instantly enhance your WinForms and ASP.NET apps by dropping in new feature sets encapsulated in components. DXperience contains:

  • IDE Productivity Tools - Make Visual Studio easier and more effective with IDE enhancements
    • DXCore - IDE tools extensible engine
    • CodeRush - Extensible swiss army knife of tools to make source code editing faster and easier, including code editing templates, code editing utilities (selection, navigation, clipboard), inline code visualizations and the upcoming unit test runner.
    • Refactor Pro - Code editing tools specifically geared for refactoring source code.
  • XAF - Business app framework for WinForms and ASP.NET
  • XPO – Object-relational mapping for .NET
  • Reporting - Reporting "platform" for WinForms and ASP.NET
  • UI Components for WinForms, ASP.NET, WPF and Silverlight

Try a fully-functional version of DXperience for free now: http://www.devexpress.com/Downloads/NET/


Interfaces and Dynamic Class Instantiation

I always enjoy Jesse Freeman's Flash Art of War column, and this week's, "Dynamically Creating(/Instantiating) Classes from XML," was especially intriguing. The thing that stuck out to me about that post is that if you are creating objects dymanically, you...

  • Sponsored Links

  •  

  • .

    Copyright © 1996-2010 Answer My Query. All rights reserved.
    iDream theme by Templates Next | Powered by WordPress